JSON Fun times
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.6/handlebars.min.js"></script>
<h1>Enter your city, breh</h1>
<input type="text" id="cityInput" placeholder="enter city">
<input type="text" id="stateInput" placeholder="enter state">
<button>
submit me my dude
</button>
<div id="loader"></div>
<div id="condition">
</div>
<div id="temp">
</div>
CSS
h1 {
font-family: 'Helvetica Neue', 'Helvetica', sans-serif;
font-weight: 300;
}
label {
display: block;
font-family: 'Helvetica Neue', 'Helvetica', sans-serif;
font-weight: 400;
font-size: 12px;
text-transform: uppercase;
margin-bottom: 5px;
display: none;
}
input {
border: 2px solid #ccc;
border-radius: 4px;
font-size: 20px;
padding: 0px 9px;
height: 40px;
margin: 0px;
}
button {
height: 44px;
line-height: 44px;
border: none;
font-size: 20px;
text-transform: uppercase;
border-radius: 4px;
padding: 0px 18px;
background: #188BCF;
color: white;
font-family: 'Helvetica Neue', 'Helvetica', sans-serif;
cursor: pointer;
}
button:hover {
background: #273A49;
}
button:focus {
border: none;
box-shadow: none;
}
a.btn {
display: inline-block;
border: none;
margin-top: 15px;
font-size: 15px;
text-transform: uppercase;
border-radius: 4px;
padding: 9px;
background: #ECC04A;
color: white;
font-family: 'Helvetica Neue', 'Helvetica', sans-serif;
cursor: pointer;
text-decoration: none;
}
#message {
font-family: 'Helvetica Neue', 'Helvetica', sans-serif;
font-weight: bold;
}
#tour-dates {
font-family: 'Helvetica Neue', 'Helvetica', sans-serif;
}
JavaScript
$(document).ready(function(){
$('button').on('click',function(){
$.ajax({
url : 'https://api.wunderground.com/api/3f883e673417b8d7/hourly/q/' + $('#stateInput').val() + '/' + $('#cityInput').val() + '.json',
method: 'get',
dataType: 'json',
beforeSend: function() {
$('#loader').html('<p>Loading...</p>');
},
success: function(data){
$('#loader').empty();
var keys = [];
var values = [];
$.each(data.hourly_forecast, function(key,value){
keys.push(key);
values.push(value);
});
if (keys.length == 0){
alert("Sorry bruh, no weather lol");
} else {
$('#condition').html(data.hourly_forecast[0].condition);
$('#temp').html(data.hourly_forecast[0].temp.english);
}
}
});
});
});