These are chat archives for FreeCodeCamp/HelpJavaScript

23rd
Nov 2017
Ogundele Olumide
@Lumexralph
Nov 23 2017 00:32
@Masd925 hey man! so you still come around ? how're you doing?
AbrisM
@AbrisM
Nov 23 2017 01:00
Hi all
Does anyone know what the "paper" method does in Javascript/html?
It's a CSS function
Mohamed Derhalli
@derhallim
Nov 23 2017 03:20
@JohnnyBizzel @Lumexralph @JLuboff @sjames1958gm thanks ... wassup !!!
CamperBot
@camperbot
Nov 23 2017 03:20
derhallim sends brownie points to @johnnybizzel and @lumexralph and @jluboff and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1769 | @johnnybizzel |http://www.freecodecamp.org/johnnybizzel
:star2: 2060 | @lumexralph |http://www.freecodecamp.org/lumexralph
:star2: 2273 | @jluboff |http://www.freecodecamp.org/jluboff
:star2: 8707 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
Ogundele Olumide
@Lumexralph
Nov 23 2017 04:23
@derhallim hey man, how're you?
Mohamed Derhalli
@derhallim
Nov 23 2017 04:41
gd gd
how's it going?
alpox
@alpox
Nov 23 2017 05:34
@AbrisM Are you sure its not an SCSS mixin?
Markus Kiili
@Masd925
Nov 23 2017 06:35
Morning.
Mohamed Derhalli
@derhallim
Nov 23 2017 06:46
@Masd925 @alpox hi guys, how r u?
Markus Kiili
@Masd925
Nov 23 2017 06:47
@derhallim Waking up. :coffee: How are you?
Mohamed Derhalli
@derhallim
Nov 23 2017 06:47
trying not to wake up
alpox
@alpox
Nov 23 2017 07:18
@derhallim already in lesson. Half asleep
Tiago Correia
@tiagocorreiaalmeida
Nov 23 2017 09:11
gm everyone
alpox
@alpox
Nov 23 2017 09:20
@tiagocorreiaalmeida :wave:
Tiago Correia
@tiagocorreiaalmeida
Nov 23 2017 09:24
how's the lesson going? :D
alpox
@alpox
Nov 23 2017 09:27
@tiagocorreiaalmeida Its over :D i'm now training my neural network
Tiago Correia
@tiagocorreiaalmeida
Nov 23 2017 09:33
sounds interesting and like an headache aswell :D
alpox
@alpox
Nov 23 2017 09:43
@tiagocorreiaalmeida Yeaa its a bit of a headache :D but mostly because i have to wait long for it to finish
I always change some parameters and have to run again :-/
Tiago Correia
@tiagocorreiaalmeida
Nov 23 2017 09:58
python right?
alpox
@alpox
Nov 23 2017 09:58
@tiagocorreiaalmeida Yeah python and scikit-learn
Tensorflow would have at least gpu usage
But we're using scikit-learn and my laptop almost steams :D
Tiago Correia
@tiagocorreiaalmeida
Nov 23 2017 10:02
aahahah place a steak on top of eat, and eat it
alpox
@alpox
Nov 23 2017 10:08
@tiagocorreiaalmeida xD streight on
Tiago Correia
@tiagocorreiaalmeida
Nov 23 2017 10:12
it*
programing and grilling some steak that's profit
alpox
@alpox
Nov 23 2017 10:14
Perfect programmer life
Lean Junio
@leanjunio
Nov 23 2017 13:46
Hey guys, can anybody tell me why my little program isn’t returning anything?
function howManyServings (params) {
  const {recipe, inventory} = params

  for(let key in inventory) {
    if(inventory[key] < recipe[key]) {
      return 0 // doesn't return
    } else {
      return 1 // doesn't return
    }
  }
}

howManyServings({
  recipe: {
    bread: 10,
    peanutButter: 5,
    jam: 5
  },
  inventory: {
    bread: 20,
    peanutButter: 10,
    jam: 5
  }
})
it returns 1
Lean Junio
@leanjunio
Nov 23 2017 13:52
oh okay, that’s weird :/ ni Node it’s not returning anything, thanks tohugh
Diego Mayer
@Chrono79
Nov 23 2017 13:53
:+1:
Stephen James
@sjames1958gm
Nov 23 2017 14:00
I tried in node and it worked - which version?
pocahontas123
@pocahontas123
Nov 23 2017 14:00
Diego Mayer
@Chrono79
Nov 23 2017 14:01
@pocahontas123 what's your question? Do you have any code yet?
Stephen James
@sjames1958gm
Nov 23 2017 14:01
@pocahontas123 You can post your code here: https://forum.freecodecamp.com/t/markdown-code-formatting/18391
Are specific tests failing?
pocahontas123
@pocahontas123
Nov 23 2017 14:01
@Chrono79 Hello, yes my code is done but it doesn't work

function sumFibs( num ) {
//F0= 0; F1= 1; F2= 1; F3= 2; F4= 3; F5= 5; F6= 8; F7= 13;
let array = [ 0, 1, 1 ];

for( let k = 2; k < num; k++ ) {
    array[k+1] = array[k] + array[k-1];
}

return array[num];

};

Stephen James
@sjames1958gm
Nov 23 2017 14:02
I don't see any summing of the numbers esp. only odd values
pocahontas123
@pocahontas123
Nov 23 2017 14:02

```function sumFibs( num ) {
//F0= 0; F1= 1; F2= 1; F3= 2; F4= 3; F5= 5; F6= 8; F7= 13;
let array = [ 0, 1, 1 ];

for( let k = 2; k < num; k++ ) {
    array[k+1] = array[k] + array[k-1];
}

return array[num];

};```

Diego Mayer
@Chrono79
Nov 23 2017 14:02
@pocahontas123 you're getting num fibonacci numbers, not all odd fibonacci numbers less than or equal than num
pocahontas123
@pocahontas123
Nov 23 2017 14:04
@Chrono79 let me think
For exemple lets take console.log( sumFibs( 4 ) );
my result is 3 and their 5
Diego Mayer
@Chrono79
Nov 23 2017 14:05
you return the nth fibonacci number
pocahontas123
@pocahontas123
Nov 23 2017 14:06
what is nth
Diego Mayer
@Chrono79
Nov 23 2017 14:06
you should return the sum of all fibonacci numbers less than or equal than num
pocahontas123
@pocahontas123
Nov 23 2017 14:07
@Chrono79 for( let k = 2; k < num; k++ ) {
array[k+1] = array[k] + array[k-1];
if( array[k+1] >= num ) {
return array[k+1];
}
}
for( let k = 2; k < num; k++ ) {
    array[k+1] = array[k] + array[k-1];
    if( array[k+1] >= num ) {
        return array[k+1];
    }
}
Diego Mayer
@Chrono79
Nov 23 2017 14:07
fibExample = [0,1,1,2,3,5];
// you returned the 4th element of the array (arrays are zero indexed), the 4th element is 3 there
Stephen James
@sjames1958gm
Nov 23 2017 14:07
sumFibs(4) - should result in fibs of 0, 1, 1, 2, 3 -> then the odd ones are 1, 1, 3 which sum to 5
pocahontas123
@pocahontas123
Nov 23 2017 14:08
I have to sum up every finobachi number before my num ?
Stephen James
@sjames1958gm
Nov 23 2017 14:08
@pocahontas123 You cannot return until you have summed the odd values.
You can change your for loop test
Well the odd ones
Diego Mayer
@Chrono79
Nov 23 2017 14:09
Your function calculates more Fibonacci number than needed, fix that first
Then add only the odd ones that are less than or equal to num
pocahontas123
@pocahontas123
Nov 23 2017 14:10
ok, gonna try it out :/
Stephen James
@sjames1958gm
Nov 23 2017 14:10
@pocahontas123 :+1: you are on the right track
pocahontas123
@pocahontas123
Nov 23 2017 14:33
i still don't understand
@sjames1958gm Can i have the numbers that give me 1785 for fibonacci(1000)
So i can figure it out how this number is done
Stephen James
@sjames1958gm
Nov 23 2017 14:40
@pocahontas123 1 + 1 + 3 + 5 + 13 + 21 + 55 + 89 + 233 + 377 + 987
pocahontas123
@pocahontas123
Nov 23 2017 14:40
But
let me calcul
Diego Mayer
@Chrono79
Nov 23 2017 14:46
@pocahontas123
for( let k = 2; k < num; k++ ) { // k < num will get you 1000 fibonacci numbers when num is 1000
    array[k+1] = array[k] + array[k-1];
}
pocahontas123
@pocahontas123
Nov 23 2017 14:46
Re, i'm trying out some thing
i come back when it's done :)
Diego Mayer
@Chrono79
Nov 23 2017 14:47
good luck :+1:
pocahontas123
@pocahontas123
Nov 23 2017 14:57
I have some thing different i noticed
i have [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987]
the 610
Why you didn't count this one?
Stephen James
@sjames1958gm
Nov 23 2017 15:01
@pocahontas123 even
sum only the odd ones
sometimes good to re-read the instructions carefully to ensure you didn't miss something.
Diego Mayer
@Chrono79
Nov 23 2017 15:04
@pocahontas123 you have to discard the even numbers there, not only 610, also 2, 8, 34 and 144
pocahontas123
@pocahontas123
Nov 23 2017 15:10
English is not my native language, i'm look what "odd ones mean"
Well, i still don't understand why they are odd numbers/even numbers
Diego Mayer
@Chrono79
Nov 23 2017 15:11
@pocahontas123 odd, numbers that aren't exactly divided by 2
pocahontas123
@pocahontas123
Nov 23 2017 15:11
they are not different from the others :/
ah
Diego Mayer
@Chrono79
Nov 23 2017 15:12
1, 3, 5
and so on
pocahontas123
@pocahontas123
Nov 23 2017 15:12
pfff ok
Ok, it's working now xD
@Chrono79 thanks
CamperBot
@camperbot
Nov 23 2017 15:15
pocahontas123 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4603 | @chrono79 |http://www.freecodecamp.org/chrono79
Diego Mayer
@Chrono79
Nov 23 2017 15:16
no problem
pocahontas123
@pocahontas123
Nov 23 2017 15:32

`function sumFibs( num ) {
let array = [ 0, 1, 1 ];

for( let k = 3; k < num+1; k++ ) {
    array[k] = array[k-1] + array[k-2];

    if( array[k] > num ) {
        array.splice(k, 1);
        break;
    }
}

let arrL = array.length;

for( k = 0; k < arrL; k++ ) {
    if( array[k] % 2 == 0 ) {
        array.splice(k, 1);
    }
}

var sum = array.reduce((a, b) => a + b, 0);

return sum;

};`

@Chrono79 Certainly not the best way but i'm happy for now
Stephen James
@sjames1958gm
Nov 23 2017 15:33
@pocahontas123 Using filter is another way to get off values
return array.filter(e => e % 2 == 1).reduce((a, c) => a + c);
Diego Mayer
@Chrono79
Nov 23 2017 15:34
@pocahontas123 you could use only one loop, using a var to store the addition
pocahontas123
@pocahontas123
Nov 23 2017 15:34
Yeah, i think i could have done that way. But i'm not really capable with reduce/filter so i try to avoid them :/
Diego Mayer
@Chrono79
Nov 23 2017 15:35
Try doing it in different ways, refactoring your code
Stephen James
@sjames1958gm
Nov 23 2017 15:35
No capable is the reason to use them to learn - they are very powerful
Diego Mayer
@Chrono79
Nov 23 2017 15:37
var sum = array.reduce((a, b) => a + (b % 2 ? b : 0), 0);
There you're doing the addition of only odd numbers
pocahontas123
@pocahontas123
Nov 23 2017 15:38
Nice one. But this return array.filter(e => e % 2 == 1).reduce((a, c) => a + c); is still comprehensible for me :)
the other one i understand but not fully
yet...
@sjames1958gm thanks
CamperBot
@camperbot
Nov 23 2017 15:39
pocahontas123 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8708 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
Diego Mayer
@Chrono79
Nov 23 2017 15:39
In the loop where you create the array with fibonacci numbers, you could test for parity and add to sum or not, that's faster and simpler
no filter or reduce involved
explore different ways of solving the same problem, that'll give you more insight about how to solve it
Diego Mayer
@Chrono79
Nov 23 2017 15:45
@pocahontas123 Also note that modifying the array you're using in a loop is (generally) wrong
for( k = 0; k < arrL; k++ ) {
    if( array[k] % 2 == 0 ) {
        array.splice(k, 1);
    }
}
You skip values like that
In this particular case, you don't get 2 even numbers next to each other check it: https://repl.it/repls/IllfatedOurChrysomelid
Blauelf
@Blauelf
Nov 23 2017 15:50

ES6 default arguments allow for such nice functions :)

const sumFibs = (num, a = 0, b = 1) => b > num ? 0 : b % 2 * b + sumFibs(num, b, a + b);

Using: ES6 const, ES6 arrow function, ES6 default parameters, conditional operator, operator precedence (because it's important that % and * are on same level and left-to-right), recursion.

Diego Mayer
@Chrono79
Nov 23 2017 15:51
@Blauelf are you trying to kill her? :P
Blauelf
@Blauelf
Nov 23 2017 15:52
Using recursion is possible, but highly inefficient. This one isn't even tail recursion, which might be optimized into a loop by a compiler.
Diego Mayer
@Chrono79
Nov 23 2017 16:03
@pocahontas123 If you're still alive, try to check Blauelf's code and the links he posted
Nazar
@IsaakNazar
Nov 23 2017 16:15
the code below doesnt retrieve all datas from twitch api, how to make it possible?
function loadTwitch(){
  var request = new XMLHttpRequest();
  request.open('GET', 'https://api.twitch.tv/kraken?client_id=lgghz9edvzz0ww7wzo5fz1d6xp4u6g');
  request.onload = function() {
    var theData = JSON.parse(request.responseText);
    console.log(theData);
  };
  request.send();
}
loadTwitch();
it retrieve the data about myself I guess
Stephen James
@sjames1958gm
Nov 23 2017 16:17

@IsaakNazar There are multiple API links to get the data

"_links": {
"channel": "https://api.twitch.tv/kraken/channel",
"teams": "https://api.twitch.tv/kraken/teams",
"user": "https://api.twitch.tv/kraken/user",
"streams": "https://api.twitch.tv/kraken/streams",
"ingests": "https://api.twitch.tv/kraken/ingests"
}

You also have to add the user

Nazar
@IsaakNazar
Nov 23 2017 16:20

@sjames1958gm ok i made smth like inside request.onload

console.log(theData._links.teams);

and theres a link that gives {"error":"Bad Request","status":400,"message":"No client id specified"}

Stephen James
@sjames1958gm
Nov 23 2017 16:21
You have to add in your client id as well
You can paste the URLs into your browser address bar to test
@IsaakNazar https://api.twitch.tv/kraken/streams/chiefpat?client_id=xxxxxx
Nazar
@IsaakNazar
Nov 23 2017 16:28
@sjames1958gm chiefpat its channel name right?
here I have to paste any channel name right?
@sjames1958gm U saved my life Stephen, GOD bless you :+1:
Nazar
@IsaakNazar
Nov 23 2017 16:33
@sjames1958gm thx
CamperBot
@camperbot
Nov 23 2017 16:33
isaaknazar sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8709 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
Razvan Jackson
@RazvanJackson
Nov 23 2017 16:48
hey
The term 'npm' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a
path was included, verify that the path is correct and try again.
how can i solve it
Stephen James
@sjames1958gm
Nov 23 2017 17:03
did you install node?
@RazvanJackson
Mohamed Derhalli
@derhallim
Nov 23 2017 17:22
@sjames1958gm heyyy
how are u?
Stephen James
@sjames1958gm
Nov 23 2017 17:23
@derhallim Good - you ?
Mohamed Derhalli
@derhallim
Nov 23 2017 17:23
good good
Razvan Jackson
@RazvanJackson
Nov 23 2017 17:23
@sjames1958gm yes
Mohamed Derhalli
@derhallim
Nov 23 2017 17:23
congrats for the game yesterday!
Stephen James
@sjames1958gm
Nov 23 2017 17:23
@derhallim Yes, kind of unfortunate that the other team got that early red card made it not so exciting
@RazvanJackson Did you close and reopen your terminal window?
Mohamed Derhalli
@derhallim
Nov 23 2017 17:24
was it early? I didn't watch it
Stephen James
@sjames1958gm
Nov 23 2017 17:24
Yes 11am here in Texas
AbrisM
@AbrisM
Nov 23 2017 18:04
Does anyone know any online IDE than JSFiddle and Codepen?
AbrisM
@AbrisM
Nov 23 2017 18:10
except it says "Another program running" but there is no other programs
what does $paper exactly do?
Blauelf
@Blauelf
Nov 23 2017 18:19
@AbrisM Maybe you need something like <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script> in your HTML?
AbrisM
@AbrisM
Nov 23 2017 18:22
Strange
in Codepen it works fine, but actually running the code by launching it just displays the HTML part and nothing more. No interactions, no user input
AbrisM
@AbrisM
Nov 23 2017 18:35
Just a white website
AbrisM
@AbrisM
Nov 23 2017 18:41

also, putting the following does not work: <!Doctype html>

<head>

<link rel="stylesheet" type="text/css" href="RansomeNote">
</head>

<body>

<script src="RansomeNoteJS.js"></script>

<p class="paper">
<span class="heading">Type Anywhere On Page:</span><br>
</p>
</body>
</html>

https://codepen.io/anon/pen/eeKNVX This is the newly updated code
Brian
@BrianCodes33
Nov 23 2017 18:58
const sumNested = arr => {
  return arr.reduce(function(a, b) {
    return a.concat(b);
  }).reduce((a,b) => {
    return a+b
  },0);
};
trying to flatten a multidimensional array and add - what am i doing wrong
alpox
@alpox
Nov 23 2017 19:09
@BrianCodes33 You only flatten it for 1 level. (Just that you are aware). In the first reduce you miss the initial value of the accumulator - so a is undefined and a.concat raises an error because it doesn't exist on undefined
Blauelf
@Blauelf
Nov 23 2017 19:51
@alpox With missing starting value, a isn't undefined, but the first value of the array, the iteration then starts with the second. Still, if that one is not an array, concat won't exist, so the problem is the same.
alpox
@alpox
Nov 23 2017 20:18
@Blauelf Oh i didn't know that behavior of reduce
Good to know
Blauelf
@Blauelf
Nov 23 2017 20:22
I actually don't like this default behaviour, as it's rarely useful. Also, not specifying a starting value also means you cannot call it on an empty value (as its non-existent first value would have to be returned)
??
i just did that one this morning but codewars broke down
server 500 errors
alpox
@alpox
Nov 23 2017 20:40
@breese8009 yea codewars seems to be broken
Tiago Correia
@tiagocorreiaalmeida
Nov 23 2017 21:30
so what are you all coding? feeling bored want to see things :D
Tiago Correia
@tiagocorreiaalmeida
Nov 23 2017 21:33
and the steaks keep coming out?
alpox
@alpox
Nov 23 2017 21:34
Nah i changed to eggs
Cannot take too much steak :D
Tiago Correia
@tiagocorreiaalmeida
Nov 23 2017 21:36
you remembered me of grilled pepper with an egg on top
alpox
@alpox
Nov 23 2017 21:36
Hmm doesn't sound too bad
I usually make egg on top of bacon
Tiago Correia
@tiagocorreiaalmeida
Nov 23 2017 21:38
that's good aswell :D
alpox
@alpox
Nov 23 2017 21:39
But grilled pepper made me think of a whole pepper filled with salsa, cheese and chicken with a rice ring around made in oven
Mmmmh
Ah cmon i just ate, don't make me think of more food :D
Tiago Correia
@tiagocorreiaalmeida
Nov 23 2017 21:41
there's always a little space available for things like those evne after eating ahahha
so how's the new house?
alpox
@alpox
Nov 23 2017 21:42
The new house is awesome :D
Its further from university but so much nicer to live in
Tiago Correia
@tiagocorreiaalmeida
Nov 23 2017 21:45
must feel good after so many years finally have a space just for you
alpox
@alpox
Nov 23 2017 21:46
Yea kinda :D its also a bit more work though
But its a good thing
Its quiet and i have my space
Tiago Correia
@tiagocorreiaalmeida
Nov 23 2017 21:53
image.png
alpox
@alpox
Nov 23 2017 22:03
I feel you
Tiago Correia
@tiagocorreiaalmeida
Nov 23 2017 22:07
after standing up starts thinking about how I should correct my posture
alpox
@alpox
Nov 23 2017 22:14
:D
I think i can make omlettes on this laptop
I start to wonder if i should stick those calculations in the cloud :D
DistinctWolf
@DistinctWolf
Nov 23 2017 22:25
How did y'all integrate weather icons to the weather app
Ogundele Olumide
@Lumexralph
Nov 23 2017 22:55
@FlashHero depends on your api or what kind of icon do you mean?
Tiago Correia
@tiagocorreiaalmeida
Nov 23 2017 22:56
@alpox safety first print them place them in your pocket just in cause you need to write them all down again :D
alpox
@alpox
Nov 23 2017 23:04
@tiagocorreiaalmeida Ah well that doesn't work well :D i didn't have to write them much but they take a long time to compute
Thats more of the problem :D
At the moment i'm running a gridsearch for hyperparameters for support vector machines. Takes quite long to evaluate all of them
Tiago Correia
@tiagocorreiaalmeida
Nov 23 2017 23:09
im like,I understand everything you are sayingahahah jesus
DistinctWolf
@DistinctWolf
Nov 23 2017 23:19
@Lumexralph open weather api
Ogundele Olumide
@Lumexralph
Nov 23 2017 23:20
@FlashHero i don't know if there's an upgrade on their API but you can get the image of the icon when you fetch your data and render it on the DOM as an img element
@FlashHero i used weatherforecast.io i hope i got the name
DistinctWolf
@DistinctWolf
Nov 23 2017 23:27
@Lumexralph ok thanks man and do i have to specify every weather conditions for example can't it just be a image of rain regardless of being heavy or light raining
CamperBot
@camperbot
Nov 23 2017 23:27
flashhero sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 2061 | @lumexralph |http://www.freecodecamp.org/lumexralph
Ogundele Olumide
@Lumexralph
Nov 23 2017 23:32
@FlashHero i think it'll be understandable to have the summary along with the icon to eliminate any ambiguity