I am writing code for the Old McDonald song. I have 3 animals as an option for the user. Based on their input, I have written code so that the song proceeds with the animal sound as text output. I would also like to add a sound for the onclick
event, but have it change with each animal. Is this possible?
Here is the code so far:
<!DOCTYPE html>
<script>
function songFunction() {
var output;
var animal = prompt("Choose an animal. Cow, chicken, or sheep?", "Enter
an animal.");
if (animal == null) {
output = "You don't want to sing along?";
}
else if (animal.toUpperCase() == "COW") {
output = "With a moo moo here, and a moo moo there. Here a moo,
there a moo, everywhere a moo moo!";
}
else if (animal.toUpperCase() == "CHICKEN") {
output = "With a cluck cluck here, and a cluck cluck there. Here a
cluck, there a cluck, everywhere a cluck cluck!";
}
else if (animal.toUpperCase() == "SHEEP") {
output = "With a baa baa here, and a baa baa there. Here a baa,
there a baa, everywhere a baa baa!"
}
else {
output = "This farm only has 3 kinds of animals. Please try again."
}
document.getElementById("message").innerHTML = output;
}
</script>
<html>
<head>
<title>Old McDonald's Farm</title>
</head>
<body>
<p>Old McDonald had a farm. And, on his farm he had a....</p>
<button onclick="songFunction()">What comes next?</button>
<p id="message"></p>
</body>
</html>