gpt4 book ai didi

Javascript函数问题

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

我试图让用户输入一个数字,然后输入另一个数字,该数字将从输入的第一个数字开始乘法表,并继续递增一个,直到达到提示用户输入的最后一个数字...

例如,如果用户输入 10,然后输入 1,然后输入 10,输出将如下所示:

10 * 1 = 10
10 * 2 = 20
10 * 3 = 30
...
10 * 10 = 100


我做错了什么?

感谢您的帮助!

function multiplierz(numberMultiplied, amountToMultiplyFirst, amountToMultiplyLast)
{


while (isNaN(numberMultiplied) = true || isNaN(amountToMultiplyFirst) = true || isNaN(amountToMultiplyLast) = true)
{
alert("YOU DID NOT ENTER ONLY NUMBERS. WAY TO GO DUMMY.");
var numberMultiplied = prompt("Please Enter The Number to Multiply");
var amountToMultiplyFirst = prompt("Start multiplying by which number?");
var amountToMultiplyLast = prompt("End multiplying by which number?");
}
for (counter = amountToMultiplyFirst; counter <= amountToMultiplyLast; counter++)
{
document.write(numberMultiplied + " * " + counter + " = " + numberMultiplied * counter + "<br />");
}
}

//Begin Program Below


multiplierz(prompt("Please Enter The Number to Multiply"),prompt("Start multiplying by which number?"),prompt("End multiplying by which number?"));
</script>

最佳答案

您的 isNan(numberMultiplied) = true 抛出错误。在 javascript 中,= 运算符用于赋值。

就这样

while (isNaN(numberMultiplied) || isNaN(amountToMultiplyFirst) || isNaN(amountToMultiplyLast) )

关于Javascript函数问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5698388/

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