Core Beginner

03  Pattern matching

match lets you branch on shape and value at once. Map coins to cents, then classify a point by which axis it sits on.

Step 3 / 3

In apply_bonus, add the bonus only when it is Some -- use if let.

Hints
  • if let Some(b) = bonus { ... } else { ... } -- a match for when you only care about one pattern.
03_match.rs
Reset to starterCompiled in a sandbox; hidden checks must pass.
Reveal solution
fn apply_bonus(score: u32, bonus: Option<u32>) -> u32 {
    if let Some(b) = bonus {
        score + b
    } else {
        score
    }
}