diff --git a/exercises/03_if/if1.rs b/exercises/03_if/if1.rs index 4734d78f..fe1b1b3f 100644 --- a/exercises/03_if/if1.rs +++ b/exercises/03_if/if1.rs @@ -2,13 +2,12 @@ // // 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 {a} else {b} } // Don't mind this for now :) diff --git a/exercises/03_if/if2.rs b/exercises/03_if/if2.rs index f512f13f..19a8b2b9 100644 --- a/exercises/03_if/if2.rs +++ b/exercises/03_if/if2.rs @@ -5,13 +5,18 @@ // // 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 { + // &str is a string slice - + // Let's say the full string is a ribbon + // A string slice is a piece of the ribbon + // It's just a reference to the ribbon so doing things to the piece won't change the original ribbon. + if fizzish == "fizz" { "foo" + } else if fizzish == "fuzz" { + "bar" } else { - 1 + "baz" } } diff --git a/exercises/03_if/if3.rs b/exercises/03_if/if3.rs index 16962740..14a10eab 100644 --- a/exercises/03_if/if3.rs +++ b/exercises/03_if/if3.rs @@ -2,17 +2,17 @@ // // Execute `rustlings hint if3` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE - pub fn animal_habitat(animal: &str) -> &'static str { + // static is a lifetime, it means that the string will be valid for the entire duration of the program + // it's practically hardcoded into the program and always available let identifier = if animal == "crab" { 1 } else if animal == "gopher" { - 2.0 + 2 } else if animal == "snake" { 3 } else { - "Unknown" + 0 }; // DO NOT CHANGE THIS STATEMENT BELOW