我应该在不使用数组的情况下找到四个数字中的最高和最低数字。我怎么能这样做呢?
道歉,我忘了链接我的代码。
var num1, num2, num3, num4;
num1 = prompt("Enter the first number.");
num2 = prompt("Enter the second number.");
num3 = prompt("Enter the third number.");
num4 = prompt("Enter the fourth number.");
if (num1 < num2)
{
if (num1 < num3)
{
if (num1 < num4)
{
var lowest = num1;
}
}
}
答案 0 :(得分:0)
将nr 1与nr比较2.将最大值保存为X.将X与nr比较3.将最高值再次保存为X.与nr比较4.将最高值保存为X,现在是最高数字。现在你可以弄清楚如何获得最低......
答案 1 :(得分:0)
var num1, num2, num3, num4;
num1 = prompt("Enter the first number.");
num2 = prompt("Enter the second number.");
num3 = prompt("Enter the third number.");
num4 = prompt("Enter the fourth number.");
var highest=num1;
if (highest < num2)
{
highest = num2;
}
if (highest < num3)
{
highest = num3;
}
if (highest < num4)
{
highest = num4;
}
alert(highest);
var lowest=num1;
if (lowest > num2)
{
lowest = num2;
}
if (lowest > num3)
{
lowest = num3;
}
if (lowest > num4)
{
lowest = num4;
}
alert(lowest);