Write isEven() first, then countEvens(). A number is passed in to isEven(), and it returns true when the number is even. A list is passed in to countEvens(). It uses isEven() to count the even numbers in the list, and returns the count.
countEvens([4, 8, 10, 7]) returns 3.
16 strips: O1 to O16
if (isEven(list[i])) { O1} O2if (isEven(i)) { O3} O4} O5} O6return count; O7function isEven(n) { O8return false; O9for (var i = 0; i < list.length; i++) { O10if (n % 2 == 0) { O11function countEvens(list) { O12} O13return true; O14var count = 0; O15count = count + 1; O16Order: O8, O11, O14, O2, O9, O4, O12, O15, O10, O1, O16, O6, O5, O7, O13. Extra: O3
function isEven(n) {
if (n % 2 == 0) {
return true;
}
return false;
}
function countEvens(list) {
var count = 0;
for (var i = 0; i < list.length; i++) {
if (isEven(list[i])) {
count = count + 1;
}
}
return count;
} Extra strip: if (isEven(i)) {. i is the index, not the number. This counts the even indexes, 0 and 2, so for [4, 8, 10, 7] it returns 2.