-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.js
More file actions
35 lines (27 loc) · 804 Bytes
/
index.js
File metadata and controls
35 lines (27 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// execute this function only when the page finished loading
$(function () {
// when the form is submitted, get the city nams
$('form').on('submit', function (event) {
event.preventDefault();
var userInput = $('input').val();
var cities = userInput.split(',');
for(var i = 0; i < cities.length; i++) {
// inside the loop
var cityName = cities[i];
console.log(cityName);
}
});
});
function printWeather(response) {
var element = $('<p>', {
text: response.main.temp
});
$('.output').append(element);
}
function getWeather(cityName) {
var url = 'https://crossorigin.me/http://api.openweathermap.org/data/2.5/weather' +
'?appid=c2f2d170f6f6fc336058e9851edb828c' +
'&q=' + cityName +
'&units=imperial';
$.get(url, printWeather);
}