Search and replace why is this not working?

I’m wondering why its not taking the arguments and replacing them?

  **Your code so far**
function myReplace(str, before, after) {
return str
.replace(str.hasOwnProperty(before), after)


console.log(myReplace("A quick brown fox jumped over the lazy dog", "jumped", "leaped"));
  **Your browser information:**

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

Challenge: Search and Replace

Link to the challenge:

This evaluates to true or false. What were you hoping to do here?

I was checking if str str.hasOwnProperty(before) has /before (“jumped”)/ and then replacing it with after(“leaped”)

Well the hasOwnProperty is used for checking if an object has a specific property name. str is a string, so you will need to use a different method. The replace method expects a string or something that evaluates to a string as the first argument.

1 Like