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
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
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
Then, I suggest you take some time to know about it.
Cause itās really helpful and will help you to solve so many problems easily.
Or else you can go with conditionals and functions then youāll be doing lots of nesting with them.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.