Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ PLATFORMS

DEPENDENCIES
rspec (~> 3.0.0.beta2)

RUBY VERSION
ruby 2.0.0p648

BUNDLED WITH
1.15.4
25 changes: 23 additions & 2 deletions lib/deaf_grandma.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,29 @@ def run!

def speak(input)

#Implement your code here <<<<<<<<<
# close the application
if input.upcase == "EXIT"
exit
end

# if input is UPPERCASE say one thing, if not, say another
if input == input.upcase
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my notes about fizzbuzz. you can clean this up quite a bit without using explicit returns.


# keep track of how many time you've said BYE
if input == "BYE"
@bye_counter = @bye_counter + 1
end

# if BYE has been said thrice, exit the application
if @bye_counter == 3
p "SEE YOU LATER SONNY!"
exit
end

return "NOT SINCE 1964!"
else # if partially lowercased phrase is said
return "SPEAK UP SONNY!"
end
end

private
Expand All @@ -38,4 +59,4 @@ def get_user_input
end

#Uncomment this next line to run your script but BE SURE to comment it, before you try and run your tests.
#DeafGrandma.new.run!
# DeafGrandma.new.run!
14 changes: 13 additions & 1 deletion lib/fizzbuzz.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@ class SuperFizzBuzz

def run(input)

#Implement your code here
if input % 3 == 0 && input % 5 == 0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be combined in an if..elsif or case statement. that way you can avoid the explicit return statements.

you won't see explicit returns a lot in ruby except in the case of early returns.

  def fn
    return true if condition
    false
  end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How could you solve this using ruby's .tap method?
https://ruby-doc.org/core-2.4.2/Object.html#method-i-tap

return "FizzBuzz"
end

if input % 5 == 0
return "Buzz"
end

if input % 3 == 0
return "Fizz"
end

return input

end

Expand Down
7 changes: 5 additions & 2 deletions spec/deaf_grandma_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
end

it "says 'NOT SINCE 1964!' when we yell" do
#implement your test here
expect(script.speak("HEY")).to eq "NOT SINCE 1964!"
end

it "EXTRA CREDIT: How would you test yelling BYE?" do
#implement your test here
# expect(script.speak("BYE")).to eq "NOT SINCE 1964!"
# expect(script.speak("BYE")).to eq "NOT SINCE 1964!"
# expect(script.speak("BYE")).to eq exit(true)
# ^^^ yeah I don't know how to test the exit condition on this along with the final phrase...
end
end
6 changes: 3 additions & 3 deletions spec/fizzbuzz_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
end

it "returns 'Buzz' when my input is divisible by 5" do
#implement your test here
expect(script.run(5)).to eq "Buzz"
end

it "returns 'FizzBuzz' when input is divisible by 3 & 5" do
#implement your test here
expect(script.run(15)).to eq "FizzBuzz"
end

it "returns the input number when input isn't divisible by 3, 5, or both" do
#implement your test here
expect(script.run(2)).to eq 2
end
end