From 7f623c808565caa8f4e25edfb6621200aaffb633 Mon Sep 17 00:00:00 2001
From: Elina Eriksson Hult
Date: Wed, 25 Sep 2024 10:38:49 +0200
Subject: [PATCH 01/12] First commit - added URL and API key
---
.DS_Store | Bin 0 -> 6148 bytes
Code/index.html | 14 ++++++++++++++
Code/script.js | 12 ++++++++++++
Code/style.css | 0
4 files changed, 26 insertions(+)
create mode 100644 .DS_Store
create mode 100644 Code/index.html
create mode 100644 Code/script.js
create mode 100644 Code/style.css
diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000000000000000000000000000000000000..135244b077e0e94e4dfc129a1afce6208fb6fd4e
GIT binary patch
literal 6148
zcmeH~F$w}f3`G;&La^D=avBfd4F+9LuotjUY(zoOdXDZ-CJ2t!BJu;tpJXO1`-+{7
zi0JyZUy1Z0GJ~7S(n4d3ypxSwWG{#Ncs-vk=Ob!XpTt>P!+UA=W1B((BtQZrKmsK2
zLj>&JhRx4X|sK7L)2aQ(s
zF~sWL4oz_`hnA|fT{MOdjVG&3F)*#|q6rC1vkL@un
zGXmNT)z$?L_2URHKLJSWDqg_du%B!J&7q|#Dlq;CI0gn1_$q-1
DrpXeH
literal 0
HcmV?d00001
diff --git a/Code/index.html b/Code/index.html
new file mode 100644
index 000000000..748c6b5ff
--- /dev/null
+++ b/Code/index.html
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+ Weather app
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Code/script.js b/Code/script.js
new file mode 100644
index 000000000..0c07ed302
--- /dev/null
+++ b/Code/script.js
@@ -0,0 +1,12 @@
+//Stockholm current weather API
+//URL current weather Stockholm + city + API key
+// https://api.openweathermap.org/data/2.5/weather?q=Stockholm,Sweden&units=metric&APPID=959cb256f265cbbe5b4051e4a40be3af
+
+// True constants
+const API_KEY = "959cb256f265cbbe5b4051e4a40be3af";
+const BASE_URL = "https://api.openweathermap.org/data/2.5/weather";
+
+let city = "Stockholm";
+
+const URL = `${BASE_URL}?q=${city}&units=metric&APPID=${API_KEY}`;
+console.log(URL)
diff --git a/Code/style.css b/Code/style.css
new file mode 100644
index 000000000..e69de29bb
From 83bfdda80197ec58692271928f9c60ac6dfec977 Mon Sep 17 00:00:00 2001
From: Elina Eriksson Hult
Date: Wed, 25 Sep 2024 11:05:09 +0200
Subject: [PATCH 02/12] Added fetch function to request current weather in
Stockholm
---
Code/index.html | 10 ++++++----
Code/script.js | 10 ++++++++++
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/Code/index.html b/Code/index.html
index 748c6b5ff..95c53acda 100644
--- a/Code/index.html
+++ b/Code/index.html
@@ -2,13 +2,15 @@
-
-
- Weather app
+
+
+ Weather app
-
+
+
+
\ No newline at end of file
diff --git a/Code/script.js b/Code/script.js
index 0c07ed302..bc1dd32fe 100644
--- a/Code/script.js
+++ b/Code/script.js
@@ -10,3 +10,13 @@ let city = "Stockholm";
const URL = `${BASE_URL}?q=${city}&units=metric&APPID=${API_KEY}`;
console.log(URL)
+
+fetch(URL)
+ .then(response => response.json())
+ .then(data => {
+ console.log(data.weather)
+ })
+
+
+
+
From f2c771420e6ea4765000cca27e77b15332f65470 Mon Sep 17 00:00:00 2001
From: Elina Eriksson Hult
Date: Wed, 25 Sep 2024 12:31:17 +0200
Subject: [PATCH 03/12] City, temperature and what type of weather displayed on
web app
---
Code/index.html | 5 +++++
Code/script.js | 30 +++++++++++++++++++++++++++++-
2 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/Code/index.html b/Code/index.html
index 95c53acda..cfef57de9 100644
--- a/Code/index.html
+++ b/Code/index.html
@@ -8,7 +8,12 @@
+ Current Weather
+
+
+
+
diff --git a/Code/script.js b/Code/script.js
index bc1dd32fe..cd56131f8 100644
--- a/Code/script.js
+++ b/Code/script.js
@@ -11,12 +11,40 @@ let city = "Stockholm";
const URL = `${BASE_URL}?q=${city}&units=metric&APPID=${API_KEY}`;
console.log(URL)
+// DOM selectors
+// const place = document.getElementById("temperature");
+
fetch(URL)
.then(response => response.json())
.then(data => {
- console.log(data.weather)
+
+ cityName = data.name;
+ //Log to console - remove later
+ console.log(cityName)
+
+ const temp = data.main.temp.toFixed(1);
+ //Log to console - remove later
+ console.log(temp)
+
+ const typeOfWeather = data.weather[0].description;
+ //Log to console - remove later
+ console.log(typeOfWeather)
+
+ const sunriseTime = data.sys.sunrise;
+ //Log to console - remove later
+ console.log(sunriseTime)
+
+ const sunsetTime = data.sys.sunset;
+ //Log to console - remove later
+ console.log(sunsetTime)
+
+ document.getElementById("location").innerText = `${cityName}`;
+ document.getElementById("temperature").innerText = `${temp}°C`;
+ document.getElementById("weather").innerText = `${typeOfWeather}`;
})
+// - The app should have: city name, current temperature, weather description,
+// sunrise/sunset time, 4-day forecast
From 0b69b765842887a636f28ecb8e3feb5449e683cf Mon Sep 17 00:00:00 2001
From: Elina Eriksson Hult
Date: Thu, 26 Sep 2024 10:52:54 +0200
Subject: [PATCH 04/12] Added sunrise, sunset and 4-day forecast
---
Code/index.html | 7 ++++++
Code/script.js | 65 +++++++++++++++++++++++++++++++++++--------------
2 files changed, 54 insertions(+), 18 deletions(-)
diff --git a/Code/index.html b/Code/index.html
index cfef57de9..39e7e2ed0 100644
--- a/Code/index.html
+++ b/Code/index.html
@@ -8,11 +8,18 @@
+
Current Weather
+ Sunrise
+ Sunset
+
+
+ 4-Day Forecast Weather
+
diff --git a/Code/script.js b/Code/script.js
index cd56131f8..6cfd14291 100644
--- a/Code/script.js
+++ b/Code/script.js
@@ -5,6 +5,7 @@
// True constants
const API_KEY = "959cb256f265cbbe5b4051e4a40be3af";
const BASE_URL = "https://api.openweathermap.org/data/2.5/weather";
+const FORECAST_BASE_URL = "https://api.openweathermap.org/data/2.5/forecast";
let city = "Stockholm";
@@ -12,39 +13,67 @@ const URL = `${BASE_URL}?q=${city}&units=metric&APPID=${API_KEY}`;
console.log(URL)
// DOM selectors
-// const place = document.getElementById("temperature");
+// const place = document.getElementById("temperature"); REMOVE THIS
fetch(URL)
.then(response => response.json())
.then(data => {
cityName = data.name;
- //Log to console - remove later
- console.log(cityName)
-
const temp = data.main.temp.toFixed(1);
- //Log to console - remove later
- console.log(temp)
-
const typeOfWeather = data.weather[0].description;
- //Log to console - remove later
- console.log(typeOfWeather)
-
- const sunriseTime = data.sys.sunrise;
- //Log to console - remove later
- console.log(sunriseTime)
+ const sunriseTime = new Date(data.sys.sunrise * 1000).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
+ const sunsetTime = new Date(data.sys.sunset * 1000).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
- const sunsetTime = data.sys.sunset;
- //Log to console - remove later
- console.log(sunsetTime)
+ // Remove consol log later
+ console.log(cityName, temp, typeOfWeather, sunriseTime, sunsetTime);
document.getElementById("location").innerText = `${cityName}`;
document.getElementById("temperature").innerText = `${temp}°C`;
document.getElementById("weather").innerText = `${typeOfWeather}`;
+ document.getElementById("sunrise").innerText = `${sunriseTime}`;
+ document.getElementById("sunset").innerText = `${sunsetTime}`;
})
-// - The app should have: city name, current temperature, weather description,
-// sunrise/sunset time, 4-day forecast
+// 4 - day forecast
+const forecastURL = `${FORECAST_BASE_URL}?q=${city}&units=metric&APPID=${API_KEY}`;
+console.log(forecastURL);
+
+fetch(forecastURL)
+ .then(response => response.json())
+ .then(data => {
+ const forecastList = document.getElementById("forecast-list");
+
+ //Grouping forecast date and calculate the average temp
+ const dailyTemps = {};
+
+ data.list.forEach(forecast => {
+ const dateObj = new Date(forecast.dt_txt); // Create Date object
+ const dayOfWeek = dateObj.toLocaleDateString('en-US', { weekday: 'long' }); // Get long full name of the day
+ const temp = forecast.main.temp;
+
+ if (!dailyTemps[dayOfWeek]) {
+ dailyTemps[dayOfWeek] = {
+ totalTemp: temp,
+ count: 1
+ };
+ } else {
+ dailyTemps[dayOfWeek].totalTemp += temp;
+ dailyTemps[dayOfWeek].count += 1;
+ }
+ })
+
+ // clear any existing forecast data
+ forecastList.innerText = "";
+ // Calculate the average and only take the first 4 days of forecast data
+ Object.keys(dailyTemps).slice(0, 4).forEach(dayOfWeek => {
+ const averageTemp = (dailyTemps[dayOfWeek].totalTemp / dailyTemps[dayOfWeek].count).toFixed(1);
+ const forecastItem = document.createElement("p");
+ forecastItem.innerHTML = `${dayOfWeek} ${averageTemp}°C`;
+ // Append the forecast item to the UL
+ forecastList.appendChild(forecastItem);
+ });
+ });
\ No newline at end of file
From 640c5af5c1ac213f9a0f80bf71550659ef6638de Mon Sep 17 00:00:00 2001
From: Elina Eriksson Hult
Date: Thu, 26 Sep 2024 13:30:42 +0200
Subject: [PATCH 05/12] Added image and styling in CSS
---
Code/index.html | 41 ++++++++++++++++++++++++++++++++++++++++-
Code/style.css | 32 ++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 1 deletion(-)
diff --git a/Code/index.html b/Code/index.html
index 39e7e2ed0..b4c9f4c4f 100644
--- a/Code/index.html
+++ b/Code/index.html
@@ -5,12 +5,51 @@
Weather app
+
+
+
Current Weather
+
+
+
+
@@ -19,7 +58,7 @@ Current Weather
4-Day Forecast Weather
-
+
diff --git a/Code/style.css b/Code/style.css
index e69de29bb..dd98f8235 100644
--- a/Code/style.css
+++ b/Code/style.css
@@ -0,0 +1,32 @@
+body {
+ font-family: 'Arial', sans-serif;
+ background-color: #f7f0cf;
+ color: #3c3c3b;
+ margin: 0;
+ padding: 20px;
+}
+
+h1 {
+ font-size: 24px;
+ margin-bottom: 10px;
+ color: #2e523a;
+ /* Dark green */
+}
+
+p {
+ font-size: 18px;
+ margin: 4px 0;
+}
+
+h2 {
+ font-size: 24px;
+ margin-bottom: 10px;
+ color: #2e523a;
+ /* Dark green */
+}
+
+#forecast-list {
+ font-size: 20px;
+ color: #2e523a;
+ margin-bottom: 15px;
+}
\ No newline at end of file
From 88e7e7671afb0656227049a036996ebf42484f99 Mon Sep 17 00:00:00 2001
From: Elina Eriksson Hult
Date: Sun, 29 Sep 2024 00:24:52 +0200
Subject: [PATCH 06/12] Added styling to CS and catch error to javascript file
---
Code/index.html | 31 +++++++++++++++++++------------
Code/script.js | 25 +++++++++++++++++--------
Code/style.css | 40 +++++++++++++++++++++++++++++++---------
3 files changed, 67 insertions(+), 29 deletions(-)
diff --git a/Code/index.html b/Code/index.html
index b4c9f4c4f..97d67ab37 100644
--- a/Code/index.html
+++ b/Code/index.html
@@ -12,11 +12,21 @@
- Current Weather
-
+
+
+
+
+
+
Sunrise
+
Sunset
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
Get your sunnies on.
diff --git a/script.js b/script.js
index 3484bd20f..d8dfb035d 100644
--- a/script.js
+++ b/script.js
@@ -7,7 +7,6 @@ const city = "Stockholm";
// Create URL for current weather
const URL = `${BASE_URL}?q=${city}&units=metric&APPID=${API_KEY}`;
-console.log(URL)
const errorDiv = document.getElementById("error");
diff --git a/style.css b/style.css
index 8cee15bdc..4a29f2900 100644
--- a/style.css
+++ b/style.css
@@ -1,4 +1,8 @@
body {
+ display: flex;
+ flex-direction: column;
+ align-items: flex-start;
+ justify-content: flex-start;
font-family: 'Arial', sans-serif;
background-color: #F7E9B9;
color: #2A5510;
@@ -7,10 +11,12 @@ body {
}
.current-weather {
- font-weight: 400;
- padding-left: 10px;
+ display: flex;
+ flex-direction: column;
+ align-items: flex-start;
+ gap: 10px;
font-size: 21px;
- line-height: 25.6px;
+ padding-bottom: 40px;
}
p {
@@ -19,21 +25,26 @@ p {
}
#image {
- padding-left: 10px;
+ display: block;
+ margin: 30px auto;
}
-h1,
-#location {
+h1 {
+ margin-top: 20px;
+ text-align: left;
font-size: 37px;
- margin-bottom: 10px;
+ padding-top: 15px;
+ padding-bottom: 15px;
color: #2A5510;
- padding-left: 10px;
- line-height: 45.1px;
- font-weight: 700;
}
-h1 {
- padding-bottom: 15px;
+#location {
+ margin-top: 20px;
+ text-align: left;
+ font-size: 37px;
+ color: #2A5510;
+ padding-left: 5px;
+
}
.forecast-container p {