+ 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

7th Nov 2021, 7:13 PM
Billy Beagle
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)
7th Nov 2021, 7:24 PM
Lisa
Lisa - avatar
+ 3
Changed line 19 +24 You are using a wrong logic at line 24. https://code.sololearn.com/cND28Pyvjq6T/?ref=app
7th Nov 2021, 7:29 PM
Coding Cat
Coding Cat - avatar
+ 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?
7th Nov 2021, 7:32 PM
Billy Beagle
+ 1
Billy Beagle Check Coding Cat 's code :)
7th Nov 2021, 7:33 PM
Lisa
Lisa - avatar
+ 1
Lisa Coding Cat Thank you both!
7th Nov 2021, 7:36 PM
Billy Beagle
+ 1
No problem Billy Beagle . Unfortunatelly not always the state is updated here in time.
8th Nov 2021, 8:09 AM
JaScript
JaScript - avatar
0
JaScript Ive already solved the code, but thanks for your time anyway! :)
7th Nov 2021, 7:47 PM
Billy Beagle