JAVASCRIPT PROGRAM TO FIND AND PRINT HOW MANY TIMES THE NUMBER 8 OCCURS IN AN ARRAY

<html>
<body>
<script language="javascript">

var i, n,count;
count=0;
n=prompt("Enter the size of the Array");
var a = new Array(n);

for( i=1; i <= n; i++ )
{
   a[i]=prompt("Enter the element   :");
}

document.write("Given Elements are" + "<br>" );
for( i=1; i <= n; i++ )
{
   document.write(a[i]+"<br>" );
}

for( i=1; i <= n; i++ )
{
    if ( a[i] == 8 )
{
             count=count+1;
}
}
  document.write(count+" time(s) appeared in the given set"+"<br>");
</script>
</body>
</html>

No comments:

Post a Comment