如何在JavaScript中调用多个功能并显示它们?

发布于 2025-01-23 11:22:03 字数 1573 浏览 2 评论 0原文

我正在尝试一次调用多个功能,并在屏幕上显示它们。 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执笔绘流年 2025-01-30 11:22:03

拼写为qoutient,将输出字符串连接在一起时。因此,口译员正在尝试评估一个尚未定义的变量

quotient is misspelled as qoutient when you concatenate your output string together. So the interpreter is attempting to evaluate a variable that hasn't actually been defined

秋千易 2025-01-30 11:22:03

变量名是“商”,而不是此“ Qutient”
只是改变。

谢谢

The variable name is "quotient" and not this "qoutient"
just change that.

Thanks

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文