Was experimenting. Need Help


I was writing a "switch" code and in the code below, I wanted to use if/else statements to print out different sentences for different choices of Pasta.

I don't know how to use if/else statements under prompt sentences.
Do we need to set variables for this or what?

Plz help


var lunch = prompt("What would you like to have for lunch?! These are the choices!");
switch(lunch) {
    case 'Salad':
      console.log("Living the healthy life!");
    case 'Pizza':
      console.log("Everyone's Favorite!");
    case 'Burgers':
      console.log("Everyone loves the king!");
    case 'Pasta':
      prompt("White or Red?");{
          if (Pasta = White) {
              console.log("White pasta coming!");
          } else {
              console.log("Red pasta coming!");
      console.log("Sorry. Not available");


It works the same way you set up the Pasta case.


So you're saying that I have to make separate cases of White and Red pastas?


Got it in the next segment.


The user can introduce something that's neither white nor red, in this case the code would output "Red pasta coming!", a quick fix could be something like this

 case 'Pasta':
      var pastaType = prompt("White or Red?");{
          if (pastaType = "White") {
              console.log("White pasta coming!");
          } else if (pastaType = "Red"{
              console.log("Red pasta coming!");
          } else{
              console.log("insert error message here");


No. If you are making pizza have similar options, then you would write it
using the Pasta as a model.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.