title: displaying "no results" if input doesn't match array name (javascript)
body: <p>I have a search function that lets the user search for an item, and if stored, will display a message (inside my results div) if it's in stock or not.  </p>
  
  <p>I would like a "no results" message to display until the search finds a result.</p>
  
  <p>I've tried but I'm having trouble. 
  If you guys could help, I'd really appreciate it. </p>
  
  <p>Here's my full code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var user = document.getElementById('user');
  var results = document.getElementById('results');
  
  $('#user').keyup(function() {
    search(user.value);
  });
  
  var apples = {
    firstName: "apples",
    stock: "in stock"
  };
  
  var bananas = {
    firstName: "bananas",
    stock: " not in stock"
  };
  
  var contacts = [apples, bananas];
  
  function printPerson(person) {
    results.innerHTML = (person.firstName + " are " + person.stock);
  }
  
  function list() {
    var contactsLength = contacts.length;
    for (var i = 0; i &lt; contactsLength; i++) {
      printPerson(contacts[i]);
    }
  }
  
  
  function search(match) {
    var contactsLength = contacts.length;
  
    for (var i = 0; i &lt; contactsLength; i++) {
      if (contacts[i].firstName == match) {
        printPerson(contacts[i]);
      }
    }
  
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;input type="text" id="user" placeholder=" type here" /&gt;
  &lt;div id="results"&gt;&lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>