From 211ce9d704d5bc908dc6cdfc6e3e5345d1ed671c Mon Sep 17 00:00:00 2001 From: Halyna Romanyshyn Date: Wed, 21 Jan 2026 12:00:35 +0100 Subject: [PATCH 01/10] Complete all 3 tasks week 2 --- task-1/leap-year.js | 20 ++++++++++++++------ task-2/app.js | 10 +--------- task-2/login.js | 35 +++++++++++++++++++++++++++++++---- task-3/converter.js | 25 ++++++++++++++++++++----- 4 files changed, 66 insertions(+), 24 deletions(-) diff --git a/task-1/leap-year.js b/task-1/leap-year.js index e05d215..3bf6a17 100644 --- a/task-1/leap-year.js +++ b/task-1/leap-year.js @@ -1,9 +1,17 @@ -import promptSync from 'prompt-sync'; +import promptSync from "prompt-sync"; const prompt = promptSync(); +const input_year = prompt("Enter a year(1-9999): "); +const year = Number(input_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 +if (!Number.isInteger(year) || year < 1 || year > 9999) { + console.log("Invalid year!"); +} else { + const isLeap = year % 400 === 0 || (year % 4 === 0 && year % 100 !== 0); + + if (isLeap) { + console.log("Yes, " + year + " is a leap year"); + } else { + console.log("No, " + year + " is not a leap year"); + } +} diff --git a/task-2/app.js b/task-2/app.js index 8c31bc5..37b5f18 100644 --- a/task-2/app.js +++ b/task-2/app.js @@ -20,14 +20,6 @@ function showMessage(message, type) { modal.classList.remove('hidden'); } -function errorMessage(message) { - showMessage(message, 'error'); -} - -function successMessage(message) { - showMessage(message, 'success'); -} - function hideModal() { const modal = document.getElementById('modal'); modal.classList.add('hidden'); @@ -78,4 +70,4 @@ function setupEventListeners() { setupEventListeners(); -export { errorMessage, successMessage }; +export { showMessage }; diff --git a/task-2/login.js b/task-2/login.js index ca9ba92..5f0361c 100644 --- a/task-2/login.js +++ b/task-2/login.js @@ -1,12 +1,39 @@ // Do not change the line below -import { errorMessage, successMessage } from './app.js'; +import { showMessage } from './app.js'; let incorrectAttempts = 0; +function errorMessage(message) { + showMessage(message, "error"); +} + +function successMessage(message) { + showMessage(message, "success"); +} + 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 >= 4) { + errorMessage("Login blocked: Too many incorrect attempts", "error"); + return; + } + + // 2) check valid credentials + const isValid = + (username === "admin" && password === "Hack1234") || + (username === "user" && password === "7654321"); + + if (isValid) { + successMessage("Logged in successfully"); + } else { + incorrectAttempts += 1; + + // after increment, if now blocked -> show blocked (requirement 3+4) + if (incorrectAttempts >= 4) { + errorMessage("Login blocked: Too many incorrect attempts", "error"); + } else { + errorMessage("Incorrect credentials", "error"); + } + } } // Do not change the line below diff --git a/task-3/converter.js b/task-3/converter.js index 0f54a18..8d4a625 100644 --- a/task-3/converter.js +++ b/task-3/converter.js @@ -5,10 +5,11 @@ const prompt = promptSync(); 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: ");//1 bug 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,7 +17,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) {//2 bug console.log("Please enter a valid positive number for the amount."); } else { const usdAmount = eurAmountNum * EUR_USD_RATE; @@ -29,8 +30,22 @@ 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;//3 bug + console.log(usdAmountNum.toFixed(2) + ' USD is equal to ' + eurAmount.toFixed(2) + ' EUR.'); + }} else if (menuSelection === "3") { + console.log(`The current exchange rate is 1 EUR = ${EUR_USD_RATE} USD.`); + } else if (menuSelection === "1") { + // EUR -> USD + const eurAmountInput = prompt("Enter amount in EUR: "); + const eurAmountNum = Number(eurAmountInput); + + 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 { console.log("Invalid selection. Please choose either 1 or 2."); From 5900a5e85077a426ad2b5e6ddc4f9088e11b6968 Mon Sep 17 00:00:00 2001 From: Halyna Romanyshyn <30292604+halyna1995@users.noreply.github.com> Date: Sat, 24 Jan 2026 18:46:20 +0100 Subject: [PATCH 02/10] Remove functions --- task-2/login.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/task-2/login.js b/task-2/login.js index 5f0361c..09ac441 100644 --- a/task-2/login.js +++ b/task-2/login.js @@ -3,13 +3,6 @@ import { showMessage } from './app.js'; let incorrectAttempts = 0; -function errorMessage(message) { - showMessage(message, "error"); -} - -function successMessage(message) { - showMessage(message, "success"); -} function onLogin(username, password) { if (incorrectAttempts >= 4) { From 0a6fb0060efc7c7b1bfa392c02aff08d66705c20 Mon Sep 17 00:00:00 2001 From: Halyna Romanyshyn <30292604+halyna1995@users.noreply.github.com> Date: Sat, 24 Jan 2026 18:47:26 +0100 Subject: [PATCH 03/10] Add functions --- task-2/app.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/task-2/app.js b/task-2/app.js index 37b5f18..f778266 100644 --- a/task-2/app.js +++ b/task-2/app.js @@ -19,6 +19,13 @@ function showMessage(message, type) { modal.classList.remove('hidden'); } +function errorMessage(message) { + showMessage(message, "error"); +} + +function successMessage(message) { + showMessage(message, "success"); +} function hideModal() { const modal = document.getElementById('modal'); From 98b10fb0e4191c558406e9bdb283a5bc46bbcfa6 Mon Sep 17 00:00:00 2001 From: Halyna Romanyshyn <30292604+halyna1995@users.noreply.github.com> Date: Sat, 24 Jan 2026 18:51:20 +0100 Subject: [PATCH 04/10] Add variable after logged in successfully Reset incorrect attempts on successful login. --- task-2/login.js | 1 + 1 file changed, 1 insertion(+) diff --git a/task-2/login.js b/task-2/login.js index 09ac441..699ef71 100644 --- a/task-2/login.js +++ b/task-2/login.js @@ -17,6 +17,7 @@ function onLogin(username, password) { if (isValid) { successMessage("Logged in successfully"); + incorrectAttempts = 0; } else { incorrectAttempts += 1; From 8fcda77e6f31909954f63452d2eb12e58eeeda76 Mon Sep 17 00:00:00 2001 From: Halyna Romanyshyn <30292604+halyna1995@users.noreply.github.com> Date: Sat, 24 Jan 2026 18:55:52 +0100 Subject: [PATCH 05/10] Update task-2/login.js Co-authored-by: Jim Cramer --- task-2/login.js | 1 + 1 file changed, 1 insertion(+) diff --git a/task-2/login.js b/task-2/login.js index 699ef71..e54fa56 100644 --- a/task-2/login.js +++ b/task-2/login.js @@ -18,6 +18,7 @@ function onLogin(username, password) { if (isValid) { successMessage("Logged in successfully"); incorrectAttempts = 0; + incorrectAttempts = 0; } else { incorrectAttempts += 1; From ba42a23e2fbf4820e648d73cb22138ba638115be Mon Sep 17 00:00:00 2001 From: Halyna Romanyshyn <30292604+halyna1995@users.noreply.github.com> Date: Sat, 24 Jan 2026 22:43:51 +0100 Subject: [PATCH 06/10] Second edit Removed redundant reset of incorrectAttempts. --- task-2/login.js | 1 - 1 file changed, 1 deletion(-) diff --git a/task-2/login.js b/task-2/login.js index e54fa56..699ef71 100644 --- a/task-2/login.js +++ b/task-2/login.js @@ -18,7 +18,6 @@ function onLogin(username, password) { if (isValid) { successMessage("Logged in successfully"); incorrectAttempts = 0; - incorrectAttempts = 0; } else { incorrectAttempts += 1; From a87d1b56ea7b9e7287388ccb4ab824928c62a932 Mon Sep 17 00:00:00 2001 From: Halyna Romanyshyn <30292604+halyna1995@users.noreply.github.com> Date: Sat, 24 Jan 2026 23:00:01 +0100 Subject: [PATCH 07/10] Add success and error message imports in login.js Import success and error message functions from app.js. --- task-2/login.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/task-2/login.js b/task-2/login.js index 699ef71..fcea0c3 100644 --- a/task-2/login.js +++ b/task-2/login.js @@ -1,5 +1,7 @@ // Do not change the line below import { showMessage } from './app.js'; +import { successMessage, errorMessage } from './app.js'; + let incorrectAttempts = 0; From fbbf339d0a7bb1660907fea744e5261b087df6de Mon Sep 17 00:00:00 2001 From: Halyna Romanyshyn <30292604+halyna1995@users.noreply.github.com> Date: Sat, 24 Jan 2026 23:00:57 +0100 Subject: [PATCH 08/10] Export errorMessage and successMessage from app.js --- task-2/app.js | 1 + 1 file changed, 1 insertion(+) diff --git a/task-2/app.js b/task-2/app.js index f778266..fda85ce 100644 --- a/task-2/app.js +++ b/task-2/app.js @@ -78,3 +78,4 @@ function setupEventListeners() { setupEventListeners(); export { showMessage }; +export { errorMessage, successMessage }; From b65742a7da45f69cec0bbdca5bf52c2a37cf5856 Mon Sep 17 00:00:00 2001 From: Halyna Romanyshyn <30292604+halyna1995@users.noreply.github.com> Date: Sat, 24 Jan 2026 23:43:04 +0100 Subject: [PATCH 09/10] Final edit everything work --- task-2/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/task-2/app.js b/task-2/app.js index fda85ce..644aa5e 100644 --- a/task-2/app.js +++ b/task-2/app.js @@ -78,4 +78,4 @@ function setupEventListeners() { setupEventListeners(); export { showMessage }; -export { errorMessage, successMessage }; + From fcf34dffdc63b6f3a9c1a57ec25ec0cfe6bfb685 Mon Sep 17 00:00:00 2001 From: Halyna Romanyshyn <30292604+halyna1995@users.noreply.github.com> Date: Sat, 24 Jan 2026 23:45:22 +0100 Subject: [PATCH 10/10] Replace error and success messages with showMessage everything work final version --- task-2/login.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/task-2/login.js b/task-2/login.js index fcea0c3..63c7559 100644 --- a/task-2/login.js +++ b/task-2/login.js @@ -1,6 +1,6 @@ // Do not change the line below import { showMessage } from './app.js'; -import { successMessage, errorMessage } from './app.js'; + let incorrectAttempts = 0; @@ -8,7 +8,7 @@ let incorrectAttempts = 0; function onLogin(username, password) { if (incorrectAttempts >= 4) { - errorMessage("Login blocked: Too many incorrect attempts", "error"); + showMessage("Login blocked: Too many incorrect attempts", "error"); return; } @@ -18,16 +18,16 @@ function onLogin(username, password) { (username === "user" && password === "7654321"); if (isValid) { - successMessage("Logged in successfully"); + showMessage("Logged in successfully", "success"); incorrectAttempts = 0; } else { incorrectAttempts += 1; // after increment, if now blocked -> show blocked (requirement 3+4) if (incorrectAttempts >= 4) { - errorMessage("Login blocked: Too many incorrect attempts", "error"); + showMessage("Login blocked: Too many incorrect attempts", "error"); } else { - errorMessage("Incorrect credentials", "error"); + showMessage("Incorrect credentials", "error"); } } }