Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
<!DOCTYPE html>
<html>
<head>
<title>Statistical Calculator</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>

<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<link rel="stylesheet" href="https://www.w3schools.com/lib/w3-colors-flat.css">

<style>
	button{
		height: 2.7em;
		
	}
</style>


</head>
<body>

<div class="w3-card-4 " style="width:330px" ng-app="stat" ng-controller="statCon" >

	<header class="w3-container w3-blue">
		<h1>Stat Calc</h1>
	</header>
	
	<div class="w3-container w3-border">
		<p id="input" class="w3-right-align w3-border-bottom">{{list}}</p>
		<p id="counter" class="w3-left-align"><sup>Count={{count}}:M={{m}}</sup></p>
		
		<p id="output" class="w3-right-align"  >{{display}}</p>
	</div>
	
	<footer class="w3-container w3-blue">
		<div class=" w3-row">
			<button class=" w3-btn w3-black w3-border w3-col l2 m2 s2 m2" ng-click="mc()">MC</button>
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2" ng-click="mr()">MR</button>
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2" ng-click="ms()">MS</button>
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="mem(1)">M+</button>
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="mem(-1)">M-</button>
		</div>
		
		<div class=" w3-row">
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="shrink()"><</button>
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="clearAll()">CAD</button>
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="clear()">C</button>
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="fe()">F-E</button>
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="exp()">Exp</button>
		</div>
		
		<div class="w3-row">
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="digit(7)">7</button>
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="digit(8)">8</button>
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="digit(9)">9</button>
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="ave()"><div class="w3-border-top">x</div></button>
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="rms()"><div class="w3-border-top">x<sup>2</sup></div></button>
		</div>
		
		<div class="w3-row">
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="digit(4)">4</button>
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="digit(5)">5</button>
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="digit(6)">6</button>
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="displaySum()">&Sigma;x</button>
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="displaySquareSum()">&Sigma;x<sup>2</sup></button>
		</div>
		
		<div class="w3-row">
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="digit(1)">1</button>
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="digit(2)">2</button>
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="digit(3)">3</button>
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="sd(0)">&sigma;<sub>n</sub></button>
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="sd(1)">&sigma;<sub>n-1</sub></button>
		</div>
		
		<div class="w3-row">
			<button class=" w3-btn w3-black w3-border  w3-col l4 m4 s4" ng-click="digit(0)">&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;</button>
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="digit('.')">.</button>
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="plusMinus()"><div class="w3-border-bottom">+</div></button>
			<button class=" w3-btn w3-black w3-border  w3-col l2 m2 s2 " ng-click="add()">Add</button>
		</div>
	</footer>
</div>




</body>
</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                
	var statApp = angular.module("stat",[]);
	statApp.controller("statCon", function($scope){
		$scope.output = 0;
		$scope.count = 0;
		$scope.list = [];
		$scope.m = 0;
		$scope.display = "0";
		
		
		
		$scope.digit = function(num){
			
			
			if ($scope.display === "0"){
				$scope.display = num + "";
			} else {
				$scope.display += num + "";
			}
			
			
			
			$scope.output = parseFloat($scope.display);
			
		}
		
		$scope.clear = function(){
			$scope.output = 0;
			$scope.dis();
		}
		
		$scope.clearAll = function(){
			$scope.clear();
			
			$scope.count = 0;
			$scope.list = [];
			$scope.mc();
			$scope.dis();
		}
		
		$scope.plusMinus = function(){
			$scope.output *= -1;
			$scope.dis();
		}
		
		$scope.shrink = function(){
		
		if($scope.display.length === 1){
			$scope.display = "0";
			$scope.output = 0;
		} else {
			$scope.display = $scope.display.slice(0, $scope.display.length - 1); 
			$scope.output = parseFloat($scope.display);
		}
		
		}
		
		$scope.add = function(){
			$scope.list.push($scope.output); 
			$scope.clear();
			$scope.count++;
			
			$scope.dis();
		}
		
		$scope.mem = function(sign){
			$scope.m += $scope.output * sign;
		}
		
		$scope.ms = function(){
			$scope.m = $scope.output;
		}
		
		$scope.mc = function(){
			$scope.m = 0;
		}
		
		$scope.mr = function(){
			$scope.output = $scope.m;
			
			$scope.dis();
		}
		
		$scope.sum = function(arr, pow){
		
			var sum = 0;
			
			arr.forEach(function(cur){
				sum += Math.pow(cur, pow);
			});
			
			return sum;
		}
		
		//dv is input if arr is input.  dv is only 0 or 1
		$scope.ave = function(arr, dv){
		
		
		
			if (arguments.length === 0){
				$scope.output = $scope.sum($scope.list, 1) / $scope.list.length;
				$scope.dis();
			} else {
				return $scope.sum(arr, 1) / (arr.length - dv);
			}
				
		}
		
		$scope.rms = function(){
			$scope.output = $scope.sum($scope.list, 2) / $scope.list.length;
			
			$scope.dis();
		}
		
		$scope.displaySum = function(){
			$scope.output = $scope.sum($scope.list, 1);
			
			$scope.dis();
		}
		
		$scope.displaySquareSum = function(){
			$scope.output = $scope.sum($scope.list,2);
			
			$scope.dis();
		}
		
		$scope.dis = function(){
			$scope.display = $scope.output + "";
			
		}
		
		$scope.exp = function(){
			$scope.display = $scope.output.toExponential() + "";
		}
		
		//todo test this function more
		$scope.fe = function(){
			var tst = parseFloat($scope.display);
			if ( tst === $scope.display.valueOf() ){
				$scope.exp();
			} else {
				$scope.display = tst.valueOf();
			}
		}
		
		//todo  add functionality for sigma,n - 1 cases as well
		//sd stands for standard deviation
		$scope.sd = function(dv){
			var mean = $scope.ave($scope.list, 0);
			var df = [];
			
			//Calculate the squared difference between list array items and the mean
			for (var i = 0, len = $scope.list.length; i < len; i++){
				df.push( Math.pow($scope.list[i] - mean, 2) );
			}
			
			$scope.output = Math.pow($scope.ave(df, dv ), 0.5);
			
			$scope.dis();
	
			
		}
		
	});

              
            
!
999px

Console