I'm currently going through a Javascript tutorial on YouTube and I've encountered an error that's puzzling me. Everything seems to be in order with the array definition.
Uncaught ReferenceError: words is not defined
window.addEventListener("load",initial());
//Global variables
let time = 5;
let score =0;
let isPlaying;
//DOM variables
const wordInput_input= document.querySelector('#word-input');
const currentWord_h2 = document.querySelector('#current-word');
const scoreDisplay = document.querySelector('#score');
const timeDisplay = document.querySelector('#time');
const message = document.querySelector('#message');
const seconds = document.querySelector('#seconds');
const words = ['hat', 'river', 'lucky', 'state'];
//Initialize game
function initial(){
//Load word from the array
showWord(words);
}
//Pick and display random word
function showWord(words){
//Generate random array index
const randIndex = Math.floor(Math.random() * words.length);
// Display random word
currentWord_h2.innerHTML = words[randIndex];
}