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.

Formatting issue within Basic Javascript, Record Collection

See original GitHub issue

Describe your problem and how to reproduce it: For the challenge Javascript Algorithms and Data Structures -> Basic Javascript -> Record Collection, the collection variable is not supposed to change, but whenever you format the code (Control + Shift + i) the collection changes, which will fail the challenge and since it only removes single space character it’s hard to notice.

To reproduce

  1. Go to the challenge.
  2. Press Control + Shift + i to format the code.
  3. Run the tests. The first test fails with You should not change the collection object’s initialization, even though the user didn’t really modify it.

Add a Link to the page with the problem: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/record-collection

Updating the challenge to remove the space and fixing the RegEx should solve the issue:

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: [ ] // <-- Remove this space
  },
  5439: {
    album: "ABBA Gold"
  }
};

And update the test/regex accordingly.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:30 (30 by maintainers)

github_iconTop GitHub Comments

3reactions
ShaunSHamiltoncommented, Sep 2, 2020

@skaparate What are your thoughts about:

  1. Change the seed so that the function accepts an object, and returns the object changed.
  2. Remove the first test (no need for it)
  3. Run all tests, by passing _recordObject to the function.
  4. Leave the collection variable as is, so campers can use it to debug.
  5. Change lesson text to clarify: “The original collection object will be used for the tests”
1reaction
RandellDawsoncommented, Sep 2, 2020

@skaparate After watching your video, I now know what the issue is. When I was testing it, I only used the function and not the function and the call to the function (which is part of the seed code). If you comment out the call to the function, it works as expected. However, we do not want a test to fail just because of a user making a call to the function while they are testing things out.

The reason calling the function with updateRecords(5439, "artist", "ABBA") causes it to fail, is based on how our test runner works. Each test is completely isolated from each other. However, for each test all the code in the editor (the function plus the call to the function) is executed before each test runs. That means, when the first test runs, the call to the function updates collection before the testString is evaluated. So, it will never be “equal” to __recordObject, because “artist”: ABBA" gets added to the property 5439 before the assert.

I will need to ponder this overnight. If I can not figure out a way to resolve, then we will have to move forward with a regex approach.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Basic JavaScript - Record Collection - JavaScript
Tell us what's happening: Describe your issue in detail here. ... Do we need to set const records to [id][prop][value] at the beginning?...
Read more >
Record Collection Tips - Zoho Cares
Zoho has done a VERY great job on making loops and record collection for us EASY! Here's a really basic loop in JAVASCRIPT....
Read more >
FreeCodeCamp: I am stuck on "Record Collection"
If prop is "tracks" and value isn't empty (""), push the value onto the end of the album's existing tracks array. If value...
Read more >
Basic Javascript: Record Collection [Please Help] - Reddit
Hi guys, first-time poster here. I've been stuck on the Record Collection challenge for two weeks now. I feel like I've hit a...
Read more >
Manage contact property formatting issues
In the dropdown menu, select Fix formatting issues. ... The rules you set will automatically accept suggestions for records currently listed ...
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