diff --git a/exercises/functions/functions1.rs b/exercises/functions/functions1.rs index 31125278..c3ecf262 100644 --- a/exercises/functions/functions1.rs +++ b/exercises/functions/functions1.rs @@ -1,8 +1,11 @@ // functions1.rs // Make me compile! Execute `rustlings hint functions1` for hints :) -// I AM NOT DONE +// This needed the call_me fucntion to be defined. fn main() { + fn call_me() { + println!("Hello World"); + } call_me(); } diff --git a/exercises/functions/functions2.rs b/exercises/functions/functions2.rs index 5721a172..c34b4695 100644 --- a/exercises/functions/functions2.rs +++ b/exercises/functions/functions2.rs @@ -1,13 +1,12 @@ // functions2.rs // Make me compile! Execute `rustlings hint functions2` for hints :) -// I AM NOT DONE - fn main() { call_me(3); } -fn call_me(num:) { +// Below I added the i32, beacuse the function expected a type to set/specified. +fn call_me(num: i32) { for i in 0..num { println!("Ring! Call number {}", i + 1); } diff --git a/exercises/functions/functions3.rs b/exercises/functions/functions3.rs index ed5f839f..fa5b16ef 100644 --- a/exercises/functions/functions3.rs +++ b/exercises/functions/functions3.rs @@ -1,10 +1,9 @@ // functions3.rs // Make me compile! Execute `rustlings hint functions3` for hints :) -// I AM NOT DONE - +// Need to pass in an unsigned 32 bit num to get this to work. fn main() { - call_me(); + call_me(10); } fn call_me(num: u32) { diff --git a/exercises/functions/functions4.rs b/exercises/functions/functions4.rs index 58637e4c..5dd86fc1 100644 --- a/exercises/functions/functions4.rs +++ b/exercises/functions/functions4.rs @@ -4,14 +4,14 @@ // This store is having a sale where if the price is an even number, you get // 10 Rustbucks off, but if it's an odd number, it's 3 Rustbucks off. -// I AM NOT DONE - fn main() { let original_price = 51; println!("Your sale price is {}", sale_price(original_price)); } -fn sale_price(price: i32) -> { +// Below I needed to specify a type for the return item +// This happened to be a i32 +fn sale_price(price: i32) -> i32 { if is_even(price) { price - 10 } else { diff --git a/exercises/functions/functions5.rs b/exercises/functions/functions5.rs index d22aa6c8..734f62f0 100644 --- a/exercises/functions/functions5.rs +++ b/exercises/functions/functions5.rs @@ -1,13 +1,12 @@ // functions5.rs // Make me compile! Execute `rustlings hint functions5` for hints :) -// I AM NOT DONE - fn main() { let answer = square(3); println!("The answer is {}", answer); } +// This funtion implicitly returns, there is no need for the ; after num * num fn square(num: i32) -> i32 { - num * num; + num * num } diff --git a/exercises/if/if1.rs b/exercises/if/if1.rs index 90867545..342461fd 100644 --- a/exercises/if/if1.rs +++ b/exercises/if/if1.rs @@ -1,13 +1,17 @@ // if1.rs -// 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 // Execute `rustlings hint if1` for hints + if a > b { + a + } else { + b + } + // No need for a return a; these fucnitons implictily return! } // Don't mind this for now :) diff --git a/exercises/intro/intro1.rs b/exercises/intro/intro1.rs index 1c4582de..4fde4bed 100644 --- a/exercises/intro/intro1.rs +++ b/exercises/intro/intro1.rs @@ -5,7 +5,6 @@ // ready for the next exercise, remove the `I AM NOT DONE` comment below. // Execute the command `rustlings hint intro1` for a hint. -// I AM NOT DONE fn main() { println!("Hello and"); diff --git a/exercises/intro/intro2.rs b/exercises/intro/intro2.rs index 97a073f0..1e8481f4 100644 --- a/exercises/intro/intro2.rs +++ b/exercises/intro/intro2.rs @@ -2,8 +2,8 @@ // Make the code print a greeting to the world. // Execute `rustlings hint intro2` for a hint. -// I AM NOT DONE fn main() { - println!("Hello {}!"); + let n = "World"; + println!("Hello {}!", n); } diff --git a/exercises/variables/variables1.rs b/exercises/variables/variables1.rs index d1af8311..80b51c01 100644 --- a/exercises/variables/variables1.rs +++ b/exercises/variables/variables1.rs @@ -2,9 +2,10 @@ // Make me compile! // Execute the command `rustlings hint variables1` if you want a hint :) -// I AM NOT DONE fn main() { - x = 5; + let x = 5; + // When using string formating the value needs to be assigned before it can + // be used, standard stuff. println!("x has the value {}", x); } diff --git a/exercises/variables/variables2.rs b/exercises/variables/variables2.rs index 7774a8fb..028ad817 100644 --- a/exercises/variables/variables2.rs +++ b/exercises/variables/variables2.rs @@ -1,10 +1,9 @@ // variables2.rs // Make me compile! Execute the command `rustlings hint variables2` if you want a hint :) -// I AM NOT DONE fn main() { - let x; + let x = 1; // Orginally let x; Variables need defining from what I can tell. if x == 10 { println!("Ten!"); } else { diff --git a/exercises/variables/variables3.rs b/exercises/variables/variables3.rs index 30ec48ff..02e8a098 100644 --- a/exercises/variables/variables3.rs +++ b/exercises/variables/variables3.rs @@ -1,10 +1,8 @@ // variables3.rs // Make me compile! Execute the command `rustlings hint variables3` if you want a hint :) -// I AM NOT DONE - fn main() { - let x = 3; + let mut x = 5; println!("Number {}", x); x = 5; // don't change this line println!("Number {}", x); diff --git a/exercises/variables/variables4.rs b/exercises/variables/variables4.rs index 77f1e9ab..b20880ed 100644 --- a/exercises/variables/variables4.rs +++ b/exercises/variables/variables4.rs @@ -1,9 +1,8 @@ // variables4.rs // Make me compile! Execute the command `rustlings hint variables4` if you want a hint :) -// I AM NOT DONE - fn main() { let x: i32; + x = 6; println!("Number {}", x); } diff --git a/exercises/variables/variables5.rs b/exercises/variables/variables5.rs index 175eebb3..9d06867f 100644 --- a/exercises/variables/variables5.rs +++ b/exercises/variables/variables5.rs @@ -1,11 +1,10 @@ // variables5.rs // Make me compile! Execute the command `rustlings hint variables5` if you want a hint :) -// I AM NOT DONE - fn main() { let number = "T-H-R-E-E"; // don't change this line println!("Spell a Number : {}", number); - number = 3; + let number = 3; // if we want to reuse a varibale name we need to use + // Shadowing, this is different from making a var mutable println!("Number plus two is : {}", number + 2); } diff --git a/exercises/variables/variables6.rs b/exercises/variables/variables6.rs index 98666914..a98d60bd 100644 --- a/exercises/variables/variables6.rs +++ b/exercises/variables/variables6.rs @@ -1,9 +1,7 @@ // variables6.rs // Make me compile! Execute the command `rustlings hint variables6` if you want a hint :) -// I AM NOT DONE - -const NUMBER = 3; +const NUMBER: i32 = 3; // Consts need to be assigned a type fn main() { println!("Number {}", NUMBER); }