What's wrong with this Record Collection strings

what’s wrong here? I’ve been stuck on this for so many days.

Screenshot 2021-08-04 at 15.57.06

Please post your actual code instead of a picture of your code.

if (prop != "tracks" && value !== "") {
    collection[id][prop] = [value];
  } else if (prop) === "tracks" && collection [id][prop] === undefined) {
    collection[id][prop] = [value];
  } else if (value ==="") {
    delete collection [id][prop]
  } else if (prop === "tracks") {
    collection[id][prop].push(value);

It helps to post your entire code.


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 (’).

You should not reference the global variable.

can you speak more on this? I’m quite confused

collection

Is not one of the function arguments. You must use the function arguments.

You also need to address the syntax error you have, notice the red squiggly lines below your code

1 Like

i’v been stuck trying to figure this out for days and I’m beginning to feel like a block head. perhaps a sample of the right code can direct me to what I’m doing wrong. i cannot seem to get this one through.

What is confusing you? How have you updated your code? Have you removed references to collection yet?

have you address the syntax errors? if you still have syntax errors whatever you write will not work, even if you have the correct logic but a typo

It would help to see your current code, we could tell you which parts are working fine and at which point you’ve invited a bug.

Yes, I’ve been gnawing my bone on the code. I’m not sure how to address syntax error and the more I attempt the edit, the more red lines I get.

Yes, i tried this, but i think I have a mental block overall on what next to do. removing collection leads to a few red lines, and i have some problems with syntax error check as well. someone help!

What is your current code? Its hard for us to say much without seeing the code.

What did you replace collection with? You should only use the 4 function arguments.

I posted my code earlier, but i think I’ve made more mess of it as i’m mentally blocked right now.

if (prop != "tracks" && value !== "") {
  } else if (prop) === "tracks" && collection [id][prop] === undefined ) {
  } else if (value ==="") {
    delete collection [id][prop]
  } else if (prop === "tracks") {
  
  }

if (prop != "tracks" && value !== "") {
  } else if (prop) === "tracks" && collection [id][prop] === undefined ) {
  } else if (value ==="") {
    delete collection [id][prop]
  } else if (prop === "tracks") {
  
  }

Let’s back up instead of hacking away parts of your code and hoping something works.


You never posted your entire code, but this is what I think you started with

// Only change code below this line
function updateRecords(records, id, prop, value) {
  if (prop != "tracks" && value !== "") {
    collection[id][prop] = [value];
  } else if (prop) === "tracks" && collection [id][prop] === undefined) {
    collection[id][prop] = [value];
  } else if (value ==="") {
    delete collection [id][prop]
  } else if (prop === "tracks") {
    collection[id][prop].push(value);
  }
  return records;
}

When I use this, I get an error

SyntaxError: unknown: Unexpected token (26:19)

  24 |   if (prop != "tracks" && value !== "") {
  25 |     collection[id][prop] = [value];
> 26 |   } else if (prop) === "tracks" && collection [id][prop] === undefined) {
     |                    ^
  27 |     collection[id][prop] = [value];
  28 |   } else if (value ==="") {
  29 |     delete collection [id][prop]

so let’s fix that first.

This line is bad:

  } else if (prop) === "tracks" && collection [id][prop] === undefined) {

So… why? Well, lets just look at the ()s… do you see a mismatch there?

i think i fixed that, but it’s yet to pass

// Only change code below this line
function updateRecords(records, id, prop, value) {

  if (prop != "tracks" && value !== "") {
  } else if ((prop) === "tracks" && collection [id][prop] === undefined) {
  } else if (value ==="") {
    delete collection [id][prop]
  } else if (prop === "tracks") {
    collection[id][prop].push(value);
  }

  return records;
  
}

Hold on. You deleted something again and by doing that you hid a useful error message.


// Only change code below this line
function updateRecords(records, id, prop, value) {
  if (prop != "tracks" && value !== "") {
    collection[id][prop] = [value];
  } else if (prop === "tracks" && collection[id][prop] === undefined) {
    collection[id][prop] = [value];
  } else if (value ==="") {
    delete collection [id][prop]
  } else if (prop === "tracks") {
    collection[id][prop].push(value);
  }
  return records;
}

You get the error message

ReferenceError: collection is not defined

THIS IS VERY USEFUL! Where is collection defined? What is collection? Is it one of the 4 function arguments that you’re allowed to use?!?

// THESE ARE THE ONLY 4 VARIABLES THAT SHOULD EXIST IN YOUR FUNCTION
//            1        2   3     4
updateRecords(records, id, prop, value)