As a newcomer to programming, I understand that variables inside a function cannot be accessed outside of it. However, I am in need of the object stored in 'call'. Is there any way to extract data from this object? I have attempted declaring 'call' outside of the function but it remains empty.
function itemCollection(question, answer) {
this.question = question;
this.answer = answer;
}
const empty = new itemCollection('empty', 'empty');
const empty2 = new itemCollection('1', '2');
function randomitem() {
let call = itemCollection[Math.floor(Math.random() * itemCollection.length)];
}
randomitem()
console.log(call);
The error:
Uncaught ReferenceError: call is not defined