0
0
Rustprogramming~10 mins

Why variables are needed in Rust - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a variable named x with the value 5.

Rust
let [1] = 5;
Drag options to blanks, or click blank then click option'
Avar
B5
Clet
Dx
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using a number instead of a variable name.
Trying to use var which is not Rust syntax.
2fill in blank
medium

Complete the code to print the value of the variable y.

Rust
println!("The value is: {}", [1]);
Drag options to blanks, or click blank then click option'
A"y"
By
Cprintln!
Dvalue
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Putting the variable name in quotes, which prints the word, not the value.
Using a wrong identifier.
3fill in blank
hard

Fix the error by completing the code to make the variable mutable.

Rust
let [1] counter = 0;
Drag options to blanks, or click blank then click option'
Amut
Bis
Clet
Dvar
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Trying to use var which is not Rust syntax.
Putting mut in the wrong place.
4fill in blank
hard

Fill both blanks to declare a mutable variable score with value 10 and then increase it by 5.

Rust
let [1] score = 10;
score [2] 5;
Drag options to blanks, or click blank then click option'
Amut
B+=
C=
Dlet
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using = instead of += which replaces the value.
Not making the variable mutable before changing it.
5fill in blank
hard

Fill all three blanks to declare a variable name with value "Alice", print it, and then change it to "Bob".

Rust
let [1] name = "Alice";
println!("Name: {}", [2]);
name [3] "Bob";
Drag options to blanks, or click blank then click option'
Amut
Bname
C=
Dlet
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Not making the variable mutable before changing it.
Using quotes around the variable name when printing.
Using the wrong operator to change the value.