Issue with the program saying I am wrong when redacting the last word


#1

Here is the code I am using and it works fine when I use a word in the middle but codecademy does not let you move on if it is the last word due to the space being added at the end. what is causing this? I am super curious if it is something that can be fixed by an if statement saying if it is the last word in a sentence to not add a space?

puts "Please enter text"
text = gets.chomp
puts "What word would you like replaced?"
redacted = gets.chomp

words = text.split(" ")

words.each do |word|
if word == redacted
print "REDACTED "
else
print word + " "
end
end


#2

nevermind apparently it fixed itself. after refreshing the browser it allowed me to this so not sure if codecademy was tired of me messing with the code then submitting again and again or what.