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.
- Initialize two counters:
evenCountandoddCount. - Iterate through
nums. - If the current number is even, increment
evenCount. Otherwise, incrementoddCount. - Print the result in the format:
Evens: X, Odds: Y.
01EXAMPLE 1
Input
nums = [1, 2, 3]Output
Evens: 1, Odds: 2Explanation: 2 is even, 1 & 3 are odd.
Constraints
- Use the modulo operator (%) to check parity.
ArraysLoopsConditionals
JavaScriptSystem handles I/O — write your function only
Loading...
2 Hidden
Input Arguments
nums[1,2,3]
Expected Output
Evens: 1, Odds: 2
Click RUN to test your solution