These are chat archives for FreeCodeCamp/HelpJavaScript

16th
Jul 2017
Pagnito
@Pagnito
Jul 16 2017 00:30
who here throughly understands heaps algorithm?
UnkyKong
@UnkyKong
Jul 16 2017 00:31
is anybody available to help me understand promises? https://codepen.io/Unky/pen/QgrXvz?editors=1010
korzo
@korzo
Jul 16 2017 00:31
@UnkyKong Sure
UnkyKong
@UnkyKong
Jul 16 2017 00:31
what is wrong with my code?
I'm trying to iterate on my user list, filter out the offline users while making my online divs. Then iterate on the offline list and make their divs
the function that is now a promise worked before I made it a promise
korzo
@korzo
Jul 16 2017 00:35
@UnkyKong you define function getUser inside promise, but never call this function, so promise is never resolved/rejected
UnkyKong
@UnkyKong
Jul 16 2017 00:37
ah, ok
FlashHero
@FlashHero
Jul 16 2017 00:44
anyone available to help ?
kumquatfelafel
@kumquatfelafel
Jul 16 2017 00:45
available...ish :p
CallMeOrange
@EgnaroDev
Jul 16 2017 00:49
@kumquatfelafel Can you take a look at my twitch tv?
UnkyKong
@UnkyKong
Jul 16 2017 00:49
@korzo now I'm passing on my offline list, but the .forEach inside my .then() isn't running
kumquatfelafel
@kumquatfelafel
Jul 16 2017 00:50
@MCTwoDigitZero can't guarantee anything, but sure.
CallMeOrange
@EgnaroDev
Jul 16 2017 00:50
hm...
Not sure if you can help but these backgrounds is the problem
I know thats .box and only set one background
I have no idea how to set different background for each username
korzo
@korzo
Jul 16 2017 00:52
@UnkyKong Your code has bad structure.
You call getUser inside the promise and then resolve promise without knowing if getUser already pushed something into offline
@UnkyKong Promise will resolve as soon as foreach loop ends
kumquatfelafel
@kumquatfelafel
Jul 16 2017 00:53
@MCTwoDigitZero gotcha
CallMeOrange
@EgnaroDev
Jul 16 2017 00:54
Do you know?
UnkyKong
@UnkyKong
Jul 16 2017 00:55
the promise is working now. and the .then is receiving the correct array. it just isn't iterating on that array
kumquatfelafel
@kumquatfelafel
Jul 16 2017 01:00
@MCTwoDigitZero accidental deletion. Is there backgrounds you have in mind for each one, or just different backgrounds in general?
CallMeOrange
@EgnaroDev
Jul 16 2017 01:00
well, these backgrounds come from twitch api
var profileb = json.profile_banner;
korzo
@korzo
Jul 16 2017 01:02
@UnkyKong It looks like the array is empty at the moment
UnkyKong
@UnkyKong
Jul 16 2017 01:03
i'm getting an array in my console when I run it
korzo
@korzo
Jul 16 2017 01:03
@UnkyKong I added console.dir(fromResolve.length); at the start of then and it log 0
UnkyKong
@UnkyKong
Jul 16 2017 01:04
image.png
huh, how is it zero and 10 ><
korzo
@korzo
Jul 16 2017 01:06
@UnkyKong Yes, but it's array is filled at the moment you see it in the console.
As i wrote before, try to log length of array at the moment it enters then
UnkyKong
@UnkyKong
Jul 16 2017 01:07
so how do I fix it?
korzo
@korzo
Jul 16 2017 01:08
@UnkyKong It's because you resolve promise in promiseUsers before all getUser function calls are finished
kumquatfelafel
@kumquatfelafel
Jul 16 2017 01:09
@MCTwoDigitZero Well, modifying box's background image is problematic, as you've already noted, since it applies to all the elements with that box class. I think you might have to for each element apply the background image not in .box (since shared) but something you make up on the spot to apply only to that specific element. Though I'm not sure how to do this offhand, or indeed if it's really best solution.
korzo
@korzo
Jul 16 2017 01:09
@UnkyKong The best way would be to refactor code and actually resolve promise with data from getUser. But it's a lot of work.
UnkyKong
@UnkyKong
Jul 16 2017 01:09
@korzo i'm here to learn to do it right
korzo
@korzo
Jul 16 2017 01:10
@UnkyKong Quick fix is to to turn getUser in the promise, collect all promises in promiseUsers and resolve them as soon as all getUser promises are resolved
@UnkyKong Moment, I will post a fork with what I'm talking about
UnkyKong
@UnkyKong
Jul 16 2017 01:13
@korzo awesome. I know I could do this easier if I didn't want my online users on top
but I want to push myself
@UnkyKong There are 2 changes: getUser return promise
promiseUsers collect promises in forEach loop and resolve when all getUser promises are resolved
UnkyKong
@UnkyKong
Jul 16 2017 01:18
then you used .all. ok cool. so I sort of getting there
@korzo thank you.
CamperBot
@camperbot
Jul 16 2017 01:21
unkykong sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 256 | @korzo |http://www.freecodecamp.com/korzo
korzo
@korzo
Jul 16 2017 01:29

@UnkyKong But you should never exchange data through global variable, but pass them as return/resolved value.
Then you can write code as:

users.forEach(function(name) {
    getUser(name)
        .then(getOfflineInfo(user))
        .then(renderUser(user));
});

Glad to help

CallMeOrange
@EgnaroDev
Jul 16 2017 01:46
Anyone want their twitch account added to my twitch.tv? :/
CallMeOrange
@EgnaroDev
Jul 16 2017 01:56
@kumquatfelafel are you good with animated?
anyone?
:gun:
I'll just ask a question..
$(".result").addClass("animated bounce"); <-- How do I make it bounce when hovered?
Moisés Man
@moigithub
Jul 16 2017 02:07
jquery have a hover method u can toggleclass there
CallMeOrange
@EgnaroDev
Jul 16 2017 02:10
.toggleclass?
@moigithub
I'll just look it up
@moigithub found it, thanks
CamperBot
@camperbot
Jul 16 2017 02:14
mctwodigitzero sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3510 | @moigithub |http://www.freecodecamp.com/moigithub
UnkyKong
@UnkyKong
Jul 16 2017 02:18
I have another question. I tried to refactor my code and now my .appendChild() are over writting themselves so I only end up with one div
Scott Rhoades
@srhoades
Jul 16 2017 02:59
can anyone give a hand with Exact Change challenge?
Christopher Blakely
@chrisbchrist
Jul 16 2017 03:03
@srhoades I got through that one yesterday after a lot of headaches, what are you having trouble with?
Scott Rhoades
@srhoades
Jul 16 2017 03:04
checkCashRegister(19.50, 20.00, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 1.00], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]) should return "Insufficient Funds".
Christopher Blakely
@chrisbchrist
Jul 16 2017 03:04
What's your code look like?
Scott Rhoades
@srhoades
Jul 16 2017 03:04
keeps returning correct to console but the test fails
Ken Haduch
@khaduch
Jul 16 2017 03:17
@srhoades - check your spelling of "Insufficient Funds" (this is a wild guess...)
Christopher Blakely
@chrisbchrist
Jul 16 2017 03:20
I'm trying to implement a search function for the twitch viewer. It searches the term through a getUserInfo/getStream function that generates a div with the ID of the username, but I can't seem to use the search function to apply a "results" class to the newly generated div.
https://codepen.io/extrachrisb/pen/VWxXbz/
CallMeOrange
@EgnaroDev
Jul 16 2017 03:23
Looks great
Stanley Su
@stanley-su
Jul 16 2017 03:36
@Hijerboa Sorry I had to go, but you can identify which key was pressed by passing in the event object to the function that is called on keyup
$(‘.searchBox’).on(‘keyup’, function(e) {
console.log(e.which); // ascii code of the key pressed, 13 is enter btw
});
Ken Haduch
@khaduch
Jul 16 2017 03:55
@chrisbchrist - I think that you might have a problem with your "search" function in that you go and request the name via getUserInfo([term]); but you do not have any way to synchronize the code that is applying the "result" class with the actual return of the data, since the call to getUserInfo() is made, then some time later the return from the $.ajax call is made. If the data for the user that you are requesting is already in your DOM, then you are adding the class to it. But if you are requesting data for a different user, then you will not be able to find the element with the ID for that user immediately when you return from the getUserInfo() call, because that user's information is not created in the DOM until after the ajax return occurs.
Christopher Blakely
@chrisbchrist
Jul 16 2017 04:06
@khaduch I haven't even accounted for duplicate user searches yet, I think I can address that after. I figured there is a problem with the order of operations but I'm not sure what it is. You're right the 2nd ajax call which defines the ID is performed as part of the getStream function which is chained to be called for each instance of getUserInfo, but I'm not sure why the ID from that call is not created before I try to assign a new class to the div with that ID
Sarah
@aggibabi
Jul 16 2017 04:08
did anyone else noticed that they removed the get help link to this forum from the challenges. It's now a get hint link to the solution
heroiczero
@heroiczero
Jul 16 2017 04:09
@aggibabi yeah always updating and changing
@aggibabi like how they got rid of chat in the top right and put it into the Settings
Christopher Blakely
@chrisbchrist
Jul 16 2017 04:09
@aggibabi They did? I thought they might have removed it since I moved on to a different set of challenges but if it was universal and applies to all the projects that's not good
Ken Haduch
@khaduch
Jul 16 2017 04:10
@chrisbchrist - it has to do with the way the ajax request works. You have the code in your JS (near the bottom) that will respond to keypress events and get the search string. You then trigger the getUserInfo() function. That makes the ajax request to the twitch site, and immediately returns to the place where it was called from, since the operation is asynchronous, it comes right back and attempts to add the class to the element, but if the new search user information is not contained in the DOM, which it most likely won't be, then you're going to get an error there because it won't find the element.
yes, that was a good example of a run-on sentence...
Sarah
@aggibabi
Jul 16 2017 04:11
yeah. i think they shouldd keep this easy to find :smile:
heroiczero
@heroiczero
Jul 16 2017 04:11
i think chat has less traffic now
kumquatfelafel
@kumquatfelafel
Jul 16 2017 04:12

:car: :car: :car: :car: :car: :car: :car: :car: :car: :car: :car: :car:
:car: :car: :car: :car: :car: :car: :car: :car: :car: :car: :car: :car:

Not anymore! :o

Nitin Sahu
@globefire
Jul 16 2017 04:12
image.png
anyone pls help
Christopher Blakely
@chrisbchrist
Jul 16 2017 04:13
@khaduch Not at all, I think I understand what you're saying, I just did not know that the ajax call behaves that way. From what you say I think I could solve it by assigning the ID in the first ajax call instead of the 2nd performed by the chained function getStream. I'm not sure what you mean by asynchronous though
Nitin Sahu
@globefire
Jul 16 2017 04:14
anyone ??
heroiczero
@heroiczero
Jul 16 2017 04:14
@globefire i=size+i not just i+size
@globefire you need to assign it to i
kumquatfelafel
@kumquatfelafel
Jul 16 2017 04:14
@globefire just post the code in chat if it's that small... It's easier not having to switch between tabs while writing reply.
Nitin Sahu
@globefire
Jul 16 2017 04:15
okk sorry i'll repost
kumquatfelafel
@kumquatfelafel
Jul 16 2017 04:15
p.s. @heroiczero is correct here. i = i + size
@globefire if still not working after making correction, then post. Otherwise... :p
Nitin Sahu
@globefire
Jul 16 2017 04:16
//noprotect
function chunkArrayInGroups(arr, size) {
  // Break it up.j
  var newarr = [], j = 0;
  var a = [];
  for(var i = 0; i < arr.length; i+size){
    a[j] = arr.slice(i,i+size);
    newarr.push(a[j]);
    j++;
  }

  return newarr;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
where should i change it ? inside for loop statement ?
heroiczero
@heroiczero
Jul 16 2017 04:16
@globefire yep still need to correct the i+size in your for statement
@globefire to either i=i+size or i+=size
Nitin Sahu
@globefire
Jul 16 2017 04:17
but i have done it in the last statement ?
that ameans the same thing, ri8?
kumquatfelafel
@kumquatfelafel
Jul 16 2017 04:18
:point_up:
Beyond this, you'll have to deal with any "leftovers" at the end of your array if size doesn't go in evenly
Nitin Sahu
@globefire
Jul 16 2017 04:18
but i have declared a new array
kumquatfelafel
@kumquatfelafel
Jul 16 2017 04:18
@globefire not the same thing. you aren't checking j in your condition, and the increment is different
i + size is not the same as i = i + size is not the same as j++.
Nitin Sahu
@globefire
Jul 16 2017 04:19
i m creating a new array and the subarrays will be pushed over there so y need to check a condition for j ?
Steven
@LemonTruth
Jul 16 2017 04:20
function bouncer(arr) {
// Don't show a false ID to this bouncer.
var nan = NaN;
var filtered = arr.filter(function(nothing){
return nothing != nan;
});
return filtered;
}
bouncer([7, "ate", 9, NaN]);
Ken Haduch
@khaduch
Jul 16 2017 04:20
@chrisbchrist - the A in AJAX is for the word Asynchronous. What it means is that the operation is performed and data requested from the site. But in order not to "block" the operation of your page, the flow of the code in your JS script continues. The AJAX operation has the callback function which is executed when the data returns. That will take action depending on what the returned data is. You make new entries to your list of users, for example. If you look at the browser devtools in the "Network" tab, you'll see how the requests are made and then the data returns later. They show an explanation of the devtools display for the timing breakdown of a request in this link. I don't know if I could grab a screenshot of a request from the execution of your page, since those views in the devtools pop in and out when you hover over transfers. But that's an explanation from my point of view.
kumquatfelafel
@kumquatfelafel
Jul 16 2017 04:20
@globefire you don't need to check for j. But you do need to increment i.
Nitin Sahu
@globefire
Jul 16 2017 04:20
can you write that part about which u r saying cuz i m not able to understand it
heroiczero
@heroiczero
Jul 16 2017 04:20
@globefire you do know you do not need j
Steven
@LemonTruth
Jul 16 2017 04:20
When I run this code, NaN isn't removed from my array. Anyone know why?
heroiczero
@heroiczero
Jul 16 2017 04:21
@LemonTruth return nothing != NaN; probably?
Nitin Sahu
@globefire
Jul 16 2017 04:22
okk so if for(var i = i +size; i < arr.length; i++)?
Ken Haduch
@khaduch
Jul 16 2017 04:22
@chrisbchrist - here is a screenshot from devtools for the request for "noobs2ninjas" from your page.
image.png
kumquatfelafel
@kumquatfelafel
Jul 16 2017 04:23
@LemonTruth NaN is a bit of a weirdo
NaN !== NaN
Ken Haduch
@khaduch
Jul 16 2017 04:23
@chrisbchrist - it shows when the request was sent, then some "Waiting" time, then the return of data in the "Content Download"
heroiczero
@heroiczero
Jul 16 2017 04:24
@LemonTruth personally i would use !isNaN(value) instead of !=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN
kumquatfelafel
@kumquatfelafel
Jul 16 2017 04:24
@LemonTruth you're essentially returning a condition that is going to be true regardless of what you feed it. Ergo, keeps everything.
@globefire nope. Your increment should be size of chunk. Your starting position of i = i + size doesn't make sense, since you're referencing i in right hand side of assignment before you've even assigned it a value. It also means you'd be skipping part of your array entirely.
Steven
@LemonTruth
Jul 16 2017 04:27
interesting
Nitin Sahu
@globefire
Jul 16 2017 04:27
okk i got it my code got executed thanks @kumquatfelafel @heroiczero
CamperBot
@camperbot
Jul 16 2017 04:27
globefire sends brownie points to @kumquatfelafel and @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1494 | @heroiczero |http://www.freecodecamp.com/heroiczero
:cookie: 473 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Steven
@LemonTruth
Jul 16 2017 04:28
function bouncer(arr) {
  // Don't show a false ID to this bouncer.
var nan = NaN;
var filtered = arr.filter(function(nothing){
      return !isNaN(nothing); 
    });
 return filtered;
}
bouncer([7, "ate", 9, NaN]);
this got rid of the NaN but also got rid of "ate". I'm simply trying to get rid of the literal value: NaN. @heroiczero
Nitin Sahu
@globefire
Jul 16 2017 04:28
what's d difference in i+size and i += size ?
Ken Haduch
@khaduch
Jul 16 2017 04:28
@chrisbchrist - I was thinking that you could provide an alternate callback function for requests that you are making as a result of a search - that could assign the extra classes, etc.?
Diego Mayer
@Chrono79
Jul 16 2017 04:28
@globefire the first one doesn't change i value
kumquatfelafel
@kumquatfelafel
Jul 16 2017 04:29
@LemonTruth consider also that isNaN(0) returns false
Ken Haduch
@khaduch
Jul 16 2017 04:30
@LemonTruth - if you carefully read the documentation on .filter() there is a really simple way to solve this. In the "Description", read the link that they have about "a value that coerces to true" at this link
kumquatfelafel
@kumquatfelafel
Jul 16 2017 04:31
@LemonTruth :point_up:
Falsy bouncer challenge is essentially a huge :trollface: :p
heroiczero
@heroiczero
Jul 16 2017 04:34
@LemonTruth they literally almost give you the answer by giving you the two function filter and Boolean
Steven
@LemonTruth
Jul 16 2017 04:35
@heroiczero well then clearly I just suck
heroiczero
@heroiczero
Jul 16 2017 04:36
@LemonTruth no just read the description of the two and it will come to you. Just take it slow
abraham anak agung
@padunk
Jul 16 2017 04:37
@LemonTruth :point_up:
Falsy bouncer challenge is essentially a huge :trollface: :p
I'm going to bang my head to the wall when finding the answer... :smile:
heroiczero
@heroiczero
Jul 16 2017 04:39
@LemonTruth remember you can treat Boolean as a function, so you do not have to create a new function. Technically, it is a method.
kumquatfelafel
@kumquatfelafel
Jul 16 2017 04:39

@globefire to provide an example, say I'm standing on the edge of a cliff, and my friend rolls a snowball downhill towards me. Whether or not I catch that snowball, it's picked up a bunch of snow as it has rolled down the hill.

However if I don't catch it, then the resulting snowball plummets into the murky waters below... never to be seen from again. On the other hand, if I do catch it, I can use it to build a snowman later.

saying i + size is like me not catching the snowball. Sure, the snowball picked up a lot of snow on the way down the hill, but it's absolutely useless to me because I don't have it.

Saying i += size is like me catching the snowball. It picked up a lot of snow, and I can use it later.

@personwhokeepspostinganddeletingcode You can edit your post if you click the ... that appears at top right when you hover your mouse over your posted comment. :p
Steven
@LemonTruth
Jul 16 2017 04:47
HOW IN THE HELL DID THIS TAKE ME A WHOLE 2 HOURS
kumquatfelafel
@kumquatfelafel
Jul 16 2017 04:48
@LemonTruth figured it out? :laughing:
Steven
@LemonTruth
Jul 16 2017 04:48
I read the description of Boolean and got it immediately....I just decided it would be a good idea to skip boolean because I was already familiar with the term "boolean" x)
Im going to thoroughly read the links from now on... xD thanks guys @kumquatfelafel @heroiczero @khaduch
CamperBot
@camperbot
Jul 16 2017 04:50
lemontruth sends brownie points to @kumquatfelafel and @heroiczero and @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 1496 | @heroiczero |http://www.freecodecamp.com/heroiczero
:cookie: 474 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:star2: 3110 | @khaduch |http://www.freecodecamp.com/khaduch
:cookie: 245 | @kaitlinmctigue |http://www.freecodecamp.com/kaitlinmctigue
CallMeOrange
@EgnaroDev
Jul 16 2017 04:50
about @MCTwoDigitZero
CamperBot
@camperbot
Jul 16 2017 04:50
:cookie: 485 | @mctwodigitzero |http://www.freecodecamp.com/mctwodigitzero
Sakitha
@Sakitha
Jul 16 2017 04:50
num = 123;
function cr(num,x){
  var a = Math.floor(num/x);
  if(!a)
    return cr(num,x/10);
  else
    return a*x;
    }
  function fn(ar,val){
     val = arguments[1]||0;
     val = val + ar[0];
     ar.shift();
     if(ar[0])return fn(ar,val);
     else return val;
  }
var ar =[0];

while(fn(ar)!=num){
  a=cr(num - fn(ar),1000);
  ar.push(a);
} 
return ar;this should be [100,20,3]
hey,i wrote this code to get an array of place-value's for a given number.the problem is ar.shift() in "fn" function seems to change the global "ar" array.how can i come around this?
kumquatfelafel
@kumquatfelafel
Jul 16 2017 05:00
@Sakitha If you don't want it to shift ar outside of function, create a deep copy of ar and pass that into fn instead.
currently, since you're passing ar, that's the array that's being shifted.
Sakitha
@Sakitha
Jul 16 2017 05:14
@kumquatfelafel thank you
CamperBot
@camperbot
Jul 16 2017 05:14
sakitha sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 475 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
kumquatfelafel
@kumquatfelafel
Jul 16 2017 05:17
@Sakitha beyond that, things seem a little weird here. Though I'm too tired to mess around with or try to decipher your code at moment. Indeed, I could be imagining problems that don't actually exist. Gonna call it a night.
np
Sakitha
@Sakitha
Jul 16 2017 05:29
@kumquatfelafel yeah,i know there are unnecessary recursive functions in that code,i just wrote them for practice.
Nitin Sahu
@globefire
Jul 16 2017 05:33

@globefire to provide an example, say I'm standing on the edge of a cliff, and my friend rolls a snowball downhill towards me. Whether or not I catch that snowball, it's picked up a bunch of snow as it has rolled down the hill.

However if I don't catch it, then the resulting snowball plummets into the murky waters below... never to be seen from again. On the other hand, if I do catch it, I can use it to build a snowman later.

saying i + size is like me not catching the snowball. Sure, the snowball picked up a lot of snow on the way down the hill, but it's absolutely useless to me because I don't have it.

Saying i += size is like me catching the snowball. It picked up a lot of snow, and I can use it later.

@kumquatfelafel thankks a lot man :laughing:

thanks @kumquatfelafel
CamperBot
@camperbot
Jul 16 2017 05:33
globefire sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 476 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Kamal
@kpbro
Jul 16 2017 05:42
i am stuck on local weather challenge
not getting json data from api
i am first testing here to get json data format from api which should replace 'weather here' text
__mifflin__
@cdrainxv
Jul 16 2017 05:52
@kpbro: Use the api provided by fcc… darksky won’t allow cross-origin api calls. https://fcc-weather-api.glitch.me/
Kamal
@kpbro
Jul 16 2017 05:53
need to check it
Thayyeb salim
@Thayyebsalim
Jul 16 2017 05:57
what about openweather?
__mifflin__
@cdrainxv
Jul 16 2017 05:58
No https on the free account.
codepen is pretty strict about using https… as it should be.
Although you could maybe modify the headers on the request.
Johnny
@jtan3
Jul 16 2017 06:00
@kpbro add ?callback=? instead of &callback=?
Thayyeb salim
@Thayyebsalim
Jul 16 2017 06:00
ah I see
Christopher Blakely
@chrisbchrist
Jul 16 2017 06:02
You can add 'https://cors-anywhere.herokuapp.com/' in front of your api call to make it cross-origin compatible
You can also make it a JSONP request, but I just added that because it's easier heh
iso
@iso1048
Jul 16 2017 06:03
what does => mean? example: var sortedArr = arr.sort((a,b) => a-b);
Christopher Blakely
@chrisbchrist
Jul 16 2017 06:04
@gothamknight It is a compacted notation for a function declaration, basically it is shorthand for function(a, b) { return a - b }
iso
@iso1048
Jul 16 2017 06:05
@chrisbchrist i thought so. Is the only benefit that there is less code to write?
Christopher Blakely
@chrisbchrist
Jul 16 2017 06:06
@gothamknight I don't understand the intricacies of it, but when I encounter it in others' code that's how I interpret it from the documentation, maybe someone else can shed some more light on it
iso
@iso1048
Jul 16 2017 06:08
@chrisbchrist oh ok. thanks
CamperBot
@camperbot
Jul 16 2017 06:08
gothamknight sends brownie points to @chrisbchrist :sparkles: :thumbsup: :sparkles:
:cookie: 291 | @chrisbchrist |http://www.freecodecamp.com/chrisbchrist
__mifflin__
@cdrainxv
Jul 16 2017 06:17
@kpbro: It’s lon and then lat. Seems the order doesn’t matter.
Also https://
Kamal
@kpbro
Jul 16 2017 06:24
@cdrainxv thanks.. got it
CamperBot
@camperbot
Jul 16 2017 06:24
kpbro sends brownie points to @cdrainxv :sparkles: :thumbsup: :sparkles:
:star2: 2759 | @cdrainxv |http://www.freecodecamp.com/cdrainxv
__mifflin__
@cdrainxv
Jul 16 2017 06:33
@kpbro: Welcome! :+1:
Randy Goldsmith
@Dueldrawer8
Jul 16 2017 06:45
so im getting this error message in my console "jquery-3.2.1.js:9566 XMLHttpRequest cannot load file:///C:/Users/randy/Desktop/WeatherApp/index.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.'
this is my api call to darkskyapi.. and i thought converting it to jsonp would fix it... https://api.darksky.net/forecast/3e5050f3f2957b587af0b9d5660ae5d4/30.170491199999997,-95.509247?callback=?
hmm why does that link work but it cant fetch the data?
__mifflin__
@cdrainxv
Jul 16 2017 06:48
Use the api provided by fcc… darksky won’t allow cross-origin api calls. https://fcc-weather-api.glitch.me/

Why do I get the error No 'Access-Control-Allow-Origin' header is present on the requested resource when I try to call the API?
We take security very seriously at Dark Sky. As a security precaution we have disabled cross-origin resource sharing (CORS) on our servers.

Your API call includes your secret API key as part of the request. If you were to make API calls from client-facing code, anyone could extract and use your API key, which would result in a bill that you'd have to pay. We disable CORS to help keep your API secret key a secret.

To prevent API key abuse, you should set up a proxy server to make calls to our API behind the scenes. Then you can provide forecasts to your clients without exposing your API key.

@Dueldrawer8
Randy Goldsmith
@Dueldrawer8
Jul 16 2017 06:51
@cdrainxv thank you, just thought there was a way i could use the API since some people suggested it
ive done this challenge before using the other weather api but it shows nothing but i created that over a year ago
__mifflin__
@cdrainxv
Jul 16 2017 06:55
openweathermap’s free account uses just http instead of https which codepen enforces (as it should for security) reasons. fcc’s api is better because it is is small, uses, https, and doesn’t expose your apiKey (as you don’t need one to make use of the api).
Randy Goldsmith
@Dueldrawer8
Jul 16 2017 06:56
@cdrainxv thanks
CamperBot
@camperbot
Jul 16 2017 06:56
dueldrawer8 sends brownie points to @cdrainxv :sparkles: :thumbsup: :sparkles:
:star2: 2760 | @cdrainxv |http://www.freecodecamp.com/cdrainxv
__mifflin__
@cdrainxv
Jul 16 2017 07:06
@Dueldrawer8: No problem. :smile:
Randy Goldsmith
@Dueldrawer8
Jul 16 2017 07:09
@cdrainxv still having problems...
cant fetch the data
makalohri
@makalohri
Jul 16 2017 07:09
@knrt10 thank you
CamperBot
@camperbot
Jul 16 2017 07:09
makalohri sends brownie points to @knrt10 :sparkles: :thumbsup: :sparkles:
:cookie: 459 | @knrt10 |http://www.freecodecamp.com/knrt10
Randy Goldsmith
@Dueldrawer8
Jul 16 2017 07:16
hmm
anyone?
__mifflin__
@cdrainxv
Jul 16 2017 07:18
@Dueldrawer8: It’s because you lost access to the fccAPI variable…
(function() {
  var fccAPI;

  function success(pos) {
    var crd = pos.coords;
    document.querySelector(".lat").innerHTML =
      "<p> Latitude: " + crd.latitude + "</p>";
    document.querySelector(".long").innerHTML =
      "<p> Longitude: " + crd.longitude + "</p>";

    fccAPI =
      "https://fcc-weather-api.glitch.me/api/current?lat=" +
      crd.longitude +
      "&lon=" +
      crd.latitude;
    // console.log(fccAPI);
    getWeather(fccAPI);
  }
  navigator.geolocation.getCurrentPosition(success);

  function getWeather(fccAPI) {
    $.getJSON(fccAPI, function(data) {
      console.log(fccAPI);
      console.log(JSON.stringify(data));
    });
  }
})();
Randy Goldsmith
@Dueldrawer8
Jul 16 2017 07:20
@cdrainxv i would think if i declared fccAPI within the main function scope globally... ic could access it anywhere within
hm nvm..seems like it doesnt matter if i declare the var fccAPI outside of function success.. only inner functions can access outside functions not the other way around
Randy Goldsmith
@Dueldrawer8
Jul 16 2017 07:30
@cdrainxv thanks again
CamperBot
@camperbot
Jul 16 2017 07:30
dueldrawer8 sends brownie points to @cdrainxv :sparkles: :thumbsup: :sparkles:
:warning: dueldrawer8 already gave cdrainxv points
Sakitha
@Sakitha
Jul 16 2017 07:47
var ar =[['a','b'],['c','d']]; return ar.reduce(function(s,v){ return s+v[0]; });hay,why doesn't this give "ac"?
Markus Kiili
@Masd925
Jul 16 2017 07:56
@Sakitha s+v[0] is ['a','b']+'c'; where ['a','b'] coerces into a string 'a,b'
You should avoid automatic coercion like that.
Manish Giri
@Manish-Giri
Jul 16 2017 08:07
Anyone comfy with Redux here?
Sakitha
@Sakitha
Jul 16 2017 08:07
@Masd925 thank you
CamperBot
@camperbot
Jul 16 2017 08:07
sakitha sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4297 | @masd925 |http://www.freecodecamp.com/masd925
zathura4240
@zathura4240
Jul 16 2017 08:22
Hi
Kelechi Chinaka
@ke1echi
Jul 16 2017 08:22
hi guys :wave:
function factors(x) {
  var xFactors = [];
  if (x < 1) {
    return -1
  }else{
    for (var i = 0; i < x.length; i++) {
      if (x % i == 0) {
        xFactors.push(x);
      }
    }
  }
  return xFactors.sort((a, b) => { return b - a });
}
trying to find the factors of a number
thr function is called like this factors(9) and i know that for loop would not work..any ideas how to go bout it
Manish Giri
@Manish-Giri
Jul 16 2017 08:24
@kelechy x.length?
Kelechi Chinaka
@ke1echi
Jul 16 2017 08:24
hi @Manish-Giri
Manish Giri
@Manish-Giri
Jul 16 2017 08:25
what is a number's length?
zathura4240
@zathura4240
Jul 16 2017 08:25
try only x
Kelechi Chinaka
@ke1echi
Jul 16 2017 08:25
that what am saying
its a number so no length prop
Manish Giri
@Manish-Giri
Jul 16 2017 08:25
so why do you have .length?
loop from 1 through x
zathura4240
@zathura4240
Jul 16 2017 08:26
yeah
Kelechi Chinaka
@ke1echi
Jul 16 2017 08:27
ok..thats true..nice idea
@Manish-Giri you learnt react?
Manish Giri
@Manish-Giri
Jul 16 2017 08:28
@kelechy yup
Kelechi Chinaka
@ke1echi
Jul 16 2017 08:29
good so you can guide us when we get there :smile:
Manish Giri
@Manish-Giri
Jul 16 2017 08:29
lol
Kelechi Chinaka
@ke1echi
Jul 16 2017 08:29
is there doc not good enough to teach redux
Manish Giri
@Manish-Giri
Jul 16 2017 08:30
I haven't looked at the official docs yet (should do that)
going through some other examples now
Kelechi Chinaka
@ke1echi
Jul 16 2017 08:33
function factors(x) {
  var xFactors = [];
  if (x < 1) {
    return -1
  }else{
    for (var i = 1; i <= x; i++) {
      if (x % i == 0) {
        xFactors.push(x);
      }
    }
  }
  return xFactors.sort((a, b) => { return b - a});
}
Expected: '[9, 3, 1]', instead got: '[9, 9]'
what am i doing wrong @Manish-Giri
Manish Giri
@Manish-Giri
Jul 16 2017 08:37
lemme see
xFactors.push(x);
should be i
not x
Kelechi Chinaka
@ke1echi
Jul 16 2017 08:40
i python tutored it
should be i not x
fixed @Manish-Giri
sometimes i feel my kata solutions are slow..do i need to worry about speed now? @Manish-Giri
alpox
@alpox
Jul 16 2017 08:48
@kelechy codewars itself is damn slow. Thats maybe why ^^
Manish Giri
@Manish-Giri
Jul 16 2017 08:49
Slow in what way? @kelechy
alpox
@alpox
Jul 16 2017 08:49
@Manish-Giri im quite comfy with redux
Manish Giri
@Manish-Giri
Jul 16 2017 08:50
@alpox damn I shut down my pc
Lemme see if I can find that example
Kelechi Chinaka
@ke1echi
Jul 16 2017 08:52
yea..and the network is not the most stable @alpox
alpox
@alpox
Jul 16 2017 08:57
@Manish-Giri no worries, i have to run my pc first too :D
Pieter Stokkink
@forkerino
Jul 16 2017 09:06
Good day!
Markus Kiili
@Masd925
Jul 16 2017 09:14
@forkerino Yeah, turned good when I found a bug after 5 hours of searching. Forgetting to use var on one variable inside a constructor. Hard to spot.
Pieter Stokkink
@forkerino
Jul 16 2017 09:14
@Masd925 ouch
Markus Kiili
@Masd925
Jul 16 2017 09:16
@forkerino I had it as a parameter before and turned it into a local variable, so that fooled me.
Pieter Stokkink
@forkerino
Jul 16 2017 09:17
@Masd925 I can imagine. Don't you have a linter or something that catches things like this?
I got some extra work to do this weekend for a client I already had before I started my job. It's just a bit of a menial task (set up a wordpress website).
So I've been putting it off a bit
Markus Kiili
@Masd925
Jul 16 2017 09:19
@forkerino I use eclipse and it has semantic validation. Doesn't complain about that for some reason. One can set linter or whatever on it too.
zathura4240
@zathura4240
Jul 16 2017 09:35
I know this is not the place to ask this but in case you guys know how to use google keywords planner for free
??
@forkerino do you freelance ?
Pieter Stokkink
@forkerino
Jul 16 2017 10:03
@zathura4240 I was, now I have a job.
Michiel
@MichielHuijse
Jul 16 2017 11:01
Hi I am working on this piece of code. And I want to print the var currentStream However it is always giving the same streamname, which I don't understand, since I am looping on the array of streams. What's wrong? https://codepen.io/michiel-huijse/pen/MoxLoz?editors=1011
alpox
@alpox
Jul 16 2017 11:06
@MichielHuijse You can use let to initialize your variable. And please ALWAYS initialize your variables - now you defined currentStream with var outside of the for loop. This creates a variable which is bound to the function scope. If you use no initializer keyword like var, let or const, your variable will be global (This happened with your i in the loop) - means it will be always the same variable everywhere in the code and can only hold one value at a time.
Because your currentStream was initialized with var - and this outside of the loop - it is bound to the function scope. This means that when your callback comes back, the variable will hold the last value it had when looping
@MichielHuijse let currentStream = streamer[i];
Siphils
@Siphils
Jul 16 2017 11:08
Return Largest Numbers in Arrays
json
@swoppy
Jul 16 2017 11:08
i have questions regarding regex, can someone help?
Siphils
@Siphils
Jul 16 2017 11:09

Return Largest Numebers in Arrays

function largestOfFour(arr) {
  // 请把你的代码写在这里
  var newArr=[];
  for(var i=0;i<arr.length;i++){
  var maxNum=arr[i][0];
    for(var j=0;j<arr[i].length;j++){
      if(maxNum<arr[i][j])  maxNum=arr[i][j];
    }
    newArr.push(maxNum);
  }
  return newArr;
}

How can I make it more simple?

alpox
@alpox
Jul 16 2017 11:10
@Siphils You can try to use Math.max
Siphils
@Siphils
Jul 16 2017 11:13
@alpox Thx:) That is really a better method.
CamperBot
@camperbot
Jul 16 2017 11:13
siphils sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1260 | @alpox |http://www.freecodecamp.com/alpox
Michiel
@MichielHuijse
Jul 16 2017 11:14
@alpox thanks, so the thing I took away is that if you want to make sure a variable is kept withing a loop. You should use let instead of var.
CamperBot
@camperbot
Jul 16 2017 11:14
michielhuijse sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1261 | @alpox |http://www.freecodecamp.com/alpox
json
@swoppy
Jul 16 2017 11:15
so what do you want to happen when you put ( ) on your regex aside from OR logic?
Pieter Stokkink
@forkerino
Jul 16 2017 11:17
( ) is a capture group. @n4poleon This means you can refer back to it later in the regex or in the result. If you use .replace, for example, you can refer back to the things in parenthesis by using $1 $2 and so on. where $1 indicates the first captured group, $2 the second and so on.
@n4poleon example:
"ac".replace(/(a)(c)/, "$1b$2") -> "abc"
alpox
@alpox
Jul 16 2017 11:21
@MichielHuijse Yep
Pieter Stokkink
@forkerino
Jul 16 2017 11:22
@MichielHuijse an alternative way to accomplish this (without let) is to use a .forEach on your array of streamers
but let is great.
Michiel
@MichielHuijse
Jul 16 2017 11:25
@forkerino aah allright, thanks
CamperBot
@camperbot
Jul 16 2017 11:25
michielhuijse sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2857 | @forkerino |http://www.freecodecamp.com/forkerino
json
@swoppy
Jul 16 2017 11:27
@forkerino ahh i remember, but regex are confusing how do you interpret this
(\s?)?
btw the ? after the () is included on the regex
Pieter Stokkink
@forkerino
Jul 16 2017 11:34
@n4poleon not sure both ? are needed
@n4poleon \s? is no space or one space (or tab, or other whitespace)
json
@swoppy
Jul 16 2017 11:36
@forkerino any whitespace
ussualy it's just one space
Pieter Stokkink
@forkerino
Jul 16 2017 11:38

@n4poleon there are other whitespace characters.

Matches a single white space character, including space, tab, form feed, line feed and other Unicode spaces. Equivalent to [ \f\n\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff].

but yeah, only one
or zero
json
@swoppy
Jul 16 2017 11:39
one space, just space
@forkerino
Vlada
@vlada140
Jul 16 2017 11:48

Can anyone explain me this code:

function mutation(arr) {
var test = arr[1].toLowerCase();
var target = arr[0].toLowerCase();
for (i=0;i<test.length;i++) {
if (target.indexOf(test[i]) < 0)
return false;
}
return true;
}
mutation(["hello", "hey"]);

When i call function "mutation" there is two arguments, but in maim function is one argument - arr

Dan Couper
@DanCouper
Jul 16 2017 11:50
There's definitely only one argument there when you call it
I can see it, here, one argument: mutation(["hello", "hey"]);
Why do you think the person writing the challenge has given the argument the name arr, ie what is tye word arr short for?
Max
@maxiwer
Jul 16 2017 12:07
Hello campers. In this code I'm trying to transfer first letters of array elements to upper case and other letters to lower case. What's wrong with code?
function titleCase(str) {
var arr = str.split(" ");
var newArr = [];
for (var i = 0; i < arr.length; i++) {
if (arr[i][0]) {
newArr.push(arr[0].toUpperCase());
} else {
newArr.push(arr[i].toLowerCase());
}
}
return newArr;
}
Pieter Stokkink
@forkerino
Jul 16 2017 12:08
@maxiwer basically what happens is you check if the i'th word has a first letter and if so you uppercase the first word and put that into newArr.
Because all words have a first letter, you push the capitalized first word exactly as many times as there are words in str
Max
@maxiwer
Jul 16 2017 12:09
@forkerino :D. I'm confused.
Pieter Stokkink
@forkerino
Jul 16 2017 12:09
@maxiwer to fix it: You don't need an if/else inside your loop. Just overwrite the element of the array.
or push to newArr, but that is not really needed.
Max
@maxiwer
Jul 16 2017 12:11
@forkerino How can I override the array?
UnkyKong
@UnkyKong
Jul 16 2017 12:16
how do I make .appendChild() append to a dynamic element. https://codepen.io/Unky/pen/QgrXvz?editors=0010 all my divs overwrite each other and i'm left with one div
Pieter Stokkink
@forkerino
Jul 16 2017 12:17
@maxiwer arr[i] = .... after = capitalize the first letter of arr[i] and concatenate the rest of the word in lowercase
shivam gupta
@shivamg11000
Jul 16 2017 12:59
hey anyone can guide me how to use OAuth with js
Abhinav Mishra
@abhinav-m
Jul 16 2017 13:11
Anyone here who has worked with Hugo
ParadoxStephen
@StephenLover
Jul 16 2017 13:31
hi guys,I am trying to reverse the string,however,i can not get the right answer,can someone help me?

function reverseString(str) {
// 请把你的代码写在这里
var array = str.split(" ");
var re_array = array.reverse();
str = re_array.join("");
return str;
}

reverseString("hello");

bahaa aldin
@bahaa-al-deen
Jul 16 2017 13:41

hey guys
i'm implementing the remove method in a linked list

this.remove = function(element){
    // Only change code below this line
    var currentNode = head;
    var previousNode;
    if (currentNode.element == element) {
      head = currentNode.next;
    } else {

//       while (currentNode.next) {
//         if (currentNode.element == element) {
//           previousNode.next = currentNode.next;
//         } else {
//           previousNode = currentNode;
//           currentNode = currentNode.next;
//         }
//       }
      while (currentNode.element != element) {
        previousNode = currentNode;
        currentNode = currentNode.next;
      }
      previousNode.next = currentNode.next;
    }

    length--;

    // Only change code above this line
  };

when i run the tests using the first (commented) while loop it doesn't pass
when i run it with the the second loop it pass
can any one tell my the reason why the first loop doesn't work ?

Pieter Stokkink
@forkerino
Jul 16 2017 13:45
@StephenLover your .split() splits on a space, but you should split between every character. Use "" instead of " "
ParadoxStephen
@StephenLover
Jul 16 2017 13:47
@forkerino thanks a lot,it works :smile:
CamperBot
@camperbot
Jul 16 2017 13:47
stephenlover sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2858 | @forkerino |http://www.freecodecamp.com/forkerino
ParadoxStephen
@StephenLover
Jul 16 2017 13:48
it is not similar with python,lol
Pieter Stokkink
@forkerino
Jul 16 2017 13:49
@BahaaZidan do you need to remove only the first node that matches?
bahaa aldin
@bahaa-al-deen
Jul 16 2017 13:50
@forkerino yes
@forkerino i know that performance wise
the second loop is better because it stops when the target element is found
but still, i think the first one should also do the job !
Abhinav Mishra
@abhinav-m
Jul 16 2017 13:53
{{ partial "post_meta.html" . }}
              <div class="post-entry">
                {{ if .Truncated }}
                  {{ .Summary }}
                  <a href="{{ .Permalink }}" class="post-read-more">[{{ i18n "readMore" }}]</a>
                {{ else }}
                  {{ .Content }}
                {{ end }}
              </div>
Pieter Stokkink
@forkerino
Jul 16 2017 13:54
@BahaaZidan I think the first one will remove all elements that match
bahaa aldin
@bahaa-al-deen
Jul 16 2017 13:54
@forkerino yes you're right
Pieter Stokkink
@forkerino
Jul 16 2017 13:54
or at least more than one
if possible
It might pass if there are two in a row
Sweet Coding :)
@SweetCodingInc
Jul 16 2017 13:57
@abhinav-thinktank is that handlebars/mustache template?
Abhinav Mishra
@abhinav-m
Jul 16 2017 13:57
@SweetCodingInc I have no idea.
@SweetCodingInc Im trying to do this thing called Hugo which is a generator of a website using Google's go
Sweet Coding :)
@SweetCodingInc
Jul 16 2017 13:58
I see..
It looks pretty much like handlebars
Abhinav Mishra
@abhinav-m
Jul 16 2017 13:58
@SweetCodingInc It generated this html, and i need to display the content, without truncating it, the if else seems obvious, but it is still getting truncated after i remove the if else part
Sweet Coding :)
@SweetCodingInc
Jul 16 2017 13:58
oh dear.. .those good old days when templating library was a thing
Abhinav Mishra
@abhinav-m
Jul 16 2017 13:59
:\
It is actually pretty cool, but i can't get it to work properly
Sweet Coding :)
@SweetCodingInc
Jul 16 2017 13:59
I'm not sure about hugo etc, but are your certain it's {{ end }} and not {{ endif }} ?
Abhinav Mishra
@abhinav-m
Jul 16 2017 14:01
yea its end
{{ define "header" }}
  <header class="header-section ">
    <div class="intro-header no-img">
      <div class="container">
        <div class="row">
          <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
            <div class="page-heading">
              <h1>{{ if .Data.Singular }}#{{ end }}{{ .Title }}</h1>
            </div>
          </div>
        </div>
      </div>
    </div>
  </header>
{{ end }}
{{ define "main" }}
  <div class="container" role="main">
    <div class="row">
      <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">

        {{ with .Content }}
            {{.}}
          </div>

        {{ end }}
        <div class="posts-list">
          {{ range .Paginator.Pages }}
            <article class="post-preview">
              <a href="{{ .Permalink }}">
                <h2 class="post-title">{{ .Title }}</h2>
                 <hr class ="small">
                {{ if .Params.subtitle }}
                  <h3 class="post-subtitle">
                    {{ .Params.subtitle }}
                  </h3>
                {{ end }}
              </a>

              <p class="post-meta">
                {{ default (i18n "dateFormat") .Site.Params.dateformat | .Date.Format | i18n "postedOnDate" }}
              </p>
              <div class="post-entry">
             <!--   {{ if .Truncated }}
                  {{ .Summary }}
                  <a href="{{ .Permalink }}" class="post-read-more">[{{ i18n "readMore" }}]</a>
                {{ else }} 
                  -->
                  {{ .Content }}
                {{ end }}
              </div>

              {{ if .Params.tags }}
                <span class="post-meta">
                  {{ range .Params.tags }}
                    #<a href="{{ $.Site.LanguagePrefix }}/tags/{{ . | urlize }}">{{ . }}</a>&nbsp;
                  {{ end }}
                </span>
              {{ end }}

            </article>
          {{ end }}
        </div>
        {{ if or (.Paginator.HasPrev) (.Paginator.HasNext) }}
          <ul class="pager main-pager">
            {{ if .Paginator.HasPrev }}
              <li class="previous">
                <a href="{{ .URL }}page/{{ .Paginator.Prev.PageNumber }}">&larr; {{ i18n "newerPosts" }}</a>
              </li>
            {{ end }}
            {{ if .Paginator.HasNext }}
              <li class="next">
                <a href="{{ .URL }}page/{{ .Paginator.Next.PageNumber }}">{{ i18n "olderPosts" }} &rarr;</a>
              </li>
            {{ end }}
          </ul>
        {{ end }}
      </div>
    </div>
  </div>
{{ end }}
This is actually the whole page being rendered, i just want to get rid of the if Truncated section
shivam gupta
@shivamg11000
Jul 16 2017 14:11
any guesses without running the code
[] + []
Stephen James
@sjames1958gm
Jul 16 2017 14:13
I am guessing empty string, not sure why.
Sweet Coding :)
@SweetCodingInc
Jul 16 2017 14:15
yes. empty string.
+ when used on operands of type != number, casts operands to string.
so if you do [2]+[1] you get 21
Stephen James
@sjames1958gm
Jul 16 2017 14:16
Well there you go.
Sweet Coding :)
@SweetCodingInc
Jul 16 2017 14:17
[1,2,3]+[1] => 1,2,31
shivam gupta
@shivamg11000
Jul 16 2017 14:18
well all are pro here
Sweet Coding :)
@SweetCodingInc
Jul 16 2017 14:21
this is not pro shit lol
pro shit begins with subclassing Array... ;)
shivam gupta
@shivamg11000
Jul 16 2017 14:21
example
Marco Galizzi
@Tezenn
Jul 16 2017 14:21
works doing
arr.forEach(function(element){)
element.reduce as well?
Sweet Coding :)
@SweetCodingInc
Jul 16 2017 14:23
This is one of the simplest questions i use to screen out wanna be javascripters ;)
shivam gupta
@shivamg11000
Jul 16 2017 14:24
well, which language is this
Sweet Coding :)
@SweetCodingInc
Jul 16 2017 14:24
That's a problem statement
English
shivam gupta
@shivamg11000
Jul 16 2017 14:24
I mean programming language
Sweet Coding :)
@SweetCodingInc
Jul 16 2017 14:24
JS
shivam gupta
@shivamg11000
Jul 16 2017 14:24
k
Sweet Coding :)
@SweetCodingInc
Jul 16 2017 14:25
that var should have made it obvious that it's js
shivam gupta
@shivamg11000
Jul 16 2017 14:25
what is this line
Inherit Array (native) class to create a sub-class 'MyArray'.
Sweet Coding :)
@SweetCodingInc
Jul 16 2017 14:25
Read the whole thing first
shivam gupta
@shivamg11000
Jul 16 2017 14:25
@SweetCodingInc var is also in C#
Sweet Coding :)
@SweetCodingInc
Jul 16 2017 14:26
nvm... solve it.. this is where pro shit begins...
then next challenge would be to call anonymous function recursively ;)
shivam gupta
@shivamg11000
Jul 16 2017 14:27
sorry bro no time
Sweet Coding :)
@SweetCodingInc
Jul 16 2017 14:28
:+1:
shivam gupta
@shivamg11000
Jul 16 2017 14:28
wheres the question gone
Sweet Coding :)
@SweetCodingInc
Jul 16 2017 14:28
I deleted it
shivam gupta
@shivamg11000
Jul 16 2017 14:28
well I didn't get the test cases
Sweet Coding :)
@SweetCodingInc
Jul 16 2017 14:29
it's like when you run that, whatever written in comment should be the output
shivam gupta
@shivamg11000
Jul 16 2017 14:31
any idea how to use OAuth 2 with js
korzo
@korzo
Jul 16 2017 14:31
@SweetCodingInc from where is this assignment?
Sweet Coding :)
@SweetCodingInc
Jul 16 2017 14:31
@korzo It's one of the screening questions we used to send as part of recruitment process
Harut
@harut-g
Jul 16 2017 14:32
How can help me how to print numbers with setTimeout?
var arr = [1, 2, 3, 4, 5, 6, 7];

function printNum(){
  setTimeout(function(){
    console.log(i);
  },10);
}
for(var i = 0; i < arr.length; i++) {
printNum(arr[i]);
}
Sweet Coding :)
@SweetCodingInc
Jul 16 2017 14:32
@shivamg11000 jS +OAuth2
shivam gupta
@shivamg11000
Jul 16 2017 14:32
with react
Marco Galizzi
@Tezenn
Jul 16 2017 14:33
guys i have an array of array. i want to sum the two integers inside the sub arrays and keep the sum but the slice methodwon't work.
var bob = [[1,2],[3,4],[5,6]];
bob.forEach(function(ele){
  ele[0] = ele[0] + ele[1];
  ele = ele.slice(0,1);
});
console.log(bob)
korzo
@korzo
Jul 16 2017 14:33
@SweetCodingInc Thanks. I like it, nice example of inheritance in JS
CamperBot
@camperbot
Jul 16 2017 14:33
:cookie: 127 | @sweetcodinginc |http://www.freecodecamp.com/sweetcodinginc
korzo sends brownie points to @sweetcodinginc :sparkles: :thumbsup: :sparkles:
Sweet Coding :)
@SweetCodingInc
Jul 16 2017 14:34
@harut-g
var arr = [1, 2, 3, 4, 5, 6, 7];

function printNum(n){
  setTimeout(function(){
    console.log(n);
  },10);
}
for(var i = 0; i < arr.length; i++) {
  printNum(arr[i]);
}
@korzo Yo! That's one of the best examples to see if someone really knows prototypal inheritance
not just that, but the chaining.
It seems simple, straightforward and insignificant but the outputs screw you up if you don't know whats going on
Markus Kiili
@Masd925
Jul 16 2017 14:36
@SweetCodingInc You are talking about a function expression without a name calling itself from the function code? arguments.callee would do it but is deprecated. I think I have seen some such code done with call or bind.
Sweet Coding :)
@SweetCodingInc
Jul 16 2017 14:37
@Masd925 Yeah.. Now that you know there is such a thing called arguments.callee, you are no longer allowed to use it ;)
it can be done with both call and bind. but I prefer call
@Tezenn
var bob = [[1,2],[3,4],[5,6]];
bob = bob.map(function(ele){
  return ele.reduce((s, c) => s+c);
});
console.log(bob);
Stephen James
@sjames1958gm
Jul 16 2017 14:39
@Tezenn I would use map for that
Markus Kiili
@Masd925
Jul 16 2017 14:39
@SweetCodingInc I have only seen it used on recruitment questions. That is one purpose of coding I guess to satisfy recruiters.
Sweet Coding :)
@SweetCodingInc
Jul 16 2017 14:39
@Masd925 not really...
Harut
@harut-g
Jul 16 2017 14:40
@SweetCodingInc thank you!
CamperBot
@camperbot
Jul 16 2017 14:40
harut-g sends brownie points to @sweetcodinginc :sparkles: :thumbsup: :sparkles:
:cookie: 128 | @sweetcodinginc |http://www.freecodecamp.com/sweetcodinginc
Sweet Coding :)
@SweetCodingInc
Jul 16 2017 14:41
There is a point that for most front end development it's not necessary to know all these things. but if you're looking for some super badass job that pays you a ton, like js framework designer or want to be on TypeScript team in Microsoft, these things are like basics.
Markus Kiili
@Masd925
Jul 16 2017 14:45
@SweetCodingInc Sure. Just one of those things I have seen in theory but never used in practice.
Sweet Coding :)
@SweetCodingInc
Jul 16 2017 14:53
@Masd925 Virtual Dom engines make heavy use of this pattern
it's always efficient and self explanatory to use recursion in dom traversal instead of implementing complicated tree algorithems
Bradley Sands
@sandsbe
Jul 16 2017 15:00
Working on Weather app. The api address link I built makes https://fcc-weather-api.glitch.me/api/current?lon=:-105&lat=:40 address, but it returns info for the sample lat & lon. Any reason why its not "reading" the -105 & 40"?
Bradley Sands
@sandsbe
Jul 16 2017 15:05
function success(pos) {
  var crd = pos.coords;
  var latitude  = Math.round(pos.coords.latitude);
  var longitude = Math.round(pos.coords.longitude);
  console.log('Your current position is:');
  console.log(`Latitude : ${latitude}`);
  console.log(`Longitude: ${longitude}`);
  console.log(`More or less ${crd.accuracy} meters.`);
  document.getElementById("out").innerHTML = '<p>Latitude is ' + latitude + '° <br>Longitude is ' + longitude + '°</p>';
  var requestURL = 'https://fcc-weather-api.glitch.me/api/current?lat=:'+latitude+'&lon=:'+longitude;
  console.log(requestURL);
};
That gets the geolocation when I pass it through navigator.geolocation.getCurrentPosition(success, error, options);
Bradley Sands
@sandsbe
Jul 16 2017 15:19
Ok, maybe that question isn't good for now. How about timing functions? I have my geolocation call my success function and then I want to take that information and use it to call my next function which is the API call.
Console.log keeps telling me that my API function is happening before my geolocation function. How should I be thinking of this when I want everything to work on page load?
Moisés Man
@moigithub
Jul 16 2017 15:20
remove :
//fcc-weather-api.glitch.me/api/current?lon=:-105&lat=:40
https://fcc-weather-api.glitch.me/ <-- u can check the example there
Bradley Sands
@sandsbe
Jul 16 2017 15:22
Huge @moigithub. Couldn't find that difference.
Bradley Sands
@sandsbe
Jul 16 2017 15:30
Thinking I need an event handler to fire the api after the geolocate info comes in...
Moisés Man
@moigithub
Jul 16 2017 15:30
about "timing" probably u refering to ASYNChronous functions/methods
call/request is sent to server.. but data dont return immediatelly.. it might take times.. depends on server loads/internet trafic and dunno what, it can take few nanoseconds to many seconds/minutes
Bradley Sands
@sandsbe
Jul 16 2017 15:31
Yup. So assuming it doesn't return immediately, I think I need to "delay" my weather api for after my geolocation
Moisés Man
@moigithub
Jul 16 2017 15:31
JS engine dont stop when u execute async functions.. but it queue and when data back those methods CALLS a callback/function saying something like "hey.. i got ur data here it is" <-- inside the callback
on the meanwhile.. it keep executing the rest of ur code(s)
Bradley Sands
@sandsbe
Jul 16 2017 15:33
well when I console.log(variable) and the variable is based on info geolocate & weather api, I get nothing
function getWeather () {
  var request = new XMLHttpRequest();
  request.open('GET', requestURL);
  request.responseType = 'json';
  request.send();
  request.onload = function() {
    var weather = request.response;
  }
}
Moisés Man
@moigithub
Jul 16 2017 15:34

getGeolocatoin( callback(position){
// position lat lon is/will be available inside this callback
})

// trying to get lat lon here.. will be undefined.. cuz callback above didnt executed/data isnt returned yet

Bradley Sands
@sandsbe
Jul 16 2017 15:34
the requestURL is my info from the geolocation call. I keep console.log(weather) and getting nothing, whether its inside the function or outside.
Moisés Man
@moigithub
Jul 16 2017 15:36
soo when u working with async functions/methods only place for SURE u have data available is inside the function/callback
Moisés Man
@moigithub
Jul 16 2017 15:39
another thing u might have is about scope
Bradley Sands
@sandsbe
Jul 16 2017 15:39
"An async function can contain an await expression, that pauses the execution of the async function and waits for the passed Promise's resolution, and then resumes the async function's execution and returns the resolved value."
Definitely don't fully grasp scope yet. Sometimes the variable is "hidden" in a function, but other times its not?
Abhinav Mishra
@abhinav-m
Jul 16 2017 15:40
Anyone know yaml?
Bradley Sands
@sandsbe
Jul 16 2017 15:41
So in my scenario above, var requestURL is in the success (). Can I still call that variable in getWeather ().
Moisés Man
@moigithub
Jul 16 2017 15:41
scopes is like bubbles or nested circles (one circle inside another inside another)
Bradley Sands
@sandsbe
Jul 16 2017 15:44
async function getProcessedData(url) {
  let v;
  try {
    v = await downloadData(url); 
  } catch(e) {
    v = await downloadFallbackData(url);
  }
  return processDataInWorker(v);
}
FlashHero
@FlashHero
Jul 16 2017 15:45
why wouldn't this work
var myArray=[['first',1],['second',2]];
var obj={};
myArray.map(function(x) {
     obj.x[1]=x[0];
})
console.log(obj);
Pieter Stokkink
@forkerino
Jul 16 2017 15:46
@FlashHero x is a variable, you cannot use dot notation for that
kumquatfelafel
@kumquatfelafel
Jul 16 2017 15:46
@FlashHero In obj, there is no "x" property
Pieter Stokkink
@forkerino
Jul 16 2017 15:46
obj[x[1]]
@kumquatfelafel :wave:
kumquatfelafel
@kumquatfelafel
Jul 16 2017 15:46
heya
FlashHero
@FlashHero
Jul 16 2017 15:48
@forkerino thanks
CamperBot
@camperbot
Jul 16 2017 15:48
flashhero sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2859 | @forkerino |http://www.freecodecamp.com/forkerino
Bradley Sands
@sandsbe
Jul 16 2017 15:56
ty @moigithub . Going to try again later.
CamperBot
@camperbot
Jul 16 2017 15:56
sandsbe sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3511 | @moigithub |http://www.freecodecamp.com/moigithub
RakeshNerkar
@Rakesh18754
Jul 16 2017 15:56
(function(){

    function test(){
           tempNums = 6;
           console.log(tempNums );
           var tempNums;
          console.log(tempNums);
           tempNums =3;
          console.log(tempNums);  
          setTimeout(function(){ console.log(tempNums); }, 3000);
    }
test();
console.log(tempNums , " outside");
})();

why does the last console throws a reference error
ReferenceError: tempNums is not defined?

as i am defining it inside test funciton as a global variable?

Stephen James
@sjames1958gm
Jul 16 2017 15:57
@Rakesh18754 You have var tempNums, which makes it local to the function
Moisés Man
@moigithub
Jul 16 2017 15:58
promises is a method to avoid callback hell (a function nested inside another nested inside another nested inside... etc etc etc )
async/await (es7) are methods to work with promises in a synchronous way
@sandsbe dont confuse/mix asynchronous(terminology ? ) with async (es7) (method)
RakeshNerkar
@Rakesh18754
Jul 16 2017 15:59
@sjames1958gm Thanks
CamperBot
@camperbot
Jul 16 2017 15:59
rakesh18754 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8078 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 16 2017 16:01
@Rakesh18754 :+1:
RakeshNerkar
@Rakesh18754
Jul 16 2017 16:12
var person = Object.create(null);
var employee = new Object(null);
console.log(Object.getPrototypeOf(person));  // null
console.log(Object.getPrototypeOf(employee));  // object{}
can any one explain the above case?
Stephen James
@sjames1958gm
Jul 16 2017 16:20
@Rakesh18754 The first parameter of Object.create becomes the prototype of the object creating which is why persons prototype is null
Moisés Man
@moigithub
Jul 16 2017 16:21
using new creates a __proto__ property
Markus Kiili
@Masd925
Jul 16 2017 16:31
@Rakesh18754 Passing null to new Object() just creates a plain object.
RakeshNerkar
@Rakesh18754
Jul 16 2017 16:37
@Masd925 so wats the diff between object.create and new...i mean when to use which method?
Markus Kiili
@Masd925
Jul 16 2017 16:40
@Rakesh18754 You use Object.create when you wan't to set the prototype of the new object and don't wan't to use a constructor. new Object() just makes a new plain object that has Object.prototype as its prototype (just like {} is). If you pass something into new Object() it is wrapped into an object.
For example creates a Number object from a number:
var obj = new Object(5);
obj instanceof Number; // true
obj.valueOf(); // 5
Miljan Grcic
@Nightimer
Jul 16 2017 16:46
    $("#btn-search").on("click", function ()) {
        var inputField = $("#inputField")
        // If input field is not empty, store value into variable
        if (inputField.val().length > 0) {
            var textToBeSearched = inputField.val();


        // If input field is empty, alert invalid input
        }    else if (inputField.val().length == 0) {
            alert ("Invalid input")
        }
    })

// When clicked it will delete everything from input field
    $("#btn-delete").on("click", function () {
        $("#inputField").val("");
    })

function sendRequest () {
    var endpoint = "https://en.wikipedia.org/w/api.php"; 
    var action = "action=query"
    var format = "json"
    var searchQuery = "titles=" + textToBeSearched;
}
How can i pass "var TextToBeSearched = inputField.val(); into send request function
Basicly all i want is to send ajax in new function, and not to nest it
RakeshNerkar
@Rakesh18754
Jul 16 2017 16:50
@Masd925 can u pls give a small example using a constructor so that i can understand the diff ...
Pieter Stokkink
@forkerino
Jul 16 2017 16:50
@Nightimer use a function parameter
and just pass it in as an argument
RakeshNerkar
@Rakesh18754
Jul 16 2017 16:51
@Masd925 i mean how to achieve the same thing using a constructor?
Miljan Grcic
@Nightimer
Jul 16 2017 16:52
@forkerino Can you explain little? Not sure what do you mean
Stephen James
@sjames1958gm
Jul 16 2017 16:52
@Rakesh18754 https://www.freecodecamp.com/challenges/make-a-person
This challenge does that exactly
Markus Kiili
@Masd925
Jul 16 2017 16:55
@Rakesh18754 You can set the prototype property of the constructor and it is set as prototype of the new objects created by new MyCar():
function MyCar() {}

MyCar.prototype = Object.prototype;

var car = new MyCar();
RakeshNerkar
@Rakesh18754
Jul 16 2017 16:58
@Masd925 ok...Thanks a lot..for ur help..
CamperBot
@camperbot
Jul 16 2017 16:58
rakesh18754 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4298 | @masd925 |http://www.freecodecamp.com/masd925
Oleh
@Lufter
Jul 16 2017 16:59

Hi guys, could you please tell me how can i use "icon" variable in api call

    icons.set("weather-icon", Skycons.PARTLY_CLOUDY_DAY);
            var icon = data["currently"].icon;
            icon = icon.replace(/\-/g,"_").toUpperCase();
            console.log(icon);
            var icons = new Skycons({"color": "orange"});
            icons.set("weather-icon", Skycons.PARTLY_CLOUDY_DAY);

replace "PARTLY_CLOUDY_DAY" with string in "icon" variable ?

    icons.set("weather-icon", Skycons.icon);
Jerard Delrosario
@jrardd
Jul 16 2017 17:12
Hi guys this is probably a dumb question, but why does this return null?
function sumAll(arr) {
  var min = Math.min(arr);
  var max = Math.max(arr);


return min;

}
sumAll([1, 4]);
Stephen James
@sjames1958gm
Jul 16 2017 17:15
@jrardd It is actually returning NaN but the FCC console shows NaN as null.
Math.min() on an array is NaN
Jerard Delrosario
@jrardd
Jul 16 2017 17:17
@sjames1958gm Ok
Why isn't it returning 1 though.
Hemakshi Sachdev
@hemakshis
Jul 16 2017 17:19
@jrardd the min function takes two arguments, not one
Math.min(start,end)
Stephen James
@sjames1958gm
Jul 16 2017 17:19
@jrardd Because Math.min(array) returns NaN, Math.min expects separate values.
You can do Math.min.apply(null, arr);
Jerard Delrosario
@jrardd
Jul 16 2017 17:20
ohh ok thanks! @sjames1958gm @hemakshis
CamperBot
@camperbot
Jul 16 2017 17:20
jrardd sends brownie points to @sjames1958gm and @hemakshis :sparkles: :thumbsup: :sparkles:
:cookie: 282 | @hemakshis |http://www.freecodecamp.com/hemakshis
:star2: 8079 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Hemakshi Sachdev
@hemakshis
Jul 16 2017 17:25
@Lufter If possible, I would suggest you to make a separate object with the name icons and having keys as the data.currently.icon and values as Skycons.[THE_CURRENT_WEATHER_CONDITION] respectively for each type of icon.. since there are not much icons u can do this! nd you don't have to do so much of coding to convert them.
Bradley Sands
@sandsbe
Jul 16 2017 17:48
@moigithub appreciate the help. Watching videos now to try and get these functions to stage properly. Still not working.
@Lufter Are you currently working on the Weather app?
Michiel
@MichielHuijse
Jul 16 2017 17:51
Can somebody explain why the links are not working? Thanks in advance! https://codepen.io/michiel-huijse/pen/MoxLoz?editors=1111
catapulto
@catapulto
Jul 16 2017 17:52
hey somebody have any others guides on javascript
Michiel
@MichielHuijse
Jul 16 2017 17:53
@catapulto checkout www.eloquentjavascript.net
catapulto
@catapulto
Jul 16 2017 17:56
@MichielHuijse i already that reading it now
but i have very much confusion in loops especillay.
Ronique Ricketts
@RoniqueRicketts
Jul 16 2017 17:58
@catapulto what better place to learn JS but from the people who holds all its learning information.
Bradley Sands
@sandsbe
Jul 16 2017 17:58
@catapulto If you're just going to read docs, the best resource is http://devdocs.io. Also, run everything through pythontutor.com. I always have those two windows open when doing js algos.
Stephen James
@sjames1958gm
Jul 16 2017 18:02
@MichielHuijse Your links are to the api URL, not to the page URL
Ghulam Shabir
@ghulamshabir
Jul 16 2017 18:04
@catapulto loop is to execute statement(s) a fixed number of times or until a condition is met, practice is the key to grasp pogramming concepts, not just reading about them
RakeshNerkar
@Rakesh18754
Jul 16 2017 18:07
var Person = {
  _name: "jade",
  getName:function(){
    console.log("this._name");
  }
}

var name = Person.getName;
console.log(name()); //Uncaught TypeError: name is not a function(…)
any idea why this givea an error?
Bradley Sands
@sandsbe
Jul 16 2017 18:09
Specifically for the weather app but also generally, why put $(document).ready(function () { CODE GOES HERE } for the JS. i.e. why keep everything in a "master" function?
Michiel
@MichielHuijse
Jul 16 2017 18:09
thanks! @sjames1958gm
CamperBot
@camperbot
Jul 16 2017 18:09
michielhuijse sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8080 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Michiel
@MichielHuijse
Jul 16 2017 18:10
solved it :)
Stephen James
@sjames1958gm
Jul 16 2017 18:10
@MichielHuijse :+1:
@sandsbe It is a timing issue not a scoping issue. You want to wait until the document is ready before attempting to manipulate the page.
This is equally valid
$(document).ready(start);
function start() {
}
Bradley Sands
@sandsbe
Jul 16 2017 18:12
Is the vanilla JS equivalent window.onload = function() { CODE HERE } ?
Ronique Ricketts
@RoniqueRicketts
Jul 16 2017 18:17
@sandsbe yes. once the page loads it fires the onload event which runs whichever code is in the curly braces.
RakeshNerkar
@Rakesh18754
Jul 16 2017 18:19
var Person = {
  _name: "jade",
  getName:function(){
    console.log("this._name");
  }
}

var name = Person.getName;
console.log(name()); //Uncaught TypeError: name is not a function(…)
any idea why this givea an error?
Bradley Sands
@sandsbe
Jul 16 2017 18:21
ty @RoniqueRicketts
CamperBot
@camperbot
Jul 16 2017 18:21
sandsbe sends brownie points to @roniquericketts :sparkles: :thumbsup: :sparkles:
:cookie: 284 | @roniquericketts |http://www.freecodecamp.com/roniquericketts
Nick Cleary
@Hijerboa
Jul 16 2017 18:23
Hey all! I'm currently working on the Wikipedia viewer project. My current plan is as follows: Us the jQuery keyPress() function to identify when a key is pressed, then a switch statement to identify which key is pressed. Then, the result of that will be pushed to an array, which is then joined and made into a string, which is then pushed to the wiki API. The results will be retrieved, and article names will simply be pushed to the page, and in order to obtain the URL's, I will append the article names to an array, join, split it at spaces, and then rejoin them using underscores, and re-add it to the wiki URL in order to obtain the proper URL for the web page. In theory this should work, but I feel like I'm over thinking it, thus over complicating it. Any suggestions?
Stephen James
@sjames1958gm
Jul 16 2017 18:23
@Rakesh18754 For some reason, name is a string and not a function.
Christopher Blakely
@chrisbchrist
Jul 16 2017 18:25
@Hijerboa You have the right idea but there are easier ways to do those things. You can for example capture the value of a text input all at once and feed it directly as a string to the API
Stephen James
@sjames1958gm
Jul 16 2017 18:25
@Hijerboa Not sure why you use an array in the first part, just concatenate a string.
Are you planning to request from the API on every character?
Nick Cleary
@Hijerboa
Jul 16 2017 18:26
@sjames1958gm yes.
Ronique Ricketts
@RoniqueRicketts
Jul 16 2017 18:26
@Hijerboa will the page load details while your typing?
Nick Cleary
@Hijerboa
Jul 16 2017 18:26
it would be a lot easier if I did on enter, but this seems like it would offer better functionality
@RoniqueRicketts yep
Moisés Man
@moigithub
Jul 16 2017 18:28
@Rakesh18754 seems name is a reserved identifier (window property)
https://developer.mozilla.org/en-US/docs/Web/API/Window/name
RakeshNerkar
@Rakesh18754
Jul 16 2017 18:29
@moigithub what is a is a reserved identifier?
Nick Cleary
@Hijerboa
Jul 16 2017 18:29
@Rakesh18754 you can't use it as a variable name
Moisés Man
@moigithub
Jul 16 2017 18:31
similar to console or document or history or status u cant use those as variables names (on the global scope)
Ronique Ricketts
@RoniqueRicketts
Jul 16 2017 18:33
@Hijerboa have you tried
$( "#target" ).keyup(function() {
  1. call api
   2.  create divs with link 
});
Nick Cleary
@Hijerboa
Jul 16 2017 18:33
@RoniqueRicketts I haven't actually tried anything; I was wondering if there was a simpler way than what I described, as I feel as if I am over engineering a simple concept
RakeshNerkar
@Rakesh18754
Jul 16 2017 18:34
@moigithub ok..but even if i change it to test then also the values are not getting printed ...it still outputs undefined
var Person = {
  _name: "jade",
  getName:function(){

    console.log(this._name);
  }
}

var test = Person.getName;

console.log(test());
@moigithub any idea ?
Nick Cleary
@Hijerboa
Jul 16 2017 18:35
@Rakesh18754 perhaps I'm wrong but if I recall correctly you can't start variable names with underscores
Moisés Man
@moigithub
Jul 16 2017 18:35
cuz on that case... this is refering to the global context (window :point_right: global scope)
and there are no _name declared on global scope
John
@AnonymousLords
Jul 16 2017 18:35
Guys why wont my code work?

// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  myObj.hasOwnProperty(checkProp);
  return checkProp;
} if (checkProp == false)
  return "Not Found";
kumquatfelafel
@kumquatfelafel
Jul 16 2017 18:36
@Rakesh18754 https://repl.it/J4T2
Ronique Ricketts
@RoniqueRicketts
Jul 16 2017 18:37
@Hijerboa seemed kinda too much with the array and all. when you could fire that function as soon as you type a letter.
RakeshNerkar
@Rakesh18754
Jul 16 2017 18:37
@moigithub @moigithub
var Person = {
  _name: "jade",
  getName:function(){

    console.log(this._name);
  }
}
var test = Person.getName;  //but if i change getName to getName() it works
var test = Person.getName();

console.log(test());
John
@AnonymousLords
Jul 16 2017 18:37
...
Nick Cleary
@Hijerboa
Jul 16 2017 18:38
@RoniqueRicketts that seems like it would work.. thank you!
CamperBot
@camperbot
Jul 16 2017 18:38
hijerboa sends brownie points to @roniquericketts :sparkles: :thumbsup: :sparkles:
:cookie: 285 | @roniquericketts |http://www.freecodecamp.com/roniquericketts
Ronique Ricketts
@RoniqueRicketts
Jul 16 2017 18:39
@Hijerboa Just trying to help. http://api.jquery.com/category/events/keyboard-events/ check these out and see if they make it easier to use these jQuery events.
Moisés Man
@moigithub
Jul 16 2017 18:39
if i recall there are some explanation about this on
You dont know JS book @Rakesh18754
John
@AnonymousLords
Jul 16 2017 18:40
nvm
RakeshNerkar
@Rakesh18754
Jul 16 2017 18:47
@moigithub thanks...nice resource ....can you pls share any more good links to refer?
CamperBot
@camperbot
Jul 16 2017 18:47
rakesh18754 sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3512 | @moigithub |http://www.freecodecamp.com/moigithub
kumquatfelafel
@kumquatfelafel
Jul 16 2017 18:47
@Rakesh18754 If you don't return the name then of course it will print when you call the function, but not when you try to print the result of the function. Since you are returning nothing the result (test), in second case, is undefined.
RakeshNerkar
@Rakesh18754
Jul 16 2017 18:52

@kumquatfelafel @kumquatfelafel
var test = Person.getName; //but if i change getName to getName() it works
var test = Person.getName();

i think wihtout () it should also work rt?

pls correct me if i am wrong.

Moisés Man
@moigithub
Jul 16 2017 18:52

when u do

var Person = {
  _name: "jade",
  getName:function(){
    console.log(this._name);
  }
}

Person.getName();

this will be refered to the left side of the dot soo on this case Person
and Person have a property named _name hence it will print "jade"

but when u make a reference to the function
test = Person.getName;
(is like extracting that function outside)

test = function(){
   console.log(this._name)
}

this context changes <--- pointing to the global window object

test() will print undefined
soo if u do
window._name = "booo" // or var _name = "booo" (same thing) (outside any function)
calling test() will output "booo"
catapulto
@catapulto
Jul 16 2017 18:56
hey help me guyz
Nick Cleary
@Hijerboa
Jul 16 2017 19:00
@catapulto what appears to be the issue?
Joseph
@revisualize
Jul 16 2017 19:02
4hrs left: Building Machine Learning Systems with Python
https://www.packtpub.com/packt/offers/free-learning
catapulto
@catapulto
Jul 16 2017 19:05
@Hijerboa how to code when high?
Nick Cleary
@Hijerboa
Jul 16 2017 19:06
@catapulto generally I find the best method to be to sit in front of the computer and start pressing the keys on the keyboard which correlate with what you want to write. I've also found that turning your computer on is very helpful
catapulto
@catapulto
Jul 16 2017 19:07
actually @Hijerboa i want creative results but it flips back
it doesnot let me work
Nick Cleary
@Hijerboa
Jul 16 2017 19:08
@catapulto maybe wait until you're not high....
catapulto
@catapulto
Jul 16 2017 19:10
actaully i dont know difference between sativa and his other partner
@Hijerboa
Nick Cleary
@Hijerboa
Jul 16 2017 19:14
@catapulto ???
Bradley Sands
@sandsbe
Jul 16 2017 19:28
Can someone direct me to how I can find out what all the possible "weather conditions" are? https://openweathermap.org/current. I'm reading these documents and can't find a list.
Damn
Thanks @jtan3
CamperBot
@camperbot
Jul 16 2017 19:31
sandsbe sends brownie points to @jtan3 :sparkles: :thumbsup: :sparkles:
:cookie: 442 | @jtan3 |http://www.freecodecamp.com/jtan3
LiciniusRex
@hashtagyolo1
Jul 16 2017 19:35
evening all
having some trouble on the Title Case challenge

https://codepen.io/LiciniusRex/pen/QgYdXG

I've gotten this far, but can't work out why I'm no longer getting a response

from console.log
Joseph
@revisualize
Jul 16 2017 19:37
@hashtagyolo1 have you tried.. www.pythontutor.com/javascript.html
@hashtagyolo1 because: TypeError: theArray.charAt is not a function
Stephen James
@sjames1958gm
Jul 16 2017 19:38
@hashtagyolo1 arrays don't have a replace function, so it probably errors out
Or as @revisualize says it tries charAt first which is also a string (not array) functoin
Joseph
@revisualize
Jul 16 2017 19:38
@hashtagyolo1 It also tells you that in the dev console.
LiciniusRex
@hashtagyolo1
Jul 16 2017 19:39
thanks @revisualize and @sjames1958gm . I'll work it from there
CamperBot
@camperbot
Jul 16 2017 19:39
hashtagyolo1 sends brownie points to @revisualize and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8081 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
:star2: 4352 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Jul 16 2017 19:39
image.png
Stephen James
@sjames1958gm
Jul 16 2017 19:39
@hashtagyolo1 :+1:
LiciniusRex
@hashtagyolo1
Jul 16 2017 19:41
@revisualize that link is amazing, thank you so much
CamperBot
@camperbot
Jul 16 2017 19:41
hashtagyolo1 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:warning: hashtagyolo1 already gave revisualize points
Lucci Paula
@luccipaula
Jul 16 2017 19:42
Hi everyone! I'm still quite confused about using APIs while working on the Weather App. How do I find my API key to use Dark Sky??
cowCrazy
@cowCrazy
Jul 16 2017 19:43
you need to sign up for dark-sky then they give you an api key
Lucci Paula
@luccipaula
Jul 16 2017 19:44
@cowCrazy Oh that makes sense, thanks!
CamperBot
@camperbot
Jul 16 2017 19:44
caixeta-paula sends brownie points to @cowcrazy :sparkles: :thumbsup: :sparkles:
:cookie: 267 | @cowcrazy |http://www.freecodecamp.com/cowcrazy
cowCrazy
@cowCrazy
Jul 16 2017 19:45
@caixeta-paula good luck :)
Joseph
@revisualize
Jul 16 2017 19:45
@caixeta-paula there's also some rules when using the Darksky API key that you need to follow.
Lucci Paula
@luccipaula
Jul 16 2017 19:46
@revisualize Where can I find those?
Joseph
@revisualize
Jul 16 2017 19:46
@caixeta-paula I t hink it is during the signup process.
cowCrazy
@cowCrazy
Jul 16 2017 19:46
@caixeta-paula you have it all there.... start with some console.log() and you will get there
Joseph
@revisualize
Jul 16 2017 19:46
@caixeta-paula API Key
If your application for access to the Service is approved, Dark Sky will provide you with an API Key which will enable you to access the Service. Your API Key is to be kept confidential and is not to be published or otherwise made accessible to the general public. If you become aware of any unauthorized use of your API Key, you agree to reset its API Key immediately. Dark Sky may unilaterally reset your API Key if it notices unauthorized use.
cowCrazy
@cowCrazy
Jul 16 2017 19:48
@caixeta-paula you can always ask question.... but after we give yo the answer the chance to think for yourself is gone :worried:
Lucci Paula
@luccipaula
Jul 16 2017 19:49
@revisualize So if I want to link to my project to get feedback later, I have to reset the API key afterwards every time?
Joseph
@revisualize
Jul 16 2017 19:50
@caixeta-paula just if you think it is being used by someone else.
@caixeta-paula or find a way to encrypt your key.
@caixeta-paula maybe rot13 it
Lucci Paula
@luccipaula
Jul 16 2017 19:51
@revisualize I see, thanks for the tips. This API stuff is kind of overwhelming me, haha.
CamperBot
@camperbot
Jul 16 2017 19:51
caixeta-paula sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4353 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Jul 16 2017 19:51
because that's like super secure. LOL.
@caixeta-paula API's shouldn't be overwhelming.
@caixeta-paula Think... How do you get information from someone else?
@caixeta-paula You ask for it.
@caixeta-paula An API is just a way for you (your app) to ask for (or be supplied) information in a manner that the person supplying the information requests.
Lucci Paula
@luccipaula
Jul 16 2017 19:54
@revisualize Very true
Christopher Blakely
@chrisbchrist
Jul 16 2017 19:59
Trying to implement a search function for my twitch viewer that gets data through 2 chained functions getUserInfo/getStream, which creates a div with a dynamic id of the username, but I can't seem to make my search function add the "results" class to my newly created div, I think there's an issue with the order of the api calls maybe?
https://codepen.io/extrachrisb/pen/VWxXbz/
It will create the div with the correct ID but I cannot access it afterwards
korzo
@korzo
Jul 16 2017 20:17
@chrisbchrist User added from search has no online/offline class
@chrisbchrist Also when you call $(id).addClass("result"); user is not yet in DOM, because getUserInfo is asynchronous
Stephen James
@sjames1958gm
Jul 16 2017 20:25
@chrisbchrist If the user if offline, the default visibility is display: none, so it doesn't show until you click offline again to change that.
The added user from search had the offline class just fine
Christopher Blakely
@chrisbchrist
Jul 16 2017 20:26
@korzo I guess I should have realized that's what the A in ajax stands for. I tried setting async to false
Stephen James
@sjames1958gm
Jul 16 2017 20:26
Changing async to false it just learning a bad habit.
Christopher Blakely
@chrisbchrist
Jul 16 2017 20:27
@sjames1958gm Oh no the search shows up properly, I haven't even handled the display settings yet because I cannot get the function to add the "results" class to the div so I can manipulate it
would using a json request in place of an ajax call work?
korzo
@korzo
Jul 16 2017 20:27
@chrisbchrist You should separate logic from presentation
Stephen James
@sjames1958gm
Jul 16 2017 20:28
getJSON is just ajax wrapped with code that assumes json.
korzo
@korzo
Jul 16 2017 20:29
@sjames1958gm No getJSON is also async. It's shortcut for $.ajax
Christopher Blakely
@chrisbchrist
Jul 16 2017 20:29
@korzo I know, I append html directly in the js which i realized is not optimal, but i need some way to refer to the generated div to edit its display with jquery
Stephen James
@sjames1958gm
Jul 16 2017 20:29
@chrisbchrist When you insert the element, you could check the current filter setting and do hide/show
Christopher Blakely
@chrisbchrist
Jul 16 2017 20:30
@sjames1958gm But I want ONLY that new searched user's div to display
not all online users. I also need to clear that div specifically later in the event of a new search and use it to check for duplicate users
slertka
@slertka
Jul 16 2017 20:31
Can anyone take a look at my code for the Wikipedia Viewer? I am alllllllmost happy with basic code but when I search and return the results, I am getting 'undefined' before the first search result html and I can't figure out why! Here's a link to my pen: https://codepen.io/slertka/pen/qjveOK?editors=0010
Stephen James
@sjames1958gm
Jul 16 2017 20:31
@slertka Are you appending to a string that hasn't been initialized?
slertka
@slertka
Jul 16 2017 20:32
@sjames1958gm oooo i didn't even think of that
@sjames1958gm lol that was it. thank you!!!
CamperBot
@camperbot
Jul 16 2017 20:32
slertka sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8082 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 16 2017 20:33
@camperbot :+1: That's the first thing I think of when undefined ends up in a display
korzo
@korzo
Jul 16 2017 20:34

@chrisbchrist it would be much easier to toggle classes on #displayBox
like

#displayBox.online .offline {
    display:none;
}

instead iterating trough all all elements

@chrisbchrist Then you can add class searchResult to result of search and add searchResult class to #displayBox
#displayBox.searchResult > div {
    display:none;
}

#displayBox.searchResult > div.searchResult {
    display: block;
}
Christopher Blakely
@chrisbchrist
Jul 16 2017 20:38
@korzo That is a good work around, I need to google that selector syntax, thank you
CamperBot
@camperbot
Jul 16 2017 20:38
chrisbchrist sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 260 | @korzo |http://www.freecodecamp.com/korzo
Christopher Blakely
@chrisbchrist
Jul 16 2017 20:40
@korzo Although I am still confused how to add searchResult only to the result to begin with
Is there a way to select it by being the newest div, I guess I could select it as a child of displayBox
korzo
@korzo
Jul 16 2017 20:43
@chrisbchrist In search function at the end you can add
$('#displayBox').removeClass('online offline).addClass('searchresult');
Christopher Blakely
@chrisbchrist
Jul 16 2017 20:45
@korzo Will that apply automatically to all the usercard child divs?
korzo
@korzo
Jul 16 2017 20:49

@chrisbchrist no. it will change class on wrapper of all divs with id displayBox.
you can then show/hide divs with CSS
If you want to do it jQuery way, then you must first hide all divs $('#displayBox > div').hide()
and then show only divs with result class

But CSS way it's easier and faster

Saikat-Sinha
@Saikat-Sinha
Jul 16 2017 20:55
anyone with Angular 1 background??Need some help!!
Michiel
@MichielHuijse
Jul 16 2017 21:01
Hi , whats wrong with my sum maker?
function sumAll(arr) {
   var min = Math.min.apply(null, arr);
  var max = Math.max.apply(null, arr);
var sum;
var i;
    for (i = min; i <= max; i++) {
      let sum;
      let currentNum;
      if (currentNum == false) {
        currentNum = min;
      }
      else {

      currentNum = currentNum + i;
      sum = sum + currentNum;
      console.log(sum);
      console.log(currentNum);
      }
    }

  return sum;
}

sumAll([1, 4]);
Moisés Man
@moigithub
Jul 16 2017 21:03
when u create/declare a variable initial value is undefined
also probably u should move ur var declarations outside the loop
Stephen James
@sjames1958gm
Jul 16 2017 21:03
@MichielHuijse your sum inside the loop (because of let) might hide the outer sum
Michiel
@MichielHuijse
Jul 16 2017 21:04
@sjames1958gm thanks again :clap:
CamperBot
@camperbot
Jul 16 2017 21:04
michielhuijse sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8083 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 16 2017 21:05
@MichielHuijse @moigithub is also correct undefined + number currentNum -> NaN
Moisés Man
@moigithub
Jul 16 2017 21:06
most probably u NO need that currentNum variable at all...
but initialize sum to 0
Michiel
@MichielHuijse
Jul 16 2017 21:07
@moigithub hmm ok, so, it is necesairy to declare sum with a value of null
Aaah, ok, that's why i got the nan error.... thanks @moigithub
CamperBot
@camperbot
Jul 16 2017 21:10
michielhuijse sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3513 | @moigithub |http://www.freecodecamp.com/moigithub
Bradley Sands
@sandsbe
Jul 16 2017 21:11
@MichielHuijse Did you get it to work? Why were you going with the min, max?
Michiel
@MichielHuijse
Jul 16 2017 21:11
Yes it works now:
function sumAll(arr) {
   var min = Math.min.apply(null, arr);
  var max = Math.max.apply(null, arr);
var sum = 0;
var i;
    for (i = min; i <= max; i++) {

      sum = sum + i;
      console.log(sum);

    }

  return sum;
}

sumAll([1, 4]);
Bradley Sands
@sandsbe
Jul 16 2017 21:12
nice
Christopher Blakely
@chrisbchrist
Jul 16 2017 21:27
@korzo The issue is I cannot assign the result class to the newly created div from the search , I cannot select it within the search function because the getUserInfo function is asynchronous
I may just make 2 new api calls specifically for the search function
korzo
@korzo
Jul 16 2017 21:33
@chrisbchrist Yeah, you should separate logic from presentation/rendering.
Your only chance at this point is to either pass some flag to getUserInfo to add class result or list for changes in DOM https://developers.google.com/web/updates/2012/02/Detect-DOM-changes-with-Mutation-Observers
@chrisbchrist Like at the end of search function, add listener and on event add result class and remove listener
Alexandru Marian
@marinik17
Jul 16 2017 21:36
@forkerino
Theo Spielman
@tls11
Jul 16 2017 22:07
hello
I’m trying to do the caesar cypher and my code makes sense to me ;-P but it’s not working. Can someone take a look?
function rot13(str) { 
  var decoded = "";
  var exceptions = [32, 33, 34, 46, 63];  // [space, !, ", ., ?]
  for (var index = 0; index < str.length; index++) {
    var temp = str.charCodeAt(index);
    if (exceptions.includes(temp)) {
      decoded += String.fromCharCode(temp);
    } else {
    decoded += String.fromCharCode(temp - 13);
    }
  }
  return decoded;
}
Luis Felipe López G.
@luishendrix92
Jul 16 2017 22:08
I'm just gonna say one thing, well, 2
first, I don't think the exceptions array will work
it'd be easier to just target letters
rather than target "not a subset of ASCII"
also
you need to do a bit of math with the charCode
if the letter is beyond M, it means you'll subtract 13, if not, you add 13
Theo Spielman
@tls11
Jul 16 2017 22:10
luis you are a god damned genius
didn’t catch that
Stephen James
@sjames1958gm
Jul 16 2017 22:18
@tdump You could use a regex on str[i] /[A-M]/.test(str[i])
Theo Spielman
@tls11
Jul 16 2017 22:42
@sjames1958gm thanks man! I got it working, but I’ll keep that in mind when I come across something like that again.
CamperBot
@camperbot
Jul 16 2017 22:42
tdump sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8085 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 16 2017 22:45
@tdump :+1:
NicholasGalarza
@NicholasGalarza
Jul 16 2017 23:05
If anyone is currently working on the Twitch API, is their API currently off service?
Nevermind, their API is currently offline. Gahhhh
CallMeOrange
@EgnaroDev
Jul 16 2017 23:13
@NicholasGalarza Its not, I'm working on twitch.tv
NicholasGalarza
@NicholasGalarza
Jul 16 2017 23:13
@MCTwoDigitZero Its not down you mean? :o:
CallMeOrange
@EgnaroDev
Jul 16 2017 23:14
Did you check this out? https://wind-bow.glitch.me
Yeah its not down
NicholasGalarza
@NicholasGalarza
Jul 16 2017 23:14
@MCTwoDigitZero Yes, I'm using that.
@MCTwoDigitZero Just yesterday it was working completely fine. I didn't change anything.
And I checked out a website that checks out the status of Twitch.tv and it says that their web server for their API is offline.
CallMeOrange
@EgnaroDev
Jul 16 2017 23:15
hm... Did you have some libraries added? e.g. jQuery
really?
NicholasGalarza
@NicholasGalarza
Jul 16 2017 23:15
Yes, I'm using jquery.
Ye
Yes
NicholasGalarza
@NicholasGalarza
Jul 16 2017 23:15
this is what I'm using
CallMeOrange
@EgnaroDev
Jul 16 2017 23:16
Strange
I think you are right
NicholasGalarza
@NicholasGalarza
Jul 16 2017 23:16
I'm not going crazy right? lol
CallMeOrange
@EgnaroDev
Jul 16 2017 23:16
Some of them are not supposed to be Account Closed
NicholasGalarza
@NicholasGalarza
Jul 16 2017 23:16
Yeah, its odd
I noticed that too.
I'm like summit is definitely not closed xD
CallMeOrange
@EgnaroDev
Jul 16 2017 23:16
lol
Saif Ur Rahman
@saifsmailbox98
Jul 16 2017 23:17
Looks down to me, don't know whether it's the glitch app or the twitch api.
NicholasGalarza
@NicholasGalarza
Jul 16 2017 23:18
I'm very certain its their API bc my issues only came about today.
CallMeOrange
@EgnaroDev
Jul 16 2017 23:18
That is Sky's project, He used wind-bow.glitch.me like me
I thought I did something wrong , but for me its not loading
NicholasGalarza
@NicholasGalarza
Jul 16 2017 23:18
@MCTwoDigitZero Ohhh I thought that was yours xD
CallMeOrange
@EgnaroDev
Jul 16 2017 23:18
lol no way
These amazing designs
NicholasGalarza
@NicholasGalarza
Jul 16 2017 23:19
@MCTwoDigitZero Yeah, each time I come across a person on gitter with crazy awesome designs skills I just hit follow right away for inspiraition xD
CallMeOrange
@EgnaroDev
Jul 16 2017 23:20
lol
NicholasGalarza
@NicholasGalarza
Jul 16 2017 23:20
In place of my GET requests, I'm just getting objects like these:
{error: "Bad Request", status: 400, message: "Invalid client id specified"}
CallMeOrange
@EgnaroDev
Jul 16 2017 23:20
Show me your url
just url
NicholasGalarza
@NicholasGalarza
Jul 16 2017 23:21
function validateUser(streamerName) {
      let url = "https://wind-bow.glitch.me/twitch-api/channels/" + streamerName;
      $.ajax({
        type: 'GET',
        //dataType: 'jsonp', 
        url: url,
        success: function(data) {
          console.log("IT WORKED", data);
          getOfflineStreamerInformation(data);
        },
        error: function (failure) {
          let error = JSON.parse(failure.responseText);
          error.name = streamerName;
          console.log("ERROR", error);
          // returns error, message, status, and name.
        }
      });
    }
CallMeOrange
@EgnaroDev
Jul 16 2017 23:22
What does streamerName look like?
A list of players?
NicholasGalarza
@NicholasGalarza
Jul 16 2017 23:22
"freecodecamp"
CallMeOrange
@EgnaroDev
Jul 16 2017 23:22
Hm.. Not sure, I dont know $.ajax() :/
Saif Ur Rahman
@saifsmailbox98
Jul 16 2017 23:23
@NicholasGalarza Thats totally fine as you are getting those error as the JSON.
NicholasGalarza
@NicholasGalarza
Jul 16 2017 23:24
@saifsmailbox98 Yeah, I just wanted to know if its some crazy error with I alone. But if other people's twitch apps I'm failing then I'm okay xD. Just gotta wait for the api to comeback up on Twitch's end.
according to this site: their API is down.
https://twitchstatus.com/
Nick Cleary
@Hijerboa
Jul 16 2017 23:25
does the wikipedia viewer project require the use of a proxy server? because my api requests are getting denied
NicholasGalarza
@NicholasGalarza
Jul 16 2017 23:25
@Hijerboa You are probably running into CORS issues.
CallMeOrange
@EgnaroDev
Jul 16 2017 23:25
@Hijerboa Show us your pen
Nick Cleary
@Hijerboa
Jul 16 2017 23:25
@MCTwoDigitZero currently im routing it through a proxy but i hit a limit
but here it is :/
NicholasGalarza
@NicholasGalarza
Jul 16 2017 23:26
Ohhhh that workaround lol
Nick Cleary
@Hijerboa
Jul 16 2017 23:26
@NicholasGalarza unfortunatly i hit a limit. Is there any other way i can do it?
NicholasGalarza
@NicholasGalarza
Jul 16 2017 23:27
I'm going to play around with your code really quickly and see if I can get it to work.
Nick Cleary
@Hijerboa
Jul 16 2017 23:27
ok thanks mate
Saif Ur Rahman
@saifsmailbox98
Jul 16 2017 23:27
Saif Ur Rahman
@saifsmailbox98
Jul 16 2017 23:28
idk
:confused:
NicholasGalarza
@NicholasGalarza
Jul 16 2017 23:29
@MCTwoDigitZero I'm getting: {"error":"Bad Request","status":400,"message":"Invalid client id specified"}
@saifsmailbox98 I'm getting:
{"display_name":"OgamingSC2","_id":71852806,"name":"ogamingsc2","type":"user","bio":null,"created_at":"2014-09-24T15:06:58Z","updated_at":"2017-07-16T21:35:42Z","logo":"https://static-cdn.jtvnw.net/jtv_user_pictures/ogamingsc2-profile_image-9021dccf9399929e-300x300.jpeg","_links":{"self":"https://api.twitch.tv/kraken/users/ogamingsc2"}}
CallMeOrange
@EgnaroDev
Jul 16 2017 23:30
Hm that looks fine
It seems they are not down
korzo
@korzo
Jul 16 2017 23:30
@NicholasGalarza I think twitch api is down
CallMeOrange
@EgnaroDev
Jul 16 2017 23:31
:o
what about that link?
Saif Ur Rahman
@saifsmailbox98
Jul 16 2017 23:31
korzo
@korzo
Jul 16 2017 23:31
@MCTwoDigitZero https://twitchstatus.com/
NicholasGalarza
@NicholasGalarza
Jul 16 2017 23:32
@korzo Yes, I think so too
CallMeOrange
@EgnaroDev
Jul 16 2017 23:32
Huh looks like its back
API.Twitch.TV Twitch's external endpoint for data retrieval Online 290 ms
NicholasGalarza
@NicholasGalarza
Jul 16 2017 23:32
Woooo! it came back up!
Stephen James
@sjames1958gm
Jul 16 2017 23:32
@Hijerboa You don't need a proxy, use origin=* and Wikipedia will supply the correct headers
Christopher Blakely
@chrisbchrist
Jul 16 2017 23:34
Mine is now only working for the first 2 users in the list.
NicholasGalarza
@NicholasGalarza
Jul 16 2017 23:35
yeah, mines is failing again. I celebrated too early.
korzo
@korzo
Jul 16 2017 23:37
@NicholasGalarza It's up and down last half and hour.
NicholasGalarza
@NicholasGalarza
Jul 16 2017 23:38
@korzo yeah, I'm going to wait till tomorrow to work on this project lol.
@korzo Actually, if you make a GET request using twitch's native API and using a key. it actually works so now I'm switching from the wind-bow workaround to my own key.
Nick Cleary
@Hijerboa
Jul 16 2017 23:45
@sjames1958gm thank you!
CamperBot
@camperbot
Jul 16 2017 23:45
hijerboa sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8086 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 16 2017 23:45
@Hijerboa you're welcome
Pagnito
@Pagnito
Jul 16 2017 23:48
anyone familiar with webpack and react environment?
Kevin
@kevinwr
Jul 16 2017 23:51
Can someone please tell me what is wrong with my JS? I'm trying to make an AJAX call to wikipedia, but I keep getting a response of 0, telling me that my call hasn't been initialized.
// Checks to see if browser can handle XHR requests directly, or if it uses older ActiveX technology, and creates a new
//XHR object based on this information.
if (window.XMLHttpRequest) {
    // For modern browser: Chrome, Firefox, etc...
    window.XHR = new XMLHttpRequest();
} else if (window.ActiveXObject) {
    //For older IE browsers
    window.XHR = new ActiveXObject("Microsoft.XMLHTTP");
}


//Actions to be completed when the search form is submitted
document.getElementById("wikiSearchForm").onsubmit = function () {

    //Sets the users search query to userQuery variable.
    var userQuery = document.getElementById("searchInput").value;

    //Replaces the spaces from userQuery with %20 to make sure it will be valid URL syntax
    userQuery = userQuery.replace(" ", "%20");

    //Sets the Wiki API request url by using the input text the user types into the form input.
    window.wikiURL = "https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=" + userQuery;

    //Call getJSON to get wiki api json data
    getJSON();

};


//This function runs an XHR request to the wikipedia API
function getJSON () {
    XHR.open("GET", wikiURL, true);
    XHR.send();
}


//This function runs when the XHR readyState value changes.
XHR.onreadystatechange = function(){
    if (XHR.readyState === 4 && XHR.status === 200) {
        alert(XHR.responseXML);
    } else {
        alert("Something went wrong. Please try again later");
    }
}
and I've checked, and the URL being produced gives me a link that returns data from Wikipedia
so I know the URL isn't the issue
Stephen James
@sjames1958gm
Jul 16 2017 23:55
@kevinwr Any errors in the devtools console?
Kevin
@kevinwr
Jul 16 2017 23:55
what's that?
Stephen James
@sjames1958gm
Jul 16 2017 23:56
@kevinwr The browser console. On windows chrome you get there by F12
@kevinwr It is where the browser shows any errors it encounters
Kevin
@kevinwr
Jul 16 2017 23:56
how do I know if there are errors? WHere does it show them?
This is what I got in the console:
thirdparty.min.js:13 Less has finished and no sheets were loaded.
/thirdparty/react.js:6541 Download the React DevTools for a better development experience: https://fb.me/react-devtools
/filesystem/FileSystem.js:904 Failed to watch root:  C:/Users/Kevin/Documents/Wikipedia Viewer/ Unknown
/project/ProjectManager.js:757 Error watching project root:  C:/Users/Kevin/Documents/Wikipedia Viewer/ Unknown(anonymous function) @ /project/ProjectManager.js:757
/project/ProjectManager.js:941 error loading project
/command/KeyBindingManager.js:578 Failed to normalize Cmd-Shift-]
/command/KeyBindingManager.js:578 Failed to normalize Cmd-Shift-[
/LiveDevelopment/MultiBrowserImpl/transports/NodeSocketTransport.js:84 NodeSocketTransport - start
NodeDebugUtils.js:114 [node-log 5:22:43 PM] { Error: ENOENT: no such file or directory, stat 'C:\Users\Kevin\Documents\GitHub\kevinwr.github.io\Wikipedia Viewer\index.html'
    at Error (native)
    at Object.fs.statSync (fs.js:987:18)
    at getFilesizeInBytes (C:\Program Files (x86)\Brackets\www\search\node\FindInFilesDomain.js:197:24)
    at getFileContentsForFile (C:\Program Files (x86)\Brackets\www\search\node\FindInFilesDomain.js:216:13)
    at Immediate.fileCrawler (C:\Program Files (x86)\Brackets\www\search\node\FindInFilesDomain.js:350:20)
    at runCallback (timers.js:570:20)
    at tryOnImmediate (timers.js:550:5)
    at processImmediate [as _immediateCallback] (timers.js:529:5)
  errno: -4058,
  code: 'ENOENT',
  syscall: 'stat',
  path: 'C:\\Users\\Kevin\\Documents\\GitHub\\kevinwr.github.io\\Wikipedia Viewer\\index.html' }
NodeDebugUtils.js:114 [node-log 5:22:43 PM] { Error: ENOENT: no such file or directory, open 'C:\Users\Kevin\Documents\GitHub\kevinwr.github.io\Wikipedia Viewer\index.html'
    at Error (native)
    at Object.fs.openSync (fs.js:640:18)
    at Object.fs.readFileSync (fs.js:508:33)
    at getFileContentsForFile (C:\Program Files (x86)\Brackets\www\search\node\FindInFilesDomain.js:217:41)
    at Immediate.fileCrawler (C:\Program Files (x86)\Brackets\www\search\node\FindInFilesDomain.js:350:20)
    at runCallback (timers.js:570:20)
    at tryOnImmediate (timers.js:550:5)
    at processImmediate [as _immediateCallback] (timers.js:529:5)
  errno: -4058,
  code: 'ENOENT',
  syscall: 'open',
  path: 'C:\\Users\\Kevin\\Documents\\GitHub\\kevinwr.github.io\\Wikipedia Viewer\\index.html' }
main.js:76 Object
main.js:76 Object
main.js:76 Object
main.js:76 Object
main.js:76 Object
main.js:76 Object
http://127.0.0.1:9222/json Failed to load resource: net::ERR_CONNECTION_REFUSED
main.js:76 Object
main.js:76 Object
main.js:76 Object
main.js:76 Object
Sorry. I don't know what the crap I'm looking at right now
Stephen James
@sjames1958gm
Jul 16 2017 23:59
@kevinwr You are running this inside of Brackets?
Kevin
@kevinwr
Jul 16 2017 23:59
I see "ERROR WATCHING PROJECT ROOT"
and "FAILED TO OAD RESOURCE ERROR CONNECTION REFUSED"
yeah