1

I'm doing a codecademy tutorial to learn about Twitter's api. It requires us to print the response according to the following instructions

# ADD CODE TO PRINT THE TWEET IN "<screen name> - <text>" FORMAT

The following is saying that, although I'm parsing the response correctly, I'm not generating the correct output.

def print_tweet(tweet)
  user = tweet["user"]["name"]  
  text = tweet["text"]
  puts user + '-' + text

end

I'm so used to using instance variables in Rails that I'm not confident about simple Ruby like this. How should I write the function to generate output in this format?

"<screen name> - <text>"

2 Answers 2

6

Prefer string interpolation instead of string concatenation:

Replace: puts user + '-' + text

With:

puts "#{user} - #{text}"
Sign up to request clarification or add additional context in comments.

Comments

1

You forget to add spaces around the - in your output. It should read

puts user + ' - ' + text

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.