These are chat archives for FreeCodeCamp/HelpJavaScript

22nd
Apr 2016
Igor Amelichev
@igoramelichev
Apr 22 2016 00:02
Hey guys,
Edward Hilgendorf
@edhilgendorf
Apr 22 2016 00:02
Hello, I am a little confused about methods such as: reduce(), is it really expecting a function passed in as a parameter? Because the functions we pass in as practice just return a number..
Igor Amelichev
@igoramelichev
Apr 22 2016 00:03
Can someone help me out with the Assignment with a Returned Value lesson?
mjqblade
@mjqblade
Apr 22 2016 00:05

some help plz

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

it says Remove all the backslashes () plz help how would this look

Jackson Bates
@JacksonBates
Apr 22 2016 00:05
@edhilgendorf I found this helpful: https://m.youtube.com/watch?v=Wl98eZpkp-c
Aaron Preston
@AaronPreston
Apr 22 2016 00:06
Hey, so can someone explain to me how Array.prototype.filter(); works? I'm struggling with figuring out how to make use of it for the Seek and Destroy challenge.
mjqblade
@mjqblade
Apr 22 2016 00:06

plz help

Jackson Bates
@JacksonBates
Apr 22 2016 00:08
@AaronPreston another YouTube link, I found this one helpful for filter: https://m.youtube.com/watch?v=OmJDmPxDr4E
mjqblade
@mjqblade
Apr 22 2016 00:11

some help plz

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

it says Remove all the backslashes () plz help how would this look

Aaron Preston
@AaronPreston
Apr 22 2016 00:13
@mjqblade What challenge is that on FreeCodeCamp?
@JacksonBates I'll check it out. Thank you!
CamperBot
@camperbot
Apr 22 2016 00:14
aaronpreston sends brownie points to @jacksonbates :sparkles: :thumbsup: :sparkles:
:star: 330 | @jacksonbates | http://www.freecodecamp.com/jacksonbates
Edward Hilgendorf
@edhilgendorf
Apr 22 2016 00:15
thanks @JacksonBates
CamperBot
@camperbot
Apr 22 2016 00:15
edhilgendorf sends brownie points to @jacksonbates :sparkles: :thumbsup: :sparkles:
:star: 331 | @jacksonbates | http://www.freecodecamp.com/jacksonbates
Jackson Bates
@JacksonBates
Apr 22 2016 00:21
@mjqblade That exercise is making the point that whenever you have a " the next one will close whatever the quotes "contain" - this is a problem in the example you give because you want the whole <a href... included in quotes, but the second " closes it prematurely. They have used a backslash to 'escape' the " character, which works...but there is a cleaner way of quoting within quotes, without having to escape characters. If you can think of another way to represent a quotation mark so that it doesn't prematurely close the whole quote, use that to replace the \"...
Tyler
@tylergross
Apr 22 2016 00:26
I have a <span class="minutesLeft">25</span> how can i use javascript to retrieve this value? ive tried text() which is returned black, and ive tried val() and html() which return undefined. any ideas?
function getMinutes(){

   var input = $(".minutesLeft").text();
   alert(input);

}
Adam Age
@adamwage
Apr 22 2016 00:29
@tylergross try, var input = $(".minutesLeft").value;
Jackson Bates
@JacksonBates
Apr 22 2016 00:29
@tylergross Hey, I just tried your code and it works fine. Did you remember to call your function?
This message was deleted
@tylergross oops, forgot to save it :) try again: http://codepen.io/Malgalin/pen/zqWqqN?editors=1010
henrywashere
@henrywashere
Apr 22 2016 00:33
need help with this exercise!
Order is important in if, else if statements.

The loop is executed from top to bottom so you will want to be careful of what statement comes first.

Take these two functions as an example.

Heres the first:

function foo(x) {
  if (x < 1) {
    return "Less than one";
  } else if (x < 2) {
    return "Less than two";
  } else {
    return "Greater than or equal to two";
  }
}
And the second just switches the order of the statements:

function bar(x) {
  if (x < 2) {
    return "Less than two";
  } else if (x < 1) {
    return "Less than one";
  } else {
    return "Greater than or equal to two";
  }
}
While these two functions look nearly identical if we pass a number to both we get different outputs.

foo(0) // "Less than one"
bar(0) // "Less than two"
Instructions
Change the order of logic in the function so that it will return the correct statements in all cases.
Adam Age
@adamwage
Apr 22 2016 00:34
For your first "if" statement, make it the most specific rule @henrywashere
Jackson Bates
@JacksonBates
Apr 22 2016 00:34
@henrywashere What is your understanding of the problem and what have you tried?
Tyler
@tylergross
Apr 22 2016 00:34
@JacksonBates hmm so weird wonder if my html flow is causing this not to work for me. I think im going to go about this a different way, thanks though
CamperBot
@camperbot
Apr 22 2016 00:34
tylergross sends brownie points to @jacksonbates :sparkles: :thumbsup: :sparkles:
Adam Age
@adamwage
Apr 22 2016 00:34
So the bar(0); is running from the first rule stating "if(0 < 2)" and stops there because it returns true
CamperBot
@camperbot
Apr 22 2016 00:35
:star: 332 | @jacksonbates | http://www.freecodecamp.com/jacksonbates
henrywashere
@henrywashere
Apr 22 2016 00:36

well, this is what it says by default:

function orderMyLogic(val) {
  if (val < 10) {
    return "Less than 10";
  } else if (val < 5) {
    return "Less than 5";
  } else {
    return "Greater than or equal to 10";
  }
}

what exactly do i have to do?

Jackson Bates
@JacksonBates
Apr 22 2016 00:36
@tylergross I'd offer to look over the whole code, but I suspect you're doing the timer, and I'm not there yet, so I don't want to see spoilers :)
Adam Age
@adamwage
Apr 22 2016 00:36
@henrywashere what does it want your end result to be?
henrywashere
@henrywashere
Apr 22 2016 00:37
no idea lol
Tyler
@tylergross
Apr 22 2016 00:37
@JacksonBates I am doing the pomodoro clock, it's been a battle but I think It's coming along nicely not as hard as some of the algorithms are
Adam Age
@adamwage
Apr 22 2016 00:38
@henrywashere in the rules on the left what does it say should return?
Jackson Bates
@JacksonBates
Apr 22 2016 00:38
@tylergross don't get me started on the alorithms! I'm wading through the tail end of the intermediate ones and I'm tempted to just skip them and start building the calculator!
henrywashere
@henrywashere
Apr 22 2016 00:38
orderMyLogic(4) should return "Less than 5"
Tyler
@tylergross
Apr 22 2016 00:38
@JacksonBates that's exactly what I did, the calculator was a lot of fun and easy to create
Adam Age
@adamwage
Apr 22 2016 00:39
@henrywashere gotcha! Okay, so the reason the code returns "Les than 10" is because right now that's the first "if" statement it's running into.
buonarfcc
@buonarfcc
Apr 22 2016 00:39

Hi please help me with the codes ' situation -> still get all the last 3 result X Reds ! for these codes -<> var Bike = function(change) {

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

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

//var myCar = new Car();

var myBike = new Bike();
myBike.setGear(2);~~~

Adam Age
@adamwage
Apr 22 2016 00:39
@henrywashere and since that statement is true, it stops running through the function and just returns whatever is in there.
@henrywashere so in your case, you should put the most specific rule, "if(val < 5) {...}" first
henrywashere
@henrywashere
Apr 22 2016 00:40
i think i know what you mean
got it
thanks @adamwage
CamperBot
@camperbot
Apr 22 2016 00:40
henrywashere sends brownie points to @adamwage :sparkles: :thumbsup: :sparkles:
:star: 297 | @adamwage | http://www.freecodecamp.com/adamwage
Adam Age
@adamwage
Apr 22 2016 00:41
You're welcome, @henrywashere !
Moisés Man
@moigithub
Apr 22 2016 00:42
@buonarfcc setGear should set only.. not add
Adam Age
@adamwage
Apr 22 2016 00:43
@buonarfcc it looks like your first function "setGear()" isn't returning the "gear" variable;
buonarfcc
@buonarfcc
Apr 22 2016 00:44
txs Moises Man -> it is fixed now ! thnk Adam Age!
Adam Age
@adamwage
Apr 22 2016 00:45
@buonarfcc nice! :)
Moisés Man
@moigithub
Apr 22 2016 00:45
@adamwage "setters" no need to return.. thats "getters" job
henrywashere
@henrywashere
Apr 22 2016 00:45
@adamwage actually im a still a bit confused...why should val<5 go first??
Adam Age
@adamwage
Apr 22 2016 00:47
@henrywashere the reasoning is because, if you put the "val < 10" first, with the val == 4. Then the function tests, "is 4 < 10?" which returns "True".
@henrywashere so since that returned "True" it'll start running the code within the "val < 10" brackets and just stop there
henrywashere
@henrywashere
Apr 22 2016 00:48
but the same goes for 4<5?
Adam Age
@adamwage
Apr 22 2016 00:48
@henrywashere meaning it never reaches the test for "is 4 < 5?"
Moisés Man
@moigithub
Apr 22 2016 00:48
return exit the funciton immediatelly @henrywashere
Adam Age
@adamwage
Apr 22 2016 00:49
@henrywashere yeah, what @moigithub said. When a function "return"s something, it'll stop right there and not go further in the function
henrywashere
@henrywashere
Apr 22 2016 00:50
ok i get it now
Adam Age
@adamwage
Apr 22 2016 00:50
it's kind of like, if you're looking up the definition of a specific word in a dictionary, then you find that word. You don't continue reading the rest of the dictionary. You "return" that definition and stop there :P
henrywashere
@henrywashere
Apr 22 2016 00:50
thanks guys
thats a good analogy lol
Adam Age
@adamwage
Apr 22 2016 00:50
Haha, hope it helps :) @henrywashere
Ozan Araz
@haraldur12
Apr 22 2016 00:57
Could someone help me out please =
for (var i = 0; i < newStr.length ; i++)
{
if ( longest < newStr[i].length){
longest = newStr[i].length;
word = newStr[i];
I don't seem to understand how it works
Adam Age
@adamwage
Apr 22 2016 00:58
what’s going on, @haraldur12 ?
Paul Manning
@paulmanning
Apr 22 2016 00:59
@haraldur12 try breaking your string into an array first, by space, then iterate over that to test the string length.
var arItems = newStr.split(“ “);
...
Christian
@cenamorado1
Apr 22 2016 01:00
can anyone help with "factorialize a number"?
do I just add an exclamation point beside the integer?
Adam Age
@adamwage
Apr 22 2016 01:02
@cenamorado1 I wish it were that simple :P But you’ll have to come up with the algorithm yourself
@cenamorado1 you can use a for loop or while loop
96street
@96street
Apr 22 2016 01:16
How do I add speed to the slideToggle();?
var $more = $('#more');
var $navDropdown = $('.navDropdown');

function moreDropdown() {
  $more.on('click', function() {

    $navDropdown.slideToggle('navToggle');

  })
}

moreDropdown();
Adam Age
@adamwage
Apr 22 2016 01:19
@96street inside the parameter for .slideToggle() add a duration. It’ll be in milliseconds i.e. “.slideToggle(400)” is going to be .4 seconds
ManBearPigg
@ManBearPigg
Apr 22 2016 01:23
Alphabet has 26 letters. I want to test every possible group of 5 letters. How do I get those?
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 01:28
@ManBearPigg aaaaa(random)
aaaab(random),and so on
random has to be changed from a to z to test every letter
Chase Webb
@jerrybaggin
Apr 22 2016 01:32
var Car = function() {
  this.wheels = 4;
  this.engines = 1;
  this.seats = 1;
};

// Only change code below this line.

var myCar = new Car(
  this.nickname ="honda"
);
anyone point out what im doing incorrectly?
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 01:33
This message was deleted
@jerrybaggin name of the exercise?
Chase Webb
@jerrybaggin
Apr 22 2016 01:35
@UtkarshShukla7 Make Instances of Objects with a Constructor Function
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 01:35
ok
Frank XC
@tenkdayz
Apr 22 2016 01:35
@jerrybaggin Car ( <<<
should be new Car (){ ...
Moisés Man
@moigithub
Apr 22 2016 01:36
@jerrybaggin when u create a new Object.. u only do
var myVar = new MyObject();
or
var myVar = new MyObject(values);
but.. ur declaration dont accept any .. like thisvar Car = function(var1, var2) {
soo first one should be the correct way
96street
@96street
Apr 22 2016 01:38
When I add the duration it doesn't slide....
var $more = $('#more');
var $navDropdown = $('.navDropdown');

function moreDropdown() {
  $more.on('click', function() {

    $navDropdown.slideToggle(3000, 'navToggle');

  })
}

moreDropdown();
@adamwage
Chase Webb
@jerrybaggin
Apr 22 2016 01:38
var myCar = new Car(this.nickname ="honda"); so this isn't correct either?
Moisés Man
@moigithub
Apr 22 2016 01:39
nope
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 01:39
@jerrybaggin
var myCar= new Car();
myCar.nickname="";
96street
@96street
Apr 22 2016 01:39
it also doesn't 'toggle' just slideDown when you click it once
Brian D.
@bdeerwester
Apr 22 2016 01:41
hey everyone, i'm stuck on Javascript > Record Collection and am having trouble figuring out how to push info onto an array. i have the 1st, 2nd, and 4th checkmarks completed, just stuck on 3
'
if (prop === "tracks" && value !== "") {
collection[id][prop].push([value]);
}
'
Chase Webb
@jerrybaggin
Apr 22 2016 01:41
@UtkarshShukla7 @moigithub so with objects I don't need any sort of parentheses or just constructor functions?\
Brian D.
@bdeerwester
Apr 22 2016 01:42
i'm getting a "TypeError: collection[id][prop].push is not a function"
^also it doesn't work without the with just .push(value)
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 01:43
@jerrybaggin calling contructor functions alone create the objects
Chase Webb
@jerrybaggin
Apr 22 2016 01:44
@UtkarshShukla7 so the new is the contructor and the new Car is the name of the constructor. so new Car (); allows for the objects to be modified ?
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 01:45
@bdeerwester collection[id][prop].push(value);
Moisés Man
@moigithub
Apr 22 2016 01:45
@jerrybaggin parentesis yes needs.. also u can pass values to it... but depends hows ur "Class" definition is made
var Cat = function(){
  this.name = "miauxor"
}

var fufly = new Cat();
var Cat = function(name){
  this.name = name
}

var fufly = new Cat("lulu");
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 01:46
@jerrybaggin no car() function is the constructor . new is the keyword which tells javascript to create object
Brian D.
@bdeerwester
Apr 22 2016 01:47
@UtkarshShukla7 hey thanks! i've tried that too, still not passing the test for some reason...
CamperBot
@camperbot
Apr 22 2016 01:47
bdeerwester sends brownie points to @utkarshshukla7 :sparkles: :thumbsup: :sparkles:
:star: 344 | @utkarshshukla7 | http://www.freecodecamp.com/utkarshshukla7
Moisés Man
@moigithub
Apr 22 2016 01:47
@bdeerwester push only works on array
Chase Webb
@jerrybaggin
Apr 22 2016 01:48
@UtkarshShukla7 gotcha! thanks again!
CamperBot
@camperbot
Apr 22 2016 01:48
jerrybaggin sends brownie points to @utkarshshukla7 :sparkles: :thumbsup: :sparkles:
:star: 345 | @utkarshshukla7 | http://www.freecodecamp.com/utkarshshukla7
Moisés Man
@moigithub
Apr 22 2016 01:48
This message was deleted
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 01:48
@jerrybaggin np
Samuel Hickey
@samaugust
Apr 22 2016 01:50

For the exercise Record Collection, I am not understanding what is wrong with this code:
var item = collection[id];
if (value === "") {
return collection;
}
if (prop !== "tracks") {
item[prop] = value;
}
else if (prop === "tracks") {
item.tracks.push(value);
}

return collection;
}

Also, for future reference, how do I format the code so that it has that nice graphical interface I see people doing above
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 01:51
help format
CamperBot
@camperbot
Apr 22 2016 01:51

:point_right: code formatting [wiki]

Multi line Code

```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 ⏎]

Single line Code

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

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

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

Brian D.
@bdeerwester
Apr 22 2016 01:51
lol samuel, i'm stuck on the same problem right now
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 01:52
@samaugust read it
Islam Ibakaev
@dagman
Apr 22 2016 01:52
finally i have started my portfolio page and this is what i have done so far.
So what do u think guys? http://codepen.io/dagman/pen/WwKrgX
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 01:52
@bdeerwester paste your complete code so someone can help you
Brian D.
@bdeerwester
Apr 22 2016 01:53
function updateRecords(id, prop, value) {

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

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

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

  return collection;
}
wow just realized my first and second IF statments probably don't need to be checking the collection, should just be checking the id, prop, and value being fed in to the function
Wayne M. Davies
@WayneMDavies
Apr 22 2016 01:56
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 01:56
@bdeerwester :+1:
Brian D.
@bdeerwester
Apr 22 2016 01:57
@WayneMDavies @UtkarshShukla7 awesome, thanks for the help guys!
CamperBot
@camperbot
Apr 22 2016 01:57
bdeerwester sends brownie points to @waynemdavies and @utkarshshukla7 :sparkles: :thumbsup: :sparkles:
:warning: bdeerwester already gave utkarshshukla7 points
:star: 249 | @waynemdavies | http://www.freecodecamp.com/waynemdavies
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 01:58
@bdeerwester np
Brian D.
@bdeerwester
Apr 22 2016 02:04
hey it's me again, even the code on that wiki page won't pass the third test...i can't figure out whats up. should I report a bug?
nevermind, i'm an idiot! carry on
D. Omran
@domran23
Apr 22 2016 02:06
@n00bax Hey, you were helping me with the Profile Lookup exercise (you reminded me that .hasOwnProperty returns a true or false). I get that part (I think lol) but I still haven't figured out this exercise. I'm at my wit's end lol.
Wayne M. Davies
@WayneMDavies
Apr 22 2016 02:16
@domran23 I was clued in on this one last night and it can be accomplished with a for loop or a while loop but the for loop is recommended. Do you have code you can post?
D. Omran
@domran23
Apr 22 2016 02:22
@WayneMDavies sorry for the delay! I'll paste it in...
function lookUpProfile(firstName, prop){
// Only change code below this line

  var temp;
  for(var i = 0; i < contacts.length; i++) {
    if(firstName == contacts[i].firstName && prop == contacts[i].hasOwnProperty(prop) === true) {
      temp = contacts[i].hasOwnProperty(prop);
     } else if(firstName != contacts[i].firstName) {
       temp = "No such contact";
    } else if(prop != contacts[i].hasOwnProperty(prop)) {
       temp = "No such property";

  }

    return temp;
  }

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
Wayne M. Davies
@WayneMDavies
Apr 22 2016 02:27
@domran23 Where is the ".hasOwnProperty" coming from? And, the last "else" does not need "if". Not sure if that will solve your problem but it is not needed.
D. Omran
@domran23
Apr 22 2016 02:30
You mean why am I using .hasOwnProperty? If so, I thought the code needed it to check if a particular property exists in the object. Also, I added the last if to set up the "no such property" statement. Let me try and remove it
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 02:32
@domran23 contacts[i].hasOwnProperty(prop) returns true or false not the name of property
Wayne M. Davies
@WayneMDavies
Apr 22 2016 02:33
@domran23 I'm not an expert but my solution did not use that. Also, I compared prop to each property rather than to itself in a series of nested if much like you have.
D. Omran
@domran23
Apr 22 2016 02:34
@UtkarshShukla7 ahh that's right! urrrggg thanks. And looks like I may not have even needed it
CamperBot
@camperbot
Apr 22 2016 02:34
domran23 sends brownie points to @utkarshshukla7 :sparkles: :thumbsup: :sparkles:
:star: 346 | @utkarshshukla7 | http://www.freecodecamp.com/utkarshshukla7
D. Omran
@domran23
Apr 22 2016 02:34
@WayneMDavies ok thanks, I need to rework this exercise from the beginning
CamperBot
@camperbot
Apr 22 2016 02:34
domran23 sends brownie points to @waynemdavies :sparkles: :thumbsup: :sparkles:
:star: 250 | @waynemdavies | http://www.freecodecamp.com/waynemdavies
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 02:36
@domran23 np
you don't need .hasOwnProperty() to pass this challenge but it helps to generalise your solution
E. Badu
@E-Badu
Apr 22 2016 02:36
Hey all, I'm suffering through an acessing objects problem. And I just can't see what i'm doing wrong.
can i get a little bit o' help?
D. Omran
@domran23
Apr 22 2016 02:36
@WayneMDavies don't be surprised if I'm back here in a few lol
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 02:37
@E-Badu paste your code and someone will help you
E. Badu
@E-Badu
Apr 22 2016 02:37
This message was deleted
CamperBot
@camperbot
Apr 22 2016 02:37
:bulb: to format code use backticks! ``` more info
E. Badu
@E-Badu
Apr 22 2016 02:37
// Setup
var testObj = {
  12: "Namath",
  16: "Montana",
  19: "Unitas"
};

// Only change code below this line;

var playerNumber = testObj[player];       // Change this Line
var player = "Montana";   // Change this Line
the problem has asked me to
Use the playerNumber variable to lookup player 16 in testObj using bracket notation.
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 02:39
@E-Badu you have to change line var playerNumber = testObj[player]; to
var playerNumber=16;
E. Badu
@E-Badu
Apr 22 2016 02:40
@UtkarshShukla7 oh. I thought I'm trying to get player number to pull from the object.
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 02:40
@E-Badu and retrieve the name of player in var player using brackets notation
no just the reverse
E. Badu
@E-Badu
Apr 22 2016 02:41
Ah!
Tyler
@tylergross
Apr 22 2016 02:44
creating the AI for the tic-tac-toe game seems very difficult, i've stumbled upon the minimax algorithm but it all seems like a ton of work to create the game
at first i was like hmmmm i'll just have the computer be on "super easy" and just randomly select an open space. yeah no that's not what i'm going to do
who understands the MM algorithm?
heymark
@heymark
Apr 22 2016 02:49
Heh. I had to implement for a Tic Tac Toe challenge a few years ago, but no recollection of how it works. Skipping the projects until I finish the algorithms.
@tylergross this might be helpful if you haven't seen it already > http://neverstopbuilding.com/minimax
Miguel T Rivera
@mtrivera
Apr 22 2016 02:54
wiki where art thou
CamperBot
@camperbot
Apr 22 2016 02:54

:point_right: algorithm where art thou [wiki]

Problem Explanation

Write an algorithm that will take an array for the first argument and return an array with all the objects that matches all the properties and values in the Object passed as second parameter.

:pencil: read more about algorithm where art thou on the FCC Wiki

Tyler
@tylergross
Apr 22 2016 02:56
@heymark I actually just read that page it helped my understand what the algorithm is but I have no idea where to begin on coding it. I guess I'll just practice some more, I've finished 95% of the algorithms just have a few of the advanced ones left that are painful
heymark
@heymark
Apr 22 2016 02:57
Yeah, I think I'm within two or three now.
Charles Lang
@Nojil
Apr 22 2016 02:57
Hey guys could i get some help with the question "Record Collection" i cant seem to get this one working

// 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 updateRecords(id, prop, value) {
if (value !== "" && prop != "tracks"){

collection[track] = value;
}

return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");

Miguel T Rivera
@mtrivera
Apr 22 2016 03:00
for(var count = 0; count < collection.length; count++) {
     while(ix < source.length){
         if(collection[count].hasOwnProperty(Object.keys(source)[ix]) &&
             collection[count][Object.keys(source)[ix]] === source[Object.keys(source)[ix]]){
                arr.push(collection[count]);
                ix++;
         }
     }
}
I'm working on where art thou but I'm getting an empty array with the last two test conditions, the first two work
Liu Zhiqun
@lzhiqun
Apr 22 2016 03:13
guys how to exclude underscore in \w!!
str=str.replace(/[^\w\d]/gi, '');
I dont want _, is there a way to exclude it using [^(neglect)]
Aaron Preston
@AaronPreston
Apr 22 2016 03:15
@lzhiqun You want to include alphanumeric characters, but remove underscores?
Liu Zhiqun
@lzhiqun
Apr 22 2016 03:15
Yes!
@AaronPreston yes!
Spencer
@coderamen
Apr 22 2016 03:18
Howdy everyone....
Aaron Preston
@AaronPreston
Apr 22 2016 03:18
@lzhiqun You can include underscores like this, /[]/ You can then of course inverse it by /[^]/
@codetechnoob Hey, welcome! How're you today?
Gahatrack
@Gahatrack
Apr 22 2016 03:19
How do I copy and paste code in the full console view?
Aaron Preston
@AaronPreston
Apr 22 2016 03:19
@lzhiqun My bad, it didn't show up right. Hold on
Tyler
@tylergross
Apr 22 2016 03:19
.column {
    width: 150px;
    height: 150px;
    display: inline;
    border: solid;
    text-align: center;

}
can anyone tell me why my <div class="column">x</div> is not being assigned those css factors?
Spencer
@coderamen
Apr 22 2016 03:20

need help with my exercise "Understanding Case Sensitivity in Variables" via Freecodecamp how do I solve this \\
// Declarations
var studlyCapVaR = camelcase10;
var properCamelCase = "A String";
var TitleCaseOver = 9000;

// Assignments
studlyCapVaR = 10;
PRoperCAmelCAse = "A String";
TitleCaseOver = 9000;

\\

Aaron Preston
@AaronPreston
Apr 22 2016 03:21
str = str.replace(/[_]/gi, '');
@lzhiqun
Liu Zhiqun
@lzhiqun
Apr 22 2016 03:22
@AaronPreston Ahhh ok I was thinking if I can combine it into something like this
str = str.replace(/[_^\w]/gi, '');
DJ
@qualitymanifest
Apr 22 2016 03:22
@tylergross it's the display:inline overriding the div's default display: block
Liu Zhiqun
@lzhiqun
Apr 22 2016 03:22
@AaronPreston Thanks! I'll just include a new line!
CamperBot
@camperbot
Apr 22 2016 03:22
lzhiqun sends brownie points to @aaronpreston :sparkles: :thumbsup: :sparkles:
:star: 276 | @aaronpreston | http://www.freecodecamp.com/aaronpreston
Tyler
@tylergross
Apr 22 2016 03:23
@qualitymanifest hmm i was hoping to create a row and have three divs aligned next to one another\
Spencer
@coderamen
Apr 22 2016 03:23
// Declarations
var studlyCapVaR = camelcase10;
var properCamelCase = "A String";
var TitleCaseOver = 9000;

// Assignments
studlyCapVaR = 10;
PRoperCAmelCAse = "A String";
TitleCaseOver = 9000;
Tyler
@tylergross
Apr 22 2016 03:24
maybe i'll try and float them, thanks @qualitymanifest
CamperBot
@camperbot
Apr 22 2016 03:24
tylergross sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star: 1139 | @qualitymanifest | http://www.freecodecamp.com/qualitymanifest
Spencer
@coderamen
Apr 22 2016 03:24
how do i solve this??
Aaron Preston
@AaronPreston
Apr 22 2016 03:25
@lzhiqun Instead of using the ^\w, you can use \W. The capital is the inverse version. Hope I helped!
E. Badu
@E-Badu
Apr 22 2016 03:26
Hello, i'm looking for help for an objects lookup problem.
// 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"
  };


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

// Change this value to test
phoneticLookup("charlie");
I'm being asked to
Convert the switch statement into a lookup table called lookup. Use it to lookup val and assign the associated string to the result variable.
am I creating the lookup table correctly?
Tyler
@tylergross
Apr 22 2016 03:31
@E-Badu looks good
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 03:32
@codetechnoob
// Declarations
var studlyCapVaR = 10;
var properCamelCase = "A String";
var titleCaseOver = 9000;

// Assignments
studlyCapVaR = 10;
ProperCamelCase = "A String";
titleCaseOver = 9000;
Spencer
@coderamen
Apr 22 2016 03:32
got it solve...:D
thanks @UtkarshShukla7
CamperBot
@camperbot
Apr 22 2016 03:32
codetechnoob sends brownie points to @utkarshshukla7 :sparkles: :thumbsup: :sparkles:
:star: 347 | @utkarshshukla7 | http://www.freecodecamp.com/utkarshshukla7
Gahatrack
@Gahatrack
Apr 22 2016 03:32

function nextInLine(arr, item) {
// Your code here
testArr.push(item);
testArr.shift();
return item; // Change this line
}

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

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

How do I call back what I .shift() ed?

E. Badu
@E-Badu
Apr 22 2016 03:33
@tylergross ok, so then how do I then go to lookup val? I think it'm not understanding what the question is asking
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 03:33
@codetechnoob np
@Gahatrack item=testArr.shift();
Tyler
@tylergross
Apr 22 2016 03:34
they want you to use an obj to test for the value they give you IE lookup["charlie"] should return "Chicago"
@E-Badu
nabeelaa
@nabeelaa
Apr 22 2016 03:36
just built a random quote machine. would love to hear your feedback http://codepen.io/nabeela/pen/xVJRmR?editors=0110
E. Badu
@E-Badu
Apr 22 2016 03:37
@tylergross ok. I understand that. So why can't i get this to run?
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 03:37
@E-Badu result=lookup[var];
Tyler
@tylergross
Apr 22 2016 03:37
@E-Badu what do you mean? currently you are returning result which returns an empty string
you no to assign result to a value as @UtkarshShukla7 has stated
need to assign*
@nabeelaa very cool.... a few of the photos do not load for me
E. Badu
@E-Badu
Apr 22 2016 03:39
oh! ok. I see I just misunderstood the comments in the code. I thought they didn't want me to mess with that at the top
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 03:39
@nabeelaa nice concept of changing image with quotes
but it will be nicer if I don't have to scroll to look at the whole image
E. Badu
@E-Badu
Apr 22 2016 03:40
I kept putting that at the bottom and it would say, result is already defined. but now i see that's because it wanted me to redefine it up at the top. ok I get it.
Thanks @tylergross and Thanks @UtkarshShukla7
CamperBot
@camperbot
Apr 22 2016 03:40
e-badu sends brownie points to @tylergross and @utkarshshukla7 :sparkles: :thumbsup: :sparkles:
:star: 348 | @utkarshshukla7 | http://www.freecodecamp.com/utkarshshukla7
:star: 343 | @tylergross | http://www.freecodecamp.com/tylergross
Liu Zhiqun
@lzhiqun
Apr 22 2016 03:40
guys whats wrong with my this code!
 arr[i].charAt(0).toUpperCase();
E. Badu
@E-Badu
Apr 22 2016 03:40
y'all are awesome! @tylergross @UtkarshShukla7
Liu Zhiqun
@lzhiqun
Apr 22 2016 03:40
i'm trying to made the first letter to uppercase
Tyler
@tylergross
Apr 22 2016 03:40
@lzhiqun try to turn it uppercase first?
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 03:40
@E-Badu np!
Tyler
@tylergross
Apr 22 2016 03:40
newvermind
Liu Zhiqun
@lzhiqun
Apr 22 2016 03:40
Yes! @tylergross
Tyler
@tylergross
Apr 22 2016 03:43
@E-Badu if you got "already defined" this is because it already says var result = "" at the top meaning they have defined the variable for you and want you to modify it in the lower section by using result = lookup[val]; glad you figured it out though
E. Badu
@E-Badu
Apr 22 2016 03:44
Yes! after modifying the top, I realized that it wanted to go into the lower section @tylergross
Tyler
@tylergross
Apr 22 2016 03:44
@UtkarshShukla7 im guessing you are on a small monitor? I am not having to scroll to look at the images
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 03:44
@tylergross yes mine is small
Aaron Preston
@AaronPreston
Apr 22 2016 03:48
Can someone help me with this? I've been stuck on the Seek and Destroy algorithm challenge all day today. I can't figure out what to put in the if statement inside of my filter()
function destroyer(arr) {

  var toRemove = [];

  for(var x = 1; x < arguments.length; x++) {
      toRemove.push(arguments[x]);
  }

  return arr.filter(function(val) {
    if() {
        return false;
    } else {
        return true;
    }
  });

}
Tyler
@tylergross
Apr 22 2016 03:49
@AaronPreston what's the condition?
Your return line is a little wrong you should have return filter(){} with returns within a rerun
Shouldn't
krisluu5695
@krisluu5695
Apr 22 2016 03:56

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

// Change the words here to test your function
wordBlanks("cat ", "little ", "hit ", "slowly!!!");

can someone help ?
Tyler
@tylergross
Apr 22 2016 03:57
@krisluu5695 almost there... Why do you put result = result?
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 03:58
@krisluu5695 just add " " in between else everything is fine
nabeelaa
@nabeelaa
Apr 22 2016 03:58
@tylergross @UtkarshShukla7 thanks for the feedback
CamperBot
@camperbot
Apr 22 2016 03:58
nabeelaa sends brownie points to @tylergross and @utkarshshukla7 :sparkles: :thumbsup: :sparkles:
:star: 345 | @tylergross | http://www.freecodecamp.com/tylergross
:star: 349 | @utkarshshukla7 | http://www.freecodecamp.com/utkarshshukla7
nabeelaa
@nabeelaa
Apr 22 2016 03:58
will try to fix it
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 03:58
@nabeelaa np
Tyler
@tylergross
Apr 22 2016 03:58
You need to fix the sentence you have it saying " cat slowly ...
krisluu5695
@krisluu5695
Apr 22 2016 03:59
tks ...
Tyler
@tylergross
Apr 22 2016 03:59
@krisluu5695 nouns come before verbs and yes you need to add spaces between each word + " " +
DJ
@qualitymanifest
Apr 22 2016 04:00
@tylergross sorry, i was out and about. have you tried inline-block? i think that might work for you
Tyler
@tylergross
Apr 22 2016 04:01
@qualitymanifest tried it but didn't work for what I needed, ended up using a float:left
Rudolf Carl Pablico
@rudolfpablico
Apr 22 2016 04:01
Hi guys! Need help on this exercise. Record Collection. It's been two days and I still can't figure it out. Thanks
Tyler
@tylergross
Apr 22 2016 04:01
@rudolfpablico what do you have so far
Rudolf Carl Pablico
@rudolfpablico
Apr 22 2016 04:02
@tylergross what my plan, is to access the property and just do if else statement but results to undefined.
Tyler
@tylergross
Apr 22 2016 04:03
Can you post your code
Rudolf Carl Pablico
@rudolfpablico
Apr 22 2016 04:04

var val = collection.id.prop;

return val;

well actually , what i want is to transfer the property to a different variable
hrokr
@hrokr
Apr 22 2016 04:04
help formatting
CamperBot
@camperbot
Apr 22 2016 04:04

:point_right: code formatting [wiki]

Multi line Code

```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 ⏎]

Single line Code

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

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

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

Tyler
@tylergross
Apr 22 2016 04:05
@rudolfpablico not really enough code for me to see what's going on but I can tell you that dot notation isn't going to work here
Rudolf Carl Pablico
@rudolfpablico
Apr 22 2016 04:06
could you give me a tip how to access the property and transfer it to a different variable?
Tyler
@tylergross
Apr 22 2016 04:06
Can you provide the object that needs to be accessed? I'm on my phone can't pull up the challenge ATM
Rudolf Carl Pablico
@rudolfpablico
Apr 22 2016 04:07
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"
}
};
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 04:08
@rudolfpablico var yourvariable=collection[id][prop];
Tyler
@tylergross
Apr 22 2016 04:08
Okay so you would have collection[id][prop] to access it.... Or collection["1245"]["artist"] would return Robert Palmer
Rudolf Carl Pablico
@rudolfpablico
Apr 22 2016 04:09
Thanks guys. Be back later if still having problem :)
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 04:10
np
V Arun Kumar
@arunvkumr
Apr 22 2016 04:13
@lzhiqun Strings are immutabale, you cannot change a specific char in a string, however you can manipulate the string to get new string or you change the entire string. In your case you can split the string into an array and change the first char of the array to uppercase and join it back. :smile:
Tyler Moore
@devopsec
Apr 22 2016 04:24

hey everyone, i'm wracking my brain with this record collection challenge, I am trying to nest some if then statements within a switch within a function to update some nested JSON elements. Let me know if anybody can figure this one out:
// 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 updateRecords(id, prop, value) {
switch (id) {
case 2548:
if (prop !== "tracks" && value !== "") {
value = collection[2548][prop];
}
else if (prop = "tracks" && value !== "") {
collection[2548]["tracks"].push(value);
}
else if (value = "") {
delete collection[2548][prop];
}
break;
case 2468:
if (prop !== "tracks" && value !== "") {
value = collection[2468][prop];
}
else if (prop = "tracks" && value !== "") {
collection[2468]["tracks"].push(value);
}
else if (value = "") {
delete collection[2468][prop];
}
break;
case 1245:
if (prop !== "tracks" && value !== "") {
value = collection[1245][prop];
}
else if (prop = "tracks" && value !== "") {
collection[1245]["tracks"].push(value);
}
else if (value = "") {
delete collection[1245][prop];
}
break;
case 5439:
if (prop !== "tracks" && value !== "") {
value = collection[5439][prop];
}
else if (prop = "tracks" && value !== "") {
collection[5439]["tracks"].push(value);
}
else if (value = "") {
delete collection[5439][prop];
}
break;
}
return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");

any ideas?
96street
@96street
Apr 22 2016 04:36
How do I add speed to the slideToggle();?
var $more = $('#more');
var $navDropdown = $('.navDropdown');

function moreDropdown() {
  $more.on('click', function() {

    $navDropdown.slideToggle('navToggle');

  })
}

moreDropdown();
Chris Lacaille
@ChrisL108
Apr 22 2016 04:44
@96street I think it's a second parameter
function reverseString(str) {
  var strArray = str.split("");
  strArray.reverse();
  strArray.join("");
  console.log(strArray.toString());
  return strArray.toString();
}

reverseString("hello");
Alexis
@alexisgcn
Apr 22 2016 04:44
Factorialize a Number
Chris Lacaille
@ChrisL108
Apr 22 2016 04:45
What am i missing? I'm getting o,l,l,e,h
Alexis
@alexisgcn
Apr 22 2016 04:46
@ChrisL108
function reverseString(str) {
  str = str.split('').reverse();
   return str.join('');
}
96street
@96street
Apr 22 2016 04:46
var $more = $('#more');
var $navDropdown = $('.navDropdown');

function moreDropdown() {
  $more.on('click', function() {

    $navDropdown.slideToggle('navToggle', 2000);

  })
}

moreDropdown();
not working ^
Alexis
@alexisgcn
Apr 22 2016 04:48
help with Factorialize a Number
CamperBot
@camperbot
Apr 22 2016 04:48
no wiki entry for: with factorialize a number
Alexis
@alexisgcn
Apr 22 2016 04:48
Help Factorialize a Number
CamperBot
@camperbot
Apr 22 2016 04:48

:point_right: algorithm factorialize a number [wiki]

Problem Explanation:

Return the factorial of the provided integer. If the integer is represented with the letter n, a factorial is the product of all positive integers less than or equal to n.

Factorials are often represented with the shorthand notation n!

For example: 5! = 1 * 2 * 3 * 4 * 5 = 120

:pencil: read more about algorithm factorialize a number on the FCC Wiki

Tyler Moore
@devopsec
Apr 22 2016 04:51
anybody got a sec to help me with nested JSON objects?
krisluu5695
@krisluu5695
Apr 22 2016 04:55
@alexisgcn can u tell me how to send page to chat screen ?
Tyler Moore
@devopsec
Apr 22 2016 04:55
Help Nesting Conditional Statement within Switch Case
CamperBot
@camperbot
Apr 22 2016 04:55
no wiki entry for: nesting conditional statement within switch case
krisluu5695
@krisluu5695
Apr 22 2016 04:56
anyone can tell me how to copy the coding page to chat screen having troubles ..... :D .... ty
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 04:57
help format
CamperBot
@camperbot
Apr 22 2016 04:57

:point_right: code formatting [wiki]

Multi line Code

```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 ⏎]

Single line Code

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

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

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

krisluu5695
@krisluu5695
Apr 22 2016 04:57
ty men .... ^^
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 04:58
np
krisluu5695
@krisluu5695
Apr 22 2016 04:58

` function nextInLine(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(nextInLine(testArr, 1)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
`

UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 04:58
`` not
krisluu5695
@krisluu5695
Apr 22 2016 04:58
opps ... sr ...
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 04:58
three backticks not one
krisluu5695
@krisluu5695
Apr 22 2016 04:59
function nextInLine(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(nextInLine(testArr, 1)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 05:00
@krisluu5695 add it using push and remove it using shift
Alexis
@alexisgcn
Apr 22 2016 05:01
@UtkarshShukla7 make this in one line```js
krisluu5695
@krisluu5695
Apr 22 2016 05:01
function nextInLine(arr, item) {
  // Your code here
  arr = arr.push(6);
  arr = arr.shift(); 
  return arr;  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 1)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
like this right ?
Alexis
@alexisgcn
Apr 22 2016 05:02
and ``` below your code
UtkarshShukla7
@UtkarshShukla7
Apr 22 2016 05:03
ok
@krisluu5695
function queue(arr, item) {
  // Your code here
  arr.push(item);
  item= arr.shift();
  return item;  // Change this line
}
ignore function name
V Arun Kumar
@arunvkumr
Apr 22 2016 05:05
@krisluu5695 You're close.. push the item that is passed to by the function, you are hard coding the push to inset 6. not item and don't store it back to arr, push function return length of the new array so storing it would change arr array to arr numeric variable, you can use the shift with arr that wouldn't matter.
krisluu5695
@krisluu5695
Apr 22 2016 05:05
ty guys ... ^^
krisluu5695
@krisluu5695
Apr 22 2016 05:12
what should we use with those == or === ?
Markus Kiili
@Masd925
Apr 22 2016 05:15
@krisluu5695 Always use strict equality ===. Abstract equality algorithm is a mess, so don't use ==.
Liu Zhiqun
@lzhiqun
Apr 22 2016 05:16
hi guys what went wrong here?
function chunkArrayInGroups(arr, size) {
  // Break it up.
  var arr1;

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

   arr1.push(arr.slice(i,i+size));

  }
  return arr1;
}
am I not delcaring the array correctly?
Markus Kiili
@Masd925
Apr 22 2016 05:17
@lzhiqun var arr1 = [];
Liu Zhiqun
@lzhiqun
Apr 22 2016 05:18
@Masd925 ahhh ok that does the trick! thanks lots
CamperBot
@camperbot
Apr 22 2016 05:18
lzhiqun sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1407 | @masd925 | http://www.freecodecamp.com/masd925
krisluu5695
@krisluu5695
Apr 22 2016 05:19
@Masd925 tks ....
CamperBot
@camperbot
Apr 22 2016 05:19
krisluu5695 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1408 | @masd925 | http://www.freecodecamp.com/masd925
96street
@96street
Apr 22 2016 05:26
No functions after this block of code work. What's wrong with this? It's just some code for a dropdown
var $more = $('#more');
var $navDropdown = $('.navDropdown');

function moreDropdown() {
  $more.on('click', function() {

    $navDropdown.slideToggle('navToggle');

  })
}
  moreDropdown();
Vivek Regmi
@vivek422336
Apr 22 2016 05:26

var firstLetterOfLastName = "";
var lastName = "Lovelace";

firstLetterOfLastName = lastName[0];
How to use bracket notation here?

Ada323
@Ada323
Apr 22 2016 05:29
I'm working on the 'Understand String Immutability' challenge and I keep getting an X for "Do not change the code above the line", even when I haven't done anything to it. Is this a bug?
@vivek422336 You did it correctly. firstLetterOfLastName = lastName[0] is the answer - it'll return an L
Whoops, firstLetterOfLastName = lastName[0]; - forgot the semi-colon!
Vivek Regmi
@vivek422336
Apr 22 2016 05:33
but it is saying i have to use bracket notation!!
V Arun Kumar
@arunvkumr
Apr 22 2016 05:33
@vivek422336 what's the challenge name?
Elbert Cortez
@trip16661
Apr 22 2016 05:33
this is stremly disgusting >.<
V Arun Kumar
@arunvkumr
Apr 22 2016 05:34
@Ada323 can you post you code here?
Elbert Cortez
@trip16661
Apr 22 2016 05:34
does anyone know how to do if there are parentheses search if they are completed
with regexp?
Vivek Regmi
@vivek422336
Apr 22 2016 05:35
challenge name is "Use Bracket Notation to Find the First Character in a String"
Elbert Cortez
@trip16661
Apr 22 2016 05:35
fuck it im going to just cheat that part only xDD ive reading regexp for the past 4 5 h
help Validate US Telephone Numbers
CamperBot
@camperbot
Apr 22 2016 05:35

:point_right: algorithm validate us telephone numbers [wiki]

Problem Explanation:

  • The task is not that hard to understand, implementing it is the hardest part. You have a to validate an US phone number. This means there is a certain amount of numbers required, while you don't need to put the country code, you will still need the area code and use one of the few formats allowed.
:pencil: read more about algorithm validate us telephone numbers on the FCC Wiki
Ada323
@Ada323
Apr 22 2016 05:37
@arunkumrv Thanks so much for the response, I figured out what was wrong.
CamperBot
@camperbot
Apr 22 2016 05:37
ada323 sends brownie points to @arunkumrv :sparkles: :thumbsup: :sparkles:
V Arun Kumar
@arunvkumr
Apr 22 2016 05:37
@vivek422336 post your code here..
CamperBot
@camperbot
Apr 22 2016 05:37
:star: 500 | @arunkumrv | http://www.freecodecamp.com/arunkumrv
Vivek Regmi
@vivek422336
Apr 22 2016 05:38

var firstLetterOfFirstName = "";
var firstName = "Ada";

firstLetterOfFirstName = firstName[0];

// Setup
var firstLetterOfLastName = "";
var lastName = "Lovelace";

firstLetterOfLastName = lastName[0];

this is the whole code, i dont know how to post the black screen

// Example
var firstLetterOfFirstName = "";
var firstName = "Ada";

firstLetterOfFirstName = firstName[0];

// Setup
var firstLetterOfLastName = "";
var lastName = "Lovelace";

firstLetterOfLastName = lastName[0];

V Arun Kumar
@arunvkumr
Apr 22 2016 05:39
@vivek422336 you code seems fine.. try reloading the page or clearing the code.
wiki format
CamperBot
@camperbot
Apr 22 2016 05:39

:point_right: code formatting [wiki]

Multi line Code

```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 ⏎]

Single line Code

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

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

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

V Arun Kumar
@arunvkumr
Apr 22 2016 05:39
:point_up_2: @vivek422336
ALMY91
@ALMY91
Apr 22 2016 05:41
in which chapter of the challenge can i find accessing properties using this. keyword?
i cant seem to find it..
Vivek Regmi
@vivek422336
Apr 22 2016 05:42
Reloading the page worked! I am sorry to bother you :) @arunkumrv
V Arun Kumar
@arunvkumr
Apr 22 2016 05:50
@ALMY91 open freecodecamp.com/map and search for object constructor or object or properties, you may find them there in javascript section.
ALMY91
@ALMY91
Apr 22 2016 05:56
@arunkumrv thanks
CamperBot
@camperbot
Apr 22 2016 05:56
almy91 sends brownie points to @arunkumrv :sparkles: :thumbsup: :sparkles:
:star: 502 | @arunkumrv | http://www.freecodecamp.com/arunkumrv
ALMY91
@ALMY91
Apr 22 2016 05:57
guys i need some help here again
karanag
@karanag
Apr 22 2016 05:58
hi...having a very basic problem...how do i return an integer and string inside a string
i tried doing this return "$count Hold";
where count is a variable
Erik Maurer
@MauPow
Apr 22 2016 06:00
function getIndexToIns(arr, num) {

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

  for (var i = 0; i<sorted.length; i++) {
    if (num > sorted[i] && num < sorted[i+1]) {
      return sorted.indexOf(sorted[i]);
    }
  }
}

getIndexToIns([10, 20, 30, 40, 50], 30);
Can someone explain why this is not working?
It doesn't return anything
Salomon May
@sollymay
Apr 22 2016 06:02
@MauPow soy first thing is that the return is inside the for loop.
ALMY91
@ALMY91
Apr 22 2016 06:03
Functions written for use as constructors do not return a value, and the value of the object creation expression is the newly created and initialized object. If a constructor does return an object value, that value bcoms the value of the object reaion and the new object is discarded
can anyone do up a simple code with comments on this?
it would be of a great help
Erik Maurer
@MauPow
Apr 22 2016 06:04
Ok... so I've declared a variable outside the for loop and changed it in the loop and then returned it... now it just returns 1
er, not always 1. But still doesn't work
karanag
@karanag
Apr 22 2016 06:05
can anyone help me
Samuel Cupidon
@Zerazera
Apr 22 2016 06:07
@ALMY91
var audi=new Car();

function Car() {
this.wheels=4; //public variable
var speed=0; //private variable
this.drive=function() {
   //do stuff
   } //public function
var spendGas() = function() {
   //do stuff
   }; //private function
}
Joseph Palacio
@Joematpal
Apr 22 2016 06:12
Has anyone worked on the Make Object Properties Private?
UDAY PRAPHULLA MALANGAVE
@malangaveuday
Apr 22 2016 06:13
Hello every one
AlonTishler
@AlonTishler
Apr 22 2016 06:14
Counting Cards - do you use switch statements at all?
Rudolf Carl Pablico
@rudolfpablico
Apr 22 2016 06:15

hi guys, having on problem on Record Collection exercise, please help
Im failing on this requirement only

After updateRecords(1245, "tracks", "Addicted to Love"), tracks should have "Addicted to Love" as the last element.

UDAY PRAPHULLA MALANGAVE
@malangaveuday
Apr 22 2016 06:15
 var newsObject;
    window.addEventListener("scroll",function(){
        if(window.pageYOffset > 900){
            console.log(window.pageYOffset);
            $.ajax({
                     url : "http://content.guardianapis.com/search?api-key=b5b674e9-e346-438c-bfce-9a3c01d6f87c"
                   }).done(function(data){
                     newsObject = data.response.results;
                    }).fail(function(){
                     console.log("fail");
                   })
              }
           console.log(newsObject);
           $(".content-wrapper").append("<p>"+ newsObject.webTitle  +"</p>")
        });
I have one doubt
i declared newsObject in parent scope and assign value to it in child but it shows undefined
please help me why this happening?
Rudolf Carl Pablico
@rudolfpablico
Apr 22 2016 06:16

here is my code

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

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

return collection;
}

karanag
@karanag
Apr 22 2016 06:16

switch(count){

case 2:
case 3:
case 4:
case 5:
case 6:
count++;
break;
case 7:
case 8:
case 9:
break;
case 10:
case "J":
case "Q":
case "K":
case "A":
count--;
break;
}

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

Rawan44
@Rawan44
Apr 22 2016 06:16

Hello, can someone see this code

function chunkArrayInGroups(arr, size) {
  // Break it up.
  var n;
  var a = [];
  if (arr % size === 0)
    n = arr / size;
  else
    n = arr / size + 1;
  for (i=0; i<n; i++) {
    a.push(arr.slice(i*size, i*size+size));
  }
  return a;
}

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

the return is an empty array, and I don't know why :(

karanag
@karanag
Apr 22 2016 06:16
this gives a result of 0 hold
not matter the input
Rudolf Carl Pablico
@rudolfpablico
Apr 22 2016 06:17
@karanag your code does not sum the value of cards
ALMY91
@ALMY91
Apr 22 2016 06:17
@Zerazera hi i still do not quite understand are u able to elaborate more on the comments according to the paragraph i gave? thx
CamperBot
@camperbot
Apr 22 2016 06:17
almy91 sends brownie points to @zerazera :sparkles: :thumbsup: :sparkles:
:star: 385 | @zerazera | http://www.freecodecamp.com/zerazera
UDAY PRAPHULLA MALANGAVE
@malangaveuday
Apr 22 2016 06:18
 var newsObject;
    window.addEventListener("scroll",function(){
        if(window.pageYOffset > 900){
            console.log(window.pageYOffset);
            $.ajax({
                     url : "http://content.guardianapis.com/search?api-key=b5b674e9-e346-438c-bfce-9a3c01d6f87c"
                   }).done(function(data){
                     newsObject = data.response.results;
                    }).fail(function(){
                     console.log("fail");
                   })
              }
           console.log(newsObject);
           $(".content-wrapper").append("<p>"+ newsObject.webTitle  +"</p>")
        });
I have one doubt
i declared newsObject in parent scope and assign value to it in child but it shows undefined
please help me why this happening?
ALMY91
@ALMY91
Apr 22 2016 06:18
@Zerazera like which part of the function written for use as constructor doesn return a value ect.
Samuel Cupidon
@Zerazera
Apr 22 2016 06:19
@malangaveuday The AJAX call is asynchronous. The function hasn't finished updating the newsObject variable by the time it reaches the console.log. You should have the console log inside the anonymous .done function. Alternatively, you could call the next function from within .done.
UDAY PRAPHULLA MALANGAVE
@malangaveuday
Apr 22 2016 06:19
@Zerazera i want to use response of ajax
karanag
@karanag
Apr 22 2016 06:20
@rudolfpablico i need to add the value of cards also ?
UDAY PRAPHULLA MALANGAVE
@malangaveuday
Apr 22 2016 06:20
how should i do ?
Samuel Cupidon
@Zerazera
Apr 22 2016 06:20
@malangaveuday Then you need to either define the function within .done or call it within .done
karanag
@karanag
Apr 22 2016 06:20
@rudolfpablico i thought i just have to add 1 or reduce 1 from the count depending on the situation
Chris Lacaille
@ChrisL108
Apr 22 2016 06:22
Would the best way to solve 'Check for Palindromes' with a RegExp?
using a regex*
UDAY PRAPHULLA MALANGAVE
@malangaveuday
Apr 22 2016 06:22
ajax.({
//call
}).done(outerFunction(data))

outerFunction(response){
//here response will availble?
}
@Zerazera does it rght?
Samuel Cupidon
@Zerazera
Apr 22 2016 06:23
@malangaveuday yes
karanag
@karanag
Apr 22 2016 06:23

switch(count){

case 2:
case 3:
case 4:
case 5:
case 6:
count++;
break;
case 7:
case 8:
case 9:
break;
case 10:
case "J":
case "Q":
case "K":
case "A":
count--;
break;
}

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

im going crazy..can some one tell me whats wrong with it
Rudolf Carl Pablico
@rudolfpablico
Apr 22 2016 06:23
@karanag you use count++ and count--
karanag
@karanag
Apr 22 2016 06:25
@rudolfpablico ... i was making a huge mistake...in the switch i used count instead of card..thats why it did not progress
thanks though
Rudolf Carl Pablico
@rudolfpablico
Apr 22 2016 06:26
@karanag welcome
Erik Maurer
@MauPow
Apr 22 2016 06:34
charCodeAt() returns a Unicode character value, right?
V Arun Kumar
@arunvkumr
Apr 22 2016 06:41
@MauPow yea that's right
Erik Maurer
@MauPow
Apr 22 2016 06:45
Is there any way to use something like push() for strings?
kirbyedy
@kirbyedy
Apr 22 2016 06:50
@MauPow I think strings are immutable in javascript
Erik Royall
@erikroyall
Apr 22 2016 06:50
^
Primitives are immutable in JS
Markus Kiili
@Masd925
Apr 22 2016 06:55
Some objects are immutable in JS
Erik Maurer
@MauPow
Apr 22 2016 06:56
What string operation would I want to use to change values in a string sequentially? (working on the cipher challenge)
If I can't use replace() or push()
I want to put the new character in a fresh string.. can't seem to get it though
kirbyedy
@kirbyedy
Apr 22 2016 06:56
I think you should use array
Frank XC
@tenkdayz
Apr 22 2016 06:57
@MauPow +=
Markus Kiili
@Masd925
Apr 22 2016 06:57
@erikroyall You can use string operations to construct a new string and assign it to same or new variable, or property like an array element.
Erik Maurer
@MauPow
Apr 22 2016 06:58
@tenkdayz oh derp haha
RakeshNerkar
@Rakesh18754
Apr 22 2016 07:10

var source1 = {
apple: 0,
banana: { price: 100 },
cherry: 97
};
var source2 = {
apple: 0,
banana: { weight: 52, price: 200 },
durian: 100
};
var mergedJSON = Object.create(source2);

for (var attrname in source1) {

        console.log(mergedJSON.hasOwnProperty(attrname));   

}

HI....Why is mergedJSON.hasOwnProperty(attrname) returning false ??
any idea?
Markus Kiili
@Masd925
Apr 22 2016 07:16
@deepakpatil007 Those are not own properties. They are inherited from prototype.
RakeshNerkar
@Rakesh18754
Apr 22 2016 07:19
@Masd925 Thanks a lot Markus.....now i got it..
CamperBot
@camperbot
Apr 22 2016 07:19
deepakpatil007 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1409 | @masd925 | http://www.freecodecamp.com/masd925
Erik Maurer
@MauPow
Apr 22 2016 07:21
Woo, finished basic algorithms :)
Luis
@zdrifted
Apr 22 2016 07:26
Nice!
RakeshNerkar
@Rakesh18754
Apr 22 2016 07:27
@Masd925 I want to merge to json objects recursively without using jquery Extend Deep copy...by pure JavaScript way...any help would be appreciated.
Markus Kiili
@Masd925
Apr 22 2016 07:29
@deepakpatil007 You wan't properties from several objects to one object? How do you handle same property names?
RakeshNerkar
@Rakesh18754
Apr 22 2016 07:32

@Masd925 var object1 = {
apple: 0,
banana: { weight: 52, price: 100 },
cherry: 97
};
var object2 = {
banana: { price: 200 },
durian: 100
};

then Output should have

object 3:-{"apple":0,"banana":{"weight":52,"price":200},"cherry":97,"durian":100}

but Object 1 and 2 should retain their values.

Markus Kiili
@Masd925
Apr 22 2016 07:44
@deepakpatil007 Something like this?
var sources = [{
  apple: 0,
  banana: { price: 100 },
  cherry: 97
},
{
  apple: 0,
  banana: { weight: 52, price: 200 },
  durian: 100
}
];

var obj = {};
for (var i=0; i<sources.length; i++) {
    for (var key in sources[i]) {
        obj[key] = sources[i][key];
    }
}

console.log(obj); // { apple: 0, banana: { weight: 52, price: 200 }, cherry: 97, durian: 100 }
You can handle existing property keys inside the loop the way you like.
Jay
@lantiwonka
Apr 22 2016 07:48

hello people, how can take one step back and show the array of the value that i have found to be the greatest after comparing it with others

``js
function largestOfFour(arr) {
// You can do this!

var storage = 0;
for (var i = 0; i < arr.length; i++)
for (var j = 0; j < arr[i].length; j++)
if(arr[i][j] > storage)
storage = arr[i][j];

return storage;

}

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

Spencer
@coderamen
Apr 22 2016 07:48

Hei all, need help to solve "Finding a Remainder in Javascript" exercise....don't quite understand cos my math kinda suck. Attach is the code ```
// Only change code below this line

var remainder;
```

// Only change code below this line

var remainder;
Jay
@lantiwonka
Apr 22 2016 07:49
your help will be appreciated
Markus Kiili
@Masd925
Apr 22 2016 07:49
@lantiwonka Initialize the variable for each subarray to 0 on -Infinity. After the inner loop, assign storage to arr[i]. Return arr at the end of function.
buiphuking
@buiphuking
Apr 22 2016 07:51
@lantiwonka concat all arr, after that arr.sort()[0];
Rada
@Radascript
Apr 22 2016 07:51
@codetechnoob do you know what a remainder means?
Markus Kiili
@Masd925
Apr 22 2016 07:53
@buiphuking Sorting is one way, but slow if you don't actually need the sorted array information. If you wan't a functional solution, using Math.max.apply is better.
Rada
@Radascript
Apr 22 2016 07:55
@lantiwonka I just sorted them from big to small and returned 1st element of each
Jay
@lantiwonka
Apr 22 2016 07:59
@buiphuking
how do i concat them if there is not any other array to concat it with ......
oh btw I am a noob here
buiphuking
@buiphuking
Apr 22 2016 08:00
@Masd925 good job !
Rada
@Radascript
Apr 22 2016 08:02
@lantiwonka make a new empty array
@lantiwonka with results
seasons
@seasonscao
Apr 22 2016 08:03
Hi, i have a issue about my code.
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUpProfile(firstName, prop){

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

   if(contacts[i].firstName === firstName && contacts[i][prop] === prop){
     return contacts[i][prop];
   }else if(contacts[i].firstName !== firstName){
     return "No such contact";
   }else{
     return "No such property";
   }
  }

}


lookUpProfile("Sherlock", "likes");
buiphuking
@buiphuking
Apr 22 2016 08:03
@lantiwonka
search Array.prototype.slice.call(arguments)
kirbyedy
@kirbyedy
Apr 22 2016 08:05
@seasonscao you might look up for hasOwnProperty
Rada
@Radascript
Apr 22 2016 08:05
@seasonscao this is part of your problem:
contacts[i][prop] === prop
when you are checking lookUpProfile("Sherlock", "likes");
that condition checks to see if his likes = likes
seasons
@seasonscao
Apr 22 2016 08:06
if( contact[i].hasOwnProperty(firstName)) ? @kirbyedy
Rada
@Radascript
Apr 22 2016 08:06
you just want to check whether it exists with either hasOwnroperty or simply you can just say contacts[i][prop] === true
or even just drop true
seasons
@seasonscao
Apr 22 2016 08:08
 contacts[i][prop] === true
?
i don’t understand it.
Joshua Swift
@joshuaswift
Apr 22 2016 08:09
@BKinahan i've read about this method but im not 100% sure how it works. Would you be able to elaborate please? Thanks!
CamperBot
@camperbot
Apr 22 2016 08:09
joshuaswift sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star: 1358 | @bkinahan | http://www.freecodecamp.com/bkinahan
Kelvin Mungai
@munga4
Apr 22 2016 08:10
@sjames1958gm Hi where is the problem4 // Example
var ourVar = 19;
// Only change code below this line
var myVar = 9;
Romain Mondon-Cancel
@skasch
Apr 22 2016 08:11

@seasonscao http://adripofjavascript.com/blog/drips/truthy-and-falsy-values-in-javascript.html

contacts[i][prop] === true

probably won't work, though either

... && contacts[i][prop]

or

contacts[i].hasOwnProperty(prop)

or

contacts[i][prop] == true

will =)

Rada
@Radascript
Apr 22 2016 08:14
@seasonscao your second issue is with your logic. As soon as the first element in the array doesn't match the name, it return "no such contact"
so what you need to do is make sure it loops through every element, and THEN if it hadn't found the one with that name, it returns "no such contact." Outside the loop.
Bhavesh
@bbhavesh
Apr 22 2016 08:30

Hey Guys
Need help completing this code

Instructions
Write a switch statement to set answer for the following ranges:
1-3 - "Low"
4-6 - "Mid"
7-9 - "High"

Note
You will need to have a case statement for each number in the range.

This is what is have written

switch(val) {
case 1:
case 2:
case 3:
result = "Low";
break;
case 4:
case 5:
case 6:
result = "Mid";
break;
case 7:
case 8:
case 9:
result = "High";
break;

]
}
Romain Mondon-Cancel
@skasch
Apr 22 2016 08:35
This message was deleted
@bbhavesh Your function do not return the result =)
Luis
@zdrifted
Apr 22 2016 08:36
What does it mean to "truncate a string"?
Romain Mondon-Cancel
@skasch
Apr 22 2016 08:37
@Rushh It means to remove some characters from the string
buiphuking
@buiphuking
Apr 22 2016 08:37
hi guys, i do No repeats please,
is there anyway to get that number instead list permutations and count them ?
Bhavesh
@bbhavesh
Apr 22 2016 08:37
@skasch What would be the right way ?
Romain Mondon-Cancel
@skasch
Apr 22 2016 08:39

@bbhavesh Actually your code should work, if you do as follow:

var val = 2;

switch(val) {
  case 1:
  case 2:
  case 3:
    result = "Low";
    break;
  case 4:
  case 5:
  case 6:
    result = "Mid";
    break;
  case 7:
  case 8:
  case 9:
    result = "High";
    break;
}

result; // === 'Low'

You just forgot a ] that should not have been here

Rustem Garaev
@fuko4
Apr 22 2016 08:41
Hi! Why is it impossible?
if(arr[i] === arr[last]){ return true; } else { return false; break; }
braek after return false
break*
How can I replace it?
Bhavesh
@bbhavesh
Apr 22 2016 08:44
@skasch Its not there actually
I typed it here in error
But my code still wont work
Romain Mondon-Cancel
@skasch
Apr 22 2016 08:44
@fuko4 Just remove it, if you return false, you probably don't have to break any loop am I right?
seasons
@seasonscao
Apr 22 2016 08:46
@Radascript Ok, i solved it. Thank you ;-)
CamperBot
@camperbot
Apr 22 2016 08:46
seasonscao sends brownie points to @radascript :sparkles: :thumbsup: :sparkles:
:star: 320 | @radascript | http://www.freecodecamp.com/radascript
Romain Mondon-Cancel
@skasch
Apr 22 2016 08:46
@bbhavesh what is your full code?
Rustem Garaev
@fuko4
Apr 22 2016 08:46
@skasch It's a for loop and I need to stop and return false

`function palindrome(str) {
var newStr = str.replace(/\s/g, "").replace(/,/g, "").replace(/./g, "");
var arr = newStr.toLowerCase().split('');
for(var i = 0; i < arr.length; i++){
var last = arr.length - 1 - i;
if(arr[i] === arr[last]){
return true;
}
else {
return false;
break;
}

}

}`

Bhavesh
@bbhavesh
Apr 22 2016 08:47
@skasch
switch(val) {
case 1:
case 2:
case 3:
result = "Low";
break;
case 4:
case 5:
case 6:
result = "Mid";
break;
case 7:
case 8:
case 9:
result = "High";
break;
}
Romain Mondon-Cancel
@skasch
Apr 22 2016 08:47
@fuko4 If your for loop is inside the function, return will stop the execution of the function and return the result
@bbhavesh val is not defined in your code, so the switch won't work =)
Ryan
@ryan-jd
Apr 22 2016 08:49
@bbhavesh your switch function looks fine - if you have already defined val are you returning or console logging result after the switch?
Rustem Garaev
@fuko4
Apr 22 2016 08:49
@skasch But it does not work :(
Eldar Tinjić
@EldarT90
Apr 22 2016 08:49
function uniteUnique(arr1, arr2, arr3) {
 var newArr = [];

 var comp = arr1.concat(arr2,arr3);
 var newStr = comp.join(",");

  for (var i=0; i<comp.length; i++) {
     if (comp[i] == newArr[i]) {
       newArr.push(comp[i]);
     }

      }


  return newArr;
}

uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
i cant use indexOf
so what should i use?
Rustem Garaev
@fuko4
Apr 22 2016 08:50
how to insert the code
Romain Mondon-Cancel
@skasch
Apr 22 2016 08:50

@fuko4

var newStr = str.replace(/\s/g, "").replace(/,/g, "").replace(/./g, "");

at the last regex, you replace every character with a "", so newStr === ""

Abdul-Samii Ajala Olalekan
@jalasem
Apr 22 2016 08:50
Please I need an advice, which alternative do I have to upload my audio files so that I can embed them on my website apart from soundcloud. Soundcloud.com have a limit of 150minutes and I want to upload audio files that are more than that.
Bhavesh
@bbhavesh
Apr 22 2016 08:50
@ryan-jd
Returning
Romain Mondon-Cancel
@skasch
Apr 22 2016 08:51
@fuko4 You need to escape the point to replace the character . as follow:
var newStr = str.replace(/\s/g, "").replace(/,/g, "").replace(/\./g, "");
Bhavesh
@bbhavesh
Apr 22 2016 08:51
@skasch how do i define val ?
Romain Mondon-Cancel
@skasch
Apr 22 2016 08:51
@bbhavesh var val = 4 for example =)
@jalasem The more flexible solution would be to host the file yourself =)
Bhavesh
@bbhavesh
Apr 22 2016 08:53

@skasch
This is how it looks here

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

switch(val) {
case 1:
case 2:
case 3:
result = "Low";
break;
case 4:
case 5:
case 6:
result = "Mid";
break;
case 7:
case 8:
case 9:
result = "High";
break;
}

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

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

Where am i going wrong ?
Rustem Garaev
@fuko4
Apr 22 2016 08:54
@skasch I have already corrected :)
Romain Mondon-Cancel
@skasch
Apr 22 2016 08:54
@bbhavesh You return answer which is equal to ""; you change the variable result in your code, not the variable answer =)
@fuko4 Still doesn't work?
Rustem Garaev
@fuko4
Apr 22 2016 08:55
@skasch All the conditions except one.
Abdul-Samii Ajala Olalekan
@jalasem
Apr 22 2016 08:55
If I do so i have to contend with file formats and compatibilty accross paltforms @bbhavesh
Romain Mondon-Cancel
@skasch
Apr 22 2016 08:56
@fuko4 You actually return true if the first character is equal to the last one; you have to check if every character is equal to its mirrored one.
Bhavesh
@bbhavesh
Apr 22 2016 08:57
@skasch
I am sorry, but could you pls just show me how do we do it ?
Romain Mondon-Cancel
@skasch
Apr 22 2016 08:59
function myTest(val) {
  // Let's suppose val = 4
  var answer = "";
  switch(val) {
    case 1:
    case 2:
    case 3:
      result = "Low";
      break;
    case 4:
    case 5:
    case 6:
      result = "Mid";
      break;
    case 7:
    case 8:
    case 9:
      result = "High";
      break;
    }
  // at this point, val = 4, answer = "" and result = "Mid"
  return answer;
}
Rustem Garaev
@fuko4
Apr 22 2016 09:00
@skasch I check all the characters . And when the characters are not even loop will to stop and return false. But do not stop!
Romain Mondon-Cancel
@skasch
Apr 22 2016 09:00
@fuko4 When the first character is equal to the last, the function reads return true; and then the function stops immediately and return the value true
UDAY PRAPHULLA MALANGAVE
@malangaveuday
Apr 22 2016 09:02
any one know free news feed api?
Brendan Kinahan
@BKinahan
Apr 22 2016 09:03
@Joshuaswift sorry, I'm just waking up and saw your message ( :point_up: April 22, 2016 8:09 AM ). Did you get the help you needed?
Rustem Garaev
@fuko4
Apr 22 2016 09:06
@skasch Now I understand!!!
Rustem Garaev
@fuko4
Apr 22 2016 09:12
I made ​​a return false outside the for loop and earned .
@skasch But now it is not performed here this condition palindrome("0_0 (: /-\ :) 0-0")
palindrome("0_0 (: /-\ :) 0-0")
should return true
Robert Uivarosi
@URobert
Apr 22 2016 09:15
@malangaveuday Im not sure if you are after the FCC news api response or not but here it the url for that:https://www.freecodecamp.com/news/hot `
Brendan Kinahan
@BKinahan
Apr 22 2016 09:15
@fuko4 how are you removing punctuation?
@fuko4 you need to remove all symbols/characters that are not numbers or letters
Rustem Garaev
@fuko4
Apr 22 2016 09:16
@BKinahan
var newSring = names.replace(/\s/g, "").replace(/,/g, "").replace(/\./g, "");
Erik Maurer
@MauPow
Apr 22 2016 09:17
Can someone help me out with pulling JSON from an API and rendering it in HTML?
Brendan Kinahan
@BKinahan
Apr 22 2016 09:17
@fuko4 ah, so you only remove spaces, commas, and periods. Try out some other regex learning tools like http://regexone.com and http://regex101.com
Erik Maurer
@MauPow
Apr 22 2016 09:17
$(document).ready(function() {
  $("#getMessage").on("click", function() {$.getJSON("http://api.icndb.com/jokes/random", function(json) {

      var html = "";

      json = json.filter(function(val) {
        return (val.id === "joke");
      });

      html = JSON.stringify(json);

      $(".message").html(html);

  });
    });
});
What is wrong with that? when I click my button, nothing happens
Brendan Kinahan
@BKinahan
Apr 22 2016 09:18
@MauPow I'm not sure json is returned as an array, and .filter() won't work on it ifi it's not one.
Rustem Garaev
@fuko4
Apr 22 2016 09:18
@skasch Thank you!
CamperBot
@camperbot
Apr 22 2016 09:18
fuko4 sends brownie points to @skasch :sparkles: :thumbsup: :sparkles:
:star: 204 | @skasch | http://www.freecodecamp.com/skasch
Erik Maurer
@MauPow
Apr 22 2016 09:19
Ok, that's just the code from the tutorial
So how do you grab just one id
er value
Rustem Garaev
@fuko4
Apr 22 2016 09:20
@BKinahan I should just delete all these characters ? It is necessary to compare only the numbers and letters ?
Brendan Kinahan
@BKinahan
Apr 22 2016 09:20
@MauPow maybe it is an array, then, if it's from the tutorial :P try to console.log(json) and see what form it actually takes, that'll help you see how to access certain parts of it, too.
Erik Maurer
@MauPow
Apr 22 2016 09:20
It's not an array I don't think actually
I've got it pulling random quotes now
{"type":"success","value":{"id":275,"joke":"Little Miss Muffet sat on her tuffet, until Chuck Norris roundhouse kicked her into a glacier.","categories":[]}}
Brendan Kinahan
@BKinahan
Apr 22 2016 09:21
@fuko4 correct, you only need to compare numbers and letters
Erik Maurer
@MauPow
Apr 22 2016 09:21
What hte hell do I do with this haha
I just want "joke"
Brendan Kinahan
@BKinahan
Apr 22 2016 09:21
@MauPow okay, so you have an object there, because it starts and ends with {}. Do you remember the challenges about accessing object properties?
Erik Maurer
@MauPow
Apr 22 2016 09:22
vaguely... with bracket notation?
value["joke"]?
Brendan Kinahan
@BKinahan
Apr 22 2016 09:23
@MauPow the joke text is held within a "joke" property of an object which is within the "value" property of the main object (json in this case)
Erik Maurer
@MauPow
Apr 22 2016 09:23
ooh got it!
Thanks @BKinahan for the reminder
CamperBot
@camperbot
Apr 22 2016 09:23
maupow sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star: 1360 | @bkinahan | http://www.freecodecamp.com/bkinahan
Brendan Kinahan
@BKinahan
Apr 22 2016 09:23
no worries :)
Matt
@Pixelbark
Apr 22 2016 09:25
Hi, I'm also having trouble with JSON accessing:
myPlants[1].trees
returns "Cannot read property '1' of undefined
oops
// Setup
var myPlants = [
  { 
    type: "flowers",
    list: [
      "rose",
      "tulip",
      "dandelion"
    ]
  },
  {
    type: "trees",
    list: [
      "fir",
      "pine",
      "birch"
    ]
  }  
];

// Only change code below this line

var secondTree = myPlants[1].trees[1]; // Change this line
Rustem Garaev
@fuko4
Apr 22 2016 09:28
@BKinahan I need to remove these symbols . But it will remain an empty array. How, then, to compare ?
Kelvin
@loweehahn
Apr 22 2016 09:29
Why do I get an output of 6 in this code? How do I access the values outside of []?
function destroyer(arr) {
  // Remove all the values
  return arr.length;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Markus Kiili
@Masd925
Apr 22 2016 09:29
@loweehahn Use arguments object. arr only contains the first passed argument.
Kelvin
@loweehahn
Apr 22 2016 09:31
@Masd925 I have trouble understanding the arguments object documentation in Mozilla Development Network website. Could you explain how arguments object works?
Rustem Garaev
@fuko4
Apr 22 2016 09:31
@BKinahan Thank you!
CamperBot
@camperbot
Apr 22 2016 09:31
fuko4 sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star: 1361 | @bkinahan | http://www.freecodecamp.com/bkinahan
Brendan Kinahan
@BKinahan
Apr 22 2016 09:33
@Pixelbark trees is not an array or property name
Matt
@Pixelbark
Apr 22 2016 09:34
OH! I see what I've done.
@BKinahan Thank you!
CamperBot
@camperbot
Apr 22 2016 09:35
pixelbark sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star: 1362 | @bkinahan | http://www.freecodecamp.com/bkinahan
Ankur sharma
@ankur1163
Apr 22 2016 09:43
can someone tell me meaning of this code
var alpha = {
  1:"Z",
  2:"Y",
  3:"X",
  4:"W",
  ...
  24:"C",
  25:"B",
  26:"A"
};
alpha[2]; // "Y"
alpha[24]; // "C"

var value = 2;
alpha[value]; // "Y"
I dont understand last 2 lines
var value =2;
alpha[value]; //y
Samuel Cupidon
@Zerazera
Apr 22 2016 09:44
var value = 2 assigns 2 to the variable value
Ankur sharma
@ankur1163
Apr 22 2016 09:44
we are creating new variable value having 2 in it
Samuel Cupidon
@Zerazera
Apr 22 2016 09:45
alpha[value] = alpha2 which refers to the item in the alpha object with index 2
Ankur sharma
@ankur1163
Apr 22 2016 09:45
alpha doesnt have any property "value"
Matt
@Pixelbark
Apr 22 2016 09:45
It's a demonstration on how you would use your own code to access properties in an object.
so essentially it is saying that alpha[2] == "y"
Samuel Cupidon
@Zerazera
Apr 22 2016 09:46
@ankur1163 If alpha had the property value you would access it as alpha.value or alpha['value']
buiphuking
@buiphuking
Apr 22 2016 09:47
guys, who passed " No repeats please " , plz give me some advice , plz
Matt
@Pixelbark
Apr 22 2016 09:47
so if you changed the last two lines to say:
var maguffin = 2;
alpha[maguffin]
alpha[maguffin]
would return 'y'
Samuel Cupidon
@Zerazera
Apr 22 2016 09:49
@ankur1163 Technically, in your example, alpha should probably be an array rather than an object.
SuryaKavutarapu
@SuryaKavutarapu
Apr 22 2016 09:49

guys need help i'm stuck over here !
function convertToF(celsius) {
// Only change code below this line
var cel = celsius;
var fahrenheit = cel * 9%5 +32;

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

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

Brendan Kinahan
@BKinahan
Apr 22 2016 09:54
@SuryaKavutarapu % is the remainder operator, not division
@SuryaKavutarapu so your code multiplies cel by 4 instead of 1.8
Ankur sharma
@ankur1163
Apr 22 2016 09:55
@Pixelbark @Zerazera normally when we do var maguffin = 2 ; . It is completely new varibla e? independent of all the other variables?
I cant wrap my head around how var value = 2 changes something in the array
Samuel Cupidon
@Zerazera
Apr 22 2016 09:55
Var value = 2 does nothing to object
It assigns 2 to the variable value
SuryaKavutarapu
@SuryaKavutarapu
Apr 22 2016 09:56
@BKinahan Thank you. i'm done with that.
CamperBot
@camperbot
Apr 22 2016 09:56
suryakavutarapu sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
Samuel Cupidon
@Zerazera
Apr 22 2016 09:56
You can then use the variable to reference the index in the object
CamperBot
@camperbot
Apr 22 2016 09:56
:star: 1363 | @bkinahan | http://www.freecodecamp.com/bkinahan
Ankur sharma
@ankur1163
Apr 22 2016 09:57
ok so var value = 2 ; creates new variable and assign value 2
ahh
so alpha[value]; is
alpha[2] and that points to array
and gives value y
Samuel Cupidon
@Zerazera
Apr 22 2016 09:58
Exactly
Ankur sharma
@ankur1163
Apr 22 2016 09:58
I got it now
:)
Samuel Cupidon
@Zerazera
Apr 22 2016 09:58
Object in this case, not array
Matt
@Pixelbark
Apr 22 2016 09:59
Awesome!
Aleksej
@tip14
Apr 22 2016 10:07
help
CamperBot
@camperbot
Apr 22 2016 10:07

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

Matt
@Pixelbark
Apr 22 2016 10:07
wiki JSON
CamperBot
@camperbot
Apr 22 2016 10:07

:point_right: challenge accessing nested arrays in json [wiki]

Challenge: Accessing Nested Arrays in JSON

As we have seen in earlier examples, JSON objects can contain both nested objects and nested arrays. Similar to accessing nested objects, Array bracket notation can be chained to access nested arrays.

Here is an example of how to access a nested array:

```js
var ourPets = {
"cats": [
"Meowzer",
"Fluffy",
"Kit-Cat"
],
"dogs": [
"Spot",
"Bowser",
"Frankie"
]
};
ourPets.cats[1]; // "Fluffy"
:pencil: read more about challenge accessing nested arrays in json on the FCC Wiki

SuryaKavutarapu
@SuryaKavutarapu
Apr 22 2016 10:09
This message was deleted
Ankur sharma
@ankur1163
Apr 22 2016 10:10
thanks @Zerazera
CamperBot
@camperbot
Apr 22 2016 10:10
ankur1163 sends brownie points to @zerazera :sparkles: :thumbsup: :sparkles:
SuryaKavutarapu
@SuryaKavutarapu
Apr 22 2016 10:10
This message was deleted
CamperBot
@camperbot
Apr 22 2016 10:10

:point_right: advantages and disadvantages of javascript [wiki]

Advantages & Disadvantages of JavaScript

Like all computer languages, JavaScript has certain advantages and disadvantages. Many of the pros and cons are related to being a client-side language.

:pencil: read more about advantages and disadvantages of javascript on the FCC Wiki

:star: 388 | @zerazera | http://www.freecodecamp.com/zerazera
Ankur sharma
@ankur1163
Apr 22 2016 10:10
thanks @Pixelbark
CamperBot
@camperbot
Apr 22 2016 10:10
ankur1163 sends brownie points to @pixelbark :sparkles: :thumbsup: :sparkles:
:star: 234 | @pixelbark | http://www.freecodecamp.com/pixelbark
karanag
@karanag
Apr 22 2016 10:10
This message was deleted
im only getting no such property and no such contact

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

  }
        return "No such property";

}

}
return "No such contact";

Matt
@Pixelbark
Apr 22 2016 10:12

New to JSON, can someone just give me a quick yes or no answer for the following before I plough right into it:

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 updateRecords(id, prop, value) {

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

  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");

Am I on the right track with this challenge? As I have a gut feeling I'm doing this completely wrong.

Stephen James
@sjames1958gm
Apr 22 2016 10:13
@Pixelbark The first statement in the if is wrong the second is correct.
@Pixelbark Ooops relooking they both are not correct
Matt
@Pixelbark
Apr 22 2016 10:14
oh yeah, that needs to be an || to begin with. But thanks, time to read up on JSON.
Thanks @sjames1958gm
CamperBot
@camperbot
Apr 22 2016 10:15
pixelbark sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 745 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Apr 22 2016 10:15
@Pixelbark When working with JSON work outside in. Collection is the object name, id selects a sub-object of collection and prop selections a property of that sub-object. Since they are variables use the bracket notation
@Pixelbark You can only use dot notation when you have the property name "hardcoded" collection.5439.album is correct, but collection.id.prop is not
Ankur sharma
@ankur1163
Apr 22 2016 10:17
can someone tell me why I am getting undefined here
Matt
@Pixelbark
Apr 22 2016 10:17
how would I select the sub-object of a sub-object? Would collection[id[prop]] work?
Ankur sharma
@ankur1163
Apr 22 2016 10:17
// 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("charlie");
Stephen James
@sjames1958gm
Apr 22 2016 10:18
@Pixelbark collection[id][prop] what you wrote would select the property of collection that is stored as a property of the id variable
Matt
@Pixelbark
Apr 22 2016 10:19
Ahhh, fantastic.
Thanks @sjames1958gm :)
CamperBot
@camperbot
Apr 22 2016 10:19
pixelbark sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: pixelbark already gave sjames1958gm points
Stephen James
@sjames1958gm
Apr 22 2016 10:20
@ankur1163 When the property is in a variable you have to use bracket notation. lookup.val is looking for a property named val
@Pixelbark When you encounter an array in JSON the value in [] is the array index.
Ankur sharma
@ankur1163
Apr 22 2016 10:23
result = lookup.[val];
this is also showing incorrect
Blauelf
@Blauelf
Apr 22 2016 10:24
dot notation or bracket notation, not both. Here, you want lookup[val].
Ankur sharma
@ankur1163
Apr 22 2016 10:24
and it worked
thanks @sjames1958gm
CamperBot
@camperbot
Apr 22 2016 10:24
ankur1163 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 746 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Ankur sharma
@ankur1163
Apr 22 2016 10:24
thanks @Blauelf
CamperBot
@camperbot
Apr 22 2016 10:24
ankur1163 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1708 | @blauelf | http://www.freecodecamp.com/blauelf
Stephen James
@sjames1958gm
Apr 22 2016 10:35
@ankur1163 :+1:
Ankur sharma
@ankur1163
Apr 22 2016 10:58
can someone tell me whats the problem in my code?
// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here
  if(myObj.hasOwnProperty("checkProp"))
  {
    return "Change Me!";
  }
  else{
    return "not Found";

  }

}

// Test your code by modifying these values
checkObj("gift");
its showing me "not found" which is obviously wrong
Stephen James
@sjames1958gm
Apr 22 2016 10:59
@ankur1163 Don't put your variable into string
@ankur1163 You are looking up "checkProp" not the value of the prop in checkProp
Ankur sharma
@ankur1163
Apr 22 2016 11:00
so i should eliminate quotes
from"checkprop"
Stephen James
@sjames1958gm
Apr 22 2016 11:00
@ankur1163 yes
Ankur sharma
@ankur1163
Apr 22 2016 11:00
ok
let me see
it worked
thanks @sjames1958gm
CamperBot
@camperbot
Apr 22 2016 11:01
ankur1163 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: ankur1163 already gave sjames1958gm points
Stuart Taylor
@Bouncey
Apr 22 2016 11:11
Hi guys I've been stuck on this for a day now and i cant get it to work
I had to convert a switch to a lookup table. I hope someone can tell me what I am doing wrong
// 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"
  };
  // Only change code above this line
  return result;
}

// Change this value to test
phoneticLookup("charlie");
Mooli
@Mooli88
Apr 22 2016 11:13
@Bouncey where have you got so far ?
i dont see you trying to return anything
Stuart Taylor
@Bouncey
Apr 22 2016 11:14
yea, i just cracked it, i was missing this line
result = lookup[val];
its working now, false al;arm haha
Mooli
@Mooli88
Apr 22 2016 11:20
hi guys , how can i stack [i] over an array ? like from this arr[i] to this arr[i][i][i] ?
Rudolf Carl Pablico
@rudolfpablico
Apr 22 2016 11:24
hi guys, need some help on profile lookup exercise,

here is my code

var i = 0;
while ( i <= contacts[i].length) {
if (contacts[i].firstName !== firstName) {
if (i > contact[i].length) {
return "No such contact";
}
else { i++; }

    }
    else {

            if (contacts[i].hasOwnProperty(prop)) {
              return contacts[i][prop];
            }
            else { return "No such property"; }

    }

  }
 return "No such contact";
Mooli
@Mooli88
Apr 22 2016 11:26
@rudolfpablico check that you are not returning too soon
Rudolf Carl Pablico
@rudolfpablico
Apr 22 2016 11:26
@Mooli88 at which part are you pertaining?
Mooli
@Mooli88
Apr 22 2016 11:27
@rudolfpablico if you returning before the loops end than you havn't check all opetions
V Arun Kumar
@arunvkumr
Apr 22 2016 11:28
@rudolfpablico i > contact[i].length try removing the [i] from here and typo contact should be contacts.
Jackson Bates
@JacksonBates
Apr 22 2016 11:29

Help me clean up a real mess! I have an array containing 12 objects. The keys for each object represent a number and the value associated with each key is a quantity of the times that number occured in a data set. Here's the array:

[{"13":1},
{"2":2,"3":1},
{"11":1},
{"2":1,"5":1},
{"3":2},
{"2":3},
{"7":1},
{"2":1,"3":1},
{"5":1},
{"2":2},
{"3":1},
{"2":1}]

How can I extract only the keys that have the highest count / frequency to create a new object like this {"13":1, "11":1, "7":1, "5":1, "3":2, "2":3} ? (the order of the key/values in the final object is not important, this example is just for illustration)...

CamperBot
@camperbot
Apr 22 2016 11:29
no wiki entry for: me clean up a real mess i have an array containing 12 objects the keys for each object represent a number and the value associated with each key is a quantity of the times that number occured in a data set heres the arrayjs13122311112151322371213151223121how can i extract only the keys that have the highest count frequency to create a new object like this 131 111 71 51 32 23 the order of the keyvalues in the final object is not important this example is just for illustration
Rudolf Carl Pablico
@rudolfpablico
Apr 22 2016 11:30
@Mooli88 i've tried to removed the last return, no results shows
@arunkumrv done correcting typos still doesn't work
V Arun Kumar
@arunvkumr
Apr 22 2016 11:31
@rudolfpablico post your code with changes.
Rudolf Carl Pablico
@rudolfpablico
Apr 22 2016 11:32
@arunkumrv

var i = 0;
while ( i <= contacts.length) {
if (contacts[i].firstName !== firstName) {
if (i > contacts.length) {
return "No such contact";
}
else { i++; }

    }
    else {

            if (contacts[i].hasOwnProperty(prop)) {
              return contacts[i][prop];
            }
            else { return "No such property"; }

    }

  }

return "No such contact";

it only fails now on "Bob", "number" should return "No such contact"
Mooli
@Mooli88
Apr 22 2016 11:34
@rudolfpablico first check if contacts[].firstName actually match firstName
then check if it has property
if all match then return the result . if not return 'no-result'
V Arun Kumar
@arunvkumr
Apr 22 2016 11:36
This message was deleted
Mooli
@Mooli88
Apr 22 2016 11:38
anyone here done 'Steamroller' ?
Jackson Bates
@JacksonBates
Apr 22 2016 11:40
@Mooli88 I passed 3/4 tests...it was frustrating me
V Arun Kumar
@arunvkumr
Apr 22 2016 11:40
@rudolfpablico while(i <= contacts.length) change it to i < contacts.length
Rudolf Carl Pablico
@rudolfpablico
Apr 22 2016 11:41
@arunkumrv thanks man! :+1:
CamperBot
@camperbot
Apr 22 2016 11:41
rudolfpablico sends brownie points to @arunkumrv :sparkles: :thumbsup: :sparkles:
:star: 510 | @arunkumrv | http://www.freecodecamp.com/arunkumrv
Rudolf Carl Pablico
@rudolfpablico
Apr 22 2016 11:41
@arunkumrv but how?
Mooli
@Mooli88
Apr 22 2016 11:41
@JacksonBates i'm trying to use loop so i could go dipper and dipper in the array . like this arr[i][i][i] but i dont understand how to do that
Rudolf Carl Pablico
@rudolfpablico
Apr 22 2016 11:41
can you explain it to me?
Mooli
@Mooli88
Apr 22 2016 11:41
arr[i] + [i] wont add them together like that arr[i][i]
@rudolfpablico just use for loop.
Rudolf Carl Pablico
@rudolfpablico
Apr 22 2016 11:43
@Mooli88 can you show me your code for this?
Ken Haduch
@khaduch
Apr 22 2016 11:43
@Mooli88 - I think that using recursion is a lot easier for the steamroller exercise - it might be the only way? I forget what they taught on that, I did the exercise a while ago.
Jackson Bates
@JacksonBates
Apr 22 2016 11:43
@Mooli88 I've forgotten what I was trying to do. I just reviewed my abandonned code and it starts with 3 messy regex replace strings! No idea what I was doing!
V Arun Kumar
@arunvkumr
Apr 22 2016 11:44
@rudolfpablico since contacts is an array.. the values are from 0 to 3 because contacts has 4 entreis. so it should check from 0 to 3. so i < contacts.length, contacts.length is 4. and i <= contacts.length means you are checking for one extra value.. which doesn't exist.
Mooli
@Mooli88
Apr 22 2016 11:44
@JacksonBates lol!
Jackson Bates
@JacksonBates
Apr 22 2016 11:45
@Mooli88 It did pass three of the tests, though, so I was on to something :)
Mooli
@Mooli88
Apr 22 2016 11:45
@khaduch excuse my ignorance but what are recursion
@JacksonBates but im pretty sure that if you used regex its mean you knew the depth of each array . i want to automate it in a way the loop will go deeper if there isn;t a number there...
@rudolfpablico try one more time. reset the challenge and start with for loop that checks for first name
Ken Haduch
@khaduch
Apr 22 2016 11:46

@rudolfpablico - since the contacts list is an array, using a for loop is a sensible way to do this. I thought of a good way to start thinking about this - what would you do if you just wanted to print the first names of each of the contacts? Then I had another explanation that I was trying to develop - this is what I came up with:

you only need to iterate over the list until you find a firstName that matches. As the problem conditions state - when you get a firstName match, you can either return the property, if it is present, or return "No such property", if it is not present. And that terminates the loop and the function. Only after examining all of the entries can you make the determination that a contact does not exist. Then you have to return the "No such contact" status, but that will be outside of the block of code that the for loop is executing.

V Arun Kumar
@arunvkumr
Apr 22 2016 11:47
and the inner if block never runs, you can remove it. and try using for loop. in for loop you can keep track of the iterations. while and do-while it's little difficult because you have to specify the initialization seperately and increment seperately..
@rudolfpablico
Ken Haduch
@khaduch
Apr 22 2016 11:47
@Mooli88 - a recursive function is a function that calls itself repeatedly to solve a problem.
Mooli
@Mooli88
Apr 22 2016 11:48

@khaduch you mean like

function func(){
if(true){
return xyz
}else{
func()
}

}

sort of ?

Jackson Bates
@JacksonBates
Apr 22 2016 11:50
@khaduch would recursion be an approach for the problem I posted earlier? Something about calling itself repeatedly rang a very faint bell, but I'm too tired to join the dots :point_up: April 22, 2016 9:29 PM
Ken Haduch
@khaduch
Apr 22 2016 11:52
@Mooli88 - yes, that's sort of the idea. In this case, if you have an array as the particular item you are looking at, you would call the 'steamroller' function again. It's a little tricky to wrap your head around.
V Arun Kumar
@arunvkumr
Apr 22 2016 11:52
@JacksonBates have a look at Object.keys(myObj) function. this function returns an array of keys of the obj you pass.
Mooli
@Mooli88
Apr 22 2016 11:52
is there any other way to access multi denominational array other than arr[i][i] ?
Jackson Bates
@JacksonBates
Apr 22 2016 11:53
@arunkumrv I'll take a look. I was reading the MDN entries on basically everything relating to objects - knowing to focus my efforts on Object.keys will help, thanks
CamperBot
@camperbot
Apr 22 2016 11:53
jacksonbates sends brownie points to @arunkumrv :sparkles: :thumbsup: :sparkles:
:star: 511 | @arunkumrv | http://www.freecodecamp.com/arunkumrv
Ken Haduch
@khaduch
Apr 22 2016 11:54
@rudolfpablico - your approach using a while loop might work, but what you want to use for your loops condition is not what you have, but this: while ( i <= contacts.length) {
Mooli
@Mooli88
Apr 22 2016 11:56
@khaduch my plan was to check it the arr[i] is an array and it has length > 0 if yes than i'll loop through it to check for typeof() `` number but again the problem is that i dont know how to access deeper lvl of the array automatically
Ken Haduch
@khaduch
Apr 22 2016 11:56
@JacksonBates - I don't think that you would need it for that, because it is a "flat" array, nothing nested inside of other objects.
Jackson Bates
@JacksonBates
Apr 22 2016 11:56
@khaduch thanks - boning up on keys at the moment :)
CamperBot
@camperbot
Apr 22 2016 11:56
jacksonbates sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star: 986 | @khaduch | http://www.freecodecamp.com/khaduch
Ken Haduch
@khaduch
Apr 22 2016 11:58
@Mooli88 - that is where recursion comes into play - essentially, any time you see an array, you would have the function call itself again to process it. So if there are 10 levels of nested arrays, it would call itself 10 times to flatten that.
Mooli
@Mooli88
Apr 22 2016 11:59
@khaduch i dont understand how it would help. how can i create a situation that this happen arr[i][i][i] without manually writing it
@khaduch and why not just use while loop instead ?
Mooli
@Mooli88
Apr 22 2016 12:04
how can i unstring something ?
Brendan Kinahan
@BKinahan
Apr 22 2016 12:04
@Mooli88 unstring?
Mooli
@Mooli88
Apr 22 2016 12:05
from '1' to 1
Ken Haduch
@khaduch
Apr 22 2016 12:05

@Mooli88 - the problem with trying to use nested loops or anything like that is that you don't know how many levels of nesting you will need.

I did a google search for recursion and found this link: http://www.htmlgoodies.com/primers/jsp/article.php/3622321/Javascript-Basics-Part-12.htm, where he talks about recursion and even mentions exactly this type of problem.

Mooli
@Mooli88
Apr 22 2016 12:06
@khaduch 1. thats what while loop is for. to keep digging until meet a certain condition.
  1. thanks i'll read it in a min
Brendan Kinahan
@BKinahan
Apr 22 2016 12:06
@Mooli88 + '1' or parseInt('1') or Number('1') all work
CamperBot
@camperbot
Apr 22 2016 12:06
mooli88 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star: 987 | @khaduch | http://www.freecodecamp.com/khaduch
Mooli
@Mooli88
Apr 22 2016 12:07
@BKinahan what about ['1', '2', '3'] ? loop ?
Brendan Kinahan
@BKinahan
Apr 22 2016 12:08
@Mooli88 loop, or something like this:
['1', '2', '3'].map(function(value) {
return +value;
});
Mooli
@Mooli88
Apr 22 2016 12:09
@BKinahan thanks!
CamperBot
@camperbot
Apr 22 2016 12:09
mooli88 sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star: 1364 | @bkinahan | http://www.freecodecamp.com/bkinahan
Ankit Panwar
@coderNoob
Apr 22 2016 12:17

My program is reaching this code but it is not flashing as I hoped it would. Why?

else{
    var flash = setInterval(function(){
      if($("#score").text() !== "- -")   
        $("#score").text(" ");
      else
        $("#score").text("- -");
    }, 5000);
    clearInterval(flash);
  }

This if loop works if I take it out of the setInterval() call back function.

Stephen James
@sjames1958gm
Apr 22 2016 12:18
@coderNoob Aren't you clearing the timer immediately after starting it?
Ankit Panwar
@coderNoob
Apr 22 2016 12:18
@sjames1958gm Isn't it executing the function till 5000ms before clearing it?
Stephen James
@sjames1958gm
Apr 22 2016 12:19
@coderNoob setInterval returns immediately the function is scheduled 5000ms in the future
A H
@allenhsieh
Apr 22 2016 12:19
Hi All, I'm having a bit of trouble with the Find The Longest Word in a String Exercise. I am trying to do it in 3 steps:
1) Split the given string into an array
2) Using a for loop, run 'push(i.length)' and push into a second array
3) finally sort the second array from greatest to least and return the greatest number stored in array2[0]
function findLongestWord(str) {
  var array = [];
  var array2 = [];
  array = str.split(' ');
  for (var i in array){
    array2.push(i.length);
  }
  array2.sort(function(a, b){
    return b - a;
  });
  return array2[0];
}

findLongestWord("The quick brown fox jumped over the lazy dog");
Ankur sharma
@ankur1163
Apr 22 2016 12:19
@sjames1958gm
whats issue in this code
A H
@allenhsieh
Apr 22 2016 12:19
It keeps on returning 1 only
Ankit Panwar
@coderNoob
Apr 22 2016 12:19
@sjames1958gm I don't understand.
Ankur sharma
@ankur1163
Apr 22 2016 12:20
var myPlants = [
  { 
    type: "flowers",
    list: [
      "rose",
      "tulip",
      "dandelion"
    ]
  },
  {
    type: "trees",
    list: [
      "fir",
      "pine",
      "birch"
    ]
  }  
];

// Only change code below this line

var secondTree = "myPlants[1].list[1]";
it has issue in myplants[1].list[1]
instructions - Retrieve the second tree from the variable myPlants using object dot and array bracket notation.
Stephen James
@sjames1958gm
Apr 22 2016 12:20
@coderNoob setInterval puts a timer on the queue to call the function returning immediately where you clear the interval removing the timer from the queue.
@coderNoob If you want a one shot timer, then use setTimeout.
Ankit Panwar
@coderNoob
Apr 22 2016 12:21
@sjames1958gm I need a flashing text to indicate a wrong move.
@sjames1958gm I though it would execute the function for 5000ms and then stop.
Diego Mayer
@Chrono79
Apr 22 2016 12:22
@ankur1163 remove the ""
var secondTree = myPlants[1].list[1];
Stephen James
@sjames1958gm
Apr 22 2016 12:22
You can start a one shot timer to stop the flashing after a certain time.
Ankur sharma
@ankur1163
Apr 22 2016 12:22
thanks @Chrono79
CamperBot
@camperbot
Apr 22 2016 12:22
ankur1163 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star: 469 | @chrono79 | http://www.freecodecamp.com/chrono79
Stephen James
@sjames1958gm
Apr 22 2016 12:23
@coderNoob That executes the function every 5000ms
Ankit Panwar
@coderNoob
Apr 22 2016 12:24
@sjames1958gm Then how do I make this text flash every 600 ms?
Stephen James
@sjames1958gm
Apr 22 2016 12:24
    var flash = setInterval(function(){
      if($("#score").text() !== "- -")   
        $("#score").text(" ");
      else
        $("#score").text("- -");
    }, 600);
    setTimeout(function () {clearInterval(flash);}, 5000);
Ankit Panwar
@coderNoob
Apr 22 2016 12:25
@sjames1958gm Didn't work.
Caleb Martin
@caleb272
Apr 22 2016 12:25
what do you guys think looks better this
```
$scope.usersPolls = pollService.findAndDeletePoll(pollName,
                                                          $scope.usersPolls);

// or this
$scope.usersPolls = pollService.findAndDeletePoll(pollName,
    $scope.usersPolls);
Stephen James
@sjames1958gm
Apr 22 2016 12:27
$scope.usersPolls = 
    pollService.findAndDeletePoll(pollName,
                              $scope.usersPolls);
Bhavesh
@bbhavesh
Apr 22 2016 12:27

Hi Guys
M stuck at this one

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

switch(val) {
case 1:
case 2:
case 3:
break;

case 4:
case 5:
case 6:
 break;

case 7:
case 8:
case 9:
  result = "Low, Mid, High";
  break;

}

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

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

Stephen James
@sjames1958gm
Apr 22 2016 12:28
@caleb272 Something like what I posted? Trying to get the $scope to line up with pollName
@bbhavesh You are returning answer, but never setting it. Also are you supposed to return low, mid, high separately for the different values of val?
Bhavesh
@bbhavesh
Apr 22 2016 12:30
@sjames1958gm
I tried all ways
It just wont work
Stephen James
@sjames1958gm
Apr 22 2016 12:31
@bbhavesh You should be setting answer = ""; some string not result. Put answer=""; before each break to the value appropriate to the case values before it
Caleb Martin
@caleb272
Apr 22 2016 12:32
@sjames1958gm no I’m just asking you guys what looks better for breaking up the lines and making them beautiful
Stephen James
@sjames1958gm
Apr 22 2016 12:32
@caleb272 I understand I was suggesting a different choice.
Joshua Swift
@joshuaswift
Apr 22 2016 12:32
function factorialize(num) {
  var array = [];
  for (i = 0; i <= num; i +=1) {
    array.push(i);
  }
  var total = array.reduce(function(a,b) {
    return a * b;
  });
  return total;
}

factorialize(5);
Bhavesh
@bbhavesh
Apr 22 2016 12:33

@sjames1958gm
Is this how you saying

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

switch(val) {
case 1:
case 2:
case 3:
answer = "Low";
break;

case 4:
case 5:
case 6:
  answer = "Mid";
  break;

case 7:
case 8:
case 9:
  answer = "High";
  break;

}

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

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

Joshua Swift
@joshuaswift
Apr 22 2016 12:33
Could anybody point me in the right direction on this? Trying to multiply all numbers in the array variable together and return total
Caleb Martin
@caleb272
Apr 22 2016 12:33
@sjames1958gm ya i know i wasn’t sure if that was a question or a suggestion thanks though
CamperBot
@camperbot
Apr 22 2016 12:33
caleb272 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 747 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Apr 22 2016 12:33
@bbhavesh Yes
@Joshuaswift That looks close - what was the first number you pushed on the array
Bhavesh
@bbhavesh
Apr 22 2016 12:35
@sjames1958gm
It still wont work
Stephen James
@sjames1958gm
Apr 22 2016 12:35
@caleb272 Of your two I would take the second. But likely the auto-formatter will choose the first .
Joshua Swift
@joshuaswift
Apr 22 2016 12:36
@sjames1958gm The first number pushed to the array would be 0 since it takes every number up to and equal to the given number (5)
Soham
@appfobia
Apr 22 2016 12:36
Hello guys.. Any idea about - func()() types of functions ?
Joshua Swift
@joshuaswift
Apr 22 2016 12:36
And funnily enough that's what I'm getting as a return value!
Stephen James
@sjames1958gm
Apr 22 2016 12:36
@Joshuaswift So you start with zero and multiply
A H
@allenhsieh
Apr 22 2016 12:36
Okay so I answered my own question and it worked! My question now is that the code is insanely ugly and inelegant. is there is a better way to do this?
function findLongestWord(str) {
  var array2 = [];
  var array = str.split(' ');
  for (var i in array){
    array2.push(array[i].length);
  }
  array2.sort(function(a, b){
    return b - a;
  });
  return array2[0];
}

findLongestWord("The quick brown fox jumped over the lazy dog");
greg
@wearenotgroot
Apr 22 2016 12:37
@Joshuaswift start with 1
Stephen James
@sjames1958gm
Apr 22 2016 12:37
@wearenotgroot I was hoping to let him figure it out.
Joshua Swift
@joshuaswift
Apr 22 2016 12:37
@sjames1958gm That makes an awful lot of sense! It's funny how when trying to solve a problem you overlook basic math sometimes
@sjames1958gm thanks Stephen
CamperBot
@camperbot
Apr 22 2016 12:38
:star: 748 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
joshuaswift sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
Joshua Swift
@joshuaswift
Apr 22 2016 12:38
@wearenotgroot Thanks also Greg
CamperBot
@camperbot
Apr 22 2016 12:38
joshuaswift sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 1037 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
Stephen James
@sjames1958gm
Apr 22 2016 12:38
@allenhsieh you can set a variable to the length of the first entry in the array and the loop setting that variable if the entry is larger and then return that variable.
A H
@allenhsieh
Apr 22 2016 12:39
Ah! so an if/then statement
that would basically cycle through the array
and compare the stored one, against the next one.
greg
@wearenotgroot
Apr 22 2016 12:40
@Joshuaswift you know you can simplify this with just a result variable and a for loop :+1:
A H
@allenhsieh
Apr 22 2016 12:40
thank you @sjames1958gm
CamperBot
@camperbot
Apr 22 2016 12:40
allenhsieh sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
Stephen James
@sjames1958gm
Apr 22 2016 12:40
@allenhsieh var largest = 0; for (var i in array){ if (array[i].length > largest) largest = array[i].length} return largest
CamperBot
@camperbot
Apr 22 2016 12:40
:star: 749 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
A H
@allenhsieh
Apr 22 2016 12:40
okay so largest would then serve as a sort of "counter" then
I didn't even think of that, thank you!
Stephen James
@sjames1958gm
Apr 22 2016 12:40
@allenhsieh Think about how you would do it without code and then write the code.
A H
@allenhsieh
Apr 22 2016 12:41
@sjames1958gm yup! I think my initial message got lost, I wrote out my logic
"Hi All, I'm having a bit of trouble with the Find The Longest Word in a String Exercise. I am trying to do it in 3 steps:
1) Split the given string into an array
2) Using a for loop, run 'push(i.length)' and push into a second array
3) finally sort the second array from greatest to least and return the greatest number stored in array2[0]"
Joshua Swift
@joshuaswift
Apr 22 2016 12:41
@wearenotgroot Yes there's probably a much more efficient way but for now I'm just trying to get it working! Thanks though
CamperBot
@camperbot
Apr 22 2016 12:41
joshuaswift sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:warning: joshuaswift already gave wearenotgroot points
A H
@allenhsieh
Apr 22 2016 12:42
So for all these algorithm exercises, i am trying my best to do it on my own
Stephen James
@sjames1958gm
Apr 22 2016 12:42
@allenhsieh If I were trying to find the longest word. Scan the array keeping track of the largest until I got to the end - then write the code
A H
@allenhsieh
Apr 22 2016 12:42
and then finding out what the best practice is/what experienced coders would do
ahhh @sjames1958gm thank you!
CamperBot
@camperbot
Apr 22 2016 12:42
allenhsieh sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: allenhsieh already gave sjames1958gm points
A H
@allenhsieh
Apr 22 2016 12:43
(not just today, but every day for the last week haha)
Joshua Swift
@joshuaswift
Apr 22 2016 12:43
@sjames1958gm @wearenotgroot One thing I'm not sure about, one of the pass conditions is factorialize(0) must return 1.
Stephen James
@sjames1958gm
Apr 22 2016 12:43
@allenhsieh Just a general rule if you start thinking about the code before a general solution you might get stuck on the wrong path. Also, don't be afraid to throw away code if it seems to complex.
CaffeineQueen
@CaffeineQueen
Apr 22 2016 12:43
Anyone here who can give me some help with nested for/ifs?

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

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

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

      console.log(contacts[n]);

      for (var p = 0; p < contacts[n].length; p++){

        if (contacts[n].p === prop){

          console.log(contacts[n].p);

          return (contacts[n].p);

      } else; {return "No such property";

            }
            }} else {return "No such contact";}
  }


// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
Stephen James
@sjames1958gm
Apr 22 2016 12:44
@Joshuaswift Sometimes special cases just require ifs
A H
@allenhsieh
Apr 22 2016 12:44
@sjames1958gm I will keep that in mind, so write it out in plain English what I want to do before typing out random bits of code haha.
CaffeineQueen
@CaffeineQueen
Apr 22 2016 12:44
It works fine to give me the individual I'm looking for but breaks after that
Stephen James
@sjames1958gm
Apr 22 2016 12:44
@CaffeineQueen Since you have the prop you don't need the inner for loop. contacts[n][prop] is direct access.
Diego Mayer
@Chrono79
Apr 22 2016 12:45
is this a good way to factorialize a number using ES6?
function factorialize(num) {
  if (num === 0) return 1;
  return [...Array(num).keys()].map(i => i+1).reduce((a, b) => a * b);
}
CaffeineQueen
@CaffeineQueen
Apr 22 2016 12:45
Even if I'm going to be checking against different properties in each case?
Joshua Swift
@joshuaswift
Apr 22 2016 12:45
@sjames1958gm @wearenotgroot And my
Samuel Cupidon
@Zerazera
Apr 22 2016 12:46
@Chrono79 Creating an array is overkill for factorialization
Stephen James
@sjames1958gm
Apr 22 2016 12:46
@CaffeineQueen There is function hasOwnProperty() that checks for the existence of a property.
@Chrono79 Wont that factorialize num+1?
Diego Mayer
@Chrono79
Apr 22 2016 12:46
@Zerazera could be, just trying to apply new things
@sjames1958gm no, it works fine, the array is like this [1,2,..., num]
Stephen James
@sjames1958gm
Apr 22 2016 12:48
@Chrono79 Duh largest i is num -1
Bhavesh
@bbhavesh
Apr 22 2016 12:48
@sjames1958gm I tried multiple ways
Looks like I am stuck ;-)