Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Justin Estrada
Justin Estrada
34,995 Points

I always get this error: syntax error, unexpected keyword_end, expecting end-of-input and i don't know what to do.

def sum_nums(num) ;
long = num.to_s ;
sum = nil ;
n = 0 ;


While n < num.length ;
   sum = long[n] + sum ;
   n = n + 1 ;
end  

end

this is the code

2 Answers

Colin Marshall
Colin Marshall
32,861 Points

You're missing the do in your while loop. You should also make "while" all lowercase.

while n < num.length do
   sum = long[n] + sum 
   n = n + 1 
end
Javier Perez
Javier Perez
3,337 Points

also there is no need for the semi colon ( ; ) at the end of every line.

Colin Marshall
Colin Marshall
32,861 Points

It is optional, but it makes your code look ugly IMO.

Ryan Drake
Ryan Drake
12,587 Points

I agree.

Don't write Ruby like you write JavaScript - quite different!