Help with lodash JavaScript project

Link to exercise:

I’m on step 25/ 26.

The goal is to create an invert method that takes in an object and creates a new object where the original object’s keys and values are flipped, so that the key becomes the value and vise versa. I was having trouble with this, and viewed the get help video. I’ve checked my syntax thoroughly and have typed exactly what was shown in the get help video, but I’m still not passing all 4 tests. I pass the first three, but get the following error message for the fourth: ‘Returns an object with all keys and values inverted - Failed: _.invert({originalKey: “originalValue”})[“originalKey”]) returned undefined instead of anotherKey’. I noticed in the get help video, she only had to pass three tests, which the code passes. A fourth test seems to have been added which i’m failing. Any ideas on what to do?

Here is my code:

  invert(object) {
    let invertedObject = {};
    for(let key in object){
      const originalValue = object[key];
      invertedObject = {originalValue : key}
    return invertedObject;
1 Like

Hello, and welcome to the forums!

The solution in the video for the invert() method is incorrect. Here is a breakdown of why it’s wrong that gives insight into fixing it as well:

1 Like