gpt4 book ai didi

javascript - 如何在javascript中的do-while循环中嵌套if语句

转载 作者:行者123 更新时间:2023-11-28 13:23:42 24 4
gpt4 key购买 nike

var temp = 110;
for {
temp-=1
if (temp >= 90) {
console.log("Today's temperature is "+temp+"! "+"Lets go play ball")
} else {
console.log("Today's temperature is "+temp+"! "+"It is too hot today to ball!")
}

}while (temp > 90)

请查看我的代码片段。由于某种原因它不会运行,并指出一些括号错误,因为我已经检查了括号。

最佳答案

它的不是为了

var temp = 110;
do { //its `do` not `for`
temp -= 1;
if (temp >= 90) {
console.log("Today's temperature is " + temp + "! " + "Lets go play ball")
} else {
console.log("Today's temperature is " + temp + "! " + "It is too hot today to ball!")
}

} while (temp > 90);

您可以使用prompt()进行用户输入:

var temp = prompt('Input temperature', '110'); // (message, default input)
console.log('temp', temp);
do { //its `do` not `for`
temp -= 1;
if (temp >= 90) {
console.log("Today's temperature is " + temp + "! " + "Lets go play ball")
} else {
console.log("Today's temperature is " + temp + "! " + "It is too hot today to ball!")
}

} while (temp > 90);

关于javascript - 如何在javascript中的do-while循环中嵌套if语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31064878/

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