These are chat archives for FreeCodeCamp/HelpJavaScript

23rd
Apr 2016
CaffeineQueen
@CaffeineQueen
Apr 23 2016 00:00
like a blind donkey in a china shop. ;)
llamatarianism
@llamatarianism
Apr 23 2016 00:00
ok just
replace all of that business, including the other loop, with something like this
Stephen James
@sjames1958gm
Apr 23 2016 00:01
@CaffeineQueen Write a function that return true/false if a number is prime and then call it inside this for loop
llamatarianism
@llamatarianism
Apr 23 2016 00:01
for (var i = 3; i < num; i += 2)
if (num % i === 0) /* then num isn't prime. */
Emma Cooper
@199coopere
Apr 23 2016 00:02
hey guys I don't know what these challenge instructions mean
llamatarianism
@llamatarianism
Apr 23 2016 00:03
it's brute-forcey and inelegant but shrug
Emma Cooper
@199coopere
Apr 23 2016 00:03
"Encode the following sequence, separated by spaces:
backslash tab tab carriage-return new-line and assign it to myStr"
Stephen James
@sjames1958gm
Apr 23 2016 00:03
@llamatarianism You can stop at Maths.sqrt(num)
llamatarianism
@llamatarianism
Apr 23 2016 00:03
@sjames1958gm ...huh, you can
TIL, thanks @sjames1958gm
CamperBot
@camperbot
Apr 23 2016 00:04
llamatarianism sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 762 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Luke
@lhovee
Apr 23 2016 00:04
function chunkArrayInGroups(arr, size) {
  // Break it up.

  for (var i=1; i<arr.length; i++) {return arr.slice(0, size*i);}

}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
I'm not sure what to do next. This just returns an array of ["a", "b"]. help please
Emma Cooper
@199coopere
Apr 23 2016 00:04
anyone know what to do
llamatarianism
@llamatarianism
Apr 23 2016 00:05
@lhovee that's because you're returning inside the loop
when you return, the entire function ends, so it never moves onto the next stage of the loop
Stephen James
@sjames1958gm
Apr 23 2016 00:06
@199coopere Use the table on the left an make a string replacing the words in the description with the special chars.
llamatarianism
@llamatarianism
Apr 23 2016 00:06
create a new array outside that loop, and PUSH slices of arr into it
Emma Cooper
@199coopere
Apr 23 2016 00:06
var myStr="// /t /t /r /n"
Luke
@lhovee
Apr 23 2016 00:06
@llamatarianism I see! What should go inside the for loop? Taking the arr.slice outside is easy but I assume I still need the loop right?
Emma Cooper
@199coopere
Apr 23 2016 00:06
like that? @sjames1958gm
Stephen James
@sjames1958gm
Apr 23 2016 00:06
@199coopere You are leaning the wrong way
Emma Cooper
@199coopere
Apr 23 2016 00:06
BLAST
Donkey butt nugget
llamatarianism
@llamatarianism
Apr 23 2016 00:07
@lhovee you still need the slice inside the loop
Emma Cooper
@199coopere
Apr 23 2016 00:07
thank you very much
llamatarianism
@llamatarianism
Apr 23 2016 00:07
but rather than RETURNING that slice, push that slice into an array
Stephen James
@sjames1958gm
Apr 23 2016 00:07
@lhovee slice off array values until the array length is less than size and add any left over.
llamatarianism
@llamatarianism
Apr 23 2016 00:07
then after your loop, return that array
Emma Cooper
@199coopere
Apr 23 2016 00:07
ty @sjames1958gm
RJsauce
@RJsauce
Apr 23 2016 00:07
Hey guys, I don't understand how to do the Word Blanks challenge. Can you help?
Stephen James
@sjames1958gm
Apr 23 2016 00:07
@199coopere :+1:
Emma Cooper
@199coopere
Apr 23 2016 00:07
thank you @sjames1958gm
CamperBot
@camperbot
Apr 23 2016 00:07
199coopere sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 763 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Emma Cooper
@199coopere
Apr 23 2016 00:08
there we go
Stephen James
@sjames1958gm
Apr 23 2016 00:08
@lhovee I would use a while loop for that challenge
Emma Cooper
@199coopere
Apr 23 2016 00:08
@RJsauce can you describe the instructions or copy paste them
Stephen James
@sjames1958gm
Apr 23 2016 00:08
@199coopere Its the mad lib one.
llamatarianism
@llamatarianism
Apr 23 2016 00:08
also you should be slicing from (size * (i - 1))
Emma Cooper
@199coopere
Apr 23 2016 00:08
haven't got there
cya
CaffeineQueen
@CaffeineQueen
Apr 23 2016 00:09
function sumPrimes(num) {


  var nlist=[];
var testnum = [];


for (var i = 3; i < num; i += 2){
  if (num % i === 0);}
    nlist.push(i);




  return nlist.reduce(function(a, b) {
  return a + b;
});}


sumPrimes(977);
llamatarianism
@llamatarianism
Apr 23 2016 00:09
personally I'd use tail call recursion
CaffeineQueen
@CaffeineQueen
Apr 23 2016 00:09
It just returns 977 back at me
Stephen James
@sjames1958gm
Apr 23 2016 00:09
while (arr.length >= size) { chop size off and push } if any left push that too
llamatarianism
@llamatarianism
Apr 23 2016 00:10
@CaffeineQueen your } is in the wrong place
CaffeineQueen
@CaffeineQueen
Apr 23 2016 00:10
It always is
llamatarianism
@llamatarianism
Apr 23 2016 00:10
you've got ;} after your if
RJsauce
@RJsauce
Apr 23 2016 00:10
Nevermind
llamatarianism
@llamatarianism
Apr 23 2016 00:10
which is breaking it
also
you're pushing NON primes to nList.
CaffeineQueen
@CaffeineQueen
Apr 23 2016 00:11
well, now I'm getting a different number, lol
llamatarianism
@llamatarianism
Apr 23 2016 00:11
wait a minute
are you trying to sum all primes UP TO a number?
CaffeineQueen
@CaffeineQueen
Apr 23 2016 00:12
yes
llamatarianism
@llamatarianism
Apr 23 2016 00:12
oh whoops, in that case you'll need to make some changes
CaffeineQueen @CaffeineQueen falls on the floor
Matt Green
@mattxgreen
Apr 23 2016 00:12
@CaffeineQueen it looks like your prime test isn't checking for even nums
llamatarianism
@llamatarianism
Apr 23 2016 00:12
:P
CaffeineQueen
@CaffeineQueen
Apr 23 2016 00:12
it was originally, haha
Ian Smith
@TOAOIanSmith
Apr 23 2016 00:13
in Falsy Bouncer, how do I check if NaN == NaN when that expression is false?
Stephen James
@sjames1958gm
Apr 23 2016 00:13
@CaffeineQueen well other than 2 it shouldn't need to
@TOAOIanSmith value != value is true if value is NaN
llamatarianism
@llamatarianism
Apr 23 2016 00:13
@TOAOIanSmith what do you mean, check if NaN is NaN?
Ian Smith
@TOAOIanSmith
Apr 23 2016 00:14
yeah
llamatarianism
@llamatarianism
Apr 23 2016 00:14
I was asking what you meant, not if you meant that.
I'm not sure exactly what you're asking.
Ian Smith
@TOAOIanSmith
Apr 23 2016 00:15
I have an array, My array has NaN in it. I need to filter() out array... NaN ==
Stephen James
@sjames1958gm
Apr 23 2016 00:15
@llamatarianism Its the falsey challenge
Ian Smith
@TOAOIanSmith
Apr 23 2016 00:15
NaN == NaN returns false
Making it impossible
Luke
@lhovee
Apr 23 2016 00:15
@llamatarianism I know this code is way off but it'll show you where I'm at ... which is kinda lost
function chunkArrayInGroups(arr, size) {
  // Break it up.
  var newArr = arr.slice(0, size);
  for (var i=0; i<arr.length; i++) {return newArr.push(arr.slice(0, size(i-1)));}

}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
Ian Smith
@TOAOIanSmith
Apr 23 2016 00:15
check if NaN is NaN? "yeah"
llamatarianism
@llamatarianism
Apr 23 2016 00:15
wouldn't isNaN() still work?
Ian Smith
@TOAOIanSmith
Apr 23 2016 00:15
No, because my strings don't pass that test
I need to keep strings as well
Well maybe not... Alright. NVM. Apparently the challenge doesn't put strings in, so I just have to compensate. TY
Stephen James
@sjames1958gm
Apr 23 2016 00:17
@TOAOIanSmith You have to have separate tests for each of the cases
llamatarianism
@llamatarianism
Apr 23 2016 00:17
NaN is falsy isn't it?
d wilder
@alhazen1
Apr 23 2016 00:17
@TOAOIanSmith Test for 'falseness'. Anything that is not false stays in the array
Stephen James
@sjames1958gm
Apr 23 2016 00:17
if !null else if !undefined else if value == value
Nan is the only value that wont pass value === value
@CaffeineQueen Write a function that tests a value for primeness. Then in your main function loop from 2 -> num and for those that are prime add to a running total that you initialize to zero
Stephen James
@sjames1958gm
Apr 23 2016 00:23
@TOAOIanSmith It can come down to a single if / else
Matt Green
@mattxgreen
Apr 23 2016 00:23
@CaffeineQueen What people are suggesting will work, but there are much better (more efficient) ways to find all the primes below a certain number. I suggest a Seive of Eratostanes https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
Ian Smith
@TOAOIanSmith
Apr 23 2016 00:23
function isFalse(val){
  var notAllowed = [false, null, 0, "", undefined, NaN];
  for(var i = 0; i < notAllowed.length; i++){
        //console.log(notAllowed[i]);
    if(val == notAllowed[i]) return false;
  }
    //console.log("t");
  return true;
}

function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  arr = arr.filter(isFalse);
  return arr;
}

retVal = bouncer([false, null, 0, NaN, undefined, ""]);
console.log(retVal);
Alright nvm, not sure how to go from here...
Matt Green
@mattxgreen
Apr 23 2016 00:23
If you want a function to just test for primes, here is one:
function isPrime(value) {
    for (var i = 2, max = Math.sqrt(value); i < max; i++) {
        if (value % i === 0) {
            return false;
        }
    }
    return value > 1;
}
Stephen James
@sjames1958gm
Apr 23 2016 00:24
@TOAOIanSmith Nan wont work
Ian Smith
@TOAOIanSmith
Apr 23 2016 00:25
Exactly, but I have to write code that passes:
bouncer([7, "ate", "", false, 9])
and bouncer([false, null, 0, NaN, undefined, ""])
krisluu5695
@krisluu5695
Apr 23 2016 00:25
function sequentialSizes(val) {
  var answer = "";
  // Only change code below this line
  switch(val) {
    case 1:
    case 2:
    case 3:
      answer = "Low";
      break;
    case 4:
    case 5:
    case 6:
      answer = "Mid";
      break;
    case 7:
    case 8:
    case 9:
      answer = "High";
      break;
    default:
      answer = "Not in case";
  }


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

// Change this value to test
sequentialSizes(5);
the question told me to have nine case statements ?
Stephen James
@sjames1958gm
Apr 23 2016 00:26
@TOAOIanSmith So you are using filter and what does that do?
krisluu5695
@krisluu5695
Apr 23 2016 00:26
isnt this wrong ?
Ian Smith
@TOAOIanSmith
Apr 23 2016 00:26
it filters based on whether or not its argument returns true
Stephen James
@sjames1958gm
Apr 23 2016 00:27
@TOAOIanSmith So if the function returns false it drops the value?
Ian Smith
@TOAOIanSmith
Apr 23 2016 00:27
Correct
krisluu5695
@krisluu5695
Apr 23 2016 00:28
can someone help me i got a problem ?..... ty
Ian Smith
@TOAOIanSmith
Apr 23 2016 00:28
And I'm having trouble because to use isNaN() I have to use it on all of my values, but it will return false for strings
Stephen James
@sjames1958gm
Apr 23 2016 00:29
You could add a special check fro NaN - if value != value then it is NaN
Ian Smith
@TOAOIanSmith
Apr 23 2016 00:29
Ahhhh, good thinking! Alright! that should do it! Thanks you @sjames1958gm
CamperBot
@camperbot
Apr 23 2016 00:29
toaoiansmith sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 764 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Apr 23 2016 00:30
@TOAOIanSmith Let me know when you done.
@krisluu5695 Maybe they don't want the default case?
d wilder
@alhazen1
Apr 23 2016 00:30
@TOAOIanSmith why not
if(testArray[i]){
  then this item stays in the array
}else{
  it gets bounced
}
Ian Smith
@TOAOIanSmith
Apr 23 2016 00:31
@sjames1958gm That did the trick :P
Stephen James
@sjames1958gm
Apr 23 2016 00:31
After several refinements this is what I ended up with.
function bouncer(arr) 
{
 return arr.filter(function(value) { return  value; });
}
@TOAOIanSmith The values falseyness filters itself
Luke
@lhovee
Apr 23 2016 00:32
function chunkArrayInGroups(arr, size) {
  // Break it up.
  var newArr = arr.slice(0, size);
  for (var i=0; i<arr.length; i++) {return newArr.push();}

}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
Can anyone help me with this? I'm not sure what to push in the for loop
Stephen James
@sjames1958gm
Apr 23 2016 00:33
@lhovee Instead of counting by one count by size then you can slice(i, i + size - 1);
Micah Bales
@micahbales
Apr 23 2016 00:33
Howdy folks. I'm working on Sum All Odd Fibonacci Numbers (https://www.freecodecamp.com/challenges/sum-all-odd-fibonacci-numbers). My code isn't quite working. Any ideas?
function sumFibs(num) {
  var curnum = 1;
  var prevnum = 1;
  var nextnum = 1;
  var oddnums= 0;
  for (i = 1; i < num; i++) {
    if (nextnum === 1)
      oddnums += nextnum;
    if  (nextnum % 2 !== 0)
      oddnums += nextnum;
    nextnum = prevnum + curnum;
    prevnum = curnum;
    curnum = nextnum;
  }
  return oddnums;
}

sumFibs(1000);
Luke
@lhovee
Apr 23 2016 00:34
@sjames1958gm do I even need the newArr variable outside the loop?
Moisés Man
@moigithub
Apr 23 2016 00:38
@micahbales ur code is generating too much numbers
Kathleen Blount
@ktblount
Apr 23 2016 00:39
Can someone look at my code for Title Case a sentence and send me in the right direction of fixing it? I think I may be grasping at straws...

function titleCase(str) {
var strings = str.toLowerCase();
var lowerCase = str.split(' ');
for (i=0, i<lowerCase.length; i++){

var upperCase = strings.charAt(0).toUpperCase();
str = upperCase;

};
return str;
}

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

Moisés Man
@moigithub
Apr 23 2016 00:40
@micahbales if sumbfibs(144)
it should generate this
1,1,2,3,5,8,13,21,34,55,89,144
(NOT 144 numbers)
and from that list.. sum the odds nums
Stacy
@SWilbon
Apr 23 2016 00:41

var a;
var b;
var c;

// Do not change code below this line

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

Initialize the three variables a, b, and c with 5, 10, and "I am a" respectively so that they will not be undefined.
a should be defined and have a value of 6
b should be defined and have a value of 15
c should not contain undefined and should have a value of "I am a String!"
I having a hard time figuring out this
Coy Sanders
@coymeetsworld
Apr 23 2016 00:43
@SWilbon you need to give a b and c initial values
so that those statements are true
Moisés Man
@moigithub
Apr 23 2016 00:43
@ktblount what this code doing ?
var upperCase = strings.charAt(0).toUpperCase();
str = upperCase;
Matthew Fricker
@mattfricker
Apr 23 2016 00:44

@moigithub The first line is accessing the first character of the strings variable and storing its upper case version in the variable upperCase

The second line is storing uppercase in the str variable

Moisés Man
@moigithub
Apr 23 2016 00:44
@mattfricker i know :P
Kathleen Blount
@ktblount
Apr 23 2016 00:44
I want to upper case just the first character of my now array and then change the value but I just realized I need to put my array back into one string, don't I?
Tyler
@tylergross
Apr 23 2016 00:45
@ktblount yes eventually place all back into one string with array.join()
Matthew Fricker
@mattfricker
Apr 23 2016 00:45
@moigithub lol - gotcha, haha.
Stacy
@SWilbon
Apr 23 2016 00:46
@coymeetsworld can you give me an example with the instructions.. I'm still learning JS
Moisés Man
@moigithub
Apr 23 2016 00:46
@ktblount well.. if u call ur function like this.. titleCase("my dog is big");
str variable inside the funciton titleCase will be the string "my dog is big"
ok?
Coy Sanders
@coymeetsworld
Apr 23 2016 00:46

sure if you wanted to give variable a a value of 1 you would do it this way:

var a = 1;

Stacy
@SWilbon
Apr 23 2016 00:46
Instructions
Initialize the three variables a, b, and c with 5, 10, and "I am a" respectively so that they will not be undefined.
Kathleen Blount
@ktblount
Apr 23 2016 00:47
Can I add it to the end of the toUpperCase() or will that not work. I'm really confused to say the least
Stacy
@SWilbon
Apr 23 2016 00:47

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

// Do not change code below this line

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

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

// Do not change code below this line

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

a should be defined and have a value of 6
b should be defined and have a value of 15
c should not contain undefined and should have a value of "I am a String!"
Do not change code below the line
Micah Bales
@micahbales
Apr 23 2016 00:48
@moigithub Thanks. Just realized that I'm doing the problem wrong! :)
CamperBot
@camperbot
Apr 23 2016 00:48
micahbales sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star: 986 | @moigithub | http://www.freecodecamp.com/moigithub
Tyler
@tylergross
Apr 23 2016 00:48
@ktblount you should be able to add it to the end ; however i'm assuming you're using a for loop to return capitalization of the entire array? in this case i would wait til the end to throw it back into a string
Kathleen Blount
@ktblount
Apr 23 2016 00:48
@moigithub yes, I understand that.
Moisés Man
@moigithub
Apr 23 2016 00:48

@ktblount then on ur code u have

var strings = str.toLowerCase();
var lowerCase = str.split(' ');

first line.. convert "my dog is big" to lowercases
second it split that string iby spaces...and turn into an array... storing those values on lowerCase variable
so lowerCase now will be ["my","dog","is","big"]

@ktblount so... what this code is doing ?
for (i=0, i<lowerCase.length; i++){
var upperCase = strings.charAt(0).toUpperCase();
str = upperCase;
};
Coy Sanders
@coymeetsworld
Apr 23 2016 00:50
@SWilbon look at my example but don't initialize a to 1, initialize it so that adding 1 to it makes 5 (i.e. 4)
Moisés Man
@moigithub
Apr 23 2016 00:50
@ktblount iterate on lowerCase array elements...
and... what else ? should it pick data from strings variable???
strings variable = "my dog is big".. from line 2 above
Coy Sanders
@coymeetsworld
Apr 23 2016 00:50
then do the same with how to make b equal to 10, and how to get the string to look like that
Kathleen Blount
@ktblount
Apr 23 2016 00:51
iterating through the arrays to capital the 0 character
Sorry I have a baby climbing all over me while doing this.
Moisés Man
@moigithub
Apr 23 2016 00:53
@ktblount ur current code.. is iterating n times (acording to loweCase array length)
pick the first character of strings which is "my dog is big" (so it pick the "m")
and turn it to upercase
and do the same everytime..
so u get
var upperCase = "M";
str = "M";
var upperCase = "M";
str = "M";
var upperCase = "M";
str = "M";
var upperCase = "M";
str = "M";
var upperCase = "M";
str = "M";
Stacy
@SWilbon
Apr 23 2016 00:53
@coymeetsworld Thanks
CamperBot
@camperbot
Apr 23 2016 00:53
swilbon sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star: 616 | @coymeetsworld | http://www.freecodecamp.com/coymeetsworld
Kathleen Blount
@ktblount
Apr 23 2016 00:53
ok, I'm seeing it now.
I think I'm going to start all over and work it out. Thank you @moigithub
CaffeineQueen
@CaffeineQueen
Apr 23 2016 00:55
I'm still really really stuck
Bruno
@bbologna
Apr 23 2016 00:56
@CaffeineQueen what's up?
Moisés Man
@moigithub
Apr 23 2016 00:56
@ktblount instead of strings variable u should use lowerCase variable..the one holding ur words array
CaffeineQueen
@CaffeineQueen
Apr 23 2016 00:56
help sum all primes
CamperBot
@camperbot
Apr 23 2016 00:56

:point_right: algorithm sum all primes [wiki]

Explanation:

The explanation for this problem is very simple. You will generate a list of prime numbers up to the number you are given as a parameter. Then you need to add them all up and return that value. The tricky part is on generating the list of prime numbers. I suggest you find a code or a good math algorithm that you can turn into code.

:pencil: read more about algorithm sum all primes on the FCC Wiki

Moisés Man
@moigithub
Apr 23 2016 00:57
@CaffeineQueen the hardest part on that one..is making an algorithm to check if a number is Prime or not....
CaffeineQueen
@CaffeineQueen
Apr 23 2016 00:57
Going on 12 hours...
Coy Sanders
@coymeetsworld
Apr 23 2016 00:58
@CaffeineQueen what are you having trouble w/?
CaffeineQueen
@CaffeineQueen
Apr 23 2016 00:58
finding the prime numbers
Coy Sanders
@coymeetsworld
Apr 23 2016 00:58
what do you have so far?
Bruno
@bbologna
Apr 23 2016 00:59
So, being prime is just a number that's mod == 0 only when is itself and 1... right?
CaffeineQueen
@CaffeineQueen
Apr 23 2016 01:00
I've written a few dozen versions
Coy Sanders
@coymeetsworld
Apr 23 2016 01:00
yes
well what do you have right now i guess? if you want to share
Moisés Man
@moigithub
Apr 23 2016 01:00
@CaffeineQueen if u readed on camperbot message above... " I suggest you find a code or a good math algorithm that you can turn into code."
CaffeineQueen
@CaffeineQueen
Apr 23 2016 01:00
nothing good
Moisés Man
@moigithub
Apr 23 2016 01:00
copy/paste FTW!!
so that math part u no need to do urself. if u cant
Bruno
@bbologna
Apr 23 2016 01:01
Ok, the easiest thing i can think of is... iterate from current number to 0... check if that number mod i == 0
is not the most effective but, its something
you can start there, and then... see how to make it more efficient.
current number to 1 actually, and increase some counter when mod i == 0... then check if has being 0 only when mod by 1
sorry about my english
CaffeineQueen
@CaffeineQueen
Apr 23 2016 01:06
function sumPrimes(num) {


  var numlist= [];

  function isPrime(num) {
    if(num < 2) return false;
    for (var i = 2; i < num; i++) {
        if(num%i===0)
            return false;
    }
    return true;
}

  for (var i=1; i<num; i++){
   if(isPrime(i)) {numlist.push(i);}


  }


  return numlist.reduce(function(a, b) {
  return a + b;});
}

sumPrimes(977);
Okay, "borrowing" a bit, this almost works
Coy Sanders
@coymeetsworld
Apr 23 2016 01:07
what does it fail on? looks pretty good
CaffeineQueen
@CaffeineQueen
Apr 23 2016 01:07
It works for the 10 but is only in the ballpark for 977
Coy Sanders
@coymeetsworld
Apr 23 2016 01:07
except you don't want i = 2
or wait i guess thats ok
Gerardo Paniagua
@igerardoh
Apr 23 2016 01:08
hi. could somebody help me please about how to solve the challenge 155? Just, I dont get it.
Moisés Man
@moigithub
Apr 23 2016 01:10
@CaffeineQueen yea probably cuz it have 2 nested loops.. takes too much time
CaffeineQueen
@CaffeineQueen
Apr 23 2016 01:10
I have no idea how to solve it really
Bruno
@bbologna
Apr 23 2016 01:11
Its something
Coy Sanders
@coymeetsworld
Apr 23 2016 01:12
@CaffeineQueen its your loop
you need <= num, not less than
977 is a prime number
Frank XC
@tenkdayz
Apr 23 2016 01:13
how can i use sort() to sort in descending order a 2d array similar to this
[["a",-23]["x",-12]["z",24]["u",-234]["j",-94],...]
descending order using their [1] index
Coy Sanders
@coymeetsworld
Apr 23 2016 01:15
need to give it a compareFunction @tenkdayz
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort like this, just have to tweak it differently to use a 2d array
Moisés Man
@moigithub
Apr 23 2016 01:16
@coymeetsworld it should be <
else 5%5 ==0 will return false... saying 5 its not prime
Coy Sanders
@coymeetsworld
Apr 23 2016 01:16
not that for loop
Matt Green
@mattxgreen
Apr 23 2016 01:16
@CaffeineQueen isn't it supposed to be inclusive of the number input?
Coy Sanders
@coymeetsworld
Apr 23 2016 01:16
the other one @moigithub @CaffeineQueen
yes @mattxgreen, she's skipping the last number
Moisés Man
@moigithub
Apr 23 2016 01:16
ahhh ok :)
Coy Sanders
@coymeetsworld
Apr 23 2016 01:16
977 is prime
CaffeineQueen
@CaffeineQueen
Apr 23 2016 01:17
function sumPrimes(num) {


  var numlist= [];

  function isPrime(num) {
    if(num === 1) return false;
    for (var i = 2; i <= num; i++) {
        if(num%i===0)
            return false;
    }
    return true;
}

  for (var i=1; i<num; i++){
   if(isPrime(i)) {numlist.push(i);}


  }


  return numlist.reduce(function(a, b) {
  return a + b;});
}

sumPrimes(977);
Moisés Man
@moigithub
Apr 23 2016 01:17
@CaffeineQueen wrong loop
Coy Sanders
@coymeetsworld
Apr 23 2016 01:17
other for loop @CaffeineQueen
CaffeineQueen
@CaffeineQueen
Apr 23 2016 01:18
Finally
thank you @moigithub and @coymeetsworld and @mattxgreen
CamperBot
@camperbot
Apr 23 2016 01:19
caffeinequeen sends brownie points to @moigithub and @coymeetsworld and @mattxgreen :sparkles: :thumbsup: :sparkles:
:star: 617 | @coymeetsworld | http://www.freecodecamp.com/coymeetsworld
:star: 987 | @moigithub | http://www.freecodecamp.com/moigithub
:star: 479 | @mattxgreen | http://www.freecodecamp.com/mattxgreen
Coy Sanders
@coymeetsworld
Apr 23 2016 01:19
np @CaffeineQueen gj
way to stick it out :thumbsup:
CaffeineQueen
@CaffeineQueen
Apr 23 2016 01:20
I need a new job :laughing:
Coy Sanders
@coymeetsworld
Apr 23 2016 01:20
what do you do and what do you want to do?
CaffeineQueen
@CaffeineQueen
Apr 23 2016 01:20
I tutor
and I want enough money to hire a cleaning lady ;)
Coy Sanders
@coymeetsworld
Apr 23 2016 01:21
lol that would be the life
CaffeineQueen
@CaffeineQueen
Apr 23 2016 01:22
and maybe to send my kids to schools that aren't going down the financial tube
Matt Green
@mattxgreen
Apr 23 2016 01:22
Which schools are those?
Bobby McDonald
@BobbyMcWho
Apr 23 2016 01:22
How do I put code into chat?
Moisés Man
@moigithub
Apr 23 2016 01:22
@BobbyMcWho copy paste
Matt Green
@mattxgreen
Apr 23 2016 01:22
Or you're going to send you kids to Finland?
Moisés Man
@moigithub
Apr 23 2016 01:23
@BobbyMcWho put 3 backticks ````at start
Matt Green
@mattxgreen
Apr 23 2016 01:23
@BobbyMcWho help format
help format
CamperBot
@camperbot
Apr 23 2016 01:23

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

CaffeineQueen
@CaffeineQueen
Apr 23 2016 01:23
the recession hit the birth rate around here, hard. They proposed closing one of the elementary schools but parents would have none of it. So they want to operate at the same capacity with a funding deficit of 800 students
Bobby McDonald
@BobbyMcWho
Apr 23 2016 01:24

'''js

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

return arr.indexOf(num);
}

getIndexToIns([120,3,5], 19);
'''

CamperBot
@camperbot
Apr 23 2016 01:24
:bulb: to format code use backticks! ``` more info
Coy Sanders
@coymeetsworld
Apr 23 2016 01:24
didn't think about the recession affecting the birth rate
Matt Green
@mattxgreen
Apr 23 2016 01:24
@BobbyMcWho close... just need backticks instead of single quotes
Tyler
@tylergross
Apr 23 2016 01:24
@BobbyMcWho need to put the code on a new line to use backticks
'''
CODE
'''
CamperBot
@camperbot
Apr 23 2016 01:24
:bulb: to format code use backticks! ``` more info
CaffeineQueen
@CaffeineQueen
Apr 23 2016 01:24
people got "responsible" and now we have broke schools, haha
Coy Sanders
@coymeetsworld
Apr 23 2016 01:24
Michigan area big on automotive though and they were definitely in trouble, I guess I can see that
Bobby McDonald
@BobbyMcWho
Apr 23 2016 01:24

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


  return arr.indexOf(num);
}

getIndexToIns([120,3,5], 19);
Bruno
@bbologna
Apr 23 2016 01:24
Done!
Bobby McDonald
@BobbyMcWho
Apr 23 2016 01:24
Why does this work?
I figured it out I guess but I cant' figure out why indexOf the num works
evolutionus
@evolutionus
Apr 23 2016 01:25
var randomNumberBetween0and19 = Math.floor(Math.random() * 20);

function randomWholeNum() {

  // Only change code below this line.

 var randomNumberBetween0and9 = Math.floor(Math.random() * 10);

  return Math.random();
}
Instructions are not clear. It says use the technique on line one to generate and return a random whole number between 0 and 9. My code is on line 7 and it's not generating a whole number. Can anyone help me with this?
Tyler
@tylergross
Apr 23 2016 01:25
indexOf returns the position of the number
Matt Green
@mattxgreen
Apr 23 2016 01:25
@BobbyMcWho you are putting the number into the array, then sorting the array
Bobby McDonald
@BobbyMcWho
Apr 23 2016 01:25
omgoodnes
I was trying to return the INDEX # of the previous element, not the numerical number
Coy Sanders
@coymeetsworld
Apr 23 2016 01:26
@evolutionus you need to return randomNumberBetween0and9, not Math.random()
Matt Green
@mattxgreen
Apr 23 2016 01:26
@BobbyMcWho Good now?
Coy Sanders
@coymeetsworld
Apr 23 2016 01:26
or not even have that variable, just return Math.floor(Math.random() * 10)
evolutionus
@evolutionus
Apr 23 2016 01:27
@coymeetsworld oh i c. thank you.
CamperBot
@camperbot
Apr 23 2016 01:27
evolutionus sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star: 618 | @coymeetsworld | http://www.freecodecamp.com/coymeetsworld
Coy Sanders
@coymeetsworld
Apr 23 2016 01:27
np
Bobby McDonald
@BobbyMcWho
Apr 23 2016 01:27
@mattxgreen yes, thank you! I was trying to subtract 1 from the indexnum of num since I forgot 0 = 1 1 =2 etc.
CamperBot
@camperbot
Apr 23 2016 01:27
bobbymcwho sends brownie points to @mattxgreen :sparkles: :thumbsup: :sparkles:
:star: 480 | @mattxgreen | http://www.freecodecamp.com/mattxgreen
Chris Peterson
@wildpetes1
Apr 23 2016 01:27
// Setup
function abTest(a, b) {
  // Only change code below this line
if (a >= 0);
  else if (b >= 0);
  else return undefined;

  // 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);
Matt Green
@mattxgreen
Apr 23 2016 01:27
@BobbyMcWho sure thing
Chris Peterson
@wildpetes1
Apr 23 2016 01:28
hey guys. what am I doing wrong.... I need a and b to be undefined when less than zero
Blake Harris
@bharris62
Apr 23 2016 01:28
howdy howdy
Matt Green
@mattxgreen
Apr 23 2016 01:28
@wildpetes1 What are you supposed to return?
Tyler
@tylergross
Apr 23 2016 01:28
@wildpetes1 instead of using a if/else try if(A | B)
Moisés Man
@moigithub
Apr 23 2016 01:29
@wildpetes1 if (a<0 || b<0 ) .....
Matt Green
@mattxgreen
Apr 23 2016 01:30
@wildpetes1 I think you want a AND b to be non-zero, otherwise return undefined?
Tyler
@tylergross
Apr 23 2016 01:30
or you could set a = undefined
friesenet21
@friesenet21
Apr 23 2016 01:31
@wildpetes1 if, else if requires {}
Chris Peterson
@wildpetes1
Apr 23 2016 01:31
@mattxgreen Yes.
Himanshu Batra
@manshu
Apr 23 2016 01:31
@moigithub is correct
Matt Green
@mattxgreen
Apr 23 2016 01:32
@wildpetes1 if(a>0 && b>0){} else {return undefined}
Moisés Man
@moigithub
Apr 23 2016 01:32
@mattxgreen samething.. if u invert the condition :)
then u can remove the else part
Muhammad Zaky Fauzi
@ZackOS
Apr 23 2016 01:32
hi, not a native speaker here. I um have a little understanding problem of "Stand in line" challenge. not sure what exactly the task i should do?
Chris Peterson
@wildpetes1
Apr 23 2016 01:33
thanks everyone!
dgerbe
@dgerbe
Apr 23 2016 01:34
' $.getJSON("http://quotes.stormconsultancy.co.uk/random.json", function(a) {
$(".message").html(a[0].content + "<p>— " + a[0].title + "</p>" + count++)
.error(function(xhr) {
alert(xhr)
})
});
Matt Green
@mattxgreen
Apr 23 2016 01:34
@moigithub Probably the same for this particular excercise, but not exactly the same
dgerbe
@dgerbe
Apr 23 2016 01:34
Can anyone tell me why this getJSON request doesn't seem to work, and I don't recieve an error?
Moisés Man
@moigithub
Apr 23 2016 01:34
@mattxgreen agree
Muhammad Zaky Fauzi
@ZackOS
Apr 23 2016 01:35
This message was deleted
Bruno
@bbologna
Apr 23 2016 01:35
just, shift-enter after first ```
@ZackOS ^
Erik Maurer
@MauPow
Apr 23 2016 01:37
Having some trouble pulling data for the Weather project. Can anyone figure out why it's returning undefined/not really working at all?
$(document).ready(function() {
  var latitude;
  var longitude;

  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
      latitude = position.coords.latitude;
      longitude = position.coords.longitude;
    })

    function setHome(lat, long) {
      $("#lat").html("Your latitude: " + lat);
      $("#long").html("Your longitude: " + long);
      $.getJSON("http://api.openweathermap.org/data/2.5/weather?lat=" + JSON.stringify(lat) + "&lon=" + JSON.stringify(long) + "&appid=2028c5bbe8723d925e5f2bf152b685ee"),

        function(home) {
          $("#home").html("Your home city: " + home["name"]);
        }
    };
    setHome(latitude, longitude);
  }



});
Matt Green
@mattxgreen
Apr 23 2016 01:39
@MauPow can you post the pen instead
Stephen James
@sjames1958gm
Apr 23 2016 01:39
@MauPow You need to call setHome inside the callback from getCurrentPosition
Moisés Man
@moigithub
Apr 23 2016 01:39
cuz async @MauPow
Erik Maurer
@MauPow
Apr 23 2016 01:39
Oh!
It worked :D
Matt Green
@mattxgreen
Apr 23 2016 01:39
@MauPow unless @moigithub 's advice resolves ya
Erik Maurer
@MauPow
Apr 23 2016 01:40
Thanks @sjames1958gm
CamperBot
@camperbot
Apr 23 2016 01:40
maupow sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
Erik Maurer
@MauPow
Apr 23 2016 01:40
Why, though?
CamperBot
@camperbot
Apr 23 2016 01:40
:star: 765 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Moisés Man
@moigithub
Apr 23 2016 01:40
u send a request.....
server start to process.. this might takes 1 hour
but ur code continue executing... so its undefined... (server didnt respond yet)
@MauPow
Stephen James
@sjames1958gm
Apr 23 2016 01:40
@MauPow BEcause get Current position is asynchronous, until the callback happens the data is not available.
Moisés Man
@moigithub
Apr 23 2016 01:40
@MauPow to make sure u got data back from server.. all ur code should be inside the callback
Erik Maurer
@MauPow
Apr 23 2016 01:41
I'm not familiar with callbacks yet... where would this be happening
or what is a 'callback'
Moisés Man
@moigithub
Apr 23 2016 01:42
a callback is just a funciton... when server is ready with some data.. it "calls" ur function @MauPow
Matt Green
@mattxgreen
Apr 23 2016 01:42
@MauPow A callback is a function that is executed when an event finishes
Bruno
@bbologna
Apr 23 2016 01:42
@MauPow callback is a function that will be called when some event fires
evolutionus
@evolutionus
Apr 23 2016 01:43
This message was deleted
Erik Maurer
@MauPow
Apr 23 2016 01:43
Ok, so that's why it's able to output my information, but when I call the weather API, nothing happens
$.getJSON("http://api.openweathermap.org/data/2.5/weather?lat=" + JSON.stringify(lat) + "&lon=" + JSON.stringify(long) + "&appid=2028c5bbe8723d925e5f2bf152b685ee"),
        function(home) {
          $("#home").html("Your home city: " + home["name"]);
Nothing happens here
Matt Green
@mattxgreen
Apr 23 2016 01:43
@MauPow your whole string of code is a callback too... $(document).ready(function()... when the document is "ready" (finished loading) your function executes
Erik Maurer
@MauPow
Apr 23 2016 01:44
Ah ok
So I do the $.getJSON part, which returns a .json file full of goodies
and then that gets stored inside (home)?
Bruno
@bbologna
Apr 23 2016 01:44
@mattxgreen good example
evolutionus
@evolutionus
Apr 23 2016 01:45
This message was deleted
Erik Maurer
@MauPow
Apr 23 2016 01:46
Basically I'm wondering how to actually pull values out of the json file that gets returned... I
Matt Green
@mattxgreen
Apr 23 2016 01:46
@MauPow the JSON that is returned from getJSON is passed into a callback (on a success)
Erik Maurer
@MauPow
Apr 23 2016 01:46
ok
Matt Green
@mattxgreen
Apr 23 2016 01:46
@MauPow There is also another callback for an error event.
Erik Maurer
@MauPow
Apr 23 2016 01:46
and would that be the function that I declare after the comma?
Matt Green
@mattxgreen
Apr 23 2016 01:48
@MauPow you should really take a look at the docs, especially as you're learning. You can be fairly certain that if there is a success callback, that there is also an error callback. Docs for getJSON are here: http://api.jquery.com/jquery.getjson/
Erik Maurer
@MauPow
Apr 23 2016 01:51
Yeah I am worried that ajax won't return the json because it's from a different domain
but that wasn't really touched on at all in the tutorials
Matt Green
@mattxgreen
Apr 23 2016 01:52
@MauPow That happens to a lot of people through codepen. The most common solution is to use a cors proxy. like http://crossorigin.me/
Erik Maurer
@MauPow
Apr 23 2016 01:53
Oh good to know
So I'm trying to pass my latitude variable to the URL... does this need to be stringify or does a number work?
Stephen James
@sjames1958gm
Apr 23 2016 01:56
If you concatenate a number to a string it handles the conversion
"" + num will convert the num to a string
CaffeineQueen
@CaffeineQueen
Apr 23 2016 01:58
I killed my computer trying to do least common multiple, lol
sorry, smallest common multiple
Stephen Fox
@stevemasta34
Apr 23 2016 02:14
So I could make a map of the "Boo who" problem, but I don't think that is desired. What is this assignment really asking?
Erik Maurer
@MauPow
Apr 23 2016 02:30
Why the heck does this weather API return temperature in Kelvin lol
Dylan
@dhcodes
Apr 23 2016 02:31
@MauPow kelvin is a universal temperature form
it's absolute
Erik Maurer
@MauPow
Apr 23 2016 02:32
Suppose that makes sense
V Arun Kumar
@arunvkumr
Apr 23 2016 02:32
@MauPow add &units=metric to get temp in Celsius by default.
Dylan
@dhcodes
Apr 23 2016 02:32
by absolute I mean it's based on absolute zero, the point at which molecules stop moving
Erik Maurer
@MauPow
Apr 23 2016 02:33
Oh yeah I know what Kelvin is hehe, just thought it was funny that while building my weather project it told me it was 289 degrees outside
Hmm @arunkumrv , I'm pulling from a json file is there a way to do that on the fly? switch between celsius and fahrenheit? or do I need to define another function to do the conversion for them
Dylan
@dhcodes
Apr 23 2016 02:36
@MauPow why not just pick one and then write a function that switches them
you used the formula earlier in FCC exercises :)
C to F is c*9/5 +32 I believe
V Arun Kumar
@arunvkumr
Apr 23 2016 02:36
@MauPow for conversion you might have to add some codes. but by adding &units=metricit saves some lines as you will be getting it in celsius by default.Just conversion for fahrenhiet. :smile:
Erik Maurer
@MauPow
Apr 23 2016 02:36
ok I will combine those thanks
How would I access the values inside of this part of the json file?
```
"weather":[
        {"id":500,
        "main":"Rain",
        "description":"light rain",
        "icon":"10n"
        }]
home.weather["main"] doesn't seem tow ork
because it is inside the array I am guessing
Dylan
@dhcodes
Apr 23 2016 02:41
weather[0].main
does that work?
Erik Maurer
@MauPow
Apr 23 2016 02:43
Yep! Thanks @dhcodes
CamperBot
@camperbot
Apr 23 2016 02:43
maupow sends brownie points to @dhcodes :sparkles: :thumbsup: :sparkles:
:star: 675 | @dhcodes | http://www.freecodecamp.com/dhcodes
Micah Bales
@micahbales
Apr 23 2016 02:44
So I'm working on Sum All Primes. It looks like this algorithm is going to be extremely complex, à la: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
Is there an easier way to find primes?
Dylan
@dhcodes
Apr 23 2016 02:52
@micahbales I think that's the most efficient way but you can make a loop of sorts. Let me look at my code
Micah Bales
@micahbales
Apr 23 2016 02:54
@dhcodes +1
Dylan
@dhcodes
Apr 23 2016 02:55
@micahbales I made a nested loop
Micah Bales
@micahbales
Apr 23 2016 02:55
@dhcodes Yeah, that's what I'm trying out now. Thanks!
CamperBot
@camperbot
Apr 23 2016 02:55
micahbales sends brownie points to @dhcodes :sparkles: :thumbsup: :sparkles:
:star: 676 | @dhcodes | http://www.freecodecamp.com/dhcodes
Dylan
@dhcodes
Apr 23 2016 02:57
it's not easy to write. one way to make it more efficient is to set a var isPrime to true, and then have it switch to false and move to the next number if it isn't prime
if it remains true, push it to an array
then eventually you'll add all the elements in the array together
good luck
Erin Heard
@ufi16
Apr 23 2016 03:11
i can't get it to return the val for the challenge 'Make Object Properties Private'

var Bike = function() {

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

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

var myCar = new Car();

var myBike = new Bike(3);

Matthew Rowe
@mnrowe
Apr 23 2016 03:16
@ufi16 do myBike.setGear(3);
Abdul-Samii Ajala Olalekan
@jalasem
Apr 23 2016 03:17

pls help this is my javascript

$(document).ready(function(){
    console.log("am working!!!");
    $('#page-2-form-card').hide();
    $('#test-btn').click(function() {
        $('#page-2-weather-card #page-2-form-card').slideToggle();
        $('#page-2-form-card').animate({ backgroundColor: "#0d47a1" }, "fast");
    });
});
$(this).animate({ backgroundColor: "olive" }, "slow");

here is my relevant html code:

 <div class="row blue-text text-darken-2">
        <div class="col s12 m6 l3 row card" style="margin-left: 1em;" id="page-2-weather-card">
          <div class="col s12 m12 l12 card flow-text waves-effect">
            <p>Ilorin, Nigeria</p>
            <p>30<sup>o</sup>c<sup><i class="material-icons">wb_sunny</i>sunny</sup></p>
            <p>Clear with periodic clouds</p>
          </div>
          <div class="col s12 m12 l12 card row waves-effect">
            <i class="fa fa-mixcloud fa-3x left"></i>
            <div class="col s5 left" style="font-size: 23pt;font-weight: 300;">Humidity</div>
            <p class="col s3 right">
              88&#37;
            </p>
          </div>
          <div class="col s12 m12 l12 card row waves-effect">
            <i class="fa fa-soundcloud fa-3x left"></i>
            <div class="col s5 left" style="font-size: 23pt;font-weight: 300;">Wind</div>
            <p class="col s3 right">
              13km/h
            </p>
          </div>
          <div class="col s12 m12 l12 card row waves-effect" style="margin-bottom: 0.5em;">
            <i class="fa fa-eye fa-3x left"></i>
            <div class="col s5 left" style="font-size: 23pt;font-weight: 300;">Visibility</div>
            <p class="col s3 right">
              72&#37;
            </p>
          </div>
        </div>
        <div class="col s12 m6 l3 row card" style="margin-left: 1em;" id="page-2-form-card">
          hello form
        </div>
      </div>

I reference my jquery before the javascript as you would expect.
But it seems not to work

Erin Heard
@ufi16
Apr 23 2016 03:18
within my function or when i'm calling it? @rwez
Chris Cullen
@123xylem
Apr 23 2016 03:20
Hey guys any help on this for loop factorialise problem?

@123xylem

function factorialize(num) {

var arr = [];
var newArr =[];

for(i= 1; i<=num; i++) { arr.push(i);
var total = 0;
for(var j=0;j<arr[i].length;j++){
total *= newArr[i][j]; }

return newArr;
}

}
factorialize(5);
im doing a for loop to make an array push out numbers 1-5
then im going through that array and mulitplying the numbers together into a total and returning total... It keeps telling me that on my second For loop the arr[i].length is undefined... Ive tried using arr[i] and newArr[i] but neither work

scottmike0
@scottmike0
Apr 23 2016 03:22
@123xylem use recursion, i recommend knowing the formula of factorial
Matthew Rowe
@mnrowe
Apr 23 2016 03:22
var Bike = function() {

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

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

var myCar = new Car();

var myBike = new Bike();

myBike.setGear(3);
myBike.getGear();
scottmike0
@scottmike0
Apr 23 2016 03:23
@123xylem recursion takes a base case and then you simply call the function and multiply it by the paramater value
Chris Cullen
@123xylem
Apr 23 2016 03:23
o is it a simple formula like *= or is it the n! ?
Erin Heard
@ufi16
Apr 23 2016 03:23
that still didn't work @rwez
Chris Cullen
@123xylem
Apr 23 2016 03:24
@scottmike0
scottmike0
@scottmike0
Apr 23 2016 03:25
@123xylem that would be without recursion doing that, but in a function, you want to return. you would simply return param(value) * functionName(n-1);
@123xylem the idea behind it is to recurse
Erin Heard
@ufi16
Apr 23 2016 03:25
i figured it out @rwez
scottmike0
@scottmike0
Apr 23 2016 03:26
@123xylem therefore you need to know what is the factorial of 0 and 1
@123xylem well really only 0
Matthew Rowe
@mnrowe
Apr 23 2016 03:26
@ufi16 nice, what was it?
scottmike0
@scottmike0
Apr 23 2016 03:26
if you know the factorial of 0 , then you will return that number.
and then you get the factorial recursive way of doing it
@123xylem does that make sense?
Erin Heard
@ufi16
Apr 23 2016 03:27
this.setGear = function() { gear = 0 + val;}; @rwez
*(val)
Chris Cullen
@123xylem
Apr 23 2016 03:27
@scottmike0 kind of... I have a very limited grasp on recursiion
Return the factorial of the provided integer.
Is the task im on
and they want me to do it in a function
scottmike0
@scottmike0
Apr 23 2016 03:28
@123xylem write out the function psuedo code that i said
@123xylem and then you may get that OHhh moment
Chris Cullen
@123xylem
Apr 23 2016 03:31
param(value) * functionName(n-1); so what values do I have? all i have is the function() which I will have to factorialize
scottmike0
@scottmike0
Apr 23 2016 03:31
okay, you have the function right?
Chris Cullen
@123xylem
Apr 23 2016 03:32
yes the name of it
and the value given by FCC
scottmike0
@scottmike0
Apr 23 2016 03:32
okay
replace the name of the functtion to that statement I put
so it should be something like return factoralize(n-1);
Chris Cullen
@123xylem
Apr 23 2016 03:34
ok
Justin-Ben
@Justin-Ben
Apr 23 2016 03:34
Could anyone point me in the right direction for the Counting Cards challenge. Just wondering if i should use a switch statement or if else?
Chris Cullen
@123xylem
Apr 23 2016 03:35
@scottmike0 but factoralize(n-1) is undefined? What will it return
scottmike0
@scottmike0
Apr 23 2016 03:36
@123xylem n being your paramater. what is the paramater name
Chris Cullen
@123xylem
Apr 23 2016 03:36
o its num
scottmike0
@scottmike0
Apr 23 2016 03:36
@123xylem and you are missing one point I said
@123xylem through the psuedocode you said
Liu Zhiqun
@lzhiqun
Apr 23 2016 03:38
guys I'm confused with the use of arguments
function destroyer(arr) {
  // Remove all the values
   arguments[0].filter(function(val){
    return (val!=arguments[1] && val!=arguments[2]);});   
  return arguments[0];
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
supposed to remove the [1] and[2] from [0]
scottmike0
@scottmike0
Apr 23 2016 03:41
@123xylem still confused?
Chris Cullen
@123xylem
Apr 23 2016 03:41
@scottmike0 yes sorry :worried:

function factorialize(num) {param(value) * functionName(n-1);
return num;
}

factorialize(5);

Noremak
@Noremak
Apr 23 2016 03:42
What exactly is the difference between + and += in javascript?
Chris Cullen
@123xylem
Apr 23 2016 03:42
This is what ive wrote obviously its wrong but im confused which bits goes where
scottmike0
@scottmike0
Apr 23 2016 03:42
@
@123xylem here is a basis for you
function factoralize(num) {
return num *  factoralize(num-1);

}
@123xylem now find what is the result when num is 0
Chris Cullen
@123xylem
Apr 23 2016 03:44
ah ok... so its a function withing a function that keeps RECURRING... what is the -1 bit about#?
scottmike0
@scottmike0
Apr 23 2016 03:44
@123xylem the n-1 means that when n reaches a certain point it will stop recurring
Chris Cullen
@123xylem
Apr 23 2016 03:45
@scottmike0 in this case is that 1?
scottmike0
@scottmike0
Apr 23 2016 03:45
@123xylem if you know the factoral math formula
Tyler
@tylergross
Apr 23 2016 03:45
wiki no auto
CamperBot
@camperbot
Apr 23 2016 03:45
no wiki entry for: no auto
scottmike0
@scottmike0
Apr 23 2016 03:45
@123xylem you should know what happens when num equals 0
Tyler
@tylergross
Apr 23 2016 03:46
wiki run auto
CamperBot
@camperbot
Apr 23 2016 03:46
no wiki entry for: run auto
Norvin Burrus
@ndburrus
Apr 23 2016 03:46
@Justin-Ben I think it's a personal preference. You could also consider using a case statement.
scottmike0
@scottmike0
Apr 23 2016 03:46
@123xylem well you should really know what happens when num equals 1 raather than 0
Tyler
@tylergross
Apr 23 2016 03:46
whats the entry for turning off infinite loops
scottmike0
@scottmike0
Apr 23 2016 03:46
@123xylem but both cases can work
@123xylem so then, what is 0! =?
Tyler
@tylergross
Apr 23 2016 03:46
wiki auto-run
CamperBot
@camperbot
Apr 23 2016 03:46

:point_right: disable code auto run [wiki]

By default, the Free Code Camp site automatically loads and runs your last recorded solution. If you have accidentally created an infinite loop or other irrecoverable error or simply don't trust the code, you can disable code auto-run by putting the following in your URL:
run=disabled

Example:

URL: http://www.freecodecamp.com/challenges/Algorithm-meet-Algorithm#?solution=function%20meetBonfire(argument)

No-Run URL: http://www.freecodecamp.com/challenges/Algorithm-meet-Algorithm#?run=disabled&solution=function%20meetBonfire(argument)

:pencil: read more about disable code auto run on the FCC Wiki

Chris Cullen
@123xylem
Apr 23 2016 03:48
@scottmike0 thanks in advance here as I have to get out of thehouse
CamperBot
@camperbot
Apr 23 2016 03:48
123xylem sends brownie points to @scottmike0 :sparkles: :thumbsup: :sparkles:
:star: 361 | @scottmike0 | http://www.freecodecamp.com/scottmike0
Chris Cullen
@123xylem
Apr 23 2016 03:48
Im gonna have to look at this later
I think I should be able to fighure it out now
scottmike0
@scottmike0
Apr 23 2016 03:48
yeah, remember conditionals
is your key @123xylem
Norvin Burrus
@ndburrus
Apr 23 2016 03:49
@Justin-Ben sorry, case is part of the switch statements.
@Justin-Ben I used a switch statement.
Bobby McDonald
@BobbyMcWho
Apr 23 2016 03:53
It gives me great satisfaction to figure out some of these bonfires
krisluu5695
@krisluu5695
Apr 23 2016 03:53
// Setup
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line

  result = {
    "alpha": "Adams",
    "bravo": "Boston",
    "charlie": "Chicago",
    "delta": "Denver",
    "echo": "Easy",
    "foxtrot": "Frank",
  };

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

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

Instructions
Convert the switch statement into a lookup table called lookup. Use it to lookup val and assign the associated string to the result variable.

can someone help me??? TY .....

Thomas McGuire
@mcguiretj
Apr 23 2016 03:53

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

// Modify values below to test your code
multiplyAll([[1],[2],[3]]);
```

Norvin Burrus
@ndburrus
Apr 23 2016 03:54
@Noremak + is an addition operator. += is - example: x += y, same as x = x + y.
WilliamDecker
@WilliamDecker
Apr 23 2016 03:54
does anyone have any good reading on API's for the random quote generator project?
Thomas McGuire
@mcguiretj
Apr 23 2016 03:55
@krisluu5695 is there an undefined instruction with an "" on that problem?
Norvin Burrus
@ndburrus
Apr 23 2016 03:55
@mcguiretj which challenge is that?
krisluu5695
@krisluu5695
Apr 23 2016 03:56
@mcguiretj oh.... i got it tk for answer men ....
CamperBot
@camperbot
Apr 23 2016 03:56
krisluu5695 sends brownie points to @mcguiretj :sparkles: :thumbsup: :sparkles:
:star: 240 | @mcguiretj | http://www.freecodecamp.com/mcguiretj
Thomas McGuire
@mcguiretj
Apr 23 2016 03:56
@krisluu5695 no problem. I know because that got me too. Best of luck
krisluu5695
@krisluu5695
Apr 23 2016 03:57
@camperbot how i can ?
Thomas McGuire
@mcguiretj
Apr 23 2016 03:59
oh sorry @ndburrus it's nesting for loops under basic javascipt I believe
DrewBowzer2016
@DrewBowzer2016
Apr 23 2016 04:08
thanks @CaroleAnneHannon for your help with Checkpoint: Stand in Line
CamperBot
@camperbot
Apr 23 2016 04:08
drewbowzer2016 sends brownie points to @caroleannehannon :sparkles: :thumbsup: :sparkles:
:star: 838 | @caroleannehannon | http://www.freecodecamp.com/caroleannehannon
krisluu5695
@krisluu5695
Apr 23 2016 04:10
// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

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

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

Instructions
Modify the function checkObj to test myObj for checkProp. If the property is found, return that property's value. If not, return "Not Found"

Am i did sth wrong ????

Kyle Roden
@kyleroden
Apr 23 2016 04:11
I think you need a semi-colon at the end of the function
Thomas McGuire
@mcguiretj
Apr 23 2016 04:12
@krisluu5695 you have to use the .hasOwnProperty method
krisluu5695
@krisluu5695
Apr 23 2016 04:12
nth happen too !!
Thomas McGuire
@mcguiretj
Apr 23 2016 04:12
function checkObj(checkProp) {
  // Your Code Here
  if (myObj.hasOwnProperty(checkProp)) {                                        
    return myObj[checkProp];
  } else {
    return "Not Found";
  }
}
krisluu5695
@krisluu5695
Apr 23 2016 04:13
got it ty :D
Thomas McGuire
@mcguiretj
Apr 23 2016 04:13
@krisluu5695 no prob
krisluu5695
@krisluu5695
Apr 23 2016 04:13
hasOwnProperty is a method of JS ?
Thomas McGuire
@mcguiretj
Apr 23 2016 04:19
hasOwnProperty is an action used to figure out if myObj has a certain property. If it is true, it returns the value of the property if that makes sense.
krisluu5695
@krisluu5695
Apr 23 2016 04:19
tks ...
Edward Hilgendorf
@edhilgendorf
Apr 23 2016 04:33
Hi, curious if someone can give me a hint on how to get started with Chunky Monkey
I have tried nesting for loops, and I just can't really wrap my mind around the math I guess
Edward Hilgendorf
@edhilgendorf
Apr 23 2016 04:40
Never mind I think I think i got it...
Edward Hilgendorf
@edhilgendorf
Apr 23 2016 04:52
Never mind I could really use a hint if anyone is around
Wait I am getting closer
kirbyedy
@kirbyedy
Apr 23 2016 04:54
@edhilgendorf everything alright ? :)
Greg D
@mosaic-greg
Apr 23 2016 04:59
good evening all. looks like netflix has a documentary on algorithms now
kirbyedy
@kirbyedy
Apr 23 2016 05:00
link ?
khail
@khailcs
Apr 23 2016 05:04
@edhilgendorf
you can use slice()
and two numbers for start and end of slice
then increment both start and end numbers until you get all your chunks ^^
khail
@khailcs
Apr 23 2016 05:11
@edhilgendorf Like this! ^^ start of slice, end of slice... until done :D
http://assets.pages.viewpoints.com/wp-content/uploads/2013/10/2Slicing-bread-600-400.jpg
Tamber Hausler
@codergeist
Apr 23 2016 05:11
Hey all, working on this lesson here, and I'm a little confused:
except I guess I don't know how to link the lessons
khail
@khailcs
Apr 23 2016 05:12
@codergeist what's the title?
Tamber Hausler
@codergeist
Apr 23 2016 05:12
Stand in Line
khail
@khailcs
Apr 23 2016 05:12
what's the problem?
Tamber Hausler
@codergeist
Apr 23 2016 05:13
I'm supposed to add the item argument to the end of the array one, and then drop the first item of the array and have that print.
my code is as follows:
function nextInLine(arr, item) {
// Your code here
arr.push(item);
arr.shift();
var myArr = arr.shift();
return myArr; // Change this line
}
I keep getting the item to push, but I lose the first two items of the array and it returns a 2
kirbyedy
@kirbyedy
Apr 23 2016 05:14
@codergeist why shift twice ?
Tamber Hausler
@codergeist
Apr 23 2016 05:14
Oh, that was me just trying things out.
It does it when shift is only declared once, too.
Oh, wait
I didn't try it with the variable.
The variable alone, I mean
And it works
XD @khailcs and @kirbyedy thanks for your time.
CamperBot
@camperbot
Apr 23 2016 05:15
codergeist sends brownie points to @khailcs and @kirbyedy :sparkles: :thumbsup: :sparkles:
:star: 907 | @kirbyedy | http://www.freecodecamp.com/kirbyedy
:star: 282 | @khailcs | http://www.freecodecamp.com/khailcs
khail
@khailcs
Apr 23 2016 05:16
@codergeist Cool, hardly done anything at all. happy coding.^^
Tamber Hausler
@codergeist
Apr 23 2016 05:16
Well, you guys were asking, and that was good enough. Thanks, and you too!
khail
@khailcs
Apr 23 2016 05:16
:+1:
kirbyedy
@kirbyedy
Apr 23 2016 05:17
:thumbsup:
khail
@khailcs
Apr 23 2016 05:18
@kirbyedy sorry man wrong tag
friesenet21
@friesenet21
Apr 23 2016 05:18
that is third solution to "Stand In Line" that I've seen. Beautiful.
kirbyedy
@kirbyedy
Apr 23 2016 05:18
no probls :)
Tamber Hausler
@codergeist
Apr 23 2016 05:19
Get a lot of questions about it, @friesenet21
?
friesenet21
@friesenet21
Apr 23 2016 05:21
I was stuck on it for awhile.
khail
@khailcs
Apr 23 2016 05:22
what are you working on now?
friesenet21
@friesenet21
Apr 23 2016 05:24
I'm stuck on card counting. It would help if I practiced it IRL. ;D
Najma Aden
@najma103
Apr 23 2016 05:25
is anyone currently working on the chunkey money assignment
i am currently not getting the last element ;(

function chunkArrayInGroups(arr, size) {
// Break it up.
var tempArr = [];
var counter = 0;

for (var i = 0; i< arr.length; i++){
tempArr.push(arr.splice(i, i+size));
}

return tempArr;

}

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

Kyle Roden
@kyleroden
Apr 23 2016 05:29
@najma103 You need to change i, not to be i++.
that increments the loop by one, but you want to increment it by the size, which is the second parameter in the function
Najma Aden
@najma103
Apr 23 2016 05:33
Thanks @kyleroden will try that - i think i had that before and it was working
CamperBot
@camperbot
Apr 23 2016 05:33
najma103 sends brownie points to @kyleroden :sparkles: :thumbsup: :sparkles:
:star: 285 | @kyleroden | http://www.freecodecamp.com/kyleroden
Najma Aden
@najma103
Apr 23 2016 05:33
now i am just throwing stuff up and seeing what sticks lol
i meant *not working
Kyle Roden
@kyleroden
Apr 23 2016 05:33
yeah that's how i've learned!
Najma Aden
@najma103
Apr 23 2016 05:35
that took care of it.
khail
@khailcs
Apr 23 2016 05:40

@najma103 this line is prettier than what i have ^^

tempArr.push(arr.splice(i, i+size));

copying it. :+1:

@friesenet21 solved it?
Najma Aden
@najma103
Apr 23 2016 05:44
Thanks Khail ;)
friesenet21
@friesenet21
Apr 23 2016 05:47
I've got an if, else if inside the switch case. Likely will be a huge detour. still working on it
Jonathan Mitchell
@Vanhealen
Apr 23 2016 05:49
With the random quote generator project, it receives the quotes from another website I am guessing right?
friesenet21
@friesenet21
Apr 23 2016 05:49
```js
```js
sankar244
@sankar244
Apr 23 2016 05:49
I am getting error with" Do not change code below the line", what can i do?
friesenet21
@friesenet21
Apr 23 2016 05:50
if (count > 0) {
    return "Bet";
  }
after case 5:
nope
Kyle Roden
@kyleroden
Apr 23 2016 05:55
@Vanhealen some people used apis to get quotes. I just made an array of my favorites.
goodm0urning
@goodm0urning
Apr 23 2016 05:57
can someone help and explain what is going on in a problem I'm having?
function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line
  for (var i = 0; i < arr.length; i++){
    for (var k = 0; k < arr[i].length; k++) {
      console.log (arr[i][k]);
    }
  }
  // Only change code above this line
  return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
It says I need to "Modify function multiplyAll so that it multiplies the product variable by each number in the sub-arrays of arr"
UtkarshShukla7
@UtkarshShukla7
Apr 23 2016 06:00
@goodm0urning store the product with each element in product variable
product*=arr[i][k];
goodm0urning
@goodm0urning
Apr 23 2016 06:00
OOOH
okay
@UtkarshShukla7 Okay whoa whoa whoa
what does the asterisk do?
when I type product = arr[i][k] it doesn't work, but product*= arr[i][k] does
it never went over this which is why I'm asking!
UtkarshShukla7
@UtkarshShukla7
Apr 23 2016 06:02
@goodm0urning it multiplies like product = product *arr[i][k];
goodm0urning
@goodm0urning
Apr 23 2016 06:03
Oh, so similar to the way +=, and -= work as modifiers
Abdul-Samii Ajala Olalekan
@jalasem
Apr 23 2016 06:03
this code keep returning invalid left handside assignment on line 17 can anyone explain that and how to fix it?
$(document).ready(function(){
    console.log("am working!!!");
    $('#page-2-form-card').hide();
    $('#test-btn').click(function() {
        $('#page-2-weather-card').slideToggle();
        $('#page-2-form-card').slideToggle();
        $('#page-2-form-card').animate({ 
            backgroundColor: "#0d47a1" 
        }, 500, function() {
        // Animation complete.
      });
    });
    $("#test-btn").click(function(){
        if ($('#test-btn').text() == 'Take a Test') {
            $("#test-btn").text() ='Submit Entry';
        } else {
            $("#test-btn").text() = 'Take a test';
        }
    });
});

// ($(this).text();
goodm0urning
@goodm0urning
Apr 23 2016 06:03
and since product is 1, that makes sense
thank you so much! @UtkarshShukla7
CamperBot
@camperbot
Apr 23 2016 06:03
goodm0urning sends brownie points to @utkarshshukla7 :sparkles: :thumbsup: :sparkles:
:star: 354 | @utkarshshukla7 | http://www.freecodecamp.com/utkarshshukla7
UtkarshShukla7
@UtkarshShukla7
Apr 23 2016 06:04
@goodm0urning np
Zoher Ali
@Zoher-ali
Apr 23 2016 06:06

hey plz any1 help me with diff two arrays challenge. I am not getting desired output. Here's my code...
function diffArray(arr1, arr2) {
    var newArr = [];
  var Array =[];
  newArr = arr1.concat(arr2);
  for(i = 0 ; i < newArr.length ; i++){
    if((arr1.indexOf(newArr[i]) != -1)&&(arr2.indexOf(newArr[i] != -1))){}
    else{
      Array.push(newArr[i]);

    }
  }
/*  arr1.filter(function check(value){
    if(arr2.indexOf(value) == -1){
      newArr = newArr.concat(value);
    }
  });
*/
  // Same, same; but different.
  return Array;
}

diffArray([1, "calf", 3, "piglet"], [1, "calf", 3, 4]);
Its working with numeric arrays
DJ
@qualitymanifest
Apr 23 2016 06:08
@jalasem when you're using jquery's .text() to assign text you do it like $('selector').text("some text") not $('selector').text() = "some text"
UtkarshShukla7
@UtkarshShukla7
Apr 23 2016 06:09
This message was deleted
Abdul-Samii Ajala Olalekan
@jalasem
Apr 23 2016 06:09
$("#test-btn").click(function(){
        if ($('#test-btn').text('Take a Test')) {
            $("#test-btn").text('Submit Entry');
        } else {
            $("#test-btn").text('Take a test');
        }
        if ($('#test-btn').text('Submit Entry')) {
            $("#test-btn").text('Take a test');
        } else {
            $("#test-btn").text('Submit Entry');
        }
    });
this doesnt work either @UtkarshShukla7
DJ
@qualitymanifest
Apr 23 2016 06:10
@jalasem i think you only need to change what you had when assigning, not comparing
@jalasem do you have a codepen
UtkarshShukla7
@UtkarshShukla7
Apr 23 2016 06:10
@jalasem
if ($('#test-btn').text()==='Submit Entry') {
            $("#test-btn").text('Take a test');
        } else {
            $("#test-btn").text('Submit Entry');
        }
Tharoon T Thiagarajan
@tharoon
Apr 23 2016 06:13
how can i have escape sequences for backslash tab tab carriage-return and new line in javaScript
UtkarshShukla7
@UtkarshShukla7
Apr 23 2016 06:13
@jalasem
$(selector).text() returns the text content
$(selector).text('xyz') sets the text content
@tharoon use double \ for backslash
Abdul-Samii Ajala Olalekan
@jalasem
Apr 23 2016 06:14
@UtkarshShukla7 thanks so much I now understand it works
CamperBot
@camperbot
Apr 23 2016 06:14
jalasem sends brownie points to @utkarshshukla7 :sparkles: :thumbsup: :sparkles:
:star: 355 | @utkarshshukla7 | http://www.freecodecamp.com/utkarshshukla7
UtkarshShukla7
@UtkarshShukla7
Apr 23 2016 06:14
np
Tharoon T Thiagarajan
@tharoon
Apr 23 2016 06:15
@UtkarshShukla7 and that i should i assign it a variable...
@UtkarshShukla7 how can i do it??
UtkarshShukla7
@UtkarshShukla7
Apr 23 2016 06:15
no in console.log
@tharoon challenge name?
Zoher Ali
@Zoher-ali
Apr 23 2016 06:15
plz sm1 help
diff two array challenge
Tharoon T Thiagarajan
@tharoon
Apr 23 2016 06:16
@UtkarshShukla7 escape sequences in strings(javaScript).
UtkarshShukla7
@UtkarshShukla7
Apr 23 2016 06:17
@tharoon var myStr="\ \t \t \r \n";
Tharoon T Thiagarajan
@tharoon
Apr 23 2016 06:18
@UtkarshShukla7 thanks :)
CamperBot
@camperbot
Apr 23 2016 06:18
tharoon sends brownie points to @utkarshshukla7 :sparkles: :thumbsup: :sparkles:
:star: 356 | @utkarshshukla7 | http://www.freecodecamp.com/utkarshshukla7
UtkarshShukla7
@UtkarshShukla7
Apr 23 2016 06:18
np
var myStr="\\ \t \t \r \n";
UtkarshShukla7
@UtkarshShukla7
Apr 23 2016 06:27
@Zoher-ali

function diffArray(arr1, arr2) {
    var newArr = [];
  var Array =[];
  newArr = arr1.concat(arr2);
  for(i = 0 ; i < newArr.length ; i++){
    if((arr1.indexOf(newArr[i]) != -1)&&(arr2.indexOf(newArr[i]) != -1)){}
    else{
      Array.push(newArr[i]);

    }
  }
/*  arr1.filter(function check(value){
    if(arr2.indexOf(value) == -1){
      newArr = newArr.concat(value);
    }
  });
*/
  // Same, same; but different.
  return Array;
}

diffArray([1, "calf", 3, "piglet"], [1, "calf", 3, 4]);
@Zoher-ali you forgot to close bracket after arr2.indexOf(newArr[i]
Zoher Ali
@Zoher-ali
Apr 23 2016 06:30
@UtkarshShukla7 thnx 4 pointing out :smile:
CamperBot
@camperbot
Apr 23 2016 06:30
zoher-ali sends brownie points to @utkarshshukla7 :sparkles: :thumbsup: :sparkles:
:star: 357 | @utkarshshukla7 | http://www.freecodecamp.com/utkarshshukla7
UtkarshShukla7
@UtkarshShukla7
Apr 23 2016 06:30
np
Punith K
@kpunith8
Apr 23 2016 06:46
having trouble in Javascript escape sequences -> I wrote this, is it correct, var myStr = '\ \t \t \r \n'; for myStr should have the escape sequences for backslash tab tab carriage-return new-line separated by spaces
ALMY91
@ALMY91
Apr 23 2016 06:49
i love coding ~~
Punith K
@kpunith8
Apr 23 2016 06:49
I got the solution, I found here in the conversation, var myStr="\ \t \t \r \n";
ALMY91
@ALMY91
Apr 23 2016 06:49
:smile:
Punith K
@kpunith8
Apr 23 2016 06:49
Thanks @UtkarshShukla7
CamperBot
@camperbot
Apr 23 2016 06:49
kpunith8 sends brownie points to @utkarshshukla7 :sparkles: :thumbsup: :sparkles:
:star: 358 | @utkarshshukla7 | http://www.freecodecamp.com/utkarshshukla7
Miguel T Rivera
@mtrivera
Apr 23 2016 06:50
wiki pig latin
CamperBot
@camperbot
Apr 23 2016 06:50

:point_right: algorithm pig latin [wiki]

Problem Explanation:

  • You need to create a program that will translate from English to Pig Latin. Check the instructions for converting to Pig Latin from the initial description or the wiki page. It might not be obvious but you need to remove all the consonants up to the first vowel in the case there letter does not start with a vowel.
:pencil: read more about algorithm pig latin on the FCC Wiki
ALMY91
@ALMY91
Apr 23 2016 06:53
<html>
<head></head>
<body>

<script type="text/javascript">
var x = "Hello there"
var q= (x!==x);

console.log(q);

</script>
</body>
</html>


}
shouldn this give me true? since x is a string it is a NaN and NaN is not equal to any other values including itself
but im getting false in my console
ALMY91
@ALMY91
Apr 23 2016 06:59
Hi is anyone here?
Punith K
@kpunith8
Apr 23 2016 06:59
when some variable assigned to something how can it contain NaN. in Javascript variable which is undefined will be having NaN, in your case it is not. @ALMY91
ALMY91
@ALMY91
Apr 23 2016 07:00
@kpunith8 what should my code look like?
Spartano
@Spartano
Apr 23 2016 07:03
hello, i am building the Wikipedia Project. Someone avaible for some questions regarding access header?
Punith K
@kpunith8
Apr 23 2016 07:03
I think your comparison is wrong.
@ALMY91
ALMY91
@ALMY91
Apr 23 2016 07:05
@kpunith8 i still don understand
<html>
<head></head>
<body>

<script type="text/javascript">
var x = "Hello there"


console.log(x!==x);

</script>
</body>
</html>


}
@kpunith8 tried this but it isn working still
Punith K
@kpunith8
Apr 23 2016 07:08
how can you check x !== x, compare with another string, for ex, var x="something" and var y; then compare var q=x!==y
@ALMY91
ALMY91
@ALMY91
Apr 23 2016 07:11
@kpunith8 NaN is never equal to any other value, including itself. thats why im checking if x!==x . Because if a NaN it would return true
@kpunith8 if x is a NaN , it wouldn be equal to itself , hence the equation wld return true
is anyone able to help me out on this?
Frank XC
@tenkdayz
Apr 23 2016 07:15
@ALMY91 what's the problem?
ALMY91
@ALMY91
Apr 23 2016 07:15
@tenkdayz my console is returning false with the code i had above. im trying to test if x is a NaN
Frank XC
@tenkdayz
Apr 23 2016 07:16
x!==x ?
that's false
ALMY91
@ALMY91
Apr 23 2016 07:16
<html>
<head></head>
<body>

<script type="text/javascript">
var x = "Hello there"


console.log(x!==x);

</script>
</body>
</html>


}
Frank XC
@tenkdayz
Apr 23 2016 07:16
@ALMY91 yeah x!==x is false..
ALMY91
@ALMY91
Apr 23 2016 07:17
@tenkdayz but if my x is a string, it is NaN, and since NaN is never equal to any value including itself, shdn it return true?
Frank XC
@tenkdayz
Apr 23 2016 07:17
"Hello there" !== "Hello there" .. false they are equal @ALMY91
ALMY91
@ALMY91
Apr 23 2016 07:18
@tenkdayz but wldn it convert to NaN?
@ALMY91 strings are NaN aren they
Frank XC
@tenkdayz
Apr 23 2016 07:18
true "Hello there" is NaN but it is equal to itself..
ALMY91
@ALMY91
Apr 23 2016 07:19
@tenkdayz hmm so how shd i amend my code?
Frank XC
@tenkdayz
Apr 23 2016 07:19
@ALMY91 what do you want it to do?
ALMY91
@ALMY91
Apr 23 2016 07:19
@tenkdayz i wld like to test if my x is a NaN
FraGileFigMent
@FraGileFigMent
Apr 23 2016 07:20
Hi! Could anyone help me with Storing Values with the Assignment Operator?
Frank XC
@tenkdayz
Apr 23 2016 07:20
use isNaN(x);
@ALMY91
ALMY91
@ALMY91
Apr 23 2016 07:20
@tenkdayz if i'd like to test using Script5's way of coding? thats for Script6..
Frank XC
@tenkdayz
Apr 23 2016 07:22
@ALMY91 no idea about that... maybe use typeof ?
@FraGileFigMent a= b; should be the last line.. vara and varb are not declared
Rahul Nayak
@pragyes31
Apr 23 2016 07:24
Hello Campers, stuck in the "falsy bouncer" bonfire. It is throwing the error "ytpeerror: undefined is not a function" Here is my code :
function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  var value;
function falsy (value) {
var bool = Boolean (value);  
}


    arr=arr.filter(falsy(value));
return arr;
  }

bouncer([7, "ate", "", false, 9]);
all the test cases ran succcessfully though

i also wrote this code for the same exercise which sailed me through this exercise but I have very little idea about how it worked :

```

FraGileFigMent
@FraGileFigMent
Apr 23 2016 07:26
@tenkdayz Thank you!
CamperBot
@camperbot
Apr 23 2016 07:26
fragilefigment sends brownie points to @tenkdayz :sparkles: :thumbsup: :sparkles:
Rahul Nayak
@pragyes31
Apr 23 2016 07:26
function bouncer(arr) {
  // Don't show a false ID to this bouncer.

    arr=arr.filter(Boolean);
return arr;
  }

bouncer([7, "ate", "", false, 9]);
CamperBot
@camperbot
Apr 23 2016 07:26
:star: 438 | @tenkdayz | http://www.freecodecamp.com/tenkdayz
Frank XC
@tenkdayz
Apr 23 2016 07:27
@pragyes31 there should be an if statement inside the filter if you want to do it that way
ALMY91
@ALMY91
Apr 23 2016 07:27
@tenkdayz hmmm im trying to make this work tho
Frank XC
@tenkdayz
Apr 23 2016 07:28
@ALMY91 does typeof work in script5 ?
Rahul Nayak
@pragyes31
Apr 23 2016 07:28
@tenkdayz in the first code i shared?
Frank XC
@tenkdayz
Apr 23 2016 07:29
@pragyes31 second
Rahul Nayak
@pragyes31
Apr 23 2016 07:29
the second code worked fine but dont know how. If loop for what? @tenkdayz
ALMY91
@ALMY91
Apr 23 2016 07:29
@tenkdayz i think we should try to convert the string to a number for it to produce NaN
@tenkdayz but im not too sure how to go abt it lol
Frank XC
@tenkdayz
Apr 23 2016 07:30
@pragyes31 oh.. strange..
ALMY91
@ALMY91
Apr 23 2016 07:32
@tenkdayz damn im not too sure how its gonna work thoo.. we need some help from the other guys../
Frank XC
@tenkdayz
Apr 23 2016 07:32
@ALMY91 I'm not sure what the solution would be..
ALMY91
@ALMY91
Apr 23 2016 07:33
@tenkdayz yeah im pretty curious too, been stuck on this all night..
seems abit quiet in here at this time
Frank XC
@tenkdayz
Apr 23 2016 07:37
@ALMY91 I'm stuck trying to make a scoreboard work.. I'm staying up a bit longer.
ALMY91
@ALMY91
Apr 23 2016 07:37
@tenkdayz i was having abit of a fever last night.. supposedly i was supposed to complete 200 pages 'of the definitive guide in another 3hrs time. now im still stuck on page 72!
Frank XC
@tenkdayz
Apr 23 2016 07:43
@ALMY91 does the NaN problem have something to do with where you're stuck?
ALMY91
@ALMY91
Apr 23 2016 07:45
@tenkdayz i went to the other camp side
var x = "Hello there"
x = parseInt(x);

if (x!==x) {
console.log( "x is a NaN");}
else { console.log ( "x is not a NaN")};
@tenkdayz parseInt(x) converts the value to either an Integer or NaN
@tenkdayz it works :)\
Frank XC
@tenkdayz
Apr 23 2016 07:46
@ALMY91 i totally forgot about that one
ALMY91
@ALMY91
Apr 23 2016 07:46
@tenkdayz its my first time coming across this tho..
Frank XC
@tenkdayz
Apr 23 2016 07:48
@ALMY91 I see..
Holic
@Holic101
Apr 23 2016 08:33
Hey everybody I'm currently stuck at the algorithm "Pig Latin". Any idea where my mistake might be?
function translatePigLatin(str) {

  var newStr = "";
  var firstChar = str.charAt(0);
  var secondChar = str.charAt(1);
  //check if first letter is a vowel and if yes put a "way" at the end
  if (/[aeiou]/.test(firstChar)){
    newStr = str.substr(0, str.length) + "way";
  }
  //check if first letter is a vowel and second letter is not a vowel
else if(/[aeiou]/.test(firstChar) && /^[aeiou]/.test(secondChar)){
 newStr = str.substr(1, str.length) + firstChar + "ay";
 }
  //check if first two letters are consonants
  else if(/[aeiou]/.test(firstChar) && /[aeiou]/.test(secondChar)){
 newStr = str.substr(2, str.length) + firstChar + secondChar + "ay";
 }
  return newStr;
}
Dardan Demiri
@dardandemiri
Apr 23 2016 08:40
@Holic101
all you need is one If else statement
// If the first letter of the first word starts with a vowel, add "way" in the end.
str[0].match(regex)
you just return str + "way "
else
// Find the first viwel and count all letters before that.
to find all letters till the first vowel you can use str.indexOf(str.match(regex)[0]);
than just substr the letters before vowel, ad them in the end, and add the word "ay"
Holic
@Holic101
Apr 23 2016 08:46
@dardandemiri thank you, I'll try that approach, sounds easier than what I've tried to do
CamperBot
@camperbot
Apr 23 2016 08:46
holic101 sends brownie points to @dardandemiri :sparkles: :thumbsup: :sparkles:
:star: 356 | @dardandemiri | http://www.freecodecamp.com/dardandemiri
Dardan Demiri
@dardandemiri
Apr 23 2016 08:46
:+1:
elminsterrr
@elminsterrr
Apr 23 2016 08:53

I have a question. Why this code is working?

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

function lookUpProfile(firstName, prop){
 for (i=0; i < contacts.length; i++) {
  if(firstName === contacts[i].firstName) {
    if(contacts[i][prop]) {

      alert("YES!");

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

This condition is like that if(contacts[i][prop]) it gives us in this case if(["Pizza", "Coding", "Brownie Points"]) then alert YES! and it is alerting, but I don't understand WHY if(["Pizza", "Coding", "Brownie Points"]) IS TRUE ? It isn't like if ( 2 === 2) then alert Yes...

Brendan Kinahan
@BKinahan
Apr 23 2016 08:55
it's more like if (2) alert("YES"); Read about truthy/falsy values in javascript :)
ALMY91
@ALMY91
Apr 23 2016 08:56
hi guys im trying to make this code work
elminsterrr
@elminsterrr
Apr 23 2016 08:56
If (2) is true, but If (0) is false, right?
ALMY91
@ALMY91
Apr 23 2016 08:56
<html>
<head></head>
<body>

<script type="text/javascript">
'a'.localeCompare('c'); 


</script>
</body>
</html>
but nth seems to be appearing in my console
Brendan Kinahan
@BKinahan
Apr 23 2016 08:56
correct, falsy values include 0,false,"",null, and undefined
everything else is truthy. if the value of the property you look for happens to be one of the falsy values, the alert won't happen
@ALMY91 try console.log('a'.localeCompare('c'));
elminsterrr
@elminsterrr
Apr 23 2016 09:00
Ok :) so when my profile Lookup wont find that prop this if statment will return undefined and the condition will be false, right? @BKinahan
ALMY91
@ALMY91
Apr 23 2016 09:00
@BKinahan why does it give me -1 tho?
@BKinahan and actually how does it decide whether a string comes before or after? for example

// Alphabetically the word "check" comes after "against" yielding a positive value
'check'.localeCompare('against'); // 2 or 1 (or some other positive value)
@BKinahan im reading it up but i still don really get it
Brendan Kinahan
@BKinahan
Apr 23 2016 09:02
@elminsterrr correct
blackjack90
@ToanPV90
Apr 23 2016 09:02
@ToanPV90
hi there
elminsterrr
@elminsterrr
Apr 23 2016 09:02
@BKinahan Thank you! :smile:
CamperBot
@camperbot
Apr 23 2016 09:02
elminsterrr sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
blackjack90
@ToanPV90
Apr 23 2016 09:02
how can i get json file in the challenge Convert JSON Data to HTML?
file path is '/json/cats.json'
CamperBot
@camperbot
Apr 23 2016 09:02
:star: 1369 | @bkinahan | http://www.freecodecamp.com/bkinahan
blackjack90
@ToanPV90
Apr 23 2016 09:02
thanks
Brendan Kinahan
@BKinahan
Apr 23 2016 09:04

@ALMY91 from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare :

DO NOT rely on exact return values of -1 or 1. Negative and positive integer results vary between browsers (as well as between browser versions) because the W3C specification only mandates negative and positive values. Some browsers may return -2 or 2 or even some other negative or positive value.

@ALMY91 as for sorting, it depends on the options you use and the browser it occurs in. Most likely for you it's simple unicode point order, the same as .sort() uses by default.
blackjack90
@ToanPV90
Apr 23 2016 09:08
@BKinahan Thank you!
CamperBot
@camperbot
Apr 23 2016 09:08
toanpv90 sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star: 1370 | @bkinahan | http://www.freecodecamp.com/bkinahan
ALMY91
@ALMY91
Apr 23 2016 09:11
@BKinahan hey thanks
CamperBot
@camperbot
Apr 23 2016 09:11
almy91 sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star: 1372 | @bkinahan | http://www.freecodecamp.com/bkinahan
Brendan Kinahan
@BKinahan
Apr 23 2016 09:14
No worries :D
ALMY91
@ALMY91
Apr 23 2016 09:23
@BKinahan just curious hv u gone to college for programming?
Brendan Kinahan
@BKinahan
Apr 23 2016 09:24
@ALMY91 Nope, just made a few webpages as a hobby while growing up, got into JavaScript more regularly recently.
Chris Cullen
@123xylem
Apr 23 2016 09:24
QUICK QUESTION: factorialize(num-1) can some1 tell me what the num-1 part means? What does the -1 do to num ?
Brendan Kinahan
@BKinahan
Apr 23 2016 09:25
@123xylem It doesn't do anything to num (the value of the variable is unchanged), but it calls the function factorialize with an argument that is one less than the value of num, aka num-1 ("num minus one")
Chris Cullen
@123xylem
Apr 23 2016 09:29
ah ok
so why does it do that?
its in recursioons
@BKinahan
Brendan Kinahan
@BKinahan
Apr 23 2016 09:30
you mean in the context of factorializing a number? if the rest of the code is as I suspect, it does that because mathematically, for a positive value n, n! == n * (n-1)!
ALMY91
@ALMY91
Apr 23 2016 09:30
@BKinahan cool haha
var point {x:1,y:1};//Define an object
"toString" in point //-->true:object inherits toString method
how does it know that the object inherits the toString method?
Chris Cullen
@123xylem
Apr 23 2016 09:35
@BKinahan what wlu.d
would happen without -1 ?
alpox
@alpox
Apr 23 2016 09:38
@123xylem then you have a number which is n times too much :-)
Michal Sadowski
@micsad
Apr 23 2016 09:38
Hey campers, I'm stuck with golf code challenge in basic Javascript. How do I go about using two arguments / parameters in a function? What value should I assign to "par" in if/else statements to make it flexible? Thanks.
Brendan Kinahan
@BKinahan
Apr 23 2016 09:38
@123xylem an infinite loop, basically
alpox
@alpox
Apr 23 2016 09:39
@123xylem if you take this logic for a recursive algorithm and dont put there the -1 you will have endless recursion
Deepak Yadav
@ydeepk
Apr 23 2016 09:41

Challange name: Slasher

Where i'm doing wrong ? please point out.
Note: Code doesn't work only for this specific instruction : slasher(["burgers", "fries", "shake"], 1) should return ["fries", "shake"].

function slasher(arr, howMany) {
// it doesn't always pay to be first
var temp = [];

if(howMany > 0 && howMany <= arr.length) {

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

  temp = arr.splice(a,howMany,arr.slice(a,howMany));

}

return temp;

} else if(howMany === 0) {

return arr;

} else {

return temp;

}

}

slasher([1, 2, 3], 2);

Edd Yerburgh
@eddyerburgh
Apr 23 2016 09:47
Anyone used the minimax/negamax algorithm for tic tac toe?
x jeremy jarratt
@transmothra
Apr 23 2016 09:49
@micsad you don't want to assign a value to par, you want to compare par to strokes. Par (and strokes) is defined by the arguments being passed to the function. So you want to have something like if (strokes == par-3) {nick = "Hawk";}
Brendan Kinahan
@BKinahan
Apr 23 2016 09:49
@micsad the golfScore function has the parameters par and strokes, and you can use those in your conditional statements without needing to assign them to any other variables
@eddyerburgh Nope, wrote my own algorithm based on the strategy steps on the wikipedia page about TTT
Edd Yerburgh
@eddyerburgh
Apr 23 2016 09:50
@BKinahan really? Is it recursive?
Brendan Kinahan
@BKinahan
Apr 23 2016 09:51
@eddyerburgh it looks one step ahead if it needs to, if that's what you mean
@eddyerburgh luckily tic tac toe is a pretty simple game
Edd Yerburgh
@eddyerburgh
Apr 23 2016 09:51
@BKinahan no I mean does it call itself, I'm having trouble getting my head round it :S
x jeremy jarratt
@transmothra
Apr 23 2016 09:52
speaking of the golf code challenge, for fun i'm trying to see if i can write a switch/case instead of if/else. This is what i have but it doesn't work for (4,2) or (5,2). What am i doing wrong?
  switch(strokes) {
    case 1: 
      nick = "Hole-in-one!";
      break;
    case (strokes <= par-2):
      nick = "Eagle";
      break;
    case par-1:
      nick = "Birdie";
      break;
    case par:
      nick = "Par";
      break;
    case par+1:
      nick = "Bogey";
      break;
    case par+2:
      nick = "Double Bogey";
      break;
    case (strokes >= par+3):
      nick = "Go Home!";
      break;
  }
  return nick;
Brendan Kinahan
@BKinahan
Apr 23 2016 09:52
@eddyerburgh ah, no. It's basically a series of conditionals that returns the best free space to mark, and stops after finding the best. it has to get called for each turn, basically each time the player has made their move
Michal Sadowski
@micsad
Apr 23 2016 09:53
@BKinahan thanks. This helps a lot. No need to touch "par" then.
CamperBot
@camperbot
Apr 23 2016 09:53
micsad sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star: 1373 | @bkinahan | http://www.freecodecamp.com/bkinahan
Edd Yerburgh
@eddyerburgh
Apr 23 2016 09:54
@BKinahan ah ok, I was going to do that but stumbled across minimax so I want to implement that now. It still has to get called each turn, it's probably less efficient than a series of if/ else statements :P but you can apply the theory to make AI in any zero sum game.
I get the theory now, but it's trying to convert the pseudocode into JavaScript I'm finding difficult
Brendan Kinahan
@BKinahan
Apr 23 2016 09:54
@eddyerburgh "Is there a game-winning move? If not, is there a move needed to stop the opponent from winning? If not, is there a move that stops the opponent from setting up a fork on the next turn? If not, is there a move that lets me set up a fork so I win on the next turn?" .. etc
Edd Yerburgh
@eddyerburgh
Apr 23 2016 09:55
@BKinahan can I see your codepen?
FraGileFigMent
@FraGileFigMent
Apr 23 2016 09:55
Could anyone help me with Increment a Number with JavaScript?
Brendan Kinahan
@BKinahan
Apr 23 2016 09:55
@eddyerburgh don't have it on codepen, but I'll post a jsfiddle if you like
Edd Yerburgh
@eddyerburgh
Apr 23 2016 09:56
@BKinahan thanks
CamperBot
@camperbot
Apr 23 2016 09:56
eddyerburgh sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star: 1374 | @bkinahan | http://www.freecodecamp.com/bkinahan
Edd Yerburgh
@eddyerburgh
Apr 23 2016 09:56
@FraGileFigMent replace i with myVar and follow the instructions
Stephane
@overmelo
Apr 23 2016 09:57
function largestOfFour(arr) {
  // You can do this!

  var maxArr=[];

  for (e=0; e<=arr.length; e++){

    if (arr[e] > maxArr ){

      maxArr = arr[e];
    }

  }

  return arr;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
hello can someone tell me whats wrong here
FraGileFigMent
@FraGileFigMent
Apr 23 2016 09:58
@eddyerburgh where to put the ++?
Edd Yerburgh
@eddyerburgh
Apr 23 2016 10:00
@FraGileFigMent if i++ is in the example code and I said replace i with myVar, where do you think you put the ++?
FraGileFigMent
@FraGileFigMent
Apr 23 2016 10:01
I tried var myVar = myVar ++; but it didn't past
Edd Yerburgh
@eddyerburgh
Apr 23 2016 10:01
@overmelo maxVar is never going to be bigger than maxArr becuase arr is an array
@FraGileFigMent just write myVAr++
You want to create a remporary variable to store the largest number from each array in.
Then at the end of the loop push that number to a new array
But because you're going through nested arrays you need two loops
Stephane
@overmelo
Apr 23 2016 10:05
alright i will try that
x jeremy jarratt
@transmothra
Apr 23 2016 10:06
@FraGileFigMent you have a space between myVar and ++
take that out
Edd Yerburgh
@eddyerburgh
Apr 23 2016 10:10
@transmothra the space doesn't matter, the problem is him assigning var myVar to myVar ++ . If you just write myVar++ or myVar ++ it will pass
AnnemiekeNL
@AnnemiekeNL
Apr 23 2016 10:10
wiki sumAll
CamperBot
@camperbot
Apr 23 2016 10:10
no wiki entry for: sumall
Edd Yerburgh
@eddyerburgh
Apr 23 2016 10:11
@transmothra whitespace pretty much only matters between keywords and their value
John O'Connell
@IAmJohnOconnell
Apr 23 2016 10:12
Working on the FCC JS Fahrenheit/Celsius challenge can anyone lend a hand?
Edd Yerburgh
@eddyerburgh
Apr 23 2016 10:12
@IAmJohnOconnell yeah, what's the problem
x jeremy jarratt
@transmothra
Apr 23 2016 10:12
@eddyerburgh ah cool thanks, i didn't know that
CamperBot
@camperbot
Apr 23 2016 10:12
transmothra sends brownie points to @eddyerburgh :sparkles: :thumbsup: :sparkles:
:star: 375 | @eddyerburgh | http://www.freecodecamp.com/eddyerburgh
Robert Uivarosi
@URobert
Apr 23 2016 10:13
@IAmJohnOconnell where you at/
John O'Connell
@IAmJohnOconnell
Apr 23 2016 10:13
Convert Celsisus to Fahrenheit
i defined the variable fahrenheit with the algorithm they provided 9/5+2 however when i change the inputs to test the code it dosent output correctly.
Robert Uivarosi
@URobert
Apr 23 2016 10:14
@IAmJohnOconnell go the helpfrontend page. I just wrote a long answer for another camper
@IAmJohnOconnell oh, that is a challenge, not project, right? Let me see your code.
Chris Cullen
@123xylem
Apr 23 2016 10:15
@alpox @BKinahan thanks
CamperBot
@camperbot
Apr 23 2016 10:15
123xylem sends brownie points to @alpox and @bkinahan :sparkles: :thumbsup: :sparkles:
:star: 1375 | @bkinahan | http://www.freecodecamp.com/bkinahan
:star: 592 | @alpox | http://www.freecodecamp.com/alpox
John O'Connell
@IAmJohnOconnell
Apr 23 2016 10:19

' ' ' function convertToF(celsius) {
// Only change code below this line
var celsius = 9/5 + 32;
var fahrenheit = celsius;

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

llamatarianism
@llamatarianism
Apr 23 2016 10:21
@IAmJohnOconnell use these ` not those '
@IAmJohnOconnell also you're misunderstanding the formula
John O'Connell
@IAmJohnOconnell
Apr 23 2016 10:21
can't find that key (feeling dumb, sorry guys)
llamatarianism
@llamatarianism
Apr 23 2016 10:22
you have to MULTIPLY the celsius value by 9/5 + 32 to get fahrenheit
well multiply and then add
Robert Uivarosi
@URobert
Apr 23 2016 10:22
This message was deleted
llamatarianism
@llamatarianism
Apr 23 2016 10:23
what you've written is roughly this: `var celsius = 33.8
also you shouldn't redeclare celsius in there
it's already defined in your function's parameters
just write: var fahrenheit = celsius * 9 / 5 + 32
ALMY91
@ALMY91
Apr 23 2016 10:25
hello..
Robert Uivarosi
@URobert
Apr 23 2016 10:25
@IAmJohnOconnell I didn't want to give the code away. Basically celsius will be the paramenter of your function and the formula ( as state by @llamatarianism above) is var fahrenheit = (celsius * 9) / 5 + 32;
@ALMY91 hi
llamatarianism
@llamatarianism
Apr 23 2016 10:25
also the key should be right next to 1 on your keyboard
ALMY91
@ALMY91
Apr 23 2016 10:25
@URobert Hi im trying to get help still haha
llamatarianism
@llamatarianism
Apr 23 2016 10:25
it might not be, idk if it's on foreign keyboards
Robert Uivarosi
@URobert
Apr 23 2016 10:26
@ALMY91 sorry I'm on multiple channels
John O'Connell
@IAmJohnOconnell
Apr 23 2016 10:26
Thank you! couldn't find that little bugger. I'll take another whack at it, Thanks guys.
Robert Uivarosi
@URobert
Apr 23 2016 10:26
@IAmJohnOconnell yw, happy coding
llamatarianism
@llamatarianism
Apr 23 2016 10:26
@ALMY91 what seems to be the problem
ALMY91
@ALMY91
Apr 23 2016 10:26
@URobert me too.. couldn get a response from the guys :(
Robert Uivarosi
@URobert
Apr 23 2016 10:27
@ALMY91 for what do you want to use that ?
ALMY91
@ALMY91
Apr 23 2016 10:28
im just reading the definitive guide.. happen to come across this but im not too sure how is this actually useful? and another thing is how is it sure that the object inherits toString method and not valueOf method?
@URobert
llamatarianism
@llamatarianism
Apr 23 2016 10:29
@ALMY91 what object are we talking about here
ALMY91
@ALMY91
Apr 23 2016 10:29

var point ={x:1,y:1};
@llamatarianism here it is. and the next line of code is "toString" in point.
Robert Uivarosi
@URobert
Apr 23 2016 10:30
@ALMY91 , @llamatarianism will help you out. I gtg... my battery is dead. If you can't get your answers, leave me a pm... and I'll get back to you when I get back. GL !
John O'Connell
@IAmJohnOconnell
Apr 23 2016 10:30
Went back and fixed it after realizing my errors. Thanks for the help guys.
ALMY91
@ALMY91
Apr 23 2016 10:30
@llamatarianism which gave a true , that the object inherits a toString method.
@URobert okay thanks!
CamperBot
@camperbot
Apr 23 2016 10:31
almy91 sends brownie points to @urobert :sparkles: :thumbsup: :sparkles:
Robert Uivarosi
@URobert
Apr 23 2016 10:31
@IAmJohnOconnell you`re welcome , use @ when mentioning people :)
llamatarianism
@llamatarianism
Apr 23 2016 10:31
wait like, point.toString()?
CamperBot
@camperbot
Apr 23 2016 10:31
:star: 817 | @urobert | http://www.freecodecamp.com/urobert
Robert Uivarosi
@URobert
Apr 23 2016 10:31
I'm out
ALMY91
@ALMY91
Apr 23 2016 10:31
@llamatarianism nope "toString" in point
@llamatarianism its using the in operator
x jeremy jarratt
@transmothra
Apr 23 2016 10:34
Golf Code challenge: i'm trying to see if i can write a switch/case instead of if/else. This is what i have but it doesn't work for (4,2) or (5,2) or (4,7) or (5,9). What am i doing wrong?
  switch(strokes) {
    case 1: 
      nick = "Hole-in-one!";
      break;
    case (strokes <= par-2):
      nick = "Eagle";
      break;
    case par-1:
      nick = "Birdie";
      break;
    case par:
      nick = "Par";
      break;
    case par+1:
      nick = "Bogey";
      break;
    case par+2:
      nick = "Double Bogey";
      break;
    case (strokes >= par+3):
      nick = "Go Home!";
      break;
  }
  return nick;
ALMY91
@ALMY91
Apr 23 2016 10:34
anyone able to help out?
llamatarianism
@llamatarianism
Apr 23 2016 10:36
@ALMY91 the only thing that's confusing me is, you said it returns false for valueOf
ALMY91
@ALMY91
Apr 23 2016 10:37
@llamatarianism nope ive nv tried valueOf yet
llamatarianism
@llamatarianism
Apr 23 2016 10:37
oh really? just my shit memory? HM
well in that case
ALMY91
@ALMY91
Apr 23 2016 10:37
@llamatarianism i meant i don understand how does it know to return true? and tt the object utilizes the toString method
llamatarianism
@llamatarianism
Apr 23 2016 10:38
I believe the reason it returns true for toString is that all objects have that property
it's part of the object prototype
ALMY91
@ALMY91
Apr 23 2016 10:38
@llamatarianism LOL thats all?
llamatarianism
@llamatarianism
Apr 23 2016 10:38
so whenever you create any object (a literal object, a number, a string)
it gets that function
Eldar Tinjić
@EldarT90
Apr 23 2016 10:46
function sym(args) {
    var argues = [].slice.call(arguments);
    var newArr = [];

  var reducing = argues.reduce(function(a,b) {
     for (var i=0;i<a.length;i++) {
       if (b.indexOf(a[i]) !== -1) {
         newArr.push(a[i]);
       }
     }
  });
  return reducing;
}  

sym([1, 2, 3], [5, 2, 1, 4]);
is this good start or not so much
?
llamatarianism
@llamatarianism
Apr 23 2016 10:47
@EldarT90 this is meant to find the symmetric difference, right?
Rahul Nayak
@pragyes31
Apr 23 2016 10:47
any hint for "seek and destroy" bonfire? I am trying to run a loop argument.length times but stuck of the next step. any hint to move forward?
llamatarianism
@llamatarianism
Apr 23 2016 10:49
@pragyes31 can you post your code here so we can see what you mean?
Eldar Tinjić
@EldarT90
Apr 23 2016 10:49
@llamatarianism yes
@llamatarianism but even though it prolly had mistakes, is it good start?
llamatarianism
@llamatarianism
Apr 23 2016 10:49
@EldarT90 yeah it actually is
remove the reduce part
but keep the for loop and everything inside it
then return newArr
and I think it'll work
so remove these lines:
var reducing = argues.reduce(function(a, b) {

});
replace them with a for loop or a foreach
argues.forEach(function(a) {
  // loop goes here
});
wait hold on
x jeremy jarratt
@transmothra
Apr 23 2016 10:51
anybody know what i've got wrong in my switch/case above?
Eldar Tinjić
@EldarT90
Apr 23 2016 10:52
oke im waiting ^^
llamatarianism
@llamatarianism
Apr 23 2016 10:52
@EldarT90 are you sure you'll only ever get 2 arguments to your function?
or could you also get 3 or 4?
Eldar Tinjić
@EldarT90
Apr 23 2016 10:52
@llamatarianism 3 or 4 is possibility
llamatarianism
@llamatarianism
Apr 23 2016 10:53
@EldarT90 hmm. in that case, I'd recommend a different approach
Eldar Tinjić
@EldarT90
Apr 23 2016 10:54
so i should delete everything ? @llamatarianism
llamatarianism
@llamatarianism
Apr 23 2016 10:54
@EldarT90 I'd use concat.apply to flatten your arguments into one array
var flatArray = [].concat.apply([], argues);
no, not everything
Eldar Tinjić
@EldarT90
Apr 23 2016 10:54
but thing is it wants difference between not all 3 or 4
but between 1 and 2 and than between 12 and 3 and then between 123 and 4
so it wont be same as if i create 1 big array
llamatarianism
@llamatarianism
Apr 23 2016 10:55
ahhh
Eldar Tinjić
@EldarT90
Apr 23 2016 10:55
and make difference inside it
llamatarianism
@llamatarianism
Apr 23 2016 10:55
uhh sorry @EldarT90 but I think the reduce might have actually been correct :D I didn't take that part into account
it's just a bit of an odd way to use reduce. not that it's not a good use of it!
Eldar Tinjić
@EldarT90
Apr 23 2016 10:55
@llamatarianism oke ^^ so lets back to the start :
function sym(args) {
    var argues = [].slice.call(arguments);
    var newArr = [];

  var reducing = argues.reduce(function(a,b) {
     for (var i=0;i<a.length;i++) {
       if (b.indexOf(a[i]) !== -1) {
         newArr.push(a[i]);
       }
     }
  });
  return reducing;
}  

sym([1, 2, 3], [5, 2, 1, 4]);
is it still make sense? :D
llamatarianism
@llamatarianism
Apr 23 2016 10:57
@EldarT90 yeah, and like I said, if you remove var reducing = (keep the argues.reduce part) and return newArr instead of reducing
it works with 2 arrays
but it seems to break with 3
Eldar Tinjić
@EldarT90
Apr 23 2016 10:59
function sym(args) {
    var argues = [].slice.call(arguments);
    var newArr = [];

  argues.reduce(function(a,b) {
     for (var i=0;i<a.length;i++) {
       if (b.indexOf(a[i]) !== -1) {
         newArr.push(a[i]);
       }
     }
  });
 return newArr;
}  

sym([1, 2, 3], [5, 2, 1, 4]);
you mean like this ??
alpox
@alpox
Apr 23 2016 11:00
@EldarT90 @llamatarianism using reduce with only a push inside looks to me like cruelty :D
sunshuhan
@sunshuhan
Apr 23 2016 11:00
@EldarT90 you can write a function that return the symmetric difference of two arrays ,and return arg.reduce(function(a,b){
return sym2(a,b);
Eldar Tinjić
@EldarT90
Apr 23 2016 11:01
@alpox hey mate ^^
@sunshuhan so that would work for 3?
sunshuhan
@sunshuhan
Apr 23 2016 11:02
@EldarT90 yes, i solved this problem just yesterday
alpox
@alpox
Apr 23 2016 11:02
@EldarT90 @sunshuhan Presents you a good way to do that :-) you can also do the work for her sym2 inside of reduce like now though
@EldarT90 I would put the newArr and push declaration inside the reduce and return the newArr from the callback to reduce
Rahul Nayak
@pragyes31
Apr 23 2016 11:02
@llamatarianism sure
it's wrong i guess on so many levels :(
function destroyer(arr) {
  // Remove all the values
  var array= arguments[0];
  for (i=1;i<arguments.length; i++) {
    arr = arr.filter(sad());
  }
  function sad() {
       for (j=0; j<array.length;j++) {
        if (array[j] == arguments[i]) {
          return false;
        }

       }       
  }
  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Eldar Tinjić
@EldarT90
Apr 23 2016 11:03
im not sure if i follow all the hints, let me try fixing it bit^^
alpox
@alpox
Apr 23 2016 11:03
@EldarT90 And redo what @llamatarianism meant :D (Sorry mate)
llamatarianism
@llamatarianism
Apr 23 2016 11:04
@pragyes31 trying to help @EldarT90 right now but 2 things that are immediately wrong:
you never return true in the function you use to filter the array
and you don't use () after a function if it's an argument to a function
Eldar Tinjić
@EldarT90
Apr 23 2016 11:04
@alpox but push is already inside reduce, isnt it ? the whole loop is inside