kailoon
November 7, 2020, 12:05pm
1
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 https://codepen.io/kailoon/pen/JjKvOBN?editors=0011
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:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
Sky020
November 7, 2020, 12:09pm
2
Hello there,
To an idea of the issue, run the tests, then type in:
5
-
See what the output shows…
kailoon
November 7, 2020, 12:11pm
3
You mean, it should shows -5?
kailoon
November 7, 2020, 12:15pm
4
Oh, I get what you mean now. run the test, then key in the value. I get -0.1300000, no idea why …
Sky020
November 7, 2020, 12:18pm
5
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…
Sky020
November 8, 2020, 2:14pm
7
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'
clearBtn.classList.remove('show')
}
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