如何在JavaScript中调用多个功能并显示它们?
我正在尝试一次调用多个功能,并在屏幕上显示它们。 ColculateUm功能能够正确显示。错误消息是未定义的。我已经查看了计算功能,我不明白我缺少什么。有其他调用该功能的方式吗?
function CalculateSum(numberOne,numberTwo) {
var sum = 0;
sum = (numberOne + numberTwo);
return sum
}
function CalculateDifference(numberOne,numberTwo) {
var difference = 0;
difference = (numberOne - numberTwo);
return difference
}
function CalculateProduct(numberOne,numberTwo) {
var product = 0;
product = (numberOne * numberTwo);
return product
}
function CalculateQuotient(numberOne,numberTwo) {
var qoutient = 0;
quotient = (numberOne / numberTwo);
return quotient
}
function Main() {
// variables for this part of the program
var numberOne = 0;
var numberTwo = 0;
var output = "";
// get value from users
numberOne = prompt("Enter first nummber");
numberTwo = prompt("Enter second number");
numberOne = Number(numberOne);
numberTwo = Number(numberTwo);
// call function and capture return value
sum = CalculateSum(numberOne, numberTwo);
difference = CalculateDifference(numberOne, numberTwo);
product = CalculateProduct(numberOne, numberTwo);
quotient = CalculateQuotient(numberOne, numberTwo);
// create output statement
output = "The sum is " + sum + ".";
output = "The difference is " + difference + ".";
output = "The product is " + product + ".";
output = "The qoutient is " + qoutient + ".";
document.write(output);
}
// We have to call our Main function explicitly or it won't work.
Main();
I'm trying to call multiple functions at once and have them displayed on the screen. CalculateSum function is able to display correctly. The error message is quotient not defined. I've looked at CalculateQuotient function, I don't understand what I'm missing. Is there a different way to call the function?
function CalculateSum(numberOne,numberTwo) {
var sum = 0;
sum = (numberOne + numberTwo);
return sum
}
function CalculateDifference(numberOne,numberTwo) {
var difference = 0;
difference = (numberOne - numberTwo);
return difference
}
function CalculateProduct(numberOne,numberTwo) {
var product = 0;
product = (numberOne * numberTwo);
return product
}
function CalculateQuotient(numberOne,numberTwo) {
var qoutient = 0;
quotient = (numberOne / numberTwo);
return quotient
}
function Main() {
// variables for this part of the program
var numberOne = 0;
var numberTwo = 0;
var output = "";
// get value from users
numberOne = prompt("Enter first nummber");
numberTwo = prompt("Enter second number");
numberOne = Number(numberOne);
numberTwo = Number(numberTwo);
// call function and capture return value
sum = CalculateSum(numberOne, numberTwo);
difference = CalculateDifference(numberOne, numberTwo);
product = CalculateProduct(numberOne, numberTwo);
quotient = CalculateQuotient(numberOne, numberTwo);
// create output statement
output = "The sum is " + sum + ".";
output = "The difference is " + difference + ".";
output = "The product is " + product + ".";
output = "The qoutient is " + qoutient + ".";
document.write(output);
}
// We have to call our Main function explicitly or it won't work.
Main();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
商
拼写为qoutient
,将输出字符串连接在一起时。因此,口译员正在尝试评估一个尚未定义的变量quotient
is misspelled asqoutient
when you concatenate your output string together. So the interpreter is attempting to evaluate a variable that hasn't actually been defined变量名是“商”,而不是此“ Qutient”
只是改变。
谢谢
The variable name is "quotient" and not this "qoutient"
just change that.
Thanks