Kevin A
Kevin A

Reputation: 83

Error - ''Uncaught TypeError: Cannot read property 'length"? of undefined''

I'm currently learning Javascript and they want me to build a Rock, paper and scissors game.

Here's the code I have so far:

let computerPlay = (array) => {
  return array[Math.floor(Math.random() * 
  array.length)]
}

const array = (["Rock", "Paper", "Scissors"])
console.log(computerPlay(array))

let singleRound = (playerSelection, 
computerSelection) => {

if ( playerSelection == "rock" || playerSelection 
== "Paper" || 
playerSelection == "scissors") {
  computerSelection = computerPlay
} else if (playerSelection == null) {
  "Canceled"
}



}

let playerSelection = prompt("What do you 
select?")
const computerSelection = computerPlay()

Thank You

Upvotes: 0

Views: 271

Answers (1)

Mosia Thabo
Mosia Thabo

Reputation: 4277

Function Definition:

let computerPlay = (array) => { //... }

Calling The Funciton:

Remember computerPlay requires an array as a parameter when you call it.

computerPlay(YOUR_ARRAY_HERE);

Upvotes: 2

Related Questions