我目前正在学习 Javascript,他们希望我构建一个 Rock, paper and scissors game .
这是我到目前为止的代码:
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()
谢谢
最佳答案
函数定义:
让computerPlay = (array) => {//... }
调用函数:
请记住,computerPlay
在调用时需要一个数组
作为参数。
computerPlay(YOUR_ARRAY_HERE);
关于javascript - 错误 - '' 未定义的类型错误 : Cannot read property 'length"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60271738/