These are chat archives for FreeCodeCamp/HelpJavaScript

16th
Aug 2017
Ogundele Olumide
@Lumexralph
Aug 16 2017 00:01
@monkingame because in the IIFE that returned a function, no value was passed for str when the expression was immediately invoked which made str undefined
@monkingame remember you did this at the end of the function expression ( ) ? no value was passed for str there which made it undefined
@monkingame consider this
const cat = (function (str) {

let init = "";
return function () {
         return init += str.length;
         }
})("a");
console.log(cat());   // 1
@sjames1958gm hey bro!
Stephen James
@sjames1958gm
Aug 16 2017 00:02
@luccifer00 To build the DOM in js only
        var span = document.createElement("span");
        div.setAttribute('class', 'jumbotron');
        span.id = "title"
        span.classList.add("title")
        span.textContent = data[1][i];
        div.appendChild(span);
        div.appendChild(document.createElement("br"));
        div.appendChild(document.createTextNode(data[2][i]));
        var a = document.createElement("a");
        a.setAttribute("href", data[3][i])
        a.textContent = "More Info . . .";
        div.appendChild(a);
@Lumexralph :wave:
monk
@monkingame
Aug 16 2017 00:02
oh thanks,I need some time to understand @Lumexralph @sjames1958gm
CamperBot
@camperbot
Aug 16 2017 00:02
monkingame sends brownie points to @lumexralph and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: monkingame already gave sjames1958gm points
:star2: 2047 | @lumexralph |http://www.freecodecamp.com/lumexralph
Stephen James
@sjames1958gm
Aug 16 2017 00:03
@monkingame :+1:
Ogundele Olumide
@Lumexralph
Aug 16 2017 00:03
@sjames1958gm howdy ?
@monkingame cool
Stephen James
@sjames1958gm
Aug 16 2017 00:03
@Lumexralph How's it going
Ogundele Olumide
@Lumexralph
Aug 16 2017 00:04
@sjames1958gm going well, to sometime off work to attend a 2 weeks bootcamp where I had to build a full stack web app
Guderian Raborg
@hypercuber
Aug 16 2017 00:04
@Chrono79 Oh, nice. Thanks.
CamperBot
@camperbot
Aug 16 2017 00:04
hypercuber sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4524 | @chrono79 |http://www.freecodecamp.com/chrono79
Stephen James
@sjames1958gm
Aug 16 2017 00:04
@Lumexralph Cool - what was the stack?
Ogundele Olumide
@Lumexralph
Aug 16 2017 00:05
@sjames1958gm the experience was a game changer for me and it threw me off my feet a while
Stephen James
@sjames1958gm
Aug 16 2017 00:05
@Lumexralph I guess they don't call it a bootcamp for nothing :)
Ogundele Olumide
@Lumexralph
Aug 16 2017 00:06
@sjames1958gm it was React on client side, NodeJS server, Postgresql for database and sequelize as the ORM
Guderian Raborg
@hypercuber
Aug 16 2017 00:06
I am not good with css. Can someone tell me what is the simplest way to move canvas to center of page. My way works but prob there is a better way.
https://codepen.io/hypercuber/pen/oeoWBV?editors=1111
Ogundele Olumide
@Lumexralph
Aug 16 2017 00:07
@sjames1958gm it was like wow! all the mystery of the web demystified but I struggled initially and it showed my weakness and what I needed to work on
@sjames1958gm how've you been?
Stephen James
@sjames1958gm
Aug 16 2017 00:09
@hypercuber flex is fine choice - you can use align-items alongside justify-content instead of align-self in the .canvas
@Lumexralph Good. Getting ready for a demo with amazon.
@Lumexralph What did you use for the bundling
Guderian Raborg
@hypercuber
Aug 16 2017 00:15
@sjames1958gm thanks
CamperBot
@camperbot
Aug 16 2017 00:15
hypercuber sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8323 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
BrianWilliams28
@BrianWilliams28
Aug 16 2017 00:21
hey guys, is it possible to loop through multiple argument arrays like in the below for example?
function uniteUnique(arr) {
  var args = Array.prototype.slice.call(arguments);





  return arr;
}

uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
korzo
@korzo
Aug 16 2017 00:23
@BrianWilliams28 Of course, but you'll need 2 loops
BrianWilliams28
@BrianWilliams28
Aug 16 2017 00:23
what?
Ogundele Olumide
@Lumexralph
Aug 16 2017 00:24
@sjames1958gm still working on it, don't know about bundling yet
Gersho
@Gersho
Aug 16 2017 00:24
well you have 3 arguments, each being an array
BrianWilliams28
@BrianWilliams28
Aug 16 2017 00:26
like the first hint says
since we don't know how many arguments there are, it's best to loop through the arguments before looping through the arrays
Gersho
@Gersho
Aug 16 2017 00:26
oh
BrianWilliams28
@BrianWilliams28
Aug 16 2017 00:26
is it possible to do something like
Gersho
@Gersho
Aug 16 2017 00:27
you're looking for the arguments object
BrianWilliams28
@BrianWilliams28
Aug 16 2017 00:27
for (var i = 0; i < arguments.length; i ++) {
stuff here
}
i need to break each argument array apart
Gersho
@Gersho
Aug 16 2017 00:29
i'd go for a for in but whatever works for you
BrianWilliams28
@BrianWilliams28
Aug 16 2017 00:29
in hold it in a container
and*
Joseph
@revisualize
Aug 16 2017 01:28
@BrianWilliams28 Each arguments array like object is broken up to be accessed like an array.
@BrianWilliams28 WHat do you mean?
Aaron Bell
@awb715
Aug 16 2017 01:44
does jquery work with handlebars templates?
Margaret
@Margaret2
Aug 16 2017 01:55
@BrianWilliams28 you just want to know how many arrays there are? just do args.length
no need for a for loop...
Stephen James
@sjames1958gm
Aug 16 2017 01:55
@awb715 Yes because handlebars renders to HTML in the backend and jquery works in the front end
John
@AnonymousLords
Aug 16 2017 02:45
Why wont this work?

function truncateString(str, num) {
if (str.length > num) {
return str.split("").slice(0, num).join("") + ("...");
  }
  else return str;
}

truncateString("aws2", 11);
If the string is bigger then my max, it should replace with dots, else return the string.
korzo
@korzo
Aug 16 2017 02:48
@AnonymousLords ... is part of the string
John
@AnonymousLords
Aug 16 2017 02:48
Oh
Okay
korzo
@korzo
Aug 16 2017 02:49
@AnonymousLords but there is special case if length is < 4
Claudio Restifo
@Marmiz
Aug 16 2017 02:49
@AnonymousLords doesn't the challenge ask you to count ... as part of the string as well?
John
@AnonymousLords
Aug 16 2017 02:49
Yeah

function truncateString(str, num) {

if (str.length > num) {
return str.split("").slice(0, num - 3).join("") + ("...");
  }
 if (num <= 3) {
   return str.split("").slice(0, num).join("") + ("...");
 }
  else return str;
}

truncateString("aws2", 11);
wont work?
Claudio Restifo
@Marmiz
Aug 16 2017 02:52
@AnonymousLords also, just for the sake of clarity, you don't necessary need to split the string, you can just slice it :)
John
@AnonymousLords
Aug 16 2017 02:53
Okay removed split and join
i added else return str; and that fixed mostly all of it
...
Claudio Restifo
@Marmiz
Aug 16 2017 02:58

@AnonymousLords mind your if condition:

if (str.length > num) { return}
if (num <= 3) {return}

truncateString("aws2", 1);

Which case do you think it triggers?

John
@AnonymousLords
Aug 16 2017 02:58
the 2nd one
Claudio Restifo
@Marmiz
Aug 16 2017 02:58
have you tried it?
John
@AnonymousLords
Aug 16 2017 02:59
truncateString("ws2", 11); returns the string
truncateString("ws2", 2); returns 'ws...'
truncateString("ws2", 2); returns 'w...'
Claudio Restifo
@Marmiz
Aug 16 2017 03:01
Sorry missed that :)
John
@AnonymousLords
Aug 16 2017 03:01
:P
realiuzed my error
John
@AnonymousLords
Aug 16 2017 03:12
thanks i got it @Marmiz @korzo @moigithub
CamperBot
@camperbot
Aug 16 2017 03:12
anonymouslords sends brownie points to @marmiz and @korzo and @moigithub :sparkles: :thumbsup: :sparkles:
:cookie: 383 | @korzo |http://www.freecodecamp.com/korzo
:star2: 1023 | @marmiz |http://www.freecodecamp.com/marmiz
:star2: 3591 | @moigithub |http://www.freecodecamp.com/moigithub
John
@AnonymousLords
Aug 16 2017 03:12

function truncateString(str, num) {

if (num < str.length && num > 3) {
return str.slice(0 , num - 3) + ("...");
}
if (num < 3) {
  return str.slice(0 , num) +  ("...");
}
  else return str;
}

truncateString("Absolutely Longer", 1);
Claudio Restifo
@Marmiz
Aug 16 2017 03:17
@AnonymousLords just a "design" thing, you can turn the function from else return str to simply return str.
Since if you reached that case means that the previous one has not returned yet :)
John
@AnonymousLords
Aug 16 2017 03:37
Okay
:)
Ginger
@GingerChew
Aug 16 2017 03:49
Hey all, I'm trying to do this number to roman numerals function and I found this example, but I don't understand how it works
function romanize (num) {
    var digits = String(+num).split(""),
        key = ["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM",
               "","X","XX","XXX","XL","L","LX","LXX","LXXX","XC",
               "","I","II","III","IV","V","VI","VII","VIII","IX"],
        roman = "",
        i = 3;
    while (i--)
        roman = (key[+digits.pop() + (i * 10)] || "") + roman;
    return Array(+digits.join("") + 1).join("M") + roman;
}
To me the math doesn't make sense?
korzo
@korzo
Aug 16 2017 03:54
@GingerChew You need 2 arrrays (or object). One for literals and one for numeric values
Ginger
@GingerChew
Aug 16 2017 03:57
I mean the one above works...Why do I need one for numeric values?
korzo
@korzo
Aug 16 2017 04:10
@GingerChew Yeah, it works, but nobody knows why :)
You need numeric values to subtract from num
Gary Siu
@GarySiu
Aug 16 2017 04:11
That's an interesting solution
heroiczero
@heroiczero
Aug 16 2017 04:11
you could set the numeric to each value of the roman numeral
@GingerChew
Ginger
@GingerChew
Aug 16 2017 04:21
@korzo there has to be someone lol
korzo
@korzo
Aug 16 2017 04:23
@GingerChew I run into this solution before, but I never got logic behind it.
Ginger
@GingerChew
Aug 16 2017 04:24
@korzo fair enough, so for the numeric values do I just make it into an object? that seems easiest
korzo
@korzo
Aug 16 2017 04:25
@GingerChew Yes, that's the way I went. but most people use 2 arrays
heroiczero
@heroiczero
Aug 16 2017 04:26
Generally everyone uses two arrays @GingerChew
Gary Siu
@GarySiu
Aug 16 2017 04:26
@GingerChew https://goo.gl/MP4ASw
Ginger
@GingerChew
Aug 16 2017 04:28
@GarySiu oh shit, thats awesome, thanks m8
CamperBot
@camperbot
Aug 16 2017 04:28
gingerchew sends brownie points to @garysiu :sparkles: :thumbsup: :sparkles:
:cookie: 439 | @garysiu |http://www.freecodecamp.com/garysiu
Gary Siu
@GarySiu
Aug 16 2017 04:29
It's still super smart how they structured the data though. Wonder how long it took them to work out the pattern.
korzo
@korzo
Aug 16 2017 04:30
@GarySiu also is it based on math or just trial->error ?
Gary Siu
@GarySiu
Aug 16 2017 04:37
@korzo I think they worked out they only needed to encode the last 3 digits for all valid roman numerals. And worked out the math to all the cases from there?
Ginger
@GingerChew
Aug 16 2017 04:38
also just realized there was a hint option on the page, doh
Markus Kiili
@Masd925
Aug 16 2017 04:57
@GingerChew You can make a solution with just var ROM = [ 'I', 'V', 'X', 'L', 'C', 'D', 'M' ];, but it too is unreadable.
Ginger
@GingerChew
Aug 16 2017 04:59
would the example I gave before be an example of advanced coding?
Markus Kiili
@Masd925
Aug 16 2017 05:00
@GingerChew No. Advanced coding is code that flows into the brain without effort.
heroiczero
@heroiczero
Aug 16 2017 05:01
Try to make efficient code.
Markus Kiili
@Masd925
Aug 16 2017 05:05
Clarity of the code is usually the most important thing. Efficiency and code length also have some value.
Ginger
@GingerChew
Aug 16 2017 05:10
I get that, but like in the hints, it give beginner, intermediate, and advanced. Keeping in mind that clarity and efficiency are more important, is there any benefit to doing it the intermediate or advanced way if the beginner way accomplishes the same thing?
Long Nguyen
@longnt80
Aug 16 2017 05:11
@GingerChew sometimes, it is subjective to decide which is beginner or advanced
Markus Kiili
@Masd925
Aug 16 2017 05:12
@GingerChew Not sure what you mean by that.
heroiczero
@heroiczero
Aug 16 2017 05:13
@GingerChew does the beginner way more clear or the advanced
Long Nguyen
@longnt80
Aug 16 2017 05:14
@heroiczero I think he said that assuming the beginner's way is more clear
heroiczero
@heroiczero
Aug 16 2017 05:15
@GingerChew in addition, there are more stuff in advanced solution probably has like https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator and other methods. Always challenge yourself, You learn more
Markus Kiili
@Masd925
Aug 16 2017 05:16
If advanced means fancy code that is harder to read and understand by others, then beginner way is better.
Long Nguyen
@longnt80
Aug 16 2017 05:16
just view it as different ways to solve the same problem
Markus Kiili
@Masd925
Aug 16 2017 05:17
If you mean different paradigms, like whether to use loops or methods, then it is mostly matter of taste.
Ginger
@GingerChew
Aug 16 2017 05:27
function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line
  //for as long as collection is less than the length of collections, i will increase
  var prop = source;
  var i = 0;
  for (prop in collection) {
    //if collection[i] has the property of srcKey, then it will slice it into arr
    if (collection.hasOwnProperty(prop)){
      arr += collection[i];
      i++;
    }
    i++;
  }

  // Only change code above this line
  return arr;
}
This function is only returning one object from the array, am I setting up my iterator wrong?
Stanley Su
@stanley-su
Aug 16 2017 05:29
@GingerChew To add an item to an array, you should use the .push function. e.g:
arr.push(collection[i]);
Ginger
@GingerChew
Aug 16 2017 05:30
okay, I was using collection.slice(i) before but it wasn't working right either
@stanley-su thanks m8
CamperBot
@camperbot
Aug 16 2017 05:30
gingerchew sends brownie points to @stanley-su :sparkles: :thumbsup: :sparkles:
:cookie: 122 | @stanley-su |http://www.freecodecamp.com/stanley-su
heroiczero
@heroiczero
Aug 16 2017 05:35
@GingerChew for (key in collection) will cycle through the property in a object collection
Ginger
@GingerChew
Aug 16 2017 05:35
@heroiczero I just got that, I'm gonna try something else
Markus Kiili
@Masd925
Aug 16 2017 05:39
@GingerChew for...in loop is not meant for iterating over array indices. A simple for loop or an array iterator is better.
@GingerChew On that challenge, you need two nested loops or iterations over collection and source's keys.
gchis66
@gchis66
Aug 16 2017 05:48
hey guys! Can I DM any of you for some help sending a POST request?
Joseph
@revisualize
Aug 16 2017 05:58
@gchis66 Why can't you just ask here? If you're able to post your question in chat you'll have EVERYONE in chat looking at it instead of just the one person you're in a PM with.
I've had people PM me... And I've walked away not seeing their question. Or I've been forced to walk away due to work.
Then ... They're stuck waiting for me to respond. But, I'm not there to respond.
Hence the reason I don't respond to unsolicited PMs.
gchis66
@gchis66
Aug 16 2017 06:00
well its for a coding practice test for a potential employer and i didnt want a bunch of people hitting them at once
i guess it doesnt matter though
var lunch; var xhr = new XMLHttpRequest(); xhr.open("POST", '', true); xhr.send(lunch ="eaten");
take a look at programmer.exults.com for the exact question
Joseph
@revisualize
Aug 16 2017 06:04
Hmm.
gchis66
@gchis66
Aug 16 2017 06:05
thats the code i put into the chrome console. it goes through but i am not receiving a response or anything
Joseph
@revisualize
Aug 16 2017 06:07
@gchis66
image.png
@gchis66 I did this:
var http = new XMLHttpRequest();
var url = "http://programmer.exults.com/";
var params = "lunch=eaten";
http.open("POST", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

http.onreadystatechange = function() {//Call a function when the state changes.
    if(http.readyState == 4 && http.status == 200) {
        alert(http.responseText);
    }
}
http.send(params);
gchis66
@gchis66
Aug 16 2017 06:10
lol this is clearly above my coding level
Joseph
@revisualize
Aug 16 2017 06:11
@gchis66 ahh.. I figured it out.
@gchis66 curl --data "lunch=eaten" http://programmer.exults.com/
gchis66
@gchis66
Aug 16 2017 06:12
is that done via command prompt?
Joseph
@revisualize
Aug 16 2017 06:13
@gchis66 Yeah.
gchis66
@gchis66
Aug 16 2017 06:13
gonna go give it a try brb
Joseph
@revisualize
Aug 16 2017 06:13
@gchis66 It tells you to Go to farfin.php
@gchis66 So, I went to http://programmer.exults.com/farfin.php
@gchis66 Then, in the console: document.cookie="lunch=eaten"
@gchis66 That's when it gives you the actual test.
gchis66
@gchis66
Aug 16 2017 06:14
lmao
Joseph
@revisualize
Aug 16 2017 06:15
@gchis66 I hope that helps.
gchis66
@gchis66
Aug 16 2017 06:16
definitely. Thanks for the help. I'm obv not ready for this just yet though.
Can you let me know how you went about doing the curl in cmd? I can't just open it up and type that into it can I?
Joseph
@revisualize
Aug 16 2017 06:16
@gchis66 What OS?
@gchis66 I'm running Ubuntu 16.10 ... So, I can just curl away.
gchis66
@gchis66
Aug 16 2017 06:17
im on windows 10
Joseph
@revisualize
Aug 16 2017 06:18
@gchis66 You'll need to download something I think to CURL
gchis66
@gchis66
Aug 16 2017 06:18
ok
Joseph
@revisualize
Aug 16 2017 06:18
@gchis66 There's also Powershell: Invoke-RestMethod
@gchis66 But, you'd need to research that commandlet
@gchis66 Hey, I normally don't really ask. But, could you actually send me that brownie point?
gchis66
@gchis66
Aug 16 2017 06:19
i have no clue how to do that
lol
ok
Joseph
@revisualize
Aug 16 2017 06:20
You @ someone and thank them.
gchis66
@gchis66
Aug 16 2017 06:20
thanks @revisualize
CamperBot
@camperbot
Aug 16 2017 06:20
gchis66 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4435 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Aug 16 2017 06:20
Sweet. My streak won't die now.
gchis66
@gchis66
Aug 16 2017 06:20
is it just for fun or do you get benefits for a higher brownie point count?
Joseph
@revisualize
Aug 16 2017 06:21
@gchis66 No benefit other than trying to get to 365 days of FreeCodeCamp Be it via assisting in chat or by completing lessons.
Alex
@alexandrupintilei
Aug 16 2017 06:42

function convertToRoman(num) {
 //TABLE OF EQUIVALENCES
  var arrConv=[{0:' '},{1:'I'},{2:'II'},{3:'III'},{4:'IV'},{5:'V'},{6:'VI'},{7:'VII'},{8:'VIII'},{9:'IX'},{10:'X'},{20:'XX'},{30:'XXX'},{40:'XL'},{50:'L'},{60:'LX'},{70:'LXX'},{80:'LXXX'},{90:'XC'},{100:'C'},{200:'CC'},{300:'CCC'},{400:'CD'},{500:'D'},{600:'DC'},{700:'DCC'},{800:'DCCC'},{900:'CM'},{1000:'M'},{2000:'MM'},{3000:'MMM'},{4000:'MMMM'},{5000:'MMMMM'},{6000:'MMMMMM'},{7000:'MMMMMMM'},{8000:'MMMMMMMM'},{9000:'MMMMMMMMM'}];

  //First we break down the number into its units
  //and create an array ex: 652 ==> [600, 50, 2]
  var arr=[num.length];
  arr=num.toString().split("").reverse();
  var i=1;
  for (var k=0;k<arr.length;k++){
    arr.splice(k,1,arr[k]*i);
    i*=10;
  }

  //We make an array of objects with the number and the roman number equivalence
 var romansArray=[];
  for (i=0;i<arr.length;i++){
    var val=arrConv.filter(function(obj){
       return obj[arr[i]];
     })[0];
    romansArray.push(val);
  }

  //I get rid of all the null values
  var result=romansArray.filter(function(val){
    return (val!=null);
  });

  //It returns the string with the roman number
  return result.map(function(value,key){
    return result[key][arr[key]];
  }).reverse().join("").trim();
}

convertToRoman(36);
Why this code dosent pass the quest?
Emmanuel Akodia
@akodiaemma
Aug 16 2017 06:57
is it possible to download the source code of an interactive web application?
Abhinav Mishra
@abhinav-m
Aug 16 2017 07:13
anyone here familiar with the react game of life app
kumquatfelafel
@kumquatfelafel
Aug 16 2017 07:14
familiar with the game of life, but not in react.
Abhinav Mishra
@abhinav-m
Aug 16 2017 07:15
@kumquatfelafel the cells on the edge of the 2d array
do i need to wrap around the column / row
to check for their neighbours
when simulating the next generation?
Manish Giri
@Manish-Giri
Aug 16 2017 07:17
@abhinav-thinktank :hand:
Abhinav Mishra
@abhinav-m
Aug 16 2017 07:17
@Manish-Giri :wave:
:clap: namaste
lol
Manish Giri
@Manish-Giri
Aug 16 2017 07:18
lol
Abhinav Mishra
@abhinav-m
Aug 16 2017 07:18
@Manish-Giri in the game of life im using a 2d array
Manish Giri
@Manish-Giri
Aug 16 2017 07:18
@abhinav-thinktank I represented my board as a 2d array
Abhinav Mishra
@abhinav-m
Aug 16 2017 07:18
if the edge of my matrix has live cells
aah yes
so if the first row has live cells
Manish Giri
@Manish-Giri
Aug 16 2017 07:18
then I used .map()
Abhinav Mishra
@abhinav-m
Aug 16 2017 07:18
oh ok..
what i wanna ask is if the first row has live cells
Manish Giri
@Manish-Giri
Aug 16 2017 07:19
oh wrap around
Abhinav Mishra
@abhinav-m
Aug 16 2017 07:19
yea
Manish Giri
@Manish-Giri
Aug 16 2017 07:19
yea I used wrap around
like for example
for the first row leftmost cell
Abhinav Mishra
@abhinav-m
Aug 16 2017 07:19
so basically the last row will count as its neighbours right
kumquatfelafel
@kumquatfelafel
Aug 16 2017 07:19
The way I've done it didn't. But you could make it wrap around as well. :point_up:
Manish Giri
@Manish-Giri
Aug 16 2017 07:19
it's left neighbor will be the last cell in first row itself
Abhinav Mishra
@abhinav-m
Aug 16 2017 07:19
aah ok
similarly for top -> bottom
is it necessary to wrap around?
Manish Giri
@Manish-Giri
Aug 16 2017 07:20
similarly for last cell in first row, it's right cell will be 0th cell in first row
Abhinav Mishra
@abhinav-m
Aug 16 2017 07:20
technically the description says an infinite 2d grid
kumquatfelafel
@kumquatfelafel
Aug 16 2017 07:20
really, the board would be infinite, so wraparound might be a more realistic compromise in terms of a computer program.
Abhinav Mishra
@abhinav-m
Aug 16 2017 07:20
yeah..
@Manish-Giri did you check the whole board every generation for next generation?
im thinking of a solution where i only check the live cells
Manish Giri
@Manish-Giri
Aug 16 2017 07:21
@abhinav-thinktank yup
Abhinav Mishra
@abhinav-m
Aug 16 2017 07:21
damn ok
you used redux for this?
i forgot
Manish Giri
@Manish-Giri
Aug 16 2017 07:21
if you don't check dead cells
Abhinav Mishra
@abhinav-m
Aug 16 2017 07:21
i think i asked you before
Manish Giri
@Manish-Giri
Aug 16 2017 07:21
you won't be able to make them come alive
Abhinav Mishra
@abhinav-m
Aug 16 2017 07:22
@Manish-Giri i mean if i check the live cells neighbours
Manish Giri
@Manish-Giri
Aug 16 2017 07:22
no i didn't know redux back then
abhi also I know thoda thoda
Abhinav Mishra
@abhinav-m
Aug 16 2017 07:22
that will give me enough to simulate the next generation
oh ok..
Manish Giri
@Manish-Giri
Aug 16 2017 07:22
bc dimaag kharab ho jata hai itna pad pad ke
Abhinav Mishra
@abhinav-m
Aug 16 2017 07:22
someone suggested i do it with redux
:P
Manish Giri
@Manish-Giri
Aug 16 2017 07:22
now i'm doing ruby
Abhinav Mishra
@abhinav-m
Aug 16 2017 07:22
oh god
itna mai nahi karsakta :P
Manish Giri
@Manish-Giri
Aug 16 2017 07:22
lol
Abhinav Mishra
@abhinav-m
Aug 16 2017 07:22
js se khush hu abhi
ruby swift python java
marjauga
Manish Giri
@Manish-Giri
Aug 16 2017 07:23
add typescript too
lol
Abhinav Mishra
@abhinav-m
Aug 16 2017 07:23
:gun:
kumquatfelafel
@kumquatfelafel
Aug 16 2017 07:23
@abhinav-thinktank If you check live cells and the dead neighbors of live cells, this would suffice, yes.
Abhinav Mishra
@abhinav-m
Aug 16 2017 07:24
@Manish-Giri @kumquatfelafel ok ty
CamperBot
@camperbot
Aug 16 2017 07:24
abhinav-thinktank sends brownie points to @manish-giri and @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 610 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:star2: 6422 | @manish-giri |http://www.freecodecamp.com/manish-giri
Abhinav Mishra
@abhinav-m
Aug 16 2017 07:24
im gonna go work on it
Huỳnh Trần Khanh
@khanh2003
Aug 16 2017 07:25
You can use ES6 Map to simulate an infinite field.
kumquatfelafel
@kumquatfelafel
Aug 16 2017 07:38
@alexandrupintilei This is result of your function, running test cases. https://repl.it/KKao/3
kumquatfelafel
@kumquatfelafel
Aug 16 2017 07:51
@alexandrupintilei and here's some added console.logs to give an even clearer picture. https://repl.it/KKao/4
So there's a very quick fix solution to your problem.
Ankur sharma
@ankur1163
Aug 16 2017 08:19
has anyone looked at cssgrid
it looks amazing
any views on cssgrid?
Lay
@L-AY
Aug 16 2017 08:21
Despite adding the route to use id dynamically, my app is unable to retrieve data from db(mongo) where I try to enter http://localhost:3000/api/customers/<_id of document from db>
// get a customer; we pass id to get customer
router.get('/:id', (req, res) => {
  Customer.getCustomers(req.params.id,(err, customer) =>{
    if(err){
      console.log(err);
      res.send(err);
    }
    res.json(customer); // feeding out a json array of customers
  });
});
Emmanuel Akodia
@akodiaemma
Aug 16 2017 08:47
any marijuana fans in the house?
Markus Kiili
@Masd925
Aug 16 2017 08:58
@akodia488 I like to listen to music about using it. So kind of yes.
Emmanuel Akodia
@akodiaemma
Aug 16 2017 09:00
@Masd925 that doenst really count bro :) where youfrom?
Markus Kiili
@Masd925
Aug 16 2017 09:00
@akodia488 Finland.
Huỳnh Trần Khanh
@khanh2003
Aug 16 2017 09:00
what does marijuana mean?
Ankur sharma
@ankur1163
Aug 16 2017 09:01
@khanh2003 drug
Markus Kiili
@Masd925
Aug 16 2017 09:01
@khanh2003 Psychoactive drug from Cannabis sativa plant.
Huỳnh Trần Khanh
@khanh2003
Aug 16 2017 09:01
i am a drug hater 😈
Emmanuel Akodia
@akodiaemma
Aug 16 2017 09:03
@khanh2003 its a name of hemp plant smoked to get high
@Masd925 thought its legal that area
Blauelf
@Blauelf
Aug 16 2017 09:19
If alcohol was measured on the same scale as cannabis, it would be banned immediately, with anybody having their apple juice going yeasty being declared a criminal. Something like that. Just that alcohol is part of our "culture". Or lack of.
Stephen James
@sjames1958gm
Aug 16 2017 09:22
@L-AY What is the error? Not found? Have you tried to use the mongo shell to retrieve using the same id
Markus Kiili
@Masd925
Aug 16 2017 09:30
@Blauelf Fermented fruit has been an important energy source at some point for humans. A genetic mutation allows us to burn alcohol 20 times faster than some of our relative animals. Why is alcohol never on a food circle? At least on the paleo diet one.
Blauelf
@Blauelf
Aug 16 2017 09:35

At least in Germany, there's no clear line after which it's "C2 abusus", so there's nobody to keep you from becoming an addict. Only when you stop "functioning", when it's too late, people notice.

Not sure how alcohol affects metabolism. At least athletes tend to avoid it, and it affects sleep quality, which already is bad on average in our noisy, always illuminated cities.

Emmanuel Akodia
@akodiaemma
Aug 16 2017 09:41
so i have created the front end for a web system i wanted to make at first.
how do i start effecting the back end
implementing the back end
can i use javascript to make changes to the back end
Markus Kiili
@Masd925
Aug 16 2017 09:45
@akodia488 You can send an ajax request to the backend server and get a response back. Forms can also be submitted to a server.
Emmanuel Akodia
@akodiaemma
Aug 16 2017 09:46
tnak youi
Markus Kiili
@Masd925
Aug 16 2017 09:47
@akodia488 You can contact some server application you write yourself, or contact some server API written by someone else.
Stephen James
@sjames1958gm
Aug 16 2017 09:48
@akodia488 There are many ways to implement a backend, if you want to use javascript then nodejs is a tool for implementing a backend in js
Emmanuel Akodia
@akodiaemma
Aug 16 2017 09:49
@sjames1958gm i have actually used a template that looks something like this..let me send to you
Blauelf
@Blauelf
Aug 16 2017 09:50

Do you have some infrastructure already? A server with a web server everything should pass through? Java container like Tomcat? PHP interpreter/plugin? Node/ExpressJS (JavaScript-based server)? Database(s)? There might be requirements leading you to re-use existing infrastructure, or setting up your own.

Interaction between front- and backend is usually done by HTTP(S) requests. AJAX stands for Asynchronous JavaScript And XML, though I haven't seen a lot XML lately (it's harder to parse), but the async part is the interesting one (most times the browser interface should not freeze while waiting for the request).

Emmanuel Akodia
@akodiaemma
Aug 16 2017 09:51
its a fully front end..web application of a procurement system. I want it to start showing me numbers...do you know what i need to start doing? please tell me..i got the make a database part quite easy but then what next
im sending the image but nothing is appearing on the screen
Stephen James
@sjames1958gm
Aug 16 2017 09:53
There is also java spring https://spring.io/
Do you have existing infrastructure as @Blauelf already asked.
Your questions are pretty wide open so there are many choice
s
Emmanuel Akodia
@akodiaemma
Aug 16 2017 09:54
okay let me make a little bit more research then i can come back with a much better question
Blauelf
@Blauelf
Aug 16 2017 09:54
Those questions remind me of some web application I built nearly 20 years ago (server-side scripting in ColdFusion). Security-wise, it was a mess (no HTTPS, authentication was... there was some).
So guilty of various crimes. For example, I stored unhashed passwords :/
Also, I concatenated strings to build my SQL statement.
yu lin yob
@Mywangyulin
Aug 16 2017 09:57
l need help
Blauelf
@Blauelf
Aug 16 2017 09:58
Little Bobby Tables came a lot later.
@Mywangyulin Unless you state your problem, nobody can help.
Stephen James
@sjames1958gm
Aug 16 2017 09:59
@Blauelf lol
@Blauelf SQL injection - nice
or not so
Emmanuel Akodia
@akodiaemma
Aug 16 2017 09:59
@Blauelf would you call wise someone who will go to a website application like for example, Messenger.com, take the front end, change it alittle and then make his/her own backend from there...(messenger being only an example not literally)
does that type of development come easy or is it a pain in teh ass
the*
yu lin yob
@Mywangyulin
Aug 16 2017 10:00
I want to change the initial letters of the word
Blauelf
@Blauelf
Aug 16 2017 10:01
@akodia488 Would probably work better for static websites. And might have legal consequences (there was a case in which they left large parts of the code untouched, which supported the case).
@Mywangyulin You cannot change individual letters, but you can replace the whole string with one that has the right first letter.
yu lin yob
@Mywangyulin
Aug 16 2017 10:03
All this I know but still
Emmanuel Akodia
@akodiaemma
Aug 16 2017 10:03
@Blauelf let's say its legal. :)
would coding the back end from the front end be suitable or just another phase all together..what do you advice codewise oh great sensei
:)
yu lin yob
@Mywangyulin
Aug 16 2017 10:04
This is what l wrote." var a=[];
var result=str.split(' ');
for(var i=0;i<result.length;i++){
var b=result[i].substr(0,1).toUpperCase()+result[i].substr(1,result[i].length-1).toLowerCase()
a.push(b)
alert(a.join(' '))
"
Emmanuel Akodia
@akodiaemma
Aug 16 2017 10:05
screencapture-gatekeeperhq-3361-dashboard-1502872951621.png
the picture has loaded @Blauelf
yu lin yob
@Mywangyulin
Aug 16 2017 10:05
Put them together and run into difficulties
Can someone help me with this problem?
Stephen James
@sjames1958gm
Aug 16 2017 10:06
@Mywangyulin you'll want to join after the loop
@Mywangyulin Do you have any example input / output?
yu lin yob
@Mywangyulin
Aug 16 2017 10:08

Have "function titleCase(str) {
// 请把你的代码写在这里
var a=[];
var result=str.split(' ');
for(var i=0;i<result.length;i++){
var b=result[i].substr(0,1).toUpperCase()+result[i].substr(1,result[i].length-1).toLowerCase();
a.push(b);

alert(a.join(' '));
}
}
titleCase("I'm a little tea pot");
"

Stephen James
@sjames1958gm
Aug 16 2017 10:08
@Mywangyulin What gets alerted?
@Mywangyulin If you move the join out of the loop and return a.join(' ') it looks ok
yu lin yob
@Mywangyulin
Aug 16 2017 10:10
I think it's terrible
Stephen James
@sjames1958gm
Aug 16 2017 10:11
@Mywangyulin terrible how?
yu lin yob
@Mywangyulin
Aug 16 2017 10:12
Yes,sir
Stephen James
@sjames1958gm
Aug 16 2017 10:12
Why do you think it is terrible?
Markus Kiili
@Masd925
Aug 16 2017 10:14
@Mywangyulin Quite close to the standard loop solution.
yu lin yob
@Mywangyulin
Aug 16 2017 10:15
Could you comb it for me?
Markus Kiili
@Masd925
Aug 16 2017 10:17
@Mywangyulin You could toss the array a and just assign the titlecased word back to the array element result[i].
yu lin yob
@Mywangyulin
Aug 16 2017 10:20
It will traverse 5 times
George Kech.
@georgemitnick
Aug 16 2017 10:47
Guys, why the last function gives "true, false, false, false"? it should be "true, false, true, true"
var yearsOfBirth = [1990, 2000, 1986, 1956];

var transfered = [];

for (var i = 0; i < yearsOfBirth.length; i++) {
    transfered.push(yearsOfBirth[i]);
}

console.log(transfered);

var correntYear = 2017;

for (var i = 0; i < transfered.length; i++) {
    if (correntYear - transfered[i] >= 18) {
        console.log("He\'s an adult and he is " + (correntYear - transfered[i]) + " years old.");
    } else if (correntYear - transfered[i] < 18) {
        console.log("He\'s underage because he is " + (correntYear - transfered[i]) + " years old.");
    }
}

var newOne = [];
var trueOrFalse = [];

function printFullAge(yearsOfBirth) {
    for (var i = 0; i < yearsOfBirth.length; i++) {
        newOne[i] = yearsOfBirth[i];
        newOne[i] = correntYear - newOne[i];
        if (newOne >= 18) {
            trueOrFalse.push(true);
        } else {
            trueOrFalse.push(false);
        }
    }
}

printFullAge(yearsOfBirth);
console.log(newOne);
console.log(trueOrFalse);
Stephen James
@sjames1958gm
Aug 16 2017 10:49
@georgemitnick if (newOne >= 18) { you are comparing an array to 18
George Kech.
@georgemitnick
Aug 16 2017 10:50
but that array after the loop has ages
I can't do that?
oh
what if I did
if (newOne[i] >= 18) ?
OK it works
Thanks for pointing it out @sjames1958gm
CamperBot
@camperbot
Aug 16 2017 10:52
georgemitnick sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8324 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 16 2017 10:53
@georgemitnick :+1:
@georgemitnick I believe for the first one it coerces [27] to a number 27 and you get true, for the rest it just fails to compare the number to the array
George Kech.
@georgemitnick
Aug 16 2017 10:54
Now it shows it correctly
I used newOne[i]
and specified the else if with that too
Stephen James
@sjames1958gm
Aug 16 2017 10:55
@georgemitnick Cool. Just explaining why you didn't get all falses
George Kech.
@georgemitnick
Aug 16 2017 10:55
Aha
But why only the first one?
it should have fail completely
heroiczero
@heroiczero
Aug 16 2017 10:57
because the first one was treated as a number but when you push the second it is an array
George Kech.
@georgemitnick
Aug 16 2017 11:04
@heroiczero Hmmm. Thanks. So JS realizes that it's an array when there's a second thing in the array?
CamperBot
@camperbot
Aug 16 2017 11:04
georgemitnick sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1615 | @heroiczero |http://www.freecodecamp.com/heroiczero
yu lin yob
@Mywangyulin
Aug 16 2017 11:05
@Masd925 My code has only one small problem, and it's OK to put "alert (a.join (" ")) "next to its next}.
Markus Kiili
@Masd925
Aug 16 2017 11:14
@Mywangyulin You need to return the result from the function, not alert it.
Stephen James
@sjames1958gm
Aug 16 2017 11:17
@georgemitnick Here the + sign is coercing the array - only the single value is coerced into a number
+[27]
27
+[27, 30]
NaN
Blauelf
@Blauelf
Aug 16 2017 11:26
I hate JavaScript when it does that. I don't think there is any reason for turning an array into a number.
Stephen James
@sjames1958gm
Aug 16 2017 11:33
@Blauelf Yep
Blauelf
@Blauelf
Aug 16 2017 11:34
No wonder languages like Elm and Typescript have evolved to fix at least part of that.
Kelechi Chinaka
@ke1echi
Aug 16 2017 12:04
i need help with type check
function well(x){
  var counter = 0;
  x = x.reduce((a, b) => a.concat(b), []);
  for (var i = 0; i < x.length; i++) {
    if (typeof (+x[i] !== 'number')) {
      if (x[i].toLowerCase() == 'good') counter++;
    }
  }
  return (counter === 0) ? 'Fail!' : (counter == 1 || counter == 2) ? 'Publish!' : 'I smell a series!'
}
['bad', 'bAd', 6, '8'] fails this test @sjames1958gm @Blauelf
Blauelf
@Blauelf
Aug 16 2017 12:07
Bad placement of parentheses. if (typeof +x[i] !== 'number')
Kelechi Chinaka
@ke1echi
Aug 16 2017 12:07
where ? @Blauelf
Blauelf
@Blauelf
Aug 16 2017 12:09
I really don't get what the 'good' means. You don't provide any "good" or "GoOd" or whatever.
Kelechi Chinaka
@ke1echi
Aug 16 2017 12:10
am trying cover check for number
it fails even if its off
Blauelf
@Blauelf
Aug 16 2017 12:10
?
What do you want to test for?
Kelechi Chinaka
@ke1echi
Aug 16 2017 12:11
['gOOd', 'bAd', 'BAD', 5, '8', 'GOOD'] should return count of good
Blauelf
@Blauelf
Aug 16 2017 12:11
What do you use the typeof for? I really don't understand that if.
Stephen James
@sjames1958gm
Aug 16 2017 12:17
@kelechy What are the instructions?
Kelechi Chinaka
@ke1echi
Aug 16 2017 12:18
check for type @Blauelf
Blauelf
@Blauelf
Aug 16 2017 12:18
But why? If you do a +, you always have a number.
Kelechi Chinaka
@ke1echi
Aug 16 2017 12:19
yea
if i also remove the first if then i cant do 6.toLowerCase() @Blauelf

`In this kata you need to check the provided array (x) for good ideas 'good' and bad ideas 'bad'. I there are one or two good ideas, return 'Publish!', if there are more than 2 return 'I smell a series!'. If there are no good ideas, as is often the case, return 'Fail!'.

The solution should be case insensitive (ie good, GOOD and gOOd all count as a good idea). All inputs may not be strings.`

Blauelf
@Blauelf
Aug 16 2017 12:22
@kelechy Then if (typeof x[i] === "string" && x[i].toLowerCase() === 'good')
Stephen James
@sjames1958gm
Aug 16 2017 12:23
@kelechy Yeah as @Blauelf shows, check the positive case is a string and is good
Kelechi Chinaka
@ke1echi
Aug 16 2017 12:23
hmm... why didnt i think of this :smile:
i guess my logic wasnt complete :smile:
thanks @Blauelf @sjames1958gm
CamperBot
@camperbot
Aug 16 2017 12:24
kelechy sends brownie points to @blauelf and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 4571 | @blauelf |http://www.freecodecamp.com/blauelf
:star2: 8325 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
George Kech.
@georgemitnick
Aug 16 2017 13:00
image.png
Guys why does he uses return fullAges ? the push already assigned the values to the new array.
Kelechi Chinaka
@ke1echi
Aug 16 2017 13:05
fullAges is the name of the array he wants to push it to @georgemitnick
George Kech.
@georgemitnick
Aug 16 2017 13:05
Yeah, but the push already does it
oh wait
if he returns the array it goes to the function
not to the array right?
Kelechi Chinaka
@ke1echi
Aug 16 2017 13:06
its array.push(item) not push(item)
George Kech.
@georgemitnick
Aug 16 2017 13:06
so the output of the function will be the content of the array fullAges?
Kelechi Chinaka
@ke1echi
Aug 16 2017 13:07
yes
George Kech.
@georgemitnick
Aug 16 2017 13:07
Now I get it
I had in my mind that by using the return fullAges he is assigning the value of the fullAges after the loop to the fullAges array
I see now
George Kech.
@georgemitnick
Aug 16 2017 13:22
Can you tell me why when I type "full_1" on the chrome console it gives me an error:
//1
var yearsOfBirth = [1990, 2000, 1986, 1956];
//2
var transfered = [];
//3
for (var i = 0; i < yearsOfBirth.length; i++) {
    transfered.push(yearsOfBirth[i]);
}

console.log(transfered);
//4
var correntYear = 2017;

for (var i = 0; i < transfered.length; i++) {
    if (correntYear - transfered[i] >= 18) {
        console.log("He\'s an adult and he is " + (correntYear - transfered[i]) + " years old.");
    } else if (correntYear - transfered[i] < 18) {
        console.log("He\'s underage because he is " + (correntYear - transfered[i]) + " years old.");
    }
}
//5
var newOne = [];
var trueOrFalse = [];
var alt = [1923, 2010, 2001, 1938];

function printFullAge(yearsOfBirth) {
    for (var i = 0; i < yearsOfBirth.length; i++) {
        newOne[i] = yearsOfBirth[i];
        newOne[i] = correntYear - newOne[i];
        if (newOne[i] >= 18) {
            trueOrFalse.push(true);
        } else if (newOne[i] < 18) {
            trueOrFalse.push(false);
        }
    }
    return trueOrFalse;
}

var full_1 = printFullAge(yearsOfBirth);
var full_2 = printFullAge(alt);

console.log(full_1);
I know that the code is a bit of a mess.
kumquatfelafel
@kumquatfelafel
Aug 16 2017 13:27
@georgemitnick your code is chock-full of global variables, which is just asking for trouble.
George Kech.
@georgemitnick
Aug 16 2017 13:27
Yeah, I could avoid all those variables if I calculated the age in the beginning
kumquatfelafel
@kumquatfelafel
Aug 16 2017 13:36

The ones that will truly break things right away are trueOrFalse and newOne. It's not really a matter of not having the variables (though you do create more than necessary). It's a matter of their position. Since newOne and trueOrFalse are defined outside the function, this gives them global scope.

In any case, the code certainly runs, but it runs improperly as a result.

https://repl.it/KMG8

satyendra kr pandit
@satyendra2013
Aug 16 2017 13:43
It does not satisfy all the test cases of mutations challenge-

function mutation(arr) {
for(var i=0; i<arr[0].length;i++){
for(var j=0; j<arr[1].length;j++){
if(arr[1].split("")[j]==arr[0].split("")[i]){
return true;
}
else {
return false;
}
}
}
}

mutation(["hello", "hey"]);

please help
kumquatfelafel
@kumquatfelafel
Aug 16 2017 13:43
@satyendra2013 only checks first character
oh wait, not even that.
satyendra kr pandit
@satyendra2013
Aug 16 2017 13:43
@kumquatfelafel by the way you have to check all character
kumquatfelafel
@kumquatfelafel
Aug 16 2017 13:44
actually, yes, that
It only checks the first character
for (var i = 0; i < 10; i++) {
  return 5; //this doesn't return 5 ten times... just once.
}
satyendra kr pandit
@satyendra2013
Aug 16 2017 13:45
no it is checking all the characters but does not execute else part..i think
@kumquatfelafel yes i know
but why not it is executing else part
kumquatfelafel
@kumquatfelafel
Aug 16 2017 13:47
@satyendra2013 I promise you, it is not checking all the characters. :laughing: https://repl.it/KMG8/3
Run this and look at console output.
satyendra kr pandit
@satyendra2013
Aug 16 2017 13:48
but for this case-mutation(["Alien", "line"]) should return true. it is returning true
kumquatfelafel
@kumquatfelafel
Aug 16 2017 13:49
You can't always rely on a single result to know whether a piece of code is doing what it's supposed to.
In that case, it checks A against l, see's they're not the same, and says "nope!"
satyendra kr pandit
@satyendra2013
Aug 16 2017 13:50
okay
kumquatfelafel
@kumquatfelafel
Aug 16 2017 13:50
for example, if I change the order of the letters slightly... https://repl.it/KMG8/4
satyendra kr pandit
@satyendra2013
Aug 16 2017 13:51
yeah i understood...thank you @kumquatfelafel
CamperBot
@camperbot
Aug 16 2017 13:51
satyendra2013 sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 611 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
kumquatfelafel
@kumquatfelafel
Aug 16 2017 13:51
return statements end the function and return the specified value, so no further execution of statements in the function will occur
So you only want to return when there's nothing left to execute.
Antonious Stewart
@Antonious-Stewart
Aug 16 2017 13:52
ok so im working on a project and i was wondering how to check an input and if the vaule isnt something i have as a choice and not allow an input or makes the user pick again what should i look up
George Kech.
@georgemitnick
Aug 16 2017 13:52
I changed it. But it still tells me that full_1 and full_2 are undefined:
function printFullAge(yearsOfBirth) {
var age = [];
var trueOrFalse = [];

for (var i = 0; i < yearsOfBirth.length; i++) {
    age[i] = correntYear - yearsOfBirth[i];
}

for (i = 0; i < age.length; i++) {
    if (age[i] >= 18) {
        console.log("He\'s an adult and he is " + age[i] + " years old.");
        trueOrFalse.push(true);
    } else {
        console.log("He\'s underage because he is " + age[i] + " years old.");
        trueOrFalse.push(false);
    }
}
    return trueOrFalse;
}

var yearsOfBirth = [1990, 2000, 1986, 1956];
var correntYear = 2017;

var full_1 = printFullAge(yearsOfBirth);
var full_2 = printFullAge([1922, 2001, 1978]);
What I'm doing wrong?
kumquatfelafel
@kumquatfelafel
Aug 16 2017 13:54

@satyendra2013 Keep in mind. You also want to check if letter is in any position of string, not just first one.

I would look into this function a bit. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf You might find helpful.

satyendra kr pandit
@satyendra2013
Aug 16 2017 13:54
@kumquatfelafel Okay Thanks a lot man
CamperBot
@camperbot
Aug 16 2017 13:54
satyendra2013 sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:warning: satyendra2013 already gave kumquatfelafel points
George Kech.
@georgemitnick
Aug 16 2017 13:55
Anyone?
Datikzz
@Datikzz
Aug 16 2017 13:55
guys, why i starts with 2 https://jsbin.com/daxujif/edit?js,console
kumquatfelafel
@kumquatfelafel
Aug 16 2017 13:57
@georgemitnick seems fine to me. (haven't checked if results are right, but coming up with results)
https://repl.it/KMG8/6
Alaa H. Youssef
@alaahamdyy26
Aug 16 2017 13:57
hi
can you pls check my weather app and tell me your feedback
satyendra kr pandit
@satyendra2013
Aug 16 2017 13:58
@alaahamdyy26 Okay
George Kech.
@georgemitnick
Aug 16 2017 13:59
@alaahamdyy26 It gives inaccurate results for my location. I'm sure it's not 150c here :D
satyendra kr pandit
@satyendra2013
Aug 16 2017 13:59
@alaahamdyy26 it is not working properly
@alaahamdyy26 it is showing incorrect result for my location
Alaa H. Youssef
@alaahamdyy26
Aug 16 2017 14:00
:worried: will recheck then
thank u guys
:D thought im done
Thomas
@sjurs1
Aug 16 2017 14:02
Anyone mind giving me a quick hand in python? I know it's a JS chat but the python room is dead
kumquatfelafel
@kumquatfelafel
Aug 16 2017 14:05

@Datikzz If I had to guess... https://developer.mozilla.org/en-US/docs/Web/API/Storage/key

The order of keys is user-agent defined, so you should not rely on it.

George Kech.
@georgemitnick
Aug 16 2017 14:07
@kumquatfelafel No luck finding what's the issue? Let me copy paste you the solution which works but I don't know why. Since both are almost 100% the same.
function printFullAge(years) {
    var ages = [];
    var fullAges = [];

    for (var i = 0; i < years.length; i++) {
        ages[i] = 2016 - years[i];
    }

    for (i = 0; i < ages.length; i++) {
        if (ages[i] >= 18) {
            console.log('Person ' + (i + 1) + ' is ' + ages[i] + ' years old, and is of full age.');
            fullAges.push(true);
        } else {
            console.log('Person ' + (i + 1) + ' is ' + ages[i] + ' years old, and is NOT of full age.');
            fullAges.push(false);
        }
    }

    return fullAges;
}

var years = [2001, 1985, 1994, 2014, 1973];
var full_1 = printFullAge(years);
var full_2 = printFullAge([2012, 1915, 1999]);
I hope this will help you to figure out why the first doesn't work
well it works but when you call full_1 or 2 it gives undefined
Alaa H. Youssef
@alaahamdyy26
Aug 16 2017 14:10
check again pls :)
kumquatfelafel
@kumquatfelafel
Aug 16 2017 14:11
@georgemitnick call full_1 or full_2 in what context?
George Kech.
@georgemitnick
Aug 16 2017 14:11
@alaahamdyy26 Seems to work but it starts with K instead of F or C
@kumquatfelafel in the console. As to see their value.
Alaa H. Youssef
@alaahamdyy26
Aug 16 2017 14:12
yea
kumquatfelafel
@kumquatfelafel
Aug 16 2017 14:12
@alaahamdyy26 I love that you have Kelvin in there... that said... user should probably be able to switch back to kelvin if it's going to be included.
George Kech.
@georgemitnick
Aug 16 2017 14:12
@kumquatfelafel console.log(full_1); also doesn't work
Alaa H. Youssef
@alaahamdyy26
Aug 16 2017 14:12
the mistake actually was that the data comes in K and i thought its F so the algorithms were not correct
kumquatfelafel
@kumquatfelafel
Aug 16 2017 14:12
@alaahamdyy26 I would also consider trying to get rid of the excess digits in temperature.
Alaa H. Youssef
@alaahamdyy26
Aug 16 2017 14:13
@kumquatfelafel (Y) Thanks u i can do that :)
CamperBot
@camperbot
Aug 16 2017 14:13
:cookie: 612 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
alaahamdyy26 sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
Thomas
@sjurs1
Aug 16 2017 14:14
@alaahamdyy26 Maybe you should include the other weather types, like rain?
kumquatfelafel
@kumquatfelafel
Aug 16 2017 14:14
So like, instead of 24.01000000000005 °C.... 24.01... or maybe 24. Up to you really, but... less "decimally", more or less :p
Alaa H. Youssef
@alaahamdyy26
Aug 16 2017 14:15
@sjurs1 I was trying to do this but i can get the types from the documentation, any help?
I need to know the exact spelling for each typr in order to include it and add images for each
@kumquatfelafel Yeaa :D will try to do that
kumquatfelafel
@kumquatfelafel
Aug 16 2017 14:17

https://repl.it/KMG8/7

@georgemitnick again, console.log's just fine. If you're talking about that undefined just beneath the printed values, ignore that, it's unrelated.

George Kech.
@georgemitnick
Aug 16 2017 14:18
console.log doesn't work with the first code
at least not to me
Datikzz
@Datikzz
Aug 16 2017 14:18
@kumquatfelafel thanks
CamperBot
@camperbot
Aug 16 2017 14:18
datikzz sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 613 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
George Kech.
@georgemitnick
Aug 16 2017 14:18
image.png
Thomas
@sjurs1
Aug 16 2017 14:21

@alaahamdyy26 OpenWeatherMap API documentation gives at least a few more possible values of weather.main which you're using:

weather.main: Group of weather parameters (Rain, Snow, Extreme etc.)

so you could include "rain", "snow" at least
Alaa H. Youssef
@alaahamdyy26
Aug 16 2017 14:25
Thank U :)
kumquatfelafel
@kumquatfelafel
Aug 16 2017 14:27
@georgemitnick I suspect it's because you're executing this command in the console at such a time as it doesn't have access to that variable.
George Kech.
@georgemitnick
Aug 16 2017 14:27
How else could I execute it/
?
Genesis Self
@GenesisSelf
Aug 16 2017 14:32
@georgemitnick I think ages[i] = is wrong
George Kech.
@georgemitnick
Aug 16 2017 14:32
What's wrong with it?
Genesis Self
@GenesisSelf
Aug 16 2017 14:32
I think changing it to simply ages makes more sense. I am going to pop it in an editor to make sure
Are you just trying to figure out why that sippet of code worked for you? @georgemitnick
George Kech.
@georgemitnick
Aug 16 2017 14:38
No, I know why it worked. I don't get why the console says that full_1 and full_2 are undefined
the second code that I past works fine
but the thing is that it's the same as the first code, my code, but still gives that issue with the function calls
Let me copy past both codes.
Genesis Self
@GenesisSelf
Aug 16 2017 14:39
Always list your global variables at the top of the code
George Kech.
@georgemitnick
Aug 16 2017 14:39
It's not that.
First code/ my code:
function printFullAge(yearsOfBirth) {
var age = [];
var trueOrFalse = [];

for (var i = 0; i < yearsOfBirth.length; i++) {
    age[i] = correntYear - yearsOfBirth[i];
}

for (i = 0; i < age.length; i++) {
    if (age[i] >= 18) {
        console.log("He\'s an adult and he is " + age[i] + " years old.");
        trueOrFalse.push(true);
    } else {
        console.log("He\'s underage because he is " + age[i] + " years old.");
        trueOrFalse.push(false);
    }
}
    return trueOrFalse;
}

var yearsOfBirth = [1990, 2000, 1986, 1956];
var correntYear = 2017;

var full_1 = printFullAge(yearsOfBirth);
var full_2 = printFullAge([1922, 2001, 1978]);
Second code, which works fine:
function printFullAge(years) {
    var ages = [];
    var fullAges = [];

    for (var i = 0; i < years.length; i++) {
        ages[i] = 2016 - years[i];
    }

    for (i = 0; i < ages.length; i++) {
        if (ages[i] >= 18) {
            console.log('Person ' + (i + 1) + ' is ' + ages[i] + ' years old, and is of full age.');
            fullAges.push(true);
        } else {
            console.log('Person ' + (i + 1) + ' is ' + ages[i] + ' years old, and is NOT of full age.');
            fullAges.push(false);
        }
    }

    return fullAges;
}

var years = [2001, 1985, 1994, 2014, 1973];
var full_1 = printFullAge(years);
var full_2 = printFullAge([2012, 1915, 1999]);
Genesis Self
@GenesisSelf
Aug 16 2017 14:41
I changed it on codepen the order and I am no longer getting an undefined issue
got: [false, true, true, false, true] for full_1
and [false, true, false] for full_2
George Kech.
@georgemitnick
Aug 16 2017 14:50
The if it's the order why the second code works?
then*
Genesis Self
@GenesisSelf
Aug 16 2017 14:51
So when I was working on your second code, it came up undefined for me
I am not completely sure why it was working before
George Kech.
@georgemitnick
Aug 16 2017 14:53
It never came undefined to me
nor to the video tutorial
Genesis Self
@GenesisSelf
Aug 16 2017 14:53
interesting. Which browser are you using?
Angel J Piscola
@Redmega
Aug 16 2017 14:53
What's the question? The mass of codepens is confusing me
George Kech.
@georgemitnick
Aug 16 2017 14:56
@GenesisSelf chrome
Marc
@MWBauer
Aug 16 2017 14:59
I'm having a hard time understanding the syntax of RegExp
And do I really need it for the palindrome puzzle?
Angel J Piscola
@Redmega
Aug 16 2017 15:00
Very useful tester + help and reference guides so you can build your regex and then just paste it into your code
Marc
@MWBauer
Aug 16 2017 15:02
thank you
George Kech.
@georgemitnick
Aug 16 2017 15:06
Anyway. I'm out.
Ronique Ricketts
@RoniqueRicketts
Aug 16 2017 15:08

I hate dealing with forms AUUGH!!. So I have a form and I want to align the input fields directly beneath each other

<form>
       <label for="current_password">Current Password<input id="current_password" type="password"></label>
       <label for="new_password">New Password<input id="new_password" type="password"></label>
      <label for="repeat_password">Repeat Password<input id="repeat_password" type="password"></label>
                    <button>Update</button>
</form>

This is the layout and my design

#main_article form{
    display:flex;
    flex-direction: column;

}
form label{
    margin:13px;
}
form input{
    margin-left:10px;
}
Christopher McCormack
@cmccormack
Aug 16 2017 15:17
@RoniqueRicketts I don't think you want to wrap your label around your input
Ronique Ricketts
@RoniqueRicketts
Aug 16 2017 15:20
@cmccormack what do you suggest?
cowCrazy
@cowCrazy
Aug 16 2017 15:21
@RoniqueRicketts you can put each one of them in its own <section> tag
Angel J Piscola
@Redmega
Aug 16 2017 15:21
@RoniqueRicketts put display: block;on the form label
Christopher McCormack
@cmccormack
Aug 16 2017 15:23
@RoniqueRicketts do you want the label above your input or next to it?
Ronique Ricketts
@RoniqueRicketts
Aug 16 2017 15:23
@cmccormack next to it input field but each input field should be stacked evenly on each other
@cmccormack when I remove the <label> from around the <input> the <label> is above the <input>
Christopher McCormack
@cmccormack
Aug 16 2017 15:27
@RoniqueRicketts something like this? https://codepen.io/cmccormack/pen/zdPgdo? note I removed your flexbox for now
Ronique Ricketts
@RoniqueRicketts
Aug 16 2017 15:28
@cmccormack yes thanks :smile:
CamperBot
@camperbot
Aug 16 2017 15:28
roniquericketts sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1145 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Aug 16 2017 15:29
@RoniqueRicketts np - notice how label was turned into a block element so you can set width, that should be all you need
cowCrazy
@cowCrazy
Aug 16 2017 15:32
@RoniqueRicketts if you are still open for ideas, check this
Ronique Ricketts
@RoniqueRicketts
Aug 16 2017 15:33
@cmccormack Yes I see that. Its looking better already. @cowCrazy Thanks much
CamperBot
@camperbot
Aug 16 2017 15:33
roniquericketts sends brownie points to @cmccormack and @cowcrazy :sparkles: :thumbsup: :sparkles:
:warning: roniquericketts already gave cmccormack points
:cookie: 334 | @cowcrazy |http://www.freecodecamp.com/cowcrazy
Ronique Ricketts
@RoniqueRicketts
Aug 16 2017 15:35
@cmccormack can I have you look on something privately?
Christopher McCormack
@cmccormack
Aug 16 2017 15:36
Sure
Marc
@MWBauer
Aug 16 2017 15:47
I'm looking at the Regexr and I'm just not understanding how to put it into code.
Do I need to assign a variable that uses the regex function?
I see all of these flags and such, but .....I'm lost.
Christopher McCormack
@cmccormack
Aug 16 2017 15:50
@MWBauer maybe you should read this first if you haven't already - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions. People love to share tools like that but they're only useful if you understand the syntax first
Marc
@MWBauer
Aug 16 2017 15:56
I keep saying the same thing about foreign languages, i.e. JS, hindi, german, HTML
For the palindromes, should I first make a regular expression by assigning a variable with the /around the string?
Christopher McCormack
@cmccormack
Aug 16 2017 16:06
@MWBauer what method are you attempting to use the regex on?
Fernando
@lestairon
Aug 16 2017 16:07
Hi, i want to save all my console.log numbers into the ranum variable, but i don't know how to do it
var myMin = Math.floor(Math.random() * 10);
var myMax = Math.floor(Math.random() * (40 - 20 + 1)) + 20;
console.log(myMin);
console.log(myMax);
var ranum = {

};
for (var i = 0; i < 100 ; i++) {
  console.log(Math.floor(Math.random() * (myMax - myMin + 1)) + myMin);
}
Christopher McCormack
@cmccormack
Aug 16 2017 16:09
@lestairon store them in a variable first then log that variable
Keith
@7KAG7
Aug 16 2017 16:10
can someone help me make sense as to why when i click the onoffswitch the temp doesnt change?```
$(document).ready(function(){
  var long;
  var lat;
  var city;
  var ftemp;
  var ctemp;
  var ktemp;
  var summary;
  var tempmin;
  var tempmax;
  var onoffswitch;

  function onoffswitch(){
  currentvalue = document.getElementById('onoffswitch').value;
  if(currentvalue == "ceclsius"){
    document.getElementById("ctemp").value="ctemp";
  }else{
    document.getElementById("ftemp").value="ftemp";
  }
}    
  //create api for specific location  
  var api = "https://fcc-weather-api.glitch.me/api/current?lat=42.214576&lon=-71.658255";

  $.getJSON(api, function(data){
    //JSON call for api 
    var summary = data.name;    
    var weatherType = data.weather[0].description;
    var ctemp = data.main.temp;
    var ftemp = data.main.temp*9/5+32;
    var humidity = data.main.humidity;
    var wind = data.wind.speed;
    var tempmin = data.main.temp_min;
    var tempmax = data.main.temp_max;

function onoffswitch(click){
    var ctemp = data.main.temp*9/5+32;
}                  
      console.log(city);
    $("#city").html(city);
        $("#weatherType").html(weatherType);
        $("#summary").html(summary);
        $("#ctemp").html(ctemp);
        $("#ftemp").html(ftemp);
        $("#wind").html(wind);
        $("#humidity").html(humidity);
        $("#tempmin").html(tempmin);
        $("#tempmax").html(tempmax);
  });

  });
Christopher McCormack
@cmccormack
Aug 16 2017 16:10
@dudeguykid you have the same function name twice and neither of them are actual click handlers
@dudeguykid you'll need something like element.addEventListener('click', function(){ ... })
Keith
@7KAG7
Aug 16 2017 16:12
so remove function onoffswitch(click){
var ctemp = data.main.temp*9/5+32;
Christopher McCormack
@cmccormack
Aug 16 2017 16:12
@dudeguykid you'll have to figure out where to do the work but you need a listener and a handler to actually determine if something was clicked.
Keith
@7KAG7
Aug 16 2017 16:12
can i just add the element with in the function onoffswitch(){...
Fernando
@lestairon
Aug 16 2017 16:12
@cmccormack How can i do that?
Sorry, i'm new to Javascript haha
Marc
@MWBauer
Aug 16 2017 16:13
@cmccormack I dunno. lol I'm having a hard time getting started with the palindromes. I need to take in an input, break it down into lowercase, analyze if it reads the same forward and back, then Boolean to true or false.
Christopher McCormack
@cmccormack
Aug 16 2017 16:13
@lestairon you have declared and assigned variables at the top of the code, do something similar with your math function, var val = Math.floor(...
Keith
@7KAG7
Aug 16 2017 16:13
thanks @cmccormack , ill mess around with it
CamperBot
@camperbot
Aug 16 2017 16:13
dudeguykid sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1146 | @cmccormack |http://www.freecodecamp.com/cmccormack
Marc
@MWBauer
Aug 16 2017 16:15
function palindrome(x) {
 var rE = new RegExp (x);
  var lowerStr = rE.toLowerCase();
  /([a-z])+/g;
 x.replace(reg);
 /*return true;*/
}
This is my mess so far.
Angel J Piscola
@Redmega
Aug 16 2017 16:16
@MWBauer RegExp doesn't have a.toLowerCase();. You'd have to do that before making the RegExp
Christopher McCormack
@cmccormack
Aug 16 2017 16:16
@MWBauer you're all over the place
@MWBauer read that link I sent you first, thoroughly if you have the time
Marc
@MWBauer
Aug 16 2017 16:16
Thank you Angel. This is the kind of thing that I need to know.
I'm trying to read it now.
Christopher McCormack
@cmccormack
Aug 16 2017 16:17
This line does nothing - /([a-z])+/g;
Marc
@MWBauer
Aug 16 2017 16:17
what's the point of the regexp?
Christopher McCormack
@cmccormack
Aug 16 2017 16:18
Regex finds patterns based on the instructions you provide it, it can be much more powerful than trying to do it manually at the cost of legibility
Angel J Piscola
@Redmega
Aug 16 2017 16:18
"Hello".match(/Hell/) === true
Marc
@MWBauer
Aug 16 2017 16:19
how is that going to figure into the palindromes if the characters will be reversed? Does it look for reversed patterns?
Christopher McCormack
@cmccormack
Aug 16 2017 16:20
I'm not sure why you're trying to use it, honestly.
alpox
@alpox
Aug 16 2017 16:21

@MWBauer A regex in javascript is represented by an object. The form /<expression>/<flags> constructs such a regex object implicitely. A regex can be stored into a variable: var reg = /[a-z]/g;. It defines some methods which can be used to use the regex on a string. Like .test.

The point of regex is to match a string. This means, the expression resembles the string you want to match through a more general expression as the string itself so the expression matches an exact form of the string.
With that you can pick out specific parts of the string which match a certain pattern or just test if a string follows a specific pattern (The pattern of the regex)

Christopher McCormack
@cmccormack
Aug 16 2017 16:22
@MWBauer Did someone say you had to use it, or did you just want to try it?
Marc
@MWBauer
Aug 16 2017 16:23
umm...hold on. I will answer that in a moment.
the clue for the .replace command says, "The replace() method returns a new string with some or all matches of a pattern replaced by a replacement. The pattern can be a string or a RegExp, and the replacement can be a string or a function to be called for each match."
Soooo...I thought that I would have to RegExp to get started.
alpox
@alpox
Aug 16 2017 16:25
@MWBauer Either that or use a string as it says. A regex is a good choice, but for beginners quite hard to grasp
Marc
@MWBauer
Aug 16 2017 16:25
I learn well if someone asks me questions. I just don't know how to put my thoughts in my head into the actions in a language that the computer understands.
Christopher McCormack
@cmccormack
Aug 16 2017 16:25
@MWBauer oh I see why you're asking now
well it's a good time to learn regexp but you can also just use a string in the first argument
Marc
@MWBauer
Aug 16 2017 16:25
Ok. So, I just need a string. The input palindrome(x) is my input, specifically the x, right?
Christopher McCormack
@cmccormack
Aug 16 2017 16:26
you may want to use a simple regex so you can use the global flag
Marc
@MWBauer
Aug 16 2017 16:27
Ok. I don't know how to set that up. The syntax, even how to begin, is just beyond me.
Christopher McCormack
@cmccormack
Aug 16 2017 16:27
Here's an example of why - notice the first example only replaces the first:
> 'this is a test'.replace(' ', '')
'thisis a test'
> 'this is a test'.replace(/ /g, '')
'thisisatest'
> 'this is a test'.replace(/\s+/g, '')
'thisisatest'
Marc
@MWBauer
Aug 16 2017 16:27
do I need to assign a variable?
Christopher McCormack
@cmccormack
Aug 16 2017 16:28
@MWBauer absolutely - it only returns a string, you can't modify a string in place (Strings are immutable)
> var test = 'this is a test'.replace(/\s+/g, '')
> test
'thisisatest'
> test.replace(/t/g, '')
'hisisaes'
> test
'thisisatest'
Marc
@MWBauer
Aug 16 2017 16:29
so if I do a var rE = x.replace(' ', '') it should take the whole string and remove all spaces, right?
er...got it
Christopher McCormack
@cmccormack
Aug 16 2017 16:31

not all the spaces, just the first one it finds. Read carefully through the replace documentation:
str.replace(regexp|substr, newSubstr|function)

substr (pattern)

A String that is to be replaced by newSubStr. It is treated as a verbatim string and is not interpreted as a regular expression. Only the first occurrence will be replaced.

Marc
@MWBauer
Aug 16 2017 16:31
Yeah, so the example of the /\s+/g would take out all spaces
the \s being the whitespace flag
Christopher McCormack
@cmccormack
Aug 16 2017 16:33
@MWBauer correct, and the following + means 'one or more of the previous match'
so if there are lots of spaces in a row they will all be replaced with a single empty string
Marc
@MWBauer
Aug 16 2017 16:35
having used the var rE = x.replace(/\s+/g) gives me a variable that is the input string minus all spaces, correct?
Fernando
@lestairon
Aug 16 2017 16:35
I'm doing something wrong, i'm only storing the random number 1 time in the variable then login the variable 100 times :l
Christopher McCormack
@cmccormack
Aug 16 2017 16:36
@MWBauer you need to add the newSubstr argument first
you'll get an error if you don't
Fernando
@lestairon
Aug 16 2017 16:37
image.png
Now i tried to use a function
Christopher McCormack
@cmccormack
Aug 16 2017 16:38
@lestairon to invoke a function you need to add the parenthesis at the end
Marc
@MWBauer
Aug 16 2017 16:38
Ok. So let's talk about SubStr. What would I want to substitute?
Fernando
@lestairon
Aug 16 2017 16:38
Right
Christopher McCormack
@cmccormack
Aug 16 2017 16:38
@lestairon you're also not assigning the result of your math expression to a variable
@lestairon also not sure why you're making ranum an object first either
Fernando
@lestairon
Aug 16 2017 16:40
I think i should make it an array
Then pushing the numbers to the variable
Christopher McCormack
@cmccormack
Aug 16 2017 16:42
for your repRN function, you can simply return your math expression
although at that point it's only one line which may be better suited inside your for loop
@MWBauer SubStr is your search, newSubstr is the replace
Marc
@MWBauer
Aug 16 2017 16:44
Yeah. Sorry. I knew that. I'm trying understand what i'm supposed to be replacing with.
Mabye even more to the point, why replace.
Christopher McCormack
@cmccormack
Aug 16 2017 16:45

Read the exercise Note:

Note
You'll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything lower case in order to check for palindromes.

Marc
@MWBauer
Aug 16 2017 16:47
Right. Is this where I put the toLowerCase?
The part that I have has already taken in a string and removed all spaces.
Christopher McCormack
@cmccormack
Aug 16 2017 16:48
you can lowercase before or after you remove punctuation spaces and symbols if you like.
depending on your regex criteria it might behoove you to lowercase first
Marc
@MWBauer
Aug 16 2017 16:49
lol
ok....
str.toLowerCase() is all I need?
Christopher McCormack
@cmccormack
Aug 16 2017 16:49
just to lowercase it. Remember that returns the lowercase string, it does not modify in place
Marc
@MWBauer
Aug 16 2017 16:50
Right. So now I have a lowercase string (x), which then goes into the regexp replace command that takes out the spaces
Christopher McCormack
@cmccormack
Aug 16 2017 16:50
spaces, punctuation, and symbols ideally
Marc
@MWBauer
Aug 16 2017 16:52
right. Is that what I've done?
Christopher McCormack
@cmccormack
Aug 16 2017 16:52
Can you paste your code?
Marc
@MWBauer
Aug 16 2017 16:53
lol Yes. But I don't want to. I just ran a test and it says, "Myundefinedageundefinedetc...
Christopher McCormack
@cmccormack
Aug 16 2017 16:53
:D
Fernando
@lestairon
Aug 16 2017 16:54
I think i did it...
var myMin = Math.floor(Math.random() * 11);
var myMax = Math.floor(Math.random() * (40 - 20 + 1)) + 20;
console.log(myMin);
console.log(myMax);
var ranum = [];
function repRN() {
  ranum.push(Math.floor(Math.random() * (myMax - myMin + 1)) + myMin);
}
for (var i = 0; i < 100 ; i++) {
  repRN();
}
console.log(ranum);
Marc
@MWBauer
Aug 16 2017 16:54
gonna poke around a minute.
be back
Fernando
@lestairon
Aug 16 2017 16:55
Nvm
Christopher McCormack
@cmccormack
Aug 16 2017 17:01
@lestairon should your min and max also be randomized?
Fernando
@lestairon
Aug 16 2017 17:01
Yeah, i want them to be randomized
Guderian Raborg
@hypercuber
Aug 16 2017 17:03
I am making the snake game. Do you guys recommend to make another object if I want my snake to be more than one square or should I just make an arr with a function or what?
https://codepen.io/hypercuber/pen/oeoWBV?editors=0011
Christopher McCormack
@cmccormack
Aug 16 2017 17:05
@hypercuber an array of objects is valid, it can store the x and y position of the segment so the "apple" doesn't spawn there. Other than that you just need to push the new head on every tick and shift the old tail off
Marc
@MWBauer
Aug 16 2017 17:06
if you use the \s and \S then whitespace and non-whitespace are removed, right?
Christopher McCormack
@cmccormack
Aug 16 2017 17:08
@MWBauer what do you expect to happen if you remove all non-whitespace?
Marc
@MWBauer
Aug 16 2017 17:08
and what am I supposed to replace with?
I expect all of the characters to become 1 big happy string.
Christopher McCormack
@cmccormack
Aug 16 2017 17:08
The empty string '' is commonly used to remove elements from a string
a-z are non-whitespace
Marc
@MWBauer
Aug 16 2017 17:09
ok. I have \s\W/g
Guderian Raborg
@hypercuber
Aug 16 2017 17:09
@cmccormack Can you help me with some code?
Marc
@MWBauer
Aug 16 2017 17:09
\s\W+/g
Christopher McCormack
@cmccormack
Aug 16 2017 17:09
@MWBauer getting closer!
@MWBauer but note, you need specify each flag in an or fashion - either split them with a pipe | or use the bracket notation around them [ ]
Marc
@MWBauer
Aug 16 2017 17:10
each flag?
Guderian Raborg
@hypercuber
Aug 16 2017 17:10
What is best? Head of snake first or last element of array?
Christopher McCormack
@cmccormack
Aug 16 2017 17:11
Head first I would have to say - shifting is a more expensive process than popping
but I haven't thought too hard about it :)
I guess if head is first you have to update x/y for all elements each time
or unshift
so maybe the same amount of work either way
Guderian Raborg
@hypercuber
Aug 16 2017 17:13
@cmccormack Okay, thanks. Will try to make snake longer.
CamperBot
@camperbot
Aug 16 2017 17:13
hypercuber sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1147 | @cmccormack |http://www.freecodecamp.com/cmccormack
Datikzz
@Datikzz
Aug 16 2017 17:13
guys, how to make "if no matches found --> console.log" ?
https://jsbin.com/daxujif/edit?js,console
Christopher McCormack
@cmccormack
Aug 16 2017 17:13
A doubly linked list could work too but may be more than you need
Marc
@MWBauer
Aug 16 2017 17:14
sorry. my computer just died and now I have to get to wrok.
work
I will keep poking around trying to figure this out.
Christopher McCormack
@cmccormack
Aug 16 2017 17:15
@MWBauer good luck - read through the examples for replace and regex again when you're free
Bryan Reese
@breese8009
Aug 16 2017 17:15
solve pattern
  * start:  ['b', 'b', 'b', 'b', 'b']
  * finish: ['.', '.', '.', '.', '.'] // (given n is 1)
  * finish: ['b', '.', 'b', '.', 'b'] // (given n is 2)
  * finish: ['b', 'b', 'b', 'b', '.'] // (given n is 5)
Christopher McCormack
@cmccormack
Aug 16 2017 17:15
@Datikzz you may need to provide more context
@breese8009 you asking us to solve it?
looks like the step is changed to n and replaces the value at the nth step with .
Datikzz
@Datikzz
Aug 16 2017 17:18
@cmccormack In my code, if Test doesnt match any my array's element --> console.log(there is no such element)
Bryan Reese
@breese8009
Aug 16 2017 17:18
@cmccormack yea whats ur solution
Christopher McCormack
@cmccormack
Aug 16 2017 17:23
@breese8009
var replaceWithDot = (arr,n) => arr.map( (v,i) => ( (i+1) % n )===0 ? '.' : v )
Abhinav Mishra
@abhinav-m
Aug 16 2017 17:30
`arr.map ( v  =>   v% n === 0 ?  '.' : v )`
aah
my bad
lol
Stephen James
@sjames1958gm
Aug 16 2017 17:31
@Datikzz Worked for me -
Abhinav Mishra
@abhinav-m
Aug 16 2017 17:31
@breese8009
var replaceWithDot = (arr,n) => arr.map( (v,i) => ( (i+1) % n )===0 ? '.' : v )
this is correct
i messed up
im gonna disappear now
Datikzz
@Datikzz
Aug 16 2017 17:32
@sjames1958gm cuz i found solution lol :^)
Christopher McCormack
@cmccormack
Aug 16 2017 17:32
@abhinav-thinktank stick around!
Abhinav Mishra
@abhinav-m
Aug 16 2017 17:32
:P
Stephen James
@sjames1958gm
Aug 16 2017 17:32
@Datikzz oh, my bad
Abhinav Mishra
@abhinav-m
Aug 16 2017 17:32
brainfart
thought value = index
Christopher McCormack
@cmccormack
Aug 16 2017 17:33
@abhinav-thinktank you'd have to increment by one as it's 0 indexed too
Abhinav Mishra
@abhinav-m
Aug 16 2017 17:33
yeap
Manish Giri
@Manish-Giri
Aug 16 2017 17:36
@abhinav-thinktank :wave:
Abhinav Mishra
@abhinav-m
Aug 16 2017 17:36
@Manish-Giri :wave:
Muhammad Hasham
@MohammadHasham
Aug 16 2017 17:37
anyone doing/done Roguelike Dungeon Crawler Game?
Christopher McCormack
@cmccormack
Aug 16 2017 17:37
@MohammadHasham I finished mine a few weeks ago
Muhammad Hasham
@MohammadHasham
Aug 16 2017 17:38
@cmccormack can you guide me somehow
i have no clue how to make the map
?
Christopher McCormack
@cmccormack
Aug 16 2017 17:40
how to actually create it? I used a brute force method, create a rectangle and determine if it intercepted with other rectangles. If not, add it. I did this in a while loop and gave it a limited number of attempts so it didn't loop indefinitely
Muhammad Hasham
@MohammadHasham
Aug 16 2017 17:42
okay! @cmccormack Thanks i'll try to wrap my mind around.
CamperBot
@camperbot
Aug 16 2017 17:42
mohammadhasham sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1148 | @cmccormack |http://www.freecodecamp.com/cmccormack
Stephen James
@sjames1958gm
Aug 16 2017 17:42
@MohammadHasham My maps are rectangles (width x height) with doors that led to other rooms.
Christopher McCormack
@cmccormack
Aug 16 2017 17:42
There's a wiki or whatever for building roguelike games in python - that makes for some decent pseudocode
@sjames1958gm did you finish yours?
Stephen James
@sjames1958gm
Aug 16 2017 17:43
Not yet - have been refactoring to use with redux
Christopher McCormack
@cmccormack
Aug 16 2017 17:43
that's a good idea, I wish I had done that as well
I still keep putting off actually implementing redux :D
Muhammad Hasham
@MohammadHasham
Aug 16 2017 17:44
@sjames1958gm that's a good idea.
@sjames1958gm Thanks. I'll try to do it.
Stephen James
@sjames1958gm
Aug 16 2017 17:44
Really stretching my brain on how to use redux. I first had a bunch of code in the reducers but that was not working
so I moved code to the component so that it could better figure out the actions as individual units.
Muhammad Hasham
@MohammadHasham
Aug 16 2017 17:45
you can implement middlewares
b/w actions and reducers
Stephen James
@sjames1958gm
Aug 16 2017 17:45
Yeah, still trying to figure that out as well..
Muhammad Hasham
@MohammadHasham
Aug 16 2017 17:46
Good Luck :+1:
Christopher McCormack
@cmccormack
Aug 16 2017 17:46
@MohammadHasham if you want you can see my source on Github for how I built my rooms/tunnels, may be helpful.
Muhammad Hasham
@MohammadHasham
Aug 16 2017 17:46
@cmccormack Yeah sure i would love to see.
Christopher McCormack
@cmccormack
Aug 16 2017 17:47
Warning it's almost 1000 lines
and can probably be improved but I spent way too much time on that project, was ready to move on
Muhammad Hasham
@MohammadHasham
Aug 16 2017 17:48
@cmccormack yeah that's fine.
Christopher McCormack
@cmccormack
Aug 16 2017 17:48
@sjames1958gm how are you storing your map grid? as state or globally?
Ronique Ricketts
@RoniqueRicketts
Aug 16 2017 17:48
@cmccormack stop putting off redux man
Muhammad Hasham
@MohammadHasham
Aug 16 2017 17:48
i just need somewhere to start
Christopher McCormack
@cmccormack
Aug 16 2017 17:48
@RoniqueRicketts haha I just haven't had a strong need to utilize it yet, easy enough to pass down a few props multiple levels
Ronique Ricketts
@RoniqueRicketts
Aug 16 2017 17:49
@cmccormack oh well, I am still a noob in terms of frontend frameworks and library. I haven't found one that grabs me as yet.
Christopher McCormack
@cmccormack
Aug 16 2017 17:50
I've only used React but really enjoyed it so far
Ronique Ricketts
@RoniqueRicketts
Aug 16 2017 17:53
@cmccormack I should start React Next Week or the week after. Lets see how well that goes. I know how to make a few components with it but I haven't used it to make anything as yet. I have a project I wanna make but I need some back end knowledge to start it. I am thinking of using react on it but Idk if I can say I like React as yet.
Christopher McCormack
@cmccormack
Aug 16 2017 17:56
once you get the hang of it you won't want to switch back to normal JS :D
Ronique Ricketts
@RoniqueRicketts
Aug 16 2017 17:57
Really?? I shall find out in a few weeks. I will practice it a little. I can only say I like a tool whenever I've used it a few times.
Hemakshi Sachdev
@hemakshis
Aug 16 2017 18:01
Hey Everyone!
I am really stuck in this thing for like days I need your help now.
My name in the Home page goes down when I click on the toggle button for my nav bar..
actually I want my nav bar above my photo.. nd when I click the toggle button it's content should come above my pic and not push my pic down (not my name also).. please help..... Here's the link
https://codepen.io/hemakshis/pen/jLGQPp?editors=1100
Ronique Ricketts
@RoniqueRicketts
Aug 16 2017 18:03
@hemakshis so you want your background image to be fixed and have the content flow over it?
Hemakshi Sachdev
@hemakshis
Aug 16 2017 18:05
@RoniqueRicketts yes but the background should be fixed for home page only and the name also to be fixed :sweat_smile:
Ronique Ricketts
@RoniqueRicketts
Aug 16 2017 18:09
@hemakshisput background-attachment: fixed; in your #home . Is that effect what you wanted?
Muhammad Hasham
@MohammadHasham
Aug 16 2017 18:12
how do you make those tunnels to go from one rectangle to another in roguelike dungeon crawler
Moisés Man
@moigithub
Aug 16 2017 18:12
move ur "nav section" outside ur "home" ?? @hemakshis
Christopher McCormack
@cmccormack
Aug 16 2017 18:14
@MohammadHasham I believe I drew a horizontal line and a vertical line between two random points in the rectangles I wanted to connect. If you draw the horizontal line first, then draw the vertical line with the x at the end of your horizontal line. I
Hemakshi Sachdev
@hemakshis
Aug 16 2017 18:14
@RoniqueRicketts the problem solved by adding navbar-fixed-top class into my nav element
Ronique Ricketts
@RoniqueRicketts
Aug 16 2017 18:15
@hemakshis ok cool
Hemakshi Sachdev
@hemakshis
Aug 16 2017 18:15
@moigithub I tried that earlier..
@RoniqueRicketts btw thanks :)
CamperBot
@camperbot
Aug 16 2017 18:15
hemakshis sends brownie points to @roniquericketts :sparkles: :thumbsup: :sparkles:
:cookie: 361 | @roniquericketts |http://www.freecodecamp.com/roniquericketts
Moisés Man
@moigithub
Aug 16 2017 18:15
"floating menu"
Ronique Ricketts
@RoniqueRicketts
Aug 16 2017 18:15
@hemakshis your welcome anytime
Muhammad Hasham
@MohammadHasham
Aug 16 2017 18:16
@cmccormack okay thanks
CamperBot
@camperbot
Aug 16 2017 18:16
:warning: mohammadhasham already gave cmccormack points
mohammadhasham sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
JeremyWeisener
@JeremyWeisener
Aug 16 2017 18:35
Hi guys, I've been trying to do Exact Change challenge for a while now but I can't seem to get it right, this is what I have so far, I don't understand why on the first run of the code it ends with 0.03 pennies even though there are plenty more
https://jsfiddle.net/zyjo9zt0/2/
if anyone can help it would be much appreciated >.<
Moisés Man
@moigithub
Aug 16 2017 18:40
floating point rounding error common on JS
u can google/check stack overflow
JeremyWeisener
@JeremyWeisener
Aug 16 2017 18:41
ahh, that's probably why all the answers I checked out had rounded everything to while numbers
I'm looking into it now, thank you @moigithub
CamperBot
@camperbot
Aug 16 2017 18:41
jeremyweisener sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3592 | @moigithub |http://www.freecodecamp.com/moigithub
Nick Cleary
@Hijerboa
Aug 16 2017 19:20
Can anyone explain why my WhereforeArtThou code doesn't work when there are multiple items in the source? It works perfectly fine with only one item.
function whatIsInAName(collection, source) {
    // What's in a name?
    var arr = [];
    var item = source;
    collect = collection;
    var sourceArray = Object.keys(source);
    var searchedFor;
    var objectsToTest = {};
    for(i=0; i<collect.length; i++){
      objectsToTest.isPresent = false;
      for(j=0; j<sourceArray.length; j++){
        searchedFor = sourceArray[j];
        objectsToTest.object = collect[i];
        if(objectsToTest.object.hasOwnProperty(sourceArray[j]) === true){
          if(objectsToTest.object[searchedFor] !== null && objectsToTest.object[searchedFor] === item[searchedFor]){
            objectsToTest.isPresent = true;
          } else {
            objectsToTest.isPresent = false;
          }
        }
      }
      if(objectsToTest.isPresent === true){
        arr.push(collect[i]);
      }
    }
    console.log(arr);
    return arr;
  }
Nick Cleary
@Hijerboa
Aug 16 2017 19:27
These are the tests I'm using:
whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
  whatIsInAName([{ "a": 1 }, { "b": 1 }, { "a": 1, "b": 2 }], { "a": 1 });
  whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 });
  whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "c": 2 });
Christopher McCormack
@cmccormack
Aug 16 2017 19:38
@Hijerboa you're repeating yourself a bit - why create searchedFor then use sourceArray[j] as your argument? Also hasOwnProperty already returns true/false, you don't need to compare it to true
you don't really need to create new variables for everything, you can use the data as-is from the function parameter, much less difficult to troubleshoot that way
Nick Cleary
@Hijerboa
Aug 16 2017 19:40
@cmccormack good points... I cleaned those up a bit
The new code: ```
function whatIsInAName(collection, source) {
    // What's in a name?
    var arr = [];
    var item = source;
    collect = collection;
    var sourceArray = Object.keys(source);
    var searchedFor;
    var objectsToTest = {};
    for(i=0; i<collect.length; i++){
      objectsToTest.isPresent = false;
      objectsToTest.object = collect[i];
      for(j=0; j<sourceArray.length; j++){
        searchedFor = sourceArray[j];
        if(objectsToTest.object.hasOwnProperty(searchedFor)){
          if(objectsToTest.object[searchedFor] !== null && objectsToTest.object[searchedFor] === item[searchedFor]){
            objectsToTest.isPresent = true;
          } else {
            objectsToTest.isPresent = false;
          }
        }
      }
      if(objectsToTest.isPresent === true){
        arr.push(collect[i]);
      }
    }
    console.log(arr);
    return arr;
  }
Christopher McCormack
@cmccormack
Aug 16 2017 19:42
This honestly isn't much better, I keep having to go back and see what you converted from/to
why is item source? Just use source
why is collect collection? Just use collection
Nick Cleary
@Hijerboa
Aug 16 2017 19:42
```
Christopher McCormack
@cmccormack
Aug 16 2017 19:42
Should objectsToTest be reset after your inner loop completes?
Nick Cleary
@Hijerboa
Aug 16 2017 19:43
function whatIsInAName(collection, source) {
    // What's in a name?
    var arr = [];
    var sourceArray = Object.keys(source);
    var searchedFor;
    var objectsToTest = {};
    for(i=0; i<collection.length; i++){
      objectsToTest.isPresent = false;
      objectsToTest.object = collection[i];
      for(j=0; j<sourceArray.length; j++){
        searchedFor = sourceArray[j];
        if(objectsToTest.object.hasOwnProperty(searchedFor)){
          if(objectsToTest.object[searchedFor] !== null && objectsToTest.object[searchedFor] === source[searchedFor]){
            objectsToTest.isPresent = true;
          } else {
            objectsToTest.isPresent = false;
          }
        }
      }
      if(objectsToTest.isPresent === true){
        arr.push(collection[i]);
      }
    }
    console.log(arr);
    return arr;
  }
Christopher McCormack
@cmccormack
Aug 16 2017 19:43
do you really even need that when you have an index you could be using throughout?
Nick Cleary
@Hijerboa
Aug 16 2017 19:43
@cmccormack yes. it's a marker as to whether the item which is being tested in the outer loop is present or not in the source
@cmccormack If nothing else my code is much cleaner now... thanks mate
CamperBot
@camperbot
Aug 16 2017 19:45
hijerboa sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1149 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Aug 16 2017 19:46
I think you can probably find an easier way to test that then storing the objects in a new object
Nick Cleary
@Hijerboa
Aug 16 2017 19:47
would it be possible to modify the current object that is presented, or would my current approach be better than that
or heck, I guess would just having a simple variable be better?
Christopher McCormack
@cmccormack
Aug 16 2017 19:49
I actually don't remember too much of this exercise - I assume if a subset of an object contains the source you append that object to an array then return the array at the end, correct?
Nick Cleary
@Hijerboa
Aug 16 2017 19:49
Pretty much yes.
Christopher McCormack
@cmccormack
Aug 16 2017 19:50
I hate FCC's naming...
Nick Cleary
@Hijerboa
Aug 16 2017 19:51
Agreed. I get (or git :P ) that they're trying to be funny but it kinda defeats purpose of teaching that your variable names should align with what they contain
Christopher McCormack
@cmccormack
Aug 16 2017 19:52
I just hate it because the code you pasted doesn't tell me what the exercise is called
should have matched function name to exercise
Nick Cleary
@Hijerboa
Aug 16 2017 19:54
ah that was my bad I should have mentioned it
Christopher McCormack
@cmccormack
Aug 16 2017 19:56
Hmm what are you doing if one property/value does match but the next does not? you don't appear to be clearing your flags in that event
Nazar Maksymchuk
@MANTENN
Aug 16 2017 19:56
https://www.freecodecamp.org/challenges/sum-all-numbers-in-a-range
Looping through would work as a far loop - is that considered a basic solution?
Can't think of anything else
Nick Cleary
@Hijerboa
Aug 16 2017 19:57
@MANTENN probably would be considered a basic solution but I don't see why it won't work
Nazar Maksymchuk
@MANTENN
Aug 16 2017 19:58
@Hijerboa thanks
CamperBot
@camperbot
Aug 16 2017 19:58
mantenn sends brownie points to @hijerboa :sparkles: :thumbsup: :sparkles:
:cookie: 274 | @hijerboa |http://www.freecodecamp.com/hijerboa
Nick Cleary
@Hijerboa
Aug 16 2017 19:58
@cmccormack IsPresent should be set to false in that case..
Christopher McCormack
@cmccormack
Aug 16 2017 19:58
@MANTENN you can do it using math as well
but that may defeat the purpose
@Hijerboa you sure you are doing that?
Nick Cleary
@Hijerboa
Aug 16 2017 20:00
if(objectsToTest.object[searchedFor] !== null && objectsToTest.object[searchedFor] === source[searchedFor]){
            objectsToTest.isPresent = true;
          } else {
            objectsToTest.isPresent = false;
          }
I believe this should be doing
Christopher McCormack
@cmccormack
Aug 16 2017 20:00
@MANTENN
/*
    For a series [2, ..., 4]:

    Min: * * 
         * * * 
    Max: * * * * 

    Fill in the rest of the rectangle with the 
        same number of entries but in reverse as such:

    Min: * * O O O O
         * * * O O O
    Max: * * * * O O 

    Now you can take the bottom row (Max + Min) and multiply by the height (Max - Min + 1)
        to get the area of the rectangle (Max + Min)*(Max - Min + 1).
        Simplified: (Max^2 + (Max*Min)) - ((Max*Min) - Min^2) + (Max + Min)
        Simplified: Max^2 - Min^2 + Max + Min
        Divide the result by 2 to get the area of the series:
            (Max^2 - Min^2 + Max + Min) / 2

*/
@Hijerboa I'm referring to properties, not values
Margaret
@Margaret2
Aug 16 2017 20:00
@MANTENN check out arr.fill() and arr.reduce()
better than for loop ^
Nick Cleary
@Hijerboa
Aug 16 2017 20:01
@cmccormack ooooohhhh i think I know what you mean
let me try something
Margaret
@Margaret2
Aug 16 2017 20:02
hmm ok maybe not fill, but there should still be a more efficient way to do it
Nick Cleary
@Hijerboa
Aug 16 2017 20:02
@cmccormack you are a genius. Thank you! It works now!
CamperBot
@camperbot
Aug 16 2017 20:02
hijerboa sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:warning: hijerboa already gave cmccormack points
Manish Giri
@Manish-Giri
Aug 16 2017 20:04
@Margaret2 :tiger:
Christopher McCormack
@cmccormack
Aug 16 2017 20:04
@Hijerboa np
Nazar Maksymchuk
@MANTENN
Aug 16 2017 20:05
@cmccormack thanks - had pre-calculus didn't study much
CamperBot
@camperbot
Aug 16 2017 20:05
mantenn sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1150 | @cmccormack |http://www.freecodecamp.com/cmccormack
Margaret
@Margaret2
Aug 16 2017 20:05
@Manish-Giri :snowman:
Fernando
@lestairon
Aug 16 2017 20:18

function factorialize(num) {
  while (num > 1) {
    num *= (num-1);
    num--;
  }
  return num;
}

factorialize(5);
Do you guys can help me with my code?
"Potential infinite loop"
Nazar Maksymchuk
@MANTENN
Aug 16 2017 20:19
@cmccormack

function sumAll(arr) {
  var n = arr.reduce(function(a,b) {
    return {max: Math.max(a,b), min: Math.min(a,b)};
  });
  return (n.max*(n.max+1)/2)-((n.min-1)*n.min/2);
}
Christopher McCormack
@cmccormack
Aug 16 2017 20:22
@MANTENN only two arguments in arr, correct? no need for reduce in that case
Nazar Maksymchuk
@MANTENN
Aug 16 2017 20:23
@cmccormack yes one input is [4,1] i thought i'd use it
@cmccormack
function sumAll(arr) {
  var max = Math.max(arr[0],arr[1]);
  var min = Math.min(arr[0],arr[1]);
  return (max*(max+1)/2)-((min-1)*min/2);
}
Datikzz
@Datikzz
Aug 16 2017 20:25
hi, im a bit stuck, how to check if localStorage has value 'bac' ?
https://jsbin.com/daxujif/edit?js,console
Manish Giri
@Manish-Giri
Aug 16 2017 20:25
localStorage.get("xyz")
check if it returns the value
@Datikzz
Nazar Maksymchuk
@MANTENN
Aug 16 2017 20:27
@lestairon It's in the while loop the numbers appear to increase
Christopher McCormack
@cmccormack
Aug 16 2017 20:27
@MANTENN your solution looked nice :) however, calling reduce over and over is fairly inefficient. Wouldn't be noticed with something small like this but in something bigger it could potentially cause an impact
Fernando
@lestairon
Aug 16 2017 20:28
@MANTENN Right, thanks
CamperBot
@camperbot
Aug 16 2017 20:28
lestairon sends brownie points to @mantenn :sparkles: :thumbsup: :sparkles:
:cookie: 351 | @mantenn |http://www.freecodecamp.com/mantenn
Nazar Maksymchuk
@MANTENN
Aug 16 2017 20:29
@lestairon use another variable to keep track of the factorial
Margaret
@Margaret2
Aug 16 2017 20:30
@lestairon if you constantly multiply num, it will get bigger and bigger instead of smaller
start with 3 and think through it yourself
Nazar Maksymchuk
@MANTENN
Aug 16 2017 20:31
@cmccormack on a factorial would you use a recursive function or loop?
Stephen James
@sjames1958gm
Aug 16 2017 20:32
@MANTENN recursion is traditional with factorial
Nazar Maksymchuk
@MANTENN
Aug 16 2017 20:33
@sjames1958gm thanks
CamperBot
@camperbot
Aug 16 2017 20:33
mantenn sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8328 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 16 2017 20:33
@MANTENN :+1:
Christopher McCormack
@cmccormack
Aug 16 2017 20:38
I personally used reduce but recursion will look nice and simple for that problem
Mark Kubik
@KUBIX90
Aug 16 2017 20:39
How do you post code in the correct format for viewing? I have a problem with one of the challenges. I think I've worked out how to do it, its just getting the syntax right to get it working
Margaret
@Margaret2
Aug 16 2017 20:39
@KUBIX90
```
code
```
^ how to format
Christopher McCormack
@cmccormack
Aug 16 2017 20:40
oops I didn't use reduce, not sure why I thought I did, but I did use a for loop
Mark Kubik
@KUBIX90
Aug 16 2017 20:40

function findLongestWord(str) {


  //Turn into an array
  //Convert array of strings into number value
  var stringArray = str.split(" ").map(function(word){

    word.length;

  });

  return stringArray;

  //Find biggest number in the array

}

findLongestWord("What is the average airspeed velocity of an unladen swallow");
Thanks
I'm getting a array of null values, any idea why? I want the charaacter length to come back as a number in an array
Stephen James
@sjames1958gm
Aug 16 2017 20:41
@KUBIX90 You aren't returning anything inside your function
Mark Kubik
@KUBIX90
Aug 16 2017 20:43
I don't understand, I'm returning the stringArray variable value which is coming back as an array of null values?
Joseph
@revisualize
Aug 16 2017 20:43
@KUBIX90 Your function is returning undefined
@KUBIX90 Your map function needs a return value.
Mark Kubik
@KUBIX90
Aug 16 2017 20:44
I see now
Fernando
@lestairon
Aug 16 2017 20:44

function factorialize(num) {
  var fac = num;
  while (num > 1) {
    fac *= num-1;
    num--;
  }
  return fac;
}

factorialize(5);
Now my problem is when i try to factorize 0 it returns 0 instead of 1 lol
John Wilfred
@ewojjowe
Aug 16 2017 20:44
Hello all
Joseph
@revisualize
Aug 16 2017 20:44
@KUBIX90 The return statement ends function execution and specifies a value to be returned to the function caller.
Syntax
return [[expression]];
expression
The expression to return. If omitted, undefined is returned instead.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return
Margaret
@Margaret2
Aug 16 2017 20:45
@lestairon so just put an if in there...
Joseph
@revisualize
Aug 16 2017 20:45
@lestairon so create an if
Mark Kubik
@KUBIX90
Aug 16 2017 20:45
Thank you both for the help, not the first time I've made that error. I'll learn someday!
@revisualize
Stephen James
@sjames1958gm
Aug 16 2017 20:46
@KUBIX90 You will learn and still make that error - I can assure you - programming is about surviving the stupid mistakes :)
Fernando
@lestairon
Aug 16 2017 20:46
Oh, i though it was something on the code that i need to change
Joseph
@revisualize
Aug 16 2017 20:46
@KUBIX90 Yes?
Fernando
@lestairon
Aug 16 2017 20:46
Thanks
Mark Kubik
@KUBIX90
Aug 16 2017 20:47
Apologies, I've not used this chatroom hardly at all, just tagged you by mistake. Thanks for your help.
@sjames1958gm Tell me about it!
Joseph
@revisualize
Aug 16 2017 20:47
@KUBIX90 You should tag people that you're speaking to in chat messages.
Nathan Vu
@NathanVu
Aug 16 2017 20:48
function factorialize(num) {
  if (num === 0) { return 1; }
  return num * factorialize(num-1);
}

factorialize(5);
can anyone explain to me what return 1 do?
Joseph
@revisualize
Aug 16 2017 20:48
@NathanVu returns the value 1
Nathan Vu
@NathanVu
Aug 16 2017 20:48
this is an example of factorizing a number using recursion. I"m trying to understand this concept
@revisualize why is it returning 120 then?
Fernando
@lestairon
Aug 16 2017 20:49
@NathanVu When you try to factorialize 0 it will return 1 instead of 0
Nathan Vu
@NathanVu
Aug 16 2017 20:49
oh so the condition is set to 0 if true, however stop at 1?
Fernando
@lestairon
Aug 16 2017 20:49
Yes
Nathan Vu
@NathanVu
Aug 16 2017 20:50
what happened if I replaced the 1 with a 10?
I now get 1200
Diego Mayer
@Chrono79
Aug 16 2017 20:51
Hi all, I don't know if it has already been mentioned, but here it goes:
Code School is going to give FREE access to their entire content library for everyone from August 18–20. It’s a learning free-for-all! (Literally — it’s free for all to learn.)
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 20:51
hello everyone
Fernando
@lestairon
Aug 16 2017 20:51
@NathanVu It will return 10 instead of 1 when you try factorialize 0
Christopher McCormack
@cmccormack
Aug 16 2017 20:52
@Chrono79 That's awesome!
Diego Mayer
@Chrono79
Aug 16 2017 20:54
Received an email just a while ago, maybe I'll finish some half-made course from the last free access period :P
Or I could check some new course
Kelechi Chinaka
@ke1echi
Aug 16 2017 20:54
nice @Chrono79
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 20:54
can someone look into my pen?when I start the game you will see taht it will play 1 sound and if you get it right it will play 2 but it plays so fast and makes the animation so fast you can«'t see it, and I know its working cause i have console logs to see it gets a new sequence, https://codepen.io/tiagocorreia/full/brYpog/ how can I avoid this?
Fernando
@lestairon
Aug 16 2017 20:56
@Chrono79 Will we have access to the libraries only for 2 days?
Kelechi Chinaka
@ke1echi
Aug 16 2017 20:56
so if i get the FREE access, i can still get access even after those dates? @Chrono79
Diego Mayer
@Chrono79
Aug 16 2017 20:57
You have to finish the courses to keep them I guess @lestairon @kelechy
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 20:57
@cmccormack do you have a minute or two to look into it?
Diego Mayer
@Chrono79
Aug 16 2017 20:58
I remember some courses working some time later too if you don't logout but I wouldn't trust that to be the case this time
Kelechi Chinaka
@ke1echi
Aug 16 2017 20:58
ok
how would u rate their js course @Chrono79
Christopher McCormack
@cmccormack
Aug 16 2017 20:59
@tiagocorreiaalmeida you'll never get blue - tempSequence.push(colors[(Math.floor(Math.random()*3))]);
Need * 4
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 21:00
you are right allready someone pointed that out before I had Tofixed and now changed to math.floor, about the other problem any idea?thanks @cmccormack
Christopher McCormack
@cmccormack
Aug 16 2017 21:00
@tiagocorreiaalmeida look into using a setInterval to play your sounds/lights, give it a long delay while you test
or a setTimeout in a loop, however you want to do it
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 21:01
you mean for every sound a new loop beside the one I allready have in the function right?
a new settimeout*
Joseph
@revisualize
Aug 16 2017 21:02
@NathanVu if (num === 0) { return 1; }
Diego Mayer
@Chrono79
Aug 16 2017 21:03
@kelechy mmmm, I don't remember too much of it, I do remember I disliked every video started with an animated and musical intro, it's ok for a video or two, but it gets annoying
Christopher McCormack
@cmccormack
Aug 16 2017 21:04
@tiagocorreiaalmeida no I don't mean that at all, loop over your array of colors, and within that loop you can use setTimout. You'll have to ensure your iterator is scoped correctly (use let) and you multiply your iterator times your time interval so they play in the proper order. HOwever, I recommend using setInterval instead and just clear the interval when you've iterated over the length of your array
Diego Mayer
@Chrono79
Aug 16 2017 21:04
https://www.codeschool.com/courses/javascript-best-practices is one you should see once you already know the basics (I didn't finish it last time, but that's because I was already doing some other courses at the same time)
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 21:07
@cmccormack that was a bit confusing to me dont know if at this point I should be more confortable with this kind of knowledge or it will come with time
Diego Mayer
@Chrono79
Aug 16 2017 21:08
And I correct myself, once the time is over you can't even review the videos if you don't pay, maybe you can download some content while it's free
Christopher McCormack
@cmccormack
Aug 16 2017 21:08
@tiagocorreiaalmeida I don't really want to walk you through it - I want you to take away both of those functions and see if you can make them work in your project
@tiagocorreiaalmeida both of those functions allow you to delay the actions so it doesn't appear to instantly change colors as it is currently
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 21:09
but in this cause will I end up using my sound function aswell right?
will just delay the time when calling it right?
Christopher McCormack
@cmccormack
Aug 16 2017 21:10
put anything that needs a delay INSIDE the setInterval callback function, so it's only called after the interval expires
that can be your sound and color highlight
Fernando
@lestairon
Aug 16 2017 21:14
How does this code works?

function factorialize(num) {
  if (num == 0) return 10;
  return num * factorialize(num-1);
}

factorialize(5);
Diego Mayer
@Chrono79
Aug 16 2017 21:15
@lestairon with recursion
but that's not the right algorithm
Fernando
@lestairon
Aug 16 2017 21:16
It's not subtracting 1 everytime the block it's running
I mean, i can understand mine

function factorialize(num) {
  var fac = num;
  while (num > 1) {
    fac *= num-1;
    num--;
  }
  if (num == 0) {
    return 1;
  }
  return fac;
}

factorialize(0);
Diego Mayer
@Chrono79
Aug 16 2017 21:17
@lestairon paste the first code here: http://www.pythontutor.com/javascript.html#mode=edit
if (num == 0) return 10; //should be
if (num === 0) return 1;
Stephen James
@sjames1958gm
Aug 16 2017 21:18
@lestairon by calling the function itself with num - 1 is essentially subtracting 1 in the loop
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 21:20
@cmccormack something liek this
case "blue":
        delay = setInterval(function() {
       $(".row div.blue").css("opacity", "1");
       $(".row div.blue audio").trigger('play');
      }, 1000);
      break;
or isnt this really the idea?
sorry to bother
Christopher McCormack
@cmccormack
Aug 16 2017 21:21
@tiagocorreiaalmeida may want to do it more programmatically
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 21:22
can you give me some light on thios?feeling lost :D
doing it here ```
for(var j = 0; j < tempSequence.length; j++){
sound(tempSequence[j]);
}
?
Stephen James
@sjames1958gm
Aug 16 2017 21:24
@lestairon This function only knows the factorial of 1 which is 1, if it is not 1 then it
multiplies num by the factorial of num -1, eventually num gets to be 1 and it returns 1 which is multiplied by 2 and returns 2
which is multiplied by 3 which returns 6 which is multiplied by 4 which returns 24 which is multiplied by 5 (num) which returns 120
function factorialize(num) {
  if (num == 1 ) return 1;
  return num * factorialize(num-1);
}
Christopher McCormack
@cmccormack
Aug 16 2017 21:24
Check out this example I made for you, very simple: https://codepen.io/cmccormack/pen/EvoKmE
Stephen James
@sjames1958gm
Aug 16 2017 21:24
@tiagocorreiaalmeida calling a function called sound for each value in an array tempSequence
Diego Mayer
@Chrono79
Aug 16 2017 21:25
@sjames1958gm leave it as === 0 because otherwise you won't get factorial(0) (it'll exceed maximum stack)
Christopher McCormack
@cmccormack
Aug 16 2017 21:25
I tried doing that factorial exercise using ES6 notation and it fails, any reason why?
Gulsvi
@gulsvi
Aug 16 2017 21:26
const factorialize = num => num < 2 ? 1 : num * factorialize(num-1);
like that?
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 21:27
in this case if I call the function inside the loop that contains the colors using setInterval wouldnt that work?
Christopher McCormack
@cmccormack
Aug 16 2017 21:27
// jshint esversion:6, asi:true
const factorialize=(num)=>num===0 ? 1 : num * factorialize(num-1)
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 21:27
and thanks for the example I think I got it
Christopher McCormack
@cmccormack
Aug 16 2017 21:27
@tiagocorreiaalmeida don't use setinterval in a loop, setinterval is it's own kind of loop. It will keep going until you clear it
Gulsvi
@gulsvi
Aug 16 2017 21:27
Your code works for me @cmccormack
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 21:27
you mean
Christopher McCormack
@cmccormack
Aug 16 2017 21:27
you get the success in FCC?
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 21:28
change my sound function
Christopher McCormack
@cmccormack
Aug 16 2017 21:28
even after a reload?
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 21:28
instead of a switch
Gulsvi
@gulsvi
Aug 16 2017 21:28
Yes, hmmm, let me try reloading
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 21:28
and 8 lines
14 or more
I can do it like in 5 right?
Christopher McCormack
@cmccormack
Aug 16 2017 21:28
FCC seems to always succeed for me if It already succeeded even if I change the code, only on reload does it fail
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 21:28
using the parameter the function accepts
yeah seems a good a idea, thanks @cmccormack hope that was the idea
CamperBot
@camperbot
Aug 16 2017 21:28
tiagocorreiaalmeida sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1151 | @cmccormack |http://www.freecodecamp.com/cmccormack
Gulsvi
@gulsvi
Aug 16 2017 21:29
okay, lol, fails if I open the challenge in incognito mode
Christopher McCormack
@cmccormack
Aug 16 2017 21:29
@tiagocorreiaalmeida Sounds like you're on track!
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 21:29
really big thanks @cmccormack
CamperBot
@camperbot
Aug 16 2017 21:29
tiagocorreiaalmeida sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:warning: tiagocorreiaalmeida already gave cmccormack points
Christopher McCormack
@cmccormack
Aug 16 2017 21:29
@tiagocorreiaalmeida np
@tiagocorreiaalmeida clone that pen if you want, I may delete it shortly
Ronique Ricketts
@RoniqueRicketts
Aug 16 2017 21:30
does anyone else has a problem with c9 where it is not accepting css values
Christopher McCormack
@cmccormack
Aug 16 2017 21:30
@RoniqueRicketts it's usually not a problem with the tool, it's a syntax problem :D
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 21:30
done eheh thanks @cmccormack
CamperBot
@camperbot
Aug 16 2017 21:30
tiagocorreiaalmeida sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:warning: tiagocorreiaalmeida already gave cmccormack points
Gulsvi
@gulsvi
Aug 16 2017 21:30

This works for me:

const factorialize = num => num < 2 ? 1 : num * factorialize(num-1);

num === 0 fails
num === 1 or num < 2 works

Ronique Ricketts
@RoniqueRicketts
Aug 16 2017 21:30
@cmccormack it would show up on the side that the code is written in
Diego Mayer
@Chrono79
Aug 16 2017 21:31
@cmccormack does this fail too? const factorialize = num => num ? num * factorialize(num-1) : 1;
Fernando
@lestairon
Aug 16 2017 21:32
@Chrono79 Where are you from?
Diego Mayer
@Chrono79
Aug 16 2017 21:32
Ciudad Autónoma de Buenos Aires, Argentina
Fernando
@lestairon
Aug 16 2017 21:32
Oh, nice
I'm from Colombia
Diego Mayer
@Chrono79
Aug 16 2017 21:32
:+1:
Christopher McCormack
@cmccormack
Aug 16 2017 21:33
@Chrono79 nope that passes
aRtoo
@artoodeeto
Aug 16 2017 21:33
@SkyC0der yow bro!! help again. how do you put multiple regular exp.
lets say you need white space and underscore? white space this \s and underscore [_]
for my code i have this.
both doesnt work. i tried putting , in between s and [

function spinalCase(str) {

  var reg = /\s[_]/gi;

  return str.replace(reg,'-');
}

//spinalCase("This Is Spinal Tap");//should return "this-is-spinal-tap".
//spinalCase("thisIsSpinalTap"); //should return "this-is-spinal-tap".
spinalCase("The_Andy_Griffith_Show"); //should return "the-andy-griffith-show".
Diego Mayer
@Chrono79
Aug 16 2017 21:34
@SkyC0der num === 1 wouldn't that fail when testing factorialize(0) ?
Christopher McCormack
@cmccormack
Aug 16 2017 21:34
hmm and now mine passes
weird
parser must get cruft in it or something
Gulsvi
@gulsvi
Aug 16 2017 21:35
@Chrono79 now it fails.... very odd
Need to open the challenge in a new incognito window with every code change... buggy
Diego Mayer
@Chrono79
Aug 16 2017 21:36
I was struggling before to force a printer to use its black cartridge, it keept using the color ones
Gulsvi
@gulsvi
Aug 16 2017 21:36
@artoodeeto /[\s_]/
when it's in brackets it matches any of those
aRtoo
@artoodeeto
Aug 16 2017 21:37
@SkyC0der oohh. thanks totoy. mwah
CamperBot
@camperbot
Aug 16 2017 21:37
artoodeeto sends brownie points to @skyc0der :sparkles: :thumbsup: :sparkles:
:warning: artoodeeto already gave skyc0der points
Gulsvi
@gulsvi
Aug 16 2017 21:37
@artoodeeto de nada tito!
aRtoo
@artoodeeto
Aug 16 2017 21:38
@SkyC0der de nada? you kknow filipino food too??
Mark Kubik
@KUBIX90
Aug 16 2017 21:38

Back again, any idea why this still isnt working? I'm getting the character kength fo the first word back everytime. I thought this was suppose to loop through until the end of he array, not just end once the argument was true?

```

Gulsvi
@gulsvi
Aug 16 2017 21:38
@artoodeeto I love lumpia
Mark Kubik
@KUBIX90
Aug 16 2017 21:38
function findLongestWord(str) {


  //Turn into an array
  //Convert array of strings into number value
  var stringArray = str.split(" ").map(function(word){

    return word.length;

  });

  //Find biggest number in the array

  var longestString = 0;
  for (var i = 0; i < stringArray.length; i++){

    if(stringArray[i] > longestString){

      longestString = stringArray[i];

    }

    return longestString;
  }

}

findLongestWord("May the force be with you");
aRtoo
@artoodeeto
Aug 16 2017 21:38
@SkyC0der im starting to think your a filipino. you just playing
Gulsvi
@gulsvi
Aug 16 2017 21:38
lol, maybe
aRtoo
@artoodeeto
Aug 16 2017 21:38
@SkyC0der aight. thats it. you pinoy brooo.
Gulsvi
@gulsvi
Aug 16 2017 21:38
haha
aRtoo
@artoodeeto
Aug 16 2017 21:39
@SkyC0der no one knows lumpia unless ur a filipino.
Diego Mayer
@Chrono79
Aug 16 2017 21:39
@KUBIX90 check where you do this: return longestString;
  for (var i = 0; i < stringArray.length; i++){

    if(stringArray[i] > longestString){

      longestString = stringArray[i];

    }

    return longestString; //it's inside the loop, so your loop won't run more than once
  }
Gulsvi
@gulsvi
Aug 16 2017 21:39
lol, lumpia is so good
Mark Kubik
@KUBIX90
Aug 16 2017 21:42
@Chrono79 Thanks, works now. I swear all my issues seem to stem from my use of the return statement, just can't seem to get my head around it for some reason. Really frustrating considering how basic it is
CamperBot
@camperbot
Aug 16 2017 21:42
kubix90 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4525 | @chrono79 |http://www.freecodecamp.com/chrono79
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 21:42
@cmccormack if you can give it a final look, https://codepen.io/tiagocorreia/pen/brYpog?editors=0110 it sound crazy literally :D
Christopher McCormack
@cmccormack
Aug 16 2017 21:42
@tiagocorreiaalmeida added a tiny bit more functionality to show how setTimeout can be used
Margaret
@Margaret2
Aug 16 2017 21:43
@KUBIX90 Math.max.apply(null, array) - get the max value in the array, no need for for loop
aRtoo
@artoodeeto
Aug 16 2017 21:43
@SkyC0der damn bro. you forgot about the pancit!
'
Christopher McCormack
@cmccormack
Aug 16 2017 21:45
@tiagocorreiaalmeida one bit of advice - if you're going to use a selector, I highly recommend you make it more specific.
$(".row div") would not be easy for someone to figure out, but adding a button class would make it much easier - $('.color-button').click
Diego Mayer
@Chrono79
Aug 16 2017 21:46
@Margaret2 that's an improvement yes (but not so easy to get for beginners and not shown in FCC, I mean the use of apply), but if s/he has trouble with where return goes, doing it with Math.max wouldn't help
Christopher McCormack
@cmccormack
Aug 16 2017 21:46
It will also prevent you from adding a row with a div later and weird stuff happening
Margaret
@Margaret2
Aug 16 2017 21:46
@Chrono79 well, you already helped him fix that, right?
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 21:46
yeah true about the noises spam im controlling badly the set interval right?:D
Diego Mayer
@Chrono79
Aug 16 2017 21:46
I hope
Margaret
@Margaret2
Aug 16 2017 21:46
anyway
my shortest solution yet!
function findLongestWord(str) {
  return Math.max.apply(null, str.split(' ').map(x=>x.length))
}
@Manish-Giri
Diego Mayer
@Chrono79
Aug 16 2017 21:47
:+1: (you could try using spread operator, that's ES6 tho)
Christopher McCormack
@cmccormack
Aug 16 2017 21:47
@tiagocorreiaalmeida I'm honestly not about to go through all your code to make sense of it, sorry :D I will try to help lead you in the right direction if you're stuck though
Mark Kubik
@KUBIX90
Aug 16 2017 21:47
@Margaret2 Thanks, i'll take look through this and the other (no doubt better) answers to see where it can be improved
CamperBot
@camperbot
Aug 16 2017 21:47
kubix90 sends brownie points to @margaret2 :sparkles: :thumbsup: :sparkles:
:star2: 2884 | @margaret2 |http://www.freecodecamp.com/margaret2
Margaret
@Margaret2
Aug 16 2017 21:48
@Chrono79 :o
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 21:49
@cmccormack you are the one doing it right thanks for updating the pen will see what I can do
CamperBot
@camperbot
Aug 16 2017 21:49
tiagocorreiaalmeida sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:warning: tiagocorreiaalmeida already gave cmccormack points
LiciniusRex
@hashtagyolo1
Aug 16 2017 21:51
Howdy folks
I'm pulling my hair out over seek and destroy. Really not understanding filter and arguments at all
I keep feeling like I'm getting somewhere, hit a brick wall and start again then hit a different wall and see no way of connecting the dots
some way points would be greatly appreciated
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 21:53
@hashtagyolo1 send what you have
LiciniusRex
@hashtagyolo1
Aug 16 2017 21:53

function destroyer(arr) {
 var result = [arr.filter(checkAnswer)];

  function checkAnswer(val){
    console.log(val === arr[3]);
  }
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Margaret
@Margaret2
Aug 16 2017 21:56
@hashtagyolo1 explanation of arguments:
arguments is basically a keyword that allows you to access whatever values were passed to the function.
looks like an array, but is not an actual array
so you need to turn it into an array in order to use any array methods on it: var args = [...arguments]
LiciniusRex
@hashtagyolo1
Aug 16 2017 21:57
ok thanks @Margaret2 . I'll see what I can do from there
CamperBot
@camperbot
Aug 16 2017 21:57
hashtagyolo1 sends brownie points to @margaret2 :sparkles: :thumbsup: :sparkles:
:star2: 2885 | @margaret2 |http://www.freecodecamp.com/margaret2
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 22:09
@cmccormack just a final question and sorry to keep bothering you, if I do it like this sound(tempSequence[j]);
clearInterval(soundTime); I will stop it before it runs right?
Emilio Vesprini
@evsprn
Aug 16 2017 22:10
@hashtagyolo1 I was going to ask about the exact same problem.
LiciniusRex
@hashtagyolo1
Aug 16 2017 22:11
I think I need to start saving my solutions so I can go back through them.
Emilio Vesprini
@evsprn
Aug 16 2017 22:11
It was a little freaky opening up gitter and finding almost the same code I was about to paste already be there.
Christopher McCormack
@cmccormack
Aug 16 2017 22:11
@tiagocorreiaalmeida hey sorry I am just about out the door - can you share your pen again and maybe someone else can help answer it?
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 22:11
@cmccormack ofcoure mate see you around
and thanks
Emilio Vesprini
@evsprn
Aug 16 2017 22:11
thanks @Margaret2
CamperBot
@camperbot
Aug 16 2017 22:11
evsprn sends brownie points to @margaret2 :sparkles: :thumbsup: :sparkles:
:star2: 2886 | @margaret2 |http://www.freecodecamp.com/margaret2
Christopher McCormack
@cmccormack
Aug 16 2017 22:12
see ya
cmccormack @cmccormack out
Emilio Vesprini
@evsprn
Aug 16 2017 22:12
@hashtagyolo1 fcc actually saves them for you
LiciniusRex
@hashtagyolo1
Aug 16 2017 22:12
At least I'm not the only one stuck @evsprn
does it?
Emilio Vesprini
@evsprn
Aug 16 2017 22:13
though having a single file with all of them is pretty comfortable
yeah
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 22:13
https://codepen.io/tiagocorreia/full/brYpog/ can someone look into my pen and see why it loops when I start it ? Can'tfigure out why if I clear the interval
LiciniusRex
@hashtagyolo1
Aug 16 2017 22:13
I think I should have just saved a whole lot of codepens
Emilio Vesprini
@evsprn
Aug 16 2017 22:15
@hashtagyolo1 I was planning on putting my solutions file in github so maybe people could criticize it. Can you let me know if you publish yours? I'd like to compare solutions.
LiciniusRex
@hashtagyolo1
Aug 16 2017 22:16
yeah sure. I'll tag you in a post on here. Not going to bed until I have this one tonight
Tiago Correia
@tiagocorreiaalmeida
Aug 16 2017 22:16
@Chrono79 you around?
Margaret
@Margaret2
Aug 16 2017 22:16
@evsprn lol i was like, "did I do something?" :joy:
Emilio Vesprini
@evsprn
Aug 16 2017 22:19
:joy: :joy:
Manish Giri
@Manish-Giri
Aug 16 2017 22:21
@Margaret2 :sparkles:
DistinctWolf
@DistinctWolf
Aug 16 2017 22:29
anyone here who can help me with nodejs
LiciniusRex
@hashtagyolo1
Aug 16 2017 22:38
@evsprn actually. I'm done for the night. Can't concentrate on this at all right now. Good luck on it
Nathan Vu
@NathanVu
Aug 16 2017 22:40
function factorialize(num) {
  if (num === 0) { return 1; }
  return num * factorialize(num-1);
}

factorialize(5);
Hey guys return 1 is it saying multiply by 1?
It doesn't specifically say multiply by 1
Margaret
@Margaret2
Aug 16 2017 22:46
@NathanVu return ends the function. It gives you the final value of the function. It doesn't multiply or anything like that.
@NathanVu the factorial of 0 is 1. So if (num === 0) { return 1; } means "if num is 0, the output should be 1"
if num is not 0, the function keeps going to the next line
aRtoo
@artoodeeto
Aug 16 2017 22:49
is my fibonaci correct?

function sumFibs(num) {

  var frst = 0;
  var scnd = 1;
  var res = 0;

  for(var i=0; i<num; i++){
    res = frst + scnd;
    frst = scnd;
    scnd = res;
  }


  return res;
}

sumFibs(4);
Margaret
@Margaret2
Aug 16 2017 22:49
@artoodeeto does it pass the tests....?
that's how you know it's correct lol
aRtoo
@artoodeeto
Aug 16 2017 22:49
@Margaret2 no. this is just for me
Margaret
@Margaret2
Aug 16 2017 22:49
oh
Nathan Vu
@NathanVu
Aug 16 2017 22:50
@Margaret2 what if I change return 1 to return 10? I end up getting 1200 instead?
Elizabeth Paul
@Kowalatam
Aug 16 2017 22:51
@NathanVu the guy in the video i posted explained this problem
it might help
:)
Margaret
@Margaret2
Aug 16 2017 22:52
@NathanVu ok, so num keeps decreasing, because you keep calling the function with num - 1. Eventually you get to factorialize(0)
Jake
@JakeDVirus
Aug 16 2017 22:52
This message was deleted
Margaret
@Margaret2
Aug 16 2017 22:53
@NathanVu if factorialize(0) returns 1, the previous num will be multiplied by 1, but if factorialize(0) returns 10, the num will be mulitplied by 10
that's why with 1 it was returning 120, and with 10 it's returning 1200
Jake
@JakeDVirus
Aug 16 2017 22:57

The syntax for jquery's getJSON method is stated as

$.getJSON(url,data,success(data,status,xhr))

where the parameters of success are given as:

data - contains the data returned from the server.
status - contains a string containing request status ("success", "notmodified", "error", "timeout", or "parsererror").
xhr - contains the XMLHttpRequest object

Now how do i pass the argument to the callback function success if i need to retrieve only the xhr.
if i pass like this success(xhr), won't it be treated as success(data)?
what is the proper way?

Moisés Man
@moigithub
Aug 16 2017 23:06

success callback is already predefined and will be called with 3 vlaues like u posted
if u wanna work with xhr,, then u need to declare 3 parameters on ur function.. the 3rd will be xhr (whatever name u use)

function myFunction(a,b,c){
  //c will be xhr
}

$.getJSON(url,data, myFunction) @NeelDVirus

Jake
@JakeDVirus
Aug 16 2017 23:11
@moigithub yeah i got your point. so it is strictly required to pass all the three arguments explicitly in order to access the third argument and its usage. isn't it?
Moisés Man
@moigithub
Aug 16 2017 23:12
yep
Jake
@JakeDVirus
Aug 16 2017 23:13
Oh thanks. actually i tend the concise and succinct way rather then being redundant and verbose. so clarified
Emilio Vesprini
@evsprn
Aug 16 2017 23:19
@hashtagyolo1 thanks
CamperBot
@camperbot
Aug 16 2017 23:19
evsprn sends brownie points to @hashtagyolo1 :sparkles: :thumbsup: :sparkles:
:cookie: 252 | @hashtagyolo1 |http://www.freecodecamp.com/hashtagyolo1
Stephen James
@sjames1958gm
Aug 16 2017 23:52
@artoodeeto Are you trying to get the 5th fibonacci number?
aRtoo
@artoodeeto
Aug 16 2017 23:53
@sjames1958gm thanks bro. but im all good. the solution that i saw it was returning the final number not the result. but if you want to help me i still have issues
CamperBot
@camperbot
Aug 16 2017 23:53
artoodeeto sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8330 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 16 2017 23:53
@artoodeeto Sure
aRtoo
@artoodeeto
Aug 16 2017 23:55
@sjames1958gm this is my solution on Sum All Odd Fibonacci Numbers
i still have some incorrect.

function sumFibs(num) {

  var frst = 1;
  var scnd = 1;
  var res = 0;
  var sumOdd = 0;

  for(var i=0; i<num; i++){
    res = frst + scnd;
    frst = scnd;
    scnd = res;

   if(res<num){
      if(res % 2 === 1){
         sumOdd += res;
     }
   }
    }
   console.log(sumOdd + 1 + 1);

  //return res;
}

//sumFibs(10); //correct
//sumFibs(1); //should return a number. //incorrect
//sumFibs(1000); //should return 1785. //correct
//sumFibs(4000000); //should return 4613732. // undertermined infinite loop
//sumFibs(4); //should return 5. //correct
//sumFibs(75024); //should return 60696. //correct
//sumFibs(75025); //should return 135721. //incorrect
Stephen James
@sjames1958gm
Aug 16 2017 23:57
@artoodeeto You need to stop the loop when res > num not when i > num
you are calculating the first 4000000 fibs when you should be calculating the fibonacci numbers up to 4000000