Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- switch problem


ctoz - 9:53 am on May 28, 2011 (gmt 0)


I have a function which chooses randomly between four other functions:

function choose(){
var choices = [func1, func2, func3, func4],
randomnumber = Math.floor(Math.random() * choices.length);
choices[randomnumber]();
}


The next step is to say, "if the outcome is func1(), do this..." for each of the four possible outcomes. I think it needs a switch function, but I'm not sure about some of the code—marked "?":

function branches() {
var a = ? func1
var b = ? func2()
var c = ? func3
var d = ? func4

switch( ? ) {
case ?func1:
doThis(); doThat(); return false;
break
case ?func2:
doThat(); doTother(); return false;
break
case ?func3:
doTother(); doSome(); return false;
break
default:
doSome(); doThis(); return false; }
}

I'll be trying things out, but someone might shorten my evening shift...

cheers


Thread source:: http://www.webmasterworld.com/javascript/4318937.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com