I’m building the JavaScript calculator with React and Tailwind css, and while it works fine in the browser, some of my test cases keep failing. Although in manual test I get the required outputs as suggested.
You are not outputting correctly. The inputs and result should be rendered to the element with the display id. Not both the formula and result. You can tell by the test assert that it is reading both.
You can look at the demo project to see how they do it. But all you should need to do is move the id, remove the condition rendering, and use some short circuit logic to render, input or result or zero for the value inside the element with the the display id.
Thanks a lot. I completely missed the display ‘id’ part! Of course it needed to be only in the result line!
My main problem was to deal with consecutive operators, and I thought of dealing with the digit that comes after these operator and then backtrack the last operators. That actually caused the error line you’ve mentioned, it was not there before. I had no idea that eval() automatically handles the ‘-’ operator if it is at the end! but everything is solved now!