Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finished challenge - David and Luke #98

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source 'https://rubygems.org'
ruby '2.0.0'

gem 'rspec', '~> 3.0.0.beta2'
gem 'rspec', '~> 3.0.0.beta2'
24 changes: 22 additions & 2 deletions lib/deaf_grandma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class DeafGrandma

def initialize
@bye_counter = 0
@bye_counter = 0
end

def run!
Expand All @@ -19,13 +19,33 @@ def run!


def speak(input)

Choose a reason for hiding this comment

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

Nice job solving it! Does this method look like it's got a lot of decisions being made? Think about how you might be able to refactor this to make the code paths a little easier to follow.

Copy link
Author

Choose a reason for hiding this comment

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

Refactored the code to reduce if statements and minimize code block length

#Check for yel

if input == input.upcase
if input == "BYE"
bye_function
else
"NOT SINCE 1964!"
end
else
"SPEAK UP SONNY!"
end

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

end

private

def bye_function
if @bye_counter < 2
@bye_counter += 1
""
else
@bye_counter = 0

Choose a reason for hiding this comment

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

You don't need to reset the bye counter here and see if you can get the program to exit after the 3rd bye.

"SEE YOU LATER SONNY!"
end
end

def print_welcome
puts "\nSpeak to your Grandmother: "
end
Expand Down
10 changes: 9 additions & 1 deletion lib/fizzbuzz.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ class SuperFizzBuzz

def run(input)

#Implement your code here
if input % 15 == 0
"FizzBuzz"
elsif input % 3 == 0
"Fizz"
elsif input % 5 == 0
"Buzz"
else
input
end

end

Expand Down
9 changes: 6 additions & 3 deletions spec/deaf_grandma_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
it "says 'SPEAK UP SONNY!' when we speak regularly" do
expect(script.speak("Hi Grandma")).to eq "SPEAK UP SONNY!"
end

it "says 'NOT SINCE 1964!' when we yell" do
#implement your test here
expect(script.speak("HI GRANDMA WHEN DID YOU LAST EAT NOODLES.")).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 ""
expect(script.speak("BYE")).to eq ""
expect(script.speak("BYE")).to eq "SEE YOU LATER SONNY!"
end
end
11 changes: 6 additions & 5 deletions spec/fizzbuzz_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
it "returns 'Fizz' when my input is divisible by 3" do
expect(script.run(3)).to eq "Fizz"
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
input_number = 1
expect(script.run(input_number)).to eq input_number
end
end