-
Notifications
You must be signed in to change notification settings - Fork 0
Joel Jacob #1
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: master
Are you sure you want to change the base?
Joel Jacob #1
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>The Kosher Wine Cellar</title> | ||
</head> | ||
<body> | ||
<script src = "./script.js"></script> | ||
|
||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,30 @@ | ||||||||||
//Declare and initilize variables | ||||||||||
let howOldAreYou; | ||||||||||
let invalidInput; | ||||||||||
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. This is not needed as I will comment below |
||||||||||
let Age; | ||||||||||
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. All JS variables should use |
||||||||||
let approvedAge = 21; | ||||||||||
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. Variables that do not change should always be a
Suggested change
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. Unrelated, |
||||||||||
const WELCOME_MESSAGE = `Welcome To The Kosher Wine Cellar! | ||||||||||
You must be over 21 years to purchase on our site!`; | ||||||||||
Comment on lines
+6
to
+7
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. Since you've defined the minimum age above (
Suggested change
|
||||||||||
|
||||||||||
alert(WELCOME_MESSAGE); | ||||||||||
|
||||||||||
Age = prompt('Please Enter Your Age'); | ||||||||||
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. Instead of splitting the declaration and assignment, simply declare age here
Suggested change
|
||||||||||
|
||||||||||
console.log(typeof Age); | ||||||||||
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. This will always be "string" |
||||||||||
|
||||||||||
invalidInput = isNaN(Age); | ||||||||||
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. This is unnecessary
Suggested change
|
||||||||||
|
||||||||||
Age =Number(Age); | ||||||||||
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.
Suggested change
You can also do
Using the plus operator next to a string will convert it to a number |
||||||||||
|
||||||||||
console.log(typeof Age); | ||||||||||
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. In the future, submit your code without loggin |
||||||||||
|
||||||||||
if (invalidInput) { | ||||||||||
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. Instead of using a separate variable "
Suggested change
|
||||||||||
alert('You have entered an invalid input!'); | ||||||||||
throw 'INVALID_INPUT'; | ||||||||||
} | ||||||||||
|
||||||||||
if (Age >=approvedAge) { | ||||||||||
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. Code clarity dictates symmetric spacing
Suggested change
|
||||||||||
alert(`You are welcome to purchase on our site!`); | ||||||||||
} else { | ||||||||||
alert(`Sorry! You are underage!`) | ||||||||||
} |
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.
Normally there's no reason to initialize variables in advance, you can simply initialize them down the line where you use it (line 15)