Итак, у меня есть небольшое приложение, основанное на игре (ножницы для бумажной бумаги), но я хочу вернуть текст с победителем и звуковым эффектом ... Итак, у меня есть 2 небольших mp3-файла аплодисменты.mp3 и fail.mp3 Как я могу сделать, чтобы вернуть текст и воспроизвести файл :(? Я пробовал несколько вещей, но он говорит мне «undefined» или другие ошибки ... :(или, может быть, он возвращает мне текст, который я могу купить услышать звук ..JavaScript return text + soundsound
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);
};