Profile image of systemAce78303
Submitted by systemAce78303
over 13 years

iterating with .times method, "It looks like you didn't print out the string 'Ruby!' 30 times."

It’s telling me there are the “wrong number of arguments” when I write

30.times print “Ruby!”

Any advice?

Answer 50a222bd797b866e30001981

7 votes

Permalink

@Chris you see the “wrong number of arguments” error because you forgot the { } to delimit the block you need to pass to .times. The .times method doesn’t accept any arguments (only a block), so if a word follows it, it assumes that it’s supposed to be an argument and throws that error.

30.times { 
  # do something
} 

# or, the equivalent

30.times do 
  # do something
end
Profile image of fanaugen
Submitted by fanaugen
over 13 years

Answer 55f18aeae39efef749000390

0 votes

Permalink

the syntax is

30.times do |x| print “Ruby!” end

Profile image of adekayor
Submitted by adekayor
over 10 years

Answer 50a15956197c9e1467007103

-10 votes

Permalink

i = 0 loop do i+= 1 print “Ruby!” break if i >=30 end

is the right answer

Profile image of SherryIcy
Submitted by SherryIcy
over 13 years

1 comments

Profile image of kakubei
Submitted by kakubei
almost 13 years

This is definitely NOT the Ruby way to do it. Alex J’s answer is much better. In Ruby there’s rarely any need to use i = 0, etc loops.

Popular free courses

  • In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.
    • Beginner Friendly.
      4 Lessons
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      11 Lessons
  • Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.
    • Beginner Friendly.
      6 Lessons
Explore full catalog