Building the word array


#1



https://www.codecademy.com/courses/ruby-beginner-en-693PD/0/3?curriculum_id=5059f8619189a5000201fbcb


What is wrong with the code? I keep getting this error: Oops, try again. It looks like you didn't set words equal to text.split.


puts "Please enter text: "
text = gets.chomp
words = text.split (",")


#2

Normally, words in a sentence are separated by space characters, not commas.

words = text.split(" ")

We're telling Ruby to break up the sentence into an array of words, and discard the space characters.


#3

I tried with and without the comma. It still did not accept my code.

Is there a reason why this code worked?

puts text = gets.chomp
text = gets.chomp

words = text.split


#4
 text.split

defaults to splitting on single spaces, but ignores leading and trailing white space.


#5

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