These are chat archives for FreeCodeCamp/HelpJavaScript

1st
Jan 2019
Kelechi Chinaka
@ke1echi
Jan 01 00:18
Happy New Year :dancer:
BP
@bgq007
Jan 01 00:46

When you are updating state in React, how do you make sure you are keeping all the state if you are just changing one thing? Example….

this.state = { isLoggedIn: true, firstName: “Bob” }

and then I want to toggle isLoggedIn via a this.handleChange() method… If I target just the isLoggedIn will I lose the firstName?

Tiago Correia
@tiagocorreiaalmeida
Jan 01 00:55
You use setState, it only changes the properties you updat
BP
@bgq007
Jan 01 01:05
@tiagocorreiaalmeida I forgot to mention setstate but I was referring to that. So when we use setstate and only mention one piece of the state object the rest remains?
Pagnito
@Pagnito
Jan 01 01:41

im appending

<div onclick="addMovie()" class="plusBtn"></div>
and i have a function addMovie(e){
console.log(e)
}

but e is undefined

im using innerHTML to append the divs, so i feel like that has somethin to do wit it
even tho even u inspect the element it has the event handler with event as an argument
tundeiness
@tundeiness
Jan 01 01:50
@padunk Thanks!! Happy new year!
Dhaval Vira
@dhavalveera
Jan 01 01:54
Happy New Year everyone
Pagnito
@Pagnito
Jan 01 02:05
figured it out
Kwek[WL]
@kwekwl
Jan 01 09:48
hi I have an issue with the Record Collection problem
var collection = {
    "2548": {
      "album": "Slippery When Wet",
      "artist": "Bon Jovi",
      "tracks": [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    "2468": {
      "album": "1999",
      "artist": "Prince",
      "tracks": [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    "1245": {
      "artist": "Robert Palmer",
      "tracks": [ ]
    },
    "5439": {
      "album": "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

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

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
my solution doesnt past 3 of the tests, any ideas why?
Tiago Correia
@tiagocorreiaalmeida
Jan 01 11:00
@bgq007 yeah indeed
alpox
@alpox
Jan 01 11:08
@kwekwl you dont seem to handle the basic case of normal properties with a defined value. Also, you set the tracks prop wrongly. If you set it to [] and then to value, the value will override the [] and you wont have an array. You were probably going for = [value]
Idowu Wasiu
@Hoxtygen
Jan 01 13:06
hello people, happy new year to you all
need a lil present from you all for this new year
I'm planning on a comment system and I have no idea how to go about it
there will be three categories of users; normal users, moderators and admins. All have varying privileges
I'm planning on having four classes; users, moderators , admins and comments
How do I connect users class to comments class such that I can say a certain user made such comment?
BP
@bgq007
Jan 01 13:21
@tiagocorreiaalmeida Ok. Thanks. I haven’t started trying things on my own. Watching those videos Ive mentioned before and I noticed one guy talking about keeping this in mind and another hasn’t mentioned it at all. So, wasn’t sure what the difference was.
Ankur sharma
@ankur1163
Jan 01 18:13
anyone here who can help me with react spring?
Pagnito
@Pagnito
Jan 01 19:29
hey anyone here can help me with connecting to sql gui
i think i figured it out
tundeiness
@tundeiness
Jan 01 20:07
Hi guys. Happy new year you all. So I still need some push to completing my marked react previewer but I have been battling with making sure the input outputs well in the previewer using the proper formatting text like \n and \r but so far it has not been totally successful. Most of the text input I want to set on a newline does not work even if I set it on a new line with \n and this has been frustrating. I have been looking for documentations to read to achieve near perfect formatting but I haven't found any . At the moment I need guide on properly formatting the text in my editor so that it can appear well as it should in the previewer. Here is my codepen on the work so far: https://codepen.io/highness/pen/ebNYVX?editors=0010 looking forward to responses. thanks.
Spyrantis Theodoros
@thodorisanta
Jan 01 20:50

function Book() { ...} let book1 = new Book()

function Book() { ...} let book1 = Book()

Above i declare an object with two way. First i use the new keyword and in the second one i dont. And if my understanding is correct, then the only difference in the two above is that in the first one the constructor of book1 will be `Book() and in the second one the constructor will be assigned to Object(). Am i correct? Or is there another reason we need the new keyword?

Markus Kiili
@Masd925
Jan 01 21:34
@thodorisanta On the first line, you are declaring a function and using it as a constructor to make an object, that you assign to a variable. On the second line, you are declaring a function and assigning its return value to a variable.
That return value could of course be an object, so that second line would also be generating an object, but with a factory function.
Pagnito
@Pagnito
Jan 01 22:28
hey im using this to check if user exists but it keeps returnign empty array even tho that user exists
db.transaction(function(trx){
      trx('users').where('email', email).then(res => {
          console.log(res)
     })
})
im using knex
oh it seems to work with other queries, i dunno why it wont work with email
oh i got it, i saved it wrong in the databse
Spyrantis Theodoros
@thodorisanta
Jan 01 23:17
@Masd925 so at the end of the day what is the main purpose of new if i can do the same thing without it
Pagnito
@Pagnito
Jan 01 23:33
is it a standard with sql to name column names in capitals?
Idowu Wasiu
@Hoxtygen
Jan 01 23:35
@Pagnito my little experience with postgresql shows all are converted to lowercase
Pagnito
@Pagnito
Jan 01 23:36
@Hoxtygen oh i see, thats why it didnt recognize my userName query
Idowu Wasiu
@Hoxtygen
Jan 01 23:37
@Pagnito I learnt the hard way too
Pagnito
@Pagnito
Jan 01 23:37
@Hoxtygen lol
Idowu Wasiu
@Hoxtygen
Jan 01 23:38
@Pagnito check the db to see which case those columns are
Pagnito
@Pagnito
Jan 01 23:39
in db they are shown userName, but it converts my queries to username
ima recreate my tables
Idowu Wasiu
@Hoxtygen
Jan 01 23:39
@Pagnito okay. I guess your query is working now
Pagnito
@Pagnito
Jan 01 23:40
yea
Idowu Wasiu
@Hoxtygen
Jan 01 23:40
@Pagnito why recreate?
Pagnito
@Pagnito
Jan 01 23:40
cuz i need to rename userName column to username
cuz it doesnt find userName, since the query will always convert to lowercase
Idowu Wasiu
@Hoxtygen
Jan 01 23:41
@Pagnito you can alter column names instead of recreating
Pagnito
@Pagnito
Jan 01 23:41
oh true