Somebody can help me I can't pass record collection

Tell us what’s happening:
Describe your issue in detail here.

I all accord with the hint 1 to type code but still can’t pass
Your code so far

// 设置
const recordCollection = {
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'
}
};

// 只修改这一行下面的代码
function updateRecords(records, id, prop, value) 
{if(prop!=='tracks'&& value!==""){records[id][prop]=value;}
else if(prop==="tracks"&&records[id].hasOwnProperty("tracks")
    records[id][prop]=[value];}
else if(prop==="tracks"&& value!==""){records[id][prop].push(value)} 
else if(value===""){delete records[id][prop];}
return records;


}
updateRecords(recordCollection,5439,'artist','ABBA');
console.log(updateRecords)



  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36

Challenge: Record Collection

Link to the challenge:

please write your code on multiple lines, that’s really really really hard to read

Dear i:
I had amended my code’s length, could you help me ,many thanks!

function updateRecords(records, id, prop, value) {
  if (prop !== 'tracks' && value !== "") {
    records[id][prop] = value;
  } else if (prop === "tracks" && records[id].hasOwnProperty("tracks") records[id][prop] = [value];
  }
  else if (prop === "tracks" && value !== "") {
    records[id][prop].push(value)
  } else if (value === "") {
    delete records[id][prop];
  }
  return records;


}

I passed your code through a formatter
this code has syntax issues, that’s the primary reason it’s not working

Don’t you get something like this?

SyntaxError: unknown: Unexpected token, expected ")" (27:71)

  25 |   if (prop !== 'tracks' && value !== "") {
  26 |     records[id][prop] = value;
> 27 |   } else if (prop === "tracks" && records[id].hasOwnProperty("tracks") records[id][prop] = [value];
     |                                                                        ^
  28 |   }
  29 |   else if (prop === "tracks" && value !== "") {
  30 |     records[id][prop].push(value)
1 Like
<REDACTED>

your code is error

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

Okay, I’ll write pseudocode and ideas next time

Dear I
I try retype.Many thanks!

Dear i
I retype the codes below: , but still can’t pass I had redacted and used your way to write on multiple lines. Could you correct my codes, if you have free time ,many thanks!

// 设置
const recordCollection = {
  2548: {
    albumTitle: 'Slippery When Wet',
    artist: 
    tracks: 
  },
  2468: {
    albumTitle: '1999',
    artist: 'Prince',
    tracks: ['1999', 'Little Red Corvette']
  },
  1245: {
    albumTitle:"Riptide"
    artist: 'Robert Palmer',
    tracks: ["Addited to Love"]
  },
  5439: {
    albumTitle: 'ABBA Gold'
    artist:"ABBA"
    tracks:["Take a Chance on Me"]
  }
};

// 只修改这一行下面的代码
function updateRecords(records, id, prop, value) {
  if (prop!=='tracks'&&value!=="") {
    records[id][prop]=value; 
  } else if (prop==="tracks"&& records[id].hasOwnProperty("tracks")) { 
    records[id][prop]=[value]; 
  } else if (prop==="tracks"&&value!=="") {
    records[id][prop].push(value);
  } else if (value==="") {
    delete records[id][prop];
  } return records;
}
updateRecords(recordCollection, 5439, 'artist', 'ABBA');
console.log(updateRecords)

What tests are you failing? What does the console say?

I reset the code but no working, can’t run the test so I don’t know where is my failing and the console no running.

What do you mean that you can’t run the tests?

What’s written in the console?

Yes,may be my codes are not correct so can’t run the test.

1 Like

I tried to run your latest code. It revealed some errors. One of them is that you forgot to add comma after you wrote some properties, like this (pay attention closely):

And undefined properties (look at artist and tracks):

Below is the computer response:
SyntaxError: unknown: Unexpected token, expected “,” (6:10)

4 | albumTitle: ‘Slippery When Wet’,
5 | artist:

6 | tracks:
| ^
7 | },
8 | 2468: {
9 | albumTitle: ‘1999’,

Dear admuh
I had added the comma and below are my retyped codes:

// 设置
const recordCollection = {
  2548: {
    albumTitle: 'Slippery When Wet',
    artist: "",
    tracks:[] 
  },
  2468: {
    albumTitle: '1999',
    artist: 'Prince',
    tracks: ['1999', 'Little Red Corvette']
  },
  1245: {
    albumTitle:"Riptide",
    artist: 'Robert Palmer',
    tracks: ["Addited to Love"]
  },
  5439: {
    albumTitle: 'ABBA Gold',
    artist:"ABBA",
    tracks:["Take a Chance on Me"]
  }
};

// 只修改这一行下面的代码
function updateRecords(records, id, prop, value) {
  if (prop!=='tracks'&&value!=="") {
    records[id][prop]=value; 
  } else if (prop==="tracks"&& records[id].hasOwnProperty("tracks")) { 
    records[id][prop]=[value]; 
  } else if (prop==="tracks"&&value!=="") {
    records[id][prop].push(value);
  } else if (value==="") {
    delete records[id][prop];
  } return records;
}
updateRecords(recordCollection, 5439, "artist", "ABBA");
console.log(updateRecords(recordCollection, 5439,"artist", "ABBA"))
updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me")
console.log(updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me"))
updateRecords(recordCollection, 2548, "artist", "");
console.log(updateRecords(recordCollection, 2548,"artist",""))
updateRecords(recordCollection, 1245, "tracks", "Addicted to Love")
console.log(updateRecords(recordCollection, 1245, "tracks", "Addicted to Love"))
updateRecords(recordCollection, 2468, "tracks", "Free")
console.log(updateRecords(recordCollection, 2468, "tracks", "Free"))
updateRecords(recordCollection, 2548, "tracks", "")
console.log(updateRecords(recordCollection, 2548, "tracks", ""))
updateRecords(recordCollection, 1245, "albumTitle", "Riptide")
console.log(updateRecords(recordCollection, 1245, "albumTitle", "Riptide"))

After run the test their responses are below and 2,5,6 items are failled.

  • Passed: 1.After updateRecords(recordCollection, 5439, "artist", "ABBA"), artist should be the string ABBA

  • Failed: 2.After updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me"), tracks should have the string Take a Chance on Me as the last and only element.

  • Passed: 3.After updateRecords(recordCollection, 2548, "artist", ""), artist should not be set

  • Passed: 4.After updateRecords(recordCollection, 1245, "tracks", "Addicted to Love"), tracks should have the string Addicted to Love as the last element.

  • Failed: 5.After updateRecords(recordCollection, 2468, "tracks", "Free"), tracks should have the string 1999 as the first element.

  • Failed: 6.After updateRecords(recordCollection, 2548, "tracks", ""), tracks should not be set

  • Passed: 7.After updateRecords(recordCollection, 1245, "albumTitle", "Riptide"), albumTitle should be the string Riptide

Why the 2,5,6 items are failed? Could you help me?many thanks!

hwapipi

Dear ilenia :
I had passed! I use 2nd hint in the ask for help item and passed , many thanks your helping.

hwapipi

Dear Iuojiyin:
I had passed! I use 2nd hint in the ask for help item and passed , many thanks your helping.

hwapipi

Dear admuh:
I had passed! I use 2nd hint in the ask for help item and passed , many thanks your helping.

hwapipi