Was experimenting. Need Help


#1


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

https://www.codecademy.com/courses/javascript-beginner-en-qDwp0/1/5?curriculum_id=506324b3a7dffd00020bf661


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!");
      break;
      
    case 'Pizza':
      console.log("Everyone's Favorite!");
      break;
      
    case 'Burgers':
      console.log("Everyone loves the king!");
      break;
      
    case 'Pasta':
      prompt("White or Red?");{
          if (Pasta = White) {
              console.log("White pasta coming!");
          } else {
              console.log("Red pasta coming!");
          }
      }
          
      break;
    
    default:
      console.log("Sorry. Not available");
}


#2

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


#3

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


#4

Got it in the next segment.


#5

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");
          }
      }
     break;

#6

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


#7

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