As you are getting elements by classname chances are that what is being returned to you are not numbers, they are probably DOM nodes or even strings. To start fixing it you should first console.log(number) this number variable of yours to check what is being returned by this let number = document.getElementsByClassName("number"); line