0
0
Rustprogramming~10 mins

Matching multiple patterns in Rust - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to match the variable against multiple values.

Rust
let x = 3;
match x {
    [1] => println!("Matched 1 or 2"),
    _ => println!("No match"),
}
Drag options to blanks, or click blank then click option'
A7 | 8
B1 | 2
C5 | 6
D3 | 4
Attempts:
3 left
💡 Hint
Common Mistakes
Using commas instead of '|' to separate values.
Forgetting to use a pattern and writing a value directly.
2fill in blank
medium

Complete the match arm to handle vowels 'a', 'e', 'i', 'o', or 'u'.

Rust
let letter = 'e';
match letter {
    [1] => println!("It's a vowel"),
    _ => println!("It's a consonant"),
}
Drag options to blanks, or click blank then click option'
A'a' | 'e' | 'i' | 'o' | 'u'
B'b' | 'c' | 'd' | 'f' | 'g'
C'm' | 'n' | 'p'
D'x' | 'y' | 'z'
Attempts:
3 left
💡 Hint
Common Mistakes
Using double quotes instead of single quotes for characters.
Missing some vowels in the pattern.
3fill in blank
hard

Fix the error in the match pattern to correctly match 10 or 20.

Rust
let num = 10;
match num {
    [1] => println!("Matched 10 or 20"),
    _ => println!("No match"),
}
Drag options to blanks, or click blank then click option'
A[10, 20]
B10, 20
C10 | 20
D(10, 20)
Attempts:
3 left
💡 Hint
Common Mistakes
Using commas to separate values in a pattern.
Using tuple or array syntax instead of pattern matching.
4fill in blank
hard

Fill both blanks to match digits 1-3 and letters 'a' or 'b'.

Rust
let value = 'b';
match value {
    [1] => println!("Digit 1 to 3"),
    [2] => println!("Letter a or b"),
    _ => println!("Other"),
}
Drag options to blanks, or click blank then click option'
A'1' | '2' | '3'
B'4' | '5' | '6'
C'a' | 'b'
D'c' | 'd'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing digits and letters in the same pattern.
Using commas instead of '|'.
5fill in blank
hard

Fill all three blanks to match uppercase vowels, lowercase vowels, and digits 0-2.

Rust
let ch = 'A';
match ch {
    [1] => println!("Uppercase vowel"),
    [2] => println!("Lowercase vowel"),
    [3] => println!("Digit 0 to 2"),
    _ => println!("Other"),
}
Drag options to blanks, or click blank then click option'
A'A' | 'E' | 'I' | 'O' | 'U'
B'a' | 'e' | 'i' | 'o' | 'u'
C'0' | '1' | '2'
D'3' | '4' | '5'
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing uppercase and lowercase characters.
Using incorrect digits or missing some vowels.