0

I'm trying to generate a random outcome based on an array, however I'm getting this error when I log it out, any ideas why?

const hockeyPlayer = {
  position: "goalie",
  action: ["stops the shot", "gives up a goal"],
  outcome: [Math.floor(Math.random() * this.action.length)],
  
    
  shot(){
    console.log(`The ${this.position} ${this.outcome}`)
  }
};
  
hockeyPlayer.shot();
tate dewey
  • 13
  • 3

1 Answers1

0
       Try this 
    
        const hockeyPlayer = 
    { position: "goalie",
 action: ["stops the shot","gives up a goal"],
shot: function(){ 
     const outcome  = this.action[Math.floor(Math.random() * this.action.length)];
          
    alert(`The ${this.position} ${this.outcome}`) } }; hockeyPlayer.shot();
Anirudh santhosh
  • 451
  • 4
  • 10