Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to shadow the variable x with a new value.
Rust
let x = 5; let x = [1]; println!("{}", x);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using the same value instead of a new one.
Trying to modify
x without shadowing.โ Incorrect
The new variable
x shadows the old one by assigning x + 1.2fill in blank
mediumComplete the code to shadow y with a string value.
Rust
let y = 10; let y = [1]; println!("{}", y);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Trying to assign a number instead of a string.
Not using quotes for the string.
โ Incorrect
Shadowing allows changing the type, so
y becomes a string.3fill in blank
hardFix the error by shadowing z with a new value inside the block.
Rust
let z = 3; { let [1] = z + 2; println!("{}", z); } println!("{}", z);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using a different variable name instead of shadowing.
Trying to modify
z without shadowing.โ Incorrect
Shadowing
z inside the block creates a new z without affecting the outer one.4fill in blank
hardFill both blanks to shadow a with a new value and then shadow it again with a string.
Rust
let a = 1; let a = [1]; let a = [2]; println!("{}", a);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Trying to shadow with a number then a number again.
Not using quotes for the string shadow.
โ Incorrect
First shadow
a with a + 1, then shadow again with a string "hello".5fill in blank
hardFill all three blanks to shadow val by doubling, then converting to string, then appending an exclamation mark.
Rust
let val = 4; let val = val [1] 2; let val = val.to_string(); let val = val [2] [3]; println!("{}", val);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
๐ก Hint
Common Mistakes
Using - instead of + for string concatenation.
Trying to multiply strings.
โ Incorrect
First multiply
val by 2, then convert to string, then append "!" using + operator.