Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'
ruby '2.0.0'
ruby '2.2.9'

gem 'rspec', '~> 3.0.0.beta2'
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.2.9p480

BUNDLED WITH
1.16.1
27 changes: 22 additions & 5 deletions lib/deaf_grandma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,31 @@ def run!
loop do
user_input = get_user_input
p speak(user_input)
if @bye_counter > 2
exit
end
end
end


def speak(input)

#Implement your code here <<<<<<<<<

if input == input.upcase
#YELL
if input == "BYE"
@bye_counter = @bye_counter + 1
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.

else
@bye_counter = 0
end

if @bye_counter == 3
"SEE YOU LATER SONNY!"
else
"NOT SINCE 1964!"
end
else
#speak
@bye_counter = 0
"SPEAK UP SONNY!"
end
end

private
Expand All @@ -38,4 +55,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!
22 changes: 19 additions & 3 deletions lib/fizzbuzz.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
class SuperFizzBuzz

def run(input)
output = ""
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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I am not seeing it. How would I use .tap here to avoid initializing output to an empty string?

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.

You could use it to simplify your code a bit here because it returns itself. You'll see .tap used quite a bit. Let's say...

def run_service
  api_service.tap do |s|
    s.prepare_data
    s.send_emails
    s.log_something
  end
end

In this particular case, you could...

"".tap do |fizz_buzz_string|
  fizz_buzz_string << "Fizz" if condition
  ...
end


#Implement your code here
divBy3 = input % 3 == 0
divBy5 = input % 5 == 0

end
if divBy3
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.

output << "Fizz"
end

if divBy5
output << "Buzz"
end

if divBy3 || divBy5
return output
Copy link
Copy Markdown
Member

@jaybobo jaybobo Mar 19, 2018

Choose a reason for hiding this comment

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

else
return input
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.

Or here?

end
end
end

#You don't necessarily need to execute this script to complete this challenge, but how would you "run" this method (pun intended) so that it printed a value to the terminal?
#

# puts SuperFizzBuzz.new.run

#HINT: it's an instance method.
6 changes: 4 additions & 2 deletions spec/deaf_grandma_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
end

it "says 'NOT SINCE 1964!' when we yell" do
#implement your test here
expect(script.speak("DO YOU LIKE KITTENS?")).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 "SEE YOU LATER SONNY!"
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(4)).to eq 4
end
end