Why is my code not working


#1



https://www.codecademy.com/courses/ruby-beginner-en-mzrZ6/0/5?curriculum_id=5059f8619189a5000201fbcb#


text = puts "what do you want printed"
text = gets.chomp
word = puts "loop"
word = gets.chomp
re_dact = "nothing to do here"
words = text.split(",")
words.each do |words|
if words == word
    print "redacted "
else
    print words
end


#2

the error is : (ruby):11: syntax error, unexpected $end, expecting keyword_end


#3

You need to end your words.each.


#4

what do you mean by that? i dont understand:confused:


#5

The syntax error is coming from the fact that you started your words.each loop, but you didn't finish it after your if statement. Once you add an end after the if statement, the syntax error should go away. There's also a few other error that will cause the code to not function right. For example, there is no need to set text to puts "Question." You should just use puts, and then set text to gets.chomp. Also in your else statement, you don't want to print all words. You want to print the word in words that you loop is on.


#6

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