From 500f1b2c10b7b1319444f9e9b105677d4fad5f0e Mon Sep 17 00:00:00 2001 From: Ilta Riikonen Date: Sun, 8 Dec 2024 02:43:41 +0200 Subject: [PATCH] --- 3b/saa.js | 36 +++++++++++++++++++++--------------- 3b/style.css | 4 ++++ 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/3b/saa.js b/3b/saa.js index 6e66d59..a43bd90 100644 --- a/3b/saa.js +++ b/3b/saa.js @@ -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 = "

Tietoa ei pystytä hakemaan

"; }); - 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 = "

Tietoa ei pystytä hakemaan

"; }); function kerro(data, field) { - teksti = "

" + data.name +"

"; - teksti += ""; - document.getElementById(field).innerHTML = teksti; -} \ No newline at end of file + let teksti = "

" + data.name + "

"; + teksti += ""; + let kuva = "http://openweathermap.org/img/w/" + data.weather[0].icon + ".png"; + teksti += "

sää ikoni

"; + teksti += document.getElementById(field).innerHTML = teksti; +} diff --git a/3b/style.css b/3b/style.css index 051401e..40049a8 100644 --- a/3b/style.css +++ b/3b/style.css @@ -32,6 +32,10 @@ body { display: none; } + .image { + padding: 0 7%; + } + #vastaus { padding: 0.5% 7% 1% 3%; }