-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyScript.js
More file actions
86 lines (68 loc) · 2.82 KB
/
myScript.js
File metadata and controls
86 lines (68 loc) · 2.82 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* Created by Joe on 12/8/2016.
*/
/*functions start*/
var swap = true;
function standardToMetric(){
if (swap===false){
$("#f").html(f);
swap=true;
}
else{
$("#f").html(c);
swap=false;
}
}
/*functions end*/
// this code is the code for the initial weather check
$(document).ready(function () {
var lon;
var lat;
$.getJSON("http://ip-api.com/json",function(data){
lat=data.lat;
lon=data.lon;
//get weather api
var weather = "http://api.openweathermap.org/data/2.5/weather?lat="+lat+"&lon="+lon+"&appid=4e44e3428b01d9a6ad76981f8ab8db5a"
$.getJSON(weather, function(data1){
var city = data1.name;
var count =data1.sys.country;
var type = data1.weather[0].description;
var kelvin =data1.main.temp;
var wind = data1.wind.speed;
f = Math.round((kelvin * (9/5)-459.67)*10)/10+" °F";
c = Math.round((kelvin-273.15)*10)/10+" °C";
//store in variables
$("#city").html(city);
$("#country").html(count);
$("#type").html(type);
$("#wind").html(wind);
$("#f").html(f);
document.getElementById('change').onclick=standardToMetric;
});
//get city from form input
$("#getcity").click(function(){
var location = $('#stateInput').val();
//prevents the form from refreshing the page
event.preventDefault();
var weather = "http://api.openweathermap.org/data/2.5/weather?q="+location+",usa&appid=4e44e3428b01d9a6ad76981f8ab8db5a";
$.getJSON(weather, function(data1){
var city = data1.name;
var count =data1.sys.country;
var type = data1.weather[0].description;
var kelvin =data1.main.temp;
var wind = data1.wind.speed;
f = Math.round((kelvin * (9/5)-459.67)*10)/10+" °F";
c = Math.round((kelvin-273.15)*10)/10+" °C";;
var swap = true
//store in variables
$("#city").html(city);
$("#country").html(count);
$("#type").html(type);
$("#wind").html(wind);
$("#f").html(f);
document.getElementById('change').onclick=standardToMetric
}
);
});
});
});