You make randomWord to a private variable of the function with a var statement. Without, you could use the global variable for the result.
function random_word() {
randomWord = word[Math.floor(Math.random() * word.length)];
}
var randomWord;
word = ["Michael", "Simon", "Peter", "Mark"];
random_word();
document.write(randomWord);
A better style and more concise would be the return of the selected item. An even better version, would be if you use the array as parameter as well, because you could use the function for other arrays as well.
function getRandomItem(array) {
return array[Math.floor(Math.random() * array.length)];
}
var words = ["Michael", "Simon", "Peter", "Mark"];
document.write(getRandomItem(words));
Bonus, add random name with interval.
function getRandomItem(array) {
return array[Math.floor(Math.random() * array.length)];
}
var words = ["Michael", "Simon", "Peter", "Mark"];
setInterval(function () {
document.getElementById('names').innerHTML += getRandomItem(words) + '<br>';
}, 2000);
<div id="names"></div>
3makes no sense, because the assignment has 4 items.