Help in a Question

+1 Ken Nishi · August 4, 2015
How do i solve this question .

Design an algorithm that will prompt an operator for a student’s serial number and the student’s exam score out of 100. Your program is then to match the exam score to a letter grade and print the grade to the screen. Calculate the letter grade as follows:


Exam score        Assigned grade
85 and above    ( HD )
75 to 84               ( D )
65 to 74                 ( C )
50 to 64                 ( P )
below 50            ( F )

Can anyone help me solve this into code,or provide a example . Thanks

Post a Reply

Replies

Oldest  Newest  Rating
0 Sid wadhwa · August 15, 2015
<!DOCTYPE html>
<html>
<head>
 <script type="text/javascript">
  function resultCalculator(){
   
   var a = parseFloat(document.getElementById('first').value);
   var b = parseFloat(document.getElementById('second').value);
   var c = parseFloat(document.getElementById('third').value);
   var d = parseFloat(document.getElementById('fourth').value);
   var e = parseFloat(document.getElementById('fifth').value);
   var end = a+b+c+d+e;
   document.getElementById('result').value = end;
   if(end > 400 && end <= 500){
    document.getElementById('grades').value = "A";
    
   }
   else if(end <= 400 && end > 300){
    document.getElementById('grades').value = "B";
  
   }
   else if(end <= 300 && end > 200){
    document.getElementById('grades').value = "C";
   }
   else if(end > 500){
    document.getElementById('grades').value = "UNDEFINED";
   }
   else{
    document.getElementById('grades').value = "F";
   }
  }
 </script>
</head>
<body>
<table style="border: 1px solid black;">
 <tr>
 <td>English : </td>
 <td><input type="text"  id="first"/></td></tr>
 <tr><td>Computers : </td>
 <td><input type="text"  id="second"/></td></tr>
 <tr><td>Science : </td>
 <td><input type="text"  id="third"/></td></tr>
 <tr><td>Hindi : </td>
 <td><input type="text"  id="fourth"/></td></tr>
 <tr><td>Maths : </td>
 <td><input type="text"  id="fifth"/></td></tr>
 <tr><td>Total : </td>
 <td><input type="text"  id="result"/></td></tr>
 <td>Grade : </td>
 <td><input type="text"  id="grades"/></td></tr>
 <tr><td></td>
 <td><input type="button" value="Submit" onclick="resultCalculator()"/></td>
 </tr>
</table>
</body>
</html>



//COPY THIS CODE AND IT WILL WORK

//YOU CAN ALSO REPLACE IF-ELSE STATEMENT WITH BOOLEAN OPERATORS TRUE-FALSE STATEMENT !
0 wernich wilsenach · August 6, 2015
easiest would be to create an if...else check -> http://devdocs.io/javascript/statements/if...else

if grade is bigger than or the same as the highest, assign grade.
else if it's bigger than or the same as than the second highest, assign grade.
else.... etc.

after that, you can have a bash at solving it with a case statement -> http://devdocs.io/javascript/statements/switch
  • 1

Javascript

107,027 followers
About

A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.

Links
Moderators