Home > Mobile >  How to call multiple functions in javascript and have them display?
How to call multiple functions in javascript and have them display?

Time:04-22

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();

CodePudding user response:

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

CodePudding user response:

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

Thanks

CodePudding user response:

I fixed quotient, but now it only displays that. I believe I'm only stuck on the output statements. I want it to display sum, difference, product and quotient. All at once...

I've had my teacher suggest this..for the calculateSum function. What am I missing?

// create output statement output = "The precentage growth is " CalculateSum ".";

The above line of code should be:

// create output statement output = "The percentage growth is " sum ".";

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 quotient = 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 "   quotient   ".";

  document.write(output);
}

// We have to call our Main function explicitly or it won't work.
Main();

  • Related