These are chat archives for FreeCodeCamp/HelpJavaScript

27th
Jan 2018
Raiden357
@raiden357
Jan 27 2018 04:06
can somebody help me with ES6: Write Higher Order Arrow Functions. The instructions are not clear
Dan Lafferty
@DanLaff
Jan 27 2018 04:33
@raiden357 Don't ask to ask, just ask. What are the instructions?
Fabien SHAN
@X140hu4
Jan 27 2018 08:04
yay finished the JS calculator, onto the pomodoro project!
legendinraze
@legendinraze
Jan 27 2018 08:24
how do I change colors of individual letters?
Aditya
@ezioda004
Jan 27 2018 08:46
@legendinraze In HTML? Maybe use <span> and give each different color property.
rukkho
@rukkho
Jan 27 2018 08:49
Hi guys
Marianissimus
@Marianissimus
Jan 27 2018 08:52
hi
rukkho
@rukkho
Jan 27 2018 08:55
I'm back after a year of delving into the world HTML/CSS . Now that my time I think is ripe for JavaScript, I definitely know you will be there for me. Thanks in anticipation of your support
Marianissimus
@Marianissimus
Jan 27 2018 08:56
Good luck!
HumaDeng
@HumaDeng
Jan 27 2018 09:58

if (typeof arr[0]=="string") {
newArr=arr.join("");
newArr1=[];
newArr2=[];

n = arr.length%size>0?Math.floor(arr.length/size)+1:arr.length/size;

for(var i=0;i<n-1;i++){
for(var j=0;j<size;j++){
newArr1.push(newArr[size*i+j]);
}

newArr2.push(newArr1);
newArr1=[];

}

if(arr.length%size>0){
for ( var m = 0; m < arr.length%size; m++) {
newArr1.push(newArr[size*i+m]);

  newArr2.push(newArr1);
}

}else{
for ( var l = 0; l < size; l++) {
newArr1.push(newArr[size*i+l]);
}
newArr2.push(newArr1);

  return newArr2;

}
}else{

newArr=arr.join("");
newArr1=[];
newArr2=[];

n = arr.length%size>0?Math.floor(arr.length/size)+1:arr.length/size;

for(var i=0;i<n-1;i++){
for(var j=0;j<size;j++){
newArr1.push(parseInt(newArr[size*i+j]));
}

newArr2.push(newArr1);
newArr1=[];

}

if(arr.length%size>0){

  for ( var m = 0; m <  arr.length%size; m++) {

  newArr1.push(parseInt(newArr[size*i+m]));
}

      newArr2.push(newArr1);

}else{

      for ( var l = 0; l <  size; l++) {
  newArr1.push(parseInt(newArr[size*i+l]));

}
newArr2.push(newArr1);

  return newArr2;

}

}
chunk([0, 1, 2, 3, 4, 5], 4);

it works,but do not let me pass

chunk([1,2,3,4],2)=[[1,2],[3,4]];

chunk([1,2,3,4,5],2)=[[1,2],[3,4],[5]];

Fabien SHAN
@X140hu4
Jan 27 2018 10:10
@HumaDeng Link to the problem? can you try editing your message? Put the backticks on separate lines
Saul Page
@saulable
Jan 27 2018 10:21
alright pussies
Long Nguyen
@longnt80
Jan 27 2018 11:18
const ninjas = [
  {name: "Yagyu", weapon: "shuriken"},
  {name: "Yoshi" },
  {name: "Kuma", weapon: "wakizashi"}
];

var allNinjasAreNamed = ninjas.every(ninja => "name" in ninja);
what is this: "name" in ninja?
I understand the code, just don't know what the above is called.
Marianissimus
@Marianissimus
Jan 27 2018 11:41
@longnt80 You have there an array of objects. Each object contains some properties: for instance, in the first one, you have "property-name": name, and value: "Yagyu", then property-name: weapon, and value: shuriken.
Long Nguyen
@longnt80
Jan 27 2018 11:49
@Marianissimus just tell me what this name" in ninja called
I know for in
Pieter Stokkink
@forkerino
Jan 27 2018 12:22
@longnt80 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/in basically for ... in uses this too to iterate over the properties.
Stephen James
@sjames1958gm
Jan 27 2018 12:25
@longnt80 The in operator returns true if the specified property is in the specified object or its prototype chain.
@longnt80 Similar to hasOwnProperty, but not limited to the object itself
Long Nguyen
@longnt80
Jan 27 2018 12:27
yeah, I just checked, similar to hasOwnProperty
thank you
@Marianissimus @forkerino @sjames1958gm
CamperBot
@camperbot
Jan 27 2018 12:27
longnt80 sends brownie points to @marianissimus and @forkerino and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:cookie: 457 | @marianissimus |http://www.freecodecamp.org/marianissimus
:star2: 8905 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
:star2: 2976 | @forkerino |http://www.freecodecamp.org/forkerino
omgallen
@omgallen
Jan 27 2018 14:03

function bouncer(arr) {

var newarr = [];

var truearr = [];
for (var i = 0; i < arr.length; i++) {
if (Boolean(arr[i]) === true) {
newarr[i] = arr[i];
}
else
newarr[i] = false;
}

truearr = newarr.filter(function(val) {
return val !== false;
});

}

bouncer([7, "ate", "", false, 9]);

Hi Guys, would you please help with this? I really don't know how to do it. I think the code should be ok
I mean ,the newarr should be [7, "ate", false, false, 9]
when I use filter to filter the false, it didn't work
omgallen
@omgallen
Jan 27 2018 14:22
I check the right answer, holy...
Stephen James
@sjames1958gm
Jan 27 2018 15:16
@omgallen because filter coerces the return of the function to boolean, simply returning the value will filter out falsy values.
you also have to remember to return the result of filter from your function
This is a short version, without using the Boolean function which is even shorter.
return arr.filter(function(val) { return val; });
FlashHero
@FlashHero
Jan 27 2018 15:25
Is reactjs for building part of a website or the whole website and can you replace back-end with react-router
Zunaid Aslam
@ZunaidAslam
Jan 27 2018 15:33

Hello guys,

I was doing beginner algorithm challenge and for factorizing 5, I used the code

function factorialize(num) {

// Only change code below this line

var myArray = [];
var sinArray = 0;

for (var i=num; i>0; i--) {

myArray.push(i);

sinArray =  myArray.reduce(function(a,b) {

return a*b;} );

}
num = sinArray;
return num;
}

factorialize(5);

It worked in factorizing all the numbers except when it came to factorizing 0, it didn't work and so i just change the value of var sinArray = 1 just to test. It worked.

In short I didn't understand how it worked.

The logic I used is first I made an emptry array and pushed each number their starting from 5 to 1. Then used reduce option to reduce the array by multiplying and putting the value in num and returning it.

Hello guys,

I was doing beginner algorithm challenge and for factorizing 5, I used the code

function factorialize(num) {

// Only change code below this line

var myArray = [];
var sinArray = 0;

for (var i=num; i>0; i--) {

myArray.push(i);

sinArray =  myArray.reduce(function(a,b) {

return a*b;} );

}
num = sinArray;
return num;
}

factorialize(5);

It worked in factorizing all the numbers except when it came to factorizing 0, it didn't work and so i just change the value of var sinArray = 1 just to test. It worked.

In short I didn't understand how it worked.

The logic I used is first I made an emptry array and pushed each number their starting from 5 to 1. Then used reduce option to reduce the array by multiplying and putting the value in num and returning it.

Sorry I posted twice by mistake
Aditya
@ezioda004
Jan 27 2018 15:40
@Zunaid-Aslam It doesnt work because the for loop never runs for 0, i > 0 is false.
Aditya
@ezioda004
Jan 27 2018 15:47
A side note, you're overwriting sinArrayevery iteration, so might as well have the reduce() outside the loop.
Pieter Stokkink
@forkerino
Jan 27 2018 15:48
@FlashHero it is only for the front end. The router is just for frontend routing, you will still need to fetch stuff from a backend and post it there to make anything non-static.
FlashHero
@FlashHero
Jan 27 2018 15:58
@forkerino oh ok thanks
CamperBot
@camperbot
Jan 27 2018 15:58
flashhero sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2977 | @forkerino |http://www.freecodecamp.org/forkerino
FlashHero
@FlashHero
Jan 27 2018 16:05
When you have a todo application made using reactjs, doesn't it take more time to render than normal JavaScript because you can't modify the state so you have to make a copy and delete or add and update and you have to map over it again every time the state changes, so isn't that taking more time than JavaScript appending nodes
May Kittens Devour Your Soul
@diomed
Jan 27 2018 16:12
dom dom dom dom...
Stephen James
@sjames1958gm
Jan 27 2018 16:44
@FlashHero react maintains its own virtual DOM that is very efficient at updating and updating the real DOM
Sweet Coding :)
@SweetCodingInc
Jan 27 2018 16:56
@FlashHero : Theoretically, you're correct. However, react has a very efficient algorithm to identify only the changed nodes. And it updates ONLY the changed nodes. Yes, there is a slight perf lag on the first page load, but after that, it is way more efficient as compared to how you'd normally update the DOM
FlashHero
@FlashHero
Jan 27 2018 16:59
@sjames1958gm @SweetCodingInc thanks
CamperBot
@camperbot
Jan 27 2018 16:59
flashhero sends brownie points to @sjames1958gm and @sweetcodinginc :sparkles: :thumbsup: :sparkles:
:cookie: 212 | @sweetcodinginc |http://www.freecodecamp.org/sweetcodinginc
:star2: 8907 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
Tiago Correia
@tiagocorreiaalmeida
Jan 27 2018 19:14
@cmccormack hey around mate?
alpox
@alpox
Jan 27 2018 19:17
@tiagocorreiaalmeida :wave:
Tiago Correia
@tiagocorreiaalmeida
Jan 27 2018 19:17
hey @alpox !! :D
alpox
@alpox
Jan 27 2018 19:18
:D hio
Tiago Correia
@tiagocorreiaalmeida
Jan 27 2018 19:19
maybe you can save me today :D trying to figure out how im gonna have google auth on the backend workign with react on frontend I think I allready asked you soemthing similiar :D
alpox
@alpox
Jan 27 2018 19:21
There should not be much of a difference to the way you are used to
Tiago Correia
@tiagocorreiaalmeida
Jan 27 2018 19:22
the only thing that gets me confused is that normally it redirects you to another page and after going to that page you will be redirect back to the api route and not the react page I think not sure
Keon Samuel
@keonsam
Jan 27 2018 19:22
I need an angular pro help
alpox
@alpox
Jan 27 2018 19:23
@tiagocorreiaalmeida Instead of the redirect, you can just return the user as json to the frontend - or some other identification that login worked
And in react you can react on that response
Tiago Correia
@tiagocorreiaalmeida
Jan 27 2018 19:24
there's one part that the user has to accept the application premission that's where I get confused just that I guess
alpox
@alpox
Jan 27 2018 19:25
Hmm right didn't think about that, let me take a short look
Tiago Correia
@tiagocorreiaalmeida
Jan 27 2018 19:25
ok cool and thanks @alpox
CamperBot
@camperbot
Jan 27 2018 19:25
tiagocorreiaalmeida sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1528 | @alpox |http://www.freecodecamp.org/alpox
alpox
@alpox
Jan 27 2018 19:26
@tiagocorreiaalmeida I guess there will just be a server route leading to that application permission which you have to route the user to
app.get('/auth/google', passport.authenticate('google', { scope: 'https://www.google.com/m8/feeds' });
Something like this
This is for the feeds now though
The user will just have to be redirected to this, then he will be sent to the google login
I'm actually not perfectly sure how it will work as i've never done this exact thing - as you know i don't use third-party auth
Tiago Correia
@tiagocorreiaalmeida
Jan 27 2018 19:28
yeah :D was just to figure out how this one would work the local strategy seems straight forward so I always like to complicate things :D
alpox
@alpox
Jan 27 2018 19:30
Well i guess you should setup some route like this which the browser directly redirects to (Without axios request)
Then, you get routed to google. The server will then redirect to one of your react pages again
Tiago Correia
@tiagocorreiaalmeida
Jan 27 2018 19:46
but how would I control if the user is authenticated on the api?
alpox
@alpox
Jan 27 2018 19:59
With the method i said before i'm not totally sure. I guess it uses cookies or something like that. But kinda i think you would have to send an access token or something back to react thats why i'm a bit confused about that method. I'm not sure if cookies would be attached to axios requests
Christopher McCormack
@cmccormack
Jan 27 2018 20:06
@tiagocorreiaalmeida I basically check anytime the user needs to do anything that requires auth . I have a api call that checks their authentication status and updates react state based on the response. Is that something like what you're looking for?
Tiago Correia
@tiagocorreiaalmeida
Jan 27 2018 20:32
yeah im doing it allreadt ehhe, was looking at your projects you used local auth, im trying to use things like facebook/twitter/github while using react well I guess I will figure it out quiet soon :D, either way how are you?
Christopher McCormack
@cmccormack
Jan 27 2018 20:36
I don't see why you can't utilize the same method, creating an endpoint that calls the provider's API to check auth status
@tiagocorreiaalmeida Good man still working on my damn voting app, but not spending nearly as much time lately
@tiagocorreiaalmeida yourself?
Tiago Correia
@tiagocorreiaalmeida
Jan 27 2018 21:01
a bit lazy lately, starting to get a bit used to react and now to redux not any master but allready got some stuff stuck in my head :D
Christopher McCormack
@cmccormack
Jan 27 2018 21:09
@tiagocorreiaalmeida that's great :) I'll get around to using redux at some point
Oğuzhan Çelikarslan
@oguzhancelikarslan
Jan 27 2018 21:26
@oguzhancelikarslan
I want to make chat application with chat room. I want to use websocket but without socket io
Any suggestions?
Simon Cordova
@gbsimon87
Jan 27 2018 22:10
Hey there :)
Was wondering if anyone here has experience with Meteor?
aRtoo
@artoodeeto
Jan 27 2018 22:19
hey fam can i get a feedback? appreciate it. thanks.
https://codepen.io/artoo/full/opQZWy/
Onome Sotu
@onomesotu
Jan 27 2018 22:27
The on button is bad
@artoodeeto I don't know if i should slide or click
it turned on by error and i almost gave up
maybe you can make the button bigger or instruction that says click on red button to turn on
Otherwise, every other thing is good
aRtoo
@artoodeeto
Jan 27 2018 22:36
@onomesotu it should alert you if you start the button first. you should slide it bro but yea i can make it bigger.
@onomesotu hey bro are you using you phone?
Onome Sotu
@onomesotu
Jan 27 2018 22:46
@artoodeeto no, I am on pc
@artoodeeto The sliding doesn't work
aRtoo
@artoodeeto
Jan 27 2018 22:46
@onomesotu press the green part bro
i mean the red
Onome Sotu
@onomesotu
Jan 27 2018 22:46
Clicking on the button was what moved it to the current position
of start
aRtoo
@artoodeeto
Jan 27 2018 22:47
what do you mean bro?
Onome Sotu
@onomesotu
Jan 27 2018 22:50
I meant sliding the button from the red stop position to the green start position doesn't work
I could only get it to start by clicking on the button position
So if i wanted to start it i clicked the red button, it slides to the right to show the game is on
aRtoo
@artoodeeto
Jan 27 2018 22:51
@onomesotu because bro its not supposed to slide you just have to click the red square
Onome Sotu
@onomesotu
Jan 27 2018 22:51
oh i see
Alright.. i thought it was meant to slide :)
aRtoo
@artoodeeto
Jan 27 2018 22:51
@onomesotu yup you got it bro. the slide part i dont know to do it yet haha
hahaha me too on the sample game
@onomesotu you playing it right now?
Idowu Wasiu
@Hoxtygen
Jan 27 2018 23:31
hello guys.... i just got hit with a CORS on twitch api given by fcc for the project..... any workaround?
document.addEventListener('DOMContentLoaded', function () {
   var url = 'https://wind-bow.gomix.me/twitch-api/streams/RobotCaleb?callback=?';
  //var url = 'https://api.twitch.tv/kraken/streams/freecodecamp?callback=?'
  var request = new XMLHttpRequest()
  request.open('GET', url, true)
  request.onreadystatechange = function () {
    if (request.readyState === request.DONE && request.status === 200) {
      if (request.responseText) {
        // var stringified = JSON.parse(request.responseText)
        // console.log(stringified)
      } else {
        console.log('Error: cant fetch data from the source')
      }
    }
  }
  request.send()
})
Dan Lafferty
@DanLaff
Jan 27 2018 23:51
@Hoxtygen var url = "https://wind-bow.glitch.me/twitch-api/streams/RobotCaleb";
I visited your URL in the browser and redirected to another domain glitch.me - the CORS is coming from that redirect, so if you update the URL, it will go away
You might want to use fetch() if you can - much simpler:
fetch("https://wind-bow.glitch.me/twitch-api/streams/RobotCaleb")
  .then(res => res.json())
  .then(data => console.log(data));
Idowu Wasiu
@Hoxtygen
Jan 27 2018 23:56
@DanLaff used your url, nothing pops out the console... typed it in the browser i got this
self    "https://api.twitch.tv/kraken/streams/RobotCaleb"
channel    "https://api.twitch.tv/kraken/channels/RobotCaleb"
@DanLaff sorry, got output now... didnt realise the console log has been comment out
surferpilgrim
@surferpilgrim
Jan 27 2018 23:58
does anyone know a native api to chrome,that plays music in the browser