Im stuck with an error: output is not defined
Trying to split the code from Functions 1 skill test so, that the randomIndex is calculated in separate function.
Here’s my code:
let names = ['Chris', 'Li Kang', 'Anne', 'Francesca', 'Mustafa', 'Tina', 'Bert', 'Jada']
let para = document.createElement('p');
// Add your code here
function chooseName(names) {
let randomIndex = random(names.lengt);
para.textContent = names[randomIndex];
}
function random(randomIndex) {
randomIndex = Math.floor(Math.random() * randomIndex);
return randomIndex;
}
chooseName(names);
// Don't edit the code below here!
section.innerHTML = ' ';
section.appendChild(para);