0
0
Rustprogramming~10 mins

What is Rust - Interactive Quiz & Practice

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

Complete the code to print "Hello, Rust!" to the console.

Rust
fn main() {
    println!([1]);
}
Drag options to blanks, or click blank then click option'
A"Hello, Rust!"
BHello, Rust!
C'Hello, Rust!'
Dprintln!("Hello, Rust!")
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Forgetting the double quotes around the string
Using single quotes instead of double quotes
Passing the text without quotes
2fill in blank
medium

Complete the code to declare a variable named age with the value 30.

Rust
fn main() {
    let [1] = 30;
}
Drag options to blanks, or click blank then click option'
Avar age
Bconst age
Cage
Dlet age
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Including let again inside the blank
Using var which is not Rust syntax
Using const which requires a type
3fill in blank
hard

Fix the error in the function signature to accept a string slice parameter named name.

Rust
fn greet([1]: &str) {
    println!("Hello, {}!", name);
}
Drag options to blanks, or click blank then click option'
Aname: &str
Bname: String
Cname
D&name
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Writing only the variable name without type
Using String instead of &str
Using &name which is invalid syntax
4fill in blank
hard

Fill both blanks to create a vector of numbers from 1 to 5 and print its length.

Rust
fn main() {
    let mut numbers = Vec::[1]();
    for i in 1..=[2] {
        numbers.push(i);
    }
    println!("Length: {}", numbers.len());
}
Drag options to blanks, or click blank then click option'
Anew
B5
Cwith_capacity
D10
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using with_capacity without a number
Looping beyond 5
Not initializing the vector properly
5fill in blank
hard

Fill all three blanks to create a hash map, insert a key-value pair, and print the value for the key.

Rust
use std::collections::HashMap;

fn main() {
    let mut map = HashMap::[1]();
    map.[2]("color", "blue");
    println!("Color: {}", map.get("color").[3]());
}
Drag options to blanks, or click blank then click option'
Anew
Binsert
Cunwrap
Dpush
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using push which is not a HashMap method
Forgetting to unwrap the Option returned by get
Not making the map mutable