I have an array
array = ["this","is","a","sentence"]
I want to print a string if one of the words in array matches a word I'm looking for.
Example:
array = ["this","is","a","sentence"]
array.each { |s|
if
s == "sentence"
puts "you typed the word sentence."
elsif
s == "paragraph"
puts "You typed the word paragraph."
else
puts "You typed neither the words sentence or paragraph."
end
This method will print:
"You typed neither the words sentence or paragraph."
"You typed neither the words sentence or paragraph."
"You typed neither the words sentence or paragraph."
"you typed the word sentence."
I want it to recognize the word "sentence" and execute "you typed the word sentence.". If one of those words is not present, it will execute the else statement "you typed neither the words sentence or paragraph.".