diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..0ba3d9d --- /dev/null +++ b/package-lock.json @@ -0,0 +1,42 @@ +{ + "name": "c55-core-week-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/package.json b/package.json new file mode 100644 index 0000000..fd51f7d --- /dev/null +++ b/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "prompt-sync": "^4.2.0" + }, + "type": "module" +} diff --git a/task-1/leap-year.js b/task-1/leap-year.js index e05d215..f2604e1 100644 --- a/task-1/leap-year.js +++ b/task-1/leap-year.js @@ -7,3 +7,22 @@ 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 + + +const year = Number(prompt('Enter to check the year: ')); + + +if (isNaN(year) || year > 9999 || year < 1) { + 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`); +} + + diff --git a/task-2/login.js b/task-2/login.js index ca9ba92..9e0dcda 100644 --- a/task-2/login.js +++ b/task-2/login.js @@ -4,10 +4,29 @@ 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 ((username === "admin" && password === "Hack1234") || (username === "user" && password === "7654321")) { + successMessage("Logged in successfully"); + } else { + incorrectAttempts++; + + if (incorrectAttempts >= 4) { + errorMessage("Login blocked: Too many incorrect attempts"); + } else { + errorMessage("Incorrect credentials"); + } + } } // Do not change the line below export { onLogin }; + + + + + + + + +// Write your code here. + // Use the variables 'username' and 'password' to access the input values + // Use incorrectAttempts to track the number of failed attempts \ No newline at end of file diff --git a/task-3/converter.js b/task-3/converter.js index 0f54a18..0f6503f 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("1: Convert EUR to USD"); -console.log("2: Convert USD to EUR"); -const menuSelection = prompt("Select your option [1 or 2]: "); +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") +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 { - console.log("Invalid selection. Please choose either 1 or 2."); +} else if (menuSelection === "3"){ + //The current exchange rate + console.log ("The current exchange rate is 1 EUR = 1.1643 USD") +} +else { + console.log("Invalid selection. Please choose either 1, 2 or 3."); }