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 trial

Java

could someone help me with this idk whats wrong

The compiler says line 12 and 40 are wrong but i dont see how

import java.io.Console;

public class Prompter {
  private Game mGame;

  public Prompter(Game game){
    mGame = game;
  }

  public void play() {
    while (mGame.getRemainingTries() > 0 && !mGame.isSolved()) {
      displayProgress();
      promptForGuess();
    }
  if (mGame.isSolved()) {
    System.out.printf("Congratulations you won with %d tries remaining.\n",
                      mGame.getRemainingTries());
  } else {
    System.out.printf("Bummer the word was %s.  :(\n",
                      mGame.getAnswer());

    } 
  }
  public boolean promptForGuess() {
 Console console = System.console();
    boolean isHit = false;
    boolean isValidGuess = false;
    while (! isValidGuess) {
      String guessAsString = console.readLine("Enter a letter:  ");   
    try {
      isHit = mGame.applyGuess(guessAsString);
      isValidGuess = true;
    } catch (IllegalArgumentException iae) {
    console.printf("%s.  Please try again.\n", iae.getMessage());
    }
      {
    return isHit;
  }

  public void displayProgress() {
  System.out.printf("You have %d tries left to solve: %s\n", 
                    mGame.getRemainingTries(),
                    mGame.getCurrentProgress());
   }
  } 
 }
}

post your code or link to workspace please ... we cant help you with just that.

2 Answers

Just above line 40 you end the previous method with stray curly brace. You also have too many close curly braces to end the file.

      {  // <-- this shouldn't be a close brace here (for the while loop), it messes up the nesting.
    return isHit;
  }

thanks! but now it says on line 12 it cant find the d in displayProgress();

I see, the curly brace above the return should be a closing brace for the while loop. It's a bit hard to keep track of the braces when the code isn't consistently formatted.

Thank You Mr. Kroger