ApexSensei

Drills › Write Apex

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') → Gold
  • badge('Silver') → Silver

Requirements:

  1. Return the tier parameter.
  2. Keep the method name badge and the String tier parameter.
  3. 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.

Try this drill free

You write the Apex yourself. ApexSensei runs it and tells you what passed and what did not.

‹ Mark a high score · Hello, ApexSensei ›