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 trialJames Kane
Front End Web Development Techdegree Student 3,070 PointsI thought I had this, anyone have any idea what im doing wrong?
error message was that the return statement was unexpected, however when I remove it the error message is 'return statement missing'. No clue. Help please
public class Order {
private String itemName;
private int priceInCents;
private String discountCode;
public Order(String itemName, int priceInCents) {
this.itemName = itemName;
this.priceInCents = priceInCents;
}
public String normalizeDiscountCode(String discountCode) {
discountCode = discountCode.toUpperCase();
} return discountCode;
public void applyDiscountCode(String discountCode) {
this.discountCode = discountCode;
discountCode = normalizeDiscountCode(discountCode);
}
}
2 Answers
Steve Hunter
57,712 PointsHi James,
There's two issues here. First, as Felix pointed out, your return
statement has crept outside of the method. You need to put that back inside it - and you can clean that up a little too. Just return the expression - don't assign it to something first. So, inside the method, you can return
the discountCode
modified with .toUpperCase()
.
Next, in your applyDiscountCode
method, you want to assign the normalised discountCode
to this.discountCode
. You've done the call correct, but do it all on one line. So, start with this.discountCode
and then assign with =
the returned value coming back from normalizeDiscountCode()
, remembering to pass the existing discountCode
into that as a parameter.
I hope that helps - shout back if not.
Steve.
Felix Sonnenholzer
14,654 PointsHi,
it is important that the return
statement is within the code block of the method, that means inside the {}
James Kane
Front End Web Development Techdegree Student 3,070 PointsJames Kane
Front End Web Development Techdegree Student 3,070 PointsI got it Steve thanks a lot.
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsGood work!
Now on to checking the
discountCode
for letters and dollar signs. Argh!Steve.