Exerpad
🔥0
0 XP
Lv.1 Beginner
Log In

Fix the Lookup

Oh no! This code tries to look up a value in a HashMap, but it doesn't handle the Option that .get() returns. The code won't compile!

Fix the code so it prints:

text
Alice scored 95

Hint: The .get() method returns an Option, not the value directly. Use if let Some(score) = scores.get("Alice") to safely unwrap it!

rust
use std::collections::HashMap;

fn main() {
let mut scores = HashMap::new();
scores.insert("Alice", 95);
scores.insert("Bob", 87);

let score = scores.get("Alice");
println!("Alice scored {}", score);
}