JS Calculator Challenge: help needed!

Hey all,
I’m resuming my work on the FCC curriculum and I’ve been tackling this one since yesterday. I was pretty lost so I followed a tutorial until I felt comfortable and took it from there. All tests but 14 and 15 fail. My ultimate goal was to use eval on a string taken from the display as the user clicks all the buttons.

github repo
live version
I’m lost at this point so I would like some guidance on how to get all tests to pass. I’m open to any comments about my code too!

Thanks in advance.

bump, I’d love some help here!

I see in multiple instances where you do something like:

if (this.currentNumber != [])

What is it that you are checking here?

Hey Cary, thanks for checking out my code and answering.

I’m doing this check so I don’t try to pop something in an empty array. I’m doubting now if pop() handles that already, but I placed it just in case. Do you believe this is problematic?

Yes, this if (this.currentNumber != []) does not check if an array is empty, and in fact that if statement will always execute as this this.currentNumber != [] is always true.

When you use an object such as an array in a if statement it uses the identity of the array, and not any actual information about its contents.

To check if an array was empty you would would look at its length property which would tell you how many elements are inside of it. An example:

const a = [];
console.log(a.length) //0

const b = [4,5,6];
console.log(b.length) //3

Thank you so much. I missed a lot here for sure. I’ll try this tomorrow and report back.

I set up a Codepen forked from yours and edited it in the main post. Feel free to delete your pen. Also thanks for this tip.

1 Like


I’ve been busy these days, and came back to check this. I took your tip and corrected that line of code. While that didn’t automatically solve the tests I’m struggling with, I think I’m closer now. As it is right now I’m satisfied.

If someone wants to peek in and check what could be going wrong with those I’d appreciate it. I definitely don’t want to make big changes in logic or start over again.


This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.