Basic JavaScript: Record Collection : alternative for NOT

Tell us what’s happening:
is there any good alernative for the NOT opperator in JS?
or .not for those using jquery

Your code so far


// Setup
var collection = {
 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'
 }
};

// Only change code below this line
function updateRecords(object, id, prop, value) {
 if (prop NOT in tracks && value != ""){
return prop = value;
 }else if (prop in tracks || tracks NOT in album){
 return "" += value;
 } else if (prop in tracks || value != ""){
 return value.pop.tracks
 }else (value = """) {
return delete prop
 }
 


 return object;
}

updateRecords(collection, 5439, 'artist', 'ABBA');

Your browser information:

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

Challenge: Record Collection

Link to the challenge:

Tell us what’s happening:

Can’t solve this one
also is there an alternative for the NOT operator ?

In jQuery I could use .not
the
prop != track
just doesn’t seem right to me

Your code so far


// Setup
var collection = {
 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'
 }
};

// Only change code below this line
function updateRecords(object, id, prop, value) {
 if (prop !=  tracks && value != ""){
return prop = value;
 }else if (prop in tracks || tracks != album){
 return "" += value;
 } else if (prop in tracks || value != ""){
 return value.pop.tracks
 }else (value = """) {
return delete prop
 }
 


 return object;
}

updateRecords(collection, 5439, 'artist', 'ABBA');

Your browser information:

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

Challenge: Record Collection

Link to the challenge:

putting your latest code in the editor the first thing I see is this:

SyntaxError: unknown: Invalid left-hand side in assignment expression (27:8)

  25 | return prop = value;
  26 |  }else if (prop in tracks || tracks != album){
> 27 |  return "" += value;
     |         ^
  28 |  } else if (prop in tracks || value != ""){
  29 |  return value.pop.tracks
  30 |  }else (value = """) {

the only thing you can have to the left side fo an assignmetn operator is a variable, here you have ""

also, one of the challenge instructions is to always return the whole object, which is done in the last line of the function, all other return statements shuld be deleted


the != operator is perfectly fine JavaScript, you can’t use jQuery here. The issue you have on this line is that you do not have a variable track anywhere, so it’s undefined - you want to use a string there, "tracks"

2 Likes

ieahleenLeader

3h

Please do not create duplicate topics for the same challenge/project question(s). This duplicate topic has been unlisted and merged with the other topic you already have on this challenge.

Thank you.

Sorry forgot I already had this one XD

You seem to be struggling with syntax. I would review the introductory lessons on variables, loops, if statements, binary operators, and objects.

No you could not, that’s a function for filtering a group of DOM elements. It has nothing to do with a boolean NOT operator, which is a core basic piece of the language.

Well, yes, it doesn’t seem right because it isn’t:

  • it’s tracks not track,
  • there isn’t a variable called tracks anyway, because
  • keys of objects are strings, so it should be "tracks"

These are extremely basic syntax errors you’re making. If you haven’t grasped the very, very basics of JS syntax after the year or so you’ve been trying to do this, and you want to learn this stuff, maybe you need to look at some other teaching methods (books? video courses?) because nothing seems to be sticking here. You’re just repeating errors you made months and months ago on the same very basic tasks.

1 Like

I hate you and love for saying and pointing this one out.
And after doing some reflecting I came to the conclusion.
Yes you are absolutely right. FCC course just does not work for me but, at the same time, I started to doubt other materials as well. I just don’t want to make the same mistake again

1 Like