const number = Number(prompt('참가 인원을 입력해 주세요.'));
const $button = document.querySelector('button');
const $input = document.querySelector('input');
const $word = document.querySelector('#word');
let word; // 제시어
let newWord; //새로 입력한 단어
const onClickButton = () => {
if (!word){
// 비어 있는 경우
word = newWord;
$word.textContent = word;
$input.value = '';
} else {
// 비어 있지 않은 경우
if(word[word.length - 1] === newWord[0]) {
// 단어가 올바른가
word = newWord;
$word.textContent = word;
$input.value = '';
}else {
// 올바르지 않은가
}
}
};
const onInput = (event) => {
newWord = event.target.value;
};
$input.addEventListener('input', onInput);
$button.addEventListener('click', onClickButton);
💡
input 창에 단어 '자바' 를 입력하면 제시어 에 입려한 단어가 들어가고,
input 창은 다음 참가자가 입력하기 편하도록 내용이 없어진다. (value = ' ';)
