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 trialBen Morse
6,068 PointsTrouble with the CharS challenge.
I'm stuck on a challenge code. I have to use CharS to compare one char to another char. I thought the syntax for it was
if (lastName.charS() >= 'M')
but i'm getting a class error.
public class ConferenceRegistrationAssistant {
public int getLineFor(String lastName) {
/* If the last name is between A thru M send them to line 1
Otherwise send them to line 2 */
int line = 0;
char letter = '';
if (lastName.charS(letter) >= 'M') {
line = 1;
} else {
line =2;
}
return line;
}
}
1 Answer
James Simshaw
28,738 PointsWhat the challenge is asking is to compare the first letter of the last name which would be done by getting the first character of the lastName string. The part in the description saying "chars can be compared using the > and < symbols." is just saying that you can take a char variable and use basic comparisons just like int variables. There is no charS function involved. Its only a typographical issue that makes it even look like it.
Ben Morse
6,068 PointsBen Morse
6,068 PointsAh i see. I was thrown off again. Happened in one of his earlier challenges
Ben Morse
6,068 PointsBen Morse
6,068 PointsOkay It worked. Thanks a bunch...it was driving me mad.