5/6 control flow know how


#1

hi, can some one help me with my code?

i keep getting this error (ruby):10: syntax error, unexpected $end, expecting keyword_end

my code is

puts = "user input"
text= gets.chomp
puts "word to redact"
redact= gets.chomp
words=text.split(",")
words.each do |word|
if word == redact
print = "REDACTED "
else
print word + " ".
end


#2

You're missing the keyword end for your each statement.


#3

Your code
puts = "user input"
text= gets.chomp
puts "word to redact"
redact= gets.chomp
words=text.split(",")
words.each do |word|
if word == redact
print = "REDACTED "
else
print word + " ".
end
My code!


#4

Omg. thank you. I realised where i went wrong. Why does a equal sign in the print "REDACTED " cause the code to change?


#5

Because it makes "REDACTED " a string variable named print, instead of an ' if ' action.

print = "REDACTED "

if word == redact
print "REDACTED"

Hope this helped.


#6

thank you very much !!!


#7

Hello, my code is just like the one you used here and it doesn't work. I also copied and pasted yours and it did not work. I am stuck. Can you help me?

puts "where are you from"
text=gets.chomp
puts "Italy"
redact=gets.chomp
words=text.split(",")
words.each do |word|

if word == redact
print "REDACTED"
else
print word +""

end


#8

I think you need redact in "" because it is a string.

if word == "redact"


#9

Hello! I'm having the same issue. Here's my code.
puts "Text to search through"
text = gets.chomp
puts "Word to redact"
redact = gets.chomp
words = text.split(" ")
words.each do |words|
print words
if words == "redact"
print "REDACTED "
else print words + " "
end
end


#10

im also having issues if anyone can help thatd be great.

puts "Why so serious?"
text= gets.chomp
puts "You talkin to me?"
redact= gets.chomp
words= text.split(" ")
words.each do |words|
print words
end
if word != redact
print "REDACTED "
else
print +" "
end


#12

change the do| words| into any random text like toll,hfgbkj, anything...
also put the 1st end at the last ...


#13

I'm stuck at this one. My code works perfectly, but CodeCademy is telling me "Oops, try again. Make sure to print each word from the user's text to the console unless that word is the word to be redacted; if it is, print REDACTED (all caps!)." Any idea what is going wrong here? I'm quite sure my code works just fine, and I followed the instructions. I just want to get past this part.

puts "Gimmie some text with your name in it somewhere."
text = gets.chomp

puts "What's your name again?"
name = gets.chomp

words = text.split(" ")
words.each do |word|
    if word == name
        print "REDACTED "
    else
        print word + " "
    end
end

#14

Sigh. So apparently in order to pass the test, you have to include the word you're redacting MORE THAN ONCE. Otherwise it will fail. Even though it doesn't say you need to do that. Excellent. At least I managed to get my code accepted...