diff --git a/world-relay/world-relay.html b/world-relay/world-relay.html new file mode 100644 index 0000000..6fd31f7 --- /dev/null +++ b/world-relay/world-relay.html @@ -0,0 +1,15 @@ + + + + + + 끝말잇기 + + +
1번째 참가자
+
제시어:
+ + + + + \ No newline at end of file diff --git a/world-relay/world-relay.js b/world-relay/world-relay.js new file mode 100644 index 0000000..93cbd96 --- /dev/null +++ b/world-relay/world-relay.js @@ -0,0 +1,33 @@ +const number = Number(prompt("참가자는 몇 명인가요?")); +const $input = document.querySelector("input"); +const $button = document.querySelector("button"); +const $word = document.querySelector("#word"); + +let newWord; +let word; +const onInput = (event) => { + newWord = event.target.value; +}; + +const $order = document.querySelector("#order"); +const onClickButton = () => { + if (!word || word.at(-1) == newWord[0]) { + word = newWord; + $word.textContent = word; + + const order = Number($order.textContent); + if (order + 1 > number) { + $order.textContent = 1; + } else { + $order.textContent = order + 1; + } + } else { + alert("틀린 단어입니다!"); + } + // 최적화 + $input.value = ""; + $input.focus(); +}; + +$input.addEventListener("input", onInput); +$button.addEventListener("click", onClickButton);