Hey, so running your app through the test we get 11/16. I will roughly go over each one, and hopefully you’ll know how to flesh out the details.
test # 7 and 8: You have this error message: ReferenceError: can’t access lexical declaration ‘result’ before initialization
– this means somewhere in your code, you have used the variable name result before it exists.
An example of what that means:
console.log(result); // result doesnt exist yet
let result = 0;
test # 10 and 14: Both are about getting the right results from a calculation
– currently inputting the two tests manually into the calculator doesn’t yield the right result either. Meaning somewhere, your calculation logic is broken.
test # 11: If you input 0 repeatedly into your calculator, currently it becomes 000000.
– The reason is in your handlechange, there’s two big blocks: A: if your calculator is in your initial state, in this state you cannot have leading zeroes. B: if your calculator isnt in your initial state, and you can have more zeroes in the display.
However, no matter what, after one input I see you change the calculator into a non initial state. This means by your second 0, that leading zero checking logic in A is never used.
Test #15: Something is wrong with how you chain calculations. My guess is after an “=” operation, the result isn’t saved as previous, so the next operation ends up having an operand of "".
A good habit to get into is split your code. Think about what a calculator needs, break those down to components, what each component needs to be able to do, break those down into functions. This way, every time something goes wrong, you can roughly know which function to look through, instead of having to sift through one big function every time.
This calculator one seems simple but I think it’s more complex than it lets on. Have you completed the other react challenges already? I have learned a TON about react (including switching to hooks/context instead of the classed components taught in the lessons) by having to read documentation on newer react versions in order to complete the first three challenges of this series.