These are chat archives for FreeCodeCamp/HelpJavaScript

30th
Aug 2017
Ronique Ricketts
@RoniqueRicketts
Aug 30 2017 00:37
@khanh2003 lol your crazy lol
Nick Cleary
@Hijerboa
Aug 30 2017 00:42
Hey does anyone know what's wrong with this line? Im getting an error saying str.replace(); is not a function
str = str.replace(/" "/gi, "_");
Joel Y.
@zapcannon99
Aug 30 2017 00:43
isn't string literals ¥ instead of /
that yen sign is a backslash btw
nvm, let me check I think I'm getting confused merp
Nick Cleary
@Hijerboa
Aug 30 2017 00:43
possibly let me try that
Joel Y.
@zapcannon99
Aug 30 2017 00:44
I'm wrong, very wrong
Nick Cleary
@Hijerboa
Aug 30 2017 00:44
nope. Unexpected token on that line now
Joel Y.
@zapcannon99
Aug 30 2017 00:44
Yeah, I was very wrong
Nick Cleary
@Hijerboa
Aug 30 2017 00:44
haha i was going to say
Joel Y.
@zapcannon99
Aug 30 2017 00:45
Maybe you don't need the Quotes?
just /\s/
Randell Dawson
@RandellDawson
Aug 30 2017 00:46
@Hijerboa
str = str.replace(/ /gi, "_");
Joel Y.
@zapcannon99
Aug 30 2017 00:46
I'm assuming that you want to replace a single space with underscore
Nick Cleary
@Hijerboa
Aug 30 2017 00:47
@rmdawson71 same error :/
Randell Dawson
@RandellDawson
Aug 30 2017 00:47
@Hijerboa - just get rid of the double quotes
Nick Cleary
@Hijerboa
Aug 30 2017 00:47
@zapcannon99 and you are correct in that
Randell Dawson
@RandellDawson
Aug 30 2017 00:47
put console.log(str) on the line before to see what it is
Moisés Man
@moigithub
Aug 30 2017 00:47
probably str variable dont have a string on it
Joel Y.
@zapcannon99
Aug 30 2017 00:47
good point, gotta make sure str is an actual string
Nick Cleary
@Hijerboa
Aug 30 2017 00:47
@moigithub you're right... I forgot I changed it to an array
some part of my brain thought it carried over
@zapcannon99 @moigithub @rmdawson71 thanks guys
CamperBot
@camperbot
Aug 30 2017 00:48
hijerboa sends brownie points to @zapcannon99 and @moigithub and @rmdawson71 :sparkles: :thumbsup: :sparkles:
:cookie: 334 | @zapcannon99 |http://www.freecodecamp.com/zapcannon99
:cookie: 300 | @rmdawson71 |http://www.freecodecamp.com/rmdawson71
:star2: 3617 | @moigithub |http://www.freecodecamp.com/moigithub
Joel Y.
@zapcannon99
Aug 30 2017 00:48
Eh better than me, I completely forgot very BASIC JS
__>
<__<
Nick Cleary
@Hijerboa
Aug 30 2017 00:49
I like to think that at some point every programmer makes a mistake that they hope is never seen in a commit
And i think I just made one of them :P
glitz20
@glitz20
Aug 30 2017 01:16
hey guys I am new to express and node js. Can anyone help me to organize files and folder. It is so confusing to me right now
Chris Cullen
@123xylem
Aug 30 2017 01:20

I have simple project location
[IMG]http://i68.tinypic.com/2d6wshs.png[/IMG]

When I run Gulp watch

var gulp        = require('gulp');
var browserSync = require('browser-sync').create();
var reload      = browserSync.reload;

gulp.task('watch', function () {

    browserSync.init({
        server: {
            baseDir: "C:\Users\Chris\Documents\Projects\Coding\GalleryFlex\index.html"
        }
    });

    gulp.watch("*.html, *.css").on("change", reload);
});

It cannot find the file I get 404 error..
[Browsersync] Serving files from: C:UsersChrisDocumentsProjectsCodingGalleryFlexindex.html

I think my base Dir: is pointing to the wrong file location?

Mohamed Wahshey
@mohamedwahshey
Aug 30 2017 01:48
Kindly help me, i need someone to monitor, guide and give me tasks to do with JavaScript language, I'm a bit lazy person and in a great need for someone to just guide me through like a coach, and i will be committed to his tasks, i know the online coding websites, all of them, but i need a person not a machine, sadly, it will be for free, but im not looking for sessions i just need guidance and tasks, kindly help.
Stephen James
@sjames1958gm
Aug 30 2017 02:07
@123xylem Maybe remove the c: and swap the \ for /
Or replace the \ with \\
Claudio Restifo
@Marmiz
Aug 30 2017 02:11
@mohamedwahshey ask on the forum, there are many people that will like to pair program :)
Mohamed Wahshey
@mohamedwahshey
Aug 30 2017 02:12
@Marmiz thanks mate for replying, u mean free code camp or github forum?
CamperBot
@camperbot
Aug 30 2017 02:12
mohamedwahshey sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1035 | @marmiz |http://www.freecodecamp.com/marmiz
Claudio Restifo
@Marmiz
Aug 30 2017 02:14
@mohamedwahshey if you are here I assume you are taking free code camp, so I'd suggest there.
Many people are learning to program as well, so maybe having a study partner can help you
Mohamed Wahshey
@mohamedwahshey
Aug 30 2017 02:15
Yes i almost finished the front end certificate, ok thx mate so much i will post there @Marmiz
CamperBot
@camperbot
Aug 30 2017 02:15
mohamedwahshey sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:warning: mohamedwahshey already gave marmiz points
Gersho
@Gersho
Aug 30 2017 02:16
if you're almost done with front end on your own, i think you're probably doing well enought on your own :)
Amit Patel
@AmitP88
Aug 30 2017 02:43
hey guys, has anyone here gotten a web developer job solely because of FreeCodeCamp?
Claudio Restifo
@Marmiz
Aug 30 2017 02:44
@AmitP88 the forum is full of stories :)
https://forum.freecodecamp.org/c/getting-a-developer-job
Amit Patel
@AmitP88
Aug 30 2017 02:47
@Marmiz ah ok. Only reason why I ask is because I've been applying, but I can't seem to get an interview =(
Claudio Restifo
@Marmiz
Aug 30 2017 02:53
@AmitP88 lots of factors: area - previous skill and experience - resume and general presentation ...
just don't give up. It's not easy ;)
Amit Patel
@AmitP88
Aug 30 2017 02:54
@Marmiz thanks :) Yeah, I do live in an area where tech is basically nonexistant lol. here's my portfolio site for more info: http://imamitpatel.com/
CamperBot
@camperbot
Aug 30 2017 02:54
amitp88 sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1036 | @marmiz |http://www.freecodecamp.com/marmiz
Amit Patel
@AmitP88
Aug 30 2017 02:54
@Marmiz if I were to apply for out of state jobs, would I have to fly down there for in-person interviews?
BrianWilliams28
@BrianWilliams28
Aug 30 2017 03:01
can someone help with this algorithm? so far i've gotten the LCM of the two integers but i'm kinda at a loss on what to do next.
function smallestCommons(arr) {
  var multiplyArr = arr[0] * arr[1];
  var range = []; // [18, 19, 20, 21, 22, 23]
  // smallestCommons(23,18) => smallestCommons(18,23);
  var sort = arr.sort(function(a, b) { 
    return a - b;
  });
  // creating the range
  for (var i = sort[0]; i <= sort[1]; i++) { 
  range.push(i);
 }
  // function to get the greatest common divisor
 function getGCD(a, b) {
  var remainder = a % b;
   while (remainder > 0) {
     a = b;
     b = remainder;
     remainder = a % b;
   }
   return b; // outputs 1
 } 
 var LCM = multiplyArr / getGCD(sort[1], sort[0]); 
console.log(LCM);
return LCM; // outputs 414...need to test this against each number in the range to see if it divides...if not, next largest common multiple needs to be tested?
}

smallestCommons([23,18]);
Gersho
@Gersho
Aug 30 2017 03:04
those challenges would be easier if there wasn't the math part xD
hmm isn't that the one where you're supposed to use prime factors to solve it ?
because math wise i have no idea what you're trying to do with that 414
(but i suck at math)
Ryan Williams
@Ryanwfile
Aug 30 2017 03:55

I'm adding a facebook icon at the bottom of a page and when I open the website file on my computer the browser loads with a console error
XMLHttpRequest cannot load file:///C:/assets/social.php. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
send @ jquery.min.js:4

and the icon loads perfectly, but when i upload the same files to github the icon no longer loads and I get the console error
Failed to load resource: the server responded with a status of 404 () assets/social.php

Any help in getting the icon to load on github would be very appreciated.

Gersho
@Gersho
Aug 30 2017 03:58
what is on line 4 of your jquery ?
@Ryanwfile
Ryan Williams
@Ryanwfile
Aug 30 2017 04:00

@Gersho it's the jquery.min.js file so near impossible to read.
the script in question though is this

<script id="facebook-jssdk" src="//connect.facebook.net/en_US/sdk.js#xfbml=1&amp;version=v2.5"></script>

Thank you for taking a look

CamperBot
@camperbot
Aug 30 2017 04:00
ryanwfile sends brownie points to @gersho :sparkles: :thumbsup: :sparkles:
:cookie: 370 | @gersho |http://www.freecodecamp.com/gersho
Gersho
@Gersho
Aug 30 2017 04:03
only thing i know about cross origin is http / https mix :(
Ryan Williams
@Ryanwfile
Aug 30 2017 04:04
I just don't understand how it works perfectly from my computer and connects to facebook fine even with an authorization modal, but uploaded it doesn't even appear
Gersho
@Gersho
Aug 30 2017 04:06
i don't know either, you'll have so ask someone better at this ^^ i guess in local some checks don't work the same way (have you tried accessing it via your local network ? l)
John
@AnonymousLords
Aug 30 2017 04:14
wait nvm
Ryan Williams
@Ryanwfile
Aug 30 2017 04:16
@Gersho Yea the files work perfect when run straight from my file system into the browser but don't work on github. Anways, thanks for trying, I'm heading to bed.
CamperBot
@camperbot
Aug 30 2017 04:16
ryanwfile sends brownie points to @gersho :sparkles: :thumbsup: :sparkles:
:warning: ryanwfile already gave gersho points
Claudio Restifo
@Marmiz
Aug 30 2017 04:27
@Ryanwfile are we talking about github pages right?
Eunice Park
@eunicode
Aug 30 2017 04:40
Can someone please explain what's wrong with my code? I'm trying to solve this algorithm: https://www.freecodecamp.org/challenges/convert-html-entities
function convertHTML(str) {

  let newStr;

  if (str.indexOf("&"||"<"||">"||'"'||"'") !== -1) {
    newStr = str.replace(/&/g, '&amp;');
    newStr = newStr.replace(/</g, '&lt;');
    newStr = newStr.replace(/>/g, '&gt;');
    newStr = newStr.replace(/"/g, '&quot;');
    newStr = newStr.replace(/'/g, 'apos;');

    return newStr;
  }

  else return str;

}

convertHTML("Dolce & Gabbana");
heroiczero
@heroiczero
Aug 30 2017 04:42
@eunipa you dont really need a if statement and
@eunipa you can make str= str.replace(..) instead of newStr
@eunipa but your mistake is 'apos;' missing & i think
Eunice Park
@eunicode
Aug 30 2017 04:45
@heroiczero Thank you. I tried getting rid of the if statement and my code works now. Do you know why the if statement makes the code not work?
CamperBot
@camperbot
Aug 30 2017 04:45
eunipa sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1672 | @heroiczero |http://www.freecodecamp.com/heroiczero
Gersho
@Gersho
Aug 30 2017 04:46
i'm not sure you can use || inside the indexOf
Eunice Park
@eunicode
Aug 30 2017 04:49
@Gersho Thanks. But if the if statement is unfulfilled, str gets returned. Otherwise some weird string gets returned. So I think the if statement partly works?:
function convertHTML(str) {

  let newStr;

  if (str.indexOf("&"||"<"||">"||'"'||"'") !== -1) {
    newStr = str.replace(/&/g, '&amp;');
    newStr = newStr.replace(/</g, '&lt;');
    newStr = newStr.replace(/>/g, '&gt;');
    newStr = newStr.replace(/"/g, '&quot;');
    newStr = newStr.replace(/'/g, '&apos;');

    return newStr;
}

  else return str;

}

convertHTML("Dolce ' Gabbana");
CamperBot
@camperbot
Aug 30 2017 04:49
eunipa sends brownie points to @gersho :sparkles: :thumbsup: :sparkles:
:cookie: 371 | @gersho |http://www.freecodecamp.com/gersho
heroiczero
@heroiczero
Aug 30 2017 04:50
@eunipa the if statement is unnecessary in the first place but it only takes one value meaning str.indexOf("&")==-1;
Gersho
@Gersho
Aug 30 2017 04:50
try
if(str.indexOf("&") || str.indexOf("<" etc...
but yeah the if not not necessary
since replace won't change your string if the regex you look for isn't there
Eunice Park
@eunicode
Aug 30 2017 04:53
@heroiczero Maybe I'm misunderstanding something, but convertHTML("Dolce ' Gabbana"); doesn't have &, and it returns Dolce \' Gabbana
heroiczero
@heroiczero
Aug 30 2017 04:55
@eunipa should it not return Dolce &apos; Gabbana
Eunice Park
@eunicode
Aug 30 2017 04:57
@Gersho woah, I tried your suggestion and it works
@heroiczero It does return Dolce &apos; Gabbana if I take out the if condition. But it returns Dolce \' Gabbana with the if condition
Gersho
@Gersho
Aug 30 2017 04:59
i was curious and rewatched my code for that challenge, didn't use replace and went full braindead xD
heroiczero
@heroiczero
Aug 30 2017 05:00
@eunipa if you have the if condition it will always go to the else with your current if statement because its when they "Do Not" have the ' and other characters since it `-1
Gersho
@Gersho
Aug 30 2017 05:01
nvm
Eunice Park
@eunicode
Aug 30 2017 05:02
@heroiczero Okay, nvm, I get it now. I was confused bc if the if condition wasn't being fulfilled, str should be returned, not some weird string with backslashes. But I think I understand why the backslash was being inserted
Gersho
@Gersho
Aug 30 2017 05:05
well it's a escape backslash
Eunice Park
@eunicode
Aug 30 2017 05:06
str is Dolce ' Gabbana and the function was returning Dolce \' Gabanna
I guess that was tripping me up.
Anyways, lesson learned. You can't have || inside indexOf()
Gersho
@Gersho
Aug 30 2017 05:10
well imagine you did "apple".indexOf("a"||"p"||"l") it's supposed to return only a single value or -1, how it is supposed to respond to this ?
Eunice Park
@eunicode
Aug 30 2017 05:11
Good point
kumquatfelafel
@kumquatfelafel
Aug 30 2017 05:16
Well... you can have || inside of indexOf. It just might not do what you expect... https://repl.it/KRBJ/5
Basically, || will return the first truthy value encountered, or false if none are encountered.
So in case of @Gersho example, it would essentially be equivalent of saying indexOf("a")
Markus Kiili
@Masd925
Aug 30 2017 05:20
@kumquatfelafel It returns the last term if all are falsy.
Gersho
@Gersho
Aug 30 2017 05:20

https://repl.it/KRBJ/5

and this is why we can't have nice things

kumquatfelafel
@kumquatfelafel
Aug 30 2017 05:21
@Masd925 Thanks for correction.
CamperBot
@camperbot
Aug 30 2017 05:21
kumquatfelafel sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4448 | @masd925 |http://www.freecodecamp.com/masd925
Eunice Park
@eunicode
Aug 30 2017 05:22
@kumquatfelafel @Masd925 Thank you. I don't know when/how I would use this knowledge, or if I'll remember it, but it's cool JS has a way of dealing with various situations
CamperBot
@camperbot
Aug 30 2017 05:22
eunipa sends brownie points to @kumquatfelafel and @masd925 :sparkles: :thumbsup: :sparkles:
:cookie: 624 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:star2: 4449 | @masd925 |http://www.freecodecamp.com/masd925
Mai Thinh
@mthinh
Aug 30 2017 05:46
 Global.checkMin(sessionVal);
   setTimeout(Global.checkMin(breakVal),10000);
hey guys, i setTime for the second line to run, but why they all run together, anyone knows why ?
Markus Kiili
@Masd925
Aug 30 2017 05:48
@mthinh It is not a time after the second line runs. setTimeout tells the browser to run the given function (first argument) after given amount of milliseconds (second argument).
Mai Thinh
@mthinh
Aug 30 2017 05:49
@Masd925 yeah, that what i means, sorry
but they all run together, and i dont know why
Markus Kiili
@Masd925
Aug 30 2017 05:50
@mthinh Does Global.checkMin(breakVal) return a function?
Mai Thinh
@mthinh
Aug 30 2017 05:50
im doing Pomodoro clock, you can check out my codepen
Markus Kiili
@Masd925
Aug 30 2017 05:51
@mthinh Is it so that you wan't to execute Global.checkMin(breakVal) after 10000 milliseconds?
Mai Thinh
@mthinh
Aug 30 2017 05:51
@Masd925 yah right,
Markus Kiili
@Masd925
Aug 30 2017 05:51
Then it needs to be setTimeout(function(){Global.checkMin(breakVal);},10000);
Mai Thinh
@mthinh
Aug 30 2017 05:52
oh let me try
Markus Kiili
@Masd925
Aug 30 2017 05:52
The first argument needs to be a function that is executed after the given amount of time.
Gersho
@Gersho
Aug 30 2017 05:53
sorry to intrude, but i don't really understand the point of having Global being a function that returns an object, isn't that the same to having Global = {Object}; ? (trying to step up my game by understanding others code)
or is there some reason to it ?
prakash chandra yadav
@prakashyadav008
Aug 30 2017 05:54
hey everyone
can anyone check if it is responsive
Mai Thinh
@mthinh
Aug 30 2017 05:55
@prakashyadav008 yah it is
Gersho
@Gersho
Aug 30 2017 05:56
yep
prakash chandra yadav
@prakashyadav008
Aug 30 2017 05:56
yesssss
first responsive html page
any ideas on how can i reduce the keep the size of the search bar same when the size reduces to less than 600px
..?
Markus Kiili
@Masd925
Aug 30 2017 05:58
@Gersho Yes, no point for having an IIFE if it just returns an object.
Mai Thinh
@mthinh
Aug 30 2017 05:58
@Masd925 i got it, thank you
CamperBot
@camperbot
Aug 30 2017 05:58
mthinh sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4450 | @masd925 |http://www.freecodecamp.com/masd925
prakash chandra yadav
@prakashyadav008
Aug 30 2017 05:58
@mthinh
Gersho
@Gersho
Aug 30 2017 05:58
@Masd925 thanks ! \o/ yeah i'm starting to understand stuff i read
CamperBot
@camperbot
Aug 30 2017 05:58
gersho sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4451 | @masd925 |http://www.freecodecamp.com/masd925
prakash chandra yadav
@prakashyadav008
Aug 30 2017 05:58
@Gersho
kumquatfelafel
@kumquatfelafel
Aug 30 2017 06:07

@prakashyadav008 @camperbot You can notify more than one person in same post like so. You can also quote post you want them to see by alt+clicking the time signature (upper right corner of comment), resulting in (for example)... :point_up: August 30, 2017 1:56 AM

More likely to get an answer (or at least response) this way... especially if the question you want people to see would require scrolling up through a number of unrelated posts.

prakash chandra yadav
@prakashyadav008
Aug 30 2017 06:11
Long Nguyen
@longnt80
Aug 30 2017 06:13
in setTimeout, the first parameter is a function name, what if that function has parameter. Can I do like this:
setTimeout(theFunc(para), 1000);
Gersho
@Gersho
Aug 30 2017 06:15
as far as i know, yes
Markus Kiili
@Masd925
Aug 30 2017 06:15
@longnt80 No, that would evaluate to the return value of that function.
kumquatfelafel
@kumquatfelafel
Aug 30 2017 06:15
@longnt80 Doing theFunc(para) will call the function, passing para as argument. :point_up: :point_down:
Markus Kiili
@Masd925
Aug 30 2017 06:16
@longnt80 The first parameter needs to be a function or an expression that evaluates to a function.
Long Nguyen
@longnt80
Aug 30 2017 06:17
so it's not gonna work? THe only way is to put that inside an anonymous function?
@Masd925 @kumquatfelafel
Markus Kiili
@Masd925
Aug 30 2017 06:18
@longnt80 If you wan't to call that function after 1000 milliseconds with the given argument, you need to wrap it into an anonymous function, yes.
Long Nguyen
@longnt80
Aug 30 2017 06:18
@Masd925 @kumquatfelafel thanks
CamperBot
@camperbot
Aug 30 2017 06:18
longnt80 sends brownie points to @masd925 and @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 625 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:star2: 4452 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Aug 30 2017 06:20
@longnt80 setTimeout("theFunc(para);",1000) would also work, but is kind of eval, so not recommended.
Long Nguyen
@longnt80
Aug 30 2017 06:21
@Masd925 I see
kumquatfelafel
@kumquatfelafel
Aug 30 2017 06:21
provided argument can't be defined within the gunction itself, or doesn't exist as variable that otherwise defined within scope of theFunc, agreed with :point_up:
Aimee
@bestAimee
Aug 30 2017 06:36
image.png
how to do ?
i don'know where wrong
Gersho
@Gersho
Aug 30 2017 06:37
arr.lenth is wrong ---> arr.length @bestAimee
Markus Kiili
@Masd925
Aug 30 2017 06:37
@bestAimee The solution is much simpler if you first push num into arr and then sort.
It is also possible to solve it without sorting at all.
Jan Shah
@JanShah
Aug 30 2017 06:38
@Masd925 how is that?
Markus Kiili
@Masd925
Aug 30 2017 06:40
@JanShah To know your spot on a classroom by length queue, you only need to calculate the amount of people shorter than you. No need to form the sorted queue for that.
Jan Shah
@JanShah
Aug 30 2017 06:40
something like find?
or filter?
idk how would you do it?
Markus Kiili
@Masd925
Aug 30 2017 06:41
@JanShah Loop or reduce that calculates the amount of elements <num.
Jan Shah
@JanShah
Aug 30 2017 06:41
so, combine them and then a reduce function?
ohh, no need to combine them
Markus Kiili
@Masd925
Aug 30 2017 06:42
@JanShah Yes, just loop or iterate arr.
Aimee
@bestAimee
Aug 30 2017 06:46
thank you @Masd925 @Gersho
CamperBot
@camperbot
Aug 30 2017 06:46
bestaimee sends brownie points to @masd925 and @gersho :sparkles: :thumbsup: :sparkles:
:cookie: 374 | @gersho |http://www.freecodecamp.com/gersho
:star2: 4453 | @masd925 |http://www.freecodecamp.com/masd925
Jan Shah
@JanShah
Aug 30 2017 07:04

@Masd925

  return arr.filter(a=>a<num).length

that is a lot better than the previous one I came up with

return [...arr,num].sort((a,b)=>a-b).indexOf(num);
whatamess
Markus Kiili
@Masd925
Aug 30 2017 07:10
@JanShah Reduce is even better, because no new array is created:
function where(arr, num) {
  return arr.reduce(function(prev, curr){
    return curr<num ? prev+1 : prev;
  },0); 
}
Jan Shah
@JanShah
Aug 30 2017 07:12
@Masd925 doesn't that return the value?
I tried a reduce first, but I needed 3 parameters to get the index and I thought.. nah
Markus Kiili
@Masd925
Aug 30 2017 07:13
@JanShah That returns the value of arr elements smaller than num.
Jan Shah
@JanShah
Aug 30 2017 07:13
@Masd925 the exercise requires the index of the position num would occupy
Markus Kiili
@Masd925
Aug 30 2017 07:14
@JanShah Yes, calculating the number of arr elements smaller than num is the same as the index of that num on a sorted array. Some math logic used there to solve it more easily.
Jan Shah
@JanShah
Aug 30 2017 07:16
@Masd925 yeah, I've just had a look at it, thanks for the info, nice and clear
CamperBot
@camperbot
Aug 30 2017 07:16
janshah sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4454 | @masd925 |http://www.freecodecamp.com/masd925
Jan Shah
@JanShah
Aug 30 2017 07:19
@Masd925
it fails all the tests..
Markus Kiili
@Masd925
Aug 30 2017 07:19
@JanShah The function name has changed. Change it and it works.
function getIndexToIns(arr, num) {
  return arr.reduce(function(acc, curr){
    return curr<num ? acc+1 : acc;
  },0); 
}
Jan Shah
@JanShah
Aug 30 2017 07:22
I missed the 0, what's the significance of that?
@Masd925
Abhinav Mishra
@abhinav-m
Aug 30 2017 07:22
initial value of the accumulator
Markus Kiili
@Masd925
Aug 30 2017 07:22
@JanShah It is the initial value of the accumulator. Means that at start we have zero elements smaller than num and reduce adds to that when such elements are found.
Jan Shah
@JanShah
Aug 30 2017 07:23
@abhinav-thinktank @Masd925 thanks for that
CamperBot
@camperbot
Aug 30 2017 07:23
janshah sends brownie points to @abhinav-thinktank and @masd925 :sparkles: :thumbsup: :sparkles:
:warning: janshah already gave masd925 points
:cookie: 535 | @abhinav-thinktank |http://www.freecodecamp.com/abhinav-thinktank
Jan Shah
@JanShah
Aug 30 2017 07:24
@Masd925 because I didn't have that I was getting a prev as the first element of the array.. I feel smarter already
Markus Kiili
@Masd925
Aug 30 2017 07:24
@JanShah Yes, prev was a bad name for that parameter. acc is better.
Jan Shah
@JanShah
Aug 30 2017 07:26
return arr.reduce((a,b)=>b<num?a+1:a,0);
I understand abc better :(

can you explain what the difference is in filter and reduce in relation to a function, it seems they both return the value needed but

@JanShah Reduce is even better, because no new array is created:

@Masd925
Markus Kiili
@Masd925
Aug 30 2017 07:31
@JanShah Filter makes a new array with all the elements <num and then you return the length of that array. Reduce just iterates arr and calculates the elements <num. So reduce doesn't make any new arrays.
So reduce should be much faster here.
Jan Shah
@JanShah
Aug 30 2017 07:32
@Masd925 I should have listened more in class.
Markus Kiili
@Masd925
Aug 30 2017 07:33
@JanShah Small details but would make a big difference on huge amounts of data.
Jan Shah
@JanShah
Aug 30 2017 07:35
I see what you mean. I have been using reduce a lot but didn't think map or filter would slow things down
Markus Kiili
@Masd925
Aug 30 2017 07:39
@JanShah Usually that doesn't matter, but you should know about efficiency too. If the data amounts are huge of some code is run many times, such things can start to matter.
Tiago Correia
@tiagocorreiaalmeida
Aug 30 2017 08:51
gm everyone
George Kech.
@georgemitnick
Aug 30 2017 09:10
Anyone here?
Markus Kiili
@Masd925
Aug 30 2017 09:11
@georgemitnick You can just post if you have a question. Usually someone answers.
George Kech.
@georgemitnick
Aug 30 2017 09:11
Problem is my question is super long
I'll have to post html, css, and js files
copy paste them here as for anyone to make sense of it
Can you do that for me.
Markus Kiili
@Masd925
Aug 30 2017 09:12
@georgemitnick You could put them on Codepen or some site like that and post the link.
George Kech.
@georgemitnick
Aug 30 2017 09:12
Copy my code to files
Oh, ok
I'll do that. Give me a minute.
There's still a problem. It's a dice game where you click on roll and it shows you a dice.
The dice img files have to be uploaded but you can make sense without it too
let me show you
George Kech.
@georgemitnick
Aug 30 2017 09:18
The issue that I face is that when I reach the limit of score of 20 that I set the roll still goes on and the "game" var is no assigned false as for the game to stop
I don't know why. I think it's because in the roll function I've said that if dice !== 1 the game goes on. But I specifically mentioned in the hold function that if the score of each player reaches 20 the "game" var is assigned false so the game must stop
The rules of the game as written as comments in the js section
Yvonne
@yvonne6344
Aug 30 2017 09:28
Q:JavaScript 的 Escape Sequences in Strings!
myStr should have encoded text with the proper escape sequences and no spacing.=> can't pass...
var myStr = "FristLine\n\b\\SecondLine\b\r\\ThirdLine";
sabahatullah
@sabahatullah
Aug 30 2017 09:28
image.png
image.png
Hey there,
could someone help me with aligning these bullet points, I have tried vertical align but to no avail
the image can also be seen here https://snag.gy/fpbvgS.jpg
basically black text bullet points should all be inline
sabahatullah
@sabahatullah
Aug 30 2017 09:39
anyone?
Tiago Correia
@tiagocorreiaalmeida
Aug 30 2017 09:42
line-height?
wonder
@wonder2991
Aug 30 2017 09:53
@sabahatullah do you have a link i can look at?
Stephen James
@sjames1958gm
Aug 30 2017 09:56
@yvonne6344 No \b and Frist should be First
Yvonne
@yvonne6344
Aug 30 2017 09:57
@sjames1958gm thanks! already succes!
var myStr="FirstLine\n\\SecondLine\\\rThirdLine";
CamperBot
@camperbot
Aug 30 2017 09:57
yvonne6344 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8412 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 30 2017 09:57
@yvonne6344 :+1:
Stephen James
@sjames1958gm
Aug 30 2017 10:02
@georgemitnick You are getting an error on the lines above game = false so it is not getting set.
VM72 pen.js:38 Uncaught TypeError: Cannot read property 'classList' of null
at HTMLButtonElement.<anonymous> (VM72 pen.js:38)
You are missing the . from those lines
Tiago Correia
@tiagocorreiaalmeida
Aug 30 2017 10:05
@sjames1958gm im imagine I have an array [1,2,3,4,5] and im looping throug it imagine im at the midle array[2] = 3 and I wanna sum the values before arr[2] in this case [0] and [1] and aswell the nnumbers after [3] and [4] how could I map those?
Stephen James
@sjames1958gm
Aug 30 2017 10:06
@tiagocorreiaalmeida That sounds more like reduce than map. I guess I am not sure what you are asking.
Tiago Correia
@tiagocorreiaalmeida
Aug 30 2017 10:09
the idea is having an array like [1,2,3,2,1]
Stephen James
@sjames1958gm
Aug 30 2017 10:09
ok
Tiago Correia
@tiagocorreiaalmeida
Aug 30 2017 10:09
and at some index find a value that would get
the sum of the others from left ro right
like [0] [1] would give 3
Stephen James
@sjames1958gm
Aug 30 2017 10:10
two different sums?
Tiago Correia
@tiagocorreiaalmeida
Aug 30 2017 10:10
so as [3] and [4]
You are given the array {1,100,50,-51,1,1}:
Your function will return the index 1, because at the 1st position of the array, the sum of left side of the index ({1}) and the sum of the right side of the index ({50,-51,1,1}) both equal 1.
like this
Stephen James
@sjames1958gm
Aug 30 2017 10:11
So the value at the index is irrelevant.
Tiago Correia
@tiagocorreiaalmeida
Aug 30 2017 10:11
was thinking about
loop every value and splice it from the start to the value
and after from the value till the end
maybe its a bad idea
Stephen James
@sjames1958gm
Aug 30 2017 10:13
Hmm
Tiago Correia
@tiagocorreiaalmeida
Aug 30 2017 10:16
sounds a bad idea?ahaha
George Kech.
@georgemitnick
Aug 30 2017 10:31
@sjames1958gm I don't see it missing any "." there.
Can you be more specific?
And why Chrome doesn't show that error to me
Oh, I see now.
Stephen James
@sjames1958gm
Aug 30 2017 10:34
@georgemitnick You see the missing .? It is in the two lines right about game = false
George Kech.
@georgemitnick
Aug 30 2017 10:34
Yeah, I saw it. Thanks @sjames1958gm
CamperBot
@camperbot
Aug 30 2017 10:34
georgemitnick sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
Stephen James
@sjames1958gm
Aug 30 2017 10:34
document.querySelector("player-" + activePlayer + "-panel").classList.add("winner"); << should be .player
CamperBot
@camperbot
Aug 30 2017 10:34
:star2: 8413 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 30 2017 10:34
:+1:
George Kech.
@georgemitnick
Aug 30 2017 10:35
Why didn't console at chrome inspect show me any error?
Stephen James
@sjames1958gm
Aug 30 2017 10:35
It did show me an error - that is what I pasted above.
When you went over 20
devtools console?
George Kech.
@georgemitnick
Aug 30 2017 10:36
OK. I change it but the game still doesn't end.
The it still rolls dices and "hold" adds the results to the scores
even though the game has to be over after 20 points
kumquatfelafel
@kumquatfelafel
Aug 30 2017 10:37

devtools console?

:point_up: This is important consideration... you really can't rely on some consoles for a lot of things, e.g. codepen.

Stephen James
@sjames1958gm
Aug 30 2017 10:39
@georgemitnick Changing those two lines fixed it for me. can you save your pen so I can see the latest?
George Kech.
@georgemitnick
Aug 30 2017 10:39
I just did
Stephen James
@sjames1958gm
Aug 30 2017 10:41
@georgemitnick So, when you add a line of code and it doesn't work I always assume the just added might be wrong.
documet.getElementById("current-" + activePlayer).textContent = "0";
This has document misspelled.
Again the devtools console showed this error
limbu
@limbu
Aug 30 2017 10:41
hi guys anyone know an alternative to webkit-search-cancel-button for firefox
Stephen James
@sjames1958gm
Aug 30 2017 10:41
VM147 pen.js:41 Uncaught ReferenceError: documet is not defined
at HTMLButtonElement.<anonymous> (VM147 pen.js:41)
George Kech.
@georgemitnick
Aug 30 2017 10:42
@sjames1958gm Oh yeah.
How did you check for errors in the console? You run the game and then check the console or the console shows it to you right away?
Stephen James
@sjames1958gm
Aug 30 2017 10:43
You have to get the totals over 20
When you press hold
George Kech.
@georgemitnick
Aug 30 2017 10:43
Yeah
and then you check the console to see if there's an error?
Tiago Correia
@tiagocorreiaalmeida
Aug 30 2017 10:50
wtf?
image.png
Stephen James
@sjames1958gm
Aug 30 2017 10:53
@georgemitnick yeah.
George Kech.
@georgemitnick
Aug 30 2017 10:53
@sjames1958gm Thanks, Stephen.
CamperBot
@camperbot
Aug 30 2017 10:53
georgemitnick sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: georgemitnick already gave sjames1958gm points
Tiago Correia
@tiagocorreiaalmeida
Aug 30 2017 10:53
@sjames1958gm any idea what im doign wrong?
Stephen James
@sjames1958gm
Aug 30 2017 10:54
@tiagocorreiaalmeida can't say. haven't done those in a long while
Tiago Correia
@tiagocorreiaalmeida
Aug 30 2017 10:54
will ask in other room thanks anyway :D
George Kech.
@georgemitnick
Aug 30 2017 14:14
Guys, JS can be so annoying some times. Can you take a look and tell me why when I hit two 6's in the row the game doesn't removes current and the whole score from a player:
https://codepen.io/georgekech/pen/EXgGLJ
I run the damn chrome console and it doesn't giving me any errors.
Stephen James
@sjames1958gm
Aug 30 2017 14:18
@georgemitnick Your if (dice != 1) means you will never get to test if dice == 6
George Kech.
@georgemitnick
Aug 30 2017 14:19
How so? If it's not 1 it can be 6
2,3,4,5,6
Stephen James
@sjames1958gm
Aug 30 2017 14:22
@georgemitnick if dice is 6 then it isn't 1 so it does the if and never gets to the else if
if (dice !== 1) {
            roundScore += dice;
            document.getElementById("current-" + activePlayer).textContent = roundScore;
} else if (dice === 6 && lastDice === 6) {
You have to test the more specific case first.
George Kech.
@georgemitnick
Aug 30 2017 14:28
Hmmmmm. Right
George Kech.
@georgemitnick
Aug 30 2017 14:36
Thanks, I get it now @sjames1958gm
CamperBot
@camperbot
Aug 30 2017 14:36
georgemitnick sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8414 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 30 2017 14:36
@georgemitnick :+1:
Aimee
@bestAimee
Aug 30 2017 14:51
image.png
how an i make them top-justify ?one <a> another is button
Moisés Man
@moigithub
Aug 30 2017 15:21
right click -> inspect element
check the "box model"
for extra padding/margins
Aimee
@bestAimee
Aug 30 2017 15:24
thank you @moigithub ,isee
CamperBot
@camperbot
Aug 30 2017 15:24
bestaimee sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3619 | @moigithub |http://www.freecodecamp.com/moigithub
Blauelf
@Blauelf
Aug 30 2017 15:25

I just tried this, but it's off by a pixel or so:

<a class="left">Left anchor element</a>
<button class="right">Right button element</button>
<style type="text/css">
a.left {
  background-color: lightBlue;
  line-height: 40px;
  display: inline-block;
}
button.right {
  height: 40px;
}
</style>

I could add a transform: translateY(-1px); to the button, but that doesn't sound right.

Why is "Tweet" a link, while "New quote" is a button? If they do what I expect them to do, you could make them two buttons.
Aimee
@bestAimee
Aug 30 2017 15:31
because New quote wo want to submit to get some data
but tweet is not
kumquatfelafel
@kumquatfelafel
Aug 30 2017 15:33
Not all buttons require data to submit.
Blauelf
@Blauelf
Aug 30 2017 15:33
And on "Tweet"? I think I'd use window.open with the right URL to open the link in a new window.
kumquatfelafel
@kumquatfelafel
Aug 30 2017 15:34
In a sense, you could think of even a click as a form of data
It's really more a matter of convenience/how you want things to look. You could potentially submit data without a "button", or indeed even have a button that does nothing if you wanted.
Blauelf
@Blauelf
Aug 30 2017 15:41
After reading MDN docs on window.open, I somewhat feel like having found some dinosaur, with support mentioned explicitly for Netscape browsers and Mozilla (but nobody mentioning Firebird AKA Phoenix AKA Firefox). It seemed so modern when I encountered it in the late 1990s.
kumquatfelafel
@kumquatfelafel
Aug 30 2017 15:43

For now 10/01/2017 the differencies of behavior found recently have not still been tested for others Browsers.

o.O

ohh wait. nvm
Blauelf
@Blauelf
Aug 30 2017 15:48
British use of dd/mm/yyyy instead of American mm/dd/yyyy? I prefer yyyy-mm-dd, or yyyy年m月d日, as they are less ambiguous.
kumquatfelafel
@kumquatfelafel
Aug 30 2017 15:50
yeaaah... forgot that we switched things around for a moment.
Blauelf
@Blauelf
Aug 30 2017 15:52
American dates are as stupid as our German numbers. 123 here is "einhundertdreiundzwanzig", translated word by word "one hundred three and twenty".
Jason Luboff
@JLuboff
Aug 30 2017 15:53
one hundred three and twenty...huh... wierd haha
Blauelf
@Blauelf
Aug 30 2017 15:53
But could be worse if I were French. 80 being 4x20 and such things.
kumquatfelafel
@kumquatfelafel
Aug 30 2017 15:56

@Blauelf first time I ever visited Germany, was really young....

We had a lot of fun with fahrt.

Blauelf
@Blauelf
Aug 30 2017 15:59
With "young", do you mean legal drinking age in Germany? With beer being available at 16, harder stuff at 18, some tourists are drunk most of their visit.
kumquatfelafel
@kumquatfelafel
Aug 30 2017 16:00

Like 10 or something. Maybe younger. So definitely not drunk. Then again, don't remember much...

Maybe blackout drunk! :o

Jason Luboff
@JLuboff
Aug 30 2017 16:02
I remember when I was younger, maybe around 12-13, can't quite remember. My family went to Mexico were the legal drinking age is 16. This girl who happened to be 16 was on this boat cruise with us that had unlimited drinks...it didn't end well for her :joy:
I like how my colors are randomly generated...but still end up almost the same.. http://stockapp-jluboff.glitch.me/
Blauelf
@Blauelf
Aug 30 2017 16:09

Since we have alcohol everywhere, and no consequences until you are no longer able to function in some way (which means you've usually already destroyed your whole family), alcoholism is a real problem. In the meantime, politicians celebrate German beer and wine.

On Mallorca, they have banned certain ways of alcohol consumption (like Sangria buckets) because of the German tourists. At least, we are (in)famous for something.

Maybe they should also ban sunburnt Brits? :P
Jason Luboff
@JLuboff
Aug 30 2017 16:15
Alright. Moved my portfolio off of codepen
Blauelf
@Blauelf
Aug 30 2017 16:16
@JLuboff What do you use for "random generation" of colours? Maybe using a random angle and developing your colours in the hsl model might work better.
Jason Luboff
@JLuboff
Aug 30 2017 16:18

@Blauelf Snippet of code:

color:
    'rgba(' +
    randomColorGen() +
    ', ' +
    randomColorGen() +
    ', ' +
    randomColorGen() +
    ', 1.0)'

Where

var randomColorGen = () => Math.ceil(Math.random() * 255);
I'm not too concerned about it (the stocks get cleared daily or if you delete one and re-add it, it'll be a different color)
Blauelf
@Blauelf
Aug 30 2017 16:19
So a 0 component is extremely unlikely.
Jason Luboff
@JLuboff
Aug 30 2017 16:21
Hmmm...I don't think I'd ever get a 0 actually... since I'm using Math.ceil?
Blauelf
@Blauelf
Aug 30 2017 16:24

The only way to get a 0 with your formula is to have Math.random() return a 0. While it isn't impossible, it is unlikely. The formula I would have expected is

() => Math.floor(Math.random() * 256)

which returns values from 0 to 255 evenly distributed.

Jason Luboff
@JLuboff
Aug 30 2017 16:26
Ah, ya you're right it can still be 0 but unlikely
Ryan Williams
@Ryanwfile
Aug 30 2017 17:08
@Marmiz Yes, github pages.
Ogundele Olumide
@Lumexralph
Aug 30 2017 17:16
Hallo :wave:
Ryan Williams
@Ryanwfile
Aug 30 2017 17:17
Anyone familiar with the facebook widget that can help explain why my website when run directly from my computer shows the fb widget and it functions perfectly but when uploaded to github the website doesn't show the fb widget at all? The code for the widget is below.
<div class="fb-like fb_iframe_widget" data-href="https://ryanwfile.github.io/SocialCelebrity.html" data-layout="button_count" data-action="like" data-show-faces="false" data-share="false" fb-xfbml-state="rendered" fb-iframe-plugin-query="action=like&amp;app_id=&amp;container_width=0&amp;href=https%3A%2F%2Ffollows.com%2F&amp;layout=button_count&amp;locale=en_US&amp;sdk=joey&amp;share=false&amp;show_faces=false">
Markus Kiili
@Masd925
Aug 30 2017 17:19
Yo.
Jason Luboff
@JLuboff
Aug 30 2017 17:31
Yo ho Yo ho the pirates life's for me?
Stephen James
@sjames1958gm
Aug 30 2017 17:33
@Lumexralph :wave:
Markus Kiili
@Masd925
Aug 30 2017 17:34
Whats wrong with my code? if (arrrrrrrrr.length>0){...}
Jason Luboff
@JLuboff
Aug 30 2017 17:41
You forgot your pirate booty
if(arrrrrrr.length > 0 && pirate.booty){...}
Markus Kiili
@Masd925
Aug 30 2017 17:41
Arrrrright.
Jason Luboff
@JLuboff
Aug 30 2017 17:42
Uggghhh why does everyone like using mongoose over vanilla mongo when creating a local authentication strategy with passport. I hate mongooosseee
Guess I'm going to have to figure this one out myself
Simon Cordova
@gbsimon87
Aug 30 2017 17:55
Hey all!
Jason Luboff
@JLuboff
Aug 30 2017 17:57
Morning (Afternoon)
Simon Cordova
@gbsimon87
Aug 30 2017 17:58
Almost evening
but bright out so all good
Avoiding No 'Access-Control-Allow-Origin' with a CORS proxy, anyone have a source that works?
vanagasa
@vanagasa
Aug 30 2017 18:20
Hey how can I search for . in string with regular exp? because /.+/g returns length of all char which are in string
Jason Luboff
@JLuboff
Aug 30 2017 18:25
@vanagasa A quick google search shows most people suggest using indexOf
instead of regex
vanagasa
@vanagasa
Aug 30 2017 18:28
oh yeah. Thanks @JLuboff f
CamperBot
@camperbot
Aug 30 2017 18:28
vanagasa sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2179 | @jluboff |http://www.freecodecamp.com/jluboff
Maulik Patel
@patelmr3
Aug 30 2017 19:07
Hello everyone, this site will help you stay up-to-date with topics of your choice. Check it out https://www.postpandit.com/
BrianWilliams28
@BrianWilliams28
Aug 30 2017 19:40
can someone tell me what this line of code means in JS? return !b ? a : gcd(b, a % b);
Jason Luboff
@JLuboff
Aug 30 2017 19:41

@BrianWilliams28

if (!b){
return a;
} else {
gcd(b, a %b);
}

So if b is not false, return a, otherwise run the function gcd

BrianWilliams28
@BrianWilliams28
Aug 30 2017 19:41
@JLuboff what does (!b) mean?
Jason Luboff
@JLuboff
Aug 30 2017 19:42
! inverses b. So if b is true !b is false
BrianWilliams28
@BrianWilliams28
Aug 30 2017 19:42
@JLuboff sorta a confusing way to write it but i guess it makes sense once you understand lol
@JLuboff thanks
CamperBot
@camperbot
Aug 30 2017 19:42
brianwilliams28 sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2180 | @jluboff |http://www.freecodecamp.com/jluboff
BrianWilliams28
@BrianWilliams28
Aug 30 2017 20:26
@JLuboff what would this code mean if (a, b) were two integers?
function gcd(a, b) { return !b ? a : gcd(b, a % b);
@JLuboff does it mean if b = 0 to return A?
Gersho
@Gersho
Aug 30 2017 20:27
an positive integer is considered "true"
Jason Luboff
@JLuboff
Aug 30 2017 20:27
Yes
BrianWilliams28
@BrianWilliams28
Aug 30 2017 20:28
so the last line means if b is not a positive integer to return a, otherwise do gcd(b, a % b);
?
Jason Luboff
@JLuboff
Aug 30 2017 20:29
if b is 0, return a, otherwise return the recursive function
But if b is a negative number it will fail
BrianWilliams28
@BrianWilliams28
Aug 30 2017 20:29
got it thanks
Gersho
@Gersho
Aug 30 2017 20:30
oh you're trying to pull prime factors or something ?
BrianWilliams28
@BrianWilliams28
Aug 30 2017 20:30
smallest common multiple algorithm...its hard
this is what i came up with to do what the above function does, i dont think it works the same though.
function GCD(a, b) {
  var remainder = a % b;
   while (remainder > 0) {
     a = b;
     b = remainder;
     remainder = a % b;
   }
   return b; // outputs 1
 }
Gersho
@Gersho
Aug 30 2017 20:31
oh right i remember yesterday, did you check that link i sent you ? it has a math proof for lcm
BrianWilliams28
@BrianWilliams28
Aug 30 2017 20:31
yeah ive been looking online a lot
i found the solution on stack overflow, and comparing it to my code now
Gersho
@Gersho
Aug 30 2017 20:31
the link provided in the challenge explains what lcm is, but now how to find it
BrianWilliams28
@BrianWilliams28
Aug 30 2017 20:32
i know what lcm is, and that you need the gcd to get it
Jason Luboff
@JLuboff
Aug 30 2017 20:32
@BrianWilliams28 The prior solution does not use a loop at all, just recursion
BrianWilliams28
@BrianWilliams28
Aug 30 2017 20:32
@JLuboff yeah i know
i think the loop is what is causing mine not to work properly
but its what i thought of at the time lol
@Gersho thanks
CamperBot
@camperbot
Aug 30 2017 20:33
brianwilliams28 sends brownie points to @gersho :sparkles: :thumbsup: :sparkles:
:cookie: 375 | @gersho |http://www.freecodecamp.com/gersho
BrianWilliams28
@BrianWilliams28
Aug 30 2017 20:34
so this formula gcd(b, a % b) takes b and multiplies it by the remainder of a and b?
Jason Luboff
@JLuboff
Aug 30 2017 20:35
No, it's a function call. So b becomes a and a % b becomes b
Gersho
@Gersho
Aug 30 2017 20:36
i don't use gcd for the lcm challenge, i use prime factorisation
BrianWilliams28
@BrianWilliams28
Aug 30 2017 20:37
a function call inside the function...i guess thats what recursion is right?
Gersho
@Gersho
Aug 30 2017 20:37
it that's the same one yes

i use this math proof

3, 9, 21
Solution: List the prime factors of each.
3: 3
9: 3 × 3
21: 3 × 7
Multiply each factor the greatest number of times it occurs in any of the numbers. 9 has two 3s, and 21 has one 7, so we multiply 3 two times, and 7 once. This gives us 63, the smallest number that can be divided evenly by 3, 9, and 21. We check our work by verifying that 63 can be divided evenly by 3, 9, and 21.

Jason Luboff
@JLuboff
Aug 30 2017 20:37
A function call inside the same function by which it is calling is recursion, yes
BrianWilliams28
@BrianWilliams28
Aug 30 2017 20:39
@JLuboff and that function call basically keeps looping until b = 0 because of the first line of what is returned right?
Jason Luboff
@JLuboff
Aug 30 2017 20:40
Ya
BrianWilliams28
@BrianWilliams28
Aug 30 2017 20:40
so technically trying to do a while loop to figure it out wasnt as dumb as i thought? lol
Gersho
@Gersho
Aug 30 2017 20:41
if it looks stupid and works, it ain't stupid
i went for a completely different approach but i'll show you mine to compare
function smallestCommons(arr) {
  var fullArr = [];
  var primeFactors = [];
  var factorsQt = {};
  var tempFactors = {};
  var result = 1;

  if (arr[0]>arr[1]){
    arr.reverse();
  }

  for (i=arr[0]; i<=arr[1]; i++){
    fullArr.push(i);
    }

  for (i=0; i<fullArr.length;i++){   // prime factorize each entry
   primeFactors.push([]);

    for (j=2; j<=fullArr[i]; j++){
      while ((fullArr[i] % j) === 0) {
                primeFactors[i].push(j);
                fullArr[i] /= j;
            }
    }
   }

  for (i=0; i<primeFactors.length;i++){    //count factor occurence in object
    tempFactors = {};

    for (j=0; j<primeFactors[i].length;j++){

      tempFactors[primeFactors[i][j]] = (tempFactors[primeFactors[i][j]] || 0) + 1;

      }


      for (var value in tempFactors) {  //transfert temp data to actual object to keep only highest occurence

        if (!factorsQt.hasOwnProperty(value)){
          factorsQt[value] = tempFactors[value];
        }



        if (tempFactors[value] > factorsQt[value]){
          factorsQt[value] = tempFactors[value];
        }

}


    }

  for (var key in factorsQt)  {    // multiply the values
    result *= Math.pow(key, factorsQt[key]);

  }

  return result;
}


smallestCommons([23,18]);
Jason Luboff
@JLuboff
Aug 30 2017 20:43
...thats a lot of loops
Gersho
@Gersho
Aug 30 2017 20:43
is that bad styling ?
Jason Luboff
@JLuboff
Aug 30 2017 20:45
I'm sure you could refactor the code some :D
Chris Juchtmans
@kjuchtmans
Aug 30 2017 20:47
Evening all coders! :wave:
Gersho
@Gersho
Aug 30 2017 20:47
:wave:
Chris Juchtmans
@kjuchtmans
Aug 30 2017 20:50

"Map the Debris" test : why is my below reduce function not accumulating correctly? Though I found a working solution using map() I want to use reduce instead.

Code:

function orbitalPeriod(arr) {
  const GM = 398600.4418;
  const earthRadius = 6367.4447;

  return arr.reduce(function(acc, spaceObject){ 
    let period = 
     Math.round(2*Math.PI*Math.sqrt(Math.pow(earthRadius + spaceObject.avgAlt, 3)/GM));
    return [{name:spaceObject.name, orbitalPeriod:period}];
  }, []);
  }

orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]);

It is returning correctly on a single object array, but not on a multi object array. cheers! k

BrianWilliams28
@BrianWilliams28
Aug 30 2017 20:51
i tested my GCD function and it seems to work equivalently to what the other one does, so i can't figure out why my code doesn't produce the same results.
function smallestCommons(arr) {
  var range = []; // [18, 19, 20, 21, 22, 23]
  // smallestCommons(23,18) => smallestCommons(18,23);
  var sort = arr.sort(function(a, b) { 
    return a - b;
  });
  var min = sort[0];
  var max = sort[1];
  // creating the range
  for (var i = sort[0]; i <= sort[1]; i++) { 
  range.push(i);
 }
  // function to get the greatest common divisor
 function GCD(a, b) {
  var remainder = a % b;
   while (remainder > 0) {
     a = b;
     b = remainder;
     remainder = a % b;
   }
   return b; // outputs 1
 } 
function LCM(a, b) {
  return a * b / GCD(max, min);
}
 var SCM = min;
 for (var i = 0; i < range.length; i++) {
   SCM = LCM(SCM, range[i]);
 }
  console.log(SCM);
  return SCM;
}

smallestCommons([23,18]);
Adam Bohannon
@abohannon
Aug 30 2017 20:57
Curious what you guys think about FCC's algo challenges with regard to technical interviews. I've tried a bunch of different coding challenge sites to continue my practice and even some of the easiest algos stump me . They often deal with things that aren't covered in FCC's challenges. I've encountered a lot of bitwise stuff, binary trees, and other CS heavy stuff.
John
@AnonymousLords
Aug 30 2017 21:27
@BrianWilliams28 is that advanced algorithm?
Blauelf
@Blauelf
Aug 30 2017 21:42
@BrianWilliams28 What if you use return a * b / GCD(a, b);, or, numerically better, return a / GCD(a, b) * b;?
I think this version of gcd looks unfamiliar, but correct.
LiciniusRex
@hashtagyolo1
Aug 30 2017 21:51
Anyone can see why this call isn't working? Can't see what I'm missing
Diego Mayer
@Chrono79
Aug 30 2017 21:54
@hashtagyolo1 add &origin=* to the url, and you have to actually call your function
LiciniusRex
@hashtagyolo1
Aug 30 2017 21:55
Thanks @Chrono79
CamperBot
@camperbot
Aug 30 2017 21:55
hashtagyolo1 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4531 | @chrono79 |http://www.freecodecamp.com/chrono79
Stephen James
@sjames1958gm
Aug 30 2017 21:55
This message was deleted
LiciniusRex
@hashtagyolo1
Aug 30 2017 22:05
Updated it @Chrono79 but still not getting any luck with it. Am I missing something really obvious again?
Jason Luboff
@JLuboff
Aug 30 2017 22:07
@hashtagyolo1 json.title does not exist
@hashtagyolo1 Add console.log(json); inside your getJSON fnction and you'll see what you get in the console
Stephen James
@sjames1958gm
Aug 30 2017 22:08
@hashtagyolo1 Try this to see the format of the json
  $(".test").html(JSON.stringify(json));
It will display in the browser. There are browser plugins for chrome that allow you to see formatted json.
Then you could plug the URL into your address bar of your browser
LiciniusRex
@hashtagyolo1
Aug 30 2017 22:09
@sjames1958gm that definitely brought something back
thanks
Eric Hasegawa
@EricHasegawa
Aug 30 2017 22:23
https://codepen.io/erichasegawa/pen/brdYKd Can anyone tell me why when I open this on mobile, the bottom of the screen cuts out way too early?
DistinctWolf
@DistinctWolf
Aug 30 2017 22:27

nodejs help please, I don't know what's wrong

 if (!user.validPassword(password)) {
          return done(null, false, { message: 'Incorrect password.' });
        }

and I have this in the schema

UserSchema.methods.validPassword = function(password, cb) {  
    bcrypt.compare(password, this.password, function(err, isMatch) {
      if (err) {
        return cb(err);
      }
      cb(null, isMatch);
    });
  };

It keeps redirecting to the failure page even when the password is right in the routes please help

Stephen James
@sjames1958gm
Aug 30 2017 22:33
@FlashHero Don't you need to supply validPassword with a callback function?
Ogundele Olumide
@Lumexralph
Aug 30 2017 22:36
@FlashHero your validPassword seems to use 2 parameters
@FlashHero UserSchema.methods.validPassword = function(password, cb) and your code if (!user.validPassword(password) the callback cb as @sjames1958gm said is missing maybe it could be the issue
@sjames1958gm shame chamberlain rejected Chelsea
Stephen James
@sjames1958gm
Aug 30 2017 22:40
 user.validPassword(password, (err, match) => { if (err)  done(null, false, { message: 'Incorrect password.' });});
@Lumexralph guess he really didn't want those better trophys
Ogundele Olumide
@Lumexralph
Aug 30 2017 22:41
@sjames1958gm :smile:
DistinctWolf
@DistinctWolf
Aug 30 2017 22:44
@sjames1958gm oh so that's the function that holds the match thanks
CamperBot
@camperbot
Aug 30 2017 22:44
flashhero sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8415 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
DistinctWolf
@DistinctWolf
Aug 30 2017 22:45
@Lumexralph thanks
Ogundele Olumide
@Lumexralph
Aug 30 2017 22:45
@FlashHero when you hear callback hell that's node for you :smile:
DistinctWolf
@DistinctWolf
Aug 30 2017 22:47
yeah the syntax ain't that hard what's hard is the callbacks and how and where they go. I'm struggling
are y'all soccer fans
Ogundele Olumide
@Lumexralph
Aug 30 2017 22:48
@FlashHero we'll eventually get a hang of it anyway
@FlashHero i think I have soft spot for Manchester United @sjames1958gm profile pics talks about his
Stephen James
@sjames1958gm
Aug 30 2017 22:50
Computers and soccer thats about it for me
DistinctWolf
@DistinctWolf
Aug 30 2017 22:51
lol what do y'all think of neymar's transfer
Ogundele Olumide
@Lumexralph
Aug 30 2017 22:56
@FlashHero transfers are now crazy, i hate the transfer market
small clubs are doomed to suffer except they get oil rich owners
DistinctWolf
@DistinctWolf
Aug 30 2017 22:59
yeah small players with little experience are getting paid very high but I think that was the best decision for PSG
DistinctWolf
@DistinctWolf
Aug 30 2017 23:41
small players meaning other people not neymar