Whenever I implement a switch statement, none of the cases seem to match the 'prefix' value. However, when I switch to using an if-else statement instead, everything functions correctly. What could be causing this discrepancy?
Thanks in advance!
//UPDATED
//el represents a DIV element with an ID attribute like el.id='mph_4';
var prefix = /^[a-z]+/.exec(id);
//------------- SWTICH -------------------------
switch (prefix) {
case 'mph':
return 1;
case 'ph':
return 2;
case 'mh':
return 3;
}
//---------------IF-ELSE------------------------
if (prefix == 'mph') {
return 1;
}
else if (prefix == 'ph') {
return 2;
}
else if (prefix == 'mh') {
return 3;
}