Yasinkarax Calculator Project

I am trying to do a basic calculator. I will show some colors of buttons when clicked the start button. For this, i am using two loops but only the first loop worked. I didn’t understand the reason.

If I open up your console, I see that your first loop is throwing an error:

pen.js:65 Uncaught TypeError: Cannot read properties of undefined (reading ‘style’)
at showColor (pen.js:65:15)
at startCal (pen.js:45:3)
at HTMLDivElement.onclick (gOXRVrJ?editors=1010:161:54)

In your code:

for(let i = 0; i <= numberLen; i++){

Think really hard about that <=. This is what is called an OBO error or a fence posting error. Think about what the length is. Remember that arrays are 0-indexed.

This is a very common mistake when indexing arrays.

I understand and fixed, thank you.

I’m trying to make a simple calculator. I am directly taken the mathematical operation from the screen and convert it to number with Number() method for the taken value is string.
typeof operator returned number when I convert the value taken from screen so I thought that I can calculate directly the value taken from THE screen. But the result is NaN. I read some solutions here in python code but I want to read other solutions if there are.

I can’t get your pen to do anything to test it.

This is a hard project - it took me a couple of tries.

I would suggest working on the logic first. You’ve put a lot of work into the design of this. I think that is a mistake, especially when you are starting out. The logic is the hardest part when you’re starting out. I might suggest working on a new pen and just getting the logic to work, even simply. Then you can add the styling in there or add the logic in here. Anytime you can break a big project into smaller chunks is a good thing.

1 Like

I asked my last reply on this post as a another question. Then the moderator added here it, I didn’t understand why. I fixed the problem using eval(), thank you. I will try to break big projects into small chunks.

Yeah, the mod probably moved it because they thought it was part of the same question.