我想提示之前提示的数字的总和



我被卡住了。

我必须提示一个号码。然后创建与初始提示相关的提示循环,然后对它们求和。我完全迷路了。我如何对它们求和?

let first_question=prompt("introduce the quantity of numbers you want to sum")
for (let i=0; i < first_question;i++)
{

let second_question= prompt ("introduce the number you want to sum");   

}

这样做:

var first_question = parseInt(prompt("Introduce the quantity of numbers you want to sum: "));
var sum = 0;
for (let i = 0; i < first_question; i++) { 
let second_question = parseInt(prompt("Introduce the number you want to sum: "));  
sum += second_question;
}

最后,变量sum将具有您想要的值。还要注意prompt((将返回一个字符串,所以我使用parseInt((将其转换为数字

最新更新