Repository navigation
Eskedar #4
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?
Eskedar #4
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,19 @@ | ||
| import promptSync from 'prompt-sync'; | ||
| const prompt = promptSync(); | ||
|
|
||
| let yearInput = Number (prompt ('please enter a year:')); | ||
|
|
||
|
|
||
| if (!Number.isInteger(yearInput) || yearInput < 0){ | ||
| console.log("Invalid year."); | ||
| }else if (yearInput % 400 === 0){ | ||
| console.log("Yes " + yearInput + " is a leap year."); | ||
| } else if (yearInput % 4 !== 0){ | ||
| console.log("No " + yearInput + " is not a leap year."); | ||
| } else if (yearInput % 100 === 0){ | ||
| console.log("No " + yearInput + " is not a leap year."); | ||
| } else { | ||
| console.log("Yes " + yearInput + " 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 | ||
|
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. when using |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,13 +1,24 @@ | ||||||
| // 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 | ||||||
| if (incorrectAttempts >= 4) { | ||||||
| errorMessage('Login Blocked: Too many failed attempts. Please try again later.'); | ||||||
| return; | ||||||
| } | ||||||
| if (username === "admin" && password ==="Hack1234") { | ||||||
| console.log(successMessage("Login Successful!")); | ||||||
|
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. The
Suggested change
|
||||||
| }else if (username === "user" && password ==="7654321") { | ||||||
| console.log(successMessage("Login Successful!")); | ||||||
| }else { | ||||||
| incorrectAttempts++; | ||||||
| if (incorrectAttempts >= 4) { | ||||||
| errorMessage('Login Blocked: Too many failed attempts. Please try again later.');} | ||||||
| else { | ||||||
| console.log(errorMessage("Incorrect credentials.")); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // Do not change the line below | ||||||
| export { onLogin }; | ||||||
|
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. Perfect! everything works really well 👍 |
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.
This works perfectly well, if you wish to challenge yourself and go one step further try to do it with only two conditions:
The challenge would be for you to fill in the condition in the
else if