Redacted 5 Control Flow


#1

Giving this error message?!
(ruby):20: syntax error, unexpected $end, expecting keyword_end

This is my code:

puts "What is the text we should check?"
text = gets.chomp

puts "What word should we redact?"
redact = gets.chomp

words = text.split(" ")

words.each do |word|
if word == redact
print "REDACTED "
else
print "#{word}" + " "
end


#2

For anyone having the same problem ill answer my own question :wink: Spot the extra 'end'

My code:

puts "What is the text we should check?"
text = gets.chomp

puts "What word should we redact?"
redact = gets.chomp

words = text.split(" ")

words.each do |word|
if word == redact
print "REDACTED "
else
print "#{word}" + " "
end
end


#3

use an end at last for if else condition


#4

This is why you should always indent your code and follow proper coding style. For Ruby, use 2 spaces for indentation after constructs that have an "end." That way, you can always easily check whether you have "unfinished" statements or constructs.