<button id="switch">スイッチを押せ</button> <p id="message">魔法はまだかかっていない</p> <button id="switch2">2番目のスイッチ</button> <p id="message2">まだ何も起きていない</p>
const btn = document.querySelector('#switch'); const msg = document.querySelector('#message'); btn.addEventListener('click', function() { msg.textContent = '魔法がかかった!'; }); const btn2 = document.querySelector('#switch2'); const msg2 = document.querySelector('#message2'); btn2.addEventListener('click', function() { msg2.textContent = '2番目の魔法がかかった!'; });
よくできていますね
001. 魔法のスイッチ
よくできていますね