ayanda
(ayanda)
1
I keep getting unexpected token ‘[’ can someone help with where am going wrong?
let names = ['Chris', 'Li Kang', 'Anne', 'Francesca', 'Mustafa', 'Tina', 'Bert', 'Jada']
let para = document.createElement('p');
// Add your code here
function chooseName(names[0],names[names.length-1]){
return Math.floor(Math.random() * (names[names.length-1] - names[0]+1)) + names[0];
}
para= chooseName()
// Don't edit the code below here!
section.innerHTML = ' ';
section.appendChild(para);
few hints:
you have to create a function named chooseName
which gets no parameters.
the function should look like this:
function chooseName() {
...
}
inside the function you have to get random value from the array,
then use
para.textContent = the variable you created to save the value in;
after the function declaration, call to the function using this line of code:
chooseName();
you can see the full answer here (Warning, you should try it yourself before looking at the answers)