Just playing around can anyone tell me what's wrong


<Below this line, add a link to the EXACT exercise that you are stuck at.>


<In what way does your code behave incorrectly? Include ALL error messages.>

im just trying to play around and do a little back and forth with the code im sure it will go through it at some time in the future with the lessons however im trying to get a little ahead of the game and understand the code a little more if anyone can explain where ive gone wrong would really appreciate it, however if there s a concept to hard to explain that im going to get to anyone then just let me know and ill keep quiet haha thanks in advance

``` print" please write a short statement about yourself" user_input= gets.chomp user_input.downcase!

if user_input.include? “s”
user_input.gsub!(/s/, “th”)
puts “adios, #{user_input}!”

print " tho thilly of me it theemth to me that your thtatement didnt contain any th’th thorry s’s would you like to try again??"
user_input2= gets.chomp

if user_input2.include? “s”
user_input.gsub!(/s/, “th”)
puts"thank you, #{user_input2}!

print “lookth like i tried have a great day”
puts “#{user_input}!”

<do not remove the three backticks above>

What makes you say that you have gone wrong?

sorry bud i got this error code

(ruby):18: syntax error, unexpected tIDENTIFIER, expecting keyword_end
print “lookth like i tried have a great day”
(ruby):20: syntax error, unexpected $end, expecting keyword_end

and the code doesn’t run properly in the box

Soo… have you read the error message you just posted? It says what was wrong.

What’s preventing you from figuring this out yourself? Ask about that

1 Like

i appreciate that, ive had a look do i need an end before the second ‘if’ statement?
and sorry for wasting your time ionatan…

Ruby can’t tell you what you want. If it says it expects something, that only means that based on what it had read so far, that was the only thing left that it expected. Since it did not find that something, it had to stop because the code doesn’t make sense.

The actual mistake would therefore be somewhere before the place that it is pointing at. What it’s saying may give a few clues about what’s wrong. Here it points at lookth and says it’s a tIDENTIFIER, an identifier is a name that refers to some value, but is that what you mean for that to be? You probably mean for that to be a string, not code, so why is that not a string?

You know, I haven’t done much Ruby yet seeing as I just started, so I am going to improvise and say that instead of having an elsif statement at the end of each of your if statements, then you should put an else statement. You also suddenly ended your 1st if statement and started another one. Here is what you said

Notice that there are two problems, one is that you used elsif instead of else, and the other is that you didn’t use the key word end. Hope this helped and that I was able to improvise on Ruby :slight_smile:

Mmmh that’s not it.

The problem should be quite obvious if one looks at the colours applied by the code editor in the area where the error message is reported at.

I noticed from control flow in Ruby that they did it similar to something like Python, here is an example.
SO though it might not fix the entire problem, there should be some attention focused towards the if statement.

This also says the area of the last elsif statement, and that it needs looking at. The second error message says that it was expecting the keyword end and it never got it on the first if statement.

Nope. Waay off.

Look at the colours of the strings in the area of where the error message is reported (near the bottom)


edit oops: had saved it as .py, causing it to use wrong syntax highlighting. It was still showing, just slightly differently. updated image.

1 Like

Tell you what, I will take the code that I think will work on this, and I will run it in the labs.

Also notice on that picture that at the very end then the elsif statement is highlighted in red. It should be else, not elsif.

You’re right, there is an end missing. That’s not what the syntax error is though, it doesn’t get that far, and neither did I. The problem that ruby is reporting is about strings and the syntax highlighter says quite a lot about what is wrong. (white text instead of red, and the elsif is red)

That is true, and I haven’t gotten that far in Ruby, I will go get the help of one of the moderators.

Ok, I messaged Leonardo, Help Desk Gold.

I’m a moderator and have that help desk gold badge :<

I’m just failing to make you folks see things my way

I know that you are a moderator, but Leon has been around for a long time and as far as I know he knows more programming then most people that I know (except my dad :slight_smile: )

I’m feeling under-appreciated here. :sob:

What information are you looking for?


I feel like you are doing a really great job, but I think that neither of us understands what is going on with the strings.