Problem with showing the results in my Calculator app with this.id

im having trouble using this.id as it doesnt return any value.

https://jsfiddle.net/o432v0L5/

I’m at the point where I want the number to be shown when I press it but it just doesnt work.

for (var i = 0; i < operator.length; i++) {
  operator[i].addEventListener('click', function (e) {
    alert(this.id)
  })
}


var number = document.getElementsByClassName('number')
for (var i = 0; i < number.length; i++) {
  number[i].addEventListener('click', function () {
    var output = getOutput()
    if (output != NaN) {
      output = output + this.id;
      printOutput(output)
    }
  })
}```

1 Answer

Have you tried

for (var i = 0; i < operator.length; i++) {
  operator[i].addEventListener('click', function (e) {
     alert(this.innerText);
  })
}

Archive from: https://stackoverflow.com/questions/59070191/problem-with-showing-the-results-in-my-calculator-app-with-this-id

Leave a Reply

Your email address will not be published. Required fields are marked *