This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by Riser
over 10 years

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

6 votes

Permalink

Yeah, there’s a silly thing you missed: the famous Eric Weinstein wants you to

print "Ruby!"

thirty times. That’s "Ruby!". Without a trailing space.

points
Submitted by Alex J
over 10 years

Answer 52208876abf821d2210022f7

4 votes

Permalink

string = 0
loop do
    string += 1
    print "Ruby!"
    break if string > 30
end

This is my code. In the console window, I can see “Ruby!” 30 times. But it is asking me to do print “Ruby!” 30 times & I cannot to the next exercise.

points
Submitted by Shiraz
over 10 years

3 comments

Shiraz over 10 years

got it :) it should be 1 instead of 0

Joseph Sawyer over 10 years

Thank you for this.

Matthew C about 10 years

string = 1 //or// break if string >= 30 //or// break if string == 30

Answer 52ba97aa9c4e9dd1d900487c

2 votes

Permalink

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

points
Submitted by amu300gmail.com
over 10 years

2 comments

Nat Veiga about 10 years

the same happened to me. thanks!

Matthew C about 10 years

it’s not an extra line, remember your counter is starting at 0, not 1. second last line should probably be break if counter >= 30

Answer 528ad2f3abf8211ce400020e

1 vote

Permalink

Should be

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

points
Submitted by Blake Craw
over 10 years

6 comments

Maddy Andrade over 10 years

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!

Blake Craw over 10 years

counter would be like an integer, where string would be a word (i.e. Ruby). Hope this helped

Andrew Kocurek over 10 years

Not following you on this one, you say string is a word but you clearly have an integer there.

Fridah Nyagu over 10 years

I dont think counter or string has any effect,It can be any letter

ADS KUL almost 10 years

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

ADS KUL almost 10 years

worked for me

Answer 52a36bc48c1ccccdf6002742

0 votes

Permalink

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

points
Submitted by Fridah Nyagu
over 10 years

Answer 544573bd631fe9af2f00aa31

0 votes

Permalink

x = 1 loop do x +=1 print “Ruby!” break if x >= 31 end

This worked for me

points
over 9 years