2014-12-01 1 views
0

Я пытался заставить этот код работать, я должен предупредить меня о классе письма, который я получил, я везде искал помощь и чувствую, что я просто что-то пропускаю. Пожалуйста, скажите мне, что я делаю неправильно.Grade Calculator Javascript

<!DOCTYPE html> 

<HTML> 
<HEAD> 
    <TITLE>Javascript Grade Calculator</TITLE> 
    <body style="background-color: yellow"> 
<H1> <style=" color: black; font-family: Times New Roman" align="center"><u>Grade Calculator</u> </H1> 
<h2>Directions: To use this calculator just enter your points for each item in the input boxes, then press the "Calculate" button to see your total points.</h2> 
<h3>   </h3> 


<SCRIPT LANGUAGE="JavaScript"> 

    function do_addition() 
    { 

     var lab1 = parseFloat(document.form1.Lab1Score.value); 
     var lab2 = parseFloat(document.form2.Lab2Score.value); 
     var lab3 = parseFloat(document.form3.Lab3Score.value); 
     var lab4 = parseFloat(document.form4.Lab4Score.value); 
     var lab5 = parseFloat(document.form5.Lab5Score.value); 
     var lab6 = parseFloat(document.form6.Lab6Score.value); 
     var test1 = parseFloat(document.form7.Test1Score.value); 
     var test2 = parseFloat(document.form8.Test2Score.value); 
     var test3 = parseFloat(document.form9.Test3Score.value); 
     var cp = parseFloat(document.form10.ClassScore.value); 
     var sum = (lab1 + lab2 + lab3 + lab4 + lab5 + lab6 + test1 + test2 + test3 + cp); 

alert("The value of Lab 1 is "+lab1+" so I got to the function"); 
alert("The value of Lab 2 is "+lab2+" so I got to the function"); 
alert("The value of Lab 3 is "+lab3+" so I got to the function"); 
alert("The value of Lab 4 is "+lab4+" so I got to the function"); 
alert("The value of Lab 5 is "+lab5+" so I got to the function"); 
alert("The value of Lab 6 is "+lab6+" so I got to the function"); 
alert("The value of Test 1 is "+test1+" so I got to the function"); 
alert("The value of Test 2 is "+test2+" so I got to the function"); 
alert("The value of Final is "+test3+" so I got to the function"); 
alert("The value of Class Score is "+cp+" so I got to the function"); 

    document.sum.value = result; 
     }  

    if (result >= 405 && result <= 450) {alert("Total Points of "+result+" gives you an A");} 
    else if (result >= 360 && result <= 404) {alert("Total Points of "+result+" gives you an B");} 
    else if (result >= 292 && result <= 359) {alert("Total Points of "+result+" gives you an C");} 
    else if (result >= 247 && result <= 291) {alert("Total Points of "+result+" gives you an D");} 
    else if (result >= 0 && result <= 246) {alert("Total Points of "+result+" gives you an F");} 


     function getTime() 
     { 
       var now = new Date(); 
       var h = now.getHours(); 
       var m = now.getMinutes(); 
       var s = now.getSeconds(); 

       m = checkTime(m); 
       s = checkTime(s); 

       document.getElementById("clock").innerHTML = h + ":" + m + ":" + s; 

       setTimeout("getTime()", 1000); 
     } 

     function checkTime(time) 
     { 
       if(time<10) 
       { 
         time = "0" + time;  
       } 

       return time; 
     } 

    </SCRIPT> 

    </HEAD> 
    </TITLE> 
    <BODY onload="getTime();"> 

    <form name="form1"> 
     Lab #1(10 points): 
     <input type="text" name="Lab1Score" size="5"><br> </form> 

    <form name="form2"> 
     Lab #2(10 points): 
     <input type="text" name="Lab2Score" size="5"><br> </form> 

    <form name="form3"> 
     Lab #3(10 points): 
     <input type="text" name="Lab3Score" size="5"><br> </form> 

    <form name="form4"> 
     Lab #4(20 points): 
     <input type="text" name="Lab4Score" size="5"><br> </form> 

    <form name="form5"> 
     Lab #5(20 points): 
     <input type="text" name="Lab5Score" size="5"><br> </form> 

    <form name="form6"> 
     Lab #6(30 points): 
     <input type="text" name="Lab6Score" size="5"><br> </form> 

    <form name="form7"> 
     Test #1(100 points): 
     <input type="text" name="Test1Score" size="5"><br> </form> 

    <form name="form8"> 
     Test #2(100 points): 
     <input type="text" name="Test2Score" size="5"><br> </form> 

    <form name="form9"> 
     Test #3(100 points): 
     <input type="text" name="Test3Score" size="5"><br> </form> 

    <form name="form10"> 
     Class participation(50 points): 
     <input type="text" name="ClassScore" size="5"><br> </form> 

    <input type="button" value="Calculate your score" name="add" onClick="do_addition()"><br> </form> 

    <p> 
    <form name="form11"> 
    Total Points(450 points): 
    <input type="text" name="Total" size="6"><br> </form> 

    <input type=reset value=Reset><br> </form> 
<p>The current time is: </p> 
<p id='clock'></p> 


</BODY> 
</HTML> 
+0

Почему вам нужны отдельные формы для каждого входа? –

+0

Я не знаю, как учитель сказал нам, но он ошибался во многих вещах. как это сделать? Это введение в класс Javascript, и он учил нас неправильным вещам. – thrashix

+0

Неверный тег. Java! = Javascript. Я исправил его для вас, но будьте осторожны, какой из них вы используете. –

ответ

0

пожалуйста сравните свой код с mine.i закрепили свой первый раздел, который вычисляет оценку в тесте и lab.please сделать то же самое для испытания на основе времени.

 <html> 
      <head> 
      <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script> 



       <script type="text/javascript"> 

       $(document).ready(function(){ 

       }); 

      </script> 
     <script type="text/javascript"> 

     var result=0; 

     function do_addition() 
      { 

       var lab1 = parseFloat(document.forms["form1"]["Lab1Score"].value); 
       var lab2 = parseFloat(document.forms["form1"]["Lab2Score"].value); 
       var lab3 = parseFloat(document.forms["form1"]["Lab3Score"].value); 
       var lab4 = parseFloat(document.forms["form1"]["Lab4Score"].value); 
       var lab5 = parseFloat(document.forms["form1"]["Lab5Score"].value); 
       var lab6 = parseFloat(document.forms["form1"]["Lab6Score"].value); 
       var test1 = parseFloat(document.forms["form1"]["Test1Score"].value); 
       var test2 = parseFloat(document.forms["form1"]["Test2Score"].value); 
       var test3 = parseFloat(document.forms["form1"]["Test3Score"].value); 
       var cp = parseFloat(document.forms["form1"]["ClassScore"].value); 
       var sum = (lab1 + lab2 + lab3 + lab4 + lab5 + lab6 + test1 + test2 + test3 + cp); 




      document.forms["form1"]["Total"].value=sum 
      result=sum; 

      if (result >= 405 && result <= 450) {alert("Total Points of "+result+" gives you an A");} 
      else if (result >= 360 && result <= 404) {alert("Total Points of "+result+" gives you an B");} 
      else if (result >= 292 && result <= 359) {alert("Total Points of "+result+" gives you an C");} 
      else if (result >= 247 && result <= 291) {alert("Total Points of "+result+" gives you an D");} 
      else if (result >= 0 && result <= 246) {alert("Total Points of "+result+" gives you an F");} 

     }  




       function getTime() 
       { 
         var now = new Date(); 
         var h = now.getHours(); 
         var m = now.getMinutes(); 
         var s = now.getSeconds(); 

         m = checkTime(m); 
         s = checkTime(s); 

         document.getElementById("clock").innerHTML = h + ":" + m + ":" + s; 

         setTimeout("getTime()", 1000); 
       } 

       function checkTime(time) 
       { 
         if(time<10) 
         { 
           time = "0" + time;  
         } 

         return time; 
       } 
     </script> 
      <style> 

      </style> 


      </head> 

      <body> 
     <form name="form1" > 
       Lab #1(10 points): 
       <input type="text" id="Lab1Score" name="Lab1Score" size="5"/><br> 


       Lab #2(10 points): 
       <input type="text" name="Lab2Score" size="5"><br> 


       Lab #3(10 points): 
       <input type="text" name="Lab3Score" size="5"><br> 


       Lab #4(20 points): 
       <input type="text" name="Lab4Score" size="5"><br> 


       Lab #5(20 points): 
       <input type="text" name="Lab5Score" size="5"><br> 


       Lab #6(30 points): 
       <input type="text" name="Lab6Score" size="5"><br> 


       Test #1(100 points): 
       <input type="text" name="Test1Score" size="5"><br> 


       Test #2(100 points): 
       <input type="text" name="Test2Score" size="5"><br> 


       Test #3(100 points): 
       <input type="text" name="Test3Score" size="5"><br> 


       Class participation(50 points): 
       <input type="text" name="ClassScore" size="5"><br> 

      <input type="button" value="Calculate your score" name="add" onClick="do_addition();"><br> 


      Total Points(450 points): 
      <input type="text" name="Total" size="6"><br> 

      <input type="reset" value="Reset"><br> 


     </form> 


     <p>The current time is: </p> 
     <p id='clock'></p> <form name="form111"> 
       Lab #1(10 points): 
       <input type="text" name="Lab1Score" size="5"><br> </form> 

      <form name="form222"> 
       Lab #2(10 points): 
       <input type="text" name="Lab2Score" size="5"><br> </form> 

      <form name="form333"> 
       Lab #3(10 points): 
       <input type="text" name="Lab3Score" size="5"><br> </form> 

      <form name="form444"> 
       Lab #4(20 points): 
       <input type="text" name="Lab4Score" size="5"><br> </form> 

      <form name="form555"> 
       Lab #5(20 points): 
       <input type="text" name="Lab5Score" size="5"><br> </form> 

      <form name="form666"> 
       Lab #6(30 points): 
       <input type="text" name="Lab6Score" size="5"><br> </form> 

      <form name="form777"> 
       Test #1(100 points): 
       <input type="text" name="Test1Score" size="5"><br> </form> 

      <form name="form888"> 
       Test #2(100 points): 
       <input type="text" name="Test2Score" size="5"><br> </form> 

      <form name="form999"> 
       Test #3(100 points): 
       <input type="text" name="Test3Score" size="5"><br> </form> 

      <form name="form100"> 
       Class participation(50 points): 
       <input type="text" name="ClassScore" size="5"><br> </form> 

      <input type="button" value="Calculate your score" name="add" onClick="do_addition()"><br> </form> 

      <p> 
      <form name="form111"> 
      Total Points(450 points): 
      <input type="text" name="Total" size="6"><br> </form> 

      <input type="reset" value="Reset"><br> </form> 
     <p>The current time is: </p> 
     <p id='clock'></p> 


      </body> 

     </html> 

 Смежные вопросы

  • Нет связанных вопросов^_^