简体   繁体   English

我如何做一个条件提示,它将继续提示直到满足条件

[英]How do I make a conditional prompt that will continue to prompt until condition is met

I am trying to learn javascript and have been playing around with a rock, paper, scissors game I made. 我正在尝试学习JavaScript,并且一直在玩我制作的石头,纸,剪刀游戏。 Currently the user can enter anything in the prompt so I was trying to make a condition in which the prompt would continue to pop up if the user puts anything other than rock, paper or scissors. 当前,用户可以在提示中输入任何内容,因此我试图做出一种条件,如果用户放置石头,纸或剪刀以外的任何内容,提示将继续弹出。 I have tried using while, do while and other attempts using if statements and have not been able to get it to work. 我尝试使用while,do while和其他尝试使用if语句,但无法使其正常工作。 Can anyone show me who I can make the prompt continue to pop up until the user puts the correct string? 谁能告诉我可以让提示继续出现的用户,直到用户输入正确的字符串为止? I didn't add the code since this is such a simple thing. 我没有添加代码,因为这很简单。 Thanks. 谢谢。

Annoying code : 烦人的代码:

var test = 0;

while(test != 10) {
    test = parseInt(prompt('Enter ten'), 10);
}

FIDDLE 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM