Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a function that takes one parameter named name.
Rust
fn greet([1]: &str) { println!("Hello, {}!", name); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different parameter name than the one used inside the function.
Forgetting to specify the parameter type.
✗ Incorrect
The function parameter must be named
name to match the usage inside the function.2fill in blank
mediumComplete the function signature to accept two parameters: a and b, both integers.
Rust
fn add([1]: i32, b: i32) -> i32 {
a + b
}Attempts:
3 left
💡 Hint
Common Mistakes
Using a different name than
a for the first parameter.Not matching parameter names with the function body.
✗ Incorrect
The first parameter must be named
a to match the function body where a + b is returned.3fill in blank
hardFix the error in the function parameter to accept a string slice named text.
Rust
fn print_text([1]) { println!("{}", text); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using
String instead of &str when the function expects a string slice.Not naming the parameter
text.✗ Incorrect
The function expects a string slice
&str named text, not an owned String.4fill in blank
hardFill both blanks to define a function that takes two parameters: width and height, both unsigned integers.
Rust
fn area([1]: u32, [2]: u32) -> u32 { width * height }
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names that don't match the function body.
Mixing up parameter names and types.
✗ Incorrect
The parameters must be named
width and height to match the function body.5fill in blank
hardFill all three blanks to define a function that takes a string slice name, an integer age, and a boolean is_student.
Rust
fn describe_person([1]: &str, [2]: i32, [3]: bool) { println!("Name: {}, Age: {}, Student: {}", name, age, is_student); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter names that don't match the print statement.
Mixing up parameter types and names.
✗ Incorrect
The parameters must be named
name, age, and is_student to match the function body.