These are chat archives for FreeCodeCamp/HelpJavaScript

7th
Aug 2017
techhamster
@techhamster
Aug 07 2017 01:23
Hi guys. I recently learned how to add Event listeners for clicking buttons and decided to experiment with hiding and showing an element. https://codepen.io/techhamster/pen/xLgWLy?editors=1011
I tried the if statements but it wouldnt hide back :(
Stephen James
@sjames1958gm
Aug 07 2017 01:27
@techhamster "false" is a string not the value false - you don't ever reset back to true - I would do else not a second if
techhamster
@techhamster
Aug 07 2017 01:28
@sjames1958gm I've tried the else thing but it still doesnt unhide it
Stephen James
@sjames1958gm
Aug 07 2017 01:30
@techhamster something weird is happening
Stephen James
@sjames1958gm
Aug 07 2017 01:39
@techhamster Not sure if status has some special meaning? this worked:
var show= true;


button.addEventListener("click", function(){
  console.log("here");
  if  (show) {
  console.log("a" + show)
    h1.style.display="none";
    ////////////
  } else {
  console.log("b" + show)
    h1.style.display="block";
  }
  show = !show;
});
status kept getting reset to a string?
techhamster
@techhamster
Aug 07 2017 01:41
@sjames1958gm Thanks dude! maybe status was a special js word just my luck haha..
CamperBot
@camperbot
Aug 07 2017 01:41
techhamster sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8259 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 07 2017 01:41
@techhamster Yeah, weird - might be something specific to codepen
kumquatfelafel
@kumquatfelafel
Aug 07 2017 01:56
status isn't a reserved word in javascript itself, but there appear to be a number of other statuses outside of the given script. Maybe one of them is causing a problem somehow. That being said, I don't feel like reading through to find out. :p
kumquatfelafel
@kumquatfelafel
Aug 07 2017 02:18

hrm... status is resulting in string when declared outside of addEventListener (initialized inside, treated as normal boolean (of course, doing this would result in own set of problems.))

When console.log(typeof status) without defining it at all, status typeof is still string, albeit an empty string.

On the other hand, when console.log(typeof show) without defining it at all, result is undefined.
moshe18
@moshe18
Aug 07 2017 02:21
\
kumquatfelafel
@kumquatfelafel
Aug 07 2017 02:21
/
kumquatfelafel
@kumquatfelafel
Aug 07 2017 02:35
@sjames1958gm yeah... so it's definitely converting the value in status to a string pretty much immediately.
Markus Kiili
@Masd925
Aug 07 2017 04:52
@kumquatfelafel status is a global property. https://developer.mozilla.org/en-US/docs/Web/API/Window/status There are other properties like that that automatically coerce the assigned value to a string.
For example name.
@techhamster @sjames1958gm
insouciantone
@insouciantone
Aug 07 2017 05:58
Hey all. Why isn't this showing the location values for my geolocation request in the html element?
Markus Kiili
@Masd925
Aug 07 2017 06:01
@insouciantone Check for any errors on the developer tools console.
F12 on some browsers.
insouciantone
@insouciantone
Aug 07 2017 06:04
@Masd925 The only errors I get are for calling the image over an unsecured HTTP url and a 404 for a GET @ the url https://s.codepen.io/boomerang/iFrameKey-5af2db0d-ec4b-5fa9-8866-aa4fe72f63f3/style.css
which I assume is happening because of my src call in the html
Markus Kiili
@Masd925
Aug 07 2017 06:05
@insouciantone It is a http/https mixed content error.
insouciantone
@insouciantone
Aug 07 2017 06:06
@Masd925 Even when I delete the whole image attribution it still won't call the location though
Markus Kiili
@Masd925
Aug 07 2017 06:07
@insouciantone Try to console.log what is happening. Is the callback function executing etc.
insouciantone
@insouciantone
Aug 07 2017 06:08
position is returning as undefined.
going to have to go over the documentation for the function most likely. I'm probably using it wrong.
insouciantone
@insouciantone
Aug 07 2017 06:21
Hurray I fixed it.
Markus Kiili
@Masd925
Aug 07 2017 06:23
@insouciantone :+1:
insouciantone
@insouciantone
Aug 07 2017 06:28
Now the real fun begins.
help?
Markus Kiili
@Masd925
Aug 07 2017 06:34
@SimpleProgrammerL Copy paste the code here and describe the problem you are having.
Letty
@SimpleProgrammerL
Aug 07 2017 06:34
Introducing JavaScript Object Notation JSON
How do you do this
insouciantone
@insouciantone
Aug 07 2017 06:35
go to the website and copy the code and paste it here
then describe your problem
Letty
@SimpleProgrammerL
Aug 07 2017 06:36
ok
var myMusic = [
{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}
//Please add an album here
];
Problem: Add a new album to the JSON object of myMusic. Add artist and title strings, release_year Numbers and formats string arrays
OliverHao233
@OliverHao233
Aug 07 2017 06:40
You can add the new album after the old album.
Markus Kiili
@Masd925
Aug 07 2017 06:40
@SimpleProgrammerL The literal needs to be like =[{...},{...}]
OliverHao233
@OliverHao233
Aug 07 2017 06:41
right
Markus Kiili
@Masd925
Aug 07 2017 06:41
Another way is to push a new object into myMusic. That should work too.
Letty
@SimpleProgrammerL
Aug 07 2017 06:55
@Masd925 @OliverHao233 @insouciantone Thank you very much
CamperBot
@camperbot
Aug 07 2017 06:55
simpleprogrammerl sends brownie points to @masd925 and @oliverhao233 and @insouciantone :sparkles: :thumbsup: :sparkles:
:cookie: 294 | @insouciantone |http://www.freecodecamp.com/insouciantone
:cookie: 3 | @oliverhao233 |http://www.freecodecamp.com/oliverhao233
:star2: 4382 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Aug 07 2017 07:01
@SimpleProgrammerL Notice that that challenge deals with JS objects and not with actual JSON (that is a string format). JS object literals just can usually be written to look like JSON.
AdamCS
@csikos3d
Aug 07 2017 07:05
Someone pls have any idea why this is not working?
//TRAIN DATAS function
function getTrainData(){
  $.getJSON(trnDataFix, function(tdd){
    trainCategories = tdd.map(trainf => trainf.trainCategory);

    showTrainData();

    });
}


function showTrainData() {
  $("#table .card").each(function(i) {
   $(this).append(trainCategories[i]);

  });
}


$(function() {
  getTrainData();

});
Markus Kiili
@Masd925
Aug 07 2017 07:07
@csikos3d Look for any errors on developer tools console and then log the ajax response tdd to see if it is coming.
AdamCS
@csikos3d
Aug 07 2017 07:11
@Masd925 it's definitely not coming. but the question is why? I have a almost same functon with a different JSON and it is working fine
Markus Kiili
@Masd925
Aug 07 2017 07:13
@csikos3d Any errors on developer tools console?
AdamCS
@csikos3d
Aug 07 2017 07:14
the only thing what it gives: undefined
Markus Kiili
@Masd925
Aug 07 2017 07:15
@csikos3d Do you have it on codepen so you could give a link to the code?
AdamCS
@csikos3d
Aug 07 2017 07:17
@Masd925 yes, of course but this is a test installments so it is not that clean than this copy-paste was.
Markus Kiili
@Masd925
Aug 07 2017 07:18
@csikos3d There are errors on browser developer tools console.
F12 on some browsers.
AdamCS
@csikos3d
Aug 07 2017 07:19
@Masd925 yes fo rthe whole pen. But not for that segment what i showd previously
Markus Kiili
@Masd925
Aug 07 2017 07:19
tdd.map is not a function
Yeah, because it returns undefined.
AdamCS
@csikos3d
Aug 07 2017 07:21
@Masd925 where did you see that.? Honestly i am not to good in debugging this is why I was ask :-)
why this is not a function? You can see there is getStationData function completely the same
and has no problem to run
but i have no idea...this is why I am confused
Markus Kiili
@Masd925
Aug 07 2017 07:23
@csikos3d Did you log tdd. If it is undefined, JS will throw an error if you use an array method on it.
@csikos3d If the response comes, tdd should be an object, not an array. The response json is like "{...}" so not an array.
So map doesn't work on it.
AdamCS
@csikos3d
Aug 07 2017 07:30
@Masd925 i just dont understand , the same things working in the get station. As matter of fact i just trying to replicate the same funrtion (getStationData) tho fetch another JSON into the same cells
Markus Kiili
@Masd925
Aug 07 2017 07:32
@csikos3d If you try the trnDataFix url on the browser address bar, you will see that the response is an object. Array methods like map don't work on objects so tdd.map(...) throws an error.
AdamCS
@csikos3d
Aug 07 2017 07:32
@Masd925 .........oh
@Masd925 this is the second time it takes me 2 day to making this stupidity...
@Masd925 than how should i list the needed attributes?
@Masd925 never mind...after this i will figure it out. sorry to bother... thank You :-)
CamperBot
@camperbot
Aug 07 2017 07:35
csikos3d sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4383 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Aug 07 2017 07:38
@csikos3d Object property keys can be looped with for...in loop or by doing a for loop through Object.keys(obj).
Blauelf
@Blauelf
Aug 07 2017 07:40
for..in includes the prototype chain, while Object.keys lists only enumerable own properties, right?
Markus Kiili
@Masd925
Aug 07 2017 07:41
@Blauelf Yeah, both work because there are no inherited enumerable properties on plain objects, but I also like the latter better.
Blauelf
@Blauelf
Aug 07 2017 07:43
I still somewhat struggle with "inherited" in JavaScript's delegation-based "inheritance". It's quite different from inheritance in Java or C++.
Markus Kiili
@Masd925
Aug 07 2017 07:45
@Blauelf Yeah, but it is standard JS terminology. A bit misleading perhaps.
alpox
@alpox
Aug 07 2017 07:49
@Blauelf its just prototypical inheritance in the end
Blauelf
@Blauelf
Aug 07 2017 07:49
I think standard JS terminology is talking about prototypes and delegation, not necessarily about inheritance. Would have to look up the standard (this thing is big, despite the language being so small)
Kelechi Chinaka
@ke1echi
Aug 07 2017 07:50
i think i term prototypical inheritance causes more confusion
Markus Kiili
@Masd925
Aug 07 2017 07:50
@Blauelf I meant that the standard uses it.
Blauelf
@Blauelf
Aug 07 2017 07:50
Just found "prototype-based inheritance" in the standard.
Kelechi Chinaka
@ke1echi
Aug 07 2017 07:51
a good term should be objects linked to other objects OLOO
Blauelf
@Blauelf
Aug 07 2017 07:51
And no mention of "delegation", although I think that's what it is. But maybe the prototype already includes that.
Markus Kiili
@Masd925
Aug 07 2017 07:51
@Blauelf 4.3.31 on the ECMA 5.1 also uses term inherited property.
Blauelf
@Blauelf
Aug 07 2017 07:53
I searched the ES7 specs, and found it there, too.
Markus Kiili
@Masd925
Aug 07 2017 07:53
@alpox Object.create is ES5 so what has it got to do with ES6?
Blauelf
@Blauelf
Aug 07 2017 07:54

@alpox I know, I use this to create dict-like objects (which are vulnerable to special property names), like Object.create(null)

I really appreciate the new Map object.

alpox
@alpox
Aug 07 2017 07:54
@Masd925 ES6 uses what exists in ES5 and just put some sugar syntax on it afaik
Markus Kiili
@Masd925
Aug 07 2017 07:54
@alpox Yes.
Blauelf
@Blauelf
Aug 07 2017 07:57
I think there's slightly more than that, but most of that could be done with external libraries. Map, Promise, stuff like that. I think web components' custom elements require using ES6 classes.
alpox
@alpox
Aug 07 2017 08:01
@Blauelf may be. I dont know exactly what it does behind the scenes. But inheritance in js and es6 is discouraged by lots of frameworks atm. React, Angular 2 and Aurelia advice against using it in favor of composition over inheritance and/or dependency injection
Blauelf
@Blauelf
Aug 07 2017 08:01
Looks like it is possible to write custom elements with ES5. Must have been a restriction of one of the frameworks (was it Angular?) then.
Huỳnh Trần Khanh
@khanh2003
Aug 07 2017 08:01

@alpox A counterexample: Proxy. Link 1 | Link 2

  • babel-plugin-proxy: This plugin is proof of concept, performance impact is huge
  • proxy-polyfill: the properties you want to proxy must be known at creation time

so,

ES6 uses what exists in ES5 and just put some sugar syntax on it afaik

is wrong.

alpox
@alpox
Aug 07 2017 08:02
@khanh2003 :+1: good to know
Blauelf
@Blauelf
Aug 07 2017 08:03
Haven't used Proxy yet, that one always stays outside my scope.
But even for Map, WeakMap (and the Sets), and consistent Promises (and not different concepts for each library), I like ES6.
alpox
@alpox
Aug 07 2017 08:06
@khanh2003 i was speaking about object inheritance at that place though, not really general about all es6 :)
Class inheritance*
Huỳnh Trần Khanh
@khanh2003
Aug 07 2017 08:07
@alpox yeah i was too lazy to scroll
Surendra Karwasra
@skkarwasra02
Aug 07 2017 08:35
when php session automatically destroy?
Owais Ahmed
@owaisehmed
Aug 07 2017 08:48
How can i check for special characters in a string??
Markus Kiili
@Masd925
Aug 07 2017 08:50
@owaisehmed Suitable regexp object.
Owais Ahmed
@owaisehmed
Aug 07 2017 08:55
@Masd925 im not getting the regexp. Please help
Owais Ahmed
@owaisehmed
Aug 07 2017 09:02
How would i check for a special character in a string?
str = "This is a string!";
or str = "This is a string?";
Vishal Nagda
@vishalnagda1
Aug 07 2017 09:08
<div class = "multi-room-row">
              <div class ="multi-room-template hidden" id="test">
                <div class="form-group ">
                  <label class="control-label col-md-4" style="font-weight: bold;" >Room Name
                  </label>
                  <div class="col-md-8">
                    <select class="form-control editable-field booking-room-id" name='id' id='bookingRoomId'>
                      <option value = "">Select Room</option>
                    </select>
                  </div>
                </div>
                <div class="form-group ">
                  <div class="col-md-2"></div>
                  <label class="control-label col-md-4" >Rate Plan
                  </label>
                  <div class="col-md-4">
                    <select class="form-control editable-field rate-plan-id" name='rate_plan_id' id='ratePlanId'>
                      <option value = "">Select RatePlan</option>
                    </select>
                  </div>
                </div>
                <div class="form-group ">
                  <div class="col-md-2"></div>
                  <label class="control-label col-md-4" >Arrival Date
                  </label>
                  <label class="control-label col-md-4" ><input id="arrivalDate" type='text' name='arrival_date' class='form-control editable-field' placeholder="yyyy-mm-dd"></label>
                </div>
                <div class="form-group ">
                  <div class="col-md-2"></div>
                  <label class="control-label col-md-4" >Departure Date
                  </label>
                  <label class="control-label col-md-4" ><input id="departureDate" type='text' name='departure_date' class='form-control editable-field' placeholder="yyyy-mm-dd"></label>
                </div>
                <div class="form-group ">
                  <div class="col-md-2"></div>
                  <label class="control-label col-md-4" >Guest Name
                  </label>
                  <label class="control-label col-md-4" ><input id="guestName" type='text' name='guest_name' class='form-control editable-field' >
                  </label>
                </div>
                <div class="form-group room-party-detail">
                  <div class="col-md-3 col-md-offset-2">
                    <select class="form-control editable-field manual-booking-adults" name="no_of_adults" id="noOfAdults">
                      <option value="1">1 Adult</option>
                      <option value="2">2 Adults</option>
                      <option value="3">3 Adults</option>
                      <option value="4">4 Adults</option>
                      <option value="5">5 Adults</option>
                      <option value="6">6 Adults</option>
                      <option value="7">7 Adults</option>
                      <option value="8">8 Adults</option>
                    </select>
                  </div>
                  <div class="col-md-3 col-md-offset-1">
                    <select class="form-control editable-field manual-booking-childrens" name="no_of_children" id="noOfChildrens">
                      <option value="0">0 Children</option>
                      <option value="1">1 Children</option>
                      <option value="2">2 Childrens</option>
                      <option value="3">3 Childrens</option>
                      <option value="4">4 Childrens</option>
                      <option value="5">5 Childrens</option>
                      <option value="6">6 Childrens</option>
                      <option value="7">7 Childrens</option>
                      <option value="8">8 Childrens</option>
                    </select>
                  </div>
                </div>

                <div class="form-group delete-rooms">
                  <div class="col-md-2"></div>
                  <label class="control-label col-md-8"><button type="button" id="removeRoomButton" class="btn btn-danger">Remove Room</button></label>
                </div>

              </div>
            <
hello friends this my HTML code snippet, In jquery I’m cloning the same.
and all clones has id like multi-room-template-cloned
in it each input has a class called editable-field.
so now I’m trying to get its value like this :
booking_data = {}
var editable_fields = $(".multi-room-template-cloned .editable-field");
      var ids = editable_fields.map(function(index) {
        return this.id;
      });
      var no_of_rooms = $.grep(ids, function (elem) {
        return elem == "bookingRoomId";
      }).length;
      for(var i=0, count=0; i<editable_fields.length; i+=editable_fields.length/no_of_rooms, count++) {
        booking_data["rooms_detail"][count] = {};
        booking_data["rooms_detail"][count]["id"] = $(editable_fields[i+0]).val();
        booking_data["rooms_detail"][count]["rate_plan_id"] = $(editable_fields[i+1]).val();
        booking_data["rooms_detail"][count]["arrival_date"] = $(editable_fields[i+2]).val();
        booking_data["rooms_detail"][count]["departure_date"] = $(editable_fields[i+3]).val();
        booking_data["rooms_detail"][count]["guest_name"] = $(editable_fields[i+4]).val();
        booking_data["rooms_detail"][count]["no_of_adults"] = $(editable_fields[i+5]).val();
        booking_data["rooms_detail"][count]["no_of_children"] = $(editable_fields[i+6]).val();
      }
      console.log(booking_data);
Vishal Nagda
@vishalnagda1
Aug 07 2017 09:14
But now I want to make it dynamically. So please help me.
Vishal Nagda
@vishalnagda1
Aug 07 2017 09:20
???
Bartosz
@CataciD
Aug 07 2017 09:34
could you write up a quick summary of what you're trying to do
its gonna be a pain trying to figure it out without comments :D
Markus Kiili
@Masd925
Aug 07 2017 09:35
@vishalnagda1 Asking specific questions gets answers better.
Bartosz
@CataciD
Aug 07 2017 09:35
true that
Vishal Nagda
@vishalnagda1
Aug 07 2017 09:52
$(".multi-room-template-cloned .editable-field”); this my jQuery selector, and it returns all the fields which has editable-field class.
now I want to get values of each field. In the above code snippet i’m doing it by using for loop. But I think that this is not a good way of doing the same. So I want someone to suggest me to get its values dynamically.
Bartosz
@CataciD
Aug 07 2017 10:06
You can do it with a forEach
just makes sure the selector returns an array, if not do [...selector]
i assume you're holding data in an object filled with the rooms? would make stuff easier
Vishal Nagda
@vishalnagda1
Aug 07 2017 10:12
yes you’re right it’s rooms data
let me try
Bartosz
@CataciD
Aug 07 2017 10:14
you could also create an object for a single room and base creating rooms on that object
and then make the first key in your rooms object the entry to the room specific object
the logic being forEeach room do room => assign its values
Vishal Nagda
@vishalnagda1
Aug 07 2017 10:17
Thank you helping me :)
Bartosz
@CataciD
Aug 07 2017 10:18
np
im actually outta things to code so decided id get a bit better if i try to explain things and help others :P
good way to practice afafik
Vishal Nagda
@vishalnagda1
Aug 07 2017 10:25
You’re doing a great job dude :+1:
Emmanuel Akodia
@akodiaemma
Aug 07 2017 10:25
hello guys i am using this code to show a loader until my page is done loading, but i wanted to make it load atleast after 5 seconds,..how can that be done
<script type="text/javascript">

    $(window).load(function() {

    $(".se-pre-con").fadeOut("slow");;
    });
Bartosz
@CataciD
Aug 07 2017 10:27
I hope so :^)
window onload is a dom prop that executes when the window loads
if you wan't the loading to last some time just make a timeout
as in, on load pop the loading image and set timeout for 5 seconds to fade
though that seems... pointless
if a site is loaded why the hell do you want me to wait 5 seconds for me to use it?
Emmanuel Akodia
@akodiaemma
Aug 07 2017 10:29
@CataciD it loads pretty fast, i wantesd the clients to see how awesome my loader is
Bartosz
@CataciD
Aug 07 2017 10:29
those loaders are usually used when your site makes http requests
dont do that
Emmanuel Akodia
@akodiaemma
Aug 07 2017 10:29
@CataciD why do you say so?
Bartosz
@CataciD
Aug 07 2017 10:29
because it's counter productive
some of the users will be put off
like why is this even here
use it when something does load
if you're making api/http requests
and you actually need to wait for a response
if you want, animate an intro for the site starting
Emmanuel Akodia
@akodiaemma
Aug 07 2017 10:30
@CataciD thats what i want to do basically
Bartosz
@CataciD
Aug 07 2017 10:30
but by definition, we think animations are cool, try adding a 1 sec animation to EVERYTHING on the site and see how users react
you'll literally get ppl clicking furiously hoping it skips
because its annoying and unintuitive
Emmanuel Akodia
@akodiaemma
Aug 07 2017 10:31
i have already made rhe animation..how do i add the set timeout property to the function
Bartosz
@CataciD
Aug 07 2017 10:31
read up on setTimeout()
its pretty simple
setTimeout(function, time)
it executes AFTER the time
so just make the function replace loading screen with actuall site
or make the loading screen fade/disappear
Abhinav Mishra
@abhinav-m
Aug 07 2017 10:32
sanitized inputs and added localstorage...
Bartosz
@CataciD
Aug 07 2017 10:32
is there a problem with it @abhinav-thinktank ? I just came here 10 minutes ago
Abhinav Mishra
@abhinav-m
Aug 07 2017 10:32
nope..
just showing it
if you find any bugs lemme know
Bartosz
@CataciD
Aug 07 2017 10:33
seems to work
just fix the css
its annoying
the border/box-shadow of the main buttons move everything around
that doesnt look nor feel good
also the input fields can have placeholders instead of actuall text
it's a lot more intuitive
because once you click a placeholder it disappears
Stephen James
@sjames1958gm
Aug 07 2017 10:59
@abhinav-thinktank For the two buttons that show during edit or add, maybe add some space above them so they aren't up against the input boxes.
Maybe center them or at least align the left side of the inputs and buttons.
Bartosz
@CataciD
Aug 07 2017 11:11
yeah, padding and margins are your friends, don't leave em out :D
and center all icons ;)
Blauelf
@Blauelf
Aug 07 2017 11:15
@abhinav-thinktank Bug: Click an entry, click edit, click back. Create a new entry, save it, instead of creating a new one, the old entry got replaced.
Darth Skywalker
@AdiSkywalker
Aug 07 2017 11:24
Got the first draft ready... Objective, in place edit on recipe name and description.. Need to workout upward data flow
Bartosz
@CataciD
Aug 07 2017 11:34
data in react is usually trasfered through props
make the parrent have a function retrieving data, pass that function, execute it with an argument from child
parrent has gimmeChildProp(x); has it as a prop, then child has a prop=parrent.prop.gimmeChildProp() something like that
on execution within the child it executes the parents function to retrieve data
Darth Skywalker
@AdiSkywalker
Aug 07 2017 11:35
Yeah.. I don't wanna do that!
That's the reason I'm passing in individual string (as opposed to object)
so that I can send back (non referenced( value
Bartosz
@CataciD
Aug 07 2017 11:35
why tho
isn't that how its done in react
or at least was when i was last doing it
Darth Skywalker
@AdiSkywalker
Aug 07 2017 11:36
Not necessarily
Bartosz
@CataciD
Aug 07 2017 11:36
so how do you want to do it?
cause i've worked on kind of abig project (in my eyes)
and everything was starting out in a state keeping component and passed down to everything else
and retrieved the same way afaik
Darth Skywalker
@AdiSkywalker
Aug 07 2017 11:36
the only restriction there is in React is that you don't haphazardly modify data. It has to be transferred around with unidirectional flow
Bartosz
@CataciD
Aug 07 2017 11:36
thought that was the way to do things
Darth Skywalker
@AdiSkywalker
Aug 07 2017 11:37
The thing is all my data resides in AppComponent (at one place)
AppComponent hosts RecipeCard which in turn hosts EditableInput
Bartosz
@CataciD
Aug 07 2017 11:39
so whats the problem?
Darth Skywalker
@AdiSkywalker
Aug 07 2017 11:39
What I would ideally like to do is send out new data (with key, name, description etc) directly to the AppComponent
Bartosz
@CataciD
Aug 07 2017 11:39
App data has a "retrieve all data" function, passes to recipe card, it passes to edible input, input executes it
or recipe card executes it giving it all the data
well
wouldnt you just do that
Darth Skywalker
@AdiSkywalker
Aug 07 2017 11:40
yes... That's how it's typically done
Bartosz
@CataciD
Aug 07 2017 11:40
recipebox if i understand correctly holds ALL the data ?
Darth Skywalker
@AdiSkywalker
Aug 07 2017 11:40
No AppComponent holds all the data
Bartosz
@CataciD
Aug 07 2017 11:40
i dont mean literally
i mean the data is TYPEd into the recipebox
cause the box has all the inputs
Darth Skywalker
@AdiSkywalker
Aug 07 2017 11:41
brb.. my machine is restrarting
Bartosz
@CataciD
Aug 07 2017 11:41
lol k
Darth Skywalker
@AdiSkywalker
Aug 07 2017 11:41
Windows 10 update :laughing:
Bartosz
@CataciD
Aug 07 2017 11:41
:D
autoset 3:00 am
"getfukt win10"
Abhinav Mishra
@abhinav-m
Aug 07 2017 11:42
@Blauelf @sjames1958gm ty just saw your messages
CamperBot
@camperbot
Aug 07 2017 11:42
abhinav-thinktank sends brownie points to @blauelf and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 4556 | @blauelf |http://www.freecodecamp.com/blauelf
:star2: 8260 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Abhinav Mishra
@abhinav-m
Aug 07 2017 11:42
will work on them soon
Stephen James
@sjames1958gm
Aug 07 2017 11:45
@AdiSkywalker If you wan't a single source of truth - Redux?
Abhinav Mishra
@abhinav-m
Aug 07 2017 11:46
@sjames1958gm should i start studying redux simultaneously
im just beginning with react
dont wanna be overwhelmed
Stephen James
@sjames1958gm
Aug 07 2017 11:48
I took it in steps, get comfortable with the react structure then you can convert to Redux, will give you a better feeling for what redux does
Bartosz
@CataciD
Aug 07 2017 11:49
i havent even touched redux
while i feel quite comfortable working in react
even helped on a big project
so id say stick with react first
Abhinav Mishra
@abhinav-m
Aug 07 2017 11:54
@sjames1958gm ok
@CataciD ok ty
CamperBot
@camperbot
Aug 07 2017 11:54
abhinav-thinktank sends brownie points to @catacid :sparkles: :thumbsup: :sparkles:
:cookie: 410 | @catacid |http://www.freecodecamp.com/catacid
Darth Skywalker
@AdiSkywalker
Aug 07 2017 11:54
@sjames1958gm : yeah! I could easily do that with redux. I'm trying to reverse engineer their methodology to fortify my understanding
@CataciD : we'll resume our discussion once my laptop is upgraded!
Should be fun
Bartosz
@CataciD
Aug 07 2017 11:57
aye
Blauelf
@Blauelf
Aug 07 2017 12:18
@AdiSkywalker Upgrade in which direction?
Bartosz
@CataciD
Aug 07 2017 12:19
whaddaya mean
lul he proly meant update
Blauelf
@Blauelf
Aug 07 2017 12:29

@CataciD I recently upgraded my laptop from 8 to 16GB of RAM, depending on device one also could upgrade storage, or install an LTE modem, something like that.

Or, one might upgrade the operating system from Jessie to Stretch.

So even if @AdiSkywalker really meant "upgraded", it could mean very different things.

Datikzz
@Datikzz
Aug 07 2017 12:31
guys, trying to animate balls, thats appear every 5 secs on canvas, can't make them move :c what I'm doing wrong, https://jsbin.com/mexofuz/24/edit?js,output
EpicTriffid
@EpicTriffid
Aug 07 2017 12:34
Hi all, so in my code below, it works for everything except when the case of the arguments might change, but adding the ignore case expression in the replace stops the code working. Remove the /******/i and it works again. Why might this be happening?

function myReplace(str, before, after) {
  var fin = [];
  var arr = str.split(" ");
  for (var x = 0; x < arr.length; x++) {
    if (arr[x] === before) {
      fin.push(str.replace(/arr[x]/i, after));
      return fin.join(" ");
    }
  }

}

myReplace("A quick brown fox jumped over the lazy dog", "jumped", "leaped");
Bartosz
@CataciD
Aug 07 2017 12:38
@Blauelf true true
but im pretty sure he meant update since he's on win 10
and mean his pc needs to restart
arr[x] is not a variable here
@EpicTriffid
dunno if that what's you meant
regular expressions are meant to search through strings
Darth Skywalker
@AdiSkywalker
Aug 07 2017 12:40
I had windows 7 now it's getting updated/upgraded to windows 10 @Blauelf @CataciD
Bartosz
@CataciD
Aug 07 2017 12:40
so its literally looking for a string "arr[x]"
Blauelf
@Blauelf
Aug 07 2017 12:41
@CataciD With Windows 10, you usually upgrade from the beta version of one windows to the beta version of the next. So even if it stays Windows 10, it might happen that some of your programmes are missing after one of the larger updates (which I would consider an upgrade in some sense - or downgrade for some people who would have wanted to keep their features).
Bartosz
@CataciD
Aug 07 2017 12:41
ok can we stop the semantics
in his case you can call it both if you want to upgrade is more suitable since he's effectively chaning to a new system
while in the same system it's still an update
with a new version
thats my perspective
EpicTriffid
@EpicTriffid
Aug 07 2017 12:45
@CataciD So i changed "arr[x]" to "before", which is a string, and its still giving me the same problem :/
Blauelf
@Blauelf
Aug 07 2017 12:45
I'll keep my Windows NT 6.1 ("Windows 7") for the lifetime of my notebook (6.1 will receive some updates till 2020). Pretty sure I cannot avoid Windows NT 6.4 ("Windows 10") when buying the next. Too much of my software is Windows only :-/
Stephen James
@sjames1958gm
Aug 07 2017 12:47
@EpicTriffid You replaced in str, but you returned fin
Bartosz
@CataciD
Aug 07 2017 12:49
omg
you odnt want a regular expression there thats my point
you're looking fora variable
so place only the var :P
afaik
Stephen James
@sjames1958gm
Aug 07 2017 12:50
@EpicTriffid new RegExp(before, 'g'); you'll need to do this to use regex
Just, fyi a string in the first parameter for replace will only replace once, which I think actually works for this challenge.
Bartosz
@CataciD
Aug 07 2017 12:51
do you?
can u just const regex = /xxxx/ig
Stephen James
@sjames1958gm
Aug 07 2017 12:52
@CataciD It will use the literal not the variable value
Bartosz
@CataciD
Aug 07 2017 12:52
well ofc lol
but at the same time why use the regex at all
ir you're using replace which takes a string?
EpicTriffid
@EpicTriffid
Aug 07 2017 12:52
Im not sure how I would preserve the case without regex?
Bartosz
@CataciD
Aug 07 2017 12:52
or put the regex INSIDE the array
Stephen James
@sjames1958gm
Aug 07 2017 12:52
Depends on if you want to replace once or all, a string will only replace once
Bartosz
@CataciD
Aug 07 2017 12:53
operate on a copy @EpicTriffid
you can also check if x[0] === x[0].toLowerCase()
which will do teh same thing
from what ive read regexps are actually quite heavy
EpicTriffid
@EpicTriffid
Aug 07 2017 13:00
Alright, so I've figured that I dont have to do the split or anything to replace the word. The code is tiny now, but now I'm figuring that the complexity comes in passing over the case from the specified word. Now, I know I don't need a regexp, but I dont understand why this wouldn't work as it is

function myReplace(str, before, after) {
  var fin = "";
      fin = str.replace(/before/i, after);
      return fin; 
}

myReplace("A quick brown fox jumped over the lazy dog", "jumped", "leaped");
I tried returning str, instead of doing the whole fin things, but then it doesn't replace
Stephen James
@sjames1958gm
Aug 07 2017 13:05
@EpicTriffid Because /before/ is looking for specifically "before"
EpicTriffid
@EpicTriffid
Aug 07 2017 13:06
@sjames1958gm Riiiggghtt
So the regexp reads the text literally
?
Stephen James
@sjames1958gm
Aug 07 2017 13:07
@EpicTriffid When using the // syntax, yes
EpicTriffid
@EpicTriffid
Aug 07 2017 13:07
hence using that new Regex thing above?
Nelson
@nelruk
Aug 07 2017 13:07
I need help with the Manipulating Complex Objects Exercise https://www.freecodecamp.org/challenges/manipulating-complex-objects
Stephen James
@sjames1958gm
Aug 07 2017 13:07
@EpicTriffid yes
function myReplace(str, before, after) {
  return str.replace(new RegExp(before), after);
}
Nelson
@nelruk
Aug 07 2017 13:07
Here is my code and doesn't work
    {
      "artist":"Metallica",
      "title":"And Justice For All",
      "release_year": 1988,
      "formats":[
        "Cs",
        "8T",
        ".mp3"
      ]
    }
  ]
];
Am I doing something wrong?
Stephen James
@sjames1958gm
Aug 07 2017 13:09
@nelruk Hmm, why two ] at the end ?
Show all of the code
Nelson
@nelruk
Aug 07 2017 13:09
@sjames1958gm
var myMusic = [ { "artist": "Billy Joel", "title": "Piano Man", "release_year": 1973, "formats": [ "CS", "8T", "LP" ], "gold": true } // Add record here [ { "artist":"Metallica", "title":"And Justice For All", "release_year": 1988, "formats":[ "Cs", "8T", ".mp3" ] } ] ];
var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
  }
  // Add record here
  [
    {
      "artist":"Metallica",
      "title":"And Justice For All",
      "release_year": 1988,
      "formats":[
        "Cs",
        "8T",
        ".mp3"
      ]
    }
  ]
];
Stephen James
@sjames1958gm
Aug 07 2017 13:09
@nelruk Structure should be [{}, {}]
@nelruk You created an extra array around your new object, not correct.
Need a comma between the two objects in the array
EpicTriffid
@EpicTriffid
Aug 07 2017 13:11
@sjames1958gm so does the new syntax allow it to read the variable?
Nelson
@nelruk
Aug 07 2017 13:11
@sjames1958gm a damn comma!
Stephen James
@sjames1958gm
Aug 07 2017 13:11
@EpicTriffid yes The Regexp constructor takes a string as it's first parameter
Nelson
@nelruk
Aug 07 2017 13:11
thank you @sjames1958gm :)
CamperBot
@camperbot
Aug 07 2017 13:11
nelruk sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8261 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 07 2017 13:11
@nelruk :+1:
EpicTriffid
@EpicTriffid
Aug 07 2017 13:12
@sjames1958gm and im guessing the constructor does that for efficiency? It used the string by default so you can get down your code faster?
@sjames1958gm Also, I know I should be putting down "i" now, but I;m not sure where within the RegExp it would go? Can't find any reference
Stephen James
@sjames1958gm
Aug 07 2017 13:14
@EpicTriffid Just different behavior with the constructor - the second parameter is for flags
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
EpicTriffid
@EpicTriffid
Aug 07 2017 13:16
@sjames1958gm Ah, there we go
didn't need the square brackets
Well, now it ignores case, but doesn't pass the case across
Gerdnermit
Well, at leats I can see what Im missing rather than fumbling in the dark
Stephen James
@sjames1958gm
Aug 07 2017 13:23
@EpicTriffid read the Note:
Vikram
@vikramnr
Aug 07 2017 13:39

`function mutation(arr) {
var str1=arr[0];
var str2=arr[1];
var len1=0;
str1=str1.toLowerCase();
str2=str2.toLowerCase();
var len=0;
if(str1.length>str2.length){len=str1.length;}else{len=str2.length;}
for(var i=0;i<len;i++){
len1+=str1.indexOf(str2[i]);if(len1<=0){return false;}else{return true;}
}
//return len1;
//}
}// Happy Coding!

mutation(["hello", "hey"]);`

Hi all, for this case alone it returning true even though len1 is -2.. What am i missing??
EpicTriffid
@EpicTriffid
Aug 07 2017 13:42
@sjames1958gm Of the exercise?
Stephen James
@sjames1958gm
Aug 07 2017 13:43
@EpicTriffid Yes. Preserve the case of the original word when you are replacing it. For example if you mean to replace the word "Book" with the word "dog", it should be replaced as "Dog
EpicTriffid
@EpicTriffid
Aug 07 2017 13:45
@sjames1958gm That's what I'm trying to do. i ignores the case when searching, but im thinking maybe i need to split the string into an array, and if the matching term is upper case, then make the one that replaces it upper case too? Or am I just over-complicating it?
Stephen James
@sjames1958gm
Aug 07 2017 13:45
@vikramnr Well e is in both strings so len1 is 1 and then it returns true
@EpicTriffid You shouldn't ignore case on the search, but you have to make after match the case of before (at least first letter) - then replace
@vikramnr Your search length should always be just str2
Vikram
@vikramnr
Aug 07 2017 14:13
@vikramnr Your search length should always be just str2 still it's not that..even after i have changed its failing
Stephen James
@sjames1958gm
Aug 07 2017 14:23
@vikramnr You can return false inside the loop, but true only after all the letters of str2 have been tested
Oleh
@Lufter
Aug 07 2017 14:23
Hey guys, I would appreciate your help on fixing problem with "CORS header ‘Access-Control-Allow-Origin’ missing"
  apiUrl = 'https://api.darksky.net/forecast/key/'; 
// old apiUrl => 'https://crossorigin.me/https://api.darksky.net/forecast/key/'  
// without using type:"GET" & header: {"Access-Control-Allow-Origin": "*"} in AJAX call
function getLocation(data){
      var cords = data.coords;
      lat = cords.latitude;
      lon = cords.longitude;
      getApiData();
      getCurrentCity();
      console.log("Loc. Cords: " + lat + " " + lon);
  }
  function getApiData(){
    $.ajax({
          url: apiUrl = apiUrl + lat + "," + lon,
          dataType: "jsonp",
          type: "GET",
          headers: {"Access-Control-Allow-Origin": "*"},
          success: function(data){
            getWeather(data);
            loadForcast();
          },
          cache: false
        })
  }
currently I'm using crossoriging.me to get data from dark sky api, but i would like to understand how to do so w/o using "proxy"
Stephen James
@sjames1958gm
Aug 07 2017 14:26
@Lufter dark sky doesn't allow cross origin requests.
https://darksky.net/dev/docs/faq
Oleh
@Lufter
Aug 07 2017 14:27
@sjames1958gm yeap, i noticed that, just to make it clear, does it mean that in any way it is not possible ?
EpicTriffid
@EpicTriffid
Aug 07 2017 14:30
@sjames1958gm Woot
function myReplace(str, before, after) {
  if (before[0] == before[0].toUpperCase()) {
    return  str.replace(before, after[0].toUpperCase() + after.slice(1));
  }
  else {
    return  str.replace(before, after);
  }
}

myReplace("A quick brown fox jumped over the lazy dog", "Jumped", "leaped");
Stephen James
@sjames1958gm
Aug 07 2017 14:31
@Lufter Not directly from the front end, some sort of proxy
@EpicTriffid :+1:
Anewil
@Anewil
Aug 07 2017 14:32
var result = 1;
function factorialize(num) {
  for (var i=2; i<=num; i++) {
    result *= i;
  }
  return result;
}

factorialize(5);
Code returns 120 but freeCodeCamp doesnt accept this
Stephen James
@sjames1958gm
Aug 07 2017 14:32
@Anewil No globals in FCC challenges, they don't get reset between tests
Anewil
@Anewil
Aug 07 2017 14:33
@sjames1958gm Thank you, it works now :smile:
CamperBot
@camperbot
Aug 07 2017 14:33
anewil sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8262 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 07 2017 14:33
@Anewil :+1:
Junicus
@Junicus
Aug 07 2017 14:40
@Lufter I ran into the same issue, I made my own proxy in heroku that way it's more reliable than one of the public proxies, you can look at how I did it on github
Oleh
@Lufter
Aug 07 2017 14:45
@Junicus thx
CamperBot
@camperbot
Aug 07 2017 14:45
lufter sends brownie points to @junicus :sparkles: :thumbsup: :sparkles:
:cookie: 357 | @junicus |http://www.freecodecamp.com/junicus
dyon3334
@dyon3334
Aug 07 2017 14:46

what am i doing wrong i get comma's inside my string after joining them '''
function reverseString(str) {
var string = str;
var array = string.split("");
var reversed = array.reverse();
return reversed.join();
}

reverseString("hello");'''

CamperBot
@camperbot
Aug 07 2017 14:46
:bulb: to format code use backticks! ``` more info
dyon3334
@dyon3334
Aug 07 2017 14:47
what am i doing wrong i get comma's inside my string after joining them function reverseString(str) { var string = str; var array = string.split(""); var reversed = array.reverse(); return reversed.join(); } reverseString("hello");
Diego Mayer
@Chrono79
Aug 07 2017 14:48
join needs arguments @dyon3334
silver537
@silver537
Aug 07 2017 14:48
Quotes
dyon3334
@dyon3334
Aug 07 2017 14:49
@Chrono79 okay thanks and how looks the code to you ?
CamperBot
@camperbot
Aug 07 2017 14:49
dyon3334 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4508 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Aug 07 2017 14:49
@dyon3334 I would chain methods
And I see no need for creating string var
dyon3334
@dyon3334
Aug 07 2017 14:50
@Chrono79 can you write me your alternative ?
Diego Mayer
@Chrono79
Aug 07 2017 14:50
split doesn't mutate your string, it returns an array
return str.split("").reverse().join("");
Junicus
@Junicus
Aug 07 2017 14:51
@dyon3334 by default join if left without arguments joins using ',' mdn, use .join('')
dyon3334
@dyon3334
Aug 07 2017 14:51
@Chrono79 thanks thats a lot shorter
CamperBot
@camperbot
Aug 07 2017 14:51
dyon3334 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: dyon3334 already gave chrono79 points
dyon3334
@dyon3334
Aug 07 2017 14:52
@Junicus thanks !!
CamperBot
@camperbot
Aug 07 2017 14:52
dyon3334 sends brownie points to @junicus :sparkles: :thumbsup: :sparkles:
:cookie: 358 | @junicus |http://www.freecodecamp.com/junicus
Diego Mayer
@Chrono79
Aug 07 2017 14:52
@dyon3334 for methods chaining to work, you need to match the type of the output of a method with the type of the input of the next one
Thayyeb salim
@Thayyebsalim
Aug 07 2017 14:53
is it possible for an ajax call to have more than 1 url as parameter or do I do another one
asking for the Twitch API project
Moisés Man
@moigithub
Aug 07 2017 14:53
1 url per ajax call @Thayyebsalim
dyon3334
@dyon3334
Aug 07 2017 14:53
@Chrono79 yes i understand but thinking in that way is more difficult then declaring variables but i will train chaining from now
Diego Mayer
@Chrono79
Aug 07 2017 14:54
:+1: It's harder to debug, yes
Thayyeb salim
@Thayyebsalim
Aug 07 2017 14:55
Oh ok @moigithub
is important that I use the callback=??
Moisés Man
@moigithub
Aug 07 2017 14:57
only needed (if u use jquery) when u wanna do jsonP calls @Thayyebsalim
to bypass CORS restriction
Thayyeb salim
@Thayyebsalim
Aug 07 2017 14:57
thanks @moigithub
CamperBot
@camperbot
Aug 07 2017 14:57
thayyebsalim sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3561 | @moigithub |http://www.freecodecamp.com/moigithub
Chris Juchtmans
@kjuchtmans
Aug 07 2017 15:05
Afternoon coders of yonder! :wave:
Stephen James
@sjames1958gm
Aug 07 2017 15:06
@kjuchtmans :wave: Morning
Chris Juchtmans
@kjuchtmans
Aug 07 2017 15:12

"Symmetric Difference" lesson:
Can Rest parameters offer a lean solution?

I'm trying to solve this dynamically, without lines and lines of code.
So, in pseudo code, I would see it like this:

function symdiff (a, b, ...theArgs) {
//1. first calculate sym diff of first 2 arguments a and b
//2. return theArgs.map(function(element) {
    return sym diff of element;
  });

Does that logic stand a chance?
thanks!

Moisés Man
@moigithub
Aug 07 2017 15:13
use reduce @kjuchtmans
if u have more than 2 elements.. reduce willpick 2.. get a result.. then pick next + previous result n so on
Chris Juchtmans
@kjuchtmans
Aug 07 2017 15:14
@moigithub reduce as a closure within a function taking ...theArgs you mean sir?
@moigithub okay, I get that
Stephen James
@sjames1958gm
Aug 07 2017 15:15
@kjuchtmans Don't make a, b a separate solution. Start with a and apply each subsequent args to a, ab, abc, abcd
Chris Juchtmans
@kjuchtmans
Aug 07 2017 15:15
@sjames1958gm sounds fair
lets grab a bite and try to code this out, thanks @sjames1958gm @moigithub
CamperBot
@camperbot
Aug 07 2017 15:15
kjuchtmans sends brownie points to @sjames1958gm and @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 8263 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
:star2: 3562 | @moigithub |http://www.freecodecamp.com/moigithub
Stephen James
@sjames1958gm
Aug 07 2017 15:16
@kjuchtmans :+1:
Datikzz
@Datikzz
Aug 07 2017 15:29
Guys, how to make balls to appear 1 in 5secs, not all at once? https://jsbin.com/mexofuz/28/edit?js,output
Moisés Man
@moigithub
Aug 07 2017 15:32
remove the for/loop
and add new Ball() on a setInterval
probably add a condition/counter.. so when it reach 20 (max ball) remove the interval
Diego Mayer
@Chrono79
Aug 07 2017 15:36
@Datikzz That remainds me of Pang arcade game ;)
Datikzz
@Datikzz
Aug 07 2017 15:47
:thinking:
Stephen James
@sjames1958gm
Aug 07 2017 15:58
@Datikzz inside your render() function call create(0)
function create(i) {
  if (i < 20) {
    balls[i] = new Ball();
    i++;
    setTimeout(() => create(i), 500);
  }
}
a7n007
@a7n007
Aug 07 2017 16:02
https://www.freecodecamp.org/challenges/symmetric-difference can anyone help me with this question i dont know how to use callback functions
Datikzz
@Datikzz
Aug 07 2017 16:05
@sjames1958gm they are not moving after that :c
Christopher McCormack
@cmccormack
Aug 07 2017 16:05
@a7n007 a callback function is simply a function you pass by reference to another function. Is it the reduce callback function you're concerned with?
Stephen James
@sjames1958gm
Aug 07 2017 16:05
@Datikzz Don't put that in your setInterval, but right before it
@Datikzz move create(0) up one line outside of setInterval
Datikzz
@Datikzz
Aug 07 2017 16:07
<3
Nicolas Ramirez
@kamatheuska
Aug 07 2017 16:16
hi everyone, I am trying to include a large text (+1000 words) in JS. I want to randomly select extracts of this text for my random quote machine. Which is the best way to include the text? like a hidden div on the html? or with the .load() function?
or as a string??
Jason Luboff
@JLuboff
Aug 07 2017 16:17
@kamatheuska You can create an array in your JS
Or an object
Nicolas Ramirez
@kamatheuska
Aug 07 2017 16:18
@JLuboff like an array with the text splitted in words?
Jason Luboff
@JLuboff
Aug 07 2017 16:18
@kamatheuska
["Here's my first quote", "Here my second quote", "Hey here's one more"]
Christopher McCormack
@cmccormack
Aug 07 2017 16:19
@kamatheuska yup you can split on [!?.]\s+ or something like that, then every element in the array would be a sentence you could use, then you can pull a random number by using Math.random() * array.length rounded
Nicolas Ramirez
@kamatheuska
Aug 07 2017 16:20
yeah, but like I said, is a really big text, and there are actually two of them, so I though I could import the tect somehow and then turn it into an array
Jason Luboff
@JLuboff
Aug 07 2017 16:20
Oh, then ya, split it like @cmccormack suggested then you'll have an array
Nicolas Ramirez
@kamatheuska
Aug 07 2017 16:21
hahaha thanks I didn't wanted the answer of the whole challenge though @cmccormack hehe
CamperBot
@camperbot
Aug 07 2017 16:21
kamatheuska sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1103 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Aug 07 2017 16:22
Sorry didn't realize it was a challenge
Jason Luboff
@JLuboff
Aug 07 2017 16:22
@cmccormack Way to go man. Such a dick move ;)
Nicolas Ramirez
@kamatheuska
Aug 07 2017 16:23
the question is actually how can I import a reaaally big text, lets say bigger than 5000 words, so I don't have it on my html/js code....sort of like how you would import an image
after that I would do something similar to what @cmccormack suggested, of course
Christopher McCormack
@cmccormack
Aug 07 2017 16:25
@JLuboff haha I'm sorry!
@kamatheuska can you have it in memory?
Jason Luboff
@JLuboff
Aug 07 2017 16:26
You can use an AJAX call to import it...but you still need to host that file somewhere
Nicolas Ramirez
@kamatheuska
Aug 07 2017 16:26
maybe dropbox of somthings? :D
I'm not positive if dropbox would work or not
Keith
@7KAG7
Aug 07 2017 16:27

hey campers, im strugglin with my weather app script, any help would be appreciated ```$(document).ready(function(){
var long;
var lat;
var temp;
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {

  long = position.coords.longitude;
  lat = position.coords.latitude;

//create api with geolocation
var api = "https://api.openweathermap.org/data/2.5/weather?id= ChIJQwHH1RoM5IkRVvrMAKJW0d0&appid=AIzaSyCcS9Sd2jqrhX6auXHiEGqkHE96HPA3A_0";

  $.getJSON(api, function(data){
//JSON call for open weather api
var weatherType = data.weather[0].description;
var kelvin = data.main.temp;
var windSpeed = data.ein.speed;
var city = data.name;

  console.log(city);
console.log(api);

});

});

}```

a7n007
@a7n007
Aug 07 2017 16:27
@cmccormack please tell me how to solve that question
Nicolas Ramirez
@kamatheuska
Aug 07 2017 16:28
@JLuboff ty that seems like the solution :)
CamperBot
@camperbot
Aug 07 2017 16:28
kamatheuska sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2133 | @jluboff |http://www.freecodecamp.com/jluboff
Kelechi Chinaka
@ke1echi
Aug 07 2017 16:29
function popShift(str) {
  var str1 = [], str2 = [], lastChar = [], string = str.split('');
  while (string.length !== 1) {
    str1.push(string.pop());
    str2.push(string.shift());
    if (string.length === 1) {
      lastChar.push(string);
    }
  }
  return (str1.join('') + ' ' + str2.join('') + ' ' + string.join('')).split(' ');
}
hi guys, this passes all test ..except one that throws a memory error, what could be wrong?
Christopher McCormack
@cmccormack
Aug 07 2017 16:30
@dudeguykid put backticks on their own line to format properly
Jason Luboff
@JLuboff
Aug 07 2017 16:31
@dudeguykid Last I checked, you can only use https for openweathermap if you're paying
Keith
@7KAG7
Aug 07 2017 16:31
$(document).ready(function(){
  var long;
  var lat;
  var temp;
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {

      long = position.coords.longitude;
      lat = position.coords.latitude;


  //create api with geolocation 
  var api = "https://api.openweathermap.org/data/2.5/weather?id= ChIJQwHH1RoM5IkRVvrMAKJW0d0&appid=AIzaSyCcS9Sd2jqrhX6auXHiEGqkHE96HPA3A_0";

      $.getJSON(api, function(data){
    //JSON call for open weather api
    var weatherType = data.weather[0].description;
    var kelvin = data.main.temp;
    var windSpeed = data.ein.speed;
    var city = data.name;

      console.log(city);
    console.log(api);

  });

  });

  }
of course
i am using an video from last year to help guide me
thanks @cmccormack and @JLuboff
CamperBot
@camperbot
Aug 07 2017 16:32
dudeguykid sends brownie points to @cmccormack and @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 1104 | @cmccormack |http://www.freecodecamp.com/cmccormack
:star2: 2134 | @jluboff |http://www.freecodecamp.com/jluboff
Keith
@7KAG7
Aug 07 2017 16:32
do you guys recommend another source?
Christopher McCormack
@cmccormack
Aug 07 2017 16:32
@dudeguykid like @JLuboff said, you're probably getting an error in your dev console. owm only supports http currently and that will be a problem. I recommend using darksky instead. Also you aren't passing along geo data so that won't work anyhow
Jason Luboff
@JLuboff
Aug 07 2017 16:33
And you have a space between the = and your api key
Christopher McCormack
@cmccormack
Aug 07 2017 16:33
@dudeguykid some people also use cors-anywhere but I would recommend just using an https api like darksky instead
Keith
@7KAG7
Aug 07 2017 16:33
nice and nice, thank you both, ill pull the go data and try darksky instead
awesome, ill try those
been stuck on this for a few days and figured i would finally breakdown and ask
Christopher McCormack
@cmccormack
Aug 07 2017 16:34
@dudeguykid did you look at your developers console? that should have given you an error you could copy/paste into google and start working toward a solution
Keith
@7KAG7
Aug 07 2017 16:35
it didnt
i thought the same but there is nothing there
there was an error that would move the code up to the line with api line but gave me no indication what it was and then would just disappear.
Stephen James
@sjames1958gm
Aug 07 2017 16:38
@dudeguykid Free code camp has a minimial weather API for this project.
https://fcc-weather-api.glitch.me/
@kelechy What is the kata?
Christopher McCormack
@cmccormack
Aug 07 2017 16:40
@sjames1958gm nice reminder, I keep forgetting that added that
Darth Skywalker
@AdiSkywalker
Aug 07 2017 16:40
@sjames1958gm A term used on code wars for a programming challenge
Stephen James
@sjames1958gm
Aug 07 2017 16:41
@AdiSkywalker Yes, I know, I was asking what kata is he working on
Darth Skywalker
@AdiSkywalker
Aug 07 2017 16:41
Oh!
My bad :laughing:
@sjames1958gm
Stephen James
@sjames1958gm
Aug 07 2017 16:41
@AdiSkywalker no problem :)
Kelechi Chinaka
@ke1echi
Aug 07 2017 16:46
thanks for your constant help..it passes all test but show memory error @sjames1958gm https://www.codewars.com/kata/popshift/train/javascript
CamperBot
@camperbot
Aug 07 2017 16:46
kelechy sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8264 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Christopher McCormack
@cmccormack
Aug 07 2017 16:50
@kelechy you're changing your string's length by 2 every iteration (pop then shift), there's a chance it may never hit 1 length
Stephen James
@sjames1958gm
Aug 07 2017 16:51
@kelechy Why the contact and split at the end?
return [str1.join(''), str2.join(''), string]
Kelechi Chinaka
@ke1echi
Aug 07 2017 16:54
yea, there are tests that hit 1 too @cmccormack
Tai Jones
@taiJones00
Aug 07 2017 16:54
function chunkArrayInGroups(arr, size) {
  // Break it up.
  var holder = [];
  for (var i = 0; i < arr.length; i+=2)
    {
      holder[i] = arr.slice(i, i + size);

    }

  return holder;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
Why am I getting a second subarray of null
Kelechi Chinaka
@ke1echi
Aug 07 2017 16:55
that does not solve the memory issue @sjames1958gm
infact the three test has an extra char, so it always hit 1 @cmccormack
Christopher McCormack
@cmccormack
Aug 07 2017 16:56
@kelechy those are the examples, do you get the error when testing against only the examples?
Kelechi Chinaka
@ke1echi
Aug 07 2017 16:56
no @cmccormack
Bryan Reese
@breese8009
Aug 07 2017 16:56
@taiJones00 should do holder.push and instead of 2 in the for loop change to size
Kelechi Chinaka
@ke1echi
Aug 07 2017 16:57
Time: 5122ms Passed: 3 Failed: 0 Errors: 1
Bryan Reese
@breese8009
Aug 07 2017 16:57
@taiJones00 holder is an empty array...so holder[i] doesnt make sense..
Tai Jones
@taiJones00
Aug 07 2017 16:57
@breese8009 What do you mean?
...
one second
Kelechi Chinaka
@ke1echi
Aug 07 2017 16:58
i think it takes too long to execute @cmccormack @sjames1958gm
Bryan Reese
@breese8009
Aug 07 2017 16:58
@taiJones00 so u want to push results to holder
Kelechi Chinaka
@ke1echi
Aug 07 2017 16:58
looking at the exec time
Tai Jones
@taiJones00
Aug 07 2017 16:59
holder[i].push(arr.slice(i, i + size))
:(
Stephen James
@sjames1958gm
Aug 07 2017 16:59
@kelechy If your string is even length then it will never stop.
The instructions for crap, because it isn't specific about even length string.
Christopher McCormack
@cmccormack
Aug 07 2017 16:59

@kelechy

infact the three test has an extra char, so it always hit 1 @cmccormack

Your examples don't fail, so you need to account for situations where it won't hit 1

Bryan Reese
@breese8009
Aug 07 2017 16:59
@taiJones00 no holder.push,,, no iteration
Stephen James
@sjames1958gm
Aug 07 2017 17:00
@kelechy Here is easier way
function popShift(s){
  let s2 = Math.floor(s.length / 2);
  return [s.slice(s.length - s2).split("").reverse().join(""), 
          s.slice(0,s2), 
          s.length % 2 == 0 ? "" : s[s2]];
}
Kelechi Chinaka
@ke1echi
Aug 07 2017 17:00
the instruction did not state that @sjames1958gm @cmccormack
Bryan Reese
@breese8009
Aug 07 2017 17:00
@taiJones00 and in ur for loop u dont want i+=2 because that only handles one case, u want to use ur param, i+=size
Stephen James
@sjames1958gm
Aug 07 2017 17:00
@kelechy Yes, but the tests have even length strings. The real ones :(
Christopher McCormack
@cmccormack
Aug 07 2017 17:01
@kelechy maybe not, but you should infer - read your own while loop and figure out what happens when it's even
Stephen James
@sjames1958gm
Aug 07 2017 17:02
@kelechy The discussions complain that the case of even strings is not well described.
Just run your loop until length <= 1
Tai Jones
@taiJones00
Aug 07 2017 17:02
arigato @breese8009
CamperBot
@camperbot
Aug 07 2017 17:02
taijones00 sends brownie points to @breese8009 :sparkles: :thumbsup: :sparkles:
:cookie: 818 | @breese8009 |http://www.freecodecamp.com/breese8009
Bryan Reese
@breese8009
Aug 07 2017 17:02
@taiJones00 :+1:
Kelechi Chinaka
@ke1echi
Aug 07 2017 17:05
ok @sjames1958gm
kumquatfelafel
@kumquatfelafel
Aug 07 2017 17:05
@taiJones00 I see you're incrementing i by 2. Suppose size is 4. Will doing this give you the right number of "chunks"?
nvm
Ryan Draves
@RyanDraves
Aug 07 2017 17:08
hey, I'm having trouble with basic React usage of props. can someone help me?
Elizabeth Paul
@Kowalatam
Aug 07 2017 17:14
so for my wherefore art thou, if my source just has one object, my code is correct but not if it has two :(
function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line
  for (var i = 0; i < collection.length; i++) {
      if (Object.keys(collection[i] === Object.keys(source))) {
              for(var name in collection[i]) {
                var value = collection[i][name];
                if (Object.values(source) == value) {
                    arr.push(collection[i]);
                }
            }
      }
  }


  // Only change code above this line
  return arr;
}

whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 });
Stephen James
@sjames1958gm
Aug 07 2017 17:17
@Kowalatam You can only push after testing all the values
Moisés Man
@moigithub
Aug 07 2017 17:18
if "source" have multiple key:values.. u need to check em all @Kowalatam
Stephen James
@sjames1958gm
Aug 07 2017 17:19
@Kowalatam You have Object.keys(collection[i] === Object.keys(source)) code inside your function call?
You need to loop over the keys/values in source then compare to collection values
Kelechi Chinaka
@ke1echi
Aug 07 2017 17:21
fixed!! @sjames1958gm buh its too long, creating a new logic might takes time, would u want to see the code, looks bulky though :smile:
Elizabeth Paul
@Kowalatam
Aug 07 2017 17:25
@sjames1958gm yeah, i kinda didn't know source had more than one object :)
@moigithub yeah,. thank you
CamperBot
@camperbot
Aug 07 2017 17:26
kowalatam sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3563 | @moigithub |http://www.freecodecamp.com/moigithub
Elizabeth Paul
@Kowalatam
Aug 07 2017 17:26
was kinda tired after i found the code didn't pass all test...
break time
:)

@sjames1958gm sounding easier than it seems :)

@Kowalatam You have Object.keys(collection[i] === Object.keys(source)) code inside your function call?
You need to loop over the keys/values in source then compare to collection values

Stephen James
@sjames1958gm
Aug 07 2017 17:32
@kelechy It shouldn't be much longer than you had before?
@Kowalatam Object.keys(source) this creates an array which you can loop over for your inner loop
Elizabeth Paul
@Kowalatam
Aug 07 2017 17:34
@sjames1958gm yeah, changed my if statement to use indexOf(source), and that works too. i just need another loop in the already loop, :)
Stephen James
@sjames1958gm
Aug 07 2017 17:37
@Kowalatam There is a array function .every that might help
Moisés Man
@moigithub
Aug 07 2017 17:38
using indexOf ?? wonder how... @Kowalatam
Elizabeth Paul
@Kowalatam
Aug 07 2017 17:39
@moigithub was talking about my first if statement
@moigithub
      if (Object.keys(collection[i]).indexOf(Object.keys(source)))
Moisés Man
@moigithub
Aug 07 2017 17:42
r u sure that works ? @Kowalatam
Object.keys return an array...
Object.keys(collection[i]) will result on something like ["a","b","c"]
Object.keys(source) will result on something like ["a"] or ["a","b"]
soo....
["a","b","c"].indexOf(["a"])
// -1 <--- not found
Elizabeth Paul
@Kowalatam
Aug 07 2017 17:45
@moigithub it actually worked, with this code below, the first two criteria's are met
function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line
  for (var i = 0; i < collection.length; i++) {
      if (Object.keys(collection[i]).indexOf(Object.keys(source))) {
              for(var name in collection[i]) {
                var value = collection[i][name];
                if (Object.values(source) == value) {
                    arr.push(collection[i]);
                }
            }
      }
  }


  // Only change code above this line
  return arr;
}

whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 });
Moisés Man
@moigithub
Aug 07 2017 17:46
n whats the first 2 criteria ?? empty array ? []
Elizabeth Paul
@Kowalatam
Aug 07 2017 17:46
@moigithub lol, no the ones where source has one object are ticked off
the arr is not empty
Moisés Man
@moigithub
Aug 07 2017 17:48
can u copy paste the 2 passing test
Elizabeth Paul
@Kowalatam
Aug 07 2017 17:50
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" })


whatIsInAName([{ "a": 1 }, { "a": 1 }, { "a": 1, "b": 2 }], { "a": 1 })
@moigithub
Moisés Man
@moigithub
Aug 07 2017 17:57
weird stuff :P
['a', 'b' ].indexOf([ 'a' ]) // -1
['a', 'b' ].indexOf([ 'a' ]) ?"yay":"nay" // "yay" :point_left: should be "nay" according to first result
Jason Luboff
@JLuboff
Aug 07 2017 18:00

@moigithub

console.log(-1 == false); // false

?

Ohh I see what you're saying
Elizabeth Paul
@Kowalatam
Aug 07 2017 18:00
@moigithub i dunno, if it worst, fine by me :smile:
works
Moisés Man
@moigithub
Aug 07 2017 18:05
@JLuboff u right.. negatives are truthy values....
@Kowalatam soo ur condition saying...
if(-1) { ... } since -1 is truthy.. it will always gonna execute
if(true){...} or if(true==true){}(if thats makes clearer)
soo u can remove that if block .. keep the innerloop and still will do whatever it doing
Maluchukwu
@Maluchukwu
Aug 07 2017 18:47
@Rafase282 alright. Thanks for your response
CamperBot
@camperbot
Aug 07 2017 18:47
maluchukwu sends brownie points to @rafase282 :sparkles: :thumbsup: :sparkles:
:star2: 1570 | @rafase282 |http://www.freecodecamp.com/rafase282
Elizabeth Paul
@Kowalatam
Aug 07 2017 18:56
@moigithub okay. thanks
CamperBot
@camperbot
Aug 07 2017 18:56
kowalatam sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3564 | @moigithub |http://www.freecodecamp.com/moigithub
Adam Bohannon
@abohannon
Aug 07 2017 19:04
can someone help me understand why this isn't working? I need to return the square of the positive integers using filter.
'use strict';

const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34];
// change code below this line
let squaredIntegers = realNumberArray;

realNumberArray.filter((num) => { if (Number.isInteger(num)) { return num * num }} );

// change code above this line
// test your code
console.log(squaredIntegers);
Moisés Man
@moigithub
Aug 07 2017 19:12
filter.. filters values ... ermm.. based on what value u returning from the function/callback it will keep or remove values from the array @abohannon
if u return a truthy value.. it will keep the value.. else discard it.. it do not change the value
u will need to filter to keep the positive values..
then use map to calculate the squares
Pethaf
@Pethaf
Aug 07 2017 19:14
@abohannon I think you want an accumulator, rather than a filter.
kumquatfelafel
@kumquatfelafel
Aug 07 2017 19:18
@abohannon you want something more along of the lines of "filter out the values that aren't integers", then square the remaining values.
Ronique Ricketts
@RoniqueRicketts
Aug 07 2017 19:18
help please
function addTogether(x) {
 var arr = Array.prototype.slice.call(arguments);
  if(arr.length > 1){
    return arr[0] + arr[1];
  }
  else if(arr.length === 1 && !isNaN(arr[0])){
    return function(y){
      return x + y;
    }    
  }
  else{
    return undefined; 
  }    
}
console.log(addTogether(2,3));
Stephen James
@sjames1958gm
Aug 07 2017 19:20
@RoniqueRicketts You are not checking if the values are numbers in the case of > 1 parameter, or in your function that you return
Pethaf
@Pethaf
Aug 07 2017 19:20
@RoniqueRicketts You are returning a function from a function.
Oh, nvm.
kumquatfelafel
@kumquatfelafel
Aug 07 2017 19:20
returning a function from a function is okay.
Ronique Ricketts
@RoniqueRicketts
Aug 07 2017 19:22
@sjames1958gm so should i like loop over the length of the arguments then check the iteration to see if it is a num?
Pethaf
@Pethaf
Aug 07 2017 19:23
@kumquatfelafel I know.
I was going to say that he should do addTogether(2)(3)
But then I saw the first line.
Adam Bohannon
@abohannon
Aug 07 2017 19:26
@Pethaf @kumquatfelafel thanks for the help. I'm going through FCC Beta ES6 challenges and some of them aren't fully fleshed out. The challenge focused on filter, but then down in the tests it says I should use map. I ended up filtering, then mapping to square the filtered nums and it worked. Cheers!
CamperBot
@camperbot
Aug 07 2017 19:26
abohannon sends brownie points to @pethaf and @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 578 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:cookie: 381 | @pethaf |http://www.freecodecamp.com/pethaf
kumquatfelafel
@kumquatfelafel
Aug 07 2017 19:27
@abohannon also, keep in mind that filter doesn't modify the original array. It returns a new array. so if you don't store that value anywhere or use it immediately...
Pethaf
@Pethaf
Aug 07 2017 19:27
@abohannon That is a very typical functional programming pattern.
kumquatfelafel
@kumquatfelafel
Aug 07 2017 19:27
np
Adam Bohannon
@abohannon
Aug 07 2017 19:27
this is what I ended up with:
'use strict';

const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34];
// change code below this line

let filteredNums = realNumberArray.filter((num) => num > 0 && Number.isInteger(num) === true);

let squaredIntegers = filteredNums.map((num) => num * num);

// change code above this line
// test your code
console.log(squaredIntegers);
Moisés Man
@moigithub
Aug 07 2017 19:27
:sad_face:
Pethaf
@Pethaf
Aug 07 2017 19:28
Very good.
Adam Bohannon
@abohannon
Aug 07 2017 19:28
@moigithub and thanks to you too! sorry forgot to tag you =)
CamperBot
@camperbot
Aug 07 2017 19:28
abohannon sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3565 | @moigithub |http://www.freecodecamp.com/moigithub
Moisés Man
@moigithub
Aug 07 2017 19:28
:D
kumquatfelafel
@kumquatfelafel
Aug 07 2017 19:30
Number.isInteger will only ever return a boolean value of true or false, so you don't need the === true. You can just say Number.isInteger(num)
Adam Bohannon
@abohannon
Aug 07 2017 19:30
Also, all of these challenges are telling me to 'use strict'; at the top of my code. I've dabbled in ES6 a bit as I worked myself through the original FCC stuff, but i haven't seen this anywhere except in the FCC beta stuff.
@kumquatfelafel ok cool
Jim Tryon
@jimtryon
Aug 07 2017 19:30
<!doctype html>
<html>
  <head>
    <title>My home page</title>
  </head>
  <body>
    <h1>My home page</h1>
    <p>Hello, I am Marijn and this is my home page.</p>
    <p>I also wrote a book! Read it
      <a href="http://eloquentjavascript.net">here</a>.</p>
  </body>
</html>
Using only body.childNodes, how would I access the a element? I’m thinking body.childNodes[2].nextSibling
Pethaf
@Pethaf
Aug 07 2017 19:39
@abohannon I have seen it mentioned previously.
To disable some of the leniency in the javascript compiler.
Guderian Raborg
@hypercuber
Aug 07 2017 19:40
Tips on drawing the stickers of a Rubik Cube so I can add functionality later:
https://codepen.io/hypercuber/pen/PKpPgz?editors=0010
Christopher McCormack
@cmccormack
Aug 07 2017 19:41
@hypercuber you're missing a side
Guderian Raborg
@hypercuber
Aug 07 2017 19:42
@cmccormack It would be invisible unless you rotate
Christopher McCormack
@cmccormack
Aug 07 2017 19:43
I honestly have no idea what your end goal is so I just pointed that out.
Guderian Raborg
@hypercuber
Aug 07 2017 19:45
@cmccormack Oh that is okay. I think I can get a fully functional Rubiks Cube by making it flat and by using double clicks on one color pieces and two color pieces
I might need to add a few buttons or whatnot but yea.
@cmccormack Thanks in advance if you have any suggests/ tips.
CamperBot
@camperbot
Aug 07 2017 19:47
hypercuber sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1105 | @cmccormack |http://www.freecodecamp.com/cmccormack
Ronique Ricketts
@RoniqueRicketts
Aug 07 2017 20:03
still unable to solve any suggested fix
function addTogether(x) {
 var arr = Array.prototype.slice.call(arguments);
  for(var i = 0; i < arr.length; i++){
  if(arr.length > 1 && !isNaN(arr[i])){
    return arr[0] + arr[1];
  }
  else if(arr.length === 1 && !isNaN(arr[0])){
    return function(y){
      return x + y;
    };   
  }
  else{
    return undefined; 
  }   
  }
}
addTogether(2,3);
Joseph
@revisualize
Aug 07 2017 20:03
Hello.
Christopher McCormack
@cmccormack
Aug 07 2017 20:03
@revisualize hiya
Joel Y.
@zapcannon99
Aug 07 2017 20:06
@RoniqueRicketts What's failing?
Ronique Ricketts
@RoniqueRicketts
Aug 07 2017 20:07

@zapcannon99 the above algorithm is for the arguments Optional in intermediate algorithms

addTogether(2, "3")
addTogether(2)([3])

fails

Christopher McCormack
@cmccormack
Aug 07 2017 20:08
@RoniqueRicketts then you need to check if the second argument is a number as well, you're currently only checking the first
Ronique Ricketts
@RoniqueRicketts
Aug 07 2017 20:09
@cmccormack !isNaN(arr[i]) wouldn't this be for each iteration?
Christopher McCormack
@cmccormack
Aug 07 2017 20:09
@RoniqueRicketts you're returning after the first iteration that is true
@RoniqueRicketts I don't remember the exercise 100%, but if there will only ever be max 2 arguments, I would recommend not using a loop
If there could be more than two, maybe do a full iteration to see if they are all numbers and return undefined immediately when one isn't, else proceed to your other conditionals
Ronique Ricketts
@RoniqueRicketts
Aug 07 2017 20:11
@cmccormack i've removed the loop and I will work on it and come back
Christopher McCormack
@cmccormack
Aug 07 2017 20:12
gl
Jacoby Clarke
@Jacobycodes18
Aug 07 2017 20:24
Hello all having trouble with some JS
Ronique Ricketts
@RoniqueRicketts
Aug 07 2017 20:24
@Jacobycodes18 like?
Jacoby Clarke
@Jacobycodes18
Aug 07 2017 20:25
So i'm trying to make a form, and there's styling on the label so that it sits over the inputs for the placeholder and moves when focused.. quite basic
But it will not work for more than the first input in the HTML
Christopher McCormack
@cmccormack
Aug 07 2017 20:27
what are you targeting in your css selectors?
Chris Juchtmans
@kjuchtmans
Aug 07 2017 20:28
evening coders young and old alike! :wave:
Jacoby Clarke
@Jacobycodes18
Aug 07 2017 20:29
@cmccormack You mean in CSS or JS?
Christopher McCormack
@cmccormack
Aug 07 2017 20:30
@Jacobycodes18 css. Maybe share your code though, may be easier. Sounds like a CSS selector issue but it could be just about anything
Lisa
@coding-lisa
Aug 07 2017 20:31
I have a question about objects and variables. Are all variables considered objects?
Chris Juchtmans
@kjuchtmans
Aug 07 2017 20:31

"Symmetric Difference" lesson: how can I apply below code to not 2 arrays, but an undetermined number of arrays?

I have this working code returning the Symm Diff correctly for 2 given arrays.
Do i encapsulate this inside a for loop?
Any thoughts welcome!

Christopher McCormack
@cmccormack
Aug 07 2017 20:32
@coding-lisa variables are references to types
Jacoby Clarke
@Jacobycodes18
Aug 07 2017 20:32
var inPut = document.querySelector("input");
   //var input = document.querySelector("input");
   console.log(inPut);
   inPut.addEventListener('input', change);
   inPut.addEventListener('keyup', change);
   inPut.addEventListener('keydown', change);


   var span = inPut.nextElementSibling;


   // span.style.fontSize = 30 + "px";
   // span.style.top = -33 + "px";
   span.style.transition = 0.3 + "s";

   // console.log($(inPut).val().length);

   function change() {
      var cs = $(this).val().length;
      console.log('heard');
      if (cs >= 1) {
         console.log("more than 1");
         span.style.fontSize = 20 + "px";
         span.style.top = -55 + "px";
      }

      if (cs === 0) {
         span.style.fontSize = 30 + "px";
         span.style.top = -33 + "px";
      }
   }
Lisa
@coding-lisa
Aug 07 2017 20:32
types?
I'm new at JavaScript, and am having trouble wrapping my brain around objects, variables, etc...
Christopher McCormack
@cmccormack
Aug 07 2017 20:32
@coding-lisa There are primative types like numbers, strings, boolean, etc... and there are objects
Chris Juchtmans
@kjuchtmans
Aug 07 2017 20:33
@coding-lisa an object like { etc etc} can become a variable, simply by assigning it like so var name = {object}
Christopher McCormack
@cmccormack
Aug 07 2017 20:33
@Jacobycodes18 please edit your post to put the backticks on their own line
Chris Juchtmans
@kjuchtmans
Aug 07 2017 20:34
from my starting days I remember getting slapped around the ears constantly with: 'is JS almost anything is an object'
Stephen James
@sjames1958gm
Aug 07 2017 20:34
@kjuchtmans
function sym(args) {
  return [].reduce.call(arguments, (a, c) => {
    // apply symm dif to a and c the code will repeat the process with a new c
  }, []);
}
Christopher McCormack
@cmccormack
Aug 07 2017 20:34
@Jacobycodes18 document.querySelectorAll("input");
Lisa
@coding-lisa
Aug 07 2017 20:35

So, an object is a value in memory (according to developer.mozilla). And an object can become a variable. But not all variables are objects.

Is that correct?

Jacoby Clarke
@Jacobycodes18
Aug 07 2017 20:35
@cmccormack Tried that it gets an error: Uncaught TypeError: inPut.addEventListener is not a function
Chris Juchtmans
@kjuchtmans
Aug 07 2017 20:36
@sjames1958gm have been doing my homework on call, apply and the thisvalue, so if I understand you correctly I want my code to run with arguments as the this value?
Christopher McCormack
@cmccormack
Aug 07 2017 20:36

@Jacobycodes18

Document.querySelector()

Returns the first Element within the document that matches the specified selector, or group of selectors.

Document.querySelectorAll()

Returns a list of the elements within the document (using depth-first pre-order traversal of the document's nodes) that match the specified group of selectors. The object returned is a NodeList.

@Jacobycodes18 use the .forEach method on querySelectorAll()
Stephen James
@sjames1958gm
Aug 07 2017 20:37
@kjuchtmans This code runs reduce against aarguments. [].reduce this is reference to array reduce function
.call says call the function (arguments becomes the "array" that reduce operate on, so it is (I believe) doing what you want.
@kjuchtmans reduce is using arguments as the this value and passing to your function the elements of arguments
Chris Juchtmans
@kjuchtmans
Aug 07 2017 20:38
@sjames1958gm it all sounds beautiful sir, like music to my ears. Now let's see how I get this up and runnin'... thanks @sjames1958gm
CamperBot
@camperbot
Aug 07 2017 20:38
kjuchtmans sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
Jacoby Clarke
@Jacobycodes18
Aug 07 2017 20:38
@cmccormack Thanks! I got it
CamperBot
@camperbot
Aug 07 2017 20:38
:star2: 8265 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Christopher McCormack
@cmccormack
Aug 07 2017 20:39
@Jacobycodes18 :thumbsup:
Jacoby Clarke
@Jacobycodes18
Aug 07 2017 20:40
@cmccormack How would the .forEach be used?
Stephen James
@sjames1958gm
Aug 07 2017 20:41
@coding-lisa a variable can "hold" a value, that can be a number, a string, or a reference to an object.
var a = 10; // the variable is a and the value is 10
var b = "test"; // the variable is b and the value is the string "test"
var c = { prop1: "one", prop2: "two"}; // here c is the variable and the value is the reference to that object.
A variable really just gives a name to a value so that you can use that value elsewhere in the code
Christopher McCormack
@cmccormack
Aug 07 2017 20:41
@Jacobycodes18 to loop over each element that was found that matched your query, then to apply something to that element
Jacoby Clarke
@Jacobycodes18
Aug 07 2017 20:43
@cmccormack Okay where, because i've tried using it and it hasn't worked
Stephen James
@sjames1958gm
Aug 07 2017 20:43

@RoniqueRicketts

if arr[0] is not a number return undefined
if (arr.length > 1)
    if arr[1] is not a number return undefined
    else return the sum of arr[0] and arr[1]
else return the function that you have.

No reason to have a for loop. just straight forward checks

Jim Tryon
@jimtryon
Aug 07 2017 20:44
How can I preserve the log in a JS console between web page refreshes?
Christopher McCormack
@cmccormack
Aug 07 2017 20:44
@Jacobycodes18 What have you tried? I won't write it for you
Jacoby Clarke
@Jacobycodes18
Aug 07 2017 20:45
inPut.ForEach(addEventListener)
Christopher McCormack
@cmccormack
Aug 07 2017 20:46

@Jacobycodes18 .forEach and you should add an anonymous function, something like

inPut.forEach(function(element){
   element.addEventListener('input', change);
   ...
})

This was written without testing so you may want to double check

Lisa
@coding-lisa
Aug 07 2017 20:46
@sjames1958gm okay, so like Objects can contain variables, which are just values. But the object is more like the overall concept?
Christopher McCormack
@cmccormack
Aug 07 2017 20:47
@Jacobycodes18 or you could use a different calllback that also assigns the event listeners
Jacoby Clarke
@Jacobycodes18
Aug 07 2017 20:47
Ahh i see
@cmccormack Thanks!
CamperBot
@camperbot
Aug 07 2017 20:47
jacobycodes18 sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1106 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Aug 07 2017 20:47
@Jacobycodes18 not a problem
Joseph Henshaw
@Big-jo
Aug 07 2017 20:48
please i need help, i have an input box that lets a user type in a city into it and then i want that city to be displayed on a map below the input box, but if i want to use google map api , i would need the longitude and latitude of the place, and that could change according to the user , so how do i go about it ?
Stephen James
@sjames1958gm
Aug 07 2017 20:50
@coding-lisa no, variables can contain references to objects. An object has specific properties in js. But in general an object is an overall convept
Tony Brackins
@mrbrackins
Aug 07 2017 20:50
not really @Big-jo check this out: http://distancebro.herokuapp.com/
made it last week
Christopher McCormack
@cmccormack
Aug 07 2017 20:50
@Big-jo https://developers.google.com/maps/documentation/geocoding/intro google maps API has this functionality as well
Joseph Henshaw
@Big-jo
Aug 07 2017 20:51
@cmccormack @mrbrackins thanks i'm looking at it now
@mrbrackins Your stuff is really amazing
Tony Brackins
@mrbrackins
Aug 07 2017 20:56
@Big-jo Thanks man! let me know if you ever need anything
CamperBot
@camperbot
Aug 07 2017 20:56
mrbrackins sends brownie points to @big-jo :sparkles: :thumbsup: :sparkles:
:cookie: 257 | @big-jo |http://www.freecodecamp.com/big-jo
Lisa
@coding-lisa
Aug 07 2017 20:56

@sjames1958gm so variables don't just contain values, they also contain references?

Thank you, this has helped

CamperBot
@camperbot
Aug 07 2017 20:56
coding-lisa sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8266 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 07 2017 20:57
@coding-lisa When it comes to object (and arrays, since arrays are also objects) variables hold references.
var arr1 = [1, 2, 3]
var arr2 = arr1;
here arr1 and arr2 are the same array
Lisa
@coding-lisa
Aug 07 2017 20:58
@sjames1958gm okay. So can a reference (a variable) also be an object ever?
Stephen James
@sjames1958gm
Aug 07 2017 20:59
@coding-lisa a reference points to an object (refers to an object)
Lisa
@coding-lisa
Aug 07 2017 21:00
@sjames1958gm okay so variables can't ever be objects then, correct?
Ronique Ricketts
@RoniqueRicketts
Aug 07 2017 21:00
@sjames1958gm thank you man
CamperBot
@camperbot
Aug 07 2017 21:00
roniquericketts sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8267 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Adam Bohannon
@abohannon
Aug 07 2017 21:03
Can anyone look at this FCC Beta challenge and tell me if it seems incomplete to you? I don't understand how to use destructuring on a string when the example talks about using it on objects? https://beta.freecodecamp.com/en/challenges/es6/use-destructuring-assignment-to-assign-variables-from-objects
why wouldn't i just do const length = greeting.length;
Elizabeth Paul
@Kowalatam
Aug 07 2017 21:06
@sjames1958gm so i have been at it for a while, and have not successfully looped through the source and compared with the other .. :(
Lisa
@coding-lisa
Aug 07 2017 21:06
@sjames1958gm I'm reading https://www.w3schools.com/js/js_objects.asp and it's confusing me. It says Objects are variables containing variables. Are all objects also a variable then? I'm sorry, I really can't seem to wrap my head around this yet
Jim Tryon
@jimtryon
Aug 07 2017 21:07
@coding-lisa You can think of everything in JS as an object.
@coding-lisa When you create an object, that is assigned to a variable, so variables would be considered a form of an object.
Elizabeth Paul
@Kowalatam
Aug 07 2017 21:09
i have written a lot of weird stuff, kinda here now
function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line
  for (var i = 0; i < collection.length; i++) {
      if (Object.keys(collection[i]).indexOf(Object.keys(source))) {
              for(var name in collection[i]) {
                var value = collection[i][name];
                //onsole.log(Object.values(source))
                for (var j = 0; j < Object.keys(source).length; j++) {
                    //console.log(Object.values(source)[j])
                    if (Object.values(source)[j] === value) {
                        console.log(Object.values(source)[j], value)
                        arr.push(collection[i]);
                    }
                }

            }
      }
  } console.log(arr)


  // Only change code above this line
  return arr;
}

whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 })
the problem is, i need to loop to source key and values to make sure that all of them are in any of the objects in collection
Walther Cantu
@walthercantu
Aug 07 2017 21:11
Hello, would appreciate some help with my FCC Twitch.tv project. So far I've been able to set up an ajax call to https://wind-bow.gomix.me/twitch-api/streams/freecodecamp to get the JSON response to check if FCC is live. I'm a little trouble getting the json object into a string and displaying it on screen. I have added JQuery in the Javascript settings of the pen but it still doesn't work. Here's the pen: https://codepen.io/walthercantu/pen/wqJaxb
kumquatfelafel
@kumquatfelafel
Aug 07 2017 21:11
Not really. Primitives are not objects. Numbers and strings do have associated javascript objects, e.g., do have associated objects that can be used as wrapper though. This is useful, for example, when you're trying to invoke functions on a string.
Stephen James
@sjames1958gm
Aug 07 2017 21:11
@Kowalatam You don't need three loops you need one over collection and one over keys of source
Elizabeth Paul
@Kowalatam
Aug 07 2017 21:12
@sjames1958gm lol, i like loops :)
@sjames1958gm wait, one for keys ?, i was having the feeling my first if statement wasn't working
hmmm
Stephen James
@sjames1958gm
Aug 07 2017 21:13
@coding-lisa objects can contain values (key/value) properties (but not variables)
Elizabeth Paul
@Kowalatam
Aug 07 2017 21:13
ganna just start over :(
Stephen James
@sjames1958gm
Aug 07 2017 21:14
@Kowalatam Keep your for loop over collection. Then for each collection[i]
check every key in source and make sure that collection[i] has the key and source[key] == collection[i][key]
Elizabeth Paul
@Kowalatam
Aug 07 2017 21:15
@sjames1958gm okay, thanks
CamperBot
@camperbot
Aug 07 2017 21:15
kowalatam sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8268 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Elizabeth Paul
@Kowalatam
Aug 07 2017 21:16
lemme see
Walther Cantu
@walthercantu
Aug 07 2017 21:26
Hello, would appreciate some help with my FCC Twitch.tv project. So far I've been able to set up an ajax call to https://wind-bow.gomix.me/twitch-api/streams/freecodecamp to get the JSON response to check if FCC is live. I'm a little trouble getting the json object into a string and displaying it on screen. I have added JQuery in the Javascript settings of the pen but it still doesn't work. Here's the pen: https://codepen.io/walthercantu/pen/wqJaxb
Jason Luboff
@JLuboff
Aug 07 2017 21:27
@walthercantu You're not getting any data back in your AJAX call. Look in your browsers console. (typically F12 if you're using windows)
@walthercantu Try adding dataType: 'jsonp', to your ajax call
Jim Tryon
@jimtryon
Aug 07 2017 21:31
Is it true that we say bling for jQuery? So like $('li') is bling li? I’ve never heard that.
Jason Luboff
@JLuboff
Aug 07 2017 21:32
@jimtryon Personally I've never heard that term, but I am also not a professional
Walther Cantu
@walthercantu
Aug 07 2017 21:32
@JLuboff Oh snap, that worked! What's the difference between json and jsonp?
Walther Cantu
@walthercantu
Aug 07 2017 21:33
@JLuboff much appreciated
Joel Y.
@zapcannon99
Aug 07 2017 21:33
jsonp is made for cross-server calls
Walther Cantu
@walthercantu
Aug 07 2017 21:33
@JLuboff thank you
CamperBot
@camperbot
Aug 07 2017 21:33
walthercantu sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2135 | @jluboff |http://www.freecodecamp.com/jluboff
Anthony Armfield
@Anthony-Armfield
Aug 07 2017 21:40

Hey guys. If I have an array of numbers, and want to iterate through that array using arr.length in a for loop, but want to include those numbers as part of a calculation, how would I do that? For instance, say I want to find all numbers that are equally divisible by each number from 1 to 10. I could set up the for loop to be something like:

for (let i = 0; i <= arr.length; i++) {
        if(num % arr[i] === 0){
        numbers.push(num);
        num++;
    } else {
        num++;
    }
}

And I want arr to be 0-10, while also using arr's 0-10 to test if a number can be equally divisible by that number AND the next number, AND the next number, and so on. Any way to do this without making 10 if statements nested inside each other?

kumquatfelafel
@kumquatfelafel
Aug 07 2017 21:41
@Anthony-Armfield you mean like a for loop inside a for loop?
Anthony Armfield
@Anthony-Armfield
Aug 07 2017 21:42
@kumquatfelafel sort of.
Let me get my code into a pen and show you what I have so far.
Here is what I have so far. I was trying to simplify the explanation. https://codepen.io/aarmfield/pen/KvNYzG?editors=0010
kumquatfelafel
@kumquatfelafel
Aug 07 2017 21:46
btw, you don't want to do num % 0.
Anthony Armfield
@Anthony-Armfield
Aug 07 2017 21:46
When you run that you will get a console log that shows the array with 693 results. I need to find the lowest number that is evenly divisible by all numbers between 1 and 10.
intcreate
@intcreate
Aug 07 2017 21:47

im getting error

type error cannot read property toLowerCase of undefined

split[i][i+1].toLowerCase()
kumquatfelafel
@kumquatfelafel
Aug 07 2017 21:47
So basically, you're looking for the LCM of the range 1 - 10?
Anthony Armfield
@Anthony-Armfield
Aug 07 2017 21:47
I started off creating an if statement that checked if the number was evenly divisible by 10, then if it was to do the same check, but by 9, and then again by 8 and so on. I wanted to clean that code up and run for loops, but can't figure out how to use the same array for the length, and the divisible number.
Yes. I can get this using if statements nested inside each other, but I wanted a bit of a cleaner code.
@kumquatfelafel
Stephen James
@sjames1958gm
Aug 07 2017 21:49
@intcreate Was is the variable split set to?
intcreate
@intcreate
Aug 07 2017 21:49

function titleCase(str) {

  // Split each word and put into array
  var split = str.split(" "); // Split where space occurs
  var edit = [];

  // Uppercase first letter of each word, lower case all other letters of word
  for(var i = 0; i < split.length; i++) {
    edit[i] = split[i][0].toUpperCase() + split[i][i+1].toLowerCase();
  }

  // Join
  edit.join(" ");

  return str;
}

titleCase("I'm a little tea pot");
Stephen James
@sjames1958gm
Aug 07 2017 21:50
@intcreate when i is 3 split[3] is tea and split[3][4] doesn't exist (undefined)
Jason Luboff
@JLuboff
Aug 07 2017 21:50
@intcreate Instead of this split[i][i+1].toLowerCase(); I would advise looking at slice
intcreate
@intcreate
Aug 07 2017 21:51
ok ill check it out again
soulproprietor
@soulproprietor
Aug 07 2017 21:55
hello !I please forgive me if this is the wrong place to ask this, but I have i have a question about an FCC project, can I ask it here?
Jason Luboff
@JLuboff
Aug 07 2017 21:55
Sure
Stephen James
@sjames1958gm
Aug 07 2017 21:55
@soulproprietor sure
Jim Tryon
@jimtryon
Aug 07 2017 21:55
Yeah, I don’t see why not
soulproprietor
@soulproprietor
Aug 07 2017 21:56
I'm on the local weather app, and the google API info is in vanilla javascript, but tne previous challenge had us using jquery and ajax. when should I use vanilla javascript, and when should I use jquery?
Stephen James
@sjames1958gm
Aug 07 2017 21:57
@soulproprietor There is really no hard and fast rule.
kumquatfelafel
@kumquatfelafel
Aug 07 2017 21:57
@Anthony-Armfield I'm still not entirely sure what you're trying to do... Say I call getDivNumArray(4), then isDivisible(). What should the result be?
Stephen James
@sjames1958gm
Aug 07 2017 21:58
@soulproprietor If you can do it in vanilla js then you won't have to load jquery library which does take > non-zero time to load
kumquatfelafel
@kumquatfelafel
Aug 07 2017 22:01
@Anthony-Armfield all numbers from 1 - 1000 that are divisible by 1 and 2 and 3 and 4?
Elizabeth Paul
@Kowalatam
Aug 07 2017 22:03
@sjames1958gm so, im stuk again :(. collection[i] key is an array of all they keys and i using an equality of that with source key doesn't work :(
kumquatfelafel
@kumquatfelafel
Aug 07 2017 22:03
post code
Elizabeth Paul
@Kowalatam
Aug 07 2017 22:04
function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line
  for (var i = 0; i < collection.length; i++) {
      console.log(Object.keys(collection[i]))
      for (var j = 0; j < Object.keys(source).length; j++) {
          if(Object.keys(collection[i]) === Object.keys(source)[j]) {
              arr.push(collection[i])
              console.log(Object.keys(source)[j])
          }
      }
  } console.log(arr)


  // Only change code above this line
  return arr;
}

whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 })
Stephen James
@sjames1958gm
Aug 07 2017 22:05
put Object.keys(source) into a variable
var keys = Object.keys(source)
now you can do
collection[i][keys[j]]
and source[keys[j]]
to compare
With your code you could do collection[i][Object.keys(source)[j]] === source[Object.keys(source)[j]]
codeolas
@codeolas
Aug 07 2017 22:06
var arr = [ {"name": "Pete", "onBoat": true}, 
            {"name": "Repeat", "onBoat": true, "alias": "Repete"}, 
            {"name": "FastFoward", "onBoat": true}];



function truthCheck(collection, pre) {
  // Is everyone being true?
   var truth = true;
   console.log(pre);
   console.log(collection[0].onBoat);
   console.log(collection[0].pre);

    for(var obj in collection){
          if(!obj.pre){

          truth = false;
          //break;
          }
    }

  return truth;
}

truthCheck([{"name": "Pete", "onBoat": true}, {"name": "Repeat", "onBoat": true, "alias": "Repete"}, {"name": "FastFoward", "onBoat": true}], "onBoat");

Hey guys, got a weird one again. Three console logs at the top. The one that says

console.log(collection[0].pre);

comes up as undefined. Since pre === onBoat, why is that not defined?

Stephen James
@sjames1958gm
Aug 07 2017 22:07
@codeolas .pre is looking for ["pre"] not ["onBoat"]
kumquatfelafel
@kumquatfelafel
Aug 07 2017 22:07
@Kowalatam The only time comparing two arrays with === will return true is if the two arrays are in the same location in memory (identical)
Elizabeth Paul
@Kowalatam
Aug 07 2017 22:08

@sjames1958gm okay.. looks confusing, but i will say okay :).

put Object.keys(source) into a variable
var keys = Object.keys(source)
now you can do
collection[i][keys[j]]
and source[keys[j]]
to compare

kumquatfelafel
@kumquatfelafel
Aug 07 2017 22:08
@Kowalatam just to sort of show you what I mean...
https://repl.it/KAap
Stephen James
@sjames1958gm
Aug 07 2017 22:08
@Kowalatam keys[j] is a key so source[keys[j]] is the value in source for that key, the same as for collection[i][keys[j]]
Elizabeth Paul
@Kowalatam
Aug 07 2017 22:09
@kumquatfelafel i tried to identical arrays and it gave false eg
[1, 2] === [1, 2]
codeolas
@codeolas
Aug 07 2017 22:09
@sjames1958gm :+1:
Stephen James
@sjames1958gm
Aug 07 2017 22:10
@codeolas :+1:
Elizabeth Paul
@Kowalatam
Aug 07 2017 22:10
@sjames1958gm ohhh, i always got the values a different way, that is by Object.values(source)...
cool. thanks
CamperBot
@camperbot
Aug 07 2017 22:10
kowalatam sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: kowalatam already gave sjames1958gm points
kumquatfelafel
@kumquatfelafel
Aug 07 2017 22:10
@Kowalatam Yes. That's to be expected, because object === comparison doesn't work in comparing the value of what is at particular memory location of object, like you might expect. Rather, it sees if the location in memory is the same. As @sjames1958gm points out, you can compare the values of the object one by one though.
Elizabeth Paul
@Kowalatam
Aug 07 2017 22:11
@kumquatfelafel okay, thanks,
CamperBot
@camperbot
Aug 07 2017 22:11
kowalatam sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 579 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Elizabeth Paul
@Kowalatam
Aug 07 2017 22:11
spent my whole day on this stuff :(...
aish.. i like it though :)
Jim Tryon
@jimtryon
Aug 07 2017 22:12
Is there a convention for coming up with a repo name? Would chess-js-game be good?
Brad
@bradtaniguchi
Aug 07 2017 22:31
@jimtryon i would say it depends on what language you plan on using
Jim Tryon
@jimtryon
Aug 07 2017 22:31
@bradtaniguchi I plan on using jQuery
Brad
@bradtaniguchi
Aug 07 2017 22:33
My vote is 'chessjs-game', alot of javascript repos smash the name with js at the end, with or without a dot. but its up to you, just no spaces haha
Marin
@MarinBegovic
Aug 07 2017 22:34
hi
anyone here familiar with waypoints.js
i have some questions about it
Jason Luboff
@JLuboff
Aug 07 2017 22:35
Yup. I avoid spaces. I'll normally do capital firstletter and no spaceing. So StockChartApp or on occasion use dashes Stock-Chart-App but prefer the first one
Joseph Henshaw
@Big-jo
Aug 07 2017 22:41
<script>
function myMap() {
var mapProp= {
    center:new google.maps.LatLng(51.508742,-0.120850),
    zoom:5,
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
}
</script>

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_KEY&callback=myMap"></script>
@cmccormack since this is how a normal map is setup using google API can you give me an example using geocoding?
Christopher McCormack
@cmccormack
Aug 07 2017 22:42
@Big-jo they should be on the page I linked, I haven't worked with Google Maps api in years though
Joseph Henshaw
@Big-jo
Aug 07 2017 22:43
@cmccormack :cry: its not there
Christopher McCormack
@cmccormack
Aug 07 2017 22:44
@Big-jo in 4 seconds I was able to do this search - http://maps.googleapis.com/maps/api/geocode/json?address=Phoenix
Joseph Henshaw
@Big-jo
Aug 07 2017 22:44
var mapProp= {
    center:new google.maps.LatLng(51.508742,-0.120850),
    zoom:5,
}
i was just wondering if the mapProp object is important
@cmccormack lmaoo
Christopher McCormack
@cmccormack
Aug 07 2017 22:45
you gotta play with it a bit
Joseph Henshaw
@Big-jo
Aug 07 2017 22:45
i'm talking about , what do i do with the MapProp object, since it has longitude and latitude
Christopher McCormack
@cmccormack
Aug 07 2017 22:45
look at lots of examples
Joseph Henshaw
@Big-jo
Aug 07 2017 22:46
and i cant be sure f what it will be since there will be any users and want to use geocoding
Jason Luboff
@JLuboff
Aug 07 2017 22:46
@cmccormack Damn bro, throwing shade
Christopher McCormack
@cmccormack
Aug 07 2017 22:47
Haha @JLuboff Sorry @Big-jo just stressing about work didn't mean to be short with ya
Jason Luboff
@JLuboff
Aug 07 2017 22:47
@cmccormack Stop stressin' brotatoe. All is chill
Jim Tryon
@jimtryon
Aug 07 2017 22:47
Is this a good enough description for a github repo?
A classic javascript game built using Bootstrap and jQuery.
Joseph Henshaw
@Big-jo
Aug 07 2017 22:48
@cmccormack no p, you're really helping anyways
Christopher McCormack
@cmccormack
Aug 07 2017 22:48
@Big-jo I'm not exactly sure what your question is - you shouldn't be hardcoding the lat lon if you want it to be dynamic - you should instead use city as your search criteria then look at the json response object to gather the lat lon to use in your map
Joseph Henshaw
@Big-jo
Aug 07 2017 22:48
@cmccormack Thanks
Jason Luboff
@JLuboff
Aug 07 2017 22:48
@jimtryon I don't even create a description for mine lol. And only maybe half have readme's (which I should get better about)
Christopher McCormack
@cmccormack
Aug 07 2017 22:48
City might be enough to do what you need though
Joseph Henshaw
@Big-jo
Aug 07 2017 22:48
@cmccormack yeah
Christopher McCormack
@cmccormack
Aug 07 2017 22:50
@Big-jo you may consider a look-ahead library for cities so you can persuade users to select one that is almost guaranteed to have a result
Joseph Henshaw
@Big-jo
Aug 07 2017 22:50
@cmccormack how do i do that
Christopher McCormack
@cmccormack
Aug 07 2017 22:52
@Big-jo beats me, but it sounds like a good idea :D
Joseph Henshaw
@Big-jo
Aug 07 2017 22:53
@cmccormack Alright, thanks, i'll look for the rest, goodluck with work
Christopher McCormack
@cmccormack
Aug 07 2017 22:53
@Big-jo thanks
CamperBot
@camperbot
Aug 07 2017 22:53
cmccormack sends brownie points to @big-jo :sparkles: :thumbsup: :sparkles:
:cookie: 258 | @big-jo |http://www.freecodecamp.com/big-jo