These are chat archives for FreeCodeCamp/HelpJavaScript

21st
Feb 2016
Aleksander Gębicki
@Takumar
Feb 21 2016 00:00
@caleb272 when you call your function, arguments[1] will receive value 2 and arguments[2] will receive value 3.
You don't have to pass arguments to your function.
Caleb Martin
@caleb272
Feb 21 2016 00:00
```
function seekAndDestroy(current) {
  return true;
}

function destroyer(arr) {
  //console.log(arr + '  :  ' + arr.filter(seekAndDestroy));
  arr = arr.filter(seekAndDestroy);
  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
look at the seekAndDestroy function i need to get 2, 3 to that function
while its being filtered
Aleksander Gębicki
@Takumar
Feb 21 2016 00:01

@caleb272 when you need to create external function, just pass to it your arguments:

function seekAndDestroy(current, args) {

as second parameter.
But as I said earlier you have to store your arguments of destroyer() function to your variable:

function destroyer(arr) {
  var args = ...
Caleb Martin
@caleb272
Feb 21 2016 00:02
function seekAndDestroy(current, args) {
  return true;
}

function destroyer(arr) {
  //console.log(arr + '  :  ' + arr.filter(seekAndDestroy));
  arr = arr.filter(seekAndDestroy(arr));
  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
it wont let me do this
casadaro
@Casadaro
Feb 21 2016 00:03
This things is killing me, can someone help me out?
Aleksander Gębicki
@Takumar
Feb 21 2016 00:03
@caleb272 look upper.
It won't let you do this because you haven't passed arguments to your seekAndDestroy() function.
arr = arr.filter(seekAndDestroy(arr, args));
casadaro
@Casadaro
Feb 21 2016 00:03
Profile Lookup
We have an array of objects representing different people in our contacts lists.

A lookUp function that takes firstName and a property (prop) as arguments has been pre-written for you.

The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.

If both are true, then return the "value" of that property.

If firstName does not correspond to any contacts then return "No such contact"

If prop does not correspond to any valid properties then return "No such property”
Aleksander Gębicki
@Takumar
Feb 21 2016 00:04
@Casadaro have you tried to write anything?
casadaro
@Casadaro
Feb 21 2016 00:04
Nevermind I found a previous answer
Caleb Martin
@caleb272
Feb 21 2016 00:05

nope
‘’'
function seekAndDestroy(current, args) {
return true;
}

function destroyer(arr) {
//console.log(arr + ' : ' + arr.filter(seekAndDestroy));
arr = arr.filter(seekAndDestroy(arr, arguments));
return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
```

function seekAndDestroy(current, args) {
  return true;
}

function destroyer(arr) {
  //console.log(arr + '  :  ' + arr.filter(seekAndDestroy));
  arr = arr.filter(seekAndDestroy(arr, arguments));
  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
sorry for spamming
that doesn’t run it throws errors
Mafalda
@otmeek
Feb 21 2016 00:10
@caleb272 someone correct me if I'm wrong, but I don't think you can pass a function like that to filter
Caleb Martin
@caleb272
Feb 21 2016 00:11
ya i know but how do you
Mafalda
@otmeek
Feb 21 2016 00:11
you either pass it like .filter(function() { }); or just with the name .filter(seekAndDestroy) without passing any arguments
Caleb Martin
@caleb272
Feb 21 2016 00:12
ya but i need to pass the arguments to seekAndDestroy when using filter i need to know how to do that
Norman Dela Cruz
@dcnr
Feb 21 2016 00:12
@caleb272 also filter's callback has fixed arguments
  1. current element value
  2. current element index
  3. the array being filtered
Mafalda
@otmeek
Feb 21 2016 00:12
do you really need another function?
you can just use an anonymous function
instead of defining another one outside destroyer(). It will make things simpler for you
Norman Dela Cruz
@dcnr
Feb 21 2016 00:13
yeah
Caleb Martin
@caleb272
Feb 21 2016 00:13
but i want to do it that way its cleaner !!!!
and its good to know how to do it
if i do an anon function do i get access to all the destroyer variables
?
Mafalda
@otmeek
Feb 21 2016 00:15
it has access to all the variables of the parent scope, but you only really need the parameter you pass it which is the current element value
Kirill
@GreatORC
Feb 21 2016 00:15
@SaintPeter Maybe it'll help you one day: the main mistake of mine was that: "return String.fromCharCode(chCode+13)" instead of "return str.fromCharCode(chCode+13)" :)
Aleksander Gębicki
@Takumar
Feb 21 2016 00:15
@caleb272 you can make your function iternal.

function destroyer(arr) {
  function seekAndDestroy(current) {
    return true; 
  }

  arr = arr.filter(seekAndDestroy);
  return arr;
}
Rex Schrader
@SaintPeter
Feb 21 2016 00:16
@GreatORC Well, I wrote the challenge, but thanks :D
CamperBot
@camperbot
Feb 21 2016 00:16
saintpeter sends brownie points to @greatorc :sparkles: :thumbsup: :sparkles:
:star: 267 | @greatorc | http://www.freecodecamp.com/greatorc
Caleb Martin
@caleb272
Feb 21 2016 00:16
ya i know but i dont want it to be internal
Kirill
@GreatORC
Feb 21 2016 00:16
@SaintPeter sorry the second instead of the first :)
Rex Schrader
@SaintPeter
Feb 21 2016 00:16
@GreatORC :D
Norman Dela Cruz
@dcnr
Feb 21 2016 00:16
@caleb272 well you can't do it that way unless you define another function that is not the filter callback, because as I've said filter's callback only accepts predefined arguments, and one more for a this object
Caleb Martin
@caleb272
Feb 21 2016 00:17
well looks like i will make it internal :( i don’t really like JS
MikeBeers
@MikeBeers
Feb 21 2016 00:17
just finished with quote project
Mafalda
@otmeek
Feb 21 2016 00:18
@MikeBeers looks great!
Rex Schrader
@SaintPeter
Feb 21 2016 00:18
@MikeBeers I love the design! The way the background color changes with each button press (and how the button matches it)
Aleksander Gębicki
@Takumar
Feb 21 2016 00:18

@caleb272 if you really want to pass arguments to external function:

  arr = arr.filter(seekAndDestroy, arguments);

and use this to access it

function seekAndDestroy(current) {
  console.log(this[1], this[2]);
}
Rex Schrader
@SaintPeter
Feb 21 2016 00:18
@MikeBeers The twitter link does not work
@MikeBeers Nor does the tumbler link
MikeBeers
@MikeBeers
Feb 21 2016 00:19
i do not have a twitter or tumblr account
Rex Schrader
@SaintPeter
Feb 21 2016 00:19
@MikeBeers You do not need to have them in order to make a link that will post to them.
jv
@Forwardslash
Feb 21 2016 00:20
help needed on passing - Adding a default option in Switch statements. I'm getting ReferenceError: c is not defined but it all looks good to me.
CamperBot
@camperbot
Feb 21 2016 00:20
no wiki entry for: needed on passing - adding a default option in switch statements im getting referenceerror c is not defined but it all looks good to me
MikeBeers
@MikeBeers
Feb 21 2016 00:20
what do i need for that then?
Rex Schrader
@SaintPeter
Feb 21 2016 00:20
@MikeBeers Well, for Twitter, check this out: https://dev.twitter.com/web/tweet-button/web-intent
Aleksander Gębicki
@Takumar
Feb 21 2016 00:20
@caleb272 it should solve your problem totally.
MikeBeers
@MikeBeers
Feb 21 2016 00:20
sweet thanks
Rex Schrader
@SaintPeter
Feb 21 2016 00:20
@MikeBeers You need to build a URL and refresh it each time you display a new quote.
Caleb Martin
@caleb272
Feb 21 2016 00:21
@Takumar thanks that was just the answer i needed
CamperBot
@camperbot
Feb 21 2016 00:21
caleb272 sends brownie points to @takumar :sparkles: :thumbsup: :sparkles:
:star: 2350 | @takumar | http://www.freecodecamp.com/takumar
jv
@Forwardslash
Feb 21 2016 00:22
my code part
switch (val) {
case a:
answer = "apple";
break;
case b:
answer = "bird";
break;
case c:
answer = "cat";
break;
default: answer = "stuff";
}
Caleb Martin
@caleb272
Feb 21 2016 00:22
instead of people telling me to make it internal or anon
Aleksander Gębicki
@Takumar
Feb 21 2016 00:23
@caleb272 you are welcome :-)
Although I think that making this function internal would be easier, because variable of external function would have also scope of internal function, and you could pass arguments with help of a variable which stored arguments.
jv
@Forwardslash
Feb 21 2016 00:26
hello, anyone? little help.
Aleksander Gębicki
@Takumar
Feb 21 2016 00:26
@Forwardslash a, b and c should be strings.
case 'a':
Caleb Martin
@caleb272
Feb 21 2016 00:26
ya i will probably do that instead but thanks for answering my question
jv
@Forwardslash
Feb 21 2016 00:26
looks like they are
ah
Aleksander Gębicki
@Takumar
Feb 21 2016 00:26
@Forwardslash put them in quotation marks
jv
@Forwardslash
Feb 21 2016 00:26
thanks!
JackeL
@jackel27
Feb 21 2016 00:28
@Forwardslash only if string, for integers, leave quotes out.
jv
@Forwardslash
Feb 21 2016 00:28
yeah, that didn't work
I'm still stuck w/ switch (val) {
case a:
answer = "apple";
break;
case b:
answer = "bird";
break;
case c:
answer = "cat";
break;
default: answer = "stuff";
}
Ashraf-Farabi
@Ashraf-Farabi
Feb 21 2016 00:29
Can I get a help on this?
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");
Instructions are to lookup val and assign the associated string to the result variable.
Rex Schrader
@SaintPeter
Feb 21 2016 00:30
@Ashraf-Farabi You need to actually use your lookup. You've got it written correctly, just use bracket notation on lookup with val and assign it to result
@Ashraf-Farabi IE: someResult = someObj[someVarWithAPropertyNameInIt];
Norman Dela Cruz
@dcnr
Feb 21 2016 00:31

@Ashraf-Farabi Hi you'll have to use the variable method with bracket notation
Two ways to access object values through properties. . and []
You use . if you literally use the property name.

var agent = {
  firstName = "Jason",
  lastName = "Bourne"
}

Using . notation

var result = agent.firstName; // result is Jason

There are two ways to use []
First one is like the . where you use the literal property name

var result = agent["firstName"]; // result is Jason

Notice that the firstName is quoted so it's a string.
The second way is with variables.

var propertyIWant = 'lastName';
var result = agent[propertyIWant];
jv
@Forwardslash
Feb 21 2016 00:32
ReferenceError: c is not defined I don't get it.
Rex Schrader
@SaintPeter
Feb 21 2016 00:32
@Forwardslash case 'c': - c needs to be a string.
Ashraf-Farabi
@Ashraf-Farabi
Feb 21 2016 00:33
Hey! It worked! Thanks @SaintPeter and @dcnr
CamperBot
@camperbot
Feb 21 2016 00:33
ashraf-farabi sends brownie points to @saintpeter and @dcnr :sparkles: :thumbsup: :sparkles:
:star: 2526 | @saintpeter | http://www.freecodecamp.com/saintpeter
:star: 669 | @dcnr | http://www.freecodecamp.com/dcnr
Rex Schrader
@SaintPeter
Feb 21 2016 00:33
@Forwardslash And so do a and b
Norman Dela Cruz
@dcnr
Feb 21 2016 00:33
@Forwardslash all your case values should be string so they should be quoted, because if you don't quote them they'll be treated as variables
jv
@Forwardslash
Feb 21 2016 00:33
"cat is the string though
err... "cat"
Norman Dela Cruz
@dcnr
Feb 21 2016 00:34
since c is undefined, you're getting that error, you're just testing if val === c (the letter c) right?
Rex Schrader
@SaintPeter
Feb 21 2016 00:34
@Forwardslash Your case statement is wrong. You are not looking for a variable c, you're looking for a STRING c:
case "c":
   answer = "cat";
   break;
Aleksander Gębicki
@Takumar
Feb 21 2016 00:35
@Forwardslash I gave you example: case 'a': and you told that you understand that it should be string. "case a:" is wrong, because a is not a variable.
jv
@Forwardslash
Feb 21 2016 00:35
<confused> anyhoo thanks for the effort. ¯_(ツ)_/¯ / gives up on code for today <closetab>
Aleksander Gębicki
@Takumar
Feb 21 2016 00:37
@Forwardslash :confused: :confused: :-)
use colons for emoticons
Norman Dela Cruz
@dcnr
Feb 21 2016 00:38

@Forwardslash think of it like

if (val === "a") {
  answer = "apple";
}

You're testing if val is equal to a string letter a, so the a should be quoted. It's the same with case "a" :D

Rex Schrader
@SaintPeter
Feb 21 2016 00:39
I think he/she left.
Norman Dela Cruz
@dcnr
Feb 21 2016 00:40
:pager:
JackeL
@jackel27
Feb 21 2016 00:44
My brain is toast.
Rex Schrader
@SaintPeter
Feb 21 2016 00:45
I've got some butter
Get some cinnemon and we're golden!
JackeL
@jackel27
Feb 21 2016 00:46
mmm let's dig in
lol
these advanced algorithms kicked my ass
Rex Schrader
@SaintPeter
Feb 21 2016 00:47
They're supposed to.
Mission: Accomplished
JackeL
@jackel27
Feb 21 2016 00:47
well, one advanced and one intermediate last 3 days...
the advanced was easier than the intermediate...
I still don't get the intermediate one...
Rex Schrader
@SaintPeter
Feb 21 2016 00:47
Which one is that?
HassineBM
@hsine55
Feb 21 2016 00:48
can you guys tell what this Falsy Bouncer code dosent remove the null value ?
function bouncer(arr) {
// Don't show a false ID to this bouncer.
return arr.filter(function(value){
return [false, NaN, 0, undefined,'', null].indexOf(value) == -1;
});
}
JackeL
@jackel27
Feb 21 2016 00:48
it was...
Rex Schrader
@SaintPeter
Feb 21 2016 00:48
@hsine55 Humm. There is an easier solution: use the Boolean function. It returns true or false for truthy and falsy values
JackeL
@jackel27
Feb 21 2016 00:48

Where art thou (hardest one I've done so far)

exact change_ easier

HassineBM
@hsine55
Feb 21 2016 00:49
oh didnt thought of that
Mafalda
@otmeek
Feb 21 2016 00:49
@jackel27 where art thou fried my brain too
HassineBM
@hsine55
Feb 21 2016 00:49
but do you have an idea why this dosent work ?
Rex Schrader
@SaintPeter
Feb 21 2016 00:49
function where(collection, source) {
  return collection.filter(function(item) {
    return Object.keys(source).every(function(key) {
      return (item.hasOwnProperty(key) && item[key] === source[key]);
    });
  });
}
@hsine55 All I know is that the way that falsy values are handled is kinda hinky and you really can't do a direct comparison. IE: NaN === NaN is false, I think.
JackeL
@jackel27
Feb 21 2016 00:50
@otmeek yeah. I try to force myself to understand it, but nothing happens. haha spent hours just looking at my code and doing nothing
HassineBM
@hsine55
Feb 21 2016 00:51
ok thanks @SaintPeter
CamperBot
@camperbot
Feb 21 2016 00:51
hsine55 sends brownie points to @saintpeter :sparkles: :thumbsup: :sparkles:
:star: 2527 | @saintpeter | http://www.freecodecamp.com/saintpeter
JackeL
@jackel27
Feb 21 2016 00:51
@SaintPeter can you explain that in english haha
Rex Schrader
@SaintPeter
Feb 21 2016 00:51
@jackel27 Sure
Mafalda
@otmeek
Feb 21 2016 00:52
@SaintPeter such a clean solution. my code for it is like 4x the size of that lol
Norman Dela Cruz
@dcnr
Feb 21 2016 00:53
@otmeek it's even shorter with arrow functions :D
Mafalda
@otmeek
Feb 21 2016 00:54
@dcnr just googled what those look like, to me it looks so cryptic lol
JackeL
@jackel27
Feb 21 2016 00:54
function where(collection, source) {
    var keys = Object.keys(source);
    return collection.filter((object) => {
        return keys.every((key) => object[key] === source[key]);
    });
}
Rex Schrader
@SaintPeter
Feb 21 2016 00:55
@jackel27 Outermost loop, we're doing a filter on collection, meaning that we're looping through each element in collection. In order for that element (object) to be kept, a true must be returned.
Next section we get all of the keys of source and we do an every function on them. every only returns true if the function it calls returns true for all values it is looping through. We're passing in each "key" from source .
Inside that every we check two things:
1) Does the object from collection (item) HAVE the key from source
2_ Does the value of collection[key] === source[key]
Essentially: Does the key exist in the colleciton item and is it the same value as in source.
JackeL
@jackel27
Feb 21 2016 00:56
function where(collection, source) {
  return collection.filter(function(item) {
    return Object.keys(source).every(function(key) {

      return (item.hasOwnProperty(key) && item[key] === source[key]);
    });
  });
}
Norman Dela Cruz
@dcnr
Feb 21 2016 00:56
@jackel27 you can strip out the return too
function where(collection, source) {
  'use strict';
  const keys = Object.keys(source);

  return collection.filter(curr_obj =>
    keys.every(key => curr_obj.hasOwnProperty(key) && curr_obj[key] === source[key])
  );
}
JackeL
@jackel27
Feb 21 2016 00:56
for reference.
@SaintPeter I get it! so you are not pushing anything, just returning by use of filter
Rex Schrader
@SaintPeter
Feb 21 2016 00:59
@jackel27 Correct. This is the "Functional Progamming" style - no data from "outside" the functions is altered.
JackeL
@jackel27
Feb 21 2016 00:59
@SaintPeter Thanks!
CamperBot
@camperbot
Feb 21 2016 00:59
jackel27 sends brownie points to @saintpeter :sparkles: :thumbsup: :sparkles:
:star: 2528 | @saintpeter | http://www.freecodecamp.com/saintpeter
Rex Schrader
@SaintPeter
Feb 21 2016 00:59
@jackel27 The idea is that each element just returns the values it needs. They're sort of chained together. It creates pretty modular and easy to maintain code.
@jackel27 Sure thing
JackeL
@jackel27
Feb 21 2016 00:59
@SaintPeter Have you done exact change?
Rex Schrader
@SaintPeter
Feb 21 2016 01:00
@jackel27 I have.
Vadim Grigorov
@Chichavl
Feb 21 2016 01:01

Hi, I am stuck with Exact Change Zipline - I cannot understand how I can see how much cash in desk it is stored in array

[["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.10], ["QUARTER", 4.25], ["ONE", 90.00], ["FIVE", 55.00], ["TEN", 20.00], ["TWENTY", 60.00], ["ONE HUNDRED", 100.00]]

I want something like array["ONE HUNDRED"]
my current idea is to convert it to object by this function but I cannot get with syntax

json = cid.map(function(x) {
    return {
      x[0]: x[1]
    };
  });

Any sugestions?

Rex Schrader
@SaintPeter
Feb 21 2016 01:01
@jackel27 I don't have quite as clean a solution for that one. It's pretty complex.
JackeL
@jackel27
Feb 21 2016 01:01

@SaintPeter Heres a challenge for you....

Your CID only has 4quarters and 4dimes..

the change is .30

you need to return 3 dimes

no hardcoding ;)

@SaintPeter want to see mine?
Rex Schrader
@SaintPeter
Feb 21 2016 01:01
@Chichavl You can do it with reduce
@Chichavl What you are showing there is good instincts. You want to build an object that has the values in it.
@jackel27 Sure
kalmont3
@kalmont3
Feb 21 2016 01:03
var myStr = \ \t \t \r \n;
var myStr = \ \t \t \r \n; // Change this line
Rex Schrader
@SaintPeter
Feb 21 2016 01:03
@kalmont3 You need quotes around it
JackeL
@jackel27
Feb 21 2016 01:03
This message was deleted
kalmont3
@kalmont3
Feb 21 2016 01:03
thank you
Rex Schrader
@SaintPeter
Feb 21 2016 01:03
@kalmont3 and a backslash is "\\"
Vadim Grigorov
@Chichavl
Feb 21 2016 01:03
@SaintPeter and what is correct syntax for
{
      x[0]: x[1]
    };
JackeL
@jackel27
Feb 21 2016 01:04
oops.
Rex Schrader
@SaintPeter
Feb 21 2016 01:04
@Chichavl You'd need an external object:
var obj = {};
cid.forEach(function(arr) {  // Use forEach since you're not returning anything
   obj[arr[0]] = arr[1];
}
JackeL
@jackel27
Feb 21 2016 01:05

@SaintPeter keep in mind, this was after I did that special test case (one I explained), few days later adjusted it to meet challenge test case...

code is in need of a cleanse

Rex Schrader
@SaintPeter
Feb 21 2016 01:05
@Chichavl Alternatively you need to use reduce
JackeL
@jackel27
Feb 21 2016 01:06
its too long... hmm
Norman Dela Cruz
@dcnr
Feb 21 2016 01:06
@Chichavl with reduce you can do something like
var cid = [["PENNY", 1.01], ["NICKEL", 2.05]];

var cid_obj = cid.reduce(function(new_obj, cash) {
  new_obj[cash[0]] = cash[1];
  return new_obj;
}, {});

cid_obj is { PENNY: 1.01, NICKEL: 2.05}
Vadim Grigorov
@Chichavl
Feb 21 2016 01:07
@SaintPeter Thanks!
CamperBot
@camperbot
Feb 21 2016 01:07
chichavl sends brownie points to @saintpeter :sparkles: :thumbsup: :sparkles:
:star: 2529 | @saintpeter | http://www.freecodecamp.com/saintpeter
Vadim Grigorov
@Chichavl
Feb 21 2016 01:08
@dcnr Thanks!
Rex Schrader
@SaintPeter
Feb 21 2016 01:08
@Chichavl @dcnr That is close to what I did
Rex Schrader
@SaintPeter
Feb 21 2016 01:10
@jackel27 WOW
@jackel27 That's kinda huge
JackeL
@jackel27
Feb 21 2016 01:10
@SaintPeter not supposed to be that huge, it was a lot shorter when I was doing the special test case..
I did not comment properly, so when I came back to it, I forgot allot of the stuff I did, so just added to it hahaha
Norman Dela Cruz
@dcnr
Feb 21 2016 01:11
@Chichavl you can even preset stuff in your object, for example you can have TOTALCASH while you build your obj
var cid = [["PENNY", 1.01], ["NICKEL", 2.05]];

var cid_obj = cid.reduce(function(new_obj, cash) {
  var denomination = cash[0];
  var amount = cash[1];

  new_obj[denomination] = amount;
  new_obj.TOTALCASH += amount;
  return new_obj;
}, {
  TOTALCASH: 0
});

cid_obj is { TOTALCASH: 3.06, PENNY: 1.01, NICKEL: 2.05}
JackeL
@jackel27
Feb 21 2016 01:11
@SaintPeter haha not much difference right?!!
Norman Dela Cruz
@dcnr
Feb 21 2016 01:11
reduce is great for these kind of stuffs
Rex Schrader
@SaintPeter
Feb 21 2016 01:11
@dcnr @Chichavl
    // Transform CID array into drawer object
    var register = cid.reduce(function(acc, curr) {
        acc.total += curr[1];
        acc[curr[0]] = curr[1];
        return acc;
    }, {total: 0});
JackeL
@jackel27
Feb 21 2016 01:11
@dcnr did not even think about reduce...
Mafalda
@otmeek
Feb 21 2016 01:12
my code for exact change is so huge I get a URI too large error when trying to view it
so I can't see my solution :(
Rex Schrader
@SaintPeter
Feb 21 2016 01:12
Oh man
JackeL
@jackel27
Feb 21 2016 01:12
    function findit(array, value) {
            return array.find(function(arg1) {
                return !!~arg1.indexOf(value);
            });
        }
hahaha
Norman Dela Cruz
@dcnr
Feb 21 2016 01:13
@otmeek lol I got that too when I intentionally broke down everything to little functions. Something like Request Entity too large
Mafalda
@otmeek
Feb 21 2016 01:13
actually i probably should submit an issue about it right? this error doesnt sound like it supposed to happen lol
Rex Schrader
@SaintPeter
Feb 21 2016 01:13
@jackel27 Haha - getting sassy with indexOf - I had never seen that !!~ construct before. I MUCH prefer !== -1 for clarity.
@otmeek It's a limitation of your browser
@otmeek What browser are you using? IE limits you to 2k characters
Mafalda
@otmeek
Feb 21 2016 01:13
oh that makes sense. how can i overcome that?
chrome
Rex Schrader
@SaintPeter
Feb 21 2016 01:14
@otmeek Humm . . well, you might be able to convert that URI into code
JackeL
@jackel27
Feb 21 2016 01:14
@SaintPeter yeah, I golfed that one, want to remember it lol. I have never seen it either, thought I'd share :)
@SaintPeter I don't think I will ever stream advanced algorithms again... It makes out to be one looooong boring stream LOL
Rex Schrader
@SaintPeter
Feb 21 2016 01:15
@otmeek What you need to do is write some code to take the encoded URI and turn it into a string
@jackel27 Haha
@jackel27 I think they're probably too complex for a whiteboard interview question
Mafalda
@otmeek
Feb 21 2016 01:16
@SaintPeter lol thats what i thought, maybe i will do that
but it means i have to deal with regex which scare me :x
Rex Schrader
@SaintPeter
Feb 21 2016 01:17
@otmeek Oh, no, no need for that
@otmeek I believe that Javascript has a url decoder
SaintPeter @SaintPeter googles
Mafalda
@otmeek
Feb 21 2016 01:17
ohh yea I think
Rex Schrader
@SaintPeter
Feb 21 2016 01:17
Mafalda
@otmeek
Feb 21 2016 01:17
I used it for the random quote generator
Rex Schrader
@SaintPeter
Feb 21 2016 01:17
Try that website - paste the solution URI into the box
Mafalda
@otmeek
Feb 21 2016 01:17
@SaintPeter thanks!
CamperBot
@camperbot
Feb 21 2016 01:17
otmeek sends brownie points to @saintpeter :sparkles: :thumbsup: :sparkles:
:star: 2530 | @saintpeter | http://www.freecodecamp.com/saintpeter
JackeL
@jackel27
Feb 21 2016 01:18
@SaintPeter I am coming up on my 30day mark since signing up on FCC and JS. I think I am doing "okay".. definitely need to read more..
Rex Schrader
@SaintPeter
Feb 21 2016 01:18
@otmeek Your next challenge is to fix the solution so it's not so long ;)
JackeL
@jackel27
Feb 21 2016 01:18
@SaintPeter i'm done with exact change. If you plan on doing that special test case, I want to see what you come up with
Rex Schrader
@SaintPeter
Feb 21 2016 01:18
@jackel27 While I would not call your soltuion "optimal", it's definitely readable. You have good instincts on variable names and your code structure is nice.
@jackel27 The main thing you need to do is move away from switch statements and use lookup objects
Mafalda
@otmeek
Feb 21 2016 01:19
@SaintPeter i see it now, I made a variable for each coin and bill and used long case statements. that's why it's so long lol
JackeL
@jackel27
Feb 21 2016 01:20
@SaintPeter lookup objects.. okay, I'll search that
Rex Schrader
@SaintPeter
Feb 21 2016 01:20
@jackel27 There is a basic javascript challenge that does exactly that
SaintPeter @SaintPeter goes to find the name
JackeL
@jackel27
Feb 21 2016 01:21
@SaintPeter originally had one switch statement, my array returned the change name + change QTY, so .50 would return [{QUARTER, 2}) ... so I took the easy way out and built a 2nd switch to multiple the 2 by quarter price
Rex Schrader
@SaintPeter
Feb 21 2016 01:22
@jackel27 Look at how I built an array of objects with the values built in.
@jackel27 At the top of my solution
Anyway, got some "Honey-Do" items to do - TTY'all Later
JackeL
@jackel27
Feb 21 2016 01:22
@SaintPeter later, till next time..
HassineBM
@hsine55
Feb 21 2016 01:24
@SaintPeter do you know what is wrong with this
function where(collection, source) {
var arr = [];
arr = collection.filter(function(value){
for(var key in Object.keys(source)){
return (value.hasOwnProperty(key) && value[key] === source[key]);
}
});
return arr;
}
Rex Schrader
@SaintPeter
Feb 21 2016 01:26
@hsine55 You are returning a value prematurely.
@hsine55 Sice you do a return right away, you're going to only check one element in Object.keys
HassineBM
@hsine55
Feb 21 2016 01:31
true, thanks. But it's not even working with the test case where the source has only one key:value so i must have missed something else
Rex Schrader
@SaintPeter
Feb 21 2016 01:34
@hsine55 Yeah, source has several keys, I believe
rocket
@rengas
Feb 21 2016 02:10
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},]
what is the difference betweeen contacts[
arjunpunnam
@arjunpunnam
Feb 21 2016 02:10
im not understanding the question here can any one please helo
rocket
@rengas
Feb 21 2016 02:10
contacts[0][firstName]
contacts[0].firstName.
arjunpunnam
@arjunpunnam
Feb 21 2016 02:10
~~
rocket
@rengas
Feb 21 2016 02:10
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},]
what is the difference betweeen contacts[0][firstName]
contacts[0].firstName.
Can someone help me on this
@arjunpunnam may I know what is question? Is it regarding my question?
arjunpunnam
@arjunpunnam
Feb 21 2016 02:13
no no this is a different one
``
rocket
@rengas
Feb 21 2016 02:13
oh! may I know what is your question
arjunpunnam
@arjunpunnam
Feb 21 2016 02:14
~~~
Norman Dela Cruz
@dcnr
Feb 21 2016 02:14

@rengas hi is this your question?

what is the difference betweeen contacts[0][firstName]
contacts[0].firstName.

arjunpunnam
@arjunpunnam
Feb 21 2016 02:14
im trying to enter my code
rocket
@rengas
Feb 21 2016 02:14
yes @dcnr
Norman Dela Cruz
@dcnr
Feb 21 2016 02:14

@rengas

Two ways to access object values through properties. . and []

Example Object:

var agent = {
  firstName = "Jason",
  lastName = "Bourne"
};

Using the Dot .

You use . if you know and want to use the property name.

var result = agent.firstName; // result is Jason

Using the []

There are two ways to use []

  • First one is like the . where you use the literal property name
    var result = agent["firstName"]; // result is Jason
    Notice that the firstName is quoted so it's a string.
  • The second way is with variables.
    var propertyIWant = 'lastName';
    var result = agent[propertyIWant];
    Here instead of directly putting the property we want, we are assigning
    it to a variable first. Note that in agent[propertyIWant], propertyIWant
    is not quoted so it is treated as a variable.

The [] is also used if your property name is not a valid variable name.
For example it has spaces or starts with a number.

arjunpunnam
@arjunpunnam
Feb 21 2016 02:14
but im unable to do that
Norman Dela Cruz
@dcnr
Feb 21 2016 02:14
@rengas XD
arjunpunnam
@arjunpunnam
Feb 21 2016 02:15
function truncate(str, num) {
  // Clear out that junk in your trunk 
  var strTest = '';
  if(str.length > num){
    strTest =  str.slice(0,num-str.length)+"...";
    console.log(strTest);
    return strTest;   
  }
  else{
    console.log(str);
    return str;
  }

}
truncate("A-tisket a-tasket A green and yellow basket", 11);
Norman Dela Cruz
@dcnr
Feb 21 2016 02:19
@rengas

TLDR;

  • Using . you are directly using the property name itself
  • using [] there are two ways:
    1. Directly access by quoting the property name: obj["myprop"]
    2. Using a variable as property name by not quoting: obj[myprop]
arjunpunnam
@arjunpunnam
Feb 21 2016 02:19
truncate("A-", 1) should return "A...".
rocket
@rengas
Feb 21 2016 02:22
@dcnr why in my example contacts[0].firstName returns undefined
Norman Dela Cruz
@dcnr
Feb 21 2016 02:23
@rengas it should return Akira though hmm
Craig Banach
@CraigBanach
Feb 21 2016 02:25

Hi guys, looking for some help on Arguments Optional, I don't know how to structure my return statement in order to accept the second argument pass, code below:

function add() {

  //console.log(arguments[0]);

  if (arguments.length == 2) {
    return arguments[0] + arguments[1];
  } else {
    return function sum(number) {

     return arguments[0] + number;

    };
  }
}

add(2)(3);

Current error add(2)(3); returns 6.

rocket
@rengas
Feb 21 2016 02:25
@dcnr sorry contacts[0][firstName] actually returns undefined. Now I got it. I understood the other way round..
@dcnr Thank you
CamperBot
@camperbot
Feb 21 2016 02:25
rengas sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
:star: 670 | @dcnr | http://www.freecodecamp.com/dcnr
rocket
@rengas
Feb 21 2016 02:25
@arjunpunnam It works as expected. I dont understand your issue
Rex Schrader
@SaintPeter
Feb 21 2016 02:25
@cragsify You need to see if arguments[0] and arguments[1] are defined or not
rocket
@rengas
Feb 21 2016 02:26
@cragsify it should add(2,3)
arjunpunnam
@arjunpunnam
Feb 21 2016 02:27
@rengas for me two cases are failing,actually im having trouble undersatbding the req
Craig Banach
@CraigBanach
Feb 21 2016 02:27
@rengas One of the criteria is add(2)(3) == 5;
arjunpunnam
@arjunpunnam
Feb 21 2016 02:27
@rengas truncate("A-tisket a-tasket A green and yellow basket", 11) should return "A-tisket...".
Norman Dela Cruz
@dcnr
Feb 21 2016 02:27
@cragsify because sum's arguments is different from add. sum's argument[0] is actually 3
arjunpunnam
@arjunpunnam
Feb 21 2016 02:28
so the string length returned should be 11?
Norman Dela Cruz
@dcnr
Feb 21 2016 02:28
@cragsify you're actually adding 3 + 3
Craig Banach
@CraigBanach
Feb 21 2016 02:29
@dcnr Thanks, your help made me understand what I was doing wrong. :D
CamperBot
@camperbot
Feb 21 2016 02:29
cragsify sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
:star: 671 | @dcnr | http://www.freecodecamp.com/dcnr
arjunpunnam
@arjunpunnam
Feb 21 2016 02:29
@rengas but for truncate("A-", 1) should return "A...". the returned length is 4
Norman Dela Cruz
@dcnr
Feb 21 2016 02:29
you're welcome, thanks too @cragsify
CamperBot
@camperbot
Feb 21 2016 02:29
dcnr sends brownie points to @cragsify :sparkles: :thumbsup: :sparkles:
:star: 361 | @cragsify | http://www.freecodecamp.com/cragsify
Norman Dela Cruz
@dcnr
Feb 21 2016 02:31
@arjunpunnam the total length of your final string answer with the ... added should be equal to num, except when num <= 3
arjunpunnam
@arjunpunnam
Feb 21 2016 02:32
oh then it works
but its no where mentioned
Norman Dela Cruz
@dcnr
Feb 21 2016 02:33

@arjunpunnam It's in the instructions though

Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a "..." ending.
Note that the three dots at the end add to the string length.

arjunpunnam
@arjunpunnam
Feb 21 2016 02:33
yes my Bad
completely missed it
@dcnr Thanks
CamperBot
@camperbot
Feb 21 2016 02:34
arjunpunnam sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
:star: 672 | @dcnr | http://www.freecodecamp.com/dcnr
Norman Dela Cruz
@dcnr
Feb 21 2016 02:39
you're welcome, thanks too @arjunpunnam
CamperBot
@camperbot
Feb 21 2016 02:39
dcnr sends brownie points to @arjunpunnam :sparkles: :thumbsup: :sparkles:
:star: 260 | @arjunpunnam | http://www.freecodecamp.com/arjunpunnam
George Phalen
@gphalen
Feb 21 2016 02:40
#206 isn't registering any of my cases as correct, but I used the same switch statement logic that worked for the previous lessons

function myTest(val) {
var answer = "";
// Only change code below this line

switch(val){
case "bob":
answer= "Marley";
break;

case 42:
answer = "The Answer";
  break;

case 1:

answer = "There is no #1";
  break;

case 99:
answer = "Missed me by this much!";
  break;

}

}
// Only change code above this line

// Change this value to test
myTest(7);

Norman Dela Cruz
@dcnr
Feb 21 2016 02:41
@gphalen you should return answer; too :D
after the entire switch
George Phalen
@gphalen
Feb 21 2016 02:42
D'oh! That was it, thanks.
Norman Dela Cruz
@dcnr
Feb 21 2016 02:42
must have been accidentally deleted :P
Bartek
@dyczol
Feb 21 2016 02:55
hey everyone! working on returning palindrome. any pointers hints ? thanks in advance
function palindrome(str) {
  str.match(/\W+/g);
  if ( str == str.split('').reverse().join('')) {
     return true;
  }else {
    return false;
  }

}
 palindrome("race car");
Norman Dela Cruz
@dcnr
Feb 21 2016 02:57
@dyczol hi \W does not include _ so you need to add it in your pattern. Also you should remove the matched objects
Bartek
@dyczol
Feb 21 2016 02:58
@dcnr ok, so more like /\W+_/g ??
Norman Dela Cruz
@dcnr
Feb 21 2016 03:00
@dyczol that would mean one or more non-word character followed by an _, so it should be \W|_
ack I'm lagging
@dyczol \W|_
or [\W_]
@dyczol also, match just returns all the matched things in an array, you should remove those in your string before you compare. Maybe use replace instead of match?
Pete Considine
@pjconsidine
Feb 21 2016 03:03
hi everyone. does anyone know anything about Jade?
Bartek
@dyczol
Feb 21 2016 03:03
@dcnr ok, let me give it a shot and I'll come back
Norman Dela Cruz
@dcnr
Feb 21 2016 03:03
@pjconsidine hi, try the FrontEnd or the main room!
Pete Considine
@pjconsidine
Feb 21 2016 03:04
i tried there
Im trying everywhere, cause i'm stopped cold
Norman Dela Cruz
@dcnr
Feb 21 2016 03:05
@pjconsidine guess it's a slow day here :(
Pete Considine
@pjconsidine
Feb 21 2016 03:05
@dcnr yeah. I guess everyone else has better things to do. :)
I'm actually surprised that I can't find an answer on Stack Overflow or somethingt
@dcnr Do you use Cloud9 at all?
Norman Dela Cruz
@dcnr
Feb 21 2016 03:07
@pjconsidine sorry I don't know anything about Jade :(
Maybe try reddit? lol
@pjconsidine no, I used my own computer for those c9.io stuffs
Pete Considine
@pjconsidine
Feb 21 2016 03:11
okay. I'm trying to get Jade running on a Cloud9 space and I'm wondering if it might be a problem with Cloud9 rather than with Jade.
I will keep hunting.
have a good night.
Norman Dela Cruz
@dcnr
Feb 21 2016 03:12
@pjconsidine good luck! :four_leaf_clover:
matthew3454
@matthew3454
Feb 21 2016 03:12
Can someone help me with the waypoint about reversing a string?
I would appreciate it.
I attempted to change the string into an array as I was directed, but I did not succeed.

```function reverseString(str) {
return str;

var myArray = ["hello"];
};
```

Norman Dela Cruz
@dcnr
Feb 21 2016 03:17
@matthew3454 hi have you looked the helpful links? it directs you to String.split(), Array.reverse(), and Array.join()
Craig Banach
@CraigBanach
Feb 21 2016 03:17
@matthew3454 You return from your function before doing anything/
Ahmed Abdelaziz
@Achmed4
Feb 21 2016 03:22
Could anyone help me please in "Counting Cards" exercise in JavaScript Basics?
Norman Dela Cruz
@dcnr
Feb 21 2016 03:30
@Achmed4 hi what you got so far?
Travis Boss
@travisboss
Feb 21 2016 03:34
@Achmed4 please post the code you are having an issue with?
Clarence W.
@leo81202
Feb 21 2016 03:40
This message was deleted
Norman Dela Cruz
@dcnr
Feb 21 2016 03:41
@leo81202 your id and prop are variables, so you should use brackets
Clarence W.
@leo81202
Feb 21 2016 03:41
I tried brackets...didn't work
Norman Dela Cruz
@dcnr
Feb 21 2016 03:41
@leo81202 delete collection[id][prop];
Clarence W.
@leo81202
Feb 21 2016 03:43
// Setup
var collection = {
    2548: {
      album: "Slippery When Wet",
      artist: "Bon Jovi",
      tracks: [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    2468: {
      album: "1999",
      artist: "Prince",
      tracks: [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    1245: {
      artist: "Robert Palmer",
      tracks: [ ]
    },
    5439: {
      album: "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function update(id, prop, value) {

  if(value !==" " && prop !== "tracks"){
    collection[id][prop] = value;

  }

  if (prop == "tracks" && value !==" "){

    collection[id][prop].push(value);

  }

  if(value == " "){
    delete collection[id][prop];

  }


  return collection;
}

// Alter values below to test your code
update(5439, "artist", "ABBA");
didn't work
Ahmed Abdelaziz
@Achmed4
Feb 21 2016 03:43
@dcnr @travisboss I finally got it, thanks anyway and sorry for bothering you :)
CamperBot
@camperbot
Feb 21 2016 03:43
achmed4 sends brownie points to @dcnr and @travisboss :sparkles: :thumbsup: :sparkles:
:star: 673 | @dcnr | http://www.freecodecamp.com/dcnr
:star: 244 | @travisboss | http://www.freecodecamp.com/travisboss
Norman Dela Cruz
@dcnr
Feb 21 2016 03:43
@leo81202 an empty value would be value === "" yours is comparing to a space
Clarence W.
@leo81202
Feb 21 2016 03:44
@dcnr that was it....LOL!!!
Norman Dela Cruz
@dcnr
Feb 21 2016 03:44
xD you're no bother :D thanks too @Achmed4
CamperBot
@camperbot
Feb 21 2016 03:44
dcnr sends brownie points to @achmed4 :sparkles: :thumbsup: :sparkles:
Eric Mauser
@emauser2
Feb 21 2016 03:44

Working on the Spinal Tap Case challenge. I can see how to get 3 of the 4 cases, but I can't figure out how to get the second test case spinalCase("thisIsSpinalTap")

any suggestions?

function spinalCase(str) {
  // "It's such a fine line between stupid, and clever."
  // --David St. Hubbins
  str = str.toLowerCase();
  var str2=str.replace(/ /g, '-');
  var str3=str2.replace(/_/g,'-');
  return str3;
}

spinalCase('The_Andy_Griffith');
CamperBot
@camperbot
Feb 21 2016 03:44
:star: 211 | @achmed4 | http://www.freecodecamp.com/achmed4
Norman Dela Cruz
@dcnr
Feb 21 2016 03:45
@emauser2 if you're set on using replace, you could use backreferences to capture a lowercase followed by an uppercase and insert the - between
@emauser2 something like
...replace(/*pattern here*/, "$1-$2");
you can solve this with one pattern too
Eric Mauser
@emauser2
Feb 21 2016 03:50
@dcnr do you mean it can be solved with one pattern in the code you suggested, or one pattern of a completely different kind?
Norman Dela Cruz
@dcnr
Feb 21 2016 03:52
@emauser2 I mean all the test cases can be solved with one pattern . For example your two replace can be rewritten as
.replace(/[_ ]/g, '-');
you'll have to add what I suggested though, because that only solves underscores and spaces
George Phalen
@gphalen
Feb 21 2016 03:53
Stuck on #209. I've written a series of if/else if statements to differentiate card numbers, but regardless of the card it just adds 1 to count

var count = 0;

function cc(card) {
// Only change code below this line

if (card===2||3||4||5||6){
count=count+1;
}

else if (card===7||8||9){
count=count+0;
}

else if (card===10||'J'||'Q'||'K'||'A'){
count=count-1;
}

if (count>0){
return (count+" Bet");
}

else if (count<=0){
return (count+" Hold");

}

return "Change Me";
// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(10); cc(10); cc(10); cc(10); cc('A');
cc(10); cc(10); cc(10); cc(10); cc('A');
cc(7); cc(7); cc(7); cc(7); cc(7);

Clarence W.
@leo81202
Feb 21 2016 03:54
@gphalen do the ''' before and after the code
CamperBot
@camperbot
Feb 21 2016 03:54
:bulb: to format code use backticks! ``` more info
Norman Dela Cruz
@dcnr
Feb 21 2016 03:54
@gphalen hi you can't "shortcut" your conditionals it should be
if (card === 2 || card === 3 || card === 4) ... etc
Susan Winters
@susanwinters214
Feb 21 2016 03:54
I just did that one tonight. You don't have to check for 7-9 because they are zero
I used a switch statement.
Clarence W.
@leo81202
Feb 21 2016 03:55
@gphalen a switch would work for shortcutting
Norman Dela Cruz
@dcnr
Feb 21 2016 03:55
yeah you can cascade the case and break where appropriate
case 1:
case 2:
case 3:
  // do something
  break;
// also works written like this
case 4: case 5: case 6:
 // etc
George Phalen
@gphalen
Feb 21 2016 03:57
OK, thanks everyone, got it working
Dulshani Gunawardhana
@dshgna
Feb 21 2016 04:03
@dcnr: regarding your answer to the Spinal Tap Case challenge. Is there a possible way to do the check for spinalTapCase inside just one replace()? This is what I had done
function spinalCase(str) { 
  if(/([a-z][A-Z])/g.test(str)){ 
    str = str.split(/(?=[A-Z])/g).join(' ');
  }
  str = str.toLowerCase().replace(/[-_\s]/g, "-");
  return str;
}
sudheerswamy
@sudheerswamy
Feb 21 2016 04:04

var myVar = 87;

// Only change code below this line
myVar = 87;

myVar should equal 88
Use the ++ operator
Do not change code above the line
Eric Mauser
@emauser2
Feb 21 2016 04:05
@dcnr thanks
CamperBot
@camperbot
Feb 21 2016 04:05
emauser2 sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
:star: 674 | @dcnr | http://www.freecodecamp.com/dcnr
sudheerswamy
@sudheerswamy
Feb 21 2016 04:05
help needed
CamperBot
@camperbot
Feb 21 2016 04:05
no wiki entry for: needed
sudheerswamy
@sudheerswamy
Feb 21 2016 04:05
myVar should equal 88
Use the ++ operator
Do not change code above the line
myVar should equal 88
Use the ++ operator
Do not change code above the line
Norman Dela Cruz
@dcnr
Feb 21 2016 04:06
@dshgna
I did it like this
function spinalCase(str) {

  return str
    .replace(/[_ ]|([a-z])([A-Z])/g, '$1-$2')
    .toLowerCase();
}
Dulshani Gunawardhana
@dshgna
Feb 21 2016 04:08
@dcnr oh that's neat! '$1-$2' would essentially mean the first and second words in each consecutive word pairs right?
Norman Dela Cruz
@dcnr
Feb 21 2016 04:09
@dshgna yeah the $1 would refer to the first () which is the lowercase one ([a-z]) and the $2 would be the second () which is the uppercase one ([A-Z])
they're called backreference
Dulshani Gunawardhana
@dshgna
Feb 21 2016 04:11
@dcnr and in the case where the match is underscore or space $1 would be the space?
Norman Dela Cruz
@dcnr
Feb 21 2016 04:11
@dshgna oh no, $1 would be nothing because it only references the ones in () and the _ and isn't
so in that case, they are just replaced by - because $1 and $2 are nothing
Dulshani Gunawardhana
@dshgna
Feb 21 2016 04:14
@dcnr oh...a bit confusing there would you mind expanding please?
Norman Dela Cruz
@dcnr
Feb 21 2016 04:14
@dshgna
for example:
"thisIs"
/([a-z])([A-Z])/ would match `sI`
$1 = 's'
$2 = 'I'
and since we told replace to do it like $1-$2
it would be s-I

so the final string would be

"this-Is"
Dulshani Gunawardhana
@dshgna
Feb 21 2016 04:16
@dcnr yes...so ()s are placeholders to refer to $1 and $2, is that right?
Norman Dela Cruz
@dcnr
Feb 21 2016 04:16
@dshgna yes in the order they are used
that's why $1 is the lowercase because it came before the second one $2
Dulshani Gunawardhana
@dshgna
Feb 21 2016 04:17
in [], no placeholders are given, so no $1, $2 so they are simply replaced by -?
Norman Dela Cruz
@dcnr
Feb 21 2016 04:17
yeah
Dulshani Gunawardhana
@dshgna
Feb 21 2016 04:17
that makes sense! thanks very much @dcnr
CamperBot
@camperbot
Feb 21 2016 04:17
dshgna sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
Norman Dela Cruz
@dcnr
Feb 21 2016 04:17
think of them () like groupings
CamperBot
@camperbot
Feb 21 2016 04:17
:star: 675 | @dcnr | http://www.freecodecamp.com/dcnr
Norman Dela Cruz
@dcnr
Feb 21 2016 04:17
which you refer back using $num
Dulshani Gunawardhana
@dshgna
Feb 21 2016 04:18
@dcnr understood!!! thanks!
CamperBot
@camperbot
Feb 21 2016 04:18
dshgna sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
:warning: dshgna already gave dcnr points
Norman Dela Cruz
@dcnr
Feb 21 2016 04:20
you're welcome, thanks too @dshgna you can play around with regex on sites like https://regex101.com/ or http://regexr.com/
CamperBot
@camperbot
Feb 21 2016 04:20
dcnr sends brownie points to @dshgna :sparkles: :thumbsup: :sparkles:
:star: 184 | @dshgna | http://www.freecodecamp.com/dshgna
Norman Dela Cruz
@dcnr
Feb 21 2016 04:23
@dshgna https://regex101.com/r/sI0lH0/1 :D look at the explanations on the right side
and the group hits/match information
Dulshani Gunawardhana
@dshgna
Feb 21 2016 04:25
@dcnr I used regex101, but only exactly understood groupings with $num after your explanation :) Its amazing how regex can make everythng much simpler!
Norman Dela Cruz
@dcnr
Feb 21 2016 04:25
@dshgna yeah, if only the patterns were so easy to make :P
@dshgna powerful stuff though if you want to filter data
Dulshani Gunawardhana
@dshgna
Feb 21 2016 04:26
@dcnr understanding regex is tough :( but regex101 does a MUCH better job than other sites I've used
Norman Dela Cruz
@dcnr
Feb 21 2016 04:28
@dshgna yeah I really like the pattern explanation, matching information, and there's also easy quick reference
sudheerswamy
@sudheerswamy
Feb 21 2016 04:33

function convert(celsius) {
// Only change code below this line

// Only change code above this line
if ( typeof fahrenheit !== 'undefined' ) {
return fahrenheit;
} else {
return 'fahrenheit not defined';
}
}

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

Create a variable fahrenheit and apply the algorithm to assign it the corresponding temperature in Fahrenheit.
help required!!
CamperBot
@camperbot
Feb 21 2016 04:34
no wiki entry for: required
sudheerswamy
@sudheerswamy
Feb 21 2016 04:34
help needed!
CamperBot
@camperbot
Feb 21 2016 04:34
no wiki entry for: needed
sudheerswamy
@sudheerswamy
Feb 21 2016 04:34
help
CamperBot
@camperbot
Feb 21 2016 04:34

Hi, I'm CamperBot! I can help you in this chatroom :smile:

Basic Commands:

  • find TOPIC find all entries about topic. ex: find js
  • wiki TOPIC show contents of topic page
  • thanks @username send brownie points to another user
  • about @username shows info on that user
  • Algorithm BONFIRENAME info on a Algorithm

:speech_balloon: meet CamperBot in this room!

:pencil: read more about camperbot on the FCC Wiki

sudheerswamy
@sudheerswamy
Feb 21 2016 04:35

@sudheerswmay
function convert(celsius) {
// Only change code below this line

// Only change code above this line
if ( typeof fahrenheit !== 'undefined' ) {
return fahrenheit;
} else {
return 'fahrenheit not defined';
}
}

// Change the inputs below to test your code
convert(30);
Create a variable fahrenheit and apply the algorithm to assign it the corresponding temperature in Fahrenheit.
help required!

help?
CamperBot
@camperbot
Feb 21 2016 04:36

Hi, I'm CamperBot! I can help you in this chatroom :smile:

Basic Commands:

  • find TOPIC find all entries about topic. ex: find js
  • wiki TOPIC show contents of topic page
  • thanks @username send brownie points to another user
  • about @username shows info on that user
  • Algorithm BONFIRENAME info on a Algorithm

:speech_balloon: meet CamperBot in this room!

:pencil: read more about camperbot on the FCC Wiki

sudheerswamy
@sudheerswamy
Feb 21 2016 04:36
Algorithm BONFIRENAME
cannelflow
@cannelflow
Feb 21 2016 04:37
@sudheerswmay f = c*(9/5)+32;
sudheerswamy
@sudheerswamy
Feb 21 2016 04:39
@cannelflow function convert(celsius) {
// Only change code below this line
// Only change code above this line
if ( typeof fahrenheit !== 'undefined' ) {
return fahrenheit;
} else {
return 'fahrenheit not defined';
}
}
// Change the inputs below to test your code
convert(30);
Create a variable fahrenheit and apply the algorithm to assign it the corresponding temperature in Fahrenheit.
help please
CamperBot
@camperbot
Feb 21 2016 04:40

:point_right: algorithm no repeats please [wiki]

Problem Explanation:

  • This task requires us to look at each possible permutation of a string. This is best done using a recursion function. Being able to build a function which collects all permutations of a string is a common interview question, so there is no shortage of tutorials out there on how to do this, in many different code languages.
  • This task can still be daunting even after watching a tutorial. You will want to send each new use of the function 3 inputs: 1. a new string (or character array) that is being built, 2. a position in your new string that's going to be filled next, and 3. an idea of what characters (more specifically positions) from the original string have yet to be used. The pseudo code will look something like this:

    ```
    var str = ???;
    perm(current position in original string, what's been used in original string, current string build thus far){
    if(current string is finished) {
    print current string;
    }else{
    for(var i = 0; i < str.length; i++) {

    if(str[i] has not been used) {
      put str[i] into the current position;
      mark str[i] as used
      perm(current position in original string, what's been used in original string, current string build thus far)
      unmark str[i] as used because another branch in the tree for i + 1 will still likely use it;
    }

    }
    }
    }
    :pencil: read more about algorithm no repeats please on the FCC Wiki

cannelflow
@cannelflow
Feb 21 2016 04:40
@sudheerswmay what are you not getting
sudheerswamy
@sudheerswamy
Feb 21 2016 04:41
@cannelflow I have no clue with this piece of code
cannelflow
@cannelflow
Feb 21 2016 04:42
@sudheerswmay if you want to convert C to F then formula is f = c*(9/5)+32;
sudheerswamy
@sudheerswamy
Feb 21 2016 04:43
@cannelflow how to change this in code
cannelflow
@cannelflow
Feb 21 2016 04:43
var fahrenheit = celsius*(9/5)+32; @sudheerswmay
sudheerswamy
@sudheerswamy
Feb 21 2016 04:43

@cannelflow function convert(celsius) {
// Only change code below this line

// Only change code above this line
if ( typeof fahrenheit !== 'undefined' ) {
return fahrenheit;
} else {
return 'fahrenheit not defined';
}
}

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

cannelflow
@cannelflow
Feb 21 2016 04:44
function convert(celsius) {
// Only change code below this line
write your formula here
// Only change code above this line
if ( typeof fahrenheit !== 'undefined' ) {
return fahrenheit;
} else {
return 'fahrenheit not defined';
}
}
// Change the inputs below to test your code
convert(30);
@sudheerswmay
sudheerswamy
@sudheerswamy
Feb 21 2016 04:44
@cannelflow Thanks
CamperBot
@camperbot
Feb 21 2016 04:44
sudheerswmay sends brownie points to @cannelflow :sparkles: :thumbsup: :sparkles:
:star: 814 | @cannelflow | http://www.freecodecamp.com/cannelflow
cannelflow
@cannelflow
Feb 21 2016 04:44
@sudheerswmay :+1:
Austin Thornley
@AustinThornley
Feb 21 2016 04:47
Will anyone help me with this? What am I doing wrong?
function convert(celsius) {
  // Only change code below this line
  var fahrenheit = celsius * 9/5 + 32;

  // Only change code above this line
  if ( typeof fahrenheit !== 'undefined' ) {
    return fahrenheit;
  } else {
    return 'fahrenheit not defined';
  }
}

// Change the inputs below to test your code
convert(-30);
Brian
@sludge256
Feb 21 2016 04:49
seems fine
Austin Thornley
@AustinThornley
Feb 21 2016 04:50
@sludge256 It's not working :/
@sludge256 Never mind, just refreshed and it worked lol
arjunpunnam
@arjunpunnam
Feb 21 2016 04:59

``
function chunk(arr, size) {
// Break it up.
var div = Math.floor(arr.length/size);
var myArr = [];
//var rem = y % x;
//console.log(arr.slice(4,6));
for(i=0;i<arr.length;i+2){
console.log(arr.slice(i,i+2));
}

return arr;
}

chunk(["a", "b", "c", "d"], 2);
~~

``
function chunk(arr, size) {
// Break it up.
var div = Math.floor(arr.length/size);
var myArr = [];
//var rem = y % x;
//console.log(arr.slice(4,6));
for(i=0;i<arr.length;i+2){
console.log(arr.slice(i,i+2));
}

return arr;
}

chunk(["a", "b", "c", "d"], 2);
``

function chunk(arr, size) {
  // Break it up.
  var div = Math.floor(arr.length/size);
  var myArr = [];
  //var rem = y % x;
  //console.log(arr.slice(4,6));
 for(i=0;i<arr.length;i+2){  
   console.log(arr.slice(i,i+2));
   }

  return arr;
}

chunk(["a", "b", "c", "d"], 2);
can anyone help me in this?
why is my console.log(arr.slice(i,i+2)); entering into an infinite loop
Bakari Holmes
@bakarih
Feb 21 2016 05:05
I'm working on arguments optional in the intermediate algorithm challenges. My code gives proper return values for every case as far as I can tell except undefined. When running in the FCC editor the console just hangs up and says "testing challenge..." . HELP please?!?!? My code is here. I've run it in JS bin: http://jsbin.com/hadicojehe/edit?html,js,console,output
help format
CamperBot
@camperbot
Feb 21 2016 05:05

:point_right: code formatting [wiki]

Inline code

This an inline `<paste code here>` code formatting with a single backtick(`) at start and end around the code.

Code Block

```js ⇦ Type 3 backticks and then press [shift + enter ⏎] (type js or html or css)

<paste your code here>,
then press [shift + enter ⏎]

``` ⇦ Type 3 backticks, then press [enter ⏎]

See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics

:pencil: read more about code formatting on the FCC Wiki

Bakari Holmes
@bakarih
Feb 21 2016 05:07
function isNumber(arg)
{
  if (typeof arg === 'number')
  {
    return true;
  }
  else return false;
}

function add() 
{
  if (arguments.length === 2)
  { 
    if (isNumber(arguments[0]) && isNumber(arguments[1]))
    {
      return arguments[0] + arguments[1];
    }
    else return undefined;
  }
  else if (arguments.length === 1)
  {
    var x = arguments[0];
    return function(y)
    {
      if (isNumber(x) && isNumber(y))
      {
        return x + y;
      }
      else return undefined;
    };
  }
}
Bartek
@dyczol
Feb 21 2016 05:08
@dcnr thanks. Palindrome function worked !
CamperBot
@camperbot
Feb 21 2016 05:08
dyczol sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
:star: 676 | @dcnr | http://www.freecodecamp.com/dcnr
Norman Dela Cruz
@dcnr
Feb 21 2016 05:14
@bakarih hi add("http://bit.ly/IqT6zt") gives that error because it's returning your closure, and I think it's waiting for input. That test case should be returning undefined instead of your closure
@dyczol hi I don't really know what I contributed but thanks too xD
CamperBot
@camperbot
Feb 21 2016 05:14
dcnr sends brownie points to @dyczol :sparkles: :thumbsup: :sparkles:
:star: 251 | @dyczol | http://www.freecodecamp.com/dyczol
Bakari Holmes
@bakarih
Feb 21 2016 05:15
@dcnr oooooh.
So you're saying the "return undefined" should be outside the closure?
Norman Dela Cruz
@dcnr
Feb 21 2016 05:17
@bakarih if you only have one argument, check first if it's a number before you return a closure :D
Olivia Legge
@livmaria7891
Feb 21 2016 05:17
Can anyone explain to me how this piece of code works to turn the arguments into an array?
var args = Array.prototype.slice.call(arguments);
Trevor Baker
@noizehack
Feb 21 2016 05:21
I think I have a recursive function that is breaking a challenge page, but it froze up and I can't delete the code to fix it. I tried reloading but that doesn't help. anyone know how to fix this?
Norman Dela Cruz
@dcnr
Feb 21 2016 05:22
@noizehack https://github.com/FreeCodeCamp/FreeCodeCamp/wiki/Loop-Protect try the disable auto run part, or clear your browser cache
Bakari Holmes
@bakarih
Feb 21 2016 05:22
@dcnr Thanks!!! Got it working!
CamperBot
@camperbot
Feb 21 2016 05:22
bakarih sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
:star: 677 | @dcnr | http://www.freecodecamp.com/dcnr
Trevor Baker
@noizehack
Feb 21 2016 05:22
@dcnr thanks
Bakari Holmes
@bakarih
Feb 21 2016 05:23
@dcnr also had to refresh my browser
shivamteotia
@shivamteotia
Feb 21 2016 05:23
i am stuck on counting cards .please help me
Jorge Alfonso Zendejas Garcia
@zgjorge
Feb 21 2016 05:28
function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line
  for (var i=0; i<arr.lenght; i++){
    for (var j=0; j<arr[i]; j++)
      {
      product += arr[i]*[j];

        //product=9;
        //console.log(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]]);
Modify function multiplyAll so that it multiplies the product variable by each number in the sub-arrays of arr
I dont know what Im doing wrong, maybe all my code is wrong, can someone guide me?
Norman Dela Cruz
@dcnr
Feb 21 2016 05:30

@livmaria7891 call allows you to invoke a function on something by giving call a this value and the arguments you want. In this case, it's calling slice on the arguments object since the arguments isn't an array you can do arguments.slice() but it works because it's array like.
so for example

Array.prototype.slice.call(arguments, 1);

Will give you the arguments from the first index. It would be something like arguments.slice(1) if arguments were an array.

M. Matthews
@mmatthews1981
Feb 21 2016 05:31
@zgjorge arr.length is misspelled, for a start
Olivia Legge
@livmaria7891
Feb 21 2016 05:32
@dcnr Thank you :)
CamperBot
@camperbot
Feb 21 2016 05:32
livmaria7891 sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
:star: 678 | @dcnr | http://www.freecodecamp.com/dcnr
Caleb Martin
@caleb272
Feb 21 2016 05:32
function destroyer(arr) {
  var seekNDestroy = (arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments));

  arr = arr.filter(function(current) {

    for (var index=1; index < seekNDestroy.length; index++) {
      if (current == seekNDestroy[index]) {
        return false;
      }
    }

    return true;
  });

  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 'mystring', 3);
could someone review this and tell me if its a good implementation
Norman Dela Cruz
@dcnr
Feb 21 2016 05:32

@livmaria7891 Another example

var result = Array.prototype.every.call(arguments, Number.isInteger);

This will apply Number.isInteger on each of argumentsand if all of them are integers, result will be true

@livmaria7891 I'm sorry I can't succinctly explain call or apply or bind but I hope you get it somewhat. You should look those functions up :D
Jorge Alfonso Zendejas Garcia
@zgjorge
Feb 21 2016 05:33
@meredithmatthews lol true, i change it, still not working :(
M. Matthews
@mmatthews1981
Feb 21 2016 05:34
@dcnr Ooh, I needed that and integer check and I didn't even know it until right this second.
Olivia Legge
@livmaria7891
Feb 21 2016 05:34
@dcnr I should! Thanks!
CamperBot
@camperbot
Feb 21 2016 05:34
livmaria7891 sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
:warning: livmaria7891 already gave dcnr points
M. Matthews
@mmatthews1981
Feb 21 2016 05:35
@zgjorge which challenge is it?
Jorge Alfonso Zendejas Garcia
@zgjorge
Feb 21 2016 05:36
@meredithmatthews Nesting For Loops
Norman Dela Cruz
@dcnr
Feb 21 2016 05:37
@caleb272 you could also use indexOf instead of looping in your filter function
M. Matthews
@mmatthews1981
Feb 21 2016 05:38
@zgjorge i see. you've got the right idea
Caleb Martin
@caleb272
Feb 21 2016 05:38
ok i will do that thanks @dcnr
CamperBot
@camperbot
Feb 21 2016 05:38
caleb272 sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
:star: 679 | @dcnr | http://www.freecodecamp.com/dcnr
budimanfix
@budimanfix
Feb 21 2016 05:39

Hello folk, many thing missing here, what is that ?? : function findLongestWord(str) {
var longestStr = 0;
var longestWord = 0 i< str.split ('');

return str.length;
}

Norman Dela Cruz
@dcnr
Feb 21 2016 05:39
@meredithmatthews where'd you need that snippet? I use a variation of it on arguments optional
Array.prototype.every.call(arguments, function(arg) { return typeof arg === 'number'; });
Jorge Alfonso Zendejas Garcia
@zgjorge
Feb 21 2016 05:39
@meredithmatthews let me try with push
M. Matthews
@mmatthews1981
Feb 21 2016 05:40
@zgjorge your syntax is off on your product += arr[i][j]; it should be ```product =arr[i][j];```
Caleb Martin
@caleb272
Feb 21 2016 05:40
ok i did that and it worked great
Jorge Alfonso Zendejas Garcia
@zgjorge
Feb 21 2016 05:41
function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line
  for (var i=0; i<arr.length; i++){
    for (var j=0; j<arr[i]; j++)
      {
      product += arr[i][j];

        //product=9;
        //console.log(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]]);
M. Matthews
@mmatthews1981
Feb 21 2016 05:41
product *=arr[i][j];
Jorge Alfonso Zendejas Garcia
@zgjorge
Feb 21 2016 05:41
@meredithmatthews something like this?
Norman Dela Cruz
@dcnr
Feb 21 2016 05:41
@zgjorge since you're multiplying it should be *= and not += :P
budimanfix
@budimanfix
Feb 21 2016 05:42
Hello folks, any wiki for this challenge?? : freecodecamp.com/challenges/find-the-longest-word-in-a-string
M. Matthews
@mmatthews1981
Feb 21 2016 05:42
@dcnr yes, in Arguments Optional. That's what I'm currently completely misunderstanding right now :)
Jorge Alfonso Zendejas Garcia
@zgjorge
Feb 21 2016 05:42
function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line
  for (var i=0; i<arr.length; i++){
    for (var j=0; j<arr[i]; j++)
      {
      product *= arr[i][j];

        //product=9;
        //console.log(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]]);
Norman Dela Cruz
@dcnr
Feb 21 2016 05:42
@zgjorge yes that's it! :D
M. Matthews
@mmatthews1981
Feb 21 2016 05:42
@zgjorge now you got it!
Jorge Alfonso Zendejas Garcia
@zgjorge
Feb 21 2016 05:43
@meredithmatthews still not working :(
Norman Dela Cruz
@dcnr
Feb 21 2016 05:43
@meredithmatthews I see! I like that bonfire, Arguments Optional, lots of things to play with
@zgjorge you should try to refresh your browser if you have correct answer but won't pass :D
@zgjorge sometimes you have clear cache in the worse case :(
Jorge Alfonso Zendejas Garcia
@zgjorge
Feb 21 2016 05:43
@dcnr let me try
M. Matthews
@mmatthews1981
Feb 21 2016 05:43
@zgjorge check your J for loop. You're missing a length
@zgjorge check to make sure your inner loop matches the structure of your outer loop
Norman Dela Cruz
@dcnr
Feb 21 2016 05:44
oh yeah nice catch @meredithmatthews
Jorge Alfonso Zendejas Garcia
@zgjorge
Feb 21 2016 05:45
@meredithmatthews yaaaay, now it worked, thank you :)
CamperBot
@camperbot
Feb 21 2016 05:45
zgjorge sends brownie points to @meredithmatthews :sparkles: :thumbsup: :sparkles:
:star: 301 | @meredithmatthews | http://www.freecodecamp.com/meredithmatthews
Norman Dela Cruz
@dcnr
Feb 21 2016 05:46
wiki find the longest word in a string
CamperBot
@camperbot
Feb 21 2016 05:46

:point_right: algorithm find the longest word in a string [wiki]

Explanation:

You have to go through each word and figure out which one is the longest and return not the word, but how many characters it has.

:pencil: read more about algorithm find the longest word in a string on the FCC Wiki

Norman Dela Cruz
@dcnr
Feb 21 2016 05:46
@budimanfix :point_up:
M. Matthews
@mmatthews1981
Feb 21 2016 05:47
@dcnr thanks :) do you think you could help me with Arguments Optional? Because I've completely hit the limit of my knowledge and I don't even understand the question the challenge is asking
CamperBot
@camperbot
Feb 21 2016 05:47
meredithmatthews sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
:star: 680 | @dcnr | http://www.freecodecamp.com/dcnr
Norman Dela Cruz
@dcnr
Feb 21 2016 05:47
@meredithmatthews sure I'll PM you
budimanfix
@budimanfix
Feb 21 2016 05:48
@dcnr Thank you :+1:
CamperBot
@camperbot
Feb 21 2016 05:48
budimanfix sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
:star: 681 | @dcnr | http://www.freecodecamp.com/dcnr
Norman Dela Cruz
@dcnr
Feb 21 2016 05:50
you're welcome, thanks too! @budimanfix you can directly look them up in the FCC wiki http://www.freecodecamp.com/wiki
Shaylee
@swheatley
Feb 21 2016 05:58
Accessing Nested Arrays in JSON hellp
var secondTree = myPlants.trees[list1];
cant figure it out need a hint
cannelflow
@cannelflow
Feb 21 2016 06:00
@swheatley myplant is an array and you don't need tree
Ken Haduch
@khaduch
Feb 21 2016 06:00
@swheatley - can you paste your code in here?
Shaylee
@swheatley
Feb 21 2016 06:00

var myPlants = [
{
type: "flowers",
list: [
"rose",
"tulip",
"dandelion"
]
},
{
type: "trees",
list: [
"fir",
"pine",
"birch"
]
}
];

// Only change code below this line

var secondTree = myPlants.type[trees1];

the 1 should be enclosed in brackets
casadaro
@Casadaro
Feb 21 2016 06:02
whats with
return math.random();
not working
cannelflow
@cannelflow
Feb 21 2016 06:02
var myPlants = [ <----myPlant is an array object here
  {  type: "flowers",<-------myPlant[0]
    list: [
      "rose",
      "tulip",
      "dandelion"
    ]
  },
  {
    type: "trees",<----myPlant[1]
    list: [
      "fir",
      "pine",<-----list[1]
      "birch"
    ]
  }  
];
@swheatley
Clarence W.
@leo81202
Feb 21 2016 06:02
@swheatley both need to be in brackets and use numbers
@Casadaro it should return a number between 0 and 1
1
Ken Haduch
@khaduch
Feb 21 2016 06:03

it might help if you look at the type of objects you have in a simple line:

myPlants = [ { x:7, list:[a, b, c ] },  { x:8, list:[a, b, c ] }  ];

If I got that right at this late hour - you can see that there are two objects in the outer array, and each object has a property that also contains an array... so you need to address it with the proper notation.

@swheatley - the second object in the array is accessed with [1], and then within that, there is a list, so you access it with .list, and the list is an array, so you then need array brackets to reference that stuff in it.
Shaylee
@swheatley
Feb 21 2016 06:05
@cannelflow
thanks
I got it
arjunpunnam
@arjunpunnam
Feb 21 2016 06:06
myData = arr.slice(j,j+size);
where Mydata is declared string
Shaylee
@swheatley
Feb 21 2016 06:06
@cannelflow makes sense that you are looking at the index of the array and then the object and then the index again
arjunpunnam
@arjunpunnam
Feb 21 2016 06:07
but when it prints as [Array[2], Array[2]]
cannelflow
@cannelflow
Feb 21 2016 06:07
@swheatley :+1:
casadaro
@Casadaro
Feb 21 2016 06:07
@leo when I use it in the Generate Random Fraction with JavaScript it give me errors
arjunpunnam
@arjunpunnam
Feb 21 2016 06:07
why is that,help please?
cannelflow
@cannelflow
Feb 21 2016 06:07
@arjunpunnam which exercise you are doing?
arjunpunnam
@arjunpunnam
Feb 21 2016 06:09
Chunky Monkey in Basic algo
Caleb Martin
@caleb272
Feb 21 2016 06:09
o that was a fun one ^
arjunpunnam
@arjunpunnam
Feb 21 2016 06:09
for(i=0;i<div;i++){
myData = arr.slice(j,j+size);
myArr.push(myData);
j=j+size;
}
console.log(myData);
return arr;
}
@cannelflow
this is looping through array and slicing it as per size
cannelflow
@cannelflow
Feb 21 2016 06:10
for(i=0;i<div;i++){ <---- i<div ?
   myData = arr.slice(j,j+size);
   myArr.push(myData);
   j=j+size;
   }
 console.log(myData);
  return arr;
}
@arjunpunnam
budimanfix
@budimanfix
Feb 21 2016 06:11
@dcnr I not find this on wiki by the way?? : .freecodecamp.com/challenges/find-the-longest-word-in-a-string
arjunpunnam
@arjunpunnam
Feb 21 2016 06:11
function chunk(arr, size) {
  // Break it up.
  var div = Math.floor(arr.length/size);
  var myData = '';
  var myArr  = [];
  var j = 0;
  //var rem = y % x;
  //console.log(arr.slice(4,6));
 for(i=0;i<div;i++){ 
   myData = arr.slice(j,j+size);
   myArr.push(myData);
   j=j+size;
   }
 console.log(myData);
  return arr;
}

chunk(["a", "b", "c", "d"], 2);
Rumen1982
@Rumen1982
Feb 21 2016 06:13
hey guys i need help in Stand in Line
cannelflow
@cannelflow
Feb 21 2016 06:13
@Rumen1982 ?
Rumen1982
@Rumen1982
Feb 21 2016 06:14
function queue(arr, item) {
 queue(1, 2); // Your code here

  return item;  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(queue(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
@cannelflow
i dont know wat to do @cannelflow
Elior Boukhobza
@mallowigi
Feb 21 2016 06:15
bf stand in line
cannelflow
@cannelflow
Feb 21 2016 06:15
Write a function queue which takes an array (arr) and a number (item) as arguments whicn is

function queue(arr, item) {
 Add the number to the end of the array, then remove the first element of array. The queue function should then return the element that was removed.
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(queue(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
@Rumen1982
CamperBot
@camperbot
Feb 21 2016 06:15
Sorry, can't find a bonfire called stand in line. [ Check the map? ]
cannelflow
@cannelflow
Feb 21 2016 06:15
Write a function queue which takes an array (arr) and a number (item) as arguments whicn is
below
function queue(arr, item) {
then Add the number to the end of the array, then remove the first element of array. The queue function should then return the element that was removed.
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(queue(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
@Rumen1982
Norman Dela Cruz
@dcnr
Feb 21 2016 06:15
@budimanfix oh you're right! I just type
wiki (challenge name)
Rumen1982
@Rumen1982
Feb 21 2016 06:16
Please give me an example on this code @cannelflow
cannelflow
@cannelflow
Feb 21 2016 06:17
@Rumen1982 inside your function fine a method to Add the number to the end of the array, then remove the first element of array. The queue function should then return the element that was removed.
Rumen1982
@Rumen1982
Feb 21 2016 06:18
how to add @cannelflow
cannelflow
@cannelflow
Feb 21 2016 06:18
push and shift method @Rumen1982
Rumen1982
@Rumen1982
Feb 21 2016 06:19
ohhooo.. @cannelflow
arjunpunnam
@arjunpunnam
Feb 21 2016 06:19
Hi @cannelflow did you missed my code?
cannelflow
@cannelflow
Feb 21 2016 06:19
@arjunpunnam working not yet good at debugging code
:worried:
arjunpunnam
@arjunpunnam
Feb 21 2016 06:20
i have a question,can i?
arr.slice(j,j+size); does it return an array
cannelflow
@cannelflow
Feb 21 2016 06:20
@arjunpunnam instead of div we can write arr.length
cuz you div is giving value 2 and arr.length is 4
arjunpunnam
@arjunpunnam
Feb 21 2016 06:21
yes we need only two iterations if the remainder is 0 @cannelflow
i have to add another condition if remainder isnt 0
cannelflow
@cannelflow
Feb 21 2016 06:22
chunk(["a", "b", "c", "d"], 2); <--- [arr],size
arr.length =4 you div is 2
@arjunpunnam
arjunpunnam
@arjunpunnam
Feb 21 2016 06:22
yes
@cannelflow
that means it iterates for 3 times and but the time i have my entire array sliced into three parts
by*
cannelflow
@cannelflow
Feb 21 2016 06:23
ok @arjunpunnam
arjunpunnam
@arjunpunnam
Feb 21 2016 06:23
but the thing is how to store that array into another array
array.push() takes only argumnts
and slice is returing array2
dogsdogsdogs123
@dogsdogsdogs123
Feb 21 2016 06:25
couldnt you just use a for loop to store one array into the other?
arjunpunnam
@arjunpunnam
Feb 21 2016 06:25
yes but im thinking of avoiding the second loop
dogsdogsdogs123
@dogsdogsdogs123
Feb 21 2016 06:25
can somebody tell me what i'm doing wrong with this switch statement

function myTest(val) {
var answer = "";
// Only change code below this line
switch(val){
case val === 1:
answer = "alpha";
break;
case val === 2:
answer = "beta";
break;
case val === 3:
answer = "gamma";
break;
case val === 4:
answer = "delta";
break;
}

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

// Change this value to test
myTest(2);

Rumen1982
@Rumen1982
Feb 21 2016 06:26
i still cant do that @cannelflow
Elior Boukhobza
@mallowigi
Feb 21 2016 06:26
you misunderstood the switch syntax @dogsdogsdogs123
cannelflow
@cannelflow
Feb 21 2016 06:26
@arjunpunnam see how it's output is https://repl.it/BolJ
@Rumen1982 paste your code
casadaro
@Casadaro
Feb 21 2016 06:26
This message was deleted
This message was deleted
cannelflow
@cannelflow
Feb 21 2016 06:26
@dogsdogsdogs123 which exercise?
Elior Boukhobza
@mallowigi
Feb 21 2016 06:26
it's
switch (variable) {
  case value: 
    ...
  case otherValue:
   ...
}
casadaro
@Casadaro
Feb 21 2016 06:27
I can’t figure out Generate Random Fraction with JavaScript
dogsdogsdogs123
@dogsdogsdogs123
Feb 21 2016 06:27
oh
ok
Rumen1982
@Rumen1982
Feb 21 2016 06:27
function queue(arr, item) {
  // Your code here

  return item;  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(queue(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
casadaro
@Casadaro
Feb 21 2016 06:28
it seems pretty straight forward.
Rumen1982
@Rumen1982
Feb 21 2016 06:28
@cannelflow
casadaro
@Casadaro
Feb 21 2016 06:28
This message was deleted
dogsdogsdogs123
@dogsdogsdogs123
Feb 21 2016 06:28
ok thanks
casadaro
@Casadaro
Feb 21 2016 06:29
function myFunction() { 
 return math.random();
}
cannelflow
@cannelflow
Feb 21 2016 06:29
@Rumen1982 ? paste your code
Rumen1982
@Rumen1982
Feb 21 2016 06:30

```
function queue(arr, item) {
// Your code here

return item; // Change this line
}

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

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

``` @cannelflow

function queue(arr, item) {
  // Your code here

  return item;  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(queue(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
@cannelflow
cannelflow
@cannelflow
Feb 21 2016 06:31
@Rumen1982 i don't find any method to Add the number to the end of the array, then remove the first element of array. The queue function should then return the element that was removed.
Rumen1982
@Rumen1982
Feb 21 2016 06:31
queue([], 1) should return 1
queue([2], 1) should return 2
queue([5,6,7,8,9], 1) should return 5
After queue(testArr, 10), myArr[4] should be 10
instruction @cannelflow
cannelflow
@cannelflow
Feb 21 2016 06:33
@Rumen1982 ok what methos you used to push a number
and shift a number
return item is doing what in your code?
Rumen1982
@Rumen1982
Feb 21 2016 06:35
function queue(arr, item) {
 queue.push([2], 1); // Your code here

  return item;  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(queue(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
@cannelflow
no return @cannelflow
cannelflow
@cannelflow
Feb 21 2016 06:37
function queue(arr, item) {
 queue.push([2], 1); // Your code here <===remove this do like arr.push(item);
  then return arr.shift()  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(queue(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
@Rumen1982
casadaro
@Casadaro
Feb 21 2016 06:41
can someome help me with Generate Random Fraction with JavaScript
Rumen1982
@Rumen1982
Feb 21 2016 06:42
Thanks a lot boss @cannelflow
CamperBot
@camperbot
Feb 21 2016 06:42
rumen1982 sends brownie points to @cannelflow :sparkles: :thumbsup: :sparkles:
:star: 816 | @cannelflow | http://www.freecodecamp.com/cannelflow
Norman Dela Cruz
@dcnr
Feb 21 2016 06:43
thanks @meredithmatthews
CamperBot
@camperbot
Feb 21 2016 06:43
dcnr sends brownie points to @meredithmatthews :sparkles: :thumbsup: :sparkles:
:star: 302 | @meredithmatthews | http://www.freecodecamp.com/meredithmatthews
Norman Dela Cruz
@dcnr
Feb 21 2016 06:44
@Casadaro hi what you got?
casadaro
@Casadaro
Feb 21 2016 06:46
@dcnr this thing is telling me to return a random decimal using math.random() so typed this
function myFunction() {
return math.random();
}
Norman Dela Cruz
@dcnr
Feb 21 2016 06:47
@Casadaro oh capitalization is important, since JS is case sensitive
@Casadaro it should be Math.random()
casadaro
@Casadaro
Feb 21 2016 06:48
thanks @dcnr
CamperBot
@camperbot
Feb 21 2016 06:48
casadaro sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
:star: 682 | @dcnr | http://www.freecodecamp.com/dcnr
Norman Dela Cruz
@dcnr
Feb 21 2016 06:48
you're welcome, thanks too @Casadaro
CamperBot
@camperbot
Feb 21 2016 06:48
dcnr sends brownie points to @casadaro :sparkles: :thumbsup: :sparkles:
casadaro
@Casadaro
Feb 21 2016 06:48
@dcnr thats the reason why friends shouldn’t let friends code tired
CamperBot
@camperbot
Feb 21 2016 06:48
:star: 238 | @casadaro | http://www.freecodecamp.com/casadaro
Norman Dela Cruz
@dcnr
Feb 21 2016 06:49
get some sleep! lol
casadaro
@Casadaro
Feb 21 2016 06:49
One letter held me up for an hour. @dcnr I read everything I could about Math.radom(), I thought I was loosing my mind!
Norman Dela Cruz
@dcnr
Feb 21 2016 06:51
@Casadaro hahah, yeah it's one of those things that can trip you up! For example String.fromCharCode() needs to be called like that instead of myString.fromCharCode()even though it's a string function you can't call it on your own string
Elior Boukhobza
@mallowigi
Feb 21 2016 07:01
it's a static method
Cam
@CamMakoJ
Feb 21 2016 07:30
help caesars cipher
CamperBot
@camperbot
Feb 21 2016 07:30

:point_right: algorithm caesars cipher [wiki]

Problem Explanation:

  • You need to write a function, which will take string encoded with
    Caesar cipher as a parameter and decode it.
  • The one used here is ROT13 where the value of the letter is
    shifted by 13 places.
    e.g. 'A' ↔ 'N', 'T' ↔ 'G'.
  • You have to shift it back 13 positions, such that 'N' ↔ 'A'.
:pencil: read more about algorithm caesars cipher on the FCC Wiki
budimanfix
@budimanfix
Feb 21 2016 07:41
Hi Folks, wich part should correct here : function findLongestWord(str) {
return str.split(' ')
.reduce(function(x,y) {
return str.length(x, y.length);
}, 0);
Luis
@zdrifted
Feb 21 2016 07:50
Introducing JavaScript Object Notation JSON <-- Which waypoint explains how to add an album to an already existing JSON object?
rocket
@rengas
Feb 21 2016 07:52
@Rushh Record collection shows how to update exsisting JSON object
Luis
@zdrifted
Feb 21 2016 07:52
I wish it was possible for external help resources/links to be added to the challenges. Maybe even approved notes or added explanations by other members
Luis
@zdrifted
Feb 21 2016 08:00
Sweet solved it, thank you @rengas
CamperBot
@camperbot
Feb 21 2016 08:00
rushh sends brownie points to @rengas :sparkles: :thumbsup: :sparkles:
:star: 232 | @rengas | http://www.freecodecamp.com/rengas
Neeraj Jha
@Jonsnow21
Feb 21 2016 08:02
hey
Luis
@zdrifted
Feb 21 2016 08:04
What's up Jonsnow21?
Neeraj Jha
@Jonsnow21
Feb 21 2016 08:06
nothing much
wbu?
about @Jonsnow21
CamperBot
@camperbot
Feb 21 2016 08:07
:star: 223 | @jonsnow21 | http://www.freecodecamp.com/jonsnow21
Luis
@zdrifted
Feb 21 2016 08:09
Nothing much, just working on challenges
Neeraj Jha
@Jonsnow21
Feb 21 2016 08:10
ohh js?
Rony Biram
@sanakrvb
Feb 21 2016 08:17
Hey all, so on this challenge I tried several things until this one worked. The thing is that I can't seem to explain to myself why this works. It seems obvious, but i'm not grasping it yet. I assigned the associating string to the result variable, but is the way I've done it the right way? Is it using val as an index inside of the lookup object?
// Setup
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"

  };

  result = lookup[val];

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

// Change this value to test
phoneticLookup("foxtrot");
Joseph
@revisualize
Feb 21 2016 08:17
Hello.
Rony Biram
@sanakrvb
Feb 21 2016 08:17
Hello @revisualize
Joseph
@revisualize
Feb 21 2016 08:18
That doesnt work?
Rony Biram
@sanakrvb
Feb 21 2016 08:20
It does work, but I can't seem to understand why. I've tried several things until I came up with this. But i'm not understanding why it works. Does lookup[val] mean that I'm using val as an index to search within lookup?
Joseph
@revisualize
Feb 21 2016 08:21
It works because you are looking inside of the object.
If you do lookup[foxtrot] what do you get?
Sorry I am missing quotes. I am on my phone.
You get the associated value of Frank
lookup["alpha"] returns "Adams"
If you have an array of 6,7,8,9 and do array2 what do you get?
array[2]
Rony Biram
@sanakrvb
Feb 21 2016 08:24
8
Joseph
@revisualize
Feb 21 2016 08:25
Instead of using array numbers you are able to associwte names to objects.
Rony Biram
@sanakrvb
Feb 21 2016 08:26
Yeah, I understand now. By typing lookup[val] I'm telling it to look inside the lookup object
Joseph
@revisualize
Feb 21 2016 08:26
Okay. Egat is vonfusing?
Wow go phone.
What is confusing.
Nevermind.
You get it now.
:D
Rony Biram
@sanakrvb
Feb 21 2016 08:27
Yeah, I do! Thank you @revisualize :)
CamperBot
@camperbot
Feb 21 2016 08:27
sanakrvb sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star: 606 | @revisualize | http://www.freecodecamp.com/revisualize
Emil Aasa
@emilaasa
Feb 21 2016 08:31
I have this code that I would ilke to run in the background and listen for changes
  8 const spawn = require('child_process').spawn;
  9 const pbpaste = spawn('pbpaste');
 10
 11 pbpaste.stdout.on('data', (data) => {
 12   console.log(`${data}`);
 13 });
It just runs the paste command in OS X
I would like to have node listen to changes in pbcopy/pbpaste and then write it to file
and run it as a service in the backgground
Anyone got some tips on what to google for?
Elior Boukhobza
@mallowigi
Feb 21 2016 08:35
to run in the background use pm2
Emil Aasa
@emilaasa
Feb 21 2016 08:36
Yeah that seems like a good solution, my current headache is the event listening
Elior Boukhobza
@mallowigi
Feb 21 2016 08:36
i dont know a lot about the clipboard, but there should be a package for that
Emil Aasa
@emilaasa
Feb 21 2016 08:37
The clipboard is figured out already, I can do all I want to do by calling my functions actively
My problem is setting up something that listens for changes
Elior Boukhobza
@mallowigi
Feb 21 2016 08:39
why changes? the clipboard is a stack, you should listen to pushes
Emil Aasa
@emilaasa
Feb 21 2016 08:41
Is it?
Seems to work like a single variable that gets overwritten
anyway, I just need to understand how I make a listener i guess
What to listen on will figure itself out
I probably just dont understand node well enough
this is client side tho
Emil Aasa
@emilaasa
Feb 21 2016 08:43
Yep I read thru the source on that one
Thats a perfect fit for client side stuff
My main idea is I pretty much just want clipboard history on my machine
and then I have some ideas on what to do with that later
Elior Boukhobza
@mallowigi
Feb 21 2016 08:44
yeah
Emil Aasa
@emilaasa
Feb 21 2016 08:45
Well thanks for your help @mallowigi , always helps to bounce things off people =)
CamperBot
@camperbot
Feb 21 2016 08:45
emilaasa sends brownie points to @mallowigi :sparkles: :thumbsup: :sparkles:
:star: 61 | @mallowigi | http://www.freecodecamp.com/mallowigi
Emil Aasa
@emilaasa
Feb 21 2016 08:45
I will keep digging
Elior Boukhobza
@mallowigi
Feb 21 2016 08:45
you can do this maybe
you can run an interval that reads the clipboard
badguy100
@badguy100
Feb 21 2016 08:49

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");

result = myNoun + myAdjective + myVerb + myAdverb;
Emil Aasa
@emilaasa
Feb 21 2016 08:51
yep @mallowigi I’ll keep trying =)
badguy100
@badguy100
Feb 21 2016 08:54
got it thanks
ingo
@milsson
Feb 21 2016 09:16
find seek
CamperBot
@camperbot
Feb 21 2016 09:16

find seek

:zero: algorithm seek and destroy

Mridul
@mridulmishra22
Feb 21 2016 09:22
Whats wrong in it:
badguy100
@badguy100
Feb 21 2016 09:24
Write a function queue which takes an array (arr) and a number (item) as arguments.
I have no idea what to do
Elior Boukhobza
@mallowigi
Feb 21 2016 09:26
darn the spaces! the spaces!
naassi
@naassi
Feb 21 2016 09:26
@budimanfix String.toLowerCase()
Cam
@CamMakoJ
Feb 21 2016 09:27
hi all
im struggling to access a value in my JSON object
var a = {
"quotes": {
"0": {
"author": "Aldo Leopold",
"quote": "To keep every cog and wheel is the first precaution of intelligent tinkering."
},
"1": {
"author": "Aldo Leopold",
"quote": "One swallow does not make a summer, but one skein of geese, cleaving the murk of March thaw, is the Spring."
},
trying this to access: document.getElementById("quote").innerHTML = a.quotes[i]quote;
nicjacob
@nicjacob
Feb 21 2016 09:30
@badguy100 just follow the description: add item at the end of arr, remove the first item, return the (former) first item. maybe some methods of this list can help you: http://www.w3schools.com/js/js_array_methods.asp
Cam
@CamMakoJ
Feb 21 2016 09:33
nvm got it figured
thx
badguy100
@badguy100
Feb 21 2016 10:09
arr.push("item");
arr.shift();
mdarafatiqbal
@mdarafatiqbal
Feb 21 2016 10:10
in the Title Case a Sentence:
whats wrong with my regular expression:
function titleCase(str) {

  str = str.split(/^[A-Za-z]/g);
  return str;
}

titleCase("I'm a little tea pot");
Ashraf-Farabi
@Ashraf-Farabi
Feb 21 2016 10:12
help Nesting For Loops
CamperBot
@camperbot
Feb 21 2016 10:12

:point_right: challenge nesting for loops [wiki]

Challenge: Nesting For Loops

If you have a multi-dimensional array, you can use the same logic as the prior Challenge to loop through both the array and any sub-arrays. Here is an example:

    var arr = [
      [1,2], [3,4], [5,6]
    ];
    for (var i=0; i < arr.length; i++) {
      for (var j=0; j < arr[i].length; j++) {
        console.log(arr[i][j]);
      }
    }

This outputs each sub-element in arr one at a time. Note that for the inner loop, we are checking the .length of arr[i], since arr[i] is itself an array.
:pencil: read more about challenge nesting for loops on the FCC Wiki

Markus Kiili
@Masd925
Feb 21 2016 10:14
@mdarafatiqbal I think you should do str=str.split(" "); Maybe some other variable name is better for an array of words.
mdarafatiqbal
@mdarafatiqbal
Feb 21 2016 10:15
@Masd925 - I need to Return the provided string with the first letter of each word capitalized.
Markus Kiili
@Masd925
Feb 21 2016 10:16
@mdarafatiqbal Are you trying to do the whole thing with regexp, or first make an array of words?
mdarafatiqbal
@mdarafatiqbal
Feb 21 2016 10:16
@Masd925 - for making array of words i'll have to split the words , right ?
Markus Kiili
@Masd925
Feb 21 2016 10:17
This message was deleted
@mdarafatiqbal You can make the array of words with str=str.split(" ");
You can then loop through the array and titlecase each word.
mdarafatiqbal
@mdarafatiqbal
Feb 21 2016 10:18
@Masd925 - Ahaan.....I'll try that and let you know in a min
Ameya Bapat
@ameyabap
Feb 21 2016 10:19
Is there auto suggest/complete in freecodecamp editor?
Ashraf-Farabi
@Ashraf-Farabi
Feb 21 2016 10:22
This message was deleted
function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line
  for (var i=0; i < arr.length; i++) {
  for (var j=0; j < arr[i].length; j++) {
  for (var k=0; k < arr[j].length; k++) {
    product = product * arr[i][j][k];
  }  
  }
}
  // Only change code above this line
  return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
Can I get some help with this? Instruction is to Modify function multiplyAll so that it multiplies the product variable by each number in the sub-arrays of arr
mdarafatiqbal
@mdarafatiqbal
Feb 21 2016 10:24
@Masd925 - Whats wrong?
  mystr = str.split(' ');
  for(var i = 0; i < mystr.length; i++){
    mystr = mystr[i].toUpperCase();
  }
  return mystr;
}
anthonygallina1
@anthonygallina1
Feb 21 2016 10:26
@ameyabap I havent seen one but you could get a linter in atom.
Neeraj Lad
@neeraj-lad
Feb 21 2016 10:32

Hi all! I am doing the Wiki Viewer project.
Here is the getJSON call I use:

$.getJSON(wikiURL, {dataType: "jsonp"}, function (data) {

and here is a sample wikiURL
https://en.wikipedia.org/w/api.php?action=opensearch&search=abc&format=jsonfm&?callback=
I am getting this error:
Refused to execute the script because its MIME type is not executable, & strict MIME type checking is enabled

Markus Kiili
@Masd925
Feb 21 2016 10:36
@mdarafatiqbal mystr[i]=... <- use the original word mystr[i] here to construct the titlecased word.
Also put var here var mystr=...
@mdarafatiqbal mystr is an array, so you access each word with mystr[i].
Neeraj Lad
@neeraj-lad
Feb 21 2016 10:46
@Masd925 could you tell me how to resolve the MIME type error?
sigursiguros
@sigursiguros
Feb 21 2016 10:48
  var range = [];
  var newRange = [];

  arr.sort(function(a, b){
    return a-b;
  });

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

  var max = range[range.length-1];
  var min = range[0];
  var count = 0;

  var checkLCM = function(arg) {
    for (var j=0; j<range.length; j++){
      if (arg % range[j] === 0){
      count += 1;
      }
    }
    return count;
  };

  var k = 1;

  while (k<1000) {
    if(checkLCM(max*k) === range.length){
      return max*k;
    }
    k++;
  }
}

smallestCommons([5,1]);
HI guys, please help me understand why my code is returning the number 10
Hi @neeraj-lad - I'm still trying
Markus Kiili
@Masd925
Feb 21 2016 10:48
@neeraj-lad Sorry, don't know about that.
Elior Boukhobza
@mallowigi
Feb 21 2016 10:49
you should debug step by step
Neeraj Lad
@neeraj-lad
Feb 21 2016 10:49
@sigursiguros could you explain your logic again?
Elior Boukhobza
@mallowigi
Feb 21 2016 10:50
also I suggest that you split up your code into smaller functions
this will be easier to debug and to test
sigursiguros
@sigursiguros
Feb 21 2016 10:51
@mallowigi I tried to do checkLCM(10) and it's not returning range.length
I have no idea why the while function returns 10
it's not equal to range.length*
Markus Kiili
@Masd925
Feb 21 2016 10:55
@sigursiguros All calls to checkLCM use the same count variable. Should you reset it on each call?
mdarafatiqbal
@mdarafatiqbal
Feb 21 2016 10:57

@Masd925 - This is the code:

  var mystr = str.split(' ');
  for(var i = 0; i < mystr.length; i++){
    mystr[i] = mystr[i].toUpperCase();
  }
  return mystr;
}

OutPut:

  ["I'M","A","LITTLE","TEA","POT"]
Markus Kiili
@Masd925
Feb 21 2016 10:59
@mdarafatiqbal It should be mystr[i] = mystr[i].charAt(0).toUpperCase()+... <- rest of word mystr[i] here lowercased.
mdarafatiqbal
@mdarafatiqbal
Feb 21 2016 10:59
what is charAt ?
Was it mentioned in any of the challenges ?
Markus Kiili
@Masd925
Feb 21 2016 11:00
@mdarafatiqbal It gives the character (string of length 1) from a string from given index.
Same as str[i] but somewhat better.
str.charAt(0) gives the first character from string str.
"catpants".charAt(0); // returns 'c'
sigursiguros
@sigursiguros
Feb 21 2016 11:02
@Masd925 thank you so much
CamperBot
@camperbot
Feb 21 2016 11:02
sigursiguros sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
sigursiguros
@sigursiguros
Feb 21 2016 11:02
it finally works
CamperBot
@camperbot
Feb 21 2016 11:02
:star: 1007 | @masd925 | http://www.freecodecamp.com/masd925
mdarafatiqbal
@mdarafatiqbal
Feb 21 2016 11:05
@Masd925 - Even though it is returning the initials in upper case, but it is not returning the rest of the letters
output is: [I,A,L,T,P]
why am i not able to use mystr[i][0]
Markus Kiili
@Masd925
Feb 21 2016 11:09
@mdarafatiqbal Could you post your code again.
mdarafatiqbal
@mdarafatiqbal
Feb 21 2016 11:10
sure
function titleCase(str) {

  var mystr = str.toLowerCase().split(' ');

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

    mystr[i] = mystr[i].charAt(0).toUpperCase();
  }
  return mystr.join('');
}

titleCase("I'm a little tea pot");

Also, the challenge details:

Title Case a Sentence
Return the provided string with the first letter of each word capitalized. Make sure the rest of the word is in lower case.

For the purpose of this exercise, you should also capitalize connecting words like "the" and "of".

Remember to use Read-Search-Ask if you get stuck. Write your own code.

Here are some helpful links:

String.split()

Markus Kiili
@Masd925
Feb 21 2016 11:15
@mdarafatiqbal mystr[i] = mystr[i].charAt(0).toUpperCase()+....; <- you have to concat the rest of the word here lowercased. Use substr(), substring(), or slice() on the original word mystr[i].
mdarafatiqbal
@mdarafatiqbal
Feb 21 2016 11:17
@Masd925 - Worked! Thanks
CamperBot
@camperbot
Feb 21 2016 11:17
mdarafatiqbal sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1008 | @masd925 | http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Feb 21 2016 11:17
@mdarafatiqbal You're wellcome.
sigursiguros
@sigursiguros
Feb 21 2016 11:18
thanks @Rafase282
CamperBot
@camperbot
Feb 21 2016 11:18
sigursiguros sends brownie points to @rafase282 :sparkles: :thumbsup: :sparkles:
:star: 991 | @rafase282 | http://www.freecodecamp.com/rafase282
Neil Ebrey
@Ebsy
Feb 21 2016 11:47
Guys, is there a problem with the Steamroller algo?
Markus Kiili
@Masd925
Feb 21 2016 11:48
@Ebsy What is your problem with it?
Neil Ebrey
@Ebsy
Feb 21 2016 11:48
my code isn't passing even though it's correct. (I bet you've never heard that one before! ;))
Markus Kiili
@Masd925
Feb 21 2016 11:49
@Ebsy Post your code please.
Markus Kiili
@Masd925
Feb 21 2016 11:50
@Ebsy Variables must be declared inside the function, so FCC can test them properly.
Neil Ebrey
@Ebsy
Feb 21 2016 11:51
ah ha! I had no idea
ok, done :) thanks @Masd925
CamperBot
@camperbot
Feb 21 2016 11:52
ebsy sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1010 | @masd925 | http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Feb 21 2016 11:52
@Ebsy I wrote the answer before you posted your code :) So common to face the issue on this challenge.
ParisGlynn
@ParisGlynn
Feb 21 2016 11:52
Hi, can anyone help? Here is my code for challenge 224 'Profile lookup' I cannot see where I'm going wrong any tips would be great!
function lookUp(firstName, prop){
// Only change code below this line
for (var i = 0; i < contacts.length; i++) {
if (contacts[i][firstName] === firstName) {
if (contacts[i].hasOwnProperty(prop)) {
return contacts[i].prop;
}
else return "No such property";
}
}
return "No such contact";
}
Markus Kiili
@Masd925
Feb 21 2016 11:53
@ParisGlynn The dot notation doesn't work if the property key is in a variable like .prop here.
Neil Ebrey
@Ebsy
Feb 21 2016 11:53
haha nice one @Masd925 I tried three different browsers and emptied the cache before coming here. Thanks so much.
CamperBot
@camperbot
Feb 21 2016 11:53
ebsy sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: ebsy already gave masd925 points
Alex Tze
@Tze14
Feb 21 2016 11:53
function end(str, target) {

  return target == str.substr(str.length-1);


}

end("He has to give me a new name", "name");
How do I return the last word in a string and not letter? I'm at the Confirm the Ending challenge.
Neil Ebrey
@Ebsy
Feb 21 2016 11:53
@Tze14 split the string into an array and return the last element
Alex Tze
@Tze14
Feb 21 2016 11:54
alright
Markus Kiili
@Masd925
Feb 21 2016 11:55
@Tze14 No, don't! The only problem with your code is the substr argument.
No need to split anything.
Alex Tze
@Tze14
Feb 21 2016 11:56
yup
there might be a solution with splitting but it would take more
i wanna do it without splitting
what's wrong with the substr argument?
Neil Ebrey
@Ebsy
Feb 21 2016 11:56
haha, I'll be off now. Masd925 knows his stuff.
Alex Tze
@Tze14
Feb 21 2016 11:57
I mean, I know what's wrong but how do I adapt it?
@Masd925
Markus Kiili
@Masd925
Feb 21 2016 11:58
@Tze14 It should be so that the length of the returned string is the same as target length.
The argument is the starting index.
You can also use negative argument that will count backwards from the last index.
sigursiguros
@sigursiguros
Feb 21 2016 11:59
function telephoneCheck(str) {
  // Good luck!
  var re = /^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})$/;

  return re.test(str);

}



telephoneCheck("555-555-5555");
@Masd925 how should I go about understanding this code?
Moisés Man
@moigithub
Feb 21 2016 12:00
@Tze14 u can do math to change symbol
myNum * -1
or just prepend a minus -myNum
Markus Kiili
@Masd925
Feb 21 2016 12:01
@sigursiguros Beats be :) Someone here must love regexp.
Alex Tze
@Tze14
Feb 21 2016 12:01
I have not idea , you are both following a specific solution and I don;t see that, any hints?
no*
Moisés Man
@moigithub
Feb 21 2016 12:01
@sigursiguros http://regexone.com/ https://regex101.com/ and a lot more on google:)
Alex Tze
@Tze14
Feb 21 2016 12:02
i'll write the code and how I want to resolve it with comments and will write back to you, ok @Masd925 ?
sigursiguros
@sigursiguros
Feb 21 2016 12:02
thanks @Masd925 @moigithub
CamperBot
@camperbot
Feb 21 2016 12:02
sigursiguros sends brownie points to @masd925 and @moigithub :sparkles: :thumbsup: :sparkles:
:warning: sigursiguros already gave masd925 points
:star: 645 | @moigithub | http://www.freecodecamp.com/moigithub
Moisés Man
@moigithub
Feb 21 2016 12:02
@Tze14 first of all.. what this does ??
str.substr
and this.. str.length-1
Alex Tze
@Tze14
Feb 21 2016 12:03
did you run it?
Moisés Man
@moigithub
Feb 21 2016 12:04
no need to run.. if u know the syntax n what it does...
it does a comparation.. and return a boolean value...
based on target n whatever substr u picking up from str
probably the easier way to figure out.. is storing on variables... and use console.log to check whats ur code doing...
Alex Tze
@Tze14
Feb 21 2016 12:05
I know what my code is doing
wait
function end(str, target) {

  return target === str.substr(str.length-1);

}

end("He has to give me a new name", "name");
Moisés Man
@moigithub
Feb 21 2016 12:05
but u cant figure out whats wrong.. so
Alex Tze
@Tze14
Feb 21 2016 12:05
it's not that I don't know what's wrong
What I am asking is, how would I be able to return the last word in a string? What I am returning here is the last letter in a string of only one word. Check the Confirm the Ending .
challenge
Moisés Man
@moigithub
Feb 21 2016 12:07
function end(str, target) {
var test=str.substr(str.length-1);
console.log("test",test);
console.log("target",target):

  return target == test;
}

end("He has to give me a new name", "name");
then open devtools (f12 on most browsers) and check console
Markus Kiili
@Masd925
Feb 21 2016 12:07
@Tze14 That substr gives only the last character. You have to substract correct number from the argument to get a substring with the length target.length.
Ramsay Sewell
@ramsaysewell
Feb 21 2016 12:07
help Title Case a Sentence
CamperBot
@camperbot
Feb 21 2016 12:07

:point_right: algorithm title case a sentence [wiki]

Explanation:

We have to return a sentence with camel case. This means that the first letter will always be in uppercase and the rest lowercase.

:pencil: read more about algorithm title case a sentence on the FCC Wiki

Ramsay Sewell
@ramsaysewell
Feb 21 2016 12:07
How do I get the first letter of the string?
Markus Kiili
@Masd925
Feb 21 2016 12:08
@ramsaysewell str.charAt(0);
Ramsay Sewell
@ramsaysewell
Feb 21 2016 12:08
Thank you.
Markus Kiili
@Masd925
Feb 21 2016 12:08
@ramsaysewell It is a string on length 1 in Javascript. No special character type.
Moisés Man
@moigithub
Feb 21 2016 12:09
@ramsaysewell u can also use indices.. (like if it were an array)
myString[0]
Ramsay Sewell
@ramsaysewell
Feb 21 2016 12:09
@moigithub I’ve .split(“ “) the string so I need to use this. Thank you.
CamperBot
@camperbot
Feb 21 2016 12:09
ramsaysewell sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star: 646 | @moigithub | http://www.freecodecamp.com/moigithub
Alex Tze
@Tze14
Feb 21 2016 12:10
help Confirm the Ending
CamperBot
@camperbot
Feb 21 2016 12:10

:point_right: algorithm confirm the ending [wiki]

Explanation:

The function is a whole Boolean operation. You need to return true if the first argument ends with the second argument. This means that for the problem script, it should return true for the end('Bastian', 'n'); case.

:pencil: read more about algorithm confirm the ending on the FCC Wiki

Markus Kiili
@Masd925
Feb 21 2016 12:10
@moigithub .charAt has better browser support and also avoids mixing strings with arrays. Also using [ ] might lead one to assume you can set characters with str[i]=...
Ramsay Sewell
@ramsaysewell
Feb 21 2016 12:11
This is what I have got so far
function titleCase(str) {

  array = str.split(" ");


  for (var i = 0; i < array.length; i++) {
    array[i].toLowerCase();
    array[i].charAt[0].toUpperCase();
  }

  return str;
}

titleCase("I'm a little tea pot");
Markus Kiili
@Masd925
Feb 21 2016 12:12
@ramsaysewell Do array[i]=... <- construct the titlecased word here using the original word array[i].
Ramsay Sewell
@ramsaysewell
Feb 21 2016 12:12
help format
CamperBot
@camperbot
Feb 21 2016 12:12

:point_right: code formatting [wiki]

Inline code

This an inline `<paste code here>` code formatting with a single backtick(`) at start and end around the code.

Code Block

```js ⇦ Type 3 backticks and then press [shift + enter ⏎] (type js or html or css)

<paste your code here>,
then press [shift + enter ⏎]

``` ⇦ Type 3 backticks, then press [enter ⏎]

See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics

:pencil: read more about code formatting on the FCC Wiki

Ramsay Sewell
@ramsaysewell
Feb 21 2016 12:13
array[i] = array[i].charAt[0].toUpperCase(); ?
Markus Kiili
@Masd925
Feb 21 2016 12:13
.charAt(0)
Also concat the rest of string lowercased to that .
Use substring, substr, or slice.
Ramsay Sewell
@ramsaysewell
Feb 21 2016 12:16
Why would it be returning only the first letter?
Moisés Man
@moigithub
Feb 21 2016 12:17
wiki immutable
CamperBot
@camperbot
Feb 21 2016 12:17

:point_right: js immutable [wiki]

Immutable means unchangeable i.e. you can't change.

Javascript has lots of immutable types e.g. string primitive type. Try this in your console.

s = "red";
console.log(s[1]); //→ "e"
s[1] = "x";
console.log(s) //→ "red"

the s didn't change! WAT!

:pencil: read more about js immutable on the FCC Wiki

Markus Kiili
@Masd925
Feb 21 2016 12:22
@ramsaysewell Strings are immutable. All string methods return a new string that must be assigned somewhere in order to be used.
@ramsaysewell On array[i] = array[i].charAt(0).toUpperCase(); the right hand side returns the first character uppercased. The assignment operator assigns it to the array element.
Shweta Roy
@anu89
Feb 21 2016 12:25
Profile lookup in javascript... i am unable to select the key
Markus Kiili
@Masd925
Feb 21 2016 12:26
@anu89 Use bracket notation perhaps.
nicjacob
@nicjacob
Feb 21 2016 12:26
@Masd925 would array[i] = array[i][0].toUpperCase(); also work or is it better to use charAt(0)?