These are chat archives for FreeCodeCamp/HelpJavaScript

12th
Jun 2016
Walton Wang
@wangwalton
Jun 12 2016 00:00
The usually solution of other campers create "TypeError: Cannot read property 'push' of undefined"
Diego Mayer
@Chrono79
Jun 12 2016 00:04
@wangwalton show your code, yes, recently they've added a new test case
@nehap12 you don't need the () and make sure collection[idToCompare][prop] is an array before using push
Walton Wang
@wangwalton
Jun 12 2016 00:09
// 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 !== "" && prop !== "tracks") {
    collection[id][prop] = value;
  } else if (value !== "" && prop == "tracks") {
    if (collection[id].hasOwnProperty("tracks")) {
      collection[id].tracks.push(value);
    } 
    collection[id]['tracks'] = value;
  } else if (value === "") {
    delete collection[id][prop];
  }
  return collection;
}

// Alter values below to test your code
updateRecords(5439, "tracks", "Take a Chance on Me");
Thanks! This is the closest I've gotten the code to work. But it doesn't create an array at 'tracks'.
bitgrower
@bitgrower
Jun 12 2016 00:13

@wangwalton -- what you need to do to create an array "tracks" for id 5439 is first, do a collection[id].hasOwnProperty(prop);

if it doesn't have the property, do this: collection[id][prop] = [value];

shivamsonu29
@shivamsonu29
Jun 12 2016 00:14
if(navigator.geolocation){
  navigator.geolocation.getCurrentPosition(function(position){
  var long=position.coords.longitude;
  var lat=position.coords.latitude;
  var api
api="#";
$.getJSON(api,function(data){

 $("#data").html("kklj");

});

});  
}
writing getJSON function after geolocation coding is not working but writing it before geolocation coding, it's working, any solution for this...
Norvin Burrus
@ndburrus
Jun 12 2016 00:14
@nehap12 which exercise is this?
Sean Hayes
@SeaHay
Jun 12 2016 00:17

for the introduction challange to If statements, it gives an example:


// Example
function ourFunction(isItTrue) {
  if (isItTrue) { 
    return "Yes, it's true";
  }
  return "No, it's false";
}

Wouldn't this function return both responces if "isItTrue" was true?

llamatarianism
@llamatarianism
Jun 12 2016 00:17
@SeaHay no
see, return ends the entire function
when you call a function, it steps through each line (basically, not exactly)
and the moment it reaches the keyword return
Sean Hayes
@SeaHay
Jun 12 2016 00:18
it ignores the rest?
llamatarianism
@llamatarianism
Jun 12 2016 00:18
it ends and the function call evaluates to whatever you returned
yes.
it's like using break or continue in a loop.
Sean Hayes
@SeaHay
Jun 12 2016 00:18
@llamatarianism thank you!
CamperBot
@camperbot
Jun 12 2016 00:18
seahay sends brownie points to @llamatarianism :sparkles: :thumbsup: :sparkles:
:cookie: 752 | @llamatarianism |http://www.freecodecamp.com/llamatarianism
llamatarianism
@llamatarianism
Jun 12 2016 00:18
although tbh
in most cases, I'd recommend using else anyway.
depends.
Walton Wang
@wangwalton
Jun 12 2016 00:19
@bitgrower Oh wow, thanks so much!
CamperBot
@camperbot
Jun 12 2016 00:19
wangwalton sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star2: 1096 | @bitgrower |http://www.freecodecamp.com/bitgrower
Abhishek Khurana
@abs-code-lab
Jun 12 2016 00:19
Hi all! I'm starting the Random Quote Machine exercise, but am a bit lost on how to use API's. Do you recommend any tutorials on topics relevant to this exercise (i.e APIs etc) ? Thank you!
Diego Mayer
@Chrono79
Jun 12 2016 00:19

@wangwalton

    if (collection[id].hasOwnProperty("tracks")) {
      collection[id].tracks.push(value);
    } 
    collection[id]['tracks'] = value;

here is your problem, as @bitgrower said, use the hasOwnProperty to check if the property tracks doesn't exist, create it as an array first, the use push <- this isn't exactly what @bitgrower said said, it's another option

bitgrower
@bitgrower
Jun 12 2016 00:19
when they added that test case to Record Collection, they really needed to update the instructions ...
llamatarianism
@llamatarianism
Jun 12 2016 00:19
in this case, I wouldn't use else.
function someFunc(arg) {
  if (arg === somethingInvalidButNotSoInvalidThatWeThrowAnError) return;
  // Do some other, really long, complex stuff.
}
in this case, I would.
function factorial(n) {
  if (n === 0) {
    return 1;
  } else {
    return n * factorial(n - 1);
  }
}
depends which is more clear.
I think using else is more explicit, and therefore usually better
however, if using else would mean the entire rest of your function would be nested
then I wouldn't use it
@abs-code-lab it's fairly simple. I could explain it to you if you want
Abhishek Khurana
@abs-code-lab
Jun 12 2016 00:25
@llamatarianism that's reassuring. I'll do a couple google searches. And yeah! If you could give a high-level explanation that'd be awesoem
Walton Wang
@wangwalton
Jun 12 2016 00:25
@Chrono79 Thanks! I put the collection[id]['tracks'] = value; under an else statement and square bracketed [value] and it worked!
CamperBot
@camperbot
Jun 12 2016 00:25
wangwalton sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1112 | @chrono79 |http://www.freecodecamp.com/chrono79
llamatarianism
@llamatarianism
Jun 12 2016 00:26
@abs-code-lab I'm gonna assume you're using jquery, right?
because trying to do ajax with vanilla JS is frankly mindnumbing, as much as I dislike jquery
also for reference
API doesn't always mean API as in like
http://ip-api.com/# or something
an API is a set of functions and procedures that allow the creation of applications which access the features or data of an operating system, application, or other service according to google. languages, libraries and frameworks all have APIs too.
anyways
assuming you're using jquery
you can just the $.getJSON method to send a request to an API
that sends a GET request to a url, and the website responds with some JSON
JSON is a way of storing data that's based on javascript objects
so then $.getJSON gives you some parsed JSON data, in the form of a javascript object, and you can just operate on that like any other JS object.
llamatarianism
@llamatarianism
Jun 12 2016 00:31
so let's say I call
$.getJSON("http://some-api.com/", function(data) {
  console.log(data);
});
that sends a GET request to http://some-api.com/, which is basically the same as visiting the site.
let's say it responds with '{"foo": "bar", "baz": 5}'
that's a JSON string. it's a string that looks like a javascript object. jQuery then parses that as {foo: "bar", baz: 5}
and then that object gets passed to the callback function as data
Abhishek Khurana
@abs-code-lab
Jun 12 2016 00:33
@llamatarianism beautiful. Thanks for the simple explanation, great starting point for me!
CamperBot
@camperbot
Jun 12 2016 00:33
abs-code-lab sends brownie points to @llamatarianism :sparkles: :thumbsup: :sparkles:
:cookie: 753 | @llamatarianism |http://www.freecodecamp.com/llamatarianism
nehap12
@nehap12
Jun 12 2016 00:34
@Chrono79

// 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) {
var idCorrect = false;
var idToCompare=0;
var hasProp = false;
var arr = [2548,2468,1245,5439];
for(var i=0; i<arr.length; i++){
if(id == arr[i]){
idCorrect = true;
idToCompare = arr[i];
}
}
if(idCorrect === true){
if(value !== "" && prop != "tracks"){
//if(collection[idToCompare].hasOwnProperty(prop) !== true){
collection[(idToCompare)][(prop)] = value;
// }
} else if(value !== "" && prop == "tracks"){
if (collection[(idToCompare)].hasownproperty(prop) === true){
hasProp = true;
}else{
hasProp = false;
}

  if(hasProp === false){
     collection[(idToCompare)][(prop)] = value;
  }else{
     collection[(idToCompare)].tracks.push(value);
  }
} else if(value ===""){
  delete collection[(idToCompare)][prop];
}

}

return collection;
}

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

this is my entire code
     collection[(idToCompare)]['tracks'] = value;
is not working for me
bitgrower
@bitgrower
Jun 12 2016 00:38
what the heck is (idToCompare) ?
Stephen James
@sjames1958gm
Jun 12 2016 00:38
@nehap12 I think an assumption is that id is a valid id, you don't have to do all that work to create another variable. Also, you don't use () inside of []
@nehap12 That should be [value] to create an array.
bitgrower
@bitgrower
Jun 12 2016 00:39
you can use just the id parameter ... and, @sjames1958gm is right, but using .hasOwnProperty is actually better code -- which should be used when adding anything to an object pretty much ... defensive programming ...
Stephen James
@sjames1958gm
Jun 12 2016 00:40
@nehap12 Also it is hasOwnProperty you need to match the case.
No, need to create a boolean and then immediately test it, and if (something === true) doesn't need the === true
if (collection[id].hasOwnProperty(prop)) {
   collection[id].tracks.push(value);
} else {
   collection[id][prop] = [value];
}
Diego Mayer
@Chrono79
Jun 12 2016 00:49
@bitgrower
if(id == arr[i]){
idCorrect = true;
idToCompare = arr[i];
}
pretty strange logic there
MeonAigeanta
@MeonAigeanta
Jun 12 2016 00:49
In Build Random Quote Machine Challenge, what is a URL we can use to get the JSON data?
Creative Shin
@CreativeShin
Jun 12 2016 00:56
function titleCase(str) {
  var splitString= str.split(" ");
  for(var i= 0; i<splitString.length;i++){
    splitString[i]= splitString[i].substring(0,1).toUpperCase();
    if(splitString[i] === 'a' ||splitString[i] === 'the' ||splitString[i] === 'and' ||splitString[i] === 'of'){
      splitString[i] = splitString[i].toUpperCase();
    }
    var string= splitString.join(" ");
  }
  return string;
}

titleCase("I'm a little tea pot");
what to do guys I managed to get the first letters capitalized... its not working though
Title Case a Sentence
help me!!!
CamperBot
@camperbot
Jun 12 2016 00:57

:point_right: adding environment variables [wiki]

Adding Envirioment Variables in Windows

Via GUI

  1. Download Varpanel.
  2. Open Varpanel.
  3. In PATH variable, add the relevant path (for example).

Via Command Line

Refer to this answer on Super User.

:pencil: read more about adding environment variables on the FCC Wiki

Diego Mayer
@Chrono79
Jun 12 2016 00:57
@Creative-Shin you are splitting in words, and replacing them with letters
Stephen James
@sjames1958gm
Jun 12 2016 00:57
@Creative-Shin You have to build the string from the first letter + the rest of the word
Creative Shin
@CreativeShin
Jun 12 2016 00:57
how ... sud I just loop?
@sjames1958gm oh and please dont post the ans
Stephen James
@sjames1958gm
Jun 12 2016 00:58
This message was deleted
Creative Shin
@CreativeShin
Jun 12 2016 00:58
O_O
Stephen James
@sjames1958gm
Jun 12 2016 00:58
@Creative-Shin You never saw that
Creative Shin
@CreativeShin
Jun 12 2016 00:58
haha I did xD
Stephen James
@sjames1958gm
Jun 12 2016 00:59
@Creative-Shin Don't use a loop use string manipulation functions.
Creative Shin
@CreativeShin
Jun 12 2016 00:59
@sjames1958gm thank you !! I didn't know about slice
CamperBot
@camperbot
Jun 12 2016 00:59
creative-shin sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1529 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jun 12 2016 00:59
@Creative-Shin slice is like substr.
Creative Shin
@CreativeShin
Jun 12 2016 00:59
how is it different that substring();
Stephen James
@sjames1958gm
Jun 12 2016 01:01
@Creative-Shin Not really that much different, just something that I have been using, kinds stuck with it.
Creative Shin
@CreativeShin
Jun 12 2016 01:01
ah... so it does the same thing then
lemme read abt it a bit
bitgrower
@bitgrower
Jun 12 2016 01:05
there are 3 or 4 functions that so similar sorts of things on strings ... substr, substring, indexOf, slice ... I think ... :)
not quite sure how they are all different ... but it amuses me there are so many different functions offering similar capapbilities ...
Creative Shin
@CreativeShin
Jun 12 2016 01:07
can I do this splitString[i]= splitString[i].substring(0,1).toUpperCase() + add the rest of the words in the string
Diego Mayer
@Chrono79
Jun 12 2016 01:07
@sjames1958gm @Creative-Shin the difference between slice and substring is that with substring your start index could be greater than the end index (it would swap them internally), with slice it'll return an empty string
Stephen James
@sjames1958gm
Jun 12 2016 01:07
@Creative-Shin yes
Creative Shin
@CreativeShin
Jun 12 2016 01:08
@sjames1958gm how?
Stephen James
@sjames1958gm
Jun 12 2016 01:08
@Creative-Shin You mean add the rest of the letters in the word?
@Creative-Shin The same way you substring the first letter you subtring the rest?
Creative Shin
@CreativeShin
Jun 12 2016 01:08
yea in the same word ... lemme repost the code again
till how much
I dont know the limit
Stephen James
@sjames1958gm
Jun 12 2016 01:09
@Creative-Shin If you only specify the start it goes to the end
Creative Shin
@CreativeShin
Jun 12 2016 01:09
@sjames1958gm @Chrono79 does extra string(1,999) results in empty string if I only have 3 letters?
or will it give me whole word?
@sjames1958gm I see...
Stephen James
@sjames1958gm
Jun 12 2016 01:10
substring(1) will give you the rest
Diego Mayer
@Chrono79
Jun 12 2016 01:10
it'll give it the whole word, but no need to especify the end, as @sjames1958gm said, if you had an string with more than 1000 chars that won't work
Creative Shin
@CreativeShin
Jun 12 2016 01:10
@Chrono79 thanks ,... you solved my prob ^^
CamperBot
@camperbot
Jun 12 2016 01:10
creative-shin sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1113 | @chrono79 |http://www.freecodecamp.com/chrono79
Creative Shin
@CreativeShin
Jun 12 2016 01:10
@sjames1958gm thanks again
CamperBot
@camperbot
Jun 12 2016 01:10
creative-shin sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: creative-shin already gave sjames1958gm points
Creative Shin
@CreativeShin
Jun 12 2016 01:11

function titleCase(str) {
  var splitString= str.split(" ");
  for(var i= 0; i<splitString.length;i++){
    splitString[i]= splitString[i].substring(0,1).toUpperCase() + splitString[i].substring(1,999).toLowerCase() ;
    if(splitString[i] === 'a' ||splitString[i] === 'the' ||splitString[i] === 'and' ||splitString[i] === 'of'){
      splitString[i] = splitString[i].toUpperCase();
    }
    var string= splitString.join(" ");
  }
return string;
}

titleCase("I'm a little tea pot");
cant believe it passed
:D
Diego Mayer
@Chrono79
Jun 12 2016 01:12
use only substring(1), it's better
Stephen James
@sjames1958gm
Jun 12 2016 01:12
@Creative-Shin That whole if with the "a" "the" should not be there -
Creative Shin
@CreativeShin
Jun 12 2016 01:12
@sjames1958gm but it said to make the articles uppercase
mentioned ones
Stephen James
@sjames1958gm
Jun 12 2016 01:13
@Creative-Shin oh, it did, did not recall that
Diego Mayer
@Chrono79
Jun 12 2016 01:13
@Creative-Shin that's already covered with the previous sentence
Stephen James
@sjames1958gm
Jun 12 2016 01:13
@Creative-Shin It only said to capitalize them, not make them all uppercase.
@Creative-Shin The reason it passes is that you have mofdified them already so they never match that if.
Creative Shin
@CreativeShin
Jun 12 2016 01:14
@sjames1958gm @Chrono79 ah i see
I misread it...
capitalize ...uppercase ... confusing h
Ethan Leyden
@Darksmurf
Jun 12 2016 01:15
I don't understand the "No repeats please" challenge.
Diego Mayer
@Chrono79
Jun 12 2016 01:15
@Darksmurf it's not an easy one
Ethan Leyden
@Darksmurf
Jun 12 2016 01:16
why does permAlone("zzzzzzzz") have to return 0 when permAlone('a') returns 1?
llamatarianism
@llamatarianism
Jun 12 2016 01:16
@Darksmurf there are no repeated characters in 'a'
there are plenty of repeated characters in 'zz...'
Ethan Leyden
@Darksmurf
Jun 12 2016 01:16
Why wouldn't the repeated characters be reduced to one?
llamatarianism
@llamatarianism
Jun 12 2016 01:16
because that's not what you're supposed to do?
Stephen James
@sjames1958gm
Jun 12 2016 01:17
@Darksmurf zzzzz has no non-repeated characters
Daniel Cartín
@Danielcv93
Jun 12 2016 01:17
hi, I have problems with the reverse string challenge!
llamatarianism
@llamatarianism
Jun 12 2016 01:17
you're supposed to count how many permutations there are with no repeated characters in a row
Ethan Leyden
@Darksmurf
Jun 12 2016 01:17
so why does permAlone("aaab") return 0
wouldn't it return at least 1?
Daniel Cartín
@Danielcv93
Jun 12 2016 01:17
if i run one by one the solutions it works, but the page said it is wrong, please help me!!
Diego Mayer
@Chrono79
Jun 12 2016 01:18
@Darksmurf think of each a having a different color
Ethan Leyden
@Darksmurf
Jun 12 2016 01:18
ok
Stephen James
@sjames1958gm
Jun 12 2016 01:18
@Danielcv93 Make sure no global variables
Ethan Leyden
@Darksmurf
Jun 12 2016 01:18
zzzzzzz still only has one permutation
llamatarianism
@llamatarianism
Jun 12 2016 01:18
@Darksmurf there are 0 permutations of that string which have no repeated characters
Ethan Leyden
@Darksmurf
Jun 12 2016 01:18
oooh
ok.
Diego Mayer
@Chrono79
Jun 12 2016 01:18
there is at least 2 combinations of a1a2a3b that's "the same" as a2a1a3b
llamatarianism
@llamatarianism
Jun 12 2016 01:18
there's "baaa", "abaa", "aaba" and "aaab"
all of which have multiple as in a row.
Ethan Leyden
@Darksmurf
Jun 12 2016 01:19
so you have to have to remove strings where a character repeats twice in one spot?
llamatarianism
@llamatarianism
Jun 12 2016 01:19
yes
Ethan Leyden
@Darksmurf
Jun 12 2016 01:19
Gotcha, thanks @llamatarianism @sjames1958gm @Chrono79
CamperBot
@camperbot
Jun 12 2016 01:19
darksmurf sends brownie points to @llamatarianism and @sjames1958gm and @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1530 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
:star2: 1114 | @chrono79 |http://www.freecodecamp.com/chrono79
:cookie: 754 | @llamatarianism |http://www.freecodecamp.com/llamatarianism
llamatarianism
@llamatarianism
Jun 12 2016 01:20
I redid that solution earlier today. came up with a very silly hack.
Ethan Leyden
@Darksmurf
Jun 12 2016 01:20
??
llamatarianism
@llamatarianism
Jun 12 2016 01:20
instead of turning "aab" into like, ["a0", "a1", "b0"] to distinguish them
I made it into [["a"], ["a"], ["b"]] and then compared by reference
Ethan Leyden
@Darksmurf
Jun 12 2016 01:21
ok. I'm gonna see if I can get regex.
Daniel Cartín
@Danielcv93
Jun 12 2016 01:22
ok, i did it! @sjames1958gm why it can't be global variables?
Diego Mayer
@Chrono79
Jun 12 2016 01:23
@Danielcv93 because with multiple tests calls, the global keeps the previous values
Daniel Cartín
@Danielcv93
Jun 12 2016 01:24
ok, it have logic.. thanks men! @Chrono79 @sjames1958gm
CamperBot
@camperbot
Jun 12 2016 01:24
danielcv93 sends brownie points to @chrono79 and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1531 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
:star2: 1115 | @chrono79 |http://www.freecodecamp.com/chrono79
Stephen James
@sjames1958gm
Jun 12 2016 01:24
Do I get a prize for solution without ever looking at the code :)
buiphuking
@buiphuking
Jun 12 2016 01:27
@Chrono79
help me
Diego Mayer
@Chrono79
Jun 12 2016 01:28
with your tic tac toe?
buiphuking
@buiphuking
Jun 12 2016 01:28
yes
pm plz
Terri Lake
@tlake25
Jun 12 2016 01:31
Help Needed! In Storing Values with the Assignment Operator, I am stuck on "a should be assigned to b with =" Here is my code:
CamperBot
@camperbot
Jun 12 2016 01:31
no wiki entry for: needed in storing values with the assignment operator i am stuck on a should be assigned to b with here is my code
Terri Lake
@tlake25
Jun 12 2016 01:31

// Setup
var a;
var b = 2;

// Only change code below this line

var a = 7;
myVar = 7;

var b = 7;
myNum = 7;

myNum = myVar;

jcroth1028
@jcroth1028
Jun 12 2016 01:34
Hi everyone, I'm having trouble with the Profile Lookup JavaScript Challenge. I am only valid results when the entry is not in the contact list, however when the entry is valid, I am not getting any return. Any help would be greatly appreciated!
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


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

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

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

  }

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
llamatarianism
@llamatarianism
Jun 12 2016 01:35
ok the problem lies here:
else if(contacts[i].firstName !== firstName)
  return "No such contact";
you're checking one contact
and then if that contact isn't the one
you're saying that none of them are the right contact
return ends the entire function, and therefore the entire loop
so you only ever check one contact
also
&& contacts[i].firstName.hasOwnProperty(prop) why?
contacts[i].firstName is a string. there's no way it's gonna have that property
contacts.firstName.prop same here
also you need to use bracket notation for prop, since it's a variable
contacts[i].prop == contacts[i]["prop"] != contacts[i][prop]
jcroth1028
@jcroth1028
Jun 12 2016 01:40
Ok that clears it up for me, thanks for your help @llamatarianism !
CamperBot
@camperbot
Jun 12 2016 01:40
jcroth1028 sends brownie points to @llamatarianism :sparkles: :thumbsup: :sparkles:
:cookie: 755 | @llamatarianism |http://www.freecodecamp.com/llamatarianism
Terri Lake
@tlake25
Jun 12 2016 01:41

Help Needed! In Storing Values with the Assignment Operator, I am stuck on "a should be assigned to b with =" Here is my code:
// Setup
var a;
var b = 2;

// Only change code below this line

var a = 7;
myVar = 7;

var b = 7;
myNum = 7;

myNum = myVar;

CamperBot
@camperbot
Jun 12 2016 01:41
no wiki entry for: needed in storing values with the assignment operator i am stuck on a should be assigned to b with here is my code setupvar avar b 2 only change code below this linevar a 7myvar 7var b 7mynum 7mynum myvar
Dylan
@dhcodes
Jun 12 2016 01:43
@tlake25 i think they are trying to show you that you can set a var by using another var
so for example, if a=7
you could do myVar = a
and b = a
@tlake25 you can get rid of myVar

you only need to fulfill these instructions:

Assign the value 7 to variable a.

Assign the contents of a to variable b.

Adrian Ferrar
@aferrar
Jun 12 2016 01:45
help
CamperBot
@camperbot
Jun 12 2016 01:45

CamperBot

Hi, I'm CamperBot! I can help you in this chatroom :smile:

Basic Commands:

  • find TOPIC find all entries about topic. e.g. find js
  • wiki TOPIC show contents of topic page
  • thanks @username send brownie points to another user
  • about @username shows info on that user
  • Algorithm BONFIRENAME info on a Algorithm

meet CamperBot in FreeCodeCamp/camperbotPlayground

:pencil: read more about camperbot on the FCC Wiki

Adrian Ferrar
@aferrar
Jun 12 2016 01:47
function mutation(arr) {
    var indexOneLower = arr[0].toLowerCase();
    var indexTwoLower = arr[1].toLowerCase();
    for (var i = 0 ; i < indexTwoLower.length ; i++) {
      if (indexOneLower.indexOf(indexTwoLower[i] !== -1)) {
        return true;
    }  else {
        return false;
      }
    }
}
mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"]);
Hello everyone, I've been stuck on mutations for awhile now and feel like I don't quite understand how to use indexOf. My code is above, can anyone give some insight as to where I'm going wrong. Thanks!
Diego Mayer
@Chrono79
Jun 12 2016 01:48
@aferrar (indexTwoLower[i] !== -1) <- this is wrong, try first (indexTwoLower[i]) !== -1
llamatarianism
@llamatarianism
Jun 12 2016 01:48
what @Chrono79 said is correct
also, you're returning inside a loop.
and it therefore also ends the loop
return ends the entire function call
so you only ever go through it once
Adrian Ferrar
@aferrar
Jun 12 2016 01:50
okie dokie thanks @Chrono79 thanks @llamatarianism
CamperBot
@camperbot
Jun 12 2016 01:50
aferrar sends brownie points to @chrono79 and @llamatarianism :sparkles: :thumbsup: :sparkles:
:star2: 1116 | @chrono79 |http://www.freecodecamp.com/chrono79
:cookie: 756 | @llamatarianism |http://www.freecodecamp.com/llamatarianism
sashabred
@sashabred
Jun 12 2016 01:51
Hello guys, I can`t undesrtand that:( You will need to use string operators to build a new string, result, using the provided variables: myNoun, myAdjective, myVerb, and myAdverb.
freeredpill
@freeredpill
Jun 12 2016 01:51

function caseInSwitch(val) {
var answer = "";
// Only change code below this line
switch (val) {
case val === 1:
answer = "alpha";
break;
case val === 2:
answer = "beta";
break;
case val === 3:
answer = "gamma";
break;
case val === 4:
answer = "delta";
break;
}

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

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

caseInSwitch(1) should have a value of "alpha"
caseInSwitch(2) should have a value of "beta"
caseInSwitch(3) should have a value of "gamma"
caseInSwitch(4) should have a value of "delta"
Norvin Burrus
@ndburrus
Jun 12 2016 01:51
@tlake25 did you get it resolved?
Norvin Burrus
@ndburrus
Jun 12 2016 01:52
@freeredpill which challenge is this?
freeredpill
@freeredpill
Jun 12 2016 01:52
Anyone know why I'm getting the caseInSwitch(1/2/3/4) should have errors. I'm not sure why when in my cases I set the value to answer it doesn't return it properly.
Selecting from many options with Switch Statements
Diego Mayer
@Chrono79
Jun 12 2016 01:52
@freeredpill case val === 1: should be case 1: and so on
freeredpill
@freeredpill
Jun 12 2016 01:53
@Chrono79 @ndburrus Thank you both.
CamperBot
@camperbot
Jun 12 2016 01:53
freeredpill sends brownie points to @chrono79 and @ndburrus :sparkles: :thumbsup: :sparkles:
:cookie: 517 | @ndburrus |http://www.freecodecamp.com/ndburrus
:star2: 1117 | @chrono79 |http://www.freecodecamp.com/chrono79
troyc12
@troyc12
Jun 12 2016 01:54
Hello everybody, I have been stuck on the Golf Code challenge for a while, and I am confused on what exact operator to use? If anybody could help, that'll be great
Diego Mayer
@Chrono79
Jun 12 2016 01:54
read the table, when not specified, use == @troyc12
Norvin Burrus
@ndburrus
Jun 12 2016 01:54
@freeredpill ...nice work! :sparkles: tests pass? if not, review the syntax/format here: case val === 1:
troyc12
@troyc12
Jun 12 2016 01:55
thanks @Chrono79
CamperBot
@camperbot
Jun 12 2016 01:55
troyc12 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1118 | @chrono79 |http://www.freecodecamp.com/chrono79
troyc12
@troyc12
Jun 12 2016 01:57
I was wondering if you're able to break it down for me? So i can have a more logical sense of what I am doing? @Chrono79
Norvin Burrus
@ndburrus
Jun 12 2016 01:58
@sashabred basically you'll create a sentence (madlib) that you'd like to build. this sentence will use the language parts (4: noun, adjective, etc.) given. there will be a couple of filler words necessary. finally, you'll concatenate the strings (being mindful of punctuation) to complete the sentence.... make sense?
Diego Mayer
@Chrono79
Jun 12 2016 01:58
Strokes    Return
==1    "Hole-in-one!"
<= par - 2    "Eagle"
==par - 1    "Birdie"
==par    "Par"
==par + 1    "Bogey"
==par + 2    "Double Bogey"
>= par + 3    "Go Home!"
use if/else with the conditions constructed as (strokes == 1) and so on @troyc12
you're evaluating strokes, and based on that value returning some string
troyc12
@troyc12
Jun 12 2016 02:01
So with the par's, are you actually adding OR subtracting from them in the condition? @Chrono79
Diego Mayer
@Chrono79
Jun 12 2016 02:01
no, you're comparing strokes to that
the values of strokes or par aren't modified in the function
Norvin Burrus
@ndburrus
Jun 12 2016 02:03
@jcroth1028 did you resolve it?
troyc12
@troyc12
Jun 12 2016 02:05
Okay. I thought when the code runs, it will add or subtract from the par value that's been given, when you first start the challenge. @Chrono79
Norvin Burrus
@ndburrus
Jun 12 2016 02:06
@troyc12 conceptually, you're modelling the Strokes/Return chart information with the if/else if command/s. the if/else if structure is driven by the variable strokes (which has different increasing/decreasing par value adjustments )... clear as mud? :sparkles:
troyc12
@troyc12
Jun 12 2016 02:06
Yeah I understand now @ndburrus . Thanks for the input
CamperBot
@camperbot
Jun 12 2016 02:06
troyc12 sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:cookie: 518 | @ndburrus |http://www.freecodecamp.com/ndburrus
Norvin Burrus
@ndburrus
Jun 12 2016 02:07
@troyc12 nice work... :+1: you're welcome... hope it helped... :)
Diego Mayer
@Chrono79
Jun 12 2016 02:08
basically, in golf, the par value is the difficulty of a certain hole, so if you do it in less than par, the better, and more than par the worst
Joseph
@revisualize
Jun 12 2016 02:08
blob
I think I'm a bit confused.
This sucks.
Diego Mayer
@Chrono79
Jun 12 2016 02:09
@revisualize I remember you asked if it was a filter, and I didn't understand what you're trying to say, I think you can't solve it filtering
jcroth1028
@jcroth1028
Jun 12 2016 02:10
@ndburrus yup!
Norvin Burrus
@ndburrus
Jun 12 2016 02:10
@jcroth1028 ok, super! :+1:
Diego Mayer
@Chrono79
Jun 12 2016 02:11
@revisualize In my first solution I used 2 for loops and a counter, maybe it helps
There are solutions with filter though, but I think the other is simpler to understand
Norvin Burrus
@ndburrus
Jun 12 2016 02:12
@sashabred how are we doing?
Adrian Ferrar
@aferrar
Jun 12 2016 02:16
So I ended up with this for the mutations section. Thanks for all the help. See anything wrong that I may have missed or could improve?
function mutation(arr) {
    var indexOneLower = arr[0].toLowerCase();
    var indexTwoLower = arr[1].toLowerCase();
    var mutationCounter = 0;
    for (var i = 0 ; i < indexTwoLower.length ; i++) {
      if (indexOneLower.indexOf(indexTwoLower[i]) !== -1) {
        mutationCounter++;
    }
  }
    if (mutationCounter === indexTwoLower.length) {
      return true;
    } else {
      return false;
    }
}
mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"]);
Diego Mayer
@Chrono79
Jun 12 2016 02:18
@aferrar you could ask if some letter isn't there (instead of if it being there) and return false, and outside the loop return true, that way, you don't need a counter
Dylan
@dhcodes
Jun 12 2016 02:19
@aferrar i personally think arrTwoLower might be a more descriptive name than indexTwoLower, but i'd be getting nitpicky
David
@Nachlawi
Jun 12 2016 02:26
Can someone help me on the "Where Art Thou" challenge. Here is my function why isn't it working?
function whereAreYou(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line

  var keyArr = Object.keys(source);

  arr = collection.filter(function(collec){
    keyArr.every(function(key){
      console.log(collec.hasOwnProperty(key) && collec[key] === source[key]);
      return collec[key] === source[key];
    });
  });

  // Only change code above this line
  return arr;
}
Ah, doesn't matter I worked it out.
Adrian Ferrar
@aferrar
Jun 12 2016 02:28
@Chrono79 much simpler. Thanks!
CamperBot
@camperbot
Jun 12 2016 02:28
aferrar sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: aferrar already gave chrono79 points
Adrian Ferrar
@aferrar
Jun 12 2016 02:29
@dhcodes I dig what you're saying though. I definitely need to be less lazy with my variable names. Thanks!
CamperBot
@camperbot
Jun 12 2016 02:29
aferrar sends brownie points to @dhcodes :sparkles: :thumbsup: :sparkles:
:star2: 1000 | @dhcodes |http://www.freecodecamp.com/dhcodes
Adam Urberg
@aurberg
Jun 12 2016 02:43
How would one change a string in an array to uppercase? I've tried array[i].toUpperCase()
well newArr.push(arr[i].toUpperCase());
Diego Mayer
@Chrono79
Jun 12 2016 02:45
@aurberg array[i] = array[i].toUpperCase(); // toUpperCase doesn't modify the string it's applied
I could help more if you show more code, just to know what you're trying to do
Adam Urberg
@aurberg
Jun 12 2016 02:51
@Chrono79 never mind, I figured it out, thanks though
CamperBot
@camperbot
Jun 12 2016 02:51
aurberg sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1119 | @chrono79 |http://www.freecodecamp.com/chrono79
Sam Nave
@shrapnel2012
Jun 12 2016 02:57
Hey everyone. Could anyone tell me how to create the scroll down option for buttons in my portfolio project? I have been googling for the last two hours and going over notes...I seemed to have misunderstood how to do this.
Kyle W Pilkinton
@tadake
Jun 12 2016 03:11
hey guys im working on the simon project and i have a function named plan that gives me a new pattern from 0 to 20 to follow. Im clueless on how to actually implement the game play though. can anyone help me with this? maybe some psudocode on how i should implement this?
Dylan
@dhcodes
Jun 12 2016 03:11
@shrapnel2012 do you just want them to jump to them or scroll slowly?
Sam Nave
@shrapnel2012
Jun 12 2016 03:12
@dhcodes jump would be good
Dylan
@dhcodes
Jun 12 2016 03:12
@shrapnel2012 that can be done with anchor tags
give your div to be jumped to an id
like id="contact"
and then on you contact button on the navbar, give it an href of #contact
ex. href = "#contact"
@tadake the path I took was to make a function for the computers turn, where it would pick a random number
Sam Nave
@shrapnel2012
Jun 12 2016 03:13
Ahhh facepalm thanks!!! that makes sense @dhcodes
CamperBot
@camperbot
Jun 12 2016 03:13
shrapnel2012 sends brownie points to @dhcodes :sparkles: :thumbsup: :sparkles:
:star2: 1001 | @dhcodes |http://www.freecodecamp.com/dhcodes
Dylan
@dhcodes
Jun 12 2016 03:14
@tadake random color that is. And then store it in an array. It would then light it up
then it goes to the players turn where the function is to take what the player clicks and add it to an array and then check if the items in the arrays match
if so, it goes back to computer turn
if not, it replays the computer's array
well re lights it up
hope that helps
Kyle W Pilkinton
@tadake
Jun 12 2016 03:16
that does alot thanks @dhcodes my brains already mush after today so i was having some trouble figuring out what to do haha :+1:
CamperBot
@camperbot
Jun 12 2016 03:16
tadake sends brownie points to @dhcodes :sparkles: :thumbsup: :sparkles:
:star2: 1002 | @dhcodes |http://www.freecodecamp.com/dhcodes
Dylan
@dhcodes
Jun 12 2016 03:17
np, good luck
shivamsonu29
@shivamsonu29
Jun 12 2016 03:25
find topic api
CamperBot
@camperbot
Jun 12 2016 03:25
find topic api
nothing found
shivamsonu29
@shivamsonu29
Jun 12 2016 03:29
find API
shivamsonu29
@shivamsonu29
Jun 12 2016 03:30
4
CamperBot
@camperbot
Jun 12 2016 03:30

:point_right: front end project use twitchtv json api [wiki]

Use the TwitchTV JSON API

If you're trying to tackle this challenge with jQuery's $.getJSON() method, chances are you'll get an error message concerning Cross-Origin Resource Sharing (CORS).

:pencil: read more about front end project use twitchtv json api on the FCC Wiki

daiwik
@daiwik
Jun 12 2016 03:33
when to use prototype other than for inheritance?
ALMY91
@ALMY91
Jun 12 2016 03:33
Hello guys i need some help here
Not too sure whats missing in my code
var objects=[{x:1},{y:2},{z:3}];
var merged=objects.reduce(union);
console.log(merged); //==> {x:1, y:2, z:3};
Robson Beaudry
@Robson-Beaudry
Jun 12 2016 03:37
Hey guys, in line nine of my code, source.criteria doesn't return the value of the property I'm trying to call (whereas if I just write source.last, it does). I think I'm misunderstanding something about how objects work. Can anyone help me?
function whereAreYou(collection, source) {
  // What's in a name?
  var arr = [];
  var criteria=Object.keys(source)[0];
  // Only change code below this line
  for(var i=0;i<collection.length;i++){
    if (collection[i].hasOwnProperty(criteria)){
      if (source.criteria==collection[i].criteria){
        arr.push(collection[i]);
      }      
    }
  }

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

whereAreYou([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
ALMY91
@ALMY91
Jun 12 2016 03:37
Hellooo?
daiwik
@daiwik
Jun 12 2016 03:38
@ALMY91 what is union? its not defined
ALMY91
@ALMY91
Jun 12 2016 03:38
@daiwik im not too sure what i should put in there tho?
Jesus Rivero
@jesusdaver86
Jun 12 2016 03:39
@ALMY91 Welcome
Yildirim
@yildirimmurat
Jun 12 2016 03:39

function largestOfFour(arr) {
// You can do this!
var maxNum=0;
for(var i=0;i<arr.length;i++){ for(var j=0;arr[i].length;j++){ if(arr[i][j]>maxNum){
maxNum=arr[i][j];
}
}
arr[i]=maxNum;
}
return arr;
}

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

what is wrong with this code?can anyone help pls?
Robson Beaudry
@Robson-Beaudry
Jun 12 2016 03:40
@yildirimmurat try to put ``` before and after your code, it makes it much more readable
chubacca21
@chubacca21
Jun 12 2016 03:41
I'm feeling really perplexed. I just started the javascript lessons and am literally just doing the "Storing Value with the Assignment Operator" where the instructions are: "Assign the value 7 to variable a. Assign the contents of a to variable b."and the only way I'm able to pass is with the following: b=7;a=b;b=a; and I really don't understand why.
Kyle W Pilkinton
@tadake
Jun 12 2016 03:42
hey guys can anyone tell me why only this only triggers one function instead of triggering them in order ?
 computer_position = 4;

  function computer_turn(){

    for(var pos = 0; pos < computer_position; pos++){

      var temp = sequence[pos];

     setTimeout(function(){

      if(temp == 'red'){
        red();
      }

       if(temp == 'blue'){
        blue();
      }

       if(temp == 'green'){
        green();
      }

       if(temp == 'yellow'){
        yellow();
      }

     },200);

    }

  }
Yildirim
@yildirimmurat
Jun 12 2016 03:42

```function largestOfFour(arr) {
// You can do this!
var maxNum=0;
for(var i=0;i<arr.length;i++){ for(var j=0;arr[i].length;j++){ if(arr[i][j]>maxNum){
maxNum=arr[i][j];
}
}
arr[i]=maxNum;
}
return arr;
}

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

robertky
@robertky
Jun 12 2016 03:49
Anyone know how to make a twitter bird appear in a bootstrap button?
I am attempting this, but it won't work :/.
 <button id="tweet" class="btn btn-primary pull-left">
    <i class="fa fa-twitter fa-4x"></i>
  </button>
Norvin Burrus
@ndburrus
Jun 12 2016 03:52
i'm working on the Seek and Destroy exercise. in the following code output, does "object Arguments" simply mean that arr has 3 objects in it (defined as "object Arguments")?
// code:

function destroyer(arr) {
  console.log("arguments: " + arguments);
  console.log("arguments.length: " + arguments.length);
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);               //  should return [1, 1].

// output:
// arguments: [object Arguments]
// arguments.length: 3
@chubacca21 can you post your code? the point of the lesson that the assignment operator takes the value on the right, and assigns it to the entity on the left... so, if you assign 7 to a, a has the value of 7. next, if you assign a to b, b now has the value of a.
daiwik
@daiwik
Jun 12 2016 03:57
@ALMY91 did you get solution
silver537
@silver537
Jun 12 2016 03:57

im stuck at this challenge called Profile Lookup

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


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

"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"

i was trying to edit it out and switch things up, but to no avail! >.> can any one give me a clue?
daiwik
@daiwik
Jun 12 2016 04:04
@ALMY91
var resultObject = arrObj.reduce(function(result, currentObject) {
    for(var key in currentObject) {
        if (currentObject.hasOwnProperty(key)) {
            result[key] = currentObject[key];
        }
    }
    return result;
}, {});
var objects=[{x:1},{y:2},{z:3}];
var resultObject = objects.reduce(function(result, currentObject) {
    for(var key in currentObject) {
        if (currentObject.hasOwnProperty(key)) {
            result[key] = currentObject[key];
        }
    }
    return result;
});
console.log(resultObject); //==> {x:1, y:2, z:3};
daiwik
@daiwik
Jun 12 2016 04:09
@ALMY91
ALMY91
@ALMY91
Jun 12 2016 04:10
@daiwik okay lemme take a loook at it!
daiwik
@daiwik
Jun 12 2016 04:11
actually you dont even need if statement, it would work if you remove if. just keep result[key] = current.....
daiwik
@daiwik
Jun 12 2016 04:16
okay this is final
var objects=[{x:1},{y:2},{z:3}];
var resultObject = objects.reduce(function(result, currentObject) {
    for(var key in currentObject) {
        result[key] = currentObject[key];        
    }
    return result;
},{});
console.log(resultObject); //==> {x:1, y:2, z:3};
Helena
@poigirl2001
Jun 12 2016 04:17
I need help with the using objects for lookup challenge.
daiwik
@daiwik
Jun 12 2016 04:17
so in this we make result equal {} as initial value and currentObject equals objects[0]
and we add each value into result using for loop
Helena
@poigirl2001
Jun 12 2016 04:18

// Setup
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line



   val = {
    "alpha":  "Adams",

     "bravo": "Boston",

     "charlie": "Chicago",

     "delta": "Denver",

     "echo": "Easy",

     "foxtrot": "Frank",

      "": undefined
  };



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

// Change this value to test
phoneticLookup("charlie");
silver537
@silver537
Jun 12 2016 04:19
@poigirl2001 it gives you a variable. so that means you must assign it to something.
Robson Beaudry
@Robson-Beaudry
Jun 12 2016 04:22
Hey guys, in line nine of my code, source.criteria doesn't return the value of the property I'm trying to call (whereas if I just write source.last, it does). I think I'm misunderstanding something about how objects work. Can anyone help me?

function whereAreYou(collection, source) {
  // What's in a name?
  var arr = [];
  var criteria=Object.keys(source)[0];
  // Only change code below this line
  for(var i=0;i<collection.length;i++){
    if (collection[i].hasOwnProperty(criteria)){
      if (source.criteria==collection[i].criteria){
        arr.push(collection[i]);
      }      
    }
  }

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

whereAreYou([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
daiwik
@daiwik
Jun 12 2016 04:24
@poigirl2001 you did part of the problem. Now you have to return it. so first make your val = {...} lookup = {...}. Not a good idea to have same name as parameter. then do return lookup[val]. Does that make sense?
@Robson-Beaudry which challenge is it
UtkarshShukla7
@UtkarshShukla7
Jun 12 2016 04:27
@Robson-Beaudry Object.keys(source) gives you an array=["last"]
not Capulet
daiwik
@daiwik
Jun 12 2016 04:29
This message was deleted
Jesus Rivero
@jesusdaver86
Jun 12 2016 04:37

Hey guys, Can anyone help me?
```

function myLocalScope() {
'use strict';

console.log(myVar);
}
myLocalScope();

// Run and check the console
// myVar is not defined outside of myLocalScope
console.log(myVar);

// Now remove the console log line to pass the test
```

Norvin Burrus
@ndburrus
Jun 12 2016 04:38
@poigirl2001 review/check the sample code format/syntax... consider var alpha = { vs. val = {. the result handling needs to be completed also... :)
daiwik
@daiwik
Jun 12 2016 04:38
@Robson-Beaudry this works--- just change .criteria to [criteria]
function whereAreYou(collection, source) {
  // What's in a name?
  var arr = [];
  var criteria=Object.keys(source)[0];
  // Only change code below this line
  for(var i=0;i<collection.length;i++){
    if (collection[i].hasOwnProperty(criteria)){      
      if (source[criteria]==collection[i][criteria]){
        arr.push(collection[i]);
      }      
    }
  }
  // Only change code above this line
  return arr;
}

whereAreYou([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
UtkarshShukla7
@UtkarshShukla7
Jun 12 2016 04:39
@daiwik where art thou
Travis
@IAmTravis
Jun 12 2016 04:39
Curious if anyone can help me with the Record Collection challenge?
UtkarshShukla7
@UtkarshShukla7
Jun 12 2016 04:39
yep
silver537
@silver537
Jun 12 2016 04:39
@IAmTravis thats a bitch exercise...
fuck that one for real.
daiwik
@daiwik
Jun 12 2016 04:39
@UtkarshShukla7 why doesn't source.criteria give the value?
silver537
@silver537
Jun 12 2016 04:40
spent 2 hours trying to figure it out
@IAmTravis paste your code
Travis
@IAmTravis
Jun 12 2016 04:40
@silver537 It's frustrating for sure. Can't figure out what's wrong with my code.
UtkarshShukla7
@UtkarshShukla7
Jun 12 2016 04:40
@daiwik let me check it once again
Norvin Burrus
@ndburrus
Jun 12 2016 04:40
@jesusdaver86 ok, myVar is requested as output, but how does the code know what it should be? review the sample code var loc = "foo";... :)
Travis
@IAmTravis
Jun 12 2016 04:40

function updateRecords(id, prop, value) {

var albumId = collection[id];
var changeProp = albumId[prop];

if (value !== "") {
if (prop === "tracks") {
albumId.tracks.push(value);
} else {
changeProp = value;
}
} else {
delete albumId[prop]; // Deletes empty properties
}

return collection;
}

silver537
@silver537
Jun 12 2016 04:41
function updateRecords(id, prop, value) {

  var albumId = collection[id];
  var changeProp = albumId[prop];

  if (value !== "") {
    if (prop === "tracks") {
      albumId.tracks.push(value);
    } else {
      changeProp = value;
    }
  } else {
    delete albumId[prop]; // Deletes empty properties
  }

  return collection;
}
Travis
@IAmTravis
Jun 12 2016 04:41
Sorry... I'm new to this chat and don't know how to past it in that code view
Yildirim
@yildirimmurat
Jun 12 2016 04:41
how you guys paste your code? when I try, it seems like a text
silver537
@silver537
Jun 12 2016 04:41
@IAmTravis @yildirimmurat paste in between ```
Travis
@IAmTravis
Jun 12 2016 04:42
@silver537 Cool, thanks
CamperBot
@camperbot
Jun 12 2016 04:42
iamtravis sends brownie points to @silver537 :sparkles: :thumbsup: :sparkles:
:cookie: 239 | @silver537 |http://www.freecodecamp.com/silver537
Robson Beaudry
@Robson-Beaudry
Jun 12 2016 04:42
thanks @daiwik
CamperBot
@camperbot
Jun 12 2016 04:42
robson-beaudry sends brownie points to @daiwik :sparkles: :thumbsup: :sparkles:
:cookie: 322 | @daiwik |http://www.freecodecamp.com/daiwik
Yildirim
@yildirimmurat
Jun 12 2016 04:42
@silver537 three before and three after code?
daiwik
@daiwik
Jun 12 2016 04:42
This message was deleted
Robson Beaudry
@Robson-Beaudry
Jun 12 2016 04:42
@yildirimmurat Make sure the ``` is above and below your code press enter after typing it
silver537
@silver537
Jun 12 2016 04:43
@yildirimmurat yes
daiwik
@daiwik
Jun 12 2016 04:43
This message was deleted
silver537
@silver537
Jun 12 2016 04:43
shift + enter of course
Yildirim
@yildirimmurat
Jun 12 2016 04:43

function largestOfFour(arr) {
  // You can do this!
  var maxNum;
  for(var i=0;i<arr.length;i++){
    maxNum=arr[i][0];
    for(var j=0;j<arr[i].length;j++){

      if(arr[i][j]>arr[i][0]){
        maxNum=arr[i][j];
      }
      arr[i]=maxNum;
    }
  }
  return arr;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
UtkarshShukla7
@UtkarshShukla7
Jun 12 2016 04:43
@daiwik got it because it looks for criteria property when you do source.criteria
Travis
@IAmTravis
Jun 12 2016 04:44
@silver537 So any ideas on what's wrong with my code?
Yildirim
@yildirimmurat
Jun 12 2016 04:44
what is wrong with my code? anyone help pls
silver537
@silver537
Jun 12 2016 04:44
@IAmTravis you assigned your prop and ids. use those variables instead of prop and id
UtkarshShukla7
@UtkarshShukla7
Jun 12 2016 04:44
@daiwik instead source[criteria] will work
Jesus Rivero
@jesusdaver86
Jun 12 2016 04:44
@ndburrus I declare myVar = "three " and I get error: "No global myVar variable"
daiwik
@daiwik
Jun 12 2016 04:45
@yildirimmurat everytime you make maxNum = arr[i][0];
Yildirim
@yildirimmurat
Jun 12 2016 04:46
@daiwik but then I am trying to find the largest one with if conditional
``
daiwik
@daiwik
Jun 12 2016 04:47
but you are only comparing it with first value
you have to compare with each value
Norvin Burrus
@ndburrus
Jun 12 2016 04:47
@jesusdaver86 where was it declared? ...and did it include the ; ?
daiwik
@daiwik
Jun 12 2016 04:48
arr[i][0] in your if statement is only first value of each array
Travis
@IAmTravis
Jun 12 2016 04:48
@silver537 I guess I'm not sure where else I'd use those variables. Feel like I already used them where it makes sense.
daiwik
@daiwik
Jun 12 2016 04:49
@yildirimmurat does that make sense?
Norvin Burrus
@ndburrus
Jun 12 2016 04:49
help format @IAmTravis
CamperBot
@camperbot
Jun 12 2016 04:49

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

This an inline `<paste code here>` code formatting with a single backtick() at _start_ and _end_ around thecode`.

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

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

Jesus Rivero
@jesusdaver86
Jun 12 2016 04:49
@ndburrus Inside the function myLocalScope
Yildirim
@yildirimmurat
Jun 12 2016 04:50
@daiwik you are right. I am trying to find out how to solve it. thanks
CamperBot
@camperbot
Jun 12 2016 04:50
yildirimmurat sends brownie points to @daiwik :sparkles: :thumbsup: :sparkles:
:cookie: 323 | @daiwik |http://www.freecodecamp.com/daiwik
Norvin Burrus
@ndburrus
Jun 12 2016 04:50
@jesusdaver86 can you post complete code.. it seems like it should pass...
Jesus Rivero
@jesusdaver86
Jun 12 2016 04:50
@ndburrus If I included ;
Norvin Burrus
@ndburrus
Jun 12 2016 04:52
@jesusdaver86 was var myVar = used?
daiwik
@daiwik
Jun 12 2016 04:52
@yildirimmurat make maxNum = 0; output of all loops. then go through each array and compare each value of each array with maxNum. when you reach end of each array push the maxNum into your arr using arr.push(maxNum). And result maxNum to 0 for next array
Jesus Rivero
@jesusdaver86
Jun 12 2016 04:52

Yes ´´´ var myVar = "two";
function myLocalScope() {
var myVar = "three";

console.log(myVar);

}
myLocalScope();

// Run and check the console
// myVar is not defined outside of myLocalScope
console.log(myVar);´´´

Norvin Burrus
@ndburrus
Jun 12 2016 04:53
@jesusdaver86 ok, this var myVar = "two"; needs to be removed... where is 'use strict'; ? :) a test that didn't pass (i assume) was No global myVar variable. the reason would be that a global var/iable was present ("two"), correct? also, you may find the text & compose buttons to the right of the text area useful (formatting code)...
daiwik
@daiwik
Jun 12 2016 04:54
and put ``` on seperate lines @jesusdaver86
silver537
@silver537
Jun 12 2016 04:54
@IAmTravis theres a property you have to set, before you use your push.
Jesus Rivero
@jesusdaver86
Jun 12 2016 04:55
@daiwik
I'll try
daiwik
@daiwik
Jun 12 2016 04:56
:)
Stephen
@stephepush
Jun 12 2016 04:56
still only getting the input as the output. Any help?
function destroyer(arr) {
  // Remove all the values
  arr = Array.from(arguments);
  var inp = arr[0];
  function seeker(inp){
    return arr[0] != arr[0].indexOf(arr.slice(1));
  }
  var result = arr.filter(seeker);
  console.log(result)
  return result;
}


destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Chris Cullen
@123xylem
Jun 12 2016 04:56
Finders Keepers
help Finders Keepers
CamperBot
@camperbot
Jun 12 2016 04:57

:point_right: algorithm finders keepers [wiki]

Algorithm Finders Keepers

Explanation:

The problem is quite simple to understand. You will check for each element in the array that is passed in the first argument, if the element plugged in to the function passed as the second argument returns true the first time. We do not care about the second or third one that is true, only the very first one if any. If there are none, then return undefined. This last bit is not explained but it is part of the tests used.

:pencil: read more about algorithm finders keepers on the FCC Wiki

ALMY91
@ALMY91
Jun 12 2016 05:00
@daiwik hey thanks in advance im trying to get it in my head
CamperBot
@camperbot
Jun 12 2016 05:00
almy91 sends brownie points to @daiwik :sparkles: :thumbsup: :sparkles:
:cookie: 324 | @daiwik |http://www.freecodecamp.com/daiwik
Jesus Rivero
@jesusdaver86
Jun 12 2016 05:01
@ndburrus
pass the test :smile: was to remove the console line thanks!!
CamperBot
@camperbot
Jun 12 2016 05:01
jesusdaver86 sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:cookie: 521 | @ndburrus |http://www.freecodecamp.com/ndburrus
Norvin Burrus
@ndburrus
Jun 12 2016 05:03
@jesusdaver86 nice work! :sparkles: i think they updated some of the exercises... my code wouldn't pass now... the function name has changed... interesting... and console.log (i believe) would not prevent a test pass... aahhh, there is a comment about that... ok...
help me where i'm wrong
CamperBot
@camperbot
Jun 12 2016 05:03
no wiki entry for: me where im wrong
daiwik
@daiwik
Jun 12 2016 05:04
@stephepush you need to use loop
ALMY91
@ALMY91
Jun 12 2016 05:05
@daiwik my console states that x is not defined?
var a = [x,e,x,r,c,s,a,g,s,];

function findall(a,x){
var results =[], //The array of indexes we'll return
len=a.length, //The length of the array to be searched
pos=0; //The position to search from

while (pos<len) {
a.indexOf(x,pos);
if(pos===-1) break;
results.push(pos);
pos=pos+1;
}
return results;



}
daiwik
@daiwik
Jun 12 2016 05:05
arr[0] equals [1,2,3,1,2,3] and you cant compare the whole array like that
Jesus Rivero
@jesusdaver86
Jun 12 2016 05:07
@ndburrus
That's it
daiwik
@daiwik
Jun 12 2016 05:07
@ALMY91 what is a? that array isn't complete and x, e, x r ... are those variables? are those strings? if they are strings they have to be in quotes
and where are you even calling the function findall?
Stephen
@stephepush
Jun 12 2016 05:11
@daiwik, I thought the whole point of the filter method was to let it do the looping for you. Oh well, lol
daiwik
@daiwik
Jun 12 2016 05:11
your console is right. you haven't defined x @ALMY91
@stephepush filter just creates a new array for you and puts in all the value that pass a given test defined by you. check out examples here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
ALMY91
@ALMY91
Jun 12 2016 05:13
@daiwik the thinf i dont understand is why do i have to define x... its an element that im searching for in the array. it isn a variable or anything
@daiwik tried putting them in quotes but its still not working
var a = ["x","e","x","r","c","s","a","g","s"];

function findall(a,x){
var results =[], //The array of indexes we'll return
len=a.length, //The length of the array to be searched
pos=0; //The position to search from

while (pos<len) {
a.indexOf(x,pos);
if(pos===-1) break;
results.push(pos);
pos=pos+1;
}
return results;



}
daiwik
@daiwik
Jun 12 2016 05:15
after a statement you end with ; not , you use comma in objects
so var results = [];
and len = a.length;
ALMY91
@ALMY91
Jun 12 2016 05:16
@daiwik hmmm still not working tho
@ALMY91 im not too sure what do they mean by x is not defined?
@daiwik why does x have to be defined. im actually finding occurences of a value x in the array a
@daiwik its not like its a variable or anything
CachiStacks
@CachiStacks
Jun 12 2016 05:18
wondering if someone could help me with record collection challenge (JS)
daiwik
@daiwik
Jun 12 2016 05:18
"x" is what you are looking for
CachiStacks
@CachiStacks
Jun 12 2016 05:18

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

return collection;
}

daiwik
@daiwik
Jun 12 2016 05:19
x is not same as "x" and your comma were right since you are declaring them. I was wrong. that is shortcut
CachiStacks
@CachiStacks
Jun 12 2016 05:19
only completes 3/4 tests
Domingo Moronta
@dj-m
Jun 12 2016 05:19
@silver537 did you come across any aid for the Profile Lookup exercise?
daiwik
@daiwik
Jun 12 2016 05:19
and you havent called your function findall(a,x); so it wont run @ALMY91
silver537
@silver537
Jun 12 2016 05:21
@dj-m i figured it out on my own. but thanks for offering.
it turns out that i had completely forgot the return terminates the function. all i had to do was input the return "No such contact"; at the end of the function.
CamperBot
@camperbot
Jun 12 2016 05:21
silver537 sends brownie points to @dj-m :sparkles: :thumbsup: :sparkles:
:cookie: 220 | @dj-m |http://www.freecodecamp.com/dj-m
daiwik
@daiwik
Jun 12 2016 05:21
@ALMY91
var a = ["x", "e", "x", "r", "c", "s", "a", "g", "s"];
console.log(a.length);
findall(a, "x");//need to call function like this :)
function findall(a, x) {
  var results = [], //The array of indexes we'll return
    len = a.length, //The length of the array to be searched
    pos = 0; //The position to search from

  while (pos < len) {
    a.indexOf(x, pos);
    if (pos === -1) break;
    results.push(pos);
    pos = pos + 1;
  }
  return results;

}
it runs but i dont know if the result is what you wanted
Sunil Mitkari
@mitkarisunil
Jun 12 2016 05:22
hey guys
how to paste the cose
code
daiwik
@daiwik
Jun 12 2016 05:22
hi @mitkarisunil
ALMY91
@ALMY91
Jun 12 2016 05:22
@daiwik why do u console.log a.length tho?
daiwik
@daiwik
Jun 12 2016 05:22
to debug
silver537
@silver537
Jun 12 2016 05:22
@CachiStacks notice object 5439 doesn't have a "tracks" property. you must create one, and then your function would work.
Sunil Mitkari
@mitkarisunil
Jun 12 2016 05:23
in gitter

@daiwik
function chunkArrayInGroups(arr, size) {
// Break it up
a=[];
b=[];
c=0;
for(i=0;i<((arr.lenth)/size);i++)
{
for(j=0;j<size;j++)
{
b[i][j].push();

  }

}
return arr;
}

chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3);

CachiStacks
@CachiStacks
Jun 12 2016 05:23
@silver537 ah i see, thanks
CamperBot
@camperbot
Jun 12 2016 05:23
cachistacks sends brownie points to @silver537 :sparkles: :thumbsup: :sparkles:
:cookie: 241 | @silver537 |http://www.freecodecamp.com/silver537
daiwik
@daiwik
Jun 12 2016 05:24
@mitkarisunil you put ``` above and below your code
Sunil Mitkari
@mitkarisunil
Jun 12 2016 05:24

'''
function chunkArrayInGroups(arr, size) {
// Break it up
a=[];
b=[];
c=0;
for(i=0;i<((arr.lenth)/size);i++)
{
for(j=0;j<size;j++)
{
b[i][j].push();

  }

}
return arr;
}

chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3);

CamperBot
@camperbot
Jun 12 2016 05:24
:bulb: to format code use backticks! ``` more info
daiwik
@daiwik
Jun 12 2016 05:24
``` not '''
CamperBot
@camperbot
Jun 12 2016 05:24
:bulb: to format code use backticks! ``` more info
Sunil Mitkari
@mitkarisunil
Jun 12 2016 05:24

```
function chunkArrayInGroups(arr, size) {
// Break it up
a=[];
b=[];
c=0;
for(i=0;i<((arr.lenth)/size);i++)
{
for(j=0;j<size;j++)
{
b[i][j].push();

  }

}
return arr;
}

chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3);

daiwik
@daiwik
Jun 12 2016 05:24
This message was deleted
Sunil Mitkari
@mitkarisunil
Jun 12 2016 05:24
function chunkArrayInGroups(arr, size) {
  // Break it up
  a=[];
  b=[];
  c=0;
  for(i=0;i<((arr.lenth)/size);i++)
  {
    for(j=0;j<size;j++)
      {
    b[i][j].push();

      }

  }
  return arr;
}

chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3);
i got it
ty
daiwik
@daiwik
Jun 12 2016 05:25
This message was deleted
Domingo Moronta
@dj-m
Jun 12 2016 05:25
@silver537 Oh, I’m trying to figure it out myself… how’d you go about it?
Sunil Mitkari
@mitkarisunil
Jun 12 2016 05:25
chunky munkey
UtkarshShukla7
@UtkarshShukla7
Jun 12 2016 05:25
@mitkarisunil typo arr.lenth
Sunil Mitkari
@mitkarisunil
Jun 12 2016 05:25
ok
silver537
@silver537
Jun 12 2016 05:26
@dj-m what exactly is your problem?
UtkarshShukla7
@UtkarshShukla7
Jun 12 2016 05:26
@mitkarisunil then b[i][j] is undefined
silver537
@silver537
Jun 12 2016 05:26
or better yet, show me your code
UtkarshShukla7
@UtkarshShukla7
Jun 12 2016 05:26
@mitkarisunil then pushing nothing
Sunil Mitkari
@mitkarisunil
Jun 12 2016 05:27
@UtkarshShukla7 how to declare
is it b[i][j]
or b=[][]
UtkarshShukla7
@UtkarshShukla7
Jun 12 2016 05:27
@mitkarisunil then returning arr instead of b
just b.push will work
Sunil Mitkari
@mitkarisunil
Jun 12 2016 05:28

'''
function chunkArrayInGroups(arr, size) {
// Break it up
a=[];
b=[];
for(i=0;i<((arr.length)/size);i++)
{
for(j=0;j<size;j++)
{
b[i][j].push();

  }

}
return b;
}

chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3);
'''

CamperBot
@camperbot
Jun 12 2016 05:28
:bulb: to format code use backticks! ``` more info
Sunil Mitkari
@mitkarisunil
Jun 12 2016 05:28
function chunkArrayInGroups(arr, size) {
  // Break it up
  a=[];
  b=[];
  for(i=0;i<((arr.length)/size);i++)
  {
    for(j=0;j<size;j++)
      {
    b[i][j].push();

      }

  }
  return b;
}

chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3);
TypeError: Cannot read property '0' of undefined
@UtkarshShukla7
UtkarshShukla7
@UtkarshShukla7
Jun 12 2016 05:29
@mitkarisunil
function chunkArrayInGroups(arr, size) {
  // Break it up
  a=[];
  b=[];
  c=0;
  for(var i=0;i<arr.length;i=i+size)
  {
    for(j=i;j<size;j++)
      {
    b.push(arr[j]);

      }

  }
  return b;
}

chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3);
Sunil Mitkari
@mitkarisunil
Jun 12 2016 05:31
then the output is [0,1,2]
ALMY91
@ALMY91
Jun 12 2016 05:31
@daiwik hmm its actually returning me an index of all the arrays? i was actually looking only for the indexes of x in the array
//Find all occurences of a value x in an array a and return an array of matching indexes

var a = ["x", "e", "x", "r", "c", "s", "a", "g", "s"];

function findall(a,x){
var results =[]; //The array of indexes we'll return
len=a.length; //The length of the array to be searched
pos=0; //The position to search from

while (pos<len) { 
a.indexOf(x,pos); //Search
if(pos===-1) break; //If nothing is found, we're done
results.push(pos); //Otherwise, store index in array
pos=pos+1; //Start next search at next element
}
return results; //Return array of indexes



}

console.log (findall(a,"x"));
Domingo Moronta
@dj-m
Jun 12 2016 05:31
@silver537 ‘'' for (var i = 0; i < contacts.length; i++) {
if (contacts[i].hasOwnProperty(firstName) && contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
}
}’''
silver537
@silver537
Jun 12 2016 05:33
@dj-m firstName is already a property, you dont have to check it. but you do have to check if its equal to the name
UtkarshShukla7
@UtkarshShukla7
Jun 12 2016 05:34
@mitkarisunil that isn't the write solution that is for giving you a hed-start
Stephen
@stephepush
Jun 12 2016 05:35
@dawik, is this what you had in mind?
function destroyer(arr) {
  // Remove all the values
  arr = Array.from(arguments);
  var inp = arr[0];
  var result = [];
  for (var i = 0; i < inp.length; i++){
      if (inp[i] != arr.slice(1)){
          result.push();
      }
  }
  console.log(result);
  return result;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Domingo Moronta
@dj-m
Jun 12 2016 05:37
@silver537 ah… however, when I try a ‘else if’ statement, my prior passing tests fail:
  for (var i = 0; i < contacts.length; i++) {
    if (contacts[i].firstName == firstName && contacts[i].hasOwnProperty(prop)) {
      return contacts[i][prop];
    } else if (contacts[i].firstName !== firstName) {
      return "No such contact";
    }
  }
Chris Cullen
@123xylem
Jun 12 2016 05:37
QUICK QUESTION: Can you tell me how to run this while loop untill arr[0] is true instead of me using break too early as I am doing.. Basically I dont know hwo to avoid an infinite loop here without an early break...

function dropElements(arr, func) {
  // Drop them elements.
for(i=0;i<arr.length;i++){ while(arr.filter(func,arr[0]===false)){
   arr.shift();
break;}
 } 



  return arr;
}

dropElements([1, 2, 3, 9, 2], function(n) {return n >2; });
ALMY91
@ALMY91
Jun 12 2016 05:39
hello can anyone tell me where went wrong here?
silver537
@silver537
Jun 12 2016 05:39

@dj-m No such contact was my mistake and took me awhile.

remember, the return function terminates the code.

i believe all you get is no such contact right? because it's in your for loop.

daiwik
@daiwik
Jun 12 2016 05:41
@ALMY91 I tried to work with what you have and this is what i get.
var a = ["x", "e", "x", "r", "c", "s", "a", "g", "s"];
console.log(a.indexOf("x",0));
findall(a, "x")
function findall(a, x) {
  var results = []; //The array of indexes we'll return
  len = a.length; //The length of the array to be searched
  pos = 0,
    found = 0;

  while (pos <= len) {
    found = a.indexOf(x, pos); //Search
   // if (pos === -1) break; wrong logic 
    if (found >= 0){ 
    results.push(found); //Otherwise, store index in array
    }
    pos = pos + 1; //Start next search at next element
  }
  console.log(results);
}
//console.log(findall(a, "x"));
this is not how i would do it doe
Kyle W Pilkinton
@tadake
Jun 12 2016 05:41
hey guy can anyone help me figure out why setTimeout isnt working for my computer_turn function?
http://codepen.io/tadake/full/gMadEz?editors=0010
daiwik
@daiwik
Jun 12 2016 05:41
indexOf only returns first element @ALMY91
ALMY91
@ALMY91
Jun 12 2016 05:42
@daiwik hmmm it starts at the beginning however its suppose to iterate through the whole array and then return indexes where it matched value x?
@daiwik so my console should be returning 0 and 2 by right...
@daiwik oh i get what u mean ! its only suppose to return the index of the first such element found
daiwik
@daiwik
Jun 12 2016 05:44
@stephepush the way I did is that I make and array removeArr in which i added value that had to be removed from arguments[0] and then used filter to test(using loop) if each value of arguments is equal to each value or removeArr(2,3). if it is don't return it
@ALMY91 yes only first index of "x" which is 0. I would rather loop through it and compare with operators === each value instead of indexOf.
ALMY91
@ALMY91
Jun 12 2016 05:46
@daiwik okay if i do this then it should return 2 in my console.log right?
var a = ["e", "e", "x", "r", "c", "s", "a", "g", "s"];

function findall(a,x){
var results =[]; //The array of indexes we'll return
len=a.length; //The length of the array to be searched
pos=0; //The position to search from

while (pos<len) { 
a.indexOf(x,pos); //Search
if(pos===-1) break; //If nothing is found, we're done
results.push(pos); //Otherwise, store index in array
pos=pos+1; //Start next search at next element
}

return results; //Return array of indexes


}


console.log (findall(a,"x"));
daiwik
@daiwik
Jun 12 2016 05:47
it would return 0 for a.indexOf("x",0);
but if you do a.indexOf("x",1); it would return 2
ALMY91
@ALMY91
Jun 12 2016 05:48
@daiwik i actually switch the first alphabet to e instead of x
@daiwik so its suppose to return 2 if i do a.indexOf("x",0);
daiwik
@daiwik
Jun 12 2016 05:49
yes
ALMY91
@ALMY91
Jun 12 2016 05:49
@daiwik but in my console.log its just printing the whole index of the array out?
blob
daiwik
@daiwik
Jun 12 2016 05:49
thats because your logic inside while loop is wrong
ALMY91
@ALMY91
Jun 12 2016 05:50
@daiwik see what i mean in my screenshot here
daiwik
@daiwik
Jun 12 2016 05:50
yea because you are pushing in the position from 0 to 9
you are not pushing in the actual index where a.indexOf(...) find the value
you need to store the value like this found = a.indexOf("x",pos);
do youknow what i mean?
Domingo Moronta
@dj-m
Jun 12 2016 05:52
@silver537 it passes all the tests but did you really have 2 forloops in there? for (var i = 0; i < contacts.length; i++) { if (contacts[i].firstName == firstName && contacts[i].hasOwnProperty(prop)) { return contacts[i][prop]; } } for (var j = 0; j < contacts.length; i++) { if (contacts[j].firstName == firstName && contacts[j][prop] !== prop) { return "No such property"; } } return "No such contact”
  for (var i = 0; i < contacts.length; i++) {
    if (contacts[i].firstName == firstName && contacts[i].hasOwnProperty(prop)) {
      return contacts[i][prop];
    }
  }
  for (var j = 0; j < contacts.length; i++) {
    if (contacts[j].firstName == firstName && contacts[j][prop] !== prop) {
      return "No such property";
    }
  }
  return "No such contact"
ALMY91
@ALMY91
Jun 12 2016 05:54
@daiwik it looks kinda weird in my console tho
//Find all occurences of a value x in an array a and return an array of matching indexes

var a = ["e", "e", "x", "r", "c", "s", "a", "g", "s"];

function findall(a,x){
var results =[]; //The array of indexes we'll return
len=a.length; //The length of the array to be searched
pos=0; //The position to search from

while (pos<len) { 
var found = a.indexOf("x",pos); //Search
if(pos===-1) break; //If nothing is found, we're done
results.push(found); //Otherwise, store index in array
pos=pos+1; //Start next search at next element
}

return results; //Return array of indexes


}


console.log (findall(a,"x"));
blob
daiwik
@daiwik
Jun 12 2016 05:55
if(found === -1) break;
because position is always positive
Domingo Moronta
@dj-m
Jun 12 2016 05:56
thanks @silver537
CamperBot
@camperbot
Jun 12 2016 05:56
dj-m sends brownie points to @silver537 :sparkles: :thumbsup: :sparkles:
:cookie: 243 | @silver537 |http://www.freecodecamp.com/silver537
ALMY91
@ALMY91
Jun 12 2016 05:57
@daiwik im currently getting Array[3]
0:2
1:2
2:2
daiwik
@daiwik
Jun 12 2016 05:57
yea since your loop keeps running until position reach 9
ALMY91
@ALMY91
Jun 12 2016 05:58
@daiwik but shouldn it be only returning the index where x is present? its showing the 0 and 1st index as well
ALMY91
@ALMY91
Jun 12 2016 06:02
@daiwik it shouldn be returning 0 and 1st index since it has a value of -1, where x is not found..
@daiwik yep i got the same answer as my console on the link u gave to me
daiwik
@daiwik
Jun 12 2016 06:03
what code are you entering
ALMY91
@ALMY91
Jun 12 2016 06:04
<html>
<head></head>
<body>
  <script type="text/javascript">

//Find all occurences of a value x in an array a and return an array of matching indexes

var a = ["e", "e", "x", "r", "c", "s", "a", "g", "s"];

function findall(a,x){
var results =[]; //The array of indexes we'll return
len=a.length; //The length of the array to be searched
pos=0; //The position to search from

while (pos<len) { 
var found = a.indexOf(x,pos); //Search
if(found===-1) break; //If nothing is found, we're done
results.push(found); //Otherwise, store index in array
pos=pos+1; //Start next search at next element
}

return results; //Return array of indexes


}


console.log (findall(a,"x"));
</script>
<body>
</html>
@daiwik here it is
daiwik
@daiwik
Jun 12 2016 06:08
var a = ["e", "e", "x", "r", "c", "s", "a", "g", "s"];
findall(a,"x")
function findall(a,x){
var results =[]; //The array of indexes we'll return

for(var i = 0;i < a.length;i++){
    if(a[i] === x){
        results.push(i);
    }
}
console.log(results);
}
this makes life easier
also go through this book http://eloquentjavascript.net/
@ALMY91
Darrel Adams
@dadams-510
Jun 12 2016 06:10
This message was deleted
Denis
@dnossyrev
Jun 12 2016 06:12

hi Guys. I need a help. Ive got a task where i need to represent JS code which shows number on the page like that:
10
10 20
10 20 30
10 20 30 40
10 20 30 40 50

I do like that, but I think this not good style
var numArr = [10, 20, 30, 40, 50];

for (var i = 0; i < numArr.length; i++) {
    if (i == 0)
        document.write(numArr[0]);
    else if (i == 1)
        document.write("<br>" + numArr[0] + " " + numArr[1]);
    else if (i == 2)
        document.write("<br>" + numArr[0] + " " + numArr[1] + " " + numArr[2]);
}
Any ideas please
ALMY91
@ALMY91
Jun 12 2016 06:15
@daiwik hm but what i don understand is its almost fine except that it returns the first 2 indexes when its value is -1...
@daiwik if not for that it would hv worked perfectly fine
silver537
@silver537
Jun 12 2016 06:17
@dj-m so it worked? sorry i didnt respond.
daiwik
@daiwik
Jun 12 2016 06:23
@ALMY91 its really hard to tell on internet
I think you are skipping a lot of basic stuff
ALMY91
@ALMY91
Jun 12 2016 06:27
@daiwik okay i'd prolly come back to this another time... getting stuck on it for way too long ...
@daiwik but thanks for the help anyways
CamperBot
@camperbot
Jun 12 2016 06:27
almy91 sends brownie points to @daiwik :sparkles: :thumbsup: :sparkles:
:cookie: 325 | @daiwik |http://www.freecodecamp.com/daiwik
ChinaMichaelwang
@ChinaMichaelwang
Jun 12 2016 06:34
@denis@dnossyrev
@dnossyrev hey there
Chris Cullen
@123xylem
Jun 12 2016 06:35
help Steamroller
CamperBot
@camperbot
Jun 12 2016 06:35

:point_right: algorithm steamroller [wiki]

Algorithm Steamroller

Explanation:

This problem seems simple but you need to make sure to flatten any array, regardless of the level which is what adds a bit of difficulty to the problem.

:pencil: read more about algorithm steamroller on the FCC Wiki

ChinaMichaelwang
@ChinaMichaelwang
Jun 12 2016 06:35
@dnossyrev it seems like you have lost an array element
@dnossyrev try to code like this
var numArr = [10,20,30,40,50];
for (var i = 0; i < numArr.length; i++) {
if (i == 0)
{
document.write(numArr[0]);
}
else if (i == 1)
{
document.write("<br>" + numArr[0] + " " + numArr1);
}
else if (i == 2)
{
document.write("<br>" + numArr[0] + " " + numArr1 + " " + numArr2);
}
}
UtkarshShukla7
@UtkarshShukla7
Jun 12 2016 06:47

@dnossyrev or try this

var numArr = [10, 20, 30, 40, 50];
for (var i = 0; i < numArr.length; i++) {
    for(var j=0;j<=i;j++){
      document.write(numArr[j] + " ");
    }
    document.write("<br>");
}

Also don't use document.write as it is unpredictable

Chris Cullen
@123xylem
Jun 12 2016 07:00
Why am i getting nulls in my asnswer? Also How do i remove them? My last 3 commented lines are an attempt to remove them
Denis
@dnossyrev
Jun 12 2016 07:04
@UtkarshShukla7 wow, thanks! I know about document.write. Here Im using just for task purposes
CamperBot
@camperbot
Jun 12 2016 07:04
dnossyrev sends brownie points to @utkarshshukla7 :sparkles: :thumbsup: :sparkles:
:cookie: 619 | @utkarshshukla7 |http://www.freecodecamp.com/utkarshshukla7
UtkarshShukla7
@UtkarshShukla7
Jun 12 2016 07:05
@dnossyrev ok np :+1:
Huy Nguyen Thuong
@NguyenThuongHuy
Jun 12 2016 07:08
Hi guys can anyone help me with Return Largest Numbers in Arrays here is my code it said cannot read property sort of undefined
function largestOfFour(arr) {
  // You can do this!
  var lagest = [];
  for (var i = 0; i <= arr.length; i++){
    arr[i].sort(function(a,b){
      return b - a;
    });

    lagest.push(arr[0]);

  }
  return lagest;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Vishaal JK
@VishuJK
Jun 12 2016 07:08
This message was deleted
Markus Kiili
@Masd925
Jun 12 2016 07:09
@NguyenThuongHuy i <= arr.length <- use < here.
silver537
@silver537
Jun 12 2016 07:09
@NguyenThuongHuy you misspelled largest
Vishaal JK
@VishuJK
Jun 12 2016 07:09
This message was deleted
Islam Abasov
@IslamA
Jun 12 2016 07:11
thanks @anuragaryan @SaintPeter @vaskezu @abhisekp for your help with Algorithm: Caesar's Cipher
CamperBot
@camperbot
Jun 12 2016 07:11
islama sends brownie points to @anuragaryan and @saintpeter and @vaskezu and @abhisekp :sparkles: :thumbsup: :sparkles:
:cookie: 335 | @anuragaryan |http://www.freecodecamp.com/anuragaryan
:star2: 2824 | @saintpeter |http://www.freecodecamp.com/saintpeter
:cookie: 311 | @vaskezu |http://www.freecodecamp.com/vaskezu
:star2: 2618 | @abhisekp |http://www.freecodecamp.com/abhisekp
Huy Nguyen Thuong
@NguyenThuongHuy
Jun 12 2016 07:12
@Masd925 the result is [[5,4,3,1],[5,4,3,1],[5,4,3,1],[5,4,3,1]] i dont know where i did wrong
i know where i did wrong
it should be largest.push(arr[i][0]);
@Masd925 @silver537 Thanks
CamperBot
@camperbot
Jun 12 2016 07:15
nguyenthuonghuy sends brownie points to @masd925 and @silver537 :sparkles: :thumbsup: :sparkles:
:cookie: 246 | @silver537 |http://www.freecodecamp.com/silver537
:star2: 1832 | @masd925 |http://www.freecodecamp.com/masd925
TechAgent
@cyberwizkid
Jun 12 2016 07:27
i think i'm a bit high now, can someone help me out with this part?
i think i'm a bit high now, can someone help me out with this part?:https://gyazo.com/041ba95bdf88b61b41bc6c8a02b4e890
TechAgent
@cyberwizkid
Jun 12 2016 07:36
anyone?
silver537
@silver537
Jun 12 2016 07:37
@cyberwizkid follow the table and do exactly what it asks.
make sure to space between each escape values.
Chris
@VexBlade
Jun 12 2016 08:02
Would this be the way I should do this, it does work but should it be done like this
var count = 0;

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

  switch (card) {
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
      count ++;
      break;
    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
      count --;
      break;

  }

  if (count === 0) {
    return count + " Hold";
  } else if (count > 0){
    return count + " Bet";
  } else if (count < 0) {
    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(7); cc(7); cc(2); cc(2);
silver537
@silver537
Jun 12 2016 08:03
yes
Chris
@VexBlade
Jun 12 2016 08:03
awesome thanks
Starting to get it now :P
silver537
@silver537
Jun 12 2016 08:03
its alot faster than using if else statements since you have multiple checks of the same thing.
Chris
@VexBlade
Jun 12 2016 08:03
Yeah
silver537
@silver537
Jun 12 2016 08:07
well i used cases for 7 8 and 9 just so i wont be confusing for me. but anywho. either way is correct
Alina Melnykova
@miroshnichka
Jun 12 2016 08:07
hey people! please tell me what is wrong with my code:
var max = 0;
var arr = [0];
function findLongestWord(str) {
  str = str.toLowerCase();
  arr = str.split(' ');
  for (var i in arr) {
    if (arr[i].length > max) {
      max = arr[i].length;
      return max;
    }
    else { return max; }
  }
}

findLongestWord("The quick brown fox jumped over the lazy dog");
ALMY91
@ALMY91
Jun 12 2016 08:09
Hi guys i have a question here
var a={}; //Start with a regular empty object

//Add properties to make it "array-like"
var i=0
while(i<10) {a[i] =i*1; i++;}
a.length=i; 
console.log(a); //var a= {[0,1,2,3,4,5,6,7,8,9]}

//Now iterate through it as if it were a real array-like
var total=0;
for(var j=0; j<a.length; j++)
total+=a[j]; //total = total + a[j]
console.log(total);
How does this line for(var j=0; j<a.length; j++) knows im referring to var a?
as in how does it know that im looking to iterate var a ?
Chris
@VexBlade
Jun 12 2016 08:10
because you say a.length?
ALMY91
@ALMY91
Jun 12 2016 08:10
@VexBlade i see, i was wondering if that is the reason. Is there a theory stating that if we state a.length, it automatically iterates through that?
Chris
@VexBlade
Jun 12 2016 08:11
Well I am not 100% sure about it but thats how you call vars :)
Still new to it myself
ALMY91
@ALMY91
Jun 12 2016 08:12
@VexBlade i rbred vaguely that i spotted this theory somewhere in my book i.. but now i cant find it haha
Chris
@VexBlade
Jun 12 2016 08:14
well im guessing it works like that, as soon as you call a.length, it tried to find where a was defined within a var.
ALMY91
@ALMY91
Jun 12 2016 08:15
@VexBlade alright thanks !
CamperBot
@camperbot
Jun 12 2016 08:15
almy91 sends brownie points to @vexblade :sparkles: :thumbsup: :sparkles:
:cookie: 204 | @vexblade |http://www.freecodecamp.com/vexblade
Kerry Webster
@kerrywebster
Jun 12 2016 08:16
This message was deleted
@ALMY91 the a.length tells the 'for' loop when to stop iterating (while 'j' less than a.length or 10 in this case. you then use 'j' as the index to reference the value in the 'a' array for your computation which is basically adding all the buckets in 'a' together. The 'total+=a[j]' is the code that actually uses the array 'a' and its values. We could have hard coded the 'a.length' and entered 10 instead and gotten the same result.
Marian Menschig
@mmenschig
Jun 12 2016 08:19
Hey guys! Any way to write this nicer? $("#resultlist").append('<li><h4><a target="_blank" href=' + searchURL + '>' + title + '</a></h4>' + '<p>' + extract + '</p></li>');
I'm trying to first write the <h4> and then write the <p> element wrapped in an <li>
unfortunately the <li> elements themselves don't have classes or ids (only the <ul> has an id)
this is for my wiki viewer which can be found here: http://mmenschig.github.io/projects/wikiViewer/index.html
NixonRichard
@NixonRichard
Jun 12 2016 08:21
Make Instances of Objects with a Constructor Function
Kerry Webster
@kerrywebster
Jun 12 2016 08:21
@mmenschig I think you've done a good job. Only thing I see is one concatination yoou could remove:
NixonRichard
@NixonRichard
Jun 12 2016 08:21
help me with this lesson
CamperBot
@camperbot
Jun 12 2016 08:21
no wiki entry for: me with this lesson
NixonRichard
@NixonRichard
Jun 12 2016 08:21
plz
Kerry Webster
@kerrywebster
Jun 12 2016 08:21
This message was deleted
Marian Menschig
@mmenschig
Jun 12 2016 08:22
could you elaborate @NixonRichard
Kerry Webster
@kerrywebster
Jun 12 2016 08:22
@mmenschig $("#resultlist").append('<li><h4><a target="_blank" href=' + searchURL + '>' + title + '</a></h4><p>' + extract + '</p></li>');
silver537
@silver537
Jun 12 2016 08:22
i wouldnt blame you. constructors are damn well confusing. but easy to execute instead of literal objects.
NixonRichard
@NixonRichard
Jun 12 2016 08:22

``var Car = function() {
this.wheels = 4;
this.engines = 1;
this.seats = 1;
};

// Only change code below this line.

var myCar;
var myCar = new Car();
`js

```

var Car = function() {
  this.wheels = 4;
  this.engines = 1;
  this.seats = 1;
};

// Only change code below this line.

var myCar;
var myCar = new Car();
Marian Menschig
@mmenschig
Jun 12 2016 08:23
i see....i think i know what you're saying here
isn't there a better way? like giving the li a class?
NixonRichard
@NixonRichard
Jun 12 2016 08:24
hi
silver537
@silver537
Jun 12 2016 08:24
take away the first myCar variable.
Jean-Philippe Sirois
@veksen
Jun 12 2016 08:25
I would probably store a template and use it, or use an actual data driven framework (I love vue.js)
NixonRichard
@NixonRichard
Jun 12 2016 08:25
still not work
silver537
@silver537
Jun 12 2016 08:26
hmmm i havn't done that one. but i remember that concept from a different lesson. what is it asking you to do? from the objectives?
NixonRichard
@NixonRichard
Jun 12 2016 08:27
The property wheels should still be 4 in the object constructor.
There should not be a property nickname in the object constructor.
The property wheels of myCar should equal 4.
The property nickname of myCar should be a string.
Kerry Webster
@kerrywebster
Jun 12 2016 08:27
@mmenschig Better or just another way. Yes. $("#resultlist").append('<li class="myclass"><a target="_blank" href="' + searchURL + '">' + title + '</a><p>' + extract + '</p></li>'); THen of course you have to add your css for myclass. More code but possibly more flexible.
NixonRichard
@NixonRichard
Jun 12 2016 08:27
only the last one remaining
silver537
@silver537
Jun 12 2016 08:28
oh shit... nickname? wtf. nvm
haha
Marian Menschig
@mmenschig
Jun 12 2016 08:28
hey thanks kerry! @kerrywebster but is there a way to add the <p> tag on a separate line?
CamperBot
@camperbot
Jun 12 2016 08:28
mmenschig sends brownie points to @kerrywebster :sparkles: :thumbsup: :sparkles:
:cookie: 20 | @kerrywebster |http://www.freecodecamp.com/kerrywebster
Marian Menschig
@mmenschig
Jun 12 2016 08:28
like appendToPrevious() or something
that's a made up method name
NixonRichard
@NixonRichard
Jun 12 2016 08:29
help me
CamperBot
@camperbot
Jun 12 2016 08:29

:point_right: adding snippets to sublime text [wiki]

Adding Snippets To Your Sublime Text Installation

If you are a user of sublime text (I hope you are, it kicks ass. You can get it here), then you may have already noticed some of the tab completion capabilities. For example, when you are opening an html tag such as <p>, it automatically closes the tag as soon as you type /. You can get similar functionality for pieces of code you end up re-writing over and over, and it's surprisingly easy!

Here's an example, which activates after typing div and then tab:

alt text

:pencil: read more about adding snippets to sublime text on the FCC Wiki

NixonRichard
@NixonRichard
Jun 12 2016 08:29
somebody c mon
this s so simple
why no one know the answer
Marian Menschig
@mmenschig
Jun 12 2016 08:30
then why can't you do it?
silver537
@silver537
Jun 12 2016 08:30
@NixonRichard i figured it out
it wants you to add a property using your variable.
use your dot notation to create on, and assaign it to a string value.
thats for the last part.
Marian Menschig
@mmenschig
Jun 12 2016 08:31
a property is something like .wheels or .engines
sooo
try something like myCar.property = yourNumber;
NixonRichard
@NixonRichard
Jun 12 2016 08:32
var myCar = new Car(){
  myCar.wheels = 4;};
still wrong
Marian Menschig
@mmenschig
Jun 12 2016 08:32
why the braces?
that's not a function
var myCar = new Car() is an instantiation of an object
silver537
@silver537
Jun 12 2016 08:33
The property nickname of myCar should be a string.
Kerry Webster
@kerrywebster
Jun 12 2016 08:33
@mmenschig You could by appending twice - once for each string - but not needed. The <p> tag forces to the next line. I would say - not to be disrespectful - to not get too hung up on how the code looks but how it displays. If it displays correctly you are the "CHAMPION". Next task. :)
NixonRichard
@NixonRichard
Jun 12 2016 08:34
var myCar = new Car()
  myCar.wheels = four ;
this s still wrong
zzz
silver537
@silver537
Jun 12 2016 08:35
@NixonRichard by dissecting what it is asking you. nickname is a property. so its going to be like wheels, seats, or engine. so if "nickname" is a property. it wants you to add a property called nickname
Marian Menschig
@mmenschig
Jun 12 2016 08:35
nixon...read what silver said
JS can't interpret four
is that a string? a variable name? a function? :)
thanks @kerrywebster! i may just move onto the twitch project now and revisit the code structure later
CamperBot
@camperbot
Jun 12 2016 08:36
mmenschig sends brownie points to @kerrywebster :sparkles: :thumbsup: :sparkles:
:warning: mmenschig already gave kerrywebster points
ALMY91
@ALMY91
Jun 12 2016 08:36
hi guys whats the difference betweena function that is subroutine and procedure?
NixonRichard
@NixonRichard
Jun 12 2016 08:37
var nickname = wheels;
var myCar = new Car();
  myCar.wheels = 4 ;
silver537
@silver537
Jun 12 2016 08:37
myCar.nickname="string";
NixonRichard
@NixonRichard
Jun 12 2016 08:38
still wrong
Marian Menschig
@mmenschig
Jun 12 2016 08:38
what do you have now?
NixonRichard
@NixonRichard
Jun 12 2016 08:38
var nickname = 4;
var myCar = new Car();
  myCar.wheels = nickname ;
Marian Menschig
@mmenschig
Jun 12 2016 08:38
a string is always placed between single or double quotes
also....i think you're getting confused here
Kerry Webster
@kerrywebster
Jun 12 2016 08:39
NixonRichard
@NixonRichard
Jun 12 2016 08:39
a little bit
ALMY91
@ALMY91
Jun 12 2016 08:39
@kerrywebster page is not found
Anurag Sharma
@anu0012
Jun 12 2016 08:39
why console.log() is not working in my code... can anybody help ?
@anu0012 what's your problem?
silver537
@silver537
Jun 12 2016 08:40
@NixonRichard
i gave you the answer dude
Anurag Sharma
@anu0012
Jun 12 2016 08:41
in 'check for palindrome' problem i am trying to see my replaced string with console.log().... but it is not working
Marian Menschig
@mmenschig
Jun 12 2016 08:41
@anu0012 what's your development environment like? are you coding in codepen or local machine?
Kerry Webster
@kerrywebster
Jun 12 2016 08:41
@ALMY91 sorry just learning the chat environment here. Link confused me but I was able to edit. Same as link @mmenschig sent.
NixonRichard
@NixonRichard
Jun 12 2016 08:41
wow
it s right
lol
silver537
@silver537
Jun 12 2016 08:42
let me see your code @NixonRichard
Marian Menschig
@mmenschig
Jun 12 2016 08:42
^ what silver said lol
Anurag Sharma
@anu0012
Jun 12 2016 08:42
@mmenschig i am woking on freecodecamp's own portal... not using any ide
Marian Menschig
@mmenschig
Jun 12 2016 08:42
ah yes of course, algorithm
NixonRichard
@NixonRichard
Jun 12 2016 08:42
var myCar = new Car();
  myCar.nickname = 'wheels' ;
silver537
@silver537
Jun 12 2016 08:42
consol.log() is exempt in fcc ide
NixonRichard
@NixonRichard
Jun 12 2016 08:42
here
silver537
@silver537
Jun 12 2016 08:43
@NixonRichard omg you still used wheels as your string. -_-
Marian Menschig
@mmenschig
Jun 12 2016 08:43
try writing the algo in jsfiddle / jsbin
Anurag Sharma
@anu0012
Jun 12 2016 08:43
ok
Marian Menschig
@mmenschig
Jun 12 2016 08:43
@NixonRichard is that the ENTIRE problem code?
silver537
@silver537
Jun 12 2016 08:43
yes
haha
Marian Menschig
@mmenschig
Jun 12 2016 08:44
@anu0012 or...install sublime/atom/brackets and install node.js and run js locally :)
damn @silver537
silver537
@silver537
Jun 12 2016 08:44
don't belittle @mmenschig
everyone learns different ways
NixonRichard
@NixonRichard
Jun 12 2016 08:44
bit i passed
it s right
Marian Menschig
@mmenschig
Jun 12 2016 08:44
i am not belittling?
silver537
@silver537
Jun 12 2016 08:45
@mmenschig just saying. i was stuck at an easy problem too and kicked myself for it. haha
NixonRichard
@NixonRichard
Jun 12 2016 08:45
all of these stuffs r ez
Marian Menschig
@mmenschig
Jun 12 2016 08:45
@NixonRichard hold on a second. you passed. but what you wrote is very difficult to follow and may not be logical. think about it
unless of course you give your car the nickname "wheels"...
NixonRichard
@NixonRichard
Jun 12 2016 08:47
why not lol
silver537
@silver537
Jun 12 2016 08:47
@NixonRichard he's right. the logic you used can affect you later on.
NixonRichard
@NixonRichard
Jun 12 2016 08:47
oh is it that serious ?
silver537
@silver537
Jun 12 2016 08:47
yes!
remember, computers are idiots compared to us.
Marian Menschig
@mmenschig
Jun 12 2016 08:47
think about it this way. once you work on projects that require more than one person, will the other programmer be able to understand and follow your thought process?
your code must be readable, to you AND others
comments should be used sparingly as well
var number = 1; // sets number to 1 for instance should be avoided
silver537
@silver537
Jun 12 2016 08:48
@NixonRichard what @mmenschig said and also, you must be VERY specific in your code. or else the computer will give you a different result.
NixonRichard
@NixonRichard
Jun 12 2016 08:50
Great
Marian Menschig
@mmenschig
Jun 12 2016 08:50
nobody said it would be easy :)
NixonRichard
@NixonRichard
Jun 12 2016 08:50
var myCar = new Car();
  myCar.nickname = "Obama" ;
silver537
@silver537
Jun 12 2016 08:50

like in this code

var Car = function() {
  //Change this constructor
  this.wheels = 4;
  this.seats = 1;
  this.engines = 1;
};

var myCar = new Car();
  myCar.nickname = 'wheels' ;

if you're not careful, you will get mixed up with the property wheels and the nickname value "wheels"

@NixonRichard PERFECT!!!!!!!
your car's name is now OBAMA!
lmao
NixonRichard
@NixonRichard
Jun 12 2016 08:51
rofl
silver537
@silver537
Jun 12 2016 08:53
gee thanks, obama >.>
Anurag Sharma
@anu0012
Jun 12 2016 08:54

function palindrome(str) {
// Good luck!
console.log(str);
str.replace(/([^\w]*)/,"");
str.toLowerCase();

var str1=str;
var arr=[];
arr=str1.split("");
arr.reverse();

var str2=arr.join("");

return str===str2;
}

palindrome("race car");

what is wrong in this code
???
Marian Menschig
@mmenschig
Jun 12 2016 08:55
@anu0012 one advice i can give for debugging is: "be generous with print statements"
what do you get when you console.log(arr.reverse());?
silver537
@silver537
Jun 12 2016 08:56
in other words, abuse the shit out of the console.log() @anu0012
Anurag Sharma
@anu0012
Jun 12 2016 08:56
console.log() is not at all working
Marian Menschig
@mmenschig
Jun 12 2016 08:56
THEN we have a problem
NixonRichard
@NixonRichard
Jun 12 2016 08:57
var Car = function
  //Change this constructor
  (wheels,seats,engines){
  this.wheels = wheels;
  this.seats = seats;
  this.engines = engines;
};

//Try it out here
var myCar = new Car(4,2,1) ;
whats wrong with this ? somebody help plz thx u
Marian Menschig
@mmenschig
Jun 12 2016 08:58
now start adding console.log() statement to trace your steps
@NixonRichard ... 10 minutes ago you said all this stuffs r ez
what do you need help with?
NixonRichard
@NixonRichard
Jun 12 2016 08:59
with the stuff i just asked u
lol
Mihajlo Krsmanović
@rektix
Jun 12 2016 09:00
Hey what API should I use for wikipedia viewer
Marian Menschig
@mmenschig
Jun 12 2016 09:00
no. you posted the entire code. you didn't ask a question
NixonRichard
@NixonRichard
Jun 12 2016 09:00
make i work ?
Marian Menschig
@mmenschig
Jun 12 2016 09:00
@rektix try the Wiki API :)
NixonRichard
@NixonRichard
Jun 12 2016 09:00
*it
Mihajlo Krsmanović
@rektix
Jun 12 2016 09:00
@mmenschig rly? hahahaha
Marian Menschig
@mmenschig
Jun 12 2016 09:00
NixonRichard
@NixonRichard
Jun 12 2016 09:00
Calling new Car(3,1,2) should produce an object with a wheels property of 3, a seats property of 1, and an engines property of 2.
Mihajlo Krsmanović
@rektix
Jun 12 2016 09:01
@mmenschig how to search using that api?
Marian Menschig
@mmenschig
Jun 12 2016 09:01
what have you tried @NixonRichard ?
NixonRichard
@NixonRichard
Jun 12 2016 09:02
i wrote the code
Marian Menschig
@mmenschig
Jun 12 2016 09:02
NixonRichard
@NixonRichard
Jun 12 2016 09:03
but it s wrong
Mihajlo Krsmanović
@rektix
Jun 12 2016 09:03
@mmenschig should I use this one? https://www.mediawiki.org/wiki/API:Search
Marian Menschig
@mmenschig
Jun 12 2016 09:03
@rektix yes and your action will be query
@NixonRichard not entirely sure what the issue is. what is your output?
Mihajlo Krsmanović
@rektix
Jun 12 2016 09:04
@mmenschig on api search or home?
silver537
@silver537
Jun 12 2016 09:04
delete the comment @NixonRichard
NixonRichard
@NixonRichard
Jun 12 2016 09:04
sorry what s the comment ?
see in the URL? there is action=query and list=search
silver537
@silver537
Jun 12 2016 09:04
the //
Mihajlo Krsmanović
@rektix
Jun 12 2016 09:05
aaah ok :D
Marian Menschig
@mmenschig
Jun 12 2016 09:05
those are URL parameters that specify the URL call
change the srsearch= value from "Albert+Einstein" to "Marie+Curie"
and what happens?
Mihajlo Krsmanović
@rektix
Jun 12 2016 09:05
yeah i looked at that before
Marian Menschig
@mmenschig
Jun 12 2016 09:05
so basically
Mihajlo Krsmanović
@rektix
Jun 12 2016 09:05
btw they use %20 instead of +
NixonRichard
@NixonRichard
Jun 12 2016 09:05
wow
Mihajlo Krsmanović
@rektix
Jun 12 2016 09:06
is it same thing?
NixonRichard
@NixonRichard
Jun 12 2016 09:06
it s worked
lol
Marian Menschig
@mmenschig
Jun 12 2016 09:06
well %20 IS +
silver537
@silver537
Jun 12 2016 09:06
-.-
Mihajlo Krsmanović
@rektix
Jun 12 2016 09:06
@mmenschig thanks bro :D
CamperBot
@camperbot
Jun 12 2016 09:06
rektix sends brownie points to @mmenschig :sparkles: :thumbsup: :sparkles:
:cookie: 311 | @mmenschig |http://www.freecodecamp.com/mmenschig
Marian Menschig
@mmenschig
Jun 12 2016 09:06
don't belittle @silver537 ;)
silver537
@silver537
Jun 12 2016 09:06
dude go to sleep!! @NixonRichard
i get the feeling your brain is fried or something
Marian Menschig
@mmenschig
Jun 12 2016 09:07
OH YEAH! now i see the problem @silver537 @NixonRichard - Nixon you CANNOT have a comment follow the function declaration
Mihajlo Krsmanović
@rektix
Jun 12 2016 09:07
btw any good music to listen to while coding?
Marian Menschig
@mmenschig
Jun 12 2016 09:07
the function must be followed by () {
silver537 @silver537 thinks @mmenschig is being a douche.
silver537
@silver537
Jun 12 2016 09:07
wait what?
NixonRichard
@NixonRichard
Jun 12 2016 09:07
darude sandstorm @rektix
Marian Menschig
@mmenschig
Jun 12 2016 09:07
wait what?!
what did I do?!
lol
silver537
@silver537
Jun 12 2016 09:08
idk. the ghost is being weird \
NixonRichard
@NixonRichard
Jun 12 2016 09:09
why do u think my brain s fried ?
did i just asked a weird question or something ?
Marian Menschig
@mmenschig
Jun 12 2016 09:09
don't listen to him, keep coding brother :+1:
silver537
@silver537
Jun 12 2016 09:10
because you are missing little things. or maybe you've been coding for far too long that you're not retaining information anymore.
Marian Menschig
@mmenschig
Jun 12 2016 09:10
although i have to admit that knowing that isn't really self-explanatory
silver537
@silver537
Jun 12 2016 09:10
its actually a bad thing to do something for a long time. if ya don't believe me, look it up. its a psychological thing.
NixonRichard
@NixonRichard
Jun 12 2016 09:11
yah awesome
Marian Menschig
@mmenschig
Jun 12 2016 09:11
yeah go take a break
fly a drone
climb a rock
do some thai boxing
or play uncharted 4
in that order
silver537
@silver537
Jun 12 2016 09:12
its like if you're running for a long time and you don't sit down. your body will literally collapse due to exhaustion. im only looking out for you. but your work proves you're not dumb. you made it this far and im still behind from you. i had to skip my challenges to literally help you.
NixonRichard
@NixonRichard
Jun 12 2016 09:13
actually i have problems with english lol
silver537
@silver537
Jun 12 2016 09:14
the only reason why i was helping you is because i understood those challenges, otherwise i wouldn't have know what was going on.
NixonRichard
@NixonRichard
Jun 12 2016 09:14
u r awesome
Marian Menschig
@mmenschig
Jun 12 2016 09:14
where are you from @NixonRichard
NixonRichard
@NixonRichard
Jun 12 2016 09:15
vietnam
in southeastasia
Marian Menschig
@mmenschig
Jun 12 2016 09:16
welp, if you're up over there, that's a sign for me to go sleep
silver537
@silver537
Jun 12 2016 09:16
then more power to you, since you've gotten this far. especially since english isnt your first language.
it's 4am here
Marian Menschig
@mmenschig
Jun 12 2016 09:17
Midwest?
NixonRichard
@NixonRichard
Jun 12 2016 09:17
hmm 4 pm here lol
Marian Menschig
@mmenschig
Jun 12 2016 09:17
2 AM here
silver537
@silver537
Jun 12 2016 09:17
mid south
Marian Menschig
@mmenschig
Jun 12 2016 09:17
TX?
NixonRichard
@NixonRichard
Jun 12 2016 09:17
do u watch euro ?
silver537
@silver537
Jun 12 2016 09:17
yessum
Marian Menschig
@mmenschig
Jun 12 2016 09:17
ATX?!
silver537
@silver537
Jun 12 2016 09:17
nope
Marian Menschig
@mmenschig
Jun 12 2016 09:17
aw :'(
silver537
@silver537
Jun 12 2016 09:17
sooooooouth
lol
Marian Menschig
@mmenschig
Jun 12 2016 09:18
close to border?
yeah @NixonRichard - Go Germany! :)
silver537
@silver537
Jun 12 2016 09:18
no more questions.
but ye
NixonRichard
@NixonRichard
Jun 12 2016 09:19
yeah Go Italia !
silver537
@silver537
Jun 12 2016 09:19
i would love to learn the italian language
NixonRichard
@NixonRichard
Jun 12 2016 09:21
Make Object Properties Private
rouxfeur
@rouxfeur
Jun 12 2016 09:21
Hi, can you recommend me a good resource to learn React ? Free or low-price
NixonRichard
@NixonRichard
Jun 12 2016 09:21
hmm what to do with this challenge sorry ?
silver537
@silver537
Jun 12 2016 09:22
@lukasdinh try the freecodecamp chat room
rouxfeur
@rouxfeur
Jun 12 2016 09:23
@silver537 you mean here on gitter?
NixonRichard
@NixonRichard
Jun 12 2016 09:23
u look like korean
silver537
@silver537
Jun 12 2016 09:24
yea. you're using one of fcc rooms here on gitter. try a different one.
Marian Menschig
@mmenschig
Jun 12 2016 09:24
lol i'm out guys night
NixonRichard
@NixonRichard
Jun 12 2016 09:24
ya cu
silver537
@silver537
Jun 12 2016 09:26
@NixonRichard at least try since im gonna get off in a few. it asks you to set up your bike object. by using this.
NixonRichard
@NixonRichard
Jun 12 2016 09:26
okay
i ll try... zzzz
lol
cu
silver537
@silver537
Jun 12 2016 09:29
i gotta finish this challenge so ill be helping you while im doing this challenge.
Anurag Sharma
@anu0012
Jun 12 2016 09:29
var str1=str.replace(/([^\w]*)/g,"");
why it is considering (_) underscore ?
LeifChen
@leifchen
Jun 12 2016 09:30
i get a "function updateRecords(id, prop, value) "push the value onto the end of the tracks array.
i get a "function updateRecords(id, prop, value) "push the value onto the end of the tracks array.
i get a "function updateRecords(id, prop, value) "
my problem is how to push the value onto the end of the json array.
shivamsonu29
@shivamsonu29
Jun 12 2016 09:32
does 2 getJSON functions can be nested??
Markus Kiili
@Masd925
Jun 12 2016 09:32
@shivamsonu29 I believe they can.
silver537
@silver537
Jun 12 2016 09:32
@leifchen check the last object in the array. noticed there's no tracks array.
LeifChen
@leifchen
Jun 12 2016 09:33
@silver537 ok i will get a try
Anurag Sharma
@anu0012
Jun 12 2016 09:33
var str1=str.replace(/([^\w]*)/g,"");
why it is considering (_) underscore ?
Markus Kiili
@Masd925
Jun 12 2016 09:34
@anu0012 \w includes letters, numbers, and _.
rishi1213e
@rishi1213e
Jun 12 2016 09:34
hey guys.
I have a problem in the problem "confirm the ending"
Anurag Sharma
@anu0012
Jun 12 2016 09:34
@Masd925 ooohhh.. thanks :)
CamperBot
@camperbot
Jun 12 2016 09:34
anu0012 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1833 | @masd925 |http://www.freecodecamp.com/masd925
rishi1213e
@rishi1213e
Jun 12 2016 09:35
I believe I found a bug

This is the code, which I used:
function confirmEnding(str, target) {

var f = (str.length - target.length);
var t = str.slice(f);
if(t == target){
return "true";
}
else{
return "false";
}

}
confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "n");

It outputs what is given in the criteria, but I am still unable to pass this problem. Help needed!!
Markus Kiili
@Masd925
Jun 12 2016 09:36
@rishi1213e "true" is a string. You should return true witch is a boolean value. Same for false.
TechAgent
@cyberwizkid
Jun 12 2016 09:36
@Masd925 hi kiili
Yomaris
@Yomaris
Jun 12 2016 09:36
what's the meaning of this challenge?
TechAgent
@cyberwizkid
Jun 12 2016 09:37
@Masd925 please just a quick one
shivamsonu29
@shivamsonu29
Jun 12 2016 09:37

@Masd925 $(document).ready(function(){