0
0
Rustprogramming~10 mins

Mutable variables 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 mutable variable named count with initial value 5.

Rust
let [1] count = 5;
Drag options to blanks, or click blank then click option'
Avar
Bmut
Cconst
Dlet
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using var instead of let.
Forgetting to add mut for mutability.
Using const which creates an immutable constant.
2fill in blank
medium

Complete the code to change the value of the mutable variable score to 10.

Rust
let mut score = 5;
score [1] 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 assignment.
Using => which is not valid here.
3fill in blank
hard

Fix the error in the code by making the variable name mutable so it can be changed.

Rust
[1] name = "Alice";
name = "Bob";
Drag options to blanks, or click blank then click option'
Alet mut
Bconst
Cmut
Dvar
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using only mut without let.
Using const which is immutable.
Using var which is not valid in Rust.
4fill in blank
hard

Fill both blanks to create a mutable variable temperature and assign it the value 25.

Rust
[1] [2] temperature = 25;
Drag options to blanks, or click blank then click option'
Alet
Bmut
Cvar
Dconst
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using var which is not valid in Rust.
Using const which creates an immutable variable.
Swapping the order of let and mut.
5fill in blank
hard

Fill all three blanks to declare a mutable variable speed, assign it 30, and then update it to 50.

Rust
[1] [2] speed = 30;
speed [3] 50;
Drag options to blanks, or click blank then click option'
Alet
Bmut
C=
Dconst
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using const instead of let.
Forgetting mut to allow changing the variable.
Using == instead of = for assignment.