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 trialSafira Nugroho
3,910 Pointserror: cannot find symbol?
Hi,
I've tried back and forth trying to compare my code to Craig's and other people's in the discussion board, but I can't seem to find what's the problem, so I hope somebody can help me with this.
Below is my code, which I think is exactly the same with Craig's:
public class Game {
private String mAnswer;
private String mHits;
private String mMisses;
public Game(String answer) {
mAnswer = answer;
mHits = "";
mMisses = "";
}
public boolean applyGuess(char letter) {
boolean isHit = mAnswer.indexOf(letter) >= 0;
if (isHit) {
mHits += letter;
} else {
mMisses += letter;
}
return isHit;
}
public String getCurrentProgress() {
String progress = "";
for (char letter: mAnswer.toCharArray());
char display = '-';
if (mHits.indexOf(letter) >= 0) {
display = letter;
}
progress += display;
return progress;
}
}
But when I try to run it in the console, it says:
./Game.java:26: error: cannot find symbol
if (mHits.indexOf(letter) >= 0) {
^
symbol: variable letter
location: class Game
./Game.java:27: error: cannot find symbol
display = letter;
^
symbol: variable letter
location: class Game
2 errors
Anyone knows what's the problem here? I'd very much appreciate the help!
3 Answers
Craig Dennis
Treehouse TeacherTake a peek at your for
loop. Something seems a little wonky near the end of it.
Michael C
3,230 Pointsmeh ignore my answer - Craig made a better approach on your problem it seems. Sry for my jibberish ;P
Safira Nugroho
3,910 PointsOops! It's always the little things. Thank you! :-)
Michael C
3,230 Pointspublic String getCurrentProgress() { //your code }
In this method you're using the char var "letter". But actually it doesn't exist there. You should bring it into the method scope as a parameter like you did in:
public boolean applyGuess(char letter)
Miguel Gonzalez Rocha
2,849 PointsYour for loop ends with ";" and you are supposed to open "{}"
Mark VonGyer
21,239 PointsMark VonGyer
21,239 PointsHi there. if you get this error; the majority of the time it relates to a mispelling in your code.
I would check letter in all places it is mentioned to make sure it is spelt consistently.