Control Flow Flashcards
true && true # => ___
true && false # => ___
false && true # => ___
false && false # => ___
true
false
false
false
true || true # => ___
true || false # => ___
false || true # => ___
false || false # => ___
true
true
true
false
false || false
true or false?
false
!true # => ____
!false # => ____
false
true
!true && !true
true or false?
false
!true && (!true || 100 != 5**2)
true or false?
false
true || !(true || false)
true or false?
true
Set the output to write “Ruby!” five times.
5.times { puts “Ruby!” }
Write an array of numbers 1-5. Note the brackets.
numbers = [1, 2, 3, 4, 5]
- Write a hash “profile” with your name, city, and state.
- Call on the city within that profile.
- Create a new hash called “favorites”.
- Add a value pair where “baseball” = “Twins”.
profile = { "name" => "Spencer" "city" => "Minneapolis" "state" => "MN" }
puts profile[“city”]
favorites = Hash.new favorites["baseball"] = "Twins"
example = [“Car”, “Boar”, 45, 9.9, true]
Access “45” in the array.
puts example[2]
- Create an array “team” of these players and their number:
Towns = 32
Russell = 0
Beasley = 5 - Call on the array to form a statement of what each number every player wears.
team = { "Towns" => "32", "Russell" => "0", "Beasley" => "5", }
team.each do |player, number|
puts “#{player} wears #{number}.”
end
Define a greeter method that takes a single string parameter, name, and returns a string greeting that person.
def greeter(name) return "Hello, #{name}!" end
Define a by_three? method that takes a single integer parameter, number, and returns true if that number is evenly divisible by three and false if not.
def by_three?(num) if num % 3 == 0 return true else return false end end
What’s the difference between “.sort” and “.sort!”?
.sort - will sort a copy
.sort! - will sort current array, replacing old with the sorted version.