Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print "small" when the number is less than 10.
Rust
let num = 5; match num { x if x [1] 10 => println!("small"), _ => println!("big"), }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' in the guard.
Using '==' which only matches exactly 10.
✗ Incorrect
The match guard uses '<' to check if the number is less than 10.
2fill in blank
mediumComplete the code to print "even" when the number is even using a match guard.
Rust
let num = 8; match num { x if x [1] 2 == 0 => println!("even"), _ => println!("odd"), }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '/' instead of '%' which does division, not remainder.
Using '+' or '-' which are arithmetic operators but not for checking evenness.
✗ Incorrect
The '%' operator is used to find the remainder. If remainder is 0 when divided by 2, the number is even.
3fill in blank
hardFix the error in the match guard to correctly check if the character is a vowel.
Rust
let ch = 'a'; match ch { c if c == 'a' || c == 'e' || c == 'i' || c == 'o' || c [1] 'u' => println!("vowel"), _ => println!("consonant"), }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '==' in the condition.
Using '!=' which checks for inequality.
✗ Incorrect
The equality operator '==' is needed to compare c with 'u'. Using '=' causes a syntax error.
4fill in blank
hardFill both blanks to create a match guard that matches numbers between 1 and 5 inclusive.
Rust
let num = 3; match num { x if x [1] 1 && x [2] 5 => println!("between 1 and 5"), _ => println!("out of range"), }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '<=' excludes 5.
Using '>' instead of '>=' excludes 1.
✗ Incorrect
The guard checks if x is greater or equal to 1 and less or equal to 5.
5fill in blank
hardFill all three blanks to create a match guard that matches even numbers greater than 10.
Rust
let num = 12; match num { x if x [1] 2 [2] 0 && x [3] 10 => println!("even and greater than 10"), _ => println!("other"), }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '/' instead of '%' for even check.
Using '<' instead of '>' for greater than check.
Using '=' instead of '==' for comparison.
✗ Incorrect
The guard uses '%' to check evenness, '>' to check greater than 10, and '==' to compare remainder to 0.