let btns = document.querySelectorAll("button");
function choosenOrder(chices1) {
let btnsPair = [chices1[0], chices1[1]];
btnsPair.forEach((choice) => {
choice.addEventListener("click", (c1) => {
let mychoice = c1.target.textContent;
return mychoice;
})
})
}
console.log(choosenOrder(btns));
//return undefined
I will be simple and direct...
I want to return the text value of the button i press using the listener function inside addEventListener. However this is not working as expected, and what ever i try it either returns undefined or not work at all, is it even possible to return a value from an event listener?
If it is not, what kinda of alternatives do I have?
Thanks in advance!