`const player = {
    currentChoice: null //my initial declaration
};



//creating a function to give one of 3 choices to player
const playerChooses = () =>{
    let value; //declaring a new variable
    
    //returning the text of the button using onclick function
    document.getElementById('pick1').onclick = function(e) {
        value = e.target.innerText;
        console.log(value);
        return String(value);

    }
    document.getElementById('pick2').onclick = function(e) {
        value = e.target.innerText;
        console.log(value);
        return String(value);
    }
    document.getElementById('pick3').onclick = function(e) {
        value = e.target.innerText;
        console.log(value);
        return String(value);

    }

}

//invoking the function
player.currentChoice = playerChooses();
console.log(player.currentChoice);`

My player.currentChoice = undefined. I am not sure if my code is wrong. I tried using if statements for each of the clicks. i tried converting to string but still cant seem to get the player.currentChoice to be the value being returned. The values i console logged are equal to what the buttons are. Anyone can help?

New contributor

M Prasaanth is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.