Skip to content

Instantly share code, notes, and snippets.

@joegiralt
Created June 8, 2013 22:48
Show Gist options
  • Save joegiralt/5736904 to your computer and use it in GitHub Desktop.
Save joegiralt/5736904 to your computer and use it in GitHub Desktop.
homework for ruby 3
# Write an expression that returns true by using ==
puts true == true
# Write an expression that returns false using ==
puts true == false
# Write an expression that returns true using != Write an expression that returns false using !=
puts false != true
puts false != false
# Write an if statement with 3 different branches use != in the first branch, == in the second, and > in the third
name="Joe"
if name != "Sara"
puts "thats not your name, " + "Sara!"
elsif name == "Joe"
puts "Hi Joe!"
elsif name.size > 3
puts "hi jumpin' jack!"
# Assign a variable based on the result of an if statement
if name.size < 3
name = "jumpin' jack"
end
# Execute code based on the result of an if statement. conditionally run puts "Hello Class" if 1 < 2
if 1 < 2
puts "Hello class"
end
# Try using an if statement at the end of an expression
puts "Zed's Dead." if 1 < 100
end
# Write an if statement that negates the or operator to return true Write an if statement that uses the and operator to create a false return
if true or poopicle>giberreish!!!!!
puts "lowrider!"
end
if true && false == false
false
end
# Write a Case Statement that checks if a variable is a vowel Rewrite that same case statement as an if statement Write a Case statement that has at 4 branches and a default return
letter = "x"
if letter != ("a" || "e" || "i" || "o" || "u")
puts letter + " is not a vowel"
else
puts letter + " is a vowel"
end
# Write a while loop that runs exactly 5 times Write a while loop that counts from 1 to 10 and puts all odd numbers you can check if a number is odd by calling the odd? method on it.
x = 0
while x < 5
puts x = x +1
end
x = 0
while x <= 10
puts x if x.odd? == true
x = x+1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment