0
0
Rustprogramming~10 mins

Constants 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 constant named MAX_SCORE with value 100.

Rust
const MAX_SCORE: i32 = [1];
Drag options to blanks, or click blank then click option'
A100
B"100"
Cmax_score
Dconst
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using quotes around numbers makes it a string, not a number.
Trying to use a variable name instead of a value.
2fill in blank
medium

Complete the code to declare a constant PI with type f64 and value 3.14.

Rust
const PI: [1] = 3.14;
Drag options to blanks, or click blank then click option'
Ai32
Bf64
Cbool
DString
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using integer type i32 for a decimal number.
Using string or boolean types incorrectly.
3fill in blank
hard

Fix the error in the constant declaration by completing the code.

Rust
const GREETING: &str = [1];
Drag options to blanks, or click blank then click option'
A"Hello"
BHello;
CHello
D'Hello'
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Forgetting quotes around string literals.
Using single quotes which are for chars, not strings.
4fill in blank
hard

Fill both blanks to declare a constant named SPEED_LIMIT of type u32 with value 60.

Rust
const SPEED_LIMIT: [1] = [2];
Drag options to blanks, or click blank then click option'
Au32
Bi32
C60
D"60"
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using signed integer type i32 when unsigned is better here.
Putting the number in quotes, making it a string.
5fill in blank
hard

Fill all three blanks to declare a constant named AUTHOR with type &str and value "Alice".

Rust
const [1]: [2] = [3];
Drag options to blanks, or click blank then click option'
AAUTHOR
B&str
C"Alice"
Dauthor
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using lowercase for constant names.
Using incorrect type for string constants.
Forgetting quotes around string values.