How To Get Average Of Five Numbers Using JavaScript
Submitted by alpha_luna on Monday, April 11, 2016 - 15:45.
In this tutorial, we are going to learn on How To Get Average Of Five Numbers Using JavaScript. AngularJS is a JavaScript framework. It can extend the HTML tag with the new attributes. It is perfect to use for SPAs or (Single Page Applications).
Today, this is a simple program using AngularJS that the user will input the five (5) value numbers that our program will compute the average of five (5) numbers automatically. And you can make this program as your Average Grade Solver.
JavaScript
This is the script to get the total average of five (5) integer number.
CSS Style
And, this is the style of this program.
Share us your thoughts and comments below. Thank you so much for dropping by and reading this blog post. For more updates, don’t hesitate and feel free to visit our website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.
Source Code
HTML Tag This is an HTML code that the five (5) integer number must be encoded in the text box then automatically we can see the average.- <center>
- <div ng-app="simpleProgram">
- <input type="number" ng-model="a" autofocus="autofocus" style="width:100px; text-align:center; font-size:18px;" step="1" min="0"/>
- <br />
- <input type="number" ng-model="b" style="width:100px; text-align:center; font-size:18px;" step="1" min="0" />
- <br />
- <input type="number" ng-model="c" style="width:100px; text-align:center; font-size:18px;" step="1" min="0" />
- <br />
- <input type="number" ng-model="d" style="width:100px; text-align:center; font-size:18px;" step="1" min="0" />
- <br />
- <input type="number" ng-model="e" style="width:100px; text-align:center; font-size:18px;" step="1" min="0" />
- <br />
- <br />
- <br />
- </div>
- </center>
- <script>
- var app = angular.module('simpleProgram', []);
- app.filter('singleDecimal', function ($filter) {
- return function (input) {
- if (isNaN(input)) return input;
- return Math.round(input * 10) / 10;
- };
- });
- app.filter('setDecimal', function ($filter) {
- return function (input, places) {
- if (isNaN(input)) return input;
- var factor = "1" + Array(+(places > 0 && places + 1)).join("0");
- return Math.round(input * factor) / factor;
- };
- });
- app.controller('Ctrl', function ($scope) {
- $scope.val = 1.56;
- });
- </script>
- <style type="text/css">
- p {
- color:blue;
- display: inline-block;
- font-family: monospace;
- font-style: bold;
- font-size:18px;
- }
- input {
- display: inline-block;
- }
- </style>
Add new comment
- 3183 views