Javascript: Keep count of even and odd random numbers and get the sum of each -


when run program getting number count , odd sum. odd count , sum gives me 0 every time. have idea missing? thanks!

i trying generate 100 random numbers , keep count of evens/odds , sum of each.

var min = 1; var max = 1000; var randomnumarray = [] var oddcount = [] var evencount = [] var oddsum = [] var evensum = []  function iseven(x){     if (x % 2 == 0)         return true;     else         return false; }  function sumofarray(evensum){     for(i = 0; i< evensum.length; i++){         if (iseven){             return(evensum);         }         else{         return (oddsum);         }     } } for( = 0; < 100; i++){     var randnumber = math.floor(min + (math.random() * max));     randomnumarray.push(randnumber); }  for( = 0; i< randnumber.length; i++){     if (iseven(evencount[i])){         return evencount;     }     else{         return oddcount;     } }  console.log('even number count: ' + evencount); console.log('odd number count: ' + oddcount); console.log('sum even: ' + evensum); console.log('sum odd: ' + oddsum); 

i use 1 function check if or odd , decide add sum number , count 1. making way more complicated , i'm wondering why u using arrays.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -