Q:

Display random value of text from an array

I have the following:
var movie;

var myMovies = ['Bones', 'Psych', 'Big Bang Theory', 'Mad Men', 
'Breaking Bad', 'Modern Family', 'Game of Thrones', 'Dexter','Bones', 'Psych', 'Big Bang Theory', 'Mad Men', 
'Breaking Bad', 'Modern Family', 'Game of Thrones', 'Dexter','Bones', 'Psych', 'Big Bang Theory', 'Mad Men', 
'Breaking Bad', 'Modern Family', 'Game of Thrones', 'Dexter'];

function generateMovies () {
  var movie = myMovies[Math.floor(Math.random() * myMovies.length)];
}

function displayMovie() {
  generateMovies();
  console.log(movie);
  $('body').text(movie);

  setTimeout(function(){
    displayMovie();
},1000);
}

displayMovie();

I would like to generate a different movie name and show them on the screen. Seems to be straight forward but obviously not! Seems like may variable is undefined.
Thanks!
Fiddle: https://jsfiddle.net/4ggwva4f/8/

A:

You are declaring the variable movie inside the function, so you are not assigning the value to the global variable.

