From 996b2d429c7cc13e68b68189148b5e8c95d3e774 Mon Sep 17 00:00:00 2001 From: Muna Nasher Date: Tue, 20 Jan 2026 22:25:27 +0100 Subject: [PATCH] Muna Naher ass.week02 --- task-1/leap-year.js | 21 ++++++++++++++++----- task-2/login.js | 20 +++++++++++++++++--- task-3/converter.js | 12 ++++++++---- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/task-1/leap-year.js b/task-1/leap-year.js index e05d215..0e8248c 100644 --- a/task-1/leap-year.js +++ b/task-1/leap-year.js @@ -1,9 +1,20 @@ import promptSync from 'prompt-sync'; const prompt = promptSync(); +let year = prompt("Enter a 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 +// convert the input to number +year = Number(year); + +// check the input vaildation +if (isNaN(year) || year < 1 || year > 9999) { + console.log("Invalid year!"); +} else { + + // leap year + if ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) { + console.log("Yes, " + year + " is a leap year"); + } else { + console.log("No, " + year + " is not a leap year"); + } +} diff --git a/task-2/login.js b/task-2/login.js index ca9ba92..1ccbc26 100644 --- a/task-2/login.js +++ b/task-2/login.js @@ -4,9 +4,23 @@ 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 >= 4) { + errorMessage("Login blocked: Too many incorrect attempts"); + return; + } + + +const isAdmin = username === "admin" && password === "Hack1234"; +const isUser = username === "user" && password === "7654321"; + +if (isAdmin || isUser) { + successMessage("Logged in successfully"); + } else { + incorrectAttempts++; + errorMessage("Incorrect credentials"); + } + } // Do not change the line below diff --git a/task-3/converter.js b/task-3/converter.js index 0f54a18..bbd3ec3 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: "); // Incorrect splleing, Bug1 console.log("1: Convert EUR to USD"); console.log("2: Convert USD to EUR"); const menuSelection = prompt("Select your option [1 or 2]: "); @@ -16,7 +16,8 @@ if (menuSelection === "1") { // EUR to USD const eurAmountInput = prompt("Enter amount in EUR: "); const eurAmountNum = Number(eurAmountInput); - if (Number.isNaN(eurAmountNum) || eurAmountNum > 0) { + // the condition is wrong, eurAmountNum > 0 should be eurAmountNum <=0 ,Bug2 + if (Number.isNaN(eurAmountNum) || eurAmountNum <= 0) { console.log("Please enter a valid positive number for the amount."); } else { const usdAmount = eurAmountNum * EUR_USD_RATE; @@ -25,13 +26,16 @@ if (menuSelection === "1") { } else if (menuSelection === "2") { // USD to EUR const usdAmountInput = prompt("Enter amount in USD: "); - const usdAmountNum = Number(usdAmountInput); + 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; + const eurAmount = usdAmountNum / EUR_USD_RATE; // eur_usd_rate is not defined, it should be EUR_USD_RATE, Bug3 console.log(usdAmountNum.toFixed(2) + ' USD is equal to ' + usdAmountNum.toFixed(2) + ' EUR.'); } } else { console.log("Invalid selection. Please choose either 1 or 2."); } + + +EUR_USD_RATE \ No newline at end of file