Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

11주차 Assignment-오수경 #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions world-relay/world-relay.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>끝말잇기</title>
</head>
<body>
<div><span id="order">1</span>번째 참가자</div></div>
<div>제시어: <span id="word"></span></div>
<input type="text">
<button>입력</button>
<script src="word-relay.js"></script>
</body>
</html>
33 changes: 33 additions & 0 deletions world-relay/world-relay.js
Original file line number Diff line number Diff line change
@@ -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);