Skip to main content
5/5

if(): write the end-of-term report line

Hard

At the end of term every student gets one line on their report. You are given the student's test scores, in order. A test the student was absent for is null.

Return one of these

  • "No results" when the student has no scores at all: the list is empty, or every test was missed.
  • "Incomplete: 2 missed" when two or more tests were missed, with the real number in place of the 2.
  • "B, average 85.5" otherwise: the grade, then the average of the tests actually taken, rounded to one decimal place.

Grades, by the average

  • "A" for 90 or more
  • "B" for 75 or more
  • "C" for 60 or more
  • "F" for below 60

A missed test is not a zero. {80, null, 91} averages 85.5, over the two tests that were taken.

Watch out

  • count() counts the nulls too, so it is not the number of tests taken.
  • A student who missed everything has taken 0 tests, so check for that before dividing.

Tip: you need the number of tests taken in more than one place. a!localVariables() lets you work it out once and name it; repeating the expression works too.

Input

  • ri!scores: List of Integer, where a missed test is null

ri! Rule Inputs

ri!scoresList of Integer
{
  80,
  null,
  91
}

Example 1: Every test taken

Input: ri!scores
{
  95,
  92,
  90
}
Output:
"A, average 92.3"

Example 2: One missed test is fine

Input: ri!scores
{
  80,
  null,
  91
}
Output:
"B, average 85.5"

Example 3: Just short of an A

Input: ri!scores
{
  89,
  90
}
Output:
"B, average 89.5"

Example 4: A C grade

Input: ri!scores
{
  70,
  61
}
Output:
"C, average 65.5"

Example 5: A failing average

Input: ri!scores
{
  61,
  58
}
Output:
"F, average 59.5"

Example 6: Two tests missed

Input: ri!scores
{
  70,
  null,
  null,
  95
}
Output:
"Incomplete: 2 missed"

Example 7: Every test missed

Input: ri!scores
{
  null,
  null
}
Output:
"No results"

Example 8: No tests yet

Input: ri!scores
{}
Output:
"No results"

Appian Expression Tips

  • • Use ri!variableName for 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