Score a risk

A risk matrix turns two guesses, how likely and how bad, into one number you can sort by.

What to build

For each risk, multiply its likelihood by its impact and print the score with its level.

Requirements

  • Each line has a likelihood and an impact, both 1 to 5.
  • Print the score and the level, separated by a space.
  • Levels: 15 to 25 critical, 10 to 14 high, 5 to 9 medium, 1 to 4 low.

Input

One risk per line: likelihood and impact, separated by a space.

Output

One line per risk: score and level.

Constraints

1 to 30 risks.

Example

Input:

4 4
3 2

Output:

16 critical
6 medium

Why it works

The score is the product of the two parts, and checking the bands from the top down gives each score exactly one level.

Examples

Example 1 · Input
4 4
3 2
Expected output
16 critical
6 medium
Example 2 · Input
2 5
1 4
Expected output
10 high
4 low

Hints

Hint 1

line.split(" ").map(Number) turns "3 4" into [3, 4].

Hint 2

Check the highest band first.

Solution

Show one correct solution (try it yourself first)
function level(score) {
  if (score >= 15) return "critical";
  if (score >= 10) return "high";
  if (score >= 5) return "medium";
  return "low";
}
let line = prompt();
while (line !== null) {
  const [l, i] = line.trim().split(/\s+/).map(Number);
  const score = l * i;
  console.log(`${score} ${level(score)}`);
  line = prompt();
}

▶ Open this solution in the compiler, then press Visualize to watch it run step by step

Lesson: Threats, vulnerabilities and risk →