[javascript] 자바스크립트에서 터치 이벤트를 사용하여 터치에 따른 사운드 출력하는 방법은?

먼저, HTML에서 터치 이벤트를 추가할 요소를 만듭니다.

<button id="touchButton">터치해주세요</button>
<audio id="touchSound">
  <source src="touch.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

그런 다음, 자바스크립트에서 터치 이벤트를 처리하고 사운드를 재생하는 기능을 추가할 수 있습니다.

const touchButton = document.getElementById('touchButton');
const touchSound = document.getElementById('touchSound');

touchButton.addEventListener('touchstart', () => {
  touchSound.play();
});

이 예제에서는 터치가 시작될 때(touchstart 이벤트) 사운드가 재생됩니다. touch.mp3 파일은 사운드 파일의 경로와 파일 형식에 맞게 수정해야 합니다.

이러한 방법을 사용하여 터치 이벤트에 따라 사운드를 출력할 수 있습니다.