0

Having trouble with onBadChoice and onChoice event handlers in a loop

I'm trying to use this code to repeatedly ask the user for a choice, but the ask() is never performed and the call just hangs up after it connects:

while(currentCall.isActive()){

ask("What's your favorite color?", {
choices: "red, blue, green",
onBadChoice: badcolor(event),
onChoice: goodcolor(event)
});
wait(500);

}

function badcolor(event){
say("I'm sorry, I didn't understand that. You can select red, blue, or green.");
}

function goodcolor(event){
say("You chose " + event.value);
}

I put the functions in separately, instead of defining them in the event handlers, because I was getting the warning "Don't make functions within a loop."

How can I set up my code to repeatedly get input from the user and respond to it with event handlers?

2 comments

Please sign in to leave a comment.