How to join words?


#1

This code is working, but the New York is printed to console separately. Have you ideas how to join two words in my word variable?
I've googled .join method, but not sure how to use it. Maybe I should to add to line 10 ? (Actually, the course doesn't accept my .join method at all). Thanks in advance

saved_new_var = word.join(word+" ")


#2

irb(main):001:0> ['new', 'york'].join ' '
=> "new york"

#3

Do you mean in my line 12 of code?

saved_new_var = [word].join' '

Unfortunately, I can not check it properly, the console gives me: undefined method `join' for "NEW":String!'
Thank you


#4

That's not quite what I did, I called join on an array of strings, you called it on something else. Didn't get the calling syntax right either! How do you call a method with one argument? (I expect this isn't something new)


#5
  1. My code doesn't know that the user will type "new york", so instead of ['new', 'york'] shouldn't I continue to use to develope my code my variable named 'word'?
  2. Than I've tried to create a new redacted string and save it as a variable, that is named saved_new_var.
  3. Polygon is new subject for me as this course is the first one I am learning Ruby and it wasn't discussed here.

#6

I imagine that

saved_new_var = word.join' '

should be right in this case, but I can't to check it.
https://www.codecademy.com/en/courses/ruby-beginner-en-mzrZ6/0/6?curriculum_id=5059f8619189a5000201fbcb


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.