Our group modified javascript for making answering duck with changeable eyes. It contains 4 different functions -
one is for playing each same sound as the answer, the other one is making an random reply and random eyes,
and the other one is for running those functions related to sound, reply, and eyes.
The last function means all these will be performed when user clicks button. Link
var replies = ["Yes", "No", "How should I know?", "Feed me and then I'll tell you.", "Maaaaybe."];
var sounds = ["yes", "no", "how", "feedme", "maybe"];
var eyes = ["eyes", "eyes2", "eyes3", "eyes4", "eyes5", "eyes", "eyes7" ];
var randomNum = 0;
var randomEyes = 0;
var audioElement;
function playSounds(r) {
var currentSound = "../sound/" + r + ".mp3";
currentSound.play();
}
function randomNum2(arrayName) {
var num = Math.floor(Math.random() * arrayName.length - 1)+1;
return num;
}
function answerQuestion () {
console.log("running");
var randomReply = replies[randomNum2(replies)];
var randomSound = sounds[randomNum2(sounds)];
var randomEyes = eyes[randomNum2(eyes)];
$("#speech").html(randomReply);
$("#eyes").html("")
function init() {
console.log('Hello World');
$("#submit").click(answerQuestion);
}
$(document).ready(function(){
init();
});