Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilta Riikonen committed Dec 8, 2024
1 parent 43ae0a3 commit 500f1b2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
36 changes: 21 additions & 15 deletions 3b/saa.js
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;
}
4 changes: 4 additions & 0 deletions 3b/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ body {
display: none;
}

.image {
padding: 0 7%;
}

#vastaus {
padding: 0.5% 7% 1% 3%;
}
Expand Down

0 comments on commit 500f1b2

Please sign in to comment.