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→ priorityHigh - score
79→ priorityNormal - score
100→ priorityHigh
Requirements:
- Write an
ifthat testsscore >= 80. - Inside that block, set
prioritytoHigh. - Use
elseto setprioritytoNormal. - Put
{at the end of theifline and theelseline.
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.
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 ›