Return the tier you were given
return sends a value back to the caller.
LessonRead this before the challenge.
A method is a small named piece of code that does one job. It can take input and give back a result:
String echo(String word) {
return word;
}Read the first line from left to right. String before the name says what type comes back. echo is the name. (String word) is the input, called a parameter. Inside the braces, return sends a value back to whoever called the method.
Calling it looks like this:
String result = echo('Hi');Now result holds Hi, because word was 'Hi' for this call.
The trap is returning a fixed value:
return 'Hi';That works when the caller sends Hi, but echo('Bye') also gives back Hi. Return the parameter, and the method works for every input.
Your task
Each member gets a badge that shows their tier. The badge method receives the tier and has to hand that same tier back.
Finish the method badge that takes a String tier and returns tier. Keep the method name and its input, and do not type any tier word yourself.
For example, when the method gets Platinum, it returns Platinum because it hands back whatever it was given.
String badge(String tier) {
return null;
}
Integer attempts = 1;Requirements
- Returns the tier it was given
- Keeps the method name and its tier input
- Returns the tier instead of null
- Works for any tier, not just a fixed
Gold