How to find total and average of students marks using JavaScript-very simple program

To find total and average of students marks using JavaScript


Now i am going  to explain about JavaScript and its advantages and disadvantages with simple program. Ok lets start...

What is JavaScript?

  •  JavaScript is a dynamic computer programming language. It is lightweight and most commonly used as a part of web pages.  
  • It is an interpreted programming language with object oriented programming. 
  • It was early known as LiveScript, then Netscape changed its name to JavaScript.

Characteristics of JavaScript

  • Open and cross-platform 
  • Designed for creating networks-centric applications.
  • Lightweight, interpreted programming language. 
  • Complementary to and integrated with HTML and Java.

Advantages of JavaScript 

  1. Perfect interfaces 
  2. Speed
  3. Increased interactivity 
  4. Quick feedback to the users.
  5. Less server interaction 

Disadvantages of JavaScript 

  1. Browser support.
  2. Client side Security.
  3. Little bit of Slow execute
  4. Single Inheritance,
  5. Stop Rendering. 
Now let we discuss with simple program 

1.Algorithm 2.Source code 

Aim

To create a JavaScript program code to find Total, Average, Result 

Algorithm 

  1. Create a function for calculation // function calculation()
  2. Declare the variable name - m1,m2,m3,m4,m5, tot,avg
  3. And get input from the user. 
  4. calculation 
  5. print the value.

Source code

<html>
<head>
<script>
function calculation()
{
    var m1,m2,m3,m4,m5, tot,avg;
    m1=Number(document.getElementById("mark1").value);
    m2=Number(document.getElementById("mark2").value);
    m3=Number(document.getElementById("mark3").value);
    m4=Number(document.getElementById("mark4").value);
    m5=Number(document.getElementById("mark5").value);
    tot=m1+m2+m3+m4+m5;
    avg=tot/5;
    document.getElementById("total").value=tot;
    document.getElementById("average").value=avg;
}
</script>
</head>
<body>
   Enter Mark-1 : <input id="mark1"> 
   Enter Mark-2 : <input id="mark2"> 
   Enter Mark-3 : <input id="mark3"> 
   Enter Mark-4 : <input id="mark4"> 
   Enter Mark-5 : <input id="mark5"> 
   <button onclick="calculation()">Result</button>
   <input id="total"> 
   <input id="avarage"> 
</body>
</html>

Sample Output

Enter Mark-1 :  72
Enter Mark-2 :  57
Enter Mark-3 :  77
Enter Mark-4 :  66
Enter Mark-5 :  78

Result
Total - 350
Average-70

Proper Expiation with code

  • function calculation() - function  to whole calculation.
  • var m1,m2,m3,m4,m5, tot,avg- variable name - used to store the value.
  • m1=Number(document.getElementById("mark1").value); -used to receive  input.
  • tot=m1+m2+m3+m4+m5 and avg=tot/5- arithmetic calculation.
  • document.getElementById("total").value=tot; - display total 
  • document.getElementById("average").value=avg; - display average 
  • <button onclick="calculation()">Result</button>- call calculation function  
More HTML & Script Programs Must visit
You may also check

Post a Comment

If you any doubts, Please let me know

Previous Post Next Post