From d7f08e6b371bd3a9ebb3f463b8a1a4f483db2990 Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 21 Jan 2026 00:16:23 +0100 Subject: [PATCH 01/12] working so far --- task-1/leap-year.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/task-1/leap-year.js b/task-1/leap-year.js index e05d215..3845342 100644 --- a/task-1/leap-year.js +++ b/task-1/leap-year.js @@ -7,3 +7,11 @@ const prompt = promptSync(); // 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 an year: '); + +if (year % 4 == 0){ + console.log('Yes, '+year + ' is a leap year'); + } + else if(year % 100 == 0){ + console.log('No, '+year+' is not a leap year'); +} From 25a8bf20d4e077e1dcf78ee615a96075942d0006 Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 21 Jan 2026 01:34:48 +0100 Subject: [PATCH 02/12] checks validity of year --- task-1/leap-year.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/task-1/leap-year.js b/task-1/leap-year.js index 3845342..a648c9c 100644 --- a/task-1/leap-year.js +++ b/task-1/leap-year.js @@ -7,11 +7,16 @@ const prompt = promptSync(); // 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 an year: '); +let UserInput = prompt('Enter an year: '); -if (year % 4 == 0){ - console.log('Yes, '+year + ' is a leap year'); - } - else if(year % 100 == 0){ - console.log('No, '+year+' is not a leap year'); +let year = Number(UserInput); + + +if(year>1 && year >9999 || isNaN(year)){ + console.log('Invalid Year'); +} +else if(year % 4 === 0){ + console.log('Yes,' +year+' is a leap year'); } + + From 0ab9c5d1523f6b7a6fffcd3be2b4ceb0f337bed0 Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 21 Jan 2026 10:52:41 +0100 Subject: [PATCH 03/12] added 2 valid users --- task-2/login.js | 6 ++++++ task-2/package-lock.json | 42 ++++++++++++++++++++++++++++++++++++++++ task-2/package.json | 6 ++++++ 3 files changed, 54 insertions(+) create mode 100644 task-2/package-lock.json create mode 100644 task-2/package.json diff --git a/task-2/login.js b/task-2/login.js index ca9ba92..ce4c317 100644 --- a/task-2/login.js +++ b/task-2/login.js @@ -4,9 +4,15 @@ 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 + + const validUsers =[ + {username : 'admin', password : 'Hack1234'}, + {username : 'user', password : 7654321} + ]; } // Do not change the line below diff --git a/task-2/package-lock.json b/task-2/package-lock.json new file mode 100644 index 0000000..862d2d4 --- /dev/null +++ b/task-2/package-lock.json @@ -0,0 +1,42 @@ +{ + "name": "task-2", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "prompt-sync": "^4.2.0" + } + }, + "node_modules/ansi-regex": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz", + "integrity": "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/prompt-sync": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/prompt-sync/-/prompt-sync-4.2.0.tgz", + "integrity": "sha512-BuEzzc5zptP5LsgV5MZETjDaKSWfchl5U9Luiu8SKp7iZWD5tZalOxvNcZRwv+d2phNFr8xlbxmFNcRKfJOzJw==", + "license": "MIT", + "dependencies": { + "strip-ansi": "^5.0.0" + } + }, + "node_modules/strip-ansi": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "license": "MIT", + "dependencies": { + "ansi-regex": "^4.1.0" + }, + "engines": { + "node": ">=6" + } + } + } +} diff --git a/task-2/package.json b/task-2/package.json new file mode 100644 index 0000000..fd51f7d --- /dev/null +++ b/task-2/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "prompt-sync": "^4.2.0" + }, + "type": "module" +} From a1a2ff718802cd1ece18a498c5c0783d34dbddd7 Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 21 Jan 2026 11:04:48 +0100 Subject: [PATCH 04/12] checks number of attempts to login --- task-2/login.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/task-2/login.js b/task-2/login.js index ce4c317..abac2d9 100644 --- a/task-2/login.js +++ b/task-2/login.js @@ -13,6 +13,11 @@ function onLogin(username, password) { {username : 'admin', password : 'Hack1234'}, {username : 'user', password : 7654321} ]; + if (incorrectAttempts >= 4){ + errorMessage('Login blocked: Too many incorrect attempts'); + return; + } + } // Do not change the line below From 8156ae2b83b80d1b3761db8279bceafc2bbf449c Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 21 Jan 2026 11:18:03 +0100 Subject: [PATCH 05/12] checks users if correct --- task-2/login.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/task-2/login.js b/task-2/login.js index abac2d9..d1d2ce5 100644 --- a/task-2/login.js +++ b/task-2/login.js @@ -17,7 +17,21 @@ function onLogin(username, password) { errorMessage('Login blocked: Too many incorrect attempts'); return; } - + + let foundCorrectUser = false; + + + if (username === validUsers[0].username && password === validUsers[0].password) { + foundCorrectUser = true; + } + + + if (username === validUsers[1].username && password === validUsers[1].password) { + foundCorrectUser = true; + } + + + } // Do not change the line below From ab6b955842eb6b7cf40723e17a42eb22d9d751cf Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 21 Jan 2026 11:22:38 +0100 Subject: [PATCH 06/12] displays messages --- task-2/login.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/task-2/login.js b/task-2/login.js index d1d2ce5..975b923 100644 --- a/task-2/login.js +++ b/task-2/login.js @@ -31,6 +31,20 @@ function onLogin(username, password) { } + if (foundCorrectUser === true) { + incorrectAttempts = 0; + successMessage("Logged in successfully"); + } else { + + incorrectAttempts = incorrectAttempts + 1; + + + if (incorrectAttempts >= 4) { + errorMessage("Login blocked: Too many incorrect attempts"); + } else { + errorMessage("Incorrect credentials"); + } + } } From 88e999498d32009c1f8a7d052a679d388f4e5ab0 Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 21 Jan 2026 11:29:13 +0100 Subject: [PATCH 07/12] first bug fixed --- task-3/converter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/task-3/converter.js b/task-3/converter.js index 0f54a18..cb5a62b 100644 --- a/task-3/converter.js +++ b/task-3/converter.js @@ -5,7 +5,7 @@ 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: "); console.log("1: Convert EUR to USD"); console.log("2: Convert USD to EUR"); const menuSelection = prompt("Select your option [1 or 2]: "); From ea400ed3734e0db637ac1f656618d5c1b85f457d Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 21 Jan 2026 11:33:11 +0100 Subject: [PATCH 08/12] fixed second bug --- task-3/converter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/task-3/converter.js b/task-3/converter.js index cb5a62b..c5d0539 100644 --- a/task-3/converter.js +++ b/task-3/converter.js @@ -16,7 +16,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; From 5321ed8e93003b4387e88c70eb9dbc6f1c599ea2 Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 21 Jan 2026 11:46:55 +0100 Subject: [PATCH 09/12] solved third bug --- task-3/converter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/task-3/converter.js b/task-3/converter.js index c5d0539..7554dec 100644 --- a/task-3/converter.js +++ b/task-3/converter.js @@ -29,7 +29,7 @@ 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; + const eurAmount = usdAmountNum / EUR_USD_RATE; console.log(usdAmountNum.toFixed(2) + ' USD is equal to ' + usdAmountNum.toFixed(2) + ' EUR.'); } } else { From eaf8ba6f3012ba4dc94482dccf359ef56e0d4541 Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 21 Jan 2026 11:52:50 +0100 Subject: [PATCH 10/12] added a thrid option --- task-3/converter.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/task-3/converter.js b/task-3/converter.js index 7554dec..8019acc 100644 --- a/task-3/converter.js +++ b/task-3/converter.js @@ -8,7 +8,8 @@ const EUR_USD_RATE = 1.1643; 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"); @@ -32,6 +33,10 @@ if (menuSelection === "1") { const eurAmount = usdAmountNum / EUR_USD_RATE; console.log(usdAmountNum.toFixed(2) + ' USD is equal to ' + usdAmountNum.toFixed(2) + ' EUR.'); } -} else { +} +else if (menuSelection === "3"){ + console.log("The current exchange rate is 1 EUR = 1.1643 USD."); +} + else { console.log("Invalid selection. Please choose either 1 or 2."); } From b2582f5ed0de598ccea43b395d9a6b09b1afcb28 Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 21 Jan 2026 12:09:53 +0100 Subject: [PATCH 11/12] fixed the every year is invalir error --- task-1/leap-year.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/task-1/leap-year.js b/task-1/leap-year.js index a648c9c..0b39853 100644 --- a/task-1/leap-year.js +++ b/task-1/leap-year.js @@ -12,11 +12,18 @@ let UserInput = prompt('Enter an year: '); let year = Number(UserInput); -if(year>1 && year >9999 || isNaN(year)){ - console.log('Invalid Year'); +if(year<1 || year >9999 || isNaN(year)){ + console.log('Invalid Year');} + else{ + + if(year % 4 === 0){ + console.log('Yes,' +year+' is a leap year'); } -else if(year % 4 === 0){ +else if(year % 100 ===0 || year % 400 === 0){ console.log('Yes,' +year+' is a leap year'); } +else{ + console.log('No,' +year+' is not a leap year'); +} - +} From 74500af99a9215dab815fda25a1fedeb726e9798 Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 21 Jan 2026 12:36:02 +0100 Subject: [PATCH 12/12] fixed the error --- task-1/leap-year.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/task-1/leap-year.js b/task-1/leap-year.js index 0b39853..2f4b777 100644 --- a/task-1/leap-year.js +++ b/task-1/leap-year.js @@ -14,16 +14,16 @@ let year = Number(UserInput); if(year<1 || year >9999 || isNaN(year)){ console.log('Invalid Year');} - else{ - if(year % 4 === 0){ + else if(year % 400 === 0 ){ console.log('Yes,' +year+' is a leap year'); } -else if(year % 100 ===0 || year % 400 === 0){ - console.log('Yes,' +year+' is a leap year'); +else if(year % 100 ===0 || !year % 4 ===0){ + + console.log('no,' +year+' is not a leap year'); } else{ console.log('No,' +year+' is not a leap year'); } -} +