课程里的记录集合 卡在这了

// 设置

var 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;

console.log(records[id][prop]);

}

else if(prop==“tracks”&&!records[id].hasOwnProperty(prop)){

records[id][prop]= value;

console.log(records[id][prop]);

}

else if(prop==“tracks”&&value!=""){

records[id][prop].push(value);

console.log(records[id].tracks[0]);

}

else if(value==""){

delete records[id][prop];

}

return ;

}

updateRecords(recordCollection, 5439, “tracks”, “ABBA”)

  1. 看报错,请使用英文标点:
    image
  2. 请仔细看题目要求,第一条就要求了函数的返回值,所以你的 return ; 肯定不对:
    image
  3. 请再仔细看题目要求,你写的是 records[id][prop]= value;,而要求是包含 value 的数组
    image

var 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(value == undefined && value == null){

delete records[id][prop];

}else{

if(prop == "tracks"){

 if(records[id].tracks == undefined ){

   records[id].tracks = [];

   records[id].tracks.push(value);

 }else{

   records[id].tracks.push(value);

 }

}else{

  records[id][prop] = value;

}

}

return records;

}

// console.log(updateRecords(recordCollection, 5439, ‘artist’, ‘ABBA’));

console.log(updateRecords(recordCollection, 2548, “artist”, “”));

console.log(updateRecords(recordCollection, 2548, “tracks”, “”));

console.log(recordCollection);

麻烦看一下这是我写的,但是value为空的时候不会通过。

谢谢你
我已经解决了