So I\'m working on a JSFiddle and I\'m a little confused about something. I have an input box called myTextField with a random paragraph and a button that calls my change functi
So what you could do is search the array of words and compare to the value. Your original code looked to see if the element was an array.
(function() {
'use strict';
function change() {
var matches = ["every", "most", "that", "half", "much", "the", "another", "her", "my", "their", "a", "an", "his", "neither", "these", "all", "its", "no", "this", "any", "those", "both", "least", "our", "what", "each", "less", "several", "which", "either", "many", "some", "whose", "enough", "more", "such", "your"],
myNewTitle = document.getElementById('myTextField').value,
title = document.getElementById('title'),
doesMatch = matches.reduce(word => myNewTitle.search(word) >= -1);
if (doesMatch) {
console.log('yes');
title.style.color = 'green';
} else {
console.log('no match');
title.style.color = 'red';
}
title.innerHTML = myNewTitle;
}
document.querySelector('#byBtn').addEventListener('click', change, false);
}());
Using Arrays to change color...