Even/Odd Score Split

EasyAcc. 95.6%
+20 XP 8

Parity Partition

Your goal is to count how many numbers in an array are even and how many are odd.

The Assignment

Your function receives an array nums.

  1. Initialize two counters: evenCount and oddCount.
  2. Iterate through nums.
  3. If the current number is even, increment evenCount. Otherwise, increment oddCount.
  4. Print the result in the format: Evens: X, Odds: Y.

01EXAMPLE 1

Inputnums = [1, 2, 3]
OutputEvens: 1, Odds: 2

Explanation: 2 is even, 1 & 3 are odd.

Constraints

  • Use the modulo operator (%) to check parity.
ArraysLoopsConditionals
JavaScript
Loading...
2 Hidden

Input Arguments

nums[1,2,3]

Expected Output

Evens: 1, Odds: 2

Click RUN to test your solution