»
EnglishFrenchVietnamese

Print - Lagrest, smallest and sum - JavaScriptBank.com

Full version: jsB@nk » Calculation » Math » Lagrest, smallest and sum
URL: https://www.javascriptbank.com/lagre-small-number.html

Lagrest, smallest and sum © JavaScriptBank.comThis JavaScript uses array to store tha values users submit then will alert the largest, smallest number and sum of the numbers.

Full version: jsB@nk » Calculation » Math » Lagrest, smallest and sum
URL: https://www.javascriptbank.com/lagre-small-number.html



JavaScript
<script language="javascript">arr=new Array() var i=0,value=0,flag=falsevar sum=0function aj(a){flag=truevar check=aarr[i]=eval(a)sum=sum+arr[i]i++document.f1.t1.value=""document.f1.t1.focus()}function j(){var n=arr.length,small=arr[n-1],large=arr[0]for(i=0;i<n;i++){if(arr[i]>large)large=arr[i]if(arr[i]<small)small=arr[i]}if(!flag){large=0;small=0;}alert(large+"  is the largest among the numbers"+"\n"+small+"  is the smallest among the numbers")alert("The sum of the numbers is  "+sum)}</script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<form name="f1" style="text-align: left; width: 40%;">Type numbers one by one as much you wish.....<br>Press &quot;OK&quot; after every number...<br>  Press &quot;RESULT&quot; to see which number is smallest and which is largest..... and the total sum of all numbers<br><input type="text" name="t1"><input type="button" value=" OK " onClick="aj(f1.t1.value)">  <br><input type="button" value=" RESULT " onClick="j()"></form><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->