This forum is now read-only. Please use our new forums! Go to forums
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
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 friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
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.