javascript - returning multiple values from functions -
i have js file (below) each function returns 2 results (step1 , step2). need put these results format like...
"mix " + (step1 producttype) + " " + (step1 peroxide) + ". " + (step1 timing)
using " + (step2 producttype) + " , mix " + (step2 tonecalc) + ", " + (step2 peroxide) + ". " + (step2 timing)
what best way these results formats above?
know how single value, not quite sure on multiple functions wrapped in function.
thanks
function doubleprocess(type) { function producttype() { var step1; var step2; if (type == "light") { step1 = "lightner"; step2 = "demi-color"; } else { step1 = "demi-color"; step2 = "demi-color"; } return step1, step2; } function tonecalc() { var step1; var step2; if (type == "light") { step1 = "light gold"; } else if (type == "dark") { step1 = "80% gold 20% red" } else { step1 = "another tone"; } step2 = "neutral"; return step1, step2; } function peroxide() { var step1; var step2; if (type == "light") { step1 == "20v/6% peroxide"; } else if (type == "dark") { step1 = "something else"; } else { step1 = "do something."; } step2 = "do else."; return step1, step2; } function level() { var step1 = ""; var step2; if (type == "dark") { step1 = "do something."; } else { step1 = "do nothing."; }; step2 = "do something."; return step1, step2; } function timing() { var step1; var step2; if (type == "light") { step1 == "do something."; step2 = "do something."; } else if (type == "dark") { step1 = "do something."; step2 = "do something."; } else { step1 = "do something."; step2 = "do something."; } return step1, step2; } }
you cannot return multiple variables function. return object.
function peroxide() { var step1; var step2; if (type == "light") { step1 == "20v/6% peroxide"; } else if (type == "dark") { step1 = "something else"; } else { step1 = "do something."; } step2 = "do else."; var rtn = new object(); rtn.step1 = step1; rtn.step2 = step2; return rtn; }
Comments
Post a Comment