Return the tier you were given
Write Apex · Beginner · 5 min · Runs in the browser, no org needed · Free
Scenario. A badge method should echo the tier it received. Return that parameter instead of a fixed word.
Return the tier passed into the method instead of a fixed word.
What you will learn
return sends a value back to the caller. Returning the parameter hands back whatever was passed in.
String badge(String tier) {
return tier;
}
Gotcha. A fixed word such as Gold ignores the tier the caller sent.
The task
Make badge hand back the tier it was given.
Examples:
badge('Gold')→ Goldbadge('Silver')→ Silver
Requirements:
- Return the
tierparameter. - Keep the method name
badgeand theString tierparameter. - Do not return a fixed word such as Gold.
Starter code
String badge(String tier) {
return null;
}
Integer attempts = 1;
When it passes
`badge` still takes a String tier and returns that tier. A hardcoded Gold does not pass.
You write the Apex yourself. ApexSensei runs it and tells you what passed and what did not.