【发布时间】:2021-07-19 10:11:04
【问题描述】:
我正在尝试实现这样的目标:
const word = "abracadabra"
const usedCharacter = ["a", "b", "c", "d", "r", "z"]
function (word, usedCharacter) {
returnAmountNotUsedCharacters;
}
返回不在 const word 中的 usedCharacters 的数量,在这种情况下:“z”不是“abracadabra”的一部分,因此 returnAmountNotUsedCharacters 将返回 1
任何人都可以对此有所了解吗? (我是初学者)
我正试图从头开始找出“刽子手”游戏。 玩家必须通过猜测字符来猜测一个单词,到目前为止我已经在获胜条件下工作了:
function isGameWon(word, guesses) {
return word.split("").every((c) => guesses.includes(c));
}
我有代码的工作部分:
for (let i = 0; i < word.length; i++) {
//if i char of string word is present in guesses, show that char on position i
if (guesses.includes(word[i])) {
wordPlaces += word[i]+" ";
//put underscores on the not yet guessed characters
} else {
wordPlaces += "_ ";
}
}
return wordPlaces;
}
//compare characters of word with characters of guessed, by splitting word() into Word[]
function isGameWon(word, guesses) {
return word.split("").every((c) => guesses.includes(c));
}
function isGameLost(word, guesses) {
}
【问题讨论】:
-
我们当然可以为您编写代码,但作为初学者,为了帮助您,请说明您的方法是什么以及您遇到的问题,并发布您所做尝试的代码。跨度>
-
你的问题是模糊的:列表中的字符是唯一的吗?如果不是,它们在不使用时是否应该重复?
-
我正在尝试从头开始找出“刽子手”游戏。玩家必须通过猜测字符来猜测一个单词,到目前为止我得到了一个获胜条件:function isGameWon(word, guesses) { return word.split("").every((c) => guesses.includes(c) );
-
但我还没有弄清楚如何“计算”存储在guesses["a", "b", "c"]
-
刚刚在原帖中添加了一些代码!
标签: javascript string function conditional-statements