Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save LukeSkyRunner/28805802147805fdf680473ed9d18ecd to your computer and use it in GitHub Desktop.
Save LukeSkyRunner/28805802147805fdf680473ed9d18ecd to your computer and use it in GitHub Desktop.
Javascript Swtich Fruit Practice
// TO SEE HOW THIS EXAMPLE WORKS, UN COMMENT OUT THE FOLLOWING LINE
//const fruit = prompt ("Enter the fruit name:");
let type = "";
switch (fruit){
case "pear" || "apple":
type = "pome"
break;
case "peach" || "coconut":
type = "drupe"
break;
case "strawberry" || "blackberry":
type = "berry"
break;
case "beans" || "peas":
type = "legumes"
break;
default:
type = "other"
break;
}
console.log(`${fruit} is type of: ${type}.`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment