JS Calculator Challenge - Tests won't pass, don't understand why

Tell us what’s happening:

Hello Campers!

I just finished coding the 4th frontend project - JS Calculator.
Everything seems to be working fine, but only 9 tests pass out of 16. I really don’t understand why.

All of them are related with the element which has an id ‘display’, maybe the problem lays there but still, no idea… Can somebody please help me ? :slight_smile:

Your code so far

https://codepen.io/dhubgrob/full/vYyjLzz

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36.

Challenge: Build a JavaScript Calculator

Link to the challenge:

First, it’s a bad practice to use divs as buttons.
Second, if you decide to use divs you should handle onClick method.

I think you’ve got some issues with the number 0. If the first number I click is 0 then I get “ERROR” in the display.

Also, I agree with @jenovs, these are <button>s. In order to use <div>s here you would not only need to handle the click event but also the keypress event and both Enter and Space bar would need to trigger a click. Instead of doing all that extra work, just make them <button>s.

Ok thanks a lot, I didn’t know about the buttons!
Now I still have work to do on the algorithmic side…
Thanks again @jenovs and @bbsmooth :slight_smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.