These are chat archives for FreeCodeCamp/HelpJavaScript

17th
Jul 2016
kevinstonge
@kevinstonge
Jul 17 2016 00:02
confirmed that this works:
inputTrimmed = inputLowercase.replace(/[^a-z0-9]/g,"");
but still would like to know how to regex parentheses!
I had to use the octal codes - my final line looked like this:
inputTrimmed = inputLowercase.replace(/\s|[,._-]|\050|\051/g,"");
thanks @kevinstonge :)
CamperBot
@camperbot
Jul 17 2016 00:05
sorry kevinstonge, you can't send brownie points to yourself! :sparkles: :sparkles:
Stephen James
@sjames1958gm
Jul 17 2016 00:12
@willcodes Sorry was offline
willcodes
@willcodes
Jul 17 2016 00:14
@sjames1958gm thank god, i've been so stumped lol. I had it at least changing the picture at one point when I called quotes[0].author
CamperBot
@camperbot
Jul 17 2016 00:14
willcodes sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1923 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 17 2016 00:14
@kevinstonge Does \( work for matching.
willcodes
@willcodes
Jul 17 2016 00:14
@sjames1958gm but i'm sure you know that wasn't the solution lol
Stephen James
@sjames1958gm
Jul 17 2016 00:14
@willcodes What do you have now
@Chrislearns Did you get help?
kevinstonge
@kevinstonge
Jul 17 2016 00:15
@sjames1958gm it honestly wasn't working for me, gave me a little yellow warning. :\ any idea what I might have done wrong?
homercrates
@homercrates
Jul 17 2016 00:15
@Chrislearns thats not inside a function right?
willcodes
@willcodes
Jul 17 2016 00:15
var random = quotes[Math.floor(Math.random() *quotes.length)];
function randomQuote() {
 var random = quotes[Math.floor(Math.random() *quotes.length)];
 $("#thisquote").text(random.quote);

  $("#thisauthor").text("-" +random.author);
  };
function changeBackground() {
   var random = quotes[Math.floor(Math.random() *quotes.length)];
  if ($(quotes[random].author)  === "Kramer") {
      $("body").css("background-image", "linear-gradient(to top, rgba(0,0,0,0.2), rgba(0,0,0,0.5)),url('file:C:/Users/user/Desktop/freecodecamp/random quote/images/kramer.jpg'"); 
    }
    else if (quotes[random].author === "George"){
      $("body").css("background-image", "linear-gradient(to top, rgba(0,0,0,0.2), rgba(0,0,0,0.5)),url('file:C:/Users/user/Desktop/freecodecamp/random quote/images/george.jpg'"); 
    }
    else if (quotes[random]["author"] === "Elaine"){
      $("body").css("background-image", "linear-gradient(to top, rgba(0,0,0,0.2), rgba(0,0,0,0.5)),url('file:C:/Users/user/Desktop/freecodecamp/random quote/images/elaine.jpg'"); 
    }
    else if (quotes[random]["author"] === "Jerry"){
      $("body").css("background-image", "linear-gradient(to top, rgba(0,0,0,0.2), rgba(0,0,0,0.5)),url('file:C:/Users/user/Desktop/freecodecamp/random quote/images/jerry.jpg'"); 
    }
    else{
      $("body").css("background-image", "linear-gradient(to top, rgba(0,0,0,0.2), rgba(0,0,0,0.5)),url('file:C:/Users/user/Desktop/freecodecamp/random quote/images/bg.jpg'"); 
    }


  };


/*  function changeColor() {
    var change = colors[Math.floor(Math.random() *colors.length)];
    $('body').css("background", change);
    $('#getQuote').css("background", change);
  };*/

  function removeHeader() {
    $("#header").remove();
  }
  $('.btn').click(function() {

    removeHeader();
    randomQuote();
    changeBackground();

});

});
Stephen James
@sjames1958gm
Jul 17 2016 00:16
@kevinstonge yellow warning in the FCC editor? Yeah not sure, maybe got confused matching parens?
kevinstonge
@kevinstonge
Jul 17 2016 00:16
ok, I went back and replaced my 050 and 051 with ( and ) and it worked. Weird. no clue what I did wrong.
Chris Drain
@Chrislearns
Jul 17 2016 00:16
lol
kevinstonge
@kevinstonge
Jul 17 2016 00:16
thanks @sjames1958gm
CamperBot
@camperbot
Jul 17 2016 00:16
kevinstonge sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1924 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 17 2016 00:16
@willcodes If you calc random twice you will get different numbers
Chris Drain
@Chrislearns
Jul 17 2016 00:16
I figured it out

function rot13(str) { // LBH QVQ VG!
var string = str.split(" ");
var finished = "";
var map = Array.prototype.map;
var charCodeArray = map.call(str, function (x){

  var  y = x.charCodeAt(0);

  if(y <= 77 && y >= 65){
    y =  y + 13;
 }
else  if(y >= 78 && y <= 91){
   y =  y - 13;}
  return y ;

});

for(var i = 0; i<charCodeArray.length; i++){
finished += String.fromCharCode(charCodeArray[i]);
}
return finished;
}

homercrates
@homercrates
Jul 17 2016 00:16
@Chrislearns isnt that your problem its not inside a function so its not really being turne don ey?
Stephen James
@sjames1958gm
Jul 17 2016 00:16
@Chrislearns :+1:
willcodes
@willcodes
Jul 17 2016 00:16
@sjames1958gm let me remove the other 2 var randoms
Stephen James
@sjames1958gm
Jul 17 2016 00:17
@Chrislearns Here is how to get the post to show correctly :point_down:
help format
CamperBot
@camperbot
Jul 17 2016 00:17

: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 thecode`.

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

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

homercrates
@homercrates
Jul 17 2016 00:17
@Chrislearns youg ot it working then?
Stephen James
@sjames1958gm
Jul 17 2016 00:18
@Chrislearns You could have done str.split("").map();
Chris Drain
@Chrislearns
Jul 17 2016 00:19
oh yea you can chain methods
@sjames1958gm
homercrates
@homercrates
Jul 17 2016 00:19
sweet
willcodes
@willcodes
Jul 17 2016 00:19
@sjames1958gm i just embeded it because as a global function it was stopping after one quote
Stephen James
@sjames1958gm
Jul 17 2016 00:19
@Chrislearns I see you had split(" ") which wouldn't split on characters is that why you didn't use string?
willcodes
@willcodes
Jul 17 2016 00:19
but it doesnt solve the problemo
Norvin Burrus
@ndburrus
Jul 17 2016 00:20
@Chrislearns
for code posting - typing shift + enter provides additional line feeds (space for posting/pasting code).
you may also find the chat & compose buttons to the right of the chat text entry area useful. the backtick/s key is located to the left of the #1 (number one) key. :sparkles:
Chris Drain
@Chrislearns
Jul 17 2016 00:20

```
function rot13(str) { // LBH QVQ VG!
var string = str.split(" ");
var finished = "";
var map = Array.prototype.map;
var charCodeArray = map.call(str, function (x){

  var  y = x.charCodeAt(0);

  if(y <= 77 && y >= 65){
    y =  y + 13;
 }
else  if(y >= 78 && y <= 91){
   y =  y - 13;}
  return y ;

});

for(var i = 0; i<charCodeArray.length; i++){
finished += String.fromCharCode(charCodeArray[i]);
}
return finished;
}

lol didn’t work
Stephen James
@sjames1958gm
Jul 17 2016 00:21
@Chrislearns Missed the ``` at the end. after shift-enter
Dexter Passenger
@DexPassenger
Jul 17 2016 00:21
Can you use .filter() on nested arrays?
Chris Drain
@Chrislearns
Jul 17 2016 00:21
@sjames1958gm
function rot13(str) { // LBH QVQ VG!
  var string = str.split(" ");
  var finished = "";
  var map = Array.prototype.map;
    var charCodeArray = map.call(str, function (x){

      var  y = x.charCodeAt(0);

      if(y <= 77 && y >= 65){
        y =  y + 13;
     }
    else  if(y >= 78 && y <= 91){
       y =  y - 13;}
      return y ;

    });
   for(var i = 0; i<charCodeArray.length; i++){
     finished += String.fromCharCode(charCodeArray[i]);
   }
  return finished;
}
nice
Stephen James
@sjames1958gm
Jul 17 2016 00:21
@Chrislearns :)
homercrates
@homercrates
Jul 17 2016 00:21
much easier
Stephen James
@sjames1958gm
Jul 17 2016 00:21
@DexPassenger yes.
Dexter Passenger
@DexPassenger
Jul 17 2016 00:22
@sjames1958gm Thank you.
CamperBot
@camperbot
Jul 17 2016 00:22
dexpassenger sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1925 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 17 2016 00:22
@DexPassenger arr[i].filter() like that?
Dexter Passenger
@DexPassenger
Jul 17 2016 00:22
Yes exactly.
Stephen James
@sjames1958gm
Jul 17 2016 00:23
@willcodes put random = into your click handler and pass it to randomQuote and changeBackground if you make it global it may only be computing it once.
kevinstonge
@kevinstonge
Jul 17 2016 00:24
Title Case a Sentence - I feel like this is poorly written (but it works!) what could I do better here?
function titleCase(str) {
  inputAsArray = str.split(" ");
  outputString = "";
  for (i=0;i<inputAsArray.length;i++) {
    outputString += inputAsArray[i].charAt(0).toUpperCase() + inputAsArray[i].slice(1).toLowerCase() + ((i == inputAsArray.length - 1) ? "" : " ");
  }
  return outputString;
}
Stephen James
@sjames1958gm
Jul 17 2016 00:25
@kevinstonge if you build an array and use join you don't have to make that test as join doesn't put a " " at the end
Rahin Ahmed
@rahin1122
Jul 17 2016 00:25
Hi Guys I was doing following the instructions below .Here Is Instructions and code .On line 4 in instructions i could not get it . nextInLine([], 1) should return 1
nextInLine([2], 1) should return 2
nextInLine([5,6,7,8,9], 1) should return 5
After nextInLine(testArr, 10), testArr[4] should be 10
kevinstonge
@kevinstonge
Jul 17 2016 00:26
so in my for loop I should push to an array and thena fter teh for loop I should join to a string?
Stephen James
@sjames1958gm
Jul 17 2016 00:26
@kevinstonge Yeah. Actually this is a good one for arraymap
function titleCase(str) {

  return str.split(' ').map(function(val) {
    return val.charAt(0).toUpperCase() + val.toLowerCase().slice(1);
  }).join(' ');

}
bitgrower
@bitgrower
Jul 17 2016 00:27
@kevinstonge getting it right is 90% of the battle at this stage in the game ... even in pro development houses, you first get it right ... and you pick up how to do things better as you go along ... keep makin' progress, getting thru the challenges ... :)
kevinstonge
@kevinstonge
Jul 17 2016 00:27
bah, I thought of using map but couldnt' see how it would work!
Rahin Ahmed
@rahin1122
Jul 17 2016 00:27

function nextInLine(arr, item) {
// Your code here
var res = arr.push(1);
var res1 = arr.shift();
return res1;

}
nextInLine([5,6,7,8,9,10,1],1);

kevinstonge
@kevinstonge
Jul 17 2016 00:27
thanks again @sjames1958gm I'm going to try to use map without looking at your code :)
CamperBot
@camperbot
Jul 17 2016 00:27
kevinstonge sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: kevinstonge already gave sjames1958gm points
kevinstonge
@kevinstonge
Jul 17 2016 00:27
thanks @bitgrower
CamperBot
@camperbot
Jul 17 2016 00:27
kevinstonge sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star2: 1141 | @bitgrower |http://www.freecodecamp.com/bitgrower
Stephen James
@sjames1958gm
Jul 17 2016 00:27
@rahin1122 add item not 1
@kevinstonge It is good that you recognized that there might be a need for improvement. The code felt clunky and you felt it :)
@ndburrus Hey you are number one on points over the last 30 days - WTG.
Norvin Burrus
@ndburrus
Jul 17 2016 00:32
@sjames1958gm thanks for noticing/commenting... now i need to refocus back to lessons & reading... :+1:
CamperBot
@camperbot
Jul 17 2016 00:32
ndburrus sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1926 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Aiden
@AidenMead
Jul 17 2016 00:32
I am completely lost on Record Collection, anyone have any advice on how to logically approach it? I'm stuck on the instructions and not knowing where to start.
And I've been staring at it for about a week.
Stephen James
@sjames1958gm
Jul 17 2016 00:33
@ndburrus Just starting on the React project for displaying this information
Norvin Burrus
@ndburrus
Jul 17 2016 00:34
@sjames1958gm sounds interesting...
Stephen James
@sjames1958gm
Jul 17 2016 00:34
@AidenMead One of the campers has a nice description of it.
https://gist.github.com/revisualize/123deb77d85079f079020ac3cd6ea5ba
Aiden
@AidenMead
Jul 17 2016 00:35
Wow, that almost makes it seem easy! Thank you @sjames1958gm
CamperBot
@camperbot
Jul 17 2016 00:35
aidenmead sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1927 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Chris Drain
@Chrislearns
Jul 17 2016 00:36
@AidenMead @sjames1958gm That’s a good description. I was going to tell him to start with a simple if statement. That way he can get those synapses firing. Also go back over the previous challenges they have all the knowledge needed to get started. Learning how to connect the dots at that point is essential.
Norvin Burrus
@ndburrus
Jul 17 2016 00:36
@sjames1958gm say, the link opens as an object...?
kevinstonge
@kevinstonge
Jul 17 2016 00:36

@sjames1958gm - my code for titleCase(str):

  stringAsArray = str.split(" ");
  fixedCaseArray = stringAsArray.map(function(val) { return val.charAt(0).toUpperCase() + val.slice(1).toLowerCase(); });
  return fixedCaseArray.join(" ");

I wonder if you'd mind commenting on how you know how much to stuff after the word 'return' because I see you put the whole damn function after the word return in your solution! Are there guidelines or rules for that?

Stephen James
@sjames1958gm
Jul 17 2016 00:37
@ndburrus Yeah that is the JSON input into the project -
Here is the sample project for the project
https://codepen.io/FreeCodeCamp/full/eZGMjp/
kevinstonge
@kevinstonge
Jul 17 2016 00:37
I can see that I don't need to assign these things to variables if I'm not going to use the variables again ... I assume that's part of it
Aiden
@AidenMead
Jul 17 2016 00:38
@Chrislearns I figured the key would lay in the previous lessons, but I keep writing out code that just accesses nested objects and then get stuck, haha.
Stephen James
@sjames1958gm
Jul 17 2016 00:39
@kevinstonge You kind of have to judge whether the beginning to end loses the meaning, if it does then you have to split it up.
There is a bit of a 'who can do it shortest' competition in this chat :)
Chris Drain
@Chrislearns
Jul 17 2016 00:40
@AidenMead lol
Stephen James
@sjames1958gm
Jul 17 2016 00:40
@Chrislearns @AidenMead there is a whole long discussion about the wording of that challenge.
FreeCodeCamp/FreeCodeCamp#9380
kevinstonge
@kevinstonge
Jul 17 2016 00:41
Thanks
John Mica
@JohnMica
Jul 17 2016 00:41
hi guys
Chris Drain
@Chrislearns
Jul 17 2016 00:43
@sjames1958gm lol I don’t blame them. When I first read it I winced myself.
Aiden
@AidenMead
Jul 17 2016 00:47
it's definitely pretty rough
Randy Goldsmith
@Dueldrawer8
Jul 17 2016 00:48
@sjames1958gm could you take a look at this and see why whenever i tweet out a quote.. there is a glitch and my main page goes to error
http://codepen.io/duel_drawer8/pen/WxdGzj
John Mica
@JohnMica
Jul 17 2016 00:49
i ran into an issue with the word blank - cant understand what they wnat from me :))
Stephen James
@sjames1958gm
Jul 17 2016 00:50
@Dueldrawer8 The error I saw in your html is http:www.twitter.com/intent/tweet missing //
Randy Goldsmith
@Dueldrawer8
Jul 17 2016 00:50
@sjames1958gm its there
window.open("http://www.twitter.com/intent/tweet?text=" + text + '-' + author);
})
Diego Mayer
@Chrono79
Jul 17 2016 00:50
@JohnMica have you read Mad Libs link yet?
Stephen James
@sjames1958gm
Jul 17 2016 00:50
@Dueldrawer8 html not js
John Mica
@JohnMica
Jul 17 2016 00:50
yep
Randy Goldsmith
@Dueldrawer8
Jul 17 2016 00:51
@sjames1958gm ah good point
John Mica
@JohnMica
Jul 17 2016 00:51
i assume is to build a quoting selfconstructing
thanks @Chrono79
CamperBot
@camperbot
Jul 17 2016 00:51
johnmica sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1546 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Jul 17 2016 00:51
you have to build a string with the 4 parameters of you function and some more words @JohnMica
Randy Goldsmith
@Dueldrawer8
Jul 17 2016 00:52
@sjames1958gm whenever i x out of the opened window the random quote page turns white?
Stephen James
@sjames1958gm
Jul 17 2016 00:52
@Dueldrawer8 Fixing that gives a different error I added target="_blank" to that a tag, and it looks like it breaks the contents of the tweet.
@Chrono79 I just started on the React project for displaying the highest ranking campers, you are number two on the recent list.
Randy Goldsmith
@Dueldrawer8
Jul 17 2016 00:54
@sjames1958gm yeah it seems thats the solution.. thanks
CamperBot
@camperbot
Jul 17 2016 00:54
dueldrawer8 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1928 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 17 2016 00:54
@Dueldrawer8 Just remove the href from the a tag in the html and I think you are golden
Diego Mayer
@Chrono79
Jul 17 2016 00:54
@sjames1958gm :+1:
Norvin Burrus
@ndburrus
Jul 17 2016 00:55
@sjames1958gm i think the json object isn't grabbing all the data. here is the data i'm seeing: https://fcctop100.herokuapp.com/
Stephen James
@sjames1958gm
Jul 17 2016 00:56
@ndburrus Hmm, interesting. That json is the link they provide in the project,
Randy Goldsmith
@Dueldrawer8
Jul 17 2016 00:56
@sjames1958gm sweetness..tried to make it a little bit responsive as well..not much you can do with a box
Caleb Catt
@cattman42
Jul 17 2016 00:56
How do you markdown again?
Stephen James
@sjames1958gm
Jul 17 2016 00:56
help format
CamperBot
@camperbot
Jul 17 2016 00:56

: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 thecode`.

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

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

Norvin Burrus
@ndburrus
Jul 17 2016 00:56
@JohnMica the exercise is asking for a sentence to be built using the 4 word types given. it may be easiest to begin by making a complete (spacing & punctuation) sentence, using the 4 words. to make sense, the complete sentence will require a few "filler" words. :sparkles:
Rahin Ahmed
@rahin1122
Jul 17 2016 00:57
@sjames1958gm Where do i add item 1 and how can i share the screenshot of codes.
Randy Goldsmith
@Dueldrawer8
Jul 17 2016 00:58
@sjames1958gm one last thing, ive been trying to select the author in the blockquote and want to text-align : right.. which selector is it?
Stephen James
@sjames1958gm
Jul 17 2016 00:58
@rahin1122 item is the value passed in and posting code is right above :point_up:
Caleb Catt
@cattman42
Jul 17 2016 00:58

function isLess(a, b) {
  // Fix this code
  if (a < b) {
    return true;
  } else {
    return false;
  }
}

// Change these values to test
isLess(10, 15);
Norvin Burrus
@ndburrus
Jul 17 2016 00:58
@sjames1958gm what is the link? (if you have it handy...)
Stephen James
@sjames1958gm
Jul 17 2016 00:58
@Dueldrawer8 Not sure I get what you mean
Caleb Catt
@cattman42
Jul 17 2016 00:58
Can anyone help me with this please? I'm trying to eliminate if else with an equality
Stephen James
@sjames1958gm
Jul 17 2016 00:59
@ndburrus which link?
John Mica
@JohnMica
Jul 17 2016 00:59
@ndburrus I solved it - must be really late and cant make sense of it :))
John Mica
@JohnMica
Jul 17 2016 00:59
thanks @ndburrus
CamperBot
@camperbot
Jul 17 2016 00:59
johnmica sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:cookie: 988 | @ndburrus |http://www.freecodecamp.com/ndburrus
Randy Goldsmith
@Dueldrawer8
Jul 17 2016 00:59
@sjames1958gm in the random quote there is two text.. the actual quote and the author who says it. I want to shift the contents of the text of the author to the right
John Mica
@JohnMica
Jul 17 2016 00:59
gitter could be too much improved :)
its like a modern IRC
Norvin Burrus
@ndburrus
Jul 17 2016 00:59
@JohnMica you're welcome! excellent job :palm_tree:
Randy Goldsmith
@Dueldrawer8
Jul 17 2016 01:00
just want to right align the authors name
Rahin Ahmed
@rahin1122
Jul 17 2016 01:00
@sjames1958gm Can you just write the full code for me .
Stephen James
@sjames1958gm
Jul 17 2016 01:00
@Dueldrawer8 If you use float:right it puts it way right
@rahin1122 Which challenge?
Randy Goldsmith
@Dueldrawer8
Jul 17 2016 01:01
@sjames1958gm hm, alright thanks
CamperBot
@camperbot
Jul 17 2016 01:01
dueldrawer8 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: dueldrawer8 already gave sjames1958gm points
Stephen James
@sjames1958gm
Jul 17 2016 01:02

@rahin1122 Is it this challenge, the one about anti pattern?

if (condition) {
   return true;
} else {
  return false;
}

can be replaced by

return condition
Rahin Ahmed
@rahin1122
Jul 17 2016 01:07

@sjames1958gm Can you just have a look at my code and could you provide me a solution for this and I am just a new beginner in javascript ..function nextInLine(arr, item) {
// Your code here
var res = arr.push(1);
var res1 = arr.shift();
return res1;

}
nextInLine([5,6,7,8,9,10,1],1);

Norvin Burrus
@ndburrus
Jul 17 2016 01:10
@sjames1958gm this is interesting. it appears that the links (listed in the exercise & that being used by the alternate source) are a little different. the alternate source link is: https://fcctop100.herokuapp.com for both local & session storage, while the exercise link offered adds (to the link mentioned) the following: /api/fccusers/top/recent (requirement #8) and /alltime (ending) (requirement #9). :sparkles:
Stephen James
@sjames1958gm
Jul 17 2016 01:11
@rahin1122 You should only use arr and item in your function - you are using arr, but you need to push item onto your array not 1
@ndburrus Interesting.
@ndburrus If you click on help score on that link you found it looks a lot more like the json.
Norvin Burrus
@ndburrus
Jul 17 2016 01:12
@rahin1122 this may be helpful: :sparkles:
Stephen James
@sjames1958gm
Jul 17 2016 01:13
@ndburrus I think the project score (x50) is not in the json.
Norvin Burrus
@ndburrus
Jul 17 2016 01:14
@sjames1958gm i think you're right - i'm not sure, but lesson (non x50) points may also not be included...
kevinstonge
@kevinstonge
Jul 17 2016 01:18
function largestOfFour(arr) {
  var largestOfFourArray = [];
  for (i=0;i<arr.length;i++) {
    largestOfFourArray.push(arr[i].sort(function(a,b) { return b - a; })[0]);
  }
  return largestOfFourArray;
}
room for improvement here?
Norvin Burrus
@ndburrus
Jul 17 2016 01:21
@cattman42 is it resolved?
also, there is a "markdown" button to the lower right of the chat text entry area that you may find useful. :)
kevinstonge
@kevinstonge
Jul 17 2016 01:22
and another one :)
function confirmEnding(str, target) {
  return (str.substr(str.length-target.length) === target) ? true : false;
}
Norvin Burrus
@ndburrus
Jul 17 2016 01:23
@rahin1122 is it resolved?
Aiden
@AidenMead
Jul 17 2016 01:32
so I have a really general question about javascript objects and nesting and such, but I think if I can wrap my head around it, it may make more sense, and it revolves around the record collection challenge
Diego Mayer
@Chrono79
Jul 17 2016 01:35
@kevinstonge yes, in this line, just do this: return str.substr(-target.length) === target; true or false is inferred
kevinstonge
@kevinstonge
Jul 17 2016 01:39
@Chrono79 - thanks! I didn't realize that would return true/false all by itself!
CamperBot
@camperbot
Jul 17 2016 01:39
kevinstonge sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1547 | @chrono79 |http://www.freecodecamp.com/chrono79
Joshua Minchew
@jminchew97
Jul 17 2016 01:40
hello can somebody help me with explaining the array method sort()?
I dont understand it and its very complicated to me
I passed the test but I want to know how
kevinstonge
@kevinstonge
Jul 17 2016 01:42
sort without any arguments will just sort from low to high or from a-z ... that's the easy part, I know...
Joshua Minchew
@jminchew97
Jul 17 2016 01:42
the whole a, b
a -b, b - a, thing is very complicated lol
llamatarianism
@llamatarianism
Jul 17 2016 01:43
@jminchew97 it's a function that's used to compare two things
Joshua Minchew
@jminchew97
Jul 17 2016 01:43
I dont understand it
kevinstonge
@kevinstonge
Jul 17 2016 01:43
alternatively you can include a compareFunction with a and b as arguments (a and be represent one item in the array and then the next item). whatever math you do with those items, if it returns a negative number, it will move a in front of b. it will loop through the array multiple times until it's all sorted
llamatarianism
@llamatarianism
Jul 17 2016 01:43
basically it applies that function to 2 items in the array
Diego Mayer
@Chrono79
Jul 17 2016 01:43
@jminchew97 don't know if it helps: http://www.w3schools.com/jsref/jsref_sort.asp
llamatarianism
@llamatarianism
Jul 17 2016 01:43
if the functionr returns a positive number
it'll swap them
Joshua Minchew
@jminchew97
Jul 17 2016 01:43
swap?
llamatarianism
@llamatarianism
Jul 17 2016 01:43
otherwise, they'll remain in the same order relative to each other
kevinstonge
@kevinstonge
Jul 17 2016 01:44
move b in front of a
Joshua Minchew
@jminchew97
Jul 17 2016 01:44
oh
llamatarianism
@llamatarianism
Jul 17 2016 01:44
let's say you have this simple, 2 item array
[2, 1]
and you sort it using the function (a, b) => a - b
Joshua Minchew
@jminchew97
Jul 17 2016 01:44
ohhhhhhhh
llamatarianism
@llamatarianism
Jul 17 2016 01:44
2 - 1 == 1, which is positive
so it swaps them
Joshua Minchew
@jminchew97
Jul 17 2016 01:44
2 - 1 is negative
llamatarianism
@llamatarianism
Jul 17 2016 01:44
whereas if it was [1, 2]
Joshua Minchew
@jminchew97
Jul 17 2016 01:44
I gotcha
llamatarianism
@llamatarianism
Jul 17 2016 01:44
then it'd be 1 - 2 == -1
so it doesn't swap them
Joshua Minchew
@jminchew97
Jul 17 2016 01:45
by the way I don't know why I said negative, lol.
So this applies no matter what?
llamatarianism
@llamatarianism
Jul 17 2016 01:45
:P I decided not to pay attention to it just to be polite
yes, this applies to all sort functions
Joshua Minchew
@jminchew97
Jul 17 2016 01:45
no what what array?
llamatarianism
@llamatarianism
Jul 17 2016 01:45
here's another example:
let foo = ["bazinga", "bingo", "baz", "quux"];
foo.sort((a, b) => a.length - b.length)
^ that will sort the strings in ascending order based on their length
doesn't matter what the array is, what it contains, it just follows those simple rules.
Joshua Minchew
@jminchew97
Jul 17 2016 01:47
I think I've gotten the hang of it.
At least better than I did before.
Rachel
@rslim87
Jul 17 2016 01:50
This message was deleted
functionalStoic
@functionalStoic
Jul 17 2016 01:51
Anyone have insight into the resolving the card counting problem. Just a direction is needed
Joshua Minchew
@jminchew97
Jul 17 2016 01:51
Hey Jason I can try to help you out
Diego Mayer
@Chrono79
Jul 17 2016 01:52
evaluate card value and modify count value in one block, evaluate count value and return in another block @JasonSooter
functionalStoic
@functionalStoic
Jul 17 2016 01:52
Sounds good @jminchew97
Joshua Minchew
@jminchew97
Jul 17 2016 01:53
@JasonSooter actually I think @Chrono79 is more experienced than me! So I'll let him help you.
functionalStoic
@functionalStoic
Jul 17 2016 01:53
@Chrono79 I've got the first part. Is a switch the best method?
labanch
@labanch
Jul 17 2016 01:53
Hello all! Can anyone explain why parseInt is used in the answer for the 'Where do I belong challenge?
function getIndexToIns(arr, num) {
  // Find my place in this sorted array
 arr.sort(function(a, b){
   return a - b;
 });
 for(var i = 0; i<arr.length; i++){
   if(arr[i] >= num){
     return parseInt(i);
   } 
 }
 return arr.length;
}

getIndexToIns([1, 2, 3], 15);
Diego Mayer
@Chrono79
Jul 17 2016 01:53
@JasonSooter switch or if/else, your choice
functionalStoic
@functionalStoic
Jul 17 2016 01:54
Ok. Got that part. Wondering about the sequencing part though. Am checking them as an array?
Diego Mayer
@Chrono79
Jul 17 2016 01:54
@labanch dunno, I think it works without it too
@JasonSooter you evaluate just 1 card at a time in your function, in the tests, it's called several times
labanch
@labanch
Jul 17 2016 01:56
@Chrono79 yeah it does. I thought parseInt only accepted strings so I was a bit confused on why it would pass with that
functionalStoic
@functionalStoic
Jul 17 2016 01:56
Ok. got it. I was thinking about the objectives wrong. Thanks for your help.
kevinstonge
@kevinstonge
Jul 17 2016 02:04
function truncateString(str, num) {
  return ((str.length <= 3) ? str.slice(0,num) + "..." : (num <=3) ? str.slice(0,num) + "..." : (num >= str.length) ? str : str.slice(0,num-3) + "...");
}
this got ugly!!
Umar Yusuf
@umaryusuf
Jul 17 2016 02:05
please I need some help, this method doed nto print myFather.name:
kevinstonge
@kevinstonge
Jul 17 2016 02:05
that works, but could anyone show me their truncate a string code??
Diego Mayer
@Chrono79
Jul 17 2016 02:06
@kevinstonge
function truncateString(str, num) {
  return num<str.length ? str.slice(0, num<=3 ? num : num -3)+"..." : str;
}
kevinstonge
@kevinstonge
Jul 17 2016 02:06
oh I knew mine was shit :) thanks @Chrono79 I'm going to study that
CamperBot
@camperbot
Jul 17 2016 02:06
kevinstonge sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: kevinstonge already gave chrono79 points
kevinstonge
@kevinstonge
Jul 17 2016 02:08
this is blowing my mind ... how do you learn to code like that?
Arcxeius
@clydebaron2000
Jul 17 2016 02:08
i am stuck on the challenge 'Record collection' for JSON objects
can anyone help me?
Diego Mayer
@Chrono79
Jul 17 2016 02:08
refactoring @kevinstonge and trying to keep it dry
Aiden
@AidenMead
Jul 17 2016 02:08
I'm stuck on the same @clydebaron2000
kevinstonge
@kevinstonge
Jul 17 2016 02:09
dry?
Diego Mayer
@Chrono79
Jul 17 2016 02:10
dry: don't repeat yourself, if you look at your code you'll see the same repeated str.slice(0,num) + "..."
kevinstonge
@kevinstonge
Jul 17 2016 02:10
yeah, that's what makes it ugly .. I just can't muster the brain power to merge all of that into one tiny line like you did.
one thing I can apply from your code is putting the conditional statement as an argument. I've never done that. I can use that in the future pretty easily. :octopus:
Diego Mayer
@Chrono79
Jul 17 2016 02:14
:+1:
kevinstonge
@kevinstonge
Jul 17 2016 02:23
@Chrono79 do you generally write your code out in longer form and then go back and refactor?
Diego Mayer
@Chrono79
Jul 17 2016 02:24
sometimes, yes, it's better to do it longer first and then trying to shrink it
Evan
@CodeDraken
Jul 17 2016 02:25
You should make a youtube series on JS :smile: @Chrono79
Islam Ibakaev
@dagman
Jul 17 2016 02:34
hey guys do u like this effect? http://codepen.io/dagman/full/qNpJgN/
Aiden
@AidenMead
Jul 17 2016 02:34
So I'm stuck on adding an array to an object, I can't figure out the correct syntax to do so.
llamatarianism
@llamatarianism
Jul 17 2016 02:42
@AidenMead adding how?
you really have to be specific, because in javascript, stuff like this is not an error:
[1, 2, 3, 4, 5] + {a: 1, b: 2}
// -> '1,2,3,4,5[object Object]'
John Freeborn
@jfx1026
Jul 17 2016 02:43
is there a way to push things to the output/codeMirror for testing? For example: can I do a console.log and check a variable's value?
Aiden
@AidenMead
Jul 17 2016 02:44
In record collection, the instructions read " If prop is "tracks" but the album doesn't have a "tracks" property, create an empty array before adding the new value to the album's corresponding property."
llamatarianism
@llamatarianism
Jul 17 2016 02:44
just assign to its tracks property
let object = {a: 1, b: 2, c: 3};
if (!object.hasOwnProperty("tracks")) {
  object.tracks = [];
}
object.tracks.push(5);
// -> {a: 1, b: 2, c: 3, tracks: [5]}
the important line there is object.tracks = []
John Freeborn
@jfx1026
Jul 17 2016 02:45
I feel your pain @AidenMead - this one is hurting my brain too
Aiden
@AidenMead
Jul 17 2016 02:46
if (prop === "tracks" && value === "") {
    collection[id].tracks = [];
does that look right?
John Freeborn
@jfx1026
Jul 17 2016 02:48

This isn't showing anything in the code window.

var testProp = collection.hasOwnProperty(prop);
  console.log ("testProp = " + testProp);

Why is that?

llamatarianism
@llamatarianism
Jul 17 2016 02:48
well syntactically it looks fine, but
if value is empty, you're supposed to delete the property
@jfx1026 that little window isn't console output
it's what your function returns
Aiden
@AidenMead
Jul 17 2016 02:49
right, which I don't particularly understand, these instructions are rough, haha.
John Freeborn
@jfx1026
Jul 17 2016 02:50
ok, so - how do I test a variable to see if it's actually doing what I think it should be?
Aiden
@AidenMead
Jul 17 2016 02:51
ohhh, do I need to nest if/else statements to get it to effectively do both or none?
is that what I've been missing? hmmm
Aiden
@AidenMead
Jul 17 2016 02:58
Nope, that's not working
It's just that one that I can't get at all
John Freeborn
@jfx1026
Jul 17 2016 03:03
@AidenMead - this is my mess, maybe we can help each other
function updateRecords(id, prop, value) {

  var testProp = collection.hasOwnProperty(prop);
  //console.log ("testProp = " + testProp);

  if (testProp===false) {
    collection[id][prop] = value;
    if (prop === "tracks" && value === "") {
      //collection[id].tracks = [];
      var object = {a: 1, b: 2, c: 3};
      //set tracks
      if (!object.hasOwnProperty("tracks")) {
        object.tracks = [];
      }
      object.tracks.push(5);
    }
  } else {
    return "WTF!";
  }

  return collection;
}
It's not working, so I don't know
Aiden
@AidenMead
Jul 17 2016 03:04
haha, I like your second to last return
John Freeborn
@jfx1026
Jul 17 2016 03:06
this nested If is not doing anything for me
Megan Charles
@teethnclaws
Jul 17 2016 03:06
I have a question about the increment lesson on Javascript. I'm using the ++ and it just doesn't want to take it
Aiden
@AidenMead
Jul 17 2016 03:06
I used stuff like :
if (value !== "" && prop !== "tracks") {
    collection[id][prop] = value;
And it seems to be working well so far, I have all but one of the test inputs testing out correctly, it's just the one "After updateRecords(5439, "tracks", "Take a Chance on Me"), tracks should have "Take a Chance on Me" as the last element." that's still returning negative.
John Freeborn
@jfx1026
Jul 17 2016 03:07
I like the use of the && here, super logical - I just can't seem to make the mental leap to do something with the code after that
that one is failing for me also
Aiden
@AidenMead
Jul 17 2016 03:08
So I was in the chat earlier and a couple of people led me to a link where there was a discussion about the instructions and how the old wording worked better, so I approached it with that.
Megan Charles
@teethnclaws
Jul 17 2016 03:09
Nevermind - though the lesson example is a little misleading
Aiden
@AidenMead
Jul 17 2016 03:09
// Write a function which takes:
//  an id, a property (prop), and a value.
function updateRecords(id, prop, value) {
// If value is non-blank (value !== "") 
// and prop is not "tracks" 
// then update or set the value for the prop.
    // Your code here

// If the prop is "tracks" and value is non-blank,
// push the value onto the end of the tracks array.
    // Your code here

// If value is blank, 
// delete that prop.
    // Your code here

// Always return the entire collection object.
  return collection;
}
John Freeborn
@jfx1026
Jul 17 2016 03:09
@AidenMead I know that you can't push with a JSON object, you have to use dot/bracket notation only
thanks for the look on that
Aiden
@AidenMead
Jul 17 2016 03:10
Ohhh, hmmmm, maybe that's the issue I'm running into
I did use push
John Freeborn
@jfx1026
Jul 17 2016 03:12
you can only push an Array - a coder friend tells me that JS doesn't use true Arrays, but you can create them.
Aiden
@AidenMead
Jul 17 2016 03:12
So I tested that, took out my .push() line, and set it equal to the new value, and it actually caused a couple of the tests to come back negative.
John Freeborn
@jfx1026
Jul 17 2016 03:13
SORRY! Undo, quick.
Aiden
@AidenMead
Jul 17 2016 03:13
haha, no worries
I've been messing with it so much that I took my original solution (that gave me the most positives) and posted it in notes for safe keeping so I can play around.
Here's what I've got:
function updateRecords(id, prop, value) {
   if (value !== "" && prop !== "tracks") {
    collection[id][prop] = value;
  } else if (prop === "tracks" && value !== "") {
    collection[id].tracks.push(value);
  } else if (value === "") {
    delete collection[id][prop];
  }
  return collection;
}
John Freeborn
@jfx1026
Jul 17 2016 03:17
thanks, still plugging away
Aiden
@AidenMead
Jul 17 2016 03:18
however, when I run a test involving the .push() condition, i am actually getting an error
kevinstonge
@kevinstonge
Jul 17 2016 03:19

is it bad that it took me a half hour to figure this out?

function chunkArrayInGroups(arr, size) {
var j = Math.ceil(arr.length/size - 1);
  for(i=0;i<=j;i++) {
    arr.splice(i,size,arr.slice(i,i+size));
  }
  return arr;
}

is there an easier way that I overlooked?

Ogundele Olumide
@Lumexralph
Jul 17 2016 03:20
hi guys
am working on local weather app presently, I got my coordinates using geolcation object on JSFiddle but when I did same thing on codepen it didn't work, what might be the problem?
Kevin
@KevinBruland
Jul 17 2016 03:22
@Lumexralph using chrome?
@Lumexralph and do you have a link? It could be a bunch of things but its probably related to https vs http
Ogundele Olumide
@Lumexralph
Jul 17 2016 03:27
yes, am using chrome but working on both JSFiddle and Codepen, should there be any issue?@Benalron
Bryan
@jbhand75-coder
Jul 17 2016 03:51
If you are using Chrome then it probably has to do with HTTPS. Here is a link to the doc that explains why it will not work. https://developers.google.com/web/fundamentals/native-hardware/user-location/obtain-location?hl=en
@Lumexralph
Sorry. That was intended for
Aiden
@AidenMead
Jul 17 2016 03:53
@jfx1026 i found another way to get to the same spot that I'm in, with the same test input coming back negative. You having any luck?
James S.
@Mrblue27
Jul 17 2016 03:56

function testLogicalAnd(val) {
  // Only change code below this line

  if (val <= 50) {
    if (val >= 25 ) {
      return "Yes";
    }
  }

  // Only change code above this line
  return "No";
}

// Change this value to test
testLogicalAnd(24);
Where do I put the && operator
kevinstonge
@kevinstonge
Jul 17 2016 03:57
if (val <= 50 && val >=25) { ...
you are combining both if statements into one
John Freeborn
@jfx1026
Jul 17 2016 03:58
@AidenMead - rebuilt everything again and I'm in the same place - I think I'm getting closer though
I'm getting this error though now : collection[id][prop] = value;
James S.
@Mrblue27
Jul 17 2016 03:59
@kevinstonge Thanks I did that but was missing the second Val. Thanks for the help
CamperBot
@camperbot
Jul 17 2016 03:59
mrblue27 sends brownie points to @kevinstonge :sparkles: :thumbsup: :sparkles:
:cookie: 261 | @kevinstonge |http://www.freecodecamp.com/kevinstonge
John Freeborn
@jfx1026
Jul 17 2016 03:59
TypeError: collection[id][prop] is undefined
Aiden
@AidenMead
Jul 17 2016 04:01
@jfx1026 can you post your code?
Tommy Izen
@TommyIzen
Jul 17 2016 04:01
can anyone tell me why this code doesn't work? Trying to solve seek and destroy
Aiden
@AidenMead
Jul 17 2016 04:01
I finally got it, had to re-write a line of code and post in in twice to work with my if/else statements without one contradicting the other, it seems
John Freeborn
@jfx1026
Jul 17 2016 04:03
the error was caused my throwing in the failing test request - when I use any other the code works (without passing the one test)
Aiden
@AidenMead
Jul 17 2016 04:05
That same thing was happening to me, I was stuck with the silly track "Take a Chance On Me" not returning positive.
But I would only get an error when I actually put in those test variables, otherwise it came back fine.
John Freeborn
@jfx1026
Jul 17 2016 04:06
I've got the reverse - the one with "Free" is failing on me now
the 5th test
Malick Arsalan
@MalickArsalan
Jul 17 2016 04:07

in "Escape Sequences in Strings" Assignment I am codding this but it is giving error

var myStr = "FirstLine \n \ SecondLine \ \r ThirdLine"; // Change this line

John Freeborn
@jfx1026
Jul 17 2016 04:07
code here
function updateRecords(id, prop, value) {

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

  return collection;
}

// Alter values below to test your code
updateRecords(2468, "tracks", "Free");
Renata Cavalheiro da Silva
@rezzycavalheiro
Jul 17 2016 04:07
hi guys! I'm stuck at the mad libs problem... I have absolutely no diea what to do or even where to start
Malick Arsalan
@MalickArsalan
Jul 17 2016 04:08
can any body help
Aiden
@AidenMead
Jul 17 2016 04:10
I realized that we were both pursuing the right track, but seperately, so .hasOwnProperty is a factor
John Freeborn
@jfx1026
Jul 17 2016 04:10
@AidenMead if I comment out 'collection[id].tracks = []; - the failed test switches from 5 to 2
Malick Arsalan
@MalickArsalan
Jul 17 2016 04:12
blob
what is wrong in this codding
Jamie
@TheJamieCrawford
Jul 17 2016 04:13

Hey, I'm doing the Global vs. Local scope functions. I'm not sure why my code isn't working:

// Setup
var outerWear = "T-Shirt";

function myOutfit() {
// Only change code below this line

var myOutfit = "sweater";

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

myOutfit();

Aiden
@AidenMead
Jul 17 2016 04:13
Yeah, that's where i realized the nested if/else statements came in, but also the .hasOwnProperty
Jamie
@TheJamieCrawford
Jul 17 2016 04:13

Challenge is

Do not change the value of the global outerWear
myOutfit should return "sweater"
Do not change the return statement

Aiden
@AidenMead
Jul 17 2016 04:13
if (value !== "") {

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

       } else if(!collection[id].hasOwnProperty("tracks")) {
         collection[id].tracks = [];
         collection[id][prop].push(value);
John Freeborn
@jfx1026
Jul 17 2016 04:14
@MalickArsalan - check the markdown help for posting your code
Faisal Zulfiqar
@faisal1337
Jul 17 2016 04:15
In 'Seek and Destroy' the first step is to store the arguments in an array? Am I right?
Malick Arsalan
@MalickArsalan
Jul 17 2016 04:16
@jfx1026 i dont get it
Aiden
@AidenMead
Jul 17 2016 04:16
@TheJamieCrawford it appears that you are trying to change the function name.. "myOutfit" is the function, whereas the variable "outerWear" is the variable that "myOutfit" it looking to change
Jamie
@TheJamieCrawford
Jul 17 2016 04:17
@AidenMead I don't understand >.<
John Freeborn
@jfx1026
Jul 17 2016 04:17
if you type three of these , then paste your code and three more, then your code will show up in black, like everyone else here - no screen shot needed
Malick Arsalan
@MalickArsalan
Jul 17 2016 04:17
ok
John Freeborn
@jfx1026
Jul 17 2016 04:17
the key is the same as the ~, without shift
martinronquillo
@martinronquillo
Jul 17 2016 04:18

```
// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

function checkObj(checkProp) {
// Your Code Here
myObj.hasOwnProperty("gift");
return "pony";

}

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

Malick Arsalan
@MalickArsalan
Jul 17 2016 04:19
var myStr = "FirstLine\n\\SecondLine\\\ThirdLine"; // Change this line
Jamie
@TheJamieCrawford
Jul 17 2016 04:19
@AidenMead I figured it out :dancer:
martinronquillo
@martinronquillo
Jul 17 2016 04:19
Testing Objects for Properties
Jamie
@TheJamieCrawford
Jul 17 2016 04:19
thanks @AidenMead
CamperBot
@camperbot
Jul 17 2016 04:19
thejamiecrawford sends brownie points to @aidenmead :sparkles: :thumbsup: :sparkles:
:cookie: 214 | @aidenmead |http://www.freecodecamp.com/aidenmead
Malick Arsalan
@MalickArsalan
Jul 17 2016 04:19
Thanks :) @jfx1026
CamperBot
@camperbot
Jul 17 2016 04:19
malickarsalan sends brownie points to @jfx1026 :sparkles: :thumbsup: :sparkles:
:cookie: 222 | @jfx1026 |http://www.freecodecamp.com/jfx1026
Malick Arsalan
@MalickArsalan
Jul 17 2016 04:20
what is wrong in this code
var myStr = "FirstLine\n\\SecondLine\\\ThirdLine"; // Change this line
Aiden
@AidenMead
Jul 17 2016 04:21
@TheJamieCrawford So look at each name, they are separate variables. So on the outside, you wear a t-shirt. The t-shirt is part of the outfit. One a very simple level, we need to do something to change the t-shirt, or "outerWear" because it's too cold. So we do something (a function labelled the general term"myOutfit") to change the outerWear. The way you have it set up, you're taking the function "myOutfit" and trying to change it, where you should be trying to change "outerWear".
Malick Arsalan
@MalickArsalan
Jul 17 2016 04:21
in Escape Sequences in Strings task
Aiden
@AidenMead
Jul 17 2016 04:21
Sorry if that makes it more confusing, haha. Trying to explain without re-writing the code ;)
@TheJamieCrawford Just saw you figured it out up a bit :+1:
NixonRichard
@NixonRichard
Jul 17 2016 04:23
This message was deleted
hi guyz
my weather app so far
can someone tell me why it doesnt return the weather ?
John Freeborn
@jfx1026
Jul 17 2016 04:28
@MalickArsalan - I'm looking back at mine, one sec
Malick Arsalan
@MalickArsalan
Jul 17 2016 04:28
Sure @jfx1026
John Freeborn
@jfx1026
Jul 17 2016 04:31
@MalickArsalan - mine is failing the same first test as yours var myStr = "FirstLine\n \\\SecondLine\\\ \rThirdLine";
I must have completed this one on my machine at work and it's not saved here
Malick Arsalan
@MalickArsalan
Jul 17 2016 04:32
ok Thanks for your Effort :)
:)
@jfx1026 - Thansk Alot
John Freeborn
@jfx1026
Jul 17 2016 04:36
@AidenMead - I finally got it, it's not pretty though
thanks @AidenMead for your tips
CamperBot
@camperbot
Jul 17 2016 04:39
jfx1026 sends brownie points to @aidenmead :sparkles: :thumbsup: :sparkles:
:cookie: 216 | @aidenmead |http://www.freecodecamp.com/aidenmead
Jod
@jod29
Jul 17 2016 04:44
Need help with falsy bouncer. here's my code. i only get 1/4 of the tests.
function falsy(value) {
   if (value === false || value === null || value === 0 || value === undefined || value === "" || value === isNaN) {
     return value;
   }
}
function bouncer(arr) {
  // Don't show a false ID to this bouncer.
   return arr.filter(falsy);
}

bouncer([7, "ate", "", false, 9]);
kevinstonge
@kevinstonge
Jul 17 2016 04:46
@jod29 I'm stuck on the same one. One thing I'm finding is that isNaN literally means "is not a number" so it will filter things like "ate" because "ate" is not a number.
James S.
@Mrblue27
Jul 17 2016 04:46
function testLogicalOr(val) {
  // Only change code below this line

  if (val > 10 || val < 20) {
    return "Outside";
  }

  {
  return "Inside";
}
  // Only change code above this line
  return "Inside";
}

// Change this value to test
testLogicalOr(10);
How do I get the inside to compute. I am only getting the Outside
Jod
@jod29
Jul 17 2016 04:46
@kevinstonge been stuck for 3 days now :)
kevinstonge
@kevinstonge
Jul 17 2016 04:46
my code only gets the first two:
function bouncer(arr) {
  return arr.filter(function(val){return (val===false||val===""||val===null||val===0||val===undefined) ? false : true; });
}
Jod
@jod29
Jul 17 2016 04:48
i only get the third one
Malick Arsalan
@MalickArsalan
Jul 17 2016 04:49
@jfx1026 - I have done but not sure what was my mistake in previous which was var myStr = "FirstLine\n\\SecondLine\\\ThirdLine"; // Change this line and var myStr="FirstLine\n\\SecondLine\\\rThirdLine";
and now*
DJ
@qualitymanifest
Jul 17 2016 04:51
@jod29 rather than specifying every kind of falsy value to filter out, try only returning truthy values. check it: https://repl.it/Ccmi
kevinstonge
@kevinstonge
Jul 17 2016 04:53
@qualitymanifest thank you!!!
CamperBot
@camperbot
Jul 17 2016 04:53
kevinstonge sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star2: 1281 | @qualitymanifest |http://www.freecodecamp.com/qualitymanifest
Jod
@jod29
Jul 17 2016 04:53
tnx @qualitymanifest
DJ
@qualitymanifest
Jul 17 2016 04:54
np
kevinstonge
@kevinstonge
Jul 17 2016 04:54
here's my code for that one now!
function bouncer(arr) {
  return arr.filter(function(val){return (val); });
}
I hate how simple it was :)
Tommy Izen
@TommyIzen
Jul 17 2016 04:54
@TommyIzen
can anyone tell me why this code doesn't work? Trying to solve seek and destroy
https://repl.it/CcmR
DJ
@qualitymanifest
Jul 17 2016 04:55
@kevinstonge you could also return !!!!!!!!!!!!!!!!!!!!val, so long as it was an even amount of exclamation points, haha.
kevinstonge
@kevinstonge
Jul 17 2016 04:55
@qualitymanifest I'm really surprised that works for the number 0.
I think that's what stopped me from even trying it that way
Jod
@jod29
Jul 17 2016 04:58
@kevinstonge @qualitymanifest (head spinning) haha! that was clever!
DJ
@qualitymanifest
Jul 17 2016 04:58
@TommyIzen you're going to need to use the arguments object again on this one, and you don't want to convert it to a string
James S.
@Mrblue27
Jul 17 2016 05:09
function testLogicalOr(val) {
  // Only change code below this line

  if (val > 10 || val < 20) {
    return "Outside";

  } 











  // Only change code above this line
  return "Inside";
}

// Change this value to test
testLogicalOr(25);
How do I return the "Inside"
```
John Alcher
@alchermd
Jul 17 2016 05:15
This message was deleted
@Mrblue27 My bad, are you writing a function that checks if val is > 10 AND <20?
DJ
@qualitymanifest
Jul 17 2016 05:19
@Mrblue27 greater than/less than's are reversed
John Alcher
@alchermd
Jul 17 2016 05:20
@Mrblue27 If so, you need to change || (OR operator) into && (AND operator)
DJ
@qualitymanifest
Jul 17 2016 05:20
@alchermd that's not the case, the name of the function is testLogicalOr
John Alcher
@alchermd
Jul 17 2016 05:23
@qualitymanifest Whoops. Have you solved it yet? What was the expected result for testLogicalOr(25) ?
DJ
@qualitymanifest
Jul 17 2016 05:24
@alchermd No worries, totally understandable why you would want to check. Anyway, that should return Outside. this is the challenge https://www.freecodecamp.com/challenges/comparisons-with-the-logical-or-operator
John Alcher
@alchermd
Jul 17 2016 05:25
@qualitymanifest Gotcha. It's quite confusing for me without understanding the context of the problem haha
DJ
@qualitymanifest
Jul 17 2016 05:26
yeah for sure. i generally just ask people to link to the challenge so i can see what's expected
John Alcher
@alchermd
Jul 17 2016 05:26
@qualitymanifest In any case, I'm looking for some help too! Are you by any chance knowledgeable in RegExp?
DJ
@qualitymanifest
Jul 17 2016 05:26
@alchermd somewhat. what's up?
Rahul Nayak
@pragyes31
Jul 17 2016 05:27
hi guys, can anybody point out why I am not able to get weather info after I select city from the list box. here is my codepen : http://codepen.io/pragyesh31/full/PzERaV/
Norvin Burrus
@ndburrus
Jul 17 2016 05:30
This message was deleted
John Alcher
@alchermd
Jul 17 2016 05:31

@qualitymanifest Here's what's up:
I'm currently on the Validate Us Numbers challenge
https://www.freecodecamp.com/challenges/validate-us-telephone-numbers

I'm aware that there's a bunch of RegExp challenges that I already passed, though I used some obscure long If-Else chains that checks for each value of the string. I guess this is the perfect challenge for me to really learn RegExp.

Would you mind guiding me step by step on what should I do in this challenge?

DJ
@qualitymanifest
Jul 17 2016 05:32
@alchermd so my solution to this ended up being a one-liner, and i wrote some pseudocode to help explain what's going on. i'll give you that pseudocode... one sec

here:

Allow a 1 and a space, then area code with BOTH parens or NO parens, then allow a space/dash, three more numbers, allow another space/dash, then the last four numbers. Nothing before or after

(parens === parenthesis)
kirbyedy
@kirbyedy
Jul 17 2016 05:34
ty @qualitymanifest
CamperBot
@camperbot
Jul 17 2016 05:34
kirbyedy sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star2: 1282 | @qualitymanifest |http://www.freecodecamp.com/qualitymanifest
DJ
@qualitymanifest
Jul 17 2016 05:35
i agree, this is a very good challenge to learn regex, and is worth taking the time to really figure out. if you're not familiar with using regex101.com for testing, check that out. if you haven't been through regexone.com 's tutorial, check that out. even after that tutorial you will probably still need to refer to MDN docs on regex quite a bit, to solve that one efficiently @alchermd
@kirbyedy did i do something for you or are you just passing out brownies to be nice?? also, dang that's quite a streak you've got!
Vercaelus
@Vercaelus
Jul 17 2016 05:38
Would anyone care to spare a moment to help me understand APIs? I literally can't even.
John Alcher
@alchermd
Jul 17 2016 05:38
@qualitymanifest Thank you for the help mate! Just another one: let's say I successfully built my RegExp, what JS function do I pass it on to check if it matches string ?
CamperBot
@camperbot
Jul 17 2016 05:38
alchermd sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star2: 1283 | @qualitymanifest |http://www.freecodecamp.com/qualitymanifest
DJ
@qualitymanifest
Jul 17 2016 05:39
@alchermd np. regex goes here.test(str)
John Alcher
@alchermd
Jul 17 2016 05:42
@qualitymanifest Gotcha. I'll get back to you if I have further questions! :D
kevinstonge
@kevinstonge
Jul 17 2016 05:44
I'd like some tips on "Seek and Destroy" - the following code works, but it can't possibly be the best way to do this:
var globalArguments = [];
function destroyer(arr) {
  globalArguments[0] = arguments[1];
  globalArguments[1] = arguments[2];
  globalArguments[2] = arguments[3];
  return arr.filter(function destroyFilter(val){return (val===globalArguments[0]||val===globalArguments[1]||(globalArguments[2]&&val===globalArguments[2])) ? false : true;});
}
I know a for loops seems to make sense, but it got mad at me for defining a function inside the for loop :\ ... the filter function.
Alex T.
@lx-t
Jul 17 2016 05:46
@kevinstonge I guess you can use in method of Array to check if val is in globalArguments to shorten your code.
Vercaelus
@Vercaelus
Jul 17 2016 05:47
@kevinstonge the compiler complains about making a function inside of a loop, but it will still work. Its how I did it. I'd show you my code for comparison, but it seems to be missing
Faisal Zulfiqar
@faisal1337
Jul 17 2016 05:48
Hey! I have coded this solution for 'Seek and Destroy'. What do you think? Is it a good approach or not? Please tell.
function getIndexToIns(arr, num) {
  // Find my place in this sorted array.
  var array = [];
  array = arguments[0];
  array.push(num);

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

  return array.indexOf(num);
}

getIndexToIns([40, 60], 50);
Alex T.
@lx-t
Jul 17 2016 05:48
@kevinstonge And there's no need in naming the callback function. You're not going to use it in your code anywhere except that filter function, right?
DJ
@qualitymanifest
Jul 17 2016 05:48
@kevinstonge are you familiar with indexOf?
kirbyedy
@kirbyedy
Jul 17 2016 05:49
@qualitymanifest its for the hint about that telephone number challenge
DJ
@qualitymanifest
Jul 17 2016 05:49
@faisal1337 it's fine but it's not good practice to name a variable "array". also you don't even need to make that variable... just use arr which is passed into the function
Faisal Zulfiqar
@faisal1337
Jul 17 2016 05:50
Thanks. Lemme change it.
:thumbsup:
Alex T.
@lx-t
Jul 17 2016 05:51
@qualitymanifest Is it a good practice when you change a function arguments inside that function?
Faisal Zulfiqar
@faisal1337
Jul 17 2016 05:51
And the solution was for 'Where do I belong'. Mistake :D
Alex T.
@lx-t
Jul 17 2016 05:51
@faisal1337 Interesting idea of finding a place for a num.
Faisal Zulfiqar
@faisal1337
Jul 17 2016 05:52
Ahan.
DJ
@qualitymanifest
Jul 17 2016 05:53
@lx-t in this case, i don't see why not. you're changing it for one specific purpose, and you don't need it after that. and i was only recommending against calling a variable "array" because its a reserved word.
kevinstonge
@kevinstonge
Jul 17 2016 05:53
function destroyer(arr) {
  globalArguments = arguments;
  return arr.filter(function(val){return (val===globalArguments[1]||val===globalArguments[2]||val===globalArguments[3]) ? false : true;});
}
this looks a bit better ... thanks @lx-t ... but could one of you share your code for Seek and Destroy? I'm not really confident that this is the best way.
CamperBot
@camperbot
Jul 17 2016 05:53
kevinstonge sends brownie points to @lx-t :sparkles: :thumbsup: :sparkles:
:cookie: 439 | @lx-t |http://www.freecodecamp.com/lx-t
DJ
@qualitymanifest
Jul 17 2016 05:54
correction, not a reserved word, but close enough.
Nelius Knight
@NeliusKnight
Jul 17 2016 05:55
Can someone help me on the golf app waypoint
DJ
@qualitymanifest
Jul 17 2016 05:55
@kevinstonge are you familiar with indexOf?
kevinstonge
@kevinstonge
Jul 17 2016 05:55
@qualitymanifest yes but I'm not sure how to use it in this situation
Dan Ichim
@danichim
Jul 17 2016 05:55
str.indexOf(searchValue[, fromIndex])
Alex T.
@lx-t
Jul 17 2016 05:57
@qualitymanifest I didn't know that JS can change arguments and it costed me some time to debug my script. Now, I'm avoiding changing arguments inside a function. :)
DJ
@qualitymanifest
Jul 17 2016 05:57
@kevinstonge make a real array of the additional arguments (the ones that come after arr). then run a filter on arr, removing the pieces of arr that are present (indexOf !== -1) in your newly made arguments array
Faisal Zulfiqar
@faisal1337
Jul 17 2016 05:58
function getIndexToIns(arr, num) {
  // Find my place in this sorted array.
  arr.push(num);
  arr.sort(function sortArr(a, b)
  {
      return a - b;
  });

  return arrindexOf(num);
}
Changed it.
function getIndexToIns(arr, num) {
  // Find my place in this sorted array.
  arr.push(num);
  arr.sort(function sortArr(a, b)
  {
      return a - b;
  });

  return arr.indexOf(num);
}
Alex T.
@lx-t
Jul 17 2016 05:58
@qualitymanifest I mean, I was surprised that a function's arguments do not belong to local namespace of a function like in some other languages.
Jod
@jod29
Jul 17 2016 05:59
thanks @faisal1337
CamperBot
@camperbot
Jul 17 2016 05:59
jod29 sends brownie points to @faisal1337 :sparkles: :thumbsup: :sparkles:
:cookie: 271 | @faisal1337 |http://www.freecodecamp.com/faisal1337
DJ
@qualitymanifest
Jul 17 2016 05:59
@lx-t hm, i see what you're saying, i haven't had problems with that yet... let me test that out real quick
Cal-culator
@Cal-culator
Jul 17 2016 05:59
Hey guys! How do i run two separate loops at the same time?
Nelius Knight
@NeliusKnight
Jul 17 2016 06:00

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
}

// Change these values to test
golfScore(4, 1);
how is this wrong?
kevinstonge
@kevinstonge
Jul 17 2016 06:00
@qualitymanifest isn't that basically what my code does? I just use an equality to check each argument instead of checking if the index is not -1.
Cal-culator
@Cal-culator
Jul 17 2016 06:01
@NeliusKnight try checking the return spellings. FCC wants it to be exact
if its still wrong, let me know
Nelius Knight
@NeliusKnight
Jul 17 2016 06:01
Ive been on this waypoint for 3 days
and THAT was the problem?!
DJ
@qualitymanifest
Jul 17 2016 06:01
@kevinstonge yes, but using an array of the other args and indexOf is less verbose, and, much more importantly, keeps you from having to hardcode in the number of extra arguments to filter
Cal-culator
@Cal-culator
Jul 17 2016 06:01
@NeliusKnight did it work?
Nelius Knight
@NeliusKnight
Jul 17 2016 06:02
it sure did @Cal-culator thank you
CamperBot
@camperbot
Jul 17 2016 06:02
neliusknight sends brownie points to @cal-culator :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for cal-culator
kevinstonge
@kevinstonge
Jul 17 2016 06:02
@qualitymanifest I'm not understanding - can you show me your code for that challenge?
Nelius Knight
@NeliusKnight
Jul 17 2016 06:02
geez...
3 days just to find out it was because of capitalization
Cal-culator
@Cal-culator
Jul 17 2016 06:02
@NeliusKnight No worries. I always check the spelling from then on after that.
DJ
@qualitymanifest
Jul 17 2016 06:02
@lx-t alright, you have a good point, thanks
CamperBot
@camperbot
Jul 17 2016 06:02
qualitymanifest sends brownie points to @lx-t :sparkles: :thumbsup: :sparkles:
:cookie: 440 | @lx-t |http://www.freecodecamp.com/lx-t
Faisal Zulfiqar
@faisal1337
Jul 17 2016 06:03
After I finish the Front End Section of FCC. What will be my level in JS. Beginner or Intermediate?
DJ
@qualitymanifest
Jul 17 2016 06:04
This message was deleted
kevinstonge
@kevinstonge
Jul 17 2016 06:04
yeah, I don't understand the e1 => part
why did you delete it? :)
Nathaniel Nasarow
@Torgian
Jul 17 2016 06:06
hey all
DJ
@qualitymanifest
Jul 17 2016 06:06
i don't like to leave solutions up... someone else might come by who is working on that and see the spoiler. anyway => is basically shorthand for function() {}
Nathaniel Nasarow
@Torgian
Jul 17 2016 06:06
need some help with the roman numeral converter
DJ
@qualitymanifest
Jul 17 2016 06:07
@kevinstonge so, make an array of the additional arguments. filter arr to remove pieces that are present in the additional elements (piece of arr.indexOf(additional element array) === -1
err !== -1
Nathaniel Nasarow
@Torgian
Jul 17 2016 06:08
Any suggestion on how to start? I'm thinking of a named array, with the character codes for each roman numeral from 1 - 9, 10, 50, 100, 500, and 1000
DJ
@qualitymanifest
Jul 17 2016 06:12
@Torgian basically yeah. make two arrays containing equivalent numbers and roman numerals at the same index. or one two-dimensional array. don't forget about 4, 9, 40, 90, etc, as those ones go by a slightly different pattern than the rest
Cal-culator
@Cal-culator
Jul 17 2016 06:13
TypeError: str.split("").toLowerCase is not a function. (In 'str.split("").toLowerCase()', 'str.split("").toLowerCase' is undefined) How do i fix this?
Nathaniel Nasarow
@Torgian
Jul 17 2016 06:13
Well, this is what i have, using char codes for the available roman numbers (HTML char codes)
DJ
@qualitymanifest
Jul 17 2016 06:13
@Torgian oh, no. no need for HTML char codes
Nathaniel Nasarow
@Torgian
Jul 17 2016 06:13
might have to change that to just regular letters
ah ok
Was thinking of using the numbers as "keys" so to speak
DJ
@qualitymanifest
Jul 17 2016 06:14
@Cal-culator lowercase before splitting
@Cal-culator can't lowercase an array
Nathaniel Nasarow
@Torgian
Jul 17 2016 06:14
or ids
kevinstonge
@kevinstonge
Jul 17 2016 06:15
@qualitymanifest that => is somehow allowing you to access arguments from destroyer inside of your filter function ... but I think I understand how it works outside of that => thing! Thank you!
CamperBot
@camperbot
Jul 17 2016 06:15
kevinstonge sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star2: 1284 | @qualitymanifest |http://www.freecodecamp.com/qualitymanifest
kevinstonge
@kevinstonge
Jul 17 2016 06:15
Here is how I had to modify it to make it work:
function destroyer(arr) { 
  globalArguments = arguments;
  return arr.filter(function(val){return Array.from(globalArguments).indexOf(val) === -1;});
}
Cal-culator
@Cal-culator
Jul 17 2016 06:16
@qualitymanifest ah ok. thanks
CamperBot
@camperbot
Jul 17 2016 06:16
cal-culator sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star2: 1285 | @qualitymanifest |http://www.freecodecamp.com/qualitymanifest
DJ
@qualitymanifest
Jul 17 2016 06:17
@kevinstonge :+1: that is pretty much how i would do it in es5. only nitpicky things: it would be good to assign globalArguments with var in front of it, and if you made it an Array at the same time as you assigned it, it wouldn't have to make a new Array on each iteration of the filter, so would be a little more efficient
kevinstonge
@kevinstonge
Jul 17 2016 06:18

var globalArguments = arguments;

doesn't that already make it an array since arguments is an array?

DJ
@qualitymanifest
Jul 17 2016 06:19
@Torgian i guess you could use the numbers as keys for the actual roman values 1: "I", 4: "IV" etc. but you're trying to make an object by wrapping it in [] when you should be wrapping it in {}. also, i think this one is just easier with arrays rather than objects
Cal-culator
@Cal-culator
Jul 17 2016 06:19
I want to replace all special characters with " ". Do I have to type all special characters manually or is there a term?
DJ
@qualitymanifest
Jul 17 2016 06:19
@kevinstonge var globalArguments = Array.from(arguments)
kevinstonge
@kevinstonge
Jul 17 2016 06:19
oh I see
Markus Kiili
@Masd925
Jul 17 2016 06:20
@kevinstonge arguments is an array-like object (has numeric properties and .length property), but no array methods.
DJ
@qualitymanifest
Jul 17 2016 06:20
@kevinstonge then change it slightly inside the filter. it's a little more efficient, but nitpicky, you got the gist of it well
kevinstonge
@kevinstonge
Jul 17 2016 06:20
got it, thanks again :)
chaitanya ashtekar
@chaitanyaashtekar
Jul 17 2016 06:21
thanks @Blauelf
CamperBot
@camperbot
Jul 17 2016 06:21
chaitanyaashtekar sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 2192 | @blauelf |http://www.freecodecamp.com/blauelf
Markus Kiili
@Masd925
Jul 17 2016 06:25
@faisal1337 All functions have .call(), .bind(), and .apply() methods that change how a function is called. The .call() method can determine the calling object (thisArg, the value of this inside the method) and also arguments passed into the method. If call() is used on an array method, the thisArg can be an array like object (needs to have numeric properties "0", "1" etc and .length property). So .call() allows calling array methods on array-like objects like strings (string wrappers are array-like), arguments objects, nodelists, etc. Also on your own array-like objects.
chaitanya ashtekar
@chaitanyaashtekar
Jul 17 2016 06:28
@Masd925
var x =new Boolean("null");  //I understand
if (x) console.log(1);

var y =new Boolean(null);  //should'nt execute
if (y)console.log(2);      //but does.why ??
kevinstonge
@kevinstonge
Jul 17 2016 06:30

how do I know when I can chain methods and when I can't?

For example this works:

arr.sort().indexOf(n);

but this doesn't work:

arr.push(i).indexOf(n);

chaitanya ashtekar
@chaitanyaashtekar
Jul 17 2016 06:31
@kevinstonge because arr.sort returns an array on which indexOf works
Nathaniel Nasarow
@Torgian
Jul 17 2016 06:31
@qualitymanifest Hey mate, so something like this you think? For the array?
Markus Kiili
@Masd925
Jul 17 2016 06:31
@chaitanyaashtekar if coerces values to Boolean type, so all objects coerce to true.
chaitanya ashtekar
@chaitanyaashtekar
Jul 17 2016 06:31
@kevinstonge but arr.push(i) doesnt return an array
kevinstonge
@kevinstonge
Jul 17 2016 06:32
thank you @chaitanyaashtekar that makes sense
CamperBot
@camperbot
Jul 17 2016 06:32
kevinstonge sends brownie points to @chaitanyaashtekar :sparkles: :thumbsup: :sparkles:
:cookie: 383 | @chaitanyaashtekar |http://www.freecodecamp.com/chaitanyaashtekar
llamatarianism
@llamatarianism
Jul 17 2016 06:32
@chaitanyaashtekar @Masd925 is right. use Boolean rather than new Boolean
~
Markus Kiili
@Masd925
Jul 17 2016 06:32
@chaitanyaashtekar If you need to coerce a value to Boolean type, you should use the Boolean function Boolean(val).
kevinstonge
@kevinstonge
Jul 17 2016 06:32
do you know of a shorthand way to stuff push and indexof into the same line? like that? :)
llamatarianism
@llamatarianism
Jul 17 2016 06:33
well you could use .concat but that won't modify the array in place like .push does
chaitanya ashtekar
@chaitanyaashtekar
Jul 17 2016 06:33
@Masd925 okay. but from the mdn website----Any object whose value is not undefined or null, including a Boolean object whose value is false, evaluates to true when passed to a conditional statement
llamatarianism
@llamatarianism
Jul 17 2016 06:33
`[1, 2, 3, 4].concat(5)
damnit
chaitanya ashtekar
@chaitanyaashtekar
Jul 17 2016 06:33
@llamatarianism i know but im asking it to clear my concept
llamatarianism
@llamatarianism
Jul 17 2016 06:33
[1, 2, 3, 4].concat(5).indexOf(5); @kevinstonge
Markus Kiili
@Masd925
Jul 17 2016 06:34
@chaitanyaashtekar Read it again. It is the same that I said.
Cal-culator
@Cal-culator
Jul 17 2016 06:34

function palindrome(str) {
  // Good luck!
    var a=str.toLowerCase().replace(/[^A-Z0-9]+/ig, "").split("");
    var b=str.toLowerCase().replace(/[^A-Z0-9]+/ig, "").split("").reverse("");
    for (var i=0; i<a.length;i++){
        if (a[i]===b[i]){
            return true;
        }
        else if (a[i]!==b[i]){
            return false;
        }
    }
}



palindrome("almostomla");
why doesn't this code work for "almostomla"?
chaitanya ashtekar
@chaitanyaashtekar
Jul 17 2016 06:35
@Masd925 yes.okay. thank you !
CamperBot
@camperbot
Jul 17 2016 06:35
chaitanyaashtekar sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2129 | @masd925 |http://www.freecodecamp.com/masd925
llamatarianism
@llamatarianism
Jul 17 2016 06:35
@chaitanyaashtekar in your example
y isn't false
it's an object that has a value of false
chaitanya ashtekar
@chaitanyaashtekar
Jul 17 2016 06:36
@llamatarianism ahhh.thanks man !
@llamatarianism thanks !
CamperBot
@camperbot
Jul 17 2016 06:36
chaitanyaashtekar sends brownie points to @llamatarianism :sparkles: :thumbsup: :sparkles:
:star2: 1010 | @llamatarianism |http://www.freecodecamp.com/llamatarianism
llamatarianism
@llamatarianism
Jul 17 2016 06:36
@Cal-culator your function only checks the first 2 letters
kevinstonge
@kevinstonge
Jul 17 2016 06:36
Thank you @llamatarianism got my one line function with that concat tip :)
CamperBot
@camperbot
Jul 17 2016 06:36
kevinstonge sends brownie points to @llamatarianism :sparkles: :thumbsup: :sparkles:
:star2: 1011 | @llamatarianism |http://www.freecodecamp.com/llamatarianism
llamatarianism
@llamatarianism
Jul 17 2016 06:36
return == break
Cal-culator
@Cal-culator
Jul 17 2016 06:37
@llamatarianism what do you mean?
can you elaborate
llamatarianism
@llamatarianism
Jul 17 2016 06:37
your loop always returns on the first iteration
and returning ends the loop
Cal-culator
@Cal-culator
Jul 17 2016 06:37
oh... i see
llamatarianism
@llamatarianism
Jul 17 2016 06:37
so you only check the first letters
Cal-culator
@Cal-culator
Jul 17 2016 06:39
@llamatarianism how do i fix it? Do i make another loop at the bottom to check?
chaitanya ashtekar
@chaitanyaashtekar
Jul 17 2016 06:39
@Cal-culator dont return true when char are equal.let the loop continue.return false only when you find them not equal
llamatarianism
@llamatarianism
Jul 17 2016 06:39
here's what you do:
chaitanya ashtekar
@chaitanyaashtekar
Jul 17 2016 06:39

@Cal-culator ```
for (var i=0; i<a.length;i++){

     if (a[i]!==b[i]){
        return false;
    }

```

damm
llamatarianism
@llamatarianism
Jul 17 2016 06:39
use .join to make a and b into strings
chaitanya ashtekar
@chaitanyaashtekar
Jul 17 2016 06:39

@Cal-culator ```
for (var i=0; i<a.length;i++){

     if (a[i]!==b[i]){
        return false;
    }

```

llamatarianism
@llamatarianism
Jul 17 2016 06:40
then compare those strings
this challenge does not need a for loop
Cal-culator
@Cal-culator
Jul 17 2016 06:41

@chaitanyaashtekar thanks
@llamatarianism thanks

```

function palindrome(str) {
// Good luck!
var a=str.toLowerCase().replace(/[^A-Z0-9]+/ig, "").split("");
var b=str.toLowerCase().replace(/[^A-Z0-9]+/ig, "").split("").reverse("");
for (var i=0; i<a.length;i++){
if (a[i]===b[i]){
}
else if (a[i]!==b[i]){
return false; break;
}
}
return true;
}

palindrome("almostomla");

CamperBot
@camperbot
Jul 17 2016 06:41
cal-culator sends brownie points to @chaitanyaashtekar and @llamatarianism :sparkles: :thumbsup: :sparkles:
:star2: 1012 | @llamatarianism |http://www.freecodecamp.com/llamatarianism
:cookie: 384 | @chaitanyaashtekar |http://www.freecodecamp.com/chaitanyaashtekar
chaitanya ashtekar
@chaitanyaashtekar
Jul 17 2016 06:41
yes you could just use ====
Cal-culator
@Cal-culator
Jul 17 2016 06:42

function palindrome(str) {
  // Good luck!
    var a=str.toLowerCase().replace(/[^A-Z0-9]+/ig, "").split("");
    var b=str.toLowerCase().replace(/[^A-Z0-9]+/ig, "").split("").reverse("");
    for (var i=0; i<a.length;i++){
        if (a[i]===b[i]){
        }
        else if (a[i]!==b[i]){
            return false; break;
        }
    }
  return true;
}



palindrome("almostomla");
I just changed it to that
It worked
chaitanya ashtekar
@chaitanyaashtekar
Jul 17 2016 06:42
@llamatarianism try return a===b no need of for loop
llamatarianism
@llamatarianism
Jul 17 2016 06:42
actually comparison doesn't work that way for arrays
[1, 2, 3] !== [1, 2, 3] because they're different objects
the solution is, like I said, to make them into strings
then compare them
chaitanya ashtekar
@chaitanyaashtekar
Jul 17 2016 06:43
yes.but they are strings.so it will work
llamatarianism
@llamatarianism
Jul 17 2016 06:43
no they're not
chaitanya ashtekar
@chaitanyaashtekar
Jul 17 2016 06:45
ahh.you are right .he didnt .join them later.i didnt read correctly
thanks @llamatarianism
CamperBot
@camperbot
Jul 17 2016 06:45
:warning: chaitanyaashtekar already gave llamatarianism points
chaitanyaashtekar sends brownie points to @llamatarianism :sparkles: :thumbsup: :sparkles:
Lee
@leebut
Jul 17 2016 06:53

Hello folks.
I'm trying to understand, 'Nesting for loops'. I got a working solution, but I don't understand what 'j' is doing.

function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line
  var array = [arr];
  for (var i=0; i < arr.length; i++){
    for (var j=0; j < arr[i].length; j++){
      product = product * arr[i][j];
    }
  }

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

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);

It looks like 'j' is checking the length of the container array and then moving to the next item. However, how is it moving in and out of each of the nested arrays [0], [1] and [2]?

kirbyedy
@kirbyedy
Jul 17 2016 06:54
I think j is looping through each element of the specified array
because you have array of arrays
Markus Kiili
@Masd925
Jul 17 2016 06:55
@leebut arr[i] is one subarray and j loop loops through its indices.
Cal-culator
@Cal-culator
Jul 17 2016 06:57
TypeError: str.toUpperCase.split is not a function. (In 'str.toUpperCase.split(" ")', 'str.toUpperCase.split' is undefined)
How do i fix this?
Markus Kiili
@Masd925
Jul 17 2016 06:58
@Cal-culator .toUpperCase().split()
Cal-culator
@Cal-culator
Jul 17 2016 06:59
@Masd925 ah ok thanks
CamperBot
@camperbot
Jul 17 2016 06:59
cal-culator sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2130 | @masd925 |http://www.freecodecamp.com/masd925
Kamil Malek
@KamilMalek
Jul 17 2016 07:00
Hey guys, in 'Wherefore art thou' intermediate algorithm scripting I'm getting ReferenceError: keys is not defined while using sourceKeys = Object.keys(source);. Can anyone tell me why?
Markus Kiili
@Masd925
Jul 17 2016 07:01
@KamilMalek Code seems right. Where are you testing it?
Kamil Malek
@KamilMalek
Jul 17 2016 07:02
Right in the fCC code editor
Markus Kiili
@Masd925
Jul 17 2016 07:02
Try refreshing the page.
Kamil Malek
@KamilMalek
Jul 17 2016 07:02
All right
Keone Martin
@Athaman
Jul 17 2016 07:02
inside the function right?
Kamil Malek
@KamilMalek
Jul 17 2016 07:02
Yes
Refreshing didn't help
Lee
@leebut
Jul 17 2016 07:03
@Masd925 does that mean the line italics product = product arr[i][j]; * is using [i] to count the index of the container array and [j] is counting the indices of the nested array?
Kamil Malek
@KamilMalek
Jul 17 2016 07:03
Here's the whole snippet:
function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line
  // There was a for loop involved. The first part involved getting the keys from the source
  sourceKeys = Object.keys(source);

  return collection.filter(function (obj){
    for(var i = 0; i < keys.length;i++){
    if(!obj.hasOwnProperty(sourceKeys[i]) || obj[sourceKeys[i]] !== source[sourceKeys[i]]) {
      return false; 
     }
    }
    return true; 
  });
  }
  // Only change code above this line
Markus Kiili
@Masd925
Jul 17 2016 07:03
@leebut Yes, i means the arr element index (elements of arr are arrays).
Keone Martin
@Athaman
Jul 17 2016 07:04
@KamilMalek put var before sourceKeys
Kamil Malek
@KamilMalek
Jul 17 2016 07:04
@Athaman Still nothing
And I tested in on a different machine just to make sure
Keone Martin
@Athaman
Jul 17 2016 07:05
oh wait, it's the keys.length in your for loop
Kamil Malek
@KamilMalek
Jul 17 2016 07:06
@Athaman Oh my god, thanks
CamperBot
@camperbot
Jul 17 2016 07:06
kamilmalek sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
:cookie: 605 | @athaman |http://www.freecodecamp.com/athaman
Kamil Malek
@KamilMalek
Jul 17 2016 07:06
Such a stupdi one
Thank you :)
Keone Martin
@Athaman
Jul 17 2016 07:06
hah, it happens :D
Lee
@leebut
Jul 17 2016 07:08
@Masd925 Thank you. I partially understand it. I'm thinking that var product should be defined globally to make it accessible to console.log() or document.GetElementById("id").innerHTML = ;
CamperBot
@camperbot
Jul 17 2016 07:08
leebut sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2131 | @masd925 |http://www.freecodecamp.com/masd925
Cal-culator
@Cal-culator
Jul 17 2016 07:21
Why does this happen?
TypeError: a[i].join is not a function. (In 'a[i].join("")', 'a[i].join' is undefined)

function titleCase(str) {
  var a= str.split(" ");
  var b=[];
  var c=[];
  var d=[];
  for (var i=0;i<a.length;i++){
    b=a[i].split("");
    b[0].toUpperCase();
    c.push(b[0]);
    d= c.join("").toUpperCase().split("");
    b[0].replace(d[i]);
    a[0].replace(d[i]);
    a[i].join("");
  }
  a.join(" ")
  console.log(a);
}

titleCase("I'm a little tea pot");
this is the code
Eric Ka-Yeung Leung
@ekleung123
Jul 17 2016 07:24
@Cal-culator don't put the brackets...it shud only be a.join("");
Cal-culator
@Cal-culator
Jul 17 2016 07:25
Which join? the one inside the loop?
@ekleung123
Eric Ka-Yeung Leung
@ekleung123
Jul 17 2016 07:25
wait...did u mean a[i].push?
by doing a[i].join, you're saying only to join one element in the array, which wouldn't make sense
Cal-culator
@Cal-culator
Jul 17 2016 07:26
@ekleung123 If i write a.join(""), wouldn't it mean join all of the words together?
I just want it to join words together
Eric Ka-Yeung Leung
@ekleung123
Jul 17 2016 07:27
doing a.join("") would convert the array into a string
Cal-culator
@Cal-culator
Jul 17 2016 07:27
@ekleung123 let me try that
Eric Ka-Yeung Leung
@ekleung123
Jul 17 2016 07:27
["apple","boy","cat"] becomes "apple, boy, cat"
Markus Kiili
@Masd925
Jul 17 2016 07:29
With just .join(""), it becomes 'appleboycat', but you can define the delimiter as you like.
jiajinning
@jiajinning
Jul 17 2016 07:31
can you help me ?
Chris
@capozzic1
Jul 17 2016 07:31
Hello. My name is Chris. I'm having a big issue with my hangman game that I feel like should have been simple. Can anyone help? I am trying to append the user's input(a single letter) to one of the underscores(which represents a missing letter). https://jsfiddle.net/jtpsj5eu/16/
jiajinning
@jiajinning
Jul 17 2016 07:32
my code run out is good ! but it con't ?why ?

function repeat(str, num) {
// repeat after me
if(num<0){
return "";
}
else {
var strs = "";
for(var i=0;i<num;i++){
strs +=str;
}
return '"'+strs+'"';
}

}

repeat("abc", 1);

Eric Ka-Yeung Leung
@ekleung123
Jul 17 2016 07:32
@Cal-culator You're also not using the replace method propertly. In the replace method, you have to tell what you want to replace and what you want to replace it with. Example: string.replace("this","that");
Cal-culator
@Cal-culator
Jul 17 2016 07:33
@ekleung123 Ah ok
@ekleung123 Going to fix that
Eric Ka-Yeung Leung
@ekleung123
Jul 17 2016 07:35
@jiajinning - ur second return statement doesn't work. Just say "return strs"
Cal-culator
@Cal-culator
Jul 17 2016 07:37
@ekleung123 can i only use the replace function for strings?
Evgueni
@Redoras
Jul 17 2016 07:38
Hello
Eric Ka-Yeung Leung
@ekleung123
Jul 17 2016 07:39
function repeat(str, num) {
// repeat after me
if(num<0){
return false;
} else {
var strs = "";
for (var i=0;i<num;i++) {
strs +=str;
}
return strs;
}
Chris
@capozzic1
Jul 17 2016 07:40
Any ideas on the hangman underscore issue?
Eric Ka-Yeung Leung
@ekleung123
Jul 17 2016 07:40
@Cal-culator - You can't use the replace method on arrays. Read this: http://www.w3schools.com/jsref/jsref_replace.asp
jiajinning
@jiajinning
Jul 17 2016 07:41
@ekleung123 thank you
CamperBot
@camperbot
Jul 17 2016 07:41
jiajinning sends brownie points to @ekleung123 :sparkles: :thumbsup: :sparkles:
:cookie: 101 | @ekleung123 |http://www.freecodecamp.com/ekleung123
Cal-culator
@Cal-culator
Jul 17 2016 07:41
@ekleung123 then how do i replace in array? I tried assigning but it didn't work
Eric Ka-Yeung Leung
@ekleung123
Jul 17 2016 07:42
to replace one value over another, you just declare a value over it..for example, let's say your array = ["apple","boy","cat"]
if you want to replace boy with girl, you say array1 = "girl";
it's array[ 1] = "girl"
Cal-culator
@Cal-culator
Jul 17 2016 07:43

function titleCase(str) {
  var a= str.split(" ");
  var b=[];
  var c=[];
  var d=[];
  var e="";
  var f=[];
  for (var i=0;i<a.length;i++){
    b=a[i].split("");
    d= c.join("").toUpperCase().split("");
    b[0]=d[i];
    a[i]= b.join("");
  }
  a.join(" ");
  console.log(a);
}

titleCase("I'm a little tea pot");
I tried doing this
Eric Ka-Yeung Leung
@ekleung123
Jul 17 2016 07:44
you can't join only 1 element in an array
you can say a = b.join("");
Cal-culator
@Cal-culator
Jul 17 2016 07:45
What i am trying to do is split the string below into individual words. And then in the loop, split the words into array.
Blauelf
@Blauelf
Jul 17 2016 07:45
@Cal-culator You might want to str.toLowerCase().split(" ") (to remove uppercase letters within words), also, you don't return the result of a.join(" ") (it won't change a but return a string, which you currently ignore)
Hari Adhikari
@harryac07
Jul 17 2016 07:48
Hello,
I need help in problem 'Sum all Odd Fibonacci Numbers'. I didn't get the idea how to proceed. I need hints.
Thanks
Eric Ka-Yeung Leung
@ekleung123
Jul 17 2016 07:49
@Cal-culator I haven't done that exercise you're doing...but what is it supposed to return with titleCase("I'm a little tea pot")
Cal-culator
@Cal-culator
Jul 17 2016 07:50
@ekleung123 its supposed to return the first letters of each word upper case
So basically, it should return I'm A Little Tea Pot
Blauelf
@Blauelf
Jul 17 2016 07:51
Have you tried toLowerCase before splitting into words, and actually returning a.join(" ")?
Cal-culator
@Cal-culator
Jul 17 2016 07:52
@Blauelf Why do i need to lower case? I don't understand
Blauelf
@Blauelf
Jul 17 2016 07:52
@Cal-culator the input material might be all-caps, and only the first letter should be uppercase.
This message was deleted
Eric Ka-Yeung Leung
@ekleung123
Jul 17 2016 07:54

@Cal-culator
function titleCase(str) {
var a = str.split(" ");
var b = [];
for (var i=0; i<a.length; i++) {
b.push(a[i].charAt(0).toUpperCase());
}
return b;
}

var y = titleCase("I'm a little tea pot");
console.log(y);

this puts each letter in an array and returns the first letter of each word
Blauelf
@Blauelf
Jul 17 2016 07:54
@Cal-culator You are doing some odd things with your one-letter variables. I don't really understand why most of them are there. You might be better off giving them meaningful names, like "words" for "a" (it's an array of all the words), "word" or "currentWord" or something like that for "b" (it's an array of the characters in the current word), ...
For example. you call c.join, with c always being the empty array. The result of that line is an array containing a single empty string.
Cal-culator
@Cal-culator
Jul 17 2016 08:00
@Blauelf Yeah... going to scrap it and start over
Blauelf
@Blauelf
Jul 17 2016 08:01
@Cal-culator If you don't want to split the individual words (the split on empty string), I would suggest using substring, substr, or slice on the word string for obtaining the rest of the word, and concatenate the capitalized first letter with the rest using operator +.
Shivam Mehta
@shivam13
Jul 17 2016 08:01
how to use images from my google drive in code pen??
Eric Ka-Yeung Leung
@ekleung123
Jul 17 2016 08:01
haha i misread the assignemnet, i thought it's supposed to only return the first letter in each word
its not much diff to return each word with the first letter capitalzied...i'll work on it now
vmohan9
@vmohan9
Jul 17 2016 08:04
Can anybody help me with the seek and destroy question? I am stuck as the input is taken as a single array.
Kevin
@KevinBruland
Jul 17 2016 08:05
@vmohan9 sure, look into arguments
@vmohan9 short answer... you can use "arguments[x]" inside the function, so argument[0] would be the array, argument1 would be the first number out of the array, argument2 would be the second... etc
but I do strongly recommend reading the MDN page they link to
vmohan9
@vmohan9
Jul 17 2016 08:07
yeah I tried that way but it did not pass all the sections... sure I will check on them. What is the use of object in this particular question?
Shivam Mehta
@shivam13
Jul 17 2016 08:08
how to use images from my google drive in code pen??
Kevin
@KevinBruland
Jul 17 2016 08:08
I did not use an object, so I can't say @vmohan9
vmohan9
@vmohan9
Jul 17 2016 08:09
cool. Thanks @Benalron
CamperBot
@camperbot
Jul 17 2016 08:09
vmohan9 sends brownie points to @benalron :sparkles: :thumbsup: :sparkles:
:cookie: 373 | @benalron |http://www.freecodecamp.com/benalron
Muhammad Hasham
@MohammadHasham
Jul 17 2016 08:09
@harryac07 @Blauelf
function destroyer(arr) {
  // Remove all the values

  var args =arr.slice.call(arguments);
  for (var i = 0;i<args.length;i++)
    {
      if (arr[i] == args[i])
        {
          return arr;
        }
    }

}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
can u guys help
Kevin
@KevinBruland
Jul 17 2016 08:10
@vmohan9 np, GL
Blauelf
@Blauelf
Jul 17 2016 08:10
@MohammadHasham Don't randomly tag people.
Muhammad Hasham
@MohammadHasham
Jul 17 2016 08:10
@Blauelf Apology.
@Blauelf Can you help me with this?
Kevin
@KevinBruland
Jul 17 2016 08:11
@MohammadHasham try to run through it mentally and see what it would be doing each time
Muhammad Hasham
@MohammadHasham
Jul 17 2016 08:12
@Benalron I have no clue about this challenge can you help me a lil
@Benalron How can i incorporate the filter?
KnoX
@knox97
Jul 17 2016 08:13
Mohammad what are you supose to do or return?
Kevin
@KevinBruland
Jul 17 2016 08:13
@MohammadHasham the first run of the for loop causes the if statement to be, "if 1 == [1, 2, 3, 1, 2, 3]", so that doesnt trigger... the second run through is, if 2 == 2, return arr... so it's returning (ending the entire function, and giving the value of the entire arr)
@MohammadHasham remember, arguments[0] is the array
Muhammad Hasham
@MohammadHasham
Jul 17 2016 08:14
@Benalron then should i store the value in another variable?
and then return that at the end
Kevin
@KevinBruland
Jul 17 2016 08:15
@MohammadHasham thats one way to do it that would work... but you don't want to return... return ends the entire function
KnoX
@knox97
Jul 17 2016 08:15
Yeah you need to make an adfitional if statement that checks if it has more then one value
Muhammad Hasham
@MohammadHasham
Jul 17 2016 08:15
@Benalron Is it really necesary yo use filter()
Kevin
@KevinBruland
Jul 17 2016 08:16
@MohammadHasham but youre also checking each argument against only 1 items in the array... you need to make it so you are checking each argument (other than arguments[0], the array] against EVERY number in the array
Eric Ka-Yeung Leung
@ekleung123
Jul 17 2016 08:16

@Cal-culator
function titleCase(str) {
var a = str.split(" "), b = [];
for (var i=0; i<a.length; i++) {
var x = a[i]
x = x.charAt(0).toUpperCase() + a[i].slice(1,a.length+1);
b.push(x);
}
return b
}

var y = titleCase("I'm a little tea pot");
console.log(y); // yields "I'm A Little Tea Pot"

Kevin
@KevinBruland
Jul 17 2016 08:16
no... I did it using 2 for loops, @MohammadHasham
KnoX
@knox97
Jul 17 2016 08:16
If it does than loop through its value or even a good while loop that will loop through every index that has value over 1
Cal-culator
@Cal-culator
Jul 17 2016 08:16
@ekleung123 I got it

function titleCase(str) {
  var a=str.toLowerCase().split(" ");
  var b=[];
  var c=[];
  var d="";
  var e=[];
  var f=[];
  var g=[];
  for (var i=0; i<a.length;i++){
      b=a[i].split("");
      console.log(b);
      c.push(b[0]);
      console.log(c);
      d = c.join("").toUpperCase();
      console.log(d);
      e= d.split("");
      console.log(e);
      b[0]=e[i];
      f=b.join("");
      console.log(f);
      g.push(f);
  }
  return g.join(" ");



}

titleCase("I'm a little tea pot");
Ignore the console.log();
Eric Ka-Yeung Leung
@ekleung123
Jul 17 2016 08:17
@Cal-culator you dont need to declare so many arrays
Kevin
@KevinBruland
Jul 17 2016 08:17
@Cal-culator that is a very interesintg solution
Cal-culator
@Cal-culator
Jul 17 2016 08:18
@ekleung123 I know. I did it because i was starting to get confused.
Eric Ka-Yeung Leung
@ekleung123
Jul 17 2016 08:18
i'm not sure that solution would work for every sentence you pass to titleCase
Kevin
@KevinBruland
Jul 17 2016 08:18
@Cal-culator remember arrays can have arrays inside of them, like, [ [0,1 ], [2,3 ], [3,4 ], [4,5 ], ]
Eric Ka-Yeung Leung
@ekleung123
Jul 17 2016 08:18
@Cal-culator just try my code .... it does it properly
Cal-culator
@Cal-culator
Jul 17 2016 08:18
@Benalron I tried that but it didn't work the way I wanted so I tried a much more simple algorithm
@ekleung123 I did. Its pretty concise. Thanks
CamperBot
@camperbot
Jul 17 2016 08:19
cal-culator sends brownie points to @ekleung123 :sparkles: :thumbsup: :sparkles:
:cookie: 102 | @ekleung123 |http://www.freecodecamp.com/ekleung123
Cal-culator
@Cal-culator
Jul 17 2016 08:20
@ekleung123 I didn't know charAt and slice works in JavaScript
Eric Ka-Yeung Leung
@ekleung123
Jul 17 2016 08:21
@Cal-culator what other langauge do you know?
Cal-culator
@Cal-culator
Jul 17 2016 08:21
C++ but haven't used it in a long time so need to refresh
@ekleung123 Java
Eric Ka-Yeung Leung
@ekleung123
Jul 17 2016 08:21
yeah some of the syntax between java and javascript are similar
Cal-culator
@Cal-culator
Jul 17 2016 08:22
@ekleung123 yeah but JavaScript is so much more easier and more user Oriented
KnoX
@knox97
Jul 17 2016 08:25
I tried java and got lost in it, but guys one question is it realy better than js? I mean can it do something that js cant?
Cal-culator
@Cal-culator
Jul 17 2016 08:26
@knox97 Java Script is for browser developing
It can't run on its own while Java can.
It depends on what you are trying to write.
Promise Tochi
@Promhize
Jul 17 2016 08:27
hello everyone, please i want this code to remove the second and third arguments from the first argument which is the array. But it is returning true for every elem, i cant find the bug, or is there a better way to go about it?
function destroyer(arr) {
  // Remove all the values
  var basearr = arr[0];
  var arglength = arguments.length;

  var newarray = [];

  for (var i = 1; i < arglength; i++) {
      newarray.push(arguments[i]);
  }

  console.log(newarray);

 var finalarray = arguments[0].filter(function(elem, index, array) {
        elem = false;
        for (i = 0; i < newarray.length; i++) {
            if (newarray[1] !== elem) {
                elem = true;
            }
        }

          return elem;
      });


  arr = finalarray

  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
KnoX
@knox97
Jul 17 2016 08:28
I wouldnt agree with that there is nodeJS and it has v8 from google integrated in it @Cal-culator
Eric Ka-Yeung Leung
@ekleung123
Jul 17 2016 08:29
@Promhize so it it supposed to return [1,2,3,1,2,3]
Markus Kiili
@Masd925
Jul 17 2016 08:29
@Promhize You should try to find an argument equal to elem, and then return false. After loop return true.
Promise Tochi
@Promhize
Jul 17 2016 08:30
supposed to return just [1,1] it is to remove the occurences of 2 and 3 @ekleung123
@Masd925 because the function can except different numbers of arguments, i cant hard code the arguments,so i decided to loop through them first and created an array from them
there seems to be something wrong with the loop, when i remove the loop and pass, newarray[1], it removes all the occurrences of 3
Lee
@leebut
Jul 17 2016 08:41
Hello Folks! I'm doing the Profile Lookup Challenge. I want to test it part-by-part, but even when the name is a name in the array, it shows 'No such contact' despite the part about bob having a green tick. How can it be right and wrong at the same time?
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i = 0; i < contacts.length; i++){
  if (contacts.firstName !== firstName){
    return "No such contact";}

}
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
kevinstonge
@kevinstonge
Jul 17 2016 08:43
contacts[i].firstName
Lee
@leebut
Jul 17 2016 08:44
@kevinstonge Ah, so I have to include the index number to the object access part?
Faisal Zulfiqar
@faisal1337
Jul 17 2016 08:44
Which API FCC used for sample 'Random Quote Machine' does anyone know?
kevinstonge
@kevinstonge
Jul 17 2016 08:45
it's an array of objects in this exercise, so yes.
Lee
@leebut
Jul 17 2016 08:47
@kevinstonge Okay. Thank you. It still shows 'No such contact', though. Is that because the task in incomplete?
CamperBot
@camperbot
Jul 17 2016 08:47
leebut sends brownie points to @kevinstonge :sparkles: :thumbsup: :sparkles:
kevinstonge
@kevinstonge
Jul 17 2016 08:47
show's no such contact for who?
actually... that's poorly written, it will return no such contact the very first time contacts[i].firstName is not the contact name :)
Muhammad Hasham
@MohammadHasham
Jul 17 2016 08:48

@faisal1337

var args =arr.slice.call(arguments);

function destroyer(arr) {
  // Remove all the values  
}

function consta(arr)
{
  for (var i = 0 ; i<arr.length;i++)
    {
      if (arr[i] == args[i])
        {

        }
    }
}

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

what i need to put in the if conditions in consta()

Blauelf
@Blauelf
Jul 17 2016 08:48
@leebut You return "No such contact" when there's at least one mismatch, not only if all the names are mismatches.
voidfire
@voidfire
Jul 17 2016 08:48
Meow, Anyone in the mood to explain a bit recursion to me? I seem to be getting wrong idea about how to factorialize a number
Blauelf
@Blauelf
Jul 17 2016 08:49
@MohammadHasham The var args line has to be inside destroyer, just like your consta function.
kevinstonge
@kevinstonge
Jul 17 2016 08:49
I'd switch that to a === and work from there. If it finds a match it should return something (and you'll need to build some conditional statements to return the correct thing)
Keone Martin
@Athaman
Jul 17 2016 08:49
@voidfire sure, recursion is basically you make a function with a base case that returns stuff, then if that base case isn't met you call the function again inside the function with an altered parameter
Faisal Zulfiqar
@faisal1337
Jul 17 2016 08:50
@MohammadHasham why would you put them outside destroyer function?
Both args line and the consta should be inside the destroyer.
Muhammad Hasham
@MohammadHasham
Jul 17 2016 08:50
@Blauelf Then i wont be able to use args in the second function
@faisal1337 Okay i'll try that
Blauelf
@Blauelf
Jul 17 2016 08:50
@MohammadHasham I told you to put both inside destroyer. If the function is inside the same scope, it can see args.
Faisal Zulfiqar
@faisal1337
Jul 17 2016 08:51
Put both inside.
And then worry about the condition.
jamesmillerho
@jamesmillerho
Jul 17 2016 08:51
` js
Muhammad Hasham
@MohammadHasham
Jul 17 2016 08:51
@faisal1337 @Blauelf Okay
Faisal Zulfiqar
@faisal1337
Jul 17 2016 08:51
@Blauelf can you tell me about the API the sample project used? Random Quote Machine. What's its name?
jamesmillerho
@jamesmillerho
Jul 17 2016 08:51
codePen doesn't ask my location. Why?
$(document).ready(function(){

  if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position){
$("#data").html("a" + position.coords.latitude + "<br>longitude: " + position.coords.longitude);});
};

})
Faisal Zulfiqar
@faisal1337
Jul 17 2016 08:52
@jamesmillerho try to do it in the FCC editor.
Lee
@leebut
Jul 17 2016 08:53
@Blauelf Oh. Thank you. Making my way into the nested array now.
CamperBot
@camperbot
Jul 17 2016 08:53
leebut sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 2193 | @blauelf |http://www.freecodecamp.com/blauelf
Faisal Zulfiqar
@faisal1337
Jul 17 2016 08:53
Do I need to put Javascript code in Codepen in <script> tags or not?
jamesmillerho
@jamesmillerho
Jul 17 2016 08:54
@faisal1337 what is that
Blauelf
@Blauelf
Jul 17 2016 08:55
Faisal Zulfiqar
@faisal1337
Jul 17 2016 08:55
@jamesmillerho are you using CodePen to complete the challenge?
And putting the code from Codepen.io to FCC editor?
Muhammad Hasham
@MohammadHasham
Jul 17 2016 08:55

@faisal1337


function destroyer(arr) {
  // Remove all the values  
  var args =arr.slice.call(arguments);


function consta(args)
{

  for (var i = 0 ; i<arr.length;i++)
    {
      if (arr[i] == args[i])
        {

        }
    }
}
}

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

@Blauelf is it okay? and when i am returning anything in consta() it does not return what is the issue here?

Faisal Zulfiqar
@faisal1337
Jul 17 2016 08:55
@Blauelf thanks.
CamperBot
@camperbot
Jul 17 2016 08:55
faisal1337 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 2194 | @blauelf |http://www.freecodecamp.com/blauelf
jamesmillerho
@jamesmillerho
Jul 17 2016 08:56
@faisal1337 I just type the code on codePen.io
Blauelf
@Blauelf
Jul 17 2016 08:56
@MohammadHasham You have no return statement, so destroyer implicitly returns undefined. Also, you never use consta. Oh, and consta would implicitly return undefined in all cases, too.
Faisal Zulfiqar
@faisal1337
Jul 17 2016 08:56
Put it back in freecodecamp edior.
editor
Muhammad Hasham
@MohammadHasham
Jul 17 2016 08:57
@Blauelf @faisal1337 Now what should i do?
Faisal Zulfiqar
@faisal1337
Jul 17 2016 08:57
Now make the condition
use indexOf()
it will help.
Muhammad Hasham
@MohammadHasham
Jul 17 2016 08:57
@faisal1337 Now the condition would be made in second function?
Blauelf
@Blauelf
Jul 17 2016 08:58
@MohammadHasham Add return statements to both of your functions, and fix the condition in consta. If you want consta to be used by filter, it should not have a parameter named args, since this shadows the variable in the outer scope.
jamesmillerho
@jamesmillerho
Jul 17 2016 08:58
@faisal1337 but I am building the weather app so I have to do it on codePen
不得不错
@hnsxxscyx
Jul 17 2016 08:59
Hi,everyone. Can you tell me where is my code wrong?
Aleksandr Vinogradskiy
@patapum86
Jul 17 2016 08:59

Hi, can you please help me with my code var Bike = function() {

// Only change code below this line.
this.getGear = function(change) {
return change;
};
this.setGear = function(change) {
return change;
};

};

var myCar = new Car();

var myBike = new Bike();

myBike.setGear(4);

Muhammad Hasham
@MohammadHasham
Jul 17 2016 08:59
@Blauelf Okay i'll try that
不得不错
@hnsxxscyx
Jul 17 2016 08:59
function chunk(arr, size) {<br> // Break it up.<br> var arr1 = [];<br> var arr2 = [];<br> for(var i=0; i<arr.length; ){<br> for(var j=0; j<size; j++,i++){<br> arr2[j] = arr[i];<br> }<br> arr1.push(arr2);<br> }<br> return arr1;<br>}<br><br>chunk(["a", "b", "c", "d"], 2);<br>
Faisal Zulfiqar
@faisal1337
Jul 17 2016 08:59
@jamesmillerho I don't know then. Sorry :/
不得不错
@hnsxxscyx
Jul 17 2016 08:59
...sorry
Aleksandr Vinogradskiy
@patapum86
Jul 17 2016 08:59
myBike.getGear() should return 4 after calling myBike.setGear(4). and it does not
Blauelf
@Blauelf
Jul 17 2016 08:59
@hnsxxscyx No HTML here.
help format
CamperBot
@camperbot
Jul 17 2016 09:00

: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 thecode`.

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

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

不得不错
@hnsxxscyx
Jul 17 2016 09:00
sorry,How push it?
function chunk(arr, size) {<br> // Break it up.<br> var arr1 = [];<br> var arr2 = [];<br> for(var i=0; i<arr.length; ){<br> for(var j=0; j<size; j++,i++){<br> arr2[j] = arr[i];<br> }<br> arr1.push(arr2);<br> }<br> return arr1;<br>}<br><br>chunk(["a", "b", "c", "d"], 2);<br>
I'm so sorry
Leow Wei Xiang
@boyboi86
Jul 17 2016 09:01
@hnsxxscyx u can try putting 3 ticks before and after your codes
`
不得不错
@hnsxxscyx
Jul 17 2016 09:01
function chunk(arr, size) {<br>  // Break it up.<br>  var arr1 = [];<br>  var arr2 = [];<br>  for(var i=0; i<arr.length; ){<br>    for(var j=0; j<size; j++,i++){<br>      arr2[j] = arr[i];<br>    }<br>    arr1.push(arr2);<br>  }<br>  return arr1;<br>}<br><br>chunk(["a", "b", "c", "d"], 2);<br>
yes,markdown
Blauelf
@Blauelf
Jul 17 2016 09:01
Now replace the <br> with line breaks (Shift+Return)
BTW, you can edit your posts using the three dot menu that appears when you hover over a post.
Leow Wei Xiang
@boyboi86
Jul 17 2016 09:01
@hnsxxscyx 不错嘛
不得不错
@hnsxxscyx
Jul 17 2016 09:01
sorry,wait
unction chunk(arr, size) {
  // Break it up.
  var arr1 = [];
  var arr2 = [];
  for(var i=0; i<arr.length; ){
    for(var j=0; j<size; j++,i++){
      arr2[j] = arr[i];
    }
    arr1.push(arr2);
  }
  return arr1;
}

chunk(["a", "b", "c", "d"], 2);
Blauelf
@Blauelf
Jul 17 2016 09:02
:+1:
不得不错
@hnsxxscyx
Jul 17 2016 09:02
原来有中国人,救我。。
英语太不行了
耽误大家的时间了,抱歉
Blauelf
@Blauelf
Jul 17 2016 09:02

@hnsxxscyx You might want to move the var arr2 = []; inside the outer loop, before the inner loop. This way you get a fresh array for each iteration of the outer loop.

And maybe you need a check like j<size && i<arr.length instead of just j<size for not including undefineds when arr.length is not a multiple of size.

不得不错
@hnsxxscyx
Jul 17 2016 09:04
Why is not new now? Every '=' didn't cover it?
Muhammad Hasham
@MohammadHasham
Jul 17 2016 09:05

@faisal1337 @Blauelf

function destroyer(arr) {
  // Remove all the values  
  var args =arr.slice.call(arguments);


function consta()
{
  var max = [2,3];
  for (var i = 0 ; i<arr.length;i++)
    {
      if (arr[i] == max[i])
        {
          return true;
        }
    }
 return false;
}
  var new_array ;
     for (var i = 0;i<arr.length;i++)
      {
        new_array= arr.filter(consta);
      }
  return new_array;
}

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

I have harcoded [2,3] in max for the time being later on i'll work on that but why is still it is being tangled?

不得不错
@hnsxxscyx
Jul 17 2016 09:05
Ok, I'll try,thanks.@Blauelf
Lee
@leebut
Jul 17 2016 09:06
Hello again. Back to the Profile Lookup.
I've got a tick for 'No such property', but I'm having trouble accessing the nested array. I've tried many things, so I'm not being lazy.
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


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

  else if (contacts[i] !== prop){
    return "No such property";
 } 
for (var j = 0; j < contacts[i].length; j++){
  return contacts[i], [prop][j];
}


}
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
不得不错
@hnsxxscyx
Jul 17 2016 09:06
@Blauelf Thanks.
CamperBot
@camperbot
Jul 17 2016 09:06
hnsxxscyx sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 2195 | @blauelf |http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Jul 17 2016 09:06
@hnsxxscyx When pushing arr2 to arr1, you copy a reference to arr2 (or more to the object arr2 is referencing) to the end of arr1. When you change arr2 now, so does the array you just pushed. That's why you should replace the content of arr2 by another empty array.
不得不错
@hnsxxscyx
Jul 17 2016 09:06
ok,I know
It's like c, array is a address.
kevinstonge
@kevinstonge
Jul 17 2016 09:07
@leebut if you say return "no such contact" when contacts[i].firstName !== firstName ... it will return "no such contact" the very first time it finds an objects in which firstname is not the one passed to it... and since there are four different objects with four different first names; you will almost always get "no such contact" returned. you must begin with === and move from there.
and when it hits "return" the function exits and that value is returned, so anything written after that will not be executed.
Lee
@leebut
Jul 17 2016 09:09
@kevinstonge, it's a mess, then.
kevinstonge
@kevinstonge
Jul 17 2016 09:10
yeah
Muhammad Hasham
@MohammadHasham
Jul 17 2016 09:10

@Blauelf

function destroyer(arr) {
  // Remove all the values  
  var args =arr.slice.call(arguments);


function consta()
{
  var max = [2,3];
  for (var i = 0 ; i<arr.length;i++)
    {
      if (arr[i] == max[i])
        {
          return true;
        }
    }
 return false;
}
  var new_array ;
     for (var i = 0;i<arr.length;i++)
      {
        new_array= arr.filter(consta);
      }
  return new_array;
}

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

I have hardcoded [2,3] for the time being but i am still left with an empty array when i return new_array? where am i wrong?

Lee
@leebut
Jul 17 2016 09:10
@kevinstonge As my code is wrong, the system shouldn't give green ticks to show that part as working.
kevinstonge
@kevinstonge
Jul 17 2016 09:11
it's returning the right answer for the wrong reasons :)
Lee
@leebut
Jul 17 2016 09:11
@kevinstonge yeah, but that is misleading me. It's not good to learn that way.
Blauelf
@Blauelf
Jul 17 2016 09:12

@MohammadHasham consta should take one argument, a value, You should then iterate args (ignoring the first element, as this is equal to arr), and compare the args element to the passed value. On match, return false, after the loop return true.

And no need for another loop in destroyer if you are going to use filter.

kevinstonge
@kevinstonge
Jul 17 2016 09:13
think of those checkboxes as clues to help you write the algorithm correctly; just because you get a green check mark, doesn't mean your algorithm is any good at all. You need to get them all and understand why you are getting each one.
不得不错
@hnsxxscyx
Jul 17 2016 09:13
@Blauelf It's gone,thank you very much.
Lee
@leebut
Jul 17 2016 09:13
@kevinstonge I've spent about 40 hours on this JavaScript section. A lot of that is from lack of clarity.
不得不错
@hnsxxscyx
Jul 17 2016 09:13
But if I write like this
function chunk(arr, size) {
  // Break it up.
  var array = [];
  for(var i=0; i<arr.length; i++){
    array[i] = arr[i];
  }
  for(i=0,h=0; h<arr.length; i++,h++){
    for(var j=0; j<size; j++){
      array[i][h] = arr[h]; 
    }
  }
  //arr = array;
  return array;
}

chunk(["a", "b", "c", "d"], 2);
Why "typeError: 0 is read-only"
Muhammad Hasham
@MohammadHasham
Jul 17 2016 09:15
I have made some changes is that okay ,
Blauelf
@Blauelf
Jul 17 2016 09:16
@hnsxxscyx Your inner loop does the same thing size times. Also, you try to access properties of numbers (array contains numbers, you try to use them as arrays)
Muhammad Hasham
@MohammadHasham
Jul 17 2016 09:16
@Blauelf

function destroyer(arr) {
  // Remove all the values  
  var args =arr.slice.call(arguments);


function consta()
{
  var max = [2,3];
  for (var i = 0 ; i<arr.length;i++)
    {
      for (var j=0;j<max.length;j++)
        {
      if (arr[i] == max[j])
        {
          return true;
        }
        }
    }
 return false;
}

        new_array= arr.filter(consta);

  return new_array;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Blauelf
@Blauelf
Jul 17 2016 09:17
@MohammadHasham Remove that max thing. AND consta SHOULD TAKE AN ARGUMENT. Also, don't loop over arr in consta, but args. And still wrong condition, and true/false inverted.

There's little use in a function passed to filter if it does not take at least one argument.

Filter will call it with three arguments (the current element, its index in the array, and the array itself), and the function will ignore all of them.

kevinstonge
@kevinstonge
Jul 17 2016 09:20
For the "Build a Random Quote Machine" challenge, I'm supposed to find my own quote api? why don't they provide one?
Blauelf
@Blauelf
Jul 17 2016 09:24
Can only guess: Different people might prefer different quotes. And searching for an API that's appropriate and its documentation is a realistic task.
kevinstonge
@kevinstonge
Jul 17 2016 09:24
good point :)
Shivam Mehta
@shivam13
Jul 17 2016 09:24
i cant access weather icons from google drive what can i do any one help me please
icons extension is ".svg"
Lee
@leebut