Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add 5 to the variable x using an assignment operator.
Rust
let mut x = 10; x [1] 5; println!("{}", x);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using '-' instead of '+' will subtract instead of add.
Forgetting to make the variable mutable with 'mut'.
โ Incorrect
The operator '+=' adds the right value to the variable and assigns the result back to it.
2fill in blank
mediumComplete the code to multiply the variable y by 3 using an assignment operator.
Rust
let mut y = 4; y [1] 3; println!("{}", y);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using '+=' or '-=' instead of '*=' changes the operation.
Not declaring the variable as mutable.
โ Incorrect
The '*=' operator multiplies the variable by the right value and assigns the result back to it.
3fill in blank
hardFix the error in the code by choosing the correct assignment operator to divide z by 2.
Rust
let mut z = 20; z [1] 2; println!("{}", z);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using '*=' multiplies instead of dividing.
Using '+=' or '-=' changes the operation.
โ Incorrect
The '/=' operator divides the variable by the right value and assigns the result back to it.
4fill in blank
hardFill both blanks to subtract 7 from a and then add 10 to b using assignment operators.
Rust
let mut a = 15; let mut b = 5; a [1] 7; b [2] 10; println!("{} {}", a, b);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Mixing up '+' and '-' operators.
Using '*=' or '/=' instead of addition or subtraction.
โ Incorrect
Use '-=' to subtract from 'a' and '+=' to add to 'b'.
5fill in blank
hardFill all three blanks to multiply m by 4, divide n by 2, and add 3 to p using assignment operators.
Rust
let mut m = 3; let mut n = 8; let mut p = 1; m [1] 4; n [2] 2; p [3] 3; println!("{} {} {}", m, n, p);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Confusing the order of operators.
Using the wrong operator for the intended operation.
โ Incorrect
Use '*=' to multiply 'm', '/=' to divide 'n', and '+=' to add to 'p'.