小编Fin*_*n E的帖子

重复switch语句,直到它有一个有效的答案

我是一个尝试用JavaScript制作文本冒险游戏的初学者,我需要重复一个switch语句,直到用户输入一个有效的答案:

opts = prompt("Do you want to TALK or LOOK?").toUpperCase();

switch(opts) {
  case "TALK":
    mes = "Is anyone in charge here?";
    speech = "Our leader is in the big building.";
    talkNot();
    break;
  case "LOOK":
    window.alert("The buildings are quite simple, and the doorways are much shorter than you. You notice, however, that there is a very tall, thin building at the end of the street.");
    break;
  default:
    window.alert("That's not an option.");
}
Run Code Online (Sandbox Code Playgroud)

任何答案都会非常有用 - 谢谢!

javascript for-loop switch-statement

3
推荐指数
1
解决办法
208
查看次数

标签 统计

for-loop ×1

javascript ×1

switch-statement ×1