title: Find the longest word/string in an array
body: <p>I just started learning JavaScript. I am trying to write a JavaScript to find and print the longest word in an Array. I came up with the code below:</p>
  
  <pre><code>var longWords = ["Penelope", "Johny", "Aubumayang", "Czechoslovakia", "Slovenia"]
  var longest = 0;
  for (var i = 0; i &lt; longWords.length; i++) {
  if (longest &lt; longWords[i].length) {
      longest = longWords[i];
    }
  }
  
  console.log(longest)
  </code></pre>
  
  <p>The problem is it always end up printing the  first element in the array. which means <code>longest = longWords[0]</code>. Now when I change the line <code>longest = longWords[i]</code> to <code>longest = longWords[i].length</code> I get the count of the longest character. Please tell me why it didn't work and how I can do this using the <code>for</code> loop.</p>