Lambda challenge question
sammyebinne (2)

Guys I got this question in the Lambda Challenge and it isn't making any sense to me why my answer isn't working.

Modify the function to return true if the array contains a 0, and returns false otherwise.

function doesArrayContainZero(numbers) {

}

/ Do not modify code below this line /

console.log(doesArrayContainZero([1, 2, 3]), '<-- should be false');
console.log(doesArrayContainZero([1, 0, 2]), '<-- should be true');

my answer:

for (var i = 0; i < numbers.length; i++){
if (numbers[i]===0){
return 'true';
} else {
return 'false';
};
};

You are viewing a single comment. View All
Answered by mwilki7 (784) [earned 5 cycles]
View Answer
ash15khng (508)

You should be returning the boolean value, not the string.
To do so, remove the quotes from the words true and false.
Also, what is a lambda challenge?

sammyebinne (2)

@ash15khng It still didn't work. LAMBDA challenge is a requirement for acceptance into LAMBDA's full stack developer training program. You get timed questions like this.

ash15khng (508)

@sammyebinne Oh, I see. Thanks! Also sorry I couldn't help.

TommyGunzz (0)

@sammyebinne did you ever solve this challenge??

sammyebinne (2)

yeah

const doesArrayContainZero = (numbers) => {

let zeroElements = numbers.filter((e) => e == 0);
return zeroElements.length ? true : false

}
/ Do not modify code below this line /

console.log(doesArrayContainZero([1, 2, 3]), '<-- should be false');
console.log(doesArrayContainZero([1, 0, 2]), '<-- should be true');

@TommyGunzz

TommyGunzz (0)

thanks, i will have to study this, dont remember .filter [email protected]