Reactjs JavaScript calculator Help

Guys please I need your help in solving User stories #11 and #13 in my JavaScript Calculator. Any help will be appreciated. Thanks in advance

Welcome there.

Let us take a look at the error:

An input of “5 . . 0” should display 5.0 : expected ‘5…0’ to equal ‘5.0’

Now, you will need to create some sort of conditional check that recognises if a number already has a decimal point in it, and, if true, should not allow another to be inserted.

The second error message:

The sequence “5 * - + 5” = should produce an output of “10” : expected ‘-25’ to equal ‘10’

So, one way to tackle this, is to check:

  1. Two or more operators are consecutively input, and neither is the - operator: Then use only the latest input operator.
  2. Three or more operators are consecutively input: Then, use only the latest input. (regardless of whether operator is - or not)

You already have the functionality to correctly calculate the sequence: 5*-5.

If there is anything specific you are struggling with, ask a specific question.

Hope this helps

2 Likes

Thanks though. I understand the question just need help in how to solve both questions. I need the answers

Hmm… Well, we will not give you the answers, and discourage users who do. We will gladly help you find your way, and provide hints, but other than sudo-code, it would not be beneficial to give you much else.

Perhaps, if you are really struggling with the logic, take a break, learn some other things, complete some other projects, and, when you return, it will be that much easier. Usually does the trick for me.

Thanks. I do appreciate your help