Basic JavaScript: Record Collection ( Got stuck)

Full instructions here:
"

  • Your function must always return the entire object.
  • If prop isn’t tracks and value isn’t an empty string, update or set that album’s prop to value .
  • If prop is tracks but the album doesn’t have a tracks property, create an empty array and add value to it.
  • If prop is tracks and value isn’t an empty string, add value to the end of the album’s existing tracks array.
  • If value is an empty string, delete the given prop property from the album.
    "

I don’t understand what the other instructions mean except the first one.
Second bullet point I don’t know how to do, and the other ones.

let’s divide the second bullet point in two parts

this is the condition

this is the action

let’s focus first on the condition

how do you check the value of a variable?

2 Likes

You use console.log().

that’s for you to see, but you can’t look always at the console abd then write the code for that situation - console.log() is not the way to write your code logic here

how do you compare the value of a variable in your code so you get a true or false back?

1 Like

With If, else if and else,

you need to check if the variable is or isn’t `“tracks”, how do you do that?

an if statement on its own can’t do that

1 Like
if (variable = "tracks") {
}

you need to do this, there is not a variable named variable

also, suggestion, use strict equality/inequality === and !==

1 Like
if (prop != "tracks") {
}

that’s half of it, not the whole condition

also, use strict equality === and inequality !== instead of those you are using

1 Like
if (prop !=== "tracks" && value !=== "") {
}

edit:


if (prop !== "tracks" && value !== "") {
}

!=== is not a valid operator

1 Like

now, the action

what does this mean? what do you need to change?

1 Like

I don’t understand that one.

what do you not understand?

there is “update or set”

"album’s prop"

and value

1 Like

I don’t know how to update or set.

please review previous challenges

Updating object properties

1 Like
object[id] = value;

edit:

object[id][prop] === value

look at collection, you are overwriting a whole object like that

and you are not using prop

1 Like