我试图制作一个文字克隆,但可以使其正常运行。我可以做些什么以使其起作用?
let body = document.querySelector("body")
let container = document.querySelector("#container")
let enter = document.querySelector("#enter")
let inputArr = []
for (let rowCount = 0; rowCount < 6; rowCount++) {
let row = []
inputArr.push(row)
for (let i = 0; i < 5; i++) {
let space = document.createElement("input");
container.appendChild(space)
row.push(space);
space.classList.add("square")
}
}
let wordSet = ["panic", "knobs", "swain", "dupes", "venom", "great", "carom", "soare"]
let num = Math.floor(Math.random()*8)
let word = wordSet[num]
console.log(word)
enter.addEventListener("click", () => {
for (let rowVal = 0; rowVal < 6; rowVal++) {
for (let col = 0; col < 5; col++) {
let current = inputArr[rowVal][col].value
if (current === "" || inputArr[rowVal][col].style.backgroundColor !== "darkgray") {
rowVal++
}
if (current == word[col]) {
inputArr[rowVal][col].style.backgroundColor = "green"
}
if (current !== word[col] && word.indexOf(current)) {
inputArr[rowVal][col].style.backgroundColor = "yellow"
}
if (current !== word[col] && word.indexOf(current) == false) {
inputArr[rowVal][col].style.backgroundColor = "white"
}
}
}
})
每当我在空间中输入一些字母并按下Enter按钮时,其他行中正方形的颜色会发生变化,并且似乎是以对角线方式的。我尝试处理IF语句,并将其更改为其他IF语句,我觉得这与为什么Wordle Clone不起作用有关,但我仍然不确定。
let body = document.querySelector("body")
let container = document.querySelector("#container")
let enter = document.querySelector("#enter")
let inputArr = []
for (let rowCount = 0; rowCount < 6; rowCount++) {
let row = []
inputArr.push(row)
for (let i = 0; i < 5; i++) {
let space = document.createElement("input");
container.appendChild(space)
row.push(space);
space.classList.add("square")
}
}
let wordSet = ["panic", "knobs", "swain", "dupes", "venom", "great", "carom", "soare"]
let num = Math.floor(Math.random()*8)
let word = wordSet[num]
console.log(word)
enter.addEventListener("click", () => {
for (let rowVal = 0; rowVal < 6; rowVal++) {
for (let col = 0; col < 5; col++) {
let current = inputArr[rowVal][col].value
if (current === "" || inputArr[rowVal][col].style.backgroundColor !== "darkgray") {
rowVal++
}
if (current == word[col]) {
inputArr[rowVal][col].style.backgroundColor = "green"
}
if (current !== word[col] && word.indexOf(current)) {
inputArr[rowVal][col].style.backgroundColor = "yellow"
}
if (current !== word[col] && word.indexOf(current) == false) {
inputArr[rowVal][col].style.backgroundColor = "white"
}
}
}
})
Whenever I type in some letters into the spaces and press the enter button, the colors of squares in other rows change, and it seems to be in a diagonal fashion. I tried messing around with the if statements, and changing them to else if statements, and I feel like that could have to do with why the wordle clone isn't working, but I'm still not entirely sure.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题在这里:
索引返回索引或-1。
I think the problem is here:
indexOf returns the index or -1.