0
0
Rustprogramming~10 mins

Logical operators 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 check if both conditions are true.

Rust
let a = true;
let b = false;
let result = a [1] b;
println!("{}", result);
Drag options to blanks, or click blank then click option'
A&&
B|
C||
D&
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using || instead of && will return true if either is true.
2fill in blank
medium

Complete the code to check if either condition is true.

Rust
let x = false;
let y = true;
let result = x [1] y;
println!("{}", result);
Drag options to blanks, or click blank then click option'
A&
B&&
C||
D|
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using && instead of || will require both to be true.
3fill in blank
hard

Fix the error in the code to correctly negate the boolean value.

Rust
let flag = true;
let negated = [1]flag;
println!("{}", negated);
Drag options to blanks, or click blank then click option'
Aneg
B!
Cnot
D~
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using ~ or not which are not valid boolean negation in Rust.
4fill in blank
hard

Fill both blanks to create a condition that is true only if a is true and b is false.

Rust
let a = true;
let b = false;
if a [1] [2] b {
    println!("Condition met");
}
Drag options to blanks, or click blank then click option'
A&&
B||
C!
D==
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using || instead of && will allow b to be true.
5fill in blank
hard

Fill all three blanks to create a condition that is true if either x is false or y is true and z is true.

Rust
let x = true;
let y = false;
let z = false;
if [1] x [2] y [3] z {
    println!("Complex condition met");
}
Drag options to blanks, or click blank then click option'
A!
B||
C&&
D==
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Mixing up operator precedence or forgetting to negate x.