title: Create a MR and MC in a javascript calculator
body: <p>Idealy, I would like my little project to have the memory functions M-, M+, MR and MC. 
  I was thinking of separate functions and variables to hold the M- and M+.
  Is this a normal approach or there is a better one ?</p>
  
  <p>Any idea what might be wrong with my script ? if there is something wrong ?</p>
  
  <p>the number-display ID is the actual calculator screen</p>
  
  <p>the code is :</p>
  
  <pre><code>$(document).ready(function(){
      var display = "";
      var operators = ["/", "*", "-", "+"];
      var decimalAdded = false;
  
      $("button").click(function() {
          var key = $(this).text();
  
        //update screen by adding display string to screen with maximum 19 numbers viewable
          function updateDisplay() {
              if (display.length &gt; 19) {
                $("#number-display").html(display.substr(display.length - 19, display.length));
              } else {
                $("#number-display").html(display.substr(0, 19));
              }
          }
        //clear all entries by resetting display and variables
          if (key === "AC" || key === "ON" || key === "MC") {
              decimalAdded = false;
              display = "";
              $("#number-display").html("0");
          }
  
          else if (key === "OFF") {
              decimalAdded = false;
              display = "";
              $("#number-display").html("");
          }
  
  
        //clear previous character and reset decimal bool if last character is decimal
          else if (key === "CE") {
              if (display.substr(display.length - 1, display.length) === ".") {
                  decimalAdded = false;
              }
              display = display.substr(0, display.length - 1);
              updateDisplay();
          }
  
        //add key to display if key is a number
          else if (!isNaN(key)) {
              display += key;
              updateDisplay();
          }
        //check that . is the first in the number before adding and add 0. or just .  
          else if (key === ".") {
              if (!decimalAdded) {
                  if(display &gt; 0){
                      display += key;
                  }
                  else {
                      display += "0" + key;
                  }
                  decimalAdded = true;
                  updateDisplay();
              }
          }
          //if key is basic operator, check that the last input was a number before inputting
          else if (operators.indexOf(key) &gt; -1) {
              decimalAdded = false;
              //first input is a number
              if (display.length &gt; 0 &amp;&amp; !isNaN(display.substr(display.length - 1, display.length))) {
                  display += key;
                  updateDisplay();
              }
          // allow minus sign as first input
              else if (display.length === 0 &amp;&amp; key === "-") {
                  display += key;
                  updateDisplay();
              }
  
          }
          // calculate square root of number
  
          else if ( $(this).id === "sqrt") {
  
                  var tempStore = display.html();
                  $("#number-display").html(eval(Math.sqrt(tempStore)));
                  decimalAdded = false;
          }
  
          // change sign of number
  
          else if ($(this).id === "plusmn") {
              var newNum = display * -1;
              $("#number-display").html(newNum);
          }
  
          // create memory plus and minus and calculate MR
          else if (key === "M-") {
  
          }
          else if (key === "M+") {
  
          }
  
          // percentage function
  
          else if (key === "%"){
  
          }
  
          else if (key == "=") {
              //if last input is a decimal or operator, remove from display
              if (isNaN(display.substr(display.length - 1, display.length))) {
                  display = display.substr(0, display.length - 1);
              }
              var calc = display;
              calc = eval(calc);
              display = String(calc);
              if (display.indexOf('.')) {
                  decimalAdded = true;
              } else {
                  decimalAdded = false;
              }
              $("#number-display").html(display);
          }
      });});
  </code></pre>