No solution works for Implement the filter Method on a Prototype

Any solution I try to this problem gives me:

// running tests
TypeError: Cannot read property ‘message’ of undefined

Even tried both given solutions on the help page and I repeatedly get this error, can anyone help?


  **Your code so far**

// The global variable
var s = [23, 65, 98, 5];

Array.prototype.myFilter = function(callback) {
// Only change code below this line
this.forEach( (el) => callback(el) && newArray.push(el) );
// Only change code above this line
return newArray;

var new_s = s.myFilter(function(item) {
return item % 2 === 1;
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36.

Challenge: Implement the filter Method on a Prototype

Link to the challenge:

I don’t kow where the error come from, it may be a question of incompatibility with your browser or browser extension

but your code is not correct

this newArray here does not exist, and that should give an error of the kind “cannot read property push of undefined”

1 Like

Thanks…rookie error haha, that went through when I created a blank array newArray, although when I had tried a for loop or even the provided solutions I got that error every time, it must be a chrome issue.

I tried to replicate your error, I get this