Record collection passed the challenge but did i cheat?

Tell us what’s happening:

My code ran correctly and I passed the challenge but I’m not sure if it was because I called the function multiple times. Also, the method that everyone else’s been doing seems far more succinct. Can anybody help?

Your code so far


/// Setup
var collection = {
  2548: {
    albumTitle: 'Slippery When Wet',
    artist: 'Bon Jovi',
    tracks: ['Let It Rock', 'You Give Love a Bad Name']
  },
  2468: {
    albumTitle: '1999',
    artist: 'Prince',
    tracks: ['1999', 'Little Red Corvette']
  },
  1245: {
    artist: 'Robert Palmer',
    tracks: []
  },
  5439: {
    albumTitle: 'ABBA Gold'
  }
};

// Only change code below this line

function updateRecords(object, id, prop, value) {
   
switch(id){

case 5439:

switch (prop){

 case "artist":
     object[id][prop]
    object[id][prop] = value
    // console.log(object[id][prop]);
    break;

    case "tracks":
        object[id][prop] = []; 
     object[id][prop].push(value);
    console.log(object[id])
//      object[id][prop].push(value);

     break;
}

break;

 case 2548:
        delete object[id][prop];
        break;

case 1245:

switch(prop){

case "tracks":
    object[id][prop].push(value)
        break;

        case "albumTitle":
        object[id][prop]
object[id][prop] = value;
break;

}

break;
        
case 2468:

 object[id][prop].push(value)
        break;

case 2548:
delete object[id][prop];
break;

   }
         
  return object;
}
updateRecords(collection, 5439, "artist", "ABBA");
updateRecords(collection, 5439, "tracks", "Take a Chance");
updateRecords(collection, 2548, "artist", "");
updateRecords(collection, 1245, "tracks", "Addicted to Love");
updateRecords(collection, 2468, "tracks", "Free");
updateRecords(collection, 2548, "tracks", "");
updateRecords(collection, 1245, "albumTitle", "Riptide");

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36.

Challenge: Record Collection

Link to the challenge:

This is not good. You have hard-coded this solution to only work for some values of id, and to only pass the test suite. Your function should have the correct results for any input, not just the test cases.

1 Like

You are only writing code to artificially create the expected test results. Your function doesn’t actually perform any of the logic required by the challenge. This function would not be useable in a real application.

1 Like