Calculator app not working, anyone see what I'm missing?

Hello everyone,

I’m pretty new to coding, but I am putting semester projects into my MS CTE Elective from the App Lab. One of my students wants to try to make a calculator, so I’m playing around with it, to see what he’s in for, and I am so confused with the results I am getting. I looked up a few tutorials on this specific type of app online, and I still can’t figure out why my particular code isn’t working. Any help I can get would be greatly appreciated.

Link to the project or level: App Lab - Code.org
What I expect to happen: I am expecting the “C” button to get rid of every value in the variables xNum and yNum, so that addition operations can continue to give accurate results
What actually happens: For some reason, the values keep getting bigger and bigger, and the results in my calculator do not reflect the correct sum.
What I’ve tried: I have tried logging the values of the 2 variables into the console. They actually return the values I expect most of the time, but results are still random large numbers. I can’t even figure out where the large numbers are coming from, or what the pattern is behind the numbers I am getting.

Never mind, I just figured it out using an AI tutor (just in case anyone else gets stuck on this)

The nested “onEvent” block is what did me in. Ironically, that was one of the things I got from the tutorial I saw. I thought the nested blocks would make it so that I could define the operator and make sure that addition was the thing that happened, in case I wanted to add other operations later. My solution now (which looks like it’s working) is to have another variable called operator that will hold the value of the last operation button pushed. This drove me nuts for 2 days, only for it to be a really simple fix. oh well. Leaving this monument to my incompetence to all who may find it useful.

1 Like