ApexSensei

Drills › Write Apex

Mark a high score

Write Apex · Beginner · 5 min · Runs in the browser, no org needed · Free

Scenario. A score of 80 or more should be marked High. Every other score should be marked Normal.

Use if and else with braces to mark a score of 80 or more as High.

What you will learn

An if chooses one path. Put the test in parentheses and keep { at the end of that line. else covers every other score.

if (score >= 80) {
    priority = 'High';
}

Gotcha. Without braces, only the next statement is part of the test.

The task

Mark a score of 80 or more as High, and every other score as Normal.

Examples:

  • score 80 → priority High
  • score 79 → priority Normal
  • score 100 → priority High

Requirements:

  1. Write an if that tests score >= 80.
  2. Inside that block, set priority to High.
  3. Use else to set priority to Normal.
  4. Put { at the end of the if line and the else line.

Starter code

Integer score = 80;
String priority;
String companyName = 'RidgePoint Capital';
Boolean reviewed = false;

When it passes

An if tests score >= 80 and sets priority to High. The else branch sets priority to Normal.

Try this drill free

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

‹ Build the account label · Return the tier you were given ›