How to get the the average of my 5 grades

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • IZAKUWA
    New Member
    • Sep 2012
    • 1

    How to get the the average of my 5 grades

    Code:
    function ave()
    {
    var num1=prompt("enter your first grade");
    document.write("<br>ENG121:"+num1);
    var num2=prompt("enter your second grade");
    document.write("<br>ACC101:"+num2);
    var num3=prompt("enter your third grade");
    document.write("<br>CS201:"+num3);
    var num4=prompt("enter your fourth grade");
    document.write("<br>LIT111:"+num4);
    var num5=prompt("enter your fifth grade");
    document.write("<br>CS211:"+num5);
    var total=prompt("total average");
    
    var total= parseInT(num1) +parseInT(num2) +parseInT(num3) +parseInT(num4) +parseInT(num5) /parseInt(5);
    document.write("<br>THE TOTAL AVE IS:"+total);
    
    
    }
    Last edited by Rabbit; Sep 19 '12, 05:31 AM. Reason: Please use code tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You need to add up all the values before . Right now you are only dividing the last number.

    Comment

    • iam_clint
      Recognized Expert Top Contributor
      • Jul 2006
      • 1207

      #3
      Code:
      var total= (parseInt(num1) +parseInt(num2) +parseInt(num3) +parseInt(num4) +parseInt(num5)) /parseInt(5);
      since you need to divide the total by 5 you should wrap your adding phrase in () so it does all of those adds first before executing the division. Also in a lot of them you had parseInT which would be causing a syntax error and not doing any of the math at all.

      Comment

      Working...