我目前正在进行课堂作业,我们正在学习if / else语句。我想知道return false;
语句是否存在与if
类似的代码。
例如:
var why = prompt("Why won't you fill in my prompt?");
if(why === "" || why === null){
// How can you make this false, so that it will ask the prompt question again?
return false; /*Like that--but not a function*/
}
答案 0 :(得分:1)
首先为响应定义一个容器,然后提示它,直到它是一个可接受的值:
var reason = null;
while (reason === "" || reason === null) {
reason = prompt("Why won't you fill in my prompt?");
}
// continue with the reason defined
答案 1 :(得分:0)
var why=null;
while (why===null||why===""){
why = prompt("Why won't you fill in my prompt?");
}