Last active
August 29, 2015 14:02
-
-
Save ryanholm/fc73734a415697a36d10 to your computer and use it in GitHub Desktop.
BLOC if statements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#CP1 | |
def favorite_number(fav,guess) | |
if guess < fav | |
"Too low" | |
elsif guess > fav | |
"Too high" | |
elsif guess == fav | |
"You got it!" | |
end | |
end | |
#RSpec | |
describe "favorite_number" do | |
it "should return 'Too low' if the guess is low" do | |
favorite_number(10, 1).should eq("Too low") | |
end | |
it "should return 'Too high' if the guess is high" do | |
favorite_number(5, 11).should eq("Too high") | |
end | |
it "should return 'You got it!' if the guess is right" do | |
favorite_number(11, 11).should eq("You got it!") | |
end | |
end | |
#CP2 | |
def lock(a,b,c,d) | |
if (a == 3 && b == 2 && c == 5 && d == 8) | |
"unlocked" | |
elsif (a == 1 && b == 1 && c == 1 && d == 1) | |
"locked" | |
elsif (a == 5 && b == 2 && c == 5 && d == 0) | |
"unlocked" | |
elsif (a == 5 && b == 2 && c == 6 && d == 8) | |
"unlocked" | |
elsif (a == 7 && b == 2 && c == 5 && d == 8) | |
"unlocked" | |
elsif (a == 7 && b == 2 && c == 6 && d == 9) | |
"unlocked" | |
end | |
end | |
def can_i_get?(item,money) | |
if item == "computer" && money >= 1000 | |
true | |
elsif item == "computer" && money < 1000 | |
false | |
elsif item == "ipad" && money == 500 | |
true | |
elsif item == "ipad" && money <= 500 | |
false | |
end | |
end | |
#RSpec | |
describe "lock" do | |
it "should return unlocked for 3258" do | |
lock(3, 2, 5, 8).should eq('unlocked') | |
end | |
it "should return locked for 1111" do | |
lock(1, 1, 1, 1).should eq('locked') | |
end | |
it "should return unlocked for other valid combinations" do | |
lock(3, 2, 5, 8).should eq('unlocked') | |
lock(5, 2, 5, 0).should eq('unlocked') | |
lock(5, 2, 6, 8).should eq('unlocked') | |
lock(7, 2, 5, 8).should eq('unlocked') | |
lock(7, 2, 6, 9).should eq('unlocked') | |
end | |
end | |
describe "can_i_get?" do | |
it "returns true if user wants a computer and has $1,000" do | |
can_i_get?("computer", 1100).should eq(true) | |
end | |
it "returns false for a computer if they don't have $1,000" do | |
can_i_get?("computer", 900).should eq(false) | |
end | |
it "returns true for a iPad if they have $500" do | |
can_i_get?("ipad", 500).should eq(true) | |
end | |
it "returns false for a iPad if they have less than $500" do | |
can_i_get?("ipad", 499).should eq(false) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment