gpt4 book ai didi

Javascript:使用两个参数进行 boolean 比较的 while 循环

转载 作者:行者123 更新时间:2023-11-28 08:05:39 25 4
gpt4 key购买 nike

我会尽力做到最好。

var myPrompt = prompt("Are you ready to go?");

如果 myPrompt == true {

console.log(“太好了,我们走吧。”)

}其他{

console.log(“快点,我们没有整晚的时间了。”)

};

问题是如何将上面的值传递到一个 boolean 函数中,该函数将在该过程中执行 while 循环?

我需要从上面获取 boolean 值并将其传递到一个函数中,该函数与任何其他值进行 boolean 比较。在比较两者时,我正在执行 while 循环,直到比较满意为止。

最佳答案

检查这个答案How to create a dialog with “yes” and “no” options?

确认函数返回一个 boolean 值。

要获得无限循环提示用户使用变量说"is",请尝试

var response;
//while the user has NOT confirmed he is ready to go
while(!(response = confirm("Are you ready to go?"))){
alert("hurry up");
}
//the user is ready to go.

编辑 ** 如果足够的话,这段代码的风格比第一个片段要好得多。请注意,您实际上并不需要变量来使代码正常工作,以下内容更清晰

//you can glean the state of the user response without a variable
while(!confirm("Are you ready to go?")){
alert("hurry up");
//process not ready state
}
alert("Lets GO!");

关于Javascript:使用两个参数进行 boolean 比较的 while 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24815602/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com