JS Calculator Testing issues

Hi, I built this Vanilla JS calculator and as far as I know it functionally passes every test, but the FCC testing suite indicates only 9 tests pass. I’ve spent hours trying to debug this project and even involved ChatGPT as a last resort and still cant figure out why it wont pass the seven remaining tests. Can anyone give me any insight at all as to what the bugs might be? Here is the CodePen link https://codepen.io/lowcities/pen/XWzjQaJ

Many Thanks!

Hello, pal. Hope you are doing good.

First i want to say the animation at button click is so cool. Good job!

So, i looked up at your code and founded a such confusing statements that could be a source of all kind of bugs and be difficult to debug. I recommend you using eval() to evaluate the expression that are in your display. And recomend too keep all the numbers and operands in your display and just change it at the moment you click in =. The only issue with eval is that someone can put malicious code in your app. But you can avoid this doing some validation of your expression before you evaluate it, like if the variable that will have the string that represents the expression should be only numbers and operands and if not, show some message at the display. To avoid error in eval() you can put it into a try/catch statement to avoid your app broke if the user put bad expression on that like 1 + / 4 5 that js engine couldn’t reconize and came into an error. For further information about eval you can look at here: JavaScript eval() Method.

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