These are chat archives for FreeCodeCamp/HelpJavaScript

28th
Jun 2017
SaiChand Duppala
@saichandd
Jun 28 2017 00:01
@Carowyn why did you give a parameter of setGear in getGear and getGear in setGear
Kevin Anderson
@LemonStain
Jun 28 2017 00:01
@roxroy thank you. trying htat now.
CamperBot
@camperbot
Jun 28 2017 00:01
lemonstain sends brownie points to @roxroy :sparkles: :thumbsup: :sparkles:
:star2: 1041 | @roxroy |http://www.freecodecamp.com/roxroy
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:02
@Carowyn getGear is what you might hear referred to as a "getter". It is used to return a certain object property without making modifications, and in this case its function does not need a parameter. You say return setGear, but what you really want to return is your bike's gear property.
What is your bike's gear property called?
Hint, car's speed property is called speed.
Kevin Anderson
@LemonStain
Jun 28 2017 00:02
@Shadilix if i =0 and num = 0, the code is going to stop running and be 0. you need to set a starting point for "i" as well
Brittani
@Carowyn
Jun 28 2017 00:02
myBike.getGear() should return 4 after calling myBike.setGear(4).
myBike.getGear() should return 3 after calling myBike.setGear(3).
myBike.getGear() should return 1 after calling myBike.setGear(1).
Ahmed Ramy
@Shadilix
Jun 28 2017 00:03
@LemonStain oh such a tricky mistake here :D
Kevin Anderson
@LemonStain
Jun 28 2017 00:03
@Shadilix like for (var i = 0; i <= x; i++) {}
Brittani
@Carowyn
Jun 28 2017 00:03
@imRadioactive I did that because it said that if you call one it should saet the other
SaiChand Duppala
@saichandd
Jun 28 2017 00:03
@Carowyn setGear(x) changes the gear, then getGear() will return whatever you set it as
Brittani
@Carowyn
Jun 28 2017 00:04
so my gears property is var gear...So I set with setGear, and have it change var gear, and then have the getGear return?
Ahmed Ramy
@Shadilix
Jun 28 2017 00:05
@LemonStain now it says that there is a potential for an infinte loop
@LemonStain can u help me fix this code ?
Jun
@kysnazz
Jun 28 2017 00:06
console.log(0.6*6) // OutPut 3.5999999999999996
//How to fix this equal to 3.6 ?
Ahmed Ramy
@Shadilix
Jun 28 2017 00:06
am very sure that to factorize a number i'll need a loop for sure
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:06
@Shadilix post updated code
Ahmed Ramy
@Shadilix
Jun 28 2017 00:07
function factorialize(num) {

  for (var i = 1; i <= num ; i++)
    {
      num = num *i;
    }
  var factor;
  num = factor;
  return factor;
}

factorialize(5);
SaiChand Duppala
@saichandd
Jun 28 2017 00:07
@imRadioactive when you create a new Bike() you need to give it a gear, later you can change it with setGear(), after a change you may get the gear with getGear()
Max
@maxiwer
Jun 28 2017 00:07
GOod mornign guys. How to get a propertues from this object ? And am I right is 'contacts' object or it's just an arrray;
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"]
}
];
for example if I want to get all number properties from contacs how should I write?
SaiChand Duppala
@saichandd
Jun 28 2017 00:07
@Carowyn when you create a new Bike() you need to give it a gear, later you can change it with setGear(), after a change you may get the gear with getGear()
Flashtzu
@Flashtzu
Jun 28 2017 00:08
function caseInSwitch(val) {
var answer = "";
// Only change code below this line
switch (val) {
case "alpha";
val = "alpha";
break;
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:08
@kysnazz It's because binary is being used behind the scenes to represent those decimal numbers, which unfortunately isn't perfectly precise. You just so happen to have stumbled upon one of those cases.
Flashtzu
@Flashtzu
Jun 28 2017 00:08
what does it want for case?
SaiChand Duppala
@saichandd
Jun 28 2017 00:09
@maxiwer contacts is an array, it contains objects
Manish Giri
@Manish-Giri
Jun 28 2017 00:09
@Flashtzu you should assign to answer, not to val
Ahmed Ramy
@Shadilix
Jun 28 2017 00:09

function factorialize(num) {

  for (var i = 1; i <= num ; i++)
    {
      num = num *i;
      if (i == num)
      {
        break;
      }
    }
  var factor;
  num = factor;
  return factor;
}

factorialize(5);
@kumquatfelafel
Flashtzu
@Flashtzu
Jun 28 2017 00:10
ok thanks
SaiChand Duppala
@saichandd
Jun 28 2017 00:10
@maxiwer to get all the number properties you write a loop and call contacts[i].number
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:10
@Shadilix num is likely increasing faster than i, ergo infinite loop
Ahmed Ramy
@Shadilix
Jun 28 2017 00:11
aw man ...
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:11
@Shadilix 5! = 5 * 4 * 3 * 2 * 1, right?
Ahmed Ramy
@Shadilix
Jun 28 2017 00:11
yea
Brittani
@Carowyn
Jun 28 2017 00:12
thanks @imRadioactive
CamperBot
@camperbot
Jun 28 2017 00:12
carowyn sends brownie points to @imradioactive :sparkles: :thumbsup: :sparkles:
:cookie: 296 | @imradioactive |http://www.freecodecamp.com/imradioactive
Brittani
@Carowyn
Jun 28 2017 00:12
thanks @kumquatfelafel
CamperBot
@camperbot
Jun 28 2017 00:12
carowyn sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 374 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Brittani
@Carowyn
Jun 28 2017 00:12
Finally got my head wrapped around it. :)
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:12
so... what if we started at the end and tried going towards 0? @Shadilix
Julianne Cho
@jucho893
Jun 28 2017 00:13
Hi guys,
are multiple if statements allowed?
Max
@maxiwer
Jun 28 2017 00:13
@imRadioactive thank you but I'm still don't understand
CamperBot
@camperbot
Jun 28 2017 00:13
maxiwer sends brownie points to @imradioactive :sparkles: :thumbsup: :sparkles:
:cookie: 297 | @imradioactive |http://www.freecodecamp.com/imradioactive
Ahmed Ramy
@Shadilix
Jun 28 2017 00:13
@kumquatfelafel like 0!=1 ?
SaiChand Duppala
@saichandd
Jun 28 2017 00:13
@maxiwer what is that you didnt understand
@Shadilix yes 0! = 1
Julianne Cho
@jucho893
Jun 28 2017 00:14
function fizzBuzz(number) {    
    var results = [];

    for(var i = 1; i <= number; i++) {

        if((i % 3 !== 0) && (i % 5 !== 0)) {
            results.push(i);

        } else if (i % 3 === 0) {
            results.push("FIZZ");

         } if (i % 5 === 0){
         results.push("BUZZ");

     }  if((i % 3 === 0) && (i % 5 === 0)){
        results.push("FIZZBUZZ");
    }
    return results;
}
Ahmed Ramy
@Shadilix
Jun 28 2017 00:14
easy , an if statement where if num == 0 , return 1
@kumquatfelafel
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:14
@Shadilix nothing to do with that. The value num is changing as you go through your for loop, right? But does the value of 0 ever change?
Ahmed Ramy
@Shadilix
Jun 28 2017 00:15
ummm ... no
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:15
currently, you're trying to start 5! with 1 and going up. What if we started 5! with 5 and went down?
Ahmed Ramy
@Shadilix
Jun 28 2017 00:15
i tried that but here is the problem
its setting i
like in a for loop
for ( var i ; ?? <= num ; i--)
am stuck with this one so thats why i tried the other way around which is a definite infinite loop
Nick Cleary
@Hijerboa
Jun 28 2017 00:16
quick question: is there a way to use .replace() in order to replace any non-alphanumberic character with null, or must I use .replace() for each and every one seperately?
Manish Giri
@Manish-Giri
Jun 28 2017 00:17
@Hijerboa you can use a regex
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:17
@Shadilix
With regards to starting point: Say we're doing 5!. What is num?
With regards to condition (when to stop): For the factorial of anything, do we multiply by 0? How about 1?
Nick Cleary
@Hijerboa
Jun 28 2017 00:18
@Manish-Giri ok thank you
CamperBot
@camperbot
Jun 28 2017 00:18
hijerboa sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6136 | @manish-giri |http://www.freecodecamp.com/manish-giri
Ahmed Ramy
@Shadilix
Jun 28 2017 00:19
num is the number we want to factoralize in case of 5! , num = 5
and no we dont multiply any factorial by 0 but 1 is viable but expendable
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:19

1 is viable but expendable

good. Not everyone might catch that ;)

@Shadilix So if we're starting at end and working backwards, could num give us our starting point?
Joseph
@revisualize
Jun 28 2017 00:21
Hey hey.
Ahmed Ramy
@Shadilix
Jun 28 2017 00:21
thanks :D
i am trying something , will show u in a bit
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:21
hi
Ahmed Ramy
@Shadilix
Jun 28 2017 00:22
function factorialize(num) {
  if (num === 0)
    {
      return 1;
    }
  for (var i = num ; i >=2 ; i--)
    {
      num *= i;
    }
}
ohh that also didnt work
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:23
@Shadilix
1.where's your return?
2.what happens when num = 1?
Joseph
@revisualize
Jun 28 2017 00:23
@Shadilix You know.. It's actually better to count up than to count down.
Saif Ur Rahman
@saifsmailbox98
Jun 28 2017 00:23
@Shadilix you are not returning after the for loop and you can put the for loop inside an else.
Joseph
@revisualize
Jun 28 2017 00:23
@Shadilix If you count down you could end up with a problem where you break below the loop.
@Shadilix You also don't have a return statement for your function.
@Shadilix You have one if the value of num is 0. But, you don't have one for anything else.
Ahmed Ramy
@Shadilix
Jun 28 2017 00:24
opps yea i forgot the return
but when i used the counting "up" ... i ended up with an infinite loop
Stephen James
@sjames1958gm
Jun 28 2017 00:24
@Shadilix And you are multiplying by num twice
@Shadilix Did you grow num and try to stop at num?
Ahmed Ramy
@Shadilix
Jun 28 2017 00:25
@Shadilix Did you grow num and try to stop at num?
what ? XD
Saif Ur Rahman
@saifsmailbox98
Jun 28 2017 00:26
@Shadilix you are also multiplying num with num in the first run
Stephen James
@sjames1958gm
Jun 28 2017 00:26
@sjames1958gm i < num while also doing num *= i
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:26
@Shadilix he means, did you have something like i <= num or whatever... which you had
Ahmed Ramy
@Shadilix
Jun 28 2017 00:27
um shouldnt that code be like
num = 5
then
i = 5
then what happens in the loop is
543*2?
Saif Ur Rahman
@saifsmailbox98
Jun 28 2017 00:27
5 * 5 * 4 * 3 * 2
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:27
@Shadilix num is already 5, so this happens ^^^
Ahmed Ramy
@Shadilix
Jun 28 2017 00:27
function factorialize(num) {
  if (num === 0)
    {
      return 1;
    }
  for (var i = num -1 ; i >=2 ; i--)
    {
      num *= i;
    }
  return num;
}

factorialize(1);
that worked ! :D
Stephen James
@sjames1958gm
Jun 28 2017 00:28
@Shadilix :+1:
Saif Ur Rahman
@saifsmailbox98
Jun 28 2017 00:28
:+1:
Ahmed Ramy
@Shadilix
Jun 28 2017 00:28
thanks !!!!
@saifsmailbox98 @saifsmailbox98 @kumquatfelafel
CamperBot
@camperbot
Jun 28 2017 00:28
shadilix sends brownie points to @saifsmailbox98 and @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 375 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:cookie: 636 | @saifsmailbox98 |http://www.freecodecamp.com/saifsmailbox98
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:28
@Shadilix what you can also do is create another variable to store the product. That way, you can go up or down with ease without modifying num.
Ahmed Ramy
@Shadilix
Jun 28 2017 00:28
how so ?
@sjames1958gm thanks !
CamperBot
@camperbot
Jun 28 2017 00:29
shadilix sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7935 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:30
@Shadilix you'd just have something like...
function factorialize(num) {
  var factorial =1;
  for (var i = 2; i <= num ; i++)
  {
      factorial *= i;
  }
  return factorial;
}
Ahmed Ramy
@Shadilix
Jun 28 2017 00:31
oh , i tried that but for some reason it didnt work ...
hold on i'll try it again before going for the next challenge
Roxroy
@roxroy
Jun 28 2017 00:32
@kysnazz , you can round the number to 2 decimal places
console.log( ( 0.6*6).toFixed(2) ) // OutPut 3.60
CamperBot
@camperbot
Jun 28 2017 00:33
:bulb: to format code use backticks! ``` more info
Ahmed Ramy
@Shadilix
Jun 28 2017 00:33
@kumquatfelafel
function factorialize(num) {
  var factorial = 1;
  for (var i =2 ; i <= num ; i++)
    {
      factorial = num*i;
    }
  return factorial;
}
it doesnt work
Nick Cleary
@Hijerboa
Jun 28 2017 00:33
'''
CamperBot
@camperbot
Jun 28 2017 00:33
:bulb: to format code use backticks! ``` more info
Saif Ur Rahman
@saifsmailbox98
Jun 28 2017 00:33
CamperBot
@camperbot
Jun 28 2017 00:34
:bulb: to format code use backticks! ``` more info
Nick Cleary
@Hijerboa
Jun 28 2017 00:34
can someone tell me why my code isn't working?
function palindrome(str) {
  str.toLowerCase();
  var workingString = str.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, '');
  var splitup = workingString.split("");
  var reversed = splitup.reverse();
  var joined = reversed.join("");
  var newString = joined;
  if(newString === str){
    return true;
  } else {
    return false;
  }

}
It works for anything without special characters
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:35
@Hijerboa I would avoid having something like that in your replace function. Take a closer look at what's available for regex https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
Nick Cleary
@Hijerboa
Jun 28 2017 00:37
I tried something like .replace(/[^\w\s]/gi, '') which should replace all special characters will null I believe but that didn't work either
Coy Sanders
@coymeetsworld
Jun 28 2017 00:37
\w includes whitespace
http://regexr.com/ can test out regex here
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:38
@Hijerboa One thing I will say is that strings are immutable. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase
As a result, your toLowerCase actually does not change your original string, but returns a new string that you do nothing with.
Moisés Man
@moigithub
Jun 28 2017 00:39
\w includes _
soo that regex will KEEP _ @Hijerboa and spaces
Nick Cleary
@Hijerboa
Jun 28 2017 00:39
@kumquatfelafel so I should make an new variable with the toLowerCase, like I did with the replace?
@moigithub ah ok thank you
CamperBot
@camperbot
Jun 28 2017 00:40
hijerboa sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3439 | @moigithub |http://www.freecodecamp.com/moigithub
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:41
@Hijerboa You don't necessarily need to create a new variable for everything you do. You can also chain your functions or reassign into old variables.
Saif Ur Rahman
@saifsmailbox98
Jun 28 2017 00:42
@Hijerboa you are comparing with str, it contains non-alphanumeric characters.
reverse() changes the original array.
toLowerCase() only returns the lowercased vaue.
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:44
For example, since toLowerCase returns a string, you can actually call it then call replace on that returned string immediately afterwards.
str = str.toLowerCase().replace(blahblahblah);
Nick Cleary
@Hijerboa
Jun 28 2017 00:44
function palindrome(str) {
  var newString = str.toLowerCase().replace(/[^a-z]/gi, '').split("").reverse().join();
  if(newString === str){
    return true;
  } else {
    return false;
  }

}
this is my new code and it isn't working. I chained the expressions like you said @kumquatfelafel
Saif Ur Rahman
@saifsmailbox98
Jun 28 2017 00:45
@Hijerboa [^a-z0-9]
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:45
^. You want to keep numbers as well.
Saif Ur Rahman
@saifsmailbox98
Jun 28 2017 00:45
join need a paramater join("")
Nick Cleary
@Hijerboa
Jun 28 2017 00:46
fixed those issues... still won't work with anything with a non-alpha numeric character
Saif Ur Rahman
@saifsmailbox98
Jun 28 2017 00:47
@Hijerboa you first need to lowercase and replace all non-alphanumeric character from str and assign it back to str, so that later you can compare with it.
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:47

^this as well.

You can also say return newString === str. That's logically equivalent to your if-else return statements.

Nick Cleary
@Hijerboa
Jun 28 2017 00:49
@saifsmailbox98 @kumquatfelafel that worked for all but one of them
function palindrome(str) {
  str = str.toLowerCase().replace(/[^a-z]/gi, '');
  var newString = str.toLowerCase().replace(/[^a-z]/gi, '').split("").reverse().join("");

  if(newString === str){
    return true;
  } else {
    return false;
  }

}
Moisés Man
@moigithub
Jun 28 2017 00:49
@Hijerboa u need to KEEP numbers too
Saif Ur Rahman
@saifsmailbox98
Jun 28 2017 00:49
@Hijerboa :point_up: June 28, 2017 6:15 AM
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:50
@Hijerboa [^a-z0-9]
Nick Cleary
@Hijerboa
Jun 28 2017 00:50
facepalm I added that then removed it on accident later
Saif Ur Rahman
@saifsmailbox98
Jun 28 2017 00:50
@Hijerboa str is already lowercased and you have already removed non-alphanumeric characters
Nick Cleary
@Hijerboa
Jun 28 2017 00:50
thank you guys....
Moisés Man
@moigithub
Jun 28 2017 00:50
@Hijerboa if u have already a "cleaned" str.. u can reuse it..
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:50
@Hijerboa you also don't need to do the tolower/replace again :p
Nick Cleary
@Hijerboa
Jun 28 2017 00:50
thank you so much @moigithub @saifsmailbox98 @kumquatfelafel
CamperBot
@camperbot
Jun 28 2017 00:50
hijerboa sends brownie points to @moigithub and @saifsmailbox98 and @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 376 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:warning: hijerboa already gave moigithub points
:cookie: 637 | @saifsmailbox98 |http://www.freecodecamp.com/saifsmailbox98
Moisés Man
@moigithub
Jun 28 2017 00:50
no need to call replace and tolowercase again
also... this comparison (newString === str return a boolean value true or false..
soo u can directly return the result of that
return newString === str; @Hijerboa
and remove the if
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:51
hahaha... this is what happens when there are too few people asking questions ^^^ :P
Nick Cleary
@Hijerboa
Jun 28 2017 00:51
removed the second instance of .replace and .toLowerCase :P
I prob would have punched my computer if it wasn't for you guys. You all rock
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:53
@Hijerboa So... any other questions? Do you want to know how to bake a cake? Simplify your life? Travel back in time? We have those answers and more, and we're all ready and willing to help! :o
Brittani
@Carowyn
Jun 28 2017 00:56
Hey, I came back to the perfect conversation...I'm about to attempt the Palindrome one. I'm taking a food break because I sat staring at my computer in confusion lol.
Nick Cleary
@Hijerboa
Jun 28 2017 00:56
Yeah one quick question: whats the meaning of life?
One guy told me it was 41 or something
Stephen James
@sjames1958gm
Jun 28 2017 00:56
42
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:57
meaningOfLife++;
pablovvb
@pablovvb
Jun 28 2017 00:57
So, this is as far as I got, which is nothing. Any hint of why I'm not filtering anything would be fully appreciated!!
function destroyer(arr) {
  // Remove all the values
  var arr2 = arr.slice.call(arguments);
  var arr1 = arr2.shift();
  var newArr = [];
  function a() { 
  return a !== arr2[i];   //this compares each element of arr1 to arr2
  }  
  for (i = 0; i < arr2.length; i++) {  
    newArr = arr1.filter(a);
  }  // deletes the similarities in arr1, and applies the changes to newArr  
//  var newArr = arr.filter(function(a) {return Boolean(!a);
   //                                          });  
  return newArr;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Nick Cleary
@Hijerboa
Jun 28 2017 00:57
@kumquatfelafel amazing
kumquatfelafel
@kumquatfelafel
Jun 28 2017 00:58

@pablovvb a !== arr2[i]?

What is a?

pablovvb
@pablovvb
Jun 28 2017 01:00
maybe there's it!!
kumquatfelafel
@kumquatfelafel
Jun 28 2017 01:03
pablovvb
@pablovvb
Jun 28 2017 01:04
hmm, I'm still not there. I need somehow to compare all the elements in arr1 to the elements in arr2, and a is not doing it because I don't mention arr1 anywhere
kumquatfelafel
@kumquatfelafel
Jun 28 2017 01:06
@pablovvb There may be a function that does something along the lines of what you want. See if you can find one https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype
Moisés Man
@moigithub
Jun 28 2017 01:07
function greaterThan3( value ) {
     if( value > 3) {return true;}
     else {return false;}
}
[1,2,3,4,5,6].filter ( greaterThan3 )
result : [4,5,6]
pablovvb
@pablovvb
Jun 28 2017 01:07
thanks for the tip, @kumquatfelafel . I'll look into it :)
CamperBot
@camperbot
Jun 28 2017 01:07
pablovvb sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 377 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Johnny O'Sullivan
@johnnyosullivan
Jun 28 2017 01:08

@pablovvb on the same problem. finding it trickier than I thought.

function destroyer(arr) { 
 var args = arr.slice.call(arguments);
 for (var i = 1; i < args.length; i++)
 var seek = args[i];
 var destroyed = args[0].filter(function(val){
   return val !== seek;
 });
 return destroyed;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);

Any advice would be helpful.

kumquatfelafel
@kumquatfelafel
Jun 28 2017 01:09
@pablovvb Also note, as @moigithub points out, you can pass values into a function. Or rather, more importantly, you can provide that function with a parameter which enables you to reference a certain value...
pablovvb
@pablovvb
Jun 28 2017 01:11
oooh!! that gets me way closer!
@johnnyosullivan in my humble review, I don't get that args[0]. What does destroyed return?
Moisés Man
@moigithub
Jun 28 2017 01:13
@johnnyosullivan what value will destroyed have after run this code...
destroyed = 1;
destroyed = 2;
destroyed = 3;
@pablovvb args is a copy of arguments... which is this [[1, 2, 3, 1, 2, 3] , 2 , 3]
soo args[0] is the first element [1, 2, 3, 1, 2, 3]
which is the same as arr
Johnny O'Sullivan
@johnnyosullivan
Jun 28 2017 01:17
@moigithub @pablovvb
[1,2,1,2] is what it's returning right now.
Moisés Man
@moigithub
Jun 28 2017 01:18
@johnnyosullivan u not answering the question :)
:point_up: 27 de junio de 2017 20:13 1, 2 or 3
Johnny O'Sullivan
@johnnyosullivan
Jun 28 2017 01:18
Am I not? Sorry. Let me revisit.
kumquatfelafel
@kumquatfelafel
Jun 28 2017 01:20

@johnnyosullivan what value will destroyed have after run this code...

destroyed = 1;
destroyed = 2;
destroyed = 3;

^this bit. Will destroyed be 1?

pablovvb
@pablovvb
Jun 28 2017 01:20
@moigithub @johnnyosullivan man, that's cleaner than mine :P I like it!! (and @johnnyosullivan , I'm exactly in the same place)
Johnny O'Sullivan
@johnnyosullivan
Jun 28 2017 01:22
@kumquatfelafel @moigithub oh man, I'm having one of those moments...I don't understand the question.
georgebatton
@georgebatton
Jun 28 2017 01:23
jnbjk
kumquatfelafel
@kumquatfelafel
Jun 28 2017 01:23

@johnnyosullivan If one were to say

var destroyed = 1;
destroyed = 2;
destroyed = 3;
console.log(destroyed);

What would show up in console?

georgebatton
@georgebatton
Jun 28 2017 01:23
Why can't I use for Stand in Line: arr.push(item);
var remove=arr.shift(item);
pablovvb
@pablovvb
Jun 28 2017 01:23
@johnnyosullivan I think moi is into something with mine as well. I may be replacing once and again the value I want to get
Saif Ur Rahman
@saifsmailbox98
Jun 28 2017 01:24
@georgebatton vvv return remove.
kumquatfelafel
@kumquatfelafel
Jun 28 2017 01:24
@georgebatton ^^^ Shift doesn't require an argument.
georgebatton
@georgebatton
Jun 28 2017 01:24
why does push require one but shift doesn't?
Saif Ur Rahman
@saifsmailbox98
Jun 28 2017 01:25
@georgebatton push adds that to the array, shift is used to remove element.
kumquatfelafel
@kumquatfelafel
Jun 28 2017 01:25
@georgebatton Shift just removes first element from array. Doesn't really care what we lowly humans and/or rodents have to say. :p
There's no need for any kind of special input in order to remove an element.
Johnny O'Sullivan
@johnnyosullivan
Jun 28 2017 01:25
Wouldn't destroyed just be equal to the number you assign it in those cases?
Moisés Man
@moigithub
Jun 28 2017 01:25
@johnnyosullivan code runs from top to bottom
@johnnyosullivan but it WONT have all 3 values
it can be 1 OR 2 OR 3... soo what value will be after the code is executed ?
Johnny O'Sullivan
@johnnyosullivan
Jun 28 2017 01:26
3
?
Moisés Man
@moigithub
Jun 28 2017 01:26
yep only last value prevails
kumquatfelafel
@kumquatfelafel
Jun 28 2017 01:26
aye
Kent Saeteurn
@sansae
Jun 28 2017 01:27

Hi all,
I am working on the "Arguments Optional" challenge. I have tested all 5 cases. The returned results are exactly what FreeCodeCamp wants, however, when click submit, only the top two cases are marked as correct. The last 3, which expects "undefined" to be returned, are marked incorrect. When testing for all 3 undefined cases in FCC's editor window, the returned result is "undefined" (It shows on the left hand column).

Does anyone know why FCC won't recognize the returned values of "undefined"?

kumquatfelafel
@kumquatfelafel
Jun 28 2017 01:27

@sansae post code

(if you're doing something like return "undefined"; lose the "")

Johnny O'Sullivan
@johnnyosullivan
Jun 28 2017 01:28
ok. so my problem is with the variable seek.
it's only taking the last item in the args array.
Kent Saeteurn
@sansae
Jun 28 2017 01:29
@kumquatfelafel https://repl.it/JEqA/67
Moisés Man
@moigithub
Jun 28 2017 01:30

@johnnyosullivan soo another concept
a loop repeat code

for (var x=1; x<= 3; x++){
    doSomething(x);
}

will do
doSomething(1)
doSomething(2)
doSomething(3)

kumquatfelafel
@kumquatfelafel
Jun 28 2017 01:30
@sansae :point_up_2: see my reply. "undefined" != undefined.
"undefined" is a string that happens to be the word "undefined". undefined, on the other hand, is... well... undefined.
Johnny O'Sullivan
@johnnyosullivan
Jun 28 2017 01:31
Thanks @moigithub and @kumquatfelafel . I have to retire for the evening, but you've set me straight.
CamperBot
@camperbot
Jun 28 2017 01:31
johnnyosullivan sends brownie points to @moigithub and @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 378 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:star2: 3440 | @moigithub |http://www.freecodecamp.com/moigithub
Johnny O'Sullivan
@johnnyosullivan
Jun 28 2017 01:32
Or on the right path at least.
Kent Saeteurn
@sansae
Jun 28 2017 01:32
@kumquatfelafel yikes. i just returned a string didn't I? lol Oops
@kumquatfelafel i fixed it
Moisés Man
@moigithub
Jun 28 2017 01:32

@johnnyosullivan soo on ur code.. on each iteration u replacing destroyed values reassigning it
only last filter result prevail

var destroyed = [1, 2, 3, 1, 2, 3].filter() // when seek is 2
var destroyed = [1, 2, 3, 1, 2, 3].filter() // when seek is 3
last one return [1,2,1,2]

Kent Saeteurn
@sansae
Jun 28 2017 01:32
@kumquatfelafel thank you!
CamperBot
@camperbot
Jun 28 2017 01:32
sansae sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 379 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
kumquatfelafel
@kumquatfelafel
Jun 28 2017 01:33
@sansae mayhaps. What it means though is that after quick alteration you've essentially passed the challenge :p
np
Maxwell Adams
@maxadams100
Jun 28 2017 01:35

You will need to use escape sequences to insert special characters correctly. You will also need to follow the spacing as it looks above, with no spaces between escape sequences or words.

Here is the text with the escape sequences written out.

FirstLinenewlinebackslashSecondLinebackslashcarriage-returnThirdLine
var myStr;"FirstLine\n\SecondLine\\rThirdLine"

Uhh that last line is what I tried. I have no clue what i'm doing help please.
Johnny O'Sullivan
@johnnyosullivan
Jun 28 2017 01:37
Yeah that makes sense now @moigithub . I'll get it in the morning. Thanks again.
CamperBot
@camperbot
Jun 28 2017 01:37
johnnyosullivan sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:warning: johnnyosullivan already gave moigithub points
kumquatfelafel
@kumquatfelafel
Jun 28 2017 01:38

@maxadams100 if you wanted to assign 5 to a var, i, would you say
var i; 5?

(Your string itself is good.)

Saif Ur Rahman
@saifsmailbox98
Jun 28 2017 01:38
:wave: :zzz:
kumquatfelafel
@kumquatfelafel
Jun 28 2017 01:38
see ya
Ednor
@ednor
Jun 28 2017 01:41
Who plays golf here ?
Keon Samuel
@keonsam
Jun 28 2017 01:41
how long does it take to get a programming job?
kumquatfelafel
@kumquatfelafel
Jun 28 2017 01:41
depends on the job
Ednor
@ednor
Jun 28 2017 01:42
Golf Code challenge is completely stranger to me, if it was soccer, I'd understand in the seconds
kumquatfelafel
@kumquatfelafel
Jun 28 2017 01:42
couldn't tell ya much more than that. Generally speaking, you can get a bit of an idea if your qualified by look at ... whatsitscalled (long day).
Ednor
@ednor
Jun 28 2017 01:44
image.png
I am completely lost
Keon Samuel
@keonsam
Jun 28 2017 01:45
yes that was a hard one to understand.
Diego Mayer
@Chrono79
Jun 28 2017 01:46
@ednor compare strokes against the first column, return the second column, use if/else
kumquatfelafel
@kumquatfelafel
Jun 28 2017 01:47
@keonsam job description! That's the word! :p
@keonsam nah. So I'm probably not the right one to talk to. ;)
tiger500
@tiger500
Jun 28 2017 01:49
convertToF(0) should return a number
convertToF(-30) should return a value of -22
convertToF(-10) should return a value of 14
convertToF(0) should return a value of 32
convertToF(20) should return a value of 68
convertToF(30) should return a value of 86
i need help
kumquatfelafel
@kumquatfelafel
Jun 28 2017 01:50
@tiger500 post your code.
tiger500
@tiger500
Jun 28 2017 01:50

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

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

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

kumquatfelafel
@kumquatfelafel
Jun 28 2017 01:51
@tiger500 Did you try doing what @saifsmailbox98 said?
tiger500
@tiger500
Jun 28 2017 01:52
yeah when i get the 2nd correct i get the 3rd one wrong @kumquatfelafel
Ednor
@ednor
Jun 28 2017 01:52
@Chrono79 what about Strokes = Par, does that mean Par = 0 ?
kumquatfelafel
@kumquatfelafel
Jun 28 2017 01:53
@ednor When strokes === par, you return "Par". for example
Diego Mayer
@Chrono79
Jun 28 2017 01:53
@ednor no, and use == or === to compare when not specified, = is used to assign values
capitalization matters
kumquatfelafel
@kumquatfelafel
Jun 28 2017 01:53
@tiger500 Let me see what you tried to do with saif. Maybe we can figure out what went wrong.
tiger500
@tiger500
Jun 28 2017 01:55

function convertToF(celsius) {
var fahrenheit=0;

// Only change code below this line
fahrenheit=(-30+8);
fahrenheit=(-10+24);

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

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

Ednor
@ednor
Jun 28 2017 01:56
@Chrono79 what about Strokes = Par, does that mean Par = 0 ?
There is column where Par has any value
tiger500
@tiger500
Jun 28 2017 01:56

@kumquatfelafel function convertToF(celsius) {
var fahrenheit=0;

// Only change code below this line
fahrenheit=(-30+8);
fahrenheit=(-10+24);

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

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

Diego Mayer
@Chrono79
Jun 28 2017 01:56

@ednor

@ednor When strokes === par, you return "Par". for example

Strokes        Return
1        "Hole-in-one!"
<= par - 2        "Eagle" //you compare strokes against par - 2 here, using <=
par - 1        "Birdie"
par        "Par"
par + 1        "Bogey"
par + 2        "Double Bogey"
= par + 3        "Go Home!"
kumquatfelafel
@kumquatfelafel
Jun 28 2017 01:57
@tiger500 alright. Well you're not using the conversion formula here. You're just hardcoding values. You need to use the formula. So what's the formula to convert celsius to fahrenheit?
tiger500
@tiger500
Jun 28 2017 01:58
@kumquatfelafel celsius9/5+2
Ednor
@ednor
Jun 28 2017 02:00
@Chrono79, in this challenge, I must use if ... return; else if (*n) ... return; and else ... return;
kumquatfelafel
@kumquatfelafel
Jun 28 2017 02:00
@tiger500 the formula we use to convert fahrenheit to celsius is Fº = Cº * 9/5 + 32.
Diego Mayer
@Chrono79
Jun 28 2017 02:01
@ednor yes, all the if/else you need to address all cases
kumquatfelafel
@kumquatfelafel
Jun 28 2017 02:01
@tiger500 do you have a variable that represents the temperature in Fº in your code?
Ednor
@ednor
Jun 28 2017 02:01
@Chrono79 ,here is what i've tried, but failed

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

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

// Change these values to test
golfScore(5, 4);
Harry Fahringer III
@harryrf
Jun 28 2017 02:02
Any idea what I'm still doing wrong here? https://codepen.io/harryrf3/pen/EXVWdv?editors=1010
My button changes from fahrenheit to celsius, but not back
Diego Mayer
@Chrono79
Jun 28 2017 02:02
@ednor where is strokes there?
Ednor
@ednor
Jun 28 2017 02:02
@ednor where is strokes there?
Euh !!!
tiger500
@tiger500
Jun 28 2017 02:03
@kumquatfelafel no
kumquatfelafel
@kumquatfelafel
Jun 28 2017 02:04
@tiger500 you don't see a variable you could use to store the temperature in ºF?
Ednor
@ednor
Jun 28 2017 02:04
@Chrono79, so instead of using par as variable, it should be strokes, right ?
kumquatfelafel
@kumquatfelafel
Jun 28 2017 02:05
@ednor both par and strokes are important.
Diego Mayer
@Chrono79
Jun 28 2017 02:05
@ednor par and strokes are your function parameters, you have to use both (not in all cases)
strokes is needed in all your if conditions, compare it against the values of the table's first column
tiger500
@tiger500
Jun 28 2017 02:05
@kumquatfelafel fahrenheit
kumquatfelafel
@kumquatfelafel
Jun 28 2017 02:05
@tiger500 yep
@tiger500 how about for ºC?
Ednor
@ednor
Jun 28 2017 02:05
@Chrono79, @kumquatfelafel, I am COMPLETELY lost
tiger500
@tiger500
Jun 28 2017 02:06
@kumquatfelafel Celsius
Diego Mayer
@Chrono79
Jun 28 2017 02:06
@ednor
if (strokes == 1) {
  return "Hole-in-one!"; // <- the string must be exactly what they wrote
Complete it with the other cases
Ednor
@ednor
Jun 28 2017 02:08
ok @Chrono79 , let me continue with your logic
kumquatfelafel
@kumquatfelafel
Jun 28 2017 02:08
@tiger500 close. Is it written exactly as Celsius in your code?
AnonimoProgrammatore
@AnonimoProgrammatore
Jun 28 2017 02:08

sorry guys but the RegEx

/\W/g

it's supposed to comprend "_" underscore too, right?

Diego Mayer
@Chrono79
Jun 28 2017 02:08
@AnonimoProgrammatore \w is all letters, all numbers and _
\W is not all that
tiger500
@tiger500
Jun 28 2017 02:08
@kumquatfelafel Celsius time
Joseph
@revisualize
Jun 28 2017 02:09
Hello.
Diego Mayer
@Chrono79
Jun 28 2017 02:09
:wave:
Ednor
@ednor
Jun 28 2017 02:09
@Chrono79 , what is the condition when strokes return Par
?
Joseph
@revisualize
Jun 28 2017 02:09
@ednor strokes return par?
Diego Mayer
@Chrono79
Jun 28 2017 02:10
@ednor strokes == par but that's the last one I'll give you, you're on your own from there
Try to see the logic of comparing strokes against the first column and returning the second, that's how you normally read a table
AnonimoProgrammatore
@AnonimoProgrammatore
Jun 28 2017 02:10
@Chrono79 Thanks you, I tought that "_" was not in \w
CamperBot
@camperbot
Jun 28 2017 02:10
anonimoprogrammatore sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4432 | @chrono79 |http://www.freecodecamp.com/chrono79
Ednor
@ednor
Jun 28 2017 02:11
Okay @revisualize and @Chrono79
AnonimoProgrammatore
@AnonimoProgrammatore
Jun 28 2017 02:12
well palyndrome function gone, may i post it here and ask you if it is ok or it could be better?
Claudio Restifo
@Marmiz
Jun 28 2017 02:12
@ednor conveniently there's a table on the page that show you the values and the expected result. Example:
strokes is par + 1 return "Bogey"
You only need to "convert" it into code
kumquatfelafel
@kumquatfelafel
Jun 28 2017 02:18

@ednor If you're still having trouble, let's take a step back on this problem for a moment.

Suppose par is 5. Let's not think of it as a variable at all... just 5.

if I hit ball in hole in 5, so strokes = 5, then I get "Par". What is the relation between strokes and 5 (par) here? Does strokes + 7 = 5? Or from another perspective, what is strokes - 5?
if I hit ball in hole in 6, so strokes = 5, then I get "Bogey". What is the relation between strokes and 5 (par) here? Does strokes + 7 = 5? Or from another perspective, what is strokes - 5?

Ednor
@ednor
Jun 28 2017 02:20
now I understand why there are positive and negative values. Below is my new code, but I still have trouble with it

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

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

// Change these values to test
golfScore(5, 4);
Diego Mayer
@Chrono79
Jun 28 2017 02:20
@ednor The strings must be exact
Hole-in-one is missing a ! at the end
CallMeOrange
@EgnaroDev
Jun 28 2017 02:21
I dont even understand Golf
kumquatfelafel
@kumquatfelafel
Jun 28 2017 02:21
@MCTwoDigitZero Nobody does. :p
Diego Mayer
@Chrono79
Jun 28 2017 02:21
@kumquatfelafel I understand golf, but I doubt I could play it ;)
CallMeOrange
@EgnaroDev
Jun 28 2017 02:21
I thought if I didnt know how to golf then it might be a trouble coding Golf Code
Ednor
@ednor
Jun 28 2017 02:22
@ednor The strings must be exact
Who hoo !
Diego Mayer
@Chrono79
Jun 28 2017 02:22
You don't need to be Tiger Woods to solve it after all
CallMeOrange
@EgnaroDev
Jun 28 2017 02:22
lol
kumquatfelafel
@kumquatfelafel
Jun 28 2017 02:22
@Chrono79 I believe the key is using a magnetic ball and a giant magnet.
Ednor
@ednor
Jun 28 2017 02:22
You don't need to be Tiger Woods to solve it after all
or Potus
Diego Mayer
@Chrono79
Jun 28 2017 02:23
@kumquatfelafel that sounds like a Coyote plan, won't work (ACME brand)
kumquatfelafel
@kumquatfelafel
Jun 28 2017 02:23
lol
Ednor
@ednor
Jun 28 2017 02:24
Thanks to @Chrono79 and @kumquatfelafel. Issue solved.
CamperBot
@camperbot
Jun 28 2017 02:24
ednor sends brownie points to @chrono79 and @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:star2: 4433 | @chrono79 |http://www.freecodecamp.com/chrono79
:cookie: 380 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Ednor
@ednor
Jun 28 2017 02:24
3 hours of coding today
Harry Fahringer III
@harryrf
Jun 28 2017 02:24
Anyone have a moment?
Claudio Restifo
@Marmiz
Jun 28 2017 02:24
@harryrf sup?
Ednor
@ednor
Jun 28 2017 02:24
day 2 of #100DaysOfCode
Diego Mayer
@Chrono79
Jun 28 2017 02:25
a long way to go, but hang in there
Harry Fahringer III
@harryrf
Jun 28 2017 02:26
My button changes from Fahrenheit to Celsius, but not back the other way after being ran
Ednor
@ednor
Jun 28 2017 02:27
a long way to go, but hang in there.
I will survive @Chrono79. Lol
Claudio Restifo
@Marmiz
Jun 28 2017 02:28
@harryrf to be honest it doesn't even change to C on my end
Harry Fahringer III
@harryrf
Jun 28 2017 02:28
Okay, now I broke it
mauriciodeleonc
@mauriciodeleonc
Jun 28 2017 02:28
@revisualize yep, could answer it, thanks
CamperBot
@camperbot
Jun 28 2017 02:28
mauriciodeleonc sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4278 | @revisualize |http://www.freecodecamp.com/revisualize
mauriciodeleonc
@mauriciodeleonc
Jun 28 2017 02:28
but now im in another challenge
Harry Fahringer III
@harryrf
Jun 28 2017 02:28
@Marmiz Yeah, I broke it by messing around, one sec
mauriciodeleonc
@mauriciodeleonc
Jun 28 2017 02:29
function findLongestWord(str) {
  var wordbank = str.split(" ");
  //console.log(str);
  //console.log(wordbank);
  var max = 0;
  for (var i = 0; i < str.length; i++ ) {

    if (wordbank[i].length > max) {
     // console.log(wordbank[i]);
      //console.log(wordbank[i].length);
      max = wordbank[i].length;
      //console.log(max);
    }
  }
  return max;
}

findLongestWord("What if we try a super-long word such as otorhinolaryngology");
kumquatfelafel
@kumquatfelafel
Jun 28 2017 02:29
@harryrf I hate to tell you this but... nvm. you noticed :p
mauriciodeleonc
@mauriciodeleonc
Jun 28 2017 02:29
this is telling me ''cannot read property of undefined''
please help
Diego Mayer
@Chrono79
Jun 28 2017 02:29
@harryrf you only change the values of some vars, you should change the html too
See the console there are some errors there
mauriciodeleonc
@mauriciodeleonc
Jun 28 2017 02:30
with the console logs i see that i get the correct answer
so im not sure where the undefined is
Harry Fahringer III
@harryrf
Jun 28 2017 02:31
Okay, I fixed it
Conor Murphy
@cmurphy580
Jun 28 2017 02:32
anyone have any ideas on how to remove text from this canvas once the mouse is off the particular color? https://codepen.io/cmurphy580/pen/bRYGBe?editors=1010
Ednor
@ednor
Jun 28 2017 02:32
Have a good night. Bye !!!
Harry Fahringer III
@harryrf
Jun 28 2017 02:32
@Chrono79 So, do something like switch between #temp_c and #temp_f?
I was hoping I could avoid that
I couldn't think of the name, but do you mean, by using .toggle()?
Diego Mayer
@Chrono79
Jun 28 2017 02:33
@harryrf move all those $("someId").html(someValue) inside the function, so the values get updated whenever you change the units
kumquatfelafel
@kumquatfelafel
Jun 28 2017 02:34
@mauriciodeleonc Take a look at what happens when we run this. https://repl.it/JEp6/3
Claudio Restifo
@Marmiz
Jun 28 2017 02:35
@mauriciodeleonc this loop:
for (var i = 0; i < str.length; i++ )
is trying to loop up to i=60 (str.length)
kumquatfelafel
@kumquatfelafel
Jun 28 2017 02:35
^ and v
Claudio Restifo
@Marmiz
Jun 28 2017 02:36
@mauriciodeleonc perhaps you want to loop for as many words you have in the splitted array :)
Harry Fahringer III
@harryrf
Jun 28 2017 02:36
@Chrono79 They are in the function though
Diego Mayer
@Chrono79
Jun 28 2017 02:36
@harryrf yes, nvm, I'm gonna check something else
Harry Fahringer III
@harryrf
Jun 28 2017 02:36
okay, thanks
Claudio Restifo
@Marmiz
Jun 28 2017 02:37
@cmurphy580 you can implement a mouseenter and mouseleave event listener
Diego Mayer
@Chrono79
Jun 28 2017 02:37
@harryrf shouldn't you change fahrenheit to false somewhere?
And viceversa, when you change form one unit to the other
Harry Fahringer III
@harryrf
Jun 28 2017 02:39
@Chrono79 I was thinking so. I've tried multiple things such as:
Conor Murphy
@cmurphy580
Jun 28 2017 02:39
@Marmiz its all in canvas so i don't know if it'll work with no elements. I have a function tracking the mouse position and the color its on. i didnt know if there is a particular canvas method with what im doing that would work
Harry Fahringer III
@harryrf
Jun 28 2017 02:40
        $(".changeUnit").on("click", function () {
          changeUnit();
         fahrenheit === false;
        });
lol, my keyboard had a brainfart
mauriciodeleonc
@mauriciodeleonc
Jun 28 2017 02:40
@kumquatfelafel okay , in the link you sent i can see that "i" goes up to 11 when the str has only 10 words, so i changed the loop to start at 1 instead of 0
kumquatfelafel
@kumquatfelafel
Jun 28 2017 02:40
@mauriciodeleonc see @Marmiz reply.
mauriciodeleonc
@mauriciodeleonc
Jun 28 2017 02:40
@Marmiz yep thats what i want
for the amount of words and not letters
Harry Fahringer III
@harryrf
Jun 28 2017 02:41
@Chrono79 For reasons I don't understand, calling changeUnit(); in that event changes it automatically
So, I've even tried adding fahrenheit === true; at the end to no avail
mauriciodeleonc
@mauriciodeleonc
Jun 28 2017 02:42
SOLVED
kumquatfelafel
@kumquatfelafel
Jun 28 2017 02:42
:+1:
mauriciodeleonc
@mauriciodeleonc
Jun 28 2017 02:42
thanks @kumquatfelafel @Marmiz
CamperBot
@camperbot
Jun 28 2017 02:42
mauriciodeleonc sends brownie points to @kumquatfelafel and @marmiz :sparkles: :thumbsup: :sparkles:
:cookie: 381 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:cookie: 963 | @marmiz |http://www.freecodecamp.com/marmiz
Diego Mayer
@Chrono79
Jun 28 2017 02:43
@harryrf
function changeUnit() { //remove fahrenheit from there
Claudio Restifo
@Marmiz
Jun 28 2017 02:43
@cmurphy580 canvas supports event listeners, so you can add the one you wants :)
Diego Mayer
@Chrono79
Jun 28 2017 02:43
          if (fahrenheit == true) {
          ...
            fahrenheit = false;
         } else { 
            ... 
            fahrenheit = true;
         }
bitcoinabdi
@bitcoinabdi
Jun 28 2017 02:45
helooo guyz
kumquatfelafel
@kumquatfelafel
Jun 28 2017 02:45
can also do fahrenheit = !fahrenheit;
Conor Murphy
@cmurphy580
Jun 28 2017 02:45
@bitcoinabdi newArr.push([...arr]);
Diego Mayer
@Chrono79
Jun 28 2017 02:46
@kumquatfelafel yes, below the if/else
Conor Murphy
@cmurphy580
Jun 28 2017 02:46
@Marmiz alright thanks for the help i'll try to get one working
CamperBot
@camperbot
Jun 28 2017 02:46
cmurphy580 sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:cookie: 964 | @marmiz |http://www.freecodecamp.com/marmiz
Harry Fahringer III
@harryrf
Jun 28 2017 02:46
@Chrono79 Now the button seems to not be working at all
bitcoinabdi
@bitcoinabdi
Jun 28 2017 02:46
@cmurphy580 thank you Boss
CamperBot
@camperbot
Jun 28 2017 02:46
bitcoinabdi sends brownie points to @cmurphy580 :sparkles: :thumbsup: :sparkles:
:cookie: 313 | @cmurphy580 |http://www.freecodecamp.com/cmurphy580
bitcoinabdi
@bitcoinabdi
Jun 28 2017 02:47
this challenge was crazy for me
kumquatfelafel
@kumquatfelafel
Jun 28 2017 02:47

@Chrono79 oh... those ... are signifying more code that been left out, right? gotcha.

Was thinking of it in terms of "checking value of fahrenheit solely for purpose of changing value of fahrenheit".

Harry Fahringer III
@harryrf
Jun 28 2017 02:47
oh, one sec
Conor Murphy
@cmurphy580
Jun 28 2017 02:47
@bitcoinabdi no problem. yah I didn't know you can do that. good to know.
Harry Fahringer III
@harryrf
Jun 28 2017 02:48
I forgot to remove fahrenheit from the initial call first
bitcoinabdi
@bitcoinabdi
Jun 28 2017 02:49
@cmurphy580 loool thats the beauty of coding
Diego Mayer
@Chrono79
Jun 28 2017 02:49
it works for me @harryrf
Harry Fahringer III
@harryrf
Jun 28 2017 02:49
Yeah, blame it on my tired brain
Diego Mayer
@Chrono79
Jun 28 2017 02:50
:+1:
Harry Fahringer III
@harryrf
Jun 28 2017 02:50
I did fahrenheit === true;
Ryan Williams
@Ryanwfile
Jun 28 2017 02:50
Can someone familiar with flexbox please help explain how to get the h2 element in the following code to take up its own row above the other 3 div columns, I'm having difficulty getting the h2 text on its own row above 3 columns. Thanks for any help.
<div id="outer">
  <div id = "inner">
    <h2 id='title'>Why doesn't this work</h2>
    <div >Here's a Test</div>
    <div>Second Test</div>
    <div>More test</div>    
  </div>
</div>

#inner{
  display:flex;
  flex-direction:row;
}
#title {
  display:block;
  width:100%;
  border:1px solid black;
}
Harry Fahringer III
@harryrf
Jun 28 2017 02:50
Thanks @Chrono79, this has been killing me. I knew I needed to change the value of the variable, but couldn't for the life of me figure it out.
CamperBot
@camperbot
Jun 28 2017 02:50
harryrf sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4434 | @chrono79 |http://www.freecodecamp.com/chrono79
Harry Fahringer III
@harryrf
Jun 28 2017 02:51
Also, @kumquatfelafel thanks to you as well. I was trying to thing of that condition earlier and it was escaping me.
CamperBot
@camperbot
Jun 28 2017 02:51
harryrf sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 382 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Claudio Restifo
@Marmiz
Jun 28 2017 02:51

@Ryanwfile you can try with:

title{
 flex: 0 0 100%
}
or 
title {
flex: none;
width: 100%
}

depends if you need it flex for other layouts or not

Harry Fahringer III
@harryrf
Jun 28 2017 02:52
So I must ask. Does my code look pretty conventional or does it look like a 3rd grader did it?
kumquatfelafel
@kumquatfelafel
Jun 28 2017 02:52
@harryrf np, but I didn't really do much :laughing:
Harry Fahringer III
@harryrf
Jun 28 2017 02:53
@kumquatfelafel That will help me in the future for sure. I was racking my brains trying to remember it
Ryan Williams
@Ryanwfile
Jun 28 2017 02:54
@Marmiz Thanks, but both ways seemed to erase the 3 column divs
CamperBot
@camperbot
Jun 28 2017 02:54
ryanwfile sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:cookie: 965 | @marmiz |http://www.freecodecamp.com/marmiz
Long Nguyen
@longnt80
Jun 28 2017 02:54
@Ryanwfile
#inner{
  display:flex;
  flex-direction:row;
  flex-wrap: wrap;
}
#title {
  display:block;
  width:100%;
  border:1px solid black;
}
add flex-wrap
Claudio Restifo
@Marmiz
Jun 28 2017 02:55
@Ryanwfile then set the 3 divs a flex: 1 0 auto to keep them in one line
while "forcing" h2 to occupy the 100%
Harry Fahringer III
@harryrf
Jun 28 2017 02:55
@longnt80 was that meant for me or someone else?
oh, nvm
Long Nguyen
@longnt80
Jun 28 2017 02:55
@harryrf sorry, it was for @Ryanwfile
Claudio Restifo
@Marmiz
Jun 28 2017 02:57
@Ryanwfile also don't forget to wrap the elements as @longnt80 suggested :)
Harry Fahringer III
@harryrf
Jun 28 2017 02:57
@longnt80 No problem :)
Ryan Williams
@Ryanwfile
Jun 28 2017 02:57
@longnt80 Thanks, that worked
CamperBot
@camperbot
Jun 28 2017 02:57
ryanwfile sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 414 | @longnt80 |http://www.freecodecamp.com/longnt80
Harry Fahringer III
@harryrf
Jun 28 2017 03:01
@Chrono79 @kumquatfelafel quickly back to the fahrenheit = !fahrenheit statement.
I could only add that in the changeUnit function after the if/else, but NOT in the click event?
Joseph
@revisualize
Jun 28 2017 03:03
I really do need to start working on projects.
Harry Fahringer III
@harryrf
Jun 28 2017 03:03
Come to think of it, I maybe should not be lazy and just try it for myself :P
I'm tired and my brain hurts, so off to bed. Good night everyone.
Long Nguyen
@longnt80
Jun 28 2017 03:04
@harryrf it is in the click event, isn't it? The if else is in the click event
Claudio Restifo
@Marmiz
Jun 28 2017 03:04
@harryrf in general when you want to handle an event with a condition this is the flow I go for:
const condition = true

action triggered {
  call method()
}

method() {
 do somethig.
at the end of the method change condition.
}
so that the source of the change is in one place only
Joseph
@revisualize
Jun 28 2017 03:06
hmmm.. I wonder... What should I do that would take me an hour and a half or so.
Claudio Restifo
@Marmiz
Jun 28 2017 03:15

@revisualize

What should I do that would take me an hour and a half or so.

Running for an hour and a half :)

Joseph
@revisualize
Jun 28 2017 03:15
I could even go ride my bike for 45min then ride it home.
Mai Thinh
@mthinh
Jun 28 2017 03:17
function rot13(str) { // LBH QVQ VG!
  var a=[];
  for(var i=0; i< str.length;i++){
  a.push(str.charCodeAt(i));
  }  

  for(var j=0; j <a.length;j++){
    a.push(String.fromCharCode(a[j]-13));
}
  return a.join('');
}



// Change the inputs below to test
rot13("SERR PBQR PNZC");
someone pls help
i got the alert that Potential infinite loop
Diego Mayer
@Chrono79
Jun 28 2017 03:23
@mthinh you're changing a.length in the second loop, so j will never be greater than that
Mai Thinh
@mthinh
Jun 28 2017 03:24
i just want to change the number values in a array into words using fromCharCode @Chrono79
Diego Mayer
@Chrono79
Jun 28 2017 03:24
don't use push
do a[j] = String...
Moisés Man
@moigithub
Jun 28 2017 03:25
@mthinh or create another empty array.. and push on this new array
Diego Mayer
@Chrono79
Jun 28 2017 03:25
your code won't pass the challenge, it needs more work, but that'll solve the potential infinite loop problem
Mai Thinh
@mthinh
Jun 28 2017 03:26
thank you @Chrono79 @moigithub
CamperBot
@camperbot
Jun 28 2017 03:26
mthinh sends brownie points to @chrono79 and @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 4435 | @chrono79 |http://www.freecodecamp.com/chrono79
:star2: 3441 | @moigithub |http://www.freecodecamp.com/moigithub
kumquatfelafel
@kumquatfelafel
Jun 28 2017 03:26
@harryrf in on click changeUnit(fahrenheit = !fahrenheit);
Absolutely nothing else I tried but this ^^ would get it to work.
One other thing I'm noting is amount of rain I got was 0.026000000000000002 CM
Joseph
@revisualize
Jun 28 2017 03:39
Imagine for a second.. You had to write a mini-research paper on someone:
Who of this list ... would you chose?
Immanuel Kant
Edgar Allen Poe (Not for his literary works but for his cryptograms)
John Locke
Socrates
Or... Other.
surferpilgrim
@surferpilgrim
Jun 28 2017 03:40
@revisualize Srinivasa Ramanujan
Mai Thinh
@mthinh
Jun 28 2017 03:42
function rot13(str) { // LBH QVQ VG!
  var a=[];
  for(var i=0; i< str.length;i++){
  a.push(str.charCodeAt(i));
  }  

  for(var j=0; j <a.length;j++){
    if (a[j]-13 < 65){
    a[j] = String.fromCharCode(a[j]+13);
    }
    else if(a[j]-13 > 65){
      a[j] = String.fromCharCode(a[j]-13);
    }
    else if(a[j]-13 == 65){
      a[j] = String.fromCharCode(65);
    }
   }
  return a.join('');
}

// Change the inputs below to test
rot13("GUR DHVPX OEBJA QBT WHZCRQ BIRE GUR YNML SBK.");
how to ignore the non- alphabetic character?
Joseph
@revisualize
Jun 28 2017 03:44
@mthinh Check if a character is in a range.
Mai Thinh
@mthinh
Jun 28 2017 03:45
A rage?
Joseph
@revisualize
Jun 28 2017 03:45
Sorry, I was missing an n
Is the value between this and this.
kumquatfelafel
@kumquatfelafel
Jun 28 2017 03:47
To be fair, when you come across something of a character, you want to check both if they're in range and in a rage. :p
Joseph
@revisualize
Jun 28 2017 03:49
I should just be an ass and write my tribute page about myself.
surferpilgrim
@surferpilgrim
Jun 28 2017 03:50
I tried to input a string inside fromCharCode but all I get is red dots,
// jshint esversion:6
function rot13(str) { // LBH QVQ VG!
  var newArray = str.split("");

   return String.fromCharCode(...newArray);

}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Moisés Man
@moigithub
Jun 28 2017 03:50
fromCharCode requires a list of numbers/codes @surferpilgrim
str.split("") will give u an array of characters
http://www.asciitable.com/
kumquatfelafel
@kumquatfelafel
Jun 28 2017 03:51
@revisualize Honestly, the main reason I haven't done that thing is because I don't know who to do it on. There was a while I was considering having user enter their name and making it into a story about them... as a duckling on an adventure.
but then I got lazy and never did it.
Joseph
@revisualize
Jun 28 2017 03:52
@kumquatfelafel Same for me.
surferpilgrim
@surferpilgrim
Jun 28 2017 03:53
@moigithub so I'd have to translate str.split("") into unicode values first?
Moisés Man
@moigithub
Jun 28 2017 03:53
ye @surferpilgrim
surferpilgrim
@surferpilgrim
Jun 28 2017 03:59
@moigithub if i understand correctly that means I have to pass the whole array inside charCodeAt() and iterate over a loop to get unicode values for all the elements in the string. is there a way to do this without using a for loop?
Moisés Man
@moigithub
Jun 28 2017 04:05
u need to use some sort of loop... for/while/forEach/map
Kevin Anderson
@LemonStain
Jun 28 2017 04:14
How can I get the array of objects accessible outside of the function? any guidance would be helpful. I am trying to take the array of objects and put them into the HTML of the page in table format . I am able to log the array to the console, but can't grab specific data. https://codepen.io/LemonStain/pen/yXPQbb
Pete Givens
@petegivens
Jun 28 2017 04:15
hey all, got a basic question. What is the difference between declaring a method in a class's constructor function vs declaring it outside using Class.Prototype.function ?
function Dog (breed) {
  this.breed = breed;
  // Difference between this
  this.bark = function() {
    console.log("woof");
  }
}

var buddy = new Dog("golden Retriever");
  // and this?
Dog.prototype.bark = function() {
  console.log("Woof");
};
buddy.bark();
CallMeOrange
@EgnaroDev
Jun 28 2017 04:17
This message was deleted
Claudio Restifo
@Marmiz
Jun 28 2017 04:20
@petegivens as far as I remember the prototype has the advantage that shares to all the instances.
Pete Givens
@petegivens
Jun 28 2017 04:22
if I declare a function inside of the constructor it would be available to all instances too, wouldn't it?
Jerard Delrosario
@jrardd
Jun 28 2017 04:23
Hi guys, can someone explain to me what the purpose of [] and () is in RegEx?
James Patrick Kerrane
@jamesjpk123
Jun 28 2017 04:24

I need help with my function:

function lookUpProfile(firstName, prop){
// Only change code below this line
  var contact;
  var property;
  if(firstName == "Akira" || firstName == "Harry" || firstName == "Sherlock" || firstName == "Kristian") {
    contact = 1;

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

  if(prop == "firstName" || prop == "lastName" || prop == "number" || prop == "likes") {
    property = 1;

    } else {
      return("No such property");
    }
  if(contact == 1 && property == 1) {
    var return1 = contacts[prop];
    return(return1);


  }

I want the function to return Vos if the function is called like "Kristian", "lastName"
Here is the table:

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"]
    }
];

Can someone help me?

Claudio Restifo
@Marmiz
Jun 28 2017 04:25
@petegivens yes, but I believe it adds a little bit of computation. I'm not sure tho.
If you find the answers care to share? :)
@jrardd
[] matches a character in the range
() matcher literally what's inside
Jerard Delrosario
@jrardd
Jun 28 2017 04:27
@Marmiz Do you mind giving an example? I'm still a bit confused :(
Pete Givens
@petegivens
Jun 28 2017 04:28
@jrardd [] means match anything in the range so like [abc] would match anything with one of those letters or [a-z] would match any single character btwn a and z
Claudio Restifo
@Marmiz
Jun 28 2017 04:29

@jrardd
(ab) matches exactly ab (bolded)
abba baba

while [ab] will match anything in the range from a to b (bolded)
abba baba

Pete Givens
@petegivens
Jun 28 2017 04:30
[abc] matches "a", "b", or "c". [a-z] specifies a range which matches any lowercase letter from "a" to "z". These forms can be mixed: [abcx-z] matches "a", "b", "c", "x", "y", or "z", as does [a-cx-z]
kumquatfelafel
@kumquatfelafel
Jun 28 2017 04:30
@jamesjpk123 contacts is an array.
James Patrick Kerrane
@jamesjpk123
Jun 28 2017 04:31
Ok @kumquatfelafel I switched var return1 = contacts[prop]; to var return1 = prop[contacts];
Jerard Delrosario
@jrardd
Jun 28 2017 04:32
Oh ok. Thank you @Marmiz @petegivens that makes a lot more sense
CamperBot
@camperbot
Jun 28 2017 04:32
jrardd sends brownie points to @marmiz and @petegivens :sparkles: :thumbsup: :sparkles:
:cookie: 275 | @petegivens |http://www.freecodecamp.com/petegivens
:cookie: 966 | @marmiz |http://www.freecodecamp.com/marmiz
kumquatfelafel
@kumquatfelafel
Jun 28 2017 04:34
@jamesjpk123 That's still wrong. What is prop[contacts]?
@jamesjpk123 Additionally, you're hardcoding the names. Don't do this.
James Patrick Kerrane
@jamesjpk123
Jun 28 2017 04:35
@kumquatfelafel I'm going to rewrite without hardcoding
surferpilgrim
@surferpilgrim
Jun 28 2017 04:36
trying to put an array inside of charCodeAt(),trying to figure out what's wrong with my for loop
// jshint esversion:6
function rot13(str) { // LBH QVQ VG!
  var newArray = str.split("");
for(var i = 0;i>newArray.length;i++){
return String.charCodeAt(newArray);
}
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Moisés Man
@moigithub
Jun 28 2017 04:38
if i is = 0
i > (greater than) arr.length
will never be true
Rayshawn Woolard
@RWoolard
Jun 28 2017 04:41
Anybody have any ideas how to learn JavaScript overnight?? Lol
surferpilgrim
@surferpilgrim
Jun 28 2017 04:42
@moigithub so it should be i<newArray.length?
kumquatfelafel
@kumquatfelafel
Jun 28 2017 04:42
@RWoolard Go to a planet where the nights are long.
;)
Moisés Man
@moigithub
Jun 28 2017 04:42
for only loops/iterate when condition is true.... so yes @surferpilgrim
but.. also.. return keyword exit the function immediatelly
that return like u have.. will break ur loop.. making this iterate only once
and... charCodeAt syntax is wrong... check on mdn.io/charCodeAt
surferpilgrim
@surferpilgrim
Jun 28 2017 04:43
@moigithub for my code I'd need to add a true false statement?
Rayshawn Woolard
@RWoolard
Jun 28 2017 04:45
lol I've looked over it before, I was deep into objective-c and swift, the logic and everything is pretty much the same but for some reason I can't get the damn syntax and the way the methods work. I got contacted today out of nowhere for a scholarship to a bootcamp but i have to take an assessment test in JavaScript 😰
surferpilgrim
@surferpilgrim
Jun 28 2017 04:46
@moigithub thanks man
CamperBot
@camperbot
Jun 28 2017 04:46
surferpilgrim sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3442 | @moigithub |http://www.freecodecamp.com/moigithub
Rayshawn Woolard
@RWoolard
Jun 28 2017 04:46
I got contacted today for a test tomorrow and the camp starts the following day 🤦🏽‍♂️
Pete Givens
@petegivens
Jun 28 2017 04:46
@RWoolard which?
kumquatfelafel
@kumquatfelafel
Jun 28 2017 04:46
@jamesjpk123 This is too hardcoded though.
Rayshawn Woolard
@RWoolard
Jun 28 2017 04:47
Fullstack Academy In NY
@petegivens
James Patrick Kerrane
@jamesjpk123
Jun 28 2017 04:47
@kumquatfelafel I understand that in real practice, hardcoding would not be applicable right?
Pete Givens
@petegivens
Jun 28 2017 04:48
nice
Rayshawn Woolard
@RWoolard
Jun 28 2017 04:48
Yea if I can pass this assessment lol 🤷🏽‍♂️
bharathbheemireddy
@bharath506315
Jun 28 2017 04:48
@surferpilgrim hey you are using newArray it is an array
but returning an string
Curtis50Jackson87
@Curtis50Jackson87
Jun 28 2017 04:49
hey guys. I'm so confused on what I'm supposed to do on the slasher flick challenge.
this is what I've come up with, but I'm missing something
function slasher(arr, howMany) {
// it doesn't always pay to be first
return arr;
}
var chopOff = slasher.slice(0);
chopOff = arr;
slasher([1, 2, 3], 2);
Pieter Stokkink
@forkerino
Jun 28 2017 04:49
@Curtis50Jackson87 you have to do the slashing inside the function.
bharathbheemireddy
@bharath506315
Jun 28 2017 04:50
@surferpilgrim https://repl.it/JFDI/0
Pete Givens
@petegivens
Jun 28 2017 04:50
@RWoolard showing them that you're eager and good at learning is probably more important than anything you can cram in the next 8 hours
gl
Joseph
@revisualize
Jun 28 2017 04:51
@Curtis50Jackson87 First off.. You need to modify the Function.
@Curtis50Jackson87 slasher is a function name.
@Curtis50Jackson87 arr is a parameter that represents an Array
@Curtis50Jackson87 howMany is a parameter that represents a Number
Rayshawn Woolard
@RWoolard
Jun 28 2017 04:52
Yea I got my fingers crossed, I been doing the practice test all day, I been gettin the same exact solutions except for some stupid syntax or some methods that don't work in JavaScript like they do in swift or obj-c.. It's killing me lol
kumquatfelafel
@kumquatfelafel
Jun 28 2017 04:52
@RWoolard which things are giving you trouble?
Joseph
@revisualize
Jun 28 2017 04:53

@Curtis50Jackson87 Having this:

var chopOff = slasher.slice(0);
chopOff = arr;

Outside of your function doesn't really do anything.. And ... The code is incorrect anyhow.

kumquatfelafel
@kumquatfelafel
Jun 28 2017 04:54
@jamesjpk123 start small, say I wanted to access the first contact in contacts. How would I do that?
Rayshawn Woolard
@RWoolard
Jun 28 2017 04:55
It's just some things I was able to do logically in obj-c and swift doesn't work in JS, unless their site is buggy, I'm watching one of the solutions and my code is identical
Joseph
@revisualize
Jun 28 2017 04:56
@RWoolard Show me your code and for which challenge.
James Patrick Kerrane
@jamesjpk123
Jun 28 2017 04:56
@kumquatfelafel you would do contacts[1]
kumquatfelafel
@kumquatfelafel
Jun 28 2017 04:56
@jamesjpk123 Is 1 the index of the first element in an array?
Rayshawn Woolard
@RWoolard
Jun 28 2017 04:56
It's on another site, it's on hackerthon
AnonimoProgrammatore
@AnonimoProgrammatore
Jun 28 2017 04:56
finally an algoritm exercise without any hint after a series of cries (sorry had to cheer somewhere)
Joseph
@revisualize
Jun 28 2017 04:56
:|
James Patrick Kerrane
@jamesjpk123
Jun 28 2017 04:57
@kumquatfelafel oh wait no, its 0
Joseph
@revisualize
Jun 28 2017 04:57
@AnonimoProgrammatore Congrats.
AnonimoProgrammatore
@AnonimoProgrammatore
Jun 28 2017 04:57
@revisualize thanks
CamperBot
@camperbot
Jun 28 2017 04:57
anonimoprogrammatore sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4279 | @revisualize |http://www.freecodecamp.com/revisualize
kumquatfelafel
@kumquatfelafel
Jun 28 2017 04:57
@jamesjpk123 Now what if I wanted to get the first name of that first contact.
James Patrick Kerrane
@jamesjpk123
Jun 28 2017 04:58
@kumquatfelafel contacts[1].firstName
kumquatfelafel
@kumquatfelafel
Jun 28 2017 04:58
@jamesjpk123 yup.
AnonimoProgrammatore
@AnonimoProgrammatore
Jun 28 2017 04:59
excuse me, but in https://www.freecodecamp.com/challenges/repeat-a-string-repeat-a-string what does it mean "repeat a string"? I don't get what it ask me...
kumquatfelafel
@kumquatfelafel
Jun 28 2017 05:00
@jamesjpk123 I mean no. What did you just say about the index of first element of an array? Is it 1?
James Patrick Kerrane
@jamesjpk123
Jun 28 2017 05:00
@kumquatfelafel nope xD its 0: contacts[0].firstName
Rayshawn Woolard
@RWoolard
Jun 28 2017 05:01
@joseph sorry 🤦🏽‍♂️... I'm doing codecamp too tho 🙌🏽. Crazy thing is I finished the JavaScript track but it was like a year ago I came back on to go through the whole fullstack
kumquatfelafel
@kumquatfelafel
Jun 28 2017 05:03
@jamesjpk123 So looking back at your code, would you still say this vvv
var return1 = contacts[prop];
James Patrick Kerrane
@jamesjpk123
Jun 28 2017 05:03
no
kumquatfelafel
@kumquatfelafel
Jun 28 2017 05:03
You are right about [prop] being in bracket by the way, but what's missing?
You need to look up that prop for a specific contact, right?
kumquatfelafel
@kumquatfelafel
Jun 28 2017 05:15

@jamesjpk123 The key if you're going to start off by hardcoding is not to try and do everything at once in hardcode, but to narrowly focus and as you go along say "okay, what can I do to generalize this? It does this in this case, how do I make it do this in all cases? etc..." changing to something closer and closer to what you need as you go along.

It might also help to think a little bit beforehand about the steps you have to take so you're less likely to get blindsided.

bharathbheemireddy
@bharath506315
Jun 28 2017 05:16
@AnonimoProgrammatore you need to repeat the string using num times
example str = 'abc' num = 3 abc is repeated in 3 times answer is abc abc abc like
AnonimoProgrammatore
@AnonimoProgrammatore
Jun 28 2017 05:27
@bharath506315 yes yes thanks, but I've already did it
CamperBot
@camperbot
Jun 28 2017 05:27
anonimoprogrammatore sends brownie points to @bharath506315 :sparkles: :thumbsup: :sparkles:
:cookie: 252 | @bharath506315 |http://www.freecodecamp.com/bharath506315
Pete Givens
@petegivens
Jun 28 2017 05:39
@kumquatfelafel ty
CamperBot
@camperbot
Jun 28 2017 05:39
petegivens sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 383 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
dunno if all of is accurate though. Would read comments.
Eunice Park
@eunicode
Jun 28 2017 05:43
Can anyone please tell me what's wrong with my code? It is the Truncate a string challenge https://www.freecodecamp.com/challenges/truncate-a-string
It fails tests for num <= 3
function truncateString(str, num) {
  // Clear out that junk in your trunk
  if (num >= str.length) {
    return str;
  }
  else if (3 < num < str.length) {
    return str.slice(0, num - 3).concat("...");
  }
  else if (num <= 3) {
    return str.slice(0, num).concat("...");
  }
}

truncateString("A-tisket a-tasket A green and yellow basket", 11);
kumquatfelafel
@kumquatfelafel
Jun 28 2017 05:44
@eunipa Can't do this a < b < c
Pieter Stokkink
@forkerino
Jun 28 2017 05:44
that would compare true or false to str.length
so would return true for any string of length 2 or up.
as true is coerced to 1 and false to 0
2895388807
@2895388807
Jun 28 2017 05:45

var myVar = 87;

// 请只修改这条注释以下的代码
myVar = myVar++;

kumquatfelafel
@kumquatfelafel
Jun 28 2017 05:46
2895388807
@2895388807
Jun 28 2017 05:46
what wrong with it?
Pieter Stokkink
@forkerino
Jun 28 2017 05:46
@2895388807 don't use myVar =
just myVar++
Eunice Park
@eunicode
Jun 28 2017 05:46
@kumquatfelafel hmm... but it passes these tests:
truncateString("A-tisket a-tasket A green and yellow basket", 11) should return "A-tisket...".
truncateString("Peter Piper picked a peck of pickled peppers", 14) should return "Peter Piper...".
2895388807
@2895388807
Jun 28 2017 05:46
@forkerino cool man!
Pieter Stokkink
@forkerino
Jun 28 2017 05:46
++ implies = @2895388807
2895388807
@2895388807
Jun 28 2017 05:46
appreciate!
Pieter Stokkink
@forkerino
Jun 28 2017 05:46
:+1:
@eunipa see my comments up
Eunice Park
@eunicode
Jun 28 2017 05:47
@forkerino I'm sorry, I wasn't sure if you were referring to me. And sorry again, bc I'm not sure I quite understand your explanation.
Pieter Stokkink
@forkerino
Jun 28 2017 05:48
@eunipa the comparison 3 < num < str.length goes left to right.
@eunipa so first 3 < num is evaluated, which is either true or false
CallMeOrange
@EgnaroDev
Jun 28 2017 05:48
function factorialize(num) {
  if (num === 0) {
return 1;
  }

  for (var i = 1; i < num; i++) {
 console.log(i); // 1,2,3,4

    var answer = num*i;

}
  return answer;
}

factorialize(5);
Pieter Stokkink
@forkerino
Jun 28 2017 05:48
then this is compared to str.length @eunipa
kumquatfelafel
@kumquatfelafel
Jun 28 2017 05:48
@eunipa That's because in those cases, 3 happens to be less than num, and num happens to be less than str.length so the function behaves as expected, even if the condition is flawed.
Pieter Stokkink
@forkerino
Jun 28 2017 05:48
when you use < , true/false will be made into a number, 1/0 respectively.
Eunice Park
@eunicode
Jun 28 2017 05:49
@forkerino @kumquatfelafel thank you very much. I will let your answers marinate in my brain for a bit...
CamperBot
@camperbot
Jun 28 2017 05:49
eunipa sends brownie points to @forkerino and @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 384 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:star2: 2781 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Jun 28 2017 05:49
@eunipa :+1:
@MCTwoDigitZero you are overwriting answer every cycle of the loop
CallMeOrange
@EgnaroDev
Jun 28 2017 05:50
oh I thought I changed both answer to num...
function factorialize(num) {
  if (num === 0) {
return 1;
  }

  for (var i = 1; i < num; i++) {
 console.log(i); // 1,2,3,4

    num = num*i;

}
  return num;
}

factorialize(5);
Pieter Stokkink
@forkerino
Jun 28 2017 05:50
@MCTwoDigitZero now the loop will never stop
because num grows faster than i
CallMeOrange
@EgnaroDev
Jun 28 2017 05:50
great
Pieter Stokkink
@forkerino
Jun 28 2017 05:50
and i<num will always be true
kumquatfelafel
@kumquatfelafel
Jun 28 2017 05:50

@eunipa it would be like if I said

if (true) {
  return str;
}

Eventually, one of those tests is going to return str when it's supposed to return str. That doesn't mean your code should always return str.

Pieter Stokkink
@forkerino
Jun 28 2017 05:51
@MCTwoDigitZero another variable is useful, but declare it outside the loop and multiply it inside.
CallMeOrange
@EgnaroDev
Jun 28 2017 05:51
function factorialize(num) {
  if (num === 0) {
return 1;
  }

  for (var i = 1; i < num; i++) {
 console.log(i); // 1,2,3,4

    var arr = i;

}
  return num*arr;
}

factorialize(5);
Make new variable outside of loop?
kumquatfelafel
@kumquatfelafel
Jun 28 2017 05:52
@MCTwoDigitZero this just overwrites arr with i repeatedly.
Pieter Stokkink
@forkerino
Jun 28 2017 05:52
@MCTwoDigitZero yes
maybe something like var product = 1;
CallMeOrange
@EgnaroDev
Jun 28 2017 05:52
but I cant have variable that contain i outside right?
hm..
Pieter Stokkink
@forkerino
Jun 28 2017 05:53
@MCTwoDigitZero you could technically, but it would cause more problems than you will solve.
CallMeOrange
@EgnaroDev
Jun 28 2017 05:53
well since i is only defined inside loop
Pieter Stokkink
@forkerino
Jun 28 2017 05:54
1. make a variable
2. loop from 1 to num
  multiply variable with iterator and store in the variable
3. return the variable
Eunice Park
@eunicode
Jun 28 2017 06:01

I'm still thinking about the if conditions, but while I'm here, can I ask another question?

For Repeat a string  (and Return Largest Numbers in Arrays)
https://www.freecodecamp.com/challenges/repeat-a-string-repeat-a-string
Why does the code not work if you create a variable inside a for loop? A for loop isn't a function, so it shouldn't affect scope..

function repeatStringNumTimes(str, num) {

  var array = []; // code works bc var array is outside of the for loop

  for (i = 1; i <= num; i++) {
    array.push(str);
  }

  return array.join(""); 
}

repeatStringNumTimes("abc", 3);
Pieter Stokkink
@forkerino
Jun 28 2017 06:05
@eunipa you mean put that line inside the for loop?
Eunice Park
@eunicode
Jun 28 2017 06:06
yes.
Pieter Stokkink
@forkerino
Jun 28 2017 06:07
it is possible, but you would overwrite the variable each cycle of the loop, so the .push would push something on an empty array each time.
@eunipa
Eunice Park
@eunicode
Jun 28 2017 06:07
@forkerino wow. Thank you so much.
CamperBot
@camperbot
Jun 28 2017 06:07
eunipa sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:warning: eunipa already gave forkerino points
kumquatfelafel
@kumquatfelafel
Jun 28 2017 06:12
@camperbot is clearly just using that as an excuse to eat the brownies.
Pieter Stokkink
@forkerino
Jun 28 2017 06:18
:smile:
forkerino @forkerino will be at work. Later!
abhishek4kahol
@abhishek4kahol
Jun 28 2017 06:36
hey guys im getting problem in weather app , when im calling the API im getting 200 ok but not getting the result, also getting CORS error , what should i do?
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.darksky.net/forecast/216e3d84d85957c9c827ce74ce9d9ef3/12.9833,77.5833. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
abhishek4kahol
@abhishek4kahol
Jun 28 2017 06:46
please help
Claudio Restifo
@Marmiz
Jun 28 2017 06:48
@abhishek4kahol try adding a &callback=? at the end of the url
abhishek4kahol
@abhishek4kahol
Jun 28 2017 06:49
ok
Coy Sanders
@coymeetsworld
Jun 28 2017 06:51
darksky api prevents calls like that, because you expose your API key. It's in their FAQ
abhishek4kahol
@abhishek4kahol
Jun 28 2017 06:51
@Marmiz its not working
Claudio Restifo
@Marmiz
Jun 28 2017 06:53
@abhishek4kahol it's working for me. callback is a query paramaeters so you need to add a ? before callback
https://api.darksky.net/forecast/216e3d84d85957c9c827ce74ce9d9ef3/12.9833,77.5833?&callback=?
or just ?callback=? since it's your first query
abhishek4kahol
@abhishek4kahol
Jun 28 2017 06:55
@Marmiz no success im getting the same CORS error
Frostbites
@Frostbites
Jun 28 2017 06:57
I am badly stuck
abhishek4kahol
@abhishek4kahol
Jun 28 2017 06:57
@coymeetsworld yes,i read it, then what else can i do, because i need to send key to get the result
Blauelf
@Blauelf
Jun 28 2017 06:57
jQuery will replace the second ? by a globally defined function (so that's a jQuery-only way, when doing manually you'd have to define your own callback function)
Frostbites
@Frostbites
Jun 28 2017 06:57



function titleCase(str) {
  var fstr = [''];
  var lowArr = str.toLowerCase().split(' ');


  for (var i = 0; i < lowArr[i]; i++){
    myArr = toUpperCase(lowArr[i].charAt(0));
    /*var newArr = myArr.toUpperCase(); */
    return myArr;


    }

  /*return newArr;*/



}


titleCase("I'm a LIttle tea pot");
That's my code
I need to replace the first string of every word in the titleCase and turn it into an uppercase
Can anyone help me?
Blauelf
@Blauelf
Jun 28 2017 06:58
@Frostbites Don't return within the loop.
Coy Sanders
@coymeetsworld
Jun 28 2017 06:59
@abhishek4kahol I used a different API, you could hack the api call I suppose to get through that restriction like @Marmiz said, but even so I don't think that should be recommended. The point is you don't want a user to see it because they can take it and rack up calls (hopefully you didn't put a credit card on your account)
abhishek4kahol
@abhishek4kahol
Jun 28 2017 06:59
@Blauelf showPosition:function(position) {
this.$http.get(https://api.darksky.net/forecas/216e3d84d85957c9c827ce74ce9d9ef3/${position.coords.latitude+','+position.coords.longitude}, function(data, status, request){
console.log('request:::',request)
    if(status == 200)
    {
      console.log(data)
      this.ping = data;
    }
  });
Frostbites
@Frostbites
Jun 28 2017 07:00
@Blauelf how?
I can define an array outside of a loop but that returns me the array as it was outside the loop
Blauelf
@Blauelf
Jun 28 2017 07:01
@Frostbites You could replace the word in the array, like lowArr[i] = lowArr[i].charAt(0).toUpperCase() + restOfTheWord;, and after the loop return lowArr.join(" ");, or use another array for that. For the rest of the word, you could use any of substring, substr, or slice.
abhishek4kahol
@abhishek4kahol
Jun 28 2017 07:02
@coymeetsworld ok , can you tell me other API which i can use
@Blauelf can you help to figure out what i am doing wrong or i can correct
Coy Sanders
@coymeetsworld
Jun 28 2017 07:04
I used apixu, yesterday someone recommended yahoo weather but I haven't tried it
abhishek4kahol
@abhishek4kahol
Jun 28 2017 07:05
thanks i'll try these two
Claudio Restifo
@Marmiz
Jun 28 2017 07:26
@abhishek4kahol since you're using angular (I believe that's where the $http come from right?) You can still try with the get jsonp method and adding a callback to the request.
JSONP is the "official" suggested method for CORS issue by codepen
Frostbites
@Frostbites
Jun 28 2017 07:29
@Blauelf I still don't get it
Nana Owusu
@nanaowusunyamekye
Jun 28 2017 07:30

Hello. need help with some javascript task i'm trying to accomplish. its an array with integers and i want to increase each array item by 1. any help?

''' for (var i = 0; i < arr.length; i++) {
return arr[i] + 1;
}

CamperBot
@camperbot
Jun 28 2017 07:30
:bulb: to format code use backticks! ``` more info
Nana Owusu
@nanaowusunyamekye
Jun 28 2017 07:31
Hello. need help with some javascript task i'm trying to accomplish. its an array with integers and i want to increase each array item by 1. any help?
```
for (var i = 0; i < arr.length; i++) {
return arr[i] + 1;
}
kumquatfelafel
@kumquatfelafel
Jun 28 2017 07:31
@nanaowusunyamekye For future: if you write it in a code block, it makes it easier to read and allows you to do some formatting. To write it in a code block...
for one line: ``` code goes here ```
or for multiple lines vvv
```
code goes here
```
You can also edit your post if you make a mistake by clicking the … that appears when you hover your mouse over your comment.
Claudio Restifo
@Marmiz
Jun 28 2017 07:31
@nanaowusunyamekye have you looked into the map method? It's great for this kind of task
Nana Owusu
@nanaowusunyamekye
Jun 28 2017 07:32
@Marmiz looking into it now. and thanks for the code formatting tip :+1:
CamperBot
@camperbot
Jun 28 2017 07:32
nanaowusunyamekye sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:cookie: 967 | @marmiz |http://www.freecodecamp.com/marmiz
Coy Sanders
@coymeetsworld
Jun 28 2017 07:33
@nanaowusunyamekye return will exit out of the loop (and function if you're using one). You should use the ++ or += operator
kumquatfelafel
@kumquatfelafel
Jun 28 2017 07:34
@nanaowusunyamekye relating to the code you posted, return ends the entire function and returns the specified value. So you should only return when you're absolutely certain you've done everything you needed to do.
KinderPreet Singh
@kindercappy
Jun 28 2017 07:37
Please checkout my Weather app. Feedback is appreciated.
https://codepen.io/kindercappy/pen/bRaNgo
Nana Owusu
@nanaowusunyamekye
Jun 28 2017 07:37
thaaaaaaaaaaaaanks @coymeetsworld been on this for over 30 minutes. I removed the return, just did the increment arr[i] ++ , exited the function and 'returned'
@coymeetsworld :+1:
Coy Sanders
@coymeetsworld
Jun 28 2017 07:38
np @nanaowusunyamekye, the map function would also be a nice option over a for loop like @Marmiz suggested
Nana Owusu
@nanaowusunyamekye
Jun 28 2017 07:38
@kumquatfelafel thank you. got it :+1:
CamperBot
@camperbot
Jun 28 2017 07:38
nanaowusunyamekye sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 385 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Nana Owusu
@nanaowusunyamekye
Jun 28 2017 07:39
@coymeetsworld ya, will look into that as well. Thank you :+1:
CamperBot
@camperbot
Jun 28 2017 07:39
nanaowusunyamekye sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star2: 2911 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Claudio Restifo
@Marmiz
Jun 28 2017 07:47
@nanaowusunyamekye since you have it already here's how id'd do it with map:
arr.map((n) => n + 1 )
Nana Owusu
@nanaowusunyamekye
Jun 28 2017 07:48
@Marmiz great :+1:
Bryan Büster
@BryanBuster
Jun 28 2017 08:03
Can anyone help with the "Profile Lookup"(challenge) I'm having no clue what to do
Ogundele Olumide
@Lumexralph
Jun 28 2017 08:08
@BryanBuster what have you tried?
Bryan Büster
@BryanBuster
Jun 28 2017 08:08
I am currently trying to get the if clause
Don't mind the look It;s just me typing stuff out.

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


function lookUpProfile(firstName, prop){
// Only change code below this line
if (firstName = contacts[0][i]
    )
  result = contacts(firstName)
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
Ogundele Olumide
@Lumexralph
Jun 28 2017 08:09
@BryanBuster
Here's an outline, if you follow it step-wise it'll help a great deal in telling you what to do or step you missed
1. you need a loop to pick each objects in the contacts array
    1.1  in the loop you need to 
         1.1.1  check if the objects picked has the firstName property equal to the firstName parameter
                  1.1.1.1 you need to check if it has a property prop
                                  return the value of prop in the object
                 1.1.1.2  return no such property if  1.1.1.1 is false
2.  when your loop is done looking through  contacts return no such contact
Bryan Büster
@BryanBuster
Jun 28 2017 08:10
@Lumexralph okay thanks I'll try that out after I come back from training
CamperBot
@camperbot
Jun 28 2017 08:10
bryanbuster sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 2005 | @lumexralph |http://www.freecodecamp.com/lumexralph
amatayamada
@amatayamada
Jun 28 2017 08:15
hey, I have a JSON collection of objects which can come from multiple sources. I need to assign them unique ids. First what came to mind is calculate SHA1 and use that as the ID. These IDs will be later, among others used in jquery-generated html as DOM id properties.
My question is, is SHA-1 40 characters long an overkill for this purpose?
Blauelf
@Blauelf
Jun 28 2017 08:23
Another question: How do you create that ID? What do you use as input, and is that reproducible over multiple browsers?
Adit
@adittyagi
Jun 28 2017 08:26
Id="any id name" in html. #id in css
Blauelf
@Blauelf
Jun 28 2017 08:28
This message was deleted
@adittyagi Was that meant to be a response to my question to @amatayamada ?
I wasn't asking about an id attribute (although a elements were using name instead of id when I learnt HTML), I was asking about that hash meant to be used as the ID value.
amatayamada
@amatayamada
Jun 28 2017 08:35
input for sha-1 is all the fields of json object appended after each other
it's not done in javascript, it's done by a python script server side
i mean, the most straightforward ids would be to just assign consequent numbers as the objects come
but as they are simultaneously done in several places it's logistically hard to achieve
sha-1 has the added value that if identical objects come they'll get the same ID, even if it's unlikely
Chris Juchtmans
@kjuchtmans
Jun 28 2017 08:37
Good day coders! :wave:
amatayamada
@amatayamada
Jun 28 2017 08:38
however when I look back at it, 40 char ids for list items in HTML webpage seem like overkill
hence my question if there isn't a more obvious solution
actually a bit longer than 40, 40+ qualifier
Blauelf
@Blauelf
Jun 28 2017 08:40
@amatayamada If the order of the fields is consistent, that should be fine (in Javascript, object property order is somewhat arbitrary, sometimes order of insertion, with in some browsers different behaviour for deleted and re-inserted properties, or alphabetic, with numeric properties in numerical order before the rest in default string ordering).
Ogundele Olumide
@Lumexralph
Jun 28 2017 08:41
@kjuchtmans Hey man!
amatayamada
@amatayamada
Jun 28 2017 08:41
the order isn't a problem, it's always done in the same specified order in the python script and the objects are checked in adherence to a json schema
abhishek4kahol
@abhishek4kahol
Jun 28 2017 08:43
@Marmiz thanks for the help , the problem is sort and i am using vue .
i'll remember get jsonp method :)
CamperBot
@camperbot
Jun 28 2017 08:43
abhishek4kahol sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:cookie: 968 | @marmiz |http://www.freecodecamp.com/marmiz
Chris Juchtmans
@kjuchtmans
Jun 28 2017 08:44

"Twitch.tv API" : how to construct a single query string containing all channel names?

I can only get one channel name to work using the following syntax:
$.getJSON("https://wind-bow.gomix.me/twitch-api/streams/ESL_SC2?callback=?", function(json){ etc

Calling JSONP with a comma-separated string containing multiple channel names - as per the API docs here returns an object including the following error:

Object

  • error: "Bad Request"
  • message: "The parameter "name" was malformed: the value must match the regular expression /^[a-zA-Z0-9][a-zA-Z0-9_]*$/"
  • status: 400

Is using multiple repeating JSONP calls, for each channel name a separate call - the only way? Seems bloated

cheers
k

Claudio Restifo
@Marmiz
Jun 28 2017 08:54
@abhishek4kahol Vue eh? Just make it work with axios and cross origin:
https://codepen.io/anon/pen/EXoVVb?editors=1011
Michiel
@MichielHuijse
Jun 28 2017 08:56
Hi I am working on the wikipediaviewer but get a CORS error with the following request. What exactly should I do? And why is there no documentation on it on the wikimedia pages?
$(document).ready(function(){ $.getJSON( "https://en.wikipedia.org/w//w/api.php?action=query&format=json&list=search&continue=&srsearch=wikipedia&srwhat=text&srprop=timestamp", function( data ) { console.log(data); }); });
I remember to use something like this on the end of the query: ?callback=? But it does not do the trick. Can someone help?
Claudio Restifo
@Marmiz
Jun 28 2017 08:59
@MichielHuijse how was the string what you added the callback query? If I recall correctly JQuery treats that as a JSONP request automatically
Michiel
@MichielHuijse
Jun 28 2017 09:02
@heroiczero thanks, will try some more sandboxing. @Marmiz, I am not to sure about this terminology.
CamperBot
@camperbot
Jun 28 2017 09:02
michielhuijse sends brownie points to @heroiczero and @marmiz :sparkles: :thumbsup: :sparkles:
:cookie: 969 | @marmiz |http://www.freecodecamp.com/marmiz
:star2: 1432 | @heroiczero |http://www.freecodecamp.com/heroiczero
Blauelf
@Blauelf
Jun 28 2017 09:02
@amatayamada If you need reproducible values (same ID on same input), I'd use a hash, or UUID version 3 or 5. If it just were for avoiding collisions, and each input would be handled once, I'd use UUIDs of any version (but if you're ok with same object receiving same ID twice, hash again would work, too).
amatayamada
@amatayamada
Jun 28 2017 09:05
@Blauelf thanks, I think I'll stick to hash then
Claudio Restifo
@Marmiz
Jun 28 2017 09:05
@MichielHuijse how was the URL when you added callback to it?
Blauelf
@Blauelf
Jun 28 2017 09:11
@MichielHuijse Wikipedia allows for adding a nice CORS-friendly header, so you can use it without JSONP. Add origin=* to your URL parameter list.
amatayamada
@amatayamada
Jun 28 2017 09:16
I'm trying to create a dynamically created list with sublists from JSON and hide the sublists until the elements in the main list are clicked.
I have read on SO that you can't use normal query $() on dynamically created objects, you are supposed to use .on() instead.
however, it still doesn't work, as apparent from the JS fiddle - clicking on Vegetables and Animals should make the sublists disappear.
I'd like to understand what problem jquery has here.
also if there are any other non-obvious errors in my approach, please point them out
new to this jquery thing :)
Michuello
@Michuello
Jun 28 2017 09:24

Hi everyone, I have a problem with "Using Objects for Lookups" challenege. Can anyone help me with my code? // Setup
function phoneticLookup(val) {
var result = "";

// Only change code below this line

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

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

Zyberg
@Zyberg
Jun 28 2017 09:25
@Michuello you return an empty string as you don't ever update result.
amatayamada
@amatayamada
Jun 28 2017 09:25
@Michuello no commas after last element in object
also what @Zyberg said
Michuello
@Michuello
Jun 28 2017 09:27
ok, how should I update result?
Zyberg
@Zyberg
Jun 28 2017 09:28
@Michuello result=something
Claudio Restifo
@Marmiz
Jun 28 2017 09:30
@amatayamada haven't looked at your code but in order to JSfiddle to listen to click events you need to change the JS loading in settings from onload to no wrap in body... or it used to be like that :)
amatayamada
@amatayamada
Jun 28 2017 09:33
@Marmiz that's not the case, added a static list to disprove your claim: https://jsfiddle.net/urr7ztup/1/
Claudio Restifo
@Marmiz
Jun 28 2017 09:34

@amatayamada anyway after a quick look this pops out:

"#main_"+externalJson[i].id

what exactly you want to do with this?

amatayamada
@amatayamada
Jun 28 2017 09:34
the static list works, the dynamically generated ones don't
uh, just look at the static list, the code is exactly the same
except ids are dynamically generated in one case and in the other case they're static
Blauelf
@Blauelf
Jun 28 2017 09:36
@amatayamada Haven't read that link, but the problem with dynamically changed code is that you'd have to attach the event listener to the click-sensitive elements you just added to the DOM. The way around would be attaching the event listener to an element that's above and won't be removed, and filter for clicks bubbling from the meant-to-be click-sensitive elements you dynamically create.
Michuello
@Michuello
Jun 28 2017 09:37
thanks @Zyberg and @amatayamada I've figure that challenge out!
CamperBot
@camperbot
Jun 28 2017 09:37
michuello sends brownie points to @zyberg and @amatayamada :sparkles: :thumbsup: :sparkles:
:cookie: 264 | @zyberg |http://www.freecodecamp.com/zyberg
:cookie: 290 | @amatayamada |http://www.freecodecamp.com/amatayamada
amatayamada
@amatayamada
Jun 28 2017 09:40
so in case anyone wonders, this approach worked, turns out relative reference was the key
Blauelf
@Blauelf
Jun 28 2017 09:42
@amatayamada I took your code and replaced var in the loop with let, and it suddenly worked. Turns out all the callbacks used a common i variable.
Blauelf
@Blauelf
Jun 28 2017 09:48

In code

for (var i=0;i<externalJson.length;++i) {
    $(document).on("click", "#main_"+externalJson[i].id, function(){
      $("#sub_"+externalJson[i].id).toggle();
  });
}

you create multiple callbacks, but they all refer to the same i, which at time of invoking the callback has the value of externalJson.length.

One way around are closures, like

function toggleElem(id) { // parameter id is not shared
    $(document).on("click", "#main_"+id, function(){
        $("#sub_"+id).toggle();
    });
}
for (var i=0;i<externalJson.length;++i) {
    toggleElem(externalJson[i].id);
}

or ES6 let

for (let i=0;i<externalJson.length;++i) { // let in for creates a new variable binding in each iteration
    $(document).on("click", "#main_"+externalJson[i].id, function(){
        $("#sub_"+externalJson[i].id).toggle();
    });
}
amatayamada
@amatayamada
Jun 28 2017 10:07
@Blauelf that's actually awesome detective work!
also answers another of my questions, why does jslint say it's bad to define functions inside a loop
I guess not defining them inside a loop prevents situations like this in the first place ;)
Thomas
@sjurs1
Jun 28 2017 10:17
Can one of you guys hack the FCC page and remove "No repeats please" from the curriculum?
Sweet Coding :)
@SweetCodingInc
Jun 28 2017 10:17
@Blauelf, @amatayamada : A much cleaner way would be the begins with selector here
$(document).on("click",  '[id^="main_"]', function(){
  let $this = $(this);
  console.log($this.attr('id'));
})
EpicTriffid
@EpicTriffid
Jun 28 2017 10:17
@EpicTriffid
Hello all. So Im currently working on changing the text of a message when i initiate a click event. I can change the text, but I dont know how to put the fadein/fadeout into my js code
$("#motiv").on("click", function () {
$(".test").html("Loading Motivational Quote...");
});
that's what im doing to change the text of "please slect quote"
Thomas
@sjurs1
Jun 28 2017 10:25
is there a way to "undo" on the FCC? I accidentally deleted a chunk of my code...
Sweet Coding :)
@SweetCodingInc
Jun 28 2017 10:25
ctrl+z ?
Thomas
@sjurs1
Jun 28 2017 10:30
Lol... That just deleted everything
balls
@SweetCodingInc Actually it did work, but I'd refreshed the page so it just removed everything instead. LOL
amatayamada
@amatayamada
Jun 28 2017 10:34
the trolls in this chat man...
:shipit:
next they'll suggest alt+f4 ;-)
Keon Samuel
@keonsam
Jun 28 2017 10:36
ctrl + shift +c
Frostbites
@Frostbites
Jun 28 2017 11:05
hey dudes
I need some help

function largestOfFour(arr) {

  var final = [];


  for (var i = 0; i < arr[i]; i++) {
    for (var j = 0; j < arr[i][j]; j++) {
      if (arr.indexOf(j) < arr.indexOf(j + 1)) {
        final.unshift(j);

      } 
    }
  } 
  return final.sort();
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
This is my coee
code
and I need to create an array that has the largest numbers from all the sub arrays
Keon Samuel
@keonsam
Jun 28 2017 11:07
@Frostbites j is just the for loop count.
plus you should use .push
final.push();
Frostbites
@Frostbites
Jun 28 2017 11:08
@keonsam can you please help me understand this phenomenon?
the j part?
Long Nguyen
@longnt80
Jun 28 2017 11:09
@Frostbites what's your logic?
what are you trying to do?
Keon Samuel
@keonsam
Jun 28 2017 11:09
use the two for loop count to get the number in the array
Frostbites
@Frostbites
Jun 28 2017 11:10
make a new array with the largest values in all sub arrays
Keon Samuel
@keonsam
Jun 28 2017 11:10
for example: arr[i][j];
Long Nguyen
@longnt80
Jun 28 2017 11:10
I know the requirement, I want to know what you're trying to do,
Frostbites
@Frostbites
Jun 28 2017 11:11
my logic is that the value that is counting the loop would be (supposedly) the value of the index from which the loop is iterating
that (j + 1) part is messy
Keon Samuel
@keonsam
Jun 28 2017 11:11
yh indexOf(j) with alway be < indexOf(j +1);
or unknown or -1.
Long Nguyen
@longnt80
Jun 28 2017 11:12
if (arr.indexOf(j) < arr.indexOf(j + 1)) {
        final.unshift(j);

      }
in this part, you insert the smaller value, not the bigger
Frostbites
@Frostbites
Jun 28 2017 11:12
@longnt80 thanks bro.
CamperBot
@camperbot
Jun 28 2017 11:12
frostbites sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 415 | @longnt80 |http://www.freecodecamp.com/longnt80
Frostbites
@Frostbites
Jun 28 2017 11:12
so I just reverse the comparison operator?
Long Nguyen
@longnt80
Jun 28 2017 11:12
@Frostbites what @keonsam said
:point_up: June 28, 2017 6:11 PM
@Frostbites and reverse
kaishuideweidao
@kaishuideweidao
Jun 28 2017 11:13
I couldn't understand it
Long Nguyen
@longnt80
Jun 28 2017 11:14
@Frostbites do you know the method sort()?
Frostbites
@Frostbites
Jun 28 2017 11:17
yes
@longnt80 yes I do
I think I am making a terrible mistake
Long Nguyen
@longnt80
Jun 28 2017 11:18
no, you can do it your way
still work
Frostbites
@Frostbites
Jun 28 2017 11:19

function largestOfFour(arr) {

  var final = [];


  for (var i = 0; i < arr[i]; i++) {
    for (var j = 0; j < arr([i][j]); j++) {
      if (arr.charAr[i][j] > arr.charAt[i][j + 1]) {
       final = final.push(arr.charAt(j));        
      } 
    }
  } 
  return final.sort();
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
this is the new code
nope
Frostbites
@Frostbites
Jun 28 2017 11:20
I tried indexOf() too
Keon Samuel
@keonsam
Jun 28 2017 11:20
indexOf() don't work that way.
arr[i][j] will work
Frostbites
@Frostbites
Jun 28 2017 11:22
can you guys give me a hint
?
Keon Samuel
@keonsam
Jun 28 2017 11:22

function largestOfFour(arr) {

  var final = [];

  for (var i = 0; i < arr[i]; i++) {
    for (var j = 0; j < arr([i][j]); j++) {
      if (arr[i][j] arr[i][j + 1]) {
       final.push(arr[i][j]);        
      } 
    }
  } 
  return final;
}
Frostbites
@Frostbites
Jun 28 2017 11:22
it's returning a blank array
since eternity
:(
koder3
@koder3
Jun 28 2017 11:23
guys why cant i access this chatroom from a challenge?
Long Nguyen
@longnt80
Jun 28 2017 11:24
@keonsam @Frostbites
i < arr[i] should be i < arr[i].length
Frostbites
@Frostbites
Jun 28 2017 11:25
type error
haha
Long Nguyen
@longnt80
Jun 28 2017 11:25
@Frostbites
function largestOfFour(arr) {

  var final = [];


  for (var i = 0; i < arr.length; i++) {
    for (var j = 0; j < arr[i].length; j++) {
      if (arr[i][j] > arr[i][j + 1]) {
       final.push(arr[i][j]);        
      } 
    }
  } 
  return final;
}
Keon Samuel
@keonsam
Jun 28 2017 11:26
that won't work
Long Nguyen
@longnt80
Jun 28 2017 11:26
yes, it works
Keon Samuel
@keonsam
Jun 28 2017 11:26
just a hit.
Frostbites
@Frostbites
Jun 28 2017 11:27
    final.push(arr.charAt[i][j]);
is not a function (says the console embedded here)
Blauelf
@Blauelf
Jun 28 2017 11:27
@Frostbites Not .charAt, you don't have strings.
Frostbites
@Frostbites
Jun 28 2017 11:28

function largestOfFour(arr) {

  var final = [];


  for (var i = 0; i < arr.length(); i++) {
    for (var j = 0; j < arr([i].length()); j++) {
      if (arr[i][j] > arr[i][j + 1]) {
        final.push(arr[i][j]);
      } 
    }
  } 
  return final.sort();
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Keon Samuel
@keonsam
Jun 28 2017 11:28
function largestOfFour(arr) {

  var final = [];


  for (var i = 0; i < arr.length; i++) {
    for (var j = 0; j < arr[i].length; j++) {
  var secNum = 0;
      if (secNum < arr[i][j]) {
       secNum = arr[i][j];        
      } 
    }
final.push(secNum);
  } 
  return final;
}
Frostbites
@Frostbites
Jun 28 2017 11:28
Interesting, thanks @Blauelf
CamperBot
@camperbot
Jun 28 2017 11:28
frostbites sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4480 | @blauelf |http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Jun 28 2017 11:28
@Frostbites Push once per outer loop iteration.
Keon Samuel
@keonsam
Jun 28 2017 11:28
that is the solution
Frostbites
@Frostbites
Jun 28 2017 11:28
@keonsam Mighty Angel! Thanks
CamperBot
@camperbot
Jun 28 2017 11:28
frostbites sends brownie points to @keonsam :sparkles: :thumbsup: :sparkles:
:cookie: 403 | @keonsam |http://www.freecodecamp.com/keonsam
Frostbites
@Frostbites
Jun 28 2017 11:29
var secNum = 0;
Blauelf
@Blauelf
Jun 28 2017 11:29
@keonsam It's one solution, and it isn't even correct. I don't like usage of magic number 0, and you placed it in the wrong line.
@Frostbites var secNum = 0; (or better var secNum = -Infinity;) belongs in the outer loop, before the inner loop.
bilaal-s
@bilaal-s
Jun 28 2017 11:30
Hello everyone.
why does setting the condition in the loop in the "addMultitples" function to 10 instead of 100, cause an error on repl, indicating a potential infinite loop?
function smallestCommons(arr) {
    arr.sort((a, b) => a - b);
    let number1 = arr[0];
    let number2 = arr[1];
    let number1arr = [];
    let number2arr = [];
    let lcm;

    function addMultiples() {
        for (let i = 1; i <= 10; i++) {
            number1arr.push(number1 * i);
            number2arr.push(number2 * i);
        }
    }

    addMultiples();

    for (let i = 0; i < number2arr.length; i++) {
      if (number1arr.indexOf(number2arr[i]) > -1) {
        lcm = number2arr[i];
        break;
      } else {
        addMultiples();
      }
    }
    return lcm;
}
smallestCommons([125, 5]);
Please note, the test case is my own, not part of the challenge
Keon Samuel
@keonsam
Jun 28 2017 11:32

function largestOfFour(arr) {
  // You can do this!
  const array = [];
  for(let i=0;i<arr.length;i++){
   array.push(arr[i].reduce((a,b)=>{
     if(b >a){
       a =b;
     }
     return a;
   },-10000000000000000));
  }
  return array;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Blauelf
@Blauelf
Jun 28 2017 11:33
@keonsam Why not use -Infinity instead of a magic number?
Keon Samuel
@keonsam
Jun 28 2017 11:33
Infinity is a keyword?
Frostbites
@Frostbites
Jun 28 2017 11:33

function largestOfFour(arr) {

  var final = [];


  for (var i = 0; i < arr.length; i++) {
    for (var j = 0; j < arr[i].length; j++) {
      if (arr[i][j] > arr[i][j+1]) {
        final.push(arr[i][j]);
      } 
    }
  } 
  return final;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Blauelf
@Blauelf
Jun 28 2017 11:33
Infinity is a global variable of floating point value Infinity.
Frostbites
@Frostbites
Jun 28 2017 11:33
This is 80% correct
returns 4 numbers but instead of returning one from each, it returns 2 from the last sub array, and none from the third sub-array
Blauelf
@Blauelf
Jun 28 2017 11:34
@Frostbites If you push, then do it in the outer loop, not inner loop.

@keonsam ES6 version, using ES6 features:

  return arr.map(subArr => Math.max(...subArr));

No loop, no reduce.

Keon Samuel
@keonsam
Jun 28 2017 11:35
nice that is true.
Frostbites
@Frostbites
Jun 28 2017 11:35
should I use that ES6 version too, or should I just try finding this out from the basics?
Keon Samuel
@keonsam
Jun 28 2017 11:36
.map is still a loop.
Blauelf
@Blauelf
Jun 28 2017 11:37
@Frostbites I think one should be able to do both. And for a specific problem pick the one better suited for the current problem.
@keonsam Of course it is. And using the spread operator lets me use a loop in Math.max, so I still have the same two nested loops, just well-hidden.
bilaal-s
@bilaal-s
Jun 28 2017 11:38
any ideas?
J-Mag Guthrie
@baseballpoetess
Jun 28 2017 11:40
Good <time-of-day>; @bilaal-s any ideas about what? I'm newly arrived.