[Note: The icon for the post says resolved…it is not!]
Greetings,
I am implementing a switch statement, but am having a problem. For some reason, the first time that the switch evaluates the expression, it matches the correct case. However, every subsequent call always fails to the default case. The relevant code follows below(lots of alerts for debugging purposes). As an example, here’s the current problem. The first time this function gets called, it is passed the number 6. The alerts that pop up are “yay6” and “July”, respectively. However, the next call to the function passes it the number 5 and the alerts that pop up are “next popup = numberRep value”, “5”, and “null”, respectively. Any ideas as to why? I’m wondering if it has something to do with declaring the variable monthName each time…but yeah I’m not too sure. Any advice would be appreciated. Thanks in advance, and here’s the code:
function getMonthname( numberRep )
{
var monthName = ‘null’;
switch( numberRep ){
case 0: monthName = ‘January’; alert( “yay0” ); break;
case 1: monthName = ‘February’; alert( “yay1” ); break;
case 2: monthName = ‘March’; alert( “yay2” ); break;
case 3: monthName = ‘April’; alert( “yay3” ); break;
case 4: monthName = ‘May’; alert( “yay4” ); break;
case 5: monthName = ‘June’; alert( “yay5” ); break;
case 6: monthName = ‘July’; alert( “yay6” ); break;
case 7: monthName = ‘August’; alert( “yay7” ); break;
case 8: monthName = ‘September’; alert( “yay8” ); break;
case 9: monthName = ‘October’; alert( “yay9” ); break;
case 10: monthName = ‘November’; alert( “yay10” ); break;
case 11: monthName = ‘December’; alert( “yay11” ); break;
default: alert(“next popup = numberRep value”); alert( numberRep); break;
}
alert( “Returning the following value…”) ;
alert( monthName );
return monthName;
}