Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialHerry Suvandy
1,745 PointsWhy we need |isAcceptable = false| while we can use isHit to loop when statement is false ??
why need isAcceptable if we just can loop using isHit ?? *I already tried this and it's work exactly same.
public boolean promptForGuess(){
boolean isHit = false;
Scanner scanner = new Scanner(System.in);
do{
System.out.printf("Enter a Letter : ");
String guessInput = scanner.nextLine();
System.out.println();
char guess = guessInput.charAt(0);
try{
isHit = game.applyGuess(guess);
}catch(IllegalArgumentException iae){
System.out.println(iae.getMessage());
}
}while(isHit = false);
return isHit;
}
1 Answer
lap Nguyen
715 Pointshe also mentioned in the vids that there are more than one way to solve a problem. I ran into this problem myself. I put
(! isAcceptable) and it showed error. When I changed it to while(isHit=false): that worked. thanks for the post Herry.
Karlyn Gibson
9,176 PointsKarlyn Gibson
9,176 PointsI wondered the same thing, but since no one has answered, I'll take a stab at why isHit and isAcceptable are used. First, isHit is supposed to check whether a letter that has been guessed is in the final answer (in our case, whether a guess is in 'treehouse'). isAcceptable is used to check whether a guess is valid (the guess is a letter, has not been guessed before, and has been normalized to be lowercase). It appears that isHit and isAcceptable will always hold the same value (true or false), but perhaps it is important to separate these two checks because one is checking against the answer and one is checking against our validation efforts. Perhaps it is possible to be a miss and and have isAcceptable be true, in which case isHit would still be false.