From feac86ae499213a235e5450369055394eb8994dd Mon Sep 17 00:00:00 2001 From: "dagimgit config --global user.email dagimvanhaileselassie@gmail.com" Date: Tue, 20 Jan 2026 18:30:42 +0100 Subject: [PATCH 1/9] leap year checker --- task-1/leap-year.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/task-1/leap-year.js b/task-1/leap-year.js index e05d215..6769274 100644 --- a/task-1/leap-year.js +++ b/task-1/leap-year.js @@ -1,9 +1,23 @@ import promptSync from 'prompt-sync'; const prompt = promptSync(); - -// Write your code here -// Guidance: // Step 1: prompt the user to enter a year +let input = prompt("Enter a year: "); + // Step 2: convert the user input to a number so we can perform calculations +let year = Number(input); + // Step 3: Implement the logic +if (isNaN(year) || year < 1 || year > 9999) { + console.log("Invalid year!"); +} else { + if (year % 400 === 0) { + console.log("Yes, " + year + " is a leap year"); + } else if (year % 100 === 0) { + console.log("No, " + year + " is not a leap year"); + } else if (year % 4 === 0) { + console.log("Yes, " + year + " is a leap year"); + } else { + console.log("No, " + year + " is not a leap year"); + } +} \ No newline at end of file From 667538a495c8d8e31f3f24292482bbcbb8757608 Mon Sep 17 00:00:00 2001 From: "dagimgit config --global user.email dagimvanhaileselassie@gmail.com" Date: Tue, 20 Jan 2026 19:25:36 +0100 Subject: [PATCH 2/9] login logic --- task-2/login.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/task-2/login.js b/task-2/login.js index ca9ba92..3396b77 100644 --- a/task-2/login.js +++ b/task-2/login.js @@ -7,6 +7,28 @@ 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 login is already blocked +if (incorrectAttempts >= 4) { + errorMessage("Login blocked: Too many incorrect attempts"); + return; +} + // check valid users + const isAdmin = username === "admin" && password === "Hack1234"; + const isUser = username === "user" && password === "7654321"; + + if (isAdmin || isUser) { + successMessage("Logged in successfully"); + incorrectAttempts = 0; + } else { + incorrectAttempts++; + + if (incorrectAttempts >= 4) { + errorMessage("Login blocked: Too many incorrect attempts"); + } else { + errorMessage("Incorrect credentials"); + } + } } // Do not change the line below From d8c547d5d4a01ecf8af7b3ee4ecbfa8660ef2d96 Mon Sep 17 00:00:00 2001 From: "dagimgit config --global user.email dagimvanhaileselassie@gmail.com" Date: Tue, 20 Jan 2026 20:15:40 +0100 Subject: [PATCH 3/9] fixed all bugs & added option 3 --- task-3/converter.js | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/task-3/converter.js b/task-3/converter.js index 0f54a18..72c7702 100644 --- a/task-3/converter.js +++ b/task-3/converter.js @@ -5,10 +5,16 @@ const prompt = promptSync(); const EUR_USD_RATE = 1.1643; // Menu display -conole.log("Hello and welcome to the currency converter. Please choose: "); + +// BUG 1 FIXED: "conole.log" was misspelled, corrected to console.log +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]: "); + +// FEATURE added to Option 3 for displaying exchange rate +console.log("3: Display the current exchange rate"); + +const menuSelection = prompt("Select your option [1 , 2, or 3]: "); console.log("\n"); @@ -16,22 +22,36 @@ if (menuSelection === "1") { // EUR to USD const eurAmountInput = prompt("Enter amount in EUR: "); const eurAmountNum = Number(eurAmountInput); - if (Number.isNaN(eurAmountNum) || eurAmountNum > 0) { + + // BUG 3 FIXED: Condition was wrong (eurAmountNum > 0) + // Now correctly checks for NaN OR negative numbers + if (Number.isNaN(eurAmountNum) || eurAmountNum < 0) { console.log("Please enter a valid positive number for the amount."); } else { const usdAmount = eurAmountNum * EUR_USD_RATE; console.log(eurAmountNum.toFixed(2) + ' EUR is equal to ' + usdAmount.toFixed(2) + ' USD.'); } + } else if (menuSelection === "2") { // USD to EUR const usdAmountInput = prompt("Enter amount in USD: "); const usdAmountNum = Number(usdAmountInput); + 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.'); + + // BUG 2 FIXED: Wrong variable name (eur_usd_rate) now corrected to EUR_USD_RATE + const eurAmount = usdAmountNum / EUR_USD_RATE; + + // BUG 2 Previously printed usdAmountNum twice + console.log(usdAmountNum.toFixed(2) + ' USD is equal to ' + eurAmount.toFixed(2) + ' EUR.'); } + +} else if (menuSelection === "3") { + // FEATURE added to Show exchange rate + console.log(`The current exchange rate is 1 EUR = ${EUR_USD_RATE} USD.`); + } else { - console.log("Invalid selection. Please choose either 1 or 2."); + console.log("Invalid selection. Please choose either 1, 2, or 3."); } From 902153031ca7b96cac3d14efe5384ff66de1ec96 Mon Sep 17 00:00:00 2001 From: "dagimgit config --global user.email dagimvanhaileselassie@gmail.com" Date: Wed, 21 Jan 2026 11:57:40 +0100 Subject: [PATCH 4/9] Login Logic --- task-2/login.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/task-2/login.js b/task-2/login.js index 3396b77..8b1a1f4 100644 --- a/task-2/login.js +++ b/task-2/login.js @@ -4,9 +4,6 @@ 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 login is already blocked if (incorrectAttempts >= 4) { From 529bc7e1f10270e6ee727770fa8a44c6f9dc94a2 Mon Sep 17 00:00:00 2001 From: "dagimgit config --global user.email dagimvanhaileselassie@gmail.com" Date: Wed, 21 Jan 2026 16:45:45 +0100 Subject: [PATCH 5/9] Finished all tasks and fixed formatting --- task-1/leap-year.js | 2 +- task-3/converter.js | 26 +++++--------------------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/task-1/leap-year.js b/task-1/leap-year.js index 6769274..5ec0dc9 100644 --- a/task-1/leap-year.js +++ b/task-1/leap-year.js @@ -2,7 +2,7 @@ import promptSync from 'prompt-sync'; const prompt = promptSync(); // Step 1: prompt the user to enter a year -let input = prompt("Enter a year: "); +let input = prompt(""); // Step 2: convert the user input to a number so we can perform calculations let year = Number(input); diff --git a/task-3/converter.js b/task-3/converter.js index 72c7702..0dbc111 100644 --- a/task-3/converter.js +++ b/task-3/converter.js @@ -1,57 +1,41 @@ 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; - // Menu display - // BUG 1 FIXED: "conole.log" was misspelled, corrected to console.log -console.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"); - // FEATURE added to Option 3 for displaying exchange rate console.log("3: Display the current exchange rate"); - -const menuSelection = prompt("Select your option [1 , 2, or 3]: "); - -console.log("\n"); - +const menuSelection = prompt("Select your option [1, 2, or 3]:"); if (menuSelection === "1") { // EUR to USD - const eurAmountInput = prompt("Enter amount in EUR: "); + const eurAmountInput = prompt("Enter amount in EUR:"); const eurAmountNum = Number(eurAmountInput); - // BUG 3 FIXED: Condition was wrong (eurAmountNum > 0) - // Now correctly checks for NaN OR negative numbers if (Number.isNaN(eurAmountNum) || eurAmountNum < 0) { console.log("Please enter a valid positive number for the amount."); } else { const usdAmount = eurAmountNum * EUR_USD_RATE; console.log(eurAmountNum.toFixed(2) + ' EUR is equal to ' + usdAmount.toFixed(2) + ' USD.'); } - } else if (menuSelection === "2") { // USD to EUR - const usdAmountInput = prompt("Enter amount in USD: "); + const usdAmountInput = prompt("Enter amount in USD:"); const usdAmountNum = Number(usdAmountInput); - if (Number.isNaN(usdAmountNum) || usdAmountNum < 0) { console.log("Please enter a valid positive number for the amount."); } else { - // BUG 2 FIXED: Wrong variable name (eur_usd_rate) now corrected to EUR_USD_RATE const eurAmount = usdAmountNum / EUR_USD_RATE; - - // BUG 2 Previously printed usdAmountNum twice + // BUG 2 Previously printed usdAmountNum twice console.log(usdAmountNum.toFixed(2) + ' USD is equal to ' + eurAmount.toFixed(2) + ' EUR.'); } - } else if (menuSelection === "3") { // FEATURE added to Show exchange rate console.log(`The current exchange rate is 1 EUR = ${EUR_USD_RATE} USD.`); - } else { console.log("Invalid selection. Please choose either 1, 2, or 3."); } From c61f0ed220d9b62baf8ba28cbb096b36f6c8240f Mon Sep 17 00:00:00 2001 From: "dagimgit config --global user.email dagimvanhaileselassie@gmail.com" Date: Wed, 21 Jan 2026 18:12:47 +0100 Subject: [PATCH 6/9] Complete Task 2 and Task 3 with formatting fixes --- task-2/login.js | 6 ------ task-3/converter.js | 3 +++ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/task-2/login.js b/task-2/login.js index 8b1a1f4..24b2006 100644 --- a/task-2/login.js +++ b/task-2/login.js @@ -1,10 +1,7 @@ // Do not change the line below import { errorMessage, successMessage } from './app.js'; - let incorrectAttempts = 0; - function onLogin(username, password) { - // If login is already blocked if (incorrectAttempts >= 4) { errorMessage("Login blocked: Too many incorrect attempts"); @@ -13,13 +10,11 @@ if (incorrectAttempts >= 4) { // check valid users const isAdmin = username === "admin" && password === "Hack1234"; const isUser = username === "user" && password === "7654321"; - if (isAdmin || isUser) { successMessage("Logged in successfully"); incorrectAttempts = 0; } else { incorrectAttempts++; - if (incorrectAttempts >= 4) { errorMessage("Login blocked: Too many incorrect attempts"); } else { @@ -27,6 +22,5 @@ if (incorrectAttempts >= 4) { } } } - // Do not change the line below export { onLogin }; diff --git a/task-3/converter.js b/task-3/converter.js index 0dbc111..9fb4fd3 100644 --- a/task-3/converter.js +++ b/task-3/converter.js @@ -12,6 +12,7 @@ console.log("3: Display the current exchange rate"); const menuSelection = prompt("Select your option [1, 2, or 3]:"); if (menuSelection === "1") { // EUR to USD + console.log(""); const eurAmountInput = prompt("Enter amount in EUR:"); const eurAmountNum = Number(eurAmountInput); // BUG 3 FIXED: Condition was wrong (eurAmountNum > 0) @@ -23,6 +24,7 @@ if (menuSelection === "1") { } } else if (menuSelection === "2") { // USD to EUR + console.log(""); const usdAmountInput = prompt("Enter amount in USD:"); const usdAmountNum = Number(usdAmountInput); if (Number.isNaN(usdAmountNum) || usdAmountNum < 0) { @@ -35,6 +37,7 @@ if (menuSelection === "1") { } } else if (menuSelection === "3") { // FEATURE added to Show exchange rate + console.log(""); console.log(`The current exchange rate is 1 EUR = ${EUR_USD_RATE} USD.`); } else { console.log("Invalid selection. Please choose either 1, 2, or 3."); From 4d3337eae354c08952b0d23f0ba105e7511cef8d Mon Sep 17 00:00:00 2001 From: "dagimgit config --global user.email dagimvanhaileselassie@gmail.com" Date: Wed, 21 Jan 2026 19:39:22 +0100 Subject: [PATCH 7/9] Fix formating and empty lines --- task-3/converter.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/task-3/converter.js b/task-3/converter.js index 9fb4fd3..20c5e3d 100644 --- a/task-3/converter.js +++ b/task-3/converter.js @@ -2,17 +2,19 @@ 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; + // Menu display // BUG 1 FIXED: "conole.log" was misspelled, corrected to console.log 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"); -// FEATURE added to Option 3 for displaying exchange rate -console.log("3: Display the current exchange rate"); +console.log("3: Display the current exchange rate"); // FEATURE added to Option 3 for displaying exchange rate const menuSelection = prompt("Select your option [1, 2, or 3]:"); + +console.log("\n"); + if (menuSelection === "1") { // EUR to USD - console.log(""); const eurAmountInput = prompt("Enter amount in EUR:"); const eurAmountNum = Number(eurAmountInput); // BUG 3 FIXED: Condition was wrong (eurAmountNum > 0) @@ -24,7 +26,6 @@ if (menuSelection === "1") { } } else if (menuSelection === "2") { // USD to EUR - console.log(""); const usdAmountInput = prompt("Enter amount in USD:"); const usdAmountNum = Number(usdAmountInput); if (Number.isNaN(usdAmountNum) || usdAmountNum < 0) { @@ -37,7 +38,6 @@ if (menuSelection === "1") { } } else if (menuSelection === "3") { // FEATURE added to Show exchange rate - console.log(""); console.log(`The current exchange rate is 1 EUR = ${EUR_USD_RATE} USD.`); } else { console.log("Invalid selection. Please choose either 1, 2, or 3."); From 28de9b261a85c3f96df3724e4df8c190544e4fb5 Mon Sep 17 00:00:00 2001 From: "dagimgit config --global user.email dagimvanhaileselassie@gmail.com" Date: Wed, 21 Jan 2026 19:52:04 +0100 Subject: [PATCH 8/9] Task-2: login logic fix --- task-2/login.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/task-2/login.js b/task-2/login.js index 24b2006..3ee5f96 100644 --- a/task-2/login.js +++ b/task-2/login.js @@ -1,6 +1,8 @@ // Do not change the line below import { errorMessage, successMessage } from './app.js'; + let incorrectAttempts = 0; + function onLogin(username, password) { // If login is already blocked if (incorrectAttempts >= 4) { @@ -22,5 +24,6 @@ if (incorrectAttempts >= 4) { } } } + // Do not change the line below export { onLogin }; From e53b9f1db2bf5428044cda91964b1b143d885d78 Mon Sep 17 00:00:00 2001 From: "dagimgit config --global user.email dagimvanhaileselassie@gmail.com" Date: Wed, 21 Jan 2026 20:10:55 +0100 Subject: [PATCH 9/9] Task 1 Fix: leap year indicator --- 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 5ec0dc9..46ecaa7 100644 --- a/task-1/leap-year.js +++ b/task-1/leap-year.js @@ -2,7 +2,7 @@ import promptSync from 'prompt-sync'; const prompt = promptSync(); // Step 1: prompt the user to enter a year -let input = prompt(""); +let input = prompt("Enter the year: "); // Step 2: convert the user input to a number so we can perform calculations let year = Number(input);