如果输入0,则要求程序终止,否则它将继续运行。如果输入0,则需要在控制台上打印输入的最大值。 需要一些帮助修复此代码。它并不总是打印输入的最大数字。有时候会。
var number = 1;
var largest = 0;
do {
number = prompt("Enter a number other than 0 and will tell you the largest");
if(number >= largest) { //If largest is small, set current number
as largest
largest = number;
}
} while (number > 0);
console.log("The largest number is " + largest);
答案 0 :(得分:0)
您必须将prompt
的值转换为数字。
var number = 1;
var largest = 0;
do {
number = prompt("Enter a number other than 0 and will tell you the largest");
if (parseFloat(number) >= largest)
largest = number;
} while (number > 0);
console.log("The largest number is " + largest);