-
Notifications
You must be signed in to change notification settings - Fork 19
Yana P #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Yana P #5
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,18 @@ | ||
| import promptSync from 'prompt-sync'; | ||
| import promptSync from "prompt-sync"; | ||
| const prompt = promptSync(); | ||
|
|
||
| const year = Number(prompt("Enter a year to check if it is a leap 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 | ||
| const isLeapYear = year % 400 === 0 || (year % 4 === 0 && year % 100 !== 0); | ||
|
|
||
| if (Number.isNaN(year)) { | ||
| console.log("Please, enter a number"); | ||
| } else if (!Number.isInteger(year)) { | ||
| console.log("Please, enter a whole number (no decimals)"); | ||
| } else if (year < 1 || year > 9999) { | ||
| console.log("Invalid year!"); | ||
| } else if (isLeapYear) { | ||
| console.log(`Yes, ${year} is a leap year`); | ||
| } else { | ||
| console.log(`No, ${year} is not a leap year`); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,27 @@ | ||
| // Do not change the line below | ||
| import { errorMessage, successMessage } from './app.js'; | ||
| 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 isValid = | ||
| (username === "admin" && password === "Hack1234") || | ||
| (username === "user" && password === "7654321"); | ||
|
|
||
| if (incorrectAttempts > 3) { | ||
| errorMessage("Login blocked: Too many incorrect attempts"); | ||
| return; | ||
| } else if (isValid) { | ||
| incorrectAttempts = 0; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, resetting
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the feedback. I added the reset because I was thinking about how a real login system usually works, where a successful login clears previous failed attempts. I understand it wasn’t required in the task, so I’ll keep that in mind for future exercises. |
||
| 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 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice that you used a boolean (
isValid), this makes more readable 👍