Exerpad
🔥0
0 XP
Lv.1 Beginner
Log In

Fix the Push

This code tries to add items to a vector, but it won't compile! There's a problem with how the vector is declared.

Fix the code so it prints:

text
red
green
blue

Hint: If you want to change a vector (like adding items with .push()), you need to make it mutable!

rust
fn main() {
let colors: Vec<&str> = Vec::new();
colors.push("red");
colors.push("green");
colors.push("blue");
for color in &colors {
println!("{}", color);
}
}