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
@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
Answer 55f18aeae39efef749000390
Answer 50a15956197c9e1467007103
-10 votes
i = 0 loop do i+= 1 print “Ruby!” break if i >=30 end
is the right answer
1 comments
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
- Free course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner Friendly4 Lessons - Free course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner Friendly11 Lessons - Free course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner Friendly6 Lessons