diff --git a/task-1/leap-year.js b/task-1/leap-year.js index e05d215..2f4b777 100644 --- a/task-1/leap-year.js +++ b/task-1/leap-year.js @@ -7,3 +7,23 @@ 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 UserInput = prompt('Enter an year: '); + +let year = Number(UserInput); + + +if(year<1 || year >9999 || isNaN(year)){ + console.log('Invalid Year');} + + else if(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'); +} + + diff --git a/task-2/login.js b/task-2/login.js index ca9ba92..975b923 100644 --- a/task-2/login.js +++ b/task-2/login.js @@ -4,9 +4,48 @@ 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} + ]; + if (incorrectAttempts >= 4){ + 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; + } + + + 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"); + } + } + } // 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" +} diff --git a/task-3/converter.js b/task-3/converter.js index 0f54a18..8019acc 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: "); 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) { console.log("Please enter a valid positive number for the amount."); } else { const usdAmount = eurAmountNum * EUR_USD_RATE; @@ -29,9 +30,13 @@ 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 { +} +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."); }