Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions javaScript.html
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>
30 changes: 30 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -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)

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

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 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

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
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!`;


alert(WELCOME_MESSAGE);

Age = prompt('Please Enter Your 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.

Instead of splitting the declaration and assignment, simply declare age here

Suggested change
Age = prompt('Please Enter Your Age');
let age = prompt('Please Enter your 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.

This will always be "string"


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);


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


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


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)) {

alert('You have entered an invalid input!');
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) {

alert(`You are welcome to purchase on our site!`);
} else {
alert(`Sorry! You are underage!`)
}