These are chat archives for FreeCodeCamp/HelpJavaScript

11th
Sep 2017
Inferfire
@Inferfire
Sep 11 2017 00:03
@jodylecompte Yeah, I am using a canvas
Jody LeCompte
@jodylecompte
Sep 11 2017 00:50

I haven't done anything with sprites on canvas in some time unfortunately, but I can atleast explain the logic behind it. What you want to do is determine when you check the X and Y of a sprite, where is that X and Y actually located? Is it the top corner? bottom corner? You can test this if you aren't already sure by drawing a sprite at 0,0 and then checking what the x and y.

Once you determine that, it's just a matter of figuring out where you don't want your player to go. For example, if I were making a snake game where the field is 500 pixels wide and 500 pixels tall, I would want to make sure my player is never below 0 or above 500 in either axis. The reason you need to determine where the X and Y lies is because thats how you know what math you need to do to adjust for the sprite. Let's say for example the sprite is 50x50 pixels, and X is measured from the top left hand corner. Then for the left hand border you could just do X < 0 while for the right hand border, you'll need to do x + 50 since you want the right hand corner o the sprite to not cross over as well. The same applies to top and bottom on the Y axis.

Does that make sense? @Inferfire

Inferfire
@Inferfire
Sep 11 2017 01:01
X and Y is located on the top left corner
But yeah it makes sense, just I'm not sure how to implement it
CamperBot
@camperbot
Sep 11 2017 01:03
inferfire sends brownie points to @jodylecompte :sparkles: :thumbsup: :sparkles:
:star2: 1229 | @jodylecompte |http://www.freecodecamp.com/jodylecompte
Jody LeCompte
@jodylecompte
Sep 11 2017 01:04
Start by figuring out where your boundaries actually are
Since you've confirmed its top left corner, that means for the left side, and the top side, you just need to make sure X is greater than your boundary
Then for right and for bottom, you need to add the sprites size
so if you just did if(sprite.y < 500), and your sprite is 50 pixels wide, then it would allow the extra to spill over since you're looking at top left corner, so youd do y + sprite height and x + sprite width
Inferfire
@Inferfire
Sep 11 2017 01:32
Using my player as player and platform as entity I tried
if (entity.y < player.y && (entity.x + entity.w) > player.x + 10 && entity.x < (player.x + player.w)
But I'm not sure what's wrong because what I wrote means the player is inside the wall right?
Jody LeCompte
@jodylecompte
Sep 11 2017 02:10
What is entity?
Gersho
@Gersho
Sep 11 2017 02:10
i assumed it was the walls
Gersho
@Gersho
Sep 11 2017 03:19

is there an equivalent to

$(document).ready(function(){}

in vanilla js ?

Claudio Restifo
@Marmiz
Sep 11 2017 03:25
@Gersho
I think you could add an event listener to DOMContentLoaded (not sure this is the exact browser implementation, maybe search MDN for the exact name`
Or use an IIFE into the body :)
Gersho
@Gersho
Sep 11 2017 03:26
thanks @Marmiz what's an IIFE ?
CamperBot
@camperbot
Sep 11 2017 03:26
gersho sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1039 | @marmiz |http://www.freecodecamp.com/marmiz
Claudio Restifo
@Marmiz
Sep 11 2017 03:27

@Gersho Immediately Invoked Function Expression.
A function that runs immediately.

https://developer.mozilla.org/en-US/docs/Glossary/IIFE

Gersho
@Gersho
Sep 11 2017 03:28
i'll end up with 15 tabs open again D: but Gersho += knowledge;
Nadia
@nadiaschutz
Sep 11 2017 04:23
hi guys
is anyone here?
Coy Sanders
@coymeetsworld
Sep 11 2017 04:29
@nadiaschutz :wave:
Nadia
@nadiaschutz
Sep 11 2017 04:32
@coymeetsworld hi
Coy Sanders
@coymeetsworld
Sep 11 2017 04:32
hello, what's up?
Gersho
@Gersho
Sep 11 2017 04:37
i'm here too
Nadia
@nadiaschutz
Sep 11 2017 04:44
well..i just need someone to check my code...i am refactoring my spaghetti code ...and my app acts strange
Coy Sanders
@coymeetsworld
Sep 11 2017 04:44
I can take a look
one thing that would be helpful when refactoring also is writing unit tests. That way you can tell pretty quickly if you introduce any regressions
Claudio Restifo
@Marmiz
Sep 11 2017 04:47
yay! :spaghetti:
Coy Sanders
@coymeetsworld
Sep 11 2017 04:54
what issues are you having @nadiaschutz ?
Gersho
@Gersho
Sep 11 2017 04:54
i tried inputing "Nadia said you must be fixed", the assistant refreshed pretending it never happened, Hal is out there
Nadia
@nadiaschutz
Sep 11 2017 04:57
idk what issues i have...it acts different in my brackets
when i click the submit button, it just closes itself
but i dont see this action in codepen
Coy Sanders
@coymeetsworld
Sep 11 2017 04:59
you do need to fix some of your import
you're importing app.js and chatbot-dp.css
Nadia
@nadiaschutz
Sep 11 2017 04:59
and?
Coy Sanders
@coymeetsworld
Sep 11 2017 04:59
that code needs to go into the CSS and JS panes, or use codepen projects if you want to work w/ multiple files
im not sure if that's causing the issue, idk what is in either of those files
Nadia
@nadiaschutz
Sep 11 2017 05:11
@coymeetsworld well the main issue what i see on codepen is that when i "submit" string and press enter console log works...but! the app closes ...it shouldn't
Claudio Restifo
@Marmiz
Sep 11 2017 05:22
@nadiaschutz that's a specific codepen behaviour I think... a simple preventDefault() should stop codepen from reloading in place
Nadia
@nadiaschutz
Sep 11 2017 05:23
@Marmiz it acts more weird on my local.....
Coy Sanders
@coymeetsworld
Sep 11 2017 05:24
yes I think that's correct, because you're using a submit button
Claudio Restifo
@Marmiz
Sep 11 2017 05:25
@nadiaschutz well submitting a form by default refresh the page since it's sending a POST request (i believe)
Coy Sanders
@coymeetsworld
Sep 11 2017 05:25
perhaps you should replace that with a normal button, or prevent the default behavior of submit buttons which does reload the page
Claudio Restifo
@Marmiz
Sep 11 2017 05:28
@nadiaschutz for reference what I generally do when dealing with forms:
if (e !== undefined && e.preventDefault) e.preventDefault();
If I want to handle the submission by myself of course
Nadia
@nadiaschutz
Sep 11 2017 05:29
@Marmiz k
Nadia
@nadiaschutz
Sep 11 2017 05:39
thank you guys
@Marmiz thanks
CamperBot
@camperbot
Sep 11 2017 05:41
nadiaschutz sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1040 | @marmiz |http://www.freecodecamp.com/marmiz
Nadia
@nadiaschutz
Sep 11 2017 05:41
@coymeetsworld thanks
Claudio Restifo
@Marmiz
Sep 11 2017 05:41
@nadiaschutz working as expected?
Nadia
@nadiaschutz
Sep 11 2017 05:41
i found the error
now fixing other errors lol
Markus Kiili
@Masd925
Sep 11 2017 05:45
@Marmiz Do you know cases when the event object would be undefined?
Claudio Restifo
@Marmiz
Sep 11 2017 05:50

@Masd925 in reality never, I think happened to me once in a React component while mounting a null child.
Was something as dumb as that.

It remained there since then

or maybe if you forget to pass the event? Dunno how the browser handles it. I think FF pass it as undefined
Markus Kiili
@Masd925
Sep 11 2017 06:10
@Marmiz I think that the browser always passes the event object as the first argument to the event callback. If you forget to write the parameter, an error would be nice.
One related problem with using parameter name event on the callback is that if you do forget to write the parameter, you are using the global window.event which is a non-standard technology and causes fun.
Emmanuel Akodia
@akodiaemma
Sep 11 2017 06:59
whener i run this code on my server, it says Parse error: syntax error, unexpected 'do' (T_DO)
    $takenNumbers = array(123234, 987578 ,356763 , 127432 )
    do {   
        $randomSixDigitNumber = rand(100000,999999);

    } while(in_array($randomSixDigitNumber, $takenNumbers);
    echo $randomSixDigitNumber;
Gersho
@Gersho
Sep 11 2017 07:01
; at end of first line ?
Emmanuel Akodia
@akodiaemma
Sep 11 2017 07:08
thanks bro
@Gersho it now says "unexpected echo"
does the echo require brackets of some sort or
Claudio Restifo
@Marmiz
Sep 11 2017 07:14
@akodiaemma think you are missing a closing parenthesis for the in_array
Abhi
@abhigk
Sep 11 2017 07:21
Hi Everybody
I was doing palindrome challenge. And I found way to remove non-alphanumeric characters. Using
input.replace(/\W/g, '')
But I can't understand this code. Anybody can explain it to me please?
Blauelf
@Blauelf
Sep 11 2017 07:26
@abhigk This replaces certain characters with the empty string (essentially removing them in the returned copy). \w is alphanumeric plus underscore, so \W is anything neither alphanumeric nor underscore. You need to add the underscore to pass some of the tests.
Gersho
@Gersho
Sep 11 2017 07:27
and if you know where all this comes from, you want to google up "regex"
Blauelf
@Blauelf
Sep 11 2017 07:29

There's also a list https://forum.freecodecamp.org/t/regular-expressions-resources/15931

I'd add regexr.com to the list of RegExp playgrounds.

Abhi
@abhigk
Sep 11 2017 07:31
Thanks for help @Blauelf @Gersho
CamperBot
@camperbot
Sep 11 2017 07:31
abhigk sends brownie points to @blauelf and @gersho :sparkles: :thumbsup: :sparkles:
:cookie: 411 | @gersho |http://www.freecodecamp.com/gersho
:star2: 4596 | @blauelf |http://www.freecodecamp.com/blauelf
Zhang LIn
@zl-cheetah
Sep 11 2017 07:34
image.png
Blauelf
@Blauelf
Sep 11 2017 07:37
@zl-cheetah You ignore the result of myobj.hasOwnProperty(checkProp). You could use it as the condition of an if.
Nadia
@nadiaschutz
Sep 11 2017 07:38
could you please help me : why does it say "Cannot read property 'value' of null"??
Zhang LIn
@zl-cheetah
Sep 11 2017 07:38
@Blauelf Thanks for help.
CamperBot
@camperbot
Sep 11 2017 07:38
zl-cheetah sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4597 | @blauelf |http://www.freecodecamp.com/blauelf
Jake
@JakeDVirus
Sep 11 2017 07:39
how to convert this curl command information to jquery ajax call
curl -H 'Accept: application/vnd.twitchtv.v5+json' \
-H 'Client-ID: uo6dggojyb8d6soh92zknwmi5ej1q2' \
Abhi
@abhigk
Sep 11 2017 07:41
@nadiaschutz because element doesn't exist. You can check using if-else before reading the element.
Claudio Restifo
@Marmiz
Sep 11 2017 07:43
@nadiaschutz also you confused the JQuery syntax with Vanilla one:
getElementById("#chat-input__text") should just be
getElementById("chat-input__text")
Nadia
@nadiaschutz
Sep 11 2017 07:44
yeah i fixed that
Blauelf
@Blauelf
Sep 11 2017 08:03
@NeelDVirus Try the headers property of a request object, like
$.ajax({
    url : "http://some/url",
    headers : {
        'Accept' : 'application/vnd.twitchtv.v5+json',
        'Client-ID' : 'uo6dggojyb8d6soh92zknwmi5ej1q2'
    }
});
Jake
@JakeDVirus
Sep 11 2017 08:06
@Blauelf yeah this will work i presume. Btw will it create cross-origin--resource-sharing issue if the request is cross origin?
Blauelf
@Blauelf
Sep 11 2017 08:08
@NeelDVirus This totally depends on the headers the server responds with. Maybe you need to tell it to respond with these headers (Wikipedia is that way), maybe you don't have to, maybe you cannot (some APIs that are not meant to be used from a browser don't add those headers, and to still use them you need some proxy)
Jake
@JakeDVirus
Sep 11 2017 08:10
@Blauelf oh then it seems "Client-ID" header is meant for CORS permission
Blauelf
@Blauelf
Sep 11 2017 08:11
So there's a specific website associated with this Client-ID?
Jake
@JakeDVirus
Sep 11 2017 08:13

@Blauelf there is a specific website "twitch.tv" of whose API i need to integrate in my twitch.tv project as part of FCC challenge.
in the documentation of their API it is stated that

To identify your application to the API, every request must include your application’s client ID, either explicitly or implicitly

insouciantone
@insouciantone
Sep 11 2017 09:16
I'm sure I'm buthering my implementation but I'm at a loss on what I should be doing. I'm trying to implement the twitch API and I can't get the second portion of my if statements to trigger, the status variable stays as "undefined". Anyone who would mind throwing me a bone? https://pastebin.com/6Jczsi3w
LydaTech
@lydatech
Sep 11 2017 09:18
anyone using lite-server with node?
Stephen James
@sjames1958gm
Sep 11 2017 09:59
@insouciantone All the calls to statusCheck will be with count as zero because they all run consecutively before count++
happens
@NeelDVirus FCC provides a proxy to allow requests with out client id
https://wind-bow.glitch.me/twitch-api/streams/
insouciantone
@insouciantone
Sep 11 2017 10:01
@sjames1958gm Except not really because when the program runs it goes through the list of streams but it doesn't call the 2nd half of the if statement
count increments as expected but the status does not return as expected so the if statement doesn't trigger to use the streams URL instead of the users
Stephen James
@sjames1958gm
Sep 11 2017 10:03
@insouciantone It doesn't go through the list of streams.
If this is all the code when
statusCheck()
statusCheck()
both times count will be zero because count++ inside the second function only happens after the response
Try console.log(stream) before the $getJSON calls to see
insouciantone
@insouciantone
Sep 11 2017 10:04
I can see with my own eyes that it goes through the list of streams when I run the program
unless I'm missing something here my issue is that the data.stream call returns null every time
Nadia
@nadiaschutz
Sep 11 2017 10:06
guys, how to post ajax request with function in the link?...the main question what function should i use...my guess its REST (?)
var endpoint = url + '/webapi?dpid=' + DPID + '&channel=' + sessionkey + '&threshold=' + TOP_THRESHOLD + '&threshlow=' + BOTTOM_THRESHOLD + '&phrase=' + encodeURIComponent(message) + 'somecompany&callback=' + somefunction;
Stephen James
@sjames1958gm
Sep 11 2017 10:07
@insouciantone You aren't passing count to statusCheck()
function statusCheck(count) << this count will be undefined
Nadia
@nadiaschutz
Sep 11 2017 10:07
i don't get what is "somefunction"
korzo
@korzo
Sep 11 2017 10:07
@nadiaschutz it's name of the function
for reference
Nadia
@nadiaschutz
Sep 11 2017 10:07
ok...which function?
insouciantone
@insouciantone
Sep 11 2017 10:08
also the count passed to statusCheck was superfluous, I got rid of it.
I missed deleting it from something else I was trying to do. Even after getting rid of it it doesn't work
Nadia
@nadiaschutz
Sep 11 2017 10:08
@korzo ok...which function?
korzo
@korzo
Sep 11 2017 10:09
@nadiaschutz function, which will process data returned from api.
I suppose it's JSONP
Stephen James
@sjames1958gm
Sep 11 2017 10:09
@insouciantone I added
console.log(stream)
right before your first $.getJSON
both times it requests freecodecamp
insouciantone
@insouciantone
Sep 11 2017 10:10
That's crazy why does the second element populate as the second stream in that case?
Stephen James
@sjames1958gm
Sep 11 2017 10:11
Because one of the responses does return and count is incremented before the second call to populate()
This is the timeline
count=0
statusCheck()
statusCheck()
populate(status)
count++
populate(status)
insouciantone
@insouciantone
Sep 11 2017 10:12
I guess I'm running into the same issue I did when trying to pass the statusCheck. The count variable isn't keeping its value.
Am I going to have to create another function that passes the value of count back to the variable?
korzo
@korzo
Sep 11 2017 10:12
@nadiaschutz If you are using jQuery, it can do it for you https://learn.jquery.com/ajax/working-with-jsonp/
Stephen James
@sjames1958gm
Sep 11 2017 10:14
Don't depend on a global pass the values through the function calls (get rid of count)
streamList.forEach(function(stream) { statusCheck(stream);})
then pass stream to populate
populate(stream, status)
insouciantone
@insouciantone
Sep 11 2017 10:15
ah, of course. That's a way better implementation. Thanks @sjames1958gm
CamperBot
@camperbot
Sep 11 2017 10:15
insouciantone sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8456 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Nadia
@nadiaschutz
Sep 11 2017 10:15
@korzo sent you PM
Stephen James
@sjames1958gm
Sep 11 2017 10:15
@insouciantone :+1:
Globals and async code are a headache
insouciantone
@insouciantone
Sep 11 2017 10:16
You're tellin' me. Hah.
RakeshNerkar
@Rakesh18754
Sep 11 2017 10:26
how to make "private" variables (those defined in the constructor), available to prototype-defined methods?
@Rakesh18754 My first thought was you can't - but there is much discussion at that link.
Markus Kiili
@Masd925
Sep 11 2017 10:35
@Rakesh18754 I think you cannot do that. Either you define the methods inside the constructor, or put the variables as properties.
RakeshNerkar
@Rakesh18754
Sep 11 2017 10:54
@sjames1958gm i read that but could nt undesrstood so was looking for help here
insouciantone
@insouciantone
Sep 11 2017 10:54
I hit a fresh roadblock. Why is this showing up as undefined? The URL seems to be passing correctly. https://codepen.io/insouciance/pen/BwBjye
insouciantone
@insouciantone
Sep 11 2017 11:19
I got it, thanks
Omran Jamal
@omranjamal
Sep 11 2017 11:54
Hey guys. I made new kind of programming-ish language using Javascript. So I was wondering if it would be appropriate to share it on the FreeCodeCamp facebook groups. Will people spite me if I do?
Johnny
@JohnnyBizzel
Sep 11 2017 12:01
@omranjamal Why would they spite you?
Markus Kiili
@Masd925
Sep 11 2017 12:02
@omranjamal Is it a programming language or a JS library?
Omran Jamal
@omranjamal
Sep 11 2017 12:05
@Masd925 Both TBH. See for yourself https://hedronium.github.io/PhraseEngine/
@JohnnyBizzel For self promotion maybe. :'(
Tess0704
@Tess0704
Sep 11 2017 12:17
anyone one can tell me what's wrong with my code, got no output, wanna cry.....
$.ajax( {
url: 'https://en.wikipedia.org/w/api.php?action=query&titles=Main%20Page&prop=revisions&rvprop=content&format=json',
data: 'butterfly',
dataType: 'json',
type: 'POST',
headers: { 'Api-User-Agent': 'Example/1.0' },
success: function(response) {
$('.df').append('<div class = "result">'+response+'</div>');
}// do something with data
} );
Abhinav Mishra
@abhinav-m
Sep 11 2017 12:19
@omranjamal thats cool stuff :)
Hello everyone can someone offer an explanation to the working of this piece of code
for (var i = 1000; i <= 10000; i += 1000) {
    setTimeout(function() {
        console.log(i);
    }, i);
}
it prints 11000 ten times
Blauelf
@Blauelf
Sep 11 2017 12:21
@Tess0704 You might need a origin=* parameter against CORS issues. Also, I think your data field might not be what the API expects.
Abhinav Mishra
@abhinav-m
Sep 11 2017 12:21
my understanding is , the for loop is run in the callstack, the last value of i is 11000
Markus Kiili
@Masd925
Sep 11 2017 12:21
@abhinav-thinktank All those timeout callbacks use the same i variable that has value 11000 after the loop has run out.
Abhinav Mishra
@abhinav-m
Sep 11 2017 12:21
setTimeout references the last value of i
@Masd925 hmm, im confused with that part, so since its the same variable it references the last value of that variable
Blauelf
@Blauelf
Sep 11 2017 12:22
@abhinav-thinktank All those function expressions have a common reference to variable i. After the loop, its value is 11000, and all those 10 callbacks will probably print that value.
Tess0704
@Tess0704
Sep 11 2017 12:22
@Blauelf then where should I put the origin thing & what i should write for data?
Markus Kiili
@Masd925
Sep 11 2017 12:22
@abhinav-thinktank Those callbacks execute at some point later when the timeout events fire and when they evaluate the i variable, they look up the scope chain and find that same loop variable.
@abhinav-thinktank So that script executes first and those callbacks execute later.
Abhinav Mishra
@abhinav-m
Sep 11 2017 12:24
@Masd925 aah , ok thanks!
CamperBot
@camperbot
Sep 11 2017 12:24
abhinav-thinktank sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4478 | @masd925 |http://www.freecodecamp.com/masd925
Abhinav Mishra
@abhinav-m
Sep 11 2017 12:24
@Blauelf ty!
Blauelf
@Blauelf
Sep 11 2017 12:25
@Tess0704 Add origin=* as another parameter to the URL. And the data is probably not a plain value but some key-value pair or something like that.
George Kech.
@georgemitnick
Sep 11 2017 12:52
Anyone else too the Udemy JS courses by that Jonas guy?
took too*
Tiago Correia
@tiagocorreiaalmeida
Sep 11 2017 13:12
@georgemitnick why=
Blauelf
@Blauelf
Sep 11 2017 13:22
@georgemitnick That guy from Lisboa? I have bought one of his courses in one of the many €10 sales, just haven't started yet.
George Kech.
@georgemitnick
Sep 11 2017 13:22
I think he's originally from Germany. At least his last name and accent are. :)
He kinda sounds like Bruno.
Pethaf
@Pethaf
Sep 11 2017 13:23
Isn't Brüno austrian?
George Kech.
@georgemitnick
Sep 11 2017 13:23
Well, Austrians are German speaking
:)
Ze vold iz vanderful!
Pethaf
@Pethaf
Sep 11 2017 13:24
Die welt ist wünderschön, ja.
Blauelf
@Blauelf
Sep 11 2017 13:27
@georgemitnick His name is German, could well be from Germany. Austrians and Swiss often have strange names. Strange to my German ears.
George Kech.
@georgemitnick
Sep 11 2017 13:27
So Austrians and German speaking Swiss don't share some last names with Germans?
Blauelf
@Blauelf
Sep 11 2017 13:31
There are regional differences. Swiss family names often end in "li".
There are probably regional differences within "German"-speaking Switzerland, too (their German is very different from ours).
Blauelf
@Blauelf
Sep 11 2017 13:39
Their most common family names seem to be same as ours. Müller, M[ae][iy]er, Schmie?(d|dt|tt|tz). @Chrono79 around? :D
Mohammed Boudad
@matrixersp
Sep 11 2017 13:51
How to match the case when replacing words? The result I want -> Si si
var replace = function(str) {
    re = /(Ci|ci)/g;
    return str.replace(re, function() {
        switch(true) {
            case re.test('ci'):
            return 'si';
            case re.test('Ci'):
            return 'Si';
        }
    });
}
console.log(replace("Ci ci"));
Blauelf
@Blauelf
Sep 11 2017 13:54
@matrixersp You mean something like function(match) { if (match === "ci") return "si"; else return "Si"; }?
Mohammed Boudad
@matrixersp
Sep 11 2017 13:58
@Blauelf Nope, suppose I have a long paragraph which contains 'ci', 'Ci', 'cI', 'CI' and I want to replace them with 'si' matching each word case
I hope this is clear
Blauelf
@Blauelf
Sep 11 2017 14:05

Ok... so would something like

var replace = function(str) {
    var re = /c(?=i)/gi;
    return str.replace(re, function(match) {
        if (match === 'c')
            return 's';
        else
            return 'S':
    });
}

?

Mohammed Boudad
@matrixersp
Sep 11 2017 14:09
@Blauelf Yeh exactly thanks, but I don't understand well how this works
Blauelf
@Blauelf
Sep 11 2017 14:12
/c(?=i)/gi matches all ("g" - global) c immediately followed by an i (which is not part of the match as that's a positive look-ahead ?=), case-insensitive ("i").
Mohammed Boudad
@matrixersp
Sep 11 2017 14:17
Okay, thanks @Blauelf
That was very helpful
CamperBot
@camperbot
Sep 11 2017 14:17
matrixersp sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4598 | @blauelf |http://www.freecodecamp.com/blauelf
Diego Mayer
@Chrono79
Sep 11 2017 14:43
@Blauelf :wave: did you invoke/summon me? :P
Blauelf
@Blauelf
Sep 11 2017 14:44
@Chrono79 Just thought about all those M[ae][iy]ers, and you're one of them.
Diego Mayer
@Chrono79
Sep 11 2017 14:44
yes I am, there are a lot of variations it seems
between portuguese and spanish surnames there are variations too, for instance Gómez and Gomes
the first one is the spanish version, the later the portuguese
Blauelf
@Blauelf
Sep 11 2017 14:47
Is Spanish different everywhere similar to how Brazilian and Portuguese Portuguese differ?
Diego Mayer
@Chrono79
Sep 11 2017 14:49
Most countries have their own terms, but I want to believe I can understand any other spanish out there (sometimes with a little imagination)
Chile has different names for a lot of things, and they're next to Argentina
Blauelf
@Blauelf
Sep 11 2017 14:50
Here, most Portuguese teachers are Brazilian. Which confuses people learning Portuguese and travelling to Portugal. They understand about nothing at first. Very different grammar.
Marc
@MWBauer
Sep 11 2017 14:50
Any thoughts on the Slasher challenge?
I tried a for loop with if/else if
Diego Mayer
@Chrono79
Sep 11 2017 14:51
Is it kind of US vs British english?
Marc
@MWBauer
Sep 11 2017 14:51
I get the right return, but it doesn't agree with me.
Diego Mayer
@Chrono79
Sep 11 2017 14:51
show your code
Marc
@MWBauer
Sep 11 2017 14:52

function slasher(arr, howMany) {
  var slash = [];
  for (var i = 0; i < howMany; i++) {
    slash = arr.splice(0, howMany);
    if (howMany < 1) {
      return [];
    } else if (howMany > arr.length) {
      return [];
    }
  }
  return slash;
}
imperial-isms
@imperial-isms
Sep 11 2017 14:53
Hey, all.
Marc
@MWBauer
Sep 11 2017 14:53
Do I need to put if/else if before for?
Diego Mayer
@Chrono79
Sep 11 2017 14:53
@MWBauer Return the remaining elements of an array after chopping off n elements from the head.
what are you returning if you have to slash 0?
Marc
@MWBauer
Sep 11 2017 14:54
isn't that what splice does? takes an array, uses how many to see how many elements to chop off, then returns rest
Diego Mayer
@Chrono79
Sep 11 2017 14:54
@imperial-isms :wave:
@MWBauer it doesn't enter the loop
Marc
@MWBauer
Sep 11 2017 14:55
how do you mean?
Diego Mayer
@Chrono79
Sep 11 2017 14:55

function slasher(arr, howMany) {
  var slash = [];
  for (var i = 0; i < howMany; i++) { // 0 isn't less than 0
    slash = arr.splice(0, howMany);
    if (howMany < 1) {
      return [];
    } else if (howMany > arr.length) {
      return [];
    }
  }
  return slash;
}
so the whole code inside the loop is ignored
and you return an empty array
Marc
@MWBauer
Sep 11 2017 14:57
Ok, so should I move the if/else if?
Diego Mayer
@Chrono79
Sep 11 2017 14:57
you have to rethink what you should do in that case
if no element should be slashed, what should you return?
Marc
@MWBauer
Sep 11 2017 14:59
Sorry. Right. Need to return the arr.
imperial-isms
@imperial-isms
Sep 11 2017 14:59

I’m working on the Wikipedia Viewer and I’m trying to understand the Wiki API.

Can I get the object with a simple call like…

$.getJSON("https://fcc-weather-api.glitch.me/api/current?lat="+ latitude + "&lon=" + longitude, function(json) ...

or is it more involved like…

$.ajax({
  url: '//www.wikidata.org/w/api.php',
  data: { action: 'wbgetentities', ids: mw.config.get('wgWikibaseItemId'), format: 'json' },
  dataType: 'jsonp',
  success: function (x) {
    console.log('wb label', x.entities.Q39246.labels.en.value);
    console.log('wb description', x.entities.Q39246.descriptions.en.value);
  }
});
Diego Mayer
@Chrono79
Sep 11 2017 15:00
:+1:
Marc
@MWBauer
Sep 11 2017 15:00
so remove [] and insert arr.
Diego Mayer
@Chrono79
Sep 11 2017 15:00
what are you using the loop for?
Marc
@MWBauer
Sep 11 2017 15:00
now I have all but the last 2 tests
To step thru howMay
Many
but I don't need iterations.
I just need to chop off
Diego Mayer
@Chrono79
Sep 11 2017 15:00
no, you don't
and if you don't use i (or whatever you called the loop indice) in your code that's a signal that the loop isn't needed
Marc
@MWBauer
Sep 11 2017 15:03
function slasher(arr, howMany) {
  var slash = [];
  if (howMany < 1) {
    return arr;
  } else if (howMany > arr.length) {
    return [];
  } else {
  slash = arr.splice(0, howMany);
  }
}
Diego Mayer
@Chrono79
Sep 11 2017 15:03
you missed a return there
Marc
@MWBauer
Sep 11 2017 15:03
The if returns the 0 chop, the else if returns the greater than arr.length chop.
now the first test isn't working. 1,2,3 2
Diego Mayer
@Chrono79
Sep 11 2017 15:05
the last else should return too
Marc
@MWBauer
Sep 11 2017 15:05
return arr.splice with 2 should chop off 1 and 2 and leave 3 according to the last return statement.
Marc
@MWBauer
Sep 11 2017 15:05
function slasher(arr, howMany) {
  var slash = [];
  if (howMany < 1) {
    return arr;
  } else if (howMany > arr.length) {
    return [];
  } else {
  return slash = arr.splice(0, howMany);
  }
}
Blauelf
@Blauelf
Sep 11 2017 15:06
Would have to be return arr.splice(howMany);
Marc
@MWBauer
Sep 11 2017 15:07
ok
so I have the 0 start index, then howMany
Diego Mayer
@Chrono79
Sep 11 2017 15:07
after reading the mdn docs, try to simplify your code
Marc
@MWBauer
Sep 11 2017 15:07
so it should see howMany and chop off that many
Blauelf
@Blauelf
Sep 11 2017 15:07
But then, you could use non-mutating method slice, like return arr.slice(howMany);. This even works for all the special cases (unless howMany is negative, which none of the test cases tests).
Marc
@MWBauer
Sep 11 2017 15:08
So I should be using slice instead of splice
?
I changed to slice. then I took out the 0 starting index and now it works.
Why does the starting index mess it up?
according to the examples the 2 goes to the third element and then deletes it, then they can move on or insert.
Blauelf
@Blauelf
Sep 11 2017 15:11
Splice mutates the array. After calling slasher, the array won't be the same, even for the calling code.
function slasher(arr, howMany) {
    return arr.splice(howMany);
}
var arr = [4, 8, 15, 16, 23, 41];
console.log(slasher(arr, 2)); // [15, 16, 23, 42]
console.log(arr); // [4, 8]
Marc
@MWBauer
Sep 11 2017 15:13
slasher becomes a new array with the remainder of what arr had. Arr ends up having just what was cut off.
Blauelf
@Blauelf
Sep 11 2017 15:14
Just don't have your function have surprising side-effects. If slasher is not documented to change the array, it shouldn't.
Marc
@MWBauer
Sep 11 2017 15:17
I'm sure I will be revisitng this lesson
Being the beginner that I am, this indexOf seems like there should be a lot more information. lol
I get the indexOf allows us to pick a place to look at...
Diego Mayer
@Chrono79
Sep 11 2017 15:22
some arguments are optional
Marc
@MWBauer
Sep 11 2017 15:24
it looks like I have strings within an array, so I have to use the array method instead of string method, yes?
Diego Mayer
@Chrono79
Sep 11 2017 15:24
@MWBauer are you talking about another challenge?
Marc
@MWBauer
Sep 11 2017 15:25
I'm sorry, yes.
The splice/slice challenge is finished.
Diego Mayer
@Chrono79
Sep 11 2017 15:25
:+1:
Marc
@MWBauer
Sep 11 2017 15:25
Thank you @Blauelf
CamperBot
@camperbot
Sep 11 2017 15:25
mwbauer sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4599 | @blauelf |http://www.freecodecamp.com/blauelf
Marc
@MWBauer
Sep 11 2017 15:25
thank you @Chrono79
CamperBot
@camperbot
Sep 11 2017 15:25
mwbauer sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4535 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Sep 11 2017 15:26
then state which challenge you're talking now so we're on the same page
Marc
@MWBauer
Sep 11 2017 15:26
My apologies.
Diego Mayer
@Chrono79
Sep 11 2017 15:26
no problem, it's just to not confuse us and you ;)
Marc
@MWBauer
Sep 11 2017 15:26
right
Diego Mayer
@Chrono79
Sep 11 2017 15:26
nothing good will come from that :P
indexOf (both in arrays or strings) returns the position of the first ocurrence of what you're looking for, or -1 if it's not there
Jason Luboff
@JLuboff
Sep 11 2017 15:29
While lastIndexOf gives the first occurence starting from the back of the array!
Marc
@MWBauer
Sep 11 2017 15:29
right. So I need to search thru the given element/string to find particular letters to say whether the ones we are looking for are found within
Does that require a search to happen multiple times?
do I need a regex?
I'm lost on how to start this one.
I can find an index, but then.....
Jason Luboff
@JLuboff
Sep 11 2017 15:31
I don't think you've mentioned which challenge you're on..?
Marc
@MWBauer
Sep 11 2017 15:31
and actually I don't have time to work on this.
Gotta' leave for lunch then work.
@JLuboff the Mutations challenge
Diego Mayer
@Chrono79
Sep 11 2017 15:31
bye then
Marc
@MWBauer
Sep 11 2017 15:32
Ya'll have a great day.
Thank you again for your help.
Jason Luboff
@JLuboff
Sep 11 2017 15:32
@MWBauer You'll need a loop
Diego Mayer
@Chrono79
Sep 11 2017 15:45
@imperial-isms sorry for the late reply, you could use any of those ways, note that when using getJSON you should use &callback=? to make it work as jsonp
https://forum.freecodecamp.org/t/how-to-retrieve-data-from-wikipedia-api/13527/3
imperial-isms
@imperial-isms
Sep 11 2017 15:45
No worries…thanks @Chrono79 !
Diego Mayer
@Chrono79
Sep 11 2017 15:46
:+1:
Will White
@willnwhite
Sep 11 2017 16:02
@imperial-isms I believe CORS is better than JSONP for this, and everything you need to make a CORS request is between https://www.mediawiki.org/wiki/API:Main_page and https://www.mediawiki.org/wiki/API:Cross-site_requests.
Diego Mayer
@Chrono79
Sep 11 2017 16:05
@willnwhite could you elaborate on why you prefer one over the other?
Christopher McCormack
@cmccormack
Sep 11 2017 16:16
I believe you can add the parameter &origin=* to the request and it will prevent the cross origin error you normally get @Chrono79
I imagine that's what @willnwhite is referring to
Will White
@willnwhite
Sep 11 2017 16:18
CORS is more secure: "CORS is able to return the data directly. In that regard it is a little tiny bit more efficient since no bubble-wrap is needed – and is a lot safer since you are not executing a JavaScript function returned returned by a potentially untrusted server." https://blog.codingoutloud.com/2014/02/20/choosing-cors-over-jsonp-over-inline-and-lessons-learned-using-cors/
JSONP is more compatible. Ideal is CORS with JSONP fallback: https://blog.algolia.com/jsonp-still-mandatory/
So I've learned something!
Before this, I just knew that CORS is the designed solution, and JSONP is a hack.
Christopher McCormack
@cmccormack
Sep 11 2017 16:25
Not all of the APIs FCC suggested support different origins, unfortunately, so JSONP may be the only way around if they also support that. I believe they're working to get rid of most of those API projects if they haven't already
Jason Luboff
@JLuboff
Sep 11 2017 16:26
Ah...I like the API projects :D
Christopher McCormack
@cmccormack
Sep 11 2017 16:27
They keep spinning up their own, maybe they'll just use those, not sure
APIs that is
but I do too, very important stuff to understand
FCC implementation outside of beta wasn't the best though, especially with the shift to https
Jason Luboff
@JLuboff
Sep 11 2017 16:28
Well I think the problem is they didn't choose API's for the long run or were too slow to account for changes in the API that made them no longer work in the same way they used to
Christopher McCormack
@cmccormack
Sep 11 2017 16:28
yeah
Jason Luboff
@JLuboff
Sep 11 2017 16:29
You know...it sure is hard when the boss of the companies significant other...constantly installs crapware onto his and her computer :(
Christopher McCormack
@cmccormack
Sep 11 2017 16:31
ouch - does the boss make it difficult to force a reimage?
Jason Luboff
@JLuboff
Sep 11 2017 16:32
  1. Don't have an image (we rarely buy more than 1 or 2 machines at a time, which results in different hardware) 2. He is normally in the Texas office were we have no IT staff 3. Ugh.
Christopher McCormack
@cmccormack
Sep 11 2017 16:32
yeah ouch
Jason Luboff
@JLuboff
Sep 11 2017 16:36
So just do what I can. But either way he is due for a laptop replacement
Christopher McCormack
@cmccormack
Sep 11 2017 16:39
Should just make everyone run linux instead :)
Jason Luboff
@JLuboff
Sep 11 2017 16:40
I'd rather not submit myself to that torture :)
Jason Luboff
@JLuboff
Sep 11 2017 16:51
Gah...the latest version of Firefox is so unstable
Christopher McCormack
@cmccormack
Sep 11 2017 16:53
Is it? I usually use it to test as it seems more stable than Chrome
Jason Luboff
@JLuboff
Sep 11 2017 16:53
My tabs have been constantly crashing
Christopher McCormack
@cmccormack
Sep 11 2017 16:53
although I run very few extensions in FF
Jason Luboff
@JLuboff
Sep 11 2017 16:53
I only have one extension which is Wappalyzer
Besides Flash
I'll update my flash see if that helps
Christopher McCormack
@cmccormack
Sep 11 2017 17:04
maybe there's an update for FF. Maybe reinstall
Jason Luboff
@JLuboff
Sep 11 2017 17:05
Nah, verified it was up to date. But so far after updating flash it hasn't crashed but I also haven't gone to a page with video
Diego Mayer
@Chrono79
Sep 11 2017 17:08
@willnwhite thanks for the explanation and the links
CamperBot
@camperbot
Sep 11 2017 17:08
chrono79 sends brownie points to @willnwhite :sparkles: :thumbsup: :sparkles:
:cookie: 361 | @willnwhite |http://www.freecodecamp.com/willnwhite
Jon
@jonandrepedersen
Sep 11 2017 17:18

Hi guys, so I'm on the https://www.freecodecamp.org/challenges/drop-it.

I did solve it, but my solution was quite different from the suggested answers/hints. Therefore, I was just curious whether my code is reaally inefficient/bad (and if so, how would you improve it?).


function dropElements(arr, func) {
  // Drop them elements.
  var newArr = [];
  for(var i=0; i<arr.length;i++){
    if(func(arr[i])){
     newArr = arr.slice(i);
      return newArr;
    }
  }
  return newArr;
}

dropElements([1, 2, 3], function(n) {return n < 3; });
Stephen James
@sjames1958gm
Sep 11 2017 17:27
@jonandrepedersen With your code you don't need the variable newArr
Other than that it is fine.
function dropElements(arr, func) {
  // Drop them elements.
  for(var i=0; i<arr.length;i++){
     if(func(arr[i])){
       return arr.slice(i);
    }
  }
  return [];
}
Jon
@jonandrepedersen
Sep 11 2017 17:43
@sjames1958gm thanks, good point.
CamperBot
@camperbot
Sep 11 2017 17:43
jonandrepedersen sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8457 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
imperial-isms
@imperial-isms
Sep 11 2017 17:46
Thanks @willnwhite …seems to be working with JSON
CamperBot
@camperbot
Sep 11 2017 17:46
imperial-isms sends brownie points to @willnwhite :sparkles: :thumbsup: :sparkles:
:cookie: 362 | @willnwhite |http://www.freecodecamp.com/willnwhite
imperial-isms
@imperial-isms
Sep 11 2017 17:47
I’m getting the object, for some reason I can’t get my .html() to stick to the element though.
I’ll come back for help on that though…got be offline for a bit
Jason Luboff
@JLuboff
Sep 11 2017 17:48
@imperial-isms Are you specifying the element correctly?
for example
$('#IdOfElement').html('<p>Hello World</p>');
$('.classOfElement').html('<p>Hello World</p>');
imperial-isms
@imperial-isms
Sep 11 2017 17:49
Yeah…it changes it very briefly, but the original element text is rapidly replacing it.
Jason Luboff
@JLuboff
Sep 11 2017 17:49
Do you have it in codepen?
Eric Hasegawa
@EricHasegawa
Sep 11 2017 17:51
Can anyone tell me what the "!" is doing before the obj.hasOwnProperty in the following line of code?
      if(!obj.hasOwnProperty(srcKeys[i]) || obj[srcKeys[i]] !== source[srcKeys[i]]) {
        return false;
      }
Jason Luboff
@JLuboff
Sep 11 2017 17:52
@EricHasegawa If the property of the object is found, normally it would return true but by having ! before, it changes the boolean to false
imperial-isms
@imperial-isms
Sep 11 2017 17:53
@JLuboff I do…I’m going to step out for a few hours. If you’re around later and still up for having a look, I’ll send it over. Thanks for your help!
CamperBot
@camperbot
Sep 11 2017 17:53
imperial-isms sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2192 | @jluboff |http://www.freecodecamp.com/jluboff
Eric Hasegawa
@EricHasegawa
Sep 11 2017 17:54
So if the object is not found it returns true?
And would another way of saying that be
Jason Luboff
@JLuboff
Sep 11 2017 17:55
If the property is not found in the object, then yes, it returns true instead of false
Eric Hasegawa
@EricHasegawa
Sep 11 2017 17:56
if(obj.hasOwnProperty(srcKeys[i]) === false || obj[srcKeys[i]] !== source[srcKeys[i]]) {
        return false;
Is that another way of writing that? @JLuboff
Jason Luboff
@JLuboff
Sep 11 2017 17:56
Yup
Eric Hasegawa
@EricHasegawa
Sep 11 2017 17:58
And that second part of the code, does that check if the value of the key in the object is the same as the value in the key of the source?
Jason Luboff
@JLuboff
Sep 11 2017 17:59
Looks like it
Eric Hasegawa
@EricHasegawa
Sep 11 2017 18:01
@JLuboff Thanks!
CamperBot
@camperbot
Sep 11 2017 18:01
erichasegawa sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2193 | @jluboff |http://www.freecodecamp.com/jluboff
Jason Luboff
@JLuboff
Sep 11 2017 18:08
@cmccormack Nope still crashing ugh. I don't want to uninstall and reinstall...too lazy lol
Christopher McCormack
@cmccormack
Sep 11 2017 18:11
@JLuboff that is pretty lazy
Jason Luboff
@JLuboff
Sep 11 2017 18:11
I know I know
Jon
@jonandrepedersen
Sep 11 2017 18:11
Anyone currently working on the "Everything Be True" challenge? :)
Christopher McCormack
@cmccormack
Sep 11 2017 18:16
@jonandrepedersen I'm sure someone is somewhere :) did you have a question about it?
Jon
@jonandrepedersen
Sep 11 2017 18:17
Hi @cmccormack. Not really any questions at this point. Just wanted to find a "coding buddy" for the challenge :)
Jon
@jonandrepedersen
Sep 11 2017 18:25
Well, had a crack at it now, and can't seem to wrap my head around how I would write the "boolean stuff" in the IF statement :p Any tips would be appreciated: https://www.freecodecamp.org/challenges/everything-be-true

function truthCheck(collection, pre) {
  // Is everyone being true?
  var times = 0;
    for(var i in collection){
      if(collection[i].hasOwnProperty(pre) && ????){
        count++;
      }
    }
  return times == collection.length;
}

truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex");
So I mean, I get the logic, just stuck at HOW to solve it :p xD

E.g.

 if(collection[i].hasOwnProperty(pre) && collection[i] === true){

Does not work :p

korzo
@korzo
Sep 11 2017 18:28
@jonandrepedersen you should only check if element has property pre
Jon
@jonandrepedersen
Sep 11 2017 18:28
Obviously because the collection[i] is not checcking in relation to the "pre", but yeah
You mean just:

function truthCheck(collection, pre) {
  // Is everyone being true?
  var times = 0;
    for(var i in collection){
      if(collection[i].hasOwnProperty(pre)){
        times++;
      }
    }
  return times == collection.length;
}

truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex");
korzo
@korzo
Sep 11 2017 18:29
@jonandrepedersen yes
Jon
@jonandrepedersen
Sep 11 2017 18:29
I get some of the requirements correct, but not all
@korzo
korzo
@korzo
Sep 11 2017 18:30
@jonandrepedersen also you don't have to count truthy elements. You can return false if condition fails
Jon
@jonandrepedersen
Sep 11 2017 18:32
Still don't fulfill all reqs. Hmm

function truthCheck(collection, pre) {
  // Is everyone being true?
  var times = 0;
    for(var i in collection){
      if(collection[i].hasOwnProperty(pre)){
        times++;
      } else {
        return false;
      }
    }
  return true;
}

truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex");
Cuz right now I'm only checking if they have the property "pre", but not checking if those actual colleciton-properties have truthy values. If I am not mistaken
@korzo
korzo
@korzo
Sep 11 2017 18:34
@jonandrepedersen You are right
I read instructions now
@jonandrepedersen if(collection[i].hasOwnProperty(pre) && collection[i][pre])
Jon
@jonandrepedersen
Sep 11 2017 18:35
Hmm, aha. I see. Easier than expected :p (it often is...) thanks @korzo
CamperBot
@camperbot
Sep 11 2017 18:35
jonandrepedersen sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 473 | @korzo |http://www.freecodecamp.com/korzo
Christopher McCormack
@cmccormack
Sep 11 2017 18:36
Or you can do something like if(!collection[i][pre]) return false
Jon
@jonandrepedersen
Sep 11 2017 18:37
Hmm, yeah I'll try that as well before proceeding. Always good to learn/getting familiar with different solutions :)
@cmccormack ty
CamperBot
@camperbot
Sep 11 2017 18:37
jonandrepedersen sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1203 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Sep 11 2017 18:38
! will coerce it into a boolean. If there is no value in the property or the property doesn't exist, you'll get undefined, and !undefined is true
Jon
@jonandrepedersen
Sep 11 2017 18:39

Hehe not very different tho :p

EDIT: ohh, didn't think about that. Nice.

Christopher McCormack
@cmccormack
Sep 11 2017 18:40
Honestly, if you can avoid using logic comparisons operators you should, it can be more difficult to troubleshoot later on
An AND can also be written as a nested if, an OR as an adjacent if, although OR isn't as bad to have in a single comparison line
imperial-isms
@imperial-isms
Sep 11 2017 19:25
B
@JLuboff hey, bud, here's my wikipedia project: https://codepen.io/imperial-isms/pen/yomWBp
Jason Luboff
@JLuboff
Sep 11 2017 19:33

@imperial-isms Try this
Instead of

$("#wiki-search").click(function () {
    var query = $("#wiki-query").val();
    var wikiObj = "";

Try

$("#wiki-search").click(function (e) {
e.preventDefault();
    var query = $("#wiki-query").val();
    var wikiObj = "";
Christopher McCormack
@cmccormack
Sep 11 2017 19:42
Or this separate:
 $('form').submit(function(e){e.preventDefault()})
Or remove forms, not sure why everyone uses forms when they aren't using a backend
Is FCC teaching them that a form is required for inputs?
Jason Luboff
@JLuboff
Sep 11 2017 19:43
I don't recall
but I think most people think if there is an input field then there needs to be a form
imperial-isms
@imperial-isms
Sep 11 2017 19:43
I'll give it a shot!
Seeing a new method I'll learn about
Christopher McCormack
@cmccormack
Sep 11 2017 19:45
@imperial-isms read up on event propagation, it will really help long-term
and also form default action
imperial-isms
@imperial-isms
Sep 11 2017 19:49
Will do...thanks!
imperial-isms
@imperial-isms
Sep 11 2017 20:13
@cmccormack I think I used form because when I looked up search bar in bootstrap navbar, that’s what the code was
Christopher McCormack
@cmccormack
Sep 11 2017 20:15
@imperial-isms May be the case bootstrap expects your search to use a backend, which makes sense. Just be aware of that the next time you implement. It's OK to use forms, just be aware of the submit action
imperial-isms
@imperial-isms
Sep 11 2017 20:15
The submit action in regards to event propagation and a form’s default action?
Sorry, I just got home and haven’t looked up what you suggested
surferpilgrim
@surferpilgrim
Sep 11 2017 21:14
nvm found what i was looking for
Eric Hasegawa
@EricHasegawa
Sep 11 2017 21:53
function whatIsInAName(collection, source) {
  var arr = [];
  // Only change code below this line
var srcKeys = Object.keys(source); 
 var result = collection.filter(function(obj) {
   for (var i=0; i < srcKeys.length; i++) {
     if(obj.hasOwnProperty(srcKeys[i]) === false || obj[srcKeys[i]] !== source[srcKeys[i]]) {
        return false;
  } else {
    return true;
  }
    }});
  return result;
}
Can anyone tell me why this doesn't work? It's the "wherefore art thou" challenge
legendinraze
@legendinraze
Sep 11 2017 21:58
function calculateTaxes(price, quantity) {
  var salesTax = .10;
  var totalPrice;
  // Only change code below this line
  totalPrice = (price * quantity * .10);


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

// Change the inputs below to test your code
calculateTaxes(1,10);
what's wrong?
Jason Luboff
@JLuboff
Sep 11 2017 22:00
@EricHasegawa Why are you using filter? And why a loop within your filter? A filter is essentially a loop
@legendinraze Your math is incorrect
Diego Mayer
@Chrono79
Sep 11 2017 22:01
@legendinraze multiplying for .10 is like calculating only the taxes, not the total price
legendinraze
@legendinraze
Sep 11 2017 22:01
You are given a variable price representing the price per item and quantity representing the number of items purchased. The salesTax variable is 10%. Use these variables to calculate the totalPrice variable as the total price after taxes.
Jason Luboff
@JLuboff
Sep 11 2017 22:01
@legendinraze ((price * quantity)+ (price * quantity) * .10)
Diego Mayer
@Chrono79
Sep 11 2017 22:02
or price * quantity * (1 + salesTax)
Jason Luboff
@JLuboff
Sep 11 2017 22:02
@Chrono79 Ya I was too lazy to make it shorthand lol
Diego Mayer
@Chrono79
Sep 11 2017 22:02
hahaha
Jason Luboff
@JLuboff
Sep 11 2017 22:02
Required too much thinking :D
Diego Mayer
@Chrono79
Sep 11 2017 22:04
going home now, see ya :wave:
Jason Luboff
@JLuboff
Sep 11 2017 22:04
:wave:
Eric Hasegawa
@EricHasegawa
Sep 11 2017 22:05
@JLuboff I borrowed most of the code off of a pre-existing solution so I could compare my own to that one, but now mine doesnt work and I don't know why
Saikat-Sinha
@Saikat-Sinha
Sep 11 2017 22:05
Anyone with angular material understanding please help
open this link in firefox http://jsfiddle.net/ThomasBurleson/44feazry/4/
the footer is floating on top of main content
in chrome it works fine
Jason Luboff
@JLuboff
Sep 11 2017 22:06
@EricHasegawa I would get rid of the filter. Filter returns an array, not a boolean which is what oyu need
Eric Hasegawa
@EricHasegawa
Sep 11 2017 22:07
@JLuboff I just don't know why this code works https://forum.freecodecamp.org/t/freecodecamp-algorithm-challenge-guide-wherefore-art-thou/16092 but mine doesn't
Jason Luboff
@JLuboff
Sep 11 2017 22:08
@EricHasegawa Becuase your return true is in the wrong spot
Notice they don't use an else statement
Eric Hasegawa
@EricHasegawa
Sep 11 2017 22:10
@JLuboff I don't understand why they do that, and I'm not sure why mine is in the wrong spot
Could you explain?
Jason Luboff
@JLuboff
Sep 11 2017 22:11
@EricHasegawa return stops all code execution. Which means, the moment you hit the return it will stop your loop. The moment we find a false result, we want to stop the code, thats why return false where it is, is fine. However, we don't want to return true until all elements in the array have been checked thus we can not return true until after our loop has completed and thus checked all elements
Eric Hasegawa
@EricHasegawa
Sep 11 2017 22:13
Why do we want to stop the code when we find a false result? Wouldn't we want to keep looping through the rest? And also wouldn't we return true when we found something that matched the second object, not when all elements have been checked? I know you're right, but I'm just confused
Jason Luboff
@JLuboff
Sep 11 2017 22:17
I had to go check the challenge, its been a while since I've looked. So we're filtering out the values that we don't want (return false)
I did the challenge different, I just used two for loops, so I might not be fully understanding the filter here.
Eric Hasegawa
@EricHasegawa
Sep 11 2017 22:19
Any chance you could paste your solution on here so I can take a look? I have to go in a sec but I'd love to have a look just to get a different perspective, mine works now too by the way
Jason Luboff
@JLuboff
Sep 11 2017 22:19
@EricHasegawa This was my last solution back in Feb. my use of JSON.stringify may or may not be good practice
function whatIsInAName(collection, source) {
  var arr = [];
var src = Object.keys(source);

  for(var i = 0; i < collection.length; i++){
    for(var j = 0; j < src.length; j += 2){
        if (JSON.stringify(collection[i][src[j]]) == JSON.stringify(source[src[j]]) && JSON.stringify(collection[i][src[j+ 1]]) == JSON.stringify(source[src[j+1]] )){
    arr.push(collection[i]);
}
    }
}
  return arr;
}

whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 });
Eric Hasegawa
@EricHasegawa
Sep 11 2017 22:20
Okay, I'll take a look, @JLuboff Thanks!
CamperBot
@camperbot
Sep 11 2017 22:20
erichasegawa sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2196 | @jluboff |http://www.freecodecamp.com/jluboff