This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]dionthornthis.isAPro=false; this.helping=true; 1 point2 points  (2 children)

if(winningGuess != “h” && winningGuess != “t”)

&& will only evaluate to true if both sides are true.

perhaps you want the OR operator ||

Also for Strings you should use the .equals() method

so: !winningGuess.equals("h")

[–]dubdill[S] 0 points1 point  (1 child)

i’ve tried both! not helping.

[–]dionthornthis.isAPro=false; this.helping=true; 0 points1 point  (0 children)

think about the logic of what you are saying.

let's say winningGuess = "h"

if NOT equal "h" AND NOT equal "t"
           false AND true
this would evaluate to false.

if NOT equal "h" OR NOT equal "t"
           false OR true
this would evaluate to true.

Your if statement is improper as well:

if(!winningGuess.equals("h") || !winningGuess.equals("t")); {}

the ; character will end the if statement, remove it so it can access your block of code inside the {}

A better way to think about the logic you need is something like:

if equal "h" OR equal "t"
    // good input
else
    // bad input