mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-11 13:19:18 +00:00
Merge pull request #4 from the-codetrane/mcain/if-and-quiz
Ifs and Quiz
This commit is contained in:
commit
205c66c13b
@ -1,13 +1,16 @@
|
||||
// if1.rs
|
||||
// Execute `rustlings hint if1` or use the `hint` watch subcommand for a hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
pub fn bigger(a: i32, b: i32) -> i32 {
|
||||
// Complete this function to return the bigger number!
|
||||
// Do not use:
|
||||
// - another function call
|
||||
// - additional variables
|
||||
if a > b {
|
||||
return a;
|
||||
} else {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
// Don't mind this for now :)
|
||||
|
||||
@ -4,13 +4,11 @@
|
||||
// Step 2: Get the bar_for_fuzz and default_to_baz tests passing!
|
||||
// Execute `rustlings hint if2` or use the `hint` watch subcommand for a hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
pub fn foo_if_fizz(fizzish: &str) -> &str {
|
||||
if fizzish == "fizz" {
|
||||
"foo"
|
||||
} else {
|
||||
1
|
||||
match fizzish {
|
||||
"fizz" => "foo",
|
||||
"fuzz" => "bar",
|
||||
_ => "baz",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -10,10 +10,14 @@
|
||||
// Write a function that calculates the price of an order of apples given
|
||||
// the quantity bought. No hints this time!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
// Put your function here!
|
||||
// fn calculate_price_of_apples {
|
||||
fn calculate_price_of_apples(amount: u32) -> u32 {
|
||||
if amount > 40 {
|
||||
return amount * 1;
|
||||
} else {
|
||||
return amount * 2;
|
||||
}
|
||||
}
|
||||
|
||||
// Don't modify this function!
|
||||
#[test]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user