-
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
Conversation
@@ -0,0 +1,30 @@ | |||
//Declare and initilize variables | |||
let howOldAreYou; |
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)
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed as I will comment below
//Declare and initilize variables | ||
let howOldAreYou; | ||
let invalidInput; | ||
let Age; |
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.
All JS variables should use camelCasing
let howOldAreYou; | ||
let invalidInput; | ||
let Age; | ||
let approvedAge = 21; |
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.
Variables that do not change should always be a const
let approvedAge = 21; | |
const approvedAge = 21; |
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.
Unrelated, minimumAge
is a more descriptive variable name
const WELCOME_MESSAGE = `Welcome To The Kosher Wine Cellar! | ||
You must be over 21 years to purchase on our site!`; |
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.
Since you've defined the minimum age above (approvedAge
) you can now use it inside the message
const WELCOME_MESSAGE = `Welcome To The Kosher Wine Cellar! | |
You must be over 21 years to purchase on our site!`; | |
const WELCOME_MESSAGE = `Welcome To The Kosher Wine Cellar! | |
You must be over ${approvedAge} years to purchase on our site!`; |
|
||
console.log(typeof Age); | ||
|
||
invalidInput = isNaN(Age); |
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 is unnecessary
invalidInput = isNaN(Age); |
|
||
invalidInput = isNaN(Age); | ||
|
||
Age =Number(Age); |
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.
Age =Number(Age); | |
age = Number(age); |
You can also do
age = +age;
Using the plus operator next to a string will convert it to a number
|
||
Age =Number(Age); | ||
|
||
console.log(typeof Age); |
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.
In the future, submit your code without loggin
|
||
console.log(typeof Age); | ||
|
||
if (invalidInput) { |
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.
Instead of using a separate variable "invalidInput
" you can inline it as such
if (invalidInput) { | |
if (isNaN(age)) { |
throw 'INVALID_INPUT'; | ||
} | ||
|
||
if (Age >=approvedAge) { |
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.
Code clarity dictates symmetric spacing
if (Age >=approvedAge) { | |
if (age >= approvedAge) { |
No description provided.