From 06ea0a15823d5bd4762c9dd52da9fafa1ab002b5 Mon Sep 17 00:00:00 2001 From: "Oh, Sukyeong" Date: Wed, 4 Sep 2024 00:06:32 +0900 Subject: [PATCH] =?UTF-8?q?11=EC=A3=BC=EC=B0=A8=20Assignment-=EC=98=A4?= =?UTF-8?q?=EC=88=98=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- world-relay/world-relay.html | 15 +++++++++++++++ world-relay/world-relay.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 world-relay/world-relay.html create mode 100644 world-relay/world-relay.js 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);