title: Mathematical calculation using firebase function
body: <p>Calculating addition, subtraction, multiplication, division and mod result using firebase function and getting undefined as a response instead of the calculated value.</p>
  
  <p><strong>CODE</strong></p>
  
  <pre><code>const functions = require('firebase-functions');
  
  exports.calculator = functions.https.onRequest((request, response) =&gt; {
  
  console.log("request.body.result.parameters: ", 
  request.body.result.parameters);
  let params = request.body.result.parameters; 
  
  var sum = parseFloat(params.number1 + params.number2);
  var sub = parseFloat(params.number1 - params.number2);
  var mul = parseFloat(params.number1 * params.number2);
  var div = parseFloat(params.number1 / params.number2);
  var mod = parseFloat(params.number1 % params.number2);
  
  if (params.operator === "addition" ) {
      response.send({
              speech:
              `Here is your answer: ${sum}`             
  });
  }
  
  else if (params.operator === "subtraction" ) {
              response.send({
                      speech:
                      `Here is your answer: ${sub}`            
          });
      }
  else if (params.operator === "multiplication" ) {
             response.send({
                     speech:
                     `Here is your answer: ${mul}`            
          });
     }
  else if (params.operator === "division" ) {
      response.send({
              speech:
              `Here is your answer: ${div}`            
          });
     }
  else if (params.operator === "modulus" ) {
      response.send({
              speech:
              `Here is your answer: ${mod}`            
          });
     }
  });
  </code></pre>
  
  <p>Response:
  Here is your answer: undefined</p>