Thith Meanth War 4/8 - error message



Really sorry to bother you, but I'm doing a bit of a "crash course" on Ruby (I'm attending an information event on coding on Sunday!) and I'm stuck.

In Lesson 4 of Thith Meanth War, I've entered my code and keep getting an error message telling me the "if" syntax is wrong and that I should make sure the code ends with "end".

I've looked for ages to see where the error is, checked previous lessons and questions on here etc.

I added an "else" command, which I'm not sure is necessary for this task, but it doesn't work without it either.

Apologies in advance - I know it'll be something obvious! Any help gratefully received.

print "Tell me something about yourself"
user_input = gets.chomp
if user_input.include? "s" print "Ah, we'll change a certain letter here"
puts "That's all fine"


It works for me. Whenever this happens, try refreshing the page, clearing the browser cache, or reading carefully what exact strings the lesson wants.


Hi Twmbarlwm,

Don't worry about bothering us - we're here to help you :)
I'm not able to see the indentation in your code because you didn't format it - you can do that by selecting it while editing your post and pressing Ctrl/Cmd + K.
I think the problem is that you need a new (indented) line after "s" on line 4. That part of your code should look like this:

if user_input.include? "s"
    print "Ah, we'll change a certain letter here"
    puts "That's all fine"

I hope this helps!
Please let me know if you have any more questions :)


Hi - I've just sorted it!

I jumped to the next lesson (first time I've ever done that, honest!) and added the .gsub method.

This meant the print "Ah, we'll change a certain letter" was deleted. This new code worked OK, so I figured the error must be in the deleted bit.

All I could think of was to move it down to a separate line. I did this and it worked! Not quite sure why, but I'm glad it's sorted.




Ruby is whitespace dependent, so you have to be careful about new lines and indentation in Ruby :)
Some languages, such as JavaScript aren't, so you could do this:

if (condition) { doStuff() }

and it wouldn't throw an error, but Ruby isn't one of those languages.


Hi zystvan

Thanks for the explanation - I'm sorry, I didn't notice your reply before I posted about working it out.



Thanks - I didn't notice this reply either, sorry. You guys move fast!

I'll bear what you say in mind in future.