I'm trying to write text chosen from a set of random strings inline with text in the html body. Here is my code so far:
Javascript
var textArray = [
'STRING 1',
'STRING 2',
'STRING 3',
'STRING 4',
'STRING 5',
'STRING 6'];
var randomNumber = Math.floor(Math.random() * textArray.length);
document.getElementById('output').innerHTML = (textArray[randomNumber]);
HTML
<body>
TEXT <span id="output"></span> TEXT
</body>
It works in JSFiddle, but I get an error in browser "Uncaught TypeError: Cannot set property 'innerHTML' of null." What's wrong with this? Also, is there a more efficient way of doing this? Here is the JSFiddle.