Skipping non matching strings when looping through an array in javascript
<p>In the code below I have a form input. When the user searches for a string that happens to be in the array I want it to output the query. When a user happens to search for a string not in the array I want to output an error message. The problem is when a user searches for a string that is other than item [0] in the array (in this case <em>ipsum</em>) they get an error message <em>and then</em> they get their query returned.  I want to know if this can be remedied using the code below or if a different methodology for doing this should be pursued ( I know that's an opinion ).</p>

<pre><code>&lt;form&gt;
&lt;input type="text" id="formInput"&gt;&lt;/input&gt;
&lt;input type = "button" id="search"&gt;&lt;/input&gt;

&lt;/form&gt;


&lt;script&gt;


var search = document.getElementById("search");


var data = ["lorim", "ipsum"];

search.onclick = function(){
var formInput = document.getElementById("formInput").value;
for (i=0; i&lt;data.length; i++){

    if (data[i] === formInput) {

      alert(data[i]);
    }   
      else{ alert("not working yet");   }
}
};

&lt;/script&gt;
</code></pre>
