HELP! NO ENTIENDO Build a JavaScript Calculator!

help the console tell me x13. If 2 or more operators are entered consecutively, the operation performed should be the last operator
entered (excluding the negative (-) sign.

No entiendo que hacer

1 Like

So, if you type 8 / * 5, the answer should be 40… in your calculator it answers infinity. There appears to be a bug in your code that doesn’t handle someone trying to change the operator midway through.

Basically test 13 is that your calculator can handle someone hitting multiple operators, meaning they can change it. So if they type 5 /, but then change their mind and want * instead, pressing * should change the operator to *… it seems your algorith is using the 0 that gets displayed after you hit the second operator, and therefore instead of being 5 *+ 5 = 10, it becomes 0 + 5 = 5… I did notice it works correctly if your first operator is a + or -, but breaks with * or /… hope that helps isolate your issue.

thank you so much, i dont know yet how to put all that information in the js but i tried ok

i dont know how to solve this problem

What problem? What specifically is going on?

hi, to solve this exercise i need 16/16 and i have 15/16 and the console tell me :
x13. If 2 or more operators are entered consecutively, the operation performed should be the last operator entered (excluding the negative (-) sign.

i understend but i dont know how to solve , i serch everywhere online and i dont know, maybye try again all the code

To implement that logic I used regex.

i dont know how to do it in that way

Hello again.

So basically you’re calculator has a nice simple flow, taking what has been entered, and putting it to screen… but because a person is weird and may hit buttons in orders they shouldn’t you need to implement some logic to check for these problems, and resolve them… take for instance, try typing this in your calculator:

3 + =

That should return three… but instead it’s putting ‘equals’ into the display… things break shortly after that… your program assumes after hitting the +, the user would type another number.

So there are a lot of ways to solve this… regex, if/then statements, checking functions… you get to decide… simply if you track the “state” of your calculator, you can write logic to check some things… what I mean by this is tracking what was previously pressed…

If someone has previously pressed the + sign, and presses it again, do nothing. If someone has previously pressed the + sign, then hits the equals, ignore the previously pressed +. That kind of thing… Don’t do it exactly like that though because there is tons of button press combinations, but thats the kinda thing I mean. Its messy, but thats what makes it a challenge :slight_smile:

1 Like