Refactoring and assessment

Posted by neitony on Stack Overflow See other posts from Stack Overflow or by neitony
Published on 2010-06-05T07:36:17Z Indexed on 2010/06/05 10:02 UTC
Read the original article Hit count: 186

Filed under:

I'm using javascript to toggle the display state of some objects based on the time of day. A sample of the code is given below. I was wondering if anyone could give a suggestion as to how I can refactor this code while at the same time improving the logic.

switch(tcode) {             
            case 'eur'     : eur.setAttribute('style', 'display:block; opacity:0.5');
                             us.style.display   = 'none';
                             asia.style.display = 'none';
                             us_inactive.style.display   = 'block';
                             asia_inactive.style.display = 'block';
            break;

            case 'us'      : us.style.display   = 'block';
                             eur.style.display  = 'none';
                             asia.style.display = 'none';
                             eur_inactive.style.display  = 'block';
                             asia_inactive.style.display = 'block';

            break;

            case 'asia'    : asia.setAttribute('style', 'display:block; opacity:0.5');
                             us.style.display   = 'none';
                             eur.style.display  = 'none';
                             eur_inactive.style.display  = 'block';
                             us_inactive.style.display = 'block';

© Stack Overflow or respective owner

Related posts about JavaScript