Question
Hello, i have an html file and a javascript that acts as a calculator, but im running into issues. My calcMean function is the only
Hello, i have an html file and a javascript that acts as a calculator, but im running into issues. My calcMean function is the only one displaying any values. My html file is as such:
and my javascript is as follows: i dont understand why values (except the mean value) aren't being printed. if anyone could remedy this issue that would be great.
"use strict"; function performStatistics(){ var newarray= document.getElementById("numbers").value.split(" "); for (var i=0; i if(newarray[i] 100){ alert("Enter positive values from 0-100") return false; } } if (newarray.length 20){ alert("Enter at least 5 values & no more than 20"); return false; } document.getElementById("meannum").value= calcMean(newarray); document.getElementById("mednum").value= calcMedian(newarray); document.getElementById("modenum").value= calcMode(newarray); document.getElementById("stddev").value= calcStdDev(newarray); document.getElementById("sumnum").value= calcSum(newarray); document.getElementById("varinum").value= calcVariance(newarray); document.getElementById("maxnum").value= findMax(newarray); document.getElementById("minnum").value= findMin(newarray); return false; }
function calcMean(array){
return calcSum(array)/array.length; }
function calcMedian(array){
var med= 0; var arraylen= array.length; arraylen.sort();
if (arraylen %2 === 0) { med= (array[arraylen / 2-1] + array[arraylen/2]) /2; //takes average of an even array } else { med= array[(arraylen- 1) /2]; //takes middle value of odd array } return med; }
function calcMode(array){ var mode=[]; var counter=[]; var i; var holder; var maxfreq = 0; for (i =0; i holder= array[i]; counter[array]= (counter[holder] || 0) +1 if (counter[holder]> maxfreq) { maxfreq= counter[holder]; } } for (i in counter) if (counter.hasOwnProperty(i)) { //returns boolean value^ if (counter[i] === maxfreq) { mode.push(Number(i)); //pushes value into (end of) array } } return mode; }
function calcStdDev(array){ return Math.sqrt(calcVariance(array)).toFixed(2); }
function calcSum(array){ var sum=0; for (var i=0; i sum += Number(array[i]); } return sum.toFixed(2); }
function calcVariance(array){ var avg= calcMean(array); var newarray=[]; var vari; for(i=0; i newarray[i]= (array[i]- avg)*(array[i]- avg); } vari= calcSum(newarray)ewarray.length; return vari.toFixed(2); }
function findMax(array){ var newarray= array; var maxnum=Math.max(newarray); return maxnum; }
function findMin(array){ var newarray= array; var minnum=Math.min(newarray) return minnum; }
FStatistical Calculator
Enter 5-20 values within 0-100 inside the box below. Each value should be separated by one space.
de fator Sport rekao to nie ste the box belo 12 13 14 15 16ePortfolio 42 L
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started