Skip to content

Commit a273575

Browse files
committed
simple js code to show the weather
1 parent adb1517 commit a273575

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Project 6 - Weather app/app.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var button = document.querySelector('.button')
2+
var inputValue = document.querySelector('.inputValue')
3+
var desc = document.querySelector('.desc');
4+
var name = document.querySelector('.name');
5+
var temp = document.querySelector('.temp');
6+
7+
button.addEventListener('click', function () {
8+
fetch('https://api.openweathermap.org/data/2.5/weather?q='+inputValue.value+'&appid=c983aed69b497603ff80d72814dbadd1')
9+
.then(response => response.json())
10+
.then(data => {
11+
var nameValue = data['name'];
12+
var tempValue = data['main']['temp'];
13+
var descValue = data['weather'][0]['description'];
14+
15+
name.innerHTML = nameValue;
16+
temp.innerHTML = tempValue;
17+
desc.innerHTML = descValue;
18+
})
19+
20+
21+
.catch(err => alert("Wrong city name!"))
22+
})

Project 6 - Weather app/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<body>
1010
<div class="input">
1111
<input type="text" class="inputValue" placeholder="Enter a city">
12-
<input type="submit" value="submit">
12+
<input type="submit" value="submit" class="button">
1313
</div>
1414

1515
<div class="display">

0 commit comments

Comments
 (0)