mardi 15 octobre 2019

Having trouble conceptualizing how i would change this if else statement into a switch statement

I need assistance with changing a very long if/else if/else statement into a switch case statement. Conceptually im not certain of what should be put in the switch expression

if (!$jq('*').hasClass("answerPick")) {
    // if nothing is selected 
     finalURL= "productResults.aspx?N=1320325";
}
else if (q1 === undefined && q2 === undefined && q3Multi === undefined) {
    // if q1 a2 and q3 arent selected 
    finalURL= "productResults.aspx?N=1320325+" + q4Multi.join('+');
}
else if (q1 != undefined && q2 === undefined && q3Multi === undefined) {
    // if q1 a2 and q3 arent selected 
    finalURL= "productResults.aspx?N=1320325+" q15 + q4Multi.join('+');
}

else if (q1 === undefined && q2 === undefined) {
    // if q1 and q2 arent selected 
     finalURL= "productResults.aspx?N=1320325+" + q3Multi + q4Multi.join('+');
}
else if (q2 === undefined && q1 != undefined) {
    // if only q2 is left unselected 
      finalURL = "productResults.aspx?N=" + q15 + q3Multi + q4Multi.join('+');
}
else if (q2 === undefined && q3Multi === undefined) {
    // if only q1 is selected 
     finalURL = "productResults.aspx?N=" + q15;
}
else{
    // if everything is selected
      finalURL = "productResults.aspx?N=" + q2 + q3Multi + q4Multi.join('+');
}

switch(expression) {
  case n:
    code block
    break;
  case n:
    code block
    break;
  default:
    default code block
} 

Please let me know of anything else i should include. I think im missing something super obvious but conceptually it isnt clicking.

Aucun commentaire:

Enregistrer un commentaire