SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)

    A few questions on script.

    Code JavaScript:
    <script type="text/javascript">
    function pFIdVal(id){return parseFloat(document.getElementById(id).value);}
    function calculate(){
    var v1=pFIdVal('mycredits')/1000000;
    var v2=pFIdVal('mybytes')/5;
    var v3=pFIdVal('mymarks')/1000;
    var v4=pFIdVal('myexp')/1000000;
    var v5=pFIdVal('myarena')/100;
    var v6=pFIdVal('myclearing')/20;
    var v7=pFIdVal('myweapons')/155000;
    var v8=pFIdVal('myore')/2000;
    var v9=pFIdVal('myherbs')/2600000;
    var tG=v1+v2+v3+v4+v5+v6+v7+v8+v9;
    document.getElementById('answer').innerHTML=tG;
    var iR;
    if(tG<3){iR='Recruit';}
    if(tG>3&&tG<10){iR='Cook';}
    if(tG>10&&tG<20){iR='Maintenance Guy';}
    if(tG>20&&tG<30){iR='Mechanic';}
    if(tG>30&&tG<40){iR='Volunteer';}
    if(tG>40&&tG<50){iR='Private';}
    if(tG>50&&tG<60){iR='Private First Class';}
    if(tG>60&&tG<70){iR='Sniper';}
    if(tG>70&&tG<80){iR='Tank Driver';}
    if(tG>80&&tG<80){iR='Airman';}
    if(tG>90&&tG<100){iR='Sergeant';}
    if(tG>100&&tG<110){iR='Warrant Officer';}
    if(tG>110&&tG<120){iR='Lieutenant';}
    if(tG>120&&tG<150){iR='Caption';}
    if(tG>150){iR='Secret Agent';}
    document.getElementById('rank').innerHTML=iR;
    }
    </script>

    the seocnd part of this code outputs a rank as you can see. Now here are a few things I would like to accomplish along with it.

    I would like multiple lines and breaks to be displayed with each rank.

    I would like to change the color of the rank text

  2. #2
    Google Engineer polvero's Avatar
    Join Date
    Oct 2003
    Location
    Mountain View
    Posts
    567
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    then add span's with classnames delegating different colors for ranks.

    Code:
    .sniper {
      color: red;
    }
    .private {
      color: green;
    }
    .mechanic {
      color: blue;
    }
    /* etc. */
    Then change each of lines appropriately:
    Code:
    // from this
    if(tG>20&&tG<30){iR='Mechanic';} 
    
    // to this
    if(tG>20&&tG<30){iR='<span class="mechanic">Mechanic</span>';}

  3. #3
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    Awesome, that solves both my problems. Super!

  4. #4
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    Ok, I have a new question. I have been wanting to add in two new fields. But for this to be a quick learning experience I'll only focus on the one, and I should be able to do the same for the second field.

    I want to put a new variable in 'mydays'. This number won't get calculated in like the others. Rather it would work as a requirement. The first 5 ranks have no days requirement, however the ones after do. So would it be possible (short of a huge rewrite) to run a validation on the days to make sure that they meet the requirement, if not then take them down to the next one they do fall under?

  5. #5
    Google Engineer polvero's Avatar
    Join Date
    Oct 2003
    Location
    Mountain View
    Posts
    567
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    At this point I really have no point what you're talking about. It was hard enough answering the first question and I'm surprised my answer was useful :|
    Would you mind adding context to all this?

  6. #6
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,182
    Mentioned
    67 Post(s)
    Tagged
    2 Thread(s)
    Code JavaScript:
    if(tG<3){iR='Recruit';}
    if(tG>3&&tG<10){iR='Cook';}
    if(tG>10&&tG<20){iR='Maintenance Guy';}
    if(tG>20&&tG<30){iR='Mechanic';} [COLOR="Red"]No requirement[/COLOR]
    if(tG>30&&tG<40){iR='Volunteer';} - [COLOR="Red"]10 day requirement[/COLOR]
    if(tG>40&&tG<50){iR='Private';} [COLOR="Red"]20 day requirement[/COLOR]
    if(tG>50&&tG<60){iR='Private First Class';} [COLOR="Red"]ETC.[/COLOR]
    if(tG>60&&tG<70){iR='Sniper';}
    if(tG>70&&tG<80){iR='Tank Driver';}
    if(tG>80&&tG<80){iR='Airman';}
    if(tG>90&&tG<100){iR='Sergeant';}
    if(tG>100&&tG<110){iR='Warrant Officer';}
    if(tG>110&&tG<120){iR='Lieutenant';}
    if(tG>120&&tG<150){iR='Caption';}
    if(tG>150){iR='Secret Agent';}

    If you look at the red you might see what i am trying to do. I want a new field (days) to be another decider. So they might meet the points requirement, but if they don't meet the days requirement, it should kick them down to one they fit.

    However, while writing this I think I'm realizing that this will be too much work. It really isn't worth it.


Bookmarks

Posting Permissions

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