This forum is now read-only. Please use our new forums! Go to forums
Print "Ruby!" 30 times.
counter = 0
loop do
counter += 1
print "Ruby! "
break if counter >= 30
end
That’s my code, why isn’t it doing it for me? It always adds nil at the after it prints ruby 30 times. Is there some silly thing I’m missing?
Alex J edited this post to fix code formatting
Answer 521b1fb780ff33560e000f94
Answer 52208876abf821d2210022f7
Answer 52ba97aa9c4e9dd1d900487c
Hey guys I had the same problem here is my code that works. I have noticed that it prints an extra line at the end of nearly everything I code, so using the 29 gets me to the 30 they ask for:’
counter = 0 loop do counter += 1 print “Ruby!” break if counter > 29 end
Answer 528ad2f3abf8211ce400020e
Should be
string = 0 loop do string += 1 print “Ruby!” break if string >= 30 end
6 comments
Do you know what the difference is between writing string vs counter in this exercise? I wrote the same thing you did but just had counter instead. What you wrote worked perfectly but I just want to clarify the difference. I Thanks!
counter would be like an integer, where string would be a word (i.e. Ruby). Hope this helped
Not following you on this one, you say string is a word but you clearly have an integer there.
I dont think counter or string has any effect,It can be any letter
string = 0 loop do string += 1 print “Ruby!” break if string >= 30 end
worked for me
Answer 52a36bc48c1ccccdf6002742
counter = 0 loop do counter += 1 print “Ruby!” break if counter >= 30 end
Answer 544573bd631fe9af2f00aa31
x = 1 loop do x +=1 print “Ruby!” break if x >= 31 end
This worked for me
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
3 comments
got it :) it should be 1 instead of 0
Thank you for this.
string = 1 //or// break if string >= 30 //or// break if string == 30