Skip to content
Advertisement

Why functions are not working properly in my calculator?

Can you help me identify where’s the problem with this code? I’m a beginner at coding and very likely I’m missing something obvious, but here’s my problem.

When clicking on numbers it seems to work fine, also adding gets to clear the display and (I think) it stores the value in its variable (operandA) but not getting the rest to work, nor the rest of the operands nor the “equals” button.

I have this JS code:

JavaScript

And this HTML code:

JavaScript

Of course, it’s not finished. My aim is to keep on adding features to it, so as to learn while tweaking it.

Thanks in advance!

PS: Yes, there is a raw style sheet in CSS:

JavaScript

Advertisement

Answer

At a first glance, you had a syntax error inside your Javascript code. You were selecting the substract DOM element like this document.getElementById("substract") while in your HTML DOM you had it like this id="subtract"

I attached a snippet of your code in my answer. I think you also missed the modulo operator case in your code. It didn’t do nothing.

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement