Front End Development Libraries Projects - Build a JavaScript Calculator

Tell us what’s happening:

All of the tests pass

Except for 13

Which I find strange because if 2 or more operators are entered consecutively, the operation performed is the last operator (excluding the - operator ); in other words, it should pass.

I focused on understanding the logic first before using React, and that led to quite the messy code, so I’ll apologize beforehand for that, but please have a look at it and help me out:
https://codepen.io/T-tsuuu/pen/ByNOpdo?editors=0011

Another question:
If it fails because of how the test is carried out, but the app actually functions right, would I be able to submit it then? Or should I make sure that it passes all the tests?

Thank you for your time!

Your code so far

https://codepen.io/T-tsuuu/pen/ByNOpdo?editors=0011

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36

Challenge Information:

Front End Development Libraries Projects - Build a JavaScript Calculator

If you look at the errors:

13. If 2 or more operators are entered consecutively, the operation performed should be the last operator entered (excluding the negative (-) sign.

TypeError: memory[i] is undefined (https://cdpn.io/cpe/boomboom/pen.js?key=pen.js-3252c055-5e28-4449-2923-7a9ec386e453:185)
FCC_Global</</a/Ua.on/a.onerror@https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js:581:13785
FCC_Global</ie/e/<@https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js:581:112350
p@https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js:581:94539
FCC_Global</n/H/<@https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js:581:95877
FCC_Global</n/O/</<@https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js:581:94902
r@https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js:1:1169
s@https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js:1:1381

There is this error: TypeError: memory[i] is undefined

The test is doing something unexpected. You can try to use console.log to analyze exactly what the test is doing that’s causing a problem.

1 Like

I commented out all of the console.log lines because it was too busy.

I added this at line 185 which was causing the error:

    console.log(i)
    if (i === 1) console.log(memory)

and got this output:

1 // this is `i`

// [object Array] (1)
[// [object Object] 

{

  "unit": "5",

  "operator": "*"

}]

TypeError: memory[i] is undefined 

Looks like there is only 1 entry in this array at position 0.

1 Like

I finally passed all 16 tests

I had been stuck on that 13th test for over 7 hours, without you pointing out where the problem was, I would have spent even more hours on it

Thank you from the heart, man!

1 Like