Cannot pass the javascript calculator test

Tell us what’s happening:
The test result shows 5 failures. However, I test it with the suggestion value and I am getting the correct answer except test #13, 5 * - 5 = -25, I get 0. Any help will be appreciated. Thanks!

Your code so far
My code so far

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36.

Challenge: Build a JavaScript Calculator

Link to the challenge:

Hello there,

To an idea of the issue, run the tests, then type in:

  1. 5
  2. -

See what the output shows…

You mean, it should shows -5?

Oh, I get what you mean now. run the test, then key in the value. I get -0.1300000, no idea why …

Right. It just shows there is a small logical error in the code, which, if you can find, will likely fix all the tests failing afterwards.

I might be able to take a look later. So, will leave it to you/others for now.

1 Like

Thanks. Been trying to fix it in the last couple of hours. No luck…

Here is the issue:

if (type === 'clear') {
    const clearBtn = calculator.querySelector('#clear')
		if (key.textContent === 'AC') {
			calculator.dataset.firstValue = ''
			calculator.dataset.modValue = ''
			calculator.dataset.operator = ''
			calculator.dataset.previousKeyType = ''
		} else {
			key.textContent = 'AC' 

Click for spoiler:

Whilst it is a useful feature - having this CLEAR CURRENT option - the tests do not make mistakes, and need to clear the current value. The tests expect the state to be fully reset, when #clear is clicked.

Hope this helps