These are chat archives for FreeCodeCamp/HelpJavaScript

5th
Apr 2018
Nate Mallison
@NJM8
Apr 05 2018 00:43
thanks @gulsvi I never knew that
CamperBot
@camperbot
Apr 05 2018 00:43
njm8 sends brownie points to @gulsvi :sparkles: :thumbsup: :sparkles:
:star2: 2695 | @gulsvi |http://www.freecodecamp.org/gulsvi
Brad
@bradtaniguchi
Apr 05 2018 00:47
Omg I was wondering why nothing was showing in an if statement.... Obviously its because the if statement is false DUH -_-
Rahsheen Porter
@rahsheen
Apr 05 2018 02:29
fatality
Ayush Bahuguna
@relentless-coder
Apr 05 2018 04:16
my firefox browser console is acting weird
name = 'AYush';
const nObj = {
    name: 'Bahuguna'
}
function printName(){
  console.log(this.name)
}
printName();
printName.call(nObj)
when I simply call printName() it doesn't print anything
Ken Haduch
@khaduch
Apr 05 2018 04:17
@relentless-coder - how is it acting? What is this pointing to in your printName function??
Ayush Bahuguna
@relentless-coder
Apr 05 2018 04:18
@khaduch that's my implicit question. Wasn't this supposed to point to the global object?
Rahsheen Porter
@rahsheen
Apr 05 2018 04:18
Nope.
It's inside a function.
Try an arrow function instead and you may get the result you were looking for...
Ayush Bahuguna
@relentless-coder
Apr 05 2018 04:19
yeah, but it's invoked in the global scope? Isn't global scope part of lexical scope for printName? Also, I ran the same code in jsfiddle and it worked as I expected
@rahsheen
my understanding is that, this also depends upon the execution context. so when I hard bind the execution context to the nObj it printed it's value
@khaduch
Claudio Restifo
@Marmiz
Apr 05 2018 04:21
@relentless-coder function bind this context in JS, that's why your name won't show up.
The fact that it works in JSfiddle may be due to the fact that is run in strict mode
Ayush Bahuguna
@relentless-coder
Apr 05 2018 04:22
@Marmiz ran the code in node environment without specifying use strict and again worked as expected
Henry
@GitHub-Henry
Apr 05 2018 04:23
@revisualize not sure why, but was thinking about your zeros and thought about a regex version, it's based on kyle's solution
function removeZeros(array) {
  const head = [];
  const tail = [];
  const zero = /^(0|'0')$/i;
  for (const e of array) {
    if (zero.test(e)) {
      tail[tail.length] = e
    } else {
      head[head.length] = e
    }
  }
  return [...head, ...tail]
}
console.log(removeZeros([0, 1, 2, 0, 3]));
Ayush Bahuguna
@relentless-coder
Apr 05 2018 04:23
again, according to my understanding, this is evaluated at the time of execution
Rahsheen Porter
@rahsheen
Apr 05 2018 04:24
It "works" but I don't see why.
Claudio Restifo
@Marmiz
Apr 05 2018 04:24
@relentless-coder be carefoul because browsers and node "evaluates" this differently.
In a browser this== windows in node this == global
Rahsheen Porter
@rahsheen
Apr 05 2018 04:25
this is crazy
Ayush Bahuguna
@relentless-coder
Apr 05 2018 04:25
okay, in my code, what would you say about the scope in which the variable name exists? @rahsheen @Marmiz
Ken Haduch
@khaduch
Apr 05 2018 04:26
@relentless-coder - I ran it in firefox on my computer and it works... it prints AYush and Bahuguna in the console
Ayush Bahuguna
@relentless-coder
Apr 05 2018 04:26
@khaduch what? Does my browser version have a bug? It sure is a developer edition.
@khaduch okay, well, at least my understanding of scope is good. I'll try it out in a stable version of firefox
Claudio Restifo
@Marmiz
Apr 05 2018 04:28

@relentless-coder it's pretty hard to tell because you are not calling this directly in the function.
You are calling it from a console.log which will determine the this context again.

p.s. good ol' times when you saw a console.log.bind(console)

Ken Haduch
@khaduch
Apr 05 2018 04:29
@relentless-coder - I also added a console.log(this); and for the first call to your function, it is displaying the Window object, on Opera I saw a name variable, I don't see it in FireFox, but it is printing your name.
Ayush Bahuguna
@relentless-coder
Apr 05 2018 04:30
@Marmiz but how would console.log change the execution context?
@khaduch yes, that's what I expected.
Rahsheen Porter
@rahsheen
Apr 05 2018 04:33
I feel like we all need to go back and read YDKJS :joy:
Ayush Bahuguna
@relentless-coder
Apr 05 2018 04:33
although, in my version of firefox, it prints window.name as empty
Claudio Restifo
@Marmiz
Apr 05 2018 04:33

@relentless-coder it should not. But it's a point worth of considering.
In this example:

name = "Test";

function printName(){
  console.log(this.name)
}

function printN(){
  return this.name
}

printName() // log 'Test'
printN() // return 'Test'

won't change anything

Ayush Bahuguna
@relentless-coder
Apr 05 2018 04:34
yes, because the variable name exists in the outermost scope
@Marmiz
@rahsheen already have. and also have sat through Kyle Simpson's course on Advanced JS. For a second, i doubted even him too
Claudio Restifo
@Marmiz
Apr 05 2018 04:34
@relentless-coder it's more because this refers to the window object (subtle but a big difference)
Rahsheen Porter
@rahsheen
Apr 05 2018 04:35
So unless you are explicitly setting window.name you don't truly know what your "outermost scope" even is, I guess.
Ken Haduch
@khaduch
Apr 05 2018 04:37
@relentless-coder - in firefox, looking at the Window object (from the console.log(this), there is a property somewhere way down the list that has the heading [default properties] and if you expand that, you see the variable name with the value AYush - so it's there, it buried inside an object, but I guess it might depend how console.log and the browser look up the values?
Ayush Bahuguna
@relentless-coder
Apr 05 2018 04:38
@rahsheen even if i don't set it explicitly, the javascript code has to be wrapped in a scope for the code execution to work
@khaduch let try it out in an html file. will be back in 5 mins
Claudio Restifo
@Marmiz
Apr 05 2018 04:41
@khaduch mind that Window and window are two different things :)
the first is a function, the second is an object
this refers to the object window not the function Window
(yay for browser's consistency)
Ayush Bahuguna
@relentless-coder
Apr 05 2018 04:42
@khaduch @rahsheen @Marmiz so I first wrote the js code in the head of the html, and it din't print the name. however, when I placed the code in a js file, this time it worked as I expected.
Ken Haduch
@khaduch
Apr 05 2018 04:43
@relentless-coder - okay, I'm going to sign off for now - I hope that I get to see the final outcome of this investigation... good luck, it seems like a bit of a tricky issue to solve!
Ayush Bahuguna
@relentless-coder
Apr 05 2018 04:44
@khaduch yeah me too. I am at work, and have to submit a project tomorrow.
Ken Haduch
@khaduch
Apr 05 2018 04:45
@relentless-coder - good luck with that project, then... and then crazy javascript this and other things... :)
Claudio Restifo
@Marmiz
Apr 05 2018 04:54
@relentless-coder where are you running that html? An online service or is just a text file opened with a browser?
it should not make a difference but sometimes some services blocks access to prevent cross-origin.. especially if the DOM is rendered in an iframe (like most of the services do)
Joseph
@revisualize
Apr 05 2018 05:24
@GitHub-Henry The Codewars challenge states that you can't use a temp array or object. Also, you can't use any array or object methods.
Markus Kiili
@Masd925
Apr 05 2018 05:50
@NJM8 Clean code. Doing the square root trick and storing the found primes and only testing against them would make it more efficient. Yours is still very brute force way. The problem, in real life, with such clean but inefficient code is that someone can turn it into crap because it has poor efficiency.
Morning.
Henry
@GitHub-Henry
Apr 05 2018 06:48
@revisualize would this be acceptable?
function removeZeros(array) {
  let head = '';
  let tail = '';
  const zero = /^(0|'0')$/i;
  for (const e of array) {
    if (zero.test(e)) {
      tail = tail + e + ',';
    } else {
      head = head + e + ',';
    }
  }
  return JSON.parse(`[${head.substring(0, head.length - 1)},${tail.substring(0, tail.length - 1)}]`);
}
Danny Chan
@chandanny
Apr 05 2018 07:28
hello
alpox
@alpox
Apr 05 2018 07:33
@GitHub-Henry I think not. I believe the gist was to do it all on the original array - so the return value and the original array are the same array.
Markus Kiili
@Masd925
Apr 05 2018 07:37
@alpox You are NOT allowed to use any temporary arrays or objects. You are also not allowed to use any Array.prototype or Object.prototype methods. Not sure if he is violating that. Restriction is a bit vaque.
Not sure what they are testing in that regard.
Aditya
@ezioda004
Apr 05 2018 07:42
They dont really test, pretty sure there was a solution with couple of temp arrays, and it was voted by some as "best practice" and "clever solution"
Markus Kiili
@Masd925
Apr 05 2018 08:32
@ezioda004 Also there were some that used array methods.
Aditya
@ezioda004
Apr 05 2018 08:35
@Masd925 Yeah, this can be implemented though. I remember solving some algos at codefights and they wont accept solution until you meet the exact requirements.
Aniculaesei
@Aniculaesei
Apr 05 2018 09:04
Hi guys!Why I can't copy the array?thank you
const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];
let arr2 =[] ;


  arr2 = arr2.push(...arr1); // change this line
Markus Kiili
@Masd925
Apr 05 2018 09:05
@Aniculaesei After let arr2 ; it is not an array. You cannot push there.
Actually its value is undefined and then you arr2.push(...)
Aniculaesei
@Aniculaesei
Apr 05 2018 09:06
this is ok?
Markus Kiili
@Masd925
Apr 05 2018 09:06
@Aniculaesei Yes.
Aniculaesei
@Aniculaesei
Apr 05 2018 09:06
@Masd925 thanks ...but still not working on the chalenge :(
CamperBot
@camperbot
Apr 05 2018 09:06
aniculaesei sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4760 | @masd925 |http://www.freecodecamp.org/masd925
Markus Kiili
@Masd925
Apr 05 2018 09:06
Not sure which lines you are supposed to touch.
Aniculaesei
@Aniculaesei
Apr 05 2018 09:07
it's written what i have to change :(
arr2 = arr2.push(...arr1); // change this line
This i've changed
and the =[] :D
alpox
@alpox
Apr 05 2018 09:08
@Aniculaesei you assign the return value of .push back to arr2 which makes arr2 become a number (The length of the array after the push)
Aditya
@ezioda004
Apr 05 2018 09:08
@Aniculaesei You said copy array? Then it can be done by simply doing arr2 = [...arr1]
Markus Kiili
@Masd925
Apr 05 2018 09:08
@Aniculaesei There are many ways to copy that array.
Aniculaesei
@Aniculaesei
Apr 05 2018 09:09
@Masd925 @ezioda004 @alpox thank you again :D
CamperBot
@camperbot
Apr 05 2018 09:09
aniculaesei sends brownie points to @masd925 and @ezioda004 and @alpox :sparkles: :thumbsup: :sparkles:
api offline
:cookie: 526 | @ezioda004 |http://www.freecodecamp.org/ezioda004
:star2: 1595 | @alpox |http://www.freecodecamp.org/alpox
abraham anak agung
@padunk
Apr 05 2018 09:10
what is polymorphism?
Aniculaesei
@Aniculaesei
Apr 05 2018 09:10
It worked with arr2 = [...arr1]
Markus Kiili
@Masd925
Apr 05 2018 09:10
@Aniculaesei ES5 way would be arr2 = arr1.slice();
Aniculaesei
@Aniculaesei
Apr 05 2018 09:10
@Masd925 I thinks it's easier in es6 with [...arr1]
:(
Markus Kiili
@Masd925
Apr 05 2018 09:11
@padunk There are several types of polymorphism in programming.
Aniculaesei
@Aniculaesei
Apr 05 2018 09:12
thanks again guys.....I have a question....you have solved all the algorithms?For me are so hard :(
How did you understand them?
It's a way to break them in steps or something like this?
alpox
@alpox
Apr 05 2018 09:12
@Aniculaesei There is always a way to break problems down into small pieces which are solvable
abraham anak agung
@padunk
Apr 05 2018 09:13
@Masd925 what is the types of it? i don't quite understand the word btw.
Markus Kiili
@Masd925
Apr 05 2018 09:13
@Aniculaesei First you need to think about how to solve it in steps (the algorithm). Use paper for this in more complex ones. Then implement it in the program.
Aniculaesei
@Aniculaesei
Apr 05 2018 09:14
@Masd925 @alpox you solved all of them? :(
Markus Kiili
@Masd925
Apr 05 2018 09:14
@Aniculaesei Yes.
alpox
@alpox
Apr 05 2018 09:14
@Aniculaesei Same
Aniculaesei
@Aniculaesei
Apr 05 2018 09:14
:(((...can I borrow your minds please? :))))
Aditya
@ezioda004
Apr 05 2018 09:14
@Aniculaesei I second what @alpox and @Masd925 said, writing pseudo code is a good step
Markus Kiili
@Masd925
Apr 05 2018 09:15
@Aniculaesei If you just read the problem description and start to make code, the screen will hypnotize you to make a bad algorithm.
Aniculaesei
@Aniculaesei
Apr 05 2018 09:18
@Masd925 @ezioda004 @alpox thanks again.... :)
CamperBot
@camperbot
Apr 05 2018 09:18
aniculaesei sends brownie points to @masd925 and @ezioda004 and @alpox :sparkles: :thumbsup: :sparkles:
api offline
api offline
api offline
Markus Kiili
@Masd925
Apr 05 2018 09:20
@padunk Function overloading, generics, and subtyping are all forms of polymorphism.
Aniculaesei
@Aniculaesei
Apr 05 2018 11:22
Theese chalenges breakes me down :((((((((((((((((((((((((
@bibek22 hellooooooooo :D
Aniculaesei
@Aniculaesei
Apr 05 2018 11:28
function getLength(str) {
  "use strict";

  // change code below this line
  const {length:len} = str.length; // change this
  // change code above this line

  return len; // you must assign length to len in line

}

console.log(getLength('FreeCodeCamp'));
@Masd925 hi again :)
Markus Kiili
@Masd925
Apr 05 2018 11:28
@Aniculaesei Hi.
Aniculaesei
@Aniculaesei
Apr 05 2018 11:29
Can you give me alittle help:)
please....
:)
Markus Kiili
@Masd925
Apr 05 2018 11:29
@Aniculaesei What is the challenge name?
Aniculaesei
@Aniculaesei
Apr 05 2018 11:29
ES6: Use Destructuring Assignment to Assign Variables from Objects
I think the first length is undefined,right?
Markus Kiili
@Masd925
Apr 05 2018 11:32
@Aniculaesei const {length:len} = str; would assign str.length to len. Is that what they wan't?
Aniculaesei
@Aniculaesei
Apr 05 2018 11:32
yes :)
@Masd925 but why =str?and not str.length????
Markus Kiili
@Masd925
Apr 05 2018 11:35
@Aniculaesei That destructuring looks for property key length on the object on the right hand side. str is a primitive string value and it is autoboxed into String object and the length property is gotten and assigned to len.
Same thing here with an object literal:
const {length: len} = {length:12};

console.log(len); // 12
In earlier example we have a string on the right hand side.
Aniculaesei
@Aniculaesei
Apr 05 2018 11:38
I ....think I got it :)
@Masd925 thanks again :)
CamperBot
@camperbot
Apr 05 2018 11:38
aniculaesei sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4762 | @masd925 |http://www.freecodecamp.org/masd925
Markus Kiili
@Masd925
Apr 05 2018 11:39
@Aniculaesei So {length:12} is an object literal and {length: len} is a pattern that defines what property values are assigned to what variables.
const there also declares those variables used.
Aniculaesei
@Aniculaesei
Apr 05 2018 11:40
I understand now..thank you :)
@Masd925 !!!I own you a cofee !! :)
Markus Kiili
@Masd925
Apr 05 2018 11:41
@Aniculaesei Good. That is my only vice :coffee:
Aniculaesei
@Aniculaesei
Apr 05 2018 11:42
And Javascript :)no?
Markus Kiili
@Masd925
Apr 05 2018 11:44
@Aniculaesei You do have a point there.
Henry
@GitHub-Henry
Apr 05 2018 11:45
@alpox since i never read the challenge i didn't read the part about solution must use original array, oh well. i based my solution on @revisualize 's comment above :point_up: April 4, 2018 10:24 PM about don't use a temp array or temp object, and don't use array objects or methods, c'est la vie.
Aniculaesei
@Aniculaesei
Apr 05 2018 11:45
@Masd925 you went to university?or you learn at home? :)
Markus Kiili
@Masd925
Apr 05 2018 11:46
@Aniculaesei I have couple of degrees. Bachelors at business ICT something (mostly software development).
Aniculaesei
@Aniculaesei
Apr 05 2018 11:47
@Masd925 pfffff.....thats ok...I strugle to learn at home....but it's extremly hard to learn alone :(
@Masd925 I am a musician :)
@Masd925 I play in a professional orchestra :)
Markus Kiili
@Masd925
Apr 05 2018 11:49
@Aniculaesei Good. You can just play a happy tune...and code some more.
Aniculaesei
@Aniculaesei
Apr 05 2018 11:50
I have my horn here :D
@Masd925 It's hard because i have to split my schedual from orchestra playing,individual practicing and...Javascript :D
Markus Kiili
@Masd925
Apr 05 2018 11:53
@Aniculaesei Most people have such problems nowadays.
Aniculaesei
@Aniculaesei
Apr 05 2018 11:54
:)
@Masd925 Thanks again :)
CamperBot
@camperbot
Apr 05 2018 11:55
aniculaesei sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
api offline
Aniculaesei
@Aniculaesei
Apr 05 2018 12:09
What is wrong woth this code? :(

const LOCAL_FORECAST = {
  today: { min: 72, max: 83 },
  tomorrow: { min: 73.3, max: 84.6 }
};

function getMaxOfTmrw(forecast) {
  "use strict";
  // change code below this line
  const {tomorrow:{max:maxOfTomorrow}} = LOCAL_FORECAST; // change this line
  // change code above this line
  return maxOfTomorrow;
}

console.log(getMaxOfTmrw(LOCAL_FORECAST)); // should be 84.6
Markus Kiili
@Masd925
Apr 05 2018 12:11
@Aniculaesei You should be using the forecast parameter inside the function, not LOCAL_FORECAST.
The function needs to work on any forecast object passed.
When the function call is made and function is being executed, the parameter forecast holds the passed object.
Aniculaesei
@Aniculaesei
Apr 05 2018 12:12
:(
I can't resolve any of them alone...I will die!!!I take my horn back :))))
@Masd925 thanks again
CamperBot
@camperbot
Apr 05 2018 12:13
aniculaesei sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
api offline
Chris
@ConnectCodes
Apr 05 2018 12:55
I am stuck on Exact Change challenge for few weeks now. Can anyone help me? I think while() loop need another condition. I suppose to get [["TWENTY", 60.00], ["TEN", 20.00], ["FIVE", 15.00], ["ONE", 1.00], ["QUARTER", 0.50], ["DIME", 0.20], ["PENNY", 0.04]] but I get [["TWENTY", 60.00], ["TEN", 20.00], ["FIVE", 20.00]] I have few console.log but stll no luck. Any ideas?
https://codepen.io/Codeconnect/pen/dZQygY
Stephen James
@sjames1958gm
Apr 05 2018 13:29
@ConnectCodes When you create your currencyAmount you should be able to fill in the holes with zeros.
You might need another array with all the currency names as a input to map
@ConnectCodes ["Twenty, "Ten", "Five", ...].map((name) { });
Danny Chan
@chandanny
Apr 05 2018 13:30
is braintreepayments good?
Chris
@ConnectCodes
Apr 05 2018 13:34
@sjames1958gm Okay regarding currency names in line 65 I have result.push([cid[i][0],local/100]); cid[i] basically does the same thing right?
Chris
@ConnectCodes
Apr 05 2018 13:43

@sjames1958gm I think my probem is here I get [“FIVE”, 20] but I suppose to get [“FIVE”, 15] I have two while loops with

while(changeCent > total){
        var local = 0;
        while(currencyAmount[i] > local){
            if(changeCent < total) {
                break;  
            }
            local += inc[i];
            total += inc[i];

      //console.log("total:", total, "local:",local,"inc:",inc[i], "i:",i);
            }
            result.push([cid[i][0],local/100]);
            i--;
        }
    return result;

But my conditions are wrong, because they don’t reduce i— when they suppose to

Stephen James
@sjames1958gm
Apr 05 2018 13:43
I misunderstood your issue
Tiago Correia
@tiagocorreiaalmeida
Apr 05 2018 13:44
hello everyone
Stephen James
@sjames1958gm
Apr 05 2018 13:45
@ConnectCodes should that test be currencyAmount[i] > local
Chris
@ConnectCodes
Apr 05 2018 13:46
@sjames1958gm are you referrering to upper while? because it is currencyAmount[i] > local
Stephen James
@sjames1958gm
Apr 05 2018 13:47
@ConnectCodes Both. But not sure if that is your problem
Chris
@ConnectCodes
Apr 05 2018 13:48
@sjames1958gm the upper is changeCent > total so it extracts money untill it is equal to change due
@sjames1958gm the inner is currencyAmount[i] > local to extract untill there is no more of that currency (before moving to the next currency)
Stephen James
@sjames1958gm
Apr 05 2018 13:52
@ConnectCodes if local is equal to currency amount shouldn't the loop continue?
Chris
@ConnectCodes
Apr 05 2018 13:55
@sjames1958gm if local is equal to currency loop should stop actually. I changed it to currencyAmount[i] >= local but now results are way off
Tiago Correia
@tiagocorreiaalmeida
Apr 05 2018 13:55
Need a little bit of help I got a server builted on node that when I start I got a function that's called after the database connection being setted, that function check's if the super admin exists on the database if not creates
require("dotenv").config();

const env = process.env.NODE_ENV || "development";

if (env === "development") {
    process.env.PUBLIC_DB_URL = process.env.DB_URL;
} else if (env === "test") {
    process.env.port = 5000;
    process.env.PUBLIC_DB_URL = process.env.TEST_DB_URL;
}

import express from "express";
import passport from "passport";
import session from "express-session";

import startDatabase from "./config/mongoose";
import user from "./routes/user";
import passportConfig from "./controllers/passport";
import errorHandler from "./utils/errorHandler";
import setAdmin from "./utils/adminSetup";
import department from "./routes/department";

startDatabase();
setAdmin();
import encryptIt from "../utils/encrypIt";
import User from "../models/user";

export default async () => {
    try {
        const adminExists = await User.findOne({ email: process.env.ADMIN_EMAIL });
        if (!adminExists) {
            await User.create({
                email: process.env.ADMIN_EMAIL,
                password: encryptIt(process.env.ADMIN_PASSWORD),
                name: "admin",
                permissions: 0,
                isActive: true,
                firstLink: false
            });
            console.log("Admin account created!");
        }
    } catch (e) {
        console.log("Error creating admin:", e);
    }
}
the thing going goes perfectly on production but when doing unity tests, the tests run before I have the time to define the admin, can you think of any work around?
Stephen James
@sjames1958gm
Apr 05 2018 13:56
@ConnectCodes I see now. you are adding inside the loop so = is not correct.
Tiago Correia
@tiagocorreiaalmeida
Apr 05 2018 13:57
maybe force the function somewhere else other than in the app it self? so I can make an async call on the tests sides before they run? not sure what's better
Chris
@ConnectCodes
Apr 05 2018 14:07
@sjames1958gm think i made this too complicated :/ Maybe I need more conditions?
Stephen James
@sjames1958gm
Apr 05 2018 14:20
@ConnectCodes Well it is sort of how I did it.
I think while(currencyAmount[i] > local){ this test isn't sufficent. You never check if the remaining change needed is >= to inc[i]
Chris
@ConnectCodes
Apr 05 2018 14:28
@sjames1958gm > You never check if the remaining change needed is >= to inc[i]
What do you mean by remaining change needed? or I need to create it something like ChangeCent - total?
Stephen James
@sjames1958gm
Apr 05 2018 14:59
@ConnectCodes Yes, something like that.
My code was like yours, but I subtracted to 0
Jason Luboff
@JLuboff
Apr 05 2018 15:12
:wave:
Tiago Correia
@tiagocorreiaalmeida
Apr 05 2018 15:17
hey there
@JLuboff
Derrick Hsiao
@DerrickHsiao
Apr 05 2018 15:19
How can I pass this challenge?
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
  var result = "";

  return result;
}

wordBlanks("dog", "big", "ran", "quickly");
Tiago Correia
@tiagocorreiaalmeida
Apr 05 2018 15:19
can you send the challenge link?
Jason Luboff
@JLuboff
Apr 05 2018 15:21
@tiagocorreiaalmeida Whats up
alpox
@alpox
Apr 05 2018 15:21
:wave:
Jason Luboff
@JLuboff
Apr 05 2018 15:21
@DerrickHsiao You need to use string concatenation to combine all of the parameters (myNoun, myAdjective, etc) into a string that is assigned to result
@alpox :wave:
Tiago Correia
@tiagocorreiaalmeida
Apr 05 2018 15:22
nothing too special just rolling my head on the keyboard to write tests :D , how about you?
Jason Luboff
@JLuboff
Apr 05 2018 15:22
Just got into work. Figuring out what to work on right now
Tiago Correia
@tiagocorreiaalmeida
Apr 05 2018 15:23
werent you doing a project to replace a previous one you had there using php? maybe I got confused
Jason Luboff
@JLuboff
Apr 05 2018 15:24
I'm currently working on a project for work that will be used for intitating facility changes (essentially a request that then needs to be approved, action items to do, etc)
Our intranet site uses PHP which I hate..but.. I don't think I'll be changing it anytime soon
Kudzu
@czhower
Apr 05 2018 15:25
Not disagreeing, but what do you hate about PHP?
Jason Luboff
@JLuboff
Apr 05 2018 15:27
I just don't care for it. It's given me trouble more than once. You can fuck up the php.ini file and php will still act as if its working but its not
Kudzu
@czhower
Apr 05 2018 15:35
that sucks, but that overall is a pretty minor point given the scope of what a language includes.
Jason Luboff
@JLuboff
Apr 05 2018 15:38
I guess
Chris
@ConnectCodes
Apr 05 2018 15:41
@sjames1958gm Thank you, it makes sense but what do you mean by subtracting to 0 ?
CamperBot
@camperbot
Apr 05 2018 15:41
connectcodes sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 9165 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
Kudzu
@czhower
Apr 05 2018 15:41
Is that the only thing that makes you dislike PHP?
alpox
@alpox
Apr 05 2018 15:42
I just mostly dislike its look and feel :shrug:
Nazar
@IsaakNazar
Apr 05 2018 15:43
@czhower hey
alpox
@alpox
Apr 05 2018 15:43
@IsaakNazar Relative
Nazar
@IsaakNazar
Apr 05 2018 15:44
when user submits empty form or inputs the same title name there should be error message, but it doesnt show up.
for error message is responsible handleAddRecipe function
codepen
Kudzu
@czhower
Apr 05 2018 15:45
@IsaakNazar Hello. Were you in the old purged FCC room too?
Nazar
@IsaakNazar
Apr 05 2018 15:48
@czhower yes!
Kudzu
@czhower
Apr 05 2018 15:49
I guess we are here now... hopefully without some of the trolls, but unfortunately a bit stodgy as well.
Tiago Correia
@tiagocorreiaalmeida
Apr 05 2018 15:53
@czhower php its the nickelback from programming languages :D
alpox
@alpox
Apr 05 2018 15:54
@IsaakNazar I'm a bit confused about your handleAddRecipe function. Shouldn't it just add a new recipe to the list of already existing recipes (If no error occurs)?
At the moment you do a .map over the existing recipes and return errors if something is not set (This means you do not error test on the input from the modal and you just throw away all error messages directly as you do not assign the .map call to anything.
Kudzu
@czhower
Apr 05 2018 15:56
Believe me, Im not arguing in favor of PHP. Just interested in why individual people don't like it.
I dont use PHP much but do use it some for WordPress and a few other things that require PHP for extensions.
Its actually a decent scripting language, but I would hate to use it for anyting large.
Nazar
@IsaakNazar
Apr 05 2018 16:02
@alpox should I create another function that will check error test? Maybe I should make it inside RecipeModal ?
alpox
@alpox
Apr 05 2018 16:14
@IsaakNazar you can do it there, but not like this :D
You have to overthink the logic
Nazar
@IsaakNazar
Apr 05 2018 16:15
@alpox ok thanx
Stephen James
@sjames1958gm
Apr 05 2018 16:16
@ConnectCodes I started with the total change and subtracted from that for each denomination until I reached zero change left to give out.
Nazar
@IsaakNazar
Apr 05 2018 16:18
@alpox I've got one more question
alpox
@alpox
Apr 05 2018 16:23
@IsaakNazar Shoot
Nazar
@IsaakNazar
Apr 05 2018 16:25
after pressing save button or enter inside Modal how to close it (Modal). cant figure out @alpox
alpox
@alpox
Apr 05 2018 16:31
@IsaakNazar You can this.props.handleCloseModal() inside of handleInsertRecipe
Chris
@ConnectCodes
Apr 05 2018 16:32
@sjames1958gm Cool similiar to mine. Finally it worked :) just one last thing currency is suppose to have two decimal places like 60.00. I did (local/100).toFixed(2) which works but I get result in string and I need it in number. Reading about it on stackoverflow makes me more confused. I tried Math.floor to change the string to number but it removes the decimal points. Any ideas?
Nazar
@IsaakNazar
Apr 05 2018 16:33
@alpox I feel little dumb myself :smile: thanx
CamperBot
@camperbot
Apr 05 2018 16:33
isaaknazar sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1596 | @alpox |http://www.freecodecamp.org/alpox
alpox
@alpox
Apr 05 2018 16:33
@IsaakNazar np
Stephen James
@sjames1958gm
Apr 05 2018 16:49
@ConnectCodes Can you use toFloat on the the string after toFixed
Nazar
@IsaakNazar
Apr 05 2018 16:56

what is the difference ?
code below works perfectly.

<button onClick={() => this.props.handleRemoveRecipe(this.props.ingredientContent)}>Delete</button>

code below throws an error

<button onClick={this.props.handleRemoveRecipe(this.props.ingredientContent)}>Delete</button>
alpox
@alpox
Apr 05 2018 17:03
@IsaakNazar The upper one passes a function as attribute to onClick which can then be called when a click event occurrs.
The lower one calls the function IMMEDIATELY and passes its RETURN VALUE as attribute to onClick which is likely no function and cannot be called.
Nazar
@IsaakNazar
Apr 05 2018 17:04
@alpox now it make sense, thanx :+1:
CamperBot
@camperbot
Apr 05 2018 17:04
isaaknazar sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
api offline
Aniculaesei
@Aniculaesei
Apr 05 2018 17:16
Hello!Did you finish the beta fcc "Import a Default Export"?
Ken Haduch
@khaduch
Apr 05 2018 17:17
@ConnectCodes - I did all of my calculations using integer values (multiplied all incoming amounts by 100, to keep it all in pennies) and then at the end used Number.parseFloat((changeTotal/100).toPrecision(2)) to get the final amount for the individual denominations of change.
@Aniculaesei - no, but what's your question? I can find the exercise and try it!
Aniculaesei
@Aniculaesei
Apr 05 2018 17:18
@khaduch I cant finish it
My code is:
import substract from "math_functions";
Ken Haduch
@khaduch
Apr 05 2018 17:18
@Aniculaesei - "subtract" is not spelled correctly?
Aniculaesei
@Aniculaesei
Apr 05 2018 17:18
maybe it 's a bug..maybe not :)))
@khaduch sorry
my bug :))))
import subtract from "math_functions";
@khaduch thank you :)
CamperBot
@camperbot
Apr 05 2018 17:20
aniculaesei sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3852 | @khaduch |http://www.freecodecamp.org/khaduch
Ken Haduch
@khaduch
Apr 05 2018 17:20
then it works?
Aniculaesei
@Aniculaesei
Apr 05 2018 17:20
@khaduch yesss
I was the probleb :)
"subtract"
Ken Haduch
@khaduch
Apr 05 2018 17:20
always happy to help - and sometimes just another set of eyes does it... :)
Aniculaesei
@Aniculaesei
Apr 05 2018 17:21
Thank you for your help :)
Ken Haduch
@khaduch
Apr 05 2018 17:21
You're welcome - any time!
Conor Murphy
@cmurphy580
Apr 05 2018 18:44
Has anyone worked with firebase before?
Brad
@bradtaniguchi
Apr 05 2018 18:49
@cmurphy580 Yea I have been using firebase lately for my side project
Conor Murphy
@cmurphy580
Apr 05 2018 18:54
@bradtaniguchi do you store data for a particular user, so when they log in it the data of another user doesn't leak into the other user's?
Brad
@bradtaniguchi
Apr 05 2018 18:55
@cmurphy580 Not sure what you mean by leak to another user
Conor Murphy
@cmurphy580
Apr 05 2018 18:57

I have two users. There's different data for each user saved. When I log back into one of the users the data from the other replaces the data for that user.
here is what i've written:

  componentWillMount() {
    const { todays_news } = this.props;
    if (!todays_news) {
      this.props.fetchNews();
    }
    const { userID } = this.props.params;
    const storeRef = base.database().ref(userID);
    storeRef.once('value', (snapshot) => {
      const data = snapshot.val() || {};
      console.log(data);
      if (data) {
        this.setState({
          news: data.news || todays_news
        });
      } else {
        this.setState({
          news: todays_news
        });
      }
    });
    console.log(this.state.news);
  }
  componentDidMount() {
    const { userID } = this.props.params;
    this.ref = base.syncState(`${userID}/news`,
    {
        context: this,
        state: 'news'
    });
  }
  componentDidUpdate() {
    const { todays_news, provider_news, term_results } = this.props;
    const active_articles = provider_news === null && term_results === null ?
                            todays_news:
                            provider_news !== null && term_results === null ?
                            provider_news.news :
                            provider_news === null && term_results !== null ?
                            term_results.news :
                            term_results !== null && provider_news !== null &&
                            term_results.timestamp > provider_news.timestamp ?
                            term_results.news :
                            provider_news.news;

    //console.log(active_articles);
    this.setState({ news: active_articles });
  }
  componentWillUnmount() {
    console.log('umnout')
    base.removeBinding(this.ref); //memory leaking
    this.setState({ news: null });
  }

@bradtaniguchi

Brad
@bradtaniguchi
Apr 05 2018 18:57
holy code batman
Thats's to much business logic unfortunately, I don't really understand how its working, nor do I see any obvious issue as to why your user data is "leaking" between logins. Hard to tell since idk how or when these functions are called. Overall the issue seems more like an architecture issue (Are you using angular? Is it a app-lifecycle issue?)
alpox
@alpox
Apr 05 2018 19:01
I also wonder why something should be leaking
Conor Murphy
@cmurphy580
Apr 05 2018 19:01
@bradtaniguchi React. i could look at the lifecycle methods again.
Brad
@bradtaniguchi
Apr 05 2018 19:02
Idk how react handles its lifecycle (Im and angular guy)
so idk if its that
But, the main thing is your user's state is carrying over even tho you "logout"
so its being held somewhere in the app and not being cleared
Conor Murphy
@cmurphy580
Apr 05 2018 19:03
@bradtaniguchi where do you see that. I have an 'unmount' method that clears the state and severs the bind to the firebase.
Nate Mallison
@NJM8
Apr 05 2018 19:08
@cmurphy580 I dont't know anything about react but how is this.props.params getting set? Seems like if you don't change that it will load the same user data
Brad
@bradtaniguchi
Apr 05 2018 19:08
I mean from what you tell me thats what it sounds like
Conor Murphy
@cmurphy580
Apr 05 2018 19:09
@bradtaniguchi firebase saves it to localstorage so i have to find a way to clear it when the user logs out. good call. @NJM8 params is set in my login.js component. its just the identifier that oAuth assigns the user.
Nate Mallison
@NJM8
Apr 05 2018 19:17
componentWillUnmount is your log out function correct? Are you clearing out localstorage any other way?
Gjermund Wiggen
@Wiggen94
Apr 05 2018 19:25
Hello everyone, I need some help with express. I'm trying to use req.path or at least find something equivalent, I want to return only the last part of the path.
http://localhost/user/1 and I want it to return only 1 and not user/1, anyone have any idea?
Ohh wait I figured it out, had to use req.params
Nate Mallison
@NJM8
Apr 05 2018 19:28
@Wiggen94 are you trying to change the path or find out what the path is?
oh ok
Conor Murphy
@cmurphy580
Apr 05 2018 19:28
@NJM8 just there. @bradtaniguchi thanks for the help
CamperBot
@camperbot
Apr 05 2018 19:28
cmurphy580 sends brownie points to @njm8 and @bradtaniguchi :sparkles: :thumbsup: :sparkles:
:cookie: 450 | @bradtaniguchi |http://www.freecodecamp.org/bradtaniguchi
:cookie: 381 | @njm8 |http://www.freecodecamp.org/njm8
Nate Mallison
@NJM8
Apr 05 2018 19:29
oh ok, you got it figured?
AbrisM
@AbrisM
Apr 05 2018 20:15
Hi all, can anyone describe what the state of an object is exactly? Is it the TYPE of class an object is, or is it the VALUES in an object?
Joseph
@revisualize
Apr 05 2018 20:34
@AbrisM What?
AbrisM
@AbrisM
Apr 05 2018 20:43
@revisualize What is the state of an object? As in, how do I determine the state and what is definition of a state?
Joseph
@revisualize
Apr 05 2018 20:45
@AbrisM I have no idea what you mean by what is the state of an object.
Is this JavaScript?
Kudzu
@czhower
Apr 05 2018 20:45
@AbrisM values
Joseph
@revisualize
Apr 05 2018 20:45
An object is an object.
An object is a key value pair.
Kudzu
@czhower
Apr 05 2018 20:46
object state is an instance of an object including it data (values)
Joseph
@revisualize
Apr 05 2018 20:46
var myObj = { key: "value" };
Kudzu
@czhower
Apr 05 2018 20:46
an object is not a key value pair, that is just how JS implements object members.
an object is far more than a keyvaluepair, else any language could have objects and all you would need is an associative array.
Joseph
@revisualize
Apr 05 2018 20:49
@czhower Then what is an object?
Kudzu
@czhower
Apr 05 2018 20:51
"In the class-based object-oriented programming paradigm, "object" refers to a particular instance of a class where the object can be a combination of variables, functions, and data structures."
the keyvaluepair is JS's implementation of the members of the object.
Joseph
@revisualize
Apr 05 2018 20:51
@czhower I don't care about... "Class-based ... yada yada yada..." I am in a HelpJavaScript chat. ... I care about JavaScript.
Kudzu
@czhower
Apr 05 2018 20:52
yes, but there is still a distinction. If you only have a key value pair and nothing more, you still dont have an object. You need functions, inheritance, overrides, polymorhism. NONE of those are provided by a simple key value pair and require additional support from the compiler.
Joseph
@revisualize
Apr 05 2018 20:53
@czhower How do I make or define an object?
Kudzu
@czhower
Apr 05 2018 20:53
Its like asking what a car is, and someone says "a car is defined as a Ford Fiesta".
That link doesnt cover inheritance etc though.
Joseph
@revisualize
Apr 05 2018 20:54
var person = {
  name: ['Bob', 'Smith'],
  age: 32,
  gender: 'male',
  interests: ['music', 'skiing'],
  bio: function() {
    alert(this.name[0] + ' ' + this.name[1] + ' is ' + this.age + ' years old. He likes ' + this.interests[0] + ' and ' + this.interests[1] + '.');
  },
  greeting: function() {
    alert('Hi! I\'m ' + this.name[0] + '.');
  }
};
Kudzu
@czhower
Apr 05 2018 20:54
But will get you started.
yes, thats a minimal JS object.
Joseph
@revisualize
Apr 05 2018 20:55
So, what happens when I get Object.keys(person);
blueteamtech
@blueteamtech
Apr 05 2018 20:55
Sooo glad to have found this chat room. I'm going through Basic Algorithm, and am always hitting a road block. Just now starting "Return Largest Numbers in Arrays" Any one else here?
Kudzu
@czhower
Apr 05 2018 20:56
That gives you the internal representation of the object and will list the keys in the keyvaluepair that JS uses to store the members.
ie object.keys returns a string array with "name", "age", etc...
Joseph
@revisualize
Apr 05 2018 20:56
And Object.values(person);
Aditya
@ezioda004
Apr 05 2018 20:56
@czhower But JS is not classical OOP therefore no class, its follow prototype inheritance. So how'd you define objects then?
Kudzu
@czhower
Apr 05 2018 20:56
Same, but returns the values of the members in an array instead of the member identifiers (name)
Joseph
@revisualize
Apr 05 2018 20:57
Correct.
So, in JavaScript an object is a set of member items that are key value pairs.
Right?
Kudzu
@czhower
Apr 05 2018 20:57
An object can be implemented in many ways and many langs define them differently, they key thing is that they support the base definition which JS does, although fairly minimally.
Joseph
@revisualize
Apr 05 2018 20:57
I don't care about other languages.
HelpJavaScript... I care about JavaScript.
Kudzu
@czhower
Apr 05 2018 20:58
No, becuase the object also needs compiler support. You are mixing up part of the implementation with what an object is. You are asking if a Ford Fiest is a car - yes.. but are all cars built like a Ford Fiesta? No.
Joseph
@revisualize
Apr 05 2018 20:58
I don't care about cars or Ford Fiesta's
Brad
@bradtaniguchi
Apr 05 2018 20:59
aw man I forget about Object.valuesdamn....
Kudzu
@czhower
Apr 05 2018 20:59
Its still important to understand implementation vs definition, espeically since it is more than a key value pair. JS has polymorphism, which cannot eb provided by a keyvaluepair alone
Joseph
@revisualize
Apr 05 2018 20:59
What is an Object in JavaScript?
Kudzu
@czhower
Apr 05 2018 20:59
Evidently you don't care to learn propoer CompSci terminology either.
Joseph
@revisualize
Apr 05 2018 20:59
No ... No I do not.
I am here to learn JavaScript.
Kudzu
@czhower
Apr 05 2018 20:59
Are you asking what is it or how is it implemented? Even if the later, the keyvaluepair is only PART of it.
Joseph
@revisualize
Apr 05 2018 20:59
If I want to learn Computer Science.. I'd go somewhere else.
Kudzu
@czhower
Apr 05 2018 21:00
Well good luck, its like saying "I want to learn to operate a Ford Fiesta, but I don't want to learn how to drive"
Aditya
@ezioda004
Apr 05 2018 21:00
JS is subset Programming and therefore CS. I learned that hard way haha
Joseph
@revisualize
Apr 05 2018 21:01
I just don't understand why I'm being told that an object (as it relates to JavaScript) is not a key value pair.
Kudzu
@czhower
Apr 05 2018 21:01
Well all langs are.. but.... the point is if you want to learn JS, you still have to learn CS principles as they apply in JS if you want to use JS properly.
How does a KVP implement inheritance and polymorphism? It doesnt.. .the compiler adds that.
Brad
@bradtaniguchi
Apr 05 2018 21:01
@revisualize Are you looking for the most details right answer, or a dumbed down answer that fits what you already know?
Aditya
@ezioda004
Apr 05 2018 21:01
Agreed @czhower
Joseph
@revisualize
Apr 05 2018 21:02
When I interact and build and work with objects in JavaScript. I work with object. All I care about is the object name. The key in that object and the value that key references.
Right?
Kudzu
@czhower
Apr 05 2018 21:02
Do you know what polymorphism or inheritance is?
Joseph
@revisualize
Apr 05 2018 21:02
Nope.
Kudzu
@czhower
Apr 05 2018 21:03
Then how can you demand to say you are right when Im telling you the difference?
Joseph
@revisualize
Apr 05 2018 21:03
I'm not saying I'm right.
When have I said that?
Aditya
@ezioda004
Apr 05 2018 21:03
I think knowing about these patterns/paradigms at the end of the helps you write more efficient program. Probably makes you stand out from other JS programmers
Kudzu
@czhower
Apr 05 2018 21:03
objects are not structures... what you are defining is a structdure with functions.... only in a very narrow and incorrect definition would that be a an object.. .and largely useless in a practial way.
Joseph
@revisualize
Apr 05 2018 21:04
I'm asking. What is an object in JavaScript if it is not a collection of member items with key value pairs?
Kudzu
@czhower
Apr 05 2018 21:04
objects have inheritance. How are you going to have inheritance with only a kvp?
the kvp is ONE PART OF HOW JS IMPLEMENTS objects. Even as an instance of the object it is only part of it although most of it.
Joseph
@revisualize
Apr 05 2018 21:05
What is inheritance?
Kudzu
@czhower
Apr 05 2018 21:05
think of this
tree
-Elm
-Oak
Joseph
@revisualize
Apr 05 2018 21:05
Okay.
Kudzu
@czhower
Apr 05 2018 21:05
Elm and oak are trees, but share all the stuff the tree object has without having to copy it
And you can use the tree interface to work on all types of trees.
Joseph
@revisualize
Apr 05 2018 21:05
Correct.
Kudzu
@czhower
Apr 05 2018 21:06
with a simple KVP, its jsut an associate array. No way to share code or inherited properties. Not to mention polpymorphism of functions.
and getter/setter functionality.
Joseph
@revisualize
Apr 05 2018 21:07
var tree = {
    name: "Elm",
    Kingdom: "Plantae",
    Clade: ["Angiosperms", "Eudicots", "Rosids"],
    Order: "Rosales",
    Family: "Ulmaceae",
    Genus: "Ulmus",
    evergreen: false,
    leaves: true,
    dropLeaves: function () { this.leaves = false; }
}
Kudzu
@czhower
Apr 05 2018 21:08
no, now you ayhve an instance of an object. Thats not inheritance.
for exmaple Elms lose their leaves in the winter
so it wmight have a DropLeaves method, btu such a method would be useless on an evergreen pine tree, so it wont have a method. But they are both trees.
When you make a new Elm class which inherits from Tree, you dont have to copy the properties every time, Its part of the Elm class itself which makes it reusable.
Joseph
@revisualize
Apr 05 2018 21:10
So, you can create a class that creates a basic object that allows you to share properties between the "tree"
Kudzu
@czhower
Apr 05 2018 21:11
more or less - thats a simplification but yes.
Joseph
@revisualize
Apr 05 2018 21:11
But, JavaScript has already done that with Object.keys() and Object.values(); ... You can recreate that functionality by creating your base object.
Kudzu
@czhower
Apr 05 2018 21:11
Elms are not evergreens BTW. :)
Joseph
@revisualize
Apr 05 2018 21:11
Whatever.
Kudzu
@czhower
Apr 05 2018 21:12
no... keys and values are part of how JS implements an object. KVPs cannot implement an object by themselves. At best they can create what is called a structure in most languages, but even then its still just the internal implementation of a structure.
When you go for surgery, do you debate with the surgeon when he gives you specific clear answers about medical questions that he has had years of education on and you don't? Or when he tells you something do you try to understand it instead?
Would you say "I want to learn Chinese, but I don't want to learn any funky symbols or how to pronounce it?" How good do you think your Chinese would be?
Joseph
@revisualize
Apr 05 2018 21:16
I still have no idea what you're talking about.
Kudzu
@czhower
Apr 05 2018 21:16
If you are going to learn any coding language, you are going to have to understand basic CompSci principles, because all coding langs are built upon pieces of it.
Joseph
@revisualize
Apr 05 2018 21:16
So, here's a question for you. Should I just say... Fuck learning JavaScript until I learn computer science?
Fuck being a Network Administrator until I learn how to dig a ditch to run cable?
Kudzu
@czhower
Apr 05 2018 21:17
First I would say that you should not be defensive and rude to people who are trying to help you, and second I would say that to understand JS, it also means to understand basic CompSci.
Joseph
@revisualize
Apr 05 2018 21:17
I'm not trying to be rude. I'm trying to get a better understanding of what the hell you're talking about.
Kudzu
@czhower
Apr 05 2018 21:17
no, but I woudl give up being a network admin if you refused to understand waht a network was or what basic concepts like Ethernet are.
well how else should I interpret things liek "whatever, f* this, f that, I dont care about compsci"?
Joseph
@revisualize
Apr 05 2018 21:18
For me as a someone that's trying to shift his 15 year career from Network Systems Administration to Systems Automation via learning web development principles... I want to understand what you're talking about when you say that an Object is not a key value pair.
Kudzu
@czhower
Apr 05 2018 21:19
A key value pair is only one part of how JS handles objects. A KVP alone cannot implement a practical object.
Joseph
@revisualize
Apr 05 2018 21:20
What is it that I need to understand to understand what an object is when I as a new developer needs to work with object as I create web applications?
Kudzu
@czhower
Apr 05 2018 21:20
But I cant explain it more because you dont even fully understand what an object is or some of its core concepts.
Joseph
@revisualize
Apr 05 2018 21:20
How do I as a developer interact or work with an Object?
Brad
@bradtaniguchi
Apr 05 2018 21:20
@revisualize I know one case where understanding an object is more important than just a KVP.
Joseph
@revisualize
Apr 05 2018 21:20
Okay.
Brad
@bradtaniguchi
Apr 05 2018 21:20
You need to use Angular
Joseph
@revisualize
Apr 05 2018 21:21
I don't know Angular.
I'm here to learn JavaScript.
Kudzu
@czhower
Apr 05 2018 21:21
in its simplest forms, an object is a set of fields, functions, properties - BUT it also needs inheritance and polymorphism. A KVP cannot do inheritance, polpymorphism or properties.
no, you dont need to use Angular.
Brad
@bradtaniguchi
Apr 05 2018 21:21
Angular compiles to javascript, and is a web framework
Kudzu
@czhower
Apr 05 2018 21:21
There are many frameworks, and one should learn JS before using any of them.
Brad
@bradtaniguchi
Apr 05 2018 21:22
very true
Kudzu
@czhower
Apr 05 2018 21:23
Learning Angular or any framework before JS is like learning to accelerate a car but not how to stop or steer it.
Joseph
@revisualize
Apr 05 2018 21:23
@czhower Is there any way you could show me an example of what you're talking about?
Kudzu
@czhower
Apr 05 2018 21:23
At least so far as we are talking about Front end frameworks.
which part?
Joseph
@revisualize
Apr 05 2018 21:34
function NewTree(name, evergreen, genus, family, order, kingdom, clade) {
  this.name = name;
  this.kingdom = kingdom;
  this.clade = [...clade];
  this.order = order;
  this.family = family;
  this.genus = genus;
  this.everygreen = evergreen;
  this.dropLeaves = function () { this.leaves = false; }
}

var tree = new NewTree('Elm', false, "Ulmus", "Ulmaceae", "Rosales", "Plantae", ["Angiosperms", "Eudicots", "Rosids"]);

console.log(tree);
Object { name: "Elm", kingdom: "Plantae", clade: […], order: "Rosales", family: "Ulmaceae", genus: "Ulmus", everygreen: false, dropLeaves: dropLeaves() }
Doesn't every tree have the property to dropLeaves?
Kudzu
@czhower
Apr 05 2018 21:37
That is a function which creates a simple dynamic object.
no, evergreens dont drop them except when dead or a few at a time. Never all for winter.
Brad
@bradtaniguchi
Apr 05 2018 21:37
@revisualize Every tree has their own property to drop leaves, if you change 1 of the instances function it changes only that individual tree. It wont change another.
Kudzu
@czhower
Apr 05 2018 21:37
search inheritance of objects.. try the mozilla link I sent above, it shows all the features of JS object.
ie, not even all Elm trees, but only ONE Elm tree....
but in a proper class tree, only non evergreens would have drop leaves.
you would have
Joseph
@revisualize
Apr 05 2018 21:39
All trees should have the option to dropLeaves.
Kudzu
@czhower
Apr 05 2018 21:39
tree
evergreens
norfolkpine
bluespruce
deciduous
maple
oak
etc
ugh.. gitter lost the indents.
Joseph
@revisualize
Apr 05 2018 21:39
Should they not?
Kudzu
@czhower
Apr 05 2018 21:39
not if dropleaves is for winter as we discussed previously. Evergreens dont drop all leaves for winter
and many tropical trees never do either.
Joseph
@revisualize
Apr 05 2018 21:40
@GitHub-Henry That actually doesn't help me.
Kudzu
@czhower
Apr 05 2018 21:40
think of i like this, if we had vehicles, woudl we add liftbucket to all vehicles, or only dumptrucks?
Joseph
@revisualize
Apr 05 2018 21:41
Depends.
Should we add lift to all vehicles. Yes.
Kudzu
@czhower
Apr 05 2018 21:41
this is where JS vs compsci comes in again. You should learn the compsci concepts of an object before learning how JS does objects.. because if you dont.. you cant understand the concepts JS is implementing.
and turnonhose to all vechicles too, not just fire trucks?
opendoor to motorcycles?
fillgastank to electric cars?
Joseph
@revisualize
Apr 05 2018 21:42
Depends.
Kudzu
@czhower
Apr 05 2018 21:42
because putting gasoline on a battery seems like a bad idea.
Joseph
@revisualize
Apr 05 2018 21:43
Would I ever create an object that represents ALL vehicles?
No.
Kudzu
@czhower
Apr 05 2018 21:44
But thats how OOP works! You create a base object that does exasctly that. It builds teh base for all the other vehicles.
sorry,t hat one was python
Joseph
@revisualize
Apr 05 2018 21:45

Because if you did that you'd have to be...

var vehicle = { number_of_tires: 2 }

but, then what if your vehicle doesn't have tires?

then you add a new intermediary class.

ie

Vehicle
--WheeledVehicle
----Motorcycle
----Car
--FlyingVehicle

number of tires has no impl at all in vehicle in this case, it is only introduced in WheeledVehicle
and because Motorcycle and Car are descended from it, they can define it as 2 and 4.
without redeclaring it, and also be compatible to WheeledVehicle
Kudzu
@czhower
Apr 05 2018 21:48
WheeledVehicle is abstract, it defines that a tirecount needs defined, but no value. only subclasses define value.
for that, add a TrackedVehicle
Joseph
@revisualize
Apr 05 2018 21:49
What if you create a Person Object and then would every person inherit the options to do things with their hands?
No.
Because not all people have hands.
Kudzu
@czhower
Apr 05 2018 21:51
Yes they would, because a person without hand is not a usual condition. In those instances it would be handled as an instance behavior.
If that was a necesary condition to handle.
Joseph
@revisualize
Apr 05 2018 21:53
I think I'll just stick with my notion that Objects in JavaScript are collections of member items that are accessed via key value pairs.
If I create a class I can have shared object members between each object.
I haven't seen anything that you've told me that doesn't state that you can't access an object via key value pairs. One of those being methods.
You haven't even shown me any code.
Kudzu
@czhower
Apr 05 2018 21:56
Ive sent you detailed links. You just refuse to read.
Joseph
@revisualize
Apr 05 2018 21:58
I've read them
function NewTree(name, evergreen, genus, family, order, kingdom, clade) {
  this.name = name;
  this.health = true;
  this.kingdom = kingdom;
  this.clade = [...clade];
  this.order = order;
  this.family = family;
  this.genus = genus;
  this.everygreen = evergreen;
}

NewTree.prototype.dropLeaves = function () { this.leaves = false; }
NewTree.prototype.sick = function () { this.health = false; }

var tree = new NewTree('Elm', false, "Ulmus", "Ulmaceae", "Rosales", "Plantae", ["Angiosperms", "Eudicots", "Rosids"]);

console.log(tree);
Kudzu
@czhower
Apr 05 2018 22:04
There is no way you read that MDN one. That would take quite a long time to read and comprehend at your current level.
Joseph
@revisualize
Apr 05 2018 22:06
@czhower That's a bit condescending.
Jason Luboff
@JLuboff
Apr 05 2018 22:06
A bit? I'd say thats an understatement.
Kudzu
@czhower
Apr 05 2018 22:06
Its 14 printed pages and you still dont understand most of the concepts in it. If you read it, you only mouthed the words quickly and didnt try to comprehend it.
Joseph
@revisualize
Apr 05 2018 22:07
@JLuboff I'm trying to be polite. I had to look up a word that actually meant less than what I wanted to say.
Brad
@bradtaniguchi
Apr 05 2018 22:07
Man yall still talking about this?
eeflores
@eeflores
Apr 05 2018 22:07
what's the original question?
Brad
@bradtaniguchi
Apr 05 2018 22:08
@eeflores Someone wanted to know what objects were basically (talk about a vague question), the OP isn't even here anymore
eeflores
@eeflores
Apr 05 2018 22:08
ah ok thanks @bradtaniguchi
CamperBot
@camperbot
Apr 05 2018 22:08
eeflores sends brownie points to @bradtaniguchi :sparkles: :thumbsup: :sparkles:
:cookie: 451 | @bradtaniguchi |http://www.freecodecamp.org/bradtaniguchi
Joseph
@revisualize
Apr 05 2018 22:08
@eeflores I was told that an Object is not a key value pair because of things like polymorphism and inheritance. And that objects cannot just be key value pairs. And I'm over here like.. What?
eeflores
@eeflores
Apr 05 2018 22:09
when I was taught about objects, they were combinations of data and functions that maintained the integrity of the data
the data was typically hidden from outside users of the object
and object definitions are what classes are
Joseph
@revisualize
Apr 05 2018 22:11
Now, when I actually am trying to use concepts from text that I've been linked and I've written code from an outside example of the text that I've been linked...
I'm being told that because of my current skill level. That there is no way that I could have read the text ... When I'm using the text that I read to create the code that I'm writing.
But, hey... I guess I don't know how to read.
Brad
@bradtaniguchi
Apr 05 2018 22:11
Man both of you guys are stubborn :/
eeflores
@eeflores
Apr 05 2018 22:12
I'll try to help you out if I can @revisualize
Joseph
@revisualize
Apr 05 2018 22:13
@eeflores It's all good man. I'm going to go back to what I was doing.
eeflores
@eeflores
Apr 05 2018 22:13
:+1:
Kudzu
@czhower
Apr 05 2018 22:13
Well one person is new to programming and JS, while another has 35 years experience. And one person keep saying "whatever" and even "I dont want to learn any compsci principles, only JS". Draw your own conclusion.
Joseph
@revisualize
Apr 05 2018 22:14
Do I need to know Comp Sci to write JavaScript?
Do I need to know Comp Sci to do programming on a basic level?
eeflores
@eeflores
Apr 05 2018 22:15
the main thing I learnt from a uni degree is best practice in relation to software development
Brad
@bradtaniguchi
Apr 05 2018 22:15
@czhower Good for you, I felt like Joseph didn't want to deepen his understanding like 3 sentences in and yet here we are man
eeflores
@eeflores
Apr 05 2018 22:15
design, structure
planning
Joseph
@revisualize
Apr 05 2018 22:15
How many programmers are there in the world making 120k+/yr without Comp Sci?
eeflores
@eeflores
Apr 05 2018 22:16
actually I wonder about that ...
Joseph
@revisualize
Apr 05 2018 22:16
Do I think there is a time and a place for learning Comp Sci?
Yes.
Brad
@bradtaniguchi
Apr 05 2018 22:16
I feel like not many, with that kinda money you can prolly get a masters. Unless you life like in San fran where its hella expensive
Joseph
@revisualize
Apr 05 2018 22:17
Is that time or that place at year 1 learning to program?
I don't know.. Maybe. But, most likely not.
Brad
@bradtaniguchi
Apr 05 2018 22:17
@revisualize Depends on what your goals in life are. Earlier the better
Joseph
@revisualize
Apr 05 2018 22:17
@bradtaniguchi True.
Brad
@bradtaniguchi
Apr 05 2018 22:18
Not like knowledge hurts, but then you gotta do what you gotta do
Kudzu
@czhower
Apr 05 2018 22:18
you dont need a CS degree, but if you refute CS principles and refuse to learn any, you are not going to go very far.
Joseph
@revisualize
Apr 05 2018 22:18
@czhower I think that's your opinion and doesn't have any factual validation.
Kudzu
@czhower
Apr 05 2018 22:18
@bradtaniguchi I was trying, but you are right. He is not interested in learning.
Joseph
@revisualize
Apr 05 2018 22:18
Yes I am.
I read what you linked me and I even wrote this code.
function NewTree(name, evergreen, genus, family, order, kingdom, clade) {
  this.name = name;
  this.health = true;
  this.kingdom = kingdom;
  this.clade = [...clade];
  this.order = order;
  this.family = family;
  this.genus = genus;
  this.everygreen = evergreen;
}

NewTree.prototype.dropLeaves = function () { this.leaves = false; }
NewTree.prototype.sick = function () { this.health = false; }

var tree = new NewTree('Elm', false, "Ulmus", "Ulmaceae", "Rosales", "Plantae", ["Angiosperms", "Eudicots", "Rosids"]);

console.log(tree);
From
var tree = {
    name: "Elm",
    Kingdom: "Plantae",
    Clade: ["Angiosperms", "Eudicots", "Rosids"],
    Order: "Rosales",
    Family: "Ulmaceae",
    Genus: "Ulmus",
    evergreen: false,
    leaves: true,
    dropLeaves: function () { this.leaves = false; }
}
Brad
@bradtaniguchi
Apr 05 2018 22:19
I will say code !== concepts for sure tho, that does need to be stated
Joseph
@revisualize
Apr 05 2018 22:19
This is me trying to learn.
I took a junk object from above.
And I wrote code based upon what you linked me.
Right?
Did I or did I not?
Because if I did.. That show's that I'm taking what you've been talking about and trying to apply it to my learning process.
Or is that not the case?
Brad
@bradtaniguchi
Apr 05 2018 22:22
@revisualize You are correct in the code sense, but I think @czhower is too stuck on the "concept" idea
Joseph
@revisualize
Apr 05 2018 22:22
The only way I can learn a concept is by applying it.
Brad
@bradtaniguchi
Apr 05 2018 22:22
Cuse you dont understand the "concept" you don't want to "learn" idea
That's true, but like if you took the same ideas into another language, some of the "concepts" you think you understand don't apply since its just for JS for example
Joseph
@revisualize
Apr 05 2018 22:24
I can't understand or articulate problems or principles of x86 ASM because I don't know x86 ASM. I only know JavaScript and PowerShell.
As someone trying to learn and grow I have to expand my learning based on what I know.
And I'm currently in a HelpJavaScript chat.
Brad
@bradtaniguchi
Apr 05 2018 22:24
That's good, Im not saying "your learning wrong"
Joseph
@revisualize
Apr 05 2018 22:29
you're*
Smootimus
@Smootimus
Apr 05 2018 22:34
=\
Joseph
@revisualize
Apr 05 2018 22:49
Anyhow, I need to leave. Have a good one.
alpox
@alpox
Apr 05 2018 22:50
@revisualize if you once need a detailed discussion for understanding OOP, give me a PM. But im in bed for this night :)
Smootimus
@Smootimus
Apr 05 2018 23:07
I'm down to discuss OOP as well, I just missed what was goin' on and it didn't sound like things were going "smooth"
Joseph
@revisualize
Apr 05 2018 23:40
@Smootimus I was just trying to actually understand what an object is in JavaScript.
Smootimus
@Smootimus
Apr 05 2018 23:47
Simply put, Objects are containers for data values
Joseph
@revisualize
Apr 05 2018 23:47
And how are those data values stored?
Smootimus
@Smootimus
Apr 05 2018 23:48
name:value pairs
Joseph
@revisualize
Apr 05 2018 23:48
HEY!
I was told that's wrong.
Smootimus
@Smootimus
Apr 05 2018 23:48
How so
Joseph
@revisualize
Apr 05 2018 23:49
Something about not taking into account polymorphism and inheritance.
Smootimus
@Smootimus
Apr 05 2018 23:49
Methods are functions that act on data in an object
... wait, what?
Brad
@bradtaniguchi
Apr 05 2018 23:49
@Smootimus Scroll up to all the stuff czhower was talking about, he goes into the concepts hardcore.
Smootimus
@Smootimus
Apr 05 2018 23:49
Those are properties of OOP
Maybe they're talking about the way Javascript handles it
And not polymorphism/inheritance/objects and OOP as a whole
I dunno
Brad
@bradtaniguchi
Apr 05 2018 23:51
I dunno either, but it went on for a while
Smootimus
@Smootimus
Apr 05 2018 23:52
Because it's not wrong, objects aren't responsible for handling inheritance and polymorphism.... you are, as the developer
So I don't know how that's even supposed to be an argument.
Joseph
@revisualize
Apr 05 2018 23:52
I wasn't trying to argue. I was trying to understand.
Smootimus
@Smootimus
Apr 05 2018 23:53
If you build an object, and say it inherets from something. That only means it's inhereting the already defined name:value pairs form another object... that's it
Joseph
@revisualize
Apr 05 2018 23:53
But, apparently because I don't understand Comp Sci ... I don't understand objects and I shouldn't be a developer.
Smootimus
@Smootimus
Apr 05 2018 23:53
Well whoever said that is the one in the wrong
Cause it sounds like someone didn't even know the material enough to even make a proper argument
Joseph
@revisualize
Apr 05 2018 23:54
I wouldn't say they're wrong... Pretentious asshole. But, not wrong.
Brad
@bradtaniguchi
Apr 05 2018 23:54
^^ hehe
Smootimus
@Smootimus
Apr 05 2018 23:54
Polymorphism is just interfacing with types of all different types
Inheretance is inhereting the name:value pairs from one object to another
And object is a collection of name:value pairs of data
And you make methods, which are functions attached to the object and are used to manipulate the data stored in said name:value pairs
That's OOP
Joseph
@revisualize
Apr 05 2018 23:55
And that's what I said.
Smootimus
@Smootimus
Apr 05 2018 23:56
lol nice wish I would've been here earlier
Joseph
@revisualize
Apr 05 2018 23:56
Object are a collection of data as member items and those items are broken down to key value pairs.
Now the value of the can be anything including a function which in turn makes the object key a method. And that method can interact independently or with the object itself.
Rahsheen Porter
@rahsheen
Apr 05 2018 23:56
You're all wrong because you don't have degrees and such :trollface:
Smootimus
@Smootimus
Apr 05 2018 23:57
LOL
Brad
@bradtaniguchi
Apr 05 2018 23:57
Shit I have a degree and I'm not too damn sure about anything
Joseph
@revisualize
Apr 05 2018 23:57
I have a degree.
Rahsheen Porter
@rahsheen
Apr 05 2018 23:57
@bradtaniguchi is especially wrong
Joseph
@revisualize
Apr 05 2018 23:57
Network Design and Administration AAS-T from a community college.
Brad
@bradtaniguchi
Apr 05 2018 23:57
aw man :worried:
Smootimus
@Smootimus
Apr 05 2018 23:57
Hah
Rahsheen Porter
@rahsheen
Apr 05 2018 23:58
Community College means you especially can never be correct 😂
I'm just kidding. Don't taze me, bro
Smootimus
@Smootimus
Apr 05 2018 23:58
:laughing:
Dayum