그래서 게임 (바위 종이 가위)을 기반으로하는 작은 앱이 있지만 승자와 사운드 효과로 텍스트를 반환하고 싶습니다 ... 그래서 2 개의 작은 mp3 파일이 있습니다. applause.mp3 and fail.mp3 어떻게하면 텍스트를 반환하고 파일을 재생할 수 있습니다 :(? 나는 tryed 몇 가지지만, "정의되지 않은"또는 다른 오류를 알려줍니다 ... :(또는 어쩌면 그것은 텍스트를 반환합니다 내가 couldnt 소리를 듣고 .. 당신은 텍스트와 함께 소리를 반환 할 필요가 없습니다JavaScript 반환 텍스트 + playsound
var compare = function(choice1) {
var winSound = document.getElementById('./sounds/Applause.mp3');
var lostSound = document.getElementById('./sounds/Fail.mp3');
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
}
if (choice1 === computerChoice) {
return('The result is a tie!');
}
else if (choice1 === 'rock') {
if (computerChoice === 'scissors') {
result = 'You are the winner.' + winSound.play();
} else {
return 'Computer is the winner.';
}
}
else if (choice1 === 'paper') {
if (computerChoice === 'rock') {
return 'You are the winner.';
} else {
return 'Computer is the winner.';
}
}
else {
if (computerChoice === 'rock') {
return 'You are the winner.';
} else {
return 'Computer is the winner.';
}
}
};
var game = function(choice1) {
document.getElementById('result').innerHTML = compare(choice1);
};