Project
You can have multiple if conditions in the same function. You can have many if conditions in the same function as well, just pay attention to the exits.
function getVotingMessage(age) {
if (age >= 18) {
return "You can vote"
}
if (age < 18) {
return "You cannot vote"
}
}
The project!
- When the number is below 0 (for example -1, -2, etc.), we want to show the message Invalid number
- When the number is 0, show the message: You don't have any items in your shopping list
- When the number is 1, show the message: You have one item in your shopping list
- When the number is above 1, show the message: You have more than 1 item in your shopping list
export function getMessage(value) {
console.log(value)
if (value < 0) {
return "Invalid number"
}
if (value === 0) {
return "You don't have any items in your shopping list"
}
if (value === 1) {
return "You have one item in your shopping list"
}
if (value > 1) {
return "You have more than 1 item in your shopping list"
}
}
This is the flowchart for the code above.