Array Competency Practice

  Given an array of integers, write a JavaScript function to find and print the highest even score in the array, the average of all odd scores in the array, and then print every test score that is between these 2 values.  Also print how many scores in the array were less than the average odd score.

function findAverage(nums)
         {  
                      sum=count=highodd=avgeven=0;

               for (i=0;i<nums.length;i++)
               {
                     if ((nums[i]%2==0) && (nums[i]> ehigh))
                     {
                          ehigh = nums[i];
                     }

                     if (nums[i]%2==1)
                     {
                         sum = sum + nums[i];
                         ecount = ecount + 1;
                     }
                     oavg = sum/ecount;
               }
              
                     document.write(“the highest even is “+ehigh+”<br>”);
                     document.write(“average odd is “+oavg+”<br>”);

               for(i=0;i<nums.length;i++)
               {
                    if (nums[i]<ehigh)
                        if (nums[i]>oavg)
                             document.write(nums[i]+”  “);

                    if (nums[i]<oavg)
                          count = count+1;
               }
              
               document.write(“number less than odd avg is “+count+”<br>”);

         }

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>