0
0
Rustprogramming~10 mins

Boolean type 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 declare a boolean variable named is_active with the value true.

Rust
let is_active: bool = [1];
Drag options to blanks, or click blank then click option'
A"true"
BTrue
Ctrue
D1
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using uppercase True instead of lowercase true
Using 1 or "true" as boolean values
2fill in blank
medium

Complete the code to assign the result of a comparison to a boolean variable.

Rust
let is_equal: bool = 5 [1] 3;
Drag options to blanks, or click blank then click option'
A==
B!=
C=
D>
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using single = instead of == for comparison
Using != which checks for inequality
3fill in blank
hard

Fix the error in the boolean expression to check if x is less than 10.

Rust
let x = 7;
let is_less = x [1] 10;
Drag options to blanks, or click blank then click option'
A<=
B<
C=>
D==
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using <= which means less than or equal
Using => which is invalid syntax
4fill in blank
hard

Fill both blanks to create a boolean expression that checks if num is between 1 and 10 (inclusive).

Rust
let num = 5;
let in_range = num [1] 1 && num [2] 10;
Drag options to blanks, or click blank then click option'
A>=
B<
C<=
D>
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using > instead of >= for the lower bound
Using < instead of <= for the upper bound
5fill in blank
hard

Fill all three blanks to create a boolean expression that checks if value is not equal to 0, less than 100, and greater than 50.

Rust
let value = 42;
let valid = value [1] 0 && value [2] 100 && value [3] 50;
Drag options to blanks, or click blank then click option'
A!=
B<
C>
D==
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using == instead of != for the first condition
Mixing up < and > operators