I am trying to assign an output of a created element but keep getting a 'ReferenceError' response is not defined.
I followed instructions online and this worked on my other function I built. I have no idea why it is not working here and would like to understand the process of what is happening and what caused the error for future reference.
-My expectation is that I selected the body element.
-I don't know what the 'section.innerHTML = ''; does and could not find an explanation online. Mozilla had it in there so I just kept it.
-I assigned a variable 'para1' to the created element 'p'.
-I then assigned an output variable to the innertext of 'para1'
-I don't understand how it is saying response is not defined.
Thank you
UPDATE: Sorry I new to Javascript and obviously have things to learn. I am trying to create a variable to output to the created element 'p' in my function. The assignment is to create an array and randomly output a name using Math.random().
I was just trying to get everything created first. I am not done building this function, I just put the variable 'response' in the function to show that I am trying to use the created variable 'response' to output my strings in the function.
let names = ['Chris', 'Li Kang', 'Anne', 'Francesca', 'Mustafa', 'Tina', 'Bert', 'Jada']
let random = Math.floor(Math.random() * 9);
// Add your code here
function chooseName(names) {
response = 'response';
}
let section = document.querySelector('body');
section.innerHTML = '';
let para1 = document.createElement('p');
para1.innerText = response;