Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

10
  • We need to see more of the writeToScreen function Commented Oct 26, 2014 at 16:07
  • function writeToScreen(a) { var elem = document.getElementById('screen'); switch (a.value) { case '+': { if (firstOperation) { lastOperation = '+'; firstNumber = elem.value; elem.value = ""; firstOperation = 0; } else { lastOperation = '+'; firstNumber += elem.value; } } break; Commented Oct 26, 2014 at 16:07
  • You can edit your post and put the code in there where it won't be truncated :) Commented Oct 26, 2014 at 16:08
  • this is the element clicked. You pass it to the function, so now that element is referenced by the a parameter. When you do a.value, get fetches the current value of the element, which is 4 for that button. The elem variable refers to the screen input. You assign to its .value property in order to update the display. So every elem.value = "...whatever..." is updating the value of the screen element, and therefore its display. Commented Oct 26, 2014 at 16:11
  • 1
    ...here's a simpler example. jsfiddle.net/340d7s9c So it has nothing to do with getElementById(). That's just a method for fetching an element from the DOM. Updating the .value of an input element will update its display. Note that most elements do not have a .value. Most other ones, like a <div> will have its content updated using .appendChild() or .textContent or other properties and methods. Commented Oct 26, 2014 at 16:19