Results 1 to 2 of 2

Thread: Else if Statment help

  1. #1
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Else if Statment help

    coming from C++ back ground and new going into Java Script

    i cant really seem to get the if Else statement working

    What i am trying to do is put a error alert box in if any one types in anything over 100 it should show that but whats happening is if i type in 600 its showing the Error Box but also saying you got an A+ after i click ok on the Error Box..

    the else i showing an Error i cant seem to figure how can i get this part working



    Code:
    script type='text/javascript'>
    function show(which) {
    var mark =  parseInt(which.value,10) || 0;  
    
    if (mark >100) 
    which.value = mark;  
    alert("Please Enter between 0 & 100 !");
    
    else 
    
    if (mark <100)
    var mod = which.id;
    var grade = "Failed";
    if (mark >=40) {grade = "D"}
    if (mark >=60) {grade = "C"}
    if (mark >=78) {grade = "B"}
    if (mark >=85) {grade = "A"}
    if (mark >=93) {grade = "A+"}
    alert ("Your grade for " + mod + " is " + grade);
    }
    </script>

  2. #2
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    got it working i just messed around with the { }


    i have 4 text boxes how can i get a image if all 4 boxes have has a value more then 40

    else if all but one have a value less then 40 show a different image ?

    Code:
    <script type='text/javascript'>
    function show(which) {
    var mark =  parseInt(which.value,10) || 0;    // trap non-numeric entries, make number integer
    if (mark >100) {
    alert("Please Enter between 0 & 100 !");
    which.value = mark; } // write it back to the field
    
    else if (mark <=100){
    var mod = which.id;
    var grade = "Failed";
    if (mark >=40) {grade = "D"}
    if (mark >=60) {grade = "C"}
    if (mark >=78) {grade = "B"}
    if (mark >=85) {grade = "A"}
    if (mark >=93) {grade = "A+"}
    alert ("Your grade for " + mod + " is " + grade);
    }
    }
    </script>

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
  •