Answer: Write a number array and add only odd numbers? Given an array, write a program to find the sum of values of even and odd index.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<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
1 |
chinese |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.