question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"After updateRecords(2468, "tracks", "Free"), tracks should have "1999" as the first element." still failing even with output correct.

See original GitHub issue

Challenge Record Collection has an issue. User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36. Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:


// Setup
var collection = {
    "2548": {
      "album": "Slippery When Wet",
      "artist": "Bon Jovi",
      "tracks": [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    "2468": {
      "album": "1999",
      "artist": "Prince",
      "tracks": [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    "1245": {
      "artist": "Robert Palmer",
      "tracks": [ ]
    },
    "5439": {
      "album": "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {
  if (prop !== "tracks" && value !== "") {
        collection[id][prop] = value;
    } else if (prop == "tracks" && value !== "") {
        if (!collection.hasOwnProperty("tracks")) { // moved from outside loop
            collection[id]["tracks"] = [];
            collection[id][prop].push(value);
        } else {
          collection[id][prop].push(value);
        }

    } else { // removed (value === "")
        delete collection[id][prop];
    }

  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");


Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
BeetleJuice-TOcommented, Aug 25, 2016

else if (prop == “tracks” && value !== “”) { // you said in this line my prop= “tracks” then let go inside the if if (!collection.hasOwnProperty(“tracks”)) { // then you said if “tracks” does not inside collection but with wrong syntax you should write if(!collection[id].hasOwnProperty(“tracks”)) collection[id][“tracks”] = []; collection[id][prop].push(value);

but totally you think wrong somewhere because if your value = null, you have to delete the item inside the object, so your first statement should be if(value = “”) {delete collection[id][prop];

0reactions
svmarinezcommented, Oct 5, 2018

@Xelepam ! is the logical NOT operator. In this context, it would be the same as saying if the ID of the collection does not have the property “tracks” in human speak.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"After updateRecords(2468, "tracks", "Free"), tracks ... - GitHub
"After updateRecords(2468, "tracks", "Free"), tracks should have "1999" as the first element." still failing even with output correct. #10132.
Read more >
I don't why it is bringing this error - The freeCodeCamp Forum
This is the errror: After updateRecords(recordCollection, 2468, “tracks”, “Free”), tracks should have the string 1999 as the first element.
Read more >
Question about JavaScript Algorithms and Data Structures
While doing the recordCollection problem, I thought I solved it, but the site is saying some of the tests are failing even though...
Read more >
Uncaught (in promise) DOMException: play() failed because ...
According to the new browser policy, the user must interact with DOM first before playing the Audio element. If ...
Read more >
Free Code Camp - Basic Javascript Flashcards | Quizlet
Sometimes you will need to build a string, Mad Libs style. By using the concatenation operator (+), you can insert one or more...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found