javascript - Unsure of how to make this calculator function work -


link codepen

for math project due soon.

i've tried apply dry concept, don't know how. started write function apply of numbers, halfway through realized there's no way work. anonymous functions need changed know that, yet can't right don't know way implement it.

document.queryselector(".button").addeventlistener("click", function) {   num = document.getelementbyid('something');     if (num != null && num === document.getelementbyid("zero")) {     calculation = calculation.concat("0");   } else if (num != null && num === document.getelementbyid("one")) {     calculation = calculation.concat("1");   } else if (num != null === && num document.getelementbyid("two")) {     calculation = calculation.concat("2");   } else if (num != nul && num === document.getelementbyid("three")) {     calculation = calculation.concat("3");   } else if (num != nul && num === document.getelementbyid("four")) {     calculation = calculation.concat("4");   } else if (num != nul && num === document.getelementbyid("five")) {     calculation = calculation.concat("5");   } else if (num != nul && num === document.getelementbyid()) {     calculation = calculation.concat("6");   } } 

each number inside button inside table. have id's identifying number are. i'm not looking code, don't want plagiarize anything. looking suggestions on differently.

your easiest method writing common function:

var buttons = document.queryselectorall("button");  (var = 0; < buttons.length; i++) {    buttons[i].addeventlistener(      "click",      function() {      var current_value = this.innerhtml; //typed single number      var display_value = document.getelementbyid('display').value; //the value on calculator display      var new_value = display_value + '' + current_value; //+''+ make string      document.getelementbyid('display').value = new_value;    });  }

try , add exceptions , calculation functions same method above filtering '+','-', etc. values.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -