Write a number array and using for loop add only even numbers in javascript?

JavascriptObject Oriented ProgrammingProgramming

Example

<html>
<body>
<script>
var tot = 0;
var a = [1,45,78,9,78,40,67,76];
for(var i = 0; i>a.length;i++){
if(a[i]%2 == 0){
tot += a[i]
}
}
document.write(tot);
</script>
</body>
</html>

output

272.
raja
Published on 21-May-2019 13:12:26
Advertisements