Tonight you're going to get the basics down and put your Ruby skills to the test.
Include all of your code in the file called ninja_skills.rb
. You can run the file by typing in ruby ninja_skills.rb
in your terminal. You may comment out pieces of code when you're not using them.
Try messing around with the Ruby REPL, IRB. You can run IRB by typing irb
in your terminal.
Get to the end of the challenges and be crowned Ruby Ninja Warrior.
Follow each instruction one by one. Each instruction's code should go on its own line.
If you're not sure about something, be comfortable searching the Ruby Docs and feel free to Google!
- Create a variable
a
and set it equal totrue
- Create a variable
b
and set it equal tofalse
- Write a statement using
a
andb
that evaluates tofalse
- puts the result to the terminal
- Write a statement using
a
andb
that evaluates totrue
- puts the result to the terminal
- 🎯 Commit -m "1. Boolean Skills"
- Create a variable of your choosing and set it equal to Nil
- p the value of the variable to the terminal
- puts the value of the variable to the terminal concatenate the string "nil was here".
- print the value of the variable to the terminal
- puts the class of the value of the variable to the terminal. Use the .class method. Look up this method on Google.
- 🎯 Commit -m "2. Nil skills."
- Create a variable
d
and set it equal to a Fixnum- puts the value of
d
to the terminal
- puts the value of
- Create a variable
e
and set it equal to a Float- puts the value of
e
to the terminal
- puts the value of
- Set
d
equal toe
on another line- puts the value of
d
to the terminal
- puts the value of
- 🎯 Commit -m "3. Integers Skills"
- Create a variable
christine
and set it equal to the string "Hi, I'm Christine" - Create a variable
likes
and set it equal to the String "long walks on the beach." - Using string interpolation and the variables
christine
andlikes
puts the following string to the terminal:"Hi, I'm Christine and I like long walks on the beach, kinda."
- Create a variable
g
and set it equal to the string "2" - Create a variable
gToNumber
and set it equal to the Integer 2 - puts the value of
g + gToNumber
in the terminal. What happens? How can you fix this? - 🎯 Commit -m "4. String skills "
-
Create a small program that asks the user to input an Integer and multiplies the number by two.
-
Create a small program that does the following
- Asks the user for their name
- Asks the user what they like to do
- Prints out the user's name and what they like to do in a sentence.
-
🎯 Commit -m "5. Input/Output skills"
- Create a variable
myFirstArray
and set it equal to an empty array - Set the variable
myFirstArray
to an array with five Strings and four Integers - Using
myFirstArray
puts the last value of the array to the terminal - Using
myFirstArray
puts the first value of the array to the terminal - Set the second value of
myFirstArray
to the String"Joe"
- Set the third value of
myFirstArray
to the Integer3
- Push the String Boolean
true
intomyFirstArray
- Puts the class of the fourth value in
myFirstArray
- 🎯 Commit -m "6. Arrays skills"
- Create a variable called myFavoriteAnimals and set it equal to a Hash with five animals. The animal name as the keys and the species as the values. You must include one animal with a name of "Edgar" and the value "Donkey"
- Change value of Edgar to be "Bear"
- Create a variable
favoriteMovie
and set it equal to a new, empty Hash. - Edit the
favoriteMovie
hash and add amovie
key with a value of your choosing. - 🎯 Commit -m "7. Hashes skills"
- Create a variable
firstRange
and set it equal to a Range from one to ten including ten. - Convert
firstRange
to an array. - Create a variable
secondRange
and set it equal to a Range from one to one thousand excluding the Number one thousand. - Convert
secondRange
to an array - Create a For loop that changes every value in
firstRange
to a String and using a p statement print those values out to the terminal - Create a variable
x
and set it equal to zero - Create a While loop that prints every value in
secondRange
while x < 50. - Using .each multiply every other value in
firstRange
by two and push those values into a new Array. Print that array to the terminal. - Using .map and if/else statements, iterate through
firstRange
and change every even value to a string. If the value is odd, don't change the value to a string. - 🎯 Commit -m "8. Range skills."
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000 using Ruby.
- 🎯 Commit -m "9. Loop skills."
Write a method called check_prime?
that will test whether a number is Prime. The method will return true if Prime, false if not.
Write another method called get_primes
that will print all the Primes up to an arbitrary limit. For example, if you invoke your method with get_primes(100)
, it will print all the Prime numbers up to and including 100.
This method can call on the previous check_prime?
method.
- 🎯 Commit -m "10. I'm a Ninja Warrior. Bow down to me."
A Prime number is a number that is not evenly divisible by another number except 1 and itself.
To test whether a number is Prime, you only need to test as far as the square root of that number. This is advisable for optimization and testing large numbers.
Check out Ruby's Prime
class: http://ruby-doc.org/stdlib-1.9.3/libdoc/prime/rdoc/Prime.html
When you're ready to submit your work,
- Add, commit, and push your code to your fork of the class repo.
- File an issue on the class repo titled "Your Name -- wXXdXX".
The issue should include:
-
A link that points back to your fork.
-
A 'comfort' score on how you feel about the material, from 1 (very uncomfortable) to 5 (very comfortable)