From 6b3f895766aebeccbc96223b2845fe0bf3a19467 Mon Sep 17 00:00:00 2001 From: Hassan Alkhalaf Date: Tue, 10 Nov 2026 14:27:23 +0100 Subject: [PATCH 1/5] Implemented the leap-year calculation logic. --- task-1/leap-year.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/task-1/leap-year.js b/task-1/leap-year.js index e05d215..558ce49 100644 --- a/task-1/leap-year.js +++ b/task-1/leap-year.js @@ -1,9 +1,17 @@ import promptSync from 'prompt-sync'; const prompt = promptSync(); +let year = Number(prompt("Enter year:")); + +if (year >= 0 && year <= 9999) { + if (year % 400 === 0) { + console.log(`Yes, year ${year} is leap`); + } else if (year % 4 === 0 && year % 100 !== 0) { + console.log(`Yes, year ${year} is leap`); + } else { + console.log(`No, year ${year} is not leap`); + } +} else { + console.log("Invalid year"); +} -// 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 From 34e6dc243a2df9c48ec3147299a40dbcce7da420 Mon Sep 17 00:00:00 2001 From: Hassan Alkhalaf Date: Tue, 10 Nov 2026 14:28:15 +0100 Subject: [PATCH 2/5] Implemented the logic for the login page. --- task-2/login.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/task-2/login.js b/task-2/login.js index ca9ba92..0010725 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) { + if (username === "admin" && password === "Hack1234" || + username === "user" && password === "7654321" + ) { + successMessage("Logged in successfully") + } else { + errorMessage("Incorrect credentials") + incorrectAttempts++ + + + } + } else { + errorMessage("Login blocked: Too many incorrect attempts") + } } -// Do not change the line below -export { onLogin }; + // Do not change the line below + export { onLogin }; From 7fb1a3d9a110d7f2ad53fc814db05d1e8d742687 Mon Sep 17 00:00:00 2001 From: Hassan Alkhalaf Date: Tue, 10 Nov 2026 15:23:05 +0100 Subject: [PATCH 3/5] Fixed the bugs and implemented new feature. --- task-3/converter.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/task-3/converter.js b/task-3/converter.js index 0f54a18..80e6ada 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.118; + // 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: Show current exchange rate.") +const menuSelection = prompt("Select your option [1, 2, or 3]: "); console.log("\n"); @@ -16,7 +18,7 @@ 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; @@ -29,9 +31,11 @@ if (menuSelection === "1") { if (Number.isNaN(usdAmountNum) || usdAmountNum < 0) { 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.'); + const eurAmount = usdAmountNum / EUR_USD_RATE + console.log(usdAmountNum.toFixed(2) + ' USD is equal to ' + eurAmount.toFixed(2) + ' EUR.'); } +} else if (menuSelection === "3") { + console.log("Current exchange rate is:" + EUR_USD_RATE) } else { - console.log("Invalid selection. Please choose either 1 or 2."); + console.log("Invalid selection. Please choose either 1, 2, or 3."); } From 3923ee3197bc5f67cde96c704de702bc143c93da Mon Sep 17 00:00:00 2001 From: Hassan Alkhalaf Date: Thu, 19 Nov 2026 16:50:45 +0100 Subject: [PATCH 4/5] Fix the calculating logic, avoiding integer numbers, and corrected grammar. --- task-1/leap-year.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/task-1/leap-year.js b/task-1/leap-year.js index 558ce49..0c0171d 100644 --- a/task-1/leap-year.js +++ b/task-1/leap-year.js @@ -3,15 +3,13 @@ const prompt = promptSync(); let year = Number(prompt("Enter year:")); -if (year >= 0 && year <= 9999) { - if (year % 400 === 0) { - console.log(`Yes, year ${year} is leap`); - } else if (year % 4 === 0 && year % 100 !== 0) { - console.log(`Yes, year ${year} is leap`); - } else { - console.log(`No, year ${year} is not leap`); - } -} else { +if (!Number.isInteger(year) || year < 1 || year > 9999) { console.log("Invalid year"); +} else if ((year % 400 === 0) || + (year % 4 === 0 && year % 100 !== 0) +) { + console.log(`Yes, the year ${year} is a leap year.`); +} else { + console.log(`No, year ${year} is not a leap year`); } From 856849fffd37bfc8be1a0c02d22e3bc4d9aaff51 Mon Sep 17 00:00:00 2001 From: Hassan Alkhalaf Date: Thu, 19 Nov 2026 16:51:20 +0100 Subject: [PATCH 5/5] Different grouping used for better readability. --- task-2/login.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/task-2/login.js b/task-2/login.js index 0010725..572633d 100644 --- a/task-2/login.js +++ b/task-2/login.js @@ -6,8 +6,8 @@ let incorrectAttempts = 0; function onLogin(username, password) { if (incorrectAttempts < 3) { - if (username === "admin" && password === "Hack1234" || - username === "user" && password === "7654321" + if ((username === "admin" && password === "Hack1234") || + (username === "user" && password === "7654321") ) { successMessage("Logged in successfully") } else { @@ -21,5 +21,5 @@ function onLogin(username, password) { } } - // Do not change the line below - export { onLogin }; +// Do not change the line below +export { onLogin };