【发布时间】:2016-11-15 09:50:25
【问题描述】:
对于 JavaScript 来说相当新,如果用户输入错误的答案,我如何循环回到提示问题,并且我希望问题重复,直到他们得到正确的答案。
<html>
<head>
<script>
</script>
<title> Javascript program</title>
</head>
<body>
<script>
var company = (prompt("What the name of the company that developed the javascript language?", ""));
if (company == 'netscape') {
alert("correct answer!");
} else {
alert("wrong answer");
}
</script>
</body>
</html>
【问题讨论】:
-
看看
while循环。顺便说一句,如果有人输入Netscape而不是netscape,会发生什么。 -
要添加到答案中,您还可以使用 do while 循环 as shown here
标签: javascript