text: function getHistory() {
      return document.querySelector('#history-value').innerText;
  }
  
  function printHistory(num) {
      document.querySelector('#history-value').innerText = num;
  }
  
  function getOutput() {
      return document.querySelector('#output-value').innerText;
  }
  
  function printOutput(num) {
      if(num == "")
      {
          document.querySelector('#output-value').innerText = num;
      }
      else
      {
          document.querySelector('#output-value').innerText = getFormattedNumber(num);
      }
  }
  
  function getFormattedNumber(num) {
      if(num == "-")
      {
          return "";
      }
      var n = Number(num);
      var value = n.toLocaleString("en");
      return value;
  }
  
  function reverseNumberFormat(num) {
      return Number(num.replace(/,/g, ''));
  }
  
  var operator = document.getElementsByClassName('operator');
  
  for(var i = 0; i < operator.length; i++){
      operator[i].addEventListener('click', function() {
          if(this.id === "clear")
          {
              printHistory("");
              printOutput("");
          }
          if(this.id == "backspace")
          {
              var output = reverseNumberFormat(getOutput()).toString();
              if(output)
              {
                  output = output.substr(0, output.length - 1);
                  printOutput(output);
              }
          }
          else{
              var output = getOutput();
              var history = getHistory();
  
              if(output == ""&&history!="")
              {
                  if(isNaN(history[history.length-1]))
                  {
                      history = history.substr(0, history.length-1);
                  }
              }
              if(output != "" || history != "")
              {
                  output = output == ""? output: reverseNumberFormat(output);
                  history += output;
                  if(this.id === "=")
                  {
                      var result = eval(history);
                      printOutput(result);
                      printHistory("");
                  }
                  else
                  {
                      history += this.id;
                      printHistory(history);
                      printOutput("")
                  }
              }
          }
      });
  }
  
  var number = document.getElementsByClassName('number');
  
  for (var i = 0; i < number.length; i++) {
      number[i].addEventListener('click', function () {
          let output = reverseNumberFormat(getOutput());
          if(output !== NaN)
          {
              output += this.id;
              printOutput(output);
          }
      });
  }
  
  var microphone = document.getElementById('microphone');
  
  microphone.onclick = function() {
      
      document.querySelector('#output-value').innerText = "";
      document.querySelector('#history-value').innerText = "";
  
      microphone.classList.add("record");
      let recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition ||window.mozSpeechRecognition || window.msSpeechRecognition)();
      recognition.lang = 'en-US';
      recognition.start();
  
      operations = {"plus" : "+",
                  "minus" : "-",
                  "difference" : "-",
                  "multiplied by" : "*",
                  "multiply" : "*",
                  "x" : "*",
                  "X" : "*",
                  "times" : "*",
                  "divided by" : "/",
                  "divide" : "/",
                  "divided" : "/",
                  "by" : "/",
                  "remainder" : "%",
                  "modulo" : "%"}
  
      recognition.onresult = function(event) {
          var input = event.results[0][0].transcript;
  
          for(property in operations)
          {
              input = input.replace(property, operations[property]);
          }
          console.log(input);
          document.querySelector('#history-value').innerText = input;
          setTimeout(function() {
              evaluate(input);
          }, 2000);
          microphone.classList.remove("record");
      }
  }
  
  function evaluate(input) {
      try {
          var result = eval(input);
          document.querySelector('#output-value').innerText = result;
      }
      catch(e)
      {
          console.log(e);
          document.querySelector('#history-value').innerText = "";
      }
  }