These are chat archives for FreeCodeCamp/HelpJavaScript

11th
May 2017
Mohamed Derhalli
@derhallim
May 11 2017 00:00
there are some web performance tests in visual studio
Jason Luboff
@JLuboff
May 11 2017 00:00
@monkeyfingerz console.log is your friend! Use it!
I'm out...see ya guys
HeebieGeeBee
@HeebieGeeBee
May 11 2017 00:00
@JLuboff cya
jmariomejiap
@jmariomejiap
May 11 2017 00:01
@JLuboff see you, and thanks again
Mohamed Derhalli
@derhallim
May 11 2017 00:01
@JLuboff tc man :clap:
HeebieGeeBee
@HeebieGeeBee
May 11 2017 00:01
@monkeyfingerz setTimeout, not setTimeOut
have a feeling im repeating myself
Ashref
@Asher2016
May 11 2017 00:02

why seTimout function doesn't working ?
```var Validator = {
//to validate that the value input string has one or more character in it
isNotEmpty: function isNotEmpty(elem){
var user_input = elem.elements, i;

                                                for ( i = 0; i < user_input.length; i++) {
                                                    var input = user_input[i];
                                                    var input_type = user_input[i].type;
                                                    var input_name = user_input[i].name;
                                                    var input_value = user_input[i].value.length;

                                                    if (( input_type == 'text') && (input_value == 0)){

                                                     var input_toFocus = document.getElementById('first_name');

                                                     window.alert("please enter a valid " + input_name);
                                                     window.setTimeout(function focusElement() {

                                                                                        input_toFocus.select();
                                                                                        input_toFocus.focus();
                                                                                        input_toFocus.style.backgroundColor = "red";}, 10)}

}}}```

HeebieGeeBee
@HeebieGeeBee
May 11 2017 00:02
@Asher2016 you dont attach it to the window object
grfraser
@grfraser
May 11 2017 00:03
@derhallim you got windows tho, i got mac preview of vs studio
Carlos García de Castro
@garciadecastro
May 11 2017 00:03
This code find the sum of the elements with even indexes (0th, 2nd, 4th...) then multiply this summed number and the final element of the array together. Any shorter suggestions?
function evenLast(data) {

    var total = 0;

    for (var i = 0; i<data.length; i += 2)  {

        total += data[i] * data[data.length - 1];

        } 

    return total;

}
Spencer Bartlett
@sbmercury
May 11 2017 00:04

Working on my random quote machine trying to convert json to html, the json is loading in fine (console.log is printing exactly what I'd expect but the page just says undefined, not the data I'm expecting

                            var html = "";
                                html += "<h1 class='quote'>";
                                console.log(json);
                                html += json["quote"];
                                html+= "</h1>";
                                $(".message").html(html);

here's a sample of the json it's working with: {"quote":"Talent does what it can; genius does what it must.","author":"Edward George Bulwer-Lytton","category":"Famous"}

Ashref
@Asher2016
May 11 2017 00:04
@HeebieGeeBee you mean window.setTimout ?
grfraser
@grfraser
May 11 2017 00:04
@derhallim prob diff features, i need to focus on learning more bfore i even concern myself with this lol. just got to js basic algorithms
HeebieGeeBee
@HeebieGeeBee
May 11 2017 00:05
@Asher2016 yes dont attach it to the windo
w
Mohamed Derhalli
@derhallim
May 11 2017 00:05
@grfraser hehe yea
HeebieGeeBee
@HeebieGeeBee
May 11 2017 00:05
its just just a static function call
Keon Samuel
@keonsam
May 11 2017 00:05
another react project down the pipeline.
Stephen James
@sjames1958gm
May 11 2017 00:06
@lpy1994 - I got it to pass - if you are still online
john94
@lpy1994
May 11 2017 00:06
@sjames1958gm yeah..
MESHACK ALFRED
@LASTBORNMESH
May 11 2017 00:06

function convertToF(celsius) {
var fahrenheit;
// Only change code below this line
var number = celsius;
number = celsius * (9/5) +32;
// Only change code above this line
return number;
}

// Change the inputs below to test your code
convertToF(-30);
@sastech

john94
@lpy1994
May 11 2017 00:07
somebody told me that the double for loop is sort of a problem
Stephen James
@sjames1958gm
May 11 2017 00:07
@lpy1994 the key was to keep track of values already seen and not search on those again.
var sum_pairs=function(ints, s){
  let a = -1, b = ints.length;
  let seen = [];
  for (let i = 0; i < ints.length - 1; i++) {
    if (seen.indexOf(ints[i]) !== -1) continue;
    let j = ints.indexOf(s - ints[i], i + 1);
    if (j !== -1) {
      if (j < b) {
        b = j;
        a = i;
      }
    }
    seen.push(ints[i]);
  }
  if (a != -1) {
    return [ints[a], ints[b]];
  }
}
@lpy1994 Yeah, the key is to not try to process the same ints[i] value over and over again.
Ashref
@Asher2016
May 11 2017 00:08
@HeebieGeeBee it works either with window or not but the problem it focus and got the style for just a 0.00001 seconds its like blinking
Abubakar Sambo
@sastech
May 11 2017 00:08
@LASTBORNMESH thanks. I will try it now
CamperBot
@camperbot
May 11 2017 00:08
sastech sends brownie points to @lastbornmesh :sparkles: :thumbsup: :sparkles:
:cookie: 205 | @lastbornmesh |http://www.freecodecamp.com/lastbornmesh
john94
@lpy1994
May 11 2017 00:08
@sjames1958gm thx man! I like how you change your profile pic frequently btw.
CamperBot
@camperbot
May 11 2017 00:08
lpy1994 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7229 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
May 11 2017 00:08
@lpy1994 :+1:
HeebieGeeBee
@HeebieGeeBee
May 11 2017 00:09
@Asher2016 well youve got it repeating every 10 milliseconds
is that what you want?
Javed Kadri
@devajirdak
May 11 2017 00:10

// Setup
var myStr = "Jello World";

// Only change code below this line

myStr = "Hello World";
myStr[0] = "H"; // Fix Me

hey guys, what am I doing wrong ? I get TypeError: Attempted to assign to readonly property. Error
Pagnito
@Pagnito
May 11 2017 00:13
why is when i subtract 20 from 96.74 i get 76.74 and then again i get 56.7399999...?
this shit is fckn up my whole cash register
HeebieGeeBee
@HeebieGeeBee
May 11 2017 00:14
floating point inprecision
@devajirdak delete that last line
Stephen James
@sjames1958gm
May 11 2017 00:15
@devajirdak You didn't fix the line it told you to, you added a new one.
Pagnito
@Pagnito
May 11 2017 00:15
@HeebieGeeBee so what should i do
HeebieGeeBee
@HeebieGeeBee
May 11 2017 00:15
depends on your setup
Danny
@danieldsutter
May 11 2017 00:16
@devajirdak What was the original code?
HeebieGeeBee
@HeebieGeeBee
May 11 2017 00:16
easiest way is to multiply all your values by 100
and then before you have to return them divide the value by 100
Pagnito
@Pagnito
May 11 2017 00:17
@HeebieGeeBee hmm, ok yea i see, thanks
CamperBot
@camperbot
May 11 2017 00:17
pagnito sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1618 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
Yonaton Rose
@yonatonrose
May 11 2017 00:19
hey how do i complete the shopping list challenge? it keeps on telling me that i need the first elements of the arrays to be strings and the second to be numbers but to me it looks like they are
Stephen James
@sjames1958gm
May 11 2017 00:20
@yonatonrose Show your code -
Yonaton Rose
@yonatonrose
May 11 2017 00:21
Screen Shot 2017-05-10 at 8.21.15 PM.png
Stephen James
@sjames1958gm
May 11 2017 00:22
@yonatonrose You have some extra [ and ] towards the end before water and after juice
This makes the 4th entry and array of arrays and not string and number
Yonaton Rose
@yonatonrose
May 11 2017 00:23
wow thanks @sjames1958gm i thought thats what made sub arrays
CamperBot
@camperbot
May 11 2017 00:23
yonatonrose sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7230 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
May 11 2017 00:23
@yonatonrose That is one more level deep [["chocolate", 1]] this is a subarray one level deep - those extra [] created two levels deep
John Edwards
@javajohnHub
May 11 2017 00:25
Ive just recently got into jquery and im digging it....anyone have a cool example they want to share
Alexey Zamsheen
@jeranimo
May 11 2017 00:26

Hi, everypony!!!
I want to ask, if anybody already did task #241 or maybe somebody knows a better and smarter way ro solve this goal, please write me in private chat.
Challenge was to find a longest word in a string, and to return it length.
My solution look like this:


function findLongestWord(str) {

  var a = str.split(" ");
  var x = 0;
  var f = a[0].length;
  var l = a[a.length -1].length;

  if( f > l ){
     x = f;
   }else if( l > f ){
     x = l;
   }
 for(var i = 1; i < a.length -2; i++){
   var y = a[i].length;
   if(y >= a[i+1].length && y >= a[i-1].length && y > x){
     x = y;
   }
 }
  return x;



}


findLongestWord("What is the average airspeed velocity of an unladen swallow");

Thanks everyone in advance!!!

Javed Kadri
@devajirdak
May 11 2017 00:27
@danieldsutter @HeebieGeeBee Thank you guys I solved it.
CamperBot
@camperbot
May 11 2017 00:27
devajirdak sends brownie points to @danieldsutter and @heebiegeebee :sparkles: :thumbsup: :sparkles:
:warning: @danieldsutter's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
:star2: 1619 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
Stephen James
@sjames1958gm
May 11 2017 00:31
@jeranimo Create a local variable that is the current longest (initialize to zero) then compare each word
length to that and update if longer. That way you don't have extra code for a[0] and a[a.length-1]
You are just if (a[i].length > longest) longest = a[i].length
then return longest
Roly desouza
@rolydesouza
May 11 2017 00:38
var myStr ="FirstLine\n\SecondLine\\rThirdline";
this is what i have for #144 can anyone help me out or lead me in the right direction
Alexey Zamsheen
@jeranimo
May 11 2017 00:42
@sjames1958gm Thanks! I've tried at first the way that you suggest but I was confused and nothing worked out! Most likely I was wrong somewhere...
If it's not difficult for you, can you improve my code, please???
CamperBot
@camperbot
May 11 2017 00:42
jeranimo sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7231 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Yonaton Rose
@yonatonrose
May 11 2017 00:43
@rolydesouza you need one more slash in front of secondline and one more after it as well
Stephen James
@sjames1958gm
May 11 2017 00:43
@jeranimo
   var a = str.split(' ');

   var longest = 0;
   for (var i = 0; i < a.length; i++) {
     if (a[i].length > longest) {
       longest = a[i].length;
     }
   }
   return longest
@rolydesouza ThirdLine need upper case L
Yonaton Rose
@yonatonrose
May 11 2017 00:43
to make a backslash u need to use two or it wont show up
Alexey Zamsheen
@jeranimo
May 11 2017 00:44
Thanks a lot!!!
Stephen James
@sjames1958gm
May 11 2017 00:44
@jeranimo :+1:
Roly desouza
@rolydesouza
May 11 2017 00:45
what a dummy thanks guys
Yonaton Rose
@yonatonrose
May 11 2017 00:47
@rolydesouza np
Maryam Mostajir
@maryam-mv
May 11 2017 00:48
Hey everyone, I'm working on "Profile Lookup" and am utterly confused. Anyone free to help?
Coy Sanders
@coymeetsworld
May 11 2017 00:51
what do you have so far @maryam-mv ?
Mohamed Derhalli
@derhallim
May 11 2017 00:51
@maryam-mv share ur code?
Maryam Mostajir
@maryam-mv
May 11 2017 00:51

//Setup
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["Javascript", "Gaming", "Foxes"]
}
];

function lookUpProfile(firstName, prop){
// Only change code below this line

var test = lookUpProfile.hasOwnProperty(firstName, prop);
var contact = lookUpProfile.hasOwnProperty(firstName);
if (test === true) {
return lookUpProfile([firstName, prop]);
}
else if (contact === true) {
return "No such contact";
} else {
return "No such property";
}

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Bob", "number");

...there's probably a better way to do that.. soz!
Coy Sanders
@coymeetsworld
May 11 2017 00:52
you don't refer to lookUpProfile again inside the function @maryam-mv, you want to run them on the objects inside the array contacts
Mohamed Derhalli
@derhallim
May 11 2017 00:52
why this: var test = lookUpProfile.hasOwnProperty(firstName, prop); ?
Maryam Mostajir
@maryam-mv
May 11 2017 00:52
That was provided :/
Coy Sanders
@coymeetsworld
May 11 2017 00:53
also you don't need to check if a contact has the property first name, you can assume all contacts have a name
provided where @maryam-mv ?
Mohamed Derhalli
@derhallim
May 11 2017 00:53
u need someway to loop through the array of contacts.. and see if each contact has that property
Danny
@danieldsutter
May 11 2017 00:53

function smallestCommons(arr) {
//create an array to store the whole range of numbers
  var allNumbersArray = [];

  //arrange the numbers in arr from lowest to highest
  arr.sort(function(a,b) {
    return b-a;
  });

  //fill in allNumbersArray with the whole range of numbers
  for (var i=arr[0]; i>=arr[1]; i--) {
    allNumbersArray.push(i);
  }

  //magic math stuff


  //return the answer...eventually
  return allNumbersArray;
}


smallestCommons([1,5]);
Trying to find the smallest common multiple, which seems by far the hardest challenge yet. I've looked up Euclid's algorithm, but am feeling pretty clueless on where go between "//magic math stuff" and "return the answer...eventually". Any tips?
Mohamed Derhalli
@derhallim
May 11 2017 00:54
think about a way to loop through the contacts array, then check each object if it contains the property @maryam-mv ;)
but u need to match the one with the name provided
Maryam Mostajir
@maryam-mv
May 11 2017 00:54
I will try! :) Thank you!! @derhallim
CamperBot
@camperbot
May 11 2017 00:54
maryam-mv sends brownie points to @derhallim :sparkles: :thumbsup: :sparkles:
:cookie: 330 | @derhallim |http://www.freecodecamp.com/derhallim
Mohamed Derhalli
@derhallim
May 11 2017 00:55
@danieldsutter which challenge is that?
nsonhouse
@nsonhouse
May 11 2017 00:56
@JLuboff Im back. I found out part of the command while at work today. But I still have a problem.
Danny
@danieldsutter
May 11 2017 00:56
Smallest Common Multiple. I have to find the scm of all numbers in the given range. @derhallim
nsonhouse
@nsonhouse
May 11 2017 00:56
@JLuboff connection.query('UPDATE products SET ? WHERE ?' , [
{ item_id: itemid },
{ item_quantity - qty }],
                           function(err, res){
                               if (err) {
                                   console.error(err);
                                   consoloe.error(result);
                               }
                               return;
@JLuboff This line is a problem: { item_quantity - qty }],
Mohamed Derhalli
@derhallim
May 11 2017 00:57
@danieldsutter why are u making a new array inside
Bruno Calhiari
@calhiari
May 11 2017 00:57
hey guys
Danny
@danieldsutter
May 11 2017 00:58
@derhallim I assumed that would be the easiest way to catch each number in the range.
Bruno Calhiari
@calhiari
May 11 2017 00:58
//waits the page to be all loaded
$(document).ready(function()
{    
    var i = 0;

    //triggered when the button is clicked
    $(".generator").on("click", function()
    {
        //receive the API
        $.ajax({method: "POST",
                      url: "https://andruxnet-random-famous-quotes.p.mashape.com/?cat=famous&count=1",
                      headers: {"X-Mashape-Key": "NKRgGDYOzcmshoW3goPeV4wTmIlrp1QE5NDjsnRywWvyCblUQ1"},
                      success: function(getQuote)
                        {                            
                            getQuote = JSON.parse(getQuote); //transforms the JSON text in a JavaScript object

                            $(".quote").html(getQuote.quote);
                            $(".author").html(getQuote.author);
                        }
                     });    

        var imgSrc = "https://unsplash.it/" + window.screen.width + "/" + window.screen.height + "/?random";

        $(".getImage").css("background-image", "url(" + imgSrc + ")");

        document.body.className = "getImage";
    });
});
can someone tell me why this background image only loads after clicking 2x on the button
this is from my codepen, i can send the link here too
grfraser
@grfraser
May 11 2017 00:59
Excercise "Factorialize a Number" says Factorials are often represented with the shorthand notation n!
I cannot find any documentation on this and it does not work when i try it. whats the deal with n!?
Mohamed Derhalli
@derhallim
May 11 2017 01:00
@grfraser n! means factorial
Coy Sanders
@coymeetsworld
May 11 2017 01:00
no documentation on factorialize? @grfraser
Mohamed Derhalli
@derhallim
May 11 2017 01:00
5! = 5 x 4 x 3 x 2 x 1
Mohamed Derhalli
@derhallim
May 11 2017 01:00
n! = n x n-1 x n-2 .... 1
Coy Sanders
@coymeetsworld
May 11 2017 01:00
:point_up: and what @derhallim said
David Amanze
@GodKingShogun
May 11 2017 01:00
anyone know how i can use a secure and unsecure get request together
Bruno Calhiari
@calhiari
May 11 2017 01:00
@grfraser man, you need to make a function which will return the factoria of a number
can someone help me with the code or tell me what i should read to learn about this?
Danny
@danieldsutter
May 11 2017 01:01
@calhiari Can you link to the codepen?
it only load the image after clicking 2x
Mohamed Derhalli
@derhallim
May 11 2017 01:03
@GodKingShogun what do u mean?
Kevin Peña
@kebien6020
May 11 2017 01:04
@calhiari because you put the class on the body after you try to apply the css so the selector doesnt match anything. The second time the class is already applied from the previous time
WillGITCode
@WillGITCode
May 11 2017 01:04
@danieldsutter that is the way I did it. since you now have an array of all the numbers in question now. doesnt that remind you of what a loop variable looks like as it iterates.... ex(1, 2, 3, 4, 5) :)
Bruno Calhiari
@calhiari
May 11 2017 01:05
@kebien6020 ooooo i see, i thought it needed to be there before i apply the class to the body
lemme try
@kebien6020 thanks man :smile:
CamperBot
@camperbot
May 11 2017 01:06
calhiari sends brownie points to @kebien6020 :sparkles: :thumbsup: :sparkles:
:cookie: 198 | @kebien6020 |http://www.freecodecamp.com/kebien6020
Bruno Calhiari
@calhiari
May 11 2017 01:06
it is working now
Daniel Zeff
@Diesirae9
May 11 2017 01:06
HMMMMM
I am stuck palindroming
Mohamed Derhalli
@derhallim
May 11 2017 01:07
@Diesirae9 can u post ur code?
Daniel Zeff
@Diesirae9
May 11 2017 01:07

function palindrome(str) {
if (str.split("").reverse().join("") == str){
return true;
}
return false;
}

palindrome("racecar");

Bruno Calhiari
@calhiari
May 11 2017 01:08
@Diesirae9 man, you're doing the right process, split(), reverse(), then join()...you just need to work around your code
Daniel Zeff
@Diesirae9
May 11 2017 01:08
So that works, and the boolean is true, but if I alter it in anyway the boolean is false
Danny
@danieldsutter
May 11 2017 01:08
@WillGITCode Thanks for the tip. I haven't really had to use anything other than for loops. Guess I'm going to read the loops documentation some more and see if one of the other types would do this for me.
CamperBot
@camperbot
May 11 2017 01:08
danieldsutter sends brownie points to @willgitcode :sparkles: :thumbsup: :sparkles:
:cookie: 311 | @willgitcode |http://www.freecodecamp.com/willgitcode
Mohamed Derhalli
@derhallim
May 11 2017 01:09
@Diesirae9 what do u mean u alter it?
Daniel Zeff
@Diesirae9
May 11 2017 01:10
palindrome("Racecar"); would return false
Bruno Calhiari
@calhiari
May 11 2017 01:10
@Diesirae9 you can search for arguments to use with these functions for make all words lower case, and to get rid of the blank spaces or special characters
because it has the first letter in upper case
Daniel Zeff
@Diesirae9
May 11 2017 01:10
right
Bruno Calhiari
@calhiari
May 11 2017 01:10
you need to make all letter in lower case or uppercase
Danny
@danieldsutter
May 11 2017 01:10
@Diesirae9 string.toLowerCase()
Mohamed Derhalli
@derhallim
May 11 2017 01:10
^
you'll also need to get rid of special and blank characters
Daniel Zeff
@Diesirae9
May 11 2017 01:11
as well an argument that will remove special characters
you'll find those reading these links
Daniel Zeff
@Diesirae9
May 11 2017 01:12
awesome thanks @derhallim @calhiari
CamperBot
@camperbot
May 11 2017 01:12
diesirae9 sends brownie points to @derhallim and @calhiari :sparkles: :thumbsup: :sparkles:
:cookie: 287 | @calhiari |http://www.freecodecamp.com/calhiari
:cookie: 331 | @derhallim |http://www.freecodecamp.com/derhallim
Daniel Zeff
@Diesirae9
May 11 2017 01:13
Some light reading for my evening!
Bruno Calhiari
@calhiari
May 11 2017 01:13
@Diesirae9 you also need to learn about regular expressions, to know how to pass the arguments
Daniel Zeff
@Diesirae9
May 11 2017 01:14
/" "/gi
David Amanze
@GodKingShogun
May 11 2017 01:14
@derhallim im chaning get request. some of them are http and some are https. i get an error in my console saying i cant do that
Daniel Zeff
@Diesirae9
May 11 2017 01:14
those guys right?
Bruno Calhiari
@calhiari
May 11 2017 01:15
it seems right, but there are more arguments you can pass to make your life easier
to remove special characters
@GodKingShogun what are you doing?
i went tough this today
through*
Daniel Zeff
@Diesirae9
May 11 2017 01:16
Look at me remembering things! doesn't mean I know how to use them yet.
looking at my notes I need /s/
WillGITCode
@WillGITCode
May 11 2017 01:16
Im feeling stuck on the JavaScript calculator challenge... Im am unsure how to make my code architecture for the operations. should i make a function for each button or a manager function. Im not sure
Bruno Calhiari
@calhiari
May 11 2017 01:16
@Diesirae9 hey, this site helps to create the right regular expression http://regexr.com/
Andrew
@VirtuaBoza
May 11 2017 01:17
super stuck on Chunky Monkey. This is my first time asking for help, so idk the protocol. Should I paste my code here???
Bruno Calhiari
@calhiari
May 11 2017 01:18
@VirtuaBoza copy your code here and the link to the challenge, it will help people know what are you talking about to help you
David Amanze
@GodKingShogun
May 11 2017 01:18
@calhiari im doing the weather app
Bruno Calhiari
@calhiari
May 11 2017 01:19
@GodKingShogun i'm on the random quotes machine yet, but try to find an API in this site, because they also use https https://market.mashape.com/dashboard
@VirtuaBoza to post codes you need to use ``` before and after
'''
CamperBot
@camperbot
May 11 2017 01:20
:bulb: to format code use backticks! ``` more info
Andrew
@VirtuaBoza
May 11 2017 01:21
function chunkArrayInGroups(arr, size) { var myArray = []; var rows = Math.ceil(arr.length / size); for (var i = 0; i < rows; i++) { if (i < rows - 1) {myArray.push(arr.slice(i * size,size));} else {myArray.push(arr.slice(i*size));} } return myArray; }
David Amanze
@GodKingShogun
May 11 2017 01:22
@calhiari @calhiari nice thanks
CamperBot
@camperbot
May 11 2017 01:22
godkingshogun sends brownie points to @calhiari :sparkles: :thumbsup: :sparkles:
:cookie: 288 | @calhiari |http://www.freecodecamp.com/calhiari
Bruno Calhiari
@calhiari
May 11 2017 01:22
@VirtuaBoza almost there

lemme help you

```function chunkArrayInGroups(arr, size) {
  var myArray = [];
  var rows = Math.ceil(arr.length / size);
  for (var i = 0; i < rows; i++) {
    if (i < rows - 1) {myArray.push(arr.slice(i * size,size));}
    else {myArray.push(arr.slice(i*size));}
  }
  return myArray;
}

```

Andrew
@VirtuaBoza
May 11 2017 01:22
ugh! thanks
Bruno Calhiari
@calhiari
May 11 2017 01:23
send the link to the challenge too
so you need to break an array into an array of arrays, so I start by getting how many rows (arrays) I'll need, then I push the slices in by row. It works for the first and last rows, but my middle rows are always empty
Bruno Calhiari
@calhiari
May 11 2017 01:25
you're doing the right think, using all the methods needed to finish
im a beginner into javascript too, let me try to find something wrong
Andrew
@VirtuaBoza
May 11 2017 01:27
meanwhile, I'll see about figuring out how to use markup in slack lol
Bruno Calhiari
@calhiari
May 11 2017 01:28
you dont need the brackets if the conditionals take only 1 line
deaninous
@deaninous
May 11 2017 01:29
it wants subArrays of seize seize up to the length of arr
Andrew
@VirtuaBoza
May 11 2017 01:29
@calhiari true, but it doesn't fix it
@deaninous I don't understand what you're saying
Bruno Calhiari
@calhiari
May 11 2017 01:31
yeah, i'm still figuring out
diegoxro
@diegoxro
May 11 2017 01:32
@VirtuaBoza arr.slice(), are your args correct?
Andrew
@VirtuaBoza
May 11 2017 01:33
@diegoxro Not sure what you're asking
diegoxro
@diegoxro
May 11 2017 01:36
@VirtuaBoza also the if is not needed
Tegh
@teghmehta
May 11 2017 01:36

function sym(args) {
  var arr = [];
  function symDiff() {

  }

  for (i = 0; i < arguments.length; i++) {
    for (j = 0; j < arguments[i].length; j++) {
      arr.push(arguments[i][j]);
    }
  }

  arr = arr.sort();
  var b = [];
  var a = arr.filter(function(elem, index, self) {
    if (index == self.indexOf(elem)) b.push(elem);
    return index == self.indexOf(elem);
  });
  function symDif() {
    return b;
  }

  console.log(b);

  return arr.reduce(symDif);
}

sym([1, 2, 3], [5, 2, 1, 4]);
Bruno Calhiari
@calhiari
May 11 2017 01:36
your second argument in slice is wrong, because it will become less than the first while the for iterates
Tegh
@teghmehta
May 11 2017 01:36
Why isnt it returning the reduced version
Bruno Calhiari
@calhiari
May 11 2017 01:37
@VirtuaBoza try to fix the second argument in the slice method
Ogundele Olumide
@Lumexralph
May 11 2017 01:37
@teghmehta arr = arr.sort(); you're sorting according to string characters
Stephen James
@sjames1958gm
May 11 2017 01:38
@teghmehta Your reduce function doesn't do any reducing, it will just return the value of b
Andrew
@VirtuaBoza
May 11 2017 01:38
@calhiari Oooooooooh!
diegoxro
@diegoxro
May 11 2017 01:38
@VirtuaBoza @calhiari also the if is not needed, all you are doing is slicing the array. it's better if he does it in the for() conditional
Andrew
@VirtuaBoza
May 11 2017 01:38
I had been treating that second arg as the length i need to pull, but it's the END!
Ogundele Olumide
@Lumexralph
May 11 2017 01:38
@teghmehta if you want to sort according to numbers your sort method needs a callback as argument to do that for you
Vicky Lai
@vickylai
May 11 2017 01:39
Good morning world!
Stephen James
@sjames1958gm
May 11 2017 01:39
@vickylaiio Good Evening :)
Ogundele Olumide
@Lumexralph
May 11 2017 01:39
@vickylaiio Morning
Vicky Lai
@vickylai
May 11 2017 01:39
Can anyone help with if statement at line 46. It doesn't seem to run...
https://codepen.io/vickylaiio/pen/RVMwmj?editors=0012#
diegoxro
@diegoxro
May 11 2017 01:40
@VirtuaBoza I used the size as my increment in the for loop. no need for if.
willyg556
@willyg556
May 11 2017 01:40
Hello fellas Im having trouble with the escape sequences in strings. This is my code so far. I am getting stuck . var myStr = "FirstLine\n\\SecondLine\\n\rThirdLine";
Bruno Calhiari
@calhiari
May 11 2017 01:40
@diegoxro sure
Vicky Lai
@vickylai
May 11 2017 01:40
I'm already thinking this is waaay more lines than a roman numerals conversion should need... but I just want to see it work first before I start golfing :sweat_smile:
Andrew
@VirtuaBoza
May 11 2017 01:41
Problem solved. Thanks @calhiari and @diegoxro
CamperBot
@camperbot
May 11 2017 01:41
virtuaboza sends brownie points to @calhiari and @diegoxro :sparkles: :thumbsup: :sparkles:
:cookie: 268 | @diegoxro |http://www.freecodecamp.com/diegoxro
:cookie: 289 | @calhiari |http://www.freecodecamp.com/calhiari
Bruno Calhiari
@calhiari
May 11 2017 01:41
@diegoxro he already used the rows, which he created to the for loop counting
Ogundele Olumide
@Lumexralph
May 11 2017 01:41
@willyg556 SecondLine\\\rThirdLine
FlashHero
@FlashHero
May 11 2017 01:41
var obj={
  name:'unknown',
  hobbie:'nothing'
}
var pop=Array.prototype.pop.call(obj);
console.log(pop);
Why don't this work ?
Bruno Calhiari
@calhiari
May 11 2017 01:41
@VirtuaBoza hahaha nice, send here what you did
diegoxro
@diegoxro
May 11 2017 01:41
@vickylaiio you got the right base cases
@VirtuaBoza yeah I would like to see
Bruno Calhiari
@calhiari
May 11 2017 01:41
i was trying to understand your code, then i opened mine too
it took me a while to solve this one too
Ogundele Olumide
@Lumexralph
May 11 2017 01:42
@vickylaiio if you're returning in a loop, it might not look like it ran
Vicky Lai
@vickylai
May 11 2017 01:42
@diegoxro Yeah it mostly works..
@Lumexralph There's no return in that one
Andrew
@VirtuaBoza
May 11 2017 01:42
Solved problem:
function chunkArrayInGroups(arr, size) {
  var myArray = [];
  var rows = Math.ceil(arr.length / size);
  for (var i = 0; i < rows; i++) {
    if (i < rows - 1) myArray.push(arr.slice(i*size,i*size + size));
    else myArray.push(arr.slice(i*size));
  }
  return myArray;
}
Ogundele Olumide
@Lumexralph
May 11 2017 01:42
@FlashHero is obj an array?
Vicky Lai
@vickylai
May 11 2017 01:42
Also the console.log()s aren't printing so I know it hasn't entered
diegoxro
@diegoxro
May 11 2017 01:43
@VirtuaBoza nice
Andrew
@VirtuaBoza
May 11 2017 01:43
My second argument in the slice is now i*size + size instead of just size
Bruno Calhiari
@calhiari
May 11 2017 01:43
i used size(1 + i) at mine
FlashHero
@FlashHero
May 11 2017 01:43
@Lumexralph I thought I can indirectly call array methods on objects
Ogundele Olumide
@Lumexralph
May 11 2017 01:43
@vickylaiio when you return in a loop, it runs once and exits the function making it look like it didn't run
Bruno Calhiari
@calhiari
May 11 2017 01:43
you can get rid of your if else statement
diegoxro
@diegoxro
May 11 2017 01:44
function chunkArrayInGroups(arr, size) {
  // Break it up.
var slicedArray = [];
    //console.log("Testing " + arr +" " + size);  
for(var i = 0 ; i < arr.length; i +=size){
    var sliced = slicedArray.push(arr.slice(i, i + size)) ;

    //console.log("Start" + i );
    //console.log("end" + (i + size ) );
    }
    return slicedArray ;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
Bruno Calhiari
@calhiari
May 11 2017 01:44
even with the else entire line
Ogundele Olumide
@Lumexralph
May 11 2017 01:44
@FlashHero the type of your data is important
Andrew
@VirtuaBoza
May 11 2017 01:44
javascript won't care if the array being sliced isn't as long as the second argument???
diegoxro
@diegoxro
May 11 2017 01:45
nope
Andrew
@VirtuaBoza
May 11 2017 01:45
oh ol
*ok
diegoxro
@diegoxro
May 11 2017 01:45
that's something I considered too
FlashHero
@FlashHero
May 11 2017 01:45
@Lumexralph so when do I actually use Array.prototype
Bruno Calhiari
@calhiari
May 11 2017 01:45
If end is greater than the length of the sequence, slice extracts through the end of the sequence (arr.length).
Andrew
@VirtuaBoza
May 11 2017 01:45
I see
Bruno Calhiari
@calhiari
May 11 2017 01:45
^ secnod argument
diegoxro
@diegoxro
May 11 2017 01:46
well is not js that does not care, it's the slice() that was designed that way
hence the if is redundant
Andrew
@VirtuaBoza
May 11 2017 01:46
got it
Michael
@seqwith
May 11 2017 01:46
Howdy, new programmer here, and I seem to be stuck on the Profile Lookup challenge, everything seems to work, in fact if I test everything within the code it works, but it will still not pass me.
Ogundele Olumide
@Lumexralph
May 11 2017 01:47
@FlashHero Array.prototype has array methods stored there and you need an array or character sequence to use it
Vicky Lai
@vickylai
May 11 2017 01:47
@Lumexralph There's no return in that one.
deaninous
@deaninous
May 11 2017 01:47
If everything works then there might be a bug
Bruno Calhiari
@calhiari
May 11 2017 01:47
@seqwith send the code and the link to the challenge, i'll try to help
Ogundele Olumide
@Lumexralph
May 11 2017 01:47
@seqwith show your code
Bruno Calhiari
@calhiari
May 11 2017 01:48
wrap your code with these ``` above and under, so it will show properly
'''
CamperBot
@camperbot
May 11 2017 01:48
:bulb: to format code use backticks! ``` more info
Ogundele Olumide
@Lumexralph
May 11 2017 01:49
@vickylaiio
for (var key in rNums) {
    //see if num == any rNums, if so, print value 'cause we're done
    if (num == key) {
        return rNums[num];
    }
}//end iterate through rNums
FlashHero
@FlashHero
May 11 2017 01:49
@Lumexralph ok thanks
CamperBot
@camperbot
May 11 2017 01:49
flashhero sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1713 | @lumexralph |http://www.freecodecamp.com/lumexralph
Michael
@seqwith
May 11 2017 01:50
` for (var i = 0; i < contacts.length; i++) {
if (contacts[i].firstName === firstName) {
if (contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
} else {
return "No such property";
}
}
}
return "No Such Contact"'
Vicky Lai
@vickylai
May 11 2017 01:50
@Lumexralph If num doesn't == key, it doesn't return.
Ogundele Olumide
@Lumexralph
May 11 2017 01:50
@seqwith return no such contact
Vicky Lai
@vickylai
May 11 2017 01:50
And I'm saying that everything works, except the if statement in line 46.
Ogundele Olumide
@Lumexralph
May 11 2017 01:51
@vickylaiio the truth is if you can post the code here, it'll be easier to debug
Bruno Calhiari
@calhiari
May 11 2017 01:51
@seqwith lemme help
 for (var i = 0; i < contacts.length; i++) {
if (contacts[i].firstName === firstName) {
if (contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
} else {
return "No such property";
}
}
}
return "No Such Contact"
Vicky Lai
@vickylai
May 11 2017 01:51
Dude, I did.
Joseph
@Aerofils
May 11 2017 01:51
Hey All, having trouble with this problem

// Setup
var testObj = {
12: "Namath",
16: "Montana",
19: "Unitas"
};

// Only change code below this line;

var playerNumber=16; // Change this Line
var player = testObj[]; // Change this Line

Not sure what's wrong :/
Ogundele Olumide
@Lumexralph
May 11 2017 01:52
@Aerofils use playerNumber to access testObj and assign the returning value to player
Michael
@seqwith
May 11 2017 01:52
@calhiari sorry still new to this site, how do I do that?
Iris Shields
@calluna
May 11 2017 01:52
Hi,
Joseph
@Aerofils
May 11 2017 01:53
like this?

// Setup
var testObj = {
12: "Namath",
16: "Montana",
19: "Unitas"
};

// Only change code below this line;

var playerNumber=test0bj; // Change this Line
var player = [playernumber:16]; // Change this Line

Iris Shields
@calluna
May 11 2017 01:53

with make object properties private, why is the example object setChange speed =+ change, but when I make a bike object the exercise will only pass if I use just a =

var Car = function() {
// this is a private variable
var speed = 10;

// these are public methods
this.accelerate = function(change) {
speed += change;
};

this.decelerate = function() {
speed -= 5;
};

this.getSpeed = function() {
return speed;
};
};

var Bike = function() {

// Only change code below this line.
var gear = 0;

this.setGear = function(shift) {
gear = shift;
};
this.reSetGear = function() {
gear -= 5;
};
this.getGear = function() {
return gear;
};

};

var myCar = new Car();

var myBike = new Bike();

Bruno Calhiari
@calhiari
May 11 2017 01:53
@seqwith you need to put it 3x above and under your code, you can read more in the link '''
Joseph
@Aerofils
May 11 2017 01:53
im kind of lost tbh
CamperBot
@camperbot
May 11 2017 01:53
:bulb: to format code use backticks! ``` more info
Bruno Calhiari
@calhiari
May 11 2017 01:54
^ this link
Ogundele Olumide
@Lumexralph
May 11 2017 01:54
@Aerofils use it with testObj
Michael
@seqwith
May 11 2017 01:54
gotcha, thanks...
Bruno Calhiari
@calhiari
May 11 2017 01:54
you're welcome
Ogundele Olumide
@Lumexralph
May 11 2017 01:55
@calluna where did you get this method?
this.reSetGear = function() {
gear -= 5;
};
Michael
@seqwith
May 11 2017 01:55
for (var i = 0; i < contacts.length; i++) { if (contacts[i].firstName === firstName) { if (contacts[i].hasOwnProperty(prop)) { return contacts[i][prop]; } else { return "No such property"; } } } return "No Such contact";
Bruno Calhiari
@calhiari
May 11 2017 01:55
almost there, hold shift while pressing enter will help
then to send you press ctrl+enter
Michael
@seqwith
May 11 2017 01:56
yeah, just seen that...not trying to spam you guys and gals to much, sorry
Bruno Calhiari
@calhiari
May 11 2017 01:57
no problem, we know you're only trying to learn how it works
Michael
@seqwith
May 11 2017 01:57
  for (var i = 0; i < contacts.length; i++) {
    if (contacts[i].firstName === firstName) {
      if (contacts[i].hasOwnProperty(prop)) {
        return contacts[i][prop];
      } else {
      return "No such property";
      }
    }
  }
  return "No Such contact";
Iris Shields
@calluna
May 11 2017 01:57
@Lumexralp somebody else said to use it, but it acts the same without it. I can only get the exercise to pass if I only use a "=" and not a "+=" like the example. even though the test results are correct
with either
Ogundele Olumide
@Lumexralph
May 11 2017 01:58
@seqwith No Such contact" Such==> such
Bruno Calhiari
@calhiari
May 11 2017 01:58
@seqwith you have an uppercase in No Such contact
just put the s in lowercase because javascript is case sensitive
Joseph
@Aerofils
May 11 2017 01:59
@Lumexralph it makes no sense. says playernumber is not defined

// Setup
var testObj = {
12: "Namath",
16: "Montana",
19: "Unitas"
};

// Only change code below this line;

var playerNumber = 16; // Change this Line
var player = testObj[playernumber]; // Change this Line

I put playernumber = 16, how is that not defnied
defined...
Michael
@seqwith
May 11 2017 01:59
OMG, did not think about case sensitivity...:(
Bruno Calhiari
@calhiari
May 11 2017 02:00
everyone have been there haha
Ogundele Olumide
@Lumexralph
May 11 2017 02:00
@calluna can you use another parameter name other than shift ?
@Aerofils playernumbe ==> playerNumber
deaninous
@deaninous
May 11 2017 02:00
@Aerofils check out the cases. js is very sensitive with its cases
Michael
@seqwith
May 11 2017 02:00
Thank you, I knew it had to be something simple. Glad I learned something today thanks everyone.
Ogundele Olumide
@Lumexralph
May 11 2017 02:00
@seqwith :+1:
Bruno Calhiari
@calhiari
May 11 2017 02:01
you're welcome :smile: @seqwith
Joseph
@Aerofils
May 11 2017 02:01
@Lumexralph @deaninous thanks guys
CamperBot
@camperbot
May 11 2017 02:01
aerofils sends brownie points to @lumexralph and @deaninous :sparkles: :thumbsup: :sparkles:
:cookie: 341 | @deaninous |http://www.freecodecamp.com/deaninous
:star2: 1714 | @lumexralph |http://www.freecodecamp.com/lumexralph
Iris Shields
@calluna
May 11 2017 02:01
@Lumexralph sure, I can use any word, it behaves the same. It will only pass the exercise without the "+" even though the example above it (Car) does pass with the "+"
deaninous
@deaninous
May 11 2017 02:02
:thumbsup: @Aerofils
Ogundele Olumide
@Lumexralph
May 11 2017 02:03
@calluna your setGear method is to take a parameter it assigns to gear using = not +=
@calluna the example was showing but you're not expected to do exactly as it was done
David Amanze
@GodKingShogun
May 11 2017 02:04
anyone know how i can request a secure http on an unsecure http and revise verse
Ogundele Olumide
@Lumexralph
May 11 2017 02:04
@calluna your code is good
Humayun Khan
@humayunk
May 11 2017 02:12

Hey guys - stuck on "Escape Sequence in Strings"

have this:

var myStr = "FirstLine\n\SecondLine\\rThirdline";

but still getting the error
"myStr should have encoded text with the proper escape sequences and no spacing."

Thoughts?

Ogundele Olumide
@Lumexralph
May 11 2017 02:13
@humayunk Thirdline ==> ThirdLine
Humayun Khan
@humayunk
May 11 2017 02:13
@Lumexralph dang, good eye. Thanks so much.
CamperBot
@camperbot
May 11 2017 02:13
humayunk sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1715 | @lumexralph |http://www.freecodecamp.com/lumexralph
Ogundele Olumide
@Lumexralph
May 11 2017 02:14
@humayunk :+1:
Brittany Rutherford
@brittanyrutherford
May 11 2017 02:22
how can I know if I need to install dependencies globally or use --save-dev?
Bruno Calhiari
@calhiari
May 11 2017 02:30
@VirtuaBoza just took 1 hour to see that you maked me hahahaha
yash5657
@yash5657
May 11 2017 02:33
@brittanyrutherford it just depends on your application..
Claudio Restifo
@Marmiz
May 11 2017 02:33
@brittanyrutherford some packages needs to run globally, but are few and mainly for scaffolding/utility.
for the rest the idea is that you save in dev the dependency that you use while writing but your program don't need to in order to run.
for example (and is quite controversial) Webpack, some people like it in dev because once the file is bundle for production and shipped you technically don't need it...
yash5657
@yash5657
May 11 2017 02:33
@brittanyrutherford Using --save-dev is fine when you're writing a simple application, and it won't be used as a library. The problem comes along when you might have dependencies
Claudio Restifo
@Marmiz
May 11 2017 02:33
Yarn has a good description of the idea behind:
https://yarnpkg.com/en/docs/dependency-types#toc-dev-dependencies
Brittany Rutherford
@brittanyrutherford
May 11 2017 02:33
thanks @Marmiz @yash5657
CamperBot
@camperbot
May 11 2017 02:33
brittanyrutherford sends brownie points to @marmiz and @yash5657 :sparkles: :thumbsup: :sparkles:
:cookie: 859 | @marmiz |http://www.freecodecamp.com/marmiz
:cookie: 198 | @yash5657 |http://www.freecodecamp.com/yash5657
Brittany Rutherford
@brittanyrutherford
May 11 2017 02:34
i think --save-dev should only be for testing libraries and typescript?
Manish Giri
@Manish-Giri
May 11 2017 02:34
@Lumexralph :wave:
@Marmiz :wave:
Ogundele Olumide
@Lumexralph
May 11 2017 02:35
@Manish-Giri wahhhhh?!
Manish Giri
@Manish-Giri
May 11 2017 02:35
:smiling_imp:
Claudio Restifo
@Marmiz
May 11 2017 02:36
@brittanyrutherford depends a lot on your app. For example if you're making a React page, React is mandatory but Babel, even tho used to transcript, can be listed as a Dev dependencies since your program run even without it :)
@Manish-Giri good day sir :wave:
Brittany Rutherford
@brittanyrutherford
May 11 2017 02:37
do I need to reuse same dev dependencies in each project? no way to centralize them and reuse them everywhere?
Claudio Restifo
@Marmiz
May 11 2017 02:37
@brittanyrutherford but don't stress too much.. there's not a universal rule that if you don't do so your program won't work... it's mainly for utility when working in team / shipping a package to the world :)
Ogundele Olumide
@Lumexralph
May 11 2017 02:38
@Manish-Giri where've you been?
mobilecititechs
@mobilecititechs
May 11 2017 02:38
Hello everyone need assistance with increment number with Java Script. Change the code to use the ++ operator on myVar.
Ogundele Olumide
@Lumexralph
May 11 2017 02:39
@mobilecititechs use ++ with myVar
pursuitgit
@pursuitgit
May 11 2017 02:39
@mobilecititechs can you show us your current code?
mobilecititechs
@mobilecititechs
May 11 2017 02:39
var myVar = 87; (myVar = myVar should be changed0
my answer myVar = ++myVar;
Ogundele Olumide
@Lumexralph
May 11 2017 02:40
@mobilecititechs myVar++;
pursuitgit
@pursuitgit
May 11 2017 02:40
so you don't need to the = and then ++myVar @mobilecititechs
Manish Giri
@Manish-Giri
May 11 2017 02:40
@Lumexralph I've been away, mostly working and finishing up my thesis
:weary:
pursuitgit
@pursuitgit
May 11 2017 02:41
@mobilecititechs all you need is myVar++;
Manish Giri
@Manish-Giri
May 11 2017 02:41
how've you been
@Lumexralph
Claudio Restifo
@Marmiz
May 11 2017 02:41
Java, right @Manish-Giri ?
Manish Giri
@Manish-Giri
May 11 2017 02:41
@Marmiz yeah
it sucks
Ogundele Olumide
@Lumexralph
May 11 2017 02:42
@Manish-Giri good to have you back
Manish Giri
@Manish-Giri
May 11 2017 02:42
@Lumexralph ty
CamperBot
@camperbot
May 11 2017 02:42
manish-giri sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1716 | @lumexralph |http://www.freecodecamp.com/lumexralph
Manish Giri
@Manish-Giri
May 11 2017 02:42
:smile:
mobilecititechs
@mobilecititechs
May 11 2017 02:42
Thanks you guys
and galls
Manish Giri
@Manish-Giri
May 11 2017 02:43
galls
!
Ogundele Olumide
@Lumexralph
May 11 2017 02:43
@Manish-Giri finished the school work?
Kelechi Chinaka
@ke1echi
May 11 2017 02:45
greetings everyone
Vicky Lai
@vickylai
May 11 2017 02:46
That moment you realize you'v written 158 lines of code and you're an idiot
Kelechi Chinaka
@ke1echi
May 11 2017 02:46
:smile: @vickylaiio
deaninous
@deaninous
May 11 2017 02:47
The more code, the merrier
Manish Giri
@Manish-Giri
May 11 2017 02:47
@Lumexralph not completely, but it's in full flow now :smile:
jmariomejiap
@jmariomejiap
May 11 2017 02:47
@vickylaiio ohhh, yeah. what a familiar feeling. sometimes I find comfort in knowing Im not the only one. :)
Kelechi Chinaka
@ke1echi
May 11 2017 02:48
hey man @Lumexralph
deaninous
@deaninous
May 11 2017 02:49
Hello everyone, There is a geniuuuuuuus in the help chat room, anyone wanna check him out?
Ogundele Olumide
@Lumexralph
May 11 2017 02:50
@kelechichinaka Bro!
@Manish-Giri cool
Claudio Restifo
@Marmiz
May 11 2017 02:50
blame
true story
Joseph
@revisualize
May 11 2017 02:53
Heh
Tu Nguyen
@nvminhtu
May 11 2017 02:53
Hi guys! I love javascript!
Joseph
@revisualize
May 11 2017 02:54
JavaScript loves you.
I dont...
But, JavaScript does.
Tu Nguyen
@nvminhtu
May 11 2017 02:55
@revisualize hehe
@revisualize got it.
Ogundele Olumide
@Lumexralph
May 11 2017 02:55
@nvminhtu you sure ? :smirk:
Tu Nguyen
@nvminhtu
May 11 2017 02:55
@revisualize do you work with React?
Joseph
@revisualize
May 11 2017 02:55
Nope
Manish Giri
@Manish-Giri
May 11 2017 02:57
@Lumexralph the jersey is barca
it's not completely visible
Tu Nguyen
@nvminhtu
May 11 2017 02:57
@revisualize yeah, hope we can support together :) here
chayawit
@chayawit
May 11 2017 02:58

I have passed this challenge https://www.freecodecamp.com/challenges/everything-be-true
with this code.

function truthCheck(collection, pre) {
  // Is everyone being true?
  return collection.reduce(function(accu, curr) {
    var bool = accu && curr.hasOwnProperty(pre) && isTruthy(curr[pre]);
    return bool;
  }, true);
}

function isTruthy(val) {
  if (typeof val === "number") {
    return val > 0;
  } else if (typeof val === "string") {
    return val.length > 0;
  } else if (typeof val === "boolean") {
    return val;
  } else {
    return false; // for null and undefined
  }
}

truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex");

But I wonder if there's a cleaner way where I don't need to use typeof

function palindrome(str) {
var temp = [];
str.toLowerCase();
for (var i = 0; i<str.length; i++){ if (str.charCodeAt(i)> 96 && str.charCodeAt(i)<123){
temp.push(str.charAt(i));
}
}

var rev_str = temp.reverse().join("");
if (str === rev_str){
return true;
}
else {
return false;
}

}

Can someone help me understand why this code doesn't work for the palindromes challenge
chayawit
@chayawit
May 11 2017 03:02
@d38tang
function palindrome(str) {
  var temp = [];
  str.toLowerCase();
  for (var i = 0; i<str.length; i++) {
    if (str.charCodeAt(i)> 96 && str.charCodeAt(i)<123){
      temp.push(str.charAt(i));
    }
  }
  var rev_str = temp.reverse().join("");
  if (str === rev_str) {
    return true;
  }
  else {
    return false;
  }
}

palindrome("eye");
PS: I haven't changed anything. Just formatted your code.
FelixHakaraia
@FelixHakaraia
May 11 2017 03:02
Hey guys just a bit confused with this one\

```js var Car = function() {
// this is a private variable
var speed = 10;

// these are public methods
this.accelerate = function(change) {
speed += change;
};

this.decelerate = function() {
speed -= 5;
};

this.getSpeed = function() {
return speed;
};
};

var Bike = function() {

// Only change code below this line.
var gear;

this.setGear = function(change) {
gear += change;
};

this.getGear = function() {
return gear;
};

};

var myCar = new Car();

var myBike = new Bike();
```

var Car = function() {
  // this is a private variable
  var speed = 10;

  // these are public methods
  this.accelerate = function(change) {
    speed += change;
  };

  this.decelerate = function() {
    speed -= 5;
  };

  this.getSpeed = function() {
    return speed;
  };
};

var Bike = function() {

  // Only change code below this line.
  var gear;

  this.setGear = function(change) {
    gear += change;
  };

  this.getGear = function() {
    return gear;
  };


};

var myCar = new Car();

var myBike = new Bike();
Ogundele Olumide
@Lumexralph
May 11 2017 03:03
@FelixHakaraia setGear method should assign change = to gear
FelixHakaraia
@FelixHakaraia
May 11 2017 03:04
@Lumexralph so gear = change?
Ogundele Olumide
@Lumexralph
May 11 2017 03:04
@FelixHakaraia yes
FelixHakaraia
@FelixHakaraia
May 11 2017 03:04
@Lumexralph That makes sense
chayawit
@chayawit
May 11 2017 03:04
@d38tang I haven't understood the whole code but I notice str.toLowerCase();. I just wanna tell you that this line doesn't change str. If you wanna change it, you have to do ``str = str.toLowerCase();.
FelixHakaraia
@FelixHakaraia
May 11 2017 03:04
@Lumexralph Thanks that worked
CamperBot
@camperbot
May 11 2017 03:04
felixhakaraia sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1717 | @lumexralph |http://www.freecodecamp.com/lumexralph
Brittany Rutherford
@brittanyrutherford
May 11 2017 03:04
what's wrong with my code?
var example = () => {
  let message = 'hello world'

  let getName = () => {
    return message
  }

  return {
    getName
  }
}()
example.getName()
Ricardo Augusto
@ricardoaugustob
May 11 2017 03:05
I did not understand this challenge
Word Blanks
d38tang
@d38tang
May 11 2017 03:07
@chayawit Thanks I just changed that part
CamperBot
@camperbot
May 11 2017 03:07
:cookie: 302 | @chayawit |http://www.freecodecamp.com/chayawit
d38tang sends brownie points to @chayawit :sparkles: :thumbsup: :sparkles:
d38tang
@d38tang
May 11 2017 03:08
@chayawit The code is based on using ASCII codes to detect non-alphanumeric values
chayawit
@chayawit
May 11 2017 03:09
@d38tang I think this is the wrong part if (str === rev_str) {
@d38tang you wanted you compare temp, not str
grfraser
@grfraser
May 11 2017 03:10
any hints as to what im doing wrong here?
function palindrome(str) {

  var rts = str.split(/.+/gi).reverse().join(/.+/gi);

  str = str.toLowerCase();
  str = str.replace(/\W/,"");
  str = str.replace(/\s/,"");
  if(str === rts){
  return true;
  } 
  return false;
 }

palindrome("eye");
FelixHakaraia
@FelixHakaraia
May 11 2017 03:11
Hey guys, missing another one :(
var oldArray = [1,2,3,4,5];

// Only change code below this line.
var newArray = oldArray.map(function() {
  return oldArray.indexOf() + 3;
});
var newArray = oldArray;
Ogundele Olumide
@Lumexralph
May 11 2017 03:12
@brittanyrutherford your IIFE is missing parenethsis
var example =( () =>{
  let message = 'hello world';

  let getName = () => {
    return message;
  };

  return {
    getName
  };
})();

example.getName();  //hello world
d38tang
@d38tang
May 11 2017 03:12
@chayawit Oh I forgot about that, thanks. I changed it to temp.join("") === rev_str
CamperBot
@camperbot
May 11 2017 03:12
d38tang sends brownie points to @chayawit :sparkles: :thumbsup: :sparkles:
:warning: d38tang already gave chayawit points
Manish Giri
@Manish-Giri
May 11 2017 03:12
@FelixHakaraia var newArray = oldArray;
why this line?
d38tang
@d38tang
May 11 2017 03:12
@chayawit Now i seem to be only failing the tests where it is supposed to return false, I'll look into it.
FelixHakaraia
@FelixHakaraia
May 11 2017 03:12
@Manish-Giri That was there before i started
chayawit
@chayawit
May 11 2017 03:12
@d38tang That won't work either because temp was already reversed
Manish Giri
@Manish-Giri
May 11 2017 03:13
@FelixHakaraia you were meant to use .map on that lne
chayawit
@chayawit
May 11 2017 03:13
@d38tang ok if it works
Manish Giri
@Manish-Giri
May 11 2017 03:13
since you didnt
you can delete it
grfraser
@grfraser
May 11 2017 03:13
any clues?
chayawit
@chayawit
May 11 2017 03:13
@d38tang only this now? palindrome("1 eye for of 1 eye.")
Brittany Rutherford
@brittanyrutherford
May 11 2017 03:13
@Lumexralph oh thanks
CamperBot
@camperbot
May 11 2017 03:13
brittanyrutherford sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1718 | @lumexralph |http://www.freecodecamp.com/lumexralph
grfraser
@grfraser
May 11 2017 03:14
function palindrome(str) {

  var rts = str.split(/.+/gi).reverse().join(/.+/gi);

  str = str.toLowerCase();
  str = str.replace(/\W/,"");
  str = str.replace(/\s/,"");
  if(str === rts){
  return true;
  } 
  return false;
 }

palindrome("eye");
FelixHakaraia
@FelixHakaraia
May 11 2017 03:14
@Manish-Giri Still not working :/
Ogundele Olumide
@Lumexralph
May 11 2017 03:14
@brittanyrutherford :+1:
Manish Giri
@Manish-Giri
May 11 2017 03:14
@FelixHakaraia oldArray.indexOf() + 3;
this is also wrong
what does that line do?
Ogundele Olumide
@Lumexralph
May 11 2017 03:15
@grfraser why don't you just replace the non-alphanumeric from the start?
d38tang
@d38tang
May 11 2017 03:15
@chayawit all the return true ones work and all the return false ones don't work
Ogundele Olumide
@Lumexralph
May 11 2017 03:15
@Manish-Giri saw my pm?
Manish Giri
@Manish-Giri
May 11 2017 03:16
@Lumexralph um, hold on
grfraser
@grfraser
May 11 2017 03:16
@Lumexralph its pretty close to the beginning, what do you mean?
d38tang
@d38tang
May 11 2017 03:16
@chayawit I fixed something now only 1 eye for of 1 eye doesn't work
chayawit
@chayawit
May 11 2017 03:16
@d38tang That's because your temp got reversed
grfraser
@grfraser
May 11 2017 03:16
@d38tang were on the same problem lol
chayawit
@chayawit
May 11 2017 03:17
@d38tang show your current code
@d38tang use ```
d38tang
@d38tang
May 11 2017 03:17

``` function palindrome(str) {
var temp = [];
str = str.toLowerCase();
for (var i = 0; i<str.length; i++){ if (str.charCodeAt(i)> 96 && str.charCodeAt(i)<123){
temp.push(str.charAt(i));
}
}
var temp2 = temp.join("");
var rev_str = temp.reverse().join("");
if (temp2 === rev_str){
return true;
}
else {
return false;
}

}

palindrome("eye"); ```

Ogundele Olumide
@Lumexralph
May 11 2017 03:17
@grfraser i don't think you need to do so much replacing, just non-alphanumeric
chayawit
@chayawit
May 11 2017 03:17
@d38tang and one more problem is your code accepts only alphabets. It should also take numbers
d38tang
@d38tang
May 11 2017 03:17
lol...
chayawit
@chayawit
May 11 2017 03:18
@d38tang type ``` in separated lines
try again
grfraser
@grfraser
May 11 2017 03:18
@Lumexralph oh cause some need spaces. but does non alphanumeric include spaces or not?
Ogundele Olumide
@Lumexralph
May 11 2017 03:19
@grfraser its letters and numbers (alphanumeric)
chayawit
@chayawit
May 11 2017 03:19
@d38tang show your formatted code. I'm too lazy to format it lol
grfraser
@grfraser
May 11 2017 03:20
@Lumexralph yes but a space is not a letter or number
when getting rid of non alphanumerics does it get rid of spaces?
Ogundele Olumide
@Lumexralph
May 11 2017 03:20
@grfraser yes, you'll need to replace that too
grfraser
@grfraser
May 11 2017 03:21
so to confirm spaces are deleted when nonalphas are deleted?
Ogundele Olumide
@Lumexralph
May 11 2017 03:21
@grfraser yes
grfraser
@grfraser
May 11 2017 03:22
@Lumexralph okay thats what i thought and apparently i need spaces. how can i delete all characters that are non alpha but keep spaces?
is there a regex for that?
chayawit
@chayawit
May 11 2017 03:23

I have passed this challenge https://www.freecodecamp.com/challenges/everything-be-true
with this code.

function truthCheck(collection, pre) {
  // Is everyone being true?
  return collection.reduce(function(accu, curr) {
    var bool = accu && curr.hasOwnProperty(pre) && isTruthy(curr[pre]);
    return bool;
  }, true);
}

function isTruthy(val) {
  if (typeof val === "number") {
    return val > 0;
  } else if (typeof val === "string") {
    return val.length > 0;
  } else if (typeof val === "boolean") {
    return val;
  } else {
    return false; // for null and undefined
  }
}

truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex");

But I wonder if there's a cleaner way where I don't need to use typeof

Ogundele Olumide
@Lumexralph
May 11 2017 03:24
@grfraser why do you want to keep spaces for palindrome?
grfraser
@grfraser
May 11 2017 03:25
palindrome("My age is 0, 0 si ega ym.") should return true.
eh i guess your right it doesnt matter
so what would you say the main issue is here ?
function palindrome(str) {

  var rts = str.split("").reverse().join("");

  str = str.toLowerCase();
  str = str.replace(/\W/,"");
  if(str === rts){
  return true;
  } 
  return false;
 }

palindrome("eye");
@Lumexralph
chayawit
@chayawit
May 11 2017 03:27
@grfraser you didn't declare rts
oh you did. sorr
Moisés Man
@moigithub
May 11 2017 03:27
@grfraser u also need tolowercase and clean ur rts string
Ogundele Olumide
@Lumexralph
May 11 2017 03:27
@grfraser remove the non-alphanumeric characters, lowercase, reverse and compare the refined string with the reversed string
grfraser
@grfraser
May 11 2017 03:27
@moigithub ah duh thank you
CamperBot
@camperbot
May 11 2017 03:27
grfraser sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3215 | @moigithub |http://www.freecodecamp.com/moigithub
grfraser
@grfraser
May 11 2017 03:28
@Lumexralph thank you let me see here...
CamperBot
@camperbot
May 11 2017 03:28
grfraser sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 1719 | @lumexralph |http://www.freecodecamp.com/lumexralph
Moisés Man
@moigithub
May 11 2017 03:28
move that line below and it should work @grfraser
grfraser
@grfraser
May 11 2017 03:29
@moigithub what line?
i got
function palindrome(str) {

  var rts = str.split("").reverse().join("");
  rts = rts.toLowerCase();
  rts = rts.replace(/\W/,"");

  str = str.toLowerCase();
  str = str.replace(/\W/,"");
  if(str === rts){
  return true;
  } 
  return false;
 }

palindrome("_eye")
chayawit
@chayawit
May 11 2017 03:29

@grfraser you should consider adding

  console.log(str);
  console.log(rts);

before your if else

Manpreet29
@Manpreet29
May 11 2017 03:29
someone pls help me with WORD BLANKS challenge
grfraser
@grfraser
May 11 2017 03:29
@chayawit why?
chayawit
@chayawit
May 11 2017 03:29
@grfraser easier to debug
Ogundele Olumide
@Lumexralph
May 11 2017 03:30
@Manpreet29 what have you tried?
diegoxro
@diegoxro
May 11 2017 03:30
@Manpreet29 what's the issue
chayawit
@chayawit
May 11 2017 03:30
@grfraser do you know how to see browser console?
grfraser
@grfraser
May 11 2017 03:30
yes , debugger; ?
diegoxro
@diegoxro
May 11 2017 03:30
dev tools
Moisés Man
@moigithub
May 11 2017 03:30
regex \W dont include _
soo u need to add it if u wanna remove underscores from ur string @grfraser
Manpreet29
@Manpreet29
May 11 2017 03:30
i am not getting exactly what to do in that challenge
grfraser
@grfraser
May 11 2017 03:31
@moigithub wait how do i get rigd of the underscore?
diegoxro
@diegoxro
May 11 2017 03:31
link?
grfraser
@grfraser
May 11 2017 03:31
_ is non alpha isnt it?
chayawit
@chayawit
May 11 2017 03:31
@grfraser google how to see console in developer tool in your browser
Manish Giri
@Manish-Giri
May 11 2017 03:31
@Manpreet29 you need to form a string, and assign it to result, using string concatenation (+). The string has to be formed by concatenating the four parameters in your function - myNoun, myAdjective, etc, along with spaces and (optionally) some words of your own - to form a coherent sentence.
chayawit
@chayawit
May 11 2017 03:31
@grfraser it's very useful for every challenge
grfraser
@grfraser
May 11 2017 03:31
@chayawit very true
Aizaz Shahid
@aizazshahid
May 11 2017 03:31
@grfraser _ its not included in \W non-words
grfraser
@grfraser
May 11 2017 03:32
@forwebtech that makes no sense lol
how do i remove it?
Aizaz Shahid
@aizazshahid
May 11 2017 03:32
[_]
diegoxro
@diegoxro
May 11 2017 03:32
@Manpreet29 all you have to do is concat/join strings
Manpreet29
@Manpreet29
May 11 2017 03:32
@Manish-Giri can u explain with example?
Moisés Man
@moigithub
May 11 2017 03:32
\W
Matches any character that is not a word character (alphanumeric & underscore). Equivalent to [^A-Za-z0-9_]
http://regexr.com/
@grfraser
grfraser
@grfraser
May 11 2017 03:32
just replace?
Aizaz Shahid
@aizazshahid
May 11 2017 03:33
@grfraser you can use .replace()
grfraser
@grfraser
May 11 2017 03:33
how is _ alpha num?
Manish Giri
@Manish-Giri
May 11 2017 03:33
@Manpreet29
function demo(word) {
return "Hello " + word;
}

demo("Manpreet"); // Hello Manpreet
grfraser
@grfraser
May 11 2017 03:33
its a special char
Moisés Man
@moigithub
May 11 2017 03:34
alpha num are only a-z and numbers 0-9
_ should be removed
Manpreet29
@Manpreet29
May 11 2017 03:34
so i have to use words and some extra words? @Manish-Giri
Manish Giri
@Manish-Giri
May 11 2017 03:34
@Manpreet29 extra words are optional
your main words are the parameters, like myNoun etc
and spaces
Manpreet29
@Manpreet29
May 11 2017 03:35
ok thanks @Manish-Giri
CamperBot
@camperbot
May 11 2017 03:35
manpreet29 sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 5470 | @manish-giri |http://www.freecodecamp.com/manish-giri
Aizaz Shahid
@aizazshahid
May 11 2017 03:35
@grfraser seems, but it's not included in alphanumerics in regex i don't know why but that's the case.
\W Matches any character that is not a word character (alphanumeric & underscore). Equivalent to [^A-Za-z0-9_]
grfraser
@grfraser
May 11 2017 03:36
??! lol
Aizaz Shahid
@aizazshahid
May 11 2017 03:37
the question should be raised, why is not included in alphanumeric, so, may be because used in programming to declare variable names as my_var so that's why, i think.
grfraser
@grfraser
May 11 2017 03:38
but what you just referenced shows an underscore??
\W Matches any character that is not a word character (alphanumeric & ## underscore ## ). Equivalent to [^A-Za-z0-9_]
Moisés Man
@moigithub
May 11 2017 03:38
^ inside [] means NOT in regex
Aizaz Shahid
@aizazshahid
May 11 2017 03:39
@grfraser you can say it's a non-alphanumeric character !
grfraser
@grfraser
May 11 2017 03:39
"Equivalent to [^A-Za-z0-9_]"
?
Aizaz Shahid
@aizazshahid
May 11 2017 03:40
@grfraser well i referenced it from http://regexr.com/ in the character class.
diegoxro
@diegoxro
May 11 2017 03:40
lol gotta love regex , For example, /\W/ or /[^A-Za-z0-9_]/ matches '%' in "50%." ( from docs)
Aizaz Shahid
@aizazshahid
May 11 2017 03:40
@grfraser [^A-Za-z0-9_] === \W
grfraser
@grfraser
May 11 2017 03:41
ah so its really something that isnt set in stone
for the purposes of this excercise and perhaps es5 js, _ is a alpha num
Moisés Man
@moigithub
May 11 2017 03:41
_ is NOT an alpha num char
u need to REMOVE it
instruction says remove all non alpha @grfraser
d38tang
@d38tang
May 11 2017 03:41
@chayawit Sorry I had to go somewhere. I changed my ASCII to include numbers and it worked. Thanks for your help!
CamperBot
@camperbot
May 11 2017 03:41
d38tang sends brownie points to @chayawit :sparkles: :thumbsup: :sparkles:
:warning: d38tang already gave chayawit points
Aizaz Shahid
@aizazshahid
May 11 2017 03:42
@grfraser where did you see its a alpha-numeric ?
Ogundele Olumide
@Lumexralph
May 11 2017 03:42
@Manish-Giri want to give you a puzzle
grfraser
@grfraser
May 11 2017 03:42

@forwebtech @forwebtech
@grfraser seems, but it's not included in alphanumerics in regex i don't know why but that's the case.

\W Matches any character that is not a word character (alphanumeric & underscore). Equivalent to [^A-Za-z0-9_]

you said it
Aizaz Shahid
@aizazshahid
May 11 2017 03:43
regexr.com it's a mistake there
because if you use \W, it will not match the underscore !
grfraser
@grfraser
May 11 2017 03:43
yeah lol
chayawit
@chayawit
May 11 2017 03:43
@d38tang np
Aizaz Shahid
@aizazshahid
May 11 2017 03:43
@grfraser thanks to you, i found a error in regexr.com, need to complain !
CamperBot
@camperbot
May 11 2017 03:43
forwebtech sends brownie points to @grfraser :sparkles: :thumbsup: :sparkles:
:cookie: 256 | @grfraser |http://www.freecodecamp.com/grfraser
Muhammad Hariz Danial bin Norizan
@PongtheGreat
May 11 2017 03:44
Why is 1 eye for of 1 eye is not a palindrome?
grfraser
@grfraser
May 11 2017 03:44
i think regex is a lil different everywhere
Moisés Man
@moigithub
May 11 2017 03:44
@PongtheGreat u should KEEP numbers too...
grfraser
@grfraser
May 11 2017 03:44
@PongtheGreat cause it starts with a number and ends with a letter
Aizaz Shahid
@aizazshahid
May 11 2017 03:44
@grfraser but i think its syntax is same every where, because i used same regex syntax in JAVA
Muhammad Hariz Danial bin Norizan
@PongtheGreat
May 11 2017 03:45
@moigithub @grfraser I guess I didn't read the instructions carefully. Thanks.
CamperBot
@camperbot
May 11 2017 03:45
pongthegreat sends brownie points to @moigithub and @grfraser :sparkles: :thumbsup: :sparkles:
:cookie: 257 | @grfraser |http://www.freecodecamp.com/grfraser
:star2: 3216 | @moigithub |http://www.freecodecamp.com/moigithub
Manish Giri
@Manish-Giri
May 11 2017 03:45
@Lumexralph which one
grfraser
@grfraser
May 11 2017 03:45
@PongtheGreat this one is hard
Ogundele Olumide
@Lumexralph
May 11 2017 03:46
@Manish-Giri can you use a JS reserved word as an object property ?
Manpreet29
@Manpreet29
May 11 2017 03:46
@Manish-Giri i m still stuck
grfraser
@grfraser
May 11 2017 03:47
@PongtheGreat np alpha num incluces numbers
Manish Giri
@Manish-Giri
May 11 2017 03:47
@Lumexralph you can, but I think it leads to unpredictable results
@Manpreet29 what's the problem
Ogundele Olumide
@Lumexralph
May 11 2017 03:47
@Manish-Giri unpredictable, like?
grfraser
@grfraser
May 11 2017 03:47
@diegoxro so is that a FCC bug?
Manpreet29
@Manpreet29
May 11 2017 03:48
@Manish-Giri i m not able to do
diegoxro
@diegoxro
May 11 2017 03:49
lol where did your message go?
Aizaz Shahid
@aizazshahid
May 11 2017 03:49
@diegoxro delete that because they write for both
MDN
\w \W
grfraser
@grfraser
May 11 2017 03:49
@forwebtech its an FCC bug
Aizaz Shahid
@aizazshahid
May 11 2017 03:49
@diegoxro @grfraser _ is matched with \w
diegoxro
@diegoxro
May 11 2017 03:49
no
Manish Giri
@Manish-Giri
May 11 2017 03:49
@Manpreet29 why? any specific part you're stuck in?
Aizaz Shahid
@aizazshahid
May 11 2017 03:50
but not \W
MESHACK ALFRED
@LASTBORNMESH
May 11 2017 03:50
guys i need help on exercise 214?? got no idea where to start
Aizaz Shahid
@aizazshahid
May 11 2017 03:50
@LASTBORNMESH 214 is your point number not the challenge one,
tell the challenge name.
grfraser
@grfraser
May 11 2017 03:50
ohhh
MESHACK ALFRED
@LASTBORNMESH
May 11 2017 03:51
its profile lookup
MESHACK ALFRED
@LASTBORNMESH
May 11 2017 03:51
@forwebtech
grfraser
@grfraser
May 11 2017 03:51
\w didnt work for me
Ogundele Olumide
@Lumexralph
May 11 2017 03:51
@LASTBORNMESH what have you tried?
grfraser
@grfraser
May 11 2017 03:51
_eye remained the same
Aizaz Shahid
@aizazshahid
May 11 2017 03:51
@LASTBORNMESH what's you code ?
@grfraser try that here regexr.com
Manish Giri
@Manish-Giri
May 11 2017 03:51

@Manpreet29

function demo(word) {
return "Hello " + word;
}
demo("Manpreet"); // Hello Manpreet

@Manpreet29 look at this code again

Ogundele Olumide
@Lumexralph
May 11 2017 03:52
@Manish-Giri you passed the puzzle anyway....easy
Aizaz Shahid
@aizazshahid
May 11 2017 03:52
if it stills don't getting it then it's a bug
Manish Giri
@Manish-Giri
May 11 2017 03:52
@Lumexralph really :open_mouth:
Ogundele Olumide
@Lumexralph
May 11 2017 03:52
@Manish-Giri so how will you reference the property?
Manish Giri
@Manish-Giri
May 11 2017 03:52
I remember @Masd925 posting something with cat the other day
MESHACK ALFRED
@LASTBORNMESH
May 11 2017 03:52
i tried some for loops but ddint work?? @forwebtech
Manish Giri
@Manish-Giri
May 11 2017 03:52
it used a console.log
diegoxro
@diegoxro
May 11 2017 03:52
I doubt it's a bug
Manish Giri
@Manish-Giri
May 11 2017 03:53
t = {
while: "hi"
}
Object {while: "hi"}
t.while
"hi"
@Lumexralph
Aizaz Shahid
@aizazshahid
May 11 2017 03:53
@LASTBORNMESH paste your code !
diegoxro
@diegoxro
May 11 2017 03:53
have not even done the challenge tho
Manish Giri
@Manish-Giri
May 11 2017 03:53
@Lumexralph I just did this
MESHACK ALFRED
@LASTBORNMESH
May 11 2017 03:53

//Setup
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["Javascript", "Gaming", "Foxes"]
}
];

function lookUpProfile(firstName, prop){
// Only change code below this line

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");

Ogundele Olumide
@Lumexralph
May 11 2017 03:53
@Manish-Giri how about while ? and how will you reference the object?
grfraser
@grfraser
May 11 2017 03:54
yeah its a bug @forwebtech
Ogundele Olumide
@Lumexralph
May 11 2017 03:54
@LASTBORNMESH
Here's an outline, if you follow it step-wise it'll help a great deal in telling you what to do or step you missed
1. you need a loop to pick each objects in the contacts array
    1.1  in the loop you need to 
         1.1.1  check if the objects picked has the firstName property equal to the firstName parameter
                  1.1.1.1 you need to check if it has a property prop
                                  return the value of prop in the object
                 1.1.1.2  return no such property if  1.1.1.1 is false
2.  when your loop is done looking through  contacts return no such contact
Manish Giri
@Manish-Giri
May 11 2017 03:54

@Manish-Giri how about while ? and how will you reference the object?

@Lumexralph as in?

I did use while there
Ogundele Olumide
@Lumexralph
May 11 2017 03:54
@Manish-Giri to "while"
Aizaz Shahid
@aizazshahid
May 11 2017 03:54
@grfraser use this [_]
Manish Giri
@Manish-Giri
May 11 2017 03:54
as for the object, just name
t
tuanha816
@tuanha816
May 11 2017 03:55
how many points can you earn through the exercises?
Manish Giri
@Manish-Giri
May 11 2017 03:55
@Lumexralph "while" seems to work the same way
diegoxro
@diegoxro
May 11 2017 03:55
now I gotta try the problem myself lol
Aizaz Shahid
@aizazshahid
May 11 2017 03:55
@grfraser well you should to change the regex then !
Ogundele Olumide
@Lumexralph
May 11 2017 03:56
@Manish-Giri let me try
Manish Giri
@Manish-Giri
May 11 2017 03:56
@Manpreet29 did you read that code?
Manpreet29
@Manpreet29
May 11 2017 03:57
@Manish-Giri i read but still stuck at it
Ogundele Olumide
@Lumexralph
May 11 2017 03:57

@Manish-Giri

let a = {
  "while": 5,
};

console.log(a["while"]);

works

Michael Fox
@misterfoxy
May 11 2017 03:57
can anyone look at my code for the javascript calculator project?
Ogundele Olumide
@Lumexralph
May 11 2017 03:58
@Manish-Giri the thing is you can only reference them using bracket notation
Aizaz Shahid
@aizazshahid
May 11 2017 03:58
@misterfoxy need a review or help?
Manish Giri
@Manish-Giri
May 11 2017 03:58
@Manpreet29 okay, what will be the output of
function test(foo, bar, baz) {
var result = foo + " " + bar + "hi" + baz;
return result;
}

test("code", "works", "here");
Michael Fox
@misterfoxy
May 11 2017 03:58
@forwebtech a bit of both
Manish Giri
@Manish-Giri
May 11 2017 03:59
@Lumexralph but it worked with dot too
Aizaz Shahid
@aizazshahid
May 11 2017 03:59
@misterfoxy well then you can ask there https://gitter.im/FreeCodeCamp/CodeReview
that will be a great place for that.
Ogundele Olumide
@Lumexralph
May 11 2017 03:59
@Manish-Giri let me run your code
Michael Fox
@misterfoxy
May 11 2017 03:59
thanks @forwebtech
CamperBot
@camperbot
May 11 2017 03:59
misterfoxy sends brownie points to @forwebtech :sparkles: :thumbsup: :sparkles:
:cookie: 477 | @forwebtech |http://www.freecodecamp.com/forwebtech
Aizaz Shahid
@aizazshahid
May 11 2017 03:59
:+1:
grfraser
@grfraser
May 11 2017 04:00
somebody please help with palindrome :(
Ogundele Olumide
@Lumexralph
May 11 2017 04:00
@Manish-Giri it worked too
Manish Giri
@Manish-Giri
May 11 2017 04:00
@Lumexralph :+1:
Manpreet29
@Manpreet29
May 11 2017 04:00
@Manish-Giri foo code works br hi here
Muhammad Hariz Danial bin Norizan
@PongtheGreat
May 11 2017 04:01
@grfraser You still stuck?
grfraser
@grfraser
May 11 2017 04:01
function palindrome(str) {

  var rts = str.split("").reverse().join("");
  rts = rts.toLowerCase();
  rts = rts.replace(/\W/,"");
  rts = rts.replace("_","");

  str = str.toLowerCase();
  str = str.replace(/\W/,"");
  str = str.replace("_","");

  if(str === rts){
  return true;
  } 
  return false;
 }

palindrome("_eye");
yes :(
Manish Giri
@Manish-Giri
May 11 2017 04:01
@Manpreet29 nope
thats where you're going wrong
Muhammad Hariz Danial bin Norizan
@PongtheGreat
May 11 2017 04:02
Try to change "" to "*"
Aizaz Shahid
@aizazshahid
May 11 2017 04:02
@grfraser use g flag
Manpreet29
@Manpreet29
May 11 2017 04:02
then what will be the output @Manish-Giri
Aizaz Shahid
@aizazshahid
May 11 2017 04:02
after the slash /.../g, g > global
if you don't use g then it return only one match instead of getting all @grfraser
Manish Giri
@Manish-Giri
May 11 2017 04:03

@Manpreet29 there are two parts to a function -

  1. when you declare a function, the terms you write inside the ( ) are called the function parameters, so here - function test(foo, bar, baz) { -> foo, bar and baz are the parameters
  2. when you actually call/invoke the function, the things you write inside the ( ) are called the function arguments, and these arguments will replace the parameters you had used in step 1

so, if you call the function like test("code", "works", "here");
then foo becomes code, bar becomes works and baz becomes here

Ken Haduch
@khaduch
May 11 2017 04:04
@Manpreet29 - it is helpful when you are learning, to add console.log statements in various places in your code and see what the output is after each step, that way you can track the progress of your function and learn what's going on.
Aizaz Shahid
@aizazshahid
May 11 2017 04:04
@grfraser and tell me why did you use same regex two times, instead you can first remove those characters and then manipulate it.
@grfraser like reversing or lowercasing
grfraser
@grfraser
May 11 2017 04:04
what do you mean 2 times?
ph
Ken Haduch
@khaduch
May 11 2017 04:05
@grfraser - I meant that comment for you, really - the output from console.log can help you to see what's going on in various stages as you modify the data.
Aizaz Shahid
@aizazshahid
May 11 2017 04:05
@grfraser used on rts and str
??
Manish Giri
@Manish-Giri
May 11 2017 04:05
@Manpreet29 with that knowledge, try out the code now, what will be the output?
grfraser
@grfraser
May 11 2017 04:05
i reversed the input srtring
Aizaz Shahid
@aizazshahid
May 11 2017 04:05
@grfraser but that doesn't mean you changed the letters,
grfraser
@grfraser
May 11 2017 04:05
i passed it, thank you @forwebtech i was forgettting global
CamperBot
@camperbot
May 11 2017 04:05
grfraser sends brownie points to @forwebtech :sparkles: :thumbsup: :sparkles:
:cookie: 478 | @forwebtech |http://www.freecodecamp.com/forwebtech
Manpreet29
@Manpreet29
May 11 2017 04:05
thank u @Manish-Giri and @khaduch
CamperBot
@camperbot
May 11 2017 04:05
manpreet29 sends brownie points to @manish-giri and @khaduch :sparkles: :thumbsup: :sparkles:
:warning: manpreet29 already gave manish-giri points
:star2: 2855 | @khaduch |http://www.freecodecamp.com/khaduch
grfraser
@grfraser
May 11 2017 04:06
no i changed them later down
Ogundele Olumide
@Lumexralph
May 11 2017 04:06
@Manish-Giri i need to cook and I don't want to stand up
Aizaz Shahid
@aizazshahid
May 11 2017 04:06
@grfraser but you should to remove the non-alphanumeric first, and then reverse it, got it ?
Manish Giri
@Manish-Giri
May 11 2017 04:06
@Lumexralph lol
grfraser
@grfraser
May 11 2017 04:07
@forwebtech why? it doesnt make a difference
Aizaz Shahid
@aizazshahid
May 11 2017 04:07
@grfraser because that is just a repetition, you don't need to do that twice.
Ogundele Olumide
@Lumexralph
May 11 2017 04:08
@Manish-Giri so now there's so much beauty in Template literals than string literals
Aizaz Shahid
@aizazshahid
May 11 2017 04:08
ok i am giving you an example
@grfraser
function foo(str) {
str = str.replace( ... .);
// now you can use that str 
}
Manpreet29
@Manpreet29
May 11 2017 04:08
@Manish-Giri thanks its done
CamperBot
@camperbot
May 11 2017 04:08
manpreet29 sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:warning: manpreet29 already gave manish-giri points
Manish Giri
@Manish-Giri
May 11 2017 04:09
:+1:
Muhammad Hariz Danial bin Norizan
@PongtheGreat
May 11 2017 04:09

var longest = 0;

function findLongestWord(str) {
str = str.split(" ");
for(var i = 0; i < str.length; i++) {
if(str[i].length > longest) {
longest = str[i].length;
}
}

return longest;
}

findLongestWord("May the force be with you");

Code return 5 but I can't pass the test case.
Aizaz Shahid
@aizazshahid
May 11 2017 04:10
@grfraser and also you can combine regex, as, /[\W_]/g
Manish Giri
@Manish-Giri
May 11 2017 04:10
@PongtheGreat make longest local variable
Cody Smith
@TheCodingSmith
May 11 2017 04:10
Could someone give me a bit of help on $( document ).ready() with an onClick? On the quote machine I have it using the onclick, but I cannot seem to get it to automatically load a quote on ready. Here is a link to my Pen. http://codepen.io/TheCodingSmith/full/RVQWBx/
Ogundele Olumide
@Lumexralph
May 11 2017 04:10
@PongtheGreat FCC don't like global variables
grfraser
@grfraser
May 11 2017 04:10
@forwebtech now the combining is useful thanks! but i dont understand your point on why i reversed first
CamperBot
@camperbot
May 11 2017 04:10
grfraser sends brownie points to @forwebtech :sparkles: :thumbsup: :sparkles:
:warning: grfraser already gave forwebtech points
Ogundele Olumide
@Lumexralph
May 11 2017 04:10
@PongtheGreat make longestlocal variable
Pagnito
@Pagnito
May 11 2017 04:11
cant understand, why it doesnt recognize arr2[i], if i console.log(arr2[i]) it gives me the values but this if statement doesnt seem to work
arr1.forEach(function(item, i){
   //arr2.forEach(function(it, ind){

     if(arr2[i].indexOf(item[1])>0){

       item[0]+=arr2[i][0];
       console.log(arr1);
     }
    // });
   });
Muhammad Hariz Danial bin Norizan
@PongtheGreat
May 11 2017 04:11
@Manish-Giri @Lumexralph Thanks.
CamperBot
@camperbot
May 11 2017 04:11
pongthegreat sends brownie points to @manish-giri and @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 5471 | @manish-giri |http://www.freecodecamp.com/manish-giri
:star2: 1720 | @lumexralph |http://www.freecodecamp.com/lumexralph
Aizaz Shahid
@aizazshahid
May 11 2017 04:11
@grfraser no i said you are doing same thing twice .
@grfraser you don't need to use the regex on both multiple instead you can just remove the required letter to remove first and then use that parameter str
Pagnito
@Pagnito
May 11 2017 04:12
arr1.forEach(function(item, i){


     if(arr2[i].indexOf(item[1])>0){

       item[0]+=arr2[i][0];
       console.log(arr1);
     }

   });
Danny
@danieldsutter
May 11 2017 04:14
For the challenge Smallest Common Multiple (https://www.freecodecamp.com/challenges/smallest-common-multiple) , I have arrived at this. It seems as though it's only running once instead of iterating through the array. What am I doing wrong?

function smallestCommons(arr) {
//create an array to store the whole range of numbers
  var allNumbersArray = [];
  //arrange the numbers in arr from lowest to highest
  arr.sort(function(a,b) {
    return b-a;
  });

  //fill in allNumbersArray with the whole range of numbers
  for (var i=arr[0]; i>=arr[1]; i--) {
    allNumbersArray.push(i);
  }
  var scm;
  var lcd;
      var dividend = allNumbersArray[0];
    var divisor = allNumbersArray[1];
  //magic math stuff
for (var j=0; j<allNumbersArray.length; j++)
  {

    var remainder;
    while (remainder !== 0) {
      remainder = dividend % divisor;
      if (remainder !== 0) {
      dividend = divisor;
      divisor = remainder;
      }
      lcd = divisor;
       scm = allNumbersArray[j] * allNumbersArray[j+1] / lcd;
    dividend = scm;
    }



  }


  //return the answer...eventually
  return scm;
}


smallestCommons([1,5]);
Aizaz Shahid
@aizazshahid
May 11 2017 04:15
@grfraser here is your refactored code:
function palindrome(str) {
    str = str.replace(/[\W_]/g, "").toLowerCase();

    var rts = str.split("").reverse().join("");

    return (str === rts);
}
palindrome("_eye");
akkie99
@akkie99
May 11 2017 04:21
@forwebtech hey, can you explain what that regEx is doing?
I mean , how it works?
I'm really stuck there
Anybody?
Aizaz Shahid
@aizazshahid
May 11 2017 04:22
@akkie99 yes ?
akkie99
@akkie99
May 11 2017 04:22
The regEx which has been used..."\W"
how does it work?
Aizaz Shahid
@aizazshahid
May 11 2017 04:22

@akkie99

Matches any character that is not a word character (alphanumeric & underscore).

it returns the matches, like what characters / letters we want to select from the given string
@akkie99 http://regexr.com/ you can play around regex there.
akkie99
@akkie99
May 11 2017 04:24
oh okay! @forwebtech Thanks!
CamperBot
@camperbot
May 11 2017 04:24
akkie99 sends brownie points to @forwebtech :sparkles: :thumbsup: :sparkles:
:cookie: 479 | @forwebtech |http://www.freecodecamp.com/forwebtech
Aizaz Shahid
@aizazshahid
May 11 2017 04:24
:+1:
grfraser
@grfraser
May 11 2017 04:27
why am i getting undefined for each word in the array in the console?
function findLongestWord(str) {
  var split = str.split(" ");
  split.forEach(function (i) {
   console.log(split[i]);
  });
}
findLongestWord("The quick brown fox jumped over the lazy dog");
@forwebtech oh i see now! much simpler thank you !
CamperBot
@camperbot
May 11 2017 04:30
grfraser sends brownie points to @forwebtech :sparkles: :thumbsup: :sparkles:
:warning: grfraser already gave forwebtech points
Kyle Naumovski
@egnarodrinksOJ
May 11 2017 04:31
@Takumar Thanks! re: adding a default option..
CamperBot
@camperbot
May 11 2017 04:31
egnarodrinksoj sends brownie points to @takumar :sparkles: :thumbsup: :sparkles:
:star2: 3596 | @takumar |http://www.freecodecamp.com/takumar
Claudio Restifo
@Marmiz
May 11 2017 04:31
@grfraser you're using a forEach loop, so the value is passed to i:
  split.forEach(function (i) {
   console.log(i);
  });
grfraser
@grfraser
May 11 2017 04:32
i also changed var split to splitted so as not to confuse the computer
shouldn’t each word be console logged then @Marmiz ?
Claudio Restifo
@Marmiz
May 11 2017 04:34

@grfraser

   console.log(i)

will print the splitted string. Try it :)

or try it here: https://repl.it/HsC5
grfraser
@grfraser
May 11 2017 04:35
oh so i dont need to add splitter[i]?
splitter[i]? if splitted is my var
Claudio Restifo
@Marmiz
May 11 2017 04:35
@grfraser in a for loop the element that "is looked at" is the variable you pass... so in your case is i
grfraser
@grfraser
May 11 2017 04:37

why does


function findLongestWord(str) {
  var splitted = str.split(" ");
  splitted.forEach(function (i) {
   console.log(i.length);
  });
}

findLongestWord("The quick brown fox jumped over the lazy dog");

end in undefined?

pursuitgit
@pursuitgit
May 11 2017 04:38
Hi friends, I'm having trouble with the 'Golf Code' exercise. Can anyone point me in the right direction? I'm not sure how to use both par and strokes in my if statements
grfraser
@grfraser
May 11 2017 04:39
@Marmiz
@pursuitgit use strokes ===
Tu Nguyen
@nvminhtu
May 11 2017 04:40
@grfraser : @Marmiz is right - you only need call i (element inside a loop)
grfraser
@grfraser
May 11 2017 04:40
but can you answer that last question please? @nvminhtu
it counts the length of 9 (alll the letters) and ends in undefined
Tu Nguyen
@nvminhtu
May 11 2017 04:40
I tested, I didn't see any console show undefined
Sulaiman
@suli-g
May 11 2017 04:40
@pursuitgit
if (this) {return "that";}
else if (this other thing) {return "that_other_thing";}
else {return "that thing";}
Tu Nguyen
@nvminhtu
May 11 2017 04:41
@grfraser : did you try to refresh debug log
grfraser
@grfraser
May 11 2017 04:41
@nvminhtu it does though lol what try it here then https://repl.it/HsC5
how do you do that
Claudio Restifo
@Marmiz
May 11 2017 04:41

@grfraser

ends in undefined

What you mean by that? It's logging the word length. The undefined comes since your function is sot returning anything...
If that's the undefined you're talking to

grfraser
@grfraser
May 11 2017 04:41
clear console
yes
the last thing returned is undefined
but only when logging length- not i itself

function findLongestWord(str) {
  var splitted = str.split(" ");
  splitted.forEach(function (i) {
   console.log(i.length);
  });
}

findLongestWord("The quick brown fox jumped over the lazy dog");
Claudio Restifo
@Marmiz
May 11 2017 04:42
@grfraser that's because your function is not returning anything, and repl.it log the return by default
don't worry about that
grfraser
@grfraser
May 11 2017 04:43
okay lol
Tu Nguyen
@nvminhtu
May 11 2017 04:43
repl.it showed that :D - even you try console.log('test');
Claudio Restifo
@Marmiz
May 11 2017 04:43
I mean, ultimately your function should do something usefoul... and that's where the undefined stop being
intcreate
@intcreate
May 11 2017 04:44
can any1 help me with this? square not turning orange when clicked.
https://codepen.io/anon/pen/vmROoN
pursuitgit
@pursuitgit
May 11 2017 04:45
is this on the right track for the gold code challenge friends? if (par === strokes){
return "Hole-in-one!";
}
else if (strokes <= par-2){
return "Eagle";
}
Gulsvi
@gulsvi
May 11 2017 04:48
@intcreate Your first line should be: var square = document.getElementsByClassName('square')[0];
Your CSS still needs height/width for the div with the new class name:
.newClass {
  height: 5rem;
  width: 5rem;  
  background: orange;  
}
Kyle Naumovski
@egnarodrinksOJ
May 11 2017 04:48
@Blauelf Thanks for Answer nor result
CamperBot
@camperbot
May 11 2017 04:48
egnarodrinksoj sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4106 | @blauelf |http://www.freecodecamp.com/blauelf
akkie99
@akkie99
May 11 2017 04:48
@pursuitgit you took the first if statement wrong...
and by the way where is the rest of the code buddy?
intcreate
@intcreate
May 11 2017 04:51
@SkyCoder01 thanks thats working
CamperBot
@camperbot
May 11 2017 04:51
intcreate sends brownie points to @skycoder01 :sparkles: :thumbsup: :sparkles:
:star2: 1353 | @skycoder01 |http://www.freecodecamp.com/skycoder01
Tu Nguyen
@nvminhtu
May 11 2017 04:52
@intcreate @SkyCoder01 It's good, and I thought that you should add class 'square' back - it will be better
var square = document.getElementsByClassName('square')[0];
// onclick suppose to turn orange 

square.onclick = function () {
  if (square.className === 'newClass') {
    square.className = 'square';
  } else {
    square.className = 'newClass';
  }
}
intcreate
@intcreate
May 11 2017 04:52
now when i click on it
it turns orange
but how do i turn it back to black when i click again
pursuitgit
@pursuitgit
May 11 2017 04:53
if (strokes === 1){
return "Hole-in-one!";
}
else if (strokes <= par-2){
return "Eagle";
}
else if (strokes = par-1){
return "Hole-in-one!";
}
is this looking better
@akkie99 I was trying to just get the concept of how to write the statement first before writing it all out
Tu Nguyen
@nvminhtu
May 11 2017 04:53
@intcreate check script in my last comment - just add square
intcreate
@intcreate
May 11 2017 04:53
when i click on it 2 times
it dissapeears
u need to have the square class or it will dissappear
Dj
@m3rkiejr
May 11 2017 04:55
after you click on it, it no longer has class square, so selector doesn't catch it in the first line?
akkie99
@akkie99
May 11 2017 04:56
@pursuitgit lol..yes...
intcreate
@intcreate
May 11 2017 04:56
square.onclick = function () {
  if (square.className === 'newClass') {  // if has newClass, remove, only square class 
                                                                                                          remain
    square.className = 'square';
  } else {
    square.className = 'square newClass'; // if dont have newClass, add it in
  }
}
Tu Nguyen
@nvminhtu
May 11 2017 04:59
nice
intcreate
@intcreate
May 11 2017 04:59
@SkyCoder01 wow thanks
CamperBot
@camperbot
May 11 2017 04:59
intcreate sends brownie points to @skycoder01 :sparkles: :thumbsup: :sparkles:
:warning: intcreate already gave skycoder01 points
Gulsvi
@gulsvi
May 11 2017 04:59
Your code was very close :)
Like @nvminhtu Was saying, best to keep that square class
Abhishek Tiwari
@fillopfy
May 11 2017 05:00
var Bike = function() {

  // Only change code below this line.

  var gear=0;
 this.getGear=function(){
   return gear;
 };
  this.setGear=function(value){
    return getGear(gear+value);

  };
what is wrong in this code
grfraser
@grfraser
May 11 2017 05:06
why does this not work?

function findLongestWord(str) {
  myArr=[];
  var splitted = str.split(" ");
  splitted.forEach(function (i) {
  var lengths = myArr.push(i.length);
  });
  lengths.sort(function(a,b){
    lengths = a-b;
    var largest = lengths.pop();
  });
  return largest;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
lengths is not defined?
Aizaz Shahid
@aizazshahid
May 11 2017 05:06
@fillopfy in your this.setgear you need to assign that parameter to the gear.
grfraser
@grfraser
May 11 2017 05:07
why is lengths undefined?
Aizaz Shahid
@aizazshahid
May 11 2017 05:07
@grfraser but why are you storing the a-b ?
grfraser
@grfraser
May 11 2017 05:08
to order from smallest to least into an array then pop off the max result
Aizaz Shahid
@aizazshahid
May 11 2017 05:08
@grfraser first you cannot assign values within a callback method.
grfraser
@grfraser
May 11 2017 05:08
its the sort function
Aizaz Shahid
@aizazshahid
May 11 2017 05:08
means:
var a = 5;
some.method( function() {
a = 10;
} );

return a;   // 5
@grfraser that is called callback method function() { ... }
grfraser
@grfraser
May 11 2017 05:09
but thats how you sort numbers
how do i assign them
Aizaz Shahid
@aizazshahid
May 11 2017 05:09
no we sort from the return value like this/
arr.sort(function(a,b) {   return a-b;  } );
or
arr.sort( (a, b) => a-b );
ES6 syntax
grfraser
@grfraser
May 11 2017 05:10
wheres your last }
i dont know es6 yet
Aizaz Shahid
@aizazshahid
May 11 2017 05:11
ok forgot it, use the first one !
grfraser
@grfraser
May 11 2017 05:11
but where is the last } for the function
Aizaz Shahid
@aizazshahid
May 11 2017 05:11
yes, i forgot }
grfraser
@grfraser
May 11 2017 05:11
there we go, isnt that what i did
sbechtold13
@sbechtold13
May 11 2017 05:11
hey anyone using ruby
grfraser
@grfraser
May 11 2017 05:11
this is javascript
Gulsvi
@gulsvi
May 11 2017 05:11
@grfraser From the Stand In Line challenge, what does .push() return?
  splitted.forEach(function(i) {
    var lengths = myArr.push(i.length);
  });
Aizaz Shahid
@aizazshahid
May 11 2017 05:12
@sbechtold13 ruby is backend ??
sbechtold13
@sbechtold13
May 11 2017 05:12
i know :laughing: trying my luck though.
Gulsvi
@gulsvi
May 11 2017 05:12
i.e. what is lengths equal to on every loop of that for each?
Aizaz Shahid
@aizazshahid
May 11 2017 05:12
grfraser
@grfraser
May 11 2017 05:12
how do i store that array?
Aizaz Shahid
@aizazshahid
May 11 2017 05:12
@grfraser what ?
sbechtold13
@sbechtold13
May 11 2017 05:12
shoot thanks @forwebtech
CamperBot
@camperbot
May 11 2017 05:12
sbechtold13 sends brownie points to @forwebtech :sparkles: :thumbsup: :sparkles:
:cookie: 480 | @forwebtech |http://www.freecodecamp.com/forwebtech
Abhishek Tiwari
@fillopfy
May 11 2017 05:12

@forwebtech is this correct
var Bike = function() {

// Only change code below this line.

var gear=0;
this.setGear=function(value){
gear=value;

};
this.getGear=function(){
return setGear(value);
};
};

grfraser
@grfraser
May 11 2017 05:13
push returns the value to the array
Abhishek Tiwari
@fillopfy
May 11 2017 05:13
var Bike = function() {

  // Only change code below this line.

  var gear=0;
  this.setGear=function(value){
    gear=value;

  };
  this.getGear=function(){
    return  setGear(value);
  };
};
grfraser
@grfraser
May 11 2017 05:13
@SkyCoder01
push returns the value to the array
Aizaz Shahid
@aizazshahid
May 11 2017 05:13
@fillopfy your getGear is not correct
Gulsvi
@gulsvi
May 11 2017 05:13
.push() returns the new length of the array after you push the item to it @grfraser
Abhishek Tiwari
@fillopfy
May 11 2017 05:13
@forwebtech why?
Aizaz Shahid
@aizazshahid
May 11 2017 05:13
because you need to just return the gear from this.getGear
grfraser
@grfraser
May 11 2017 05:13
@forwebtech that is the syntax i used how do i store it into an array
@SkyCoder01 oh yes
Gulsvi
@gulsvi
May 11 2017 05:14
var myArr = [11,22,33];
var foo = myArr.push(100);
// foo is equal to 4 and myArr is equal to [11,22,33,100]
grfraser
@grfraser
May 11 2017 05:15
soo

function findLongestWord(str) {
  myArr=[];
  var splitted = str.split(" ");
  splitted.forEach(function (i) {
    myArr.push(i.length);
  });
  myArr.sort(function(a,b){
    myArr = a-b;
    var largest = myArr.pop();
  });
  return largest;
}
Abhishek Tiwari
@fillopfy
May 11 2017 05:15
@forwebtech that worked. Thanks! But why my code was wrong, logically it should return the value of setGear(value);
CamperBot
@camperbot
May 11 2017 05:15
fillopfy sends brownie points to @forwebtech :sparkles: :thumbsup: :sparkles: