I can't seem to assign an array value to a variable. It always returns undefined. 

In my code I have set currentWord = text[wordPos]. At the end of the code I have console logged currentWord, and text[wordPos]. My thinking says that they should return the same value, but they don't. currentWord returns undefined, and text[wordPos] returns the correct value (the first word in the 'text' array).

**Solved. I had mistakenly forgot that I had 2 arrays, and thought the text array was not empty, but it was. The words array is the array I had filled in separate file.**

```js
var text = Array();

var wordPos = 0;
var currentWord = text[wordPos];

function gen() {
  text = [];
  var random;

  for (var i = 0; i < 10; i++) {
    random = words[Math.floor(Math.random() * 50)];
    text.push(random);
  }
  document.getElementById('text').innerHTML = text.join(" ");

  console.log(currentWord);
  console.log(text[wordPos]);
}
```