I can't do my calculator

I am working on my calculator project and I have 13/16 tests passing but I have no idea what to do on these last three. It seems way beyond my skill level.


Live page

If anyone can help me I would appreciate it so much! I have been stuck for so long and I have no clue what I can even try and do to solve the last three tests. I feel helpless.

For the following test:

When the decimal element is clicked, a “.” should append to the currently displayed value; two “.” in one number should not be accepted

you are going to need to think how you could first recognize when a number displayed already has a decimal point. There are several ways (i.e. iterating through to check for the character, using regex to test if the character exists). Once you know one already exists, then you just do not let your app append it.

1 Like

@RandellDawson Thank you! That is the one I have been looking at. I am looking back on regex’s as they are very hard but I will look into it! Thanks again! :smile:

Alright, I have been working on it and I have gotten less tests passing but I think I might be going somewhere. Are the additions to my code good or bad?

Live Page

I feel like what I have added should work. Now all it does is DUPLICATE decimals. Test # 12. Also the clearing test #7 and #8 are the same test but both are not working even though the clear button clears everything. I don’t know what is going on anymore and I am really frustrated and doubting my skills.

Your calculator is still permitting a user to enter multiple decimal points and also multiple operators in a row. This is causing your eval to error out. You can see the evals creating during the tests by adding the following line as the first line of your answer function:

console.log('eval(' + $('#display').html() + ')');

When the tests are ran, the following evals are displayed in the console:


These are not valid mathematical expressions, which is why the error occurs.

1 Like