-
Notifications
You must be signed in to change notification settings - Fork 175
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
JavaScript Pizzeria #136
base: main
Are you sure you want to change the base?
JavaScript Pizzeria #136
Conversation
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.
Hey there! Awesome work on putting together this project 🥳
JavaScript
- In your code, you declare the variable
orderedFood
without using let or const. It's important to declare variables explicitly, as this avoids potential issues with global variables. - The flow is overall well controlled, you've added a lot of fallbacks for different alternatives which is great! However, maybe you'd want to consider to stop the flow when an invalid input is detected. You can use
return
to exit the function if the choice is invalid. For example:
if (pizzachoice !== "1" && pizzachoice !== "2" && pizzachoice !== "3") {
alert("Sorry, we don't have that kind of pizza.");
return; // Stop further execution
}
Clean Code
- See comments in code about indentation. Check your whole file
- Remember to always write variable names in camelCase (mealChoice, pizzaChoice)
Keep up the good work! Remember to think about these things going forward, and your code will be more readable and robust.
After a while, I figured it must be because I was using digits, not text. I tested”, ’ and ´ until I spotted that a backtick/grave/grave accent was used in the first alert that came with the fork. Changed all string/text values to that specific tick and just like that, the code worked. This also made me discover that everything between two quotation marks turns into text, while the ${name} still function when using the backtick. So I used ”” for the meal choices (since it has to be only text) and for the alert, I used ` since it has ${name} in it. | ||
|
||
### Old variable? | ||
${name} turned into a strikethrough text. When I hovered over it, it said ”'name' is deprecated.” Googled it, and read that the warning is being shown because the name variable may be removed in future versions. Not sure if it affects my code, but to avoid any issues I changed it to $userName and the strikethough disappeared. |
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.
name
is an old JavaScript keyword, but changing to userName
sounds like a really good solution ⭐
alert(”Thanks, ${name}! You wish to order Pizza!”) | ||
} | ||
|
||
After a while, I figured it must be because I was using digits, not text. I tested”, ’ and ´ until I spotted that a backtick/grave/grave accent was used in the first alert that came with the fork. Changed all string/text values to that specific tick and just like that, the code worked. This also made me discover that everything between two quotation marks turns into text, while the ${name} still function when using the backtick. So I used ”” for the meal choices (since it has to be only text) and for the alert, I used ` since it has ${name} in it. |
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.
parseInt()
💡
code/script.js
Outdated
` | ||
) | ||
//Pizza | ||
if (mealchoice === "1") { |
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.
I saw you mentioned this in your README as well, regarding indentation. If you've turned off the default formatting, make sure to have another look through your file and indent everything properly, e.g.
if (mealchoice === "1") {
const pizzachoice = prompt(
`Thanks, ${userName}! You wish to order Pizza!
What type of Pizza you like to order? Please enter the number of your choice.
1. Capricciosa
2. Hawaii
3. Vesuvius
`)
if (pizzachoice === "1") {
orderedFood = "Capricciosa pizza"
} else if (pizzachoice === "2") {
orderedFood = "Hawaii pizza"
} else if (pizzachoice === "3") {
orderedFood = "Vesuvius pizza"
} else {
alert("Sorry, we don't have that kind of pizza.")
}
if (orderedFood) {
alert(`You've chosen ${orderedFood}`)
}
} else if....
code/script.js
Outdated
// Step 2 - Food choice | ||
// Your code goes here | ||
const mealchoice = prompt( |
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.
camelCase! -> mealChoice
Netlify link
Add your Netlify link here like this (update with the correct one):
https://johannas-js-pizzeria.netlify.app/