These are chat archives for FreeCodeCamp/HelpJavaScript

26th
Apr 2016
DanishKalim
@DanishKalim
Apr 26 2016 00:00
@Chrono79 plz help me out plz.
Diego Mayer
@Chrono79
Apr 26 2016 00:00
@DanishKalim I'm trying to figure out how to do it
DanishKalim
@DanishKalim
Apr 26 2016 00:02
ok bro.
so when your uncheck button is clicked, simply use prop to toggle checked yes/no. There might be a way to do it in one line but I think you will have to do if (button is checked) {$("#checkbox").prop(checked,false); } else {$("#checkbox').prop(checked,true);} thats pseudo code and might not be 100% correct syntax wise
DanishKalim
@DanishKalim
Apr 26 2016 00:07
@calicode bro i want to add button in my code which deletes checked element
Andrew Schmidthuber
@calicode
Apr 26 2016 00:13
@DanishKalim sorry, i mis-read your question. It looks like you are using regular javascript. The way I would solve that is to set a class on an element when its checked, and then select elements with that class and remove them. Googling remove dom elements would probably help with the last part.
http://www.w3schools.com/js/js_htmldom_document.asp has a lot of what you will need
Chris Cullen
@123xylem
Apr 26 2016 00:17
Hello guys... I am finding the longest word in a string... Any ideas why this produces no results? Could someone give me a hint please!!?

function findLongestWord(str) {
str= str.split(" ");
var newArr =[];
newArr.push(str);
for(i=0;i<=newArr;i++){
var wordLength= newArr[i];
}
return wordLength;

}

findLongestWord("The quick brown fox jumped over the lazy dog");

I have split the string into words... then pushed the string into an array
and in that array I am using a forloop to count the word length and am trying to store that as a variable
Moisés Man
@moigithub
Apr 26 2016 00:21
@123xylem explain each line of code u have :)
Ken Haduch
@khaduch
Apr 26 2016 00:21
@123xylem - look up the .split() method - it generates an array containing each of the words.
Diego Mayer
@Chrono79
Apr 26 2016 00:21

@DanishKalim beware, you have to work it a little, for example, hide the button when there are no fruits

var fruits=[];
  function addfruit(){
     var cfruit=document.getElementById("fruit").value;
      fruits.push(cfruit);
       displayfruit() ;
    }

    function displayfruit(){

      var x = 0;
        document.getElementById("allfruits").innerHTML = "";
       for(x=0; x<fruits.length; x++){
        document.getElementById("allfruits").innerHTML  +=  ' <input type="radio" class="fruits" name="thefruit" />' + fruits[x]  + "<br>"; 

         }   
    }

    function removefruit(){

       var x = document.getElementsByClassName("fruits");
       for(var i=0; i<x.length; i++){
         if (x[i].checked) fruits.splice(i, 1); 

         }   
        displayfruit();
    }

and

<input type="text" id="fruit"  onkeydown = "if (event.keyCode == 13) addfruit()"/>


        <div id="allfruits"></div>

<input type="button" id="remove" value="Remove" onClick="removefruit()"/>
Andrew Schmidthuber
@calicode
Apr 26 2016 00:21
str.split turns it into an array already. so you are pushing an array to an array. i <= newArr is going to stop right away I think or after one loop. newArr.length is probably what you are looking for. From there you need to compare the length of the current array element to the biggest known so far
Chris Cullen
@123xylem
Apr 26 2016 00:22
@moigithub @khaduch @calicode thanks Ok Point taken on the split method aswelll
CamperBot
@camperbot
Apr 26 2016 00:22
123xylem sends brownie points to @moigithub and @khaduch and @calicode :sparkles: :thumbsup: :sparkles:
:star: 367 | @calicode | http://www.freecodecamp.com/calicode
:star: 1011 | @moigithub | http://www.freecodecamp.com/moigithub
:star: 1009 | @khaduch | http://www.freecodecamp.com/khaduch
Chris Cullen
@123xylem
Apr 26 2016 00:24
Ok here is my change but still no joy

function findLongestWord(str) {
str= str.split(" "); //makes string array split into seperate words

for(i=0;i<=str;i++){ //scans array counting characters in each word
var wordLength= str[i]; //creates new var that stores Scans results.. From here I can just compare the numbers
}
return wordLength;

}

findLongestWord("The quick brown fox jumped over the lazy dog");

Btw how do i make my code look like code in this chatroom?
Ken Haduch
@khaduch
Apr 26 2016 00:24
help format
CamperBot
@camperbot
Apr 26 2016 00:24

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

Ken Haduch
@khaduch
Apr 26 2016 00:25
@123xylem ^^^^ formatting code
@123xylem - for(i=0;i<=str;i++) - you are trying to iterate over an array - something needs to be added to this to tell you when to stop...
Chris Cullen
@123xylem
Apr 26 2016 00:26
function findLongestWord(str) {
str=  str.split(" "); //makes string array split into seperate words

  for(i=0;i<=str;i++){ //scans array counting characters in each word
var wordLength= str[i]; //creates new var that stores Scans results.. From here I can just compare the numbers
  }
 return wordLength;

}

findLongestWord("The quick brown fox jumped over the lazy dog");
thanks
?doesnt sttr<= say stop at the end of str
Andrew Schmidthuber
@calicode
Apr 26 2016 00:27
try changing that to str.length
Chris Cullen
@123xylem
Apr 26 2016 00:27
o yea my bad
Ken Haduch
@khaduch
Apr 26 2016 00:27
@123xylem - str is now an array, so you need to use the .length value.
Andrew Schmidthuber
@calicode
Apr 26 2016 00:28
var blah = "the uqick brown fox".split(" ")
undefined
0 < blah
false
1 < blah
false
1 < blah.length
true
Chris Cullen
@123xylem
Apr 26 2016 00:28
well its still not producing anything.. it says wordlength is out of scope but I dont see hwo I can do that
Bob Evermore
@BeeQuickest
Apr 26 2016 00:28
@khaduch are you still around?
Ken Haduch
@khaduch
Apr 26 2016 00:28
@BeeQuickest - yes, still here, Bob
D.Mills
@millsdee74
Apr 26 2016 00:29
thanks @Rafase282 for your help with Checkpoint: Word Blanks
CamperBot
@camperbot
Apr 26 2016 00:29
millsdee74 sends brownie points to @rafase282 :sparkles: :thumbsup: :sparkles:
:star: 1182 | @rafase282 | http://www.freecodecamp.com/rafase282
Bob Evermore
@BeeQuickest
Apr 26 2016 00:30
I found the developer tools console but I don't know how to use it. Is there a discussion somewhere that I can refer to? Sorry to be so lame, but this is all really foreign to me
Chris Cullen
@123xylem
Apr 26 2016 00:30
is it not producing anything because its saying wordLength is out of scope? Im not sure how to change that except to define WordLength before the function altogether
Andrew Schmidthuber
@calicode
Apr 26 2016 00:31
define it outside of the for loop, it shouldn't be out of scope
i dont know why its giving you that error tbh. but you also want to be looking at str[i].length
Ken Haduch
@khaduch
Apr 26 2016 00:32
@BeeQuickest - well, if you look at the "Map" on the free code camp, there are some things on the bottom of the list, there is a section of videos on "Chrome Developer Tools" - it might be good enough to help you get oriented to how to use it? But there is probably a tutorial for Edge, as well, somewhere out there on the interwebs?
Chris Cullen
@123xylem
Apr 26 2016 00:33
@calicode ah thanks... yes it was defined in the forloop so thats why it was out of scope... I will try adding the .length to my [i] aswell... I need something extra to learn this stuff I guess cos I have to ask so many questions to get through each challenge :/
CamperBot
@camperbot
Apr 26 2016 00:33
123xylem sends brownie points to @calicode :sparkles: :thumbsup: :sparkles:
Ken Haduch
@khaduch
Apr 26 2016 00:33
@BeeQuickest this site: https://developer.microsoft.com/en-us/microsoft-edge/platform/documentation/f12-devtools-guide/ has information. BAsically, for using console.log, you would probably want to use "The Console tool (CTRL+2)"
CamperBot
@camperbot
Apr 26 2016 00:33
:warning: 123xylem already gave calicode points
Islam Ibakaev
@dagman
Apr 26 2016 00:33
added some changes to portfolio http://codepen.io/dagman/full/WwKrgX/
Joseph
@revisualize
Apr 26 2016 00:34
function is_a_in(val) {
    for (var i = 0; i > val.length(); i++) {
            if (val[i] == "a") {
                      return true;
            }
     }
     return false; // Not out of scope
}
@calicode
Andrew Schmidthuber
@calicode
Apr 26 2016 00:34
yea thats the wierd thing, javascript doesn't use blockscope its function. might be something with fcc's editor
Bob Evermore
@BeeQuickest
Apr 26 2016 00:34
I'm sticking with Chrome. I only ventured onto Edge earlier today to see how it differed. Not impressed. Thanks for pointing me to the videos. It's kind of embarassing to have to ask something so obvious, but at the end of the Map doesn't seem like the most logical place to put something that a new student will put to heavy use and then not tell them it's available...
DanishKalim
@DanishKalim
Apr 26 2016 00:34
@Chrono79 ur code is not working dear.
Bob Evermore
@BeeQuickest
Apr 26 2016 00:34
@khaduch Thank you!
CamperBot
@camperbot
Apr 26 2016 00:34
beequickest sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star: 1010 | @khaduch | http://www.freecodecamp.com/khaduch
Andrew Schmidthuber
@calicode
Apr 26 2016 00:34
might be because the for loop never ran idk
Ken Haduch
@khaduch
Apr 26 2016 00:35
@123xylem - it might seem counter-productive, but as you have probably learned and been exposed to quite a bit of new stuff, perhaps going back and reviewing some of the earlier lessons would be helpful? I always find that after getting some practice with something, going back and re-reading is helpful to make the information sink in.
Joseph
@revisualize
Apr 26 2016 00:36
@calicode That code I wrote above is an example. If I included an else if the first val[0] was not "a" it would invoke the else process. Therefore, the loop would only run once.
Chris Cullen
@123xylem
Apr 26 2016 00:36
@khaduch @calicode btw just out of curiousity can you guys see an easy fix to this naturally? Or does it still take some effort?
Joseph
@revisualize
Apr 26 2016 00:36
Does that make sense?
Andrew Schmidthuber
@calicode
Apr 26 2016 00:36
it takes a lot of practice and running into these same issue
Ken Haduch
@khaduch
Apr 26 2016 00:37
@BeeQuickest - you're welcome - basically if you can get into the tools (looks like F12 is the key?) then CTRL + 2 should open the console. Then try to run your code that prints the firstName values out and see what you see. Inserting console.log statements is really helpful to figuring out what is going on in various stages of your code's execution.
Ryan
@ryanjmack
Apr 26 2016 00:37

Seek and Destroy Bonfire

function destroyer(arr) {
var args = Array.prototype.slice.call(arguments, 1);

var newArr = arr.filter(function(val) {
return args.indexOf(val); 
});

return newArr;
}

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

So it's logging [1, 3, 1, 3] right now... So it filters out the first argument of 2, but how could I make it repeat for additional arguments?

Andrew Schmidthuber
@calicode
Apr 26 2016 00:38
@revisualize yep it makes sense.
Ken Haduch
@khaduch
Apr 26 2016 00:40

@123xylem - you're still talking about the longest word challenge? I would suggest that you just make a loop that will print each word out to console.log, and I hope you know how to access the JavaScript console in your browser tools? It will give you some insight and you can build on that. The next thing is that for each word, you get the .length and have a variable that you use to compare that against, and store the longest word's length? After you loop through all of the words, you should have the longest word value, and that is what you return.

If you're talking about something else - never mind! :)

Islam Ibakaev
@dagman
Apr 26 2016 00:40
@ryanjmack u should return val if val not existed in args array
Diego Mayer
@Chrono79
Apr 26 2016 00:40
Maria Campbell
@interglobalmedia
Apr 26 2016 00:40
function repeatStringNumTimes(str, num) {
  // repeat after me
  num = Number(num);

  var result = "";
  while(true) {
    // "&" is the Bitwise & operator. Performs the AND operation on each pair of bits. a       
    // AND b yield 1 only if both a and b are 1.
    if(num & 1) {
      result += str;
    }
    // unsigned rightshift bitshift operator shifts the next digit to the least                           // significant (rightmost) position.
    num >>>= 1;
    if(num < 0) return result === "";
    str += str;
  }
  return result;
}

repeatStringNumTimes("abc", 3);
I almost have this down, but am wondering what I am missing in terms of when num < 0 return ""; Is this otherwise legal code, or will I have to reconfigure this whole thing? Any feedback would be highly appreciated. Thanks!
Andrew Schmidthuber
@calicode
Apr 26 2016 00:41
@ryanjmack i think i just looped through arguments[i] using length. for yours you could just update the slice call
Sergiusz
@Wetlize
Apr 26 2016 00:42

Hey guys, might be stupid question because I'm a little bit sleepy, but can someone answer to me please, why:

function mutation(arr) {
  var string1 = arr[0].toLowerCase();
  var string2 = arr[1].toLowerCase();

  for (var i = 0; i < string2.length; i++) {
    if (string1.indexOf(string2[i]) === -1) {
      return false;
    }
  }
  return true;
}

mutation(["hello", "hey"]);

return false/true as it should to be, but:

function mutation(arr) {
  var string1 = arr[0].toLowerCase();
  var string2 = arr[1].toLowerCase();

  for (var i = 0; i < string2.length; i++) {
    if (string1.indexOf(string2[i]) === -1) {
      return false;
    } else {
      return true;
  }
}

mutation(["hello", "hey"]);

return true?

Daniel Godigna
@DGAcode
Apr 26 2016 00:44
hello
can somebody explain me what to do in Stand in Line
Diego Mayer
@Chrono79
Apr 26 2016 00:45
@Wetlize if you return true inside the loop when the first letter is in both words it stop comparing
Also, it seems you're missing a closing }
Frank XC
@tenkdayz
Apr 26 2016 00:47
@33hawk show your code
Daniel Godigna
@DGAcode
Apr 26 2016 00:47
well is the exercise
of js
Matt James
@thirteenten
Apr 26 2016 00:48
Hello everyone, im having some issues getting started on the roman numeral converter. can someone help point me in the right direction?
Sergiusz
@Wetlize
Apr 26 2016 00:49
@Chrono79 I see now, thanks for the answer
CamperBot
@camperbot
Apr 26 2016 00:49
wetlize sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star: 498 | @chrono79 | http://www.freecodecamp.com/chrono79
Frank XC
@tenkdayz
Apr 26 2016 00:49
@33hawk what do you need to do?
Daniel Godigna
@DGAcode
Apr 26 2016 00:49
@tenkdayz Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.
Frank XC
@tenkdayz
Apr 26 2016 00:50
@33hawk do you know how to use .push() and .shift() ?
Daniel Godigna
@DGAcode
Apr 26 2016 00:51
yeap
how do I paste my code in the chat
?
Diego Mayer
@Chrono79
Apr 26 2016 00:51
help format
CamperBot
@camperbot
Apr 26 2016 00:51

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

KimJongUno
@KimJongUno
Apr 26 2016 00:52
@33hawk i guess you could store the value of the first element in a variable, then do the push and shift things and return the variable that has the deleted number
Sergiusz
@Wetlize
Apr 26 2016 00:53
@33hawk you need to push item inside the array, and then create a variable, which will shift array.
Frank XC
@tenkdayz
Apr 26 2016 00:53
@33hawk just push the item and assign the shift index to a variable.
Mariya
@mariyadiminsky
Apr 26 2016 00:53
Anyone know if there are frameworks or anything that can be used to create interactive choice based stories for ios like in Walking Dead ios games? I've been searching and can't really find anything solid.
Daniel Godigna
@DGAcode
Apr 26 2016 00:53
OK thanks everybody
Diego Mayer
@Chrono79
Apr 26 2016 00:53
I think he should return the shift, no var needed
Daniel Godigna
@DGAcode
Apr 26 2016 00:54

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

return item; // Change this line
}

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

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

sorry my bad
Sergiusz
@Wetlize
Apr 26 2016 00:57
@33hawk btw, @Chrono79 is right, no need variable. just return the shift.
Daniel Godigna
@DGAcode
Apr 26 2016 00:57
@Chrono79 @Wetlize Thanks
CamperBot
@camperbot
Apr 26 2016 00:57
33hawk sends brownie points to @chrono79 and @wetlize :sparkles: :thumbsup: :sparkles:
:star: 273 | @wetlize | http://www.freecodecamp.com/wetlize
:star: 499 | @chrono79 | http://www.freecodecamp.com/chrono79
MikeBeers
@MikeBeers
Apr 26 2016 00:58
working on the calc app. I am trying to create click listener. From listener use a switch statement to display the pushed button. Not quite sure how to grab ID from the switch statement.
$(".target").click(function(id) {
    var number;
 switch(number) {
         case "one":
             alert("one");

         case $("#two"):
         $('#input').val($('#input').val()+2);
 }
    });
Diego Mayer
@Chrono79
Apr 26 2016 01:00
@MikeBeers does this work inside your function?
$(this).attr("id")
Ryan
@ryanjmack
Apr 26 2016 01:01
@dagman thank you
CamperBot
@camperbot
Apr 26 2016 01:01
ryanjmack sends brownie points to @dagman :sparkles: :thumbsup: :sparkles:
:star: 439 | @dagman | http://www.freecodecamp.com/dagman
MikeBeers
@MikeBeers
Apr 26 2016 01:01
@Chrono79 on case part?
Islam Ibakaev
@dagman
Apr 26 2016 01:01

@Wetlize this is because in second solution

function mutation(arr) {
  var string1 = arr[0].toLowerCase();
  var string2 = arr[1].toLowerCase();

  for (var i = 0; i < string2.length; i++) {
    if (string1.indexOf(string2[i]) === -1) {
      return false;
    } else {
      return true;
  }
}

mutation(["hello", "hey"]);

you returns true immidiately after you find out that hello contains 'h' but u also should check wether 'e' and 'y' are in 'hello'

Rafael J. Rodriguez
@Rafase282
Apr 26 2016 01:01
You are welcome @millsdee74
Diego Mayer
@Chrono79
Apr 26 2016 01:02
@MikeBeers
var number = $(this).attr("id");
Islam Ibakaev
@dagman
Apr 26 2016 01:02
@Rafase282 yo man what about this http://codepen.io/dagman/full/WwKrgX/
Chris Cullen
@123xylem
Apr 26 2016 01:03
help Find the Longest Word in a String
CamperBot
@camperbot
Apr 26 2016 01:03

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

Explanation:

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

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

Sergiusz
@Wetlize
Apr 26 2016 01:04
@dagman yeah, @Chrono79 is already helped me. thanks anyway, that was really stupid.
CamperBot
@camperbot
Apr 26 2016 01:04
wetlize sends brownie points to @dagman and @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: wetlize already gave chrono79 points
:star: 440 | @dagman | http://www.freecodecamp.com/dagman
Túlio Citadin Gonçalves
@tuliocg
Apr 26 2016 01:04
hi there
i m on clng 184 n havin problem with it
```js
MikeBeers
@MikeBeers
Apr 26 2016 01:05
@Chrono79 when I used at the case statement it worked. Not sure about at the var statement
Túlio Citadin Gonçalves
@tuliocg
Apr 26 2016 01:05
function nextInLine(arr, item) {
  // Your code here
  var temp = arr.shift();
  arr.push(item);

  return temp;  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
MikeBeers
@MikeBeers
Apr 26 2016 01:05
```
$(".target").click(function(id) {
    var number = $(this).attr("id");
 switch(number) {
     case "#one":
             alert("one");

         case $("#two"):
         $('#input').val($('#input').val()+2);
 }
    });
Chase Webb
@jerrybaggin
Apr 26 2016 01:06
function palindrome(str) {
  // Good luck!
  var newString = str.toLowerCase().replace(/\W|_/g,'');
  var reversedString = newString.split('').reverse('').join();

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


}



palindrome("eye");
could anyone take a look at this? Im not sure what im missing??
Diego Mayer
@Chrono79
Apr 26 2016 01:06
@MikeBeers case "one" without the #
Chris Cullen
@123xylem
Apr 26 2016 01:07
OK Ive nearly got this easy problem cracked!!!
I dont know why my for loop isnt storing all the variables... If you know a good link I can look at to help then please post or give me a hint

function findLongestWord(str) {
str=  str.split(" "); //makes string array split into seperate words
var wordLength=0;
  for(i=0;i<=str.length;i++){ //scans array counting characters in each word
   wordLength =str[i].length;    // TRYING TO Get this to tell me the lengths of ALL parts of this array.!!       

  }
  return wordLength;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
Diego Mayer
@Chrono79
Apr 26 2016 01:07
@jerrybaggin is reverse().join("")
MikeBeers
@MikeBeers
Apr 26 2016 01:08
@Chrono79 thanks
CamperBot
@camperbot
Apr 26 2016 01:08
mikebeers sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star: 500 | @chrono79 | http://www.freecodecamp.com/chrono79
Chase Webb
@jerrybaggin
Apr 26 2016 01:08
@Chrono79 lol appericate it
nabeelaa
@nabeelaa
Apr 26 2016 01:10
hi..im having troubles pulling the rain data from openweather API. Can anyone please help me with this. It shows undefined http://codepen.io/nabeela/pen/wGEdLx
KimJongUno
@KimJongUno
Apr 26 2016 01:15
@123xylem first of all, with this line wordLength =str[i].length; you store the word that is in the position [i] of the array, which means that the first time when i = 0, wordLength will store the length of "The", but the second time, when i = 1 the value of wordLength now will be the length of"quick", so when your for loop ends, you will be returning the value of the length of the last word "dog".
Islam Ibakaev
@dagman
Apr 26 2016 01:16
@123xylem i think i find what u need :smile:
function findLongestWord(str) {
    str = str.split(" ");
    var wordL = 0, i = 0;
    for(i = 0; i < str.length; i++) {
        if(str[i].length > wordL) {
            wordL = str[i].length;
        }    
    }
    return wordL;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
Frank XC
@tenkdayz
Apr 26 2016 01:17
@nabeelaa where is this data.rain['3h'] ? I dont see it anywhere in the obj
Chris Cullen
@123xylem
Apr 26 2016 01:17
@KimJongUno cant wordL store more than 1 instance of [i]?
KimJongUno
@KimJongUno
Apr 26 2016 01:19
@123xylem it could if you make it an array, but you have an int, and it's changing your previous values to store the new ones
nabeelaa
@nabeelaa
Apr 26 2016 01:19
@tenkdayz How do I pull data for rain?
Chris Cullen
@123xylem
Apr 26 2016 01:19
@dagman btw thanks I want to figure it out without copyng your code tho
CamperBot
@camperbot
Apr 26 2016 01:19
123xylem sends brownie points to @dagman :sparkles: :thumbsup: :sparkles:
:star: 441 | @dagman | http://www.freecodecamp.com/dagman
Frank XC
@tenkdayz
Apr 26 2016 01:20
@nabeelaa what kind of data do you want to get?
KimJongUno
@KimJongUno
Apr 26 2016 01:20
@KimJongUno You can still use an int for this challenge tho, all you need to store in it is the highest value, which can be done with a comparison in your loop.
Chris Cullen
@123xylem
Apr 26 2016 01:21
ahhok
nabeelaa
@nabeelaa
Apr 26 2016 01:21
@tenkdayz rain.3h - Precipitation volume mm per 3 hours. This is what I found in the API docs
but its not working for me
Frank XC
@tenkdayz
Apr 26 2016 01:21
@nabeelaa from what lat and lon ?
nabeelaa
@nabeelaa
Apr 26 2016 01:22
@tenkdayz current location
Diego Mayer
@Chrono79
Apr 26 2016 01:23
@nabeelaa maybe not related but don't define a class name starting with a number
http://stackoverflow.com/questions/448981/which-characters-are-valid-in-css-class-names-selectors
Frank XC
@tenkdayz
Apr 26 2016 01:23
@nabeelaa i doesn't show in my current location
@nabeelaa i see it now.. it only show where it's raining.. i see
ali
@ahamidizadeh
Apr 26 2016 01:25
can someone help me with "profile lookup">? step 196 freecodecamp...
Diego Mayer
@Chrono79
Apr 26 2016 01:26
@ahamidizadeh Paste your code
ali
@ahamidizadeh
Apr 26 2016 01:26

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
for (var i=0; i<contacts.length;i++)
for (var j=0; j < contacts[i].length;j++)
return constant[i][j];

// Only change code above this line
}

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

nabeelaa
@nabeelaa
Apr 26 2016 01:26
@tenkdayz yes its only showing where its raining.
thanks for you help @tenkdayz
CamperBot
@camperbot
Apr 26 2016 01:27
nabeelaa sends brownie points to @tenkdayz :sparkles: :thumbsup: :sparkles:
:star: 456 | @tenkdayz | http://www.freecodecamp.com/tenkdayz
ali
@ahamidizadeh
Apr 26 2016 01:27
firstName has to match and prop value has to show if it matches also...
Diego Mayer
@Chrono79
Apr 26 2016 01:27
@ahamidizadeh use ```when pasting code like this
help format
CamperBot
@camperbot
Apr 26 2016 01:27

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

MikeBeers
@MikeBeers
Apr 26 2016 01:28
$(".target").click(function(id) {
    var number = $(this).attr("id");
 switch(number) {
     case "one":
             $('#input').val($('#input').val()+1);
      case "two":
         $('#input').val($('#input').val()+2);
         case "three":
         $('#input').val($('#input').val()+3);
         case "four":
         $('#input').val($('#input').val()+4);
         case "five":
         $('#input').val($('#input').val()+5);
         case "six":
         $('#input').val($('#input').val()+6);
         case "seven":
         $('#input').val($('#input').val()+7);
         case "eight":
         $('#input').val($('#input').val()+8);
         case "nine":
         $('#input').val($('#input').val()+9);
         case "zero":
         $('#input').val($('#input').val()+0);
 }
    });
@Chrono79 each button push puts all 10 numbers lol
Diego Mayer
@Chrono79
Apr 26 2016 01:29
@MikeBeers where are your break; s?
ali
@ahamidizadeh
Apr 26 2016 01:30

```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
for (var i=0; i<contacts.length;i++)
for (var j=0; j < contacts[i].length;j++)
return constant[i][j];

// Only change code above this line
}

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

oops
Frank XC
@tenkdayz
Apr 26 2016 01:30
@nabeelaa np.. strange because it's raining where I'm at and your syntax seems to be correct.. and it's also undefined.
Diego Mayer
@Chrono79
Apr 26 2016 01:30
@ahamidizadeh you're not using your params inside the function, also, what is constant[i][j] ?
use shift+enter to go to the next line, left the ```in a line alone, at the top of the code and at the end
ali
@ahamidizadeh
Apr 26 2016 01:32
I guess im trying to reach the properties or prop but dont know how in a array of objects...
MikeBeers
@MikeBeers
Apr 26 2016 01:32
@Chrono79 the last few switch statements I used I did not use break.
Diego Mayer
@Chrono79
Apr 26 2016 01:32
@MikeBeers they're needed
ali
@ahamidizadeh
Apr 26 2016 01:33
```
MikeBeers
@MikeBeers
Apr 26 2016 01:33
i used a return.
ali
@ahamidizadeh
Apr 26 2016 01:33
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
for (var i=0; i<contacts.length;i++)
  for (var j=0; j < contacts[i].length;j++)
    return constant[i][j];


// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
thanks @Chrono79
CamperBot
@camperbot
Apr 26 2016 01:34
ahamidizadeh sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star: 501 | @chrono79 | http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Apr 26 2016 01:34
@ahamidizadeh better, now check the other things I told you
You don't need more than one loop there
MikeBeers
@MikeBeers
Apr 26 2016 01:36
@Chrono79 thoughts on putting if statements as part of the switch?
Taneisha S. Mitchell-Gayle
@taneipoo
Apr 26 2016 01:36
@llamatarianism & @sjames1958gm I need you guys help!
I'm at palidrome & I've figured out quite a spot of it, my last challenge is the special characters, I have /[^a-zA-Z0-9-_&\/\\#+()$~%.'":*?<>{} ]/ in my search string however when I do a print of the string before reversing it I get 0_0(:/-:)0-0 when it's reversed I'm getting 0-0):-/:(0_0 can you see what my challenge is -_-
good now how do I fix it lol
MikeBeers
@MikeBeers
Apr 26 2016 01:36
 case "zero":
         if ($("#input").val() ) {
         $('#input').val($('#input').val()+0);
         }
 break;
 }
Diego Mayer
@Chrono79
Apr 26 2016 01:37
@MikeBeers why don't
$(".target").click(function() {
    var number = $(this).attr("id");
 switch(number) {
     case "one":
             $('#input').val($('#input').val()+1);
break;
      case "two":
         $('#input').val($('#input').val()+2);
break;
         case "three":
         $('#input').val($('#input').val()+3);
break;
         case "four":
         $('#input').val($('#input').val()+4);
break;
         case "five":
         $('#input').val($('#input').val()+5);
break;
         case "six":
         $('#input').val($('#input').val()+6);
break;
         case "seven":
         $('#input').val($('#input').val()+7);
break;
         case "eight":
         $('#input').val($('#input').val()+8);
break;
         case "nine":
         $('#input').val($('#input').val()+9);
break;
         case "zero":
         $('#input').val($('#input').val()+0);
break;
 }
    });
Rafael J. Rodriguez
@Rafase282
Apr 26 2016 01:39
@dagman that looks nice for the most part
MikeBeers
@MikeBeers
Apr 26 2016 01:40
@Chrono79
$(".target").click(function(id) {
    var number = $(this).attr("id");
 switch(number) {
     case "one":
             $('#input').val($('#input').val()+1);
         break;
      case "two":
         $('#input').val($('#input').val()+2);
         break;
         case "three":
         $('#input').val($('#input').val()+3);
    break;     
     case "four":

         $('#input').val($('#input').val()+4);
    break;     
     case "five":
         $('#input').val($('#input').val()+5);
    break;     
     case "six":
         $('#input').val($('#input').val()+6);
    break;
     case "seven":
         $('#input').val($('#input').val()+7);
    break;
     case "eight":
         $('#input').val($('#input').val()+8);
    break;     
     case "nine":
         $('#input').val($('#input').val()+9);
    break;     
     case "zero":
         if ($("#input").val() ) {
         $('#input').val($('#input').val()+0);
         }
 break;
 }
    });
case zero?
Luis
@zdrifted
Apr 26 2016 01:41
Am I close or way off in my approach to Caesars Cipher algorithm?
function rot13(str) { // LBH QVQ VG!

  var codeUni = [];
  var splitStr = str.split("");

  for (i = 0; i < splitStr.length; i++) {
    codeUni.push( splitStr[i].charCodeAt(0) + 13 );

  }



  return String.fromCharCode(codeUni);
}
MikeBeers
@MikeBeers
Apr 26 2016 01:41
it works, but wondering if it is okay to use if statements inside the switch?
Diego Mayer
@Chrono79
Apr 26 2016 01:41
@MikeBeers +"0" instead of +0 ?
And I think it should be +"X" instead of +X where X is the number of the button, isn't that right? Maybe it's casting the sum as a string anyway
MikeBeers
@MikeBeers
Apr 26 2016 01:42
?
Diego Mayer
@Chrono79
Apr 26 2016 01:45
@Rushh not all chars have to shift 13 places to the same side
MikeBeers
@MikeBeers
Apr 26 2016 01:45
I am now able to put the numbers in the field.
Luis
@zdrifted
Apr 26 2016 01:46
thanks @Chrono79 I forgot about that
CamperBot
@camperbot
Apr 26 2016 01:46
rushh sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star: 502 | @chrono79 | http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Apr 26 2016 01:48
@MikeBeers you're disabling to input 0.5 for example that way
Only one 0 is ok
Stephen James
@sjames1958gm
Apr 26 2016 01:48
@Rushh I don't think fromCharCode takes an array. Maybe push the fromCharCode value. Also you are supposed to pass some characters through unchanged and add 13 to some and subtract 13 from others.
Erik Maurer
@MauPow
Apr 26 2016 01:49
Basic question: When do I put something inside of the document load function, and when do I place it before or after?
MikeBeers
@MikeBeers
Apr 26 2016 01:49
I was trying to make it so dont have a whole bunch of leading zero's
Erik Maurer
@MauPow
Apr 26 2016 01:50
I know it loads on page load obviously but just want a really basic rule
For context I'm designing my wikipedia search page
MikeBeers
@MikeBeers
Apr 26 2016 01:50
@Chrono79 I like that
Stephen James
@sjames1958gm
Apr 26 2016 01:51
@taneipoo What are you selecting with that regex
Luis
@zdrifted
Apr 26 2016 01:53
thanks @sjames1958gm I think you're right
CamperBot
@camperbot
Apr 26 2016 01:53
rushh sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 806 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Apr 26 2016 01:56
@MauPow If you are doing anything that references the HTML (DOM) it needs to be in document.loaded or ready.
Erik Maurer
@MauPow
Apr 26 2016 01:56
ok... what do you mean by ready
Stephen James
@sjames1958gm
Apr 26 2016 01:57
There is a document.ready() function, not sure if there is a difference between that and loaded, ready may be jquery only
Erik Maurer
@MauPow
Apr 26 2016 01:58
ok cool
Taneisha S. Mitchell-Gayle
@taneipoo
Apr 26 2016 02:02
never mind @sjames1958gm I finally figured it out lol
I had it like this var aStr = str.toLowerCase().split(" ").join("").replace(/[^a-zA-Z-():\/{}\\0-9 ]/g, "");
I eventually realized I was over complicating the problem & took out all the special char & left it as alphanumeric...
passed with flying colors :-)
OmMinky
@OmMinky
Apr 26 2016 02:02
HI all, can anybody help with Nesting For Loops? I don't know where to start
Taneisha S. Mitchell-Gayle
@taneipoo
Apr 26 2016 02:03
thanks for coming to my rescue bro @sjames1958gm
CamperBot
@camperbot
Apr 26 2016 02:03
taneipoo sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 807 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Diego Mayer
@Chrono79
Apr 26 2016 02:08
You have to use one loop inside the other to run through the elements of a 2d array
The example in the challenge description is very clear
Instead of using console.log you have to store the product
@OmMinky the above message was for you
Taneisha S. Mitchell-Gayle
@taneipoo
Apr 26 2016 02:16
@Chrono79 I never used a loop I used toLowerCase, split, join & replace all on one line & saved to one variable then for the 2nd part (to reverse the string) I used the 1st variable & applied split, reverse and join to it.
OmMinky
@OmMinky
Apr 26 2016 02:16
@Chrono79 , will try, so no need to use console.log?
Diego Mayer
@Chrono79
Apr 26 2016 02:16
@taneipoo Sorry, I mentioned you and I meant OmMinky, just missclicked.
Stephen James
@sjames1958gm
Apr 26 2016 02:17
@taneipoo /\W|_/ is all you needed
@taneipoo That selects all non alphanumeric and because for some reason is considered alpha numeric
Taneisha S. Mitchell-Gayle
@taneipoo
Apr 26 2016 02:17
@Chrono79 oh that's cool :-)
aahhhhh cool @sjames1958gm
Diego Mayer
@Chrono79
Apr 26 2016 02:18
@OmMinky no, as you can see, the function is already returning product
You have to set product value inside the loops
OmMinky
@OmMinky
Apr 26 2016 02:20
@Chrono79 thanks, the mutiplyAll function , product variable is confusing. Not sure how to use 'product' variable
CamperBot
@camperbot
Apr 26 2016 02:20
omminky sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star: 503 | @chrono79 | http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Apr 26 2016 02:21
@OmMinky you have two ways of storing product:
product = product * arr[i][j];
or
product *= arr[i][j];
OmMinky
@OmMinky
Apr 26 2016 02:23
@Chrono79 thanks you, this helps
CamperBot
@camperbot
Apr 26 2016 02:23
omminky sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: omminky already gave chrono79 points
Diego Mayer
@Chrono79
Apr 26 2016 02:23
Enough coding for the day, see ya
dab_umana
@dabumana
Apr 26 2016 02:25
i dont understand the problem of nextInLine function, can anyone help me?
V Arun Kumar
@arunvkumr
Apr 26 2016 02:31
@dabumana Post your code, someone will help you out.:smile:
charazn
@charazn
Apr 26 2016 02:52
@moigithub @revisualize @llamatarianism Thank you
CamperBot
@camperbot
Apr 26 2016 02:52
charazn sends brownie points to @moigithub and @revisualize and @llamatarianism :sparkles: :thumbsup: :sparkles:
:star: 462 | @llamatarianism | http://www.freecodecamp.com/llamatarianism
:star: 1012 | @moigithub | http://www.freecodecamp.com/moigithub
:star: 975 | @revisualize | http://www.freecodecamp.com/revisualize
d wilder
@alhazen1
Apr 26 2016 03:01
This message was deleted
This message was deleted
This message was deleted
Kyle B.
@manbearkyle
Apr 26 2016 03:04

hey guys should I be using any "if/else" or "for" statements to complete the Stand in Line checkpoint?

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


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

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

Checkpoint Git page --> https://github.com/FreeCodeCamp/FreeCodeCamp/wiki/Checkpoint-Stand-In-Line

Victor
@abeledovictor
Apr 26 2016 03:10
Hi guys, I need some help with one of the javascript challenges,

Instruction: set reminder equial to the remainder of 11 divided by 3 using the remainder (%) operator
Code:

var remainder;

JustinMartinIsHere
@JustinMartinIsHere
Apr 26 2016 03:12
still havin trouble understanding JS escapes stuck on problem set"Escape Sequences in Strings" can anyone help me
Diego Mayer
@Chrono79
Apr 26 2016 03:17
@manbearkyle No, just arr.push(item) first and then return arr.shift()
Don't use testArr inside the function, use arr
@abeledovictor remainder = 11 % 3;
d wilder
@alhazen1
Apr 26 2016 03:18
@abeledovictor That % symbol is an operator just like + or -. The result of 11%3 is the remainder of dividing 11/3
@JustinMartinIsHere What is your escaped string and what is it not doing?
Victor
@abeledovictor
Apr 26 2016 03:21
@Chrono79 @alhazen1 thanks!!! english isnt my mother tounge and the description and examples were a bit confusing :P
CamperBot
@camperbot
Apr 26 2016 03:21
abeledovictor sends brownie points to @chrono79 and @alhazen1 :sparkles: :thumbsup: :sparkles:
:star: 504 | @chrono79 | http://www.freecodecamp.com/chrono79
:star: 353 | @alhazen1 | http://www.freecodecamp.com/alhazen1
Kyle B.
@manbearkyle
Apr 26 2016 03:22
@Chrono79 wow I can't believe it was that simple. Thanks Diego :clap:
CamperBot
@camperbot
Apr 26 2016 03:22
manbearkyle sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star: 505 | @chrono79 | http://www.freecodecamp.com/chrono79
d wilder
@alhazen1
Apr 26 2016 03:23
@abeledovictor You are welcome!
Luong Quoc Dinh
@luongquocdinh
Apr 26 2016 03:33
hello, I am new member :)
Frank XC
@tenkdayz
Apr 26 2016 03:33
@luongquocdinh welcome
D.Mills
@millsdee74
Apr 26 2016 03:38

Challenge:Assignment with a Returned Value , I can't complete processArg to processed instruction, this is what I have, can anyone help....// Setup
var processed = 2;

function process(num) {
return (num + 3) / 5;
}

processed = process(7);

// Only change code below this line

Kyle B.
@manbearkyle
Apr 26 2016 03:38
thanks @Rafase282 for your help with Checkpoint: Word Blanks
CamperBot
@camperbot
Apr 26 2016 03:38
manbearkyle sends brownie points to @rafase282 :sparkles: :thumbsup: :sparkles:
:star: 1183 | @rafase282 | http://www.freecodecamp.com/rafase282
d wilder
@alhazen1
Apr 26 2016 03:38
@luongquocdinh Hello new member!
Rafael J. Rodriguez
@Rafase282
Apr 26 2016 03:39
:+1:
buckshot307
@buckshot307
Apr 26 2016 03:47
@millsdee74 what error is it giving you?
Gary
@keengar
Apr 26 2016 03:49

Record Collection: everything I try in the below code keeps replacing the array in the object with a string.
else if (collection[id][prop] === "tracks") {
collection[id].tracks.push(value);
}

Object for reference:
var collection = {
2548: {
album: "Slippery When Wet",
artist: "Bon Jovi",
tracks: [
"Let It Rock",
"You Give Love a Bad Name"
]
},
2468: {
album: "1999",
artist: "Prince",
tracks: [
"1999",
"Little Red Corvette"
];

Master Builder
@McGowanC
Apr 26 2016 03:49
@keengar you hsould put that in a snippet
@keengar so it's readable
D.Mills
@millsdee74
Apr 26 2016 03:51

@buckshot307 can't figure out where that 7 fits in, this is what I have and error:processed=2 // Example
var changed = 0;

function change(num) {
return (num + 5) / 3;
}

changed = change(10);

// Setup
var processed = 2;

function processArg(num) {
return (num + 3) / 5;
}
processed = processArg =(2);

Gary
@keengar
Apr 26 2016 03:51
'''else if (collection[id][prop] === "tracks") {
collection[id].tracks.push(value);
}
Object for reference:
var collection = {
2548: {
album: "Slippery When Wet",
artist: "Bon Jovi",
tracks: [
"Let It Rock",
"You Give Love a Bad Name"
]
},
2468: {
album: "1999",
artist: "Prince",
tracks: [
"1999",
"Little Red Corvette"
];'''
CamperBot
@camperbot
Apr 26 2016 03:51
:bulb: to format code use backticks! ``` more info
Gary
@keengar
Apr 26 2016 03:52
yup, just failed. else if (collection[id][prop] === "tracks") { collection[id].tracks.push(value); } Object for reference: var collection = { 2548: { album: "Slippery When Wet", artist: "Bon Jovi", tracks: [ "Let It Rock", "You Give Love a Bad Name" ] }, 2468: { album: "1999", artist: "Prince", tracks: [ "1999", "Little Red Corvette" ];
Master Builder
@McGowanC
Apr 26 2016 03:52
ah gary super close! you just have to hit shitf+enter after those tick marks to go into markdown mode
```
else if (collection[id][prop] === "tracks") {
collection[id].tracks.push(value);
}
Object for reference:
var collection = {
2548: {
album: "Slippery When Wet",
artist: "Bon Jovi",
tracks: [
"Let It Rock",
"You Give Love a Bad Name"
]
},
2468: {
album: "1999",
artist: "Prince",
tracks: [
"1999",
"Little Red Corvette"
];
buckshot307
@buckshot307
Apr 26 2016 03:54
@millsdee74 the argument is what the function will run. So it would look like Function(argument); and the challenge just wants you to use processArg() on the number
@millsdee74 my mistake didn't read it fully. It wants you to set the variable processed to equal the function processArg() of 7
d wilder
@alhazen1
Apr 26 2016 03:58

@keengar

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

Try removing the . between [id] and tracks. I think that shouldn't be there

D.Mills
@millsdee74
Apr 26 2016 03:58
@buckshot307 did that and it did not go through
buckshot307
@buckshot307
Apr 26 2016 03:59
@millsdee74 can you paste your code?
D.Mills
@millsdee74
Apr 26 2016 04:00
@buckshot307 I got it. Thanks. I know, for sure, I did that many times before now.
CamperBot
@camperbot
Apr 26 2016 04:00
millsdee74 sends brownie points to @buckshot307 :sparkles: :thumbsup: :sparkles:
:star: 305 | @buckshot307 | http://www.freecodecamp.com/buckshot307
Gary
@keengar
Apr 26 2016 04:01
@wcrm I was able to get it to allow me to enter the code, but not to send the markdown. What's the trick to submitting?
Master Builder
@McGowanC
Apr 26 2016 04:01
@keengar apologies I should have said that, when you are ready to send, you hit control+enter
buckshot307
@buckshot307
Apr 26 2016 04:01
@millsdee74 good deal! sometimes the code bugs out unless you refresh the page or reset the code, but be careful because it erases everything you've typed if you reset.
Gary
@keengar
Apr 26 2016 04:01
@alhazen1 breaks it to remove that .
D.Mills
@millsdee74
Apr 26 2016 04:02
@buckshot307 I'll keep that in mind
Gary
@keengar
Apr 26 2016 04:02
// Only change code below this line
function updateRecords(id, prop, value) {
  if (value === "") {
    delete collection[id][prop];
  } else if (collection[id][prop] !== "" && collection[id][prop] !== "tracks") {
    collection[id][prop] = value;
  } else if (collection[id][prop] === "tracks") {
    collection[id][prop].push(value);
  }

  return collection;
}

// Alter values below to test your code
updateRecords(2468, "tracks", "Addicted to Love");
d wilder
@alhazen1
Apr 26 2016 04:03
@keengar UR right
Luong Quoc Dinh
@luongquocdinh
Apr 26 2016 04:03
var myStr = "\"I am a \"double quoted\" string inside \"double quotes\"";
1.You should use two double quotes (") and four escaped double quotes (\")??
2.Variable myStr should equal to ("I am a "double quoted" string inside "double quotes"")???
Gary
@keengar
Apr 26 2016 04:04
@wcrm #228 Got it thanks! Any idea what is needed to push to the end of an array in an object?
CamperBot
@camperbot
Apr 26 2016 04:04
keengar sends brownie points to @wcrm :sparkles: :thumbsup: :sparkles:
:star: 75 | @wcrm | http://www.freecodecamp.com/wcrm
vijanard
@vijanard
Apr 26 2016 04:07
Encode the following sequence, separated by spaces:
backslash tab tab carriage-return new-line and assign it to myStr?!
what are we supposed to do with this?!!
please help some1 :/
Gary
@keengar
Apr 26 2016 04:08
@vijanard backslash = \, tab = \t
vijanard
@vijanard
Apr 26 2016 04:08
var myStr="\ \t \t \n \r";
i tried this...it isnt executing! :/
Gary
@keengar
Apr 26 2016 04:09
need to separate it by spaces
vijanard
@vijanard
Apr 26 2016 04:10
@keengar each of them is separated by spaces...still the output isnt right
Gary
@keengar
Apr 26 2016 04:11
it's the first \ you need another so that it is escaped
vijanard
@vijanard
Apr 26 2016 04:12
got it :) thanks @keengar
CamperBot
@camperbot
Apr 26 2016 04:12
vijanard sends brownie points to @keengar :sparkles: :thumbsup: :sparkles:
:star: 229 | @keengar | http://www.freecodecamp.com/keengar
Gary
@keengar
Apr 26 2016 04:12
@vijanard
what you have matches the solution I got except for two \s
cool, glad to hear it @vijanard
d wilder
@alhazen1
Apr 26 2016 04:16
@keengar
if (value === "") {
    delete collection[id][prop];
  } else if (prop !== "" && prop !== "tracks") {
    collection[id][prop] = value;
  } else if (prop === "tracks") {
    collection[id][prop].push(value);
  }
Gary
@keengar
Apr 26 2016 04:20
@alhazen1
Thank you so much. I've used every type of syntax to add the value with length and four or five other ways that generated the string, but didn't even think of checking my conditions. Funny that I had so much extra code
CamperBot
@camperbot
Apr 26 2016 04:20
keengar sends brownie points to @alhazen1 :sparkles: :thumbsup: :sparkles:
:star: 355 | @alhazen1 | http://www.freecodecamp.com/alhazen1
Alex Myers
@qckpckt
Apr 26 2016 04:24
Hi all, I’m working on the caesar’s cipher challenge. are the suggestions about unicode character conversion methods a red herring?
I can build a function that subtracts 13 from the unicode value of the letters but that doesnt actually work because the cipher loops over the alphabet and not the full unicode value range. I cant think of a way to integrate that loop using unicode. anyone who did this recently care to share their input?
Martialis39
@Martialis39
Apr 26 2016 04:26
@qckpckt Hey
Alex Myers
@qckpckt
Apr 26 2016 04:26
hi @Martialis39
Martialis39
@Martialis39
Apr 26 2016 04:26
Ok, so is the problem looping over?
d wilder
@alhazen1
Apr 26 2016 04:26
@keengar You are welcome. At first glance everything looked right
Martialis39
@Martialis39
Apr 26 2016 04:26
For example, unicode of V, + 13,
does that break?
Alex Myers
@qckpckt
Apr 26 2016 04:27
it would assign v a non alphanumeric character, yes
it wouldnt loop back around the alphabet
Martialis39
@Martialis39
Apr 26 2016 04:27
ok! Do something like
If (longer than the range)
one sec
Alex Myers
@qckpckt
Apr 26 2016 04:28
@Martialis39 I think I know where you’re going with that. Lemme try and figure it out. Thank you!
CamperBot
@camperbot
Apr 26 2016 04:28
qckpckt sends brownie points to @martialis39 :sparkles: :thumbsup: :sparkles:
:star: 284 | @martialis39 | http://www.freecodecamp.com/martialis39
Martialis39
@Martialis39
Apr 26 2016 04:31
@qckpckt Sure :)
@qckpckt Just to give you one more hint. I did it a bit differently where I actually had an array that represented the alphabet. At that point I had a range of 25 and from there its easier to handle the loop over. Im sure you can get to a similar position with your approach :)
d wilder
@alhazen1
Apr 26 2016 04:38
@qckpckt another option is to split the alphabet in half. Shift +13 in first half and -13 for the second.
Alex Myers
@qckpckt
Apr 26 2016 04:39
@Martialis39 that’s what I was wondering - whether it was actually easier just to not use unicode values at all...
Martialis39
@Martialis39
Apr 26 2016 04:42
@qckpckt I hope you got it, I have to dash
Best of luck ;)
Alex Myers
@qckpckt
Apr 26 2016 04:42
No problem @Martialis39 I’ll figure it out :)
buckshot307
@buckshot307
Apr 26 2016 04:43
Anyone see why this isn't working?
function dropElements(arr, func) {
 var num = 0;

 for (var i = 0; i < arr.length; i++) {
    if (!func(arr[i])) {
      num = arr.shift();
    } 
  }
  return arr;
}


dropElements([1, 2, 3, 4], function(n) {return n >= 3; });
I added the var num and num = ... to see if that helped. It didn't.
function dropElements(arr, func) {

 for (var i = 0; i < arr.length; i++) {
    if (!func(arr[i])) {
      arr.shift(i);
    } 
  }
  return arr;
}


dropElements([1, 2, 3, 4], function(n) {return n >= 3; });
buckshot307
@buckshot307
Apr 26 2016 04:49
nvmd got it!
d wilder
@alhazen1
Apr 26 2016 04:49
@buckshot307 I'm not sure what this challenge is but it looks like you are removing any that aren't > 3. shift always removes the first element
@buckshot307 checkout array.filter method
Chris Cullen
@123xylem
Apr 26 2016 04:52
help Find the Longest Word in a String
CamperBot
@camperbot
Apr 26 2016 04:52

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

Explanation:

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

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

Ahmed Abdelaziz
@Achmed4
Apr 26 2016 05:02
I'm wondering why my code doesn't work specially when calling my function with this getIndexToIns([2, 5, 10], 15);
function getIndexToIns(arr, num) {
  // Find my place in this sorted array.

  var args = Array.prototype.slice.call(arguments);
  args.splice(0, 1);

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

  for(var i = arr.length-1; i >= 0; i--) {

    if(args[0] > arr[i]) {
      return arr.indexOf(arr[i+1]);
    } else if (args[0] === arr[i]) {
      return arr.indexOf(arr[i]);
    }

  }

}
Markus Kiili
@Masd925
Apr 26 2016 05:02
@buckshot307 You mutate the array you iterate over with for. It tends to screw up the indices. While loop works better on this challenge.
@Achmed4 It is easier if you first push num into the array and then sort. Then you can find the answer with indexOf.
Ahmed Abdelaziz
@Achmed4
Apr 26 2016 05:08
@Masd925 Thank you so much :)
CamperBot
@camperbot
Apr 26 2016 05:08
achmed4 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1411 | @masd925 | http://www.freecodecamp.com/masd925
Chris Cullen
@123xylem
Apr 26 2016 05:16

function findLongestWord(str) {
str=  str.split(" "); //makes string array split into seperate words
  var wordL=0;
  for(var i=0;i<str.length;i++){ //scans array counting characters in each word

    if ( str[i].length > wordL) {// if previous longest word stored is longer than current word then return it     

      wordL = str[i].length;

  } 
  }return wordL;
    }


findLongestWord("The quick brown fox jumped over the lazy dog");
Can some1 tell me why it keeps looking for a larger string?
And why it doesnt just give the firststring as 3 when its more than 0
Markus Kiili
@Masd925
Apr 26 2016 05:20
@123xylem It goes through all the words and figures out the longest length.
Frank XC
@tenkdayz
Apr 26 2016 05:20
@123xylem do you have to return a string or a number?
Spencer Kuzara
@kodaxx
Apr 26 2016 05:25
Not getting any response from openweathermap API...I've registered my key, and I keep getting invalid key error
Any suggestions?
Nevermind, working all of the sudden
Alex Myers
@qckpckt
Apr 26 2016 05:36
OK. can someone please explain to me why this works:
function rot13(str) { // LBH QVQ VG!
  function charSel(p1) {
    var huh = [];
   var blah = p1.charCodeAt(p1);
   if (blah <= 77) { 
     huh = blah+13;
   } else {
     huh = blah-13;
   } return String.fromCharCode(huh);
   }
  var charCode = str.replace(/[\w*]/g, charSel);
  return charCode;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC”);
How does it know to apply the changes to every character in the blah variable without a for loop? is it because replace iterates over every character in the string you supply?
why doesnt it even care that i made huh an array?
Markus Kiili
@Masd925
Apr 26 2016 05:38
@qckpckt You overwrite the array in huh with a number.
@qckpckt .replace invokes the function charSel on all matches it finds on the string.
buckshot307
@buckshot307
Apr 26 2016 05:41
@kodaxx that thing is super buggy. I couldn't get mine to work, and the example ones I looked at wouldn't work either.
Chris Cullen
@123xylem
Apr 26 2016 05:43
@Masd925 @tenkdayz I have to return a number.. It passes but I just wonder why it keeps going through all the strings when the first string is more than 0
Markus Kiili
@Masd925
Apr 26 2016 05:44
@123xylem The if clause only assigns a new value to wordL. The for loop is not stopped.
Frank XC
@tenkdayz
Apr 26 2016 05:44
@123xylem if you want it to stop use break;
@123xylem but then it will stop at the first word because of obvious reasons
Chris Cullen
@123xylem
Apr 26 2016 05:48
@Masd925 ah gotya.. the If keeps working until its <str.length and doesnt return as return is outside the funciton...
Elbert Cortez
@trip16661
Apr 26 2016 05:55
function sym(args) {
var argsArray = [].slice.call(arguments);
function symOfTwo(firstArr,secondArr){
  firstArr.filter(function(elem,index){
    return secondArr.indexOf(elem) === -1;
  });
  secondArr.filter(function(elem,index){
    return firstArr.indexOf(elem) === -1;
  });
  return firstArr.concat(secondArr);
}



  return symOfTwo(argsArray[0],argsArray[1]);
}

sym([1, 2, 3], [5, 2, 1, 4]);
why is this filter not working?
Coy Sanders
@coymeetsworld
Apr 26 2016 05:56
don't believe Array.filter modifies the array @trip16661, think you need to assign the results of that function to an array
Zach
@Moose1551
Apr 26 2016 05:57
Can someone briefly explain to me why this returns "c"?
function repeatStringNumTimes(str, num) {
  num = 0;
  var newString = "";
  for (var i = 0; i < str.length; i++) {
    newString = str[i];
  }
    return newString;

}
repeatStringNumTimes("abc", 3);
Coy Sanders
@coymeetsworld
Apr 26 2016 05:58
you keep reassigning newString to each character of str, which in this case is "abc" @Moose1551
it ends with the last character of the string which is c and that is what is returned
you have 2 problems w/ your code
Zach
@Moose1551
Apr 26 2016 06:00
@coymeetsworld , Thanks!
CamperBot
@camperbot
Apr 26 2016 06:00
moose1551 sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star: 625 | @coymeetsworld | http://www.freecodecamp.com/coymeetsworld
Coy Sanders
@coymeetsworld
Apr 26 2016 06:00
np @Moose1551
Elbert Cortez
@trip16661
Apr 26 2016 06:01
@coymeetsworld thanks
CamperBot
@camperbot
Apr 26 2016 06:01
trip16661 sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star: 626 | @coymeetsworld | http://www.freecodecamp.com/coymeetsworld
Josselin Milon
@Gjloss
Apr 26 2016 06:02

Hi guys! in the falsy bouncer challenge, I was trying something fairly dirty to see if it would work or not... Well it didn't but I don't get why
'''
function bouncer(arr) {
// Don't show a false ID to this bouncer.
function callback(x) {
return (x !== false) && (x !== null) && (x !==0) && (x !=="") && (x !== undefined) && (x !== NaN);
}

return arr.filter(callback);
}

bouncer([1, null, NaN, 2, undefined]);
'''

Coy Sanders
@coymeetsworld
Apr 26 2016 06:03
np @trip16661
Josselin Milon
@Gjloss
Apr 26 2016 06:03
oh my... first of, how do I make it look like a code block :-/
Coy Sanders
@coymeetsworld
Apr 26 2016 06:04
help format
CamperBot
@camperbot
Apr 26 2016 06:04

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

d wilder
@alhazen1
Apr 26 2016 06:06
@Gjloss I can't remember details but !== checks for more than just equality. Try !=
Markus Kiili
@Masd925
Apr 26 2016 06:06
@Gjloss NaN is problematic, because NaN===NaN is false. And x!==NaN is always true for any value x.
Zach
@Moose1551
Apr 26 2016 06:06
@coymeetsworld, now this returns "abc." Do you have any suggestions on how to incorporate the "num" argument?
function repeatStringNumTimes(str, num) {
  str = str.split(" ");
  num = 0;
  var newString = "";
  for (var i = 0; i < str.length; i++) {
    newString = str[i];
  }
    return newString;

}
repeatStringNumTimes("abc", 3);
Coy Sanders
@coymeetsworld
Apr 26 2016 06:07
This message was deleted
theres a much simpler way to do it @Gjloss btw
you need to use num in your for loop @Moose1551 , because num is a condition for how many times you want to iterate
you also need to look at how you're modifying newString, you need to be using string concatenation, not keep reassigning it to a value
V Arun Kumar
@arunvkumr
Apr 26 2016 06:09
@Moose1551 try using += str[i] and num as condition in for loop.
d wilder
@alhazen1
Apr 26 2016 06:09
@Gjloss He's right. That is a very complex test for not falsy
Josselin Milon
@Gjloss
Apr 26 2016 06:10
indeed, using the boolean makes it so much easier! But in my example, I don't get why 'x != null' wouldn't filter null?
d wilder
@alhazen1
Apr 26 2016 06:11
@Moose1551 How about
function repeatStringNumTimes(str, num) {
  var newString = "";
  for (var i = 0; i < num; i++) { 
    newString += str
  }
    return newString;

}
repeatStringNumTimes("abc", 3);
Coy Sanders
@coymeetsworld
Apr 26 2016 06:11
why are you giving him the code @alhazen1 ? also its missing a semicolon...
Markus Kiili
@Masd925
Apr 26 2016 06:12
@Gjloss You should always use strict equality === and !==. Using abstract equality == and != leads to problems because the abstract equality algorithm is so complicated.
d wilder
@alhazen1
Apr 26 2016 06:13
@coymeetsworld Sorry! Carried away - need sleep - bedtime now
V1ad1m1r
@V1ad1m1r
Apr 26 2016 06:13
js
$(document).ready(function() {

  if ("geolocation" in navigator) {
    navigator.geolocation.getCurrentPosition(function(position) {

      $(".tester").text("latitude: " + position.coords.latitude + "longitude: " + position.coords.longitude);

      console.log(position.coords.longitude);
Ok everyone :) been at this one for a few days, and Im just not seeing it. Why wont my geolocation call pull the geolocation?
Coy Sanders
@coymeetsworld
Apr 26 2016 06:13
but having said that that is what you can do for the solution @alhazen1 @Moose1551
did you enable geolocation in your browser?
@V1ad1m1r
V1ad1m1r
@V1ad1m1r
Apr 26 2016 06:16
i have. still didnt run,.
ill give it another try though.
Coy Sanders
@coymeetsworld
Apr 26 2016 06:16
console doesn't show longitude?
do you have an ending curly brace to your code too?
Zach
@Moose1551
Apr 26 2016 06:17
@coymeetsworld, With the solution provided, how does the loop know that "num" is 3? Is "num" used as an argument a global variable? That is to say, will java always recognize "num" in a function as a numeral?
Coy Sanders
@coymeetsworld
Apr 26 2016 06:17
num isn't a global variable @Moose1551
if you declare one in your parameters for the function that is what will be used even if theres a global variable w/ same name
V1ad1m1r
@V1ad1m1r
Apr 26 2016 06:18
@coymeetsworld I do. the code continues as the whole app should run from the load screen.
Zach
@Moose1551
Apr 26 2016 06:18
Or was it because "num" was established as a number is the test "repeatStringNumTimes("abc" , 3)?"
@coymeetsworld , Did I just say the second part of your message, but in a dumb way?
Coy Sanders
@coymeetsworld
Apr 26 2016 06:19
num is a local variable defined in repeatStringNumTimes
whatever your 2nd argument is in your function call is what num is
V1ad1m1r
@V1ad1m1r
Apr 26 2016 06:19
i am getting this notice in my console.... getCurrentPosition() and watchPosition() are deprecated on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS.
but I am unaware of a way to turn a codepen into a secure origin.
Coy Sanders
@coymeetsworld
Apr 26 2016 06:20
so if you call repeatStringNumTimes("abc", 4), num will be 4 for that call, if you call repeatStringNumTimes("abc", 10), num will be 10
Zach
@Moose1551
Apr 26 2016 06:20
@coymeetsworld , awesome, dude. 'Preciate it!
Coy Sanders
@coymeetsworld
Apr 26 2016 06:20
can you post the url to your pen @V1ad1m1r
yeah np @Moose1551
V1ad1m1r
@V1ad1m1r
Apr 26 2016 06:21
@coymeetsworld sure :) sent you a pm
Drew Stonebraker
@drstonebraker
Apr 26 2016 06:21

I can't figure out why my regex ins't working. I'm trying to filter out white space characters

```

Zach
@Moose1551
Apr 26 2016 06:21
I accidentally completed this challenge about a hundred times in the bonfire challenge "Find the Longest Word in a String", haha. Too bad I didn't do it on my own in the challenge.
Drew Stonebraker
@drstonebraker
Apr 26 2016 06:22
  str = str.split('').filter(function(val) {
  return val == /\S/;
});
Zach
@Moose1551
Apr 26 2016 06:22
I bet I would have accidentally completed "Return the Longest Word in a String" in this one eventually if I kept at it.
Hector Garcia
@augmt
Apr 26 2016 06:27
@Stoney229 try val.match(/\S/) instead of val == /\S/
Drew Stonebraker
@drstonebraker
Apr 26 2016 06:27
ah, ty!
Hector Garcia
@augmt
Apr 26 2016 06:28
np :)
Zach
@Moose1551
Apr 26 2016 06:31
One more question, how did the loop know to multiply "str" and "num" together without "[i]" being used in the statement "newString += str"?
Coy Sanders
@coymeetsworld
Apr 26 2016 06:32
you don't need i, you want the entire string
Zach
@Moose1551
Apr 26 2016 06:35
I guess I'm kind of seeing it. I guess I'm having trouble understanding how the parts of a "for Loop" interact with statements and variables.
Coy Sanders
@coymeetsworld
Apr 26 2016 06:45
there's 3 parts to a for loop separated by semi-colons: initializing the variable, checking condition on the variable, and modifying the variable
the idea is you modify the variable enough times that the condition will eventually be false and the loop will be terminated, else you run into an infinite loop unable to exit out

so something like

for (var i = 0; i < 3; i++) {
  console.log("i is: " + i);
}

will print out

i is 0
i is 1
i is 2
i is initialized to 0 (first part of the loop), 2nd part is the condition where the loop will run if its true, and 3rd part is what happens after a run of the loop is done
i is 3 doesn't show because when i == 3, i is no longer less than 3 so the condition is false, and thus the for loop terminates
Jérôme
@ajie62
Apr 26 2016 06:50
Hello, could someone explain to me "Stand in Line" from the JavaScript lessons? I don't understand very well.
Hector Garcia
@augmt
Apr 26 2016 06:54
@ajie62 given an array arr and a number item, you want to push item onto arr and both remove and return the first element in arr
Jérôme
@ajie62
Apr 26 2016 06:59
Hm... Indeed, I learned properly how to use .push(); and .pop(); but I'm not sure how I should do it here. (As I'm French, sometimes it's difficult for me to understand everything the first time I read it.)
mine ran successfully (the non 'var' created variable still passed 5)
Hector Garcia
@augmt
Apr 26 2016 07:00
@ajie62 instead of .pop(), take a look at .shift()
Robin D
@goosenoose
Apr 26 2016 07:01

'''// Declare your variable here
var myGlobal = 10;

function fun1() {
// Assign 5 to oopsGlobal Here
oopsGlobal = 5;

}

// Only change code above this line
function fun2() {
var output = "";
if (typeof myGlobal != "undefined") {
output += "myGlobal: " + myGlobal;
}
if (typeof oopsGlobal != "undefined") {
output += " oopsGlobal: " + oopsGlobal;
}
console.log(output);
}
'''

CamperBot
@camperbot
Apr 26 2016 07:01
:bulb: to format code use backticks! ``` more info
Robin D
@goosenoose
Apr 26 2016 07:01

```// Declare your variable here
var myGlobal = 10;

function fun1() {
// Assign 5 to oopsGlobal Here
oopsGlobal = 5;

}

// Only change code above this line
function fun2() {
var output = "";
if (typeof myGlobal != "undefined") {
output += "myGlobal: " + myGlobal;
}
if (typeof oopsGlobal != "undefined") {
output += " oopsGlobal: " + oopsGlobal;
}
console.log(output);
}
```
was this supposed to fail?
mine ran successfully (the non 'var' created variable still passed 5)

Hector Garcia
@augmt
Apr 26 2016 07:02
@goosenoose nope, you did what the tests asked you to do
Robin D
@goosenoose
Apr 26 2016 07:02
-_-;... doesn't feel right
ok
thank you
Hector Garcia
@augmt
Apr 26 2016 07:02
not declaring a variable using var makes it a global variable
Robin D
@goosenoose
Apr 26 2016 07:03
i see....
whereas var declaration observes where the variable is
e.g. if it is in a function, it will only work whilst in that function?
Hector Garcia
@augmt
Apr 26 2016 07:04
yep
Robin D
@goosenoose
Apr 26 2016 07:04
sweet
i love you :)
thanks @augmt
CamperBot
@camperbot
Apr 26 2016 07:04
goosenoose sends brownie points to @augmt :sparkles: :thumbsup: :sparkles:
:star: 391 | @augmt | http://www.freecodecamp.com/augmt
Hector Garcia
@augmt
Apr 26 2016 07:04
haha
if you have a global variable
in this case oopsGlobal
you can also access it using window.oopsGlobal
Robin D
@goosenoose
Apr 26 2016 07:05
saw that while trying to finagle displaying js in html
will learn more about it
thank you
Hector Garcia
@augmt
Apr 26 2016 07:06
no problem :)
Darth Skywalker
@adityaparab
Apr 26 2016 07:06
@augmt : Just to add to that. If on node.js the global scope will be on process object. If on browser, global scope will be on window object.
RainVector
@RainVector
Apr 26 2016 07:07
how can i get the length of an array?
Darth Skywalker
@adityaparab
Apr 26 2016 07:07
arrayName.length
Robin D
@goosenoose
Apr 26 2016 07:07
yourArray.length()
*length
Darth Skywalker
@adityaparab
Apr 26 2016 07:07
var x = [1,2,3,4,5,6];
console.log(x.length); // 6
RainVector
@RainVector
Apr 26 2016 07:08
Thx
Drew Stonebraker
@drstonebraker
Apr 26 2016 07:13
I can't figure out why calling .reverse() on my reverseStr array also reverses my str array
function palindrome(str) {
  // Good luck!
  str = str.toLowerCase().match(/[a-z]|[0-9]/gi);

  var reverseStr = str.reverse();
  //reverseStr.reverse();

  console.log(str);

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



palindrome("eye");
str returns a reversed array depending on whether I have reverseStr.reverse(); commented out or not
Frank XC
@tenkdayz
Apr 26 2016 07:15
@Stoney229 youre reversing str and assigning it to reverseStr
24manish
@24manish
Apr 26 2016 07:17
how to Generate Random Whole Numbers with JavaScript
Drew Stonebraker
@drstonebraker
Apr 26 2016 07:18
@tenkdayz yes, that is my intention. I want reverseStr to be the reverse of str. but it seems applying .reverse() to str before assigning the value to reverseStr reverses str too. so then I want to call .reverse() on one of them again to get them opposite from each other, but when I call it on one, it always reverses the other at the same time, and I don't understand why
@24manish I believe you multiply the result of Math.random by some integer and round down with Math.floor
24manish
@24manish
Apr 26 2016 07:21
yaa i got it. thanks buddy.
Darth Skywalker
@adityaparab
Apr 26 2016 07:21
@Stoney229 Use this function to reverse a string
function reverse(s) {
  return s.split('').reverse().join('');
}
Drew Stonebraker
@drstonebraker
Apr 26 2016 07:22
@adityaparab thank you. do you know why calling .reverse() on one array was reversing both of my arrays?
CamperBot
@camperbot
Apr 26 2016 07:22
stoney229 sends brownie points to @adityaparab :sparkles: :thumbsup: :sparkles:
:star: 37 | @adityaparab | http://www.freecodecamp.com/adityaparab
Markus Kiili
@Masd925
Apr 26 2016 07:24
@Stoney229 Arrays are objects in JS. If you assign an array from one variable to another, they both refer to the same array.
Drew Stonebraker
@drstonebraker
Apr 26 2016 07:25
@Masd925 wow i did not know that. thank you!
CamperBot
@camperbot
Apr 26 2016 07:25
stoney229 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1412 | @masd925 | http://www.freecodecamp.com/masd925
Darth Skywalker
@adityaparab
Apr 26 2016 07:25
str.reverse() modifies str (notice that it doesn't take any parameters) So first you're reversing the str itself and then assigning that reversed str to reverseStr variable. :)
.reverse() API doesn't return you the reversed string. The Object (str, in this case) is passed to reverse function implicitly.
why this wont start secondTime counter after 1st is finished
pay attention to function timing and clock , tnx
Darth Skywalker
@adityaparab
Apr 26 2016 07:29
@Stoney229 Another thing is - the .reverse() API belongs to Array.prototype.reverse. Strings are NOT Arrays. string are Strings. :) So if you want the .reverse() API to work correctly, you must first cast that string into an Array using the String.prototype.split() API. Split will return an Array then you call .reverse() on that array. Then cast that Array into String by the .join() API.
Drew Stonebraker
@drstonebraker
Apr 26 2016 07:30
@adityaparab my understanding was that calling .match() on my string had already made it into an array. is that not correct?
Santosh Venkatraman
@thesantosh
Apr 26 2016 07:30
Guys. How do I solve "Profile Lookup"? I am stuck with "No such contact" and "No such property" cases.
This is the function I have constructed -
function lookUpProfile(firstName, prop){
// Only change code below this line
var returnValue = "";
var noFirstName = false;
var noProp = false;
for (var i = 0;i < contacts.length;i++) {
if (firstName === contacts[i].firstName && prop in contacts[i]) {
return contacts[i][prop];
}
else if(firstName !== contacts[i].firstName) {
noFirstName = noFirstName && true;
console.log(noFirstName);
}
else if(!(prop in contacts[i])) {
noProp = noProp && true;
console.log(noProp);
}
}
// Only change code above this line
if (noFirstName === true) {
return "No such contact";
}
if (noProp === true) {
return "No such property";
}
}
Markus Kiili
@Masd925
Apr 26 2016 07:32
@Stoney229 .match() is a string method that returns an array.
@thesantosh Format your code please.
help format
CamperBot
@camperbot
Apr 26 2016 07:32

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

Markus Kiili
@Masd925
Apr 26 2016 07:34
@thesantosh Easiest way is to put two nested if clauses inside contact loop. First for firstname check and second for property existence.
Darth Skywalker
@adityaparab
Apr 26 2016 07:34
@Stoney229 : You are partially correct. :) Even though it returns an Array that is not the same array that your code expects. .match returns array of MATCHED substrings. What you want is the entire string in reverse order. :) It may be valid in this particular case, however, you gotta know it intimately to have some fun ;)
CamperBot
@camperbot
Apr 26 2016 07:34
no wiki entry for: with remainder httpswwwfreecodecampcomchallengesfinding-a-remainder-in-javascriptsolution2f2f20only20change20code20below20this20line0a0a0a11202f2032025203d2023b0a
Hector Garcia
@augmt
Apr 26 2016 07:34
@EldarT90 look at your clock function. it seems like you forgot to wrap the remainder of the code in an else block
Pabba Shiva Ram Kaushil
@PabbaShivaRamKaushil
Apr 26 2016 07:34
"Quoting Strings with Single Quotes" in basic javascript .
can anyone me with this code
Drew Stonebraker
@drstonebraker
Apr 26 2016 07:34
@adityaparab thank you
CamperBot
@camperbot
Apr 26 2016 07:34
stoney229 sends brownie points to @adityaparab :sparkles: :thumbsup: :sparkles:
:warning: stoney229 already gave adityaparab points
Darth Skywalker
@adityaparab
Apr 26 2016 07:35
@Alhaji24 : It should be 11 % 3 = 2;
Eldar Tinjić
@EldarT90
Apr 26 2016 07:36
@augmt good eye ^^ tnx mate
CamperBot
@camperbot
Apr 26 2016 07:36
eldart90 sends brownie points to @augmt :sparkles: :thumbsup: :sparkles:
:star: 393 | @augmt | http://www.freecodecamp.com/augmt
Pabba Shiva Ram Kaushil
@PabbaShivaRamKaushil
Apr 26 2016 07:36
@PabbaShivaRamKaushil
"Quoting Strings with Single Quotes" in basic javascript .
can anyone help me with this code please.
Darth Skywalker
@adityaparab
Apr 26 2016 07:37
@PabbaShivaRamKaushil : Just do 'Quoting Strings with Single Quotes' instead of "Quoting Strings with Single Quotes"
Alhaji Turay
@Alhaji24
Apr 26 2016 07:37
@adityaparab not working says bad left assignment
Darth Skywalker
@adityaparab
Apr 26 2016 07:39
@Alhaji24 : yes.. that is a syntac error. It was just an explanation. I'm not able to access that particular case so I don't know what is desired output.
Markus Kiili
@Masd925
Apr 26 2016 07:39
@Stoney229 You can make it work by putting this after the match line: return str.join("")===str.reverse().join(""); You can compare string content with ===, but not array content, because they are objects.
Darth Skywalker
@adityaparab
Apr 26 2016 07:39
but if you want remainder of 11/3 then you gotta do something like var remainder = 11%3;
Pabba Shiva Ram Kaushil
@PabbaShivaRamKaushil
Apr 26 2016 07:39
@adityaparab thanku
Alhaji Turay
@Alhaji24
Apr 26 2016 07:41
@adityaparab thanks
CamperBot
@camperbot
Apr 26 2016 07:41
alhaji24 sends brownie points to @adityaparab :sparkles: :thumbsup: :sparkles:
:star: 38 | @adityaparab | http://www.freecodecamp.com/adityaparab
TanYiXun
@TanYiXun
Apr 26 2016 07:48
Guys can anyone help me?
function palindrome(str) {
  if( str == str.replace(/\W+/g, "").toLowerCase().split('').reverse().join('')){return true;}
  return false;
}
palindrome("eye");
Markus Kiili
@Masd925
Apr 26 2016 07:49
@TanYiXun You are not removing underscore.
Pabba Shiva Ram Kaushil
@PabbaShivaRamKaushil
Apr 26 2016 07:50
"Escape Sequences in Strings" please help me this code in basic javascript.
TanYiXun
@TanYiXun
Apr 26 2016 07:50
@Masd925 ?
@Masd925 i want to remove all non-alphanumeric characters (punctuation, spaces and symbols)
Markus Kiili
@Masd925
Apr 26 2016 07:51
@TanYiXun \w includes underscore, therefore \W doesn't target underscore.
@TanYiXun In your condition, the str in the left side is not lowercased, which is a problem.
Pabba Shiva Ram Kaushil
@PabbaShivaRamKaushil
Apr 26 2016 07:53
"Escape Sequences in Strings" anyone please help me this code in basic javascript.
Eldar Tinjić
@EldarT90
Apr 26 2016 07:54
https://codepen.io/EldarT/pen/zqJGQv why my second counter (id pause) is ignored
it should influence the DOM value which gets put inside the counter
after 1st part of counter is done
TanYiXun
@TanYiXun
Apr 26 2016 07:55
@Masd925 ive tried this
i changed its but still not fully functioning..
function palindrome(str) {

  if( str.replace(/\W+/g, "") == str.replace(/\W+/g, "").toLowerCase().split('').reverse().join('')){return true;}
  return false;    
}

palindrome("eye");
Luong Quoc Dinh
@luongquocdinh
Apr 26 2016 07:56
Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.
Rohit Kumar Jena
@rohitrango
Apr 26 2016 07:56

In the following code -

function checkCashRegister(price, cash, cid) {
  var change, ret = cash-price;
  change = [["PENNY", 0.01], ["NICKEL", 0.05], ["DIME", 0.10], ["QUARTER", 0.25], ["ONE", 1.00], ["FIVE", 5.00], ["TEN", 10.00], ["TWENTY", 20.00], ["ONE HUNDRED", 100.00]];

  for(var i=cid.length-1;i>=0;i--) {

    if(ret===0)
      break;

    if(Math.floor(ret/change[i][1]) < cid[i][1]/change[i][1]) {

      change[i][1] = (Math.floor(ret/change[i][1]))*change[i][1];
      ret = ret-change[i][1];
      cid[i][1] -= change[i][1];

    }
    else {

      change[i][1] = cid[i][1] - Math.floor(ret/change[i][1])*change[i][1];
      ret -= change[i][1];    
      cid[i][1] -= change[i][1];
    }

  }

  var res=[],resChange=[];

  if(ret>0)
    return "Insufficient funds";

  else if(ret===0) {

     for(var x=0;x<change.length;x++) {
       if(change[x][1]!==0)
         resChange.push(change[x]);
     }
    for(var y=0;y<change.length;y++) {
       if(cid[y][1]!==0)
         res.push(cid[y]);
     }

    if(res==[])
      return "Closed";

    return resChange;

  } 
  // Here is your change, ma'am.

}
checkCashRegister(19.50, 20.00, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.10], ["QUARTER", 4.25], ["ONE", 90.00], ["FIVE", 55.00], ["TEN", 20.00], ["TWENTY", 60.00], ["ONE HUNDRED", 100.00]]);

It should return [["QUARTER", 0.50]] but it returns [["PENNY",0.01],["NICKEL",0.05],["DIME",0.1],["QUARTER",0.5]]
Can anyone explain where am I going wrong ?

Markus Kiili
@Masd925
Apr 26 2016 07:57
@TanYiXun First replace and lowercase the string. Then do the palindromicality check. Stuffing on one line produces extra work.
Pabba Shiva Ram Kaushil
@PabbaShivaRamKaushil
Apr 26 2016 07:57
"Escape Sequences in Strings" please help me this code in basic javascript.
TanYiXun
@TanYiXun
Apr 26 2016 07:58

@Masd925 this?

function palindrome(str) {

  if( str.replace(/\W+/g, "") == str.toLowerCase().replace(/\W+/g, "").split('').reverse().join('')){return true;}
  return false;    
}

palindrome("eye");

still left these cases
palindrome("A man, a plan, a canal. Panama") should return true.
palindrome("My age is 0, 0 si ega ym.") should return true.
palindrome("0_0 (: /-\ :) 0-0") should return true.

Markus Kiili
@Masd925
Apr 26 2016 07:59
@TanYiXun Lowercase the left side too.
TanYiXun
@TanYiXun
Apr 26 2016 07:59
@Masd925 oh..
@Masd925 THanks!!!!
CamperBot
@camperbot
Apr 26 2016 08:00
tanyixun sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1413 | @masd925 | http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Apr 26 2016 08:00
@TanYiXun It gets much better if you first replace and lowercase the string. Then do the palindromicality check on another line.
Pabba Shiva Ram Kaushil
@PabbaShivaRamKaushil
Apr 26 2016 08:02
"Escape Sequences in Strings" please help me this code in basic javascript.?????
TanYiXun
@TanYiXun
Apr 26 2016 08:02
@Masd925 Sure will try again sometime :)
Hector Garcia
@augmt
Apr 26 2016 08:04
@PabbaShivaRamKaushil what have you tried so far?
Kevin
@KevinBruland
Apr 26 2016 08:05
    var save1 = [];
    var save2 = [];
    var save3 = [];

    $("#save1").on("click", function() {
        save1 = [];
        for (x=0; x<121; x++){
            save1.push($("#grid-box" + x).css("background-color"))
        }

    });
I need that same function for all the var save's
I know I can use "this", but I am struggling to figure out how to target the array using the variable input for the .on click
Hector Garcia
@augmt
Apr 26 2016 08:07
@PabbaShivaRamKaushil you've escaped the tab, carriage-return, and new-line but you're missing the backslash and the first tab
and you also have too many quotes around your string
Pabba Shiva Ram Kaushil
@PabbaShivaRamKaushil
Apr 26 2016 08:10
@augmt can you please send the code. it ain't working.
Hector Garcia
@augmt
Apr 26 2016 08:12
@PabbaShivaRamKaushil i can't send you the answer but i can fix your code
var myStr="\ \t \r \n"; // Change this line
from here you need to escape the backslash and add an extra tab before or after the first tab
Jérôme
@ajie62
Apr 26 2016 08:14
I've been struggling with "Stand in Line" for two hours now... Looking for a solution, but couldn't find one. I must be dumb! Could someone help me?
I tried lots of things, but I don't get the idea...
Codemzy
@codemzy
Apr 26 2016 08:15
@ajie62 what you got so far?
Jérôme
@ajie62
Apr 26 2016 08:15
I know if have to use .shift(), maybe sth else but don't know where to put it
Pabba Shiva Ram Kaushil
@PabbaShivaRamKaushil
Apr 26 2016 08:15
@augmt it ain't workin'.please send entire code once.
Jérôme
@ajie62
Apr 26 2016 08:15
I've got nothing. I reset everything... It's starting to get on my nerves! xD

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

return item; // Change this line
}

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

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

Codemzy
@codemzy
Apr 26 2016 08:16
@ajie62 yeah .shift() is needed to remove the first item from the end, so you will need that... but you need something first to add item to the end of the array... take a look at .push()
Jérôme
@ajie62
Apr 26 2016 08:16
This message was deleted
Hector Garcia
@augmt
Apr 26 2016 08:16
@PabbaShivaRamKaushil i can't do that, sorry. you're almost at the solution
though you can take a look at some hints if you need more help
hint Escape Sequences in Strings
CamperBot
@camperbot
Apr 26 2016 08:17
Set a bonfire to talk about with bonfire name
Hector Garcia
@augmt
Apr 26 2016 08:17
bonfire Escape Sequences in Strings
CamperBot
@camperbot
Apr 26 2016 08:17
Sorry, can't find a bonfire called escape sequences in strings. [ Check the map? ]
Hector Garcia
@augmt
Apr 26 2016 08:18
hmm
Jérôme
@ajie62
Apr 26 2016 08:18
@codemzy I know what push and shift do, what I don't know is where I have to put them. I have the function nextInLine(arr, item), then I put an open bracket, and then it's where I don't know what to type...
Codemzy
@codemzy
Apr 26 2016 08:20
@ajie62 ok so break it down one step at a time... don't let it overwhelm you (easier said than done I know). First part of the challenge is to push item to the array. So start with that. On the first line in your function you should push the item to the array, using .push() ... give that a go first
Pabba Shiva Ram Kaushil
@PabbaShivaRamKaushil
Apr 26 2016 08:22
"Escape Sequences in Strings" please help me this code in basic javascript.
why my second animation (reverting) is not respecting the rule - it is corelated with var fixing
but it finished in 50% time of var fixing
Codemzy
@codemzy
Apr 26 2016 08:25
@ajie62 this should help... say I had an array called animals... and I wanted to add the variable newAnimal to the end of the array... I would do this...
var animals = ['cat', 'rabbit','frog'];
var newAnimal = 'dog';
animals.push(newAnimal);
// now animals = ['cat', 'rabbit','frog','dog'];
Pabba Shiva Ram Kaushil
@PabbaShivaRamKaushil
Apr 26 2016 08:26
"Escape Sequences in Strings" please help me this code in basic javascript.?????? anyone. I'm unable to solve this .
Jérôme
@ajie62
Apr 26 2016 08:26
@codemzy Ok, so in my code, should I add something to 'var testArr'?
@codemzy that's the only Array I see in the code, that's why I'm wondering
Zuo Bruno
@Brun0L3z
Apr 26 2016 08:27

this code seems to be right but fails all the time:
function convertToF(celsius) {
// Only change code below this line

var fahrenheit = celcius * 9/5 + 32;

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

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

Rudolf Carl Pablico
@rudolfpablico
Apr 26 2016 08:27
@Brun0L3z typo error
Zuo Bruno
@Brun0L3z
Apr 26 2016 08:28
ahhh
Rudolf Carl Pablico
@rudolfpablico
Apr 26 2016 08:28
@Brun0L3z typo error on var fahrenheit = celcius * 9/5 + 32; celcius should be celsius
Zuo Bruno
@Brun0L3z
Apr 26 2016 08:28
Thanks @rudolfpablico
CamperBot
@camperbot
Apr 26 2016 08:28
brun0l3z sends brownie points to @rudolfpablico :sparkles: :thumbsup: :sparkles:
:star: 249 | @rudolfpablico | http://www.freecodecamp.com/rudolfpablico
Zuo Bruno
@Brun0L3z
Apr 26 2016 08:28
I see it now
Rudolf Carl Pablico
@rudolfpablico
Apr 26 2016 08:28
Welcome
Codemzy
@codemzy
Apr 26 2016 08:29
@ajie62 the array is passed in to your function here function nextInLine(arr, item) so the array is stored in the arr variable within your function, and the item to add is stored in item
Rohit Kumar Jena
@rohitrango
Apr 26 2016 08:29
can anyone tell me the general form of US numbers
PS. Im not from US
telephoneCheck("1 (555) 555-5555") returns true but telephoneCheck("2(757)622-7382") returns false
Jérôme
@ajie62
Apr 26 2016 08:31
@codemzy How can I put code in a black box? (so it would show it properly instead of just pasting it here)
Codemzy
@codemzy
Apr 26 2016 08:31
wiki format
CamperBot
@camperbot
Apr 26 2016 08:31

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

Codemzy
@codemzy
Apr 26 2016 08:31
@ajie62 :point_up_2:
Jérôme
@ajie62
Apr 26 2016 08:32

`function nextInLine(arr, item) {
var newNumber = 6;
arr.push(newNumber);
var removedNumber = arr.shift(7);

return removedNumber; // Change this line
}
`

function nextInLine(arr, item) {
var newNumber = 6;
arr.push(newNumber);
var removedNumber = arr.shift(7);

return removedNumber; // Change this line
}
@codemzy thanks. so this is what I got so far
CamperBot
@camperbot
Apr 26 2016 08:33
ajie62 sends brownie points to @codemzy :sparkles: :thumbsup: :sparkles:
:star: 903 | @codemzy | http://www.freecodecamp.com/codemzy
Jérôme
@ajie62
Apr 26 2016 08:34
@codemzy there's an error with: nextInLine([],1) should return 1 & after nextInLine(testArr, 10), testArr[4] should be 10
Codemzy
@codemzy
Apr 26 2016 08:34
@ajie62 Looking good and you got the idea. couple of things... the number to add will be passed in to the function as item so you dont need to set up your own variable or number.. you just need to push the item so you can get rid of this line.. var newNumber = 6; and just go ahead and push item to the array
@ajie62 then... with .shift() it will automatically remove the first entry in the array, so you don't need to pass any argument, so you can get rid of the 7 from the brackets
Jérôme
@ajie62
Apr 26 2016 08:37
function nextInLine(arr, item) {
  arr.push(item);
  var removedNumber = arr.shift();

  return removedNumber;  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
Ok, this worked but I'd like you (if you don't mind) to explain exactly how it works, because I'm not sure I understand 100%...
Eldar Tinjić
@EldarT90
Apr 26 2016 08:38
https://codepen.io/EldarT/pen/zqJGQv still need help with animation, tnx
actually i dont
Codemzy
@codemzy
Apr 26 2016 08:40
@ajie62 great thats perfect. Ok so how it works ... I will comment this out... this is your function...
// this is your function named 'nextInLine' which takes two arguments / parameters 'arr' and 'item'
function nextInLine(arr, item) {
  // this line pushes the 'item' that has been passed in to the function, to the end of the 'arr' that has been passed in
  arr.push(item);
  // arr.shift() removes the first item from the arr, and you have stored this first item in your variable 'removedNumber'
  var removedNumber = arr.shift();
  // this line returns the 'removedNumber'
  return removedNumber;  // Change this line
}
Jérôme
@ajie62
Apr 26 2016 08:44
Oh, OK! Now I understand, thank you for your help, Emma! You seem very strong with JavaScript. Would it be possible for us to talk on Skype or something like it? I'd be glad if you could help me sometimes... And we could also talk about coding, etc.
Rudolf Carl Pablico
@rudolfpablico
Apr 26 2016 08:44

Hi guys, need help on this. What wrong with my code

var Bike = function() {

// Only change code below this line.
var gear = 0;
this.setGear = function(change) {
gear += change;
};

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

};

//var myCar = new Car();

var myBike = new Bike();

myBike.setGear(3);
myBike.getGear();

Im on Make Object properties private exercise.

Luong Quoc Dinh
@luongquocdinh
Apr 26 2016 08:57
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";
}
// Only change code above this line
}
why I ran right output but it still does not pass???
golfScore(4, 1) should return "Hole-in-one!"
golfScore(4, 2) should return "Eagle"
golfScore(5, 2) should return "Eagle"
golfScore(4, 3) should return "Birdie"
golfScore(4, 4) should return "Par"
golfScore(1, 1) should return "Hole-in-one!"
golfScore(5, 5) should return "Par"
golfScore(4, 5) should return "Bogey"
golfScore(4, 6) should return "Double Bogey"
golfScore(4, 7) should return "Go Home!"
golfScore(5, 9) should return "Go Home!"
Markus Kiili
@Masd925
Apr 26 2016 08:59
@luongquocdinh You are not celebrating "hole in one" and "go home" enough.
Zoher Ali
@Zoher-ali
Apr 26 2016 08:59
hey every1... someone plz help me with Arguments optional challenge
Markus Kiili
@Masd925
Apr 26 2016 09:00
@Zoher-ali Sure.
Luong Quoc Dinh
@luongquocdinh
Apr 26 2016 09:00
thanks @Masd925. I've found the problem
CamperBot
@camperbot
Apr 26 2016 09:00
luongquocdinh sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1414 | @masd925 | http://www.freecodecamp.com/masd925
Zoher Ali
@Zoher-ali
Apr 26 2016 09:02
@Masd925 here is my code ... i m not getting closure concept clear
function addTogether() {

  if(typeof arguments[0] == "number" && typeof arguments[1] == "number"){
        sum = arguments[0] + arguments[1];
    return sum;

  }
  else{
    return undefined;
  }

}

addTogether(2,[3]);
Markus Kiili
@Masd925
Apr 26 2016 09:04
@Zoher-ali You need two if clauses. One for two valid arguments and the second for one valid argument (arguments.length===1). In all other cases the function will automatically return undefined. You should only care about positive tests. The second if block should return a function. You can construct it or use add.bind().
Codemzy
@codemzy
Apr 26 2016 09:04
@ajie62 hey sorry I only just saw your message. I don't have skype but I am usually around in chat if you get stuck! and there are lots of other helpful people here aswell :thumbsup:
Zoher Ali
@Zoher-ali
Apr 26 2016 09:06
@Masd925 i m confused with that only... wat function would it return wat will it do?
Jérôme
@ajie62
Apr 26 2016 09:06
@codemzy no problem! thanks again for the help
CamperBot
@camperbot
Apr 26 2016 09:06
ajie62 sends brownie points to @codemzy :sparkles: :thumbsup: :sparkles:
:warning: ajie62 already gave codemzy points
naassi
@naassi
Apr 26 2016 09:08
I can not work this one out, it seems to be working but only one arr deep can anyone explain what im doin wrong ?
function steamrollArray(arr) {
  var srArr = [];
 function arrChecker(item) {
  if(Array.isArray(item)) {
    return arrChecker(item[0]);
  }
   return item;
 }
  for(var i = 0; i < arr.length; i ++) {
    srArr.push(arrChecker(arr[i]));
  }
  return srArr;
}

steamrollArray([1, [2], [3, [[4]]]]);
shalk(xiao kun)
@shalk
Apr 26 2016 09:09
 return arrChecker(item[0]);
only flaten one deep
Rudolf Carl Pablico
@rudolfpablico
Apr 26 2016 09:10

Hey guys, what's wrong in my code

var Bike = function() {

// Only change code below this line.
var gear = 0;
this.setGear = function(change) {
gear += change;
};

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

};

//var myCar = new Car();

var myBike = new Bike();

myBike.setGear(3);
myBike.getGear();

my code still returning the gear value even i comment out this myBike.getGear();
naassi
@naassi
Apr 26 2016 09:12
@shalk Yea i can see thats the problem and I have tried a for loop and incrementing but just cant work it out
shalk(xiao kun)
@shalk
Apr 26 2016 09:13
@naassi you should ensure every element in result is not Array. My solution : apply steamrollArray for every element (isArray)
????
Zoher Ali
@Zoher-ali
Apr 26 2016 09:17
function addTogether() {
 if(arguments.length === 1 && typeof arguments[0] == "number"){
   return function(val){
     return val + arguments[0];
   };
 }
  if(typeof arguments[0] == "number" && typeof arguments[1] == "number"){
        sum = arguments[0] + arguments[1];
    return sum;

  }
  else{
    return undefined;
  }

}

addTogether(2,[3]);
wats wrong in dis?
This message was deleted
shalk(xiao kun)
@shalk
Apr 26 2016 09:19
arguments will override in your return function .... assign arguments[0] to another variable
I met the problem before.
Rudolf Carl Pablico
@rudolfpablico
Apr 26 2016 09:20
@PabbaShivaRamKaushil too much spaces
Pabba Shiva Ram Kaushil
@PabbaShivaRamKaushil
Apr 26 2016 09:21
it ain't working @rudolfpablico
what is the problem in my code?
Rudolf Carl Pablico
@rudolfpablico
Apr 26 2016 09:22
@PabbaShivaRamKaushil reduce some spaces on myStr variable
Brendan Kinahan
@BKinahan
Apr 26 2016 09:22
morning y'all
Rudolf Carl Pablico
@rudolfpablico
Apr 26 2016 09:23
@BKinahan it's afternoon in PH :)
shalk(xiao kun)
@shalk
Apr 26 2016 09:23
good afternoon! @BKinahan
Brendan Kinahan
@BKinahan
Apr 26 2016 09:23
morfterning y'all
Pabba Shiva Ram Kaushil
@PabbaShivaRamKaushil
Apr 26 2016 09:23
@rudolfpablico cleared the spaces but it aint working.
Rudolf Carl Pablico
@rudolfpablico
Apr 26 2016 09:24
@PabbaShivaRamKaushil add one space
Pabba Shiva Ram Kaushil
@PabbaShivaRamKaushil
Apr 26 2016 09:24

// Example
var ourStr = "I come first. ";
ourStr += "I come second.";

// Only change code below this line

var myStr ="This is the first sentence." ;

myStr +="This is the second sentence." ;

@rudolfpablico
Gelman Solomon
@gelmans91
Apr 26 2016 09:25
how can I shhow what I wrote ?
Brendan Kinahan
@BKinahan
Apr 26 2016 09:25
@PabbaShivaRamKaushil your myStr ends up as "This is the first sentence.This is the second sentence." see the spacing error?
@gelmans91
```js
paste your code here
```
Gelman Solomon
@gelmans91
Apr 26 2016 09:25
function truncate(str, num) {
  if(num <=3){
    return str.slice(0,num) + "...";
  } 
  if(num >= str.length){
    return str;
  } else {
    return str.slice(0,num-3) + "...";
  }
}

truncate("A-tisket a-tasket A green and yellow basket", 11);
whats wrong here ?
Pabba Shiva Ram Kaushil
@PabbaShivaRamKaushil
Apr 26 2016 09:28
@BKinahan its not working. can you show the code
shalk(xiao kun)
@shalk
Apr 26 2016 09:29
The test case taught me a lot. Maybe your are not fully considered @gelmans91
Rudolf Carl Pablico
@rudolfpablico
Apr 26 2016 09:29

@PabbaShivaRamKaushil // Example
var ourStr = "I come first. ";
ourStr += "I come second.";

// Only change code below this line

var myStr ="This is the first sentence. " ;

myStr += "This is the second sentence." ;

Dardan Demiri
@dardandemiri
Apr 26 2016 09:34
Please
Can someone help me with this test
It's english Basic
Gelman Solomon
@gelmans91
Apr 26 2016 09:38
@shalk what ?
alpox
@alpox
Apr 26 2016 09:38
@dardandemiri 1C, 2F, 3B, 4E, 5D, 6A (English natives correct me if i'm wrong :D)
Dardan Demiri
@dardandemiri
Apr 26 2016 09:39
Thank You @alpox
CamperBot
@camperbot
Apr 26 2016 09:39
dardandemiri sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star: 608 | @alpox | http://www.freecodecamp.com/alpox
shalk(xiao kun)
@shalk
Apr 26 2016 09:39
@gelmans91 lol , I talk about the functiontruncate
Dardan Demiri
@dardandemiri
Apr 26 2016 09:41
the ex 2?
Brendan Kinahan
@BKinahan
Apr 26 2016 09:41
do your own dang homework
The point of it is to find out what you know, not to find out what internet people know..
Dardan Demiri
@dardandemiri
Apr 26 2016 09:43
This message was deleted
This message was deleted
This message was deleted
This message was deleted
This message was deleted
This message was deleted
This message was deleted
CamperBot
@camperbot
Apr 26 2016 09:45
dardandemiri sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star: 1389 | @bkinahan | http://www.freecodecamp.com/bkinahan
Brendan Kinahan
@BKinahan
Apr 26 2016 09:46
woo, brownies
the doer
@ewathedoer
Apr 26 2016 09:46
hehe it made my day @dardandemiri
and it has just started
Brendan Kinahan
@BKinahan
Apr 26 2016 09:47
anyway, my point stands
Dardan Demiri
@dardandemiri
Apr 26 2016 09:47
This message was deleted
Rudolf Carl Pablico
@rudolfpablico
Apr 26 2016 09:48
Well, we shouldn't be judgmental.
Dardan Demiri
@dardandemiri
Apr 26 2016 09:50
This message was deleted
Pabba Shiva Ram Kaushil
@PabbaShivaRamKaushil
Apr 26 2016 09:50
i have tried everything it aint working .
shalk(xiao kun)
@shalk
Apr 26 2016 09:51
wow, the message can be deleled
Dardan Demiri
@dardandemiri
Apr 26 2016 09:52
Yeah of course :P
Brendan Kinahan
@BKinahan
Apr 26 2016 09:52
lol
Rudolf Carl Pablico
@rudolfpablico
Apr 26 2016 09:53
@PabbaShivaRamKaushil i think you should try a little harder.
Sameer Shamsudeen
@sameershamsudheen
Apr 26 2016 09:54
rollem
CamperBot
@camperbot
Apr 26 2016 09:54
@sameershamsudheen says enjoy!https://www.youtube.com/watch?v=dQw4w9WgXcQ
Sameer Shamsudeen
@sameershamsudheen
Apr 26 2016 09:54
same videos :)
Kevin
@KevinBruland
Apr 26 2016 10:05
I think I am confused about global and local variables
if someone can explain something to me
var intervalID = 'off';    

$("#animateIt").on("click", function(){
    if (intervalID == 'off'){
    intervalID='on';
    setInterval(animation, 1500);
    }
    else {
    intervalID = 'off';
    }
});
I don't understand why running through that does not change the value of intervalID, the else statement is never triggers
Coryphaeus
@cvdeby
Apr 26 2016 10:08
@Benalron It happens because you used == instead of ===. == means that types are the same i.e. 'a' == 'b' returns true and 'a' === 'b' returns false.
Kevin
@KevinBruland
Apr 26 2016 10:09
@cvdeby I thought that was the case, but I had === initially and it didnt work either
Brendan Kinahan
@BKinahan
Apr 26 2016 10:09
@cvdeby that wouldn't cause the problem here.
@cvdeby 'a' == 'b' does not return true.
Kevin
@KevinBruland
Apr 26 2016 10:10
@BKinahan any thoughts on what is causing it?
ugh
Brendan Kinahan
@BKinahan
Apr 26 2016 10:11
@Benalron is this the complete code?
Kevin
@KevinBruland
Apr 26 2016 10:11
I figured it out
every time I come to this chat to ask a question, I figure it out
Brendan Kinahan
@BKinahan
Apr 26 2016 10:11
@Benalron haha, congrats :)
Dardan Demiri
@dardandemiri
Apr 26 2016 10:11
@Benalron That's better than receiving an answer
:D
Kevin
@KevinBruland
Apr 26 2016 10:11
I can stare at it for an hour, and a minute after I post it here I will figure it out : \
Brendan Kinahan
@BKinahan
Apr 26 2016 10:11
@Benalron "power of posting"
Often just thinking about how to ask a question will make you see your problem in a new way.
Dardan Demiri
@dardandemiri
Apr 26 2016 10:12
@Benalron what was wrong with the code ?
Kevin
@KevinBruland
Apr 26 2016 10:12
I think for me, it's seeing my code in a different window / format
@dardandemiri , its embarassing to say... but I was expecting it to clear the interval... creating a toggle on / off for a function
Coryphaeus
@cvdeby
Apr 26 2016 10:13
@Benalron I'm sorry for wrong suggestion :smile: I have no idea, why did I thought so)
Kevin
@KevinBruland
Apr 26 2016 10:13
@dardandemiri but I never told it to actually clear the interva
Dardan Demiri
@dardandemiri
Apr 26 2016 10:14
yeah I understand can you paste your correct code
Kevin
@KevinBruland
Apr 26 2016 10:15
well, I don't have correct code yet, because clearInterval(animation) isnt working yet
Sameer Shamsudeen
@sameershamsudheen
Apr 26 2016 10:15
Algorithm Chunky Monkey
Algorithm ChunkyMonkey
Dardan Demiri
@dardandemiri
Apr 26 2016 10:16
@sameershamsudheen write help before that
help chunky Monkey
CamperBot
@camperbot
Apr 26 2016 10:17
no wiki entry for: chunky monkey
Dardan Demiri
@dardandemiri
Apr 26 2016 10:17
help Chunky Monkey
CamperBot
@camperbot
Apr 26 2016 10:17
no wiki entry for: chunky monkey
Sameer Shamsudeen
@sameershamsudheen
Apr 26 2016 10:17
ok help Algorithm Chunky Monkey
help Algorithm Chunky Monkey
CamperBot
@camperbot
Apr 26 2016 10:17

:point_right: algorithm chunky monkey [wiki]

Explanation

Our goal for this Algorithm is to split arr (first argument) into smaller chunks of arrays with the length provided by size (second argument). There are 4 green checks (objectives) our code needs to pass in order to complete this Algorithm:

  1. (['a', 'b', 'c', 'd'], 2) is expected to be [['a', 'b'], ['c', 'd']]
  2. ([0, 1, 2, 3, 4, 5], 3) is expected to be [[0, 1, 2], [3, 4, 5]]
  3. ([0, 1, 2, 3, 4, 5], 2) is expected to be [[0, 1], [2, 3], [4, 5]]
  4. ([0, 1, 2, 3, 4, 5], 4) is expected to be [[0, 1, 2, 3], [4, 5]]

Click More information under the Algorithm title and read the helpful links if you haven't yet.

:pencil: read more about algorithm chunky monkey on the FCC Wiki

Coryphaeus
@cvdeby
Apr 26 2016 10:17
@Benalron If you wanna stop interval, you need to put setInterval(func, int) into a variable and than stop it like
var uniqueInterval = setInterval(animation, 1500);
...
clearInterval(uniqueInterval);
Sameer Shamsudeen
@sameershamsudheen
Apr 26 2016 10:17
bf spoiler
CamperBot
@camperbot
Apr 26 2016 10:17
Sorry, can't find a bonfire called spoiler. [ Check the map? ]
Kevin
@KevinBruland
Apr 26 2016 10:18
@cvdeby ah, I cant just clear it from what I am using?
Coryphaeus
@cvdeby
Apr 26 2016 10:19
@Benalron You can, but you need to use the result of setInterval like an argument for clearInterval;
@Benalron clearInterval find your unique setInterval and clear it.
Kevin
@KevinBruland
Apr 26 2016 10:21
@cvdeby hmm, im a little confused
Ankit Panwar
@coderNoob
Apr 26 2016 10:24
Your criticism is welcome
http://codepen.io/coderNoob/full/wGmbqZ/
Kevin
@KevinBruland
Apr 26 2016 10:24
@cvdeby could I just declare the variable inside my else statement? I want it to start in a default state of off
Dardan Demiri
@dardandemiri
Apr 26 2016 10:25
@coderNoob Good job
But is it choosing randomly or have you programmed it this way
Kevin
@KevinBruland
Apr 26 2016 10:27
@coderNoob I like it... but I will note if you click quickly, it does not play the sound... so if you get three of one color in a row, and you click a few times quickly... you lose the audio cue for how many times youve clicked
Coryphaeus
@cvdeby
Apr 26 2016 10:27
@Benalron Just put your setInterval() into a variable and whenever you want, you can stop it with clearInterval() and that is it :smile: But I cannot understand why click event doesn't work. Of course that variable should be global or something, you need the callback function from setInterval actually
Dardan Demiri
@dardandemiri
Apr 26 2016 10:27
@Benalron that's true
Ankit Panwar
@coderNoob
Apr 26 2016 10:27
@Benalron I know :(
@dardandemiri What do you mean?
randomly as in ?
Dardan Demiri
@dardandemiri
Apr 26 2016 10:29

For example,

You can code the game like this:

Level 1: Red
Level 2: Blue Green
Level 3: Green Green Red

Or, you can make
Abdulkarim Eskandar
@iskandar992
Apr 26 2016 10:30
hey guys
i'm at challenge number 252 and i don't seem to know what the problem is ?
Dardan Demiri
@dardandemiri
Apr 26 2016 10:30
Level 1: Random(Color)
Level 2: 2xRandom(Color)
Level 3: 3xRandom(Color)
Abdulkarim Eskandar
@iskandar992
Apr 26 2016 10:30
function palindrome(str) {
  // Good luck!
  var arr1 = [];
  var arr2 = [];
  var str1 ;
  var str2;

  arr1 = str.split("");
  arr1 = arr1.filter(function(val){
    return val == " ";
  });
  str1 = arr1.join("");

  arr2 = str.split("");
  arr2 = arr2.filter(function(val){
    return val == " ";
  });
  arr2 = arr2.reverse();
  str2 = arr2.join("");

  if(str1 === str2) {
    return true;
  } else {
      return false;
    }


}



palindrome("eye");
the code checks if a string palindrome or not
it gives true for the really palinndrome strings but doesnt return false on faulty ones
Ankit Panwar
@coderNoob
Apr 26 2016 10:31
@dardandemiri It's all random.
Kevin
@KevinBruland
Apr 26 2016 10:31
@cvdeby yeah... the thing is when I am adding that, its automatically starting up with the animation, even when I seeming havent called it
Ankit Panwar
@coderNoob
Apr 26 2016 10:31
@dardandemiri The game requires us to press random tiles
Dardan Demiri
@dardandemiri
Apr 26 2016 10:32
That's nice ;)
Bravo
Ankit Panwar
@coderNoob
Apr 26 2016 10:33
@dardandemiri Thanks. :smile:
CamperBot
@camperbot
Apr 26 2016 10:33
codernoob sends brownie points to @dardandemiri :sparkles: :thumbsup: :sparkles:
:star: 366 | @dardandemiri | http://www.freecodecamp.com/dardandemiri
Kevin
@KevinBruland
Apr 26 2016 10:34
    var animation = function() {
        load1();

        setTimeout(function() {
            load2();
        }, 500);
        setTimeout(function() {
            load3();
        }, 1000);
    }
    var animationSpeed = setInterval(animation, 1500);
    var intervalID = "off";

    $("#animateIt").on("click", function() {
        if (intervalID === "off") {
            intervalID = "on";
            setInterval(animationSpeed);
        } else {

            intervalID = "off";
            clearInterval(animationSpeed);
        }
    });
Stephen James
@sjames1958gm
Apr 26 2016 10:34
@iskandar992 Your two filters appear to eliminate all non-blank values
Kevin
@KevinBruland
Apr 26 2016 10:35
when I have that, @cvdeby ... it starts everything off with the interval already set... even before I click animateIt
Abdulkarim Eskandar
@iskandar992
Apr 26 2016 10:36
@sjames1958gm they eliminate the blank values not the non-blank
Stephen James
@sjames1958gm
Apr 26 2016 10:37
@iskandar992 But they don't if a filter function returns true - then keep the element - yours olny return true for blanks
Abdulkarim Eskandar
@iskandar992
Apr 26 2016 10:39
@sjames1958gm no it eliminates the blanks if the condition was true
this is the function from the tutorials it eliminates all elements which are equal to 5
array = array.filter(function(val) {
return val !== 5;
});
Stephen James
@sjames1958gm
Apr 26 2016 10:40
@iskandar992 So to eliminate blanks val !== " " the last code posted had val == " "
Abdulkarim Eskandar
@iskandar992
Apr 26 2016 10:43
@sjames1958gm yeah thanks so much my bad :smile:
CamperBot
@camperbot
Apr 26 2016 10:43
iskandar992 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 811 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Apr 26 2016 10:43
:+1:
@iskandar992 To be honest, a regular expression and string.replace might work better in eliminating characters, because you will have to handle more than just blanks
Coryphaeus
@cvdeby
Apr 26 2016 10:44
@Benalron animationSpeed triggered right after defining, you need to assign setInterval inside an if statement. So it'll looks like this
var animationSpeed;
// if you wanna trigger it right after defining
// var animationSpeed = setInterval(animation, 1500); 
$("#animateIt").on("click", function () {
  if(intervalID === 'off') {
    animationSpeed = setInterval(animation, 1500);
  } else {
    if (animationSpeed !== undefined) {
          clearInterval(animationSpeed);
    }
  }
});
Abdulkarim Eskandar
@iskandar992
Apr 26 2016 10:47
@sjames1958gm i figured that my way is a little bit naive , but i'm still new
you mean replacing every blank with an underscore or something or what
Stephen James
@sjames1958gm
Apr 26 2016 10:48
@iskandar992 No, eliminating all characters that are not 'a-z, 0-9'
@iskandar992 applying toLowerCase to your input string as well will reduce eliminate case sensitivity.
Kevin
@KevinBruland
Apr 26 2016 10:49
@cvdeby ill try that
Abdulkarim Eskandar
@iskandar992
Apr 26 2016 10:49
@sjames1958gm :+1: got it
Stephen James
@sjames1958gm
Apr 26 2016 10:49
@sjames1958gm Good luck!
Kevin
@KevinBruland
Apr 26 2016 10:49
@cvdeby YES! Thank you so much
CamperBot
@camperbot
Apr 26 2016 10:49
benalron sends brownie points to @cvdeby :sparkles: :thumbsup: :sparkles:
:star: 378 | @cvdeby | http://www.freecodecamp.com/cvdeby
AparnaSE
@AparnaSE
Apr 26 2016 10:54

Hey Guys need help in bouncy getting null value returned in the array even after filter
```function falsy(value){
if(value===false|| value===null||value===""||value===undefined||value.isNaN||value===0)
{
return false;
}
return true;
}
function bouncer(arr) {
// Don't show a false ID to this bouncer.
var x= Boolean(false);
arr=arr.filter(falsy);
return arr;
}

bouncer([false, null, 0, NaN, undefined, ""]);
```

Markus Kiili
@Masd925
Apr 26 2016 10:55
@AparnaSE It is NaN you have trouble with.
@AparnaSE Syntax for using isNaN is isNaN(value), but it is not a test for NaN. It coerces the value to number and then tests for NaN, which causes it to return true for many values besides NaN.
Hanan Mufti
@h-ARTS
Apr 26 2016 11:00
hi everyone
function palindrome(str) {
  str.toLowerCase();
  if (str) {
      str.replace(/[^a-zA-Z0-9]+/ig, "_")
  }
  return str;
}



palindrome("Eye with me");
I want to check if i can replace this with underscore, but its not working. Any idea why?
Stephen James
@sjames1958gm
Apr 26 2016 11:03
@h-ARTS replace doesn't modify str - you have to capture the return value. Remember strings are immutable in js
Jackson Bates
@JacksonBates
Apr 26 2016 11:16
for the Arguments Optional algorithm, can anyone point me at some documentation that explains how the addTogether(2)(3) syntax works? I don't get how the parentheses side-by-side work, and I didn't see anything in the MDN...could just be tired eyes, though...
also, is that a closures thing, or an arguments thing?
Markus Kiili
@Masd925
Apr 26 2016 11:17
@JacksonBates addtogether(2) should return a function and (3) invokes it.
Abdulkarim Eskandar
@iskandar992
Apr 26 2016 11:20

@sjames1958gm hi again :worried: i'v altered my code so now it's like this

function palindrome(str) {
  // Good luck!
  var re1 = /\W/gi;

  var arr1 = [];
  var arr2 = [];
  var str1 ;
  var str2;

  arr1 = str.split("");
  str1 = arr1.join("");
  str1 = str1.toLowerCase();
  str1 = str1.replace(re1,"");




  arr2 = str.split("");

  arr2 = arr2.reverse();
  str2 = arr2.join("");
  str2 = str2.toLowerCase();
  str2 = str2.replace(re1,"");



  if(str1 == str2) {
    return true;
  } else {
      return false;
    }


}

but this check is giving me a hard time and its the last one :S palindrome("0_0 (: /-\ :) 0-0")

Jackson Bates
@JacksonBates
Apr 26 2016 11:21
@Masd925 I understood that much from the challenge instructions, but that doesn't really make sense to me - is there documentation for this? I have a little sense of it from the closure MDN docs for the makeAdder example, but that doesn't have the adjacent parentheses syntax...not sure how to access the second parenthesis.
Mooli
@Mooli88
Apr 26 2016 11:22
whats the difference between $.getJSON() to $.get()
Markus Kiili
@Masd925
Apr 26 2016 11:23
@JacksonBates Here is an example:
function test1 () {           // returns a function that doubles passed numbers
    return function (input) {
        return input*2;
    };
}

test1();     // returns the function:  function (input) {return input*2;} that doubles passed numbers
test1()(7);  // invokes the function and returns 14
Stephen James
@sjames1958gm
Apr 26 2016 11:23
@iskandar992 \W unfortunately includes _ try /\W|_/
Jackson Bates
@JacksonBates
Apr 26 2016 11:24
@Masd925 I'll have a tinker with that and see how I go...thanks
CamperBot
@camperbot
Apr 26 2016 11:24
jacksonbates sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1415 | @masd925 | http://www.freecodecamp.com/masd925
Stephen James
@sjames1958gm
Apr 26 2016 11:25
@Mooli88 $.getJSON sends different headers indicating that it accepts json
Mooli
@Mooli88
Apr 26 2016 11:25
@sjames1958gm so i can't get json file with $.get()?
Abdulkarim Eskandar
@iskandar992
Apr 26 2016 11:26
@sjames1958gm yup it's done thank you sp much
but why did we include the haiphen and the underscore to be part of our palindrome and not other non-alphabetic chars although they were placed in palindrome way
CamperBot
@camperbot
Apr 26 2016 11:26
iskandar992 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: iskandar992 already gave sjames1958gm points
Mooli
@Mooli88
Apr 26 2016 11:29
@sjames1958gm i only just started learning ajax so im not yet familiar with some of the terms like header or Accept
Markus Kiili
@Masd925
Apr 26 2016 11:37
@Mooli88 $.get and $.getJSON are both shorthand notations for certain $.ajax calls. You can get json with $.get for example like this:
$.get( "test.php", function( data ) {
  $( "body" )
    .append( "Name: " + data.name ) // John
    .append( "Time: " + data.time ); //  2pm
}, "json" );
Hanan Mufti
@h-ARTS
Apr 26 2016 11:39
function findLongestWord(str) {
  var string = str.split('');
  var longest = 0;
  for (var i = 0; string.length > i; i++) {
    if (string[i].length > longest) {
        string[i].length = longest;
    }
  }
  return longest;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
I have problem: typeerror: cannot assign to read only property 'length' of string T??
Mooli
@Mooli88
Apr 26 2016 11:40
@Masd925 so this even more confusing. why is there a json before the last ( ? when should i use which
Markus Kiili
@Masd925
Apr 26 2016 11:41
@h-ARTS Strings are immutable so you cannot set string length: string[i].length = longest;.
AparnaSE
@AparnaSE
Apr 26 2016 11:41
@Masd925 I dont think it is with NaN. I think due to comparison of value === null
Markus Kiili
@Masd925
Apr 26 2016 11:42
@h-ARTS Maybe longest = string[i].length;
Hanan Mufti
@h-ARTS
Apr 26 2016 11:43
than how should i split it?
@Masd925 i can't even split it :worried:
AparnaSE
@AparnaSE
Apr 26 2016 11:43
@Masd925 yes it is due to NaN
Markus Kiili
@Masd925
Apr 26 2016 11:43
@AparnaSE Your code leaves only NaN in the array. FCC console shows it as null.
@AparnaSE NaN is the only value for which value===value is false and value!==value is true. Therefore you can test NaN with value!==value.
Hanan Mufti
@h-ARTS
Apr 26 2016 11:47
function findLongestWord(str) {
  var array = str.split('');
  var longest = 0;
  for (var i = 0; array.length > i; i++) {
    if (array[i].length > longest) {
        array[i].length = longest;
    }
  }
  return array;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
now i tried with array and it's still not working :worried:
Markus Kiili
@Masd925
Apr 26 2016 11:47
@h-ARTS Just do what I suggested and split the string first with .split(" ") <- space here. Then it works.
AparnaSE
@AparnaSE
Apr 26 2016 11:48
@Masd925 worked! Thank you so much :clap:
Hanan Mufti
@h-ARTS
Apr 26 2016 11:48
function findLongestWord(str) {
  var string = str.split(" ");
  var longest = 0;
  for (var i = 0; string.length > i; i++) {
    if (string[i].length > longest) {
        string[i].length = longest;
    }
  }
  return string;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
same problem
Abdulkarim Eskandar
@iskandar992
Apr 26 2016 11:49
@h-ARTS you also need to use longest.length in the comparison
if (string[i].length > longest.length)
Jackson Bates
@JacksonBates
Apr 26 2016 11:49
@Masd925 I managed to hack together something that worked. Thanks for your help :)
CamperBot
@camperbot
Apr 26 2016 11:49
jacksonbates sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: jacksonbates already gave masd925 points
Rohit Kumar Jena
@rohitrango
Apr 26 2016 11:52
can anyone help me with the 'Make a person' challenge ?
Hanan Mufti
@h-ARTS
Apr 26 2016 11:52
@iskandar992 i tried that too but it returns "0"
not 6
Rohit Kumar Jena
@rohitrango
Apr 26 2016 11:52
var Person = function(firstAndLast) {
    this.firstAndLast = firstAndLast;

  this.getFirstName = function() {
    var x = this.firstAndLast.split(" ");
    return x[0];
  };

  this.getLastName = function() {
    var x = firstAndLast.split(" ");
    return x[1];
  };

  this.getFullName = function() {
    return firstAndLast;
  }
  ;
  this.setFirstName = function(first) {
    var x = firstAndLast.split(" ");
    x[0] = first;
    x = x.join(" ");
    firstAndLast = x;
    return first;
  };

  this.setLastName = function(last) {
    var x = firstAndLast.split(" ");
    x[1] = last;
    x = x.join(" ");
    firstAndLast = x;
    return last;
  };

  this.setFullName = function(name) {
    firstAndLast = name;
    return name;
  };

};

var bob = new Person('Bob Ross');
//console.log(Object.keys(bob).length);
//bob.setFullName("Haskell Curry");
bob.getFullName();
Brendan Kinahan
@BKinahan
Apr 26 2016 11:53
@iskandar992 no.. longest is a number, it doesn't have length the way a string does
Marcel Schulz
@MarcelSchulz
Apr 26 2016 11:53
to the react folks: is there anything I need to keep in mind when trying to invoke a component’s method from withing a jQuery ajax callback within another method? this.methodName() will simply not fire at all
Rohit Kumar Jena
@rohitrango
Apr 26 2016 11:54
got it
thanks
Priyanka Gaikwad
@gaikwadpriyanka24
Apr 26 2016 11:54
Hi, I need help on "falsy bouncer " challenge. i have written afunction which return false if parameter passed to thefunction is falsy. but if i pass non -empty string that function's returning me false....
heres my code

function filterFalsVals(arrElement) {

 if (arrElement !== false && arrElement !== null && arrElement !== 0 && arrElement !== "" && arrElement !== undefined && !isNaN(arrElement)) {

  return true;
}

return false;

}

Abdulkarim Eskandar
@iskandar992
Apr 26 2016 11:54
@BKinahan you're right , the way i did it was with an empty string so i didn;t bother to look at his variable
Rohit Kumar Jena
@rohitrango
Apr 26 2016 11:55
@gaikwadpriyanka24 try Boolean(arrElement) !== false
instead of the long condition in the if statement
Abdulkarim Eskandar
@iskandar992
Apr 26 2016 11:56
@h-ARTS the string[i].length = longest should be inversed
longest = string[i].length
Priyanka Gaikwad
@gaikwadpriyanka24
Apr 26 2016 11:56
@rohitrango what that functions does?
does it check for falsy values?
Rohit Kumar Jena
@rohitrango
Apr 26 2016 11:56
it converts the expression into equivalent binary
boolean
sorry for the typo
yes
Abdulkarim Eskandar
@iskandar992
Apr 26 2016 11:57
@h-ARTS also the for-loop condition should be inverted
Rohit Kumar Jena
@rohitrango
Apr 26 2016 11:57
Boolean(expr) will return false if the value of expr is a null list, 0 , NaN or anything else
Hanan Mufti
@h-ARTS
Apr 26 2016 11:57
@iskandar992 oh gosh that was dumb :smile: thank you saved my life :smile: :+1:
CamperBot
@camperbot
Apr 26 2016 11:57
h-arts sends brownie points to @iskandar992 :sparkles: :thumbsup: :sparkles:
:star: 255 | @iskandar992 | http://www.freecodecamp.com/iskandar992
Abdulkarim Eskandar
@iskandar992
Apr 26 2016 11:58
any time :+1:
Brendan Kinahan
@BKinahan
Apr 26 2016 11:58
@rohitrango Boolean(arrElement) !== false is a long way of writing Boolean(arrElement)
Rohit Kumar Jena
@rohitrango
Apr 26 2016 11:58
yes @BKinahan :P
just to explain things :)
Priyanka Gaikwad
@gaikwadpriyanka24
Apr 26 2016 12:00
@rohitrango Thank you :)
CamperBot
@camperbot
Apr 26 2016 12:00
gaikwadpriyanka24 sends brownie points to @rohitrango :sparkles: :thumbsup: :sparkles:
:star: 310 | @rohitrango | http://www.freecodecamp.com/rohitrango
Rohit Kumar Jena
@rohitrango
Apr 26 2016 12:00
someone refer to the first testcase of the 'Make a person' challenge. I think the length should be 7 and not 6
shalk(xiao kun)
@shalk
Apr 26 2016 12:00
help ~ 367.4 / 10 = 36.73999999999999999999999.
CamperBot
@camperbot
Apr 26 2016 12:00
no wiki entry for: 3674 10 3673999999999999999999999
shalk(xiao kun)
@shalk
Apr 26 2016 12:01
help math
CamperBot
@camperbot
Apr 26 2016 12:01

:point_right: math.max [wiki]

Math.max()

The Math.max() function returns the largest of zero or more numbers.

:pencil: read more about mathmax on the FCC Wiki

Theodore P.
@Ierofantis
Apr 26 2016 12:04
can anyone explain why the animation one by one on my simon game is not working?
Rohit Kumar Jena
@rohitrango
Apr 26 2016 12:06
someone please help with this challenge
Make a person challenge - idk why this image is showing up :/
var Person = function(firstAndLast) {
    this.firstAndLast = firstAndLast;

  this.getFirstName = function() {
    var x = this.firstAndLast.split(" ");
    return x[0];
  };

  this.getLastName = function() {
    var x = this.firstAndLast.split(" ");
    return x[1];
  };

  this.getFullName = function() {
    return this.firstAndLast;
  }
  ;
  this.setFirstName = function(first) {
    var x = this.firstAndLast.split(" ");
    x[0] = first;
    x = x.join(" ");
    this.firstAndLast = x;
    return first;
  };

  this.setLastName = function(last) {
    var x = this.firstAndLast.split(" ");
    x[1] = last;
    x = x.join(" ");
    this.firstAndLast = x;
    return last;
  };

  this.setFullName = function(name) {
    this.firstAndLast = name;
    return this.firstAndLast;
  };


};

var bob = new Person('Bob Ross');
console.log(Object.keys(bob).length);
bob.getFirstName();
Object.keys(bob).length should return 6. but it returns 7
shalk(xiao kun)
@shalk
Apr 26 2016 12:09
try to output keys.
["firstAndLast", "getFirstName", "getLastName", "getFullName", "setFirstName", "setLastName", "setFullName"]
Rohit Kumar Jena
@rohitrango
Apr 26 2016 12:22
@shalk then how will i store the name of the Person
Diego Mayer
@Chrono79
Apr 26 2016 12:25
@rohitrango count how many this.nameFunction you have
Rohit Kumar Jena
@rohitrango
Apr 26 2016 12:25
6
and a variable this.firstAndLast
this.firstAndLast
Diego Mayer
@Chrono79
Apr 26 2016 12:26
@rohitrango instead of this, use var with firstAndLast
Rohit Kumar Jena
@rohitrango
Apr 26 2016 12:26
okay
Diego Mayer
@Chrono79
Apr 26 2016 12:27
@rohitrango another thing, you only have to return in the gets, not in the sets
Rohit Kumar Jena
@rohitrango
Apr 26 2016 12:28
still doesnot work @Chrono79
Diego Mayer
@Chrono79
Apr 26 2016 12:28
@rohitrango there are more things wrong with your code
Rohit Kumar Jena
@rohitrango
Apr 26 2016 12:28
okay, checking them out
i dont think there are any more errors in this one -
var Person = function(f) {

  var firstAndLast = f;

  this.getFirstName = function() {
    var x = firstAndLast.split(" ");
    return x[0];
  };

  this.getLastName = function() {
    var x = firstAndLast.split(" ");
    return x[1];
  };

  this.getFullName = function() {
    return firstAndLast;
  };

  this.setFirstName = function(first) {
    var x = firstAndLast.split(" ");
    x[0] = first;
    x = x.join(" ");
    firstAndLast = x;

  };

  this.setLastName = function(last) {
    var x = this.firstAndLast.split(" ");
    x[1] = last;
    x = x.join(" ");
    firstAndLast = x;

  };

  this.setFullName = function(name) {
    firstAndLast = name;

  };

};

var bob = new Person('Bob Ross');
bob.setLastName("Curry");
//bob.getFullName();
Diego Mayer
@Chrono79
Apr 26 2016 12:29
@rohitrango to make things easier I would store the name in the var as a 2 element array
Rohit Kumar Jena
@rohitrango
Apr 26 2016 12:30
it is the same as concatenating the 2 strings in the getFullName function
Diego Mayer
@Chrono79
Apr 26 2016 12:31
@rohitrango Maybe, but you have to type less code
AudioGen
@AudioGen
Apr 26 2016 12:31
Hello
Rohit Kumar Jena
@rohitrango
Apr 26 2016 12:32
i did the same as u told @Chrono79 but when the keys increased from 7 to 8 , i had to adopt this one
Diego Mayer
@Chrono79
Apr 26 2016 12:32

@rohitrango

var x = this.firstAndLast.split(" ");

I think this. is not needed there
Also look at the methods list they give you, I don't know if you have to name the params exactly or not

@AudioGen hello
Rohit Kumar Jena
@rohitrango
Apr 26 2016 12:33
@Chrono79 clear
overlooked it :P
AudioGen
@AudioGen
Apr 26 2016 12:38
any good sources on error handling?
like try, catch, throw, finally statements?
unnzowy
@unnzowy
Apr 26 2016 12:39
Hi Guys. This solution works, but is it good (enough)?
function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  //var myFalse = Boolean();

  arr2 = [];

  for(i=0; i < arr.length; i++)  {
    var myFalse = Boolean(arr[i]);
      if(myFalse){
        arr2.push(arr[i]);
      }        
    }
   return arr2;
}
Diego Mayer
@Chrono79
Apr 26 2016 12:40
@unnzowy you could use Array.filter there, I think that's what they want you to do
AudioGen
@AudioGen
Apr 26 2016 12:41
@unnzowy If it works, it works but from what I have read it's not recommended to use Boolean Objects
Diego Mayer
@Chrono79
Apr 26 2016 12:41
@AudioGen Don't know any good source, sorry
unnzowy
@unnzowy
Apr 26 2016 12:41
yeah i know, im checking solutions on the other site, anyway thanks :)
Elbert Cortez
@trip16661
Apr 26 2016 12:42
guys I'm trying to sum all the amount values of an object like this ({"some"{name: something,amount;someval},...}) in a var but its not working with a for in loop , how can i do it instead
for(var key in object){
    total += object[key].amount;
  }
Diego Mayer
@Chrono79
Apr 26 2016 12:46

@trip16661

var Objeto = {"some":{name: "something",amount: 2}, "some2":{name: "something",amount: 3}};
var total = 0;
for(var key in Objeto){
    total += Objeto[key].amount;
}

console.log(total);

It works for me

Abdulkarim Eskandar
@iskandar992
Apr 26 2016 12:53
hello
Diego Mayer
@Chrono79
Apr 26 2016 12:54
hi
Abdulkarim Eskandar
@iskandar992
Apr 26 2016 12:54
any idea why isn't this function delivering the right result
function titleCase(str) {
  var tempArray = str.split(" ");

  for(var i=0; i < tempArray.length; i++)
  {
    var a = i;
    var b = i + 1;

    if (a === 0) {
      tempArray[a] = tempArray[a].toUpperCase();
    }
    else if(tempArray[a] === " " && tempArray[b] !== " ") {
      tempArray[b] = tempArray[b].toUpperCase();
    } else  {tempArray[a] = tempArray[a].toLowerCase();}

  }
  str = tempArray.join(" ");
  return str;
}

titleCase("I'm a little tea pot");
Elbert Cortez
@trip16661
Apr 26 2016 12:55
@Chrono79 yeah but it says undefined xD
Diego Mayer
@Chrono79
Apr 26 2016 12:55
@iskandar992 tempArray[x] is never " "
When you split a string using split(" "), that array only contains words, that is if you have only single spaces between the words, like the test cases
Elbert Cortez
@trip16661
Apr 26 2016 12:56
@Chrono79 thanks xD
Abdulkarim Eskandar
@iskandar992
Apr 26 2016 12:56
why not , doesn't it add the blanks as well
Elbert Cortez
@trip16661
Apr 26 2016 12:56
wait did they remove the brownie points?
Diego Mayer
@Chrono79
Apr 26 2016 12:57
@trip16661 Maybe they're fixing the camperbot script
help format
CamperBot
@camperbot
Apr 26 2016 12:57

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

Diego Mayer
@Chrono79
Apr 26 2016 13:00
@iskandar992 I suggest you lowerCase the whole string and after splitting, uppercase the first letter and concatenate with the rest of the word, finally return a string
Abdulkarim Eskandar
@iskandar992
Apr 26 2016 13:02
i ran my code on https://repl.it/CJlA but i added a printing to the array elements
it totally does what its meant to do but the problem is after the join :S
@Chrono79
Tyler
@tylergross
Apr 26 2016 13:03
Has anyone created the tic tac toe challenge? I understand how the minimax algorithm functions determining all possible solutions and picking the best, I've researched a lot of sample code and theory but I cannot figure out how to put this into a function. Is there a good step by step tutorial to designing a minimax algorithm?
Diego Mayer
@Chrono79
Apr 26 2016 13:03
@iskandar992 No it doesn't, it returns this:
'I\'M a little tea pot'
Abdulkarim Eskandar
@iskandar992
Apr 26 2016 13:04
@Chrono79 yes but have you tried to print the elements of the array
it prints them with every first letter as a capital
Diego Mayer
@Chrono79
Apr 26 2016 13:05
@iskandar992 at what point of the code?
Abdulkarim Eskandar
@iskandar992
Apr 26 2016 13:06
@Chrono79
function titleCase(str) {
  var tempArray = str.split("");

  for(var i=0; i < tempArray.length; i++)
  {
    var a = i;
    var b = i + 1;

    console.log(tempArray[i]);

    if (a === 0) {
      tempArray[a] = tempArray[a].toUpperCase();
    }
    else if(tempArray[a] === " " && tempArray[b] !== " ") {
      tempArray[b] = tempArray[b].toUpperCase();
    } else  {tempArray[a] = tempArray[a].toLowerCase();}

  }
  str = tempArray.join("");
  return str;
}

titleCase("I'm a little tea pot");
try it yourself
i tried removing the else and its returning capitals on the first of each word
but other cases aren't being handled
Diego Mayer
@Chrono79
Apr 26 2016 13:09
@iskandar992 remove this:
else  {tempArray[a] = tempArray[a].toLowerCase();}
Abdulkarim Eskandar
@iskandar992
Apr 26 2016 13:09
already did
function titleCase(str) {
  str = str.toLowerCase();
  var tempArray = str.split("");
  var array = [];

  for(var i=0; i < tempArray.length; i++)
  {
    var a = i;
    var b = i + 1;
    if (a === 0) {
      tempArray[a] = tempArray[a].toUpperCase();
    }
    else if(tempArray[a] === " " && tempArray[b] !== " ") {
      tempArray[b] = tempArray[b].toUpperCase();
    } 

  }
  str = tempArray.join("");
  return str;
}

titleCase("I'm a little tea pot");
done :D :D
@Chrono79 thxx
Diego Mayer
@Chrono79
Apr 26 2016 13:12

@iskandar992 no problem but this sentence here is always false I think so delete and try

else if(tempArray[a] === " " && tempArray[b] !== " ") {
      tempArray[b] = tempArray[b].toUpperCase();
    }

As I said before, tempArray[a] === " " is always false and false and anything is false too so...

Abdulkarim Eskandar
@iskandar992
Apr 26 2016 13:13
no the challenge is already completed nothing wrong with it
Diego Mayer
@Chrono79
Apr 26 2016 13:13
This message was deleted
Alexis
@alexisgcn
Apr 26 2016 13:15
help Find the Longest Word in a String
CamperBot
@camperbot
Apr 26 2016 13:15

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

Explanation:

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

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

Abdulkarim Eskandar
@iskandar992
Apr 26 2016 13:15
yeah i know i only put these cuz i thought maybe the problem some how was because of the i
Diego Mayer
@Chrono79
Apr 26 2016 13:15
@iskandar992 forget what I said, I thought you where splitting with " ", and you're using "" that gives you an array with elements of length 1 and tempArray[x] can be " "
olciandro matos
@olciandromatos
Apr 26 2016 13:16
hello guys!!
i'm stuck in the exercise 216 - Counting Cards
i need help
please
!!!
Diego Mayer
@Chrono79
Apr 26 2016 13:18
@olciandromatos Paste some code
olciandro matos
@olciandromatos
Apr 26 2016 13:18
ok!
Diego Mayer
@Chrono79
Apr 26 2016 13:18
help Counting Cards
CamperBot
@camperbot
Apr 26 2016 13:18

:point_right: checkpoint counting cards [wiki]

Checkpoint: Counting Cards

About Blackjack

In the casino game Blackjack, a player can gain an advantage over the house by keeping track of the relative number of high and low cards remaining in the deck. This is called Card Counting.

Having more high cards remaining in the deck favors the player. Each card is assigned a value according to the table below. When the count is positive, the player should bet high. When the count is zero or negative, the player should bet low.

Value Cards
+1 2, 3, 4, 5, 6
0 7, 8, 9
-1 10, 'J', 'Q', 'K','A'

Instructions

You will write a card counting function. It will receive a card parameter and increment or decrement the global count variable according to the card's value (see table). The function will then return the current count and the string "Bet" if the count is positive, or "Hold" if the count is zero or negative.

Example Output:

:pencil: read more about checkpoint counting cards on the FCC Wiki

olciandro matos
@olciandromatos
Apr 26 2016 13:18
yes

var count = 0;

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

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

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

i dont know how to do
Diego Mayer
@Chrono79
Apr 26 2016 13:19
@olciandromatos you have to evaluate 2 things inside your function, the card value and the count value
The first evaluation can be done with nested ifs or switch
And after that, evaluate count value and return count + " Hold" or " Bet" depending on count value (note the space between count and Bet or Hold)
olciandro matos
@olciandromatos
Apr 26 2016 13:19
right!!
i'm undertanding
Diego Mayer
@Chrono79
Apr 26 2016 13:21
@olciandromatos There you go, happy coding
olciandro matos
@olciandromatos
Apr 26 2016 13:21
ok i gonna try
Rimsf9
@Rimsf9
Apr 26 2016 13:27
Untitled.png