-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js~
54 lines (51 loc) · 1.64 KB
/
script.js~
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//fixme and switch to currency
$(document).ready(function() {
console.log("hello world");
$("#weatherSubmit").click(function(e) {
e.preventDefault();
var value = $("#weatherInput").val();
console.log(value);
var myurl= "http://api.openweathermap.org/data/2.5/weather?q=" + value + ",US&units=imperial" + "&APPID=4ccc856bec704207ab8bdabc4121683a";
$.ajax({
url : myurl,
dataType : "json",
success : function(json) {
console.log(json);
var results = "";
results += '<h2>Weather in ' + json.name + "</h2>";
for (var i=0; i<json.weather.length; i++) {
results += '<img src="http://openweathermap.org/img/w/' + json.weather[i].icon + '.png"/>';
}
results += '<h2>' + json.main.temp + " °F</h2>"
results += "<p>"
for (var i=0; i<json.weather.length; i++) {
results += json.weather[i].description
if (i !== json.weather.length - 1)
results += ", "
}
results += "</p>";
results += "<p>Humidity: " + json.main.humidity + "%</p>";
$("#weatherResults").html(results);
}
});
});
$("#stackSubmit").click(function(e) {
e.preventDefault();
var value = $("#stackInput").val();
console.log(value);
var myurl= "https://api.stackexchange.com/2.2/search?order=desc&sort=activity&site=stackoverflow&intitle=" + value;
$.ajax({
url : myurl,
dataType : "json",
success : function(json) {
console.log(json);
var stackResults = "";
for (var j = 0; j < json.items.length; j++) {
stackResults += '<a href="' + json.items[j].link + '">' +
json.items[j].title + '</a>' + '<br/><br/>';
}
$('#stackFinalResults').html(stackResults);
}
});
});
});