if(): exam pass-rate status without dividing by zero
Medium
A course dashboard shows how each class did in its final exam. You are given how many students took the exam and how many of them passed.
The pass rate is passed ÷ took the exam: 14 passed out of 20 who took it is 14 ÷ 20 = 0.7, which is 70%.
Return
"On track"— the pass rate is 70% or more"Needs attention"— it is below 70%"No results yet"— nobody has taken the exam, that is,ri!tookExamis 0
Watch out
- With nobody tested the pass rate would be 0 ÷ 0, and dividing by zero is an error, so check for zero first.
if()only runs the branch it picks, so a division placed in the other branch never happens.ri!passedis never more thanri!tookExam.
Inputs
ri!passed— Integerri!tookExam— Integer
ri! Rule Inputs
ri!passedInteger17
ri!tookExamInteger20
Example 1 — Most of the class passed
Input: ri!passed
17
Input: ri!tookExam
20
Output:
"On track"
Example 2 — Exactly 70% is on track
Input: ri!passed
7
Input: ri!tookExam
10
Output:
"On track"
Example 3 — Just under 70%
Input: ri!passed
13
Input: ri!tookExam
20
Output:
"Needs attention"
Example 4 — Nobody has taken the exam yet
Input: ri!passed
0
Input: ri!tookExam
0
Output:
"No results yet"
Example 5 — Everyone who took it failed
Input: ri!passed
0
Input: ri!tookExam
12
Output:
"Needs attention"
Appian Expression Tips
- • Use
ri!variableNamefor rule inputs - • Use
a!localVariables(local!x: …, body)for locals - • Use
a!forEach(items: …, expression: fv!item)to iterate - • Use
where()/reject(fn!isnull, list)to filter