Skip to content
Advertisement

How to check game win and display win message Java

I have created a program where you need to decode the word “program” however I am trying to detect when the user wins and matches all the letters, I am trying to display this but I am facing an issue where, even when all the letters in the word match a winning message is not displayed

my code

”’

JavaScript

”’

Advertisement

Answer

Do not use the == operator to compare Strings. Use the equals(..) method.

JavaScript

Strings are objects so using the == operator will check if they are the exact same object. This will work if you are pointing to the same String reference but may not if you are trying to compare two separate references.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement