Passing array to function java script

<html>
<body>
<script>

//Input the size and values of array
var a=[];
var size=prompt("Enter the size of the array");
for(var i=0;i<size;i++)
{
a[i]=prompt("Enter the "+(i+1)+" th element of array");
}



//function call
var s=sumNumber(a);
document.write(s);


//called function body

function sumNumber(a){

//var a=[];

var sum=0;



for(var i=0;i<a.length;i++)
{

sum=Number(sum)+Number(a[i]);
}


return sum;
}
</script>
</body>
</html>

Comments

Popular posts from this blog

Git Commands With Output Log

Java Interview Preparation (conceptual)

Java 8 Function Interface