Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using commas instead of '|' to separate values.
Forgetting to use a pattern and writing a value directly.
✗ Incorrect
The pattern '1 | 2' matches if x is 1 or 2.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using double quotes instead of single quotes for characters.
Missing some vowels in the pattern.
✗ Incorrect
The pattern matches any vowel character.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using commas to separate values in a pattern.
Using tuple or array syntax instead of pattern matching.
✗ Incorrect
Use '|' to match multiple values in a pattern, not commas or brackets.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing digits and letters in the same pattern.
Using commas instead of '|'.
✗ Incorrect
The first blank matches digits '1', '2', or '3'. The second blank matches letters 'a' or 'b'.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing uppercase and lowercase characters.
Using incorrect digits or missing some vowels.
✗ Incorrect
The blanks match uppercase vowels, lowercase vowels, and digits 0 to 2 respectively.