From e0f1e9819a98704610fda1f7ce74698c7c1ca749 Mon Sep 17 00:00:00 2001 From: Abdenour Dio Date: Sun, 22 Feb 2026 14:53:45 +0100 Subject: [PATCH 1/9] feat:fetch weather data from openweather API --- .gitignore | 3 ++ .../solution/index.js | 27 ++++++++++++++++++ .../solution/package-lock.json | 28 +++++++++++++++++++ .../solution/package.json | 16 +++++++++++ 4 files changed, 74 insertions(+) create mode 100644 .gitignore create mode 100644 web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js create mode 100644 web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/package-lock.json create mode 100644 web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0907fef --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.env +node_modules +tempCodeRunnerFile.js \ No newline at end of file diff --git a/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js b/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js new file mode 100644 index 0000000..163aa06 --- /dev/null +++ b/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js @@ -0,0 +1,27 @@ +require('dotenv').config(); +//CONSTANTS +const API_KEY = process.env.API_KEY +const LAT = -76.67954 +const LON = -42.80039 + +async function getWeather() { + const response = await fetch(`https://api.openweathermap.org/data/2.5/weather?lat=${LAT}&lon=${LON}&appid=${API_KEY}`) + if (!response.ok){ + throw new Error("a problem has occured") + } + const data = await response.json() + let weather = data['weather'][0]['main'] + let temp = data['main']['temp'] + let humidity = data['main']['humidity'] + const weather_status = { + "weather" : weather, + "temp" : temp, + "humidity" : humidity + } + console.log(weather_status) +} + +getWeather() + + + diff --git a/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/package-lock.json b/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/package-lock.json new file mode 100644 index 0000000..4719a9c --- /dev/null +++ b/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/package-lock.json @@ -0,0 +1,28 @@ +{ + "name": "weather_api", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "weather_api", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "dotenv": "^17.3.1" + } + }, + "node_modules/dotenv": { + "version": "17.3.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.3.1.tgz", + "integrity": "sha512-IO8C/dzEb6O3F9/twg6ZLXz164a2fhTnEWb95H23Dm4OuN+92NmEAlTrupP9VW6Jm3sO26tQlqyvyi4CsnY9GA==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + } + } +} diff --git a/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/package.json b/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/package.json new file mode 100644 index 0000000..c3cb5e3 --- /dev/null +++ b/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/package.json @@ -0,0 +1,16 @@ +{ + "name": "weather_api", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "type": "commonjs", + "dependencies": { + "dotenv": "^17.3.1" + } +} From 8d9a9381ef33166843c15708f77e1dbe30fdd3b5 Mon Sep 17 00:00:00 2001 From: Abdenour Dio Date: Sun, 22 Feb 2026 15:12:34 +0100 Subject: [PATCH 2/9] feat: add geocoding api to fetch lat and lon based on city_name --- ...rn JavaScriptsolutionindex.js\357\200\242" | 233 ++++++++++++++++++ .../solution/index.js | 23 +- 2 files changed, 249 insertions(+), 7 deletions(-) create mode 100644 "ersabdnoOneDriveDocumentsVS codeProjectsJS-projectIT-25-26webLearning-Season03-backendchallengesode.js & Modern JavaScriptsolutionindex.js\357\200\242" diff --git "a/ersabdnoOneDriveDocumentsVS codeProjectsJS-projectIT-25-26webLearning-Season03-backendchallengesode.js & Modern JavaScriptsolutionindex.js\357\200\242" "b/ersabdnoOneDriveDocumentsVS codeProjectsJS-projectIT-25-26webLearning-Season03-backendchallengesode.js & Modern JavaScriptsolutionindex.js\357\200\242" new file mode 100644 index 0000000..bbb20aa --- /dev/null +++ "b/ersabdnoOneDriveDocumentsVS codeProjectsJS-projectIT-25-26webLearning-Season03-backendchallengesode.js & Modern JavaScriptsolutionindex.js\357\200\242" @@ -0,0 +1,233 @@ +commit e0f1e9819a98704610fda1f7ce74698c7c1ca749 (HEAD -> web/AbdenourDio/backend-weather-app) +Author: Abdenour Dio +Date: Sun Feb 22 14:53:45 2026 +0100 + + feat:fetch weather data from openweather API + +commit b5b1ec3d306d391918b60d6844ea21c253fffa10 (origin/web) +Author: anouar mellouk +Date: Sat Feb 21 00:43:21 2026 +0100 + + add README file for back challenge + +commit ff0b9a488e425135cb051096db3a5f7a92d79923 +Author: anouar mellouk +Date: Sat Feb 21 00:31:44 2026 +0100 + + update README file for frontend session + +commit b41b7b288d1defcd397f110802a3959a642a26a2 +Author: anouar mellouk +Date: Sat Feb 21 00:20:21 2026 +0100 + + update README file ( frontend challenge 01) + +commit ad6481d4115a711198de73f916e5fe30addf1a0a +Author: anouar mellouk +Date: Sat Feb 21 00:17:32 2026 +0100 + + add frontend challenge 01 + +commit 67b3762bed2d513712df6dca239bfaa155be10ea +Author: anouar mellouk +Date: Sat Feb 21 00:04:11 2026 +0100 + + add lesson 01 + +commit dcd91a2bde10bd437a4499afe91d9dd799a490a8 +Author: anouar mellouk +Date: Tue Feb 10 20:23:39 2026 +0100 + + update CHALLENES.md + +commit 756d2acf614820d1ebdbdb835ec84938d479b16c +Author: anouar mellouk +Date: Tue Feb 10 20:19:24 2026 +0100 + + update README.mdfor challenge 01 + +commit cf29249d93dcf7c2b6c56ce74bb08e08144ba966 +Author: anouar mellouk +Date: Tue Feb 10 20:15:45 2026 +0100 + + update CONTRIBUTING.md + +commit d3b9abc2881f249b86531b6b6abf2bac8d23e886 +Author: anouar mellouk +Date: Tue Feb 10 15:42:55 2026 +0100 + + update README.md for challenge-01 + +commit ef05ef97ceff16b073610c938508e48137e646d9 +Author: anouar mellouk +Date: Tue Feb 10 15:14:51 2026 +0100 + + update SESSIONS.md + +commit c26358abe547b72722572fff3887fffcb7880f98 +Author: anouar mellouk +Date: Tue Feb 10 15:08:30 2026 +0100 + + update SESSIONS.md + +commit 4fd5fd843b920958c197e545ed424e6ca1eade1c +Author: anouar mellouk +Date: Tue Feb 10 15:07:20 2026 +0100 + + update SESSIONS.md + +commit 5022c571c7a1121e1afcb539d63836ee295fd27a +Author: anouar mellouk +Date: Tue Feb 10 15:06:16 2026 +0100 + + update SESSIONS.md + +commit 4759e3ec1ad9dfaac9e4a5a599c97d99daeed590 +Author: anouar mellouk +Date: Tue Feb 10 15:03:23 2026 +0100 + + update SESSIONS.md + +commit 9c7c92858a5b9095590ed7ddeac5b8a3efbb2de0 +Author: anouar mellouk +Date: Tue Feb 10 14:50:49 2026 +0100 + + setup project structure and add README documentation + +commit 480aef843b0ff8a00ff996f556244f005e553c1f +Author: AnouarMellouk-Engineer +Date: Thu Feb 5 21:13:14 2026 +0100 + + Update css.md + +commit 23ab7502b686ae38cb970f54013d1a508d9f713c +Author: AnouarMellouk-Engineer +Date: Thu Feb 5 21:11:42 2026 +0100 + + Update html.md + +commit c2f7c51205a88ca9fc76a67abb4914fca51bdc56 +Author: AnouarMellouk-Engineer +Date: Thu Feb 5 21:06:44 2026 +0100 + + Update html.md + +commit f868cbcfadf7c8aa3c9c3dd9eca968e1ba65462a +Author: anouar mellouk +Date: Thu Feb 5 20:59:59 2026 +0100 + + Add HTML and CSS fundamentals README + +commit 4742d374974e8e6893c9a6c27a541a42b0001e97 +Author: AnouarMellouk-Engineer +Date: Thu Feb 5 19:25:51 2026 +0100 + + Update README.md + +commit ea8d3319dd1eadf30a08796e85aec10d5a5e5cec +Author: anouar mellouk +Date: Thu Feb 5 19:21:51 2026 +0100 + + Add JavaScript basics lessons and README + +commit a5b47b2c4c2f08ffc91266a0640c27266524e7d5 (origin/main, origin/HEAD, main) +Merge: c2925fc 6a80b10 +Author: DerricheRania <159639527+DerricheRania@users.noreply.github.com> +Date: Sun Feb 1 22:51:41 2026 +0100 + + Merge pull request #2 from MicroClub-USTHB/DerricheRania-patch-1-1 + + Add files via upload + +commit 6a80b10b55ca29d74cc16192e2e4e0f0e29f4bce +Author: DerricheRania <159639527+DerricheRania@users.noreply.github.com> +Date: Sun Feb 1 22:51:23 2026 +0100 + + Add files via upload + +commit c2925fcce5d4d80605546a8c31d4a9a0296b99b9 +Author: DerricheRania <159639527+DerricheRania@users.noreply.github.com> +Date: Sun Feb 1 22:49:02 2026 +0100 + + Delete ai/AI Learning Season/Learning Season Track 1/Workshop1-Python Fundamentals (for AI) directory + +commit 34872098092a3f973d2afa4d683e560369446566 +Author: DerricheRania <159639527+DerricheRania@users.noreply.github.com> +Date: Sun Feb 1 22:48:34 2026 +0100 + + Add files via upload + +commit c52cf17c35c48c5ac525e64d2f465645da548510 +Author: DerricheRania <159639527+DerricheRania@users.noreply.github.com> +Date: Sun Feb 1 22:46:45 2026 +0100 + + Delete ai/AI Learning Season/Learning Season Track 1/Workshop1-Python Fundamentals (for AI) directory + +commit 85bf6eaa69a4c28810474b54a65d4eca67a0a797 +Merge: c56895b 7c2bab0 +Author: DerricheRania <159639527+DerricheRania@users.noreply.github.com> +Date: Sun Feb 1 22:45:48 2026 +0100 + + Merge pull request #1 from MicroClub-USTHB/DerricheRania-patch-1 + + Add files via upload + +commit 7c2bab07720eb10cb8d38a80e70c920efe45842d +Author: DerricheRania <159639527+DerricheRania@users.noreply.github.com> +Date: Sun Feb 1 22:45:21 2026 +0100 + + Add files via upload + +commit c56895b50b27e99f0318c2dfb583ea5f1b7b27e7 +Author: Adel HB +Date: Fri Jan 30 12:06:15 2026 +0100 + + Updated global README.md file + +commit 694bdca9f1827b20e2b4650b053273980e5a2156 +Author: Adel HB +Date: Fri Jan 30 11:59:08 2026 +0100 + + Better Build IT README.md file + +commit 5c6f226dcd2d9d63dc378aa61f3d32a7e3ba8ec1 +Author: Adel HB +Date: Fri Jan 30 11:31:28 2026 +0100 + + Added all Build IT repositories as submodules + +commit 99ae781d3ce9b960fec394526900165d487a156d +Author: Adel HB +Date: Thu Jan 29 22:14:23 2026 +0100 + + Added Build IT overview markdown file + +commit ade86cce318c573935c5000d18948c6d79825c58 +Author: DerricheRania <159639527+DerricheRania@users.noreply.github.com> +Date: Tue Dec 30 19:42:30 2025 +0100 + + Add files via upload + +commit b0d1041083919b58bda74a1ae309ac4b902a04fd +Author: DerricheRania <159639527+DerricheRania@users.noreply.github.com> +Date: Tue Dec 30 19:41:00 2025 +0100 + + Add files via upload + +commit 089b742dc255c3878cb4fb1fa94465b23e094286 +Author: DerricheRania <159639527+DerricheRania@users.noreply.github.com> +Date: Tue Dec 30 19:04:14 2025 +0100 + + Add files via upload + +commit e6a5fa7c6582d9a98707b27926a16b52c72c067a +Author: Adel HB +Date: Mon Dec 8 23:29:57 2025 +0100 + + Added main repository folders + +commit 2e4fc7e3e4240b429e8ce4b3b4ce26a026d6340a +Author: HADJ ARAB Adel <51239656+Adel2411@users.noreply.github.com> +Date: Mon Dec 8 22:43:56 2025 +0100 + + Initial commit diff --git a/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js b/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js index 163aa06..e9f6fcc 100644 --- a/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js +++ b/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js @@ -1,19 +1,28 @@ require('dotenv').config(); //CONSTANTS const API_KEY = process.env.API_KEY -const LAT = -76.67954 -const LON = -42.80039 - +let city_name = "london" async function getWeather() { - const response = await fetch(`https://api.openweathermap.org/data/2.5/weather?lat=${LAT}&lon=${LON}&appid=${API_KEY}`) + const geocoding_response = await fetch(`http://api.openweathermap.org/geo/1.0/direct?q=${city_name}&appid=${API_KEY}`) + if (!geocoding_response.ok) { + throw new Error("a problem has occured") + } + const geocoding_data = await geocoding_response.json() + city_name = geocoding_data['0']['name'] //updated city_name variable + const country = geocoding_data['0']['state'] + let lat = geocoding_data['0']['lat'] + let lon = geocoding_data['0']['lon'] + const response = await fetch(`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=${API_KEY}`) if (!response.ok){ throw new Error("a problem has occured") } const data = await response.json() - let weather = data['weather'][0]['main'] - let temp = data['main']['temp'] - let humidity = data['main']['humidity'] + const weather = data['weather'][0]['main'] + const temp = data['main']['temp'] + const humidity = data['main']['humidity'] const weather_status = { + "Country" : country, + "city" : city_name, "weather" : weather, "temp" : temp, "humidity" : humidity From 1c8e3a0d5d23dbe506b5089e438490afb16b0734 Mon Sep 17 00:00:00 2001 From: Abdenour Dio Date: Sun, 22 Feb 2026 15:35:02 +0100 Subject: [PATCH 3/9] feat: add input for city name with simple validation(no empty or number) --- .../solution/index.js | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js b/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js index e9f6fcc..196dc53 100644 --- a/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js +++ b/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js @@ -1,7 +1,19 @@ require('dotenv').config(); -//CONSTANTS -const API_KEY = process.env.API_KEY -let city_name = "london" +const prompt = require('prompt-sync')({ sigint: true }); // package for getting input + +const API_KEY = process.env.API_KEY // api_key +let city_name; +do { + city_name = prompt("enter a city name to get its weather status: "); + + if (!city_name) { + console.log("city name cannot be empty. Try again"); + } else if (/\d/.test(city_name)) // wch had syntax asahbi, hbit nchecki berk bli not a number + { + console.log("city name cannot contain numbers. Try again"); + + } +}while (!city_name || /\d/.test(city_name)); // while empty or includes number async function getWeather() { const geocoding_response = await fetch(`http://api.openweathermap.org/geo/1.0/direct?q=${city_name}&appid=${API_KEY}`) if (!geocoding_response.ok) { @@ -9,7 +21,7 @@ async function getWeather() { } const geocoding_data = await geocoding_response.json() city_name = geocoding_data['0']['name'] //updated city_name variable - const country = geocoding_data['0']['state'] + const country = geocoding_data['0']['country'] let lat = geocoding_data['0']['lat'] let lon = geocoding_data['0']['lon'] const response = await fetch(`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=${API_KEY}`) From 5d0a2d6836ae63388109baea07965892f5534781 Mon Sep 17 00:00:00 2001 From: Abdenour Dio Date: Sun, 22 Feb 2026 17:29:03 +0100 Subject: [PATCH 4/9] fix: handle network/city name/API key erros with try/catch --- .../solution/index.js | 81 +++++++++++++------ 1 file changed, 57 insertions(+), 24 deletions(-) diff --git a/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js b/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js index 196dc53..c181b02 100644 --- a/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js +++ b/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js @@ -1,6 +1,8 @@ require('dotenv').config(); const prompt = require('prompt-sync')({ sigint: true }); // package for getting input + + const API_KEY = process.env.API_KEY // api_key let city_name; do { @@ -14,32 +16,63 @@ do { } }while (!city_name || /\d/.test(city_name)); // while empty or includes number + + +//fetching data async function getWeather() { - const geocoding_response = await fetch(`http://api.openweathermap.org/geo/1.0/direct?q=${city_name}&appid=${API_KEY}`) - if (!geocoding_response.ok) { - throw new Error("a problem has occured") - } - const geocoding_data = await geocoding_response.json() - city_name = geocoding_data['0']['name'] //updated city_name variable - const country = geocoding_data['0']['country'] - let lat = geocoding_data['0']['lat'] - let lon = geocoding_data['0']['lon'] - const response = await fetch(`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=${API_KEY}`) - if (!response.ok){ - throw new Error("a problem has occured") - } - const data = await response.json() - const weather = data['weather'][0]['main'] - const temp = data['main']['temp'] - const humidity = data['main']['humidity'] - const weather_status = { - "Country" : country, - "city" : city_name, - "weather" : weather, - "temp" : temp, - "humidity" : humidity + try { + if (!API_KEY) { + throw new Error("API-KEY is missing !!! check env file!!!!!!!") + } + const geocoding_response = await fetch(`http://api.openweathermap.org/geo/1.0/direct?q=${city_name}&appid=${API_KEY}`) + + if (geocoding_response.status === 401 || geocoding_response.status === 403){ + throw new Error("INVALID API KEY!!") + } + if (geocoding_response.status === 504) { + throw new Error("Server error, try again later") + } + if (geocoding_response.status === 408) { + throw new Error("slow or unstable client internet connection, check your internet") + } + const geocoding_data = await geocoding_response.json() + if (geocoding_data.length === 0) // if city name was wrong + { + throw new Error("Invalid city name") + } + if (!geocoding_response.ok) { + throw new Error(`Unexpected error: ${geocoding_response.status}`) + } + city_name = geocoding_data['0']['name'] //updated city_name variable + const country = geocoding_data['0']['country'] + let lat = geocoding_data['0']['lat'] + let lon = geocoding_data['0']['lon'] + const response = await fetch(`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=${API_KEY}`) + if (response.status === 504) { + throw new Error("Server error, try again later") + } + if (response.status === 408) { + throw new Error("slow or unstable client internet connection, check your internet") + } + if (!response.ok) { + throw new Error(`Unexpected error: ${response.status}`) + } + const data = await response.json() + const weather = data['weather'][0]['main'] + const temp = data['main']['temp'] + const humidity = data['main']['humidity'] + const weather_status = { + "Country" : country, + "city" : city_name, + "weather" : weather, + "temp" : temp, + "humidity" : humidity + } + console.log(weather_status) + }catch (error){ + console.error("Something went wrong: ", error.message) + } - console.log(weather_status) } getWeather() From f028856552cf456c314cd788c38652db74217f97 Mon Sep 17 00:00:00 2001 From: Abdenour Dio Date: Sun, 22 Feb 2026 17:34:40 +0100 Subject: [PATCH 5/9] refactor: remove number checking in do while for city_name because it is useless --- .../ode.js & Modern JavaScript/solution/index.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js b/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js index c181b02..bb5f943 100644 --- a/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js +++ b/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js @@ -4,18 +4,13 @@ const prompt = require('prompt-sync')({ sigint: true }); // package for getting const API_KEY = process.env.API_KEY // api_key -let city_name; +let city_name; // initial declare do { city_name = prompt("enter a city name to get its weather status: "); if (!city_name) { console.log("city name cannot be empty. Try again"); - } else if (/\d/.test(city_name)) // wch had syntax asahbi, hbit nchecki berk bli not a number - { - console.log("city name cannot contain numbers. Try again"); - - } -}while (!city_name || /\d/.test(city_name)); // while empty or includes number +}}while (!city_name) // while empty //fetching data From d69f4b585269c11550f5d30d9565ddefeb077516 Mon Sep 17 00:00:00 2001 From: Abdenour Dio Date: Mon, 23 Feb 2026 21:06:43 +0100 Subject: [PATCH 6/9] refactor: remove geocoding-api and use built-in API request by city name --- .../solution/index.js | 43 +++++++------------ 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js b/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js index bb5f943..52bb437 100644 --- a/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js +++ b/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js @@ -19,49 +19,37 @@ async function getWeather() { if (!API_KEY) { throw new Error("API-KEY is missing !!! check env file!!!!!!!") } - const geocoding_response = await fetch(`http://api.openweathermap.org/geo/1.0/direct?q=${city_name}&appid=${API_KEY}`) - - if (geocoding_response.status === 401 || geocoding_response.status === 403){ + const response = await fetch(`https://api.openweathermap.org/data/2.5/weather?q=${city_name}&units=${"metric"}&appid=${API_KEY}`) + if (response.status === 401 || response.status === 403){ throw new Error("INVALID API KEY!!") - } - if (geocoding_response.status === 504) { - throw new Error("Server error, try again later") - } - if (geocoding_response.status === 408) { - throw new Error("slow or unstable client internet connection, check your internet") - } - const geocoding_data = await geocoding_response.json() - if (geocoding_data.length === 0) // if city name was wrong - { - throw new Error("Invalid city name") - } - if (!geocoding_response.ok) { - throw new Error(`Unexpected error: ${geocoding_response.status}`) } - city_name = geocoding_data['0']['name'] //updated city_name variable - const country = geocoding_data['0']['country'] - let lat = geocoding_data['0']['lat'] - let lon = geocoding_data['0']['lon'] - const response = await fetch(`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=${API_KEY}`) if (response.status === 504) { throw new Error("Server error, try again later") } if (response.status === 408) { throw new Error("slow or unstable client internet connection, check your internet") } + + const data = await response.json() + console.log(data) + if (response.status === 404) // if city name was wrong + { + throw new Error("Invalid city name") + } if (!response.ok) { throw new Error(`Unexpected error: ${response.status}`) } - const data = await response.json() + const country = data['sys']['country'] + city_name = data['name'] //updated city_name variable const weather = data['weather'][0]['main'] const temp = data['main']['temp'] const humidity = data['main']['humidity'] const weather_status = { - "Country" : country, + "country" : country, "city" : city_name, "weather" : weather, - "temp" : temp, - "humidity" : humidity + "temp" : `${temp}°C`, + "humidity" : `${humidity}%` } console.log(weather_status) }catch (error){ @@ -70,7 +58,8 @@ async function getWeather() { } } -getWeather() + +getWeather() // dédicace l Anouar From 647bc46f146a06afb61bc643bbd93e52a60ac57e Mon Sep 17 00:00:00 2001 From: Abdenour Dio Date: Tue, 24 Feb 2026 00:24:06 +0100 Subject: [PATCH 7/9] remove logs file --- ...rn JavaScriptsolutionindex.js\357\200\242" | 233 ------------------ .../solution/index.js | 3 +- 2 files changed, 1 insertion(+), 235 deletions(-) delete mode 100644 "ersabdnoOneDriveDocumentsVS codeProjectsJS-projectIT-25-26webLearning-Season03-backendchallengesode.js & Modern JavaScriptsolutionindex.js\357\200\242" diff --git "a/ersabdnoOneDriveDocumentsVS codeProjectsJS-projectIT-25-26webLearning-Season03-backendchallengesode.js & Modern JavaScriptsolutionindex.js\357\200\242" "b/ersabdnoOneDriveDocumentsVS codeProjectsJS-projectIT-25-26webLearning-Season03-backendchallengesode.js & Modern JavaScriptsolutionindex.js\357\200\242" deleted file mode 100644 index bbb20aa..0000000 --- "a/ersabdnoOneDriveDocumentsVS codeProjectsJS-projectIT-25-26webLearning-Season03-backendchallengesode.js & Modern JavaScriptsolutionindex.js\357\200\242" +++ /dev/null @@ -1,233 +0,0 @@ -commit e0f1e9819a98704610fda1f7ce74698c7c1ca749 (HEAD -> web/AbdenourDio/backend-weather-app) -Author: Abdenour Dio -Date: Sun Feb 22 14:53:45 2026 +0100 - - feat:fetch weather data from openweather API - -commit b5b1ec3d306d391918b60d6844ea21c253fffa10 (origin/web) -Author: anouar mellouk -Date: Sat Feb 21 00:43:21 2026 +0100 - - add README file for back challenge - -commit ff0b9a488e425135cb051096db3a5f7a92d79923 -Author: anouar mellouk -Date: Sat Feb 21 00:31:44 2026 +0100 - - update README file for frontend session - -commit b41b7b288d1defcd397f110802a3959a642a26a2 -Author: anouar mellouk -Date: Sat Feb 21 00:20:21 2026 +0100 - - update README file ( frontend challenge 01) - -commit ad6481d4115a711198de73f916e5fe30addf1a0a -Author: anouar mellouk -Date: Sat Feb 21 00:17:32 2026 +0100 - - add frontend challenge 01 - -commit 67b3762bed2d513712df6dca239bfaa155be10ea -Author: anouar mellouk -Date: Sat Feb 21 00:04:11 2026 +0100 - - add lesson 01 - -commit dcd91a2bde10bd437a4499afe91d9dd799a490a8 -Author: anouar mellouk -Date: Tue Feb 10 20:23:39 2026 +0100 - - update CHALLENES.md - -commit 756d2acf614820d1ebdbdb835ec84938d479b16c -Author: anouar mellouk -Date: Tue Feb 10 20:19:24 2026 +0100 - - update README.mdfor challenge 01 - -commit cf29249d93dcf7c2b6c56ce74bb08e08144ba966 -Author: anouar mellouk -Date: Tue Feb 10 20:15:45 2026 +0100 - - update CONTRIBUTING.md - -commit d3b9abc2881f249b86531b6b6abf2bac8d23e886 -Author: anouar mellouk -Date: Tue Feb 10 15:42:55 2026 +0100 - - update README.md for challenge-01 - -commit ef05ef97ceff16b073610c938508e48137e646d9 -Author: anouar mellouk -Date: Tue Feb 10 15:14:51 2026 +0100 - - update SESSIONS.md - -commit c26358abe547b72722572fff3887fffcb7880f98 -Author: anouar mellouk -Date: Tue Feb 10 15:08:30 2026 +0100 - - update SESSIONS.md - -commit 4fd5fd843b920958c197e545ed424e6ca1eade1c -Author: anouar mellouk -Date: Tue Feb 10 15:07:20 2026 +0100 - - update SESSIONS.md - -commit 5022c571c7a1121e1afcb539d63836ee295fd27a -Author: anouar mellouk -Date: Tue Feb 10 15:06:16 2026 +0100 - - update SESSIONS.md - -commit 4759e3ec1ad9dfaac9e4a5a599c97d99daeed590 -Author: anouar mellouk -Date: Tue Feb 10 15:03:23 2026 +0100 - - update SESSIONS.md - -commit 9c7c92858a5b9095590ed7ddeac5b8a3efbb2de0 -Author: anouar mellouk -Date: Tue Feb 10 14:50:49 2026 +0100 - - setup project structure and add README documentation - -commit 480aef843b0ff8a00ff996f556244f005e553c1f -Author: AnouarMellouk-Engineer -Date: Thu Feb 5 21:13:14 2026 +0100 - - Update css.md - -commit 23ab7502b686ae38cb970f54013d1a508d9f713c -Author: AnouarMellouk-Engineer -Date: Thu Feb 5 21:11:42 2026 +0100 - - Update html.md - -commit c2f7c51205a88ca9fc76a67abb4914fca51bdc56 -Author: AnouarMellouk-Engineer -Date: Thu Feb 5 21:06:44 2026 +0100 - - Update html.md - -commit f868cbcfadf7c8aa3c9c3dd9eca968e1ba65462a -Author: anouar mellouk -Date: Thu Feb 5 20:59:59 2026 +0100 - - Add HTML and CSS fundamentals README - -commit 4742d374974e8e6893c9a6c27a541a42b0001e97 -Author: AnouarMellouk-Engineer -Date: Thu Feb 5 19:25:51 2026 +0100 - - Update README.md - -commit ea8d3319dd1eadf30a08796e85aec10d5a5e5cec -Author: anouar mellouk -Date: Thu Feb 5 19:21:51 2026 +0100 - - Add JavaScript basics lessons and README - -commit a5b47b2c4c2f08ffc91266a0640c27266524e7d5 (origin/main, origin/HEAD, main) -Merge: c2925fc 6a80b10 -Author: DerricheRania <159639527+DerricheRania@users.noreply.github.com> -Date: Sun Feb 1 22:51:41 2026 +0100 - - Merge pull request #2 from MicroClub-USTHB/DerricheRania-patch-1-1 - - Add files via upload - -commit 6a80b10b55ca29d74cc16192e2e4e0f0e29f4bce -Author: DerricheRania <159639527+DerricheRania@users.noreply.github.com> -Date: Sun Feb 1 22:51:23 2026 +0100 - - Add files via upload - -commit c2925fcce5d4d80605546a8c31d4a9a0296b99b9 -Author: DerricheRania <159639527+DerricheRania@users.noreply.github.com> -Date: Sun Feb 1 22:49:02 2026 +0100 - - Delete ai/AI Learning Season/Learning Season Track 1/Workshop1-Python Fundamentals (for AI) directory - -commit 34872098092a3f973d2afa4d683e560369446566 -Author: DerricheRania <159639527+DerricheRania@users.noreply.github.com> -Date: Sun Feb 1 22:48:34 2026 +0100 - - Add files via upload - -commit c52cf17c35c48c5ac525e64d2f465645da548510 -Author: DerricheRania <159639527+DerricheRania@users.noreply.github.com> -Date: Sun Feb 1 22:46:45 2026 +0100 - - Delete ai/AI Learning Season/Learning Season Track 1/Workshop1-Python Fundamentals (for AI) directory - -commit 85bf6eaa69a4c28810474b54a65d4eca67a0a797 -Merge: c56895b 7c2bab0 -Author: DerricheRania <159639527+DerricheRania@users.noreply.github.com> -Date: Sun Feb 1 22:45:48 2026 +0100 - - Merge pull request #1 from MicroClub-USTHB/DerricheRania-patch-1 - - Add files via upload - -commit 7c2bab07720eb10cb8d38a80e70c920efe45842d -Author: DerricheRania <159639527+DerricheRania@users.noreply.github.com> -Date: Sun Feb 1 22:45:21 2026 +0100 - - Add files via upload - -commit c56895b50b27e99f0318c2dfb583ea5f1b7b27e7 -Author: Adel HB -Date: Fri Jan 30 12:06:15 2026 +0100 - - Updated global README.md file - -commit 694bdca9f1827b20e2b4650b053273980e5a2156 -Author: Adel HB -Date: Fri Jan 30 11:59:08 2026 +0100 - - Better Build IT README.md file - -commit 5c6f226dcd2d9d63dc378aa61f3d32a7e3ba8ec1 -Author: Adel HB -Date: Fri Jan 30 11:31:28 2026 +0100 - - Added all Build IT repositories as submodules - -commit 99ae781d3ce9b960fec394526900165d487a156d -Author: Adel HB -Date: Thu Jan 29 22:14:23 2026 +0100 - - Added Build IT overview markdown file - -commit ade86cce318c573935c5000d18948c6d79825c58 -Author: DerricheRania <159639527+DerricheRania@users.noreply.github.com> -Date: Tue Dec 30 19:42:30 2025 +0100 - - Add files via upload - -commit b0d1041083919b58bda74a1ae309ac4b902a04fd -Author: DerricheRania <159639527+DerricheRania@users.noreply.github.com> -Date: Tue Dec 30 19:41:00 2025 +0100 - - Add files via upload - -commit 089b742dc255c3878cb4fb1fa94465b23e094286 -Author: DerricheRania <159639527+DerricheRania@users.noreply.github.com> -Date: Tue Dec 30 19:04:14 2025 +0100 - - Add files via upload - -commit e6a5fa7c6582d9a98707b27926a16b52c72c067a -Author: Adel HB -Date: Mon Dec 8 23:29:57 2025 +0100 - - Added main repository folders - -commit 2e4fc7e3e4240b429e8ce4b3b4ce26a026d6340a -Author: HADJ ARAB Adel <51239656+Adel2411@users.noreply.github.com> -Date: Mon Dec 8 22:43:56 2025 +0100 - - Initial commit diff --git a/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js b/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js index 52bb437..b309a84 100644 --- a/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js +++ b/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js @@ -53,8 +53,7 @@ async function getWeather() { } console.log(weather_status) }catch (error){ - console.error("Something went wrong: ", error.message) - + console.error("Something went wrong: ", error.message) } } From 6acd5e68b1da0d4fbe674c26635a9c86cc8651f2 Mon Sep 17 00:00:00 2001 From: Abdenour Dio Date: Tue, 24 Feb 2026 14:53:34 +0100 Subject: [PATCH 8/9] docs: add README file and documante the project --- .../solution/README.md | 47 +++++++++++++++++++ .../solution/index.js | 2 +- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/README.md diff --git a/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/README.md b/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/README.md new file mode 100644 index 0000000..4694248 --- /dev/null +++ b/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/README.md @@ -0,0 +1,47 @@ +# Weather CLI + +A simple command-line tool that fetches real-time weather data for any city using the OpenWeatherMap API. + +## What it does + +You enter a city name, and it returns the current weather status including temperature, humidity, weather condition, and country. + +## Setup + +**1. Clone the repo and install dependencies** +```bash +npm install +``` + +> This project uses `prompt-sync`for user input and `dotenv` for environment variables. + +**2. Get an API key** + +Create a free account at [openweathermap.org](https://openweathermap.org/api) and grab your API key. + +**3. put you api key in `.env` file** +``` +API_KEY=your_api_key_here +``` + +**4. Run the app** +```bash +node index.js +``` + +## Example + +``` +enter a city name to get its weather status: Algiers +{ + country: 'DZ', + city: 'Algiers', + weather: 'Clear', + temp: '18°C', + humidity: '72%' +} +``` + +## Notes + +- Handles API errors (invalid key, city not found, server issues). \ No newline at end of file diff --git a/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js b/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js index b309a84..8278866 100644 --- a/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js +++ b/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/index.js @@ -40,7 +40,7 @@ async function getWeather() { throw new Error(`Unexpected error: ${response.status}`) } const country = data['sys']['country'] - city_name = data['name'] //updated city_name variable + city_name = data.name //ktacheft bli t9der dir . fi plaset [''] const weather = data['weather'][0]['main'] const temp = data['main']['temp'] const humidity = data['main']['humidity'] From 8e1aa83b816eca1d38f01fc05c0292b4cd17f205 Mon Sep 17 00:00:00 2001 From: Abdenour Dio Date: Tue, 24 Feb 2026 14:57:20 +0100 Subject: [PATCH 9/9] docs: update env part --- .../challenges/ode.js & Modern JavaScript/solution/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/README.md b/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/README.md index 4694248..ee39919 100644 --- a/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/README.md +++ b/web/Learning-Season/03-backend/challenges/ode.js & Modern JavaScript/solution/README.md @@ -19,7 +19,7 @@ npm install Create a free account at [openweathermap.org](https://openweathermap.org/api) and grab your API key. -**3. put you api key in `.env` file** +**3. Create `.env` file and put you api key** ``` API_KEY=your_api_key_here ```