dcsimg
www.webdeveloper.com
Results 1 to 1 of 1

Thread: [RESOLVED] switch statement

  1. #1
    Join Date
    Jul 2006
    Posts
    5

    Post NOT RESOLVED - switch statement

    [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;
    }
    Last edited by RyanSteele; 07-16-2006 at 07:46 PM. Reason: Icon won't change

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles