-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
53 lines (43 loc) · 1.63 KB
/
index.js
File metadata and controls
53 lines (43 loc) · 1.63 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
var inputval = document.getElementById("inputval")
var buttonid = document.getElementById("buttonid")
buttonid.addEventListener("click",()=>{
var url ="http://api.openweathermap.org/data/2.5/weather?q="+ inputval.value +"&appid=your_api_id_here";
fetch(url)
.then(
(apidata) => apidata.json()
)
.then((data) => {
console.log(data)
//city//
var nameval = data['name']
var namehtml = document.getElementById("namehtml")
namehtml.innerHTML = nameval
console.log(nameval)
// description//
var weatherval = data['weather'][0]['description']
var desphtml = document.getElementById("desphtml")
desphtml.innerHTML = weatherval
console.log(weatherval)
// temperature in F//
var tempval = data['main']['temp']
var tempfar = Math.floor(((tempval-273.15)*1.8)+32);
var tempf = document.getElementById("tempf")
tempf.innerHTML = `${tempfar} ℉`
console.log("farenhite",tempfar)
// temperature in c//
var tempval = data['main']['temp']
var tempcel = Math.floor(tempval-273.15);
var tempc = document.getElementById("tempc")
tempc.innerHTML = `${tempcel} ℃`
console.log("celcius",tempcel)
// icon //
var icondata = data['weather'][0]['icon']
var icon = document.getElementById('icon')
icon.innerHTML = `<img src="http://openweathermap.org/img/wn/${icondata}.png"></img>`
console.log(icondata)
})
// error//
.catch( (error) => {
console.log("error is ", error)
})
})