javascript - What is best way to refactor these series of if statements? -


so have bunch of questions radio buttons, each question having 3 options choose from. have bunch of if statements ( lot of them) determine final answer based on answers each question.

for example:

question 1 :             a)            b)            c)  question 2 :             d)            e)            f)  question 3 :             g)            h)            i) 

and on.

if statements follows : if ( question 1 == || question 2 == f && question 3 == )

if want conditions form of if statements, it'd take space , not best practice.

what best way refactor these if statements?

if every single combination of choices leads unique outcome, you're looking @ n-dimensional matrix. in simpler words, think of every option step in path in array:

$outcomes = array(     'a' => array(         'd' => array(             'g' => 'outcome 1',             'h' => 'outcome 2',             'i' => 'outcome 3'         ),         'e' => array(..),         ..     'b' => array(..),     .. );  echo 'the outcome is: ', $outcomes[$question1][$question2][$question3]; 

whether best possible way implement questionable, don't know without knowing more logic.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -