These are chat archives for FreeCodeCamp/HelpFrontEnd

17th
Jan 2018
Toni Shortsleeve
@KoniKodes
Jan 17 2018 01:22
@JureVidrih That was fun!
Wolfion
@DEEPANSHU-BHASKER
Jan 17 2018 02:59
hello guys i need somehelp
i have background image set
but when i run live server of vs code it doesnt show my bg image in browser
_
Stephen James
@sjames1958gm
Jan 17 2018 03:15
@DEEPANSHU-BHASKER Check your devtools and see if the URL of your image is correct for liveserver
abraham anak agung
@padunk
Jan 17 2018 03:36
@artoodeeto you could change your background color to rgba and delete the opacity
aRtoo
@artoodeeto
Jan 17 2018 03:40
@padunk but i dont want to remove the opacity bro. is there other way?
abraham anak agung
@padunk
Jan 17 2018 03:45
@artoodeeto rgba is red, green blue and alpha alhpa will give you the opacity like effect
aRtoo
@artoodeeto
Jan 17 2018 03:45
@padunk aight thanks bro
CamperBot
@camperbot
Jan 17 2018 03:45
artoodeeto sends brownie points to @padunk :sparkles: :thumbsup: :sparkles:
:cookie: 417 | @padunk |http://www.freecodecamp.org/padunk
aRtoo
@artoodeeto
Jan 17 2018 04:28
hello fam what do you suggest about this text and the cell. the text is overlapping the cells. any suggestion?
https://codepen.io/artoo/pen/Zvomxr?editors=0100
This message was deleted
Yingjie (Iris) Hu
@huyingjie
Jan 17 2018 04:32
This is my Wikipedia Viewer https://codepen.io/yingjiehu/pen/ppxRRM Any suggestion will be appreciated
aRtoo
@artoodeeto
Jan 17 2018 04:36
@huyingjie like it bro
Yingjie (Iris) Hu
@huyingjie
Jan 17 2018 04:37
@artoodeeto Thank you :)
CamperBot
@camperbot
Jan 17 2018 04:37
huyingjie sends brownie points to @artoodeeto :sparkles: :thumbsup: :sparkles:
:cookie: 321 | @artoodeeto |http://www.freecodecamp.org/artoodeeto
Yingjie (Iris) Hu
@huyingjie
Jan 17 2018 04:37
@artoodeeto I mimicked the example because I do not know how to design the website
aRtoo
@artoodeeto
Jan 17 2018 04:38
@huyingjie hahaha. same shit here bro. usually i google a design. yours looks great. keep it up. :0
Yingjie (Iris) Hu
@huyingjie
Jan 17 2018 04:39
@artoodeeto Your method is great. I will try it on my next project :+1:
aRtoo
@artoodeeto
Jan 17 2018 04:41
@huyingjie yea much easier. but some time i make my own. haha.
@huyingjie oh sorry youre a she. zup sis! lol
haha
Yingjie (Iris) Hu
@huyingjie
Jan 17 2018 04:42
@artoodeeto :smile:
You can design !
aRtoo
@artoodeeto
Jan 17 2018 04:45
@huyingjie lol i wish!! hahaha. cant even. hahahaha
@huyingjie check my profile its ugly. haha
Yingjie (Iris) Hu
@huyingjie
Jan 17 2018 04:46
@artoodeeto Where is the profile?
aRtoo
@artoodeeto
Jan 17 2018 04:46
@huyingjie check mine here
Yingjie (Iris) Hu
@huyingjie
Jan 17 2018 04:48
@artoodeeto The images are broken.
aRtoo
@artoodeeto
Jan 17 2018 04:49

@huyingjie nevermind that. but is this your achievemnts?? is this you?

spotting elegance within the chaos, design, fabrication, programming, motorcycling, aircraft building and the best Speed Demon player around 1998-present EDUCATION Sabrina Aircraft Manufacturing, Chicago, Illinois PUBLICATIONS/TALKS/DOCUMENTARIES Transport Canada Medical Certificate Fall 2012 Edison Regional Gifted Center, a Chicago Public School (4.00/4.00) Illinois Mathematics and Science Academy (4.00/4.00) Massachusetts Institute of Technology (5.00/5.00) Graduate Record Examinations (168/170v; 170/170q; 5.5/6.0w; 980/990p) Harvard PhD Candidate (qualification: A) Cargese Summer Institute String Theory and Holography School Harvard PhD student (4.00/4.00) RESEARCH EXPERIENCE Blue Origin LLC, Kent, Washington NASA Kennedy Space Center, Port Canaveral, Florida The Center for the Fundamental Laws of Nature, Cambridge, Massachusetts Boeing Phantom Works, Huntington Beach, California European Organization for Nuclear Research, Geneva, Switzerland HONORS/AWARDS Lindau-Nobel Young Researcher MIT Physics PhD Fellowship (declined) Hertz Foundation Fellow Harvard Physics Purcell Fellow MIT Physics Orloff Scholarship Award (highest graduating GPA: 5.00) Harvard GSAS James Mills Peirce Fellow World Quantitative and Science Scholar Harvard Smith Fellow Illinois All-State Academic Team 'Top of the World' Scholar Illinois Aviation Trades Association Industry Achievement Award MIT Freshman Entrepreneurship Award (inaugural--the first to be so honored) Scientific American 30 under 30 SU-MIT Scholar, Istanbul, Turkey Physics First Primer (documentary) Eight Six Quebec (documentary) Insights into Becoming a Theoretical Physicist (talk) Gaussian Measures in Quantum Theory (talk) Semiclassical Virasoro Symmetry of the Quantum Gravity S-Matrix (JHEP) Classical Interpretation of the Weinberg Soft Factor, origins of 'the Triangle' (note) LICENSES/CERTIFICATES Industry Canada Radio Operators Certificate Canadian Solo Flight Certificate MIT Pirate's License (proficient in Sabre, Sailing, Pistol & Archery) FAA Light Sport Aircraft Manufacturer U.S. Solo Flight Permit FAA Authorized Experimental Aircraft Test Pilot Illinois Motorcycle License SKILLS Fall 2009 Summer 2009 Spring 2009 Winter 2005 Fall 2004 Winter 2008 Spring 2007 Spring 2010 Spring 2011 Winter 2014 Spring 2014 Summer 2014 Summer 2014 2015-2020 2014-2015 2014 2013-2014 2013 2013-2014 Winter 2013 Summer 2012 2012 Spring 2012 2011 Summer 2010 2010 2014-present 2012-2013 Summer 2011 Winter 2011 Summer 2009 2005-present 2014-present 2014 2013 2012 2010-2013 2007-2010 1998-2007 Sabrina Gonzalez Pasterski New Gravitational Memories, introducing 'the Triangle' (talk) Winter 2015 2015 Forbes 30 Under 30 Winter 2015 Physics, Forbes and the Future (talk) Spring 2015 National Science Foundation Graduate Research Fellow 2015-2020 Spring 2015 Asymptotic Virasoro Symmetries and Gravitational Memory (talk) Asymptotic Symmetries and Electromagnetic Memory, completing 'the Triangle' for EM (JHEP) Spring 2015 The Road Not Taken (talk) Fall 2015 Life+Style "Remarkable Woman" (cover story) 2015 Summer 2015 Dr. Strominger or: How Andy Learned to Stop Worrying and Love 'the Triangle' (talk) String Theory School (talk) Fall 2015 2016 Summer 2014 Low’s Subleading Soft Theorem as a Symmetry of QED (PRL Editors' Suggestion) Winter 2015 Higher d Supertranslations and Weinberg's Soft Graviton Theorem (AMSA) Referee for the Journal of High Energy Physics 2016-present Perfect Attendance from kindergarten-senior year @MIT (never sick or absent) 1998-2013 New Gravitational Memories (JHEP) Asymptotic Symmetries @ Null Infinity (talk) Memory Effects (talk) Summer 2016 Summer 2016 Steven P. Jobs Trust's Ozy Rising Star MIT Physics Rising Star 2016 (as if 2009) A Triangle of Traits: Constraining Scattering Through IR Effects (talk) Fall 2016 MIT Admissions Early Action nunc pro tunc December 16, 2009 (the inaugural honorary MIT Tube) 2016 _ Harvard's M

Yingjie (Iris) Hu
@huyingjie
Jan 17 2018 04:49
@artoodeeto It seems to be not finished. You do not provide your personal social links.
No. Wow, this person has a lot of achievements.
aRtoo
@artoodeeto
Jan 17 2018 04:50
@huyingjie are you sabrina gonzalez paterski?
Yingjie (Iris) Hu
@huyingjie
Jan 17 2018 04:50
There are many chinese people called Yingjie, haha
aRtoo
@artoodeeto
Jan 17 2018 04:50
@huyingjie stop lying
@huyingjie is this you?
Yingjie (Iris) Hu
@huyingjie
Jan 17 2018 04:51
Nope
This is my project page http://projects.yingjiehu.com/
aRtoo
@artoodeeto
Jan 17 2018 04:52
@huyingjie whre you got that link then?
like you profile. you use bootstrap?
havent reallty done mine.
Yingjie (Iris) Hu
@huyingjie
Jan 17 2018 04:52
I used bootstrap
You mean ”banner”?
@artoodeeto Bootstrap is not hard. It is like adding classes to HTML elements.
aRtoo
@artoodeeto
Jan 17 2018 04:55
@huyingjie yea. i was so noob before. still practicing. haha. im gonna redo all the projects. hey but you sure ur not paterzki?
@huyingjie damn! that lady is alien. i swear!
Yingjie (Iris) Hu
@huyingjie
Jan 17 2018 04:56
@artoodeeto I am a human being, not an alian ;)
aRtoo
@artoodeeto
Jan 17 2018 04:56
@huyingjie so freakin its you then?? youre sabrina?
the fuck you doin here? you bored or somethin? and why you using linglings name??
why you posing though? too popular?
Ken Haduch
@khaduch
Jan 17 2018 05:01
@huyingjie - wikipedia - I like the styling, if you didn't do it as an original idea, it's a good learning experience anyway to mimic a design that you have seen.
One comment that I would give - for a search string that doesn't return results, I think that it is a good idea to add a message to the output to indicate that "No results found".
Another thing that I noticed, upon narrowing the viewport, is that the "Random" button splits and part of it wraps onto a new line. Everything else seems to reformat nicely.
abraham anak agung
@padunk
Jan 17 2018 05:02
@huyingjie I like your site. :+1:
Yingjie (Iris) Hu
@huyingjie
Jan 17 2018 05:02
@padunk Thank you;)
CamperBot
@camperbot
Jan 17 2018 05:02
huyingjie sends brownie points to @padunk :sparkles: :thumbsup: :sparkles:
:cookie: 418 | @padunk |http://www.freecodecamp.org/padunk
Yingjie (Iris) Hu
@huyingjie
Jan 17 2018 05:03
@khaduch Thank you for your long feedback. I will add “No results found”. I don’t know why “Random” button splits when coding.
CamperBot
@camperbot
Jan 17 2018 05:03
huyingjie sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3681 | @khaduch |http://www.freecodecamp.org/khaduch
Roman Struna
@RomchyFCC
Jan 17 2018 05:28

Darren and I decided to make a beginner friendly project on GitHub to learn the basics of working on a project with a group. The good 'ol learn by doing technique, if anyone is interested in joining

https://github.com/RomchyFCC/collaborative_effort

You can fork this repo and get started.
You don't need to know any programing language for this.

Yingjie (Iris) Hu
@huyingjie
Jan 17 2018 05:31
@khaduch I added “No results found”. The splitting problem is because of fontawesome 5 icon. I asked in the forum for help.
Yessine
@yessinekebir
Jan 17 2018 09:07
Hi guys
Muhammed Hafiz
@zifahm
Jan 17 2018 10:11
i need arr=["hello,hi,welcome"] to arr=["hello", "hi", "welcome"] ?
anybody can help?
Marianissimus
@Marianissimus
Jan 17 2018 10:12
trying to split a string, are you? :) @zifahm
Sweet Coding :)
@SweetCodingInc
Jan 17 2018 10:13
@zifahm
const arr=["hello,hi,welcome"];

const newArr = arr.reduce( (f, c) => {
  return f.concat(c.split(','));
},[]);

console.log(newArr); // ["hello", "hi", "welcome"]
const arr=["hello,hi,welcome"];

const newArr = arr.reduce( (f, c) =>  f.concat(c.split(',')) ,[]);

console.log(newArr); // ["hello", "hi", "welcome"]
Marianissimus
@Marianissimus
Jan 17 2018 10:14
are you trying to confuse him? :confused:
Muhammed Hafiz
@zifahm
Jan 17 2018 10:14
@SweetCodingInc thanks
Sweet Coding :)
@SweetCodingInc
Jan 17 2018 10:14
@zifahm Did I confuse you, as @Marianissimus deems?
Markus Kiili
@Masd925
Jan 17 2018 10:15
arr = arr[0].split(","); // [ 'hello', 'hi', 'welcome' ]
@zifahm
Muhammed Hafiz
@zifahm
Jan 17 2018 10:15
no problem peeps
Markus Kiili
@Masd925
Jan 17 2018 10:24
@SweetCodingInc String.prototype.concat.apply(arr).split(","); would also work on an array with several elements. Reduce one is also nice.
Sweet Coding :)
@SweetCodingInc
Jan 17 2018 10:38
@Masd925 :+1:
that prototype one looks clean
Joshua Frias
@Juke-Magic
Jan 17 2018 12:40
guys how do i add \n in here?
result = result + [i] + ", ";
Amit Patel
@AmitP88
Jan 17 2018 12:42

hey all, I'm stuck on yet another algorithm - Return Largest Numbers in Array. Here's my code so far:


function largestOfFour(arr) {
  // You can do this!






  var maxArr = arr.map(function(max) {

      for (var i = 0; i < arr.length; i++) {    


           return Math.max.apply(null, arr[i]); 

      }


  });            


      return maxArr;


//        return Math.max.apply(null, arr[0]);     







}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

I understand that this code outputs [5,5,5,5], which is the highest element of the first sub-array. But, I'm having trouble figuring out how my for loop should be. I've tried making a nested for loop using i and j, but that didn't work either.

Markus Kiili
@Masd925
Jan 17 2018 12:42
@Juke-Magic Adding a string and an array is not a good idea.
@AmitP88 arr.map... already loops arr elements. No need for that for loop.
Marianissimus
@Marianissimus
Jan 17 2018 12:44
@AmitP88 you tell it: for every item of the bigarray (so all 4 sub-arrays), return the largest in the first subarray - arr[i], which it does
Joshua Frias
@Juke-Magic
Jan 17 2018 12:44
@Masd925 yep its just for testing stuff
how to i create a line break though?
here is the pen
Marianissimus
@Marianissimus
Jan 17 2018 12:44
you return it too soon, it doesn't get the chance to loop through all the subarrays @AmitP88
Amit Patel
@AmitP88
Jan 17 2018 12:45
@Marianissimus so I should put my return statement outside the loop?
Markus Kiili
@Masd925
Jan 17 2018 12:45
@AmitP88 Better to name it like arr.map(function(innerArray) { so you see that that parameter holds each inner array in its turn.
And just return the largest number of array innerArray from that map callback.
Marianissimus
@Marianissimus
Jan 17 2018 12:46
@AmitP88 yes, outside the loop. maybe use the results for each subarray and create a new one? I dont know...
Amit Patel
@AmitP88
Jan 17 2018 12:46
@Marianissimus I was thinking of doing that, but wouldn't that break the DRY rule?
Marianissimus
@Marianissimus
Jan 17 2018 12:47
why? what are you repeating? you need to return an array, dont you?
Amit Patel
@AmitP88
Jan 17 2018 12:47
oh, I thought you meant like:
math.max.apply(null, arr[0]
math.max.apply(null, arr[1]
etc
Marianissimus
@Marianissimus
Jan 17 2018 12:47
or use the map/reduce function. it's shorter, of course
Markus Kiili
@Masd925
Jan 17 2018 12:47
@AmitP88 You just need to map element arrays to maximum elements of those arrays. So map is a good idea.
Marianissimus
@Marianissimus
Jan 17 2018 12:48
@AmitP88 oh, no. use the loop, just dont return the results, use them in a new array;
push them into newarr, for instance
Amit Patel
@AmitP88
Jan 17 2018 12:48
ah I see
Joshua Frias
@Juke-Magic
Jan 17 2018 12:49
guys help me please
i need ya'll
Amit Patel
@AmitP88
Jan 17 2018 12:50
ok, I'll brb. gotta sort this out real quick. thanks @Marianissimus @Masd925 for your tips. I'll let you know how it goes :)
CamperBot
@camperbot
Jan 17 2018 12:50
amitp88 sends brownie points to @marianissimus and @masd925 :sparkles: :thumbsup: :sparkles:
:cookie: 456 | @marianissimus |http://www.freecodecamp.org/marianissimus
:star2: 4657 | @masd925 |http://www.freecodecamp.org/masd925
Markus Kiili
@Masd925
Jan 17 2018 12:51
@AmitP88 Easiest is to forget the loop and just use map and Math.max.
Amit Patel
@AmitP88
Jan 17 2018 12:52
@Masd925 for sure. I'll see if I can pull it off using just those two methods. I think I'm overdoing it with the loop
Ayush Bahuguna
@relentless-coder
Jan 17 2018 12:53
can anyone help me with react?

this is my component

export function AllExpense(props) {
    const renderExpense = ({data}) => {
        console.log(data.data);
        return (
            <div>
                <div>
                    <h2><Link to="/expense/new">Add Expense</Link></h2>
                </div>
                {
                    data.data.length > 0 ? <ul>
                        <li>
                            data.data.map(el =><ListItem key={el._id.toString()} value={el}/>)
                        </li>
                    </ul> : <h2>Enter some data!!</h2>
                }

            </div>
        )
    };
    return allExpenseAPi().then(renderExpense).catch((err) => {
        alert(err.message)
    })
}

and I keep getting error Objects are not valid as a React child

William Watts
@Braillon7
Jan 17 2018 12:58
hello campers...I'm in dire need of help on something that could turn out to be very simple...I'm working on the second page of my "todoapp" and for some reason I can't get my, short, Jquery function to work..it's just a short statement to bring up a css class instruction https://codepen.io/Braillon7/pen/RxBWbY
Anshul Adlakha
@anshuladlakha
Jan 17 2018 13:02
I'm trying to make a new tab chrome extension and I'm trying to add a clock to it and I'm having a really hard time because Chrome won't let me load setIntervals which I need for updating the time every second, then I tried using chrome alarms API by adding a event page but for some reason that's not working either. Can anyone help me out.
Ayush Bahuguna
@relentless-coder
Jan 17 2018 13:04
okay, i resolved it, nevermind
William Watts
@Braillon7
Jan 17 2018 13:06
@AmitP88 were you able to figure it out?
Joy
@Yorokobi05
Jan 17 2018 13:56
Hello, I would just like to ask if the challenge for the Falsy Bouncer under the Basic Algorithm cannot be solved by using Microsoft Edge. (Am I really required to use Mozilla for this?) Thanks.
VaseJS
@VaseJS
Jan 17 2018 14:00
@Yorokobi05 maybe just not microsoft Edge
Joy
@Yorokobi05
Jan 17 2018 14:00
ok, thanks. I'll try again. :)
Tom
@moT01
Jan 17 2018 14:12
@Braillon7 any luck? what are you trying to do? - you add the active class but there's no style for it
ehutchllew
@ehutchllew
Jan 17 2018 14:46
@Braillon7 the event handler is working, but your task-form element seems to be hidden, at least on my screen.
@relentless-coder if you need further help with react, let me know, I work with it daily hehe.
Emil
@aguyinmontreal
Jan 17 2018 15:37
Hi everyone! Does someone knows how jquery ajax exactly determines what is a "fail" in $.ajax.fail ? I can't find the documentation for it :/
Omar Tan
@wheelhot
Jan 17 2018 15:39

Woo hoo! Finally completed Twitch.tv project!

https://codepen.io/wheelhot/full/XVxyEK/

Oddly there’s some weird scaling behaviour on codepen, I don’t get this issue on the various browsers I tested

ehutchllew
@ehutchllew
Jan 17 2018 15:41
@aguyinmontreal been a while since i've used jQuery's ajax call, but isn't there an "error" parameter when you fill out the request object?
Kaz Baig
@kbaig
Jan 17 2018 15:41

@aguyinmontreal From the jquery.ajax documentation:

jqXHR.fail(function( jqXHR, textStatus, errorThrown ) {});
An alternative construct to the error callback option, the .fail() method replaces the deprecated .error() method. Refer to deferred.fail() for implementation details.

The jqXHR objects returned by $.ajax()
Stephen James
@sjames1958gm
Jan 17 2018 15:43
@wheelhot :+1:
Kaz Baig
@kbaig
Jan 17 2018 15:43
@ehutchllew nice! Maybe consider subtle borders for the thumbnails to improve contrast with the background?
(and also potentially slightly rounded borders)
The text on thumbnail hover is overflowing for me in some cases when I keep the browser wide but make it a bit shorter
Emil
@aguyinmontreal
Jan 17 2018 15:46

@ehutchllew @kbaig I'm talking about this example : var jqxhr = $.get( "example.php", function() { alert( "success" ); }) .done(function() { alert( "second success" ); }) .fail(function() { alert( "error" ); }) .always(function() { alert( "finished" ); }); see here: http://api.jquery.com/jQuery.get/

No matter what response is sent by my server, my front-end code uses the ".fail" and not the ".done" code. So, I wanted to know what are the specs for the ".fail" condition.

Kaz Baig
@kbaig
Jan 17 2018 15:47
@aguyinmontreal what does the error say?
if there is one
Emil
@aguyinmontreal
Jan 17 2018 15:48
What is a "failure" exactly?
Kaz Baig
@kbaig
Jan 17 2018 15:48
If the call fails for whatever reason
As seen above, the params of jqXHR.fail are errors, so try logging those to see what's going on
Emil
@aguyinmontreal
Jan 17 2018 15:50
@kbaig no error on console, I will try to log the error, thanks
CamperBot
@camperbot
Jan 17 2018 15:50
aguyinmontreal sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
:cookie: 531 | @kbaig |http://www.freecodecamp.org/kbaig
Ayush Bahuguna
@relentless-coder
Jan 17 2018 15:54
@ehutchllew hey, yes, so I have started learning since last weekend, and so far I have managed to setup a dummy app, it has no css styles though, could you give my code a quick glance, and point out the bad practices? https://github.com/relentless-coder/expense-management I had built this project on Angular, but then to learn better, I replaced the client with React.
Ayush Bahuguna
@relentless-coder
Jan 17 2018 16:02
@aguyinmontreal could you share your code? From my understanding, XMLHTTPRequest consider a request as a failure when the response code received from the server is 400 series and 500 series, now as far as promises are concerned, it's probable that code inside your .done() is throwing an error that .fail() is collecting.
ehutchllew
@ehutchllew
Jan 17 2018 16:04
@relentless-coder cool, i'll take a look
Emil
@aguyinmontreal
Jan 17 2018 16:11
@relentless-coder this is what I get when logging what's inside the .fail() : "readyState":4,"responseText":"OK","status":200,"statusText":"OK"
Ayush Bahuguna
@relentless-coder
Jan 17 2018 16:15
@aguyinmontreal No, but the code, I can help you better if I know the context, how are you using the ajax call?
@ehutchllew thank you
CamperBot
@camperbot
Jan 17 2018 16:16
relentless-coder sends brownie points to @ehutchllew :sparkles: :thumbsup: :sparkles:
:cookie: 366 | @ehutchllew |http://www.freecodecamp.org/ehutchllew
Amit Patel
@AmitP88
Jan 17 2018 16:17

@Braillon7 nah, still stuck :worried: here's what I have so far:


function largestOfFour(arr) {
  // You can do this!



  // loop through all the sub-arrays
  for(var i = 0; i < arr.length; i++) {
    for(var j = 0; j < arr[i].length; j++) {
       var maxElement = Math.max.apply(null, arr[i]);      
    }
  }


  var maxArray = arr.map(function() {
    return maxElement;      
  });


  return maxArray;

}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

I'm getting [1001,1001,1001,1001] for the output

ugh, I know it must either be something to do with my for-loop or my map method, but I have no idea how to solve this
Ayush Bahuguna
@relentless-coder
Jan 17 2018 16:20
@AmitP88 so you have to return an array containing the max element for each array?
Amit Patel
@AmitP88
Jan 17 2018 16:20
@relentless-coder yeah, it's the Return Largest Numbers in an Array algorithm problem
been stuck on this for about a day now
Eric Weiss
@eweiss17
Jan 17 2018 16:21
aren't you just immediately overwriting maxElement before returning it
Ayush Bahuguna
@relentless-coder
Jan 17 2018 16:21
@AmitP88 no worries, could you explain me your point of view? What do you think can solve this?
@AmitP88 How about you explain yourself the code that you have written on a piece of paper, going through each step
Amit Patel
@AmitP88
Jan 17 2018 16:22
I'm able to get the highest number from one of the sub-arrays, and i'm able to use the map method to put that in a new array, but I need to be able to loop through all the sub arrays to get all the highest elements, then place all those in the new array via map method. My issue is, I can't figure out how my loop should be in order to do this. I've tried the simple loop and multidimensional loop, but I'm having a tough time seeing the logic solution
Ayush Bahuguna
@relentless-coder
Jan 17 2018 16:22
@AmitP88 if it makes you feel better, you are only two correct steps away from solving this
Amit Patel
@AmitP88
Jan 17 2018 16:23
@relentless-coder it does. Thanks man. I know I'm close, it's just, I can't see the logic yet to connect it together
CamperBot
@camperbot
Jan 17 2018 16:23
amitp88 sends brownie points to @relentless-coder :sparkles: :thumbsup: :sparkles:
:cookie: 384 | @relentless-coder |http://www.freecodecamp.org/relentless-coder
Ayush Bahuguna
@relentless-coder
Jan 17 2018 16:24
@AmitP88 1st: You don't need map in your code, 2nd: Take a strong hard look at your maxElement variable inside the second loop, do you think it's working as expected?
Amit Patel
@AmitP88
Jan 17 2018 16:24
@eweiss17 I think so. But I also tried using the map method in the for loop to avoid this, but then I run into errors
Ayush Bahuguna
@relentless-coder
Jan 17 2018 16:25
@AmitP88 also, you have used map incorrectly, in case you are still fixated at using map to solve your problem
Eric Weiss
@eweiss17
Jan 17 2018 16:26
the result is a new array with the max values?
Amit Patel
@AmitP88
Jan 17 2018 16:26

@relentless-coder in the loop, I don't think it is. But, if I just had the maxElement variable alone, and use this instead:

var maxElement = Math.max.apply(null, arr[0]);

then it returns the highest element in the first sub-array

Eric Weiss
@eweiss17
Jan 17 2018 16:26
can you just push the highest values on an array if map is giving problems
Amit Patel
@AmitP88
Jan 17 2018 16:26
@eweiss17 yup, that's the goal at least
I was just thinking of that actually. just creating a new variable set to an empty array, then use .push to place the elements in
Ayush Bahuguna
@relentless-coder
Jan 17 2018 16:28
@AmitP88 pull the maxElement outside your second loop, then after the second loop push the maxElement into an array
Kaz Baig
@kbaig
Jan 17 2018 16:28
This would be a relatively simple one liner solution
Nick
@rhozeta
Jan 17 2018 16:29
can anyone help with jQuery animation
Ayush Bahuguna
@relentless-coder
Jan 17 2018 16:29
@kbaig can you share? I have been working towards learning algorithms and datastructures, and I am sure your code could be a part of my arsenal.
Nick
@rhozeta
Jan 17 2018 16:29
$(document).ready(function(){

var $truck = $('#truck')


$truck.click(function (){

    $truck.animate({right: "300px"});
});

});
however when clicking no animation occurs
Kaz Baig
@kbaig
Jan 17 2018 16:30
to return an array that contains max of each subarray
function largestOfEach(arr) {
  return arr.map(subArr => Math.max(...subArr));
}
Ayush Bahuguna
@relentless-coder
Jan 17 2018 16:30
@rhozeta right property doesn't work with static DOM elements
Muhammed Hafiz
@zifahm
Jan 17 2018 16:30
Could anyone tell me why is this not rendering
https://codepen.io/m_zifah/pen/MrPZZO?editors=0011
console doesnt give any errors, i tried without the map and it works fine
Kaz Baig
@kbaig
Jan 17 2018 16:30
@relentless-coder ^
Ayush Bahuguna
@relentless-coder
Jan 17 2018 16:31
@kbaig what would you say is the complexity of your solution?
Amit Patel
@AmitP88
Jan 17 2018 16:31

@relentless-coder


function largestOfFour(arr) {
  // You can do this!



  // loop through all the sub-arrays
  for(var i = 0; i < arr.length; i++) {
    for(var j = 0; j < arr[i].length; j++) {
         var newArray = [];
          newArray.push(maxElement);

      return newArray;       
    }

       var maxElement = Math.max.apply(null, arr[i]);


  }




}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

Hmm, I'm doing something wrong :(

Nick
@rhozeta
Jan 17 2018 16:31
@relentless-coder what would be my option for animating that then?
Emil
@aguyinmontreal
Jan 17 2018 16:32
@kbaig Thank you so much!! I don't know why I didn't find this myself when I looked on stackoverflow!
CamperBot
@camperbot
Jan 17 2018 16:32
aguyinmontreal sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
api offline
Eric Weiss
@eweiss17
Jan 17 2018 16:33
@AmitP88 i got a solution using your method, ditch the j loop and go from there
Emil
@aguyinmontreal
Jan 17 2018 16:33
@relentless-coder kbaig found the issue ;) (for my issue, sorry to interrupt) https://stackoverflow.com/questions/6186770/ajax-request-returns-200-ok-but-an-error-event-is-fired-instead-of-success
Toni Shortsleeve
@KoniKodes
Jan 17 2018 16:34
@zifahm Try changing document.getElementById to document.querySelector
Ayush Bahuguna
@relentless-coder
Jan 17 2018 16:34
@aguyinmontreal told you that it was highly probable that promise was throwing error
Emil
@aguyinmontreal
Jan 17 2018 16:34
@relentless-coder thanks
CamperBot
@camperbot
Jan 17 2018 16:34
aguyinmontreal sends brownie points to @relentless-coder :sparkles: :thumbsup: :sparkles:
:cookie: 385 | @relentless-coder |http://www.freecodecamp.org/relentless-coder
Amit Patel
@AmitP88
Jan 17 2018 16:35

@eweiss17


function largestOfFour(arr) {
  // You can do this!



  // loop through all the sub-arrays
  for(var i = 0; i < arr.length; i++) {

       var maxElement = Math.max.apply(null, arr[i]);  
       var newArray = [];
       newArray.push(maxElement);

      return newArray;     
  }




}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

Here's what I did after ditching the j loop like you suggested

Nick
@rhozeta
Jan 17 2018 16:35
@relentless-coder how would I go about animating that static element?
ehutchllew
@ehutchllew
Jan 17 2018 16:35
@zifahm not familiar with panel group but have you tried adding any styling?
Ayush Bahuguna
@relentless-coder
Jan 17 2018 16:35
@rhozeta translate
Eric Weiss
@eweiss17
Jan 17 2018 16:35
did it work?
Muhammed Hafiz
@zifahm
Jan 17 2018 16:35
@KoniKodes nope no change
Amit Patel
@AmitP88
Jan 17 2018 16:35
@eweiss17 the output now is [5]
Ayush Bahuguna
@relentless-coder
Jan 17 2018 16:35
@rhozeta i mean the translate3d
Muhammed Hafiz
@zifahm
Jan 17 2018 16:36
@ehutchllew when i try without the map func it works fine
Eric Weiss
@eweiss17
Jan 17 2018 16:36
return newArray outside of the for loop
Nick
@rhozeta
Jan 17 2018 16:36
@relentless-coder so I would have to use #truck.css({translate3d: x,x,x });
Amit Patel
@AmitP88
Jan 17 2018 16:36
@eweiss17 now I get [1001]
ehutchllew
@ehutchllew
Jan 17 2018 16:37
@zifahm try defining your state inside the constructor:
constructor(){
super();
this.state = {}
}
Amit Patel
@AmitP88
Jan 17 2018 16:37
@eweiss17 it also says that return newArray is out of scope
Muhammed Hafiz
@zifahm
Jan 17 2018 16:37
@ehutchllew i tried that too
Ayush Bahuguna
@relentless-coder
Jan 17 2018 16:37
@rhozeta I am sorry if this going to sound rude, but kindly look up translate3d property on Google, and take it from there :)
ehutchllew
@ehutchllew
Jan 17 2018 16:38
@zifahm remove the logic from the render method, create your own class methods and then render based off of their output.
Amit Patel
@AmitP88
Jan 17 2018 16:38
@eweiss17 just solved it by moving var newArray=[] outside of scope
Ayush Bahuguna
@relentless-coder
Jan 17 2018 16:38
@AmitP88 why are you so obsessed with the correct solution? Instead think of your approach
Eric Weiss
@eweiss17
Jan 17 2018 16:38
great
Kaz Baig
@kbaig
Jan 17 2018 16:38
@relentless-coder no clue what the technical answer would be to that but it def is a pretty computationally minimally expensive solution, assuming the operators and methods work efficiently
Amit Patel
@AmitP88
Jan 17 2018 16:39
@relentless-coder lol because I've been stuck on this for hours and hours. but yeah, you're right. I need to focus on the steps and strategy, not the solution itself
Muhammed Hafiz
@zifahm
Jan 17 2018 16:39
@ehutchllew like functions to handle output?
could you give an example
Amit Patel
@AmitP88
Jan 17 2018 16:39
after getting it to work thanks to @eweiss17 and @relentless-coder , I now see that I was waaaaaaay overthinking this.
CamperBot
@camperbot
Jan 17 2018 16:39
amitp88 sends brownie points to @eweiss17 and @relentless-coder :sparkles: :thumbsup: :sparkles:
api offline
:cookie: 603 | @eweiss17 |http://www.freecodecamp.org/eweiss17
Ayush Bahuguna
@relentless-coder
Jan 17 2018 16:40
@kbaig what's the basis of your response?
@kbaig leave it, I am going crazy due to AWS Developer Support's service.
Amit Patel
@AmitP88
Jan 17 2018 16:40
I need to take the absolute simplest approach to problems now. thanks guys :) I'll restudy this solution for a while, make sure I get the lesson lol
ehutchllew
@ehutchllew
Jan 17 2018 16:41
@zifahm yeah, like
_getRecipes(){
   this.state.map( () => {
   // logic goes here, then return
    }
}

render(){
  return(
      {this._getRecipes()}
);
}
Muhammed Hafiz
@zifahm
Jan 17 2018 16:41
@ehutchllew okay let me try :smile:
Kaz Baig
@kbaig
Jan 17 2018 16:41
@relentless-coder well the fastest way to do it logically would be to replace each item in the array with the highest item in the array, which is what I'm doing
ehutchllew
@ehutchllew
Jan 17 2018 16:42
@zifahm Or instead of directly calling the function in the render return, try setting the function output to constructor variables or state variables and then populating your HTML based off of said variables.
Kaz Baig
@kbaig
Jan 17 2018 16:42
It would be faster if you used for loops probably since apparently they're faster than Array methods
ehutchllew
@ehutchllew
Jan 17 2018 16:42
@kbaig If I'm not mistaken, map and forEach are faster than for
I could be wrong though, I'm not an expert haha
Toni Shortsleeve
@KoniKodes
Jan 17 2018 16:45
@zifahm I'm sorry. I do think @ehutchllew is correct.
Muhammed Hafiz
@zifahm
Jan 17 2018 16:45
what to do
ehutchllew
@ehutchllew
Jan 17 2018 16:46
@zifahm okay so my suggestion is, if it's still not working, take a step back and just get something extremely basic to render like: <div><p> HI </p> </div> add some styling to it to make sure it's not empty, and then work up from there.
Muhammed Hafiz
@zifahm
Jan 17 2018 16:47
okay
@ehutchllew see now it renders without the map
ehutchllew
@ehutchllew
Jan 17 2018 16:55
@zifahm Okay I'm testing some stuff gimme one sec
Muhammed Hafiz
@zifahm
Jan 17 2018 16:56
@ehutchllew thank you
CamperBot
@camperbot
Jan 17 2018 16:56
zifahm sends brownie points to @ehutchllew :sparkles: :thumbsup: :sparkles:
:cookie: 367 | @ehutchllew |http://www.freecodecamp.org/ehutchllew
ehutchllew
@ehutchllew
Jan 17 2018 17:05
@zifahm So I've never used react on codepen, but when I check what the return is on a map function it just says function() { [native code] } trying to figure out what is going on.
Muhammed Hafiz
@zifahm
Jan 17 2018 17:06
i typed h1 above map and it renders @ehutchllew
Kaz Baig
@kbaig
Jan 17 2018 17:07
@ehutchllew [native code] refers to code native to the browser, might need more context
ehutchllew
@ehutchllew
Jan 17 2018 17:08
@zifahm yeah, it's not liking the expression in the html for some reason, going to try storing values on a state variable and re-rendering. Hold up.
Muhammed Hafiz
@zifahm
Jan 17 2018 17:09
how am i suppose to complete this challenge without codepen?
LydaTech
@lydatech
Jan 17 2018 17:12
@zifahm why cant you use codepen?
ehutchllew
@ehutchllew
Jan 17 2018 17:15
@zifahm this is weird, using map or forEach seems to break it.
Muhammed Hafiz
@zifahm
Jan 17 2018 17:15
@lydatech this code dosent render when there is map func in it, i took out the map and it renders quite fine, and there is no errors in console log
https://codepen.io/m_zifah/pen/MrPZZO?editors=1010
@ehutchllew hmm
ehutchllew
@ehutchllew
Jan 17 2018 17:17
@zifahm ugh i figured it out
i'm so dumb, forgot about it.
Stephen James
@sjames1958gm
Jan 17 2018 17:17
@zifahm Your maps need return if you use {} for arrow functions
ehutchllew
@ehutchllew
Jan 17 2018 17:17
@sjames1958gm tried with return as well, nothing. I did this and it worked:
_getRecipeTitles(){
    let arr = [];
    this.state.recipes.forEach((item) => {
      arr.push(<h1>{item.title}</h1>)
    });
    return arr;   
  }
I forgot that react renders elements/components in arrays.
Muhammed Hafiz
@zifahm
Jan 17 2018 17:18
@sjames1958gm @ehutchllew ohhh
return
Stephen James
@sjames1958gm
Jan 17 2018 17:19
@zifahm If you use () then it automatically returns
Muhammed Hafiz
@zifahm
Jan 17 2018 17:20
@sjames1958gm @ehutchllew thank you so much guys
CamperBot
@camperbot
Jan 17 2018 17:20
zifahm sends brownie points to @sjames1958gm and @ehutchllew :sparkles: :thumbsup: :sparkles:
api offline
:star2: 8865 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
ehutchllew
@ehutchllew
Jan 17 2018 17:20
@zifahm did it work with just a return or did it require an array as well?
Muhammed Hafiz
@zifahm
Jan 17 2018 17:20
ehutchllew
@ehutchllew
Jan 17 2018 17:20
sweet
Muhammed Hafiz
@zifahm
Jan 17 2018 17:21
:)
Stephen James
@sjames1958gm
Jan 17 2018 17:21
@zifahm I forget that often, so I saw it pretty quickly :)
Muhammed Hafiz
@zifahm
Jan 17 2018 17:27
@sjames1958gm :)
dinesh
@1532j0004kg
Jan 17 2018 17:29
hi james
yogiwhocodes
@yogiwhocodes
Jan 17 2018 17:36
Hi everyone, just discovered this chat here and don't know if this is the right place to ask... I'm working on the random quote machine and I'm stuck with my twitter button. I wanna use the .attr method to push the quote into the twitter 'data-text' field but can't figure out how to implement it. Could somebody maybe help me out there? This is my codepen (please ignore the design!) https://codepen.io/yogiwhocodes/pen/ZvOmyd
Ken Haduch
@khaduch
Jan 17 2018 18:18
@yogiwhocodes - hello. Not sure about the twitter button just yet, but looking at the page. One suggestion - get a quote to populate your quote box or put some text in there to begin with - maybe a favorite quote? And something like "Click the button for new quotes"... ?
Ken Haduch
@khaduch
Jan 17 2018 18:28
@yogiwhocodes - one problem is that there is no button or element with the id twitter-btn, at least it doesn't appear to be there? I think that after running that twitter code, it makes its own element on the page. Going to look at the docs to see how they recommend updating it.
Aditya
@ezioda004
Jan 17 2018 18:31
@khaduch There is an <a> with that id, trying to debug too but no idea why it is acting this way.
Ken Haduch
@khaduch
Jan 17 2018 18:37
@ezioda004 - I've been confused about this twitter intent thing for a while. I found another method to do it, but this seems like a way that is supposed to work. Still looking... @yogiwhocodes
Aditya
@ezioda004
Jan 17 2018 18:41
@khaduch I meant this code is weird like I commented the whole $("#twitter-btn") click event out and its still working like before
I think its because of this part of the code
window.twttr = (function(d, s, id) {
  var js,
    fjs = d.getElementsByTagName(s)[0],
    t = window.twttr || {};
  if (d.getElementById(id)) return t;
  js = d.createElement(s);
  js.id = id;
  js.src = "https://platform.twitter.com/widgets.js";
  fjs.parentNode.insertBefore(js, fjs);

  t._e = [];
  t.ready = function(f) {
    t._e.push(f);
  };
  return t;
})(document, "script", "twitter-wjs");
Ken Haduch
@khaduch
Jan 17 2018 18:49

@ezioda004 @yogiwhocodes - that is what I was referring to in my comment about "twitter code". I have something that works, based on information that I found on stackoverflow. It doesn't style the button, but I think that you can make the HTML code to do that. This is something that updates the link with the new tweet (some formatting, like removing the <p> tags) would be a good thing to do.

        var tbutton = $('.twitter-share-button');
        var theQuote = encodeURIComponent(receivedQuote[0].content + receivedQuote[0].title);
        tbutton.attr('href', 'https://twitter.com/intent/tweet?text=' + theQuote);

See if that works for you?

Aditya
@ezioda004
Jan 17 2018 18:56
@khaduch Yeah this'd work but isnt windows.open better to use instead of changing the href of the anchor tag? Cause apparently @yogiwhocodes was also going for that (last part of the code)
Ken Haduch
@khaduch
Jan 17 2018 19:03

@ezioda004 - well, I should have added that I changed the code for the button to add a target="_blank" into the anchor, so that it would open in a separate window.

One thing to be cautious of, in the way that @yogiwhocodes is trying to do it, is that this code:

$("#twitter-btn").on("click", function() {
  window.open(
    "https://twitter.com/intent/tweet?text=" +
      encodeURIComponent($("#quote").text())
  );

would have to be run every time you get a new quote because it is only setting up the click handler one time. And you would have to make sure to remove the click handler prior to updating the new one. Running that twitter intent code (the code that you posted above) to me seems to be geared to building a single tweet button that sends pre-determined text. Not to say that it cannot be made to work, but it seems that the method that I posted above (taken from that stackoverflow post and massaged a little) can be made to work. Maybe there is a better twitter method to do what you and @yogiwhocodes are trying to do?

Ken Haduch
@khaduch
Jan 17 2018 19:08

@ezioda004 @yogiwhocodes - okay, one more pass at this, after a little more thought. I removed the code that I added in this post (from my working copy of the quote button) :point_up: January 17, 2018 1:49 PM and modified the click handler to look like this:

$("#twitter-btn").on("click", function() {
  var getQuote = encodeURIComponent($("#quote").text())
  window.open(
    "https://twitter.com/intent/tweet?text=" + getQuote

  );
});

So that it actually reads the #quote text from the HTML DOM. And that seems to work, at least it gets the updated quotes. Still doesn't have the pretty twitter button, but the HTML could be tweaked. Or maybe it will play nicely with the twitter code? (No, it won't work once you run that twitter function... so I'm leaving it as I had it. I'll save a fork of @yogiwhocodes pen and I have to go and shovel some snow...)

Aditya
@ezioda004
Jan 17 2018 19:10
@khaduch Yes, thats how I did too, you get the text() from the <p> or whatever you stored them in
Ken Haduch
@khaduch
Jan 17 2018 19:12
@yogiwhocodes @ezioda004 - this is the forked copy of the pen that is mostly working - just for reference
Tychro van den Broeke
@tychro
Jan 17 2018 19:12
does anyone know how to get the time and date in JS linked to my HTML?
Aditya
@ezioda004
Jan 17 2018 19:12
Current time?
Tychro van den Broeke
@tychro
Jan 17 2018 19:13
yes
and the date
yozhikvtumane
@yozhikvtumane
Jan 17 2018 19:13
Hello! I am currently doing Twitch project and I subscribed to FreeCodeCamp channel, but I can't see it in object I get from the server
Aditya
@ezioda004
Jan 17 2018 19:15
@tychro
var d = new Date();
var n = d.getDate();
To get the current date
Tychro van den Broeke
@tychro
Jan 17 2018 19:15
is time the same?
Aditya
@ezioda004
Jan 17 2018 19:17

Kinda, you'd have to do something like

d.getHours(); 
d.getMinutes(); 
d.getSeconds();

and concatenate them

@yozhikvtumane Can you post your codepen link?
Kaz Baig
@kbaig
Jan 17 2018 19:19
There's also a bunch of methods on Date to get the string in different formats, found in the Conversion getter section of the Date documentation
Aditya
@ezioda004
Jan 17 2018 19:20
^
yozhikvtumane
@yozhikvtumane
Jan 17 2018 19:26
Aditya
@ezioda004
Jan 17 2018 19:31
@yozhikvtumane Dont think they let you see the subscribers of a channel, you can only see followers
I am trying to get what the task is asking for
Aditya
@ezioda004
Jan 17 2018 19:35
Yes but youre not requesting from https://api.twitch.tv/kraken/users/<user ID>/follows/channels , the fcc one only takes 3 parameters, unless I'm wrong
yozhikvtumane
@yozhikvtumane
Jan 17 2018 19:36
Aditya
@ezioda004
Jan 17 2018 19:38

This server caches data to lower the request rate. To prevent abuses this server accepts GET requests only, and serves only routes /users/:user, /channels/:channel, and /streams/:stream

None of them returns the list of channels followed by a user.

yozhikvtumane
@yozhikvtumane
Jan 17 2018 19:39
list of channels is in "user" object

This server caches data

How often does it refresh data?

Aditya
@ezioda004
Jan 17 2018 19:42
No idea, maybe someone else knows about this but as far as I know it doesnt return it
grantknaver
@grantknaver
Jan 17 2018 19:45
anyone familiar with firebase?
yozhikvtumane
@yozhikvtumane
Jan 17 2018 19:52
I think I got it wrong
I don't need to parse the whole list of user's subscriptions and see whether FCC is online or not, I just need to create random list of channels with FCC in it and check them, right?
Samer
@samerx96
Jan 17 2018 20:00
Hey guys
do you think a 256gb macbook pro 15' 2016 with touchpad + iPad pro 4g 128gb for 2260$ is a good deal?
William Watts
@Braillon7
Jan 17 2018 20:07
@ehutchllew @moT01 nope no luck...I can console log an output but i can't seem to get an action out of any class I use https://codepen.io/Braillon7/pen/RxBWbY
William Watts
@Braillon7
Jan 17 2018 20:20
"transform: translate(0, 100%);" is hiding the task-form...once commented out you can see it
Dan Lafferty
@DanLaff
Jan 17 2018 20:39
@Braillon7 I'm looking at your code and your jQuery call is trying to add an "active" class to all elements with the 'task-form' class. You don't have .active defined in your CSS. Perhaps you're confusing it with the active selector? A class named "active" is not the same as ":active". Also, your CSS has invalid comments in it - // is for JavaScript. CSS needs /* */
I'm having trouble figuring out what you're trying to accomplish by scanning above - if you can summarize, I'm happy to take a closer look
ehutchllew
@ehutchllew
Jan 17 2018 20:41
@Braillon7 fixed it. Sorry couldn't respond, internet went out.
@Braillon7 @DanLaff Like Dan said, you have to change .task-form:active to .task-form.active
Dan Lafferty
@DanLaff
Jan 17 2018 20:57
If it's a matter of opening/closing the form with a sliding motion, remove the transition and transform code from your CSS and change your jQuery to:
$(".add-circle, .close-btn").on("click", () => $(".task-form").slideToggle());
William Watts
@Braillon7
Jan 17 2018 21:03
wow you guys were a lot of help...I feel like an idiot. I thought I already tried that before as I originally had &.active and it wasn't working. This was a simple as a fix as I assumed it would be and believe it or not I spent all day trying to figure it out lol
@ehutchllew thank you
CamperBot
@camperbot
Jan 17 2018 21:03
braillon7 sends brownie points to @ehutchllew :sparkles: :thumbsup: :sparkles:
:cookie: 368 | @ehutchllew |http://www.freecodecamp.org/ehutchllew
William Watts
@Braillon7
Jan 17 2018 21:03
@DanLaff thank you
Brandon Blackwell
@Radlerz1
Jan 17 2018 21:04

hello, if i have an object like this

randomObject : {
name: 'randomName',
age: 34
}

is there a way I can update name without knowing that the object is randomObject?

William Watts
@Braillon7
Jan 17 2018 21:04
hmmm how come @DanLaff didn't get any brownie points? give the man his brownie points lol
Dan Lafferty
@DanLaff
Jan 17 2018 21:05
I'm not a camper, just visiting to practice coding while helping others in the process
@Radlerz1 Object.keys() should help you with that
William Watts
@Braillon7
Jan 17 2018 21:06
lol oh...well thank you kind Sir! @DanLaff
CamperBot
@camperbot
Jan 17 2018 21:06
braillon7 sends brownie points to @danlaff :sparkles: :thumbsup: :sparkles:
api offline
Dan Lafferty
@DanLaff
Jan 17 2018 21:06
Happy to help :)
Brandon Blackwell
@Radlerz1
Jan 17 2018 21:06
{
_id: "5a5fa8998e0cb9206c0d33a7",
__v: 0,
twitter: {
id: "786553098864963584"
}
}
what about that? how do I update name without knowing its twiter? it could be google, facebook, or twitter. Object.keys returns some random stuff I tried
Object.keys returns this [ '$__', 'isNew', 'errors', '_doc', '$init' ]
Dan Lafferty
@DanLaff
Jan 17 2018 21:10
@Radlerz1 You can also use for...in:
let myObj = {
  randomObject1: {
    name: "randomName",
    age: 34
  },
};

for (let obj in myObj) {
  if (myObj[obj].name === "randomName") console.log(myObj[obj].age); // 34 is logged
}
And with Object.keys():
console.log(myObj[Object.keys(myObj)].age) // 34 gets logged