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 Java Objects (Retired) Creating the MVP Strings and Chars

Dean Onizuka
Dean Onizuka
4,753 Points

task 2 for scrabble game java

can anyone tell me why this does not work for

"Can you also please help me write out the hasTile method? It should return true if the hand has the tile, and false if it doesn't. Thanks!"

public boolean hasTile(char tile) {
      if (mHand.indexOf(tile)) >= 0; {
        return true;
      } else {
       return false;
      }
    }

2 Answers

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Your paren should be after the >= 0 not before it, also no semi-colon there.

Hope it helps!

Dean Onizuka
Dean Onizuka
4,753 Points

sorry if this is a dumb question but why the change of syntax between this 'if/else' statement in the challenge exercise and the 'if/else' statement for the hangman game.

 public boolean applyGuess(char letter) {
    boolean isCorrect = mAnswer.indexOf(letter) >= 0; 
    if (isCorrect) {
      mCorrect += letter;
    } else {
      mWrong += letter;
    }
    return isCorrect;

in this instance only the letter is surrounded by parens. also there is a semi colon at the end of the >=0. just wondering since i know java is very specific.

Lee Reynolds Jr.
Lee Reynolds Jr.
5,160 Points

In the example they both follow the same basic rule that I have noticed. When you are opening a block of code using the "{" you do not use a ";". Also I have noticed that whenever you are opening a new block of code using the curly brackets, you almost always use parens. I'm also a beginner but that's what I have noticed, my word isn't law :) Happy Coding

Dean Onizuka
Dean Onizuka
4,753 Points

ahh i'll keep that in mind. thanks. java seems to be a lot of trial and error lol

Lee Reynolds Jr.
Lee Reynolds Jr.
5,160 Points

haha yeah I've noticed that. I have a lot of errors that I have to take the time and figure out but with the help of Craig and all of the other treehouse team members, you'll always come out on top. The forum is also very very helpful, for it shows people of all levels of learning coming together and sharing their personal encouraging thoughts and ideas to make this thing work. I love this place and I am happy for other students like you on the team.

Dean Onizuka
Dean Onizuka
4,753 Points

for sure. thanks for the input. i'll definitely be seeing you around on the forums