Same Response but different Code...WHY?

Tell us what’s happening:
This my code gave me False which was the response to output. However is not submitting… Is this my Method as well correct because what i found in the Hint is different from mine.

  **Your code so far**

function checkPositive(arr) {
// Only change code below this line
let newCheck = arr.every(function(e){
return e === parseInt(arr) ? true: e !== true ? false : NaN;

return newCheck

// Only change code above this line
console.log(checkPositive([1, 2, 3, -4, 5]));
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36

Challenge: Use the every Method to Check that Every Element in an Array Meets a Criteria

Link to the challenge:

I don’t understand this line.

Why are you trying to parse an int out of the array? That is non-sensical and I think evaluates to 1. parseInt is used for strings, not arrays.

All you need to do there is check if the number being passed into the callback is positive. Your logic should be much simpler.

I am still a BEGINNER in JS and understanding this is a bit difficult.

I used parseInt because that’s what i saw in my search to solve the question.

Please it's not NON-SENSICAL but i accept that it might be a WRONG APPLICATION OF METHODS


what should this do?
if you explain what your logic here we could try to help

ParseInt there is that : i want to say if e is equal to a wholenumber(positiveNumber) it should console log true if not, false else NaN… This is what i want to do and the response to this gave me false which is the answer I should deliver according to the challenge…

Please Help for Correction

But you are calling parseInt on the entire array, arr. This is the part that does not make sense.

I think trying to use the functional syntax is confusing you. How would you write a raw for loop to check if every element in an array is positive? It helps to think of how you would solve the problem with simple loops before using the more advanced syntax.

1 Like

I’m sorry, I didn’t intend to be rude. I meant the code is non-sensical, not you. Trust me, we’ve all written bad code. We all remember what it was like to learn this stuff - it was hard. And the only way to learn to write good code is to write a lot of bad code first, and learn from the mistakes.

And it will work with the every, if you get the logic right. (But I do agree that if you are having trouble, simplify until you understand…) It’s just that running parseInt on the array doesn’t makes sense and there is no need for parseInt in general because you aren’t dealing with strings. In your loop (whether for or every ) all you need to do is confirm that the elements (numbers) are positive. There is no need to parseInt or do a nested ternary.


This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.