These are chat archives for FreeCodeCamp/HelpJavaScript

26th
Aug 2016
Joseph Parkton
@hippybear
Aug 26 2016 00:00
I 'think' its because constructors dont actually modify your object?
also why its better to use prototypes instead of native code
Om Agarwal
@om00webdeveloper
Aug 26 2016 00:01
collection[id][prop] = value; is not working in challenge: Reccord Collection
Tracey King
@TraceyK14
Aug 26 2016 00:01
How would It prevent modifying the object?
Om Agarwal
@om00webdeveloper
Aug 26 2016 00:02
please help
Stephen James
@sjames1958gm
Aug 26 2016 00:02
@OmAgarwal2002 What does your code look like (leave the collection object off)
Joseph Parkton
@hippybear
Aug 26 2016 00:02
@TraceyK14 constructors dont actually change the values in an obj
Om Agarwal
@om00webdeveloper
Aug 26 2016 00:02

// 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 updateRecords(id, prop, value) {

collection[id][prop] = value;

return collection;
}

// Alter values below to test your code
updateRecords(5439, "tracks", "");

David Beczuk
@dbeczuk
Aug 26 2016 00:03
@stonefmagiecurata so is this better? return arr.filter(function (val) {return Boolean(val);});
Tracey King
@TraceyK14
Aug 26 2016 00:04
@hippybear Ahh ok, I will need to look more into constructors it seems. Think you for pointing me in the right direction.
Stephen James
@sjames1958gm
Aug 26 2016 00:04
@OmAgarwal2002 that should set the tracks property to an empty string.
stonefmagiecurata
@stonefmagiecurata
Aug 26 2016 00:04
@dbeczuk it does the same thing
Om Agarwal
@om00webdeveloper
Aug 26 2016 00:04
Yeah that doesnt really matter, but I'm trying to do what the challenge says but it just isnt working @sjames1958gm
Joseph Parkton
@hippybear
Aug 26 2016 00:05
@TraceyK14 @sjames1958gm would know better
Stephen James
@sjames1958gm
Aug 26 2016 00:05
@OmAgarwal2002 The challenge says if value == "" then delete the property
stonefmagiecurata
@stonefmagiecurata
Aug 26 2016 00:05
@dbeczuk I don;t know which one is better, I would say just go with whatever looks clearer to you
Om Agarwal
@om00webdeveloper
Aug 26 2016 00:05
value of what though? @sjames1958gm
David Beczuk
@dbeczuk
Aug 26 2016 00:06
@stonefmagiecurata well now I understand better what Boolean() does. So it makes more sense to me than my porevious code.
previous*
stonefmagiecurata
@stonefmagiecurata
Aug 26 2016 00:06
@dbeczuk then go with that one
David Beczuk
@dbeczuk
Aug 26 2016 00:07
@stonefmagiecurata okay, thanks.
CamperBot
@camperbot
Aug 26 2016 00:07
dbeczuk sends brownie points to @stonefmagiecurata :sparkles: :thumbsup: :sparkles:
:warning: dbeczuk already gave stonefmagiecurata points
stonefmagiecurata
@stonefmagiecurata
Aug 26 2016 00:07
@dbeczuk thanks, have a good rest :D
CamperBot
@camperbot
Aug 26 2016 00:07
stonefmagiecurata sends brownie points to @dbeczuk :sparkles: :thumbsup: :sparkles:
:cookie: 255 | @dbeczuk |http://www.freecodecamp.com/dbeczuk
Om Agarwal
@om00webdeveloper
Aug 26 2016 00:07
thanks @revisualize
CamperBot
@camperbot
Aug 26 2016 00:07
omagarwal2002 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 1741 | @revisualize |http://www.freecodecamp.com/revisualize
Eric Bomblatus
@erbombla
Aug 26 2016 00:20
Can someone help? I don't understand increment (++_
Stephen James
@sjames1958gm
Aug 26 2016 00:21
@erbombla The increment operator x++ is essentially x = x + 1
@erbombla There are some subtleties with ++x and x++ when they are part of an expression.
Eric Bomblatus
@erbombla
Aug 26 2016 00:22
Ok, so if
Stephen James
@sjames1958gm
Aug 26 2016 00:22
@erbombla ++x will increment x prior to the operation and x++ after.
Eric Bomblatus
@erbombla
Aug 26 2016 00:23
var myVar = 66;
then
```
mVar = 65++;
Stephen James
@sjames1958gm
Aug 26 2016 00:24
@erbombla ++ only works on a variable not a constant
aushakov95
@aushakov95
Aug 26 2016 00:25
@erbombla
var myVar = 66;
myVar++; // myVar is now 67
Andrew Kay
@andrewjkay
Aug 26 2016 00:25
I'm stuck on title case a sentence. I can get all the strings capitalized, but not in the same array to join them again. Here's my code; haven't written the joining part yet since this part is still broken
function titleCase(str) {
  var strArray = str.split(' ');
    for(i = 0; i <= strArray.length;i++) {
      function capsFirst(string) {
        var capsArray = [];
        return string.charAt(0).toUpperCase() + string.slice(1);
        capsArray.push(string);
      };
   };
};
Stephen James
@sjames1958gm
Aug 26 2016 00:26
@andrewjkay When do you call capsFirst? Also how would you push on caps array after the return?
JoeShepard1
@JoeShepard1
Aug 26 2016 00:26
I got a little further in my update records challenge
Andrew Kay
@andrewjkay
Aug 26 2016 00:26
just realized I forgot to call it
JoeShepard1
@JoeShepard1
Aug 26 2016 00:26
fixed the condition now i have a undefined error
Andrew Kay
@andrewjkay
Aug 26 2016 00:26
I'll try to move the return
Eric Bomblatus
@erbombla
Aug 26 2016 00:28
@aushakov95 oh, so in this instance i = myVar.
Stephen James
@sjames1958gm
Aug 26 2016 00:28
@erbombla Exactly
Andrew Kay
@andrewjkay
Aug 26 2016 00:28
function titleCase(str) {
  var strArray = str.split(' ');
    for(i = 0; i <= strArray.length;i++) {
      function capsFirst(string) {
        var capsArray = [];
        string.charAt(0).toUpperCase() + string.slice(1);
        capsArray.push(string);
        return capsArray
      };
      capsFirst(strArray[i]);
   };
};

console.log(titleCase("I'm a little tea pot"));
now it just does nothing (console stuff because I'm not using the fcc editor and I want to see what's happening)
JoeShepard1
@JoeShepard1
Aug 26 2016 00:29
 if (prop != "tracks" && value !== "") {
    collection[id][prop] = value;
  }
  else if (prop == "tracks" && collection.hasOwnProperty("tracks")) {
    collection[id][prop] = [];
    collection[id][prop].push(value);
  }
  else if (prop == "tracks" && value !== ""){
    collection[id][prop].push(value);
    }
  else if (value === "") {
    delete collection[id][prop];
  }
Stephen James
@sjames1958gm
Aug 26 2016 00:29
@andrewjkay So capsFirst is creating and array which you throw away
@andrewjkay Maybe capsArray is defined outside of the function and you push the result of the function call?
JoeShepard1
@JoeShepard1
Aug 26 2016 00:29
it is throwing an undefined error for 'push' under else if - collection.hasOwnProperty
Andrew Kay
@andrewjkay
Aug 26 2016 00:29
@sjames1958gm I'm trying to return that array and I'm not sure what's wrong here
aushakov95
@aushakov95
Aug 26 2016 00:30
Having a bit of problem with geolocation for the Local Weather site; everything else works good.
When I assign a variable to a longitude/latitude - the variable does not retain the data for some reason, so that prevents me from using these variables later on in my code. Tried looking this problem up on google, but there isn’t much out there on geolocation. So here is my code for assigning the variables:
var myLat;
 var myLong;
  if (navigator.geolocation){
        navigator.geolocation.getCurrentPosition(function(position){
      myLat = position.coords.latitude;
      myLong = position.coords.longitude;
    });
  }
Stephen James
@sjames1958gm
Aug 26 2016 00:30
@andrewjkay You return it but the call to the function does assign the return value
Andrew Kay
@andrewjkay
Aug 26 2016 00:30
@sjames1958gm that will work? when I tried it didn't seem like a global var for some reason
ooh ok
Stephen James
@sjames1958gm
Aug 26 2016 00:30
@andrewjkay Not a global, still inside your outer functoin.
@aushakov95 You are trying to use myLat and myLong after the getCurrentPosition call?
aushakov95
@aushakov95
Aug 26 2016 00:31
@sjames1958gm Yes. getCurrentPosition(function(position){….
Stephen James
@sjames1958gm
Aug 26 2016 00:32
@aushakov95 getCurrentPosition is asynchronous and the values are not available until after the current code continues.
You need to use those values in the getCurrentPosition callback.
@aushakov95 Or call a function within the callback (passing the lat/long to the function)
Andrew Kay
@andrewjkay
Aug 26 2016 00:32
function titleCase(str) {
  var capsArray = [];
  var strArray = str.split(' ');
    for(i = 0; i <= strArray.length;i++) {
      function capsFirst(string) {
        string.charAt(0).toUpperCase() + string.slice(1);
        capsArray.push(string);
        return capsArray
      };
      capsFirst(strArray[i]);
   };
  return capsArray
};

console.log(titleCase("I'm a little tea pot"));
aushakov95
@aushakov95
Aug 26 2016 00:33
@sjames1958gm Thanks!
CamperBot
@camperbot
Aug 26 2016 00:33
aushakov95 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2859 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Andrew Kay
@andrewjkay
Aug 26 2016 00:33
still nothing
this is terrible code tbh but I don't know a better way to do it
Stephen James
@sjames1958gm
Aug 26 2016 00:33
@andrewjkay You really don't need the function.
Andrew Kay
@andrewjkay
Aug 26 2016 00:34
@sjames1958gm not sure how else to make it work
Stephen James
@sjames1958gm
Aug 26 2016 00:34
@andrewjkay Also, string.charAt(0).toUpperCase() + string.slice(1); this doesn't change string but creates a new string.
Andrew Kay
@andrewjkay
Aug 26 2016 00:34
This message was deleted
This message was deleted
Stephen James
@sjames1958gm
Aug 26 2016 00:34
@andrewjkay
        capsArray.push(string.charAt(0).toUpperCase() + string.slice(1));
Andrew Kay
@andrewjkay
Aug 26 2016 00:35
i'll try using that
Stephen James
@sjames1958gm
Aug 26 2016 00:35
@andrewjkay That can be the only thing in your for loop (no function needed)
replace string with strArray[i]
Nicolas Nielsen
@niconielsen
Aug 26 2016 00:37
// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};
function checkObj(checkProp) {
// Your Code Here
if (myObj.hasOwnProperty(checkProp)){
return myObj.checkProp;
}else{
return "Not found";
}
}
// Test your code by modifying these values
checkObj("gift");
cld\\c\
Andrew Kay
@andrewjkay
Aug 26 2016 00:37
@sjames1958gm I see what you mean, one second I'll set it up
Nicolas Nielsen
@niconielsen
Aug 26 2016 00:37
Hi. Does anyone see the error?
Stephen James
@sjames1958gm
Aug 26 2016 00:37
@niconielsen On a recent lesson you should have learned that dot notation doesn't work with variables.
Nicolas Nielsen
@niconielsen
Aug 26 2016 00:38
thanks Stephen!
Andrew Kay
@andrewjkay
Aug 26 2016 00:40
@sjames1958gm that works, but only if I console log inside the for loop
but capsArray should be available to everything inside the function right?
Stephen James
@sjames1958gm
Aug 26 2016 00:40
@andrewjkay yes. let's see
Andrew Kay
@andrewjkay
Aug 26 2016 00:40
function titleCase(str) {
  var capsArray = [];
  var strArray = str.split(' ');
    for(i = 0; i <= strArray.length;i++) {
        capsArray.push(strArray[i].charAt(0).toUpperCase() + strArray[i].slice(1));
      };
  console.log(capsArray);
   };

titleCase("I'm a little tea pot");
Stephen James
@sjames1958gm
Aug 26 2016 00:41
@andrewjkay So now you have to join capsArray and return?
Andrew Kay
@andrewjkay
Aug 26 2016 00:41
this way logs nothing, inside the for loop it logs five lines, like this: [I'm] [I'm A] [I'm A Little] etc
@sjames1958gm do I join it inside the for loop though?
Stephen James
@sjames1958gm
Aug 26 2016 00:42
@andrewjkay Outside when you return.
Andrew Kay
@andrewjkay
Aug 26 2016 00:42
right now it doesn't return anything if I try to access outside the for loop
Stephen James
@sjames1958gm
Aug 26 2016 00:43
@andrewjkay You have one slight error in your for loop which is causing it to bail, which is why you don't see the console.log.
Om Agarwal
@om00webdeveloper
Aug 26 2016 00:43

// 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 updateRecords(id, prop, value) {

if (value === "") {
delete collection[id][prop];
}
else if (prop != "tracks" && value !== '') {
collection[id].artist = value;
}
else if (prop == "tracks" && collection.hasOwnProperty("tracks") === true) {
collection[id].tracks = [];
}
else if (prop == "tracks" && collection.hasOwnProperty("tracks") === false) {
collection[id].tracks.push(value);
}
return collection;
}

// Alter values below to test your code
updateRecords(5439, "tracks", "Take a Chance on Me");

Andrew Kay
@andrewjkay
Aug 26 2016 00:43
ok I'll check it out thanks
Om Agarwal
@om00webdeveloper
Aug 26 2016 00:43
not working
Andrew Kay
@andrewjkay
Aug 26 2016 00:44
@sjames1958gm thanks, I'll be back I'm sure :smile:
CamperBot
@camperbot
Aug 26 2016 00:44
andrewjkay sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2860 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 26 2016 00:44
@andrewjkay If you can fix that and return the joined array - :checkered_flag:
Om Agarwal
@om00webdeveloper
Aug 26 2016 00:44

// 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 updateRecords(id, prop, value) {

if (value === "") {
delete collection[id][prop];
}
else if (prop != "tracks" && value !== '') {
collection[id].artist = value;
}
else if (prop == "tracks" && collection.hasOwnProperty("tracks") === true) {
collection[id].tracks = [];
}
else if (prop == "tracks" && collection.hasOwnProperty("tracks") === false) {
collection[id].tracks.push(value);
}
return collection;
}

// Alter values below to test your code
updateRecords(5439, "tracks", "Take a Chance on Me");

not working
Stephen James
@sjames1958gm
Aug 26 2016 00:44
@OmAgarwal2002 while this may work for the tests collection[id].artist = value; this should use [prop] not .artist
@OmAgarwal2002 How is it not working.
@OmAgarwal2002 This code is saying if there is no property tracks then I will push onto a non-existant array
else if (prop == "tracks" && collection.hasOwnProperty("tracks") === false) {
collection[id].tracks.push(value);
Om Agarwal
@om00webdeveloper
Aug 26 2016 00:45
ok thanks @sjames1958gm , but the problem still doesnt go away
CamperBot
@camperbot
Aug 26 2016 00:45
omagarwal2002 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2861 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 26 2016 00:47

@OmAgarwal2002 This code is saying if I have a tracks property then I'll just set it to the empty array.

else if (prop == "tracks" && collection.hasOwnProperty("tracks") === true) {
collection[id].tracks = [];

Also every reference should be collection[id]

JoeShepard1
@JoeShepard1
Aug 26 2016 00:47
i am having the same problem
Om Agarwal
@om00webdeveloper
Aug 26 2016 00:47
yes
thats what the instructions say dot they? @sjames1958gm
*don't
Stephen James
@sjames1958gm
Aug 26 2016 00:48
@OmAgarwal2002 If the property exists - then push, if the property doesn't exist then create and empty array then push onto it
JoeShepard1
@JoeShepard1
Aug 26 2016 00:48
```
 if (prop != "tracks" && value !== "") {
    collection[id][prop] = value;
  }
  else if (prop == "tracks" && collection.hasOwnProperty("tracks")) {
    collection[id][prop] = [];
    collection[id][prop].push(value);
  }
  else if (prop == "tracks" && value !== ""){
    collection[id][prop].push(value);
    }
  else if (value === "") {
    delete collection[id][prop];
  }
```
Om Agarwal
@om00webdeveloper
Aug 26 2016 00:48
the error that it is giving me right now is :smile:
[prop]
Stephen James
@sjames1958gm
Aug 26 2016 00:48
@OmAgarwal2002 it should be collection[id].hasOwnProperty
@JoeShepard1 You are doing the same, when it has the property you are reinitializing it to [] and pushing.
Om Agarwal
@om00webdeveloper
Aug 26 2016 00:50
@sjames1958gm it tried collection[id].hasOwnProperty
Stephen James
@sjames1958gm
Aug 26 2016 00:50
@JoeShepard1 And it should be collection[id].hasOwnProperty
Om Agarwal
@om00webdeveloper
Aug 26 2016 00:50
but no difference
Stephen James
@sjames1958gm
Aug 26 2016 00:50
@OmAgarwal2002 Your conditions are backwards.
@JoeShepard1 collection.hasOwnProperty("tracks") if you make this !collection[id].hasOwnProperty("tracks")
@OmAgarwal2002 if collection[id].hasOwnProperty this is true then push
Om Agarwal
@om00webdeveloper
Aug 26 2016 00:53
ok
tried it, nothing happens

function updateRecords(id, prop, value) {

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

// Alter values below to test your code
updateRecords(5439, "tracks", "Take a Chance on Me");

JoeShepard1
@JoeShepard1
Aug 26 2016 00:53
I fixed it with the [id] and it is re-intializing because it is true
Stephen James
@sjames1958gm
Aug 26 2016 00:54
@JoeShepard1 Did you put the ! to negate the test?
JoeShepard1
@JoeShepard1
Aug 26 2016 00:54
collection[id].hasOwnProperty("tracks") === false)
Stephen James
@sjames1958gm
Aug 26 2016 00:54
@OmAgarwal2002 If prop is "tracks" and value isn't empty (""), push the value onto the end of the album's existing tracks array.
@JoeShepard1 That should do it.
@OmAgarwal2002 Swap your true and false
JoeShepard1
@JoeShepard1
Aug 26 2016 00:54
I did not know what that was when I was searching for posted problem solutions :/ duh
I saw ! on the front-end and completely looked it over..would of saved me plenty of time..thanks James
Stephen James
@sjames1958gm
Aug 26 2016 00:55
@JoeShepard1 oops on my part
JoeShepard1
@JoeShepard1
Aug 26 2016 00:56
That's not on you man. I spent a good time looking over others code and did not spot that subtle difference. I realized I should make it false, but for future ref will use !
others'
Om Agarwal
@om00webdeveloper
Aug 26 2016 00:57

@sjames1958gm my error is
Type Error: Cannot read property 'push' of undefined

can you post your final code?
@JoeShepard1

it would be great help

Stephen James
@sjames1958gm
Aug 26 2016 00:57
@OmAgarwal2002 Let me see
JoeShepard1
@JoeShepard1
Aug 26 2016 00:58
function updateRecords(id, prop, value) {
  if (prop != "tracks" && value !== "") {
    collection[id][prop] = value;
  }
  else if (prop == "tracks" && collection[id].hasOwnProperty("tracks") === false) {
    collection[id][prop] = [];
    collection[id][prop].push(value);
  }
  else if (prop == "tracks" && value !== ""){
    collection[id][prop].push(value);
    }
  else if (value === "") {
    delete collection[id][prop];
  }






  return collection;
}
Om Agarwal
@om00webdeveloper
Aug 26 2016 00:58
please, Im very frustrated with thus
Yeyo Selso Poche
@Naxell
Aug 26 2016 00:59
i need some help in Testing Objects for Properties....i have not clue what to do ...some hints are welcome
Stephen James
@sjames1958gm
Aug 26 2016 00:59
@JoeShepard1 look how the logic is simplified, just by putting value === "" first
function updateRecords(id, prop, value) {
  if (value === "") {
    delete collection[id][prop];
  }
  else if (prop != "tracks") { // We know here that value !== ""
    collection[id][prop] = value;
  }
  else if (collection[id].hasOwnProperty("tracks")) { // We know here that prop === "tracks"
    collection[id].tracks.push(value);
  }
  else  { // the only condition left here is "tracks", value != "" and no property
    collection[id][prop] = [];
    collection[id][prop].push(value);
  }
return collection;
}
JoeShepard1
@JoeShepard1
Aug 26 2016 00:59
I say damn these objects lol. I spent way too much time on this, but in the end am so much better for it
Om Agarwal
@om00webdeveloper
Aug 26 2016 01:00
thanks a lot
Andrew Kay
@andrewjkay
Aug 26 2016 01:01
@sjames1958gm still stuck on this loop
Stephen James
@sjames1958gm
Aug 26 2016 01:01
@andrewjkay Did you see <= length should be < length?
JoeShepard1
@JoeShepard1
Aug 26 2016 01:02
@sjames1958gm that looks hell of a lot simpler..I am still stuck on following instructions mode vs making life easier mode
Andrew Kay
@andrewjkay
Aug 26 2016 01:02
@sjames1958gm why is that?
Stephen James
@sjames1958gm
Aug 26 2016 01:02
@JoeShepard1 Understood.
Andrew Kay
@andrewjkay
Aug 26 2016 01:02
OH because it counts from 0
Stephen James
@sjames1958gm
Aug 26 2016 01:02
@andrewjkay because arr[arr.length] is undefined so you stop before i gets to the length
Andrew Kay
@andrewjkay
Aug 26 2016 01:02
so 0 is actually 1
This message was deleted
Stephen James
@sjames1958gm
Aug 26 2016 01:03
undefined.charAt(0) - causes it to throw an error and the code doesn't complete
Andrew Kay
@andrewjkay
Aug 26 2016 01:03
oh ok so inside the loop, it doesn't care, but if it gives an undefined value at any time, a more global variable won't use anything it gave before the undefined?
Stephen James
@sjames1958gm
Aug 26 2016 01:04
@andrewjkay What happens is it goes into the loop one more time and throws an error, throwing an error is like a return the console.log outside the loop is skipped
Andrew Kay
@andrewjkay
Aug 26 2016 01:05
@sjames1958gm that makes sense, thanks again
CamperBot
@camperbot
Aug 26 2016 01:05
andrewjkay sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: andrewjkay already gave sjames1958gm points
Joseph Parkton
@hippybear
Aug 26 2016 01:05
is it better to use for(var n = 0; n < some.length; n++) { .... } or for(var n in some){ .... }?
Stephen James
@sjames1958gm
Aug 26 2016 01:05
@andrewjkay I would suggest when you have these kind of unseeable errors to copy your code to something like repl.it or jsbin it will show the error
Joseph Parkton
@hippybear
Aug 26 2016 01:05
I mean is one faster?
Andrew Kay
@andrewjkay
Aug 26 2016 01:05
I was wondering if there was something like that, I've only been using esprima for syntax checking
Stephen James
@sjames1958gm
Aug 26 2016 01:06
@hippybear I don't know - it recommended to not use for .. in for arrays as the order is not guaranteed (although I haven't see out of order)
Joseph Parkton
@hippybear
Aug 26 2016 01:08
Im used to seeing it from py maybe its some code rivalry?
hehehe
@sjames1958gm its also the method FCC uses in some of the solutions for the challenges
Stephen James
@sjames1958gm
Aug 26 2016 01:09
@Naxell You will need to use and if and .hasOwnProperty to test if the property in checkProp is on the object.
@hippybear Interesting.
@hippybear I usually use forEach if I know that I won't be exiting the loop early
Yeyo Selso Poche
@Naxell
Aug 26 2016 01:10
@sjames1958gm ok thanks..
CamperBot
@camperbot
Aug 26 2016 01:10
naxell sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2862 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Joseph Parkton
@hippybear
Aug 26 2016 01:10
right?
I have seen that more than the for in
Andrew Kay
@andrewjkay
Aug 26 2016 01:12
general question, is FCC more picky about semicolons than it needs to be? I though in js a line break works the same way in most cases
Or I guess more picky than most editors/checkers
Joseph Parkton
@hippybear
Aug 26 2016 01:14
YES!!!
Andrew Kay
@andrewjkay
Aug 26 2016 01:15
@hippybear re: semicolons? every time I paste something I've written somewhere else it lights up everywhere
function titleCase(str) {
  str.toLowerCase();
  var joinedArray;
  var capsArray = [];
  var strArray = str.split(' ');
    for(i = 0; i < strArray.length; i++) {
        capsArray.push(strArray[i].charAt(0).toUpperCase() + strArray[i].slice(1));
        joinedArray = capsArray.join(" ");
        console.log(joinedArray);
      }
    return joinedArray;
   }

titleCase("sHoRt AnD sToUt");
why isn't toLowerCase working here?
Joseph Parkton
@hippybear
Aug 26 2016 01:18
@andrewjkay yep exactly
jsbin is kinda picky too
also that slice isnt giving you what you want?
nenetx
@nenetx
Aug 26 2016 01:20
good night everyone, i see youre all beyond this, but im stuck in the escape string sequences exercise
Andrew Kay
@andrewjkay
Aug 26 2016 01:20
@hippybear everything works, I just wrote it without realizing the tests had weird caps in the strings
nenetx
@nenetx
Aug 26 2016 01:21
can someone review my code and let me know what am i missing?
Andrew Kay
@andrewjkay
Aug 26 2016 01:21
well everything but toLowerCase works
LPR-309
@LPR-309
Aug 26 2016 01:21
@andrewjkay str = str.toLowerCase(); ? You're not assigning it
Joseph Parkton
@hippybear
Aug 26 2016 01:22
@andrewjkay nice
Andrew Kay
@andrewjkay
Aug 26 2016 01:22
@LPR-309 fixed it
thanks @LPR-309
CamperBot
@camperbot
Aug 26 2016 01:22
andrewjkay sends brownie points to @lpr-309 :sparkles: :thumbsup: :sparkles:
:cookie: 298 | @lpr-309 |http://www.freecodecamp.com/lpr-309
Andrew Kay
@andrewjkay
Aug 26 2016 01:23
this one was a bear for me
LPR-309
@LPR-309
Aug 26 2016 01:23
:thumbsup:
lswei07
@lswei07
Aug 26 2016 01:26
@andrewjkay you should change letter to lowercase strArray[i].slice(1).toLowerCase()
Andrew Kay
@andrewjkay
Aug 26 2016 01:27
@lswei07 that's probably better but this also passed
Norvin Burrus
@ndburrus
Aug 26 2016 01:32
@nenetx resolved?
Stephen James
@sjames1958gm
Aug 26 2016 01:33
@andrewjkay YOu got it ! :+1:
nicop
@nicopcat
Aug 26 2016 01:41
hello
var myStr = \ \t \b \r \n;
here's my code
where's went wrong L0L
Diego Mayer
@Chrono79
Aug 26 2016 01:42
@nicopcat reset the challenge
nicop
@nicopcat
Aug 26 2016 01:45
doesn't work
QAQ
Ryan Williams
@Ryanwfile
Aug 26 2016 01:48
This message was deleted
Can someone please help me with this code for my simon project please. The codepen link is http://codepen.io/Ryanwfile/pen/EyBGBg Thank you
setInterval(function()
     {
       setInterval(function() 
         { 
          $('.circle > .sector')
            .buttons.lightUp()
         },  250);
     },1000);
I am just trying to have this function repeat indefinitely once the player wins but this only executes once
Vishon
@Symbolistic
Aug 26 2016 01:50
how do i ask for help here? Like where can i type the code for the exercise i am having issues with
Vu Phung
@VDPhung
Aug 26 2016 01:50
How do you push a value to an object property?
Vishon
@Symbolistic
Aug 26 2016 01:50
^that is one of my issues
Alexander Køpke
@alexanderkopke
Aug 26 2016 01:52
@tofu123 pushing is for arrays.. if you want to add a property and give it a value you do it like this: object.property = value;
Vishon
@Symbolistic
Aug 26 2016 01:52
guys im having issues with the "Record Collection" Exercise for Javascript.
im just overall confused about it
i am trying to create the function for it and here is what i got so far

function updateRecords(id, prop, value) {

if(prop !== "tracks" && value !== ""){
var newt = collection[id].prop = value;

}

else if(prop === "tracks" && collection[id].hasOwnProperty("tracks")){
collection[id].tracks = [];
}

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

return collection;
}

the whole thing looks stupid to me the whole code i made seems like a mess.
its annoying me like crazy
Stephen James
@sjames1958gm
Aug 26 2016 01:54
@Ryanwfile 2107 pen.js:201 Uncaught TypeError: Cannot read property 'lightUp' of undefined
@Ryanwfile Realize that every second it is going to start another timer so you are going to have a lot of timers running pretty quickly
@Symbolistic prop is a variable - dot notation is not for variables
Vishon
@Symbolistic
Aug 26 2016 01:56
i dont even understand how you would access a object using a functions parameters. I passed down all the objects information, the id, property, value
but like you said, prop is a variable, so i dont get how i would access and change objects with a function
this is why the record collection exercise is so confusing
Alexander Køpke
@alexanderkopke
Aug 26 2016 01:57
@Symbolistic indeed.. have you ever used the console in your browser?
Stephen James
@sjames1958gm
Aug 26 2016 01:57
@Symbolistic collection is a global, so it is accessible inside the function. id, prop and value are coming from the function call.
@Symbolistic The code is not far off from correct.
Rony Vidaur
@RonyVidaur
Aug 26 2016 01:58
hay guys, kinda need some help here, I'm building my Weather App, and right now im just testing, just to see if I can get the data correctly
so Im calling the API
Ryan Williams
@Ryanwfile
Aug 26 2016 01:58
@sjames1958gm Thanks for the help. The lightUp function seems to be working because I am console logging when it occurs, I understand the timer issue I am just wondering how to get the lights to keep lighting up instead of just lighting up once each
CamperBot
@camperbot
Aug 26 2016 01:58
ryanwfile sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2863 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Rony Vidaur
@RonyVidaur
Aug 26 2016 01:58
as you can see if you visit the pen that i've got so far
but in the console is showing 404 not found
and is because codepen is aparently attaching some stuff to the address
oh and also you need to click the button to test
Jason Gresalfi
@jgresalfi
Aug 26 2016 02:01
@Symbolistic Try accessing your obj properties like this: collection[id][prop]
Vishon
@Symbolistic
Aug 26 2016 02:01
smashing head into keyboard
wtfffffff Jason you were right
i didnt think you could use back-to-back brackets
Alexander Køpke
@alexanderkopke
Aug 26 2016 02:01
@RonyVidaur you have gotten and appid yet? http://openweathermap.org/appid the appid needs to be in the url for it to work
Jason Gresalfi
@jgresalfi
Aug 26 2016 02:02
yeah - it looks a little wonky but that's how you do it
Vishon
@Symbolistic
Aug 26 2016 02:02
ty guys that fixed my first issues
Jason Gresalfi
@jgresalfi
Aug 26 2016 02:03
i'm having issues with this exercise too. whenever i write a new value to a property, it rewrites the whole object so only my last change gets preserved. everything else goes back to default values
Stephen James
@sjames1958gm
Aug 26 2016 02:06
@Ryanwfile You have way to many setIntervals that are not being stopped. You even have a for loop of 50 setIntervals.
Ryan Williams
@Ryanwfile
Aug 26 2016 02:07
@sjames1958gm Ok thank you very much for the help
CamperBot
@camperbot
Aug 26 2016 02:07
ryanwfile sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: ryanwfile already gave sjames1958gm points
Stephen James
@sjames1958gm
Aug 26 2016 02:07
@jgresalfi That is the purpose of colleciton copy to allow the tester to reset the collection back for each test.
Jason Gresalfi
@jgresalfi
Aug 26 2016 02:10
@sjames1958gm does the reset happen dynamically because I’m not manually resetting the data. If I change and artist name it works. If I change the album name associated with that artist, it also changes but the artist name goes back to default...
i’m definitely missing something
jinjuujii
@jinjuujii
Aug 26 2016 02:11
i completed the palindrome exercise but i don't like my if statement. is there a way to simplify that statement with an inherent function or parameters?
function palindrome(str) {
  // Good luck!

  str = str.toLowerCase();
  var arrayString = str.split("");
  var removedArray = [];
  var Wordstring ="";
  var arraybackwardString =[];
  var backWordstring="";

  console.log(arrayString);

 for (var i = 0; i < str.length; i++){
    if (arrayString[i] === "a"|| arrayString[i] === "b" ||
       arrayString[i] === "c" || arrayString[i] === "d" || 
       arrayString[i] === "e" || arrayString[i] === "f" || 
       arrayString[i] === "g" || arrayString[i] === "h" || 
       arrayString[i] === "i" || arrayString[i] === "j" || 
       arrayString[i] === "k" || arrayString[i] === "l" || 
       arrayString[i] === "m" || arrayString[i] === "n" || 
       arrayString[i] === "o" || arrayString[i] === "p" || 
       arrayString[i] === "q" || arrayString[i] === "r" || 
       arrayString[i] === "s" || arrayString[i] === "t" || 
       arrayString[i] === "u" || arrayString[i] === "v" ||
       arrayString[i] === "w" || arrayString[i] === "x" || 
       arrayString[i] === "y" || arrayString[i] === "z" ||
       arrayString[i] === "y" || arrayString[i] === "0"|| arrayString[i] === "1" || arrayString[i] === "2"|| arrayString[i] === "3" || arrayString[i] === "4"|| arrayString[i] === "5" || arrayString[i] === "6"|| arrayString[i] === "7" || arrayString[i] === "8"|| arrayString[i] === "9")

      removedArray.push(arrayString[i]);
    }


Wordstring = removedArray.join("");

  for (var j = Wordstring.length+1; i >=0; i--){
    arraybackwardString.push(removedArray[i]);
  }

backWordstring= arraybackwardString.join("");



 if (Wordstring == backWordstring){
    return true;
  }
  else{
    return false;
  } 
}

palindrome("eye");
Ken Haduch
@khaduch
Aug 26 2016 02:14
@jinjuujii - that is an effective but inefficient way to do that. Have you been introduced to regular expressions? You could cut that down to one line of code.
jinjuujii
@jinjuujii
Aug 26 2016 02:14
what do you mean regular expressions?
Stephen James
@sjames1958gm
Aug 26 2016 02:19
@jgresalfi I believe it resets the values between each test.
@jinjuujii Also - wasn't reverse a string just challenge or two ago.
jinjuujii
@jinjuujii
Aug 26 2016 02:20
@sjames1958gm yes.. this is how i did my reverse string challenge
Ken Haduch
@khaduch
Aug 26 2016 02:20
@jinjuujii - they covered some of the basics in the of Regular Expressions in the Basic Javascript lessons. Using regular expressions, you can form patterns that will recognize certain character patterns - for example, a regular expression /abc/ will match the letter a, b, or c. There are special patterns such as /\w/ that will match any word character, etc. Go to the map and search for "Regular" and it will bring up the list of lessons, you can take a quick review.
jinjuujii
@jinjuujii
Aug 26 2016 02:20
function reverseString(str) {
  var array = [];

array = str.split("");

var reversed = array.reverse();

return reversed.join("");

}

reverseString("hello");
Stephen James
@sjames1958gm
Aug 26 2016 02:21
@jinjuujii But here you did it differently
Vishon
@Symbolistic
Aug 26 2016 02:21
dam i only have 1 issue standin in my way
"After updateRecords(5439, "tracks", "Take a Chance on Me"), tracks should have "Take a Chance on Me" as the last element."
jinjuujii
@jinjuujii
Aug 26 2016 02:21
@khaduch thanks. i remembered something like that.. i'll take a look
CamperBot
@camperbot
Aug 26 2016 02:21
jinjuujii sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 1577 | @khaduch |http://www.freecodecamp.com/khaduch
Vishon
@Symbolistic
Aug 26 2016 02:21
this is my code so far

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

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

}

else if(prop === "tracks" && collection[id].hasOwnProperty("tracks") !== true){
collection[id][prop] = [];
}

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

else if (value === ""){
delete collection[id][prop];
}
return collection;
}

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

jinjuujii
@jinjuujii
Aug 26 2016 02:22
@sjames1958gm yes. here i didn't have to worry about special characters matching or not. i just needed to reverse it
Vishon
@Symbolistic
Aug 26 2016 02:22
i feel like the "push" isnt working
or maybe the brackets didnt work, i tried to make a new array in it
Stephen James
@sjames1958gm
Aug 26 2016 02:23
@jinjuujii Once you had the removeArray - you could reverse it with reverse()
jinjuujii
@jinjuujii
Aug 26 2016 02:23
@Symbolistic i did this yesterday. i had the same problem. .push() is a function of ARRAYS .. we can't use it for strings
Vishon
@Symbolistic
Aug 26 2016 02:23
ohhhhhhh
so what do i do in replacement
Alexander Køpke
@alexanderkopke
Aug 26 2016 02:23
@Symbolistic the prop may be tracks but what if tracks doesn't exist in the collection[id]?
Stephen James
@sjames1958gm
Aug 26 2016 02:23
@Symbolistic You only create the [] you never push onto it.
jinjuujii
@jinjuujii
Aug 26 2016 02:24
@sjames1958gm yes i did do it with the reverse function. here i did it with a reverse loop ... sigh thanks for pointing that out
CamperBot
@camperbot
Aug 26 2016 02:24
jinjuujii sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2864 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 26 2016 02:25
@jinjuujii :) - also there are challenges with regexp I though before this one.
jinjuujii
@jinjuujii
Aug 26 2016 02:25
@sjames1958gm i think so but i've been doing these bonfires through arrays
LOL
Vishon
@Symbolistic
Aug 26 2016 02:26
@alexanderkopke i thought if tracks didnt exist that it automatically created it for u'
Alexander Køpke
@alexanderkopke
Aug 26 2016 02:26
@jinjuujii objects work that way but push doesn't work that way
Stephen James
@sjames1958gm
Aug 26 2016 02:27
@Symbolistic this doesn't put value into the array
else if(prop === "tracks" && collection[id].hasOwnProperty("tracks") !== true){
collection[id][prop] = [];
Vishon
@Symbolistic
Aug 26 2016 02:27
collection[id][prop].push(value);
i thought that line would tho
but ofc i was just told push wont work
Stephen James
@sjames1958gm
Aug 26 2016 02:28
@Symbolistic else if blocks are mutually exclusive. You can push onto the empty array you created
Alexander Køpke
@alexanderkopke
Aug 26 2016 02:28
@Symbolistic the reason for push is to add to an array, whether it is empty or otherwise. But it has to exist first
Stephen James
@sjames1958gm
Aug 26 2016 02:29
@Symbolistic Also, collection[id][prop] = [value]; creates the array and populates it in one step
Alexander Køpke
@alexanderkopke
Aug 26 2016 02:29
@sjames1958gm true but won't it be a problem if there are already items in the array?
Stephen James
@sjames1958gm
Aug 26 2016 02:30
@alexanderkopke There is code that checks that he has the .hasOwnProperty check
Vishon
@Symbolistic
Aug 26 2016 02:30
omg
else if(prop === "tracks" && collection[id].hasOwnProperty("tracks") !== true){
collection[id][prop] = [value];
}
it worked
i was so confused by what everyone was telling me lol
Alexander Køpke
@alexanderkopke
Aug 26 2016 02:31
@sjames1958gm true but as I recall an empty array doesn't return falsy. Maybe I remember wrong.. brb I will check
@Symbolistic sorry. Didn't mean to startle you
Stephen James
@sjames1958gm
Aug 26 2016 02:31
@Symbolistic You had the code, but you thought that the push would run after the [] but the else if are mutually exclusive
Rony Vidaur
@RonyVidaur
Aug 26 2016 02:32
@alexanderkopke oh yes I did, totally forgot about it, thanks dude, I'll give it a try later
CamperBot
@camperbot
Aug 26 2016 02:32
ronyvidaur sends brownie points to @alexanderkopke :sparkles: :thumbsup: :sparkles:
Stephen James
@sjames1958gm
Aug 26 2016 02:32
@Symbolistic You could also have added a push right below the = [] and it would have worked as well
CamperBot
@camperbot
Aug 26 2016 02:32
:cookie: 724 | @alexanderkopke |http://www.freecodecamp.com/alexanderkopke
Vishon
@Symbolistic
Aug 26 2016 02:33
thanks for the help everyone. I am still trying to figure out how to understand all of this and how to understand "programmers talk" lol
i got a lot of practicing to do, i cant imagine how hard it will be when i have to do this as a jr web developer job
Stephen James
@sjames1958gm
Aug 26 2016 02:33
@Symbolistic As long as you are willing to push through all the annoyance and frustration you can make it :) :+1:
Vishon
@Symbolistic
Aug 26 2016 02:34
thanks again =)
Alexander Køpke
@alexanderkopke
Aug 26 2016 02:34
ok just tested Boolean([]) and it returns true.
Daulis M Gonzalez
@daulis809
Aug 26 2016 02:34
Hi all
Alexander Køpke
@alexanderkopke
Aug 26 2016 02:36
@Symbolistic you did a great job btw. Even if you didn't understand it all much of the code was correct and just need minor adjustments.
Jason Gresalfi
@jgresalfi
Aug 26 2016 02:36
@sjames1958gm Thanks for the guidance on this. I’m working this exercise right now...
CamperBot
@camperbot
Aug 26 2016 02:36
jgresalfi sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2865 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Kevin Ogden
@kogden
Aug 26 2016 02:41
Can someone tell me what this line of js means?
str.replace(/[\W_]/g, '')
I dont get this part, /[\W_]/g
K R Vinay Kumar
@vinaykumar94
Aug 26 2016 02:41
Can someone help me with my project..I am doing resume maker Website where user can enter details and download resume on pdf.i have made a template and forms for the user to give inputs .now I have to store this data and give it to template and create pdf when user click on button..how do I store data and give it to create pdf .m please help me with this..than k you
Alexander Køpke
@alexanderkopke
Aug 26 2016 02:42
@kogden that is regex.. it matches all non-alphanumeric values and underscores
Ken Haduch
@khaduch
Aug 26 2016 02:42
@kogden - that \W is a regular expression that will match any non-word character, and since the _ is part of the set of word characters, you also want to match it. The square brackets group them together so that it will look at each character with that pattern. So this takes any non-word characters plus the underscore and removes them from the string.
Kevin Ogden
@kogden
Aug 26 2016 02:44
ohh okay
@alexanderkopke thanks!
CamperBot
@camperbot
Aug 26 2016 02:44
kogden sends brownie points to @alexanderkopke :sparkles: :thumbsup: :sparkles:
:cookie: 725 | @alexanderkopke |http://www.freecodecamp.com/alexanderkopke
Kevin Ogden
@kogden
Aug 26 2016 02:44
@khaduch thank you@
CamperBot
@camperbot
Aug 26 2016 02:44
kogden sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 1578 | @khaduch |http://www.freecodecamp.com/khaduch
Chad Powell
@cjpowellaz
Aug 26 2016 02:47
Hello all, working on Seek and Destroy and having trouble writing a callback function. I have looked at examples online but I still can't make sense of it all the way. Here is my code so far:

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

var args = Array.prototype.slice.call(arguments);

callback();

}
function verifier(args) {
for (i = 0; i < args.length; i++) {
var partOfArray = args.indexOf(arr[0]);
}
}

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

I made tried to make a function to do the indexOf then use it as the callback, but I don't know what to put for the arguments
Ken Haduch
@khaduch
Aug 26 2016 02:48
@cjpowellaz - post using the markdown format...
'''
CamperBot
@camperbot
Aug 26 2016 02:48
:bulb: to format code use backticks! ``` more info
K R Vinay Kumar
@vinaykumar94
Aug 26 2016 02:50
Anyone here know jquery??
Chris Cullen
@123xylem
Aug 26 2016 02:50

function newChoice() {
  choice = choices[Math.floor(Math.random() * choices.length)];
  return choice;
  console.log(choice + " cpu next choice");
}

var user;
$(document).ready(function() {
  user = prompt("Choose X or O", "Make sure its Caps!");

  if (user == "X") {
    userX = true;
    console.log(userX + "X");
    console.log(userO + "o");
    $(".box").on('click', function act() {
      var id = $(this).attr('id'); //logs clicked box ID and pushes into array
      switch (id) {
        case "a":
          removeChoice("a");
          answer.push("A");
          break;
        case "b":
          removeChoice("b");
          answer.push("B");
          break;
        case "c":
          removeChoice("c");

          answer.push("C");
          break;
        case "d":
          removeChoice("d");

          answer.push("D");
          break;


      };
      console.log(answer + " usermoves X");      console.lgo(choices + " choices array after user move");

      cpu();
      newChoice();

    });
In my tictac game I let user choose a box then remove that choice (*removeChoice() ) from the choice array. However the CPU seems to choose a box before I can remove it...
Can I rewrite the above to change that?
Daulis M Gonzalez
@daulis809
Aug 26 2016 02:51
@vinaykumar94 i might be able to help, whats your question
Ken Haduch
@khaduch
Aug 26 2016 02:51
@vinaykumar94 - someone might know jQuery...
Chad Powell
@cjpowellaz
Aug 26 2016 02:53
function destroyer(arr) {
  // Remove all the values
    var args = Array.prototype.slice.call(arguments)
  callback();
}
    function verifier(args) {
    for (i = 0; i < args.length; i++) {
      var partOfArray = args.indexOf(arr[0]);
    }
  }
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
I have no idea what to put after "callback" none of the example code online explained that
Ken Haduch
@khaduch
Aug 26 2016 03:00
@cjpowellaz - well, a good place to start would be to split the arguments into two different arrays - the first is the one that you want to filter the extra arguments from. You can do this with a for loop, but they are suggesting that the Array.filter() would be helpful.
Chad Powell
@cjpowellaz
Aug 26 2016 03:01
in the Wiki it said to use, "var args = Array.prototype.slice.call(arguments)"
that's why that is there
I've been reading about callbacks during my down time at work and I seem to barely get it right now
Chad Powell
@cjpowellaz
Aug 26 2016 03:11
reading through that one again @alexanderkopke, that was one of the articles on my work computer all day.
:smile:
khayati-oussama
@khayati-oussama
Aug 26 2016 03:22

```js
function destroyer(arr) {
// Remove all the values
var args = Array.prototype.slice.call(arguments)
callback();
}
function verifier(args) {
for (i = 0; i < args.length; i++) {
var partOfArray = args.indexOf(arr[0]);
}
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);

some help plz

xzombx
@xzombx
Aug 26 2016 03:22

Hey guys, quick question. I'm on Using Objects for Lookups and I can't for the life of me figure out why it isn't outputting the correct object for me. I've looked at the example time and time again and I was wondering if any of you guys saw any blatant errors popping out. Thanks in advance! Code : function phoneticLookup(val) {
var result = "";

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

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

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

Chad Powell
@cjpowellaz
Aug 26 2016 03:23
that's what I am beating my head against too! @khayati-oussama
khayati-oussama
@khayati-oussama
Aug 26 2016 03:24
@cjpowellaz we really need help :smile:
Chris Cullen
@123xylem
Aug 26 2016 03:25
var boxTop = ["A", "B", "C"];
var boxMid = ["D", "E", "F"];
var boxBot = ["G", "H", "I"];
var boxVert1 = ["A", "D", "G"];
var boxVert2 = ["B", "E", "H"];
var boxVert3 = ["C", "F", "I"];
var boxDiag1 = ["A", "E", "I"];
var boxDiag2 = ["C", "E", "G"];

function win(){
  for (j=0;j<answers.length;j++){
  if(answer[j]==)                                       // How can i say if J finds all elements of var box top eg A B and C?

}}
Im trying to write a victory scan that checks to see if user inputs ever contain the victory condiition inputs.
Chad Powell
@cjpowellaz
Aug 26 2016 03:26
it's pretty quiet in here tonight, I think I will try another time, falling asleep at the keyboard
khayati-oussama
@khayati-oussama
Aug 26 2016 03:27
@cjpowellaz :+1:
Jason Gresalfi
@jgresalfi
Aug 26 2016 03:28
@xzombx Well, it doesn’t look like you’re assigning anything to result. Is the function returning anything besides an empty string?
xzombx
@xzombx
Aug 26 2016 03:30
nothing. when I lookup = result; nothing and if i switch it result = lookup, it gives me the entire table.
Suzanne Atkinson
@AdventureBear
Aug 26 2016 03:32
Anyone help with pairwise? this code works for all but the case when there are repeated numbers in the array that continue to match the element I'm comparing with. How do exit a forEach loop, or should I be using while?
Norvin Burrus
@ndburrus
Aug 26 2016 03:32

@xzombx :sparkles:

  • need to handle the result
  • notice how the example code allows looking into the object & retreiving the desired value...

    var value = 2;
    alpha[value]; // "Y" **this line***
  • so, we want to : Use it (the object table) to lookup val and assign the associated string to the result variable.

  • val would be our input val/ue. see function input variable, here:
    function phoneticLookup(val) {
  • what would our table/object name be?
  • how do we assign this to result?

...clear as mud?

Jason Gresalfi
@jgresalfi
Aug 26 2016 03:32
@xzombx Ok, so you have to return ‘result’ with the value of the lookup that the function is supposed to be doing. So tying the property (or key) to it’s proper value based on the function argument and assigning that to result
xzombx
@xzombx
Aug 26 2016 03:38
@ndburrus table name is lookup. wouldn't i just do lookup = result since the function is searching for val[charlie]?
or am i missing something obvious here?
Norvin Burrus
@ndburrus
Aug 26 2016 03:39
@xzombx take a peek at the bottom code that is not to be changed...
result needs a value assigned to it, right?
Jay Song
@gnosyaj
Aug 26 2016 03:39
so stupid
freecodecamp's link shows console.log being the answer but now i use answer = and that's the solution
gosh
wth
Gene N.
@gnwankpa
Aug 26 2016 03:40
Hey all... stuck on this counting cards challenge... Not sure what I am doing wrong

var count = 0;

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

if (card == 2 || 3 || 4 || 5 || 6) {
count += 1;
return count + " Bet";
} else if (card == 7 || 8 || 9) {
return count + " Hold";
} else if (card == 10 || 'J' || 'Q' || 'K' || 'A') {
count -= 1;
return count + " Hold";
}

// 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');

count goes all the way up to 5 but never changes
Norvin Burrus
@ndburrus
Aug 26 2016 03:40
@gnwankpa :sparkles:
  • handle the return outside the conditional
  • only handle the count variable inside the conditional (for all five cards - to get the final count value)
  • once we have the final count value, then we can evaluate/handle the desired return.
  • right now, the code bases the return on an "each card" evaluation, see that? it doesn't consider 5 cards, just one.
Gene N.
@gnwankpa
Aug 26 2016 03:41
ah, let me try that thanks
thanks @ndburrus
CamperBot
@camperbot
Aug 26 2016 03:41
gnwankpa sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:star2: 1874 | @ndburrus |http://www.freecodecamp.com/ndburrus
Norvin Burrus
@ndburrus
Aug 26 2016 03:41
@gnwankpa you're welcome! :+1:
@xzombx how are we doing?
Mrsmao
@whb123
Aug 26 2016 03:45
why i dont have the 88

var myVar = 87;

// Only change code below this line
myVar = myVar++;

Jason Gresalfi
@jgresalfi
Aug 26 2016 03:47
@whb123 Just try myVar++
xzombx
@xzombx
Aug 26 2016 03:48
i have a headache. ok so the val in the function is charlie which then calls the lookup to go searching for charlie. it finds charlie which is chicago. result needs to reflect this. so lookup.charlie = result?
nope nvm
Mrsmao
@whb123
Aug 26 2016 03:49
@jgresalfi thanks
CamperBot
@camperbot
Aug 26 2016 03:49
whb123 sends brownie points to @jgresalfi :sparkles: :thumbsup: :sparkles:
:cookie: 211 | @jgresalfi |http://www.freecodecamp.com/jgresalfi
Norvin Burrus
@ndburrus
Aug 26 2016 03:50
@xzombx almost.... :point_up: previous notes
in the lower left of the code window, we see tht we need to use bracket notation (as opposed to dot nottion).
Jason Gresalfi
@jgresalfi
Aug 26 2016 03:50
@whb123 I don’t know the technical reason why you weren’t getting a result. myVar = myVar + 1 will also work
xzombx
@xzombx
Aug 26 2016 03:50
@ndburrus lookup["charlie"] = result?
Gene N.
@gnwankpa
Aug 26 2016 03:51
ok so I moved the return out of the conditional @ndburrus but my count doesnt seem to be adding or subtracting properly (Always adding 1 to count)

var count = 0;

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

if (card == 2 || 3 || 4 || 5 || 6) {
count = count + 1;
} else if (card == 7 || 8 || 9) {
} else if (card == 10 || 'J' || 'Q' || 'K' || 'A') {
count = count - 1;

}
return count;

// Only change code above this line
}

Norvin Burrus
@ndburrus
Aug 26 2016 03:51
@xzombx we need to use the variable, not the key (as in key/value pair) value... let the code do the work!
so, what is our function input variable?
"function phoneticLookup(val) {"
xzombx
@xzombx
Aug 26 2016 03:52
yea the value is charlie right?
Jason Gresalfi
@jgresalfi
Aug 26 2016 03:53
@xzombx What @ndburrus is saying. Just pass the val parameter into your object notation in place of the key name
xzombx
@xzombx
Aug 26 2016 03:53
@jgresalfi lookup[val] = result;?
Jason Gresalfi
@jgresalfi
Aug 26 2016 03:54
@xzombx Close…you’ve got the general idea
xzombx
@xzombx
Aug 26 2016 03:54
@jgresalfi haha im so sorry guys. I'll get it through my head eventually
Jason Gresalfi
@jgresalfi
Aug 26 2016 03:55
@xzombx No apologies, this stuff is a little weird sometimes. The result will EQUAL something…
Norvin Burrus
@ndburrus
Aug 26 2016 03:56
@gnwankpa i gave some misinformation. the eval is for each card. sorry. anyway, we need to handle the result - which includes a string return.
Jason Gresalfi
@jgresalfi
Aug 26 2016 03:56
@xzombx you want to use your val parameter but it’s a variable name so you can’t use dot notation. you need to use brackets, and you need to reference the main object variable while you’re at it...
xzombx
@xzombx
Aug 26 2016 03:57
@jgresalfi @ndburrus you guys deserve rewards. i finally understand now. I'm not sure why it wasn't clicking but its all good now. thank you guys
CamperBot
@camperbot
Aug 26 2016 03:57
xzombx sends brownie points to @jgresalfi and @ndburrus :sparkles: :thumbsup: :sparkles:
:star2: 1875 | @ndburrus |http://www.freecodecamp.com/ndburrus
:cookie: 212 | @jgresalfi |http://www.freecodecamp.com/jgresalfi
Jason Gresalfi
@jgresalfi
Aug 26 2016 03:57
@xzombx Thanks for tipping the band!
CamperBot
@camperbot
Aug 26 2016 03:57
jgresalfi sends brownie points to @xzombx :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for xzombx
Gene N.
@gnwankpa
Aug 26 2016 03:57
yes @ndburrus but I am just trying to test out the count variable and it does not seem to update properly with my conditional logic
Norvin Burrus
@ndburrus
Aug 26 2016 03:57
@xzombx you're welcome! great job! enjoy! :palm_tree:
this may be helpful: :+1:
Gene N.
@gnwankpa
Aug 26 2016 03:58
so if I pass console.log(cc('K')); it gives me 1 instead of a -1
Norvin Burrus
@ndburrus
Aug 26 2016 04:00
@gnwankpa missing }, after return count;
now test.... see your values/results?
Gene N.
@gnwankpa
Aug 26 2016 04:01
hmm ok
Chad Powell
@cjpowellaz
Aug 26 2016 04:03
working on Seek and Destroy, the wiki recommends writing a callback function to perform indexOf()
Gene N.
@gnwankpa
Aug 26 2016 04:03
the bracket it there under the comment
when I add a bracket after the return I get an error
Chad Powell
@cjpowellaz
Aug 26 2016 04:04
function destroyer(arr, callback) {
  // Remove all the values
    var args = Array.prototype.slice.call(arguments);
 callback(); 
}
  function verifier(args) {
    for (var i = 0; i < args.length; i++) {
      var partOfArray = args.indexOf(arr[0]);
    }
  }
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
billpzt
@billpzt
Aug 26 2016 04:04
I really think they should have us train more before these projects. I feel like the lessons just fly by and then suddenly you're thrown into the deep end of a pool. Having trouble with the Record Collection exercise. The dot vs bracket notation seems confusing to me, my code doesn't work and I have no idea why because syntax presents no error messages and some of the exercise targets are marked as right even though my code didn't produce the correct answer... Very frustrating!
Norvin Burrus
@ndburrus
Aug 26 2016 04:05
@billpzt this may be helpful: :sparkles:
@gnwankpa can you console.log and see your results?
billpzt
@billpzt
Aug 26 2016 04:06
@ndburrus thanks, I'll check that out
CamperBot
@camperbot
Aug 26 2016 04:06
billpzt sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:star2: 1876 | @ndburrus |http://www.freecodecamp.com/ndburrus
Norvin Burrus
@ndburrus
Aug 26 2016 04:06
@billpzt you're welcome! enjoy! :palm_tree:
Jason Gresalfi
@jgresalfi
Aug 26 2016 04:08
@billpzt The other thing you can do is drop all the exercise code into Chrome Dev Tools…are you familiar with how to use the Snippets feature and the debug tools?
Angel J Piscola
@Redmega
Aug 26 2016 04:08
hey y'all
Jose Escobar Mejia
@mejiaadonay
Aug 26 2016 04:08
How anyone knows how to finish this challenge "Stand in Line"
Jason Gresalfi
@jgresalfi
Aug 26 2016 04:09
@billpzt Here’s a Dev Tools primer from Code School. I think it’s free and it’s totally worth the time to get a basic understanding of how to debug your code: https://www.codeschool.com/courses/discover-devtools
billpzt
@billpzt
Aug 26 2016 04:09
@jgresalfi Hi, nope, no idea
@jgresalfi Ok, will check that out too, thanks
CamperBot
@camperbot
Aug 26 2016 04:10
billpzt sends brownie points to @jgresalfi :sparkles: :thumbsup: :sparkles:
:cookie: 213 | @jgresalfi |http://www.freecodecamp.com/jgresalfi
Jason Gresalfi
@jgresalfi
Aug 26 2016 04:11
@billpzt No worries. The nice thing about using it is that it will show you all errors in the console and it will allow you to step line-by-line through your code so you can figure out where the error is coming from
@billpzt One more link to Dev Tools Snippets. I create and use these all the time, in fact it helped me iron out my probs with the Record Collection exercise: https://developers.google.com/web/tools/chrome-devtools/debug/snippets/?hl=en
billpzt
@billpzt
Aug 26 2016 04:14
@jgresalfi That'll be helpful, I had written it all before earlier this afternoon, didn't work, scrapped everything, tried it all over again, but still not getting it right.
@jgresalfi thanks
CamperBot
@camperbot
Aug 26 2016 04:14
billpzt sends brownie points to @jgresalfi :sparkles: :thumbsup: :sparkles:
:warning: billpzt already gave jgresalfi points
billpzt
@billpzt
Aug 26 2016 04:15
Oh, I thought we were supposed to hand out points left and right hahaha
Jason Gresalfi
@jgresalfi
Aug 26 2016 04:15
@billpzt Good luck. Just take it step by step and use the tests to guide your coding.
@billpzt I have no idea how these points work, and I don’t know any of the words that trigger the Gitter bot or whatever it’s called. ;-)
billpzt
@billpzt
Aug 26 2016 04:16
@jgresalfi merci!
Jason Gresalfi
@jgresalfi
Aug 26 2016 04:16
lol
Gene N.
@gnwankpa
Aug 26 2016 04:21
Hey guys.. anyone know why I get a +1 to my count no matter what I feed the function?

var count = 0;

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

if (card == 2 || 3 || 4 || 5 || 6) {
count = count + 1;
} else if (card == 7 || 8 || 9) { count = count;
} else if (card == 10 || 'J' || 'Q' || 'K' || 'A') {
count = count - 1;

}
return count;

// Only change code above this line
}

console.log(cc('K'));

Coy Sanders
@coymeetsworld
Aug 26 2016 04:22
your if statements aren't working the way you want them to @gnwankpa
Jason Gresalfi
@jgresalfi
Aug 26 2016 04:22
@gnwankpa Hey Gene, try count++ instead of count = count +/- 1
Coy Sanders
@coymeetsworld
Aug 26 2016 04:22
card == 2 || 3 is not short for card ==2 || card ==3
what happens is no matter what card is count will be incremented by 1, because if card ==2, it will try to evaluate 3, 3 is a true value in JavaScript so the if statement passes
Jason Gresalfi
@jgresalfi
Aug 26 2016 04:23
@coymeetsworld is also correct. You might want to take a look at switch statements and try that instead.
Gene N.
@gnwankpa
Aug 26 2016 04:23
oh wow, so I will need to type each of those out then?
ok let me try the switch statements
Kent Saeteurn
@sansae
Aug 26 2016 04:23
Hi all, I've been working on the "Wherefore Art Thou" javascript challenge for about one month now. I feel I'm super close to solving the problem. The code I have seems like it should work. I trace through it line by line and I keep track of the variables and what's going on, but for some reason, the last test case for the problem is not passing. I don't know why? Can anyone help me figure out why? My fiddle is here: https://jsfiddle.net/scLacy90/1/ (all my code is original, so pardon the notes and all the extra comments; my brain has been hurting trying really hard to understand this problem; it took me the longest time to figure out how to use Object.keys)
Coy Sanders
@coymeetsworld
Aug 26 2016 04:23
yeah you should probably do a case/switch statement as @jgresalfi said, code will be much shorter
Gene N.
@gnwankpa
Aug 26 2016 04:24
thanks @coymeetsworld & @jgresalfi
CamperBot
@camperbot
Aug 26 2016 04:24
gnwankpa sends brownie points to @coymeetsworld and @jgresalfi :sparkles: :thumbsup: :sparkles:
:cookie: 214 | @jgresalfi |http://www.freecodecamp.com/jgresalfi
:star2: 1328 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Coy Sanders
@coymeetsworld
Aug 26 2016 04:24
no problem @gnwankpa good luck
Jason Gresalfi
@jgresalfi
Aug 26 2016 04:24
@gnwankpa Plus, you won’t need to bother with evaluating the cards that don’t affect your count score - good luck and have fun!
Kent Saeteurn
@sansae
Aug 26 2016 04:24
Chad Powell
@cjpowellaz
Aug 26 2016 04:28
Ok, quitting on callbacks, trying this:
function destroyer(arr) {
  var newArray = [];
  var args = Array.prototype.slice.call(arguments);

 for (var i = 0; i < args[0].length; i++) {
   if (arr.indexOf(args[i])) {
     newArray.push(args[i]);
     return newArray;
   }
 } 
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
amrezo
@amrezo
Aug 26 2016 04:31
Hi everyone I'm not too sure what I'm supposed to do in teh javascript challenge: Stand In Line
Angel J Piscola
@Redmega
Aug 26 2016 04:35
What does the user story say to do @amrezo
amrezo
@amrezo
Aug 26 2016 04:35
Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.
the function is currently:

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

return item; // Change this line
}

Angel J Piscola
@Redmega
Aug 26 2016 04:36
Ok. So you need to add the number to the end of the array, remove the first element of the array, and then return the element which you removed
That's what it says, right?
amrezo
@amrezo
Aug 26 2016 04:36
yes so add as in add operator
or like append it
Angel J Piscola
@Redmega
Aug 26 2016 04:36
When we add something to an array, do we perform addition on the array or do we append the item to the end like a list?
amrezo
@amrezo
Aug 26 2016 04:37
append i believe
Angel J Piscola
@Redmega
Aug 26 2016 04:37
If I told you to add eggs to your shopping list, what would you do?
amrezo
@amrezo
Aug 26 2016 04:37
add it to the list
Angel J Piscola
@Redmega
Aug 26 2016 04:37
Bingo
An array is just a list of things
amrezo
@amrezo
Aug 26 2016 04:37
oh ok thats a better way of thinking about it
so will i use push()?
Angel J Piscola
@Redmega
Aug 26 2016 04:38
That's definitely a way to do it
amrezo
@amrezo
Aug 26 2016 04:38
ok thanks very much @Redmega ill try that
CamperBot
@camperbot
Aug 26 2016 04:38
amrezo sends brownie points to @redmega :sparkles: :thumbsup: :sparkles:
:cookie: 93 | @redmega |http://www.freecodecamp.com/redmega
Angel J Piscola
@Redmega
Aug 26 2016 04:38
No problem! :thumbsup: Good luck
It happens to return what you removed too, so that takes care of two birds with one stone
Angel J Piscola
@Redmega
Aug 26 2016 04:42
@jgresalfi Nice one. Forgot about that
Saves him an [0]
amrezo
@amrezo
Aug 26 2016 04:43
oh alright thank you both :D
Jason Gresalfi
@jgresalfi
Aug 26 2016 04:43
@Redmega ;-)
@Redmega Plus he’d have to assign the splice to a new array
amrezo
@amrezo
Aug 26 2016 04:45
YES! I got it right!
Angel J Piscola
@Redmega
Aug 26 2016 04:45
Shame that push doesn't chain properly
Nice work :thumbsup:
amrezo
@amrezo
Aug 26 2016 04:45
thanks @Redmega and @jgresalfi
CamperBot
@camperbot
Aug 26 2016 04:45
amrezo sends brownie points to @redmega and @jgresalfi :sparkles: :thumbsup: :sparkles:
:cookie: 216 | @jgresalfi |http://www.freecodecamp.com/jgresalfi
:warning: amrezo already gave redmega points
Angel J Piscola
@Redmega
Aug 26 2016 04:49
@sansae What's the expected outcome again?
Daniel
@profoundhub
Aug 26 2016 04:54
@jgresalfi @Redmega :+1: good job everyone! @amrezo
amrezo
@amrezo
Aug 26 2016 04:54
thanks :D
Vishon
@Symbolistic
Aug 26 2016 04:57
im having an issue right now with the "Profile Lookup" Javascript exercise.
i usually got 4 checks, saying I completed 4 of the 5 tasks with this code

function lookUpProfile(firstName, prop){
// Only change code below this line
for(i=0;i<5;i++){
if(contacts[i].firstName===firstName && contacts[i].hasOwnProperty(prop) === true){
return contacts[i][prop];
}

else if(contacts[i].firstName===firstName && contacts[i].hasOwnProperty(prop)===false){
  return "No such property";
}

}
// Only change code above this line
}

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

but then i add this line into the for loop and i end up only having 1 check mark and losing the other 4...
else if(contacts[i].hasOwnProperty(firstName)===false){
  return "No such contact";
}
olgi3rd
@olgi3rd
Aug 26 2016 05:02
How to read other people's code?
Andrew Kay
@andrewjkay
Aug 26 2016 05:06
I've got a question regarding the Return Largest Numbers challenge. What I have console.logs the max of each of the four arrays, but also logs 1 first..? not sure what's up, I'd appreciate any input
billpzt
@billpzt
Aug 26 2016 05:06
For the Record Collection exercise: I couldn't copy and paste my code into DevTools, the DevTools tutorial was going to take too long and the bracket vs dot notation didn't have the info I was looking for, so I just compared my code with the solution at the GitHub page and made sure I followed along step by step to understand the logic. So: Thanks @leftynaut @DarrenJansen for your help with Checkpoint: Record Collection
CamperBot
@camperbot
Aug 26 2016 05:06
billpzt sends brownie points to @leftynaut and @darrenjansen :sparkles: :thumbsup: :sparkles:
:cookie: 271 | @darrenjansen |http://www.freecodecamp.com/darrenjansen
:cookie: 549 | @leftynaut |http://www.freecodecamp.com/leftynaut
Andrew Kay
@andrewjkay
Aug 26 2016 05:06
This message was deleted
John Carlo
@JohnCarlo
Aug 26 2016 05:07

Guys is there a bug in Javascript Escapet strings?


var myStr="FirsLine \n Secondline \r ThirdLine";

this is my code

Chris Cullen
@123xylem
Aug 26 2016 05:08
$("#button").click(location.reload());
Is this button right for reloading the page?
Andrew Kay
@andrewjkay
Aug 26 2016 05:09


function largestOfFour(arr) {
  var largestArr = []
  for(x=0;x<4;x++) {
      var largestNum = (Math.max.apply(Math, arr[x]));
console.log(largestNum);
    }
  }

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
fixed it with duct tape


function largestOfFour(arr) {
  var largestArr = []
  for(x=0;x<4;x++) {
      var largestNum = (Math.max.apply(Math, arr[x]));
      if (largestNum != 1) {
console.log(largestNum);
      }
    }
  }

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Hèlen Grives
@mesmoiron
Aug 26 2016 05:12
@Vishon sorry I can't grab nickname on mobile. Anyway you should carefully examine your if else statements. Sometimes only one gets executed and the rest ignored. They may be overlapping in functionality. Review the logic.
Angel J Piscola
@Redmega
Aug 26 2016 05:13
Am I taking extra steps I don't need to take?
/* jshint esversion:6 */

//Normally I'd just use _.xor...
function diffArray(r1,r2) {
  return [].concat(r1,r2).filter(x => !r2.filter(x => ~r1.indexOf(x)).concat(r1.filter(x => ~r2.indexOf(x))).includes(x));
}

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
@123xylem jqueryevent handlers take a function reference. You're calling a function and putting the result there instead. Try $("#button").click(location.reload);
Vishon
@Symbolistic
Aug 26 2016 05:15
@mesmoiron Yeah it seems like they're overlapping, I just don't understand how to fix that.
Markus Kiili
@Masd925
Aug 26 2016 05:19
@Redmega I think the concat+filter+indexOf+lastIndexOf is a bit simpler solution.
Hèlen Grives
@mesmoiron
Aug 26 2016 05:19
@JohnCarlo
lloan alas
@ledkyb
Aug 26 2016 05:19
Does anyone know if there is a reason why an algorithm challenge would not pass even though the correct answers are produced?
Markus Kiili
@Masd925
Aug 26 2016 05:19
@ledkyb Are you using global variables?
lloan alas
@ledkyb
Aug 26 2016 05:20
@Masd925 Yeah
Markus Kiili
@Masd925
Aug 26 2016 05:20
@ledkyb They mess up FCC tests.
Hèlen Grives
@mesmoiron
Aug 26 2016 05:20
@JohnCarlo it works for me
lloan alas
@ledkyb
Aug 26 2016 05:20
@Masd925 Oh lord, lol. Mkay - I'll look in to that, haha. Thanks
CamperBot
@camperbot
Aug 26 2016 05:20
ledkyb sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2365 | @masd925 |http://www.freecodecamp.com/masd925
John Carlo
@JohnCarlo
Aug 26 2016 05:21
@mesmoiron is there anything wrong on my code :( i stuck in this simple escape string challenge
Julian
@WizrdJim
Aug 26 2016 05:21
I'm having trouble figuring out how to use replace to remove all punctuation from a string.
strCheck=str.toLowerCase().replace(/_.,/g,"");
Markus Kiili
@Masd925
Aug 26 2016 05:23
@WizrdJim Palindrome challenge?
Julian
@WizrdJim
Aug 26 2016 05:23
yep
Vishon
@Symbolistic
Aug 26 2016 05:23
smashing head into keyboard jesus god, javascript pisses me off...
Hèlen Grives
@mesmoiron
Aug 26 2016 05:23
@JohnCarlo have you called the variable? myStr; because it prints new lines correctly
Markus Kiili
@Masd925
Aug 26 2016 05:23
@WizrdJim You could look at \W and \w metacharacters.
Hèlen Grives
@mesmoiron
Aug 26 2016 05:25
@Symbolistic I luckily passed that stage. There's hope haha I know what you mean,
Julian
@WizrdJim
Aug 26 2016 05:25
@Masd925 like this? strCheck=str.toLowerCase().replace(/\W\w/g,"");
Angel J Piscola
@Redmega
Aug 26 2016 05:25
@Masd925 Kudos
function diffArray(r1,r2) {
  return [].concat(r1,r2).filter((x,y,z) => z.lastIndexOf(x)===z.indexOf(x))
}
@Masd925 Thanks, rather, so the bot can understand me. ;)
CamperBot
@camperbot
Aug 26 2016 05:25
redmega sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2366 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Aug 26 2016 05:26
@Redmega That is the most elegant one I have found.
@WizrdJim You only need one of those W or w.
Angel J Piscola
@Redmega
Aug 26 2016 05:26
Seriously. It's very concise
John Carlo
@JohnCarlo
Aug 26 2016 05:26
@mesmoiron yeah and i already did
@mesmoiron This error is making me crazy " myStr should have encoded text with the proper escape sequences and no spacing."
 but this is my code
Angel J Piscola
@Redmega
Aug 26 2016 05:27
Alright, it's way too late for me to deal with the roman numeral challenge right now
John Carlo
@JohnCarlo
Aug 26 2016 05:27
@mesmoiron
Angel J Piscola
@Redmega
Aug 26 2016 05:27
GOod night all
John Carlo
@JohnCarlo
Aug 26 2016 05:27
@mesmoiron

var myStr;

myStr="FirsLine\n\\Secondline\r\\ThirdLine";
Hèlen Grives
@mesmoiron
Aug 26 2016 05:28
@WizrdJim one way to do it; select all alpha numeric characters and negate it. (Stackoverflow)
Julian
@WizrdJim
Aug 26 2016 05:29
@mesmoiron are you saying like skip the replace function all together?
Markus Kiili
@Masd925
Aug 26 2016 05:31
@WizrdJim Using one of \w or \W gets you quite close. Just some wrestling with one more character.
Julian
@WizrdJim
Aug 26 2016 05:33
@Masd925 \s for white space as well?
John Carlo
@JohnCarlo
Aug 26 2016 05:34

@mesmoiron i try to use the console of the web and put this code


var myStr;

myStr="FirsLine\n\\Secondline\\nThirdLine";

i use \n in before the thirdline coz carriage return not working on web console

Vishon
@Symbolistic
Aug 26 2016 05:34
man screw this garbage, im going to sleep before i end up breaking something. im done.
Markus Kiili
@Masd925
Aug 26 2016 05:34
@WizrdJim There are many ways, but there is a metacharacter for all the non-alphanumerics, so it is easier to use it.
Julian
@WizrdJim
Aug 26 2016 05:35
@Masd925 which is /w
Andrew Kay
@andrewjkay
Aug 26 2016 05:36
sorry guys afk for a sec
swapnildaddikar
@swapnildaddikar
Aug 26 2016 05:36
guys anyone here knows what a callback function is ?
Markus Kiili
@Masd925
Aug 26 2016 05:37
@WizrdJim So \W is all characters except alphanumerics. Underscore is in \w, so you need to remove it separately.
Chris Cullen
@123xylem
Aug 26 2016 05:37
@Redmega thanks
CamperBot
@camperbot
Aug 26 2016 05:37
:cookie: 98 | @redmega |http://www.freecodecamp.com/redmega
123xylem sends brownie points to @redmega :sparkles: :thumbsup: :sparkles:
Chris Cullen
@123xylem
Aug 26 2016 05:38
 if (userX) {
    $("#" + choice + "").text("O");

    console.log(choice + " cpumove");

    removeChoice(choice);

    console.log(choices + " choices array after cpumove")
  } else {
    $("#" + choice + "").text("X");
My tic tac inputs are done in JS... IS there a way of me saying O has class of color:blue in css or is there some kind of way of me changing the O and X color?
Markus Kiili
@Masd925
Aug 26 2016 05:38
@swapnildaddikar A function passed as an argument to another function.
Hèlen Grives
@mesmoiron
Aug 26 2016 05:38
@WizrdJim Why do you have double escape after \n? That;s not necessary.
Chris Cullen
@123xylem
Aug 26 2016 05:38
Or Can I create a var in js that has a class in css?
Turns out I cant
Julian
@WizrdJim
Aug 26 2016 05:43
@mesmoiron I have no idea as to what you maybe even referring to i do know i dont know how to get rid of the stupid underscore
Markus Kiili
@Masd925
Aug 26 2016 05:46
@WizrdJim You can use brackets [] and _ and \W
ZZPot
@ZZPot
Aug 26 2016 05:49
how to delete or change on_click handler?
I reassign it to another function, but it still executes previous code and new too
Hèlen Grives
@mesmoiron
Aug 26 2016 05:54
@WizrdJim sorry was trying it out and a bit frustrated why it didn't work. Had to find the assignment. Ok here it is: the second line is \SecondLine. So the backlash has to be escaped too. Further every spacing you type will be a space. The assignment says no spacing. So type no space
Keith
@kmcdougal
Aug 26 2016 05:55

1.randomFraction should return a random number.
2.The number returned by randomFraction should be a decimal.
3.You should be using Math.random to generate the random decimal number.

function randomFraction() {
return Math.floor(Math.random() /5);

what am i missing?

Hèlen Grives
@mesmoiron
Aug 26 2016 05:55
@WizrdJim \SecondLine\ thus \SecondLine\
Markus Kiili
@Masd925
Aug 26 2016 05:55
@ZZPot JS or jQuery?
ZZPot
@ZZPot
Aug 26 2016 05:56
@Masd925 jq
Joseph
@revisualize
Aug 26 2016 05:56
So, I was at the Seattle Software Craftsmanship Community meetup tonight and at the after social someone told me.. You should really check out FreeCodeCamp. I was like... :|
Hèlen Grives
@mesmoiron
Aug 26 2016 05:56
@WizrdJim should have used the backticks as the double backslashes are vanishing. Haha
Markus Kiili
@Masd925
Aug 26 2016 05:56
@ZZPot You can use $(selector).off("eventName")
Julian
@WizrdJim
Aug 26 2016 05:57
@Masd925 Thanks this has done the job
CamperBot
@camperbot
Aug 26 2016 05:57
wizrdjim sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2367 | @masd925 |http://www.freecodecamp.com/masd925
Joseph
@revisualize
Aug 26 2016 05:57
@WizrdJim \SecondLine\ thus \\SecondLine\\
ZZPot
@ZZPot
Aug 26 2016 05:57
@Masd925 what about reset? I mean, if I want to change behavior?
Markus Kiili
@Masd925
Aug 26 2016 05:58
@ZZPot Depends on the logic I think. You can bind another function for example.
ZZPot
@ZZPot
Aug 26 2016 05:59
and previous still executes with new one
Julian
@WizrdJim
Aug 26 2016 05:59
@revisualize @mesmoiron its getting late and I feel I'll need a full lecture as to what that secondline thing is referring to.
Jack
@jh0l
Aug 26 2016 05:59
is defining something as "" the same as it having a value of undefined?
ZZPot
@ZZPot
Aug 26 2016 06:00
@Jhollond nope
Joseph
@revisualize
Aug 26 2016 06:00
@WizrdJim It's just JS Escape characters.
Jack
@jh0l
Aug 26 2016 06:00
@ZZPot ohe
Joseph
@revisualize
Aug 26 2016 06:00
@Jhollond No.
@Jhollond "" is an empty string. i.e. defined as an empty string.
Jack
@jh0l
Aug 26 2016 06:01
what if the comparison operator is !=
Markus Kiili
@Masd925
Aug 26 2016 06:01
@ZZPot If you unbind the event and bind it again with a new function, the old one should not exist anymore.
Jack
@jh0l
Aug 26 2016 06:01
or ==
Hèlen Grives
@mesmoiron
Aug 26 2016 06:01
@WizrdJim you are already there. One minute. Read the assignment carefully. Type the first word. Type the newline character. Type the second word; but escape the backlashes. Type the cariage return character. Type the last word.
Julian
@WizrdJim
Aug 26 2016 06:03
@revisualize like /t and /n
Hèlen Grives
@mesmoiron
Aug 26 2016 06:04
@WizrdJim "firstword\n\secondword\lrthirdword\
John Carlo
@JohnCarlo
Aug 26 2016 06:04

Hello guys need to clarify something in this challenge
Understand String Immutability

how am i supposed to replace the string in array if i don't still come up to it, so basically i did in this challenge is this:


// Setup
var myStr = "Jello World";

// Only change code below this line

//myStr[0] = "H"; // Fix Me

myStr="Hello World";

i know that this is not right but is it okay for a moment

CamperBot
@camperbot
Aug 26 2016 06:04

welcome to FreeCodeCamp @JohnCarlo!

Hèlen Grives
@mesmoiron
Aug 26 2016 06:04
@WizrdJim \\secondword\\
Julian
@WizrdJim
Aug 26 2016 06:05
@JohnCarlo you should probably just change myStr[0].
Jimmy Yew
@Jimyew
Aug 26 2016 06:06
@JohnCarlo remove the comment and change the first alphabet which is myStr[0]
Hèlen Grives
@mesmoiron
Aug 26 2016 06:07
Is there a place to test markup and so? You know where to put the garbage?
ZZPot
@ZZPot
Aug 26 2016 06:10
@Masd925 thanks, that works, but I should find short way
CamperBot
@camperbot
Aug 26 2016 06:10
zzpot sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2368 | @masd925 |http://www.freecodecamp.com/masd925
Essaid Serhani
@purelight4ever
Aug 26 2016 06:11

Please I need your help on this: // Setup
function abTest(a, b) {
// Only change code below this line

// Only change code above this line

return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
}

// Change values below to test your code
abTest(2,2);

ZZPot
@ZZPot
Aug 26 2016 06:11
@purelight4ever and?
Julian
@WizrdJim
Aug 26 2016 06:11
@mesmoiron thanks while I never figured out the secondline thing I'm glad you tried to help me figure it out. I've finished the stupid assignment already.
CamperBot
@camperbot
Aug 26 2016 06:11
wizrdjim sends brownie points to @mesmoiron :sparkles: :thumbsup: :sparkles:
:cookie: 263 | @mesmoiron |http://www.freecodecamp.com/mesmoiron
LPR-309
@LPR-309
Aug 26 2016 06:12
@mesmoiron JSFiddle
DJ
@qualitymanifest
Aug 26 2016 06:12
@mesmoiron https://gitter.im/FreeCodeCamp/camperbotPlayground is a good place to test markdown
(assuming you were talking about gitter markdown)
LPR-309
@LPR-309
Aug 26 2016 06:12
Oops, I read code. Nevermind. xD
amrezo
@amrezo
Aug 26 2016 06:12
hey everyone I am having trouble solving this challenge: Return Early Pattern for Functions
tried if (a || b > 0) {
return undefined;
}
but it’s not working
the instructions are to Modify the function abTest so that if a or b are less than 0 the function will immediately exit with a value of undefined.
DJ
@qualitymanifest
Aug 26 2016 06:13
@amrezo unfortunately or (||) doesn't work like that. you need to specify the condition on each side
amrezo
@amrezo
Aug 26 2016 06:14
a < 0 && b < 0 ?
kirbyedy
@kirbyedy
Aug 26 2016 06:14
thats AND
swapnildaddikar
@swapnildaddikar
Aug 26 2016 06:14
does anyone know meaning of (for var item in object)
DJ
@qualitymanifest
Aug 26 2016 06:14
you don't need to switch it to and, but yeah, you got the rest right
swapnildaddikar
@swapnildaddikar
Aug 26 2016 06:14
?
kirbyedy
@kirbyedy
Aug 26 2016 06:14
you need OR
amrezo
@amrezo
Aug 26 2016 06:14
ok ok
so a < 0 || b < 0
DJ
@qualitymanifest
Aug 26 2016 06:14
This message was deleted
amrezo
@amrezo
Aug 26 2016 06:14
haha that worked!
thanks a lot
kirbyedy
@kirbyedy
Aug 26 2016 06:14
:ok_hand:
amrezo
@amrezo
Aug 26 2016 06:15
how come OR doesn’t work like that?
DJ
@qualitymanifest
Aug 26 2016 06:15
swapnildaddikar
@swapnildaddikar
Aug 26 2016 06:15
ya
thanks @qualitymanifest
CamperBot
@camperbot
Aug 26 2016 06:15
swapnildaddikar sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star2: 1376 | @qualitymanifest |http://www.freecodecamp.com/qualitymanifest
swapnildaddikar
@swapnildaddikar
Aug 26 2016 06:16
ill read and ask u if any douts
doubts *
so here the var is assigned with the property name and object iterates through the enumerable values
like 0 1 2
?
Markus Kiili
@Masd925
Aug 26 2016 06:21
@swapnildaddikar for...in loop iterates over property keys of enumerable properties of the object itself and those inherited from the prototype chain.
swapnildaddikar
@swapnildaddikar
Aug 26 2016 06:23
for (var prop in userData) {
            console.log(prop + ": " + userData[prop]);
        }
so lets say that the object has property of
name and speciality
and userdata is an objectr
so tis loops goes for
userdata[name] and
userdata[speciality]
?
@Masd925
Markus Kiili
@Masd925
Aug 26 2016 06:25
@swapnildaddikar prop goes through the property keys of userData.
swapnildaddikar
@swapnildaddikar
Aug 26 2016 06:25
name : xyz
speciality :xyz
userdata[name] and
userdata[speciality]
what will be in the [] ?
will it be a number which we get from object.keys or the property name
Markus Kiili
@Masd925
Aug 26 2016 06:27
@swapnildaddikar That should print the property keys and values.
swapnildaddikar
@swapnildaddikar
Aug 26 2016 06:27
im nt getting u
userdata[ what will be over here]
?
inside the braacket
Markus Kiili
@Masd925
Aug 26 2016 06:28
@swapnildaddikar Property keys "name" or "speciality"
swapnildaddikar
@swapnildaddikar
Aug 26 2016 06:28
cool
Markus Kiili
@Masd925
Aug 26 2016 06:28
If I understand your object correctly.
swapnildaddikar
@swapnildaddikar
Aug 26 2016 06:28
userdata[name] and
userdata[speciality] so this is right
?
ya
it has those properties
Markus Kiili
@Masd925
Aug 26 2016 06:29
I think you got it right.
swapnildaddikar
@swapnildaddikar
Aug 26 2016 06:29
cool thanks
Tomekp
@tomaszp84
Aug 26 2016 06:34

Hi there, I' ve got a problem with task called Record Collection:

// 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 updateRecords(id, prop, value) {
if (value === '') {
delete collection[id][prop];
} else if (prop !== "tracks") {
collection[id][prop] = value;
} else {
collection[id][prop].push(value);
}

return collection;
}

// Alter values below to test your code
updateRecords(5439, "tracks", "Take a Chance on Me");

and I have msg like that :"
// 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 updateRecords(id, prop, value) {
if (value === '') {
delete collection[id][prop];
} else if (prop !== "tracks") {
collection[id][prop] = value;
} else {
collection[id][prop].push(value);
}

return collection;
}

// Alter values below to test your code
updateRecords(5439, "tracks", "Take a Chance on Me");

And I get :" TypeError: Cannot read property 'push' of undefined"
deepakSpatil
@deepakSpatil
Aug 26 2016 06:36

Any one knows any tools or site which is good to unminify JS File..
I tried a few but they just Beautify the js they do not resolve the variable names.

so all the function are displayed as a b c etc

Markus Kiili
@Masd925
Aug 26 2016 06:38
@deepakSpatil Change those a,b into descriptive variable names? Not possible.
Egoscio
@Egoscio
Aug 26 2016 06:38
@deepakSpatil I'm not really sure if that's possible. Variables and functions are named by the developer. Once it's minified in that fashion, said data is simply lost.
Unless you have some sort of AI that can intelligently generate them. Otherwise, they're lost just like comments are lost.
Darth Skywalker
@adityaparab
Aug 26 2016 06:40
You will need corresponding source map to un-uglify the code
Ciprian
@Cipriot
Aug 26 2016 06:51

// Example
var ourArray = ["John", 23];

// Only change code below this line.
var myArray = [];

Chris Cullen
@123xylem
Aug 26 2016 06:54
http://codepen.io/123xylem/pen/JKqYZY?editors=1111
Review my TicTacToe Game.. There are some problems including that the AI is thicker than pavarottis waistline...
It fulfills the user stories but I dont know if I will submit it yet.
LuisFromDP
@LuisFromDP
Aug 26 2016 06:55
Hey, anyone wants to pair and help with the "Nesting For Loops"?
Egoscio
@Egoscio
Aug 26 2016 07:01
You could just ask for help here if you encounter any :)
LuisFromDP
@LuisFromDP
Aug 26 2016 07:01
Here's my code

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

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

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

swapnildaddikar
@swapnildaddikar
Aug 26 2016 07:03
it should be arr.length
@LuisFromDP
your product is just a variable storing the result
function multiplyAll(arr) ... here arr contains [[1,2],[3,4],[5,6,7]]
LuisFromDP
@LuisFromDP
Aug 26 2016 07:05
Thanks you! Its works! I had it right earlier but forgot the [i] but i thought maybe it was the product
swapnildaddikar
@swapnildaddikar
Aug 26 2016 07:05
cool :D
product is an variable
just for storing
the argument passed is the actual array
LuisFromDP
@LuisFromDP
Aug 26 2016 07:08
product *= arr[i][j] what does that line actually do?
I'm just trying to figure out the structure of the math in this, sometime i solve these problems but I'm still lost on how it actually really works
swapnildaddikar
@swapnildaddikar
Aug 26 2016 07:09
ya u will get good at it eventually
Egoscio
@Egoscio
Aug 26 2016 07:09
sets the value of product to itself multiplied by the queried value from the nested array or dictionary.
Markus Kiili
@Masd925
Aug 26 2016 07:10
@LuisFromDP That is the same as product = product * arr[i][j]
Jack
@jh0l
Aug 26 2016 07:10
I get an error when I do this var locale_time = [Number(astronomy.current_time.hour), Number(astronomy.current_time.minute]);
swapnildaddikar
@swapnildaddikar
Aug 26 2016 07:10
for now u can just write the complete syntax
so u can understand better
both the functions do the same thing
Jack
@jh0l
Aug 26 2016 07:10
does this mean I have to define variables with = Number(astronomy.current_time.hour) in them?
LuisFromDP
@LuisFromDP
Aug 26 2016 07:11
Thanks guys!
swapnildaddikar
@swapnildaddikar
Aug 26 2016 07:11
product = product arr[i][j] and product=arr[i][j];
forgot the * sorry
Egoscio
@Egoscio
Aug 26 2016 07:11
@Jhollond Can't say much without seeing your error.
Jack
@jh0l
Aug 26 2016 07:12
it says it expected a ]
*there was an unexpected ]
LuisFromDP
@LuisFromDP
Aug 26 2016 07:12
I see, it's just the change of syntax that confuses me, i get it now
Egoscio
@Egoscio
Aug 26 2016 07:12
At the end, swap the ]); with )];
Jack
@jh0l
Aug 26 2016 07:12
you can't put methods in an array when defining it?
oh hey yeah!
Gordon
@gordoh
Aug 26 2016 07:13
Hey guys. I am busy creating a rock paper scissors game and trying to code it so that if the user chooses an option besides for rock, paper scissors, a loop will come up and make the user repick. Its almost working except now the loop keeps running no matter what the user picks so I have to go to task manager and end the browser window. I dont know what is wrong with my code, please will somebody look at it and give me some advice?
Egoscio
@Egoscio
Aug 26 2016 07:13
Sometimes it's the small stuff :)
Gordon
@gordoh
Aug 26 2016 07:13
var userChoice = prompt("Do you choose rock, paper or scissors?");
do{
    if (userChoice === "rock"){
         userChoice = "rock";}
        else if (userChoice === "Rock"){
         userChoice = "rock";}
        else if (userChoice === "paper"){
             userChoice = "paper";}
            else if (userChoice === "Paper"){
                 userChoice = "paper";}
                else if (userChoice === "scissors"){
                     userChoice = "scissors";}
                    else if (userChoice === "Scissors"){
                         userChoice = "scissors"}
                        else {userChoice = "invalid";
                        prompt("That choice is invalid. Please choose either rock, paper or scissors")}
                   while (userChoice === "invalid")      }
Jack
@jh0l
Aug 26 2016 07:13
thank you :) @Egoscio
CamperBot
@camperbot
Aug 26 2016 07:13
jhollond sends brownie points to @egoscio :sparkles: :thumbsup: :sparkles:
:cookie: 24 | @egoscio |http://www.freecodecamp.com/egoscio
Egoscio
@Egoscio
Aug 26 2016 07:14
@gordoh What's up with the indentation?
Gordon
@gordoh
Aug 26 2016 07:14
I dont know thats how code academy works
sorry about that lol
Egoscio
@Egoscio
Aug 26 2016 07:14
var userChoice = prompt("Do you choose rock, paper or scissors?");
do {
    if (userChoice === "rock") {
        userChoice = "rock";
    } else if (userChoice === "Rock") {
        userChoice = "rock";
    } else if (userChoice === "paper") {
        userChoice = "paper";
    } else if (userChoice === "Paper") {
        userChoice = "paper";
    } else if (userChoice === "scissors") {
        userChoice = "scissors";
    } else if (userChoice === "Scissors") {
        userChoice = "scissors"
    } else {
        userChoice = "invalid";
        prompt("That choice is invalid. Please choose either rock, paper or scissors")
    }
    while (userChoice === "invalid")
}
Gordon
@gordoh
Aug 26 2016 07:15
so I have told it to basically ignore if the user sets a capital letter so it wont get stumped by that. And then if he selects anything except rock, paper or scissors, the window will prompt him again to make another choice
Egoscio
@Egoscio
Aug 26 2016 07:16
You can just use .toLocaleLowerCase()
Gordon
@gordoh
Aug 26 2016 07:16
I dont know that... I havent learnt it yet
Donatas
@Lieutenant4
Aug 26 2016 07:16
var lookup = {
    "alpha": "Adams",
    "bravo": "Boston",
    "charlie": "Chicago",
    "delta": "Denver",
    "echo": "Easy",
    "foxtrot": "Frank"
  };
hi there, started lookup, don't know what i'm doing it wrong
Egoscio
@Egoscio
Aug 26 2016 07:16
Ah! Well it's especially useful in your case, I recommend taking a peak to trim some fat :)
Gordon
@gordoh
Aug 26 2016 07:17
so I would say if (userChoice === "Rock") { userChoice.toLocaleLowerCase()
like that?
okay never mind that I will check it out
Im more interested in why my loop wont stop running
Egoscio
@Egoscio
Aug 26 2016 07:17
Nah, just do if (userChoice.toLocaleLowerCase() === 'rock') { /* do something */ }
Best would be to do a switch statement, but I'll let you advance at your own pace.
Gordon
@gordoh
Aug 26 2016 07:18
so switch instead of if eles
else
Vishon
@Symbolistic
Aug 26 2016 07:18
I swear to god this profile lookup exercise is pissing me off so much right now
Gordon
@gordoh
Aug 26 2016 07:18
I have learnt switch statements already so I can change it
Egoscio
@Egoscio
Aug 26 2016 07:18
Yeah, I find it more suitable for your situation, but...
Dan Couper
@DanCouper
Aug 26 2016 07:18
What's do doing there
Vishon
@Symbolistic
Aug 26 2016 07:18
i been trying to figure this stupid thing out for 4 hours now
and i am about to break somethin
Gordon
@gordoh
Aug 26 2016 07:19
the "do" ensures that the loop runs at least once
Egoscio
@Egoscio
Aug 26 2016 07:19
Your problem is you need to do userChoice = prompt("That choice is invalid. Please choose either rock, paper or scissors")
Vishon
@Symbolistic
Aug 26 2016 07:19

function lookUpProfile(firstName, prop){
// Only change code below this line
for(i=0;i<5;i++){
if(contacts[i].firstName===firstName && contacts[i].hasOwnProperty(prop)===true){
return contacts[i][prop];
}

else if(contacts[i].hasOwnProperty(firstName)===false){
  return "No such contact";
}

else if(contacts[i].firstName===firstName && contacts[i].hasOwnProperty(prop)===false){
  return "No such property";
}

}
// Only change code above this line
}

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

Dan Couper
@DanCouper
Aug 26 2016 07:19
Ah crap I missed the while, sorry
Gordon
@gordoh
Aug 26 2016 07:19
@Symbolistic i have spend the whole of yesterday on it and still i havent figured it out
Vishon
@Symbolistic
Aug 26 2016 07:19
it makes no damn sense why its not working
i've tried to rewrite it different ways nothing works
apparently the if statements, are overriding the ones above them
Egoscio
@Egoscio
Aug 26 2016 07:20
@DanCouper Not a problem :) Hope that fixes it, leaves you some time to improve with lowercase and switch too once you are comfortable with them :)
Vishon
@Symbolistic
Aug 26 2016 07:20
its so stupid, makes no sense why its doing that
Egoscio
@Egoscio
Aug 26 2016 07:21
@Symbolistic Care you describe what's your expectation?
Gordon
@gordoh
Aug 26 2016 07:21
@Egoscio il be back but Im sticking around to discuss this profile lookup issue
Vishon
@Symbolistic
Aug 26 2016 07:21
"Kristian", "lastName" should return "Vos"
"Sherlock", "likes" should return ["Intriguing Cases", "Violin"]
"Harry","likes" should return an array
"Bob", "number" should return "No such contact"
"Akira", "address" should return "No such property"
basically this is the full code.

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

function lookUpProfile(firstName, prop){
// Only change code below this line
for(i=0;i<5;i++){
if(contacts[i].firstName===firstName && contacts[i].hasOwnProperty(prop)===true){
return contacts[i][prop];
}

else if(contacts[i].hasOwnProperty(firstName)===false){
  return "No such contact";
}

else if(contacts[i].firstName===firstName && contacts[i].hasOwnProperty(prop)===false){
  return "No such property";
}

}
// Only change code above this line
}

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

Egoscio
@Egoscio
Aug 26 2016 07:22
Hmm, could you expand the formatting please? So it's easier to analyze?
LuisFromDP
@LuisFromDP
Aug 26 2016 07:22
@Lieutenant4 remove quotes from the properties, aplha, bravo...etc
Gordon
@gordoh
Aug 26 2016 07:22
Why isnt it formatting properly. Its hard to read the way it is posted
Vishon
@Symbolistic
Aug 26 2016 07:22
how do u format
Gordon
@gordoh
Aug 26 2016 07:22

Egoscio
@Egoscio
Aug 26 2016 07:22
Same way you did, just change the position of the `
friesenet21
@friesenet21
Aug 26 2016 07:22
!not '''
CamperBot
@camperbot
Aug 26 2016 07:22
:bulb: to format code use backticks! ``` more info
Donatas
@Lieutenant4
Aug 26 2016 07:22
@LuisFromDP still same
Egoscio
@Egoscio
Aug 26 2016 07:22
(triple `)
Gordon
@gordoh
Aug 26 2016 07:22
```js
LuisFromDP
@LuisFromDP
Aug 26 2016 07:23

@Lieutenant4
var lookup = {
alpha:"Adams",
bravo:"Boston",
charlie:"Chicago",
delta:"Denver",
echo: "Easy",
foxtrot: "Frank"
};

result = lookup[val];

Egoscio
@Egoscio
Aug 26 2016 07:23
You could also just post it on hastebin.com or gist
That way it won't spam the chat.
Vishon
@Symbolistic
Aug 26 2016 07:23

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

function lookUpProfile(firstName, prop){
// Only change code below this line
for(i=0;i<5;i++){
if(contacts[i].firstName===firstName && contacts[i].hasOwnProperty(prop)===true){
return contacts[i][prop];
}

else if(contacts[i].hasOwnProperty(firstName)===false){
  return "No such contact";
}

else if(contacts[i].firstName===firstName && contacts[i].hasOwnProperty(prop)===false){
  return "No such property";
}

}
// Only change code above this line
}

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

ughhh
ill post it on hastebin
Gordon
@gordoh
Aug 26 2016 07:24
you put the ```js on top
then your code
then ```
under
Vishon
@Symbolistic
Aug 26 2016 07:24

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


function lookUpProfile(firstName, prop){
// Only change code below this line
   for(i=0;i<5;i++){
    if(contacts[i].firstName===firstName && contacts[i].hasOwnProperty(prop)===true){
      return contacts[i][prop];
    }

    else if(contacts[i].hasOwnProperty(firstName)===false){
      return "No such contact";
    }

    else if(contacts[i].firstName===firstName && contacts[i].hasOwnProperty(prop)===false){
      return "No such property";
    }

   }
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
Egoscio
@Egoscio
Aug 26 2016 07:24
http://hastebin.com/jisawizoza.js to view correct syntax highlighting
Kent Saeteurn
@sansae
Aug 26 2016 07:25
expected
Vishon
@Symbolistic
Aug 26 2016 07:25
boom got it
Mrsmao
@whb123
Aug 26 2016 07:25
var myStr="I am a \"double quoted \" string inside \" double quotes\" "; // Change this line
where is wrong
Gordon
@gordoh
Aug 26 2016 07:27
function lookUpProfile(firstName, prop){
// Only change code below this line



  for (i=0;i < contacts.length; i++){

 if (contacts[i].firstName === firstName) {
   if (contacts[i].prop === prop){
       return contacts[i][prop];

 }}
 if (contacts[i].firstName != firstName){
  return "No such contact";
  }
  if (contacts[i].prop.hasOwnProperty){
    return "No such property";}
 }
this is what mine looks like. its also not right though...
Im so over this challenge @Symbolistic its ridiculous
Vishon
@Symbolistic
Aug 26 2016 07:27
it really is
Egoscio
@Egoscio
Aug 26 2016 07:27
First off, as Gordon demonstrated, don't hardcode the length of the array.
( in the for loop )
Gordon
@gordoh
Aug 26 2016 07:28
Yea use contacts.length rather than 5
Egoscio
@Egoscio
Aug 26 2016 07:29
Also, for the sake of legibility, you can declare a variable in the for loop: var contact = contacts[i]
and access that instead
Vishon
@Symbolistic
Aug 26 2016 07:30
Honestly, screw this exercise, i'm just gonna look at the answer i dont care anymore.
Gordon
@gordoh
Aug 26 2016 07:30
How do you do that? @Symbolistic
Egoscio
@Egoscio
Aug 26 2016 07:30
You don't...
friesenet21
@friesenet21
Aug 26 2016 07:31
@Symbolistic @gordoh It may help to think about which case you want to return first . They don't all need if
Mrsmao
@whb123
Aug 26 2016 07:31
noone can answer me?
help help
CamperBot
@camperbot
Aug 26 2016 07:31
no wiki entry for: help
Egoscio
@Egoscio
Aug 26 2016 07:31
@whb123 Your string has no issues on my side. I ran it in my node REPL and no errors.
Vishon
@Symbolistic
Aug 26 2016 07:31
I'm so over this exercise, its not worth busting my brain over.
Mrsmao
@whb123
Aug 26 2016 07:32
i cant have the result
...
Egoscio
@Egoscio
Aug 26 2016 07:32
@Symbolistic I actually recommend covering it, searching the answers defeats the purpose. Also, you're somewhat lacking the required skills to continue until you can solve it yourself imo
Vishon
@Symbolistic
Aug 26 2016 07:33
doesn't matter, i'll learn as i move on and read the answer.
no point ripping apart my brain and potentially breaking my pc over this
Gordon
@gordoh
Aug 26 2016 07:34
@Symbolistic personally, I think its teaching you a very small lesson that wont be used very often. but I do agree that you should be able to figure it out alone if you want to get to the harder stuff. As for me, I am taking a break on FCC and trying out CodeAcademy. So far it has helped me get a better understanding of jS, and i am gonna come back to this once I have gained the required knowledge to use it
*crack it
Egoscio
@Egoscio
Aug 26 2016 07:35
Typically, every single one of the exercises has a real world use, because when you're in the real world, you need to be able to understand and solve anything that comes in your way.
LPR-309
@LPR-309
Aug 26 2016 07:36
@whb123 inside \" double quotes\" "; Check for spaces between " and double, and also the space between the two " at the very end. FCC challenges can be very picky about small things like that, it may be messing it up
Gordon
@gordoh
Aug 26 2016 07:36
Well, cheers guys. Im gonna go now change that rock paper scissors game to try get it working properly
Egoscio
@Egoscio
Aug 26 2016 07:37
good luck
Chris Cullen
@123xylem
Aug 26 2016 07:37
http://codepen.io/123xylem/pen/JKqYZY?editors=1111
HEY! Review my TicTacToe Game.. There are some problems including that the AI is thicker than pavarottis waistline...
but It fulfills the user stories I just dont know if I will submit it yet.
Alice
@yutiyi
Aug 26 2016 07:38
更改myFunction 来生成一个随机数取代 0,这题什么意思啊?
Egoscio
@Egoscio
Aug 26 2016 07:38
@123xylem Does it randomly place it in an open spot or is there an actual algorithm behind this?
Chris Cullen
@123xylem
Aug 26 2016 07:39
@Egoscio random... I havent worked out the algo logic yet and getting here was hard enough so far
Jimmy Yew
@Jimyew
Aug 26 2016 07:40

function repeatStringNumTimes(str, num) {
  // repeat after me

  return str.repeat(num);

}

repeatStringNumTimes("abc", 3);
Egoscio
@Egoscio
Aug 26 2016 07:40
Ah, fair enough. Well done! I'd recommend not forcing the input to be capital though, easy and rewarding fix :+1:
Jimmy Yew
@Jimyew
Aug 26 2016 07:40
Hello people, how do I check for negative (num)?
Chris Cullen
@123xylem
Aug 26 2016 07:40
ok
Dan Couper
@DanCouper
Aug 26 2016 07:40
< 0
Alice
@yutiyi
Aug 26 2016 07:41
。。。。。
Dan Couper
@DanCouper
Aug 26 2016 07:41
@Jimyew < 0
IE is the number less than zero
Chris Cullen
@123xylem
Aug 26 2016 07:42
@Egoscio fix in
Egoscio
@Egoscio
Aug 26 2016 07:42
@Jimyew Does your string have a repeat method?
Chris Cullen
@123xylem
Aug 26 2016 07:42
if X or x
Egoscio
@Egoscio
Aug 26 2016 07:42
@123xylem You could make the input lowercase by default and compare with the lowercase value, or use regular expressions (slightly overkill)
Jimmy Yew
@Jimyew
Aug 26 2016 07:42
@DanCouper tried <0, not working. Hmm...
Chris Cullen
@123xylem
Aug 26 2016 07:42
@Egoscio i just said if usr = X or x
krupa007
@krupa007
Aug 26 2016 07:43
Topic : Manipulate Arrays With unshift .

var myArray = [["John", 23], ["dog", 3]];
myArray.shift();

// Only change code below this line.
myArray.unshift(["paul" , 35 ]);

Jimmy Yew
@Jimyew
Aug 26 2016 07:43
@Egoscio yes. the code have ; im returning the string with repeated "num" of times
krupa007
@krupa007
Aug 26 2016 07:43
i 'm unable to run
Mrsmao
@whb123
Aug 26 2016 07:43
var myStr=" I am a \" double quoted \" string inside \" double quotes \" ";
@LPR-309
cant
Dan Couper
@DanCouper
Aug 26 2016 07:43
@Jimyew then it's something else in the code, you'll need to post what you're trying to do
Manoj
@Manoj-Fernando
Aug 26 2016 07:44
how do i access the nested object's properties?
can anyone help?
Egoscio
@Egoscio
Aug 26 2016 07:44
@123xylem if (user.match(/x/i)) { }
i makes it case insensitive
@Manoj-Fernando Are you using bracket or dot notation?
jcfa01
@jcfa01
Aug 26 2016 07:45
function largestOfFour(arr) {
  // You can do this!
  largest = [];
  for(var i = 0;i < 4;i++) {
    for(var j = 0;j < 4;j++) {
      //console.log(arr[i][j]);
      if (largest < arr[i][j]) {
        largest[i] = arr[i][j];
        //console.log(arr[i][j]);
      }
    }
  }
  return largest;
can someone tell me what's wrong with this code it only outputs the 1st and second array largest [5,13]
Jimmy Yew
@Jimyew
Aug 26 2016 07:45

@DanCouper I'm doing Basic Algo Scripting: Repeat a String

Repeat a given string (first argument) num times (second argument). Return an empty string if num is not a positive number.

Dan Couper
@DanCouper
Aug 26 2016 07:45
@Jimyew ah, I see
jamesmillerho
@jamesmillerho
Aug 26 2016 07:46
@jcfa01
function largestOfFour(arr){
  return arr.map(function(a){return Math.max.apply(null, a);});
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Manoj
@Manoj-Fernando
Aug 26 2016 07:47
@Egoscio dot notation
Egoscio
@Egoscio
Aug 26 2016 07:47
@jcfa01 I don't understand, how are you using a less than operator for an array?
Jimmy Yew
@Jimyew
Aug 26 2016 07:47
@jamesmillerho you just posted the whole answer in different style to jcfa1. I don't think he/she understand
Dan Couper
@DanCouper
Aug 26 2016 07:47
@Jimyew What you have fine, you just need a condition first. if (number < 0) return '' on the line before the string.repeat should do it
Egoscio
@Egoscio
Aug 26 2016 07:48
@Manoj-Fernando myObject.myNestedObject1.myNestedObject2
Manoj
@Manoj-Fernando
Aug 26 2016 07:48
@Egoscio its not working
Egoscio
@Egoscio
Aug 26 2016 07:48
Assuming:
var myObject = {
   myNestedObject1: {
      myNestedObject2: // some value
   }
}
Jimmy Yew
@Jimyew
Aug 26 2016 07:49
@DanCouper that's a great help! Thanks
CamperBot
@camperbot
Aug 26 2016 07:49
jimyew sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:cookie: 197 | @dancouper |http://www.freecodecamp.com/dancouper
Manoj
@Manoj-Fernando
Aug 26 2016 07:49
@Egoscio 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"
}
};
Egoscio
@Egoscio
Aug 26 2016 07:50
@Manoj-Fernando You can't use dot notation for numbers.
That requires bracket notation.
collection["2548"].album
Manoj
@Manoj-Fernando
Aug 26 2016 07:51
@Egoscio ok bro let me try
schoebli93
@schoebli93
Aug 26 2016 07:51
How do i filter out NaN from an array using array.filter()?
[1, null, NaN, 2, undefined] should return [1, 2]
Markus Kiili
@Masd925
Aug 26 2016 07:52
@schoebli93 You can test for value NaN with val!==val.
Or for not being NaN with val===val