From 3b04157458d2983c3cc9e844be55f26403b1cf2b Mon Sep 17 00:00:00 2001 From: Moroj-Alharbi Date: Mon, 21 Jan 2019 18:25:23 +0300 Subject: [PATCH 1/3] HW-Done --- app.rb | 13 +++++++++++++ data-collections.md | 28 ++++++++++++++-------------- data-types.md | 24 ++++++++++++------------ 3 files changed, 39 insertions(+), 26 deletions(-) create mode 100644 app.rb diff --git a/app.rb b/app.rb new file mode 100644 index 0000000..5213f46 --- /dev/null +++ b/app.rb @@ -0,0 +1,13 @@ +i = 1 +while i <= 100 + # Your code goes in here. + if i % 3 == 0 and i % 5 == 0 + puts "FizzBuzz" + elsif i % 3 == 0 + puts "Fizz" + elsif i % 5 == 0 + puts "Buzz" + else puts i + end + i+=1 +end \ No newline at end of file diff --git a/data-collections.md b/data-collections.md index 1105e5d..58bb54e 100644 --- a/data-collections.md +++ b/data-collections.md @@ -9,37 +9,37 @@ planeteers = ["Earth", "Wind", "Captain Planet", "Fire", "Water"] Access the second value in `planeteers`. ```rb -# Your answer here +planeteers[1] ``` Add "Heart" to the end of `planeteers`. ```rb -# Your answer here +planeteers << "Heart" ``` Remove "Captain Planet" from the array (without using a method). ```rb -# Your answer here +planeteers -= ["Captain Planet"] ``` Combine `planeteers` with `rangers = ["Red", "Blue", "Pink", "Yellow", "Black"]` and save the result in a variable called `heroes`. ```rb -# Your answer here +heroes = planeteers + rangers ``` Alphabetize the contents of `heroes` using a method. [The Ruby documentation might help](http://ruby-doc.org/core-2.2.0/Array.html). ```rb -# Your answer here +heroes.sort ``` Randomize the contents of `heroes` using a method. [The Ruby documentation might help](http://ruby-doc.org/core-2.2.0/Array.html). ```rb -# Your answer here +heroes.shuffle ``` #### Bonus @@ -47,13 +47,13 @@ Randomize the contents of `heroes` using a method. [The Ruby documentation might Select a random element from `heroes` using a method. [The Ruby documentation might help](http://ruby-doc.org/core-2.2.0/Array.html). ```rb -# Your answer here +heroes.sample ``` Select all elements in `heroes` that begin with "B" using a method. [The Ruby documentation might help](http://ruby-doc.org/core-2.2.0/Array.html). ```rb -# Your answer here +heroes.select {|el| el.start_with?('B')} ``` ### Hashes @@ -61,37 +61,37 @@ Select all elements in `heroes` that begin with "B" using a method. [The Ruby do Initialize a hash called `ninja_turtle` with the properties `name`, `weapon` and `radical`. They should have values of "Michelangelo", "Nunchuks" and `true` respectively. ```rb -# Your answer here +ninja_turtle = {"name" => "Michelangelo", "weapon" => "Nunchuks", "radical" => true} ``` Add a key `age` to `ninja_turtle`. Set it to whatever numerical value you'd like. ```rb -# Your answer here +ninja_turtle = ninja_turtle.merge("age"=>3) ``` Remove the `radical` key-value pair from `ninja_turtle`. ```rb -# Your answer here +ninja_turtle.delete("radical") ``` Add a key `pizza_toppings` to `ninja_turtle`. Set it to an array of strings (e.g., `["cheese", "pepperoni", "peppers"]`). ```rb -# Your answer here +ninja_turtle = ninja_turtle.merge("pizza_toppings" => ["cheese", "pepperoni","peppers"]) ``` Access the first element of `pizza_toppings`. ```rb -# Your answer here +ninja_turtle["pizza_toppings"][0] ``` Produce an array containing all of `ninja_turtle`'s keys using a method. [The Ruby documentation might help](http://ruby-doc.org/core-1.9.3/Hash.html). ```rb -# Your answer here +ninja_turtle.flatten ``` #### Bonus diff --git a/data-types.md b/data-types.md index 5b06811..96d5a99 100644 --- a/data-types.md +++ b/data-types.md @@ -10,28 +10,28 @@ 2 ** 3 ``` ```text -Your answer. +8 ``` ```rb ((16 / 4) * (2 + 1)) ** 2 ``` ```text -Your answer. +144 ``` ```rb ("a milli " + "a milli") * 3 ``` ```text -Your answer. +"a milli a millia milli a millia milli a milli" ``` ```rb ("a milli " * 4) / 2 ``` ```text -Your answer. +Error out ``` ```rb @@ -39,7 +39,7 @@ my_favorite_number = 13 puts "My favorite number is: " + my_favorite_number ``` ```text -Your answer. +Error out ``` ```rb @@ -47,7 +47,7 @@ my_favorite_number = 13 puts "My favorite number is: #{my_favorite_number}" ``` ```text -Your answer. +My favorite number is: 13 ``` ### Truthiness and Falsiness @@ -55,14 +55,14 @@ Your answer. #### Which of these evaluate as `false` in Ruby? Mark all that apply. ```text -[ ] false +[ false ] false [ ] 0 [ ] "" [ ] null [ ] [ ] (empty array) [ ] undefined [ ] NaN -[ ] nil +[ false ] nil ``` #### What are the outputs and/or side effects of the following code snippets? @@ -78,7 +78,7 @@ if no_name end ``` ```text -Your answer. +My name is: ``` ```rb @@ -88,7 +88,7 @@ if no_name end ``` ```text -Your answer. +nil ``` ```rb @@ -98,7 +98,7 @@ if age end ``` ```text -Your answer. +Error out ``` ```rb @@ -108,7 +108,7 @@ if age end ``` ```text -Your answer. +Error out ``` ### Conditionals From eae35d56f93e403263c97397e4b29b9ad3d6381f Mon Sep 17 00:00:00 2001 From: Moroj-Alharbi Date: Mon, 21 Jan 2019 18:41:02 +0300 Subject: [PATCH 2/3] edit --- data-types.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data-types.md b/data-types.md index 96d5a99..fd937fd 100644 --- a/data-types.md +++ b/data-types.md @@ -108,7 +108,7 @@ if age end ``` ```text -Error out +My age is: 20 ``` ### Conditionals From 1a515f4480ebae1b4e3ef4c092d76e2647ed8a3c Mon Sep 17 00:00:00 2001 From: Moroj-Alharbi Date: Mon, 21 Jan 2019 20:47:47 +0300 Subject: [PATCH 3/3] edit --- data-collections.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/data-collections.md b/data-collections.md index 58bb54e..7008ec6 100644 --- a/data-collections.md +++ b/data-collections.md @@ -61,37 +61,37 @@ heroes.select {|el| el.start_with?('B')} Initialize a hash called `ninja_turtle` with the properties `name`, `weapon` and `radical`. They should have values of "Michelangelo", "Nunchuks" and `true` respectively. ```rb -ninja_turtle = {"name" => "Michelangelo", "weapon" => "Nunchuks", "radical" => true} +ninja_turtle = {:name => "Michelangelo", :weapon => "Nunchuks", :radical => true} ``` Add a key `age` to `ninja_turtle`. Set it to whatever numerical value you'd like. ```rb -ninja_turtle = ninja_turtle.merge("age"=>3) +ninja_turtle = ninja_turtle.merge(:age=>3) ``` Remove the `radical` key-value pair from `ninja_turtle`. ```rb -ninja_turtle.delete("radical") +ninja_turtle.delete(:radical) ``` Add a key `pizza_toppings` to `ninja_turtle`. Set it to an array of strings (e.g., `["cheese", "pepperoni", "peppers"]`). ```rb -ninja_turtle = ninja_turtle.merge("pizza_toppings" => ["cheese", "pepperoni","peppers"]) +ninja_turtle = ninja_turtle.merge(:pizza_toppings => ["cheese", "pepperoni","peppers"]) ``` Access the first element of `pizza_toppings`. ```rb -ninja_turtle["pizza_toppings"][0] +ninja_turtle[:pizza_toppings][0] ``` Produce an array containing all of `ninja_turtle`'s keys using a method. [The Ruby documentation might help](http://ruby-doc.org/core-1.9.3/Hash.html). ```rb -ninja_turtle.flatten +ninja_turtle.keys ``` #### Bonus