Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using a number instead of a variable name.
Trying to use
var which is not Rust syntax.โ Incorrect
In Rust, let declares a variable. Here, x is the variable name.
2fill in blank
mediumComplete 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Putting the variable name in quotes, which prints the word, not the value.
Using a wrong identifier.
โ Incorrect
To print the value of a variable, use its name without quotes.
3fill in blank
hardFix 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Trying to use
var which is not Rust syntax.Putting
mut in the wrong place.โ Incorrect
In Rust, mut makes a variable mutable so its value can change.
4fill in blank
hardFill 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'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using
= instead of += which replaces the value.Not making the variable mutable before changing it.
โ Incorrect
Use mut to make score mutable and += to add 5 to it.
5fill in blank
hardFill 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'
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.
โ Incorrect
Make name mutable with mut, print it by its name, and assign a new value with =.