Q:

JavaScript search string contains?

I have a little problem with my current code.
I have a textBox in which I want to enter a search frase,  and get an answer that somehow rely to what I have asked.
It works OK as long as I only enter a single word in my textBox,  if my Array holds that word it will be found.
But when I enter a full Question like: How old are you ?
even that my Array holds the word: "old"
 It wont get found.
How can I correct this behaviour  ?
function askQ(){
  var searchWord = new Array("age","old","color","fun","eyes",
                                "legs","eye","leg");
  var findme = document.getElementById('askBox').value;

  if (searchWord.indexOf(findme) > -1 ) {
  document.getElementById('bubble').innerHTML = "FOUND IT!";
} else {
  document.getElementById('bubble').innerHTML = "SORRY!";
}

A:

Your code currently checks to see if the whole input string is inside of the array. This means it is checking to see if "How old are you" is contained inside of the array - which it is not.
You will probably need to iterate through the entire array, and compare each string in the array to the input.
document.getElementById('bubble').innerHTML = "SORRY!";
for (var i = 0; i < searchWord.length; i++) {
    if(findme.indexOf(searchWord[i])>-1){
        document.getElementById('bubble').innerHTML = "FOUND IT!";
    }
}

