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 trialAlex Popian
977 PointsWhat am I doing wrong? Can someone please help me understand?
First of all, I have no idea what I'm doing... I took a break from coding and now I'm going at it again hoping to understand it better than I did the first time but it's the complete opposite. I went over the last 3 videos before I stopped and I still can't figure out how to complete this challenge. I took a 2 week break and now I can't even understand what "int line = 0" is meant to do. Can someone point me in the right direction so that I may understand a bit of what is going on? Thank you for your time :)
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 */
char firstLetter = lastName.charAt(0);
if (firstLetter <= 'M') {
int line = 1;
} else {
int line = 2;
}
int line = 0;
return line;
}
}
2 Answers
Jennifer Nordell
Treehouse TeacherHi there! Would it encourage you to know that you're really not that far off? The majority of the problem lies in you not understanding the int line = 0
line and what it does. This is a declaration of an integer variable named "line". So with very few modifications, your code passes. Take a look:
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 firstLetter = lastName.charAt(0);
if (firstLetter <= 'M') {
line = 1;
} else {
line = 2;
}
return line;
}
}
We declare our integer variable and set it equal to 0. Why? Because we don't yet know which line the user is supposed to go in. But after we figure that out, we assign them to the correct line. But every time you write int line
, you are redeclaring that variable. We only declare it once, and then reuse it over and over.
By the way, I do not recommend taking a two week break from coding. I do sometimes take breaks, but I try to limit myself to 48 hours maximum without looking at some form of code. The longer you wait in between, the more likely it is to look like ancient Egyptian algebra when you return.
Hope this helps!
Alex Popian
977 PointsI actually remember now! Thanks for the help. In my mind, I forgot that when we said in line = 0 we were declaring line as a variable and now it is all coming back to me. Thanks so much for putting me back on track and the reason for the long break was that I had no internet while I was gone so I had no choice but will keep in mind in the future.