Just playing around can anyone tell me what's wrong


#1


https://www.codecademy.com/en/courses/ruby-beginner-en-JdNDe/0/8?curriculum_id=5059f8619189a5000201fbcb

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}!"

elsif
    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
user_input2.downcase!

if user_input2.include? "s"
    user_input.gsub!(/s/, "th")
    puts"thank you, #{user_input2}!
    
elsif
    print "lookth like i tried have a great day"
    puts "#{user_input}!"   
end


#2

What makes you say that you have gone wrong?


#3

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


#4

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


#5

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


#6

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?


#7

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:


#8

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.


#9

I noticed from control flow in Ruby that they did it similar to something like Python, here is an example.
https://www.codecademy.com/courses/ruby-beginner-en-NFCZ7/0/1?curriculum_id=5059f8619189a5000201fbcb
SO though it might not fix the entire problem, there should be some attention focused towards the if statement.


#10

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.


#11

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.


#12

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


#13

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


#14

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)


#15

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


#16

Ok, I messaged Leonardo, Help Desk Gold.


#17

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

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


#18

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: )


#19

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

What information are you looking for?


#20

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.