From: Brandon Weaver Date: 2013-05-12T09:00:29+09:00 Subject: Re: Newbie - Grade My Method? --001a11c2c01077cb7604dc7a1662 Content-Type: text/plain; charset=ISO-8859-1 Read back through the description, from 1 to n. That means a range, like 1...5, and it wants you to print exactly as it says. This is typically the first problem for weeding out newbies. Personally I'd fail you because you didn't do things exactly like the specification. Look into: Range, Implicit Returns, and Print. On May 11, 2013 6:45 PM, "Pro Spectus" wrote: > Hi all, > > I'm trying to teach myself Ruby with the hope of doing a RoR bootcamp. > > I'm totally new to programming.. can you please give me feedback! > > # Write a program which iterates through numbers from 1 to n, > # and prints "fiz" if the number is divisible by 3, "buz" if it is > # divisible by 5, and "fizbuz" if it is divisible by both 3 and 5. > > def fizz(*numbers) > numbers.each do |i| > if i % 3 == 0 && i % 5 == 0 > puts "#{i} is fizbuz cause it's divisible by both 3 and 5." > elsif i % 3 == 0 > puts "#{i} is fiz cause it's divisible by 3." > elsif i % 5 == 0 > puts "#{i} is buz cause it's divisible by 5." > else > puts "#{i} is not divisible by 3 or 5 -- FAIL!" > end > end > end > > puts fizz(3, 13, 29, 65, 97) > > -- > Posted via http://www.ruby-forum.com/. > > --001a11c2c01077cb7604dc7a1662 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

Read back through the description, from 1 to n. That means a= range, like 1...5, and it wants you to print exactly as it says. This is t= ypically the first problem for weeding out newbies. Personally I'd fail= you because you didn't do things exactly like the specification.

Look into: Range, Implicit Returns, and Print.

On May 11, 2013 6:45 PM, "Pro Spectus"= <lists@ruby-forum.com> w= rote:
Hi all,

I'm trying to teach myself Ruby with the hope of doing a RoR bootcamp.<= br>
I'm totally new to programming.. can you please give me feedback!

# Write a program which iterates through numbers from 1 to n,
# and prints "fiz" if the number is divisible by 3, "buz&quo= t; if it is
# divisible by 5, and "fizbuz" if it is divisible by both 3 and 5= .

def fizz(*numbers)
=A0 numbers.each do |i|
=A0 =A0 if i % 3 =3D=3D 0 && i % 5 =3D=3D 0
=A0 =A0 =A0 puts "#{i} is fizbuz cause it's divisible by both 3 an= d 5."
=A0 =A0 elsif i % 3 =3D=3D 0
=A0 =A0 =A0 puts "#{i} is fiz cause it's divisible by 3."
=A0 =A0 elsif i % 5 =3D=3D 0
=A0 =A0 =A0 puts "#{i} is buz cause it's divisible by 5."
=A0 =A0 else
=A0 =A0 =A0 puts "#{i} is not divisible by 3 or 5 -- FAIL!"
=A0 =A0 end
=A0 end
end

puts fizz(3, 13, 29, 65, 97)

--
Posted via http://= www.ruby-forum.com/.

--001a11c2c01077cb7604dc7a1662--