Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions task-1/leap-year.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

const year = prompt("Enter a year: ");

const yr = parseInt(year);

const isLeapYear = (y) => {
if (y >= 1 && y <= 9999) {
return (y % 4 === 0 && y % 100 !== 0) || (y % 400 === 0);
}
return null;
};


const result = isLeapYear(yr);
if (result== null) console.log("Invalid year.");
else if (result) {
console.log(`${yr} is a leap year.`);
} else {
console.log(`${yr} is not a leap year.`);
}
24 changes: 24 additions & 0 deletions task-2/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,30 @@ 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
let correctUsername1 = 'admin';
let correctPassword1 = 'Hack1234';
let correctUsername2 = 'user';
let correctPassword2 = '7654321';
let maxAttempts = 3;

if (incorrectAttempts > maxAttempts) {
errorMessage('Login blocked: too many incorrect attempts.');
return;
}
if (
(username === correctUsername1 && password === correctPassword1) ||
(username === correctUsername2 && password === correctPassword2)
) {
successMessage('Logged in successfully!');
incorrectAttempts = 0; // Reset on successful login
} else {
incorrectAttempts++;
if (incorrectAttempts > maxAttempts) {
errorMessage('Login blocked: too many incorrect attempts.');
} else {
errorMessage('Incorrect credentials.');
}
}
}

// Do not change the line below
Expand Down
16 changes: 10 additions & 6 deletions task-3/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@ const prompt = promptSync();

// Exchange rate for EUR/USD (How much 1 EUR is in USD)
const EUR_USD_RATE = 1.1643;
const USD_EUR_RATE = 1 / EUR_USD_RATE;

// 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: View current exchange rate (EUR to USD)");
const menuSelection = prompt("Select your option [1 ,2 ,3 ]: ");

console.log("\n");

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;
Expand All @@ -29,9 +31,11 @@ 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 * USD_EUR_RATE;
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.toFixed(4) + ' USD.');
} else {
console.log("Invalid selection. Please choose either 1 or 2.");
console.log("Invalid selection. Please choose either 1, 2, or 3.");
}
Loading