-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ilta Riikonen
committed
Dec 8, 2024
1 parent
43ae0a3
commit 500f1b2
Showing
2 changed files
with
25 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,38 @@ | ||
fetch('https://api.openweathermap.org/data/2.5/weather?lang=fi&q=helsinki&units=metric&APPID=665ecd56dfc08dbb50feb8b8f5034e28') | ||
.then(function(response) { | ||
fetch( | ||
"https://api.openweathermap.org/data/2.5/weather?lang=fi&q=helsinki&units=metric&APPID=665ecd56dfc08dbb50feb8b8f5034e28" | ||
) | ||
.then(function (response) { | ||
return response.json(); | ||
}) | ||
.then(function(responseJson) { | ||
.then(function (responseJson) { | ||
kerro(responseJson, "helsinki"); | ||
}) | ||
.catch(function(error) { | ||
.catch(function (error) { | ||
document.getElementById("vastaus").innerHTML = | ||
"<p>Tietoa ei pystytä hakemaan</p>"; | ||
}); | ||
|
||
fetch('https://api.openweathermap.org/data/2.5/weather?lang=fi&q=tampere&units=metric&APPID=665ecd56dfc08dbb50feb8b8f5034e28') | ||
.then(function(response) { | ||
fetch( | ||
"https://api.openweathermap.org/data/2.5/weather?lang=fi&q=tampere&units=metric&APPID=665ecd56dfc08dbb50feb8b8f5034e28" | ||
) | ||
.then(function (response) { | ||
return response.json(); | ||
}) | ||
.then(function(responseJson) { | ||
.then(function (responseJson) { | ||
kerro(responseJson, "tampere"); | ||
}) | ||
.catch(function(error) { | ||
.catch(function (error) { | ||
document.getElementById("vastaus").innerHTML = | ||
"<p>Tietoa ei pystytä hakemaan</p>"; | ||
}); | ||
|
||
function kerro(data, field) { | ||
teksti = "<h3>" + data.name +"</h3>"; | ||
teksti += "<ul><li><b>Sää:</b> " + data.weather[0].description; | ||
teksti += "</li><li><b>Lämpötila: </b> " + data.main.temp + " °C"; | ||
teksti += "</li><li><b>Tuulen nopeus: </b> " + data.wind.speed + " m/s"; | ||
teksti += "</li></ul>"; | ||
document.getElementById(field).innerHTML = teksti; | ||
} | ||
let teksti = "<h3>" + data.name + "</h3>"; | ||
teksti += "<ul><li><b>Sää:</b> " + data.weather[0].description; | ||
teksti += "</li><li><b>Lämpötila: </b> " + data.main.temp + " °C"; | ||
teksti += "</li><li><b>Tuulen nopeus: </b> " + data.wind.speed + " m/s"; | ||
teksti += "</li></ul>"; | ||
let kuva = "http://openweathermap.org/img/w/" + data.weather[0].icon + ".png"; | ||
teksti += "<p class='image'><img src='" + kuva + "'alt='sää ikoni'></img></p>"; | ||
teksti += document.getElementById(field).innerHTML = teksti; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,10 @@ body { | |
display: none; | ||
} | ||
|
||
.image { | ||
padding: 0 7%; | ||
} | ||
|
||
#vastaus { | ||
padding: 0.5% 7% 1% 3%; | ||
} | ||
|