These are chat archives for FreeCodeCamp/HelpJavaScript

28th
Apr 2017
Brittany Rutherford
@brittanyrutherford
Apr 28 2017 00:00
can't we pass promises from server to client?
Keon Samuel
@keonsam
Apr 28 2017 00:04
@paulgillaspie function nextInLine(arr, item) {
// Your code here
arr.push(item);
arr.shift();
return arr; // Change this line
}
Johnny Meza
@XLpacman805
Apr 28 2017 00:10
@brittanyrutherford I don't know any node but I noticed in fetch you're using `` and not ' '. Is that how it's supposed to be?
Brittany Rutherford
@brittanyrutherford
Apr 28 2017 00:10
@XLpacman805 it doesn't matter, i am using it so i can embed the ID later on instead of static 34
Johnny Meza
@XLpacman805
Apr 28 2017 00:15
I don't even know what any of that code does besides console.log(). Lol, I'll learn soon enough.
Roxroy
@roxroy
Apr 28 2017 00:15
@brittanyrutherford , You cannot pass a promise between server and client and via versa. The promise is implemented and managed by either the client or the server. Do you have a link to the code ? What are you trying to do perhaps there is another way
Ryan Nelson
@iamryandnelson
Apr 28 2017 00:16
Any ideas about what I'm doing wrong in my code? I'm working on the Twitch.tv project and I'm trying to run an ajax call to the twitch.tv/channels url, then a second ajax call to the twitch.tv/streams url for each channel I've picked to display on my page. Not sure what I'm missing... http://codepen.io/iamryandnelson/pen/vmXzXz?editors=0111
Brittany Rutherford
@brittanyrutherford
Apr 28 2017 00:17
@roxroy i wanto connect to twitch api, from node
so i am doing a proof of concept first
Conor Murphy
@cmurphy580
Apr 28 2017 00:19

Can anyone see any problems with my regex for checking the validity of IP addresses?

/^(([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])\.){3}(([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])){1}$/;

let me know if you need to know the proper format

Brittany Rutherford
@brittanyrutherford
Apr 28 2017 00:19

i want to search for a user, submit the request, and send it to node, then i want to communicate with twitch service from node, so i want to have the following:

front-end file contact >> node like (app.get('/twitch/userId) .. then node contacts the webservice @roxroy

Roxroy
@roxroy
Apr 28 2017 00:20
@brittanyrutherford , ok. What is the link to the code? Did you originally develop it without node.js and are you now converting to to use nodejs?
Brittany Rutherford
@brittanyrutherford
Apr 28 2017 00:20
i know i can use fetch directly from front end, but I want to practice
@roxroy it's locally, am using node ..
Joseph
@revisualize
Apr 28 2017 00:21
Hello.
Brittany Rutherford
@brittanyrutherford
Apr 28 2017 00:22
i am trying to even use fetch to get the data directly, it's not workingm always returning 404 and type: "cors" , don't know what that means
hi joseph
Roxroy
@roxroy
Apr 28 2017 00:22
@brittanyrutherford , what sections of the nodejs part is working?
aRtoo
@artoodeeto
Apr 28 2017 00:22
hey guys struggle is real. can i have a help. how can you loop inside an array with objects?? im confused because the object are not number. heres the code:



//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




          for(var c=0;c<contacts.length; c++){
            if(contacts[c].firstName == firstName){
              console.log(contacts[c].firstName)


            } 
          }


         /*     for(var i=0;i<contacts.length; i++){
          if(contacts[i].lastName == prop){
            console.log(contacts[i].lastName);
          }
        }*/



// Only change code above this line
}



// Change these values to test your function
lookUpProfile("Harry" , "lastName");
Joseph
@revisualize
Apr 28 2017 00:22
@artoodeeto Just like that.
Brittany Rutherford
@brittanyrutherford
Apr 28 2017 00:23
@roxroy if i contact the webservice and log things in node, it's working perfectly. so I can contact the web service, log the result inside node, and it will show just find, now how to do I use fetch?
I can't use fetch with either my node api, or directly with the web service
aRtoo
@artoodeeto
Apr 28 2017 00:23
@revisualize but how can i loop through the lastname, numbe and likes??
Joseph
@revisualize
Apr 28 2017 00:23
@artoodeeto You don't need to for this lesson.
HeebieGeeBee
@HeebieGeeBee
Apr 28 2017 00:23
https://codepen.io/Geeheeb/pen/QvdPWJ?editors=0010 if anyone could have a bit of a go of my tic toe, give some feedback, any bugs etc, much appreciated
Brittany Rutherford
@brittanyrutherford
Apr 28 2017 00:24

so this:

 fetch(`web service url`)
            .then((results) => {
                console.log(results);
            })
            .catch((e) => console.log(e));

is not working

Joseph
@revisualize
Apr 28 2017 00:24
@artoodeeto Do you want to do things that are not required for this lesson?
@artoodeeto I can tell you how to do what you want to do but, it is not required for the lesson.
cbot
CamperBot
@camperbot
Apr 28 2017 00:26
you called?
aRtoo
@artoodeeto
Apr 28 2017 00:26
@revisualize no man. i want to solve this problem myself.
@revisualize you know any tutorial on object.key??
Gulsvi
@gulsvi
Apr 28 2017 00:26
@brittanyrutherford
fetch(`web service url`)
  .then(res => res.json())
  .then(results => console.log(results))
  .catch(e => console.log(e));
Joseph
@revisualize
Apr 28 2017 00:26
@artoodeeto What?
aRtoo
@artoodeeto
Apr 28 2017 00:27
@artoodeeto someone told me. that i could use object.keys
Joseph
@revisualize
Apr 28 2017 00:27
@artoodeeto Look you can use Object.Keys to create an array of all of the Objects keys and iterate across the list.
But, that isn't required for the lesson.
Roxroy
@roxroy
Apr 28 2017 00:28

@brittanyrutherford , here is some code I used to get data from google search service

const getContent = function(url) {
  // return new pending promise
  return new Promise((resolve, reject) => {
    const httpLib = require('http');
    const request = httpLib .get(url, (response) => {
      if (response.statusCode < 200 || response.statusCode > 299) {
         reject(new Error('Failed to load page, status code: ' + response.statusCode));
       }
      const body = [];
      response.on('data', (chunk) => body.push(chunk));
      response.on('end', () => resolve(body.join('')));
    });
    request.on('error', (err) => reject(err))
    })
};

You can adapt it to fit your needs. the rest of the code is here.

aRtoo
@artoodeeto
Apr 28 2017 00:29
@revisualize then how can i solve that problem without object,keys then?? because lstname, numbers, and likes i cant loop thru them
Joseph
@revisualize
Apr 28 2017 00:29
@artoodeeto You don't need to loop through them.
@artoodeeto You just need to see if the object HAS the property.
Ryan Nelson
@iamryandnelson
Apr 28 2017 00:29
Can someone help me with my code? I'm working on the Twitch.tv project and I'm trying to run an ajax call to the twitch.tv/channels url, then a second ajax call to the twitch.tv/streams url for each channel I've picked to display on my page. Not sure what I'm missing... http://codepen.io/iamryandnelson/pen/vmXzXz?editors=0111
Joseph
@revisualize
Apr 28 2017 00:30
@artoodeeto And... How do you test if an object has a property?
aRtoo
@artoodeeto
Apr 28 2017 00:30
@revisualize ha??? hahaha. if you dont then u cant run thru the arrray man
haha
@revisualize hasOwnproperty
Joseph
@revisualize
Apr 28 2017 00:30
Bingo
aRtoo
@artoodeeto
Apr 28 2017 00:31
@revisualize but i used it awhile ago no use because i can only do this on the code.

  for(var c=0;c<contacts.length; c++){
            if(contacts[c].firstName == firstName){
              console.log(contacts[c].firstName)


            } 
          }
Joseph
@revisualize
Apr 28 2017 00:32
@artoodeeto What?
@artoodeeto Show me.
Brittany Rutherford
@brittanyrutherford
Apr 28 2017 00:32
thanks @SkyCoder01 the res => res.json() is what i needed
CamperBot
@camperbot
Apr 28 2017 00:32
brittanyrutherford sends brownie points to @skycoder01 :sparkles: :thumbsup: :sparkles:
:star2: 1212 | @skycoder01 |http://www.freecodecamp.com/skycoder01
aRtoo
@artoodeeto
Apr 28 2017 00:33
@revisualize u see the code. i cant loop thru the data of the objects because is just firstName
Joseph
@revisualize
Apr 28 2017 00:33
@artoodeeto contacts[c].hasOwnProperty("lastName")
@artoodeeto Okay.
@artoodeeto I think I see your problem.
aRtoo
@artoodeeto
Apr 28 2017 00:34
@revisualize i tried that too before man
Joseph
@revisualize
Apr 28 2017 00:34
@artoodeeto I think you're confused about how to work with object values that are stored in an array.
@artoodeeto That works. If you tried it before I want you to show me.
Stephen James
@sjames1958gm
Apr 28 2017 00:35
@iamryandnelson The second callback updates a class game - but that will update all of the elements with the class
game which could be multiple elements.
Joseph
@revisualize
Apr 28 2017 00:35
@artoodeeto Now I'm not really sure what you're confused with.
aRtoo
@artoodeeto
Apr 28 2017 00:36
@revisualize i know how to get the array sir likes contacts[x].firstname. u see i can just only use the firstname. because the inner is an object
Joseph
@revisualize
Apr 28 2017 00:37
@artoodeeto Okay.
@artoodeeto Then what is your confusion?
aRtoo
@artoodeeto
Apr 28 2017 00:38
@revisualize can u show me how sir?? like im confused on how to loop thru the firstname, lastname,numbers,
Joseph
@revisualize
Apr 28 2017 00:38
The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.
@artoodeeto The function should check if firstName is an actual contact's firstName
You're doing that here: if(contacts[c].firstName == firstName)
Now you just need to check if the given property (prop) is actually a property of that contact.
And you use .hasOwnProperty() to check if an object has a property
But, I guess...
@artoodeeto If you really want to create an array of object keys ... You'd do:
Object.keys(contacts[c])
This is what you'd do to create an array of the properties for the contacts array element object
@artoodeeto Then you could iterate across that new array.
Joseph
@revisualize
Apr 28 2017 00:43
@artoodeeto And see if there is a prop value in that array.
Ikenna
@orinocogroup
Apr 28 2017 00:44
have a problem guys
Joseph
@revisualize
Apr 28 2017 00:44
@artoodeeto But... That's a lot of extra code for something that is accomplished with .hasOwnProperty()
Ikenna
@orinocogroup
Apr 28 2017 00:44

// Initialize these three variables
var a;
var b;
var c;

// Do not change code below this line

a = a + 1;
b = b + 5;
c = c + " String!";

a should be defined and have a value of 6
and i typed in var a = 6;.........it gives me error, pls i need help
Stephen James
@sjames1958gm
Apr 28 2017 00:47
@orinocogroup a should be 6 after a = a + 1 as well
Ikenna
@orinocogroup
Apr 28 2017 00:49
how?
@sjames1958gm @sjames1958gm how?
Joseph
@revisualize
Apr 28 2017 00:50
@orinocogroup What + 1 is 6?
Stephen James
@sjames1958gm
Apr 28 2017 00:50
@orinocogroup What number when you add 1 to it give you 6
Ikenna
@orinocogroup
Apr 28 2017 00:50

@revisualize // Initialize these three variables
var a;
var b;
var c;

// Do not change code below this line

a = a + 1;
b = b + 5;
c = c + " String!";

Joseph
@revisualize
Apr 28 2017 00:51
@orinocogroup I see that.
Thanks for sharing it again.
Stephen James
@sjames1958gm
Apr 28 2017 00:51
@orinocogroup You need to initialize the variables such that when combined
with the code at the bottom you get the correct result
Ikenna
@orinocogroup
Apr 28 2017 00:51
the question is a should be defined and have a variable of 6
Joseph
@revisualize
Apr 28 2017 00:51
@orinocogroup Yes.
@orinocogroup What +1 equals 6?
Ikenna
@orinocogroup
Apr 28 2017 00:52
@revisualize 5
Joseph
@revisualize
Apr 28 2017 00:52
!
Sweet
Ikenna
@orinocogroup
Apr 28 2017 00:52
but 5 does not work either
Joseph
@revisualize
Apr 28 2017 00:52
@orinocogroup Show me.
Stephen James
@sjames1958gm
Apr 28 2017 00:52
@orinocogroup Show
Ikenna
@orinocogroup
Apr 28 2017 00:52
ok it worked
@revisualize it worked
Joseph
@revisualize
Apr 28 2017 00:53
Congrats.
hekri-d
@hekri-d
Apr 28 2017 00:55
got a problem guys.
Joseph
@revisualize
Apr 28 2017 00:56

@orinocogroup So, here is what that lesson is trying to teach you.
You have a variable declaration process. And that is when you simply just do

var name;

With that code you're just declaring a variable name. The value of that variable is currently undefined (a keyword in programming and JavaScript)

There is a process where you are able to declare a variable and initialize the variable to have a value.

var name = "Happy Feet";

With that code you've declared the variable name and initialized the value to a string of "Happy Feet".

aRtoo
@artoodeeto
Apr 28 2017 00:56
@revisualize ohh. thnk you sir
Ryan Nelson
@iamryandnelson
Apr 28 2017 00:56
@sjames1958gm I changed classes to be unique to each channel. Still doesn't work... http://codepen.io/iamryandnelson/pen/vmXzXz?editors=1111
aRtoo
@artoodeeto
Apr 28 2017 00:56
@revisualize appreciate ur help
Joseph
@revisualize
Apr 28 2017 00:56
@artoodeeto I have a bit of a write up on that lesson: Gist by revisualize / FreeCodeCamp - Profile Lookup.js
@artoodeeto It may help.
aRtoo
@artoodeeto
Apr 28 2017 00:57
@revisualize for sure sir. ill read this. thank so much
CamperBot
@camperbot
Apr 28 2017 00:57
artoodeeto sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3839 | @revisualize |http://www.freecodecamp.com/revisualize
hekri-d
@hekri-d
Apr 28 2017 00:59
@artoodeeto drop the 'sir' part. We know you're a nice guy. Everyone (in this and most cases Joseph and James) here is glad to help you so no need for formalities like that. :)
aRtoo
@artoodeeto
Apr 28 2017 01:00
sorry man. im used to it. i call them bros and dudes sometime though haha
Stephen James
@sjames1958gm
Apr 28 2017 01:01
@iamryandnelson if (data2.stream === null); this <<< ; at the end is invalidating your if so the next code always runs
hekri-d
@hekri-d
Apr 28 2017 01:01
@artoodeeto no need to be sorry. Just sayin'. Relax... :)
Ryan Nelson
@iamryandnelson
Apr 28 2017 01:02
@sjames1958gm What is "this<<<;"?
Jason Shoemaker
@kutsuya1
Apr 28 2017 01:03
@artoodeeto yeah, I was trying to figure out if you were being sarcastic
Stephen James
@sjames1958gm
Apr 28 2017 01:03
@iamryandnelson the semicolon at the end of the if statement is bad
aRtoo
@artoodeeto
Apr 28 2017 01:04
@kutsuya1 nahh bro. im used to it becasue i was in the military. 50 push ups if you dont address the TI sir/maam.
Ryan Nelson
@iamryandnelson
Apr 28 2017 01:04
@sjames1958gm Omg, lol. You are a genius! Thank you :)!!
CamperBot
@camperbot
Apr 28 2017 01:04
iamryandnelson sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7006 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Jason Shoemaker
@kutsuya1
Apr 28 2017 01:04
@artoodeeto ah, I see! :)
hekri-d
@hekri-d
Apr 28 2017 01:05
@artoodeeto has anyone tried to troll the crap out of the guys in the military that scream on one's face?
CamperBot
@camperbot
Apr 28 2017 01:05
:trollface: troll problems? notify admins here
Stephen James
@sjames1958gm
Apr 28 2017 01:05
@iamryandnelson thx - it was a mystery at first
CamperBot
@camperbot
Apr 28 2017 01:05
sjames1958gm sends brownie points to @iamryandnelson :sparkles: :thumbsup: :sparkles:
:cookie: 266 | @iamryandnelson |http://www.freecodecamp.com/iamryandnelson
aRtoo
@artoodeeto
Apr 28 2017 01:06
@hekri-d hahaha. not yet. im used to screaming but i cant stand doing push up under the freakin sun man.
Keon Samuel
@keonsam
Apr 28 2017 01:07
I pick to join the navy but was Iike hell no I ain't fighting no world war 3.
hekri-d
@hekri-d
Apr 28 2017 01:07
If I was somehow to land on one those bootcamps or whatever they're called I'd surely ask one of them guys 'why are you screaming?'. We're not deaf or anything.
Ryan Nelson
@iamryandnelson
Apr 28 2017 01:10
@sjames1958gm So, I just changed the unique "game" classes for each channel back to a universal class "game" and the code still works. It looks like the issue was just the semi-colon.
aRtoo
@artoodeeto
Apr 28 2017 01:13

haloo guys. quick question. why is it on my 2nd if the prop wont display?? it says undefined but no errors.

code:


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




          for(var c=0;c<contacts.length; c++){

            if(contacts[c].firstName == firstName){
              console.log(contacts[c].firstName);

              if(contacts[c].hasOwnProperty(prop)){
               console.log(contacts[c].prop);
              }
                else{console.log("No such prop")}
              }

            } 



         /*     for(var i=0;i<contacts.length; i++){
          if(contacts[i].lastName == prop){
            console.log(contacts[i].lastName);
          }
        }*/




// Only change code above this line
}
Keon Samuel
@keonsam
Apr 28 2017 01:14
if you are not afraid to die and kill people then go for it.
Coy Sanders
@coymeetsworld
Apr 28 2017 01:15
yes, because most people that serve in the military do die and kill people....
hekri-d
@hekri-d
Apr 28 2017 01:20
@coymeetsworld not all of them do but @keonsam isn't wrong. If you wanna join the military you better be prepared for that.
Keon Samuel
@keonsam
Apr 28 2017 01:21
no but if a world war break out then.
Coy Sanders
@coymeetsworld
Apr 28 2017 01:21
more accurate to say very few, and there are jobs in military that dont involve combat
not likely to be a world war anytime soon
HeebieGeeBee
@HeebieGeeBee
Apr 28 2017 01:25
you realise its pretty much impossible to have a hot war between nuclear powers dont you
Jason Shoemaker
@kutsuya1
Apr 28 2017 01:25
I thought nukes were hot
HeebieGeeBee
@HeebieGeeBee
Apr 28 2017 01:26
well its just very short
Keon Samuel
@keonsam
Apr 28 2017 01:26
some say nukes are fake.
Roxroy
@roxroy
Apr 28 2017 01:26
@artoodeeto , I don't see the code for "No such contact";
HeebieGeeBee
@HeebieGeeBee
Apr 28 2017 01:26
should go ask japan
aRtoo
@artoodeeto
Apr 28 2017 01:27

@roxroy right

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




          for(var c=0;c<contacts.length; c++){

            if(contacts[c].firstName == firstName){
              //res =  contacts[c].firstName;

              if(contacts[c].hasOwnProperty(prop)){
               res = contacts[c][prop];
              }
                else{
                   res = ("No such prop");
                }
              }

            } 

  return res ;

// Only change code above this line
}



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

but still not working

Coy Sanders
@coymeetsworld
Apr 28 2017 01:28
right, nukes don't exist, North Korea is not really testing them and we're outraged at something that we dont have lol
Roxroy
@roxroy
Apr 28 2017 01:34
@artoodeeto , you are close you need to return the correct text, it should be "No such property"
aRtoo
@artoodeeto
Apr 28 2017 01:35

@roxroy yea


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




          for(var c=0;c<contacts.length; c++){

            if(contacts[c].firstName == firstName){


              if(contacts[c].hasOwnProperty(prop)){
               res = contacts[c][prop];
              }
                else{
                   res = "No such property";
                }
              } 

            } 

  return res ;

// Only change code above this line
}

like this right.

Roxroy
@roxroy
Apr 28 2017 01:36
@artoodeeto , the very end outside the for loop it should should return return "No such contact";
@artoodeeto , set var res = No such contact"; and move it in to the lookUpProfile function
aRtoo
@artoodeeto
Apr 28 2017 01:41
@roxroy ohh thank you sir. but why cant i use else statement on my first if??
CamperBot
@camperbot
Apr 28 2017 01:41
artoodeeto sends brownie points to @roxroy :sparkles: :thumbsup: :sparkles:
:cookie: 775 | @roxroy |http://www.freecodecamp.com/roxroy
WillGITCode
@WillGITCode
Apr 28 2017 01:42
Im having a hard time wrapping my head around objects in the Wherefore art thou challenge.
I can loop through the object but cant test for a given property and value pair.
Any ideas?
function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line
  for(var i = 0; i < Object.keys(collection).length;i++){
    if(collection.hasOwnProperty(source)){
      arr.push(collection[i]);
    }

  }

  // Only change code above this line
  return arr;
}

whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
Roxroy
@roxroy
Apr 28 2017 01:43
@artoodeeto , the else goes the the last if, However, you can use brackets to change what if it is linked to?
aRtoo
@artoodeeto
Apr 28 2017 01:46
@roxroy im sorry sir i didtn understand.
Roxroy
@roxroy
Apr 28 2017 01:47
@WillGITCode , you are going to need two loops, One for the list of persons and the other the attribute of each person.
Steven Stinson
@rufusBot
Apr 28 2017 01:48
How do I post code into this chat?
grfraser
@grfraser
Apr 28 2017 01:48
three ` on each end
hekri-d
@hekri-d
Apr 28 2017 01:49
@rufusBot you put it inside ```
WillGITCode
@WillGITCode
Apr 28 2017 01:49
@rufusBot triple click the tilda key then paste.
Roxroy
@roxroy
Apr 28 2017 01:49

@artoodeeto , here is your code

for (var c = 0; c < contacts.length; c++) {
    if (contacts[c].firstName == firstName) {
      if (contacts[c].hasOwnProperty(prop)) {
        res = contacts[c][prop];
      } else {
        res = "No such property";
      }
    }
  }

The else goes with 'f (contacts[c].hasOwnProperty(prop)) {'

hekri-d
@hekri-d
Apr 28 2017 01:49
@rufusBot if it's too long then use codepen
Steven Stinson
@rufusBot
Apr 28 2017 01:50

I'm on the palindrome challenge but only one test isn't passing and I have no idea why.

function palindrome(str) { str = str.toLowerCase().replace(/[^a-z]+/g,""); return str === str.split("").reverse().join(""); }

That didn't work lol
Francis Ngo
@francisngo
Apr 28 2017 01:50
hey all. i am trying to rewrite the underscore function for both _find & _reject. i am using a function that returns the number if the number is even. in the _find function, i have the even numbers return but when i use it for _reject, i am not getting the odd numbers. can someone help me with my code?
Steven Stinson
@rufusBot
Apr 28 2017 01:51
function palindrome(str) {
   str = str.toLowerCase().replace(/[^a-z]+/g,"");
   return str === str.split("").reverse().join("");
}
There we go
Francis Ngo
@francisngo
Apr 28 2017 01:52
function _find(list, predicate){
  var array = [];
  if(list == null){
    return list;
  }
  _each(list, function(item){
    if(predicate(item)){
      array.push(predicate(item));
    }
  });
  return array.shift();
}

function _reject(list, predicate){
  if(list == null){
    return list;
  }
  _filter(list, function(item){
    return !predicate(item);
  });
}

//helper function
function _filter(list, predicate){
  var array = [];
  if(array == null){
    return array
  }
  _each(list, function(item){
    if(predicate(item)){
      array.push(predicate(item));
    }
  });
  return array;
}

function _each(array, callback){
  for(var i = 0; i < array.length; i++){
    callback(array[i]);
  }
}

//test
var numbers = [1, 2, 3, 4, 5];

function isEven(num){
  return num % 2 === 0;
}

console.log(_reject(numbers, isEven));
console.log(_find(numbers, isEven));
grfraser
@grfraser
Apr 28 2017 01:52
sorry lol how did you do that @rufusBot
Steven Stinson
@rufusBot
Apr 28 2017 01:53
Do what
grfraser
@grfraser
Apr 28 2017 01:53
the colorful code
Steven Stinson
@rufusBot
Apr 28 2017 01:53
The only test it isn't passing is showing "1 eye for of 1 eye." as false
you do and then paste it to the next line and put on the line under it
whops
lol
```
Button under the escape button
grfraser
@grfraser
Apr 28 2017 01:54
so like
this
lol
hahah
thanks @rufusBot
CamperBot
@camperbot
Apr 28 2017 01:54
grfraser sends brownie points to @rufusbot :sparkles: :thumbsup: :sparkles:
:cookie: 241 | @rufusbot |http://www.freecodecamp.com/rufusbot
grfraser
@grfraser
Apr 28 2017 01:55
this
is
cool
and
colorful 
function _reject (){};
lol
Steven Stinson
@rufusBot
Apr 28 2017 01:56
rofl
Stephen James
@sjames1958gm
Apr 28 2017 01:56
@rufusBot Did you remove the numbers? You weren't supposed to
Steven Stinson
@rufusBot
Apr 28 2017 01:58
Did I?
Kingsley
@Kingwindie
Apr 28 2017 01:58
can someone tell me what's wrong with this code,it's rejecting the else whenever i insert else ifhttps://codepen.io/kingwindie/pen/BRWojQ?editors=1011
Stephen James
@sjames1958gm
Apr 28 2017 01:59
@rufusBot [^a-z] this matches all but letters, including numbers
@Kingwindie The semi colon at the end of the of your else if is closing the if / else not allowing the else
Kingsley
@Kingwindie
Apr 28 2017 02:01
@sjames1958gm lol thanks alot
CamperBot
@camperbot
Apr 28 2017 02:01
kingwindie sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7007 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Kingsley
@Kingwindie
Apr 28 2017 02:01
i would have never cught that
caught
Stephen James
@sjames1958gm
Apr 28 2017 02:01
@Kingwindie yw
Steven Stinson
@rufusBot
Apr 28 2017 02:01
How do I include numbers as well?
Stephen James
@sjames1958gm
Apr 28 2017 02:02
@rufusBot put 0-9 in there as well
Roxroy
@roxroy
Apr 28 2017 02:03
@Kingwindie , you can also use the switch statement in this case https://www.w3schools.com/js/js_switch.asp . It is easier to read and at add more check for different names
Steven Stinson
@rufusBot
Apr 28 2017 02:04
Doesn't seem to be working. Plus there are other strings it's testing that have numbers
Kingsley
@Kingwindie
Apr 28 2017 02:04
@roxroy ok i will look into that,right now i'm watching this really great basic level js tutorial from ejMedia on youtube,thanks for the tip
CamperBot
@camperbot
Apr 28 2017 02:04
kingwindie sends brownie points to @roxroy :sparkles: :thumbsup: :sparkles:
:cookie: 776 | @roxroy |http://www.freecodecamp.com/roxroy
Stephen James
@sjames1958gm
Apr 28 2017 02:05
@rufusBot /[^a-z0-9]/g
Steven Stinson
@rufusBot
Apr 28 2017 02:05
Yeah I figured it out lol
Thanks man
anderson
@anderson2825
Apr 28 2017 02:29

```
function destroyer(arr) {
// Remove all the values
var arrda= Array.prototype.slice.call(arguments,1);
function arrdfilter(element, index){
return arr.indexOf(arrda) === index;
}
return arr.filter(arrdfilter);

}

destroyer([1,2,1,3,2,3], 2, 3);
``` why is wrong?

function destroyer(arr) {
  // Remove all the values
      var arrda= Array.prototype.slice.call(arguments,1);
     function arrdfilter(element, index){
        return arr.indexOf(arrda) === index;
       }
    return arr.filter(arrdfilter);

}

destroyer([1,2,1,3,2,3], 2, 3);
hi,guys!
tell me answer!
eeflores
@eeflores
Apr 28 2017 02:38
ah you still need to process the other elements in the arguments object
Antonio Alcobas
@ooofooo
Apr 28 2017 02:40

var myArray = [];
for(i=0;i<5;i++){
myArray.push(i+1);
}

Hey I was hoping someone could explain why this pushes out the zero when I run the tests?

Christopher McCormack
@cmccormack
Apr 28 2017 02:43
@ooofooo that should work
@ooofooo what do you mean pushes out the zero?
@ooofooo myArray.push(i+1); i + 1 will make it so your first value is 1 and the last value is 4 (i<5) + 1 = 5
Gulsvi
@gulsvi
Apr 28 2017 02:45
maybe var i=0?
Antonio Alcobas
@ooofooo
Apr 28 2017 02:45
@cmccormack ah ok yes that makes sense thank you
CamperBot
@camperbot
Apr 28 2017 02:45
ooofooo sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 450 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Apr 28 2017 02:45
np
Pagnito
@Pagnito
Apr 28 2017 02:46
why are people using math.sqrt for the sieve of eratosthenes?
Charlotte Couttie
@charlottecouttie
Apr 28 2017 02:47
Hi there
I need help with javascript challenge to change the code to use the ++ operator on myVar and having myVar eaual 88
here is the code

var myVar = 87;

// Only change code below this line
myVar = myVar + 1;

Christopher McCormack
@cmccormack
Apr 28 2017 02:48
@Pagnito the sqrt of a number you're trying to find primes for is the highest you'll ever have to go
Charlotte Couttie
@charlottecouttie
Apr 28 2017 02:48
I mean above is the challenge question
Csaba Balogh
@JasonCorp84
Apr 28 2017 02:48
Hello

function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var i =0; multiplyAll.length; i++){
for (var j = 0; j < arr[i].length; j++){
product = product * arr[i][j];
}
}
// Only change code above this line
return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);

ehat is wrong here ?
Modify function multiplyAll so that it multiplies the product variable by each number in the sub-arrays of arr
Christopher McCormack
@cmccormack
Apr 28 2017 02:49
@charlottecouttie do exactly what it says, use the ++ operator
variableName++ is the same as saying variableName = variableName + 1
Pagnito
@Pagnito
Apr 28 2017 02:50
@cmccormack not sure what ur saying
@cmccormack are we finding all the primes below the argument?
Csaba Balogh
@JasonCorp84
Apr 28 2017 02:51
variableName++ = variableName=variableName + 1
Pagnito
@Pagnito
Apr 28 2017 02:51
arent*
Charlotte Couttie
@charlottecouttie
Apr 28 2017 02:52
@cmccormack thank you! that was simpler than I expected
CamperBot
@camperbot
Apr 28 2017 02:52
charlottecouttie sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 451 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Apr 28 2017 02:52
@Pagnito sqrt is used when finding primes, as you would never find a prime higher than the sqrt of the number to which you're searching for primes
Suzanne Atkinson
@AdventureBear
Apr 28 2017 02:53
this may be a basic question, but is there a built in method to convert an array of text to an array of numbers?
here is a sample:
["54044", "14108", "79294", "29649", "25260", "60660", "2995", "53777", "49689"]
Christopher McCormack
@cmccormack
Apr 28 2017 02:54
@AdventureBear you can use the map() method on an array
Suzanne Atkinson
@AdventureBear
Apr 28 2017 02:54
I'm importing from a file where they are separated by newlines and am splitting the file with a regex to get that array. I'm not sure where in the str.split() command I could add a parseInt to do it all in one go.
Christopher McCormack
@cmccormack
Apr 28 2017 02:55
I think the syntax would be as simple as Array.map(Number);
Suzanne Atkinson
@AdventureBear
Apr 28 2017 02:55
@cmccormack I was going to use that (or a forEach...) but didn't know if there was a slicker way to do it when I split the text file?
Christopher McCormack
@cmccormack
Apr 28 2017 02:55
@AdventureBear not going to get much slicker than map
Suzanne Atkinson
@AdventureBear
Apr 28 2017 02:55
@cmccormack OK thanks. I'm probably overthinking it and should do that.
CamperBot
@camperbot
Apr 28 2017 02:55
adventurebear sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 452 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Apr 28 2017 02:55
np
Suzanne Atkinson
@AdventureBear
Apr 28 2017 02:56
@cmccormack right, I meant the step prior that I just explained. The raw file is a text file of numbers separated by newline charactures. SO I read the whole file, split by a regex that includes a new line and that's where I get that array of charactoers.
Pagnito
@Pagnito
Apr 28 2017 02:56
@cmccormack k thanks
CamperBot
@camperbot
Apr 28 2017 02:56
pagnito sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 453 | @cmccormack |http://www.freecodecamp.com/cmccormack
Gebre Mesquitta
@MtZionCode
Apr 28 2017 02:56
Hey, I'm on the Return Early Pattern for Function, and I'm stumped! Is this correct: a < 0;
b < 0; ?
Christopher McCormack
@cmccormack
Apr 28 2017 02:57
@AdventureBear seems like a good way to do it
@MtZionCode I don't see a return in what you pasted
Gebre Mesquitta
@MtZionCode
Apr 28 2017 02:59
@cmccormack should I write: return "undefined"
Jason Luboff
@JLuboff
Apr 28 2017 03:00
Undefined is not a string
John McLellan
@McGooble
Apr 28 2017 03:03
I'm having some troubles with lookup tables..
Gebre Mesquitta
@MtZionCode
Apr 28 2017 03:05
@JLuboff true....and hmm
Suzanne Atkinson
@AdventureBear
Apr 28 2017 03:10
@cmccormack I got it working with this:
Andrew Strong
@bathorystoy
Apr 28 2017 03:10
just working on my own little side projects and i can never get bootstraps grid system to work in codepen. can someone tell me where i am going wrong?
Suzanne Atkinson
@AdventureBear
Apr 28 2017 03:10
 var textArr = evt.target.result.split(/\r\n|\r|\n/g);
      var sortArr = textArr.map(function(num) {
        return parseInt(num)
      })
@bathorystoy I think you have to use an older version of bootstrap? I remember reading about it recently on the forum.
Andrew Strong
@bathorystoy
Apr 28 2017 03:12
ok cool. what does everyone else do just use css?
Gabe Rotberg
@grotberg
Apr 28 2017 03:12
@bathorystoy codepen gives you bootstrap-4 by default, while the FCC examples use an earlier version. You can either find the CDN for a different version of bootstrap or check out the bootstrap-4 documentation to figure out what you need to do.
Andrew Strong
@bathorystoy
Apr 28 2017 03:13
ok thank you @grotberg
CamperBot
@camperbot
Apr 28 2017 03:13
bathorystoy sends brownie points to @grotberg :sparkles: :thumbsup: :sparkles:
:cookie: 279 | @grotberg |http://www.freecodecamp.com/grotberg
Gabe Rotberg
@grotberg
Apr 28 2017 03:13
@bathorystoy and as for bootstrap vs raw css... depends on what you're trying to do. Bootstrap is very nice for making things that look like bootstrap.
Andrew Strong
@bathorystoy
Apr 28 2017 03:13
glad to hear it’s not just me
Suzanne Atkinson
@AdventureBear
Apr 28 2017 03:14
@grotberg Bootstrap is very nice for making things that look like bootstrap. :clap:
anderson
@anderson2825
Apr 28 2017 03:16
@eeflores okay! i try it
Alison Foss
@davyfones
Apr 28 2017 03:19
Ok so I'm working through the javascript portion and I'm on the one asking you to remove backslashes used to escape quotes and to use single quotes....i can't seem to meet all of the objectives and it seems ridiculous
andoreilly
@andoreilly
Apr 28 2017 03:20

does var a = 7;
var b = var a; Assign the value 7 to variable a.

Assign the contents of a to variable b? thank youuu

Alison Foss
@davyfones
Apr 28 2017 03:21
you would just do
Gabe Rotberg
@grotberg
Apr 28 2017 03:21
@davyfones there's a few sneaky bits in there. remember you need to escape the original backslashes, and the tests also think one of the line breaks should be a carriage return and one of them should be a line break, which are not equivalent.
Alison Foss
@davyfones
Apr 28 2017 03:21
var a=7;
var b=a
andoreilly
@andoreilly
Apr 28 2017 03:22
@davyfones thank youuu
CamperBot
@camperbot
Apr 28 2017 03:22
andoreilly sends brownie points to @davyfones :sparkles: :thumbsup: :sparkles:
:cookie: 120 | @davyfones |http://www.freecodecamp.com/davyfones
EK Azubuike
@ekazubuike
Apr 28 2017 03:23

Hey, I'm stuck on the Smallest Common Multiple challenge. Here's my code:

function smallestCommons(arr) {
  var nums = [];
  //create array of numbers between arguments in ascending order
  if (arr[0] - arr[1] < 0) {
    for (var i = arr[0]; i <= arr[1]; i++) {
      nums.push(i);
    }
  } else if (arr[0] - arr[1] > 0) {
    for (var j = arr[0]; j >= arr[1]; j--) {
      nums.unshift(j);
    }
  }
  //add multiples of the largest number in array to acc until it's divisible by
  //nums[k]
  var acc = nums[nums.length - 1];
  var k = 0;
  while (k <= nums.length)  {
    if (acc % nums[k] !== 0) {
    acc += nums[nums.length - 1];
    }
    k++;
  }
  return acc;
}


smallestCommons([1, 5]);

How do I make it so that my if statement keeps executing until acc is divisible by nums[k]before incrementing k?

Alison Foss
@davyfones
Apr 28 2017 03:23

@grotberg var myStr = "<a href=\"http://www.example.com\" target=\"_blank\">Link</a>";
is the original code

what i did was
var myStr = "<a href= 'http://www.example.com' target= '_blank'>Link</a>";

PhilAScript826
@PhilAScript826
Apr 28 2017 03:24
Hey so im pretty sure my code is right for the "Using Objects for Lookups" but i havent been able to pass it and not sure what to do. HELP!
Gabe Rotberg
@grotberg
Apr 28 2017 03:25
@davyfones Oops, I was completely mistaken about which exercise you were on.
@davyfones OK, so for things like this I like to first remove the offending attribute value so I can see the raw html first, then go from there: <a href="">Link</a>
@davyfones you don't want to escape those original two quotes, because then the html won't parse right.
Alison Foss
@davyfones
Apr 28 2017 03:27
gotcha ok I'll try that
Michelle Carey
@genovese28
Apr 28 2017 03:28

Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed. function nextInLine(arr, item) {

return item; // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

can anyone help me?
Gomathi Sankar
@Sankar88
Apr 28 2017 03:29

Exercise: Using Objects for Lookups
Below code was not working,
var lookup = {
alpha: "Adams",
bravo:"Boston",
charlie:"Chicago",
delta:"Denver",
echo:"Easy",
foxtrot:"Frank",
"":undefined
};
result = lookup.val;

//Where i'm going wrong ? Help Plz

PhilAScript826
@PhilAScript826
Apr 28 2017 03:30
help!

function phoneticLookup(val) {
var result = "";

// Only change code below this line
var lookup = {
"alpha":"Adams",
"bravo":"Boston",
"charlie":"Chicago",
"delta":"Denver",
"echo":"Easy",
"foxtrot":"Frank"
};

// Only change code above this line
return result;
}

// Change this value to test
phoneticLookup("charlie");

xemexpress
@xemexpress
Apr 28 2017 03:30
Hi guys, I am reviewing arguments option. Looking at this advanced solution, I don't understand the last two lines of it. Could anyone explain it a bit to me? Thanks!!
function addTogether() {
  var args = Array.from(arguments);
  return args.some(n => typeof n !== "number") ? 
    undefined : args.length > 1 ?
      args.reduce( (acc, n) => acc += n, 0) : 
      (n) => typeof n === "number" ? 
        n + args[0] : undefined;
}
Manish Giri
@Manish-Giri
Apr 28 2017 03:30
@PhilAScript826 lookup is the object from which you need to get the property of the value val and assign to result
Suzanne Atkinson
@AdventureBear
Apr 28 2017 03:30
@ekazubuike are you familiar with writing recursive functions?
Manish Giri
@Manish-Giri
Apr 28 2017 03:30
@Sankar88 use bracket notation
Gomathi Sankar
@Sankar88
Apr 28 2017 03:31
Yes, result = lookup[val];
It works
Moisés Man
@moigithub
Apr 28 2017 03:31
@xemexpress last 2 lines
arrow function
+ ternary operator
Gomathi Sankar
@Sankar88
Apr 28 2017 03:31
But whats wrong with dot ?
@Manish-Giri : Why result = lookup.val; not working ?
xemexpress
@xemexpress
Apr 28 2017 03:32
@moigithub So what is passed to the arrow function?
Manish Giri
@Manish-Giri
Apr 28 2017 03:32
@Sankar88 because there's no property called val directly in the object..
xemexpress
@xemexpress
Apr 28 2017 03:32
what that n would be?
Jean Saint-Hilaire
@Wisestjean
Apr 28 2017 03:33
how can I write decimal number in JS
Charlotte Couttie
@charlottecouttie
Apr 28 2017 03:34
hey I am having trouble with the Convert Celsius to Fahrenheit challenge
Gomathi Sankar
@Sankar88
Apr 28 2017 03:35
@Manish-Giri : Thanks! I didn't notice that only bracket is used in "Accessing Objects Properties with Variables" exercise
CamperBot
@camperbot
Apr 28 2017 03:35
sankar88 sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 5319 | @manish-giri |http://www.freecodecamp.com/manish-giri
Charlotte Couttie
@charlottecouttie
Apr 28 2017 03:35
Could someone please help me in the correct way to tackle this challenge please?
Manish Giri
@Manish-Giri
Apr 28 2017 03:35
@Wisestjean 4.5
@charlottecouttie what's the problem?
Charlotte Couttie
@charlottecouttie
Apr 28 2017 03:36

function convertToF(celsius) {
var fahrenheit;
// Only change code below this line

// Only change code above this line
return fahrenheit;
}

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

this is the instructions –– To test your learning, you will create a solution "from scratch". Place your code between the indicated lines and it will be tested against multiple test cases.

The algorithm to convert from Celsius to Fahrenheit is the temperature in Celsius times 9/5, plus 32.

You are given a variable celsius representing a temperature in Celsius. Use the variable fahrenheit already defined and apply the algorithm to assign it the corresponding temperature in Fahrenheit.

I don't know how to approach this?
Jean Saint-Hilaire
@Wisestjean
Apr 28 2017 03:37
do I need to write float(variable); ?
Manish Giri
@Manish-Giri
Apr 28 2017 03:37

This is what you need to focus on

The algorithm to convert from Celsius to Fahrenheit is the temperature in Celsius times 9/5, plus 32.

That's the formula, just plug in the given celsius variable into it, and assign the result to the fahrenheit variable

@charlottecouttie
Brittany Rutherford
@brittanyrutherford
Apr 28 2017 03:38

if I use this:

document.getElementsByClassName('mydiv')[0].style.cssText = 'display: inline';

Then I try to play with stylesheets in developer tools, I can't change them after setting them with JavaScript, is this normal?

Moisés Man
@moigithub
Apr 28 2017 03:38
@xemexpress dont know :D
do u know if that code works ??
David Miller
@DavidMillerFL
Apr 28 2017 03:38

Hey everyone, doing the algorithms finally… "Find the Longest Word in a String”

Do I need to first create an array out of my string and then sort the array by largest word?

Or is there a better way?
Gabe Rotberg
@grotberg
Apr 28 2017 03:40
@DavidMillerFL that would be a pretty slick solution! there are definitely other ways, though.
I think I just ended up just splitting the string and using a for loop to compare lengths... but your way sounds more elegant.
David Miller
@DavidMillerFL
Apr 28 2017 03:41
@grotberg One of the problems I’m having is, I forgot most of the commands and stuff so I keep having to google search. How do you compare string lengths?
Victoria Zambrano
@vzambrano98
Apr 28 2017 03:41
Hey guys , anyone wanna check out my quote machine? maybe peep at why my twitter button is an absolute fraud! lol!
http://codepen.io/vzambrano98/pen/gmrLZw?editors=0001
Charlotte Couttie
@charlottecouttie
Apr 28 2017 03:42
@Manish-Giri thanks!!
CamperBot
@camperbot
Apr 28 2017 03:42
charlottecouttie sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 5320 | @manish-giri |http://www.freecodecamp.com/manish-giri
xemexpress
@xemexpress
Apr 28 2017 03:42
@moigithub the code works
Gabe Rotberg
@grotberg
Apr 28 2017 03:44
@DavidMillerFL easier than you'd think! myStringVar.length
David Miller
@DavidMillerFL
Apr 28 2017 03:45
ahh I see. I have no idea how programmers remember so many different … commands?
Gabe Rotberg
@grotberg
Apr 28 2017 03:45
@DavidMillerFL so you can iterate through and check each word length vs the previous longest one.
David Miller
@DavidMillerFL
Apr 28 2017 03:45
Thanks @grotberg
CamperBot
@camperbot
Apr 28 2017 03:45
davidmillerfl sends brownie points to @grotberg :sparkles: :thumbsup: :sparkles:
:cookie: 280 | @grotberg |http://www.freecodecamp.com/grotberg
Moisés Man
@moigithub
Apr 28 2017 03:45
@xemexpress ahh ok.. the second part is when u pass something like
addTogether(1)(2)
 args.length > 1 ?
      args.reduce( (acc, n) => acc + n, 0) : 
      (n) => typeof n === "number" ? 
        n + args[0] : undefined;
Alison Foss
@davyfones
Apr 28 2017 03:45
@grotberg ok so i'm not sure where I'm struggling. There are three objectives and before I mess with the code at all one of them is checked off. And I feel like I'm doing the right thing by removing the backslash escape quotes from the HTML tag but I can't move on
Gabe Rotberg
@grotberg
Apr 28 2017 03:45
@DavidMillerFL some I remember, but I end up googling a lot myself. more important to remember what you can do, even if you have to look up exactly how.
PhilAScript826
@PhilAScript826
Apr 28 2017 03:45
@Manish-Giri Thanks!
CamperBot
@camperbot
Apr 28 2017 03:45
philascript826 sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 5321 | @manish-giri |http://www.freecodecamp.com/manish-giri
Alison Foss
@davyfones
Apr 28 2017 03:45
it's incredibly frustrating
Gabe Rotberg
@grotberg
Apr 28 2017 03:46
@davyfones remind me the name of the exercise? Let me go refresh my memory.
Manish Giri
@Manish-Giri
Apr 28 2017 03:46
@davyfones post your challenge URL here, click "run tests" first
Manish Giri
@Manish-Giri
Apr 28 2017 03:47
Change the provided string from double to single quotes and remove the escaping.
did you understand escaping?
Alison Foss
@davyfones
Apr 28 2017 03:48
i did that and it didn't work for me
Gabe Rotberg
@grotberg
Apr 28 2017 03:48
@davyfones aha! I steered you wrong, and I apologize. I didn't realize the html code was inside a string as well.
Manish Giri
@Manish-Giri
Apr 28 2017 03:48
well then show what you did
because your URL doesn't have it
Alison Foss
@davyfones
Apr 28 2017 03:49

var myStr = "<a href=\"http://www.example.com\" target=\"_blank\">Link</a>";

var myStr = "<a href='http://www.example.com' target='_blank'>Link</a>"

xemexpress
@xemexpress
Apr 28 2017 03:49
@moigithub ah! Yes! Thank you!!!!
CamperBot
@camperbot
Apr 28 2017 03:49
xemexpress sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3165 | @moigithub |http://www.freecodecamp.com/moigithub
Manish Giri
@Manish-Giri
Apr 28 2017 03:49
@davyfones put the single quotes outside
use double quotes inside
Alison Foss
@davyfones
Apr 28 2017 03:49
oh ok
Manish Giri
@Manish-Giri
Apr 28 2017 03:49
like the given example
'This string has "double quotes" in it. And "probably" lots of them.'
Alison Foss
@davyfones
Apr 28 2017 03:50
@Manish-Giri gotcha i reversed it. thanks so much!
CamperBot
@camperbot
Apr 28 2017 03:50
davyfones sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 5322 | @manish-giri |http://www.freecodecamp.com/manish-giri
Csaba Balogh
@JasonCorp84
Apr 28 2017 03:52
hello
Manish Giri
@Manish-Giri
Apr 28 2017 03:52
:+1:
Csaba Balogh
@JasonCorp84
Apr 28 2017 03:52
what is wrong with this?

function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (b = 0; b <multiplyAll.length; b++) {
for (i = 0; i < multiplyAll[b].length; i++)
product *= multiplyAll([b][i]);
}
// Only change code above this line
return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);

Manish Giri
@Manish-Giri
Apr 28 2017 03:54
@JasonCorp84 where are you using the array arr in all that?
jhobotuck
@jhobotuck
Apr 28 2017 03:56
Really thought I nailed this one but it is giving me 0 when returning longestWord
function findLongestWord(str) {

  var longestWord = 0;
  var lengthOfWord = 0;

  var stringSplit = str.split(" ");

  for (var i = 0; i >= stringSplit.length; i++) {

  lengthOfWord = stringSplit[i].length;

  if (lengthOfWord > longestWord) {
    longestWord = lengthOfWord;
  }

  }
  return longestWord;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
Any guidance appreciated!
Csaba Balogh
@JasonCorp84
Apr 28 2017 03:56
@Manish-Giri I am lost wth this one. Should I declare arr?
Gabe Rotberg
@grotberg
Apr 28 2017 03:57
@jhobotuck in your forstatement, check the conditional (the one in the middle)
Manish Giri
@Manish-Giri
Apr 28 2017 03:57
@JasonCorp84 it's already setup for you - function multiplyAll(arr) {
@JasonCorp84 what is the purpose of multipyAll here?
for (b = 0; b <multiplyAll.length; b++) {
for (i = 0; i < multiplyAll[b].length; i++)
product *= multiplyAll([b][i]);
Csaba Balogh
@JasonCorp84
Apr 28 2017 03:59
that should be the arr ?
when I used that I got an error
"arr is not a function"
Manish Giri
@Manish-Giri
Apr 28 2017 04:00
using arr is the first step
Erol Aliyev
@erolaliyev
Apr 28 2017 04:00
Hi guys. Can anybody explain me what a constructor function is? i've searched on internet. but couldn't understand
Csaba Balogh
@JasonCorp84
Apr 28 2017 04:01
@Manish-Giri thank you
CamperBot
@camperbot
Apr 28 2017 04:01
jasoncorp84 sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 5323 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Apr 28 2017 04:01
@erolaliyev think of it as the function to use to create objects of a given type..
PhilAScript826
@PhilAScript826
Apr 28 2017 04:01
need help with this one too

// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

function checkObj(checkProp) {
// Your Code Here
if (myObj.hasOwnProperty(checkProp) === true) {
return myObj.checkProp;
}
else{
return "Not Found";
}
}

// Test your code by modifying these values
checkObj("pet");

Manish Giri
@Manish-Giri
Apr 28 2017 04:01
@PhilAScript826 use bracket notation
jhobotuck
@jhobotuck
Apr 28 2017 04:02
@grotberg I struggle with conditionals. With this one I have returned stringSplit.length and get 9. Is it the operators?
Erol Aliyev
@erolaliyev
Apr 28 2017 04:02
@Manish-Giri yeah i get it. but i cant understand syntax
PhilAScript826
@PhilAScript826
Apr 28 2017 04:03
@Manish-Giri Where?
Manish Giri
@Manish-Giri
Apr 28 2017 04:04
@PhilAScript826 return myObj.checkProp;
fathurrahman alif fahrezi
@fathurrahmanaf
Apr 28 2017 04:04
hi, i am kind of confused with this command "i need to create an object with properties called 'PHONE' which contain my phone number, but i am confused that i need to enter the value of that properties as STRING." So, is this correct if i put it like this: var contact = { "phone" : 1234667788};
Gabe Rotberg
@grotberg
Apr 28 2017 04:04
@jhobotuck for this line for (var i = 0; i >= stringSplit.length; i++) { your conditional (i >= stringSplit.length) is telling the function to keep going as long as i is greater or equal to stringSplit.length. since i initialized to zero, it fails instantly and the code inside the loop doesn't get executed.
Csaba Balogh
@JasonCorp84
Apr 28 2017 04:04
for (var i=0; i < arr.length; i++){
for(var j=0; j < arr[i].length; j++) {
product *= arr[i][j];
}
}
Manish Giri
@Manish-Giri
Apr 28 2017 04:04
@fathurrahmanaf 1234667788 should be a string
so "1234667788"
Csaba Balogh
@JasonCorp84
Apr 28 2017 04:05
omg. I was able to do this but, I still do not understand the nested loops
Gabe Rotberg
@grotberg
Apr 28 2017 04:05
@jhobotuck instead, you want it to tell the loop to keep going as long as "i is less than stringSplit.length' (remember, array starts at 0, but length counts the first index as 1)
Csaba Balogh
@JasonCorp84
Apr 28 2017 04:05
is there any good explanation somewhere that I should watch ?
fathurrahman alif fahrezi
@fathurrahmanaf
Apr 28 2017 04:05
@Manish-Giri thx! i'll try it!
CamperBot
@camperbot
Apr 28 2017 04:05
fathurrahmanaf sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 5324 | @manish-giri |http://www.freecodecamp.com/manish-giri
jhobotuck
@jhobotuck
Apr 28 2017 04:06
Ahhh yeah. I looked up conditionals while I was waiting. I thought the loop executed as long the condition was true when it is the other way around. thanks @grotberg
CamperBot
@camperbot
Apr 28 2017 04:06
jhobotuck sends brownie points to @grotberg :sparkles: :thumbsup: :sparkles:
:cookie: 283 | @grotberg |http://www.freecodecamp.com/grotberg
Csaba Balogh
@JasonCorp84
Apr 28 2017 04:06
index 0 is the first one.
Manish Giri
@Manish-Giri
Apr 28 2017 04:07
go here and run your code
put a console.log statement before the product line
PhilAScript826
@PhilAScript826
Apr 28 2017 04:08
@Manish-Giri i tried it but it doesnt work, probably something im doing wrong, but why is that the case? I dont think i've used bracket notations for return before
Manish Giri
@Manish-Giri
Apr 28 2017 04:08
@PhilAScript826 show what you tried
Csaba Balogh
@JasonCorp84
Apr 28 2017 04:08
@Manish-Giri you are for president! Thanks again :)
CamperBot
@camperbot
Apr 28 2017 04:08
jasoncorp84 sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:warning: jasoncorp84 already gave manish-giri points
PhilAScript826
@PhilAScript826
Apr 28 2017 04:08
@Manish-Giri return [myObj.checkProp];
Manish Giri
@Manish-Giri
Apr 28 2017 04:09
@JasonCorp84 lol, welcome!
@PhilAScript826 you sure that's the right syntax?
isn't there an example on the page?
rebeccatay92
@rebeccatay92
Apr 28 2017 04:10

Hello, Im working on the look-up table exercise. Can someone explain why the below doesn't run?

// Setup
function phoneticLookup(val) {
var result = "";

// Only change code below this line
val = {
"alpha": "Adams",
"bravo": "Boston",
"charlie": "Chicago",
"delta" : "Denver",
"echo" : "Easy",
"foxtrot": "Frank"
};

// Only change code above this line
return result;
}

// Change this value to test
phoneticLookup("charlie");

PhilAScript826
@PhilAScript826
Apr 28 2017 04:10
@Manish-Giri yeah thats what you said to put brackets around no?
Manish Giri
@Manish-Giri
Apr 28 2017 04:11
@PhilAScript826 I said use "bracket notation"
not the same as putting [ ] around
see this
@rebeccatay92 name this object something else
 {
"alpha": "Adams",
"bravo": "Boston",
"charlie": "Chicago",
"delta" : "Denver",
"echo" : "Easy",
"foxtrot": "Frank"
};
like lookup
PhilAScript826
@PhilAScript826
Apr 28 2017 04:13
@Manish-Giri yup your right lol had my slow moment. thanks!
CamperBot
@camperbot
Apr 28 2017 04:13
philascript826 sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:warning: philascript826 already gave manish-giri points
jhobotuck
@jhobotuck
Apr 28 2017 04:19
Okay I sorted the conditional now I am having trouble with the loop getting a "TypeError: Cannot read property "length" is undefined"
function findLongestWord(str) {

  var longestWord = 0;
  var lengthOfWord = 0;
  var stringFromArray = "";

  var stringSplit = str.split(" ");

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

  lengthOfWord = stringSplit[i].length;

  if (lengthOfWord >= longestWord) {
    longestWord = lengthOfWord;
  }

  }
  return longestWord;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
Manish Giri
@Manish-Giri
Apr 28 2017 04:22
@jhobotuck this is wrong
var i = 0; i <= stringSplit.length
if you start at 0
you'll only go upto stringSplit.length -1
rebeccatay92
@rebeccatay92
Apr 28 2017 04:24
Oh great, it returns properly now.
thanks @Manish-Giri
CamperBot
@camperbot
Apr 28 2017 04:24
rebeccatay92 sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 5325 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Apr 28 2017 04:24
@rebeccatay92 :+1:
jhobotuck
@jhobotuck
Apr 28 2017 04:24
Removed the equal sign and everything passed. Thanks @Manish-Giri!
CamperBot
@camperbot
Apr 28 2017 04:24
jhobotuck sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 5326 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Apr 28 2017 04:25
:+1:
jhobotuck
@jhobotuck
Apr 28 2017 04:25
Not sure why it worked but yeah
Or why it gave me error. Oh well. Much to learn.
Csaba Balogh
@JasonCorp84
Apr 28 2017 04:26
sry
I had no clue this will cover an entire page
john g
@jgwould
Apr 28 2017 04:31
Confused with
var myStr;
myStr= "FirstLine \n \\ \SecondLine\ \\ \r ThirdLine"; // Change this line
"Escape sequences in a string" Getting the error message: myStr should have encoded text with the proper escape sequences and no spacing.
Sergey Lukin
@not-a-cylon
Apr 28 2017 04:31
@jgwould you might not need the spaces.
john g
@jgwould
Apr 28 2017 04:32
ok
not it
Sergey Lukin
@not-a-cylon
Apr 28 2017 04:34

@jgwould every time you stick a standalone \ in your string, JS will try to interpret whatever comes after it as a special character. Which \S should not be.

Print whatever you have to the console and compare to what they're looking for.

john g
@jgwould
Apr 28 2017 04:35
ok
confusing problem
Moisés Man
@moigithub
Apr 28 2017 04:36
newline is this \n
backslash is this \\
soo WHY u have 2 extra \
john g
@jgwould
Apr 28 2017 04:36
because Im learning
Sergey Lukin
@not-a-cylon
Apr 28 2017 04:37
:+1:
Moisés Man
@moigithub
Apr 28 2017 04:37

from instructions

Here is the text with the escape sequences written out.

FirstLinenewlinebackslashSecondLinebackslashcarriage-returnThirdLine

john g
@jgwould
Apr 28 2017 04:38
var myStr="FirstLine\n\\SecondLine\\\rThirdLine"
got it
FirstLine
\SecondLine\
ThirdLine
That was confusing about it^ and the reason I had extra "\"
Victoria Zambrano
@vzambrano98
Apr 28 2017 04:53
Hey guys, hoping everyone is doing well :smile: I was wondering if anyone could chat for a sec about using anchor links and how to populate the href with a variable. I can't just write the variable in html....I tried just putting .html(all the stuff) with everything the anchor needed to have, but that was a no go. any thoughts or pointers?
jhobotuck
@jhobotuck
Apr 28 2017 04:55

I don't get it. I'm passing all the tests in "Title Case a Sentence" but am not earning the tick on the objective.

```

Here is the code.
function titleCase(str) {

  var stringFromArray = "";
  var capitalBegin = "";
  var lowerWord = "";
  var newStr = "";

  var splitString = str.split(" ");


  for (var i = 0; i < splitString.length; i++) {
    stringFromArray = splitString[i];
    capitalBegin = stringFromArray[0].toUpperCase();
    lowerWord = stringFromArray.slice(1, stringFromArray.length).toLowerCase();
    newStr += capitalBegin + lowerWord + " "; 
  }

  return newStr;
}

titleCase("Short And Stout");
Long Nguyen
@longnt80
Apr 28 2017 04:56
@jhobotuck
close FreeCodeCamp tab, reopen then try again
jhobotuck
@jhobotuck
Apr 28 2017 04:57
Just tried it. No luck.
Long Nguyen
@longnt80
Apr 28 2017 04:57
@jhobotuck
maybe close the browser
jhobotuck
@jhobotuck
Apr 28 2017 04:59
@longnt80 Again no luck.
Report a bug?
Long Nguyen
@longnt80
Apr 28 2017 04:59
@vzambrano98
not sure if I can help but maybe you can give us an example, maybe others can see and help you
@jhobotuck
the alert box just keep loading right?
@jhobotuck
jhobotuck
@jhobotuck
Apr 28 2017 05:01
The alert box?
Victoria Zambrano
@vzambrano98
Apr 28 2017 05:01
@longnt80 haha no it's all good, I'm just working on the quote machine and i just have no idea why I'm struggling with the tweet button so much. I'm just not sure how to put the content of the actual quote into the text portion of the link
David Miller
@DavidMillerFL
Apr 28 2017 05:01
I feel like I’ll never be a programer because all these algorithm challenges so far required me to google the solutions :-/
Long Nguyen
@longnt80
Apr 28 2017 05:03

@jhobotuck

The alert box?

alt

Victoria Zambrano
@vzambrano98
Apr 28 2017 05:04
@DavidMillerFL Don't feel so down. Coding is really really hard. If you really push and come in here and ask for help and learn something from the answers, or you find what you need from google but you still learn something from then i say it was well worth it.
jhobotuck
@jhobotuck
Apr 28 2017 05:05
Yeah my problem isn't not getting the alert box but not gaining the green ticks next to the objectives despite my code filfulling the criteria (or at least from what I can gather).
Long Nguyen
@longnt80
Apr 28 2017 05:05
@DavidMillerFL
don't try to search for the solution, maybe try to search for the hint
you can come here for the hints
@jhobotuck
I see, never have that problem. Maybe report a bug
Victoria Zambrano
@vzambrano98
Apr 28 2017 05:06
@DavidMillerFL @longnt80 is definitely right :+1:
David Miller
@DavidMillerFL
Apr 28 2017 05:07
@vzambrano98 I guess that’s true. I just want the satisfaction of ‘figuring it out’ entirely on my own ya know. Granted I’ve only been learning JS for like a little over 2 weeks @longnt80 And yes sometimes I do get hints… but when I have a general idea of what it is I want to do, I have to ask for an actual code to figure it out lol
Long Nguyen
@longnt80
Apr 28 2017 05:07
@jhobotuck did you try to complete the challenge again?
Jason Luboff
@JLuboff
Apr 28 2017 05:08
@jhobotuck you're adding a space to the end that's why it's passing. Try return newStr.trim();
It's not*
hsumo
@hsumo
Apr 28 2017 05:09
does .indexOf search for the whole string or each letter of the string?
Long Nguyen
@longnt80
Apr 28 2017 05:09
@DavidMillerFL
that means you didn't grasp the basic concept in earlier challenges/lessons, you should go back and read more about the concept
I found w3school is a good start
@JLuboff
then how can he passed all the test of the challenge?
David Miller
@DavidMillerFL
Apr 28 2017 05:10
@longnt80 Yeah I kind of feel that’s my problem. I guess I’m trying to rush through it and learn programming as fast as possible, but I clearly need to take my time here.
Jason Luboff
@JLuboff
Apr 28 2017 05:10
He isn't passing them hence why he hasn't gotten the alert
Victoria Zambrano
@vzambrano98
Apr 28 2017 05:11
@DavidMillerFL two weeks?!?!? Oh haha! you're already doing so much though. Don't stress, try and do more research and less looking at the answers. feel free to slap your code up in here and let people help you pick it apart use all your resources. What really helped me with algorithms is pythontutor.com
you can visualize your code in there and see where it's breaking etc.
Jordi Hereu
@jhereu
Apr 28 2017 05:11
@hsumo what do you mean? indexOf looks for any substring inside the provided array
David Miller
@DavidMillerFL
Apr 28 2017 05:13
@vzambrano98 Thanks! Appreciate the replies. Pythontutor.com, I don’t suppose that’s for javascript, huh
CamperBot
@camperbot
Apr 28 2017 05:13
davidmillerfl sends brownie points to @vzambrano98 :sparkles: :thumbsup: :sparkles:
:cookie: 295 | @vzambrano98 |http://www.freecodecamp.com/vzambrano98
hsumo
@hsumo
Apr 28 2017 05:14
@JHereu just doing the mutations algorithm challenge and having trouble with mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"]) should return true.
@JHereu qrstu is reversed in the string
Markus Kiili
@Masd925
Apr 28 2017 05:15
@hsumo String indexOf method looks for a substring, and array indexOf looks for an element.
Long Nguyen
@longnt80
Apr 28 2017 05:16
@hsumo
indexOf only return the first result it can find
Victoria Zambrano
@vzambrano98
Apr 28 2017 05:16
@DavidMillerFL it was created for python but it definitely does do javascript, and more :)
Markus Kiili
@Masd925
Apr 28 2017 05:17
@hsumo Are you looping the second string characters?
Long Nguyen
@longnt80
Apr 28 2017 05:17
@hsumo
you need to use it in a loop to search through the whole string
hsumo
@hsumo
Apr 28 2017 05:17
@longnt80 @Masd925 ah i see
@longnt80 @Masd925 yeah i haven't looped it yet
function mutation(arr) {


 if (arr[0].toLowerCase().indexOf(arr[1].toLowerCase()) !== -1) {return true;} else {
   return false;}
}

mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"])
David Miller
@DavidMillerFL
Apr 28 2017 05:18
@vzambrano98 Hmm I’m going to do Code Academy’s JS course, restart FCC’s section on JS, Lyndas, and I’ll check out pythontutor.com
Victoria Zambrano
@vzambrano98
Apr 28 2017 05:18
@DavidMillerFL happy coding :)
Long Nguyen
@longnt80
Apr 28 2017 05:19
@hsumo
yeah, use a loop now
Jordi Hereu
@jhereu
Apr 28 2017 05:19
@hsumo yea it returns true cause qrstu is inside the looong string (reversed). If you execute longString.reverse().indexOf(shortString) > -1, you have a predicate for the function. With this exemple you provided, it is true
Markus Kiili
@Masd925
Apr 28 2017 05:19
@hsumo You have the logic, but you need to check each letter.
hsumo
@hsumo
Apr 28 2017 05:20
@JHereu @Masd925 gotcha, thanks for the help guys
CamperBot
@camperbot
Apr 28 2017 05:20
hsumo sends brownie points to @jhereu and @masd925 :sparkles: :thumbsup: :sparkles:
:cookie: 3 | @jhereu |http://www.freecodecamp.com/jhereu
:star2: 3955 | @masd925 |http://www.freecodecamp.com/masd925
Deryck Austin
@Deryckaus
Apr 28 2017 05:23
Hi all, i cant get this to work,, any ideas please?

function titleCase(str) {
  var words = str.toLowerCase().split(" ");
  for (var i = 0; i < words.length; i++) {
      var letters = words[i].split("");
      letters[0] = letters[0].toUpperCase();
      words[i] = letters.join("  ");
      }

  return words.join(" ");
}
titleCase("I'm a little tea pot");
Markus Kiili
@Masd925
Apr 28 2017 05:26
@Deryckaus Join letters by (""), not (" ")
@Deryckaus Strings were invented to not have to fiddle with character arrays. So you could use string operations for making the titlecased word.
Deryck Austin
@Deryckaus
Apr 28 2017 05:34
@Masd925 Thanks , but didnt work!
CamperBot
@camperbot
Apr 28 2017 05:34
deryckaus sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 3956 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Apr 28 2017 05:35
@Deryckaus You also have two spaces on the second join.
Works if you fix the join arguments.
Mark Mascarenhas
@Freedom41
Apr 28 2017 05:49
guys i am stuck in palindrome

here is my code ``` function palindrome(str) {

var a = str.replace(/[@#₹&£€$¢^°={}\%""''®™℅©~`•√π÷׶∆_(/)/:/-||,.]/g, "" );

var b= a.toLowerCase();
var c = a.toLowerCase();

var d = (b == c) ? false: true;

return d;

}

palindrome("Eyπ÷():e");
```

Vamp
@the-vampiire
Apr 28 2017 05:50
function palindrome(str) {
var a = str.replace(/[@#₹&£€$¢^°={}\%""''®™℅©~`•√π÷׶∆_(/)/:/-||,.]/g, "" );
var b= a.toLowerCase();
var c = a.toLowerCase();
var d = (b == c) ? false: true;
return d;
}
palindrome("Eyπ÷():e");
Mark Mascarenhas
@Freedom41
Apr 28 2017 05:50
i am getting both true and false but not at the same time
Markus Kiili
@Masd925
Apr 28 2017 05:50
@Freedom41 There is a regex metacharacter for alphanumeric characters. Look at \w and \W.
Vamp
@the-vampiire
Apr 28 2017 05:51
jesus that regex tho
dudes got the root, register, trademark, and copywrite hah. impressive. ya listen to Markus
Markus Kiili
@Masd925
Apr 28 2017 05:52
@Freedom41 You also need to figure out some algorithm for the palindromicality check. Just comparing the string with itself is not good.
Vamp
@the-vampiire
Apr 28 2017 05:53
@Freedom41 by definition isn’t b always going to === c?
Mark Mascarenhas
@Freedom41
Apr 28 2017 05:54
oh ok ill try to figure it out and see if it works
thanks @Masd925 and @the-vampiire
CamperBot
@camperbot
Apr 28 2017 05:54
freedom41 sends brownie points to @masd925 and @the-vampiire :sparkles: :thumbsup: :sparkles:
:cookie: 318 | @the-vampiire |http://www.freecodecamp.com/the-vampiire
:star2: 3957 | @masd925 |http://www.freecodecamp.com/masd925
Vamp
@the-vampiire
Apr 28 2017 05:54
you have defined both variables the same way
Dan Couper
@DanCouper
Apr 28 2017 05:54
@Freedom41 b and c are exactly the same, so d is always false, and so the function just returns false for everything.
ah snap
Mark Mascarenhas
@Freedom41
Apr 28 2017 05:55
ok ill see to that thanks @DanCouper
CamperBot
@camperbot
Apr 28 2017 05:55
freedom41 sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:cookie: 664 | @dancouper |http://www.freecodecamp.com/dancouper
Vamp
@the-vampiire
Apr 28 2017 05:55
@Freedom41 you have a couple of options. the simplest of which would be to split the string into an array so that you can use the handy array method ‘reverse’ then join back for comparison
Jordi Hereu
@jhereu
Apr 28 2017 05:56
Also @Freedom41 its redundant to use a ternary operator to return a boolean, as the predicate is already a boolean. You can just do:
d = (b!=c)
Vamp
@the-vampiire
Apr 28 2017 05:57
ex:
var a = string;
var b = string.split(‘’).reverse().join(‘'); // [’s’, ’t’, ‘r’, ‘i’, ’n’, ‘g’] —> [‘g’, ’n’, ‘i’, ‘r’, ’t’, ’s’] —> ‘gnirts'
Mark Mascarenhas
@Freedom41
Apr 28 2017 05:57
ok I'll try it as well...... I'll try that too thanks @JHereu
CamperBot
@camperbot
Apr 28 2017 05:57
freedom41 sends brownie points to @jhereu :sparkles: :thumbsup: :sparkles:
:cookie: 4 | @jhereu |http://www.freecodecamp.com/jhereu
Vamp
@the-vampiire
Apr 28 2017 05:58
@JHereu even simpler return b === c
Mark Mascarenhas
@Freedom41
Apr 28 2017 05:58
ok ill try the reverse method off i go thanks @the-vampiire
CamperBot
@camperbot
Apr 28 2017 05:58
freedom41 sends brownie points to @the-vampiire :sparkles: :thumbsup: :sparkles:
:warning: freedom41 already gave the-vampiire points
Vamp
@the-vampiire
Apr 28 2017 05:58
if true // true if false // false
skip the additional variable and test. all you care is to return true or false anyways
Markus Kiili
@Masd925
Apr 28 2017 05:59
@the-vampiire Only problem with that algorithm is that it is very slow on long strings. You could use array iterator or a loop for a solution that stops early (usually comparing the first and last characters gives the result etc).
Vamp
@the-vampiire
Apr 28 2017 06:00
meh
i dont think you will notice that speed
Jordi Hereu
@jhereu
Apr 28 2017 06:00
@the-vampiire Nice, i was focusing on this line only. The less lines the better 😁
Vamp
@the-vampiire
Apr 28 2017 06:00
you can have a recursive function that tests the outer 2, slices them off, compares the next 2 and so forth
Markus Kiili
@Masd925
Apr 28 2017 06:02
@the-vampiire Yes, there are many elegant efficient algorithms too.
Vamp
@the-vampiire
Apr 28 2017 06:02
the only way to know for sure is to get to the center character by testing all outers
Markus Kiili
@Masd925
Apr 28 2017 06:02
But you can stop early if there is a mismatch. That is the main difference.
Vamp
@the-vampiire
Apr 28 2017 06:03
function is_palindrome(str){
   // optional regex filter 
    return str === str.split(‘’).reverse().join(‘’);
}
yes thats true. I would be curious on the performance differences. I thnk they would be negligible unless youre talking full books worth of palindrome checks. at which point you have to ask yourself who the fuck wrote a book lengthed palindrome and why are they asking you to test it
lol
Long Nguyen
@longnt80
Apr 28 2017 06:05

hey guys, I'm working on Show Local Weather challenge. However, Chrome won't get the geolocation from codepen since it's not https
here's the error:

getCurrentPosition() and watchPosition() no longer work on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See https://goo.gl/rStTGz for more details.

How do I fix this?

Vamp
@the-vampiire
Apr 28 2017 06:06
CamperBot
@camperbot
Apr 28 2017 06:06
:cookie: 198 | @longnt80 |http://www.freecodecamp.com/longnt80
:star2: 1214 | @skycoder01 |http://www.freecodecamp.com/skycoder01
the-vampiire sends brownie points to @longnt80 and @skycoder01 :sparkles: :thumbsup: :sparkles:
Vamp
@the-vampiire
Apr 28 2017 06:06
give him a thanks as well.
Long Nguyen
@longnt80
Apr 28 2017 06:06
haha @the-vampiire thanks man
CamperBot
@camperbot
Apr 28 2017 06:06
longnt80 sends brownie points to @the-vampiire :sparkles: :thumbsup: :sparkles:
:cookie: 319 | @the-vampiire |http://www.freecodecamp.com/the-vampiire
Vamp
@the-vampiire
Apr 28 2017 06:07
no do not thank me
David Miller
@DavidMillerFL
Apr 28 2017 06:07
Is there a way to reset my javascript progress without creating a new acc on FCC?
Vamp
@the-vampiire
Apr 28 2017 06:07
thank @SkyCoder01
CamperBot
@camperbot
Apr 28 2017 06:07
the-vampiire sends brownie points to @skycoder01 :sparkles: :thumbsup: :sparkles:
:warning: the-vampiire already gave skycoder01 points
Vamp
@the-vampiire
Apr 28 2017 06:07
I didnt write it, he did and shared with me.
Long Nguyen
@longnt80
Apr 28 2017 06:08
ok thank you @SkyCoder01
:+1: :smile:
CamperBot
@camperbot
Apr 28 2017 06:08
longnt80 sends brownie points to @skycoder01 :sparkles: :thumbsup: :sparkles:
:star2: 1215 | @skycoder01 |http://www.freecodecamp.com/skycoder01
Vamp
@the-vampiire
Apr 28 2017 06:08
@DavidMillerFL I dont think so…why? technically you could go through each challenge and delete it then submit..
@longnt80 it is now your duty to bookmark that page and share it the next tim you see someone ask this question, and of course credit sky and demand he be thanked. saved me a lot of headache
David Miller
@DavidMillerFL
Apr 28 2017 06:09
I know I could do that but it would take a while and be tedious, I was hoping for a way to reset my progress with just a few clicks. I want to re-take JS section of the course so I grasp it and understand it better. I feel like I went too quick. @the-vampiire
Long Nguyen
@longnt80
Apr 28 2017 06:09
@the-vampiire
:+1:
Vamp
@the-vampiire
Apr 28 2017 06:09
@DavidMillerFL you can just start on challenge 1 and repeat it
nothing stops you from doing that. if youre starting t the beginning it wont matter if they are all green you are going through each one anyway
David Miller
@DavidMillerFL
Apr 28 2017 06:10
But when I open it, the solution would be there in front of my face, no ? @the-vampiire I don’t wanna see it lol.
Vamp
@the-vampiire
Apr 28 2017 06:10
ah
okay I will help you
Long Nguyen
@longnt80
Apr 28 2017 06:10
@DavidMillerFL
you don't have to, just go back and read it again and do more research on those concepts
Vamp
@the-vampiire
Apr 28 2017 06:10
now with even more challenges, all fresh and shiny with your name on it :)
David Miller
@DavidMillerFL
Apr 28 2017 06:10
@the-vampiire Hmm, let me take a look
Deryck Austin
@Deryckaus
Apr 28 2017 06:11
@Masd925 @Masd925 Thanks
CamperBot
@camperbot
Apr 28 2017 06:11
deryckaus sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: deryckaus already gave masd925 points
Vamp
@the-vampiire
Apr 28 2017 06:11
same original challenges with a bunch of new bits added in. and your progress is 0. learn your heart out
David Miller
@DavidMillerFL
Apr 28 2017 06:12
@the-vampiire Well this is good… but, what is it ? Is this different than the FCC I’ve been using?
Vamp
@the-vampiire
Apr 28 2017 06:12
its their beta page
to test out new challenges
basically its a secret treasure chest with all new challenges
David Miller
@DavidMillerFL
Apr 28 2017 06:13
Ah cool, so then those new challenges get added to the main site after passing the tests. Thanks! @the-vampiire
CamperBot
@camperbot
Apr 28 2017 06:13
davidmillerfl sends brownie points to @the-vampiire :sparkles: :thumbsup: :sparkles:
:cookie: 320 | @the-vampiire |http://www.freecodecamp.com/the-vampiire
Vamp
@the-vampiire
Apr 28 2017 06:13
as you use it be sure to give them suggestions to improve things
yes be ware - your progress is not merged
no word yet on whether it will be merged when the beta goes live or not.
so if youve been hoarding your brownie points to show off to the nonexistant people who care you may lose them
David Miller
@DavidMillerFL
Apr 28 2017 06:15
That’s ok, once I finish the Basic Javascript section, I’ll just switch back to my old account
Markus Kiili
@Masd925
Apr 28 2017 06:15
@the-vampiire Palindromicality check loop solution is around 30x faster than the reverse solution on short sentences. With array iterator solutions, the difference between reverse and a solution that stops early (using every for example) is around 2-3x faster. For longer strings the difference gets bigger.
Long Nguyen
@longnt80
Apr 28 2017 06:17
@Masd925
this is way more advanced for the people working on that challenge
Vamp
@the-vampiire
Apr 28 2017 06:17
@Masd925 neat thanks. what did you use to get those figures? I have been looking for a way to test the efficiency of some of my algorithms
CamperBot
@camperbot
Apr 28 2017 06:17
the-vampiire sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 3958 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Apr 28 2017 06:18
@the-vampiire I use a browser and sometimes https://jsperf.com/
Vamp
@the-vampiire
Apr 28 2017 06:18
how do you test in browser?
Prabakaran V
@PrabakaranVR
Apr 28 2017 06:19
can anyone help out?

function largestOfFour(arr) {
// You can do this!
var largN = 0;
for (var i=0; i< arr.length; i++){
for (var j=0; j < arr[i]; arr[i]++){
if (arr[j]>largN){
largN = arr[j];
}
}
}
return largN;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

Markus Kiili
@Masd925
Apr 28 2017 06:20
@the-vampiire You can make a basic html page and javascript file there that has something like this that prints to the console:
Vamp
@the-vampiire
Apr 28 2017 06:20
and can you post your code for comparison? I understand the concept I think but I have not ever written a palindrome checker that way
Markus Kiili
@Masd925
Apr 28 2017 06:20
    var times = 1000;

    var start = new Date().getTime();

    for (var i = 0; i < times; ++i) {
        // code to be tested
    }

    var end = new Date().getTime();
    var time = end - start;
    console.log("Executed code " + times + " times");
    console.log('Execution time: ' + time);
    console.log("Average time per execution: " + time/times);
Vamp
@the-vampiire
Apr 28 2017 06:20
ah I see. was about to ask if yo just build a simple front end shell for it
@PrabakaranVR

function largestOfFour(arr) {
  // You can do this!
  var largN = 0;
  for (var i=0; i< arr.length; i++){
    for (var j=0; j < arr[i]; arr[i]++){
      if (arr[j]>largN){
        largN = arr[j];
      }
    }
  }  
  return largN;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Markus Kiili
@Masd925
Apr 28 2017 06:21
@the-vampiire That is good for a quick test and for reliable results jsperf is good.
Vamp
@the-vampiire
Apr 28 2017 06:22
@PrabakaranVR are the yasking for the largest value across all 4 arrays or for an array of the largest values from each array?
just checked, it’s the latter
Prabakaran V
@PrabakaranVR
Apr 28 2017 06:24
@the-vampiire need to get largest number from each array for 'Return Largest Numbers in Arrays' challenge .
Vamp
@the-vampiire
Apr 28 2017 06:24
ya
for (var i=0; i< arr.length; i++){
    for (var j=0; j < arr[i]; arr[i]++)
this is no good
you are comparing j to the value of arr[i], an array, and your incrementor is incrementing arr[i], an array
these are not valid expressions
have you learned the array method, sort()?
David Miller
@DavidMillerFL
Apr 28 2017 06:29
Assignment always goes from right to left. Everything to the right of the = operator is resolved before the value is assigned to the variable to the left of the operator.
Prabakaran V
@PrabakaranVR
Apr 28 2017 06:29
yeah i have, should i use sort()?
David Miller
@DavidMillerFL
Apr 28 2017 06:29
This doesn’t mean it solves things from left to right, like math problems, does it?
It just solves the math problem first before assigning it
Markus Kiili
@Masd925
Apr 28 2017 06:30
@PrabakaranVR You can make that work if you initialize the variable for each subarray and then assign it back to the array after the inner loop.
Vamp
@the-vampiire
Apr 28 2017 06:30
here are some things to look up:
1) how for loops work (initial expression, condition, increment expression)
2) array method push() [I would suggest learning all 4 ‘movement’ array methods, push(), unshift(), pop(), shift()]
3) array method sort()
Markus Kiili
@Masd925
Apr 28 2017 06:31
@PrabakaranVR Finding a way to use Math.max is much better than using sort.
Prabakaran V
@PrabakaranVR
Apr 28 2017 06:31
@the-vampiire okay, thank you!
CamperBot
@camperbot
Apr 28 2017 06:31
prabakaranvr sends brownie points to @the-vampiire :sparkles: :thumbsup: :sparkles:
:cookie: 321 | @the-vampiire |http://www.freecodecamp.com/the-vampiire
Vamp
@the-vampiire
Apr 28 2017 06:31
better performance @Masd925 ?
Prabakaran V
@PrabakaranVR
Apr 28 2017 06:31
@Masd925 thanks!
CamperBot
@camperbot
Apr 28 2017 06:31
prabakaranvr sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 3959 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Apr 28 2017 06:32
@the-vampiire Simpler also.
Vamp
@the-vampiire
Apr 28 2017 06:32
@PrabakaranVR sure, in fact you can also tack on splice and slice methods as well if you want to learn about all the movements.
@Masd925 maybe in this case just to get the max of the array but there are quite a few challenges and algos that are made easier by having elements in order
max wont do much for you there, no?
Markus Kiili
@Masd925
Apr 28 2017 06:34
@the-vampiire You can use Math.max for getting the maximum value of each subarray. Usually sort is to be avoided if you don't need the sorted array later.
Vamp
@the-vampiire
Apr 28 2017 06:36
I see
Im curious though how does math max work? it has to do some sort of sorting or indexing of values no?
largest.push(arr.sort( // small to big).pop())
largest.push(Math.max(arr))
it must be combining sort and pop / shift
err thats no good
math max has to be used in reduce for an array
Vamp
@the-vampiire
Apr 28 2017 06:41
now I’m curious. but not curious and awake enough to make a test case. I would think
largest.push(arr.sort(function(a,b){return a-b;}).pop());

// may be faster than

largest.push(arr.reduce(function(a,b){return Math.max(a,b);}));
Markus Kiili
@Masd925
Apr 28 2017 06:42
@the-vampiire I meant using Math.max.apply(null,innerArray)
But reduce should be faster than using sort too.
307590317
@307590317
Apr 28 2017 06:46
@Masd925 I find it!
Vamp
@the-vampiire
Apr 28 2017 06:46
@Masd925 very strange…must be making a mistake somewhere I’m tired lol
var arr = [1, 3, 12];

console.log(arr.sort(function(a,b){return a-b;}).pop()); // 12

console.log(arr.reduce(function(a,b,c){return Math.max(a,b,c);})); // 3..?

function getMaxOfArray(numArray) {
    return Math.max.apply(null, numArray);
}

console.log(getMaxOfArray(arr)); // 3..?
(a,b,c) because (a,b) was also returning 3...
Jor
@joreyesl
Apr 28 2017 06:48
@the-vampiire you used .pop() earlier, when you go are reduce arr, it now only has [1,3]
Vamp
@the-vampiire
Apr 28 2017 06:49
ah of course
yep that was it
tired eyes
Markus Kiili
@Masd925
Apr 28 2017 06:49
@the-vampiire Internally Math.max just compares the first two arguments and then the larger with the next etc. So it is a loop like @PrabakaranVR was using there.
Vamp
@the-vampiire
Apr 28 2017 06:52
alright im off to bed boys. goodnight thanks for the benchmark tip @Masd925
CamperBot
@camperbot
Apr 28 2017 06:52
the-vampiire sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: the-vampiire already gave masd925 points
Vamp
@the-vampiire
Apr 28 2017 06:52
@joreyesl thanks for catching my mistake
Markus Kiili
@Masd925
Apr 28 2017 06:52
@the-vampiire Bye.
fathurrahman alif fahrezi
@fathurrahmanaf
Apr 28 2017 06:54

var full_name = "John Doe";

var contact = {
"phone" : "11212121212",
"email" : "xxxxxx@gmail.com"
};

console.log("First name:", full_name,". Phone:", contact[0],". Email:", contact[1]);


can someone please tell me how to show the phone & email properties?

Markus Kiili
@Masd925
Apr 28 2017 06:55
var contact = {
"phone" : "11212121212",
"email" : "xxxxxx@gmail.com"
};

contact.phone; // '11212121212'
@fathurrahmanaf
fathurrahman alif fahrezi
@fathurrahmanaf
Apr 28 2017 06:56
@Masd925 thank you very much!!!
CamperBot
@camperbot
Apr 28 2017 06:56
fathurrahmanaf sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 3960 | @masd925 |http://www.freecodecamp.com/masd925
Ramana reddy MV
@Ramanareddymv
Apr 28 2017 06:58
image.png
hel me
Sergey Lukin
@not-a-cylon
Apr 28 2017 06:59
@Ramanareddymv match what the result says. Or are you confused about how special characters work?
sunny
@sunshinehelloworld
Apr 28 2017 07:00
http://www.freecodecamp.cn/challenges/profile-lookup#?solution=%2F%2FSetup%0Avar%20contacts%20%3D%20%5B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Akira%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Laine%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220543236543%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Pizza%22%2C%20%22Coding%22%2C%20%22Brownie%20Points%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Harry%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Potter%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220994372684%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Hogwarts%22%2C%20%22Magic%22%2C%20%22Hagrid%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Sherlock%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Holmes%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220487345643%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Intriguing%20Cases%22%2C%20%22Violin%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Kristian%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Vos%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%22unknown%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Javascript%22%2C%20%22Gaming%22%2C%20%22Foxes%22%5D%0A%20%20%20%20%7D%0A%5D%3B%0A%0A%0Afunction%20lookUp(firstName%2C%20prop)%7B%0A%2F%2F%20Only%20change%20code%20below%20this%20line%0Afor(var%20i%20%3D%200%3B%20i%20%3C%20contacts.length%3B%20i%2B%2B%20)%7B%0A%20%20if(contacts%5Bi%5D%5B%22firstName%22%5D%20%3D%3D%20firstName%20%26%26%20contacts%5Bi%5D.hasOwnProperty(prop))%7B%0A%20%20%20%20return%20contacts%5Bi%5D%5Bprop%5D%3B%0A%20%20%7D%20else%20if(contacts%5Bi%5D%5B%22firstName%22%5D%20!%3D%20firstName)%20%7B%0A%20%20%20%20return%20%22No%20such%20contact%22%3B%0A%20%20%7D%20else%20if(!contacts%5Bi%5D.hasOwnProperty(prop))%20%7B%0A%20%20%20%20return%20%22No%20such%20property%22%3B%0A%20%20%7D%0A%7D%0A%2F%2F%20Only%20change%20code%20above%20this%20line%0A%7D%0A%0A%2F%2F%20Change%20these%20values%20to%20test%20your%20function%0AlookUp(%22Kristian%22%2C%20%22lastName%22)%3B where is wrong?
Ramana reddy MV
@Ramanareddymv
Apr 28 2017 07:00
the result not matched @not-a-cylon @not-a-cylon
Sergey Lukin
@not-a-cylon
Apr 28 2017 07:01
right, @Ramanareddymv , change it to match the result :P
Vishal Singhania
@vishal090
Apr 28 2017 07:01
Hi guys..I am stuck with the MadLibs exercise under the Basic Javascript section. Is there anyone who could help me out in explaining the approach that I shoud take?
Sergey Lukin
@not-a-cylon
Apr 28 2017 07:01
you can console.log() it to see what you have so far.
@vishal090 what does your code look like so far?
zxyango
@zxyango
Apr 28 2017 07:02
what's the mean myStr should have encoded text with the proper escape sequences and no spacing.
@vishal090
Vishal Singhania
@vishal090
Apr 28 2017 07:04

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "";
// Your code below this line

result = wordBlanks.myAdjective() + wordBlanks.myNoun() + wordBlanks.myVerb() + wordBlanks.myAdverb();
// Your code above this line
return result;
}

// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");

It throws an error wordBlanks.myAdjective() is not a function
Markus Kiili
@Masd925
Apr 28 2017 07:05
@vishal090 Just use the parameters myNoun, myAdjective, myVerb, myAdverb in the code. not wordBlanks.myAdjective().
On that function call, myNoun would hold dog etc.
By using the parameter, you make the function work with any passed words.
Sergey Lukin
@not-a-cylon
Apr 28 2017 07:06
@vishal090 cuz stuff() tells the compiler run a function called stuff. Referencing variables doesn't use ().
Abhishek Saini
@sainiabhi
Apr 28 2017 07:06
//Factorial

function factorial(n) {
  if (n === 0) {
    return 1;
  }

  // This is it! Recursion!!
  return n * factorial(n - 1);
}

document.write("Factorial is : " + factorial(5));

Can anyone explain me step by step how it is working?

Or any reference from where I can check how it is working

Markus Kiili
@Masd925
Apr 28 2017 07:07
@sainiabhi You can put a console.log(n); at the start of the function and check what the console shows.
Sergey Lukin
@not-a-cylon
Apr 28 2017 07:08
:+1:
Markus Kiili
@Masd925
Apr 28 2017 07:08
@sainiabhi For example factorial(3); evaluates to 3*factorial(2) which evaluates to 3*2*factorial(1) which evaluates to 3*2*1*factorial(0) which evaluates to 3*2*1*1 which evaluates to 6.
Abhishek Saini
@sainiabhi
Apr 28 2017 07:09
@Masd925 thanks :)
CamperBot
@camperbot
Apr 28 2017 07:09
sainiabhi sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 3961 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Apr 28 2017 07:09
So each function call execution makes another call which eventually hits n===0 and all the calls get evaluated in reverse order.
Abhishek Saini
@sainiabhi
Apr 28 2017 07:09
It's tricky
but very powerful
Markus Kiili
@Masd925
Apr 28 2017 07:10
@sainiabhi Sometimes it is the best way to go. In JS you learn to avoid it usually, because JS doesn't optimize recursion and using it can freeze the browser.
Vishal Singhania
@vishal090
Apr 28 2017 07:11
@Masd925 Thanks !! It works.. @not-a-cylon Thanks for the stuff() explaination part..It striked
CamperBot
@camperbot
Apr 28 2017 07:11
vishal090 sends brownie points to @masd925 and @not-a-cylon :sparkles: :thumbsup: :sparkles:
:cookie: 383 | @not-a-cylon |http://www.freecodecamp.com/not-a-cylon
:star2: 3962 | @masd925 |http://www.freecodecamp.com/masd925
Abhishek Saini
@sainiabhi
Apr 28 2017 07:11
exactly if any condition fails it will take the infinite loop
Sergey Lukin
@not-a-cylon
Apr 28 2017 07:11
seems like recursion tricks are more of a whiteboard interview thing.
np
Abhishek Saini
@sainiabhi
Apr 28 2017 07:13
@not-a-cylon yeah they will ask almost everytime during interview
Sergey Lukin
@not-a-cylon
Apr 28 2017 07:14
lulz
Christopher Emmons
@canyouhearmeknocking
Apr 28 2017 07:19
hey, I'm stuck trying to figure out how 'a' can be assigned to 'b' with '=' in the "storing values with the assignment operator" lesson. can someone help?
ive tried
var a = 7;
lol my bad this is the first time using this obviously
Markus Kiili
@Masd925
Apr 28 2017 07:20
@canyouhearmeknocking Assignment operator evaluates the right hand side and assigns the value to the variable on the left. So from right to left.
Christopher Emmons
@canyouhearmeknocking
Apr 28 2017 07:22
var a = var b; this is my guess but it's not seeming to work
Markus Kiili
@Masd925
Apr 28 2017 07:22
@canyouhearmeknocking The var cannot be used on the right side.
Jor
@joreyesl
Apr 28 2017 07:22
@canyouhearmeknocking var is used to declare the variable. if you do var a = 7 then you are declaring the variable a and assigning it the value of 7 in the same line. The assignment goes from right to left. so 7 gets assigned to a. Now if you want to assign a to b. Then a has to be on the right side.
Markus Kiili
@Masd925
Apr 28 2017 07:23
If b is already declared, just use b.
Christopher Emmons
@canyouhearmeknocking
Apr 28 2017 07:28
then i would guess the solution is var a = b; ??? that's not right either though. thanks for bearing with me. this seems like it should be simple but im not grasping
rebeccatay92
@rebeccatay92
Apr 28 2017 07:32
I got stuck at the profile lookup. This code runs when I lookup the first entry in the lookup table. However, how do i get it to search throughout the whole table?
function lookUpProfile(firstName, prop){
// Only change code below this line
for (i = 0; i < contacts.length; i ++) {
  if (firstName === contacts[i].firstName){
    if (contacts[i].hasOwnProperty(prop) === true) {
      return contacts[i][prop];
    } else return "No such property";
  } else return "No such contact";
}
// Only change code above this line
}
Sergey Lukin
@not-a-cylon
Apr 28 2017 07:32
@rebeccatay92 you're returning "No such contact" too early.
fathurrahman alif fahrezi
@fathurrahmanaf
Apr 28 2017 07:32
var full_name = "John Doe";

var contact = {
    "phone" : "123456789",
    "email" : "abc@gmail.com"
};

console.log("First name:", full_name,". Phone:", contact.phone,". Email:", contact.email); // First name: John Doe . Phone: 123456789 . Email: abc@gmail.com
there is a space shown after every properties called. like "John Doe(space).(space)Phone" can someone please help to escape one of the space so the result will be "John Doe.(space)Phone
Christopher Emmons
@canyouhearmeknocking
Apr 28 2017 07:33
the answer was b=a; thanks
Sergey Lukin
@not-a-cylon
Apr 28 2017 07:33
@rebeccatay92 Needs to be outside the loop, otherwise it exits out if the very first name doesn't match.
@fathurrahmanaf try using + operator to concatenate strings, instead. Using , adds a space automatically.
rebeccatay92
@rebeccatay92
Apr 28 2017 07:36
function lookUpProfile(firstName, prop){
// Only change code below this line
for (i = 0; i < contacts.length; i ++) {
  if (firstName === contacts[i].firstName){
    if (contacts[i].hasOwnProperty(prop) === true) {
      return contacts[i][prop];
    } else return "No such property";
  }
} 
return "No such contact";
// Only change code above this line
}
Aha! thanks @not-a-cylon
CamperBot
@camperbot
Apr 28 2017 07:36
rebeccatay92 sends brownie points to @not-a-cylon :sparkles: :thumbsup: :sparkles:
:cookie: 384 | @not-a-cylon |http://www.freecodecamp.com/not-a-cylon
fathurrahman alif fahrezi
@fathurrahmanaf
Apr 28 2017 07:37
@not-a-cylon thank you very much again!!!
CamperBot
@camperbot
Apr 28 2017 07:37
fathurrahmanaf sends brownie points to @not-a-cylon :sparkles: :thumbsup: :sparkles:
:cookie: 385 | @not-a-cylon |http://www.freecodecamp.com/not-a-cylon
Sergey Lukin
@not-a-cylon
Apr 28 2017 07:37
:D
Markus Kiili
@Masd925
Apr 28 2017 07:37
@rebeccatay92 That === true is redundant.
Christopher Emmons
@canyouhearmeknocking
Apr 28 2017 07:44
Thanks @masd925
CamperBot
@camperbot
Apr 28 2017 07:44
canyouhearmeknocking sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 3963 | @masd925 |http://www.freecodecamp.com/masd925
Manuchehr Muhidinov
@manucher17
Apr 28 2017 07:51
var myStr = "I am a \"double quoted\" string inside \"double quotes\"."; Help, please
rugano
@rugano
Apr 28 2017 07:56
Good morning pals
Manuchehr Muhidinov
@manucher17
Apr 28 2017 07:57
@rugano hey)
Hellsgear
@Hellsgear
Apr 28 2017 07:59
Hej =)
one question how can i access a global variable in a function and change its value for example +=1 ?
i am super stuck xDDD
Manuchehr Muhidinov
@manucher17
Apr 28 2017 08:01
@Hellsgear why would you need that? We should use more local variables and less global
Hellsgear
@Hellsgear
Apr 28 2017 08:03
i am referring to the challenge counting cards and there i have a fixed var count that i must not change
and i need to write a function to change the "count" depending on the cards
rugano
@rugano
Apr 28 2017 08:03
function findLongestWord(str){
var sentence = str.split('');

var eachword = 0;
for(var i = 0;i < eachword.length;i++){
eachword += sentence[i];
}
return eachword += sentence[i];
findLongestWord("Google do a barrel roll");
how do i correct this?
rebeccatay92
@rebeccatay92
Apr 28 2017 08:04
@Hellsgear
hmm just call the var and use the mathematical operator on it.
eg: varName += 1;
but this changes the global variable as well.
Hellsgear
@Hellsgear
Apr 28 2017 08:04
that doesnt work xPPP that is what i did
Sergey Lukin
@not-a-cylon
Apr 28 2017 08:04
@rugano eachword is an integer, not string or array. Won't make sense to call .length on it.
rebeccatay92
@rebeccatay92
Apr 28 2017 08:05
@Hellsgear can you copy n paste the code here? I presume u are referring to the "Bet" or "Hold" exercise
Manuchehr Muhidinov
@manucher17
Apr 28 2017 08:05
@rugano agreed. You may need str.length
rugano
@rugano
Apr 28 2017 08:06
@not-a-cylon ok,what else do i need to correct?
Sergey Lukin
@not-a-cylon
Apr 28 2017 08:06
@rugano also double-check your delimeter in .split() or just print sentence to the console to look at it.
Might not end up looking the way you intended.
Hellsgear
@Hellsgear
Apr 28 2017 08:07

var count = 0;

function cc(card) {
// Only change code below this line
switch(card) {
case 2:
case 3:
case 4:
case 5:
case 6:
count += 1;
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count -= 1;
break;
}
if (count <= 0) {
console.log(count + ' Hold');
} else {
console.log(count + ' Bet');
}
// Only change code above this line
}

i dunno how to copy it in the console xDDDD
i am a noob xD
heroiczero
@heroiczero
Apr 28 2017 08:08
@Hellsgear i think you have to return the results
Sergey Lukin
@not-a-cylon
Apr 28 2017 08:08
surround with ``` in beginning and end next time
rugano
@rugano
Apr 28 2017 08:10
@manucher17 ok
wFez
@wFez
Apr 28 2017 08:12
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
  var result = "";
  // Your code below this line


  // Your code above this line
  return result;
}

// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");
rebeccatay92
@rebeccatay92
Apr 28 2017 08:12
return count + " Hold"; n likewise. the switch is correct, and ++ -- works in place of +=1 and -=1 too.
wFez
@wFez
Apr 28 2017 08:12
wordBlanks("dog", "big", "ran", "quickly") should contain all of the passed in words separated by non-word characters (and any additional words in your madlib).
what does it means
heroiczero
@heroiczero
Apr 28 2017 08:14
@wFez need to use the parameters of the function to make a sentence in the var result. parameters of function: https://en.wikipedia.org/wiki/Parameter_(computer_programming)
rebeccatay92
@rebeccatay92
Apr 28 2017 08:14
@wFez the mad libs exercise requires you to craft a sentence like "The lazy cat jumped quickly over the fence".
Hellsgear
@Hellsgear
Apr 28 2017 08:14
var count = 0;

function cc(card) {
  // Only change code below this line
  switch(card) {
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
    return count += 1;
    case 10:
    case 'J':
    case 'Q':
    case 'K':
    case 'A':
    return count -= 1;
  }
      if (count <= 0) {
      console.log(count + ' Hold');
     } else {
      console.log(count + ' Bet');
  }
  // Only change code above this line
}



// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('6');
didn´t word either =/
i mean with return
heroiczero
@heroiczero
Apr 28 2017 08:15

@Hellsgear no

      if (count <= 0) {
      console.log(count + ' Hold');
     } else {
      console.log(count + ' Bet');
  }

these need to return the results

rebeccatay92
@rebeccatay92
Apr 28 2017 08:15
@Hellsgear count +=1; is correct. u should change console log to return instead
Hellsgear
@Hellsgear
Apr 28 2017 08:15
oh oops xD ok i`ll try
rebeccatay92
@rebeccatay92
Apr 28 2017 08:16
@wFez just a hint:
console.log("The " + myNoun +........);
rmbr to add spaces!
Hellsgear
@Hellsgear
Apr 28 2017 08:17
holy moly it worked thx =)))
Chris Juchtmans
@kjuchtmans
Apr 28 2017 08:17

Goodmorning all !

Question relating to testing objects for properties : is one allowed to pass multiple variables to hasOwnProperty like so: contacts.hasOwnProperty(firstName, likes) ?

Or is this not permissible?

cheers,
k

Sergey Lukin
@not-a-cylon
Apr 28 2017 08:18
MDN is a great resource overall.
heroiczero
@heroiczero
Apr 28 2017 08:19
@kjuchtmans that is not permissable. can only use one variable.
Chris Juchtmans
@kjuchtmans
Apr 28 2017 08:19
@not-a-cylon Great tip, thanks !
CamperBot
@camperbot
Apr 28 2017 08:19
kjuchtmans sends brownie points to @not-a-cylon :sparkles: :thumbsup: :sparkles:
:cookie: 387 | @not-a-cylon |http://www.freecodecamp.com/not-a-cylon
Chris Juchtmans
@kjuchtmans
Apr 28 2017 08:19
@heroiczero thank you
CamperBot
@camperbot
Apr 28 2017 08:19
kjuchtmans sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1194 | @heroiczero |http://www.freecodecamp.com/heroiczero
Pieter Stokkink
@forkerino
Apr 28 2017 08:20
Hello!
wFez
@wFez
Apr 28 2017 08:22
@rebeccatay92 thanks for the reply
CamperBot
@camperbot
Apr 28 2017 08:22
wfez sends brownie points to @rebeccatay92 :sparkles: :thumbsup: :sparkles:
:cookie: 221 | @rebeccatay92 |http://www.freecodecamp.com/rebeccatay92
rugano
@rugano
Apr 28 2017 08:23
How do i double check my delimeter in .split('') ?
Pieter Stokkink
@forkerino
Apr 28 2017 08:24
@rugano it is between the parens ()
so empty string in this case
rugano
@rugano
Apr 28 2017 08:25
when i write: var eachword = int; i get an error "int not defined"
@forkerino should i write a single or double quotes?
heroiczero
@heroiczero
Apr 28 2017 08:26
@rugano is int a variable? or a string?
Pieter Stokkink
@forkerino
Apr 28 2017 08:26
@rugano well you are treating int as a variable, so that doesn't work if you didn't declare it first.
Aizaz Shahid
@aizazshahid
Apr 28 2017 08:30
What's going on ? @/all
@forkerino How are you ?
rugano
@rugano
Apr 28 2017 08:40
Hey campers,i deeply stuck
Pieter Stokkink
@forkerino
Apr 28 2017 08:41
@forwebtech Hey, doing well. And you?
@rugano explain
Chris Juchtmans
@kjuchtmans
Apr 28 2017 08:44

Can anyone confirm this code is syntactically and logically correct?

It's my first building block toward solving the Profile Lookup exercise: I'm trying to iterate through the object and first locate the given firstName, then - if this returns True - locate the given prop

Code :
for (var i=0; i < contacts.length; i++) { for (var j=0; j < contacts[i].length; j++) { if (contacts.hasOwnProperty(firstName)) { if (contacts.hasOwnProperty(prop)) { return contacts[prop]; } } } }

Pieter Stokkink
@forkerino
Apr 28 2017 08:44
@kjuchtmans You only need one loop. Contacts is an array, but inside it are objects.
Chris Juchtmans
@kjuchtmans
Apr 28 2017 08:44
only one aye... I'm looking into it
Pieter Stokkink
@forkerino
Apr 28 2017 08:45
the nested ifs are good.
just need an index on contacts in there
Jakub Kałamarz
@kkalamarz
Apr 28 2017 08:45
function chunkArrayInGroups(arr, size) {
var times = arr.length / size;
var result = [];
  for (var i = 0; i < times; i++) {
    var newArr = [];
    newArr = arr.slice(0, size);
    result.push(newArr);
    for (var k = 0; k < size; k++){
    arr.shift();
    }
  }
  return result;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
spagethi code? What do you think?
rugano
@rugano
Apr 28 2017 08:45
function findLongestWord(str){
var sentence = str.split('');
var eachword = str;
var int = 0;
for(var i = 0;i < str.length;i++){
eachword += sentence[i];

}
return eachword += sentence[i];
}
findLongestWord("Google do a barrel roll");
how do i correct it?
Pieter Stokkink
@forkerino
Apr 28 2017 08:45
@kkalamarz why have a newArr at all?
Jakub Kałamarz
@kkalamarz
Apr 28 2017 08:47
@forkerino slice dont return sliced, and dont change antyhink at main array?
Pieter Stokkink
@forkerino
Apr 28 2017 08:47
@rugano I can copy your code and leave some comments inside
@kkalamarz I mean you can just push the slice straight into result.
rugano
@rugano
Apr 28 2017 08:49
@forkerino i will appreciate.This section of fcc is really draining my reasoning.Does it happen like this to everyone?
Pieter Stokkink
@forkerino
Apr 28 2017 08:49
function findLongestWord(str){
var sentence = str.split(''); 
var eachword = str; // not needed
var int = 0; // better be named longestWord or something
for(var i = 0;i < str.length;i++){ // you need to loop over 'sentence', not str
eachword += sentence[i]; // remove this and replace with a comparison between int and the length of the current word.
     // if it is longer, assign the length to int
}
return eachword += sentence[i];  // return int instead.
}
findLongestWord("Google do a barrel roll");
@rugano
@kkalamarz like so: result.push(arr.slice(0,size);
Jakub Kałamarz
@kkalamarz
Apr 28 2017 08:51
@forkerino Thanks, It so huge mistake? Or its barerly fine?
Pieter Stokkink
@forkerino
Apr 28 2017 08:52
@kkalamarz it is ok to do it the way you did, but it makes it more difficult to understand the code, because you have to keep track of one more variable when reading it.
@kkalamarz can I show you another solution?
Aizaz Shahid
@aizazshahid
Apr 28 2017 08:53
what are sparse arrays ?
Manuchehr Muhidinov
@manucher17
Apr 28 2017 08:54
Confirm the Ending. I'm kinda stuck
function confirmEnding(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
  for (var i = 0; i < str.length; i++) {
    console.log(first[0] + first[first.length - 1]); 
  }
  return str;
}

confirmEnding("Bastian", "n");
Pieter Stokkink
@forkerino
Apr 28 2017 08:54
@forwebtech arrays with loads of zeros / undefineds/ nulls in it.
Aizaz Shahid
@aizazshahid
Apr 28 2017 08:54
@forkerino that means garbage value ?
like!
Pieter Stokkink
@forkerino
Apr 28 2017 08:55
@manucher17 you don't need a loop for this. You can use .slice or .substr or .substring and compare some things.
CamperBot
@camperbot
Apr 28 2017 08:55
manucher17 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 1987 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Apr 28 2017 08:55
@forwebtech Not necessarily garbage, as the values are needed to keep all the non-zero values in the right place.
Manuchehr Muhidinov
@manucher17
Apr 28 2017 08:56
@forkerino thanks. I'll try again)
CamperBot
@camperbot
Apr 28 2017 08:56
manucher17 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:warning: manucher17 already gave forkerino points
Aizaz Shahid
@aizazshahid
Apr 28 2017 08:56
alright !
Pieter Stokkink
@forkerino
Apr 28 2017 08:56
@manucher17 :+1:
Markus Kiili
@Masd925
Apr 28 2017 08:59
@forwebtech Sparse arrays are arrays with holes. They can have missing elements.
Ming Zhu
@chocobrownie
Apr 28 2017 09:00
Hi, I have a question: when I have a asynchronous function call in my page and I need its result to run a few things, how do I know how long it will take? Or how long does my html JavaScript program take? I think I need those data to compare and calculate which step on my program will the asynchronous function result be ready to use
Aizaz Shahid
@aizazshahid
Apr 28 2017 09:00
@Masd925 didn't understand holes ?
holes === undefined ?
@chocobrownie in that case that function has some property to check its status !
like, foo().readyState()
Pieter Stokkink
@forkerino
Apr 28 2017 09:02
@chocobrownie You cannot know. It depends on the connection speed, server speed, availability and so on. You have to do everything you need to do with the data coming back from the api inside the callback.
Ming Zhu
@chocobrownie
Apr 28 2017 09:02
Oh nice, let me check it out @forwebtech Any advice on what should I read?
Markus Kiili
@Masd925
Apr 28 2017 09:02
@forwebtech
Aizaz Shahid
@aizazshahid
Apr 28 2017 09:02
@chocobrownie try to console it !
Markus Kiili
@Masd925
Apr 28 2017 09:02
var arr = [];
arr[5] = "cat";
arr.length; // 6
arr[0] // undefined
arr.hasOwnProperty(5); // true
arr.hasOwnProperty(0); // false
Ming Zhu
@chocobrownie
Apr 28 2017 09:03
@forkerino what if my program is simple, I finished everything else but the api is still not ready? But I need its result?
Markus Kiili
@Masd925
Apr 28 2017 09:03
@forwebtech Array elements (or other object properties) can exist and have value undefined, or not exist and return undefined when accessed.
Aizaz Shahid
@aizazshahid
Apr 28 2017 09:03
@Masd925 that means:
var arr = [];
arr[0] = undefined;

arr.hasOwnProperty(0);   // true ????
Markus Kiili
@Masd925
Apr 28 2017 09:04
arr[2] = undefined;
arr.hasOwnProperty(2); // true
arr[2]; // undefined
yes
Pieter Stokkink
@forkerino
Apr 28 2017 09:04
@chocobrownie it has to be done inside the callback, because that is the only place where you know the data exists. Consider the callback the thing that triggers when the data comes back. You can call other functions inside the callback and pass in the data is argument.
Markus Kiili
@Masd925
Apr 28 2017 09:05
@forwebtech So checking for undefined is not a valid way to check for property existence.
Aizaz Shahid
@aizazshahid
Apr 28 2017 09:05
oh, that means actually holes are garbage values which we can observe in C language.
Praveen Saraogi
@raviloop
Apr 28 2017 09:05

function titleCase(str) {

  var some = str.split(" ");

  for( i=0;i<some.length;i++){

    some[i] = some[i].charAt(0).toUpperCase() + some[i].slice();
  }



  return some.join(" ");
}

titleCase("I'm a little tea pot");
THis is capitalizing the word but its returning the actual word after the first capital letter , for instance i want to capitalize first letter of word " hello", so according to my code it will return "Hheloo" and i want it to return "Hello"
Aizaz Shahid
@aizazshahid
Apr 28 2017 09:06
like if we don't initialize array or variable it can be count as hole !
Pieter Stokkink
@forkerino
Apr 28 2017 09:06
@raviloop your slice needs an index as argument
Markus Kiili
@Masd925
Apr 28 2017 09:06
@forwebtech Hole means that some indices are missing.
There we had only element at index 5 and 0,1,2,3,4 were missing.
Pieter Stokkink
@forkerino
Apr 28 2017 09:06
@forwebtech you only have a hole if there is something on both sides of it. Otherwise it is an abyss and existential dread will set in.
Praveen Saraogi
@raviloop
Apr 28 2017 09:07
@forkerino you meant to say like thise slice(some[i]) or slice([i])
Pieter Stokkink
@forkerino