【发布时间】:2019-05-17 09:18:08
【问题描述】:
我正在开发我的第一个真正的项目,一个“刽子手”风格的游戏。我正在尝试执行此操作,但不确定我哪里出错了:如果单击了“错误的字母”,则随机显示一个“身体部位”并从数组中删除,这样它就不会重复。
let wrongAmount = 0
let wrongLettersArray = ["#alphabetLetterA", "#alphabetLetterB", "#alphabetLetterC", "#alphabetLetterD", "#alphabetLetterE", "#alphabetLetterF", "#alphabetLetterG", "#alphabetLetterH", "#alphabetLetterJ", "#alphabetLetterK", "#alphabetLetterM", "#alphabetLetterN", "#alphabetLetterQ", "#alphabetLetterR", "#alphabetLetterU", "#alphabetLetterV", "#alphabetLetterW", "#alphabetLetterX", "#alphabetLetterY", "#alphabetLetterZ"]
let bodyPartsArray = ["#losingTorso", "#losingRightArm", "#losingLeftArm", "#losingRightLeg", "#losingLeftLeg"]
let correctLettersArray = ["#correctLetterP", "#correctLetterI", "#correctLetterS", "#correctLetterT", "#correctLetterO", "#correctLetterL"]
function wrongGuess() {
$(wrongLettersArray).on('click', function () {
$(bodyPartsArray).show()
wrongGuess()
})
}
//if a wrong letter is clicked show one of the body parts at random
//remove from list so it cannot repeat
//add 1 to the wrong amount
【问题讨论】:
标签: javascript jquery arrays function for-loop