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 trialGonzalo Torres del Fierro
Courses Plus Student 16,751 Pointsmissing return statement...what i did wrong..?
i think i.m close...but
public class Tweet {
private String text;
public static final int MAX_CHARS = 140;
public int result;
public int getRemainingCharacterCount(){
result = MAX_CHARS - text.length();
if(result>=0){
return result;
}
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
3 Answers
markmneimneh
14,132 PointsHello
The problem is here
public int getRemainingCharacterCount(){
result = MAX_CHARS - text.length();
if(result>=0){
return result;
}
}
what if the 'if' statement is false? what is being returned?
you need an else
or you can return some default value, depending on what the challenge is asking you to doo
example
public int getRemainingCharacterCount(){
result = MAX_CHARS - text.length();
if(result>=0){
return result;
} else{ retun 1}
}
or
public int getRemainingCharacterCount(){
result = MAX_CHARS - text.length();
if(result>=0){
return result;
}
return 1
}
these are just examples to point you into the right direction
if this answers your question, please mark the question as answered.
Gonzalo Torres del Fierro
Courses Plus Student 16,751 Pointshello, the problem, is there is no need of a if statement, we just need to return a value.. in this particular case, i found out this simple solution:
public int getRemainingCharacterCount(){ return MAX_CHARS - text.length();
}
markmneimneh
14,132 Pointsnope ... your code is not correct. you must account for a case when result < 0. What happens then?
Gonzalo Torres del Fierro
Courses Plus Student 16,751 Pointswell i check back my solution, and it works...i mean passed the challenge....so i can not understand, why you said that my code it is worng??, may be not perfect, not the best solution, but works... did you really try my way?.. regards Mark
Gonzalo Torres del Fierro
Courses Plus Student 16,751 Pointsyou are right, but on the challenge request, the scope for me, is "return the value" not a validation, as you probably thinking correctly by the way....but for a starting guy like me the challenge it is covered with the small code...