끝말잇기 게임을 만드는 중..
1번 플레이어
2번 플레이어
3번 플레이어
1번 플레이어
.. 로 넘어가는 표시를 할 필요가 있었다.
내가 생각한 방법.
let number = parseInt(prompt('몇명이 참가하나요?'));
let count = 1;
let countArr = [];
for (let i = 1; i <= number; i++) {
countArr.push(i)
}
const wordInput = () => {
count += 1;
$order.textContent = countArr[(count -1)%number];
// number가 3일때: countArr = [1, 2, 3] order = 1, 2, 3, 1 ...
}
제로초님의 방법.
const order = Number($order.textContent);
if (order + 1 > number) {
$order.textContent = 1;
}
else {
$order.textCountent = order + 1;
}
// 몇번째 턴인지 나타낼때는 따로 변수를 만들어 줘야할듯.. (내생각)
https://youtu.be/eGpgnp2SNgk?list=PLcqDmjxt30RvEEN6eUCcSrrH-hKjCT4wt&t=142
이랬던 순서도에서 "제시어가 비어있는가?" 와 "입력한 단어가 올바른가?" 는
또는(or)의 관계이기 때문에
이렇게 바꿔줄 수 있고 코드도
const onClickButton = () => {
if (!word) {
wordInput()
}
else {
if (word[word.length - 1] === newword[0]) {
wordInput()
}
else {
alert('다시 입력해주세요')
$input.value = '';
$input.focus();
}
}
};
에서
const onClickButton = () => {
if (!word || word[word.length - 1] === newword[0]) {
wordInput()
}
else {
alert('다시 입력해주세요')
$input.value = '';
$input.focus();
}
};
이렇게 바꿔줄 수가 있다.