【发布时间】:2017-02-15 15:08:01
【问题描述】:
我做了一个while循环,它允许总结提示框并显示最大的数字。我正在尝试将 While 循环转换为 For 循环。我遇到了麻烦,因为我对 For 循环几乎一无所知,任何帮助将不胜感激。谢谢
var a = Number(prompt("Enter First Number"));
var b = Number(prompt("Enter Second Number"));
var c = Number(prompt("Enter Third Number"));
while (a > 0) {
if (a > b && a > c) {
alert(prompt("A is Bigger"));
}
if (b > a && b > c) {
alert(prompt("B is Bigger"));
}
if (c > a && c > b) {
alert(prompt("C is Bigger"));
} else {
alert(prompt("Each number is the same"))
}
alert(prompt(a + b + c));
}
【问题讨论】:
-
把它转换成for循环是没有意义的
-
alert(prompt())是一个非常奇怪的结构。你提示用户输入,然后提醒用户,然后把它扔掉...... -
感谢回复,这是一个有2个需求的项目。用 While 循环做我在那里做的事情,然后在 For 循环中做同样的事情。
-
另外,至少在提问之前read the documentation。请阅读How to Ask。关键词:“搜索和研究”和“解释......任何阻碍你自己解决的困难”。
-
@Quentin 好吧,我不会说这没有意义,
while循环更适合解决问题。
标签: javascript loops for-loop