js를 이용한 끝말잇기 게임입니다.
<form action="">
<h1 id="word">끝말잇기</h1>
<input type="text" name="" id="in">
<button id="btn">click</button>
<span id="out"></span>
</form>
let word = document.getElementById('word');
let input = document.getElementById('in');
let btn = document.getElementById('btn');
let out = document.getElementById('out');
btn.addEventListener('click', function(e) {
e.preventDefault();
if (word.textContent[word.textContent.length - 1] == input.value[0]) {
alert('딩동댕');
word.textContent = input.value;
input.value = '';
input.focus();
} else {
alert('땡');
input.value = '';
input.focus();
}
});