These are chat archives for FreeCodeCamp/HelpJavaScript

28th
Mar 2016
Micah Bales
@micahbales
Mar 28 2016 00:00
@moigithub lol well that should have been obvious, huh? thanks so much for pointing that out
CamperBot
@camperbot
Mar 28 2016 00:00
micahbales sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:warning: micahbales already gave moigithub points
Micah Bales
@micahbales
Mar 28 2016 00:00
had been staring at it for a while. :)
Dustin
@Key-Banger
Mar 28 2016 00:06
@Szakins I'll post it if it works.
devonwilson1
@devonwilson1
Mar 28 2016 00:08
someone gotta trips for help?
counting cards assignment
Moisés Man
@moigithub
Mar 28 2016 00:10
@Key-Banger hows the Diff going? i got a working code using reduce + indexOf + lastIndexOf
oloughlinp
@oloughlinp
Mar 28 2016 00:11
@devonwilson1 the intent is that var vount = 0changes depending on the car. If the card is between 2-6, add one to count
Dustin
@Key-Banger
Mar 28 2016 00:11
@moigithub problematic. I got it to work for numbers. .sort() gives me issues with strings.
oloughlinp
@oloughlinp
Mar 28 2016 00:11
@devonwilson1 if it is 7,8,9, don't change the count variable
Moisés Man
@moigithub
Mar 28 2016 00:12
@Key-Banger probably u DONT need to sort em :)
oloughlinp
@oloughlinp
Mar 28 2016 00:12
@devonwilson1 after you change the count varibale, then you need to decide what to print.
Dustin
@Key-Banger
Mar 28 2016 00:16
@moigithub I don't follow your indexOf, lastIndexOf.
devonwilson1
@devonwilson1
Mar 28 2016 00:18
ok so what would this look like

var count = 0;

function cc(card) {
// Only change code below this line
if (card < 7) {
return "5 Bet";
}
else if (card > 6) {
return "0 Hold";
}

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

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

Bill
@W8sconsin
Mar 28 2016 00:18
https://www.freecodecamp.com/challenges/record-collection Could someone help me to figure out what exactly to do on this exercise?
Moisés Man
@moigithub
Mar 28 2016 00:20
@Key-Banger [1,2,3,4,1].indexOf(1) <--- return 0 (the first 1 )
[1,2,3,4,1].lastIndexOf(1) <--- returns 4 (the last 1 )
devonwilson1
@devonwilson1
Mar 28 2016 00:20
so am i using an if statement
or how would i write out if 2, 3, 4, 5, 6, +1
and so forth?
Matt Green
@mattxgreen
Mar 28 2016 00:21
@Key-Banger You still working on the array diff?
Dustin
@Key-Banger
Mar 28 2016 00:22
@mattxgreen yea, I haven't tried .filter() yet. I got it to work with numbers using .filter() ironically. Array of strings goes haywire.
@mattxgreen this worked for numbers.
function diff(arr1, arr2) {
  var newArr = [];
  var newArr2 = [];
  newArr = arr1.concat(arr2);
  newArr = newArr.sort(function(a, b) {
  return a - b;
});
  newArr = newArr.reduce(function(previousValue, currentValue) {
    if (previousValue !== currentValue) {

      newArr2.push(previousValue);

      return currentValue;
    }
  });
  newArr2 = newArr2.filter(Boolean);
  return newArr2;
}

diff([1, 2, 3, 5], [1, 2, 3, 4, 5]);
Matt Green
@mattxgreen
Mar 28 2016 00:24
@Key-Banger So, I actually spent some time on that excercise, and did three different solutions. You want to see them, or you prefer to solve on your own first?
Dustin
@Key-Banger
Mar 28 2016 00:25
@mattxgreen I like to solve on my own, but also don't like spending a night reinventing the wheel. ha ha ha
Matt Green
@mattxgreen
Mar 28 2016 00:27
@Key-Banger it's up to you...
oloughlinp
@oloughlinp
Mar 28 2016 00:27
@Key-Banger I don't know if this is right - but try != instead of !==
Shawn Samii
@samii1031
Mar 28 2016 00:28
hiya! any one available to explain "Return Early Pattern for Functions" in regular english, because the example doesn't fit the exercise and I am good and confused in practice, I think I got it in principle
Matt Green
@mattxgreen
Mar 28 2016 00:29
@samii1031 I can help, what you need?
Dustin
@Key-Banger
Mar 28 2016 00:29
@mattxgreen Let me work. If you don't mind ill send you a message so if I get it or not you can share. I'd love to see a different(better) way once I figure it out.
Ramana Venkata
@vramana
Mar 28 2016 00:29
@oloughlinp i don't think it will make a difference changing operators there.
Shawn Samii
@samii1031
Mar 28 2016 00:29
Here is the example:
function myFun() {
console.log("Hello");
return "World";
console.log("byebye")
}
myFun();
ok, bybrbyr new makes it to the console log
got it
Zabe Sangary
@zabesangary
Mar 28 2016 00:30
what are the difference between += and +
Shawn Samii
@samii1031
Mar 28 2016 00:30
but the excercise wants to compare number which isnt a function, right?
*numbers
Matt Green
@mattxgreen
Mar 28 2016 00:30
@samii1031 So the objective is to return undefined if a or b is < 0
Zabe Sangary
@zabesangary
Mar 28 2016 00:30
when you want to concatenate a variable or adding string
devonwilson1
@devonwilson1
Mar 28 2016 00:31
@samii1031
can you help me with the counting cards assignment
Shawn Samii
@samii1031
Mar 28 2016 00:31
@devonwilson1 - no sure I made it that far yet, but I'll do what I can
Ramana Venkata
@vramana
Mar 28 2016 00:32
@zabefloyd += is just short hand notation. Can you give an example? Then some one can illustrate better
oloughlinp
@oloughlinp
Mar 28 2016 00:32
@zabefloyd x += 3 is the same as x = x + 3 while just a plus sign is for adding things together how you would normally use the + sign
devonwilson1
@devonwilson1
Mar 28 2016 00:32
im not sure what function to use or statement to use like if statement or shift statement thing
Matt Green
@mattxgreen
Mar 28 2016 00:32
@samii1031 You familiar with logical operators? That should be all you need to solve this one
Shawn Samii
@samii1031
Mar 28 2016 00:33
oh
well that exoains that
*explains that
devonwilson1
@devonwilson1
Mar 28 2016 00:34
@oloughlinp can you help me specifically please
oloughlinp
@oloughlinp
Mar 28 2016 00:34
@devonwilson1 what are you stuck on?
Zabe Sangary
@zabesangary
Mar 28 2016 00:35
ah okay thanks for clearing my confusion
here is an example var anAdjective = "awesome!"; var ourStr = "Free Code Camp is "; ourStr += anAdjective; var someAdjective = "Awesome" + "!"; var myStr = "Learning to code is "; myStr += someAdjective;
applesauce9091
@applesauce9091
Mar 28 2016 00:36
can I have help with Adding a default option in Switch statements? I keep getting "ReferenceError: a is not defined"
Zabe Sangary
@zabesangary
Mar 28 2016 00:36
switch are awesome it makes sense
Ramana Venkata
@vramana
Mar 28 2016 00:37
@zabefloyd Use the ``` to format your code. long lines of code like above are considered harder to read.
Shawn Samii
@samii1031
Mar 28 2016 00:37
@applesauce9091 whats your code look like?
Matt Green
@mattxgreen
Mar 28 2016 00:38
@applesauce9091 post code
Zabe Sangary
@zabesangary
Mar 28 2016 00:38
using mac your code
applesauce9091
@applesauce9091
Mar 28 2016 00:38

function myTest(val) {
var answer = "";
// Only change code below this line
switch (answer) {
case a:
answer = "apple";
break;
case b:
answer = "bird";
break;
case c:
answer = "cat";
break;

default:
   answer = "stuff";

}

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

// Change this value to test
myTest(1);

devonwilson1
@devonwilson1
Mar 28 2016 00:38
really the specifics of how to write this out
@oloughlinp
im not sure what kind of assignment or statement to use
Zabe Sangary
@zabesangary
Mar 28 2016 00:38
lines
devonwilson1
@devonwilson1
Mar 28 2016 00:38
i was starting with an if if else statement at first
Zabe Sangary
@zabesangary
Mar 28 2016 00:38
This message was deleted
applesauce9091
@applesauce9091
Mar 28 2016 00:39
instruction Instructions
Write a switch statement to set answer for the following conditions:
"a" - "apple"
"b" - "bird"
"c" - "cat"
default - "stuff"
Matt Green
@mattxgreen
Mar 28 2016 00:39
@applesauce9091 put "" around a b and c
applesauce9091
@applesauce9091
Mar 28 2016 00:39
tried it @mattxgreen still same thing
Zabe Sangary
@zabesangary
Mar 28 2016 00:40
This message was deleted
devonwilson1
@devonwilson1
Mar 28 2016 00:40
break;
something like that
@oloughlinp what should start with
Matt Green
@mattxgreen
Mar 28 2016 00:40
@applesauce9091 AND switch (val)
(not answer)
oloughlinp
@oloughlinp
Mar 28 2016 00:40
@devonwilson1 you'll want if statements. In words: if the card is 2,3,4,5, or 6, then you will want to add +1 to count. If the card is equal to 7,8, or 9, do nothing to the count otherwise if the card is equal 10, J, Q, K A, subtract 1 from count.
devonwilson1
@devonwilson1
Mar 28 2016 00:41
ok thanks ill try writing that out again
applesauce9091
@applesauce9091
Mar 28 2016 00:41
genius @mattxgreen thanks!!!
CamperBot
@camperbot
Mar 28 2016 00:41
applesauce9091 sends brownie points to @mattxgreen :sparkles: :thumbsup: :sparkles:
:star: 386 | @mattxgreen | http://www.freecodecamp.com/mattxgreen
oloughlinp
@oloughlinp
Mar 28 2016 00:41
@devonwilson1 after you changed the count variable, you will need to decide what to print (the bet or hold in the instructions)
devonwilson1
@devonwilson1
Mar 28 2016 00:41
okay i will
Matt Green
@mattxgreen
Mar 28 2016 00:42
@applesauce9091 np
devonwilson1
@devonwilson1
Mar 28 2016 00:42
so am i writing if var count or if function cc(card)?
Shawn Samii
@samii1031
Mar 28 2016 00:42
@applesauce9091 don't forget case d
oloughlinp
@oloughlinp
Mar 28 2016 00:42
@devonwilson1 I wouldn't use a break, you are thinking of a switch statement that isn't needed on this exercise
devonwilson1
@devonwilson1
Mar 28 2016 00:42
okay
so what am i targeting with the if statement
oloughlinp
@oloughlinp
Mar 28 2016 00:43
Yep, several of them
devonwilson1
@devonwilson1
Mar 28 2016 00:43
var count or function cc(card)
oloughlinp
@oloughlinp
Mar 28 2016 00:44
This message was deleted
This message was deleted

var count = 0;

function cc(card) {
// Only change code below this line
if(card <= 6 .....){
do something to count;
}

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

Micah Bales
@micahbales
Mar 28 2016 00:44
Hi folks! I'm trying to make sure that the input I receive from a text box has no spaces, but my code doesn't seem to be working. Check out line 69 for the critical piece: http://codepen.io/micahbales/pen/ONmXry?editors=0010
Bill
@W8sconsin
Mar 28 2016 00:47
Could someone help with this? ```
// Only change code below this line
function update(id, prop, value) {
  collection[id][prop] = value;
  if (value === "") {
    collection[id][prop].pop();
  }
  return collection;
}

// Alter values below to test your code
update(5439, "artist", "ABBA");
update(2548, "artist", "");
I get "TypeError: collection[id][prop].pop is not a function". What is the correct syntax?
devonwilson1
@devonwilson1
Mar 28 2016 00:49
@oloughlinp this what i got so far

var count = 0;

function cc(card) {
// Only change code below this line
if(card >= 2, 3, 4, 5, 6) {
return "+1";

}
else if (card >= 7, 8, 9) {
return "0";
}
else if (card >= 10, 'J', 'Q', 'K', 'A')
return "-1";

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

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

oloughlinp
@oloughlinp
Mar 28 2016 00:50
@devonwilson1
```
devonwilson1
@devonwilson1
Mar 28 2016 00:50
yes
obviously its wrong not sure how to go about changing this
oloughlinp
@oloughlinp
Mar 28 2016 00:50
var count = 0; function cc(card) { // Only change code below this line if(card >=2 || card<=6) { count++; }
devonwilson1
@devonwilson1
Mar 28 2016 00:51
i do not understand i feel so stupid
oloughlinp
@oloughlinp
Mar 28 2016 00:52
The syntax isn't quite right. You can only compare one thing at a time (like is x>6) and connect the comparisions with a logical connective (or ||, and &&)
devonwilson1
@devonwilson1
Mar 28 2016 00:52
okay so do all the possible card values separately?
oloughlinp
@oloughlinp
Mar 28 2016 00:52
so you can ask if(x is greater than 2, or x is less than 6) if(card>=2 || card<=6)
@devonwilson1 you can combine them in the if statements like the table in the example by using && and or || statements.
Kent
@kenthub
Mar 28 2016 00:54

I'm working on the challenge "Stand in Line" and i'm stuck. Can anyone offer a suggestion as to if I am on the right track using .push() I'm not sure what the challenge wants specifically.

```function queue(arr, item) {
// Your code here

item = arr.push();

return item; // Change this line
}

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

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

Andres Ariel Alvarez-Saucedo
@Andr3sAlv
Mar 28 2016 00:56

Can someone help me figure out why this isn’t running? function bigCC(arr) {
return n.split("").filter(function(e) {
return e != '-';
}).reduce(function(p,n) {
return parseInt(p)+parseInt(n);
}) >= p.split("").filter(function(e) {
return e != '-';
}).reduce(function(p,n) {
return parseInt(p) + parseInt(n);
}) ? n : p; });
}

bigCC(['4916-2600-1804-0530', '4779-252888-3972','4556-4242-9283-2260'])

Kevin Mulligan
@kmulligan
Mar 28 2016 00:58
Going to need someone to explain boolean operators to me. Have no idea, have looked at MDN and W3Schools and scratching my head
oloughlinp
@oloughlinp
Mar 28 2016 00:59
var count = 0;
function cc(card) {
// Only change code below this line
if(card >=2 || card <= 6) {
    count++;
} else if (card <= 9){
   //do nothing to count
} else //no if statement needed, since we covered the rest of the possibilities
   count--;
@devonwilson1
@kmulligan You know how plus, minus, times, divide work? They operate on two numbers, conduct an operation (+,-,*,/), and give you a number in return.
Kevin Mulligan
@kmulligan
Mar 28 2016 01:05
I get AND, OR, NOT logic
I just don't know what the challenge is asking
oloughlinp
@oloughlinp
Mar 28 2016 01:05
@kmulligan sounds good lol
@kmulligan which exercise?
Kevin Mulligan
@kmulligan
Mar 28 2016 01:06
Boo Who
oloughlinp
@oloughlinp
Mar 28 2016 01:06
Ah, not that far yet
Christy Rettger
@ChristyRettger
Mar 28 2016 01:07
I think I'm done with my Random Quote Machine project, anyone want to check it out and give me some feedback please? http://codepen.io/christyrettger/full/xVrdeR/
Kevin Mulligan
@kmulligan
Mar 28 2016 01:08
@ChristyRettger Looks good, you might make the tweet button bigger and have it tweet attribution to the person you are quoting instead of to codepen
oloughlinp
@oloughlinp
Mar 28 2016 01:09
@kmulligan compare the parameter with === true or false is what cocmes to mind when I read it
Christy Rettger
@ChristyRettger
Mar 28 2016 01:09
@kmulligan Does it help if you think about the Boolean as "If true, return true"? Do you have any context for the Boolean you're trying to use?
@kmulligan Thank you for the feedback! I don't really use Twitter, is a tweet supposed to contain a link back to the original page or no? I could take that out but I figured maybe it was like sharing on Facebook and should have the link for who ever sees it to read more. I don't really know what the standard for tweets is though.
CamperBot
@camperbot
Mar 28 2016 01:11
christyrettger sends brownie points to @kmulligan :sparkles: :thumbsup: :sparkles:
:star: 306 | @kmulligan | http://www.freecodecamp.com/kmulligan
Kevin Mulligan
@kmulligan
Mar 28 2016 01:11
@ChristyRettger @oloughlinp I think it it wanting me to use something called object.prototype.valueOf()... what I have works except for two things, which is my guess due to these things called boolean primitives.
function boo(bool) {

  var x = Boolean(bool);

  if (x) {
    return false;
  }

  if (!x) {
    return true;
  }
oloughlinp
@oloughlinp
Mar 28 2016 01:12
@kmulligan Do you understand the difference between a primitive and an object? That's what the exercise is really getting at.
Yan Kozlovskiy
@YanKozlovskiy
Mar 28 2016 01:12
what do we do for the mutation challenge?
function mutation(arr) {
  var a = arr[0].toLowerCase().split("").sort();
  var b = arr[1].toLowerCase().split("").sort();
  if (b.indexOf(a)) {
    return true;
  }
  return false;
}// Go through every character, if a character isn't there return false. Otherwise return true;
mutation(["hello", "hey"]);
Kevin Mulligan
@kmulligan
Mar 28 2016 01:13
@ChristyRettger I mean if you wanted to get fancy you could have it include a link with a shortened URL in it. I can see what you're saying to have it include "Generated from [url to website]" ... only thing is the URL is so long, you only get 140 characters
oloughlinp
@oloughlinp
Mar 28 2016 01:16
@kmulligan that valueOf will turn the argument into a primitive type - you don't want to do that. You just want to see if the argument is a(boolean) primitive type
Christy Rettger
@ChristyRettger
Mar 28 2016 01:17
@kmulligan Yeah that 140 characters is why most of the quotes are cut off and I didn't even put in anything for it to display attribution for the quote. I guess I could do a shorter link but some of the quotes still won't display in full. Generally I think maybe having created a link that changes with the page content was the purpose of the exercise but maybe it's not really a useful button for the content lol. Unless I put "read the rest of the quote here: url..." maybe I'll do it that way. Appreciate the comments! :)
Kevin Mulligan
@kmulligan
Mar 28 2016 01:18
@ChristyRettger I think for the purpose of the challenge you can say you passed, just something to keep in mind
oloughlinp
@oloughlinp
Mar 28 2016 01:18
@kmulligan === compares both type and value, so did:
function boo(bool) {
  // What is the new fad diet for ghost developers? The Boolean.
  return bool === true || bool ===false;
}

boo(null);
Kevin Mulligan
@kmulligan
Mar 28 2016 01:21
@oloughlinp huh. ok
I dunno, I could be slow, but I think that challenge needs a lot better wording
Bartek
@dyczol
Mar 28 2016 01:23
hey campers ! I'm working on Bonfire- Return the largest number. I want to sort through each array and then push index 0 of each sorted array into placeHolder. The following code sorts only through the first array. Any suggestions or hints ?
function largestOfFour (arr){
  var placeHolder = [];
  var largestNumber = 0;
  for(var i in arr){
    for(var j in arr){
      arr[j].sort(function(a, b){return b-a;});
    return arr;
    }
}

}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
oloughlinp
@oloughlinp
Mar 28 2016 01:24
@dyczol here's a hint: should both for loops be the same? they are both iterating on the same thing.
@dyczol and what are you doing with i?
Bartek
@dyczol
Mar 28 2016 01:25
@oloughlinp is it about the second for loop ? maybe
```
for(var j in arr[i]) ??
oloughlinp
@oloughlinp
Mar 28 2016 01:26
Exactly
Theres a little more to it though
Bartek
@dyczol
Mar 28 2016 01:30
ok, the first one makes sense. something with the sort function ? i'm not worrying about pushing the numbers yet. I want to sort all arrays first ....
oloughlinp
@oloughlinp
Mar 28 2016 01:30
This message was deleted
This message was deleted
Bartek
@dyczol
Mar 28 2016 01:34
Currently i have this and it returns [5,4,3,1]
for(var i in arr){
    for(var j in arr[i]){
      arr[i].sort(function(a, b){return b-a;});
    return arr[i];
    }
so the question is how do I sort through the next array..
oloughlinp
@oloughlinp
Mar 28 2016 01:36
Return makes you stop looping and return :)
Bartek
@dyczol
Mar 28 2016 01:38
aha! thank you @oloughlinp
CamperBot
@camperbot
Mar 28 2016 01:38
dyczol sends brownie points to @oloughlinp :sparkles: :thumbsup: :sparkles:
:star: 260 | @oloughlinp | http://www.freecodecamp.com/oloughlinp
Yan Kozlovskiy
@YanKozlovskiy
Mar 28 2016 01:38
where can we get the answers to the challenges?
Christy Rettger
@ChristyRettger
Mar 28 2016 01:39
@dyczol when I get stuck I copy/paste my code into code pen and change all the return's to console.log's to see what parts are actually running and where it's getting stuck... usually it's running fine and a poorly place return is stopping it, then if I think I need return's I change them back one at a time, and keep testing, if it gets stuck then instead of return I needed to assign a variable... so in your code above instead of "return arr[i];" you could store that arr[i] result as a variable for later use. Maybe more of an answer than you were looking for but I've done that a few times when I've meant to have a loop and it didn't seem to be looping.
Kevin Mulligan
@kmulligan
Mar 28 2016 01:42
It is interesting to me to see how different people tackle the same problem
oloughlinp
@oloughlinp
Mar 28 2016 01:43
I do console.log() when I get stuck on the website, and use Firefox's console to see what outputs (F12) instead of codepen
Bartek
@dyczol
Mar 28 2016 01:44
@ChristyRettger thanks! sounds like a great idea , will definitely give it a shot.
CamperBot
@camperbot
Mar 28 2016 01:44
dyczol sends brownie points to @christyrettger :sparkles: :thumbsup: :sparkles:
:star: 289 | @christyrettger | http://www.freecodecamp.com/christyrettger
Elbert Cortez
@trip16661
Mar 28 2016 01:50
function findLongestWord(str) {
  var splittedStr = str.split(" ");
  var longestWord = 0;
  for (a = 0; a < splittedStr.length;a++){
    if(splittedStr[a].length > longestWord.length){
      longestWord = splittedStr;
    }
  }

  return longestWord.length;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
i don't think im doing anything wrong
but nothing is returning
Kevin Mulligan
@kmulligan
Mar 28 2016 01:51
@trip16661 what is the length of longestWord
wait
re-reading challenge
Elbert Cortez
@trip16661
Mar 28 2016 01:52
@kmulligan i initialize it to 0
so it suposed to have just 1
harpoon747
@harpoon747
Mar 28 2016 01:53
Hi Everyone ! Need a little help in the code below
var Car = function() {
  // this is a private variable
  var speed = 10;

  // these are public methods
  this.accelerate = function(change) {
    speed += change;
  };

  this.decelerate = function() {
    speed -= 5;
  };

  this.getSpeed = function() {
    return speed;
  };
};

var Bike = function() {

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

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

var myCar = new Car();

var myBike = new Bike();

myBike.setGear(4);
myBike.getGear();
myBike.setGear(3);
myBike.getGear();
myBike.setGear(1);
myBike.getGear();
Kevin Mulligan
@kmulligan
Mar 28 2016 01:53
@trip16661 No sorry I misread what was going on
@trip16661 in your if statement, when you first do it, my guess is longestWord.length = undefined? since it is set to 0 above, but not 100%. I would remove the .length part from that if statement
Elbert Cortez
@trip16661
Mar 28 2016 01:57
that return 9
which is false so i think i might be doing something wrong
i think it's counting the arrays inside of splittedStr
but it shouldn't
the a is targeting the first array so it should just..
Christy Rettger
@ChristyRettger
Mar 28 2016 02:03
@trip16661 I think you need to decide if longestWord is a length or a string... by initially making it 0 it's like you're going to use it to keep track of the longest length, but then in your if statement it should say: longestWord = splittedStr[a].length, otherwise you're changing longestWord to a string, which then has a .length property to use in the > statement...
Kent
@kenthub
Mar 28 2016 02:11
Anyone able to help with Javascript? Code challenge"Stand in Line".
function queue(arr, item) {
  // Your code here
  var newArray = 
  arr.push(item);
  arr.shift();

  return newArray;  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(queue(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
Elbert Cortez
@trip16661
Mar 28 2016 02:15
@ChristyRettger @kmulligan thanks
CamperBot
@camperbot
Mar 28 2016 02:15
trip16661 sends brownie points to @christyrettger and @kmulligan :sparkles: :thumbsup: :sparkles:
:star: 308 | @kmulligan | http://www.freecodecamp.com/kmulligan
:star: 290 | @christyrettger | http://www.freecodecamp.com/christyrettger
SUSHANTH PATWARI
@suzello
Mar 28 2016 02:17
Anyone able to help with Javascript? Code challenge "Return Largest Numbers in Arrays"

function largestOfFour(arr) {
// You can do this!
for (var i=0; i <= arr.length-1; i++)
{
arr = Math.max.apply(Math, arr[i]); // 306

return arr;
}
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

This message was deleted
harpoon747
@harpoon747
Mar 28 2016 02:20
@kenthub you need to return the removed element only
Kent
@kenthub
Mar 28 2016 02:21
@harpoon747 Thanks, I guess I read to much into it.
CamperBot
@camperbot
Mar 28 2016 02:21
kenthub sends brownie points to @harpoon747 :sparkles: :thumbsup: :sparkles:
:star: 240 | @harpoon747 | http://www.freecodecamp.com/harpoon747
SUSHANTH PATWARI
@suzello
Mar 28 2016 02:28
need help with this please
function largestOfFour(arr) {
  // You can do this!
for (var i=0; i <= arr.length-1; i++)
  {
  arr = Math.max.apply(Math, arr[i]); 


  return arr;
}
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Matt Green
@mattxgreen
Mar 28 2016 02:42
@suzello The goal is to find a single largest number, or 4 numbers?
Pascal T.
@omegga
Mar 28 2016 02:42
@suzello what do you have to do ?
Matt Green
@mattxgreen
Mar 28 2016 02:44
@suzello Well, this will get you an array of 4 (instantiate answer above for loop):
answer.push(Math.max.apply(Math, arr[i]));
If you need 1 answer, you could do the same math on that array, or you could add a a condition to your existing logic
SUSHANTH PATWARI
@suzello
Mar 28 2016 02:47
@mattxgreen i need largest number from each array
*sub array
Artur Sęp
@a-sep
Mar 28 2016 02:48
God morning all :)
SUSHANTH PATWARI
@suzello
Mar 28 2016 02:50
@mattxgreen thank you , got it
CamperBot
@camperbot
Mar 28 2016 02:50
suzello sends brownie points to @mattxgreen :sparkles: :thumbsup: :sparkles:
:star: 387 | @mattxgreen | http://www.freecodecamp.com/mattxgreen
harpoon747
@harpoon747
Mar 28 2016 02:58
Hi Guys ! Stuck in Make Object Properties Private Challenge. Can someone suggest what mistakes I am making in the below code
var Car = function() {
  // this is a private variable
  var speed = 10;

  // these are public methods
  this.accelerate = function(change) {
    speed += change;
  };

  this.decelerate = function() {
    speed -= 5;
  };

  this.getSpeed = function() {
    return speed;
  };
};

var Bike = function() {

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

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

var myCar = new Car();

var myBike = new Bike();

myBike.setGear(4);
myBike.getGear();
myBike.setGear(3);
myBike.getGear();
myBike.setGear(1);
myBike.getGear();
Susan
@susanpv
Mar 28 2016 03:10
hello, I am stuck in the reverse.. am I doing something wrong here?

function reverseString(str) {
var str1= "";
var pos = 0;

for (i=1;i<=str.length;i++)
{
pos = str.Length - i;
str1 += str.substring(pos,1);
}
return str1;
}

reverseString("Howdy");

Yashdeep Hinge
@yashdeeph709
Mar 28 2016 03:13
just start with str.length and i>0 anf fo (str. charAt(i)
Pierre Humberdroz
@phumberdroz
Mar 28 2016 03:13
function chunkArrayInGroups(arr, size) {
  var result = [];
  var test = [];
  arr.forEach (function(element, index, array){
    if(test.length === size){
      result.push(test);
      test = [];
      test.push(element);

    } else {
      test.push(element);
    }
    console.log (test);
    console.log (typeof result);
  });

  return result;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
What is wrong with this ?
https://www.freecodecamp.com/challenges/chunky-monkey the challange
DJ
@qualitymanifest
Mar 28 2016 03:14
@susanpv you have capitalized Length here, length doesn't get capitalized though pos = str.Length - i;. but regardless, you're overcomplicating it
Aknotts
@Aknotts
Mar 28 2016 03:14
// Setup
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line
  switch(val) {
    case "alpha": 
      result = "Adams";
      break;
    case "bravo": 
      result = "Boston";
      break;
    case "charlie": 
      result = "Chicago";
      break;
    case "delta": 
      result = "Denver";
      break;
    case "echo": 
      result = "Easy";
      break;
    case "foxtrot": 
      result = "Frank";
      break;
    case "":
      result = "undefined";
  }

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

// Change this value to test
phoneticLookup("charlie");
Sidharth Kriplani
@sidkrip
Mar 28 2016 03:16
wiki no repeats please
CamperBot
@camperbot
Mar 28 2016 03:16

:point_right: algorithm no repeats please [wiki]

Problem Explanation:

  • This task requires us to look at each possible permutation of a string. This is best done using a recursion function. Being able to build a function which collects all permutations of a string is a common interview question, so there is no shortage of tutorials out there on how to do this, in many different code languages.
  • This task can still be daunting even after watching a tutorial. You will want to send each new use of the function 3 inputs: 1. a new string (or character array) that is being built, 2. a position in your new string that's going to be filled next, and 3. an idea of what characters (more specifically positions) from the original string have yet to be used. The pseudo code will look something like this:

    ```
    var str = ???;
    perm(current position in original string, what's been used in original string, current string build thus far){
    if(current string is finished) {
    print current string;
    }else{
    for(var i = 0; i < str.length; i++) {

    if(str[i] has not been used) {
      put str[i] into the current position;
      mark str[i] as used
      perm(current position in original string, what's been used in original string, current string build thus far)
      unmark str[i] as used because another branch in the tree for i + 1 will still likely use it;
    }

    }
    }
    }
    :pencil: read more about algorithm no repeats please on the FCC Wiki

Pierre Humberdroz
@phumberdroz
Mar 28 2016 03:18
@sidkrip was that for me?
Sidharth Kriplani
@sidkrip
Mar 28 2016 03:18
nope
DJ
@qualitymanifest
Mar 28 2016 03:18
@meat147 the second, full "test" array isn't getting pushed to result because you're only pushing on a fresh run of the loop. by the time that test === ["c", "d"] the forEach loop has ended
@meat147 a simple for loop would be easier
Pierre Humberdroz
@phumberdroz
Mar 28 2016 03:19
@qualitymanifest just saw that too thanks!
CamperBot
@camperbot
Mar 28 2016 03:19
meat147 sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star: 1121 | @qualitymanifest | http://www.freecodecamp.com/qualitymanifest
Pierre Humberdroz
@phumberdroz
Mar 28 2016 03:20
function chunkArrayInGroups(arr, size) {
  var result = [];
  var test = [];
  arr.forEach (function(element, index, array){
    if(test.length === size){
      result.push(test);
      test = [];
      test.push(element);

    } else {
      test.push(element);
    }
    console.log (test);
    console.log (typeof result);
  });
  result.push(test);
  console.log("Final "+ result);
  return result;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
My final result
anthonyjl92
@anthonyjl92
Mar 28 2016 03:36
how do you remove all non-alphanumeric characters in a string?
Stefan Gisi
@stgisi
Mar 28 2016 03:38
@anthonyjl92 http://www.regexr.com/
@anthonyjl92 https://regex101.com/
Andy Morgan
@AndrewRMorgan
Mar 28 2016 03:41
function destroyer(arr) {

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

 var toStay = arguments[0].filter(function(val) {
   for (var x = 0; x < toRemove.length; x++) {
   return val !== toRemove[x];
   }  
 });

return toStay;
}

destroyer([3, 5, 1, 2, 2], 2, 3, 5);
Can someone tell me why the second part of this is only remove 2 from the array?
Stefan Gisi
@stgisi
Mar 28 2016 03:42
@AndrewRMorgan Hold on a sec, I'll take a look at it
Andy Morgan
@AndrewRMorgan
Mar 28 2016 03:43
@stgisi Thanks.
CamperBot
@camperbot
Mar 28 2016 03:43
andrewrmorgan sends brownie points to @stgisi :sparkles: :thumbsup: :sparkles:
:star: 312 | @stgisi | http://www.freecodecamp.com/stgisi
Zara Leventhal
@zaralev
Mar 28 2016 03:48
@JamesPatel37 thank you! sorry for late response :)
CamperBot
@camperbot
Mar 28 2016 03:48
zaralev sends brownie points to @jamespatel37 :sparkles: :thumbsup: :sparkles:
:star: 254 | @jamespatel37 | http://www.freecodecamp.com/jamespatel37
EternityElephant
@EternityElephant
Mar 28 2016 03:48
Hey guys I wa wondering if i could get an explanation for the challenge "Slasher Flick". I'm not sure what it's asking me to do
I thought it was simple but looking at the return values i should be getting im confused
Matt Green
@mattxgreen
Mar 28 2016 03:53
@EternityElephant It's asking you to return the last howMany elements
anthonyjl92
@anthonyjl92
Mar 28 2016 03:53
is there a special regular expression to remove underscores? or is it written like /_/gi?
Matt Green
@mattxgreen
Mar 28 2016 03:53
so, [1,2,3,4,5,6,7,8,9], 3 would be 7,8,9
@anthonyjl92 I believe that works, but if not you can protect it /\_/gi
EternityElephant
@EternityElephant
Mar 28 2016 03:55
ohhh lol alright i gotcha
anthonyjl92
@anthonyjl92
Mar 28 2016 03:55
thank you
Stefan Gisi
@stgisi
Mar 28 2016 03:55
This message was deleted
Matt Green
@mattxgreen
Mar 28 2016 03:55
@anthonyjl92
Stefan Gisi
@stgisi
Mar 28 2016 03:57
@AndrewRMorgan I fixed it and sent it to you in private chat
@AndrewRMorgan With an explanation, you were close though! Good job
@AndrewRMorgan Thanks for letting me help you mwahahahaha
CamperBot
@camperbot
Mar 28 2016 03:58
stgisi sends brownie points to @andrewrmorgan :sparkles: :thumbsup: :sparkles:
:star: 266 | @andrewrmorgan | http://www.freecodecamp.com/andrewrmorgan
Stefan Gisi
@stgisi
Mar 28 2016 03:58
Anyone finished tic-tac-toe yet?
Ramana Venkata
@vramana
Mar 28 2016 03:59
@stgisi Do you need help ??
Stefan Gisi
@stgisi
Mar 28 2016 04:00
@vramana I mean... I'm almost done, just debugging. I don't think you'd wanna loop at the slop I threw together though hahaha. Just curious how long it took you.
Charly
@Ralooe
Mar 28 2016 04:01
hey everyone, i'm really trying to find what i need out of the help chat but updating the record collection has me stuck ... what am i doing wrong ?

```// Setup
var collection = {
2548: {
album: "Slippery When Wet",
artist: "Bon Jovi",
tracks: [
"Let It Rock",
"You Give Love a Bad Name"
]
},
2468: {
album: "1999",
artist: "Prince",
tracks: [
"1999",
"Little Red Corvette"
]
},
1245: {
artist: "Robert Palmer",
tracks: [ ]
},
5439: {
album: "ABBA Gold"
}
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function update(id, prop, value) {

for(id in collection){

 if (value !== ""){

  if (prop !== "tracks"){
      //update or set value of prop
      collection.id[prop] = value;
      break;
  }
  else if(prop === "tracks" || value !== ""){
        //push value onto end of tracks array
        collection.id[prop].push(value);
        break;
        }

  }
  else { 
    // delete that prop
    collection.id[prop] = "";
    break;
  }

}//for loop
return collection;
}

// Alter values below to test your code
update(5439, "artist", "ABBA");

Ramana Venkata
@vramana
Mar 28 2016 04:02
@stgisi I never finished the challenges. Too boring because I know I can do them and I am a bit lazy. I will complete them someday. But I can review your code if you want me to.
Stefan Gisi
@stgisi
Mar 28 2016 04:02
@vramana Okay, hold on a moment
Matt Green
@mattxgreen
Mar 28 2016 04:03
@Ralooe at a glance I see this:
function update(id, prop, value) {
for(id in collection){
@Ralooe You are overwriting id
Charly
@Ralooe
Mar 28 2016 04:04
so how do i loop through the obj?
Stefan Gisi
@stgisi
Mar 28 2016 04:04
@vramana I sent you a private message
Ramana Venkata
@vramana
Mar 28 2016 04:05
@Ralooe I use Object.keys(collection) it returns an array of keys of the object
Matt Green
@mattxgreen
Mar 28 2016 04:05
@Ralooe You can do it like that, but I would use a different var name. I would also declare it locally with var=
@Ralooe That probably isn't your only problem... gimme a min
anthonyjl92
@anthonyjl92
Mar 28 2016 04:06
function palindrome(str) {
  var newstr=str.toLowerCase().replace(/\W+|\_/gi,"");
  var reverse=newstr.split("").reverse().join("");

  if(reverse === newstr){
    return true;
  }
    return false;
}

palindrome("race Car");
Is there a more efficient way to solve palindromes?
Charly
@Ralooe
Mar 28 2016 04:06
@mattxgreen @vramana thnks
CamperBot
@camperbot
Mar 28 2016 04:06
ralooe sends brownie points to @mattxgreen and @vramana :sparkles: :thumbsup: :sparkles:
:star: 229 | @vramana | http://www.freecodecamp.com/vramana
:star: 388 | @mattxgreen | http://www.freecodecamp.com/mattxgreen
Matt Green
@mattxgreen
Mar 28 2016 04:08
@Ralooe You can't access object with a variable name with dot notation... you have to use bracket
so:
DJ
@qualitymanifest
Mar 28 2016 04:09
@anthonyjl92 you don't need the + in your regex since you're using the g flag, and you don't need the i in your regex since everything is lowercase already
@anthonyjl92 that's not a bad solution though
@anthonyjl92 another way to make it shorter would be to just return newstr compared with itself reversed
Matt Green
@mattxgreen
Mar 28 2016 04:10
@Ralooe
collection.id[prop] = value;
// should be:
collection[id][prop] = value;
anthonyjl92
@anthonyjl92
Mar 28 2016 04:10
@qualitymanifest thank you for the tips!
Charly
@Ralooe
Mar 28 2016 04:12
@mattxgreen that + new var in the loop ?
Matt Green
@mattxgreen
Mar 28 2016 04:13
@Ralooe I think that'll get you going... yes I would rename id. This is simple: for (var key in collection)
Charly
@Ralooe
Mar 28 2016 04:13
@mattxgreen k .. i'll try that
V Arun Kumar
@arunvkumr
Mar 28 2016 04:15
@anthonyjl92 you could also do..
function palindrome(str) {
str=str.toLowerCase().replace(/\W|_/gi,"");
  var reverse=str.split("").reverse().join("");
  return (reverse === newstr);
}
palindrome("race Car");
Matt Green
@mattxgreen
Mar 28 2016 04:19
@arunkumrv
function palindrome(str) {
  str = str.toLowerCase().replace(/[^a-z0-9]|\s+|\r?\n|\r/gmi,'');
  return (str == str.split('').reverse().join(''));
}
:p
V Arun Kumar
@arunvkumr
Mar 28 2016 04:20
@mattxgreen your solution is shorter.. but the regexp is lengthy :wink:
Matt Green
@mattxgreen
Mar 28 2016 04:21
I know... your regex is better
I'm declaring what to keep, and you're just throwing away whitespace
anthonyjl92
@anthonyjl92
Mar 28 2016 04:26
function findLongestWord(str) {
  var arr=str.split(" "); //words are split by spaces
  var longest=0; //default longest word length

  for(var i=0;i<arr.length;i++){ //loops through array of words
    if(arr[i].length>longest){ //if current word length is longer
      longest=arr[i].length; //set longest to current word length
    }
  }
  return longest;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
is there way to shorten this? are there better solutions?
Ramana Venkata
@vramana
Mar 28 2016 04:28
@anthonyjl92 There is.
All solutions involve the same computations you are doing here. Some run slower some run faster. Some are terse Some are length.
anthonyjl92
@anthonyjl92
Mar 28 2016 04:33
yea I think that's a big concern of mine. There are multiple solutions to these problems but I want to write code that's short and efficient
Ramana Venkata
@vramana
Mar 28 2016 04:34
@anthonyjl92 Shortest code may not be the most efficient.
Atleast The solution I have in mind will not run faster than what you wrote.
anthonyjl92
@anthonyjl92
Mar 28 2016 04:36
ah I see, is there a program that checks the runtime of solutions?
Ramana Venkata
@vramana
Mar 28 2016 04:37
@anthonyjl92 Runtime will vary. You can try to benchmark your solution us jsperf.com etc., But it's truly not worth it.
The advice I heard is that until you hit a bottleneck. Don't worry about micro-optimizations. Just trust the compiler. If ever you run in trouble, profile your code and optimize the slow parts.
And it worked for all the time.
Jesus Arteaga
@HecticHiccups
Mar 28 2016 04:41
About @vramana
anthonyjl92
@anthonyjl92
Mar 28 2016 04:41
Thank you for the advice!
CamperBot
@camperbot
Mar 28 2016 04:41
:star: 229 | @vramana | http://www.freecodecamp.com/vramana
Andy Roush
@AndyRoush
Mar 28 2016 04:46
Hi guys. I am on this converting lesson, and I honestly have no idea what to do here. If anyone can give me some guidance.... I don't even know where to start =(. https://www.freecodecamp.com/challenges/convert-celsius-to-fahrenheit
Zabe Sangary
@zabesangary
Mar 28 2016 04:47
This message was deleted
Matt Green
@mattxgreen
Mar 28 2016 04:47
@AndyRoush step 1: create a variable called fahrenheit
Jesus Arteaga
@HecticHiccups
Mar 28 2016 04:47
Tf=tc*(9/5)+32
Paul Borawski
@iAmNawa
Mar 28 2016 04:48
hello everyone!
Jesus Arteaga
@HecticHiccups
Mar 28 2016 04:48
That's all @AndyRoush
Zabe Sangary
@zabesangary
Mar 28 2016 04:48
why is it counting from 1? is that because it counts the [] bracket space?
if that make sense
var myArray = [0];
Matt Green
@mattxgreen
Mar 28 2016 04:49
@AndyRoush then assign the fahrenheit var to the return val of the celcius formula
Andy Roush
@AndyRoush
Mar 28 2016 04:49
@HecticHiccups How did you come up with TF and TC?
Kelvin-penang
@Kelvin-penang
Mar 28 2016 04:49
function myFunction() {
var myVar = 'use strict';
console.log(myVar);
}
myFunction();
Can anybody help? I thought I already had no Global variable in here
Andy Roush
@AndyRoush
Mar 28 2016 04:50
@mattxgreen Ok cool. But what does this mean? This is what confuses me - if ( typeof fahrenheit !== 'undefined' ) {
return fahrenheit;
} else {
return 'fahrenheit not defined';
}
}
Kelvin-penang
@Kelvin-penang
Mar 28 2016 04:50
but I still can't pass the test
Ramana Venkata
@vramana
Mar 28 2016 04:51
@zabefloyd Can you rephrase your question?
Jesus Arteaga
@HecticHiccups
Mar 28 2016 04:51
Temperature in Far, temp in celcius @AndyRoush
Zabe Sangary
@zabesangary
Mar 28 2016 04:51
okay
Matt Green
@mattxgreen
Mar 28 2016 04:52
@AndyRoush They are just checking to ensure fahreheit has value before returning it
Jesus Arteaga
@HecticHiccups
Mar 28 2016 04:52
You don't need to change anything else @AndyRoush
And that mean they're making sure it isn't null.
Matt Green
@mattxgreen
Mar 28 2016 04:53
@AndyRoush you don't really need to be concerned with it at the moment. Just assign the correct val to fahrenheit and it'll work
Andy Roush
@AndyRoush
Mar 28 2016 04:54
Ok cool thanks @mattxgreen and @HecticHiccups . I will try and work it out now.
CamperBot
@camperbot
Mar 28 2016 04:54
andyroush sends brownie points to @mattxgreen and @hectichiccups :sparkles: :thumbsup: :sparkles:
:star: 389 | @mattxgreen | http://www.freecodecamp.com/mattxgreen
:star: 204 | @hectichiccups | http://www.freecodecamp.com/hectichiccups
Jesus Arteaga
@HecticHiccups
Mar 28 2016 04:54
No thank you for the brownies.
Andy Roush
@AndyRoush
Mar 28 2016 04:55
np :)
Jesus Arteaga
@HecticHiccups
Mar 28 2016 04:55
I was starving nom nom nom
Zabe Sangary
@zabesangary
Mar 28 2016 04:56
@vramana var myArray = [0, 1, 3];
what is the index of 0?
Kyle Morton
@kmorton1988
Mar 28 2016 04:56
I'm so lost with geolocation.
Idon't know how to use it to display local weather.
or at least I"m not sure where to go next.
Ramana Venkata
@vramana
Mar 28 2016 04:56
@zabefloyd 0
Zabe Sangary
@zabesangary
Mar 28 2016 04:56
use google mam kmorton :D
Kyle Morton
@kmorton1988
Mar 28 2016 04:56
been googling for the past 4 days
still can't wrap my head around it.
Zabe Sangary
@zabesangary
Mar 28 2016 04:57
it is not 1?
thought it is one
Kyle Morton
@kmorton1988
Mar 28 2016 04:57
What?
Ramana Venkata
@vramana
Mar 28 2016 04:57
@zabefloyd Array indices start with 0. You will get used to it.
Zabe Sangary
@zabesangary
Mar 28 2016 04:58
ah okay thought it counts [] the empty space but I guess that only happens if you use quotes?
Kyle Morton
@kmorton1988
Mar 28 2016 04:59
[] inidates that the variable is an array
each item in the array is separated by a comma, such as var array = [1, 2, 3, 4], in this case, the number 1 is at index 0.
Jesus Arteaga
@HecticHiccups
Mar 28 2016 05:00
Hai
Zabe Sangary
@zabesangary
Mar 28 2016 05:01
what if have space [1 , 3 , 5];
Clare Dickerson
@claredickerson
Mar 28 2016 05:01
i really wish i was having an easier time with javascript :( sometimes it makes perfect sense and other times i can't.
Zabe Sangary
@zabesangary
Mar 28 2016 05:02
@claredickerson have you tried http://www.asmarterwaytolearn.com/
that book will help you if you are a beginner like me
Clare Dickerson
@claredickerson
Mar 28 2016 05:02
@zabefloyd i will look at it, thanks
CamperBot
@camperbot
Mar 28 2016 05:02
claredickerson sends brownie points to @zabefloyd :sparkles: :thumbsup: :sparkles:
:star: 56 | @zabefloyd | http://www.freecodecamp.com/zabefloyd
Zabe Sangary
@zabesangary
Mar 28 2016 05:03
it is the top rated book at amazon
Kyle Morton
@kmorton1988
Mar 28 2016 05:06
@zabefloyd I'm not sure what you mean "what if I have space". The array there is pretty simple. index 0 = 1, index 1 = 3, index 2 = 5
Ramana Venkata
@vramana
Mar 28 2016 05:07
@claredickerson Practice a lot. Only writing more JS makes you better. Have you watched any Programming Talks ??
Kyle Morton
@kmorton1988
Mar 28 2016 05:07
@claredickerson I'm right there with you.
Clare Dickerson
@claredickerson
Mar 28 2016 05:07
@vramana i haven't. like a TED talk or some other organization?
Rayner Rodriguez
@raynerjrp
Mar 28 2016 05:07

Why I can't push an element as an array at the end of tracks property in the collection object
var collection = {
2548: {
album: "Slippery When Wet",
artist: "Bon Jovi",
tracks: [
"Let It Rock",
"You Give Love a Bad Name"
]
}
};

collection[2548]["tracks"].push(value);
What I'm doing wrong?

Clare Dickerson
@claredickerson
Mar 28 2016 05:07
@kmorton1988 solidarity and brownie points (thx!)
CamperBot
@camperbot
Mar 28 2016 05:07
claredickerson sends brownie points to @kmorton1988 :sparkles: :thumbsup: :sparkles:
:star: 296 | @kmorton1988 | http://www.freecodecamp.com/kmorton1988
Ramana Venkata
@vramana
Mar 28 2016 05:08
@claredickerson Talks given by software engineers.
Zabe Sangary
@zabesangary
Mar 28 2016 05:08
because it is Bon Jovi lol
Kyle Morton
@kmorton1988
Mar 28 2016 05:08
lol. Wouldn't mind another mind if ever you wanted to joint code sometime @claredickerson
Clare Dickerson
@claredickerson
Mar 28 2016 05:08
@vramana i'll look into it
haha i'll consider it @kmorton1988
Stefan Gisi
@stgisi
Mar 28 2016 05:09
@vramana thanks
CamperBot
@camperbot
Mar 28 2016 05:09
stgisi sends brownie points to @vramana :sparkles: :thumbsup: :sparkles:
Ramana Venkata
@vramana
Mar 28 2016 05:09
@claredickerson Watch this talk https://www.youtube.com/watch?v=hQVTIJBZook There are things to learn but don't worry about them. Just listen to the guy.
CamperBot
@camperbot
Mar 28 2016 05:09
:star: 230 | @vramana | http://www.freecodecamp.com/vramana
Zabe Sangary
@zabesangary
Mar 28 2016 05:10
the weird pars of JavaScript :D https://www.youtube.com/watch?v=Bv_5Zv5c-Ts
Ramana Venkata
@vramana
Mar 28 2016 05:10
I have seen that talk 5 or 6 times but it still feels so awesome to re watch it.
Malviya
@malviyaprateek
Mar 28 2016 05:11
how to solve "Stand in Line" in js
Ramana Venkata
@vramana
Mar 28 2016 05:27
@malviyaprateek What have you tried till now??
Tanner Kiser
@Kiser3613
Mar 28 2016 05:28
Hey guys! I need some help with Nesting For Loops in Javascript!
Ramana Venkata
@vramana
Mar 28 2016 05:28
@Kiser3613 What help do you need?
Tanner Kiser
@Kiser3613
Mar 28 2016 05:29
@vramana Well here is my code. I'm not sure what I'm doing wrong.

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

product = product * a;  

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

product = product * i;
Ramana Venkata
@vramana
Mar 28 2016 05:32
@Kiser3613 Hint: You need to multiply the numbers of the array arr
Just read you program again.
Matt Green
@mattxgreen
Mar 28 2016 05:33
@Kiser3613 you're missing a critical { (if your code is pasted accurately
Tanner Kiser
@Kiser3613
Mar 28 2016 05:33
@mattxgreen I didn't paste very well! Thank you though!
CamperBot
@camperbot
Mar 28 2016 05:33
kiser3613 sends brownie points to @mattxgreen :sparkles: :thumbsup: :sparkles:
:star: 390 | @mattxgreen | http://www.freecodecamp.com/mattxgreen
Tanner Kiser
@Kiser3613
Mar 28 2016 05:33
@vramana Ok, I'll try it out! Thanks!
CamperBot
@camperbot
Mar 28 2016 05:33
kiser3613 sends brownie points to @vramana :sparkles: :thumbsup: :sparkles:
:star: 231 | @vramana | http://www.freecodecamp.com/vramana
Clare Dickerson
@claredickerson
Mar 28 2016 05:38
thanks @vramana i'll watch it!
CamperBot
@camperbot
Mar 28 2016 05:38
claredickerson sends brownie points to @vramana :sparkles: :thumbsup: :sparkles:
:star: 232 | @vramana | http://www.freecodecamp.com/vramana
Ramana Venkata
@vramana
Mar 28 2016 05:40
@claredickerson I highly recommend you do. There may be things you don't understand them. Just listen it as a story.
Abdullah Hoosen
@abdullahhoosen
Mar 28 2016 05:50
thanks @CaroleAnneHannon for your help with Checkpoint: Stand in Line
CamperBot
@camperbot
Mar 28 2016 05:50
abdullahhoosen sends brownie points to @caroleannehannon :sparkles: :thumbsup: :sparkles:
:star: 813 | @caroleannehannon | http://www.freecodecamp.com/caroleannehannon
Olawale Akinseye
@brainyfarm
Mar 28 2016 06:00
@Kiser3613, to access element in your two dimensional array, you do arr[a][i]
Elbert Cortez
@trip16661
Mar 28 2016 06:12
function confirmEnding(str, target) {
  var targetEnding = target.length;
  var ending = str.Substring(str.length -targetEnding);
  if(ending === target){return true;}
  else{return false;}


       // "Never give up and good luck will find you."
  // -- Falcor

}

confirmEnding("Bastian", "n");
here I am again D:
Umesh Kunwar
@umeshku
Mar 28 2016 06:14
palindrome("0_0 (: /-\ :) 0-0") should return true.
How to do this?
palindrome("0_0 (: /-\ : ) 0-0") should return true.
Zabe Sangary
@zabesangary
Mar 28 2016 06:16
This message was deleted
var users = ['rgnet1', 'zabe', 'grae'];
  for (var i = 0; i <= users.length; i++) {
  console.log("There are " + i + " users" );
}
kirbyedy
@kirbyedy
Mar 28 2016 06:17
@umeshku the task says:
You'll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything lower case in order to check for palindromes.
so you will have to use the regex for start
and the method toLowerCase
Zabe Sangary
@zabesangary
Mar 28 2016 06:18
how can I get the output like this
1 rgnet1
2 zabe
3 grae
thanks in advance
Elbert Cortez
@trip16661
Mar 28 2016 06:19
@trip16661 substring in cap D:im an idiot
Ramana Venkata
@vramana
Mar 28 2016 06:19
@zabefloyd It should be console.log(i + 1, users[i])
Zabe Sangary
@zabesangary
Mar 28 2016 06:19
neat!
do you mind if you tell me what is going on here console.log(i + 1, users[i])?
Ramana Venkata
@vramana
Mar 28 2016 06:21
@zabefloyd You wanted to print 1 2 3 the start of each line. which is achieved by console.log(i+1)
Zabe Sangary
@zabesangary
Mar 28 2016 06:21
correct
kirbyedy
@kirbyedy
Mar 28 2016 06:21
@vramana I dont think that will work
There are 01 rgnet1 users
There are 11 zabe users
There are 21 grae users
Zabe Sangary
@zabesangary
Mar 28 2016 06:22
it worked
Ramana Venkata
@vramana
Mar 28 2016 06:22
You wanted to print the names beside those numbers. console.log(i+1, users[i]) or console.log(i + 1 + " " + users[i])
Zabe Sangary
@zabesangary
Mar 28 2016 06:23
that's right yes it worked fine
Ramana Venkata
@vramana
Mar 28 2016 06:23
console.log can take multiple arguments and it will inserts spaces automatically between arguments.
kirbyedy
@kirbyedy
Mar 28 2016 06:23
which one worked
Zabe Sangary
@zabesangary
Mar 28 2016 06:24
the output is
1 "rgnet1"
2 "zabe"
3 "grae"
4 undefined
for (var i = 0; i < users.length; i++) {

console.log(i + 1, users[i] );
}
Ramana Venkata
@vramana
Mar 28 2016 06:25
@zabefloyd it should be i < users.length
Zabe Sangary
@zabesangary
Mar 28 2016 06:25
ah was wondering where the 4 undefined came from
kirbyedy
@kirbyedy
Mar 28 2016 06:28
hmmm why the hell is my output this:
There are 01 rgnet1 users
There are 11 zabe users
There are 21 grae users
with the same code
Zabe Sangary
@zabesangary
Mar 28 2016 06:29
paste your code here?
kirbyedy
@kirbyedy
Mar 28 2016 06:30
var users = ['rgnet1', 'zabe', 'grae'];
  for (var i = 0; i < users.length; i++) {
  console.log("There are " + i+1 + " " + users[i] + " users" );
}
the difference is the text basically
in the log
Zabe Sangary
@zabesangary
Mar 28 2016 06:32
you are adding i + i
var users = ['rgnet1', 'zabe', 'grae'];


for (var i = 1; i < users.length; i++) {

console.log("No" + i + " User Name is" + users[i] );
}
try this
```
var users = ['rgnet1', 'zabe', 'grae'];
  for (var i = 1; i < users.length; i++) {
  console.log("There are " + i+1 + " " + users[i] + " users" );
}
```
Ramana Venkata
@vramana
Mar 28 2016 06:34
@kirbyedy wrap i + 1 in paranthesis (i + 1). Then your code will work.
kirbyedy
@kirbyedy
Mar 28 2016 06:35
its the brackets
tax @vramana
CamperBot
@camperbot
Mar 28 2016 06:36
kirbyedy sends brownie points to @vramana :sparkles: :thumbsup: :sparkles:
:star: 233 | @vramana | http://www.freecodecamp.com/vramana
Zabe Sangary
@zabesangary
Mar 28 2016 06:36
and to count from 1 change it from 0 to 1 , for (var i = 1; i < users.length; i++)
Ramana Venkata
@vramana
Mar 28 2016 06:36
@zabefloyd Then you have use <= instead of < other wise you will miss out one number
Matt Green
@mattxgreen
Mar 28 2016 06:37
@AndyRoush remove the period
Andy Roush
@AndyRoush
Mar 28 2016 06:39
thanks @mattxgreen that worked =)
CamperBot
@camperbot
Mar 28 2016 06:39
andyroush sends brownie points to @mattxgreen :sparkles: :thumbsup: :sparkles:
:star: 391 | @mattxgreen | http://www.freecodecamp.com/mattxgreen
Zabe Sangary
@zabesangary
Mar 28 2016 06:39
ah yes that's right way I rather count from 1
var users = ['rgnet1', 'zabe', 'grae'];
  for (var i = 1; i <= users.length; i++) {
  console.log("There are " + i + " " + users[i] + " users" );
}
Ramana Venkata
@vramana
Mar 28 2016 06:40
@zabefloyd But Since array indexing starts from 0 you have to write users[i -1]
Other you will be trying to read users[3] which is undefined.
@zabefloyd As I said earlier indexing start's with 0. It may feel a little wierd now. You will get used to it.
Zabe Sangary
@zabesangary
Mar 28 2016 06:42
ah didn't see the undefined yes
great thanks!
Ramana Venkata
@vramana
Mar 28 2016 06:44
Your welcome
Zabe Sangary
@zabesangary
Mar 28 2016 06:46
JS < # :D
Zabe Sangary
@zabesangary
Mar 28 2016 06:53
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];

// Only change code below this line.
var myData = myArray[3][0];
the output is undefined
Matt Green
@mattxgreen
Mar 28 2016 06:54
are you looking for 10?
Zabe Sangary
@zabesangary
Mar 28 2016 06:54
anything
any number
Matt Green
@mattxgreen
Mar 28 2016 06:54
[3][0][0] is 10
element [3][0] is an array
Zabe Sangary
@zabesangary
Mar 28 2016 06:55
it says undefined
Matt Green
@mattxgreen
Mar 28 2016 06:55
show me the code in it's entirety
Zabe Sangary
@zabesangary
Mar 28 2016 06:57
that's the all code
Matt Green
@mattxgreen
Mar 28 2016 06:57
you're not returning anything?
Zabe Sangary
@zabesangary
Mar 28 2016 06:58
no is not
Matt Green
@mattxgreen
Mar 28 2016 06:58
what is the objective?
Ramana Venkata
@vramana
Mar 28 2016 06:58
@zabefloyd Which challenge is this ??
Zabe Sangary
@zabesangary
Mar 28 2016 06:58
@vramana Access MultiDimensional Arrays With Indexes
that helps?
cause the url takes the entire page
Islam Ibakaev
@dagman
Mar 28 2016 06:59
maybe you should write return myData?
Zabe Sangary
@zabesangary
Mar 28 2016 07:00
or console.log()?
yes
kirbyedy
@kirbyedy
Mar 28 2016 07:01
you are suppose to find the number 8 no ?
Zabe Sangary
@zabesangary
Mar 28 2016 07:01
return or console
yes
now I will find how to
just wanted know why I get undefined
kirbyedy
@kirbyedy
Mar 28 2016 07:01
so you need to access the third array and second element
Islam Ibakaev
@dagman
Mar 28 2016 07:01
@zabefloyd myData should be equal to 8.
kirbyedy
@kirbyedy
Mar 28 2016 07:01
arrays are 0 based
Islam Ibakaev
@dagman
Mar 28 2016 07:02
@zabefloyd var myData = myArray[2][1];
try this
kirbyedy
@kirbyedy
Mar 28 2016 07:02
@dagman why giving the answer ?
Joseph Stivala
@joestivala
Mar 28 2016 07:03
@zabefloyd I was having a problem understanding it myself earlier, check this video out it helped me https://www.youtube.com/watch?v=Cta5s1QBD8E
Islam Ibakaev
@dagman
Mar 28 2016 07:04
@kirbyedy omg i am answergiver!
:smile:
Zabe Sangary
@zabesangary
Mar 28 2016 07:07
i was trying myArray[2][1][0];
it was close :) thanks guys again!
the third and second element that clears it up
ah cool will watch it @joestivala
Ramana Venkata
@vramana
Mar 28 2016 07:11
@joestivala Quick advice: Don't use document.writeIt is not a good practice.
Joseph Stivala
@joestivala
Mar 28 2016 07:12
@vramana thats a given but the explination about how to setup and understand the arrays is the benefit of the video
Ramana Venkata
@vramana
Mar 28 2016 07:12
Okay
Islam Ibakaev
@dagman
Mar 28 2016 07:13
I WANNA SEE YOUR WEATHER APP
!
Miguel T Rivera
@mtrivera
Mar 28 2016 07:19
wiki cipher
CamperBot
@camperbot
Mar 28 2016 07:19

:point_right: algorithm caesars cipher [wiki]

:triangular_flag_on_post: Remember to use Read-Search-Ask if you get stuck. Try to pair program. :busts_in_silhouette: Write your own code. :memo:

:checkered_flag: Problem Explanation:

  • You need to write a function, which will take string encoded with
    Caesar cipher as a parameter and decode it.
  • The one used here is ROT13 where the value of the letter is
    shifted by 13 places.
    e.g. 'A' ↔ 'N', 'T' ↔ 'G'.
  • You have to shift it back 13 positions, such that 'N' ↔ 'A'.

:pencil: read more about algorithm caesars cipher on the FCC Wiki

Himzo
@himzo-bosnjakovic
Mar 28 2016 07:20
Hi, I need someone that is a javascript expert, I am doing a school project if anyone wants to help PM me please...
Zabe Sangary
@zabesangary
Mar 28 2016 07:23
wiki cipher
CamperBot
@camperbot
Mar 28 2016 07:23

:point_right: algorithm caesars cipher [wiki]

:triangular_flag_on_post: Remember to use Read-Search-Ask if you get stuck. Try to pair program. :busts_in_silhouette: Write your own code. :memo:

:checkered_flag: Problem Explanation:

  • You need to write a function, which will take string encoded with
    Caesar cipher as a parameter and decode it.
  • The one used here is ROT13 where the value of the letter is
    shifted by 13 places.
    e.g. 'A' ↔ 'N', 'T' ↔ 'G'.
  • You have to shift it back 13 positions, such that 'N' ↔ 'A'.

:pencil: read more about algorithm caesars cipher on the FCC Wiki

Trilok reddy
@Trilokreddy007
Mar 28 2016 07:23
has any one solved convert celsius to farenheit
@zabefloyd can u help im not able to solve convert celsius to farenheit
Islam Ibakaev
@dagman
Mar 28 2016 07:24
@Trilokreddy007 click on temperature http://codepen.io/dagman/pen/eZRBeq
@Trilokreddy007
    function toF(celsius) {
        celsius = parseInt(celsius);
        return Math.round((celsius * (9 / 5) + 32)) + '°F';
    }

    function toC(fahrenheit) {
        fahrenheit = parseFloat(fahrenheit);
        return Math.round(((fahrenheit - 32) * (5 / 9))) + '°C';
    }
seasons
@seasonscao
Mar 28 2016 07:27
Excuse me, i have a question. What is the question meaning?
Trilok reddy
@Trilokreddy007
Mar 28 2016 07:28

@dagman function convert(celsius) {
// Only change code below this line

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

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

@seasonscao describe the question
seasons
@seasonscao
Mar 28 2016 07:29
myStr should have the escape sequences for backslash tab tab carriage-return new-line separated by spaces
just output : var myStr = backslash tab tab carriage-return new-line ?
kirbyedy
@kirbyedy
Mar 28 2016 07:30
@seasonscao there is the table on left, which explains
tab is \t for example
so now follow the table, and write what the task asks for
Trilok reddy
@Trilokreddy007
Mar 28 2016 07:30
@kirbyedy can u tell me how to solve challenge 144
kirbyedy
@kirbyedy
Mar 28 2016 07:31
I dont know what is the challenge 144
you can ask a question and I will try to help
seasons
@seasonscao
Mar 28 2016 07:31
@kirbyedy thank you
CamperBot
@camperbot
Mar 28 2016 07:31
seasonscao sends brownie points to @kirbyedy :sparkles: :thumbsup: :sparkles:
:star: 752 | @kirbyedy | http://www.freecodecamp.com/kirbyedy
Trilok reddy
@Trilokreddy007
Mar 28 2016 07:32

@kirbyedy Convert Celsius to Fahrenheitfunction convert(celsius) {
// Only change code below this line

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

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

kirbyedy
@kirbyedy
Mar 28 2016 07:33
@Trilokreddy007 do you know mathematically how to convert celsius to fahrenheit ?
Trilok reddy
@Trilokreddy007
Mar 28 2016 07:33
@kirbyedy nope
Islam Ibakaev
@dagman
Mar 28 2016 07:33
@Trilokreddy007 maybe this
function convert(celsius) {
    if ( typeof celsius !== 'number' ) {
        return 'fahrenheit not defined';
    } 
    return celsius * (9 / 5) + 32; 
}

convert('hello'); // 'fahrenheit not defined'
convert(30); // 86
kirbyedy
@kirbyedy
Mar 28 2016 07:33
Lars
@LarsEum
Mar 28 2016 07:34
Hello everybody, I guess I have a simple question: Im on WayPoint (Nesting For Loops int he basic javascript lessons). There is a multi-dimensional arry, which should be multiplied. My question is about the nested loop, which iterates for the length of arr[i].length. Isnt't arr[i].length equal to the number of parts of the outside array? in this case = 3? [[1,2],[3,4],[5,6,7]] Shouldn`t the iteration go for the length of each inside array?
Islam Ibakaev
@dagman
Mar 28 2016 07:35
@Trilokreddy007 fahrenheit = celsius * (9 / 5) + 32
Trilok reddy
@Trilokreddy007
Mar 28 2016 07:36
@dagman worked like charm thanks alot
CamperBot
@camperbot
Mar 28 2016 07:36
trilokreddy007 sends brownie points to @dagman :sparkles: :thumbsup: :sparkles:
:star: 364 | @dagman | http://www.freecodecamp.com/dagman
Robert Axelsen
@robaxelsen
Mar 28 2016 07:39
help record collection
CamperBot
@camperbot
Mar 28 2016 07:39

:point_right: checkpoint record collection [wiki]

Checkpoint: Record Collection

Instructions

You are given a JSON object representing (a small part of) your record collection. Each album is identified by a unique id number and has several properties. Not all albums have complete information.

Write a function which takes an id, a property (prop), and a value.

For the given id in collection:

If value is non-blank (value !== ""), then update or set the value for the prop.

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

If value is blank, delete that prop.

Always return the entire collection object.

Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.

:pencil: read more about checkpoint record collection on the FCC Wiki

martinturner400
@martinturner400
Mar 28 2016 07:42
hi all, pretty confused with this?! i think it is just the way the question is worded, but what exactly are they asking me to do??
Encode the following sequence, separated by spaces:
backslash tab tab carriage-return new-line and assign it to myStr
am i actually supposed to include these words, or just the escape sequences?
Elbert Cortez
@trip16661
Mar 28 2016 07:45
function truncateString(str, num) {
  var myTruncated =""; 
    if (num <= 3){

      return str.slice(0, num) + "...";
    }else {

      return str.slice(0, num - 3) + "...";
    } 

  // Clear out that junk in your trunk

}

truncateString("A-tisket a-tasket A green and yellow basket", 11);
what am i missing?
martinturner400
@martinturner400
Mar 28 2016 07:47
no worries figured it out, very strangely worded that one though i think!
rouje
@rouje
Mar 28 2016 07:47

@LarsEum

arr = [[1,2],[3,4],[5,6,7]]
//arr.length is 3
//arr[0].length is 2
//arr[1].length is also 2
//arr[2].length is 3

Lars
@LarsEum
Mar 28 2016 07:49
yes. and arr[i] i thought describes the length of the outside loop, which is permanently 3
or is that my mistake?
martinturner400
@martinturner400
Mar 28 2016 07:51
@trip16661 have you called the function?
Islam Ibakaev
@dagman
Mar 28 2016 07:52
@trip16661 i got 'A-tisket...'
Lars
@LarsEum
Mar 28 2016 07:53
Or lets put it another way: Don`t I have to tell the iteration to iterate in arr[0] just two times and for example in arr2 three times
or steps?
ah moment
yes
of course
thanks
:-)
rouje
@rouje
Mar 28 2016 07:54
:+1:
Lars
@LarsEum
Mar 28 2016 07:54
@TreadStone071
mhh,m why didn´t it send browny points?
Clare Dickerson
@claredickerson
Mar 28 2016 07:57
you have to tag the person you're thanking @LarsEum
:D
kirbyedy
@kirbyedy
Mar 28 2016 08:00
@claredickerson thanks
CamperBot
@camperbot
Mar 28 2016 08:00
kirbyedy sends brownie points to @claredickerson :sparkles: :thumbsup: :sparkles:
:star: 197 | @claredickerson | http://www.freecodecamp.com/claredickerson
Clare Dickerson
@claredickerson
Mar 28 2016 08:01
haha no problem
Trilok reddy
@Trilokreddy007
Mar 28 2016 08:02
@dagman once againhere : Escaping Literal Quotes in Strings
var myStr = "I am a \" double quoted \" string inside \"double quotes\".";
out put = "iam a "double quoted" string inside "double quotes "". how can put the extra double quote at the end using backslashes
kirbyedy
@kirbyedy
Mar 28 2016 08:04
@Trilokreddy007 you just need them inside the quote
Islam Ibakaev
@dagman
Mar 28 2016 08:04
@Trilokreddy007 i did that way myStr = "I am a \"double quoted\" string inside \"double quotes\"";
and its works
looks like you made the same
Trilok reddy
@Trilokreddy007
Mar 28 2016 08:08
@dagman it is not working still it printing single " at end
kirbyedy
@kirbyedy
Mar 28 2016 08:10
@Trilokreddy007 paste the exact code
you have to be careful with all the letters
and dots
and spaces
Trilok reddy
@Trilokreddy007
Mar 28 2016 08:11
@kirbyedy var myStr = "I am a \" double quoted \" string inside \"double quotes\"";
kirbyedy
@kirbyedy
Mar 28 2016 08:12
you have extra spaces
"I am a \"double quoted\" string inside \"double quotes\"";
Islam Ibakaev
@dagman
Mar 28 2016 08:13
@Trilokreddy007 var myStr = "I am a \"double quoted\" string inside \"double quotes\".";
Clare Dickerson
@claredickerson
Mar 28 2016 08:19
I've decided to do some Code Avengers javascript tutorials to see if they help me more. I have a better chance of understanding the how if I also understand the why, which they don't always explain here. Anyone else use it? Thoughts?
kirbyedy
@kirbyedy
Mar 28 2016 08:24
@claredickerson is that free or... ?
Clare Dickerson
@claredickerson
Mar 28 2016 08:26
yes! @kirbyedy
lessons 1 and 2 are a little basic but 3 gets fun
kirbyedy
@kirbyedy
Mar 28 2016 08:26
Error: Server Error ughm... :(
but I have to pay
J Player
@Heyjp
Mar 28 2016 08:29
Anything you can use to supplement your learning is good, I haven't used that site personally but if you want to get to grips with the inner workings of javascript https://www.udemy.com/understand-javascript/ is a good resource. I think the first 4 hours are on youtube as well.
John Michael Tubiera
@jmstubiera
Mar 28 2016 08:29
@claredickerso I guess this was the one I tried back then when it was still like playing Zelda however you control the movements by code. Seems the site has been updated though.
Clare Dickerson
@claredickerson
Mar 28 2016 08:40
@Heyjp i'll check it out!
@kirbyedy huh. weird. i googled "learn javascript free" and it was in a list haha. maybe there was a certain url?
oops
try that one
i even set up a profile from there and it never asked my to pay
kirbyedy
@kirbyedy
Mar 28 2016 08:44
ok that one works, tax @claredickerson
CamperBot
@camperbot
Mar 28 2016 08:44
kirbyedy sends brownie points to @claredickerson :sparkles: :thumbsup: :sparkles:
:warning: kirbyedy already gave claredickerson points
kirbyedy
@kirbyedy
Mar 28 2016 08:45
I will give it a try, just for fun :)
Clare Dickerson
@claredickerson
Mar 28 2016 08:45
@jmstubiera there was a little game thing where you moved a tank. it did remind me of zelda a little.
CamperBot
@camperbot
Mar 28 2016 08:45
claredickerson sends brownie points to @jmstubiera :sparkles: :thumbsup: :sparkles:
:star: 137 | @jmstubiera | http://www.freecodecamp.com/jmstubiera
Clare Dickerson
@claredickerson
Mar 28 2016 08:45
ha! apparently it thinks tank is thank. ENJOY YOUR POINT!
@kirbyedy you bet!
kirbyedy
@kirbyedy
Mar 28 2016 08:46
lol
John Michael Tubiera
@jmstubiera
Mar 28 2016 08:46
@claredickerson oh lol tanks tanks tanks
CamperBot
@camperbot
Mar 28 2016 08:46
jmstubiera sends brownie points to @claredickerson :sparkles: :thumbsup: :sparkles:
:star: 198 | @claredickerson | http://www.freecodecamp.com/claredickerson
Clare Dickerson
@claredickerson
Mar 28 2016 08:47
lolol
I ALMOST HAVE 200! CAN I GET 2 MORE TANKS?!
jkjkjk
kirbyedy
@kirbyedy
Mar 28 2016 08:49
you can solve 2 challenges in the fcc map
easy ones
Clare Dickerson
@claredickerson
Mar 28 2016 08:57
I KNOWWWWW lol :)
i'm going to sleep for now
HAVE A GOOD NIGHT ALL! if you kids tweet feel free to find me @clareeewolf. sometimes i'm funny. :) i like to see tweets. no presh.
kirbyedy
@kirbyedy
Mar 28 2016 09:00
night
Robert Axelsen
@robaxelsen
Mar 28 2016 09:10
help Profile Lookup
CamperBot
@camperbot
Mar 28 2016 09:10

:point_right: checkpoint profile lookup [wiki]

Checkpoint: Profile Lookup

Instructions

We have an array of objects representing different people in our contacts lists.

A lookUp function that takes firstName and a property (prop) as arguments has been pre-written for you.

The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.

If both are true, then return the "value" of that property.

If firstName does not correspond to any contacts then return "No such contact"

If prop does not correspond to any valid properties then return "No such property"

Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.

:pencil: read more about checkpoint profile lookup on the FCC Wiki

Mohammedaadem As
@mohamma548
Mar 28 2016 09:15
guys whats wrong with this code

function truncateString(str, num) {
// Clear out that junk in your trunk
if(str.length>num){
return str.slice(0,num-3)+"...";

}
if(num<=3){
return str.slice(0, num) + "...";
}
return str;
}function truncateString(str, num) {
// Clear out that junk in your trunk
if(str.length>num){
return str.slice(0,num-3)+"...";

}
if(num<=3){
return str.slice(0, num) + "...";
}
return str;
}

Catalin Scripcariu
@CatalinScr
Mar 28 2016 09:16
help Make a Person
CamperBot
@camperbot
Mar 28 2016 09:16

:point_right: algorithm make a person [wiki]

Explanation:

When I started the program I figured I just had to create the six functions mentioned in the details. However, it was not that simple. Creating them as a function was not the right way, I had to create them in a different way to make them a key.

There is also a tricky part as you need six keys no more or less, so at first I had the variable that store the original name as a key too which was wrong.

As for the usage of array, that is optional, you could also create new variable to hold the separated string if you wish but an array is easier to deal with as strings are immutable.

Read the instructions carefully, it is always a good hint in itself to run the code and check what the test results were so you know what to expect but do not fixate yourself on that. Once you understand what you need to do, this problem is very easy and straightforward.

:pencil: read more about algorithm make a person on the FCC Wiki

Sonkeng Maldini
@sdmg15
Mar 28 2016 09:18
@camperbot it's how with your algorith explanation?
Trilok reddy
@Trilokreddy007
Mar 28 2016 09:18
@kirbyedy thanks buddy ur were write it doesn't execute properly if it has space it.
CamperBot
@camperbot
Mar 28 2016 09:18
trilokreddy007 sends brownie points to @kirbyedy :sparkles: :thumbsup: :sparkles:
:star: 754 | @kirbyedy | http://www.freecodecamp.com/kirbyedy
Mohammedaadem As
@mohamma548
Mar 28 2016 09:19

function truncateString(str, num) {
// Clear out that junk in your trunk
if(str.length>num){
return str.slice(0,num-3)+"...";

}
if(num<=3){
return str.slice(0, num) + "...";
}
return str;
}

Catalin Scripcariu
@CatalinScr
Mar 28 2016 09:21
@mohamma548 what is the output
help Truncate String
CamperBot
@camperbot
Mar 28 2016 09:21
no wiki entry for: truncate string
Mohammedaadem As
@mohamma548
Mar 28 2016 09:23
@CatalinScr it doest work for smaller strings
eg "A-"
Catalin Scripcariu
@CatalinScr
Mar 28 2016 09:24
one sec
Mohammedaadem As
@mohamma548
Mar 28 2016 09:28
please coders i need help

function truncateString(str, num) {
// Clear out that junk in your trunk
if(str.length>num){
return str.slice(0,num-3)+"...";

}
if(num<=3){
return str.slice(0, num) + "...";
}
return str;
}

what is with this wrong "trunkating a string"
Catalin Scripcariu
@CatalinScr
Mar 28 2016 09:29
@mohamma548 in that case A- has a length of 2
first you must check if num > 3
Mohammedaadem As
@mohamma548
Mar 28 2016 09:30
@CatalinScr ya but did you check the instruction?
Catalin Scripcariu
@CatalinScr
Mar 28 2016 09:31
@mohamma548 yes, look at this:
function truncateString(str, num) {
  // Clear out that junk in your trunk
  if(num<=3){
return str.slice(0,num) + "...";
}
  else {if(str.length>num){
return str.slice(0,num-3)+"...";
}
       }




  return str;
}
Mohammedaadem As
@mohamma548
Mar 28 2016 09:34
@CatalinScr what is the difference then with my code?
Catalin Scripcariu
@CatalinScr
Mar 28 2016 09:37
@mohamma548 you solution was very good, but you must checked first if the num is smaller than 3.
Ayan Bhowmick
@Ayan5
Mar 28 2016 09:37
~~~
var myStr="I am a\"double quoted\"string inside\"double quoted\"";
lpix
@lpix
Mar 28 2016 09:38
This message was deleted
rouje
@rouje
Mar 28 2016 09:38
@Ayan5 you're missing a space
Catalin Scripcariu
@CatalinScr
Mar 28 2016 09:39
@mohamma548 in the case A-, 1 the if checks first if A-.length>1 (and it is ) and return the result ...
Ayan Bhowmick
@Ayan5
Mar 28 2016 09:40
@TreadStone071 where did I missed space?
Catalin Scripcariu
@CatalinScr
Mar 28 2016 09:40
@mohamma548 checking first if num < 3 with this case you return A...
Mohammedaadem As
@mohamma548
Mar 28 2016 09:40
@CatalinScr what about the last case?
Catalin Scripcariu
@CatalinScr
Mar 28 2016 09:40
which one
Mohammedaadem As
@mohamma548
Mar 28 2016 09:40
the last case is a bit different
for num=2
Catalin Scripcariu
@CatalinScr
Mar 28 2016 09:42
@mohamma548 truncateString("Absolutely Longer", 2). In this case when if 2<3 return Ab...
Mohammedaadem As
@mohamma548
Mar 28 2016 09:42
@CatalinScr ya it works thx
CamperBot
@camperbot
Mar 28 2016 09:42
mohamma548 sends brownie points to @catalinscr :sparkles: :thumbsup: :sparkles:
:star: 345 | @catalinscr | http://www.freecodecamp.com/catalinscr
Catalin Scripcariu
@CatalinScr
Mar 28 2016 09:43
@mohamma548 I know that because I tested it. You have understood?
rouje
@rouje
Mar 28 2016 09:50
@Ayan5 also check for spelling. they must exactly match what is required
Sonkeng Maldini
@sdmg15
Mar 28 2016 10:05
when i do this `````javascript var myvar = -1; javascript``````
what does it means really in memory ?
sayan
@sayan1991
Mar 28 2016 10:06
can you help me with this code

function findLongestWord(str) {
var lonfestword = str.split(" ");

var newArray = lonfestword.map(function(val){return val.length;});

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

  if(newArray[i] > max) {
   max = newArray[i];
  } 

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

can not get the longest word in the string
rouje
@rouje
Mar 28 2016 10:19
@sayan1991 your for loop returns max on the first iteration. :smile:
jamesbcn
@jamesbcn
Mar 28 2016 10:23

https://www.freecodecamp.com/challenges/returning-boolean-values-from-functions

"You should not use any if or else statements"

What am I supposed to do here?

lpix
@lpix
Mar 28 2016 10:33
@jamesbcn use boolean to replace the if/else statement
J Player
@Heyjp
Mar 28 2016 10:44
@jamesbcn look at the hints, your answer should be very similar to the second example they give
Alex Tze
@Tze14
Mar 28 2016 10:55
help caesars
CamperBot
@camperbot
Mar 28 2016 10:55

:point_right: algorithm caesars cipher [wiki]

:triangular_flag_on_post: Remember to use Read-Search-Ask if you get stuck. Try to pair program. :busts_in_silhouette: Write your own code. :memo:

:checkered_flag: Problem Explanation:

  • You need to write a function, which will take string encoded with
    Caesar cipher as a parameter and decode it.
  • The one used here is ROT13 where the value of the letter is
    shifted by 13 places.
    e.g. 'A' ↔ 'N', 'T' ↔ 'G'.
  • You have to shift it back 13 positions, such that 'N' ↔ 'A'.

:pencil: read more about algorithm caesars cipher on the FCC Wiki

Brendan Kinahan
@BKinahan
Mar 28 2016 10:56
Pnrfne'f Pvcure, ybgf bs sha
Andreas Alme
@Addibro
Mar 28 2016 10:58
hey you lovely guys, Im having some trouble with Profile Lookup, have a look:
function lookUp(firstName, prop){
// Only change code below this line
for (var i = 0; i < contacts.length; i++) {
  if (contacts[i].firstName == firstName) {
    if (contacts[i].hasOwnProperty (prop)) {
        return contacts[i].prop;

    } else {
      return "No such property";
    }

  } else {
    return "No such contact";

 }
}

// Only change code above this line
}

// Change these values to test your function
lookUp("Akira", "likes");
something Im missing?
Brendan Kinahan
@BKinahan
Mar 28 2016 11:00
@Addibro Looks like you're only checking the first contact before deciding how to return.
Andreas Alme
@Addibro
Mar 28 2016 11:01
@BKinahan loop's not doing what it should you mean?
Brendan Kinahan
@BKinahan
Mar 28 2016 11:03
@Addibro Sort of.. the loop has the correct general structure, but you can only decide that there is no matching contact after the loop has completed, because only then an you know that all of the contacts were checked and none of them match the name.
Andreas Alme
@Addibro
Mar 28 2016 11:05
@BKinahan yeah.. must confess Im a bit confused
Brendan Kinahan
@BKinahan
Mar 28 2016 11:11
@Addibro Okay, step through your code logically:
First step in the loop:
i==0:
if(contacts[0].firstName == firstName) { // if the first contact's name matches
if(contacts[0].hasOwnProperty (prop)){ // if the property is there
return contacts[0].prop;  // there is a slight error here, it should be bracket notation for the variable prop
} else { return "No such property"; // if the property is not in the first contact
}
} else { // if the first contact's name does not match
return "No such contact"; // by this point it is definite that one of the returns is reached, so the loop and function stop, and no other contacts are checked
}
}
}
Andreas Alme
@Addibro
Mar 28 2016 11:15
@BKinahan right.. that make sense, thanks. Not comfortable with the notation rules yet. So, how should one make the loop continue?
CamperBot
@camperbot
Mar 28 2016 11:15
addibro sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star: 1164 | @bkinahan | http://www.freecodecamp.com/bkinahan
Brendan Kinahan
@BKinahan
Mar 28 2016 11:16
@Addibro well, if you move the return "No such contact"; line outside of the for loop, the entire loop will run, and if it doesn't reach any of the return lines within it, the function will keep going after the loop and reach the last return
Andreas Alme
@Addibro
Mar 28 2016 11:18
@BKinahan right, I'll try that, thanks a lot mate
CamperBot
@camperbot
Mar 28 2016 11:18
addibro sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:warning: addibro already gave bkinahan points
Andreas Alme
@Addibro
Mar 28 2016 11:32
@BKinahan hey, I tried this one, but I get "contact is not defined":
for (var i = 0; i < contact.length; i++) {
  if (firstName == contacts[i].firstName) {
    if (contacts[i].hasOwnProperty (prop)) {
      return contacts[i][prop];
    } else {
      return "No such property";
    }
  }
}
return "No such contact";
kirbyedy
@kirbyedy
Mar 28 2016 11:33
you have a typo @Addibro
once you write contact, next time contacts
1 line
Andreas Alme
@Addibro
Mar 28 2016 11:34
@kirbyedy aw shit, thanks man
CamperBot
@camperbot
Mar 28 2016 11:34
addibro sends brownie points to @kirbyedy :sparkles: :thumbsup: :sparkles:
:star: 756 | @kirbyedy | http://www.freecodecamp.com/kirbyedy
Lawrence Archer
@LawrenceArcher
Mar 28 2016 11:35
help falsy bouncer
CamperBot
@camperbot
Mar 28 2016 11:35

:point_right: algorithm falsy bouncer [wiki]

Problem Explanation:

Remove all falsy values from an array.

:pencil: read more about algorithm falsy bouncer on the FCC Wiki

Trilok reddy
@Trilokreddy007
Mar 28 2016 11:53
@kirbyedy hi challenge 148 escape sequences in strings=myStr should have the escape sequences for backslash tab tab carriage-return new-line separated by spaces
Mohammedaadem As
@mohamma548
Mar 28 2016 11:57
hey guys could you help please with this code

function chunkArrayInGroups(arr, size) {
// Break it up.'
var arr1= [];

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

 arr1[i]=arr.slice(i,i+size);

}
return arr1 ;

}

Pascal T.
@omegga
Mar 28 2016 12:00
@mohamma548 try this
arr1.push(arr.slice(i,i+size) );
Trilok reddy
@Trilokreddy007
Mar 28 2016 12:01
@Scriptonaut hi challenge 148 escape sequences in strings=myStr should have the escape sequences for backslash tab tab carriage-return new-line separated by spaces
has anyone has completed challenge 148
Brendan Kinahan
@BKinahan
Mar 28 2016 12:09
@Trilokreddy007 the challenges aren't numbered, there are other ways to get points. Use the challenge title.
@Trilokreddy007 use the table in the instructions to construct a string of the correct escaped characters
anthonygallina1
@anthonygallina1
Mar 28 2016 12:49
@BKinahan hi
Brendan Kinahan
@BKinahan
Mar 28 2016 12:49
@anthonygallina1 howdy
anthonygallina1
@anthonygallina1
Mar 28 2016 12:49
:)
@BKinahan seems preety quiet in here
Colin
@CThor
Mar 28 2016 12:51
I would chat more but I have to be low-key at work :smile:
anthonygallina1
@anthonygallina1
Mar 28 2016 12:51
Hi @CThor
kirbyedy
@kirbyedy
Mar 28 2016 12:51
how is this possible
same code in safari produces 17mil. loops, and in chrome 3mil
anthonygallina1
@anthonygallina1
Mar 28 2016 12:52
@kirbyedy hello :)
kirbyedy
@kirbyedy
Mar 28 2016 12:52
hi
same computer, just a different browser
anthonygallina1
@anthonygallina1
Mar 28 2016 12:53
Hmm would have to look into the source of the 2 browsers
kirbyedy
@kirbyedy
Mar 28 2016 12:53
firefox 5mil
anthonygallina1
@anthonygallina1
Mar 28 2016 12:53
This message was deleted
kirbyedy
@kirbyedy
Mar 28 2016 12:54
function measureLoopSpeed() {
  var count = 0
  function addOne() { count = count + 1 }

  // Date.now() returns a big number representing the number of
  // milliseconds that have elapsed since Jan 01 1970
  var now = Date.now()

  // Loop until Date.now() is 1000 milliseconds (1 second) or more into
  // the future from when we started looping. On each loop, call addOne
  while (Date.now() - now < 1000) addOne()

  // Finally it has been >= 1000ms, so let's print out our total count
  console.log(count)
}

measureLoopSpeed()
same code, different browsers
anthonygallina1
@anthonygallina1
Mar 28 2016 12:55
I believe it
kirbyedy
@kirbyedy
Mar 28 2016 12:55
looks like safari is the fastest... I hate it...
anthonygallina1
@anthonygallina1
Mar 28 2016 12:55
@kirbyedy maybe like the reason flex box doesnt work in all browsers the same
Probably not but I thought I would throw that in there
kirbyedy
@kirbyedy
Mar 28 2016 12:59
:)
Damian
@an0o0nym
Mar 28 2016 12:59
Hi guys, I have the two functions. Function1() returns multi-dimensional array. Function2(arr) as you can see takes an array as a parameter. how can I call Function2 with the result from function1? I tried several ways, i.e.:
Function1(Function2());
var arr = Function2(); Function1(arr);
But anytime I call that Function1 does not seem to get the arr parameter, and thus it is undefined inside it. I know I could do:
Function2(){ var jsonArr = ...//my code...// Function1(jsonArr)};
But is there any other way? SImilar to the first two examples I gave you?
Markus Kiili
@Masd925
Mar 28 2016 13:05
@an0o0nym To call function2 with the return value of function1, do: function2(function1(possible arguments...));
Damian
@an0o0nym
Mar 28 2016 13:10
@Masd925 that is what i tried to do. the function which should receive arguments from the other one does not receive it
Markus Kiili
@Masd925
Mar 28 2016 13:11
@an0o0nym You have to post the code if you wan't more advice.
Damian
@an0o0nym
Mar 28 2016 13:11
maybe I show you my code :
            function getWikiContent(){
                $.getJSON("https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=Java&formatversion=2&callback=?", function(json){
                    console.log("Json output: ");
                    console.log(json);
                    return json;
                }); 
            }
            function appendBox(arrJSON){
                console.log("arrJSON inside appendBox: ");
                console.log(arrJSON);
                return true;
            }

I called it like this:

//1st try
appendBox(getWikiContent());
//2nd try
var arr = getWikiContent(); 
appendBox(arr);
//3nd try
getWikiContent(function(data){
    appendBox(data);
}

But every time the array in appendBox is type of undefined. And it is always called as a first, thus causing this problem.

@Masd925 ^^^
Jalay
@JalaySimaria
Mar 28 2016 13:16
@an0o0nym try removing return true; from appendBox function
Damian
@an0o0nym
Mar 28 2016 13:16
it wasnt previous there, I added it just a sec ago. @JalaySimaria
@JalaySimaria anyways it wont change anything as I do get nothing in console.log
kirbyedy
@kirbyedy
Mar 28 2016 13:19
dont know if this makes any difference
&format=json
this is how I have it
Markus Kiili
@Masd925
Mar 28 2016 13:19
@an0o0nym Is your getWikiContent function returning anything?
kirbyedy
@kirbyedy
Mar 28 2016 13:20
it does, but not the json formatted data
Damian
@an0o0nym
Mar 28 2016 13:20
yes, multi-dim array @Masd925
kirbyedy
@kirbyedy
Mar 28 2016 13:21
try with this: &format=json
instead of that one you have
Damian
@an0o0nym
Mar 28 2016 13:22
@kirbyedy I do have a &format=json
kirbyedy
@kirbyedy
Mar 28 2016 13:22
right, sorry, missed that
Damian
@an0o0nym
Mar 28 2016 13:23
@kirbyedy no worries.
kirbyedy
@kirbyedy
Mar 28 2016 13:24
@an0o0nym can you link your pen
Damian
@an0o0nym
Mar 28 2016 13:25

Everything is working perfectly when I do

getWikiContent(){
//code here
appendBox(json);
}

It does return the console.log line from the appendBox function. My question is how can I do that in the other way, to call appendBox function which is outside getWikiContent(). Is there any way to do that?

I called it like this:

//1st try
appendBox(getWikiContent());
//2nd try
var arr = getWikiContent(); 
appendBox(arr);
//3nd try
getWikiContent(function(data){
    appendBox(data);
}

But every time the array in appendBox is type of undefined. And it is always called as a first, thus causing this problem.

@kirbyedy working on local machine
Jalay
@JalaySimaria
Mar 28 2016 13:27

@an0o0nym here is what you need to do:

function getWikiContent() {
    var obj_variable = $.getJSON("https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=Java&formatversion=2&callback=?", function(json) {
        console.log("1) Json output: ");
        console.log("2) " + json);
        return json;
    });
    return obj_variable;
}

function appendBox(arrJSON) {
    console.log("3) arrJSON inside appendBox: ");
    console.log("4) " + arrJSON);
}

and then execute it like this:

appendBox(getWikiContent());

GIVE IT A TRY !

Damian
@an0o0nym
Mar 28 2016 13:27
Thats all Ive got
$(document).ready(function(){
                $("#searchButton").on("click", function(){
                    $("#feelingLucky").remove();
                    $("#searchForm").animate({
                       margin: "8% auto"
                    },450);
                    //here I try to call my functions
                });
            });

            function getWikiContent(){
                $.getJSON("https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=Java&callback=?", function(json){
                    console.log("Json output: ");
                    console.log(json);
                    return json;
                }); 
            }
            function appendBox(arrJSON){
                console.log("arrJSON inside appendBox: ");
                console.log(arrJSON);
                return true;
            }
@JalaySimaria hang on, will try
@JalaySimaria seems to be working, however what I get is an object. No problem with that at all, but my original question was how to pass an array with the result of function getWIkiContent() to appendBox(arrJSON)
kirbyedy
@kirbyedy
Mar 28 2016 13:34
maybe if you have the wiki call inside the append function ?
just a thought...
Mohammedaadem As
@mohamma548
Mar 28 2016 13:35
what is wrong with this code?

function mutation(arr) {
if(arr.indexOf(arr,0)){
return true;

}

return false;

}

Damian
@an0o0nym
Mar 28 2016 13:37
@kirbyedy yes that would probably work, as I tried the opposite, namely append function inside wiki call.
Jalay
@JalaySimaria
Mar 28 2016 13:38
@an0o0nym since the ajax response of getWIkiContent function is an object, you have to wrap that object into an array and then pass it to appendBox
kirbyedy
@kirbyedy
Mar 28 2016 13:38
I have my wiki call inside the click button
Damian
@an0o0nym
Mar 28 2016 13:40
@JalaySimaria you are right. will try that.
Andreas Alme
@Addibro
Mar 28 2016 13:41
How come I can't use bracket notation on "contacts[i].firstName"? And how come I can't use dot notation on "contacts[i][prop]"?
for (var i = 0; i < contacts.length; i++) {
  if (firstName == contacts[i].firstName) {
    if (contacts[i].hasOwnProperty (prop)) {
      return contacts[i][prop];
    } else {
      return "No such property";
    }
  }
}
return "No such contact";
Jalay
@JalaySimaria
Mar 28 2016 13:41
@mohamma548 in your if condition you don't need to add 2nd argument as 0 as it is 0 by default, but that's not an issue. nothing's wrong with that function. are you facing anything unusual?
Zabe Sangary
@zabesangary
Mar 28 2016 13:42
var ourArray = ["Stimpson", "J", "cat"];
ourArray.shift(); 
ourArray.unshift("Happy");
var ourArray = ["Stimpson", "J", "cat"];
var b = ourArray.pop();
why do you need to assign it to a new variable and when not to? thanks in advance.
Markus Kiili
@Masd925
Mar 28 2016 13:44
@Addibro The dot notation only works if the property key string is a valid JS identifier (for example "12" and "lives left" are not) and you write the key after the dot: var cat={clothes:"pants", "lives left":3}; cat.clothes; //returns "pants". Bracket notation works with keys that can be arbitrary strings cat["lives left"]; //returns 3, variables var key="clothes"; cat[key]; //returns "pants", or expressions cat["lives"+" "+"left"]; //returns 3.
Konrad Turlejski
@Konrad0381
Mar 28 2016 13:45
Can you tell me what I should do?
Zabe Sangary
@zabesangary
Mar 28 2016 13:52
 result = myNoun + " " + myAdjective + " " + myVerb + " " + myAdverb;
Jalay
@JalaySimaria
Mar 28 2016 13:52
@zabefloyd you don't need to assign that .pop method to a new variable unless you use the returned value, from that method, somewhere else in your code. some methods might return value and some might not, it's up to your requirement whether it's useful for you(then save it in variable) or not
Zabe Sangary
@zabesangary
Mar 28 2016 13:53
@Konrad0381 you need to concatenate the result
@JalaySimaria that makes sense thanks!
CamperBot
@camperbot
Mar 28 2016 13:55
zabefloyd sends brownie points to @jalaysimaria :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for jalaysimaria
lpix
@lpix
Mar 28 2016 13:56
function telephoneCheck(str) {
  // Good luck!
 //things to check: parentheses match correctly, begins with 1 if total length is 11, all numbers


  //check matching parentheses
    var p1 = str.indexOf('(');
    var p2 = str.indexOf(')');
  //is there a first parenthesis?
  if((p2!==-1 && p1==-1)||(p1!==-1 && p2==-1)){
    return false;
  }if(p1!==-1 && (p2-p1)!==4){
    return false;
  }

  str = str.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g, "");
  str = str.replace(/\s+/g,"");

  if(str.length<10||str.length>11){
    return false;
  }else {
    if(str[0]!==1){
    return false;
    }
  }
  return true;
}
why is a telephone starting with 1 not recognized as valid?
Konrad Turlejski
@Konrad0381
Mar 28 2016 13:56
Thanks smile:
Arnaud Casamé
@arnaudcasame
Mar 28 2016 13:56
This message was deleted

Can someone help me with the destroyer algorithm? Don't even know where to start since function takes multiple arguments and the callback takes only one argument.

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

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

Andreas Alme
@Addibro
Mar 28 2016 13:57
@Masd925 allright, thanks masd
CamperBot
@camperbot
Mar 28 2016 13:57
addibro sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1243 | @masd925 | http://www.freecodecamp.com/masd925
lpix
@lpix
Mar 28 2016 13:59
@djcase001 this one is tricky..start by separating the array from the numbers Hint: use splice
Josh Bivens
@joshbivens
Mar 28 2016 14:00
Quick question. Can anyone help me?
Arnaud Casamé
@arnaudcasame
Mar 28 2016 14:00
ok, but how do I manage the multiple arguments affair in the callback function????
Jalay
@JalaySimaria
Mar 28 2016 14:00
@djcase001 an idea: you can executing the callback function multiple times. meaning a for loop till the length of the array and execute callback function inside that for loop passing the current indexed array value
Arnaud Casamé
@arnaudcasame
Mar 28 2016 14:00
@lpix ok, but how do I manage the multiple arguments affair in the callback function????
Markus Kiili
@Masd925
Mar 28 2016 14:01
@djcase001 Use arguments object.
Dmytro Bondarenko
@gonardfreeman
Mar 28 2016 14:01
hey guys!
got question about palindrome
lpix
@lpix
Mar 28 2016 14:02
^ What @Masd925 said @djcase001 ..arguments object kind of acts like an array
Jalay
@JalaySimaria
Mar 28 2016 14:02
@joshbivens sure, what is it?
Dmytro Bondarenko
@gonardfreeman
Mar 28 2016 14:03
task says that we need to remove all non-alphabetical characters, but last testcase say that it must return true on this expression palindrome("0_0 (: /-\ :) 0-0")
lpix
@lpix
Mar 28 2016 14:03
@gonardfreeman ask away
Arnaud Casamé
@arnaudcasame
Mar 28 2016 14:03
@Masd925 give me an example. please
Dmytro Bondarenko
@gonardfreeman
Mar 28 2016 14:03
@lpix so it must return true with empty string/list?
lpix
@lpix
Mar 28 2016 14:04
@gonardfreeman have you tried it? with my answer removing non-alphanumerical answers passed the test
Markus Kiili
@Masd925
Mar 28 2016 14:04
@djcase001 You can use arguments[i] and arguments.length to access all the passed arguments.
lpix
@lpix
Mar 28 2016 14:05
@gonardfreeman it worked for me shrugs
Arnaud Casamé
@arnaudcasame
Mar 28 2016 14:05
@Masd925 it's getting a bit clear. but give me an example
Dmytro Bondarenko
@gonardfreeman
Mar 28 2016 14:05
@lpix just start reading, and was confused by it)
negyvenketto
@negyvenketto
Mar 28 2016 14:05
@gonardfreeman yes, you remove all non alphanumerics. so for that example you will check "0000"
Dmytro Bondarenko
@gonardfreeman
Mar 28 2016 14:05
@lpix ok, thank you)
CamperBot
@camperbot
Mar 28 2016 14:05
gonardfreeman sends brownie points to @lpix :sparkles: :thumbsup: :sparkles:
:star: 316 | @lpix | http://www.freecodecamp.com/lpix
Dmytro Bondarenko
@gonardfreeman
Mar 28 2016 14:05
@negyvenketto thanks)
CamperBot
@camperbot
Mar 28 2016 14:05
gonardfreeman sends brownie points to @negyvenketto :sparkles: :thumbsup: :sparkles:
:star: 328 | @negyvenketto | http://www.freecodecamp.com/negyvenketto
lpix
@lpix
Mar 28 2016 14:05
@gonardfreeman np
@djcase001 I converted the arguments into an array then I used splice to seperate the first argument from the rest
Markus Kiili
@Masd925
Mar 28 2016 14:07
@djcase001 for (var i=0; i<arguments.length; i++) {console.log(arguments[i]);} would print all the arguments of a function call.
Arnaud Casamé
@arnaudcasame
Mar 28 2016 14:08
Thanks a lot @Masd925
CamperBot
@camperbot
Mar 28 2016 14:08
djcase001 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1244 | @masd925 | http://www.freecodecamp.com/masd925
lpix
@lpix
Mar 28 2016 14:23
nvm..i got it
Zabe Sangary
@zabesangary
Mar 28 2016 14:26
var myList = [["Mango", 3, "Apple", 4], ["Grapes", 3, "Some", 4], [2, "item", 5, "item"], [2, "item", 5, "item5"]];
console.log(myList);
what is wrong with my code?
instruction
Create a shopping list in the variable myList. The list should be a multi-dimensional array containing several sub-arrays.
Pascal T.
@omegga
Mar 28 2016 14:31
@zabefloyd I guess all subarrays must start with item name then number of item
Zabe Sangary
@zabesangary
Mar 28 2016 14:39
The first element in each sub-array should contain a string with the name of the item. The second element should be a number representing the quantity
that's what it says
DCOSMINC
@DCOSMINC
Mar 28 2016 14:41
function mutation(arr) {
  for(var i = 0; i <arr[1].length;i++ ) {
    if (arr[0].toLowerCase().indexOf(arr[1][i].toLowerCase())!==-1) {
      return true;
    } else {
      return false;
    }
  } 
}
mutation(["hello", "hey"]);
Could someone tell me why the mutation bellow doesn't work with that?>.> everything else does
Theodore P.
@Ierofantis
Mar 28 2016 14:41

I have a problem if anyone could help me I would be nice.

Can I push this somehow to an array?

var newa=[];
var args = Array.prototype.slice.call(arguments);    
var t = args.toString();

I 've made this but It only stores the first number of arguments

  for (var i=0; i<t.length;i++){
  var v= newa.push(t);
  return v ;

  }
Jalay
@JalaySimaria
Mar 28 2016 14:47
@DCOSMINC this is wrong
for(var i = 0; i <arr[1].length;i++ ) {   // arr[1].length should be arr.length
DCOSMINC
@DCOSMINC
Mar 28 2016 14:48
but arr is an array with 2 strings in it
i wanna see the length of the second element
Shouldn't i ? ehm
CodaGirl
@CodaGirl
Mar 28 2016 14:50
Hello can someone explain to me what to they mean by encode the following sequence : backslash tab tab carriage-return new-line?
Mooli
@Mooli88
Mar 28 2016 14:50
hi all, im starting the Show the Local Weather project and the instructions suggest to go to http://openweathermap.org/current#geo for the Open Weather API. but i have no idea how to use it . how to i import this API and and use it ???
Ken Haduch
@khaduch
Mar 28 2016 14:50
@Ierofantis - not sure what you are trying to do, but after that Array.prototype.slice.call(arguments); call, the variable args should be an array?
Vivek
@vivek28111992
Mar 28 2016 14:51
@CodaGirl you should use \ to pass the element given in problem
Ken Haduch
@khaduch
Mar 28 2016 14:51
@CodaGirl - they just mean to make a string and use the code for each character - that is backslash is encoded as \\, tab as \t - the information that they have in the description of the lesson.
separated by spaces, of course.
Theodore P.
@Ierofantis
Mar 28 2016 14:52

@khaduch

 return newa.push(args);

this is what you mean?

CodaGirl
@CodaGirl
Mar 28 2016 14:52
@vivek28111992 @khaduch thank you for the fast response, but i already used this '// \t \t \r \n ' and it turned out to be not correct, am i doing it wrong?
CamperBot
@camperbot
Mar 28 2016 14:52
codagirl sends brownie points to @vivek28111992 and @khaduch :sparkles: :thumbsup: :sparkles:
:star: 809 | @khaduch | http://www.freecodecamp.com/khaduch
:star: 431 | @vivek28111992 | http://www.freecodecamp.com/vivek28111992
Jalay
@JalaySimaria
Mar 28 2016 14:53
@DCOSMINC can you tell me what do you want to accomplish with that function? I'll get a better idea
DCOSMINC
@DCOSMINC
Mar 28 2016 14:53
@JalaySimaria i gotta check if the letters from the second string of the array are in the first string, it works for all the cases except the one that's in the picture
kirbyedy
@kirbyedy
Mar 28 2016 14:56
@CodaGirl you have to use the backslash not the slash, the rest is fine
first 2
pgjones72
@pgjones72
Mar 28 2016 14:58
hey guys. I'm still having issues accessing keys and properties in objects with bracket notation. any help?
function lookUp(firstName, prop){
// Only change code below this line

  for(firstName in contacts){
    for(prop in contacts[firstName]){
      if(contacts[firstName].prop !== ""){
      return firstName[prop];
    }
      else{
        return "No such contact";
      }
    }
  }
Nazgul13
@Nazgul13
Mar 28 2016 14:59
a
Jalay
@JalaySimaria
Mar 28 2016 14:59
@DCOSMINC ok I think this is what happening in your code for the given array
when it starts checking, "h" from hello and "h" from "hey" matches and it'll return true! finish game is over, it returned true and for loop will stop, it won't check for "e" and "y" from "hey".
makes sense?
Brendan Kinahan
@BKinahan
Mar 28 2016 14:59
@pgjones72 if(contacts[firstName].prop !== "") uses dot notation, not bracket notation
Nazgul13
@Nazgul13
Mar 28 2016 14:59
var Car = function(wheels, seats, engines) {
  //Change this constructor
  this.wheels = 4;
  this.seats = 1;
  this.engines = 1;
};

//Try it out here
var myCar=new Car(3,1,2);
anyone know why this doesn't pass?
Markus Kiili
@Masd925
Mar 28 2016 15:00
@pgjones72 The dot notation only works if the property key string is a valid JS identifier (for example "12" and "lives left" are not) and you write the key after the dot: var cat={clothes:"pants", "lives left":3}; cat.clothes; //returns "pants". Bracket notation works with keys that can be arbitrary strings cat["lives left"]; //returns 3, variables var key="clothes"; cat[key]; //returns "pants", or expressions cat["lives"+" "+"left"]; //returns 3.
Vivek
@vivek28111992
Mar 28 2016 15:00
@CodaGirl you dont need //, you only need /
Markus Kiili
@Masd925
Mar 28 2016 15:00
@pgjones72 So .prop doesn't work there.
DCOSMINC
@DCOSMINC
Mar 28 2016 15:01
@JalaySimaria hmm i guess that makes sense...
Mooli
@Mooli88
Mar 28 2016 15:01
guys, do i need to know ajax in order to complete Show the Local Weather ?
DCOSMINC
@DCOSMINC
Mar 28 2016 15:01
@JalaySimaria thanks
CamperBot
@camperbot
Mar 28 2016 15:01
dcosminc sends brownie points to @jalaysimaria :sparkles: :thumbsup: :sparkles:
:star: 49 | @jalaysimaria | http://www.freecodecamp.com/jalaysimaria
Jalay
@JalaySimaria
Mar 28 2016 15:01
@DCOSMINC maybe you should do something like this:
function mutation(arr) {
  for(var i = 0; i <arr[1].length;i++ ) {
    if (arr[0].toLowerCase().indexOf(arr[1][i].toLowerCase())===-1) {
      return false; // keep iterating until it's false
    }
  } 
  return true;  // will return true if length of "hey" exceeds
}
pgjones72
@pgjones72
Mar 28 2016 15:01
@Masd925 [prop] doesn't work either
Brendan Kinahan
@BKinahan
Mar 28 2016 15:02
@pgjones72 for(firstName in contacts) is a confusing use of the for...in syntax
DCOSMINC
@DCOSMINC
Mar 28 2016 15:02
@JalaySimaria oh i see, that makes more sense... thanks
CamperBot
@camperbot
Mar 28 2016 15:02
dcosminc sends brownie points to @jalaysimaria :sparkles: :thumbsup: :sparkles:
:warning: dcosminc already gave jalaysimaria points
pgjones72
@pgjones72
Mar 28 2016 15:03
@BKinahan why?
@BKinahan sorry. I've been stuck here for a week
Matthew Fricker
@mattfricker
Mar 28 2016 15:03
@pgjones72 - can you copy all of your code, including the object you are trying to work on?
pgjones72
@pgjones72
Mar 28 2016 15:03
@mattfricker ok
Brendan Kinahan
@BKinahan
Mar 28 2016 15:03
@pgjones72 you're saying "for each element in contacts, call the current element by the variable firstName and do this with it:"
pgjones72
@pgjones72
Mar 28 2016 15:04
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUp(firstName, prop){
// Only change code below this line

  for(firstName in contacts){
    for(prop in contacts[firstName]){
      if(contacts[firstName][prop] !== ""){
      return firstName[prop];
    }
      else{
        return "No such contact";
      }
    }
  }

// Only change code above this line
}

// Change these values to test your function
lookUp("Akira", "likes");
Brendan Kinahan
@BKinahan
Mar 28 2016 15:04
@pgjones72 that can lead to a monster of a line something like if(firstName.firstName == firstName){... :P
pgjones72
@pgjones72
Mar 28 2016 15:05
@BKinahan sigh. I get the confusion. I'm as confused as the IDE
pgjones72
@pgjones72
Mar 28 2016 15:06
@BKinahan Thanks. I'll check that out
CamperBot
@camperbot
Mar 28 2016 15:06
pgjones72 sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star: 1167 | @bkinahan | http://www.freecodecamp.com/bkinahan
Brendan Kinahan
@BKinahan
Mar 28 2016 15:06
@pgjones72 but in short, using a variable name in a for...in loop that is the same as a parameter of your function should be avoided
Mohammedaadem As
@mohamma548
Mar 28 2016 15:07
what is wrong witrh this code_

function mutation(arr) {
if(arr.indexOf(arr,0)){
return true;

}

return false;

}

Brendan Kinahan
@BKinahan
Mar 28 2016 15:07
@zabefloyd what part are you stuck with?
Zabe Sangary
@zabesangary
Mar 28 2016 15:07
var myList = [[["Mango"], [3]], [["Mango"], [3]], [[2], ["item"], [5]], ["item"]], [[2], ["item"], [5], ["item5"]]];
console.log(myList[0]);
here is m code, stuck on the order of arrays
Jalay
@JalaySimaria
Mar 28 2016 15:08

@pgjones72 prop is an argument here

function lookUp(firstName, prop){

and you're using that as a variable here

for(prop in contacts[firstName]){ // use something else, not prop
Brendan Kinahan
@BKinahan
Mar 28 2016 15:08
@mohamma548 arr.indexOf(arr) asks where arr is within arr, which is possibly only useful for detecting circular references
@zabefloyd the elements of your subarrays are each arrays with 1 element; they should instead simply be either strings or numbers
@zabefloyd e.g. "Mango" instead of ["Mango"]
pgjones72
@pgjones72
Mar 28 2016 15:11
on a completely unrelated note, my chat box will only work in a seperate window now. Is there a reason for this?