JS Calculator Not all tests passing

hey guys i am working on the “Build a JavaScript Calculator” project in the “front end libraries” certification and am nearly passing all tests but I have a few that are failing.

my codepen is here: https://codepen.io/notcode5/pen/WNwOJoX

as you can see, four tests are not passing. those are 7, 10, 11, and 13.

10, 11, and 13 are all related and basically is the same general error. and that is just where it says that if it has multiple decimal points (test 11), multiple zeros at start of a number (test 10), or multiple consecutive operators (test 13), the code should automatically not accept it.

I don’t know how to make it to where the code does not accept these three things so any help on this would be appreciated.

ALSO, dont forget about good ol test number 7! test 7 is unrelated to the three aforementioned tests and is completely its own thing. test 7 just says that when the clear button is pressed, it should clear all the input and output values (which it does) but the reason why test 7 fails is because even though the clear button does its job, IT DOESN’T SHOW 0 IN THE DISPLAY ON PRESS.

so yeah, it clears the values but it doesn’t show zero in the resetted display. instead it just shows nothing in the display (aka a blank display). this little extra detail in test 7 is a real hassle and annoyance and i feel that it is negligible but I guess I have to do it to pass the test :expressionless: (honestly I like it better blank, instead of the zero like in most calculators)

so again, any help on this issue (test 7) would be appreciated also.

And that is it! All other tests are passing as of now, 12 out of 16. which is pretty good tbh, the calculator works otherwise, just these little details are preventing me from moving on.

thanks!

Regarding test number 7, the default state (answer.value) should display a “0” after you clear the formula.

yes i know this, i do not know how to do so… thats why i posted

My apologies, I sort of skimmed your post quickly. For a few of the tests, you might want to consider having logic/functions specific to the decimal and operators buttons respectively. Though a few tests were solved with updating your pushToScreen() function like this:

function pushToScreen(x) { 
  if (x === "c") {
    answer.value = "0";
  } else if (x !== "c" && answer.value === "0") {
    answer.value = x;
  } else {
    answer.value += x;
  }
}
1 Like

I forked you calculator and hacked at the JS a bit, so you can definitely improve it. But good news, there’s only one more test to pass. Take a look:

I left some comments, but let me know if you have any questions. My thoughts on the final test start at line 20

1 Like

OKAY, thank you very much for all of your help and feedback, the final test shouldnt be too hard to pass :crazy_face: @kclarke.design

1 Like