How to combine a switch statement and a while loop?

javascript

#1



This is the type of code I am doing for a school project:

var espanol = prompt("What do you want to ask me?");
while(espanol.length >= 1); {
switch(espanol){
case '12':
console.log("1");
var espanol = prompt("Anything else?");
break;
case '22':
console.log("2");
var espanol = prompt("Anything else?");
break;
case '32':
console.log("3");
var espanol = prompt("Anything else?");
break;
case '42':
console.log("4");
var espanol = prompt("Anything else?");
break;
case '52':
console.log("5");
var espanol = prompt("Anything else?");
break;
case '62':
console.log("");
var espanol = prompt("Anything else?");
break;
case '7':
console.log("");
var espanol = prompt("Anything else?");
break;
case '8':
console.log("");
var espanol = prompt("Anything else?");
break;
case '9':
console.log("");
var espanol = prompt("Anything else?");
break;
case '10':
console.log("");
var espanol = prompt("Anything else?");
break;
case '11':
console.log("");
var espanol = prompt("Anything else?");
break;
case '12':
console.log("");
var espanol = prompt("Anything else?");
break;
case '13':
console.log("");
var espanol = prompt("Anything else?");
break;
case '14':
console.log("");
var espanol = prompt("Anything else?");
break;
case '15':
console.log("");
var espanol = prompt("Anything else?");
break;
case '16':
console.log("");
var espanol = prompt("Anything else?");
break;
case '17':
console.log("");
var espanol = prompt("Anything else?");
break;
case '18':
console.log("");
var espanol = prompt("Anything else?");
break;
case '19':
console.log("");
var espanol = prompt("Anything else?");
break;
case '20':
console.log("");
var espanol = prompt("Anything else?");
break;
case '21':
console.log("");
var espanol = prompt("Anything else?");
break;
case '22':
console.log("");
var espanol = prompt("Anything else?");
break;
case '23':
console.log("");
var espanol = prompt("Anything else?");
break;
case '24':
console.log("");
var espanol = prompt("Anything else?");
break;
case '25':
console.log("");
var espanol = prompt("Anything else?");
break;
case '26':
console.log("");
var espanol = prompt("Anything else?");
break;
case '27':
console.log("");
var espanol = prompt("Anything else?");
break;
case '28':
console.log("");
var espanol = prompt("Anything else?");
break;
case '29':
console.log("");
var espanol = prompt("Anything else?");
break;
case '30':
console.log("");
var espanol = prompt("Anything else?");
break;

default:
console.log("I'm sorry, I'm not sure what that meant. Check the questions to see what I understand");
}


What I want for this code is to continue on so you can ask multiple questions (I know not all of them are filled out), but when I try the page crashes. How would I make this code so every time the prompt is filled out, a new prompt pops up (where "anything else" is) that would run the code again with a different value for espanol?


Replace this line with your code.


#2

If I get your question well enough, I suggest you could do something like this:

switch (new Date().getDay()) {
    case 1:
    case 2:
    case 3:
    default: 
        text = "Looking forward to the Weekend";
        break; 
    case 4:
    case 5:
       text = "Soon it is Weekend";
        break; 
    case 0:
    case 6:
       text = "It is Weekend";
}

You could group the case.