gpt4 book ai didi

javascript - 错误 - '' 未定义的类型错误 : Cannot read property 'length"?

转载 作者:行者123 更新时间:2023-12-01 00:07:35 26 4
gpt4 key购买 nike

我目前正在学习 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com