I'm currently enrolled in a JavaScript coding course where I am tackling a task involving validating serial numbers. The requirement is to check if a serial number is valid and then add it to an array to store all the valid serial numbers. The criteria for a valid serial number are as follows:
- It must be an odd number
- It must have exactly 6 digits
Below is my current code snippet:
function findEfficientBulbs(serialNumbers) {
console.log(serialNumbers);
const efficientSerialNumbers = [];
for (let i = 0; i < serialNumbers.length; i++) {
let currentNumber = serialNumbers[i]
if (currentNumber % 2 === 1 && currentNumber.length === 6) {
efficientSerialNumbers.push(currentNumber)
}
};
return efficientSerialNumbers;
}
However, after testing my code on the platform, I received an error message indicating that the even numbers were not being removed. Here is the specific error message:
'should keep all efficient numbers - those that are odd and have six digits'
✕ AssertionError: expected [] to deeply equal [ 234567, 456789 ]
logs
[ 123456, 234567, 345678, 456789 ]'
I have attempted using nested if statements but still faced the same issue.