aquaballoon

jQuery - Grading

Sep 25th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.84 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3.     <head>
  4.         <meta charset="UTF-8">
  5.         <title>MIU</title>
  6.  
  7.         <!--location of script => /home/userName/www/jquery.js-->
  8.         <script src="jquery-1.11.1.min.js"> </script>
  9.  
  10.         <script>
  11.  
  12.             // description of function
  13.             // by Enkh-Urnux
  14.             function jason(num_grade){
  15.  
  16.                 if (num_grade >=90)
  17.                     return "A";
  18.                 else if (num_grade >=80)
  19.                     return "B";
  20.                 else if (num_grade >=70)
  21.                     return "C";
  22.                 else if (num_grade >=60)
  23.                     return "D";
  24.                 else
  25.                     return "F";  
  26.             } // end of grade function
  27.  
  28.             // beginning of main function
  29.             $(document).ready(function(){  //or => $(function(){
  30.  
  31.                 $("#show").hide();
  32.                 $("#result").hide();
  33.  
  34.                 $("#btLogin").click(function(){
  35.                     var login = jQuery("#login").val();
  36.                     var password = $("#password").val();
  37.  
  38.                     if(login == "miu"){
  39.                         alert("Welcome " + login);
  40.                         $("#show").show();
  41.                     }else
  42.                         alert("Who are you?");
  43.                 });
  44.  
  45.                 $("#btGrade").click(function(){
  46.  
  47.                     var name = $("#name").val();
  48.                     var id = $("#id").val();
  49.                     var java = $("#java").val();
  50.                     var web = $("#web").val();
  51.                     var cpp = $("#cpp").val();
  52.  
  53.                     var total = parseInt(java)+parseInt(web)+parseInt(cpp);
  54.                     var average = parseInt(total/3);
  55.  
  56.                     var scJava = parseInt(java);
  57.                     var scWeb = parseInt(web);
  58.                     var scCpp = parseInt(cpp);
  59.                    
  60.                     var array = [scJava, scWeb, scCpp];
  61.  
  62.                     if( isNaN(scJava) || scJava > 100 || isNaN(scWeb) || scWeb > 100 || isNaN(scCpp) || scCpp > 100){
  63.                         alert("Insert value between 0 and 100");
  64.                     }else{
  65.  
  66.                         $("#result").show();
  67.  
  68.                         $("#grade").html(
  69.                             "Name : " + name  
  70.                             + "<br>Student ID : " + id  
  71.                             + "<br><br>Total of your score : " + total
  72.                             + "<br>Average of your score : " + average
  73.                             + "<br>Your highest score : " + Math.max.apply(Math, array)
  74.                             + "<br>Your lowest score : " + Math.min.apply(Math, array)
  75.                             + "<br><br>Java: " + jason(scJava) + "<br>Web: " + jason(scWeb) + "<br>C++: " + jason(scCpp)
  76.                         );
  77.  
  78.                     }  //end of else
  79.                 });  //end of btGrade click
  80.  
  81.             }); //end of main function
  82.  
  83.         </script>
  84.  
  85.     </head>
  86.     <body>
  87.  
  88.         <label>Login</label>
  89.         <input id="login" type="text"><br>
  90.         <label>Password</label>
  91.         <input id="password" type="password">
  92.         <button id="btLogin">Login</button>
  93.         <br><br>
  94.  
  95.         <div id="show">
  96.             <h1>Grade</h1>
  97.  
  98.             <label>Name</label>
  99.             <input id="name" type="text">
  100.             <label>Student ID</label>
  101.             <input id="id" type="text"><br>
  102.  
  103.             <label>Java</label>
  104.             <input id="java" type="text" >
  105.  
  106.             <label>Web</label>
  107.             <input id="web" type="text" >
  108.  
  109.             <label>C++</label>
  110.             <input id="cpp" type="text" ><br>
  111.  
  112.             <button id="btGrade" >Click</button>
  113.  
  114.         </div>
  115.  
  116.         <div id="result">
  117.             <h1>Result</h1>
  118.             <p id="grade"></p>
  119.         </div>
  120.  
  121.     </body>
  122. </html>
Advertisement
Add Comment
Please, Sign In to add comment