diff --git a/Gemfile.lock b/Gemfile.lock index dfd2ba5..3b37d98 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -17,6 +17,10 @@ GEM PLATFORMS ruby + x64-mingw-ucrt DEPENDENCIES rspec (~> 3.0.0.beta2) + +BUNDLED WITH + 2.4.10 diff --git a/lib/deaf_grandma.rb b/lib/deaf_grandma.rb index 83ad52a..d5fce03 100644 --- a/lib/deaf_grandma.rb +++ b/lib/deaf_grandma.rb @@ -19,8 +19,23 @@ def run! def speak(input) - #Implement your code here <<<<<<<<< + if input == "BYE" + @bye_counter = @bye_counter + 1 + p @bye_counter + if @bye_counter == 3 + p "SEE YOU LATER SONNY!" + exit + end + end + + if input != input.upcase + return "SPEAK UP SONNY!" + end + + if input == input.upcase + return "NOT SINCE 1964!" + end end @@ -38,4 +53,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! diff --git a/lib/fizzbuzz.rb b/lib/fizzbuzz.rb index 86f9def..2e95107 100644 --- a/lib/fizzbuzz.rb +++ b/lib/fizzbuzz.rb @@ -1,13 +1,18 @@ class SuperFizzBuzz def run(input) - - #Implement your code here - + if (input % 3 == 0 and input % 5 == 0) + "FizzBuzz" + elsif input % 5 == 0 + "Buzz" + elsif input % 3 == 0 + "Fizz" + else input + 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. diff --git a/spec/deaf_grandma_spec.rb b/spec/deaf_grandma_spec.rb index cf09766..78860b1 100644 --- a/spec/deaf_grandma_spec.rb +++ b/spec/deaf_grandma_spec.rb @@ -5,14 +5,20 @@ let(:script) { DeafGrandma.new } it "says 'SPEAK UP SONNY!' when we speak regularly" do - expect(script.speak("Hi Grandma")).to eq "SPEAK UP SONNY!" + expect(script.speak("speak")).to eq "SPEAK UP SONNY!" end it "says 'NOT SINCE 1964!' when we yell" do #implement your test here + expect(script.speak("YELL")).to eq "NOT SINCE 1964!" end it "EXTRA CREDIT: How would you test yelling BYE?" do #implement your test here + expect { + 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!" + }.to raise_error(SystemExit) end end diff --git a/spec/fizzbuzz_spec.rb b/spec/fizzbuzz_spec.rb index cfda46b..ebe1979 100644 --- a/spec/fizzbuzz_spec.rb +++ b/spec/fizzbuzz_spec.rb @@ -9,14 +9,15 @@ 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(16)).to eq 16 + expect(script.run(7)).to eq 7 end end