JS básico 92/111

Perdón si lo escribo en español. No encuentro el error en este código
ya que realiza lo pedido por el ejercicio.

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

Después de updateRecords(recordCollection, 2548, "artist", "") , artist no se debe establecido

Debería eliminar “artist” y así lo hace la función.
Alguno sabe por qué no estaría bien el código ?

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Thanks !. im so new here, nx time ill do it in that form.

I was able to look at your code.

Two things.

No.1:
You need to use all four function parameters.

You are not using records at all.
You are not supposed to use recordCollection but instead you have to use records.
You need to replace all of the recordCollections in your code with records.

No.2:
You have errors in the following areas.

You are not supposed to use dots and brackets.
Just use the brackets.

For example:
records[id][prop]

Hope that makes sense!

that’s makes all the sense! Thanks you for your time !

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.