<p dir="auto">Challenge <a href="https://www.freecodecamp.com/challenges/record-collection#?solution=%0A%2F%2F%20Setup%0Avar%20collection%20%3D%20%7B%0A%20%20%20%202548%3A%20%7B%0A%20%20%20%20%20%20album%3A%20%22Slippery%20When%20Wet%22%2C%0A%20%20%20%20%20%20artist%3A%20%22Bon%20Jovi%22%2C%0A%20%20%20%20%20%20tracks%3A%20%5B%20%0A%20%20%20%20%20%20%20%20%22Let%20It%20Rock%22%2C%20%0A%20%20%20%20%20%20%20%20%22You%20Give%20Love%20a%20Bad%20Name%22%20%0A%20%20%20%20%20%20%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%202468%3A%20%7B%0A%20%20%20%20%20%20album%3A%20%221999%22%2C%0A%20%20%20%20%20%20artist%3A%20%22Prince%22%2C%0A%20%20%20%20%20%20tracks%3A%20%5B%20%0A%20%20%20%20%20%20%20%20%221999%22%2C%20%0A%20%20%20%20%20%20%20%20%22Little%20Red%20Corvette%22%20%0A%20%20%20%20%20%20%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%201245%3A%20%7B%0A%20%20%20%20%20%20artist%3A%20%22Robert%20Palmer%22%2C%0A%20%20%20%20%20%20tracks%3A%20%5B%20%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%205439%3A%20%7B%0A%20%20%20%20%20%20album%3A%20%22ABBA%20Gold%22%0A%20%20%20%20%7D%0A%7D%3B%0A%2F%2F%20Keep%20a%20copy%20of%20the%20collection%20for%20tests%0Avar%20collectionCopy%20%3D%20JSON.parse%28JSON.stringify%28collection%29%29%3B%0A%0A%2F%2F%20Only%20change%20code%20below%20this%20line%0Afunction%20updateRecords%28id%2C%20prop%2C%20value%29%20%7B%0A%20%20var%20identry%20%3D%20id%3B%0A%20%20var%20recordID%20%3D%20collection%5Bidentry%5D%3B%0A%20%20if%28value%20!%3D%3D%22%22%29%7B%0A%20%20%20%20if%28prop%20%3D%3D%3D%20%22tracks%22%29%7B%0A%20%20%20%20%20%20recordID%5Bprop%5D.push%28value%29%3B%0A%20%20%20%20%7D%0A%20%20%20%20else%7B%0A%20%20%20%20%20%20recordID%5Bprop%5D%20%3D%20value%3B%0A%20%20%20%20%7D%0A%20%20%7D%0A%20%20%20else%7B%0A%20%20%20%20%20delete%20recordID%5Bprop%5D%3B%0A%20%20%20%7D%0A%20%20return%20collection%3B%0A%7D%0A%0A%2F%2F%20Alter%20values%20below%20to%20test%20your%20code%0AupdateRecords%285439%2C%20%22artist%22%2C%20%22ABBA%22%29%3B%0A%0A" rel="nofollow">Record Collection</a> has an issue.<br>
User Agent is: <code class="notranslate">Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0</code>.<br>
Please describe how to reproduce this issue, and include links to screenshots if possible.</p>
<p dir="auto">My code:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
// Setup
var collection = {
    2548: {
      album: &quot;Slippery When Wet&quot;,
      artist: &quot;Bon Jovi&quot;,
      tracks: [ 
        &quot;Let It Rock&quot;, 
        &quot;You Give Love a Bad Name&quot; 
      ]
    },
    2468: {
      album: &quot;1999&quot;,
      artist: &quot;Prince&quot;,
      tracks: [ 
        &quot;1999&quot;, 
        &quot;Little Red Corvette&quot; 
      ]
    },
    1245: {
      artist: &quot;Robert Palmer&quot;,
      tracks: [ ]
    },
    5439: {
      album: &quot;ABBA Gold&quot;
    }
};
// 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) {
  var identry = id;
  var recordID = collection[identry];
  if(value !==&quot;&quot;){
    if(prop === &quot;tracks&quot;){
      recordID[prop].push(value);
    }
    else{
      recordID[prop] = value;
    }
  }
   else{
     delete recordID[prop];
   }
  return collection;
}

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


I keep getting this error:

After updateRecords(5439, &quot;tracks&quot;, &quot;Take a Chance on Me&quot;), tracks should have &quot;Take a Chance on Me&quot; as the last element.

and when i change the values to test the code i get this error on the console that says: recordID[prop] is undefined
"><pre class="notranslate"><span class="pl-c">// Setup</span>
<span class="pl-k">var</span> <span class="pl-s1">collection</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
    <span class="pl-c1">2548</span>: <span class="pl-kos">{</span>
      <span class="pl-c1">album</span>: <span class="pl-s">"Slippery When Wet"</span><span class="pl-kos">,</span>
      <span class="pl-c1">artist</span>: <span class="pl-s">"Bon Jovi"</span><span class="pl-kos">,</span>
      <span class="pl-c1">tracks</span>: <span class="pl-kos">[</span> 
        <span class="pl-s">"Let It Rock"</span><span class="pl-kos">,</span> 
        <span class="pl-s">"You Give Love a Bad Name"</span> 
      <span class="pl-kos">]</span>
    <span class="pl-kos">}</span><span class="pl-kos">,</span>
    <span class="pl-c1">2468</span>: <span class="pl-kos">{</span>
      <span class="pl-c1">album</span>: <span class="pl-s">"1999"</span><span class="pl-kos">,</span>
      <span class="pl-c1">artist</span>: <span class="pl-s">"Prince"</span><span class="pl-kos">,</span>
      <span class="pl-c1">tracks</span>: <span class="pl-kos">[</span> 
        <span class="pl-s">"1999"</span><span class="pl-kos">,</span> 
        <span class="pl-s">"Little Red Corvette"</span> 
      <span class="pl-kos">]</span>
    <span class="pl-kos">}</span><span class="pl-kos">,</span>
    <span class="pl-c1">1245</span>: <span class="pl-kos">{</span>
      <span class="pl-c1">artist</span>: <span class="pl-s">"Robert Palmer"</span><span class="pl-kos">,</span>
      <span class="pl-c1">tracks</span>: <span class="pl-kos">[</span> <span class="pl-kos">]</span>
    <span class="pl-kos">}</span><span class="pl-kos">,</span>
    <span class="pl-c1">5439</span>: <span class="pl-kos">{</span>
      <span class="pl-c1">album</span>: <span class="pl-s">"ABBA Gold"</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span>
<span class="pl-c">// Keep a copy of the collection for tests</span>
<span class="pl-k">var</span> <span class="pl-s1">collectionCopy</span> <span class="pl-c1">=</span> <span class="pl-c1">JSON</span><span class="pl-kos">.</span><span class="pl-en">parse</span><span class="pl-kos">(</span><span class="pl-c1">JSON</span><span class="pl-kos">.</span><span class="pl-en">stringify</span><span class="pl-kos">(</span><span class="pl-s1">collection</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-c">// Only change code below this line</span>
<span class="pl-k">function</span> <span class="pl-en">updateRecords</span><span class="pl-kos">(</span><span class="pl-s1">id</span><span class="pl-kos">,</span> <span class="pl-s1">prop</span><span class="pl-kos">,</span> <span class="pl-s1">value</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">var</span> <span class="pl-s1">identry</span> <span class="pl-c1">=</span> <span class="pl-s1">id</span><span class="pl-kos">;</span>
  <span class="pl-k">var</span> <span class="pl-s1">recordID</span> <span class="pl-c1">=</span> <span class="pl-s1">collection</span><span class="pl-kos">[</span><span class="pl-s1">identry</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
  <span class="pl-k">if</span><span class="pl-kos">(</span><span class="pl-s1">value</span> <span class="pl-c1">!==</span><span class="pl-s">""</span><span class="pl-kos">)</span><span class="pl-kos">{</span>
    <span class="pl-k">if</span><span class="pl-kos">(</span><span class="pl-s1">prop</span> <span class="pl-c1">===</span> <span class="pl-s">"tracks"</span><span class="pl-kos">)</span><span class="pl-kos">{</span>
      <span class="pl-s1">recordID</span><span class="pl-kos">[</span><span class="pl-s1">prop</span><span class="pl-kos">]</span><span class="pl-kos">.</span><span class="pl-en">push</span><span class="pl-kos">(</span><span class="pl-s1">value</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
    <span class="pl-k">else</span><span class="pl-kos">{</span>
      <span class="pl-s1">recordID</span><span class="pl-kos">[</span><span class="pl-s1">prop</span><span class="pl-kos">]</span> <span class="pl-c1">=</span> <span class="pl-s1">value</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
  <span class="pl-kos">}</span>
   <span class="pl-k">else</span><span class="pl-kos">{</span>
     <span class="pl-k">delete</span> <span class="pl-s1">recordID</span><span class="pl-kos">[</span><span class="pl-s1">prop</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
   <span class="pl-kos">}</span>
  <span class="pl-k">return</span> <span class="pl-s1">collection</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-c">// Alter values below to test your code</span>
<span class="pl-en">updateRecords</span><span class="pl-kos">(</span><span class="pl-c1">5439</span><span class="pl-kos">,</span> <span class="pl-s">"artist"</span><span class="pl-kos">,</span> <span class="pl-s">"ABBA"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>


<span class="pl-v">I</span> <span class="pl-s1">keep</span> <span class="pl-s1">getting</span> <span class="pl-s1">this</span> error:

<span class="pl-v">After</span> <span class="pl-en">updateRecords</span><span class="pl-kos">(</span><span class="pl-c1">5439</span><span class="pl-kos">,</span> <span class="pl-s">"tracks"</span><span class="pl-kos">,</span> <span class="pl-s">"Take a Chance on Me"</span><span class="pl-kos">)</span><span class="pl-kos">,</span> <span class="pl-s1">tracks</span> <span class="pl-s1">should</span> <span class="pl-s1">have</span> <span class="pl-s">"Take a Chance on Me"</span> <span class="pl-s1">as</span> <span class="pl-s1">the</span> <span class="pl-s1">last</span> <span class="pl-s1">element</span><span class="pl-kos">.</span>

<span class="pl-c1">and</span> <span class="pl-s1">when</span> <span class="pl-s1">i</span> <span class="pl-s1">change</span> <span class="pl-s1">the</span> <span class="pl-s1">values</span> <span class="pl-s1">to</span> <span class="pl-s1">test</span> <span class="pl-s1">the</span> <span class="pl-s1">code</span> <span class="pl-s1">i</span> <span class="pl-s1">get</span> <span class="pl-smi">this</span> <span class="pl-s1">error</span> <span class="pl-s1">on</span> <span class="pl-s1">the</span> <span class="pl-smi">console</span> <span class="pl-s1">that</span> <span class="pl-s1">says</span>: <span class="pl-s1">recordID</span><span class="pl-kos">[</span><span class="pl-s1">prop</span><span class="pl-kos">]</span> <span class="pl-s1">is</span> <span class="pl-c1">undefined</span></pre></div>
<p dir="auto">Challenge <a href="https://www.freecodecamp.com/challenges/record-collection#?solution=%0A%2F%2F%20Setup%0Avar%20collection%20%3D%20%7B%0A%20%20%20%202548%3A%20%7B%0A%20%20%20%20%20%20album%3A%20%22Slippery%20When%20Wet%22%2C%0A%20%20%20%20%20%20artist%3A%20%22Bon%20Jovi%22%2C%0A%20%20%20%20%20%20tracks%3A%20%5B%20%0A%20%20%20%20%20%20%20%20%22Let%20It%20Rock%22%2C%20%0A%20%20%20%20%20%20%20%20%22You%20Give%20Love%20a%20Bad%20Name%22%20%0A%20%20%20%20%20%20%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%202468%3A%20%7B%0A%20%20%20%20%20%20album%3A%20%221999%22%2C%0A%20%20%20%20%20%20artist%3A%20%22Prince%22%2C%0A%20%20%20%20%20%20tracks%3A%20%5B%20%0A%20%20%20%20%20%20%20%20%221999%22%2C%20%0A%20%20%20%20%20%20%20%20%22Little%20Red%20Corvette%22%20%0A%20%20%20%20%20%20%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%201245%3A%20%7B%0A%20%20%20%20%20%20artist%3A%20%22Robert%20Palmer%22%2C%0A%20%20%20%20%20%20tracks%3A%20%5B%20%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%205439%3A%20%7B%0A%20%20%20%20%20%20album%3A%20%22ABBA%20Gold%22%0A%20%20%20%20%7D%0A%7D%3B%0A%2F%2F%20Keep%20a%20copy%20of%20the%20collection%20for%20tests%0Avar%20collectionCopy%20%3D%20JSON.parse%28JSON.stringify%28collection%29%29%3B%0A%0A%2F%2F%20Only%20change%20code%20below%20this%20line%0Afunction%20updateRecords%28id%2C%20prop%2C%20value%29%20%7B%0A%20%20if%28%20value%20!%3D%3D%20%22%22%29%7B%0A%20%20%20%20if%28prop!%3D%3D%22tracks%22%29%7B%0A%20%20%20%20%20%20collection%5Bid%5D%5Bprop%5D%3Dvalue%3B%0A%20%20%20%20%7D%0A%20%20%20%20else%20if%28%20prop%20%3D%3D%3D%22tracks%22%29%7B%0A%20%20%20%20%20%20collection%5Bid%5D%5Bprop%5D.push%28value%29%3B%0A%20%20%20%20%7D%0A%20%20%7D%0A%20%20else%0A%20%20%20%20delete%20collection%5Bid%5D%5Bprop%5D%3B%0A%0A%20%20return%20collection%3B%0A%7D%0A%0A%2F%2F%20Alter%20values%20below%20to%20test%20your%20code%0AupdateRecords%285439%2C%20%22artist%22%2C%20%22ABBA%22%29%3B%0A%0A" rel="nofollow">Record Collection</a> has an issue.<br>
User Agent is: <code class="notranslate">Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36</code>.<br>
Please describe how to reproduce this issue, and include links to screenshots if possible.</p>
<p dir="auto">My code:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
// Setup
var collection = {
    2548: {
      album: &quot;Slippery When Wet&quot;,
      artist: &quot;Bon Jovi&quot;,
      tracks: [ 
        &quot;Let It Rock&quot;, 
        &quot;You Give Love a Bad Name&quot; 
      ]
    },
    2468: {
      album: &quot;1999&quot;,
      artist: &quot;Prince&quot;,
      tracks: [ 
        &quot;1999&quot;, 
        &quot;Little Red Corvette&quot; 
      ]
    },
    1245: {
      artist: &quot;Robert Palmer&quot;,
      tracks: [ ]
    },
    5439: {
      album: &quot;ABBA Gold&quot;
    }
};
// 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( value !== &quot;&quot;){
    if(prop!==&quot;tracks&quot;){
      collection[id][prop]=value;
    }
    else if( prop ===&quot;tracks&quot;){
      collection[id][prop].push(value);
    }
  }
  else
    delete collection[id][prop];

  return collection;
}

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

"><pre class="notranslate"><span class="pl-c">// Setup</span>
<span class="pl-k">var</span> <span class="pl-s1">collection</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
    <span class="pl-c1">2548</span>: <span class="pl-kos">{</span>
      <span class="pl-c1">album</span>: <span class="pl-s">"Slippery When Wet"</span><span class="pl-kos">,</span>
      <span class="pl-c1">artist</span>: <span class="pl-s">"Bon Jovi"</span><span class="pl-kos">,</span>
      <span class="pl-c1">tracks</span>: <span class="pl-kos">[</span> 
        <span class="pl-s">"Let It Rock"</span><span class="pl-kos">,</span> 
        <span class="pl-s">"You Give Love a Bad Name"</span> 
      <span class="pl-kos">]</span>
    <span class="pl-kos">}</span><span class="pl-kos">,</span>
    <span class="pl-c1">2468</span>: <span class="pl-kos">{</span>
      <span class="pl-c1">album</span>: <span class="pl-s">"1999"</span><span class="pl-kos">,</span>
      <span class="pl-c1">artist</span>: <span class="pl-s">"Prince"</span><span class="pl-kos">,</span>
      <span class="pl-c1">tracks</span>: <span class="pl-kos">[</span> 
        <span class="pl-s">"1999"</span><span class="pl-kos">,</span> 
        <span class="pl-s">"Little Red Corvette"</span> 
      <span class="pl-kos">]</span>
    <span class="pl-kos">}</span><span class="pl-kos">,</span>
    <span class="pl-c1">1245</span>: <span class="pl-kos">{</span>
      <span class="pl-c1">artist</span>: <span class="pl-s">"Robert Palmer"</span><span class="pl-kos">,</span>
      <span class="pl-c1">tracks</span>: <span class="pl-kos">[</span> <span class="pl-kos">]</span>
    <span class="pl-kos">}</span><span class="pl-kos">,</span>
    <span class="pl-c1">5439</span>: <span class="pl-kos">{</span>
      <span class="pl-c1">album</span>: <span class="pl-s">"ABBA Gold"</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span><span class="pl-kos">;</span>
<span class="pl-c">// Keep a copy of the collection for tests</span>
<span class="pl-k">var</span> <span class="pl-s1">collectionCopy</span> <span class="pl-c1">=</span> <span class="pl-c1">JSON</span><span class="pl-kos">.</span><span class="pl-en">parse</span><span class="pl-kos">(</span><span class="pl-c1">JSON</span><span class="pl-kos">.</span><span class="pl-en">stringify</span><span class="pl-kos">(</span><span class="pl-s1">collection</span><span class="pl-kos">)</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-c">// Only change code below this line</span>
<span class="pl-k">function</span> <span class="pl-en">updateRecords</span><span class="pl-kos">(</span><span class="pl-s1">id</span><span class="pl-kos">,</span> <span class="pl-s1">prop</span><span class="pl-kos">,</span> <span class="pl-s1">value</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
  <span class="pl-k">if</span><span class="pl-kos">(</span> <span class="pl-s1">value</span> <span class="pl-c1">!==</span> <span class="pl-s">""</span><span class="pl-kos">)</span><span class="pl-kos">{</span>
    <span class="pl-k">if</span><span class="pl-kos">(</span><span class="pl-s1">prop</span><span class="pl-c1">!==</span><span class="pl-s">"tracks"</span><span class="pl-kos">)</span><span class="pl-kos">{</span>
      <span class="pl-s1">collection</span><span class="pl-kos">[</span><span class="pl-s1">id</span><span class="pl-kos">]</span><span class="pl-kos">[</span><span class="pl-s1">prop</span><span class="pl-kos">]</span><span class="pl-c1">=</span><span class="pl-s1">value</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
    <span class="pl-k">else</span> <span class="pl-k">if</span><span class="pl-kos">(</span> <span class="pl-s1">prop</span> <span class="pl-c1">===</span><span class="pl-s">"tracks"</span><span class="pl-kos">)</span><span class="pl-kos">{</span>
      <span class="pl-s1">collection</span><span class="pl-kos">[</span><span class="pl-s1">id</span><span class="pl-kos">]</span><span class="pl-kos">[</span><span class="pl-s1">prop</span><span class="pl-kos">]</span><span class="pl-kos">.</span><span class="pl-en">push</span><span class="pl-kos">(</span><span class="pl-s1">value</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
  <span class="pl-kos">}</span>
  <span class="pl-k">else</span>
    <span class="pl-k">delete</span> <span class="pl-s1">collection</span><span class="pl-kos">[</span><span class="pl-s1">id</span><span class="pl-kos">]</span><span class="pl-kos">[</span><span class="pl-s1">prop</span><span class="pl-kos">]</span><span class="pl-kos">;</span>

  <span class="pl-k">return</span> <span class="pl-s1">collection</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-c">// Alter values below to test your code</span>
<span class="pl-en">updateRecords</span><span class="pl-kos">(</span><span class="pl-c1">5439</span><span class="pl-kos">,</span> <span class="pl-s">"artist"</span><span class="pl-kos">,</span> <span class="pl-s">"ABBA"</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
</pre></div>