From ca3b7fb56368dfd21e19e3073ecec63c9c587b58 Mon Sep 17 00:00:00 2001 From: mohammedalfakih-dev Date: Wed, 21 Jan 2026 02:59:57 +0100 Subject: [PATCH 1/7] task 1 done --- task-1/leap-year.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/task-1/leap-year.js b/task-1/leap-year.js index e05d215..e75ff6f 100644 --- a/task-1/leap-year.js +++ b/task-1/leap-year.js @@ -4,6 +4,16 @@ const prompt = promptSync(); // Write your code here // Guidance: -// Step 1: prompt the user to enter a year -// Step 2: convert the user input to a number so we can perform calculations -// Step 3: Implement the logic +let year = prompt("Enter a year: "); +year = Number(year); +if (isNaN(year) || year < 1 || year > 9999) { + console.log("Invalid year!"); +} else { + let isLeap = + ((year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0)); + if (isLeap) { + console.log("Yes " + year + " is a leap year."); + } else { + console.log("No " + year + " is not a leap year."); + } +} From 285243ebe68443925343a51f6765dc93e95a01c0 Mon Sep 17 00:00:00 2001 From: mohammedalfakih-dev Date: Wed, 21 Jan 2026 03:33:49 +0100 Subject: [PATCH 2/7] task 2 done --- task-2/login.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/task-2/login.js b/task-2/login.js index ca9ba92..d083f84 100644 --- a/task-2/login.js +++ b/task-2/login.js @@ -4,10 +4,22 @@ import { errorMessage, successMessage } from './app.js'; let incorrectAttempts = 0; function onLogin(username, password) { - // Write your code here. - // Use the variables 'username' and 'password' to access the input values - // Use incorrectAttempts to track the number of failed attempts + if (incorrectAttempts >= 3) { + errorMessage("Login blocked: Too many incorrect attempts."); + } else { + const isAdmin = (username === "admin" && password === "Hack1234"); + const isUser = (username === "user" && password === "7654321"); + + if (isAdmin || isUser) { + successMessage("Logged in successfully!"); + } else { + incorrectAttempts++; + errorMessage("Incorrect credentials."); + if (incorrectAttempts >= 3) { + errorMessage("Login blocked: Too many incorrect attempts."); + } + } + } } -// Do not change the line below export { onLogin }; From 8a9aa27c10aeb43f8dd6dc35775d657cb0251833 Mon Sep 17 00:00:00 2001 From: mohammedalfakih-dev Date: Wed, 21 Jan 2026 03:38:32 +0100 Subject: [PATCH 3/7] fix incorrectAttempts to be > 3 instead of >= 3 --- task-2/login.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/task-2/login.js b/task-2/login.js index d083f84..46f012c 100644 --- a/task-2/login.js +++ b/task-2/login.js @@ -4,7 +4,7 @@ import { errorMessage, successMessage } from './app.js'; let incorrectAttempts = 0; function onLogin(username, password) { - if (incorrectAttempts >= 3) { + if (incorrectAttempts > 3) { errorMessage("Login blocked: Too many incorrect attempts."); } else { const isAdmin = (username === "admin" && password === "Hack1234"); @@ -15,7 +15,7 @@ function onLogin(username, password) { } else { incorrectAttempts++; errorMessage("Incorrect credentials."); - if (incorrectAttempts >= 3) { + if (incorrectAttempts > 3) { errorMessage("Login blocked: Too many incorrect attempts."); } } From 799a4ac05fb15bfd51fdd44f119214c7caf3fa14 Mon Sep 17 00:00:00 2001 From: mohammedalfakih-dev Date: Wed, 21 Jan 2026 03:50:51 +0100 Subject: [PATCH 4/7] Use Number.isNaN for year validation instead of isNaN --- task-1/leap-year.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/task-1/leap-year.js b/task-1/leap-year.js index e75ff6f..daa31bb 100644 --- a/task-1/leap-year.js +++ b/task-1/leap-year.js @@ -6,7 +6,7 @@ const prompt = promptSync(); // Guidance: let year = prompt("Enter a year: "); year = Number(year); -if (isNaN(year) || year < 1 || year > 9999) { +if (Number.isNaN(year) || year < 1 || year > 9999) { console.log("Invalid year!"); } else { let isLeap = From 62c44a7d33557a87389650d5dfe39dc00186ce2b Mon Sep 17 00:00:00 2001 From: mohammedalfakih-dev Date: Wed, 21 Jan 2026 04:34:57 +0100 Subject: [PATCH 5/7] Fixed some bugs and added new feature ( display exhangerate) --- task-3/converter.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/task-3/converter.js b/task-3/converter.js index 0f54a18..ab86c78 100644 --- a/task-3/converter.js +++ b/task-3/converter.js @@ -2,13 +2,15 @@ import promptSync from 'prompt-sync'; const prompt = promptSync(); // Exchange rate for EUR/USD (How much 1 EUR is in USD) -const EUR_USD_RATE = 1.1643; +const eur_usd_rate = 1.1643; // Menu display -conole.log("Hello and welcome to the currency converter. Please choose: "); +console.log("Hello and welcome to the currency converter. Please choose: "); console.log("1: Convert EUR to USD"); console.log("2: Convert USD to EUR"); -const menuSelection = prompt("Select your option [1 or 2]: "); +console.log("3: Display the current exchange rate"); + +const menuSelection = prompt("Select your option [1 , 2 or 3]: "); console.log("\n"); @@ -16,10 +18,10 @@ if (menuSelection === "1") { // EUR to USD const eurAmountInput = prompt("Enter amount in EUR: "); const eurAmountNum = Number(eurAmountInput); - if (Number.isNaN(eurAmountNum) || eurAmountNum > 0) { + if (Number.isNaN(eurAmountNum) || eurAmountNum < 0) { console.log("Please enter a valid positive number for the amount."); } else { - const usdAmount = eurAmountNum * EUR_USD_RATE; + const usdAmount = eurAmountNum * eur_usd_rate; console.log(eurAmountNum.toFixed(2) + ' EUR is equal to ' + usdAmount.toFixed(2) + ' USD.'); } } else if (menuSelection === "2") { @@ -30,8 +32,13 @@ if (menuSelection === "1") { console.log("Please enter a valid positive number for the amount."); } else { const eurAmount = usdAmountNum / eur_usd_rate; - console.log(usdAmountNum.toFixed(2) + ' USD is equal to ' + usdAmountNum.toFixed(2) + ' EUR.'); + console.log(usdAmountNum.toFixed(2) + ' USD is equal to ' + eurAmount.toFixed(2) + ' EUR.'); } -} else { - console.log("Invalid selection. Please choose either 1 or 2."); +} else if (menuSelection === "3") { + // Display exchange rate + console.log("The current exchange rate is 1 EUR = " + eur_usd_rate.toFixed(4) + " USD"); + +} + else { + console.log("Invalid selection. Please choose either 1, 2 or 3."); } From d42f2a534b4c11344c11c5e4419b884c1f039d5c Mon Sep 17 00:00:00 2001 From: mohammedalfakih-dev Date: Sun, 25 Jan 2026 23:30:01 +0100 Subject: [PATCH 6/7] Fix const usage and apply 2spacen --- task-1/leap-year.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/task-1/leap-year.js b/task-1/leap-year.js index daa31bb..c2f1bd3 100644 --- a/task-1/leap-year.js +++ b/task-1/leap-year.js @@ -4,13 +4,15 @@ const prompt = promptSync(); // Write your code here // Guidance: -let year = prompt("Enter a year: "); -year = Number(year); +const input = prompt("Enter a year: "); +const year = Number(input); + if (Number.isNaN(year) || year < 1 || year > 9999) { - console.log("Invalid year!"); + console.log("Invalid year!"); } else { - let isLeap = - ((year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0)); + const isLeap = + ((year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0)); + if (isLeap) { console.log("Yes " + year + " is a leap year."); } else { From 99aedce8969b3788cf606adabff922799098f25c Mon Sep 17 00:00:00 2001 From: mohammedalfakih-dev Date: Sun, 25 Jan 2026 23:33:28 +0100 Subject: [PATCH 7/7] Refactor login logic and remove duplicate checks --- task-2/login.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/task-2/login.js b/task-2/login.js index 46f012c..3e9fc34 100644 --- a/task-2/login.js +++ b/task-2/login.js @@ -4,9 +4,12 @@ import { errorMessage, successMessage } from './app.js'; let incorrectAttempts = 0; function onLogin(username, password) { - if (incorrectAttempts > 3) { + if (incorrectAttempts >= 3) { errorMessage("Login blocked: Too many incorrect attempts."); - } else { + + return; + + } const isAdmin = (username === "admin" && password === "Hack1234"); const isUser = (username === "user" && password === "7654321"); @@ -15,11 +18,9 @@ function onLogin(username, password) { } else { incorrectAttempts++; errorMessage("Incorrect credentials."); - if (incorrectAttempts > 3) { - errorMessage("Login blocked: Too many incorrect attempts."); - } + } } -} + export { onLogin };