+ 1
Code always acts the same, despite conditions
I'm trying to create a betting simulator (with no prize, only win or lose results). You have to guess if the number is even or odd. If you guess correctly, you win. If you fail, you lose, Also, it should announce you if you didn't enter a valid type, and only if you didn't. But whatever you do, the code always thinks you lost and you have not entered a valid type. The output is the same, despite multiple if() statements. https://code.sololearn.com/cZq4b8w3yg9C/?ref=app
7 Answers
+ 5
Do not compare strings with == (this compares for identity of instance â not the content of the strings)
Rather use the .equals() method for comparison. For example:
bettedType.equals(trueType)
+ 3
Changed line 19 +24
You are using a wrong logic at line 24.
https://code.sololearn.com/cND28Pyvjq6T/?ref=app
+ 1
Lisa Thanks, it works! However the last if() statement is still broken. I've tried using !bettedType.equals() but it does the same. Any suggestions?
+ 1
Billy Beagle
Check Coding Cat 's code :)
+ 1
Lisa Coding Cat Thank you both!
+ 1
No problem Billy Beagle . Unfortunatelly not always the state is updated here in time.
0
JaScript Ive already solved the code, but thanks for your time anyway! :)