Skip to content

Conversation

joshlieb
Copy link
Member

@joshlieb joshlieb commented Nov 3, 2022

No description provided.

@@ -0,0 +1,30 @@
//Declare and initilize variables
let howOldAreYou;
Copy link
Member Author

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;
Copy link
Member Author

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;
Copy link
Member Author

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;
Copy link
Member Author

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

Suggested change
let approvedAge = 21;
const approvedAge = 21;

Copy link
Member Author

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

Comment on lines +6 to +7
const WELCOME_MESSAGE = `Welcome To The Kosher Wine Cellar!
You must be over 21 years to purchase on our site!`;
Copy link
Member Author

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

Suggested change
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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary

Suggested change
invalidInput = isNaN(Age);


invalidInput = isNaN(Age);

Age =Number(Age);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
Copy link
Member Author

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) {
Copy link
Member Author

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

Suggested change
if (invalidInput) {
if (isNaN(age)) {

throw 'INVALID_INPUT';
}

if (Age >=approvedAge) {
Copy link
Member Author

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

Suggested change
if (Age >=approvedAge) {
if (age >= approvedAge) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant