Record collection - tests not succeeding

Tell us what’s happening:
Hi,

When testing my code I only get a checkmark for the 4th and 5th test.

However, when I test my code with console.log everything seems to be working as it should. For example the first test gives this as output:

id: 5439
prop: artist
value: ABBA
object[id][prop]: undefined
original input:
{ albumTitle: 'ABBA Gold' }
 
conditional executed: 
1
 
result: 
{ albumTitle: 'ABBA Gold', artist: 'ABBA' }

As I see it, this should check off the first test.

Can anyone pitch in what i did wrong here?

Note: I left the console.log code in to see my testing method as well.

Thanks
Wannes

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) { 

console.log('id: ' + id)
console.log('prop: ' + prop)
console.log('value: ' + value)
console.log('object[id][prop]: ' + object[id][prop])
console.log('original input:')
console.log(object[id])

console.log(" ")
console.log("conditional executed: ")



if (prop !== 'tracks' && value) {
    console.log("1")  
    collection[id][prop] = value;
  } else if (prop === "tracks" && object[id][prop] == undefined) {
    console.log("2") 
    collection[id][prop] = [value] 
  } else if (prop === "tracks" && value !== "") {
    console.log("3")
    object[id][prop].push(value) 
  } else if (value == "") {
    console.log("4") 
    delete collection[id][prop]
  }

console.log(" ")
console.log("result: ")
console.log(collection[id])
return object;
}

updateRecords(collection, 5439, 'artist', 'ABBA');
//updateRecords(collection, 5439, "tracks", "Take a Chance on Me")
//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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36.

Challenge: Record Collection

Link to the challenge:

how to show the issue…

the tests use a different object than the one in the editor, as said here:

Note: A copy of the collection object is used for the tests.

so let’s add a different object, and call the function on that

const collection2 = {
  1239: {
      'artist': "Abracadabra",
      'year of recording': 2017
   },
   1245: {}
}

updateRecords(collection2, 1239, "title", "Neverwhere")
updateRecords(collection2, 1245, "tracks", "Addicted to Love")

add this at the end of your editor, see if what you get with all your console.logs make sense and you understand what’s going on

Thanks for the reply.
I’ll test this one out and get back to you.

@ILM ,

I figured it out. I was using the name of the object instead of the argument of the function.
Thanks a lot, stupid that I didn’t see that one myself.