/ Chyba nespracovanej syntaktickej chyby v buzzingovom kóde v Ruby - ruby, rspec

Nespracovaná syntaktická chyba v buzzingovom kóde v Ruby - ruby, rspec

Nemôžem zistiť svoju syntaktickú chybu. Od môjho čítania očakáva koncové kľúčové slovo?

Som "zahrnovať rspec súbor, ktorý je testovanie môjho kódu okrem chybové hlásenie a kód.Ďakujem všetkým, ktorí pomáhajú!

def fizzbuzz(int)
if int % 3 == 0;
puts "Fizz";
if int % 5 == 0;
puts "Buzz";
if int % 3 && 5 == 0;
puts "FizzBuzz";
end

Súbor RSPEC:

require_relative "./spec_helper.rb"

describe "fizzbuzz" do
it "returns "Fizz" when the number is divisible by 3" do
fizz_3 = fizzbuzz(3)

expect(fizz_3).to eq("Fizz")
end
it "returns "Buzz" when the number is divisible by 5" do
fizz_5 = fizzbuzz(5)

expect(fizz_5).to eq("Buzz")
end
it "returns "FizzBuzz" when the number is divisible by 3 and 5" do
fizz_15 = fizzbuzz(15)

expect(fizz_15).to eq("FizzBuzz")
end
it "returns nil when the number is not divisible by 3 or 5" do
fizz_4 = fizzbuzz(4)

expect(fizz_4).to eq(nil)
end
end

CHYBA:

/Users/user/Development/code/rspec-fizzbuzz-001-prework-web/spec/spec_helper.rb:8:in `require_relative": /Users/user/Development/code/rspec-fizzbuzz-001-prework-web/fizzbuzz.rb:8: syntax error, unexpected end-of-input, expecting keyword_end (SyntaxError)
from /Users/user/Development/code/rspec-fizzbuzz-001-prework-web/spec/spec_helper.rb:8:in `<top (required)>"
from /Users/user/Development/code/rspec-fizzbuzz-001-prework-web/spec/fizzbuzz_spec.rb:1:in `require_relative"
from /Users/user/Development/code/rspec-fizzbuzz-001-prework-web/spec/fizzbuzz_spec.rb:1:in `<top (required)>"
from /Users/user/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1361:in `load"
from /Users/user/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1361:in `block in load_spec_files"
from /Users/user/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1359:in `each"
from /Users/user/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.1/lib/rspec/core/configuration.rb:1359:in `load_spec_files"
from /Users/user/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:102:in `setup"
from /Users/user/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:88:in `run"
from /Users/user/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:73:in `run"
from /Users/user/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.1/lib/rspec/core/runner.rb:41:in `invoke"
from /Users/user/.rvm/gems/ruby-2.2.1/gems/rspec-core-3.4.1/exe/rspec:4:in `<top (required)>"
from /Users/user/.rvm/gems/ruby-2.2.1/bin/rspec:23:in `load"
from /Users/user/.rvm/gems/ruby-2.2.1/bin/rspec:23:in `<main>"
from /Users/user/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval"
from /Users/user/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>"

odpovede:

0 pre odpoveď č. 1

musíte ukončiť svoje vyhlásenia if, toto by malo problém vyriešiť:

def fizzbuzz(int)
if int % 3 == 0
puts "Fizz"
end
if int % 5 == 0
puts "Buzz"
end
if (int % 3 == 0) && (int % 5 == 0)
puts "FizzBuzz"
end
end

0 pre odpoveď č. 2

Chcete niečo také:

def fizzbuzz(int)
if int % 3 == 0 && int % 5 == 0
puts "FizzBuzz"
elsif int % 3 == 0
puts "Fizz"
elsif int % 5 == 0
puts "Buzz"
end
end

Tým sa bude zobrazovať iba "FizzBuzz", ak je násobkom obidvoch "Fizz" iba pre násobky len 3 a "Buzz" pre násobky len 5.