generated from HackYourFuture/core-assignment-week-2
-
Notifications
You must be signed in to change notification settings - Fork 19
Pavel T #25
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
Open
pavel-tisner
wants to merge
3
commits into
HackYourAssignment:main
Choose a base branch
from
pavel-tisner:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Pavel T #25
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,23 @@ | ||
| // Do not change the line below | ||
| import { errorMessage, successMessage } from './app.js'; | ||
| import { errorMessage, successMessage } from "./app.js"; | ||
|
|
||
| let incorrectAttempts = 0; | ||
| const loginButton = document.getElementById("loginButton"); | ||
|
|
||
| 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")) && | ||
| incorrectAttempts < 3) { | ||
| successMessage("Logged in successfully"); | ||
| incorrectAttempts = 0; | ||
| } else { | ||
| errorMessage("Incorrect credentials"); | ||
| incorrectAttempts += 1; | ||
| if (incorrectAttempts > 3) { | ||
| loginButton.disabled = true; | ||
| errorMessage("Login blocked: Too many incorrect attempts"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Do not change the line below | ||
| export { onLogin }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,37 +1,51 @@ | ||
| import promptSync from 'prompt-sync'; | ||
| import promptSync from "prompt-sync"; | ||
| const prompt = promptSync(); | ||
|
|
||
| // Exchange rate for EUR/USD (How much 1 EUR is in USD) | ||
| 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"); | ||
|
|
||
| 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; | ||
| console.log(eurAmountNum.toFixed(2) + ' EUR is equal to ' + usdAmount.toFixed(2) + ' USD.'); | ||
| console.log( | ||
| eurAmountNum.toFixed(2) + | ||
| " EUR is equal to " + | ||
| usdAmount.toFixed(2) + | ||
| " USD.", | ||
| ); | ||
| } | ||
| } else if (menuSelection === "2") { | ||
| // USD to EUR | ||
| const usdAmountInput = prompt("Enter amount in USD: "); | ||
| const usdAmountNum = Number(usdAmountInput); | ||
| if (Number.isNaN(usdAmountNum) || usdAmountNum < 0) { | ||
| 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 / EUR_USD_RATE; | ||
| console.log( | ||
| usdAmountNum.toFixed(2) + | ||
| " USD is equal to " + | ||
| eurAmount.toFixed(2) + | ||
| " EUR.", | ||
| ); | ||
| } | ||
| } else if (menuSelection === "3") { | ||
| // show exchange rate | ||
| console.log("The current exchange rate is 1 EUR = " + EUR_USD_RATE + " USD."); | ||
| } else { | ||
| console.log("Invalid selection. Please choose either 1 or 2."); | ||
| console.log("Invalid selection. Please choose either 1, 2, or 3."); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 was a good improvement idea. Unfortunately, it doesn't work, because
app.jsenables it again at line 41 (loginButton.disabled = true;)But don't worry about it. It is more than the exercise was asking for, and nice to see the improvement :)