Exerpad
🔥0
0 XP
Lv.1 Beginner
Log In

Fix the Index

Oh no! This code is trying to print the last item in the vector, but it uses the wrong index and crashes!

Fix the code so it prints:

text
cherry

Hint: Remember, vector indexes start at 0. A vector with 3 items has indexes 0, 1, and 2 — not 3!

rust
fn main() {
let fruits = vec!["apple", "banana", "cherry"];
println!("{}", fruits[3]);
}