title: Incorrect Return Value for Comparison Function?
body: <p>The function, expensiveItem(menu), should return the most expensive item in the array, meals. In this case, it should return "Double Quarter Pounder with Cheese". Instead, it returns "Double Cheeseburger". Where did I go wrong in my 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 item1 = {
    name: "Big Mac",
    price: 3.99,
    calories: 530
  };
  var item2 = {
    name: "Filet-O-Fish",
    price: 3.79,
    calories: 390
  };
  var item3 = {
    name: "Double Cheeseburger",
    price: 1.59,
    calories: 430
  };
  var item4 = {
    name: "Double Quarter Pounder with Cheese",
    price: 4.79,
    calories: 740
  };
  var item5 = {
    name: "Chicken McNuggets",
    price: 4.49,
    calories: 190
  };
  
  var meals = [item1, item2, item3, item4, item5];
  
  
  function init() {
    var lowestCost = document.getElementById('cheapestItem');
  
    lowestCost.onclick = function() {
      cheapestItem(meals);
    }
  
    var highestCost = document.getElementById('highestCost');
  
    highestCost.onclick = function() {
      expensiveItem(meals);
    }
  
  }
  
  window.onload = init;
  
  
  // return name of cheapest item on menu
  function cheapestItem(menu) {
    var msg = document.getElementById('msg1'); // is this necessary? Code works fine without it...
  
    var cheapestItem = operation(menu, "less");
    msg1.innerHTML = "The cheapest item is " + cheapestItem;
  }
  
  // return name of most expensive item on menu
  function expensiveItem(menu) {
    var msg = document.getElementById('msg2');
  
    var expensiveItem = operation(menu, "greater");
    msg2.innerHTML = "The most expensive item is " + expensiveItem;
  }
  
  //return result based on given comparator operator
  function operation(menu, op) {
    var v1 = menu[0].price;
    var item;
  
    for (var i = 0; i &lt; menu.length; i++) {
      var v2 = menu[i].price;
  
  
      if ((op == "less" &amp;&amp; (v2 &lt; v1)) ||
        (op == "greater" &amp;&amp; (v2 &gt; v1))) {
        result = v2;
        item = menu[i].name;
      }
    }
    console.log(item);
    return item;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;body&gt;
  
    &lt;input type="button" id="cheapestItem" value="Cheapest Item"&gt;
    &lt;/div&gt;
    &lt;p id="msg1"&gt;message 1&lt;/p&gt;
  
    &lt;input type="button" id="highestCost" value="Most Expensive Item"&gt;
    &lt;/div&gt;
    &lt;p id="msg2"&gt;message 2&lt;/p&gt;
  &lt;/body&gt;</code></pre>
  </div>
  </div>
  </p>