These are chat archives for FreeCodeCamp/HelpJavaScript

15th
Feb 2016
bitgrower
@bitgrower
Feb 15 2016 00:00 UTC
@Jarevalo92 -- where are you using val in the above pasted code?
Moisés Man
@moigithub
Feb 15 2016 00:01 UTC
post ur code.. how u doing... usng val
Otman Bouchari
@obouchari
Feb 15 2016 00:01 UTC
Hello @*, anyone did the "Sum All Numbers in a Range" challenge using reduce?
Moisés Man
@moigithub
Feb 15 2016 00:01 UTC
@obouchari post ur code...
bitgrower
@bitgrower
Feb 15 2016 00:01 UTC
@obouchari - I don't remember!!!
John Arevalo
@Jarevalo92
Feb 15 2016 00:01 UTC
// 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");
bitgrower
@bitgrower
Feb 15 2016 00:02 UTC
so where are you using val in your code @Jarevalo92 ?
Otman Bouchari
@obouchari
Feb 15 2016 00:02 UTC
@bitgrower Can you have a look :)
bitgrower
@bitgrower
Feb 15 2016 00:02 UTC
LOL ... did you mean me, @obouchari ?
Otman Bouchari
@obouchari
Feb 15 2016 00:02 UTC
yeh
Moisés Man
@moigithub
Feb 15 2016 00:02 UTC
@Jarevalo92 but.. u not using val in there...
Otman Bouchari
@obouchari
Feb 15 2016 00:02 UTC
hhh LOL
Moisés Man
@moigithub
Feb 15 2016 00:02 UTC
@Jarevalo92 before return result... u should have something like
result = .... something with val and lookup variables
John Arevalo
@Jarevalo92
Feb 15 2016 00:03 UTC
@bitgrower I guess thats my question. How do I use it
Otman Bouchari
@obouchari
Feb 15 2016 00:03 UTC
@bitgrower Its the first one under Intermediate Algo Scripting
John Arevalo
@Jarevalo92
Feb 15 2016 00:03 UTC
ive tried result = lookup[''];
Moisés Man
@moigithub
Feb 15 2016 00:04 UTC
u r close...
add val variable now..
bitgrower
@bitgrower
Feb 15 2016 00:05 UTC
reduce is a wonderful thing ... but I used a sort of series calculation instead of reduce (I can thank an advanced algebra class for that ... LOL ... series are cool things ... )
@obouchari -- did you look at the examples on the MDN page for array.reduce ?
Moisés Man
@moigithub
Feb 15 2016 00:06 UTC
@obouchari post ur code!!!!
bitgrower
@bitgrower
Feb 15 2016 00:06 UTC
@moigithub -- I think he's just trying to understand how to use array.reduce ... :)
Otman Bouchari
@obouchari
Feb 15 2016 00:06 UTC
I know how to use it, but I think you will need to generate an array out of the range to use reduce on it
bitgrower
@bitgrower
Feb 15 2016 00:07 UTC
LOL @obouchari -- yeah, you would ... that's why I didn't do that ...
Otman Bouchari
@obouchari
Feb 15 2016 00:07 UTC
@bitgrower But I solved it without reduce just simple loop
Moisés Man
@moigithub
Feb 15 2016 00:07 UTC
This message was deleted
Otman Bouchari
@obouchari
Feb 15 2016 00:07 UTC
function sumAll(arr) {
  var max = Math.max.apply(Math, arr);
  var min = Math.min.apply(Math, arr);
  var result = 0;
  for (; min <= max; min++) {
    result += min;
  }
  return result;
}

sumAll([1, 4]);
Moisés Man
@moigithub
Feb 15 2016 00:08 UTC
This message was deleted
bitgrower
@bitgrower
Feb 15 2016 00:08 UTC
yeah, that would do it ...
Otman Bouchari
@obouchari
Feb 15 2016 00:09 UTC
@bitgrower I just want to know if missed something about arrays, Although Underscore have something like _.range()
Tarik Nachat
@intertarik
Feb 15 2016 00:11 UTC

function lookUp(firstName, prop){
// Only change code below this line
for (var i=0; i < contacts.lenght ; i++){

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

// Only change code above this line
}
please can someone help me

Otman Bouchari
@obouchari
Feb 15 2016 00:11 UTC
@moigithub @bitgrower Is ES6 supported in the FCC ?
bitgrower
@bitgrower
Feb 15 2016 00:11 UTC
in the challenges ?
Moisés Man
@moigithub
Feb 15 2016 00:11 UTC
think saw few ppl posting code on es6
bitgrower
@bitgrower
Feb 15 2016 00:12 UTC
yep -- I used an ES6 method on confirm the ending ...
Otman Bouchari
@obouchari
Feb 15 2016 00:12 UTC
Yeah in their code area
bitgrower
@bitgrower
Feb 15 2016 00:12 UTC
@intertarik please format your code for helper's tired eyes ... like @campberbot indicates (follow the instructions closely)
explain format
CamperBot
@camperbot
Feb 15 2016 00:13 UTC

:point_right: code formatting [wiki]

Inline code

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

Code Block

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

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

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

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

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

Darius Bžozovskis
@darelisss
Feb 15 2016 00:13 UTC
who can point into right direction?
Write a function queue which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The queue function should then return the element that was removed.
Aleksander Gębicki
@Takumar
Feb 15 2016 00:14 UTC
@darelisss for sure you read about necessary methods: push() and shift(), that's all you need to complete this challenge :-)
bitgrower
@bitgrower
Feb 15 2016 00:14 UTC
@dareliss -- go check out the different Array functions in the Mozilla Developer Network pages
Tarik Nachat
@intertarik
Feb 15 2016 00:14 UTC
This message was deleted
bitgrower
@bitgrower
Feb 15 2016 00:15 UTC
@intertarik -- follow the instructions CLOSELY ...
Francisco Darré
@frandarre
Feb 15 2016 00:15 UTC
Heading to algorithms now. It's scary!
bitgrower
@bitgrower
Feb 15 2016 00:15 UTC
nah, it's a lot of fun !!!
Tarik Nachat
@intertarik
Feb 15 2016 00:15 UTC
This message was deleted
Francisco Darré
@frandarre
Feb 15 2016 00:15 UTC
Hope I get some fun out of it! Probably will feel awesome after finishing it, lol
Darius Bžozovskis
@darelisss
Feb 15 2016 00:16 UTC
@Takumar @bitgrower thanks guys
CamperBot
@camperbot
Feb 15 2016 00:16 UTC
darelisss sends brownie points to @takumar and @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 2319 | @takumar | http://www.freecodecamp.com/takumar
:star: 523 | @bitgrower | http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Feb 15 2016 00:17 UTC
yw @darelisss
Aleksander Gębicki
@Takumar
Feb 15 2016 00:17 UTC
@darelisss you are welcome :-)
Tarik Nachat
@intertarik
Feb 15 2016 00:18 UTC
This message was deleted
CamperBot
@camperbot
Feb 15 2016 00:18 UTC
:bulb: to format code use backticks! ``` more info
Tarik Nachat
@intertarik
Feb 15 2016 00:18 UTC
This message was deleted
CamperBot
@camperbot
Feb 15 2016 00:18 UTC
:bulb: to format code use backticks! ``` more info
Otman Bouchari
@obouchari
Feb 15 2016 00:19 UTC
@intertarik use ` instead of '
bitgrower
@bitgrower
Feb 15 2016 00:19 UTC
@intertarik -- backtick -- the key to the left of your 1 key ...
Tarik Nachat
@intertarik
Feb 15 2016 00:19 UTC
function lookUp(firstName, prop){
// Only change code below this line
 for (var i=0; i < contacts.lenght ; i++){

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

// Only change code above this line
}
bitgrower
@bitgrower
Feb 15 2016 00:20 UTC
YAY!!!!
Tarik Nachat
@intertarik
Feb 15 2016 00:20 UTC
yéééééh thx
hhhh
bitgrower
@bitgrower
Feb 15 2016 00:20 UTC
so ... how well is it working ? what part isn't working ?
you have a problem in your loop -- a couple of them, actualy
Tarik Nachat
@intertarik
Feb 15 2016 00:20 UTC
the all parts
Moisés Man
@moigithub
Feb 15 2016 00:21 UTC
@intertarik u missing a "no such contact" messsage
Aleksander Gębicki
@Takumar
Feb 15 2016 00:21 UTC
@intertarik you have to tell also that there is No such contact in your code :-)
bitgrower
@bitgrower
Feb 15 2016 00:21 UTC
okay ... well, you have a spelling error in your for loop...
Tarik Nachat
@intertarik
Feb 15 2016 00:21 UTC
ohh yes ... but where put it ??
Aleksander Gębicki
@Takumar
Feb 15 2016 00:22 UTC
@intertarik with each iteration of your loop you check only one contact.
So when can you say that you haven't found your contact?
bitgrower
@bitgrower
Feb 15 2016 00:22 UTC
@intertarik -- if I have 20 marbles in a bag, how many do I have to look at to know there are no black marbles in the bag (not a trick question)
Tarik Nachat
@intertarik
Feb 15 2016 00:23 UTC
whene i= = (contacts.lenght-1) ?? @Takumar
Moisés Man
@moigithub
Feb 15 2016 00:24 UTC
yes.. no .. maybe... 3%
fast way to know is testing :P
trial n error
bitgrower
@bitgrower
Feb 15 2016 00:24 UTC
@intertarik -- take your mind away from js for a second, and your efforts on this solution ... and answer my question ?
Aleksander Gębicki
@Takumar
Feb 15 2016 00:25 UTC
@intertarik not really, please listen now to @bitgrower , that's a good explanation :-)
You are checking first contact, second...
You are taking first marble...
bitgrower
@bitgrower
Feb 15 2016 00:25 UTC
thanks @Takumar
CamperBot
@camperbot
Feb 15 2016 00:25 UTC
bitgrower sends brownie points to @takumar :sparkles: :thumbsup: :sparkles:
:star: 2320 | @takumar | http://www.freecodecamp.com/takumar
SSabu
@SSabu
Feb 15 2016 00:26 UTC
Hello All! Is it possible for anyone to help me on Seek & Destroy challenge?
Tarik Nachat
@intertarik
Feb 15 2016 00:26 UTC
ok @bitgrower
SSabu
@SSabu
Feb 15 2016 00:26 UTC
I am having confusion with the arguments object
bitgrower
@bitgrower
Feb 15 2016 00:26 UTC
sure, @SSabu -- please post your code ...
SSabu
@SSabu
Feb 15 2016 00:26 UTC
ok
thanks.
bitgrower
@bitgrower
Feb 15 2016 00:26 UTC
@SSabu -- that's a common mis-understanding with that challenge ... you are not alone ...
SSabu
@SSabu
Feb 15 2016 00:26 UTC

'''
function destroyer(arr) {
var mustRemove = [];
for (var i = 1; i < arguments.length; i++) {
arr = arr.filter(function(val){ return val != arguments[i];
});
(function(){return arr;})();

}

return arr;
}

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

CamperBot
@camperbot
Feb 15 2016 00:26 UTC
:bulb: to format code use backticks! ``` more info
Tarik Nachat
@intertarik
Feb 15 2016 00:27 UTC
@bitgrower i have to look how many marbles i took ..
SSabu
@SSabu
Feb 15 2016 00:27 UTC
lol- SORRY! I'm a newbie, still working on posting code so it looks formatted correctly
bitgrower
@bitgrower
Feb 15 2016 00:27 UTC
close!!! use backtick ... --> ```js
and that must be on a line by itself ...
SSabu
@SSabu
Feb 15 2016 00:27 UTC
thanks @camperbot
CamperBot
@camperbot
Feb 15 2016 00:27 UTC
ssabu sends brownie points to @camperbot :sparkles: :thumbsup: :sparkles:
:star: 1182 | @camperbot | http://www.freecodecamp.com/camperbot
bitgrower
@bitgrower
Feb 15 2016 00:28 UTC
@intertarik ... make it 5 marbles ... how many marbles do I have to look at to determine there are NO black marbles in the bag ?
Aleksander Gębicki
@Takumar
Feb 15 2016 00:28 UTC
@intertarik do you need to check first marble, 10 or 18?
When you check 18 marble and all are white, can you say that you don't have black marbles in your bag?
SSabu
@SSabu
Feb 15 2016 00:29 UTC
function destroyer(arr) {
  var mustRemove = [];
  for (var i = 1; i < arguments.length; i++) {
    arr = arr.filter(function(val){ return val != arguments[i];
  });
    (function(){return arr;})();

  }

  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
bitgrower
@bitgrower
Feb 15 2016 00:29 UTC
YAY!!!! @SSabu
SSabu
@SSabu
Feb 15 2016 00:29 UTC
thanks!
I get a message saying, "Don't define a function in a for loop"
But how else Can you make it cycle through the arguments?
Tarik Nachat
@intertarik
Feb 15 2016 00:29 UTC
@bitgrower 5 marbles
bitgrower
@bitgrower
Feb 15 2016 00:29 UTC
right ... so, don't do that ...
@intertarik -- YES!!!!
so how many elements in your array do you have to look at ?
Tarik Nachat
@intertarik
Feb 15 2016 00:30 UTC
4 itels
SSabu
@SSabu
Feb 15 2016 00:30 UTC
one at a time
Tarik Nachat
@intertarik
Feb 15 2016 00:30 UTC
items
SSabu
@SSabu
Feb 15 2016 00:31 UTC
@bitgrower any other suggestions?
bitgrower
@bitgrower
Feb 15 2016 00:31 UTC
well ... I don't remember the # of elements in the array ... but, assuming it's 4 ... yah, you have to look thru ALL of them ...
Otman Bouchari
@obouchari
Feb 15 2016 00:31 UTC
@SSabu Use Array methods
bitgrower
@bitgrower
Feb 15 2016 00:31 UTC
hang on ... let me look @SSabu
Francisco Darré
@frandarre
Feb 15 2016 00:31 UTC
function factorialize(num) {
  for(var i = 1 ; i <= num; i++) {
    num *= i;
  }
  return num;
}

factorialize(5);
Why I'm getting an infinite loop? Shouldn't it finish when reaching i <= num?
bitgrower
@bitgrower
Feb 15 2016 00:31 UTC
he is using filter @obouchari
SSabu
@SSabu
Feb 15 2016 00:31 UTC
k, thanks @bitgrower
CamperBot
@camperbot
Feb 15 2016 00:31 UTC
ssabu sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 524 | @bitgrower | http://www.freecodecamp.com/bitgrower
Francisco Darré
@frandarre
Feb 15 2016 00:31 UTC
Or this isn't how you do it at all? :p
Otman Bouchari
@obouchari
Feb 15 2016 00:31 UTC
I missed that lol
bitgrower
@bitgrower
Feb 15 2016 00:31 UTC
@frandarre -- it has to do with your loop definition ...
SSabu
@SSabu
Feb 15 2016 00:32 UTC
no worries @obouchari
Francisco Darré
@frandarre
Feb 15 2016 00:32 UTC
@bitgrower mk, I'll give it more thougth. Thanks!
CamperBot
@camperbot
Feb 15 2016 00:32 UTC
frandarre sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 525 | @bitgrower | http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Feb 15 2016 00:32 UTC
I think ... anyway ... LOL ... hang on ...need to look at @SSabu 's code
@frandarre -- it DOES have to do with your loop definition, in a way ... look at how you are using your num variable ...
Otman Bouchari
@obouchari
Feb 15 2016 00:33 UTC
@frandarre You check the num but you change it a the same time so the loop will keep going forever !
Francisco Darré
@frandarre
Feb 15 2016 00:33 UTC
Oh, let me correct that. Thanks @obouchari @bitgrower
CamperBot
@camperbot
Feb 15 2016 00:33 UTC
frandarre sends brownie points to @obouchari and @bitgrower :sparkles: :thumbsup: :sparkles:
:warning: frandarre already gave bitgrower points
:star: 334 | @obouchari | http://www.freecodecamp.com/obouchari
bitgrower
@bitgrower
Feb 15 2016 00:35 UTC

arr = arr.filter(function(val){ return val != arguments[i];

@SSabu -- I have a hard time figuring out exactly what js would do with that statement ... you might want to review Array.filter() in Mozilla Developer Network ... they have handy examples on the pages, too ...

yw @frandarre ... :)
Tarik Nachat
@intertarik
Feb 15 2016 00:35 UTC
i did this ans still don't work
````js
SSabu
@SSabu
Feb 15 2016 00:36 UTC
So, when I use that statement in replit and put in a value instead of "arguments [i]" it removes that value from the array
Tarik Nachat
@intertarik
Feb 15 2016 00:36 UTC
function lookUp(firstName, prop){
// Only change code below this line
  var j=1;

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

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


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


   }else{
     j++;
   }
 }
  if (j== contacts.lenght){
    return  "No such contact";
  }


// Only change code above this line
}
bitgrower
@bitgrower
Feb 15 2016 00:36 UTC
okay ... did you read the Arguments Object page, @SSabu ?
SSabu
@SSabu
Feb 15 2016 00:36 UTC
yes
that's why it says arguments[i] instead of just a straight value in the filter method
Moisés Man
@moigithub
Feb 15 2016 00:37 UTC
@intertarik the last if no needed.. neither j variable
bitgrower
@bitgrower
Feb 15 2016 00:37 UTC
what do you think the length of the arguments Object is ... and what do you think the values are ?
SSabu
@SSabu
Feb 15 2016 00:37 UTC
the length of the arguments object depends on how many arguments you input into the function
bitgrower
@bitgrower
Feb 15 2016 00:38 UTC
along with length being misspelled again ...
okay, in the first test case ...
@SSabu -- what are they in the first test case (the one I think you included above)
SSabu
@SSabu
Feb 15 2016 00:38 UTC
2 and 3
bitgrower
@bitgrower
Feb 15 2016 00:39 UTC
those are the only arguments in the arguments object ?
SSabu
@SSabu
Feb 15 2016 00:39 UTC
well there's the array too, but is that part of the arguments object?
bitgrower
@bitgrower
Feb 15 2016 00:39 UTC
what is arguments[0]?
argument1?
Otman Bouchari
@obouchari
Feb 15 2016 00:39 UTC
@SSabu Are you using (function(){return arr;})(); for debuging ?
bitgrower
@bitgrower
Feb 15 2016 00:39 UTC
@SSabu -- yes, it is ...
SSabu
@SSabu
Feb 15 2016 00:39 UTC
ok, will that's why the loop starts at 1
well
not sure what you are asking @obouchari
bitgrower
@bitgrower
Feb 15 2016 00:40 UTC
what may help is to understand that there are arguments, and some of them may actually get named in the formal function definition ... which makes it easy for you to use them ...
Francisco Darré
@frandarre
Feb 15 2016 00:40 UTC
function factorialize(num) {
  var n = num;
  for(var i = 1; i < n; i++) {
    num *= i;
  }

  if(num !== 0){
  return num;
  } else {
    return 1;
  }
}

factorialize(5);
This works. The 'if' is too cheeky or it's how it's supposed to be solved?
bitgrower
@bitgrower
Feb 15 2016 00:40 UTC
in this case ... arguments[0] is the same thing as arr
SSabu
@SSabu
Feb 15 2016 00:40 UTC
yes
@bitgrower that makes sense
Otman Bouchari
@obouchari
Feb 15 2016 00:41 UTC
@SSabu What is the purpose of putting this (function(){return arr;})(); inside the loop?
SSabu
@SSabu
Feb 15 2016 00:41 UTC
that's why I started the loop at 1
bitgrower
@bitgrower
Feb 15 2016 00:41 UTC
@frandarre -- well, considering someone could pass you a 0, it seems more than fair to check for it ... :) ... both 0 & 1 make for easy returns ... (although 0! I think is undefined ?)
SSabu
@SSabu
Feb 15 2016 00:42 UTC
@obouchari so that it updates the values in the array
Francisco Darré
@frandarre
Feb 15 2016 00:42 UTC
@bitgrower so it's ok? Nice, then. Thanks for the help!
bitgrower
@bitgrower
Feb 15 2016 00:42 UTC
or maybe I'm confusing it with some of the other numeric stuff we've used in the challenges ...
CamperBot
@camperbot
Feb 15 2016 00:42 UTC
frandarre sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:warning: frandarre already gave bitgrower points
SSabu
@SSabu
Feb 15 2016 00:42 UTC
should I take that out of the loop? it seemed like that line was important to actually run the method
and have the array be updated after each filter
Otman Bouchari
@obouchari
Feb 15 2016 00:43 UTC
@SSabu Thats an IIFE so it will execute and take out of the function
bitgrower
@bitgrower
Feb 15 2016 00:43 UTC
@frandarre -- there's a concept known as defensive coding ... where you assume someone passing you data isn't passing you values that you expect ... in which case, you reject them outright, instead of having to find some weird bugs in your code ...
SSabu
@SSabu
Feb 15 2016 00:43 UTC
what's an IIFE?
no worries, I can google it.
Otman Bouchari
@obouchari
Feb 15 2016 00:44 UTC
@SSabu Immediately Invoked Function Expression
SSabu
@SSabu
Feb 15 2016 00:44 UTC
ok, thanks @obouchari
CamperBot
@camperbot
Feb 15 2016 00:44 UTC
ssabu sends brownie points to @obouchari :sparkles: :thumbsup: :sparkles:
Francisco Darré
@frandarre
Feb 15 2016 00:44 UTC
@bitgrower then it's not cheeky if we want to prevent people from exploiting our code
CamperBot
@camperbot
Feb 15 2016 00:44 UTC
:star: 335 | @obouchari | http://www.freecodecamp.com/obouchari
Otman Bouchari
@obouchari
Feb 15 2016 00:44 UTC
@SSabu Try to comment that and run your test again
SSabu
@SSabu
Feb 15 2016 00:45 UTC
ok, I did that. the test returned nothing
bitgrower
@bitgrower
Feb 15 2016 00:45 UTC
I didn't understand jQuery at all until I learned about IIFE's
SSabu
@SSabu
Feb 15 2016 00:45 UTC
so now the code looks like this
bitgrower
@bitgrower
Feb 15 2016 00:46 UTC
I could copy and paste code -- but didn't know how to debug it or do anything overly useful ...
SSabu
@SSabu
Feb 15 2016 00:46 UTC

function destroyer(arr) {
  var mustRemove = [];
  for (var i = 1; i < arguments.length; i++) {
    arr = arr.filter(function(val){ return val != arguments[i];
  });
    }

  (function(){return arr;})();
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
bitgrower
@bitgrower
Feb 15 2016 00:46 UTC
@frandarre -- defensive programming is good programming practice, for sure ...
where are you returning anything @SSabu ... ya gotta have a return statement ... the return in your last line does not return from destroyer, but from the anonymous function call ...
Moisés Man
@moigithub
Feb 15 2016 00:47 UTC
@SSabu u CANT use arguments object like that...
SSabu
@SSabu
Feb 15 2016 00:47 UTC
i hate arguments object...
bitgrower
@bitgrower
Feb 15 2016 00:47 UTC
like what, @moigithub ?
Moisés Man
@moigithub
Feb 15 2016 00:47 UTC
@SSabu cuz every function have its own arguments object copy
bitgrower
@bitgrower
Feb 15 2016 00:48 UTC
ahhh ... excellent point, @moigithub
Otman Bouchari
@obouchari
Feb 15 2016 00:48 UTC
@moigithub True!!!
Moisés Man
@moigithub
Feb 15 2016 00:48 UTC
if u have 2 nested function.. arguments will be different for both of em
SSabu
@SSabu
Feb 15 2016 00:48 UTC
I don't understand...
bitgrower
@bitgrower
Feb 15 2016 00:49 UTC
arr.filter calls a function, @SSabu -- so it creates a new arguments object ... but which parts are you not understanding ... ? what @moigithub said, or what I said ?
Otman Bouchari
@obouchari
Feb 15 2016 00:49 UTC
@SSabu anonymous function inside filter has its own arguments object...
SSabu
@SSabu
Feb 15 2016 00:50 UTC
@moigithub's point
@obouchari so could I take out the for loop?
bitgrower
@bitgrower
Feb 15 2016 00:50 UTC

okay...

let's not use IIFE's as an example ... let's just say I have a function, and within that function f(a), I call function b

Otman Bouchari
@obouchari
Feb 15 2016 00:50 UTC
@SSabu
arr = arr.filter(function(val){ return val != arguments[i]; // arguments[i] is not what you thinking
SSabu
@SSabu
Feb 15 2016 00:51 UTC
ok
bitgrower
@bitgrower
Feb 15 2016 00:51 UTC

when I call function a -- an arguments object is created ...

when I call function b, yet another arguments object is created ... each one's is accessed by the special variable arguments

SSabu
@SSabu
Feb 15 2016 00:51 UTC
ok
Otman Bouchari
@obouchari
Feb 15 2016 00:52 UTC
@SSabu arguments[i] at the time you using it belongs to function(val) {};
bitgrower
@bitgrower
Feb 15 2016 00:52 UTC
so ... when you use arguments in an function, it refers ONLY to the the arguments passed to the function currently executing ...
SSabu
@SSabu
Feb 15 2016 00:52 UTC
ok
so how would you make the arguments function refer to the arguments passed into the original function?
sorry, arguments object...
bitgrower
@bitgrower
Feb 15 2016 00:54 UTC
set the arguments object to a variable ... and refer to that variable ... OR, more ideal, use something like splice
Moisés Man
@moigithub
Feb 15 2016 00:54 UTC
make a copy on an array first
SSabu
@SSabu
Feb 15 2016 00:54 UTC
ok.
bitgrower
@bitgrower
Feb 15 2016 00:54 UTC
so you make a copy ...
SSabu
@SSabu
Feb 15 2016 00:54 UTC
thanks
yes, I"ve seen splice used a lot in examples I've found online
bitgrower
@bitgrower
Feb 15 2016 00:54 UTC
er slice ... easier to copy ... but splice can be used sweetly here as well ...
SSabu
@SSabu
Feb 15 2016 00:55 UTC
splice does what exactly?
bitgrower
@bitgrower
Feb 15 2016 00:55 UTC
splice does a LOT ... but to copy an array, use slice ...
SSabu
@SSabu
Feb 15 2016 00:55 UTC
make a copy of the array being passed into the original function?
bitgrower
@bitgrower
Feb 15 2016 00:55 UTC
splice might be a bit of overwhelm atm ...
first get your arguments objects straightened out ...
SSabu
@SSabu
Feb 15 2016 00:56 UTC
ok, thanks all. I will look into splice and slice and think about how making a copy of the original array would help here.
bitgrower
@bitgrower
Feb 15 2016 01:00 UTC
congratulations on getting this far in the js challenges, @SSabu -- S&D is a challenge many folks have trouble with ...
SSabu
@SSabu
Feb 15 2016 01:02 UTC
thanks @bitgrower
CamperBot
@camperbot
Feb 15 2016 01:02 UTC
ssabu sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:warning: ssabu already gave bitgrower points
Moisés Man
@moigithub
Feb 15 2016 01:03 UTC

@SSabu
just thinking ... if u using this way

 for (var i = 1; i < arguments.length; i++) {
    arr = arr.filter(function(val){ return val != arguments[i];
  });
    }

u no need to really make a copy of the whole argumnent object..

just the one u using at moment the filter callback use.. cuz u only need 1 value... at time
SSabu
@SSabu
Feb 15 2016 01:03 UTC
ok thanks @moigithub
CamperBot
@camperbot
Feb 15 2016 01:03 UTC
ssabu sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star: 597 | @moigithub | http://www.freecodecamp.com/moigithub
SSabu
@SSabu
Feb 15 2016 01:03 UTC
I still need to try to figure out what that means though
Moisés Man
@moigithub
Feb 15 2016 01:04 UTC
so on the filter.. u only using arguments[i] whatever i value is
SSabu
@SSabu
Feb 15 2016 01:04 UTC
yes
Moisés Man
@moigithub
Feb 15 2016 01:04 UTC
var igonnausethis = arguments[i];
SSabu
@SSabu
Feb 15 2016 01:04 UTC
ok, will think about that and the other suggestions you have all given me
yes, it makes sense now why I would need to do that
oh....!
hellotojello
@hellotojello
Feb 15 2016 01:06 UTC
function titleCase(str) {

  var splitStrings = str.split(" ");
  var stringStorage = splitStrings.map(function(val){
                                       for (var i = 0; i < splitStrings; i++)
  return val[i][0];
                                       });





  return stringStorage;
}
I know it isn't the answer, but i'm wondering why it's returning null for stringStorage. shouldn't it give me the first letter of the i-th item of the array?
SSabu
@SSabu
Feb 15 2016 01:06 UTC
so I could have that variable definition in the for loop and the array filter method using the variable. but wouldn't the array filter need to be in the for loop too
?
Moisés Man
@moigithub
Feb 15 2016 01:07 UTC
you have the filter inside the loop now... and yes about the var too
SSabu
@SSabu
Feb 15 2016 01:07 UTC
should I have the filter outside the loop?
Moisés Man
@moigithub
Feb 15 2016 01:07 UTC
didnt tested so not sure if will work :) but best way to find out is trying :)
nope
SSabu
@SSabu
Feb 15 2016 01:07 UTC
ok, will think about that.
yes, that makes sense
thanks @moigithub
CamperBot
@camperbot
Feb 15 2016 01:08 UTC
ssabu sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:warning: ssabu already gave moigithub points
SSabu
@SSabu
Feb 15 2016 01:08 UTC
sigining off the chat to try all the suggestions you guys have given me
thanks again!
Moisés Man
@moigithub
Feb 15 2016 01:09 UTC
@hellotojello this makes an array... from a string.. "splitting" on a space
var splitStrings = str.split(" ");
so if u have "hello world".. u will get ["hello","world"]
@hellotojello Array.map.. its like a for/loop
it picks each element of the array .. and pass it one by one to ur callback
splitStrings.map(function(val){
so val at first loop will be "hello"
and at second loop will be "world"
@hellotojello return val[i][0];
since val === "hello" (at first loop)
val[0] will return "h"
but its not an array of array.. so u cant do val[i][0]
hellotojello
@hellotojello
Feb 15 2016 01:14 UTC
so i don't need the for loop?
Moisés Man
@moigithub
Feb 15 2016 01:15 UTC
on console doing "hello"[0][0] returns "h" :)
Preston Moore
@FrOyxx
Feb 15 2016 01:16 UTC
This message was deleted
Moisés Man
@moigithub
Feb 15 2016 01:16 UTC
@hellotojello nope
Preston Moore
@FrOyxx
Feb 15 2016 01:18 UTC

Can anyone point out why my code is returning two for:

Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a two-dimensional array.

function chunk(arr, size) {
  // Break it up.
  result = [];
  arr1 = arr.slice(0,size);
  arr2 = arr.slice(size);

  //return result.push(arr1, arr2);
  return result.push(arr1, arr2);
}

chunk(["a", "b", "c", "d"], 2);
Moisés Man
@moigithub
Feb 15 2016 01:20 UTC
@FrOyxx push return a number
which correspong the length of the array
u pushing 2 elements to result... so ur function will return 2
Preston Moore
@FrOyxx
Feb 15 2016 01:22 UTC
@moigithub ok that makes sense. thanks for the explanation
CamperBot
@camperbot
Feb 15 2016 01:22 UTC
froyxx sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star: 598 | @moigithub | http://www.freecodecamp.com/moigithub
Kevin Myrick
@aphextwin234
Feb 15 2016 01:28 UTC
```
<script type="text/javascript">
/*<![CDATA[*/
var sportLink=[];


</script>
</head>

<body>
<form>
Select sport
<select id="sportlist" onchange="window.location.href=this.value">
<option></option>
<option value="http://www.espn.go.com/mlb">Baseball</option>
<option>Football</option>
<option>Hockey</option>
<option>Basketball</option>
<option>Tennis</option>
</select>


</form>
</body>

</html>
I'm trying to make a drop down list with three addtional url's per sport. I'm sort of lost.
bitgrower
@bitgrower
Feb 15 2016 01:30 UTC
I'm probably behind the times, I'd probably just use html/css ...
Marc
@wumpafruits
Feb 15 2016 01:30 UTC
// Setup
function abTest(a, b) {
  // Only change code below this line



  // Only change code above this line

  return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
}

// Change values below to test your code
abTest(2,2);

When a return statement is reached, the execution of the current function stops and control returns to the calling location.

Example

function myFun() {
console.log("Hello");
return "World";
console.log("byebye")
}
myFun();
The above outputs "Hello" to the console, returns "World", but "byebye" is never output, because the function exits at the return statement.

Instructions
Modify the function abTest so that if a or b are less than 0 the function will immediately exit with a value of undefined.

Not sure what to do with undefined and if I'm supposed to use a switch state or if

@aphextwin234 shoutout to you for your username =p
Moisés Man
@moigithub
Feb 15 2016 01:31 UTC
undefined is a javascript keyword
Kevin Myrick
@aphextwin234
Feb 15 2016 01:32 UTC
@wumpafruits ^_^
are you saying use css to create additional links? @bitgrower
bitgrower
@bitgrower
Feb 15 2016 01:38 UTC
yeah ... if you look around on the css sites, I'm pretty sure you'll find css code to create cascading menus ...
Otman Bouchari
@obouchari
Feb 15 2016 01:45 UTC
@moigithub undefined: A primitive value automatically assigned to variables that have just been declared or to formal arguments for which there are no actual arguments.
Nick Robson
@nickrobson
Feb 15 2016 01:54 UTC
function doSomething(arg1, arg2) {
    console.log(arg1);
    console.log(arg2);
}
doSomething(1, 2);
// => "1"
// => "2"
doSomething();
// => "undefined"
// => "undefined"
cannelflow
@cannelflow
Feb 15 2016 02:19 UTC
@brainyfarm yes cuz you folks are always there when i need help :smile:
Michelle
@Michelle2016
Feb 15 2016 02:35 UTC
Hello everyone...I am a bit stuck with else if statements. I understand the overall concept but I am having an issue with the 'Golf Code'.
Otman Bouchari
@obouchari
Feb 15 2016 02:36 UTC
function diff(arr1, arr2) {
  var newArr = [];
  // Same, same; but different.

  newArr = newArr.concat(arr1, arr2);

  newArr = newArr.filter(function (val) {
    return !(arr1.indexOf(val) > -1 && arr2.indexOf(val) > -1);
  });

  return newArr;
}

diff([1, 2, 3, 5], [1, 2, 3, 4, 5]);
Any better way than doing this ?
cannelflow
@cannelflow
Feb 15 2016 02:37 UTC
@Michelle2016 can you paste your code
Brett
@BLayman
Feb 15 2016 02:37 UTC
I'm on the "Where art thou" challenge, and I'm having difficulty working with objects. I found a way to compare the properties of the "collection" and "source" objects, but I don't know how to compare the values of those properties. Here's my code:
function where(collection, source) {
  var arr = [];
  var keyarr = [];
  for(i=0;i<collection.length;i++){
   if (collection[i].hasOwnProperty(Object.keys(source))){
     arr.push(collection[i]);
   }

  }


  return arr;
}

where([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
Michelle
@Michelle2016
Feb 15 2016 02:38 UTC

@cannelflow function golfScore(par, strokes) {
// Only change code below this line

if (1, 1){
return "Hole-in-one!";
}
else if(strokes <= par - 2){
return "Eagle";
}

@cannelflow I am guessing that my condition should only be numeric?
cannelflow
@cannelflow
Feb 15 2016 02:40 UTC
if (1, 1){<-------if(1,1) means nothing do like if(strokes===1)
return "Hole-in-one!";
}
else if(strokes <= par - 2){<------this part is good
return "Eagle";
}
@Michelle2016
Michelle
@Michelle2016
Feb 15 2016 02:41 UTC
@cannelflow That is so funny because the if (1,1) is the par that they were giving me the green check for.
The second part else if they were still giving me the incorrect red X.
cannelflow
@cannelflow
Feb 15 2016 02:42 UTC
@Michelle2016 yes if(1,1) will do good sry cuz strokes value is also 1 can you show you whole code
but its good to write like if(strokes===1)
SSabu
@SSabu
Feb 15 2016 02:44 UTC
hello, it's me again... still having trouble with Search and Destroy challenge. I did make a little progress since last time.
Can anyone help?
here's my code:
function destroyer(arr) {
  var mustRemove = arr.splice(1, arr.length);

  for (var i=0; i<mustRemove.length;i++)
    var remove = mustRemove[i];
    arr = arr.filter(function(val) { return val != remove; 
                                   }); 
  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
I think I just figured out my mistake...
Michelle
@Michelle2016
Feb 15 2016 02:45 UTC

@cannelflow Thank you for your help, I got it!

function golfScore(par, strokes) {
// Only change code below this line

if (strokes == 1){
return "Hole-in-one!";
}
else if(strokes <= par - 2){
return "Eagle";
}
else if (strokes == par - 1){
return "Birdie";
}
else if (strokes == par){
return "Par";
}
else if (strokes == par + 1){
return "Bogey";
}
else if (strokes == par + 2 ){
return "Double Bogey";
}
else if ( strokes >= par +3){
return "Go Home!";
}else{
return "Change Me";
}
// Only change code above this line
}

CamperBot
@camperbot
Feb 15 2016 02:45 UTC
michelle2016 sends brownie points to @cannelflow :sparkles: :thumbsup: :sparkles:
:star: 799 | @cannelflow | http://www.freecodecamp.com/cannelflow
Otman Bouchari
@obouchari
Feb 15 2016 02:45 UTC
@SSabu you slicing from arr not arguemnts
cannelflow
@cannelflow
Feb 15 2016 02:46 UTC
@Michelle2016 :+1:
Michelle
@Michelle2016
Feb 15 2016 02:46 UTC
@cannelflow Yea!!!
SSabu
@SSabu
Feb 15 2016 02:46 UTC
yes, that's what I realized.
Thanks @obouchari
CamperBot
@camperbot
Feb 15 2016 02:46 UTC
ssabu sends brownie points to @obouchari :sparkles: :thumbsup: :sparkles:
:star: 338 | @obouchari | http://www.freecodecamp.com/obouchari
SSabu
@SSabu
Feb 15 2016 02:46 UTC
My question is why there is only one argument for the original function.
Shouldn't there be 2: one array, and then arguments for the values to remove from the array?
Otman Bouchari
@obouchari
Feb 15 2016 02:47 UTC
Arguments in function contain all arguments passed in not parameters defined in the function
bitgrower
@bitgrower
Feb 15 2016 02:47 UTC
@SSabu -- it's like I explained earlier ... you can have ANY number of variables sent to a function ...
however ... they aren't always necessarily named ...
in this case, 3 arguments are passed, only the first of which is named (arr)
SSabu
@SSabu
Feb 15 2016 02:48 UTC
ok, so I should split the argument arr into the array from which I am supposed to remove values, and then the values which I am supposed to remove?
bitgrower
@bitgrower
Feb 15 2016 02:49 UTC

or put another way .... (number of named-parameters) !== (number of arguments passed to the function)

...in this case ...

Otman Bouchari
@obouchari
Feb 15 2016 02:49 UTC
@SSabu also put in mind that arguments are not arrays even though the look like it, so you have to use apply/call
SSabu
@SSabu
Feb 15 2016 02:49 UTC
ok.
bitgrower
@bitgrower
Feb 15 2016 02:49 UTC
arr = argument[0] = [1,2,3,1,2,3]
SSabu
@SSabu
Feb 15 2016 02:50 UTC
and then what do you call the 2,3 in the example?
bitgrower
@bitgrower
Feb 15 2016 02:50 UTC
argument1 -- has no "name" until you give it one ... = 2
SSabu
@SSabu
Feb 15 2016 02:50 UTC
argument1 and argument 2?
bitgrower
@bitgrower
Feb 15 2016 02:50 UTC
argument [2] = 3
SSabu
@SSabu
Feb 15 2016 02:51 UTC
is it argument 2 = 3 by default, or do I have to do something to assign value 3 to argument2?
bitgrower
@bitgrower
Feb 15 2016 02:51 UTC
both the 2nd & 3rd arguments have NO NAME outside of arguments[n]
no you are handed the arguments object, you don't have to do anything with it except use the values you find
go run your code at pythontutor.com/javascript.html
SSabu
@SSabu
Feb 15 2016 02:52 UTC
I'm running my code on replit
so should I use arguments.slice(1,1) to peel off the arguments one by one?
bitgrower
@bitgrower
Feb 15 2016 02:52 UTC
there's a reason I'm recommending pythontutor ... I've not seen the same features on repl.it
Otman Bouchari
@obouchari
Feb 15 2016 02:53 UTC
@SSabu
function foo() {
    console.log(arguments); // { '0': 2, '1': 3 }
}

foo(2,3);
SSabu
@SSabu
Feb 15 2016 02:53 UTC
ok, I'll check it out
Otman Bouchari
@obouchari
Feb 15 2016 02:54 UTC
@SSabu Arguments are Array like object
bitgrower
@bitgrower
Feb 15 2016 02:54 UTC
no ... I really wouldn't recommend using arguments.slice(1,1) in the way you are indicating ... there are much cleaner ways of doing that (you CAN loop thru the arguments object if you really need to ...
array-like -- which means MOST of the array functions don't work on it, except .length
oh, and indexing ...
Otman Bouchari
@obouchari
Feb 15 2016 02:55 UTC
@bitgrower @SSabu arguments.slice() would not work
bitgrower
@bitgrower
Feb 15 2016 02:55 UTC
indeed!!!
wasn't paying attention ... LOL ...
SSabu
@SSabu
Feb 15 2016 02:56 UTC
function destroyer(arr) {
  //var mustRemove = arguments.splice(1, arr.length);

  for (var i=1; i<arguments.length;i++)
    var remove = arguments[i];
    arr = arr.filter(function(val) { return val != remove; 
                                   }); 
  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
bitgrower
@bitgrower
Feb 15 2016 02:56 UTC
which is WHY you want to make a copy of the arguments.object and/or parts of the AO
does it work ?
SSabu
@SSabu
Feb 15 2016 02:57 UTC
ok, so this returns [1,2,1,2]
Otman Bouchari
@obouchari
Feb 15 2016 02:57 UTC
@bitgrower Can still use slice [].slice(arguments, 1);
bitgrower
@bitgrower
Feb 15 2016 02:57 UTC
so it's removing the 3's ... not the 2's ...
SSabu
@SSabu
Feb 15 2016 02:58 UTC
yes
and when I change so the i starts at 0 it returns the same array with the 2's inside it...
can you assign arguments to a variable? so var x = arguments?
bitgrower
@bitgrower
Feb 15 2016 03:00 UTC
I would look at your return statement based on your results ... (not based on the code) ...
@SSabu -- there is a line of code on the MDN AO page you can steal ... :)
SSabu
@SSabu
Feb 15 2016 03:00 UTC
ok, will take a look.
I took a long nap, haven't been working on this since I was last on here, for what it's worth...
Thanks @obouchari & @bitgrower
CamperBot
@camperbot
Feb 15 2016 03:01 UTC
ssabu sends brownie points to @obouchari and @bitgrower :sparkles: :thumbsup: :sparkles:
:warning: ssabu already gave obouchari points
:star: 526 | @bitgrower | http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Feb 15 2016 03:01 UTC
you might also want to take a look at the indexxOf array function, too ...
and you could use pythontutor to step thru the code and see why it's giving you the results you are getting ...
Otman Bouchari
@obouchari
Feb 15 2016 03:05 UTC
@bitgrower Nice tool man! pythontutor
bitgrower
@bitgrower
Feb 15 2016 03:05 UTC
yeah ... it gets hard to follow if you have more than a few arrays, but it can really help get insight on what's going on ....
Meghana
@meghanasarikonda
Feb 15 2016 03:06 UTC
Hello guys im at basic algorithm scripting now didn't completed my basic front end projects, which one to do first,any help???
Otman Bouchari
@obouchari
Feb 15 2016 03:06 UTC
True and learn some neat stuff on the way ;)
bitgrower
@bitgrower
Feb 15 2016 03:06 UTC
seek and destroy was driving me nuts because I didn't understand the difference between named parameters & the arguments object -- when I put some S&D code in and saw that arr = 1,2,3,1,2,3 -- I was convinced that there was something REALLY basic I didn't understand ...
and, at that point, I started to be able to ask the questions which helped me finally understand ...
...then I pieced different things I'd learned about js and finally understood why arr was 1,2,3,1,2,3 ... and expanded my understanding of js tremendously ...
Meghana
@meghanasarikonda
Feb 15 2016 03:08 UTC
Anyone please
Otman Bouchari
@obouchari
Feb 15 2016 03:09 UTC
@meghanasarikonda You can follow the order of projects
Tribute is kind of simpler to build than Portfolio
bitgrower
@bitgrower
Feb 15 2016 03:10 UTC
I would recommend doing the first 2 front end projects if you've done all the html/css, jquery, bootstrap stuff ...
...yeah, and it's better to do them while all the stuff you've just learned is fresh in your mind ...
What they did with those projects was an EXCELLENT move, imo ...
people get so bogged down in doing the algos & learning js, they forget what they just learned ...
Meghana
@meghanasarikonda
Feb 15 2016 03:11 UTC
@bitgrower okay I will complete my projects now
SSabu
@SSabu
Feb 15 2016 03:12 UTC
I like that python tutor @bitgrower
bitgrower
@bitgrower
Feb 15 2016 03:12 UTC
LOL ... told ya ... :)
they have other languages, too (obvious by the name, I'm sure ... )
SSabu
@SSabu
Feb 15 2016 03:13 UTC
so if I made a copy of the arguments object, in the example, that would be an array with 2 and 3 in it, right?
based on the example: destroyer([1,2,3,1,2,3], 2,3)
bitgrower
@bitgrower
Feb 15 2016 03:13 UTC
@SSabu -- go try it and see
w/ pythontutor you should be able to see EXACTLY what's going on ...
SSabu
@SSabu
Feb 15 2016 03:14 UTC
how should I make a copy of the arguments object? just like var x = arguments?
bitgrower
@bitgrower
Feb 15 2016 03:14 UTC
did you look on the MDN Arguments Object page like I told you about 5 minutes ago ?
SSabu
@SSabu
Feb 15 2016 03:14 UTC
yeah
bitgrower
@bitgrower
Feb 15 2016 03:15 UTC
don't glance at it ... READ it ... starting from the beginning ...
SSabu
@SSabu
Feb 15 2016 03:15 UTC
meh
Daniel Cleveland
@dpcleveland
Feb 15 2016 03:15 UTC
Could someone give me a hint on where to start with Falsy Bouncer? The instructions are to "Remove all falsy values from an array." I've read the filter() documentation at MDN, but am just so lost on where to even start. Like, do I create a new variable outside the function like MDN shows? Do I loop through every value in the array individually?
bitgrower
@bitgrower
Feb 15 2016 03:16 UTC
let me tell you something, @SSabu -- software changes rapidly -- if you want to work in software, you need to be able to go get these answers for yourself ...
it's an important skill ...as important as being able to write the code ...
that was true 35 years ago ... and it's even truer today ... :)
SSabu
@SSabu
Feb 15 2016 03:17 UTC
it worked!
umm... ok
bitgrower
@bitgrower
Feb 15 2016 03:18 UTC
YAY!!!!
you figured it out ???
SSabu
@SSabu
Feb 15 2016 03:18 UTC
yeah
bitgrower
@bitgrower
Feb 15 2016 03:19 UTC
so...did you have a breakthrough insight ?
do you understand why your code works ?
SSabu
@SSabu
Feb 15 2016 03:20 UTC
lol, still trying to figure that out, actually.
bitgrower
@bitgrower
Feb 15 2016 03:21 UTC

if you go into my profile http://freecodecamp.com/bitgrower -- you can click on my solution ...

NOW, let me tell you that I had kinda given up, so that's not original code ... HOWEVER, what I did do is sit down and understand, IN DETAIL why it works (well, with the exception of the line of code I stole from MDN) ...

...and I explain it all in my solution ...
...because the solution really is a BRILLIANT use of economical javascript ...
SSabu
@SSabu
Feb 15 2016 03:22 UTC
I took the line from the MDN where it turns the arguments object into an array
I understand the rest of the code
bitgrower
@bitgrower
Feb 15 2016 03:22 UTC
ah ... you found it !!!!
excellent !
SSabu
@SSabu
Feb 15 2016 03:22 UTC
I don't understand how that line turns the arguments object into an array
it's a long line
bitgrower
@bitgrower
Feb 15 2016 03:23 UTC
it is ...
SSabu
@SSabu
Feb 15 2016 03:23 UTC
 var args = (arguments.length === 1?[arguments[0]]:Array.apply(null, arguments));
bitgrower
@bitgrower
Feb 15 2016 03:23 UTC
yeah, it uses the ternary operator to determine the length of the arguments array/object
SSabu
@SSabu
Feb 15 2016 03:23 UTC
that was my trouble... i was assuming the arguments object was an array that I could loop through
bitgrower
@bitgrower
Feb 15 2016 03:23 UTC
if it's 1 -- hey, just return it back
SSabu
@SSabu
Feb 15 2016 03:23 UTC
ok, I'll look
bitgrower
@bitgrower
Feb 15 2016 03:24 UTC
if it's 2 -- then it turns the arguments object into an array ... using apply ... I don't understand that very well .
SSabu
@SSabu
Feb 15 2016 03:24 UTC
ternary operator?
ok will research that
bitgrower
@bitgrower
Feb 15 2016 03:24 UTC
it's basically a way of shortcutting an if/else statement ...
Daniel Cleveland
@dpcleveland
Feb 15 2016 03:25 UTC
Is this anywhere close to the solution for Falsy Bouncer? It doesn't work, but I feel like it's close...
function bouncer(obj) { if(!isNaN(obj)) { return true; } } var filtered = arr.filter(bouncer); console.log(filtered); bouncer([7, "ate", "", false, 9]);
bitgrower
@bitgrower
Feb 15 2016 03:25 UTC
if (x === 3)
do something
else
do something else
SSabu
@SSabu
Feb 15 2016 03:25 UTC
that's awesome though, I was working on this for like a week, or at least putting it off for a week because I was on a roll with the basic challenges and this one completely threw me for a loop.
bitgrower
@bitgrower
Feb 15 2016 03:25 UTC
would be x===3? do something : do something else
LOL ... I hear ya ...
SSabu
@SSabu
Feb 15 2016 03:26 UTC
:smile:
bitgrower
@bitgrower
Feb 15 2016 03:26 UTC
but go check out my solution, because I think the comments will help you to understand the solution (which is the wiki solution) ...
it's a handful of lines ... but very elegant...
SSabu
@SSabu
Feb 15 2016 03:27 UTC
ok, I will
Gordon Davidescu
@gordondavidescu
Feb 15 2016 03:27 UTC
yo
mapping the debris description is wack
bitgrower
@bitgrower
Feb 15 2016 03:28 UTC
...and, then make your own comments -- because I can nearly guarantee you, you'll go back and look at that solution again ...
@gordondavidescu -- you won't get any argument from me on that
like ... hi, can we dimensionalize the numbers here ?
I've taken it to mean you have to add the radius of the earth to the height
bitgrower
@bitgrower
Feb 15 2016 03:33 UTC
I can't say much for no repeats please, either ... seems like b(1) a(1) b(2) a(2) is different than b(2)a(2)b(1)a(1) in determining the # of permutations ...
SSabu
@SSabu
Feb 15 2016 03:34 UTC
Array.apply(null, arguments)
so this is the part that turns the arguments into an array it seems.
bitgrower
@bitgrower
Feb 15 2016 03:34 UTC
yes...
SSabu
@SSabu
Feb 15 2016 03:35 UTC
ok, I'll look into the apply method.
Gordon Davidescu
@gordondavidescu
Feb 15 2016 03:35 UTC
@bitgrower is that all it means?
i'm reading the wikipedia article and getting nowhere
bitgrower
@bitgrower
Feb 15 2016 03:36 UTC
yeah ... that's a bit of a "through the looking glass" -- using apply (& bind & call) ... if you get any profound insight, @SSabu,, come back and share it ...
SSabu
@SSabu
Feb 15 2016 03:36 UTC
lol.... i'm a dabbler... don't think I will come to a profound insight... but if I do, I'll keep you posted
bitgrower
@bitgrower
Feb 15 2016 03:37 UTC
@gordondavidescu -- that's what I kind of took away from it ... but I'm not getting the right answer, either ... so ... you know the saying "don't follow me, I'm lost!"
I did figure out what they want in that equation is in meters & they give you a value in kM ...
@SSabu -- do you know any other programming languages ?
SSabu
@SSabu
Feb 15 2016 03:40 UTC
I've studied python a bit
just dabbling in all this
my job is boring...
lol
don't know if I could be a professional programmer though because this stuff is pretty challenging...
do you @bitgrower ?
bitgrower
@bitgrower
Feb 15 2016 03:41 UTC
do I what ?
SSabu
@SSabu
Feb 15 2016 03:41 UTC
know other languages?
bitgrower
@bitgrower
Feb 15 2016 03:41 UTC
yeah ...
SSabu
@SSabu
Feb 15 2016 03:41 UTC
nice!
bitgrower
@bitgrower
Feb 15 2016 03:41 UTC
pascal, c, several different assembly languages -- or at least I used to ... :)
a little bit of python ...
SSabu
@SSabu
Feb 15 2016 03:41 UTC
nice!
bitgrower
@bitgrower
Feb 15 2016 03:42 UTC
oh yeah, and let's not forget basic ... hahahahahahaha
SSabu
@SSabu
Feb 15 2016 03:42 UTC
cool. Ok, signing off. thanks again !
Pradeep CE
@cepradeep
Feb 15 2016 03:42 UTC

@bitgrower

several different assembly languages
Respect :+1:

bitgrower
@bitgrower
Feb 15 2016 03:42 UTC
you bet ...
rphares
@rphares
Feb 15 2016 03:59 UTC
wow, quiet in here today...
Gordon Davidescu
@gordondavidescu
Feb 15 2016 04:07 UTC
thanks @bitgrower
CamperBot
@camperbot
Feb 15 2016 04:07 UTC
gordondavidescu sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 527 | @bitgrower | http://www.freecodecamp.com/bitgrower
Jonathan Mitchell
@Vanhealen
Feb 15 2016 04:43 UTC
Did anybody complete the Chunk challenge?
uriznik
@uriznik
Feb 15 2016 04:44 UTC
are you stuck on it?
DJ
@qualitymanifest
Feb 15 2016 04:44 UTC
@Vanhealen i'm sure somebody has. paste your code and your issue and maybe they will give some advice
Jonathan Mitchell
@Vanhealen
Feb 15 2016 04:45 UTC
Did you guys do FCC in order completely? it is meant to be done in order
?
DJ
@qualitymanifest
Feb 15 2016 04:45 UTC
it's meant to be done in order but you can jump around if you want
bitgrower
@bitgrower
Feb 15 2016 04:48 UTC
@rphares -- Valentine's Day ...
@vanhealen -- chunky monkey ?
rphares
@rphares
Feb 15 2016 04:50 UTC
@Vanhealen , it is meant to, but by no means required,
i have thus (no where near done) but many do not,
if you have prior coding experience, feel free to skip around--
bitgrower
@bitgrower
Feb 15 2016 04:51 UTC
@Vanhealen -- some exercises make a lot of sense to do before others ... like the nested for loops comes after an exercise in using a for loop to walk thru an array ...
rushi
@rush86999
Feb 15 2016 04:51 UTC

@rush86999
anybody know why this doesn’t work i am trying to pass a number or a “.” point in the if function

else if (!(isNaN(this.pressed) || (this.pressed == ".")

decimal point

rphares
@rphares
Feb 15 2016 04:51 UTC
the material does build-- it expects you to know more as the lessons progress, so if you are new to coding, going in order will be beneficial. if not, do what you like, though the review doesn't hurt and should be quick if you know a lot :)
bitgrower
@bitgrower
Feb 15 2016 04:52 UTC
which challenge, @rush86999 ?
Brett
@BLayman
Feb 15 2016 04:52 UTC
I'm on the "Where art thou" challenge, and I'm having difficulty working with objects. I found a way to compare the properties of the "collection" and "source" objects, but I don't know how to compare the values of those properties. Here's my code:
function where(collection, source) {
  var arr = [];
  var keyarr = [];
  for(i=0;i<collection.length;i++){
   if (collection[i].hasOwnProperty(Object.keys(source))){
     arr.push(collection[i]);
   }

  }


  return arr;
}

where([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
rushi
@rush86999
Feb 15 2016 04:52 UTC
this is not a javascript challenge it is the calculator challenge but this is a javascript question @bitgrower
bitgrower
@bitgrower
Feb 15 2016 04:53 UTC
I was just reading how isNaN is a very tricky function ... and about the only way to make sure you have NaN is to check the value you are checking against NaN ....BECAUSE, hold onto your seats ... NaN !== NaN ... (go figure!)
rushi
@rush86999
Feb 15 2016 04:54 UTC
the if( ) should allow either number OR decimal point send from a click function but not working for the decimal point
bitgrower
@bitgrower
Feb 15 2016 04:54 UTC
@BLayman -- it may help to review some of the previous object algo challenges ..
like Profile Lookup ...
DJ
@qualitymanifest
Feb 15 2016 04:54 UTC
@bitgrower and typeof NaN === number :wink2:
rushi
@rush86999
Feb 15 2016 04:54 UTC
i am using console log and the expression i mentioned doesn’t seem to allow “.” to go through
bitgrower
@bitgrower
Feb 15 2016 04:56 UTC
yeah ... that too .. @qualitymanifest -- I spent hours trying to figure out why my falsy bouncer didn't work and discovered that ... LOL ...
@rush86999 dunno about the . ... have you tried escaping it ?
@BLayman -- I can't say my solution is the best or fastest way to do it ... but I did make use of the Object.keys function ...
rushi
@rush86999
Feb 15 2016 04:59 UTC
@bitgrower i am not sure that would matter but I’ll try. it’s just string object
@bitgrower yea doesn’t work
try it on jsfiddle see
greg
@wearenotgroot
Feb 15 2016 05:02 UTC

@BLayman this will most certainly fail

if (collection[i].hasOwnProperty(Object.keys(source))){

if you read the return value of Object.keys you will notice that it returns an array of properties from the object you pass as an argument/parameter

@BLayman so if you want to check if properties in source exist in collection then you have to loop through the returned array in Object.keys(source)
@rush86999 what you working on?
Neal Caffery
@neal1991
Feb 15 2016 05:04 UTC
for the Seek and Destory, I am confused that how to filter the arguments.
function isExist(value)
{
  if(value)
    {
      return false;
    }
  else
    return true;
}

function destroyer(arr) {
  // Remove all the values
  for (var i = 1;i < arguments.length;i ++)
    {
      arguments[0].filter(isExist);
    }
  return arr;
}
@neal1991 look at the examples on how to get the arguments
bitgrower
@bitgrower
Feb 15 2016 05:06 UTC
@neal1991 -- 90% of the time people's initial problem with S& D is this: they don't understand what Arguments Objects represents, AND they think Arguments Object === arr ... and it is NOT ... arr is arguments[0];
and you can't use filter on the arguments object ...
it is array-like -- but it is NOT an array ...
Neal Caffery
@neal1991
Feb 15 2016 05:07 UTC
The crucial probelm is the isExist function can not accept arguments in the filter.
bitgrower
@bitgrower
Feb 15 2016 05:07 UTC
why do you think that, @neal1991 ?
Brett
@BLayman
Feb 15 2016 05:08 UTC
@bitgrower Yeah I think that challenge was helpful for understanding .hasOwnProperty , but in this case I don't know the name of the properties, so I can't use object.property to compare them. Like how I did contacts[0].firstName in profile lookup.
Neal Caffery
@neal1991
Feb 15 2016 05:08 UTC
In the destoryer function, I need the arguments, and then filter them, isn't it?
bitgrower
@bitgrower
Feb 15 2016 05:09 UTC
you need to use the Object.keys to get an iterator ... :)
greg
@wearenotgroot
Feb 15 2016 05:09 UTC
@neal1991 also remember each function is assigned an object (arguments) that will contain all the parameters passed on to the function, named or not named
bitgrower
@bitgrower
Feb 15 2016 05:09 UTC
This message was deleted
greg
@wearenotgroot
Feb 15 2016 05:10 UTC
@bitgrower :smile:
bitgrower
@bitgrower
Feb 15 2016 05:10 UTC
LOL ... devilish little thing, isn't it ... who you send msgs to ...
greg
@wearenotgroot
Feb 15 2016 05:10 UTC
@neal1991 remember about scope as well
bitgrower
@bitgrower
Feb 15 2016 05:10 UTC
I don't see why it doesn't do auto-complete ...
Neal Caffery
@neal1991
Feb 15 2016 05:11 UTC
..,.I do not understand what do you mean.
greg
@wearenotgroot
Feb 15 2016 05:11 UTC
@bitgrower not a big deal :smile: we can just edit
bitgrower
@bitgrower
Feb 15 2016 05:11 UTC
I mean, it does -- but under what pattern, I'm not sure ... I'll go to type someone's name and I'll end up with @camperbot ...
bitgrower @bitgrower is auto-complete spoiled
bitgrower
@bitgrower
Feb 15 2016 05:11 UTC
@neal1991 -- we know you don't understand ... and that's one of the reasons you're having problems ...
Brett
@BLayman
Feb 15 2016 05:12 UTC
@wearenotgroot It seems to be successful in pushing the collection objects that contain a key that is found in source, but it fails at returning the objects that match both the keys, and the values associated with the keys.
greg
@wearenotgroot
Feb 15 2016 05:12 UTC
@neal1991 remember if you try and access arguments inside the filter you will access the arguments of the filter function and not the main function it is in
bitgrower
@bitgrower
Feb 15 2016 05:12 UTC
the arguments object is an array-like object containing ALL the arguments ...
greg
@wearenotgroot
Feb 15 2016 05:12 UTC
@BLayman you need to test for it separately
bitgrower
@bitgrower
Feb 15 2016 05:12 UTC
however, not all parameters provided in the function definition have to have names ... so the only way you can find them is through the arguments object ...
Neal Caffery
@neal1991
Feb 15 2016 05:13 UTC
I know this, but how should I use it for the filter, it is the poinrt.
bitgrower
@bitgrower
Feb 15 2016 05:13 UTC
in this case, you are passed 3 arguments, and you only have 1 named argument ...
Brett
@BLayman
Feb 15 2016 05:13 UTC
@wearenotgroot I think it would fail to work if source contained more that one key, which might be what you're getting at.
bitgrower
@bitgrower
Feb 15 2016 05:13 UTC
@neal1991 -- start with Arguments Object page on Mozilla Developer Network ... there's a nice little piece of code which will convert your AO to an array ... :)
greg
@wearenotgroot
Feb 15 2016 05:14 UTC
@neal1991 just store the values on argument of the main function into an array so the filter can access it
Neal Caffery
@neal1991
Feb 15 2016 05:14 UTC
can you give an example, I think it would be easier for me to understand ...
bitgrower
@bitgrower
Feb 15 2016 05:14 UTC
literally, @neal1991
greg
@wearenotgroot
Feb 15 2016 05:14 UTC
@BLayman need more loops then,
bitgrower
@bitgrower
Feb 15 2016 05:14 UTC
arguments[0] = [1,2,3,1,2,3]
arguments1 = 2
arguments2 = 3
Neal Caffery
@neal1991
Feb 15 2016 05:15 UTC
but the arr how to be passed to the isExist function
greg
@wearenotgroot
Feb 15 2016 05:15 UTC
@BLayman remember you have other types of loop that specialises on looping through properties as well
Brett
@BLayman
Feb 15 2016 05:15 UTC
@wearenotgroot So I shouldn't use a for loop?
bitgrower
@bitgrower
Feb 15 2016 05:16 UTC
@neal1991 -- read up on Array.filter ...
greg
@wearenotgroot
Feb 15 2016 05:16 UTC
@BLayman you can use normal for loop
@BLayman you just need separate for loops
@BLayman or a filter then a for loop for the properties
Brett
@BLayman
Feb 15 2016 05:17 UTC
@wearenotgroot would nesting the loops be a good approach?
greg
@wearenotgroot
Feb 15 2016 05:17 UTC
@BLayman sure thing
bitgrower
@bitgrower
Feb 15 2016 05:18 UTC

@BLayman remember you have other types of loop that specialises on looping through properties as well

^^^ I'm all ears... :)

greg
@wearenotgroot
Feb 15 2016 05:18 UTC
@BLayman just dont get confuse on which is which
@bitgrower for (var someprop in) :smile:
Brett
@BLayman
Feb 15 2016 05:20 UTC
@wearenotgroot @bitgrower So I think I could figure out how to use two loops to find the shared properties in collection and source, but the main wall that I'm hitting is that I don't know how to compare the values of those properties, to make sure those match too.
greg
@wearenotgroot
Feb 15 2016 05:20 UTC
@BLayman you can try and use a filter for the collection then for loop for the Object.keys, that way you only have to deal with 1 for loop
bitgrower
@bitgrower
Feb 15 2016 05:20 UTC
value = object[property]
knnonah
@knnonah
Feb 15 2016 05:21 UTC
Will someone please help me understand why this function is not working properly?

//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 lookUp(firstName, prop){
// Only change code below this line
for(var i = 0; i < contacts.length; i++){
if(firstName === contacts[i].firstName && prop === contacts[i].prop){
return contacts[i].prop;
}
if (firstName !== contacts[i].firstName){
return "No such contact";
}
if(prop !== contacts[i].prop){
return "No such property";
}

}

// Only change code above this line
}

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

Brett
@BLayman
Feb 15 2016 05:21 UTC
@bitgrower But what if I don't know what the property is called?
bitgrower
@bitgrower
Feb 15 2016 05:21 UTC
@wearenotgroot -- so then you would have to check .hasOwnProperty, right?
that's what Object.keys is for
greg
@wearenotgroot
Feb 15 2016 05:22 UTC
@bitgrower :+1:
knnonah
@knnonah
Feb 15 2016 05:22 UTC
For some reason the first "if" statement is not evaluating.
It is not evaluating true.
Jonathan Mitchell
@Vanhealen
Feb 15 2016 05:22 UTC
@bitgrower i meant more for like the algorithm challenges
knnonah
@knnonah
Feb 15 2016 05:22 UTC
The arguments of "Akira", "likes" are contained in contacts. Therefore, they are true.
greg
@wearenotgroot
Feb 15 2016 05:23 UTC
@knnonah this guy ----->prop === contacts[i].prop will not give you the result you are after
bitgrower
@bitgrower
Feb 15 2016 05:23 UTC
@knnonah -- can you please help the tired eyes of the helpers here and use @camperbot's formatting instructions (follow closely & carefully) ...
explain format
CamperBot
@camperbot
Feb 15 2016 05:23 UTC

:point_right: code formatting [wiki]

Inline code

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

Code Block

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

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

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

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

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

greg
@wearenotgroot
Feb 15 2016 05:23 UTC
@knnonah to test if the property exist use .hasOwnPropert(prop)
Brett
@BLayman
Feb 15 2016 05:23 UTC
@bitgrower But wouldn't that just tell me if it has a property, not the value of the property?
Alex
@wiscoay521
Feb 15 2016 05:23 UTC
can anyone explain the .reduce function? the mozilla description is sort of weird
im on the first intermediate bonfire summing all numbers in a range
greg
@wearenotgroot
Feb 15 2016 05:24 UTC
@wiscoay521 is it ?
bitgrower
@bitgrower
Feb 15 2016 05:24 UTC
@Blayman -- once you use Object(keys) you have an array of keys ...you can iterate thru those
Alex
@wiscoay521
Feb 15 2016 05:24 UTC
@wearenotgroot yeah i don't really understand it
bitgrower
@bitgrower
Feb 15 2016 05:24 UTC
post your code @wiscoay521 ... always seemed pretty straightforward to me ...
knnonah
@knnonah
Feb 15 2016 05:24 UTC
@camperbot
Alex
@wiscoay521
Feb 15 2016 05:25 UTC
ah i haven't started it haha. just looking at how best to approach it first
greg
@wearenotgroot
Feb 15 2016 05:25 UTC
@wiscoay521 well it start out with the previous at element zero, then you have a current, now do some computation on those then return result, that result will now be the previous
bitgrower
@bitgrower
Feb 15 2016 05:25 UTC
@knnonah -- you can say things like "help", "wiki", "explain" to get @camperbot's attention ...
greg
@wearenotgroot
Feb 15 2016 05:25 UTC
@wiscoay521 then it moves on to the next
Alex
@wiscoay521
Feb 15 2016 05:25 UTC
@wearenotgroot oh ok that helps
greg
@wearenotgroot
Feb 15 2016 05:26 UTC
@wiscoay521 take a look at the table displaying data on the example
bitgrower @bitgrower thinks she should go thru the FCC suggested course on functional programming ...
Alex
@wiscoay521
Feb 15 2016 05:26 UTC
so if an array is like this ([1,4]) than it means it is a ranged array? like 1,2,3,4?
bitgrower
@bitgrower
Feb 15 2016 05:26 UTC
@wiscoay521 -- no .
it's just 2 numbers
knnonah
@knnonah
Feb 15 2016 05:27 UTC
Why doesn't contact[i].prop work?
Also, contact[i].hasOwnProperty(prop) isn't working as well?
Alex
@wiscoay521
Feb 15 2016 05:27 UTC
@bitgrower oh ok. i thought the parenthesis meant it was a range or something
bitgrower
@bitgrower
Feb 15 2016 05:27 UTC
which parentheses ?
Alex
@wiscoay521
Feb 15 2016 05:28 UTC
sumAll ([1, 4]);
greg
@wearenotgroot
Feb 15 2016 05:28 UTC
@knnonah if you analyse your data. you will see that prop is not a property on the object so .(dot) notation will not work
{
"firstName": "Akira",//<--------------------.firstName will work
"lastName": "Laine",//<---------------------.lastName will work
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
Alex
@wiscoay521
Feb 15 2016 05:28 UTC
it wants me to sum the two numbers and all numbers in between. Since there are only two numbers I was wondering how exactly I sum numbers that aren't there
Brett
@BLayman
Feb 15 2016 05:28 UTC
@bitgrower Oh, so Object.keys() gives you the keys, and the value of the keys?
bitgrower
@bitgrower
Feb 15 2016 05:28 UTC
LOL ... no, that means it's an argument being passed to the function ... :) ... I think the instructions mention it's a 2 member array ...
@Blayman -- that's how I understand it ... it's an array of the keys of your object ...
knnonah
@knnonah
Feb 15 2016 05:29 UTC
Yes, is prop a variable and if the argument "likes" is assigned to it and "likes" is a property why doesn't it work?
Alex
@wiscoay521
Feb 15 2016 05:29 UTC
@bitgrower oh jeezz. duh lol

We'll pass you an array of two numbers. Return the sum of those two numbers and all numbers between them.

The lowest number will not always come first.

those are the instructions though
greg
@wearenotgroot
Feb 15 2016 05:30 UTC
@knnonah using variable to access the object and values, you have to use bracket notation
bitgrower
@bitgrower
Feb 15 2016 05:30 UTC
LOL ... we all do s* like that, not to worry ... laugh ... slap your head and go ... okay, hopefully I won't make THAT mistake again ...
...but the PRIMARY lesson is to read things CAREFULLY ... read 'em once, and even when you think you understand them ... read them again ...
greg
@wearenotgroot
Feb 15 2016 05:31 UTC
@knnonah like so contacts[i][prop] as oppose to contacts[i].prop
bitgrower
@bitgrower
Feb 15 2016 05:31 UTC
there are ANY number of challenges where I didn't do that to begin with, and would have gotten to solutions much faster had I ...
greg
@wearenotgroot
Feb 15 2016 05:32 UTC
@knnonah this guy ---prop = 'likes' --->contacts[i][prop] is the same as contacts[i].likes or contacts[i]['likes'] if prop is equal likes that is
bitgrower
@bitgrower
Feb 15 2016 05:33 UTC
seems like straightforward instructions to me, @wiscoay521 -- I don't know how they could get too much clearer ... :)
knnonah
@knnonah
Feb 15 2016 05:34 UTC
@wearenotgroot
bitgrower
@bitgrower
Feb 15 2016 05:34 UTC

@wiscoay521 -- so break it down ...

you have 2 numbers, and they aren't in order ...

ah ... okay, maybe I need to put them in consistent order before I move on ... :)

knnonah
@knnonah
Feb 15 2016 05:35 UTC
@wearenotgroot using the bracket notation or the hasOwnProperty() method is not working.
bitgrower
@bitgrower
Feb 15 2016 05:35 UTC
@wiscoay521 -- then I have 2 numbers, and I need to sum up the intervening numbers and the 2 numbers I've been given ... hmmmmm ... okay ... how can I do that?
greg
@wearenotgroot
Feb 15 2016 05:35 UTC
@knnonah depends on how you are using them
knnonah
@knnonah
Feb 15 2016 05:35 UTC
I am still not seeing where I am going wrong and where my misunderstanding is.
greg
@wearenotgroot
Feb 15 2016 05:36 UTC
@knnonah post updated code
bitgrower
@bitgrower
Feb 15 2016 05:36 UTC
@wiscoay521 -- many times if you just solve the problem any way you can to get the right solution, then you can get some insight into how to solve the problem better ... :)
knnonah
@knnonah
Feb 15 2016 05:37 UTC

@wearenotgroot
function lookUp(firstName, prop){
// Only change code below this line
for(var i = 0; i < contacts.length; i++){
if(firstName === contacts[i].firstName && prop === contacts[i].hasOwnProperty(prop)){
return contact[i][prop] ;
}
if (firstName !== contacts[i].firstName){
return "No such contact";
}
if(prop !== contacts[i].prop){
return "No such property";
}

}

// Only change code above this line
}

Brett
@BLayman
Feb 15 2016 05:37 UTC

@bitgrower @wearenotgroot Ok, I think I have a strategy for getting the values associated with the keys. Use Object.keys() to make an array of the keys, then use that array to get the values associated with those keys. Something like this:

sourceKeys =  Object.keys(source);
valueOfFirstKey =  source.sourceKeys[0];

look about right?

greg
@wearenotgroot
Feb 15 2016 05:38 UTC
@knnonah the most trickiest but rather simple part of this challenges is where to do the return "No such contact" bane of peoples existence
@knnonah remember .hasOwnProperty will return a boolean value
@knnonah if the property in question exist it will return true if not false
@knnonah the correct use is
if(firstName === contacts[i].firstName && contacts[i].hasOwnProperty(prop))
@knnonah prop value is 'likes' --while ------->contacts[i].hasOwnProperty(prop) will return true/false so this wont work prop === contacts[i].hasOwnProperty(prop)
@
knnonah
@knnonah
Feb 15 2016 05:42 UTC
@wearenotgroot Previously, I tried the hasOwnProperty based my condition on the true or false outcome and still the function did not evaluate correctly.
greg
@wearenotgroot
Feb 15 2016 05:42 UTC
@BLayman sure that will work
@knnonah yes because of the second if test you have
Brett
@BLayman
Feb 15 2016 05:43 UTC
@bitgrower @wearenotgroot Cool, I think I have the tools to figure it out now. Thanks for pointing me in the right direction.
CamperBot
@camperbot
Feb 15 2016 05:43 UTC
blayman sends brownie points to @bitgrower and @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 844 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
:star: 528 | @bitgrower | http://www.freecodecamp.com/bitgrower
greg
@wearenotgroot
Feb 15 2016 05:43 UTC
@wiscoay521 sorry wrong mention :smile:
knnonah
@knnonah
Feb 15 2016 05:43 UTC
@wearenotgroot The if test for firstName?
greg
@wearenotgroot
Feb 15 2016 05:44 UTC
@knnonah this guy --------->
if (firstName !== contacts[i].firstName){
return "No such contact";
}
@knnonah what happens if the first if test fails ? and this triggers?
knnonah
@knnonah
Feb 15 2016 05:45 UTC
@wearenotgroot I get "No such contact" in the console.
greg
@wearenotgroot
Feb 15 2016 05:45 UTC
@knnonah yes you do
@knnonah however are you sure it chck every item on contacts array?
knnonah
@knnonah
Feb 15 2016 05:46 UTC
It doesn't. It only checks FirstName.
At least, that is my belief.
greg
@wearenotgroot
Feb 15 2016 05:47 UTC
@knnonah well ->firstName !== contacts[i].firstName means it the firstName are not equal
Marek Slabicki
@thaniri
Feb 15 2016 05:48 UTC
hello, can anyone help me center an h1? http://codepen.io/thaniri/pen/MKPEXm
greg
@wearenotgroot
Feb 15 2016 05:48 UTC
@knnonah it is the same as else
if(firstName === contacts[i].firstName)
{
}
else
{

}
knnonah
@knnonah
Feb 15 2016 05:48 UTC
@wearenotgroot Yes, that is a condition written into the exercise. If firstName does not correspond to any contacts then return "No such contact"
greg
@wearenotgroot
Feb 15 2016 05:49 UTC
@knnonah yes, but think of what happens if the first if test fails
@knnonah the second one will be executed next
@knnonah then it will be triggered and then returns No such contact
knnonah
@knnonah
Feb 15 2016 05:50 UTC
Yes, but it triggers only if firstName has no match.
greg
@wearenotgroot
Feb 15 2016 05:50 UTC
@knnonah but you cant be sure if the test reaches the end of the contacts array
knnonah
@knnonah
Feb 15 2016 05:50 UTC
No, I can't.
greg
@wearenotgroot
Feb 15 2016 05:50 UTC
@knnonah ok let take an example
@knnonah let's say "Harry" is the name you are after
@knnonah now we know that the first on the list is Akira
@knnonah so the first if test will fail for sure
@knnonah then it moves on to the second if test
@knnonah finds that the firstName isnt a match then return No such contact
@knnonah the loop exits and the function returns
@knnonah you see what happened?
@knnonah it never got to the second item on the array
knnonah
@knnonah
Feb 15 2016 05:53 UTC
Yes, I understand. The function is only evaluating thru the first item in the array.
greg
@wearenotgroot
Feb 15 2016 05:53 UTC
@knnonah remember every return statement will stop the loop and exit the function
knnonah
@knnonah
Feb 15 2016 05:54 UTC
I need to rearrange my return statements.
greg
@wearenotgroot
Feb 15 2016 05:54 UTC
@knnonah ok then how can we make sure that it will not exit too early?
@knnonah :+1:
SuhasHosamani
@SuhasHosamani
Feb 15 2016 05:54 UTC

hi All

function factorialize(num) {
  var factorial;
  var ans = 1;
    for(i=0; i<num; i++){
    factorial = num - i;     
      ans = ans * factorial;
  }
  return factorial;
}

factorialize(5);

whats is wrong with this code?

greg
@wearenotgroot
Feb 15 2016 05:54 UTC
@knnonah most simpliest solution is to not have the second if test
@knnonah just return "No such contact" outside the for loop
@knnonah that way you let the test continue until the end of the contacts array
knnonah
@knnonah
Feb 15 2016 05:57 UTC
@wearenotgroot Thanks for your help. I am going to rewrite the function now.
CamperBot
@camperbot
Feb 15 2016 05:57 UTC
knnonah sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 845 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
greg
@wearenotgroot
Feb 15 2016 05:57 UTC
@knnonah YW
@SuhasHosamani you are returning the wrong thing
@SuhasHosamani try return ans instead of factorial
bitgrower
@bitgrower
Feb 15 2016 06:00 UTC
also @SuhasHosamani -- did you mean factorial to be num -1 ?
Sri Keerthi N
@keerthinerella
Feb 15 2016 06:00 UTC
can anyone help me out ... in solving the "stand in line" chaallenge in javascript?
David Weedmark
@DavidWeedmark
Feb 15 2016 06:00 UTC
working on the wikipedia project. has anyone noticed that you can just paste wikipedia's search code into a page and it works? no api's needed
bitgrower
@bitgrower
Feb 15 2016 06:01 UTC
@keerthinerella -- it's a 2 line solution, pretty much -- and the best way to find it, imnsho ...
is to go look inthe Mozilla Developer Network on the arrays page and "shop" for some functions which will satisfy the challenge ... :)
Sri Keerthi N
@keerthinerella
Feb 15 2016 06:01 UTC
@bitgrower i have used push and pop functions there..
greg
@wearenotgroot
Feb 15 2016 06:02 UTC
@SuhasHosamani `
function factorialize(num) {
  var factorial;
  var ans = 1;
    for(i=0; i<num; i++){
    factorial = num - i;     
      ans = ans * factorial;  //<-----------------------stored the computed value on ans but returned factorial for some reason :)
  }
  return factorial; //<-------------returning the wrong thing, return ans instead
}

factorialize(5);
Sri Keerthi N
@keerthinerella
Feb 15 2016 06:02 UTC
@bitgrower yet it is not completed
bitgrower
@bitgrower
Feb 15 2016 06:03 UTC
good !!! you are very close then .. but you picked up one wrong function ... you need to replace it with a different one .. there are methods for getting the value on the "left" side of the array, and ones for getting the value on the "right" side of the array ... .different functions
greg
@wearenotgroot
Feb 15 2016 06:03 UTC
@DavidWeedmark yes but the point was to use the api
bitgrower
@bitgrower
Feb 15 2016 06:03 UTC
(but ones this old assembly language programmer finds near & dear to her heart ... !!!)
Sri Keerthi N
@keerthinerella
Feb 15 2016 06:04 UTC
@bitgrower so shall i use shift function here?
bitgrower
@bitgrower
Feb 15 2016 06:04 UTC
hmmm .... well, try it out and see !!!!!
David Weedmark
@DavidWeedmark
Feb 15 2016 06:05 UTC
@wearenotgroot oh I'll be doing it the hard way. I just wanted to see how they did it, when lo and behold, it worked!
greg
@wearenotgroot
Feb 15 2016 06:05 UTC
@DavidWeedmark :+1:
LaevateinY
@LaevateinY
Feb 15 2016 06:06 UTC
function steamroller(arr) {
  // I'm a steamroller, baby
  var result = [];
  function flatten(stuff) {
    for (i = 0; i < stuff.length; i++) {
      if (Array.isArray(stuff[i])) {
         flatten(stuff[i]);
      } else {
        result.push(stuff[i]);
      }
    }
  }
  flatten(arr);
  return result;
}
sorry...anyone did this yet?
greg
@wearenotgroot
Feb 15 2016 06:07 UTC
@DavidWeedmark well the wikipedia page uses it's own api so, it only make sense that what you did will work :smile:
LaevateinY
@LaevateinY
Feb 15 2016 06:07 UTC
I can't seem to be able to complete it...:(
bitgrower
@bitgrower
Feb 15 2016 06:08 UTC
LOL, yes @LaevateinY -- lots of folks ...
LaevateinY
@LaevateinY
Feb 15 2016 06:10 UTC
i mean like is there anything wrong with my recursion? it crashes my browser everytime haha
bitgrower
@bitgrower
Feb 15 2016 06:10 UTC
...I'd say your browser has spoken ...
SuhasHosamani
@SuhasHosamani
Feb 15 2016 06:12 UTC
@bitgrower yes num -1
Sri Keerthi N
@keerthinerella
Feb 15 2016 06:13 UTC
@bitgrower i have used shift function...but no change ;(
greg
@wearenotgroot
Feb 15 2016 06:13 UTC
@SuhasHosamani did my suggestion worked?
Sri Keerthi N
@keerthinerella
Feb 15 2016 06:13 UTC
can u help me out?
bitgrower
@bitgrower
Feb 15 2016 06:13 UTC
@keerthinerella -- post your code follow @camperbot's instructions CLOSELY
explain format
CamperBot
@camperbot
Feb 15 2016 06:13 UTC

:point_right: code formatting [wiki]

Inline code

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

Code Block

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

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

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

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

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

SuhasHosamani
@SuhasHosamani
Feb 15 2016 06:14 UTC
@wearenotgroot yes :) thanks
CamperBot
@camperbot
Feb 15 2016 06:14 UTC
suhashosamani sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 846 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
greg
@wearenotgroot
Feb 15 2016 06:14 UTC
@SuhasHosamani next time name the variable properly and note what to use them for :smile:
@SuhasHosamani i think you got confuse because you both have factorial and ans variable
SuhasHosamani
@SuhasHosamani
Feb 15 2016 06:16 UTC
@wearenotgroot yes got confused :smile:
greg
@wearenotgroot
Feb 15 2016 06:17 UTC
@LaevateinY you forgot to concat the arrays!
SuhasHosamani
@SuhasHosamani
Feb 15 2016 06:17 UTC
@wearenotgroot can i better tat ans??
greg
@wearenotgroot
Feb 15 2016 06:17 UTC
@SuhasHosamani you mean if your code was ok?
@SuhasHosamani yes your code it good
LaevateinY
@LaevateinY
Feb 15 2016 06:18 UTC
@wearenotgroot Doesn't the push function push all the values that are not arrays into the array called result?
SuhasHosamani
@SuhasHosamani
Feb 15 2016 06:19 UTC
@wearenotgroot okay
greg
@wearenotgroot
Feb 15 2016 06:20 UTC
@LaevateinY well the point of the isArray test was to test if the item is an array
@LaevateinY then concat the result of
@LaevateinY a recursive call
@LaevateinY something like -
@LaevateinY
if (Array.isArray(stuff[i])) {
         result = result.concat(flatten(stuff[i]));
      } else {
@LaevateinY the recursive call is meant to check if there is further more array inside the item you tested
anyways going to eat beakfast
GL and Happy Coding
Markus Kiili
@Masd925
Feb 15 2016 06:26 UTC
@LaevateinY The function gets simpler if you forget the inner function and use steamroller to flatten the inner arrays.
LaevateinY
@LaevateinY
Feb 15 2016 06:31 UTC
@Masd925 @wearenotgroot Thanks guys...I found the issue but I'm not sure why
CamperBot
@camperbot
Feb 15 2016 06:31 UTC
laevateiny sends brownie points to @masd925 and @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 984 | @masd925 | http://www.freecodecamp.com/masd925
:star: 847 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
LaevateinY
@LaevateinY
Feb 15 2016 06:31 UTC
    for (var i = 0; i < stuff.length; i++) {
Apparently i needed to add the "var" in the declaration of the loop variable
which I'm not very sure why...you guys have any idea?
bitgrower
@bitgrower
Feb 15 2016 06:33 UTC
you've otherwise defined it as a global, @LaevateinY -- that means each call of the function is going to be using the same variable i
Markus Kiili
@Masd925
Feb 15 2016 06:34 UTC
@LaevateinY You need to declare it inside the for loop definition or at the start of the function. Both are actually equivalent.
LaevateinY
@LaevateinY
Feb 15 2016 06:35 UTC
oh i see...so in previous exercises it worked because i only used the i once!
@bitgrower @Masd925 thanks guys
CamperBot
@camperbot
Feb 15 2016 06:35 UTC
laevateiny sends brownie points to @bitgrower and @masd925 :sparkles: :thumbsup: :sparkles:
:warning: laevateiny already gave masd925 points
:star: 529 | @bitgrower | http://www.freecodecamp.com/bitgrower
Yuvraj Adagale
@Yuvraj1989
Feb 15 2016 06:36 UTC
can anyone please help me with Counting cards challenge
bitgrower
@bitgrower
Feb 15 2016 06:37 UTC
well, when you are using recursion -- local variables take on added significance ... :)
I'm sure @Mas925 & @wearenotgroot have better explanations ... :)
@Yuvraj1989 -- sure -- helps if you can post your code as to @camperbot's instructions:
explain format
CamperBot
@camperbot
Feb 15 2016 06:39 UTC

:point_right: code formatting [wiki]

Inline code

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

Code Block

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

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

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

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

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

SuhasHosamani
@SuhasHosamani
Feb 15 2016 06:40 UTC

Hi All,

function palindrome(str) {
  // Good luck!
  var arr = [];
  arr = str.split('');
  arr.reverse();
  revstr = arr.join('');
revstr = revstr.replace(/' '/g, '');
  if(revstr === str){
    return true;
  }else{
    return revstr;
  }

}
palindrome("race car");

space is not getting removed.

bitgrower
@bitgrower
Feb 15 2016 06:44 UTC
you probably need to declare revstr before using it, @SuhasHosamani
uriznik
@uriznik
Feb 15 2016 06:45 UTC
and you've only removed spaces from the reversed string
bitgrower
@bitgrower
Feb 15 2016 06:46 UTC
that too, @uriznik -- I'm not sure if @SuhasHosamani has assumed strings are mutable ... (which they aren't)
Yuvraj Adagale
@Yuvraj1989
Feb 15 2016 06:47 UTC

var count = 0;

function cc(card) {
// Only change code below this line
if (card<1 && card<=6){ count =1+ card; if(count>0){
return count+"Bet";
}if (count === 0 || count<0){ return count + "Hold"; } } if (card >6 && card<=9){
count=card;
if(count>0){
return count+"Bet";
}if (count === 0 || count<0){ return count + "Hold"; } } if (card ===10 || card === 'J'|| card ==='Q'||card ==='K'||card =='A'){ count -=card; if(count>0){
return count+"Bet";
}if (count === 0 || count<0){
return count + "Hold";
}

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

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

bitgrower
@bitgrower
Feb 15 2016 06:47 UTC
yeah, looks like you cannot do this effectively: revstr = revstr.replace(...
Yuvraj Adagale
@Yuvraj1989
Feb 15 2016 06:48 UTC
not working
bitgrower
@bitgrower
Feb 15 2016 06:48 UTC
can you post your code via @camperbot's formatting instructions ?
explain format
CamperBot
@camperbot
Feb 15 2016 06:48 UTC

:point_right: code formatting [wiki]

Inline code

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

Code Block

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

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

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

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

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

bitgrower
@bitgrower
Feb 15 2016 06:48 UTC
thanks!
SuhasHosamani
@SuhasHosamani
Feb 15 2016 06:49 UTC
revstr = revstr.replace(/\s/g, '');
  str = str.replace(/\s/g, '');
this worked guys
Markus Kiili
@Masd925
Feb 15 2016 06:50 UTC
@SuhasHosamani You should first remove the non-alphanumerics with replace and then construct the reversed string. That way you only need to replace once.
bitgrower
@bitgrower
Feb 15 2016 06:51 UTC
hmmm ... wonder if my playground is more restrictive for some reason ...
so ... you are saying those assignments worked ... or are you saying that you've solved the challenge... @SuhasHosamani ?
E
@efhjones
Feb 15 2016 06:53 UTC
Hi everyone, could someone please tell me why my function capitalizeFirstLetter is returning that it's not a function?
function capitalizeFirstLetter(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
}
var capitalized; 

function titleCase(str) {
    var splitStr = str.split(" ");

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

    var capitalized = splitStr.capitalizeFirstLetter();
    return capitalized;
  }
}
Olawale Akinseye
@brainyfarm
Feb 15 2016 06:54 UTC
@efhjones why are you slicing after capitalization?
Markus Kiili
@Masd925
Feb 15 2016 06:54 UTC
@efhjones Variables need to be declared inside the function so FCC can test function properly.
Ankit Panwar
@coderNoob
Feb 15 2016 06:55 UTC
What happens when you call slice() on an array without passing any argument?
uriznik
@uriznik
Feb 15 2016 06:55 UTC
@efhjones what type is splitStr?
SuhasHosamani
@SuhasHosamani
Feb 15 2016 06:56 UTC
@Masd925 @bitgrower only half assignment worked, the other half not working
Markus Kiili
@Masd925
Feb 15 2016 06:57 UTC
@efhjones splitStr is an array and arrays don't have method capitalizeFirstLetter.
Yuvraj Adagale
@Yuvraj1989
Feb 15 2016 06:57 UTC

'var count = 0;

function cc(card) {
// Only change code below this line
if (card<1 && card<=6){ count =1+ card; if(count>0){
return count+"Bet";
}if (count === 0 || count<0){ return count + "Hold"; } } if (card >6 && card<=9){
count=card;
if(count>0){
return count+"Bet";
}if (count === 0 || count<0){ return count + "Hold"; } } if (card ===10 || card === 'J'|| card ==='Q'||card ==='K'||card =='A'){ count -=card; if(count>0){
return count+"Bet";
}if (count === 0 || count<0){
return count + "Hold";
}

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

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

E
@efhjones
Feb 15 2016 06:58 UTC
@Masd925 Ah ok. That would be convenient wouldn't it? :laughing:
@Masd925 earlier versions had SplitStr[i] in hopes of capitalizing the first character in a string in an array :grimacing:
Yuvraj Adagale
@Yuvraj1989
Feb 15 2016 07:01 UTC
''' js
CamperBot
@camperbot
Feb 15 2016 07:01 UTC
:bulb: to format code use backticks! ``` more info
Yuvraj Adagale
@Yuvraj1989
Feb 15 2016 07:01 UTC

'''var count = 0;

function cc(card) {
// Only change code below this line
if (card<1 && card<=6){ count =1+ card; if(count>0){
return count+"Bet";
}if (count === 0 || count<0){ return count + "Hold"; } } if (card >6 && card<=9){
count=card;
if(count>0){
return count+"Bet";
}if (count === 0 || count<0){ return count + "Hold"; } } if (card ===10 || card === 'J'|| card ==='Q'||card ==='K'||card =='A'){ count -=card; if(count>0){
return count+"Bet";
}if (count === 0 || count<0){
return count + "Hold";
}

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

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

CamperBot
@camperbot
Feb 15 2016 07:01 UTC
:bulb: to format code use backticks! ``` more info
Markus Kiili
@Masd925
Feb 15 2016 07:01 UTC
@efhjones Your code has several small problems. If you don't get it working I can post the repaired version of it that works.
E
@efhjones
Feb 15 2016 07:01 UTC
@Masd925 thanks, i'll keep working on it for a while and come back just before my fist goes through the screen
CamperBot
@camperbot
Feb 15 2016 07:01 UTC
efhjones sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 985 | @masd925 | http://www.freecodecamp.com/masd925
Yuvraj Adagale
@Yuvraj1989
Feb 15 2016 07:02 UTC

```var count = 0;

function cc(card) {
// Only change code below this line
if (card<1 && card<=6){ count =1+ card; if(count>0){
return count+"Bet";
}if (count === 0 || count<0){ return count + "Hold"; } } if (card >6 && card<=9){
count=card;
if(count>0){
return count+"Bet";
}if (count === 0 || count<0){ return count + "Hold"; } } if (card ===10 || card === 'J'|| card ==='Q'||card ==='K'||card =='A'){ count -=card; if(count>0){
return count+"Bet";
}if (count === 0 || count<0){
return count + "Hold";
}

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

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

E
@efhjones
Feb 15 2016 07:02 UTC
@Yuvraj1989 the back ticks have to be on a new line
Markus Kiili
@Masd925
Feb 15 2016 07:02 UTC
@efhjones Yes, that feeling is the driving force behind learning to code.
Yuvraj Adagale
@Yuvraj1989
Feb 15 2016 07:02 UTC
@Masd925 please
Mohit Garg
@mohitgarg
Feb 15 2016 07:03 UTC
Hii @/all Can anyone recommend a good blog name for javascript? I want to start a blog to help the beginners get started on JS
E
@efhjones
Feb 15 2016 07:04 UTC
Javascribe! :laughing: :
Markus Kiili
@Masd925
Feb 15 2016 07:05 UTC
@4mohit JavaScript, the pesky little browser scripting language...not!
greg
@wearenotgroot
Feb 15 2016 07:06 UTC
@SuhasHosamani post you updated code
Yuvraj Adagale
@Yuvraj1989
Feb 15 2016 07:07 UTC
var count = 0;

function cc(card) {
  // Only change code below this line
  if (card<1 && card<=6){
    count =1+ card;
    if(count>0){
      return count+"Bet";
    }if (count === 0 || count<0){
      return count + "Hold";
    }
  }
  if (card >6 && card<=9){
    count=card;
    if(count>0){
      return count+"Bet";
    }if (count === 0 || count<0){
      return count + "Hold";
    }
  }
  if (card ===10 || card === 'J'|| card ==='Q'||card ==='K'||card =='A'){
    count -=card;
    if(count>0){
      return count+"Bet";
    }if (count === 0 || count<0){
      return count + "Hold";
    }

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

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
bitgrower
@bitgrower
Feb 15 2016 07:07 UTC
@Yuvraj1989 -- you are SOOOO close ... you need to put the ```js on one line, and have nothing else on that line ...
uriznik
@uriznik
Feb 15 2016 07:07 UTC
@Yuvraj1989 have you done an exercise using the 'switch' statement?
Marina
@chandra90
Feb 15 2016 07:07 UTC
```
Yuvraj Adagale
@Yuvraj1989
Feb 15 2016 07:07 UTC
yes I have
TheoSarran
@TheoSarran
Feb 15 2016 07:07 UTC

Hi, are there other ways to write Seek and Destroy without indexOf ?

```/jshint esversion: 6 /

function destroyer(arr, ...args) {
arr = arr.filter(function(val) {
if(args.indexOf(val) == -1) {
return val;
}
});
return arr;
}

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

Thanks!

bitgrower
@bitgrower
Feb 15 2016 07:07 UTC
ahh you got it !!!! Congrats!
Marina
@chandra90
Feb 15 2016 07:08 UTC
function convert(celsius) {
  // Only change code below this line

myVar=(9/5)+32;

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

// Change the inputs below to test your code
convert(0);
How to Create a variable fahrenheit and apply the algorithm to assign it the corresponding temperature in Fahrenheit.?
bitgrower
@bitgrower
Feb 15 2016 07:08 UTC
Why don't you want to use indexOf, @TheoSarran
greg
@wearenotgroot
Feb 15 2016 07:08 UTC
@Yuvraj1989 review this challenge: Multiple Identical Options in Switch Statements
Marina
@chandra90
Feb 15 2016 07:08 UTC
Please help!
kirbyedy
@kirbyedy
Feb 15 2016 07:08 UTC
@chandra90 first of all you have to declare a variable
TheoSarran
@TheoSarran
Feb 15 2016 07:08 UTC
I just thought I'd ask, I find it useful to know different ways to do the same thing, for flexibility
Yuvraj Adagale
@Yuvraj1989
Feb 15 2016 07:09 UTC
@wearenotgroot Ok I'll try
casadaro
@Casadaro
Feb 15 2016 07:09 UTC
could this be written as a switch statement?
// Only change code below this line
function update(id, prop, value) {
  if(value !== "" && prop !== "tracks") {
    collection[id][prop] = value;
  }

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

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

  return collection;
}
bitgrower
@bitgrower
Feb 15 2016 07:09 UTC
you have a solution which works ? @TheoSarran ... I would say most people find indexOf as a pretty cool way to solve problems ...
Ankit Panwar
@coderNoob
Feb 15 2016 07:10 UTC
What happens when you call slice() on an array without passing any argument?
TheoSarran
@TheoSarran
Feb 15 2016 07:10 UTC
Great! I was curious... I'm pretty new. Thanks for the info @bitgrower
CamperBot
@camperbot
Feb 15 2016 07:10 UTC
theosarran sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 533 | @bitgrower | http://www.freecodecamp.com/bitgrower
Abhishek Kumar
@abhishekKumar1
Feb 15 2016 07:10 UTC
@chandra90 your myVar is doing nothing to the input "celsius" check your formula
bitgrower
@bitgrower
Feb 15 2016 07:10 UTC
I would say you are doing very well if you are already attacking Seek and Destroy ...
Marina
@chandra90
Feb 15 2016 07:10 UTC
@wearenotgroot , I know the formula, the problem is to write the algorithm
greg
@wearenotgroot
Feb 15 2016 07:11 UTC
@chandra90 same as the formula
@chandra90 you just forgot to multiply the celsius
bitgrower
@bitgrower
Feb 15 2016 07:11 UTC
@chandra90 -- keep an eye on all the variables you are using, and arguments that are passed in, and make sure they are doing what you expect!
Abhishek Kumar
@abhishekKumar1
Feb 15 2016 07:11 UTC
@Casadaro it will be complicated for switch because there are two things to check value and prop
bitgrower
@bitgrower
Feb 15 2016 07:11 UTC
err...make you you are using them in ways you think you are ... :)
Markus Kiili
@Masd925
Feb 15 2016 07:12 UTC
@TheoSarran You can do it without adding new parameters to the function.
greg
@wearenotgroot
Feb 15 2016 07:12 UTC
@coderNoob try it and see what happens :smile:
George Armstrong
@george-of-croton
Feb 15 2016 07:12 UTC

function lookUp(firstName, prop){
for (var i = 0; i < contacts.length; i++){

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

}


}

// Only change code below this line

// Only change code above this line
}

// Change these values to test your function
lookUp("Kristian", "lastName");

bitgrower
@bitgrower
Feb 15 2016 07:12 UTC
@coderNoob -- or go check out the MDN page and see what it says .. :)
George Armstrong
@george-of-croton
Feb 15 2016 07:13 UTC
there is something wrong with my else if statement here. it evaluates to true even firstname is equal contacts[i].firstName
greg
@wearenotgroot
Feb 15 2016 07:14 UTC
@george-of-croton remember you have an &&
Sangeetha
@manmarziyan
Feb 15 2016 07:15 UTC
                    I'm working on the simon game. I have an array of divs that need to be clicked, but I want a delay between each click. 

Here is my loop :

for(var i =0; i<sequence.length; i++){
$("#div" +sequence[i]).click();
}

I tried using setTimeOut, but I can't call functions inside loops. How do I do it?

I'm working on the simon game. I have an array of divs that need to be clicked, but I want a delay between each click. Here is my loop :

for(var i =0; i<sequence.length; i++){
$("#div" +sequence[i]).click();
}

I tried using setTimeOut, but I can't call functions inside loops. How do I do it?

casadaro
@Casadaro
Feb 15 2016 07:16 UTC
@abhishekKumar1 looking at it, I felt like all he if statements were a hack job and was wondering if their might be a better way.
Sangeetha
@manmarziyan
Feb 15 2016 07:16 UTC
(argh sorry about the format. )
George Armstrong
@george-of-croton
Feb 15 2016 07:17 UTC
@wearenotgroot does that affect how i should write my else if statement?
greg
@wearenotgroot
Feb 15 2016 07:18 UTC
@george-of-croton just remember it will evaluate both
uriznik
@uriznik
Feb 15 2016 07:18 UTC
@george-of-croton how many different things does your function return and does that match the specs?
greg
@wearenotgroot
Feb 15 2016 07:18 UTC
@george-of-croton also use strict mode comparison 3 equals ===
casadaro
@Casadaro
Feb 15 2016 07:18 UTC
@wearenotgroot I just completed the music collection today. I used a series of if statments. is there a better way to write it? ```
function update(id, prop, value) {
  if(value !== "" && prop !== "tracks") {
    collection[id][prop] = value;
  }

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

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

  return collection;
}
Marina
@chandra90
Feb 15 2016 07:19 UTC
I still do not understand
myVar= fahrenheit;
myVar=*9/5+32;
`
greg
@wearenotgroot
Feb 15 2016 07:19 UTC
@Casadaro looks fine!
@Casadaro you can restructure the if statement if you like
@chandra90 ---------formula ------->T(°F) = T(°C) × 9/5 + 32
myVar=*9/5+32; //<------------where is the celsius?
George Armstrong
@george-of-croton
Feb 15 2016 07:21 UTC
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 lookUp(firstName, prop){
  for (var i = 0; i < contacts.length; i++){

  if ((firstName === contacts[i].firstName) && (contacts[i].hasOwnProperty(prop))){
    return contacts[i][prop];
  }
    else if( firstName !==  contacts[i].firstName) {
      return firstName
;


    }


    }



// Only change code below this line

// Only change code above this line
}

// Change these values to test your function
lookUp("Kristian", "lastNa
Marina
@chandra90
Feb 15 2016 07:22 UTC
@wearenotgroot I got it , but how ro add C in the formula?
greg
@wearenotgroot
Feb 15 2016 07:22 UTC
@chandra90 look at the code where do you see a variable/parameter named celsius?
@chandra90 -------->convert(celsius)<-------------------------- use that
Ankit Panwar
@coderNoob
Feb 15 2016 07:24 UTC
@wearenotgroot Thanks. Apparently it returns the original array as it is.
CamperBot
@camperbot
Feb 15 2016 07:24 UTC
codernoob sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 848 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
George Armstrong
@george-of-croton
Feb 15 2016 07:24 UTC
something about my else if statement is causing it to evaluate as true when firstname === contacts name...
greg
@wearenotgroot
Feb 15 2016 07:25 UTC
@coderNoob yes. because it has nothing to work on :smile:
uriznik
@uriznik
Feb 15 2016 07:25 UTC
@chandra90 are you not sure how variables are used in expressions/calculations?
Marina
@chandra90
Feb 15 2016 07:25 UTC
@wearenotgroot So, I need to use convert(celsius) instead of my var bla bla?
Yuvraj Adagale
@Yuvraj1989
Feb 15 2016 07:25 UTC
hey finally I got the trick for the Counting Cards
greg
@wearenotgroot
Feb 15 2016 07:25 UTC
@chandra90 you can store the result on myVar
@chandra90 you just need to complete the formula
@chandra90 the thing you are trying to convert is store in celsius which is the function parameter
@chandra90 the value of celsius is pass on to the function call when ----------->convert(6)------>convert(celsius)---------------> myVar = celsius * 9/5 +32
@chandra90 makes sense?
casadaro
@Casadaro
Feb 15 2016 07:30 UTC
thanks @wearenotgroot im sure the further I get the worse my previous code is good to look.
CamperBot
@camperbot
Feb 15 2016 07:30 UTC
casadaro sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 849 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
George Armstrong
@george-of-croton
Feb 15 2016 07:31 UTC
function lookUp(firstName, prop){
  for (var i = 0; i < contacts.length; i++){

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

    }



    }
greg
@wearenotgroot
Feb 15 2016 07:32 UTC
@george-of-croton yes that is the most simply and trickiest part to understand for most people
@george-of-croton ok lets take an example
@george-of-croton here is our array
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"]
    },
];
@george-of-croton now say you are looking for the firstName equal "Harry"
@george-of-croton when the for loop gets going
@george-of-croton then the first if statement gets execute--------->
 if (firstName === contacts[i].firstName && (contacts[i].hasOwnProperty(prop))){
    return contacts[i][prop];
      }
@george-of-croton it will result to false
@george-of-croton then it move to the second test the else if
else if (firstName !== contacts.firstName) {
      return "No such contact";

    }
@george-of-croton what do you think happens next?
@george-of-croton any clue?
George Armstrong
@george-of-croton
Feb 15 2016 07:36 UTC
wait wouldnt the if statement result to true if we searched harry because harry is a contact?
Marina
@chandra90
Feb 15 2016 07:36 UTC
var celcius=(30);  
function farenhight(celcius ) {
var farenheight =celsius * 9/5 +32};
check please
greg
@wearenotgroot
Feb 15 2016 07:37 UTC
@george-of-croton well it will be false because Akira is first on the list
@george-of-croton but yes Harry is in the list so it should be true
George Armstrong
@george-of-croton
Feb 15 2016 07:37 UTC
oh okay then it will return no such contact
greg
@wearenotgroot
Feb 15 2016 07:37 UTC
@george-of-croton yep, and why is that bad?
uriznik
@uriznik
Feb 15 2016 07:38 UTC
@chandra90 what does that function return?
George Armstrong
@george-of-croton
Feb 15 2016 07:38 UTC
because harry is a contact...
greg
@wearenotgroot
Feb 15 2016 07:39 UTC
@chandra90 the formula is now correct however you dont have to have another function
@george-of-croton what happens is because of the return key word
@george-of-croton the loops stop/break and the function exits
@george-of-croton so we cannot complete the search
@george-of-croton now, how can we fix this?
George Armstrong
@george-of-croton
Feb 15 2016 07:41 UTC
@wearenotgroot hmmmm...
@wearenotgroot i could change the value of firstName instead of returning a string?
greg
@wearenotgroot
Feb 15 2016 07:43 UTC
@george-of-croton not necessay
@george-of-croton there is much simplier approach
@george-of-croton simple solution is to not check it at all
@george-of-croton remove that else if statement
@george-of-croton and move the return "No such contact" elsewhere
@george-of-croton but where? that is the question
Abhishek Kumar
@abhishekKumar1
Feb 15 2016 07:44 UTC
@Casadaro try if , else if and else
greg
@wearenotgroot
Feb 15 2016 07:45 UTC
@george-of-croton how can we make sure the the loop continues/ finishes when the first if test turns to be false on every iteration
@george-of-croton this is our loop right now
for (var i = 0; i < contacts.length; i++){

  if (firstName === contacts[i].firstName && (contacts[i].hasOwnProperty(prop))){
    return contacts[i][prop];
      }
    else if (firstName !== contacts.firstName) { //<--------------------if we remove this the loop continues if the first if test is false
      return "No such contact"; //<---------------where to move this??

    }



    }
George Armstrong
@george-of-croton
Feb 15 2016 07:49 UTC
@wearenotgroot do we make it part of the for loop?
greg
@wearenotgroot
Feb 15 2016 07:49 UTC
@george-of-croton no we want it not to break the loop so we need to move it
Neeraj Lad
@neeraj-lad
Feb 15 2016 07:49 UTC
Hi there!
Is there anyone here who has completed the Weather App project? Need some help
greg
@wearenotgroot
Feb 15 2016 07:50 UTC
@george-of-croton where is the most logical place to put it then? if we want it remove from the loop?
@george-of-croton the answer is outside the loop
George Armstrong
@george-of-croton
Feb 15 2016 07:50 UTC
outside of the loop
greg
@wearenotgroot
Feb 15 2016 07:51 UTC
@george-of-croton :smile: :+1:
@george-of-croton remember the code execute from top to bottom
@george-of-croton so we place it outside the loop after the loop
@george-of-croton that way even if the first if test and any other test is not triggered
@george-of-croton the loop finishes the search
George Armstrong
@george-of-croton
Feb 15 2016 07:52 UTC
@wearenotgroot that makes a lot of sense!
greg
@wearenotgroot
Feb 15 2016 07:52 UTC
@george-of-croton then we eliminate any doubt that there isnt a contact with the given firstname
George Armstrong
@george-of-croton
Feb 15 2016 07:52 UTC
@wearenotgroot thank you!
CamperBot
@camperbot
Feb 15 2016 07:52 UTC
george-of-croton sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 850 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
greg
@wearenotgroot
Feb 15 2016 07:52 UTC
@george-of-croton YW
George Armstrong
@george-of-croton
Feb 15 2016 07:53 UTC
thank you very much!
Neeraj Lad
@neeraj-lad
Feb 15 2016 07:53 UTC
@wearenotgroot did you complete the Weather project?
greg
@wearenotgroot
Feb 15 2016 07:53 UTC
@george-of-croton remember you still have this ------->If prop does not correspond to any valid properties then return "No such property"
@neeraj-lad yes why
@neeraj-lad also there is a chat for that stuff btw
Mercy Shabusale
@lomu99
Feb 15 2016 07:54 UTC
switch (val) {
case "bob":
answer="Marley";
break;
case 42:
answer="The Answer";
break;
case 1:
answer="There is a no #1";
break;
case 99:
answer="Missed me by this much!";
break;
case 7:
answer="Ate Nine";
break;
replacing if/if else...all tests pass except case 1,can anybody help me out?
Neeraj Lad
@neeraj-lad
Feb 15 2016 07:54 UTC
@wearenotgroot thanks! but I was facing issues with Mixed content requests over chrome.
CamperBot
@camperbot
Feb 15 2016 07:54 UTC
neeraj-lad sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 851 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
greg
@wearenotgroot
Feb 15 2016 07:55 UTC
@neeraj-lad yep chrome has stricter check than other browsers
Neeraj Lad
@neeraj-lad
Feb 15 2016 07:55 UTC
@wearenotgroot how did you handle http access to open weather api, from codpen which is https? I found a workaround using background pages, but it seemed a bit complex.
greg
@wearenotgroot
Feb 15 2016 07:56 UTC
@neeraj-lad what is the url you using
uriznik
@uriznik
Feb 15 2016 07:56 UTC
@lomu99 does what you're setting answer to exactly match what the challenge asks for?
greg
@wearenotgroot
Feb 15 2016 07:56 UTC
@neeraj-lad link the codepen
greg
@wearenotgroot
Feb 15 2016 07:57 UTC
@neeraj-lad have you tried with http in front
Mercy Shabusale
@lomu99
Feb 15 2016 07:57 UTC
@uriznik yes, i think so
Neeraj Lad
@neeraj-lad
Feb 15 2016 07:57 UTC
@wearenotgroot yes.. didn't solve it. Tried https, but api call was unsuccessful
greg
@wearenotgroot
Feb 15 2016 07:58 UTC
@neeraj-lad ok linked the project then
greg
@wearenotgroot
Feb 15 2016 08:00 UTC
@neeraj-lad you can either try jsonp
@neeraj-lad
"http://api.openweathermap.org/data/2.5/weather?callback=?lat=" + Math.round(latitude) + "&lon=" + Math.round(longitude) + "&appid=44db6a862fba0b067b1930da0d769e98";
@neeraj-lad by adding ?callback=?
Neeraj Lad
@neeraj-lad
Feb 15 2016 08:01 UTC
@wearenotgroot sorry.. didn't get that
greg
@wearenotgroot
Feb 15 2016 08:02 UTC
@neeraj-lad look at that url and what you have right now
George Armstrong
@george-of-croton
Feb 15 2016 08:02 UTC
@wearenotgroot i need to add one more if statement in that exercise but again im returning the presult of the previous if statement...
greg
@wearenotgroot
Feb 15 2016 08:02 UTC

@neeraj-lad this part

"http://api.openweathermap.org/data/2.5/weather?callback=?lat="

vs

"http://api.openweathermap.org/data/2.5/weather?lat="
@neeraj-lad by adding the callback=? you are saying that the request is jsonp
@neeraj-lad that will solve your problem
Neeraj Lad
@neeraj-lad
Feb 15 2016 08:04 UTC
@wearenotgroot I got this:
{"cod":"404","message":"Error: Not found city"}
greg
@wearenotgroot
Feb 15 2016 08:04 UTC
@neeraj-lad yes beacuse it cannot find the location you are after
uriznik
@uriznik
Feb 15 2016 08:05 UTC
@lomu99 check down the bottom left for what each test expects
greg
@wearenotgroot
Feb 15 2016 08:05 UTC
@neeraj-lad also remember there is a delay on the getCurrentPosition
Neeraj Lad
@neeraj-lad
Feb 15 2016 08:06 UTC
@wearenotgroot I put the lat & lon values.. shouldn't it find the location then?
greg
@wearenotgroot
Feb 15 2016 08:10 UTC
@neeraj-lad i see the problem
@neeraj-lad dont use Math.round
Neeraj Lad
@neeraj-lad
Feb 15 2016 08:11 UTC
@wearenotgroot did you not face mixed content issues? I got them on firefox too.
greg
@wearenotgroot
Feb 15 2016 08:11 UTC
@neeraj-lad it chopps off some decimal so it cant pin point exact where you are
Neeraj Lad
@neeraj-lad
Feb 15 2016 08:12 UTC
@wearenotgroot maybe..
George Armstrong
@george-of-croton
Feb 15 2016 08:12 UTC
    }
 if ( firstName !== contacts.firstName ){
   result = "No such contact";
 }
   else if (prop !== contacts[prop] ){
     result = "No such property";
   }
this is not working for me
greg
@wearenotgroot
Feb 15 2016 08:13 UTC
@neeraj-lad hmm working on my end
@neeraj-lad even without the callback=?
Neeraj Lad
@neeraj-lad
Feb 15 2016 08:13 UTC
@wearenotgroot sorry?
greg
@wearenotgroot
Feb 15 2016 08:14 UTC
@neeraj-lad only used this
var latitude = position.coords.latitude;
    var longitude = position.coords.longitude;
    openWeatherURL += "http://api.openweathermap.org/data/2.5/weather?lat=" + latitude + "&lon=" + longitude + "&appid=44db6a862fba0b067b1930da0d769e98";
@neeraj-lad and it work
Neeraj Lad
@neeraj-lad
Feb 15 2016 08:15 UTC
@wearenotgroot yeah.. but adding 'callback=?' after 'weather?' doesn't work somehow
@wearenotgroot I guess, I'll try some other api then.. which offers https calls
uriznik
@uriznik
Feb 15 2016 08:16 UTC
@george-of-croton if you're looking for harry and the first contact is alice what happens?
greg
@wearenotgroot
Feb 15 2016 08:16 UTC
@neeraj-lad ok try this
$(document).ready(function () {

  var openWeatherURL = "";


  if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(function(position) {
    console.log(position);
    var latitude = position.coords.latitude;
    var longitude = position.coords.longitude;
    openWeatherURL = "http://api.openweathermap.org/data/2.5/weather?callback=?";

    $.getJSON(openWeatherURL,{lat:latitude,lon:longitude, APPID:'44db6a862fba0b067b1930da0d769e98'}, function(json){
          console.log(json);
        var city = json["name"];
        var country = json["sys"]["country"];
        var location = city + ", " + country;

        var weatherDesc = json["weather"][0]["description"];

        var windSpeed = json["wind"]["speed"];

        $(".location").html("<h3>" + location + "</h3>");   
        $(".weather-desc").html("<h3>" + weatherDesc + "</h3>");
        $(".wind-speed").html("<h3>" + windSpeed + " meter/sec</h3>");

    }); //end getJSON  


  }); //end navigator.geolocation if clause
}

}); //end document ready
@neeraj-lad you can add an object that contains the url parameter on the getJSON
@neeraj-lad instead of adding it to the url it self
Neeraj Lad
@neeraj-lad
Feb 15 2016 08:18 UTC
@wearenotgroot didn't help :(
greg
@wearenotgroot
Feb 15 2016 08:18 UTC
@neeraj-lad that way you can just add a base url which is much cleaner and gives you more controll
George Armstrong
@george-of-croton
Feb 15 2016 08:19 UTC
@uriznik it returns alice
greg
@wearenotgroot
Feb 15 2016 08:19 UTC
@neeraj-lad it works even in firefox
uriznik
@uriznik
Feb 15 2016 08:20 UTC
@george-of-croton is that snippet in or outside the for loop?
Neeraj Lad
@neeraj-lad
Feb 15 2016 08:20 UTC
@wearenotgroot strange.. it didn't work for me
greg
@wearenotgroot
Feb 15 2016 08:20 UTC
@neeraj-lad what error you getting?
George Armstrong
@george-of-croton
Feb 15 2016 08:20 UTC
@uriznik outside
greg
@wearenotgroot
Feb 15 2016 08:20 UTC
@neeraj-lad and did you allow the geolocate on you browser?
Neeraj Lad
@neeraj-lad
Feb 15 2016 08:21 UTC
@wearenotgroot same one.. Mixed Content. Yes, I enabled it.
greg
@wearenotgroot
Feb 15 2016 08:22 UTC
@neeraj-lad and you copied exactly the code above?
kirbyedy
@kirbyedy
Feb 15 2016 08:22 UTC
it should work, I just tried it
stupid question, do you have jquery embedded ?
uriznik
@uriznik
Feb 15 2016 08:23 UTC
@george-of-croton what happens if you look for harry and a property of 'pizza'?
Neeraj Lad
@neeraj-lad
Feb 15 2016 08:23 UTC
@wearenotgroot yes, I replaced my js code with yours, saved it, and refreshed the page.
a9eel
@a9eell12
Feb 15 2016 08:23 UTC
need help
greg
@wearenotgroot
Feb 15 2016 08:24 UTC
@neeraj-lad i refeshing it and it havent change
George Armstrong
@george-of-croton
Feb 15 2016 08:24 UTC
@ it returns "no such contact"
@uriznik it returns "no such contact"
uriznik
@uriznik
Feb 15 2016 08:25 UTC
@george-of-croton can you paste the whole function
Neeraj Lad
@neeraj-lad
Feb 15 2016 08:25 UTC
@wearenotgroot I undid the change, after it didn't work. I'll change it again now.
@wearenotgroot do you see the changed js code?
greg
@wearenotgroot
Feb 15 2016 08:26 UTC
@neeraj-lad yep i see it
@neeraj-lad it works
George Armstrong
@george-of-croton
Feb 15 2016 08:26 UTC
function lookUp(firstName, prop){
  for (var i = 0; i < contacts.length; i++){

  if (firstName === contacts[i].firstName && (contacts[i].hasOwnProperty(prop))){
   return contacts[i][prop];
      }




    }
 if ( firstName !== contacts.firstName ){
   result = "No such contact";
 }
   else if (!contacts.hasOwnProperty(prop) ){
     result = "No such property";
   }






  return result;







// Only change code below this line

// Only change code above this line
}

// Change these values to test your function
lookUp("Harry", "address");
Neeraj Lad
@neeraj-lad
Feb 15 2016 08:27 UTC
@wearenotgroot
Mixed Content: The page at 'https://s.codepen.io/neeraj-lad/fullpage/dGadyX?' was loaded over HTTPS, but requested an insecure script 'http://api.openweathermap.org/data/2.5/weather?callback=jQuery2130792804101…2002&lon=73.0437446&APPID=44db6a862fba0b067b1930da0d769e98&_=1455524804055'. This request has been blocked; the content must be served over HTTPS.
greg
@wearenotgroot
Feb 15 2016 08:27 UTC
@neeraj-lad ok you are using https
@neeraj-lad change the http to be https then
@neeraj-lad same code but use https
@neeraj-lad
@neeraj-lad because the browser sees to different header info so that is why it is throwing this error
uriznik
@uriznik
Feb 15 2016 08:30 UTC
@george-of-croton ok so you're looping through looking for harry and a prop 'pizza' and it goes through the loop - what happens next?
greg
@wearenotgroot
Feb 15 2016 08:30 UTC
@neeraj-lad ok if it still persist
@neeraj-lad then add this to the url for the query
@neeraj-lad add this in front of the ---->openWeatherURL, this ----->https://crossorigin.me/
@neeraj-lad should look like this
openWeatherURL = "https://crossorigin.me/http://api.openweathermap.org/data/2.5/weather?callback=?";
Neeraj Lad
@neeraj-lad
Feb 15 2016 08:33 UTC
@wearenotgroot Found the issue at last!
greg
@wearenotgroot
Feb 15 2016 08:33 UTC
@neeraj-lad which was?
George Armstrong
@george-of-croton
Feb 15 2016 08:34 UTC
@uriznik the the code says if harry is not in the function return "no such contact"
Neeraj Lad
@neeraj-lad
Feb 15 2016 08:34 UTC
@wearenotgroot I have https everywhere extension enabled. It might be changing http://codepen.io/neeraj-lad/full/dGadyX/ to codepen.io/neeraj-lad/full/dGadyX/
@wearenotgroot so silly of me!
George Armstrong
@george-of-croton
Feb 15 2016 08:34 UTC
@uriznik but harry is in the the function and i want i to run the else statement on pizza
greg
@wearenotgroot
Feb 15 2016 08:34 UTC
@neeraj-lad :smile:
Neeraj Lad
@neeraj-lad
Feb 15 2016 08:34 UTC
@wearenotgroot thanks a ton for your help! :D
CamperBot
@camperbot
Feb 15 2016 08:34 UTC
neeraj-lad sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:warning: neeraj-lad already gave wearenotgroot points
greg
@wearenotgroot
Feb 15 2016 08:34 UTC
@neeraj-lad YW
SuhasHosamani
@SuhasHosamani
Feb 15 2016 08:36 UTC

@wearenotgroot

function palindrome(str) {
  // Good luck!
  var arr = [];
  arr = str.split('');
  arr.reverse();
  revstr = arr.join('');
revstr = revstr.replace(/[,. ]/g, '').toLowerCase();
  str = str.replace(/[,. ]/g, '').toLowerCase();
  if(revstr === str){
    return true;
  }else{
    return false;
  }

}
palindrome("0_0 (: /-\ :) 0-0");

this last string is failing

greg
@wearenotgroot
Feb 15 2016 08:36 UTC
@SuhasHosamani yes
@SuhasHosamani here is the thing to consider----> most people doesnt know that underscore is considered an alphanummeric
@SuhasHosamani so you have to filter it out separately
SuhasHosamani
@SuhasHosamani
Feb 15 2016 08:38 UTC
@wearenotgroot how?
greg
@wearenotgroot
Feb 15 2016 08:38 UTC
@SuhasHosamani another thing consider using \W <----------------- will take care of all non-word characters
@SuhasHosamani add _ in the regex
George Armstrong
@george-of-croton
Feb 15 2016 08:39 UTC
   }
 if ( firstName !== contacts.firstName ){
   result = "No such contact";
 }



else  if (prop !== contacts.hasOwnProperty(prop) ){
     result = "No such property";
   }
i cannot get this bottom part to return correctly
greg
@wearenotgroot
Feb 15 2016 08:39 UTC
@SuhasHosamani go practice ---->https://regex101.com/
SuhasHosamani
@SuhasHosamani
Feb 15 2016 08:40 UTC
@wearenotgroot :smile: :+1:
greg
@wearenotgroot
Feb 15 2016 08:40 UTC
@george-of-croton hmm didnt we cover the second if last time?
@george-of-croton you only need to have return "No such contact" outside the loop and near the lass } of the function
@george-of-croton like that

function lookUp(firstName, prop){
  for (var i = 0; i < contacts.length; i++){

    if (firstName === contacts[i].firstName && (contacts[i].hasOwnProperty(prop))){
                      return contacts[i][prop];
      }
      else if (!contacts.hasOwnProperty(prop) ){
                        result = "No such property"; //<----------this part you can just return no such property immediately, return "No such property"
     }



  }


  return "No such contact";

// Only change code above this line
}
uriznik
@uriznik
Feb 15 2016 08:45 UTC
@george-of-croton you can also replace an if(a == something && b = 4) { .. } with a nested if ( a ...) { if (b ...) {...} ... and it could make the code clearer
SuhasHosamani
@SuhasHosamani
Feb 15 2016 08:46 UTC

@wearenotgroot

revstr = revstr.replace(/[,._ ]/g, '').toLowerCase();
  str = str.replace(/[,._ ]/g, '').toLowerCase();

not working

greg
@wearenotgroot
Feb 15 2016 08:48 UTC
@SuhasHosamani as I said try \W bcoz this will take care of any non-word characters.
[\W_]
@SuhasHosamani another thing is try to use toLowerCase then replace then split then reverse then join
SuhasHosamani
@SuhasHosamani
Feb 15 2016 08:50 UTC
@wearenotgroot oh ok i'l try
@wearenotgroot Bingo tat worked
greg
@wearenotgroot
Feb 15 2016 08:51 UTC
@SuhasHosamani :+1:
@george-of-croton so how did it went?
a9eel
@a9eell12
Feb 15 2016 08:58 UTC
please help !!
Hananel Gez
@WebDevPr0
Feb 15 2016 09:18 UTC
What I missing here?
Convert the switch statement into a lookup table called lookup. Use it to lookup val and assign the associated string to the result variable.
// 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");
@mossandboar Do you still need help with the testObj question?
Abhishek Kumar
@abhishekKumar1
Feb 15 2016 09:30 UTC
@WebDevPr0 Try " " in names too like "alpha":"Adams"
and so on for bravo, charlie...
srinivas
@srinivasdasu
Feb 15 2016 09:31 UTC
can anyone help me on arguments optiona;
l
?
Yuvraj Adagale
@Yuvraj1989
Feb 15 2016 09:34 UTC

' ' '
var count = 0;

function cc(card) {
// Only change code below this line
switch(card){
case 2:
count+=1;
return count + " Bet";
case 3:
count+=1;
return count+" Bet";
case 4:
count+=1;
return count+" Bet";
case 5:
count+=1;
return count+" Bet";
case 6:
count+=1;
return count+" Bet";
case 7:
count=0;
return count+"Bet";
case 8:
count=0;
return count+"Bet";
case 9:
count=0;
return count+" Bet";
case 'K':
count-=1;
return count+" Bet";
case 'J':
count-=1;
return count+" Bet";
case 'Q':
count-=1;
return count+" Bet";
case 'A':
count-=1;
return count+" Bet";
}
return "Change Me";
// Only change code above this line
}

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

Abhishek Kumar
@abhishekKumar1
Feb 15 2016 09:35 UTC
@Yuvraj1989 u havn't used the break; statement anywhere
and please if you have similar cases don't repeat them.
Yuvraj Adagale
@Yuvraj1989
Feb 15 2016 09:41 UTC
@abhishekKumar1 I think if you are using return in function, you cannot use break;
keRee
@keRee
Feb 15 2016 09:43 UTC
hello @all
Abhishek Kumar
@abhishekKumar1