These are chat archives for FreeCodeCamp/HelpJavaScript

20th
Apr 2016
Phenoix8
@Phenoix8
Apr 20 2016 00:00
var myMusic = [
{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}
[
{
"artist": "Daft Punk",
"title": "Homework",
"release_year": 1997,
"formats": [
"CD",
"Cassette",
"LP" ],
"gold": true
}
]// Add record here
];
thtas my code what am i doing wrong @tylergross
Kevin
@KevinBruland
Apr 20 2016 00:00
im a little confused as to why this isnt working:
str[x] = str[x].split("")[0].toUpperCase().join("");
Hanan Mufti
@h-ARTS
Apr 20 2016 00:00
Hi everyone
Kevin
@KevinBruland
Apr 20 2016 00:00
in a function
Micah Bales
@micahbales
Apr 20 2016 00:01
@khaduch OOOHH... that makes sense. Thanks so much!
Tyler
@tylergross
Apr 20 2016 00:01
you almost have it right... you don't need to brackets though []
CamperBot
@camperbot
Apr 20 2016 00:01
micahbales sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star: 967 | @khaduch | http://www.freecodecamp.com/khaduch
Tyler
@tylergross
Apr 20 2016 00:01
should look like var myMusic = [{}, {}, {}.....];
Hanan Mufti
@h-ARTS
Apr 20 2016 00:01
Whats the problem exactly here in my code:
heymark
@heymark
Apr 20 2016 00:01
@cenamorado1 for the purposes of this exercise, it looks like that's what they're after
Hanan Mufti
@h-ARTS
Apr 20 2016 00:01
// Setup
var testObj = {
  12: "Namath",
  16: "Montana",
  19: "Unitas"
};

// Only change code below this line;

var playerNumber = 16;       // Change this Line
var player = testObj[16];   // Change this Line
X = You should use bracket notation to access testObj
bitgrower
@bitgrower
Apr 20 2016 00:02
they want you to use the var playerNumber, I believe, @h-ARTS
Phenoix8
@Phenoix8
Apr 20 2016 00:03

var myMusic = [
{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}

{
"artist": "Daft Punk",
"title": "Homework",
"release_year": 1997,
"formats":
"CD",
"Cassette",
"LP" ,
"gold": true
}
// Add record here
];

@tylergross
is this correct
Hanan Mufti
@h-ARTS
Apr 20 2016 00:04
@bitgrower "playerNumber should be a number"
Phenoix8
@Phenoix8
Apr 20 2016 00:04
??
Tyler
@tylergross
Apr 20 2016 00:04
looks better just missing on thing now @Phenoix8 under formats see how they started a new array []
heymark
@heymark
Apr 20 2016 00:04
@h-ARTS that line was right, it's the one below it that needs fixing.
Tyler
@tylergross
Apr 20 2016 00:04
in the example so "formats": ["cd", "ex", "any"]. "gold":true }
bitgrower
@bitgrower
Apr 20 2016 00:05
@h-ARTS and it is! you set it to the number 16 ... now use playerNumber inside your brackets after testObj ...
Stephen James
@sjames1958gm
Apr 20 2016 00:05
@Phenoix8 Looks like you are missing a comma after the first closing brace },
Tyler
@tylergross
Apr 20 2016 00:05
yes that too
Hanan Mufti
@h-ARTS
Apr 20 2016 00:06
@bitgrower ahhhh how can i be so stupid :smile: thank you so much :+1: :+1:
CamperBot
@camperbot
Apr 20 2016 00:06
h-arts sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 1005 | @bitgrower | http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Apr 20 2016 00:06
yw ... !
Kevin
@KevinBruland
Apr 20 2016 00:06
function titleCase(str) {
  str = str.toLowerCase().split(" ");
 return str[0].split("")[0].toUpperCase().join("");
}

titleCase("I'm a lIttle tea pot");
Can someone explain to me why im getting an error when the .join is on the end?
bitgrower
@bitgrower
Apr 20 2016 00:07
not to worry ... humiliation is not rare in programming ... LOL ... all kinds of "little" things can trip ya up ... the main thing is, don't beat yourself up about it ... it's perfectly normal and common ..
Ken Haduch
@khaduch
Apr 20 2016 00:07
@micahbales - you're welcome...
Kevin
@KevinBruland
Apr 20 2016 00:08
is it because im trying to join something that is still set as just an individual item in the array?
heymark
@heymark
Apr 20 2016 00:08
@Benalron why str[0]?
Phenoix8
@Phenoix8
Apr 20 2016 00:08
WOW a FREAKING COMMA I'VE BEEN STUCK ON THIS FOR LIKE 20 MINUTES THANKS @tylergross @sjames1958gm
CamperBot
@camperbot
Apr 20 2016 00:08
phenoix8 sends brownie points to @tylergross and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 326 | @tylergross | http://www.freecodecamp.com/tylergross
:star: 709 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Kevin
@KevinBruland
Apr 20 2016 00:09
@heymark im not trying to fully solve the problem yet, im just testing a specific section... it's string 0 and not within a loop yet so I can figure out how to get it to capitalize one letter
@heymark I am able to get it to capitalize the first letter, but I can't seem to get .join("") to work to rejoin the array
Ken Haduch
@khaduch
Apr 20 2016 00:10

@Benalron -

is it because im trying to join something that is still set as just an individual item in the array?

That's what I was going to say. YOu are doing a join on item [0] of the array, which is no longer an array.

Kevin
@KevinBruland
Apr 20 2016 00:10
@khaduch thats what I figured, I just can't figure out how to go back to targeting the fully array on the same line... do I need to do that on a seperate line of code?
heymark
@heymark
Apr 20 2016 00:11
@Benalron you're trying to "join" a 1-character string, not an array element
Ken Haduch
@khaduch
Apr 20 2016 00:11
@Benalron - sometimes that's what you need to do.
Kevin
@KevinBruland
Apr 20 2016 00:11
@khaduch OK, thanks a lot for both of your help
CamperBot
@camperbot
Apr 20 2016 00:11
benalron sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star: 968 | @khaduch | http://www.freecodecamp.com/khaduch
heymark
@heymark
Apr 20 2016 00:12
@Benalron or get comfortable with map :)
Kevin
@KevinBruland
Apr 20 2016 00:14
I'll probably get a refresher on the map thing after I awkwardly split this a couple times
heymark
@heymark
Apr 20 2016 00:15
enjoy
Andrew Vanboxel
@avanbox
Apr 20 2016 00:18
hey everyone. im working on a challenge and am a bit stuck. Ive got two objects. i need to see if they any keys in the first object are in the second object. This first object is an array of three objects each having two keys. How do i iterate through the individual keys of the first object?
[{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" })
Kevin
@KevinBruland
Apr 20 2016 00:19
Well, I got it to work lol
heymark
@heymark
Apr 20 2016 00:19
nice!
Kevin
@KevinBruland
Apr 20 2016 00:19
now I just need to look at other results to see how they do it in 1/10th of the code I did
heymark
@heymark
Apr 20 2016 00:20
@Benalron here's a quickie > https://jsfiddle.net/qb8mxfna
Virali
@virali17
Apr 20 2016 00:20
hey i have written this code and it shows the correct answer still when i try to run this. nothing happens and one of the requirement of the program doesn't get fulfilled
could anyone please help me out with this

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

testArr.push(item);
item = testArr.shift();

return item; // Change this line
}

// Test Setup
var testArr = [5,6,7,8,9];

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

here is my code
Micah Bales
@micahbales
Apr 20 2016 00:20
@khaduch Hi, I have another question. Are you still around?
Moisés Man
@moigithub
Apr 20 2016 00:21
@avanbox u have 2 arguments there.. the first is an array of object
the second is an object
to get ALL the keys names u can use Object.keys
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
this will return an array with a list of keys names
Frank XC
@tenkdayz
Apr 20 2016 00:22
@virali17 declare a new var item = testArr.shift();
Moisés Man
@moigithub
Apr 20 2016 00:22
@virali17 u should work with arr (the argument) instead of testArr
Andrew Vanboxel
@avanbox
Apr 20 2016 00:22
@moigithub Thanks Ive been using that but say for one object it returns [first, last] how do I access just [first] or [last]
CamperBot
@camperbot
Apr 20 2016 00:22
avanbox sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star: 972 | @moigithub | http://www.freecodecamp.com/moigithub
Ken Haduch
@khaduch
Apr 20 2016 00:22
@micahbales - yup, just about to run off to some other task, but I'm still here...
Micah Bales
@micahbales
Apr 20 2016 00:23
I have kind of a strange question
Moisés Man
@moigithub
Apr 20 2016 00:23
@avanbox its an array.. u use indices...
myArray[0] <-- will access the first element
if multiple elemtsn.. u need an iterator.. like for/forEach
Micah Bales
@micahbales
Apr 20 2016 00:24
@khaduch If you look down at the bottom of my javascript, I have a function called playerClick()
@khaduch I just realized that i really want to have all my click actions run through this function.
Andrew Vanboxel
@avanbox
Apr 20 2016 00:24
ok thanks thats what i thought i just couldnt get it to work. im going to start over thank you again
Micah Bales
@micahbales
Apr 20 2016 00:24
@khaduch But I'm also realizing I don't know how to make this work in terms of "this" statements.
@khaduch for example, $(this ' p').whateverjquery doesn't work. Does this kind of expression even exist?
@khaduch (let me know if I'm making sense...)
Moisés Man
@moigithub
Apr 20 2016 00:25
@virali17 item = testArr.shift(); also u overriding the value of the argument passed.... probably would be good if u create anther variable instead
Ken Haduch
@khaduch
Apr 20 2016 00:26
@micahbales - this should refer to the object that was clicked. So you cannot use it in the jQuery search function, it should already be set to point to the object that was clicked. Now I'm not sure if it's the div or the p - you might just try this.whateverJQuery to see what happens?
Stephen James
@sjames1958gm
Apr 20 2016 00:26
@micahbales It appears that if you do $('p', this) p is selected in terms of this
Kevin
@KevinBruland
Apr 20 2016 00:26
@heymark thats a lot cleaner than my 12 lines lol
Micah Bales
@micahbales
Apr 20 2016 00:27
@khaduch I think that @sjames1958gm has a good looking answer here. Let me try this out and see if it works. Thanks to you both!
CamperBot
@camperbot
Apr 20 2016 00:27
micahbales sends brownie points to @khaduch and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: micahbales already gave khaduch points
:star: 710 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Ken Haduch
@khaduch
Apr 20 2016 00:27
@sjames1958gm - interesting. I was thinking that you could do this.child() something or other, but that syntax that you suggested looks better than other contortions... :)
Micah Bales
@micahbales
Apr 20 2016 00:27
+1
Stephen James
@sjames1958gm
Apr 20 2016 00:28
@khaduch I am a genius, or good at googling :)
Micah Bales
@micahbales
Apr 20 2016 00:28
@sjames1958gm googling is an essential skill.
heymark
@heymark
Apr 20 2016 00:29
@Benalron but not necessarily more readable
Virali
@virali17
Apr 20 2016 00:30
oh yes i should have used arr instead of testArr. I got the correct output. Thank you @moigithub
CamperBot
@camperbot
Apr 20 2016 00:30
virali17 sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star: 973 | @moigithub | http://www.freecodecamp.com/moigithub
Frank XC
@tenkdayz
Apr 20 2016 00:30
@micahbales use $(this).childre(1)
Abdul-Samii Ajala Olalekan
@jalasem
Apr 20 2016 00:30

@khaduch

please help!

//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++ ){
    contacts[i].hasOwnProperty()
  }
// Only change code above this line
}

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

Profile Lookup

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

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

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

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

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

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

anyone can help pls
heymark
@heymark
Apr 20 2016 00:32
@jalasem what are you having trouble with?
Islam Ibakaev
@dagman
Apr 20 2016 00:32
is there anyone who get certification on freecodecamp?
Ken Haduch
@khaduch
Apr 20 2016 00:32
@jalasem - you are off to a good start, in that you realize that a for loop is required to access the individual contact records. - Now, look at each of the tasks in the problem statement.
Hanan Mufti
@h-ARTS
Apr 20 2016 00:33
I want to test my code and I can't return "pony" nor "kitten"
// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here
  if (myObj.hasOwnProperty(checkProp) === true) {
    return myObj.checkProp;
  } else {
    return "Not Found";
  }
}

// Test your code by modifying these values
checkObj("gift");
Micah Bales
@micahbales
Apr 20 2016 00:33
@sjames1958gm @khaduch So I'm doing this now, and the console.log is firing, but my .text() is not...
  function playerClick() {
    if ($(this).text() === '') { // make sure the box hasn't been selected before
    $('p', this).text(x);
    console.log(clicked);
    }
  }
Ken Haduch
@khaduch
Apr 20 2016 00:34

@jalasem -

  • The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.
    --- You are supposed to take the contact that you are examining, and compare the firstName function argument with the firstName property of the contact, see if it matches. Then determine if that contact has the property that is given in the prop function argument.

  • If both are true, then return the "value" of that property.
    --- That is one condition where you can successfully return from the function with a property value from the object

  • If firstName does not correspond to any contacts then return "No such contact"
    ---- This is only to be returned after all of the contacts have been examined. (Everyone who has a problem with this gets this return in the wrong place...)

  • If prop does not correspond to any valid properties then return "No such property"
    ---- This implies that that firstName matches, but the property does not exist for that contact. So you can return this after you find a matching name, and no property.

Are those checks in the right order? I mean, as they were stated in the problem?

Stephen James
@sjames1958gm
Apr 20 2016 00:35
@micahbales Is it supposed to write an X in the square?
heymark
@heymark
Apr 20 2016 00:35
@h-ARTS try bracket notation instead of dot notation
Hanan Mufti
@h-ARTS
Apr 20 2016 00:36
@heymark thank you it worked!
CamperBot
@camperbot
Apr 20 2016 00:36
h-arts sends brownie points to @heymark :sparkles: :thumbsup: :sparkles:
:star: 190 | @heymark | http://www.freecodecamp.com/heymark
Micah Bales
@micahbales
Apr 20 2016 00:36
@sjames1958gm x is a variable that === "X"
Andrew Vanboxel
@avanbox
Apr 20 2016 00:36
anyone happen to be working on "where art thou"
Micah Bales
@micahbales
Apr 20 2016 00:36
@sjames1958gm (so, yes)
Stephen James
@sjames1958gm
Apr 20 2016 00:37
@micahbales When I click it puts an X in the square I click
Micah Bales
@micahbales
Apr 20 2016 00:37
this is only affecting the bottom right hand square right now. the rest are still working on the old system.
@sjames1958gm
Stephen James
@sjames1958gm
Apr 20 2016 00:37
Ah yes it does
Micah Bales
@micahbales
Apr 20 2016 00:38
@sjames1958gm It's working for you in the lower right hand square?
Stephen James
@sjames1958gm
Apr 20 2016 00:38
No I meant yes it doesn't work :)
Micah Bales
@micahbales
Apr 20 2016 00:38
:D
Ken Haduch
@khaduch
Apr 20 2016 00:42

@micahbales - I edited your code to look like this, because I don't know what this refers to in the playerClick() function:

  $('#nine').on('click', function() {
    clicked[8] = true;  
    playerClick(this);


  });

  // when the player clicks a block
  function playerClick(that) {
    if ($(that).text() !== '') { // make sure the box hasn't been selected before

    }
    $('p', that).text(x);
    console.log(clicked);
  }

So I'm passing this as that to the function, and it looks like it makes the last square work? Oops, but it makes all of the other squares change, too... :)

because it is changing all of the p elements for everything that is not passing this as that...
Stephen James
@sjames1958gm
Apr 20 2016 00:43
@khaduch @micahbales Yes - just tried that and it worked
Amir Ghafouri
@amirghafouri
Apr 20 2016 00:44
Why is this returning "TypeError: Cannot read property of '1' of undefined"? When I do tests to return cid[0][1] it works, but inside of the loop it isn't recognizing cid[i][1]
  cash = cash * 100;
  price = price * 100;

  var changeDue = cash - price;
  var cidSum = 0;
  var changeReturned = [];

  // sum of cash-in-drawer
  cid.forEach(function(value) {
    cidSum += value[1] * 100;
  });

  // main control
  if (changeDue > cidSum) {
    return "Insufficient Funds";
  } else if (changeDue === cidSum) {
    return "Closed";
  }

  //while (changeDue > 0) {
    for (var i=0; i<cid.length; i++) {
      if (cid[i][1] <= changeDue && cid[i+1][1] > changeDue) {
        changeReturned.push(cid[i]);
        changeDue -= cid[i][1];
      }
    }  
 //}
  return changeReturned;
}
Ken Haduch
@khaduch
Apr 20 2016 00:44
@micahbales - because playerClick did not know what this was clicked, so you pass in the value of this from the click function and then you've got it...
Stephen James
@sjames1958gm
Apr 20 2016 00:44
@khaduch Turns out this in playerClick is window - not sure why it worked for any
@amirghafouri cid[i] must be wrong at some point perhaps when you do cid[i+1] and i = cid.length - 1
Micah Bales
@micahbales
Apr 20 2016 00:45
@khaduch Brilliant! Thanks so much. I had read about "this ==> that", but had never used it before.
CamperBot
@camperbot
Apr 20 2016 00:45
micahbales sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:warning: micahbales already gave khaduch points
Ken Haduch
@khaduch
Apr 20 2016 00:45
@sjames1958gm @micahbales - I think that it worked only for the lower right because Micah set it up initially to work that way. Then changing it to be $('p', this) essentially made all p elements accessible to that function if this was window... sheesh!
Micah Bales
@micahbales
Apr 20 2016 00:47
Somehow I didn't realize I needed to pass "this" to the function. Thought it would "know where it was" when clicked
Obviously not! :D
heymark
@heymark
Apr 20 2016 00:48
@amirghafouri is that the whole function? Looks like something's missing at the top.
Ken Haduch
@khaduch
Apr 20 2016 00:49
@micahbales - I think that this for the click handler is only local to the scope of the click handler. As Stephen pointed out, and it must be the default, this has window in any other function - probably a global value for this.
Micah Bales
@micahbales
Apr 20 2016 00:50
that makes sense. will need to remember that next time i need to pass this to an external function.
Stephen James
@sjames1958gm
Apr 20 2016 00:51
@micahbales I might just call it elem in the called function you can still do $(elem) - might be more descriptive the $(that)
Micah Bales
@micahbales
Apr 20 2016 00:52
While we're all here.. Is there a good way for me to collapse my nine click events into one?
@sjames1958gm My understanding is that calling it that is actually a Javascript convention.
Stephen James
@sjames1958gm
Apr 20 2016 00:53
@micahbales You can attach to .block and then use the id of this (or that).
I've lost your link - you can use the class as a selector for .on('click'
Ken Haduch
@khaduch
Apr 20 2016 00:57

@sjames1958gm @micahbales - can you do $(that)? Because that is already a jquery object - maybe it works? I've just not done that much fancy stuff in jquery...

And if that isn't a JavaScript convention, it should darned well be! (I just used it here because it seemed logical...)

Micah Bales
@micahbales
Apr 20 2016 00:57
crap. I don't know what happened, but all of a sudden nothing works.
@khaduch It is, interestingly enough.
Ken Haduch
@khaduch
Apr 20 2016 00:58
@micahbales - you're getting an error in the console: pen.js:10 Uncaught ReferenceError: clicked is not defined
Micah Bales
@micahbales
Apr 20 2016 00:58
got it.
removed some now-useless code, but forgot to remove all of it. :)
Thanks so much you guys. You saved me a whole lot of head-desking
Amir Ghafouri
@amirghafouri
Apr 20 2016 00:59
@sjames1958gm This is it. Not sure how I can execute the same logic in a way that will work. Maybe with a ternary operator for the second part of the if statement that test whether we are currently on the last element of the cid array?
Stephen James
@sjames1958gm
Apr 20 2016 00:59
@khaduch If a variable is a DOM element then $(var) works
Ken Haduch
@khaduch
Apr 20 2016 01:00
@sjames1958gm - cool... thanks for the help with this, now if only I can remember this for when I get to this project... :)
CamperBot
@camperbot
Apr 20 2016 01:00
khaduch sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 711 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Micah Bales
@micahbales
Apr 20 2016 01:01
@khaduch You haven't done tic tac toe yet?
Ken Haduch
@khaduch
Apr 20 2016 01:02
@micahbales - no... I have too many learning projects going on... :)
Micah Bales
@micahbales
Apr 20 2016 01:03
@khaduch nice
Ken Haduch
@khaduch
Apr 20 2016 01:04
and I'm stuck here in the chat room too many times helping people, which helps me in the long run, but I usually find that all of my computer time is spent explaining a few of the basic stumbling blocks to people... ;) I'll get there someday!
"Record Collection" is a popular one...
Wayne M. Davies
@WayneMDavies
Apr 20 2016 01:05
Well, here's one for you; I can't get this to return anything but "undefined". I think it's because of the nested array but nothing I've tried seems to return the prop:

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

var msg1 = "No such contact";
var msg2 = "No such property";

while (firstName === contacts[firstName]) {
}
alert (msg1);

while (prop === contacts[prop]) {
}
alert (msg2);

console.log(contacts[prop]);
return contacts[prop];

// Only change code above this line
}

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

Ken Haduch
@khaduch
Apr 20 2016 01:06
@WayneMDavies - another of my favorites!
Micah Bales
@micahbales
Apr 20 2016 01:06
@khaduch I'm super focused on finishing my front-end certification, because i've promised myself a mac laptop when I complete it. (And my current, PC laptop is killing me with a totally dead battery.)
Wayne M. Davies
@WayneMDavies
Apr 20 2016 01:07
sorry man
Ken Haduch
@khaduch
Apr 20 2016 01:08
@WayneMDavies - no apologies necessary! This is one of my favorites...
Your code is not right... contacts is an array of objects, so you need to have an index into the array in order to actually look at a contact object. Instead of a while loop, a for loop would be much more effective... that will get you started on a slightly better path.
Wayne M. Davies
@WayneMDavies
Apr 20 2016 01:09
That's wierd cause the exercise calls for a while loop.
Chase Webb
@jerrybaggin
Apr 20 2016 01:09
could someone explain how I actually post my code instead of copy and paste?
Wayne M. Davies
@WayneMDavies
Apr 20 2016 01:10
I'l keep working on it
@jerrybaggin yeah, me too
acgillette
@acgillette
Apr 20 2016 01:10
Haha I was just coming in here to ask about that same project as well
Micah Bales
@micahbales
Apr 20 2016 01:10
@jerrybaggin You see the ~ key on your keyboard, upper left hand side?
acgillette
@acgillette
Apr 20 2016 01:10
the contacts one
Micah Bales
@micahbales
Apr 20 2016 01:10
@jerrybaggin hit shift and use the apostrophe key there three times ```
then type your code. then type ``` below, and hit enter
Ken Haduch
@khaduch
Apr 20 2016 01:11
help format
CamperBot
@camperbot
Apr 20 2016 01:11

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

Micah Bales
@micahbales
Apr 20 2016 01:11
your code here
Ken Haduch
@khaduch
Apr 20 2016 01:11
@acgillette - welcome to the contact help room! :) Ask away!
Chase Webb
@jerrybaggin
Apr 20 2016 01:11
~~~
Micah Bales
@micahbales
Apr 20 2016 01:12
sorry, was wrong about shift. lol
Chase Webb
@jerrybaggin
Apr 20 2016 01:12
lol
Ken Haduch
@khaduch
Apr 20 2016 01:12

@WayneMDavies

That's wierd cause the exercise calls for a while loop.

It does? Let me look at that again?

acgillette
@acgillette
Apr 20 2016 01:12
I'm just struggling with the logic of it. Right now I have a for nested for loop that finds contacts[i][j but I'm a bit stuck on what to do next
Coy Sanders
@coymeetsworld
Apr 20 2016 01:13
which challenge is that @acgillette?
Chase Webb
@jerrybaggin
Apr 20 2016 01:13
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(collection.ablum[1] !== ""){

  }

  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
this work?
acgillette
@acgillette
Apr 20 2016 01:14
the Profile Lookup
Wayne M. Davies
@WayneMDavies
Apr 20 2016 01:14
@khaduch I should say that the previous exercise introduces the while loop so I assumed that I should use it
Coy Sanders
@coymeetsworld
Apr 20 2016 01:14
ah well you shouldn't need more than one for loop for that
Chase Webb
@jerrybaggin
Apr 20 2016 01:14
well alright im in action now, quick question fellas/ladies! in my if statement in this record collection challenge, is my if(collection.ablum.1 !="" ) the second object 2468?
Coy Sanders
@coymeetsworld
Apr 20 2016 01:14
if you want to post your code we can help further if there's a specific issue you're having
acgillette
@acgillette
Apr 20 2016 01:15
 function lookUpProfile(firstName, prop){
// Only change code below this line
  for (var i = 0; i < contacts.length; i++) {
    for (var j = 0; j < contacts[i].length; j++) {
      if (contacts[i][j] == contacts[i][firstName]) {

      }
    }
  }
// Only change code above this line
}
is all I have right now
Coy Sanders
@coymeetsworld
Apr 20 2016 01:16
you shouldn't need that 2nd loop, you only have a one dimensional array of objects
acgillette
@acgillette
Apr 20 2016 01:16
yeah I think I'm starting to see it
I think I assumed that because that's what we've been learning I'd need it
Coy Sanders
@coymeetsworld
Apr 20 2016 01:16
not in this case no you won't need that
you would iterate through the loop to find the object with the right firstName
then once you find that object check to see if it has the property prop, look up hasOwnProperty() function on how to do that
Ken Haduch
@khaduch
Apr 20 2016 01:18
@acgillette @coymeetsworld - Coy is right - what you are looking at when you have contacts[i] is an object, and you cannot use a for loop to examine object properties, at least not in any sensible way (if it does work at all? Not sure if an object has a .length() method?)
Coy Sanders
@coymeetsworld
Apr 20 2016 01:19
don't believe it does @khaduch , but you don't need it because you don't need to iterate through all the properties of an object
Ken Haduch
@khaduch
Apr 20 2016 01:20
@WayneMDavies - hmmmmm... it might just be circumstance that they had the while loop right before this one. Not to say that it is impossible to use a while loop, but you then have to have an index into the array and make sure to increment it as you go along...
Coy Sanders
@coymeetsworld
Apr 20 2016 01:20
if you're looking for a specific property just need to use hasOwnProperty(propertyYou'reLookingFor)
Chase Webb
@jerrybaggin
Apr 20 2016 01:20
@khaduch love that mustache.
Ken Haduch
@khaduch
Apr 20 2016 01:20
@coymeetsworld - yes, so it wouldn't work anyway in that code... but you are correct in that you don't need to look at all of the properties of these objects in this case...
acgillette
@acgillette
Apr 20 2016 01:21
function lookUpProfile(firstName, prop){
// Only change code below this line
  for (var i = 0; i < contacts.length; i++) {
    if (contacts[i][firstName] == firstName) {

    }
  }
// Only change code above this line
}
so would this be closer to where I want to be?
Coy Sanders
@coymeetsworld
Apr 20 2016 01:21
yes thats good
Chase Webb
@jerrybaggin
Apr 20 2016 01:25
in the record challenge if my prop is tracks and value is not blank, im supposed to push the value on the end of the tracks array. so would it be something like this collection.tracks0.push(); ?
Coy Sanders
@coymeetsworld
Apr 20 2016 01:27
you need to use id and value in that @jerrybaggin
buonarfcc
@buonarfcc
Apr 20 2016 01:29
Hello any one howdy?
acgillette
@acgillette
Apr 20 2016 01:30
function lookUpProfile(firstName, prop){
// Only change code below this line
  for (var i = 0; i < contacts.length; i++) {
    if (contacts[i][firstName] == firstName) {
      if (contacts[i].hasOwnProperty(prop)) {
        return contacts[i][prop];
      } else {
        return "No such property";
      }
    } else {
      return "No such contact";
    }
  }
// Only change code above this line
}
Am I way off here? I feel like this looks somewhat right but the property portion isn't working
Coy Sanders
@coymeetsworld
Apr 20 2016 01:30
looks perfect to me
buonarfcc
@buonarfcc
Apr 20 2016 01:30

please give me a hand on this simple addition codes-> I got exactly all the 3 numbers asked but system still red Xs me on the last 3 of them?var Bike = function() {

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

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

var myBike = new Bike();
myBike.setGear(1);

Coy Sanders
@coymeetsworld
Apr 20 2016 01:30
what test isn't passing?
oh wait, your first if statement
i missed it, you don't want to use bracket notation for firstName
acgillette
@acgillette
Apr 20 2016 01:31
so change it to contact[i].firstName?
Coy Sanders
@coymeetsworld
Apr 20 2016 01:31
yes
otherwise if you called lookup("Akira", "likes"), it would be checking for the property named Akira
not the firstName with the value of Akira
Chase Webb
@jerrybaggin
Apr 20 2016 01:32
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(collection.tracks[0] !== "" || prop !== collection.tracks[0]){

  }

  return collection;
}
what does the id reference? the 2548 numbers?
Coy Sanders
@coymeetsworld
Apr 20 2016 01:32
yes @jerrybaggin
Tyler
@tylergross
Apr 20 2016 01:32
has anyone done the least common multiply challenge? it seems to me like to find the solution we need to find all of the prime factorizations of every number in the sequence and then multiply by the highest counted prime factors .... seems like a lot of programming... anyone have any other methods that might be easier to find the least common multiple?
acgillette
@acgillette
Apr 20 2016 01:33
it seems like the main problem is it's not returning the property value correctly
Tyler
@tylergross
Apr 20 2016 01:33
i tried a for loop counting up until all numbers were divisible, however this possibly creates an infinite loop but seems a lot easier
acgillette
@acgillette
Apr 20 2016 01:34
the "no contact" and "no property" tests are passing but not the ones that involve returning a property
Coy Sanders
@coymeetsworld
Apr 20 2016 01:34
can you post your modified code @acgillette ?
@tylergross theres an algorithm you can use for that challenge
try looking at that, you can solve the problem much easier using recursion
acgillette
@acgillette
Apr 20 2016 01:36
```
function lookUpProfile(firstName, prop){
// Only change code below this line
  for (var i = 0; i < contacts.length; i++) {
    if (contacts[i].firstName == firstName) {
      if (contacts[i].hasOwnProperty(prop)) {
        return contacts[i][prop];
      } else {
        return "No such property";
      }
    } else {
      return "No such contact";
    }
  }
// Only change code above this line
}
Coy Sanders
@coymeetsworld
Apr 20 2016 01:37
oh ok your loop is exiting prematurely
you're only checking the first item in the array with this logic, no matter what a return statement will hit
Tyler
@tylergross
Apr 20 2016 01:38
@coymeetsworld thanks i found a much easier formula than factoring and multiplying primes
CamperBot
@camperbot
Apr 20 2016 01:38
tylergross sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star: 597 | @coymeetsworld | http://www.freecodecamp.com/coymeetsworld
Coy Sanders
@coymeetsworld
Apr 20 2016 01:38
really @tylergross ?
well gj then, couldn't find anything easier than that
Seniority
@Seniority
Apr 20 2016 01:39
for JavaScript objects, do you HAVE to put the property name in quotes? or are the quotes optional?
Tyler
@tylergross
Apr 20 2016 01:39
@coymeetsworld says to multiply all numbers and then divide by the greatest common denominator to find the lowest common multiple
Coy Sanders
@coymeetsworld
Apr 20 2016 01:40
hmm interesting
Tyler
@tylergross
Apr 20 2016 01:40
@coymeetsworld not sure if it works for multiple numbers though, going to test it out
acgillette
@acgillette
Apr 20 2016 01:40
oh hmmm ok. Is it using the return statements that is doing it? I think I see whats going on
Coy Sanders
@coymeetsworld
Apr 20 2016 01:41
yes @acgillette, need to rework small part in your logic
you're exiting the for loop too early
interesting @tylergross i'll have to check that out thanks for the link
CamperBot
@camperbot
Apr 20 2016 01:41
coymeetsworld sends brownie points to @tylergross :sparkles: :thumbsup: :sparkles:
:star: 328 | @tylergross | http://www.freecodecamp.com/tylergross
Chase Webb
@jerrybaggin
Apr 20 2016 01:44
@coymeetsworld im not actually sure what im supposed to do with this id... i tired if(id.tracks[0]) which doesnt work because the id is undefined.
Coy Sanders
@coymeetsworld
Apr 20 2016 01:44
you still need to use the collection array
Chase Webb
@jerrybaggin
Apr 20 2016 01:45
so id.collection.tracks[0]. ?
Ken Haduch
@khaduch
Apr 20 2016 01:45
@acgillette - you just need to make sure that your code will check every contact in the array for a name match before you can return "no such contact"... So you just have to move that last return elsewhere to make sure that you do that.
Coy Sanders
@coymeetsworld
Apr 20 2016 01:46
yep that's right @khaduch @acgillette
acgillette
@acgillette
Apr 20 2016 01:51
oh yes i see what you mean now. Would moving the return outside the for loop fix it?
Coy Sanders
@coymeetsworld
Apr 20 2016 01:52
yes
you want to go through the array, and if you don't find what you're looking for then you know the contact doesn't exist
Ken Haduch
@khaduch
Apr 20 2016 01:57
@acgillette - you're on the way! Good luck!
LostInTransistors
@marcosignorello
Apr 20 2016 01:58
I think you can filter the array right? @khaduch
heymark
@heymark
Apr 20 2016 02:02
@tylergross thanks for that LCM article. That explains why the LCM exercise comes right after the Sum All Primes exercise. :)
CamperBot
@camperbot
Apr 20 2016 02:02
heymark sends brownie points to @tylergross :sparkles: :thumbsup: :sparkles:
:star: 329 | @tylergross | http://www.freecodecamp.com/tylergross
Ken Haduch
@khaduch
Apr 20 2016 02:02
@jerrybaggin - just looking through the responses - I don't see any response to your question. Yes, the "id" is the numeric property value for each object in the collection, so 2458, 2468, etc. will the the id values.
acgillette
@acgillette
Apr 20 2016 02:11
Got it! Thanks so much for your help @khaduch and @coymeetsworld !
CamperBot
@camperbot
Apr 20 2016 02:11
acgillette sends brownie points to @khaduch and @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star: 598 | @coymeetsworld | http://www.freecodecamp.com/coymeetsworld
:star: 969 | @khaduch | http://www.freecodecamp.com/khaduch
Coy Sanders
@coymeetsworld
Apr 20 2016 02:11
nice, gj @acgillette
D. Omran
@domran23
Apr 20 2016 02:12
piggy backing on @jerrybaggin, so we need to run a loop to check all the id's in the array? I only know about loops from other courses. So far, I haven't run across loops in this course so far...
so like this? for(var i = 0; i <= collection.length; i++)
A H
@allenhsieh
Apr 20 2016 02:14

Hi all, I posted this in the wrong channel but I'm having trouble with the Record Collection exercise. I've worked through most of it and I know i have an error somewhere but I can't see where. The instructions:
Write a function which takes an id, a property (prop), and a value.

For the given id in collection:

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

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

If value is blank, delete that prop.

Always return the entire collection object.

My code:

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

    }
  }

  return collection;
}
Stephen James
@sjames1958gm
Apr 20 2016 02:14
@domran23 not <= only <
Moisés Man
@moigithub
Apr 20 2016 02:14
@allenhsieh prop is a variable.. sooo NO dot notation...
Stephen James
@sjames1958gm
Apr 20 2016 02:15
@allenhsieh Also, it looks like you are overwriting the incoming id with your loop. Since you have id, a loop is not needed
Coy Sanders
@coymeetsworld
Apr 20 2016 02:15
@domran23 is that for record collection? If so no you don't need to use a for loop yet
D. Omran
@domran23
Apr 20 2016 02:16
but the function needs to find the id somehow
A H
@allenhsieh
Apr 20 2016 02:16
@sjames1958gm OH MY GOODNESS. THANK YOU.
CamperBot
@camperbot
Apr 20 2016 02:16
allenhsieh sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 712 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
A H
@allenhsieh
Apr 20 2016 02:16
@moigithub thank you, i will try all bracket
CamperBot
@camperbot
Apr 20 2016 02:16
allenhsieh sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star: 974 | @moigithub | http://www.freecodecamp.com/moigithub
Ken Haduch
@khaduch
Apr 20 2016 02:16
@allenhsieh - also you don't need a for loop for that... you have the direct id value to access the particular record.
D. Omran
@domran23
Apr 20 2016 02:16
@coymeetsworld yes and that's good to know lol
@sjames1958gm it appears I don't need a loop...
Stephen James
@sjames1958gm
Apr 20 2016 02:17
@domran23 yes
Ken Haduch
@khaduch
Apr 20 2016 02:17
@acgillette - you're welcome.... good luck with continuing projects!
A H
@allenhsieh
Apr 20 2016 02:17
@khaduch thank you!
CamperBot
@camperbot
Apr 20 2016 02:17
allenhsieh sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star: 970 | @khaduch | http://www.freecodecamp.com/khaduch
D. Omran
@domran23
Apr 20 2016 02:19
@coymeetsworld I thought it odd the exercise would need something the course hadn't covered yet but a loop made sense at first. From other courses I've learned they can be used this way
Coy Sanders
@coymeetsworld
Apr 20 2016 02:19
right @domran23
Stephen James
@sjames1958gm
Apr 20 2016 02:19
@domran23 Soon it will
Wayne M. Davies
@WayneMDavies
Apr 20 2016 02:20

@allenhsieh Well, I'm still getting "undefined" :```
function lookUpProfile(firstName, prop){
// Only change code below this line

var msg1 = "No such contact";
var msg2 = "No such property";

while (firstName == contacts.firstName) {
for ( var i = 1; i < contacts.length; i++) {
for (var j = 0; j < contacts[i].length; j++) {
while (prop == contacts.prop);
}
alert (msg2);
}
alert (msg1);
}

console.log(contacts.prop);
return contacts.prop;

// Only change code above this line
}

And i still don't know how to paste code. Sorry.
Coy Sanders
@coymeetsworld
Apr 20 2016 02:20
help format
CamperBot
@camperbot
Apr 20 2016 02:20

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

Coy Sanders
@coymeetsworld
Apr 20 2016 02:21
also @WayneMDavies you don't need a 2nd for loop
Wayne M. Davies
@WayneMDavies
Apr 20 2016 02:21
what about the nested array "likes"
D. Omran
@domran23
Apr 20 2016 02:21
@sjames1958gm ok, so how about now lol. How does the function associate id with the proper collection object property?
Coy Sanders
@coymeetsworld
Apr 20 2016 02:21
dont think you need to look in there
you just need to see if the object has a property and if so return it
Wayne M. Davies
@WayneMDavies
Apr 20 2016 02:22
right, okay
Coy Sanders
@coymeetsworld
Apr 20 2016 02:22
if the value of the property happens to be an array you just return it anyways, don't need to iterate through it to find something
Stephen James
@sjames1958gm
Apr 20 2016 02:22
@WayneMDavies You have too many loops - the first while loop will always evaluate to false because contacts is an array and has no firstname property
@domran23 If collection is an array, you have to search the entries to find a match
Wayne M. Davies
@WayneMDavies
Apr 20 2016 02:23
@sjames1958gm hmmm, in the array there is "firstName"
That's the first evaluation
Stephen James
@sjames1958gm
Apr 20 2016 02:23
@WayneMDavies That is a property of collection[i] not collection
D. Omran
@domran23
Apr 20 2016 02:24
@sjames1958gm collection is a JSON that contains arrays in other objects
Wayne M. Davies
@WayneMDavies
Apr 20 2016 02:24
ummm, different challenge?
Stephen James
@sjames1958gm
Apr 20 2016 02:24
@domran23 Oops
@WayneMDavies Oopps
Sorry guys
Are you doing lookup profile?
Then it is an array of objects.
@WayneMDavies Lookup Profile challenge?
Wayne M. Davies
@WayneMDavies
Apr 20 2016 02:26
yeah, I took out the second for loop but the problem persists
Stephen James
@sjames1958gm
Apr 20 2016 02:26
@domran23 are you on a new challenge.
D. Omran
@domran23
Apr 20 2016 02:26
no, this is the problem

// 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") {
prop = value;
} if (prop == "tracks" && value !== "") {
"tracks".push(value);
} if (value === "") {
delete [prop];
}
return collection;
}

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

Wayne M. Davies
@WayneMDavies
Apr 20 2016 02:27
that's the collection challenge
D. Omran
@domran23
Apr 20 2016 02:27
and instructioins

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

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

For the given id in collection:

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

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

If value is blank, delete that prop.

Always return the entire collection object.

my attempted solution is included
Wayne M. Davies
@WayneMDavies
Apr 20 2016 02:27
I'm on a different one called Profile Lookup
Stephen James
@sjames1958gm
Apr 20 2016 02:27
@domran23 So id is passed to your function.
@WayneMDavies Yes. Similar but different :)
Ken Haduch
@khaduch
Apr 20 2016 02:28
@domran23 and collection is the, um, collection of objects...
that you have been passed an id to use for access purposes.
D. Omran
@domran23
Apr 20 2016 02:29
Maybe I'm thinking into it too much but how does the function know that id belongs to the numbers in the object? I'm trying to associate them somehow
Stephen James
@sjames1958gm
Apr 20 2016 02:30
@domran23 By defintion of the problem
Ken Haduch
@khaduch
Apr 20 2016 02:30
in other words this line: For the given id in collection: - means that you have to access the collection and do something to one of the objects in it, using id.
A H
@allenhsieh
Apr 20 2016 02:30

@sjames1958gm @khaduch @moigithub Ok so i updated my code. I feel like the first if statement is wrong because when i run it, it is only giving me one green checkmark

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

What I tried was adding a variable right after declaring the function, something like

var property = collection[id].prop;

but i noticed that was redundant and didn't follow the principle of DRY

Stephen James
@sjames1958gm
Apr 20 2016 02:31
@allenhsieh Remember the comment about brackets. .prop refers to a property named prop [prop] refers to a property in the variable prop
D. Omran
@domran23
Apr 20 2016 02:31
ok so it's understood that id is for the collection. I was thinking into it too much
Stephen James
@sjames1958gm
Apr 20 2016 02:32
@domran23 :+1:
Wayne M. Davies
@WayneMDavies
Apr 20 2016 02:32
function lookUpProfile(firstName, prop){
// Only change code below this line

  var msg1 = "No such contact";
  var msg2 = "No such property";

  while (firstName == contacts.firstName) {
    for ( var i = 1; i < contacts.length; i++) {
        while (prop == contacts.prop);
          }
    alert (msg2);
     }
  alert (msg1);

  console.log(contacts.prop);
  return contacts.prop;

// Only change code above this line
}
Moisés Man
@moigithub
Apr 20 2016 02:32
:point_up: April 19, 2016 9:14 PM @allenhsieh
Ken Haduch
@khaduch
Apr 20 2016 02:32
@domran23 - looking at the test descriptions also gives you some additional insight into what they are expecting, sometimes useful to look at it from that perspective.
Wayne M. Davies
@WayneMDavies
Apr 20 2016 02:32
@khaduch where am I going wrong?
Stephen James
@sjames1958gm
Apr 20 2016 02:32
@WayneMDavies the first while loop will not be true ever as contacts (the array) as no property firstname
D. Omran
@domran23
Apr 20 2016 02:33
@khaduch ahh that's a good tip! thanks
CamperBot
@camperbot
Apr 20 2016 02:33
domran23 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star: 971 | @khaduch | http://www.freecodecamp.com/khaduch
D. Omran
@domran23
Apr 20 2016 02:33
@sjames1958gm thanks!
CamperBot
@camperbot
Apr 20 2016 02:33
domran23 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 713 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
A H
@allenhsieh
Apr 20 2016 02:33
@sjames1958gm whoops, i went off and was trying out various bits of code, didn't see that you responded to someone else. Thank you once again and sorry for the redundancy.
CamperBot
@camperbot
Apr 20 2016 02:33
allenhsieh sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: allenhsieh already gave sjames1958gm points
Stephen James
@sjames1958gm
Apr 20 2016 02:34
@allenhsieh np
D. Omran
@domran23
Apr 20 2016 02:34
I need to stop copy and pasting my code lol. How do you insert it otherwise?
Wayne M. Davies
@WayneMDavies
Apr 20 2016 02:34

@sjames1958gm ```js
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"]
}
];

```

Seems to have that property?
Ken Haduch
@khaduch
Apr 20 2016 02:34
@WayneMDavies - you should remove that while loop. It is accessing nothing of use, and is unnecessary... There is no such property as contacts.firstName. Here is a hint - you should work up some code where you can refer to individual contacts with the notation contacts[i], as there is an array of contacts, and you want to be looking at each of them to process the conditions they are asking you to look for.
Stephen James
@sjames1958gm
Apr 20 2016 02:35
@WayneMDavies contacts itself doesn't have that property contacts[i] does.
heymark
@heymark
Apr 20 2016 02:35
Oh man, Array.from is pretty great.
A H
@allenhsieh
Apr 20 2016 02:35
@khaduch thank you for the "for the given id in collection" comment, it just made something "click" for me. I hope this is an "a-ha!" moment
CamperBot
@camperbot
Apr 20 2016 02:35
allenhsieh sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:warning: allenhsieh already gave khaduch points
Nicolas May
@hynso
Apr 20 2016 02:36
Has anyone here used the minimax algorithm in the tic tac toe zipline?
Ken Haduch
@khaduch
Apr 20 2016 02:37
@allenhsieh - good! One thing to do after getting the solution is to go back and re-read the lesson and problem statement and see how to understand what they are asking for in light of having a better understanding of it. Sometimes the wording of the problems is tricky, most often it seems to be pretty straightforward in these early problems.
Stephen James
@sjames1958gm
Apr 20 2016 02:41
@WayneMDavies Sometimes it helps to work with real world examples. Imagine these are each a card in a rolodex (does anyone still know what a rolodex is?).
Then for each card in the rolodex, if the firstname is the one I am looking for, does the card have the property I am looking for I am done (return the value). If the card does not I am done, return "no such property". If I get through all the cards and no match on firstname then I am done, no such contact.
Steven Gallegos
@webdev1990
Apr 20 2016 02:42
Screenshot from 2016-04-19 19:41:56.png
I am really lost, any pointers, I am stuck on filtering the same numbers of the index
Wayne M. Davies
@WayneMDavies
Apr 20 2016 02:43
@sjames1958gm Thanks, I will go home and work on this later; I truly appreciate your help.
CamperBot
@camperbot
Apr 20 2016 02:43
waynemdavies sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 714 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Wayne M. Davies
@WayneMDavies
Apr 20 2016 02:44
Oh, and I know what a Rolodex is, lol.
Stephen James
@sjames1958gm
Apr 20 2016 02:44
@WayneMDavies For me reasoning how to solve the problem without the computer first then translating to code can help.
@webdev1990 I am not sure your arguments array from destroyer will get to the popoff function.
robynsmith
@robynsmith
Apr 20 2016 02:45

Hello everyone. I have a relatively simple problem. Here is my code:

https://github.com/robynsmith/fccTribute

For some reason, this line doesn’t seem to work:

$(document).ready(function(){ $("h1").addClass("animated bounce"); });

The code seems to work on codepen but doesn’t work when I launch index.html from my home system.

Any ideas on what I’m doing wrong?
Steven Gallegos
@webdev1990
Apr 20 2016 02:45
@sjames1958gm i see, then I am a lot farther off than I expected lol hmm, I really need to focus on the filter
Stephen James
@sjames1958gm
Apr 20 2016 02:46
@webdev1990 If you convert arguments to an array and pass it as the second argument to filter, it becomes this in the filter function.
Brian D.
@bdeerwester
Apr 20 2016 02:47

hey all, any reason you can see why I can't push this value onto my array?

// Only change code below this line
function updateRecords(id, prop, value) {
...
if (prop === "tracks" && value !== "") {
collection[id][prop].push(value);
}
...
return collection;
}

Steven Gallegos
@webdev1990
Apr 20 2016 02:48
@sjames1958gm great hint, hmmm, back to the lab with this one!
Stephen James
@sjames1958gm
Apr 20 2016 02:48
@webdev1990 Good luck.
uriznik
@uriznik
Apr 20 2016 02:48
@robynsmith how are you loading the jquery js?
aerowinc
@aerowinc
Apr 20 2016 02:48
whats wrong with code like this?
Brian D.
@bdeerwester
Apr 20 2016 02:48
specifically, i'm on javascript "Accessing Nested Arrays in JSON"
aerowinc
@aerowinc
Apr 20 2016 02:48

function lookUp(firstName, prop) {
for (var i = 0; i < contacts.length; i++) {
if ( contacts[i].firstName == firstName && contacts[i][prop] !== undefined ) {
return contacts[i][prop];
} else if ( contacts[i][prop] === undefined ) {
return "No such property";
}
}
return "No such contact";

// Only change code above this line
}

Stephen James
@sjames1958gm
Apr 20 2016 02:48
@bdeerwester That looks correct
robynsmith
@robynsmith
Apr 20 2016 02:49

@uriznik I’m loading it in the HTML file on line 11:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>

Brian D.
@bdeerwester
Apr 20 2016 02:49
agh maybe there's a bug then? i'm failing the third checkmark
Stephen James
@sjames1958gm
Apr 20 2016 02:49
@aerowinc If the first entry's firstname is not a match you will never get to the second one.
Steven Gallegos
@webdev1990
Apr 20 2016 02:49
@sjames1958gm thank you!
CamperBot
@camperbot
Apr 20 2016 02:49
webdev1990 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
Ken Haduch
@khaduch
Apr 20 2016 02:49
@robynsmith - hello. Do you have the "animate.css" library loaded in your project somewhere? I don't see it in your HTML code.
CamperBot
@camperbot
Apr 20 2016 02:49
:star: 715 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
robynsmith
@robynsmith
Apr 20 2016 02:50
@khaduch I’m not sure. I thought it was included with jquery? This is my first time doing things outside of codepen and I just used the ability to load librarys through it’s tools.
uriznik
@uriznik
Apr 20 2016 02:50
@robynsmith add the html and body tags - codepen does it for you but outside of there you'll need them
robynsmith
@robynsmith
Apr 20 2016 02:50
This is what I was doing:
<head>
  <link rel="stylesheet" type="text/css" href="styles.css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
  <script src="main.js"></script>
</head>
I thought the above was sufficient?
Ken Haduch
@khaduch
Apr 20 2016 02:52
try adding //cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.3/animate.min.css and see... I think you need that. Also the items that @uriznik pointed out. You need those outside of CodePen.
@robynsmith
robynsmith
@robynsmith
Apr 20 2016 02:55
Ah
Adding this fixed it:
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.3/animate.min.css”>
So…..does jquery require me to include specific css components for things?
And if so - how do I figure out what CSS dependencies are required for specific functions within jQuery?
Ken Haduch
@khaduch
Apr 20 2016 02:57
@robynsmith - yes, jquery doesn't include everything, there are many CSS libs out there, if you're using something, you have to include it. I think that one of the early FCC CodePen examples had that animate.css added in.
Another thing you can do is go to your CodePen project and right-click in the frame where the page is being displayed, and "View Frame Source", You'll see everything that was there in the codepen project.
A H
@allenhsieh
Apr 20 2016 02:58

Okay So i know where the problem is with the brackets and I understand .prop is the property name (artist) and [prop] would be the value ("abba") so I reread the exercises and I tried using a variable but I think i just knocked myself further from the right path

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

Another variation without variables and no bracket (just top if statement)

function updateRecords(id, prop, value) {
   if ((value !== "") && (prop !== "tracks")){
     collection.id.prop = value;
    } else if ((prop == "tracks") && (value !== "")){
      collection[id].tracks.push(value);
    } else if (value === ""){
      delete collection[id].prop;
    }
  return collection;
}
robynsmith
@robynsmith
Apr 20 2016 02:58
Ahhh
I think I get it now
Thank you @khaduch
CamperBot
@camperbot
Apr 20 2016 02:59
robynsmith sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star: 972 | @khaduch | http://www.freecodecamp.com/khaduch
robynsmith
@robynsmith
Apr 20 2016 02:59
Thank you @uriznik
CamperBot
@camperbot
Apr 20 2016 02:59
robynsmith sends brownie points to @uriznik :sparkles: :thumbsup: :sparkles:
:star: 369 | @uriznik | http://www.freecodecamp.com/uriznik
robynsmith
@robynsmith
Apr 20 2016 03:00
@khaduch So to make sure I have it right: the reason why it animates is nothing to do with jQuery, jQuery just updated the element with animate related CSS?
Ken Haduch
@khaduch
Apr 20 2016 03:00
I think that jQuery itself is self-contained? If you are adding other things like those animate classes, they are not part of jQuery, probably not part of Bootstrap - they are in a separate library (or CSS package) that you need to specify when you're using it. There are so many things, jQuery is more or less a DOM searching and manipulation package. It does fiddle with CSS to the extent that it is doing fades, etc. (Maybe someone will correct me on that.)
robynsmith
@robynsmith
Apr 20 2016 03:00
Cool
That helps
I thought that was a jquery function
So much learning happening today :)
Ken Haduch
@khaduch
Apr 20 2016 03:01
@robynsmith - that's correct. You can write your own CSS or have jQuery add CSS attributes to elements in the DOM, or use another CSS library, "animate" is a good example, but there are probably thousands of CSS libraries out there?
This is the place to be learning! :) Good luck!
heymark
@heymark
Apr 20 2016 03:01
Depends whether you're using jQuery's built-in animation tools or using it to trigger CSS animations (e.g. by adding/removing a class), doesn't it?
A H
@allenhsieh
Apr 20 2016 03:03
@khaduch I'm still having problems, both variations i posted above don't work but i think i'm close
oh wow it is late.
i will try again tomorrow
thank you all for your help
so close i can taste it
Ken Haduch
@khaduch
Apr 20 2016 03:08

@allenhsieh - hello again. Someone pointed out above that your use of the variable prop to access properties of an object is covered by one of the lessons "Accessing Objects Properties with Variables", which states:

Another use of bracket notation on objects is to use a variable to access a property. 
This can be very useful for iterating through lists of the object properties or for doing the lookup.

Here is an example of using a variable to access a property:

var someProp = "propName";
var myObj = {
  propName: "Some Value"
}
myObj[someProp]; // "Some Value"

Basically, if you recall the times when you use "dot" notation or "square bracket" notation to access object properties, when the property name is held in a variable, you need to use square bracket notation. So - the example shows it. You have to use it! Let me look at your code and see if there are other things that you're having problems with...

Helen Jessica
@near93
Apr 20 2016 03:08
Hi all, I'm trying to create a simple shopping list loop but I'm stuck with setting array into a list.

var i, product, listLength, list, myList = [];

function shoppingList(){
product = document.shoppingForm.productInput.value;
myList.push(product);

listLength = myList.length;

for(i = 0; i < listLength; i++){
list += '<li>' + myList[i] + '</li>';
}

document.getElementById("list").innerHTML = list;
}

Ken Haduch
@khaduch
Apr 20 2016 03:12
@allenhsieh - yes, you are using collection[id] which is correct, because id is a variable that is holding the property name for the record album object, but you also have prop, so you need to use square bracket notation there, too. Just to put this in because I"m going to log off here... collection[id][prop] would be something that you would need to see in your code.
@near93 - do you have a link to a project or something? It would be nice to have the full context of what you are doing...
Helen Jessica
@near93
Apr 20 2016 03:16
Hi @khaduch, here it is: http://codepen.io/near93/pen/MyXaKb I'm confused as how to display the item one at a time.
Ken Haduch
@khaduch
Apr 20 2016 03:19

@near93 - ah, okay. You are putting the entire list out there each time, so as you build up the list, each item will be duplicated (or multiplicated?) :)

So you can clear the HTML for the list and write the entire list out again, or figure out how to append the new element to the list.

aerowinc
@aerowinc
Apr 20 2016 03:19
@sjames1958gm what do you mean by that exactly
Helen Jessica
@near93
Apr 20 2016 03:20
Will give it a try, thanks! @khaduch
CamperBot
@camperbot
Apr 20 2016 03:20
near93 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star: 973 | @khaduch | http://www.freecodecamp.com/khaduch
Ken Haduch
@khaduch
Apr 20 2016 03:21

@near93 - or just append the last item from the list as you're doing now, but instead of the entire list, just get the last item. For example, if you just do this:

  document.getElementById("list").innerHTML = '';
  for(i = 0; i < myList.length; i++){

add that line before the loop, it fixes it.

Yuri Morozov
@daturon
Apr 20 2016 03:22
@near93 ```
var i, product, listLength, list, myList = [];

function shoppingList() {
  product = document.shoppingForm.productInput.value;
  myList.push(product); 

  document.getElementById("list").innerHTML +=
    '<li>' + product + '</li>';  
}
Helen Jessica
@near93
Apr 20 2016 03:23
wow, thanks @daturon
CamperBot
@camperbot
Apr 20 2016 03:23
near93 sends brownie points to @daturon :sparkles: :thumbsup: :sparkles:
Austin Miles
@Nolo900
Apr 20 2016 03:23
Anyone see why this function isn't filtering out these types of values?
function bouncer(arr) { 
  arr = arr.filter(isFalsy);    
  console.log(arr);  
  return arr;
}

function isFalsy(arrItem) {

    return (typeof arrItem !== false || 
            typeof arrItem !== null ||
            typeof arrItem !== 0 ||
            arrItem !== "" ||
            typeof arrItem !== undefined ||
            typeof arrItem !== NaN
           );  
}

bouncer([7, "ate", "", false, 9]);
CamperBot
@camperbot
Apr 20 2016 03:23
:star: 292 | @daturon | http://www.freecodecamp.com/daturon
Helen Jessica
@near93
Apr 20 2016 03:23
or I could just remove the loop. Thanks! @khaduch
CamperBot
@camperbot
Apr 20 2016 03:23
near93 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:warning: near93 already gave khaduch points
Andrew Charlebois
@andrewchar
Apr 20 2016 03:24
@Nolo900 i think .filter returns a value of either true or false.
Helen Jessica
@near93
Apr 20 2016 03:24
I think the button itself is like a loop every time a new product is added.
Yuri Morozov
@daturon
Apr 20 2016 03:25
This message was deleted
Ken Haduch
@khaduch
Apr 20 2016 03:25
@Nolo900 - well, I think that you would want to use && instead of || because you want all of those conditions to be met.
Also there is a Boolean element that you can use, I think it's easier? I don't remember the exact method...
Yuri Morozov
@daturon
Apr 20 2016 03:26
This message was deleted
Lawrence Eagles
@lawrenceagles
Apr 20 2016 03:26
Hi guys, i have soveld this problem my own way. but I want to understand something. why mush the sort() method take the callback fucntion for all test to be passed. I just want to understand better what the callback function does here. Thanks.
function getIndexToIns(arr, num) {
  // Find my place in this sorted array.

 var newArr = arr.push(num);

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

  return arr.indexOf(num);


}

getIndexToIns([40, 60], 50);
Artur Sęp
@a-sep
Apr 20 2016 03:26

Hi, my "Roman Numeral Converter" pass tests, but I know that this is not best solution. How You have solve this lesson?
```
function convertToRoman(num) {
var rom = {
1: "I",
2: "II",
3: "III",
4: "IV",
5: "V",
6: "VI",
7: "VII",
8: "VIII",
9: "IX",
10: "X",
20: "XX",
30: "XXX",
40: "XL",
50: "L",
60: "LX",
70: "LXX",
80: "LXXX",
90: "XC",
100: "C",
200: "CC",
300: "CCC",
400: "CD",
500: "D",
600: "DC",
700: "DCC",
800: "DCCC",
900: "CM",
1000: "M",
2000: "MM",
3000: "MMM"
};
num = num.toString().split("");

if (num.length == 4) {
    num[0] += "000";
    num[1] += "00";
    num[2] += "0";
} else if (num.length == 3) {
    num[0] += "00";
    num[1] += "0";
} else if (num.length == 2) {
    num[0] += "0";
}

function convert(n) {
    return rom[n];
}

function testUndefined(e) {
    if (e != "0" && e != "00" && e != "000") return true;
}

num = num.filter(testUndefined).map(convert).join("");
console.log(num);
return num;

}

convertToRoman(36);

try again :)
function convertToRoman(num) {
    var rom = {
        1: "I",
        2: "II",
        3: "III",
        4: "IV",
        5: "V",
        6: "VI",
        7: "VII",
        8: "VIII",
        9: "IX",
        10: "X",
        20: "XX",
        30: "XXX",
        40: "XL",
        50: "L",
        60: "LX",
        70: "LXX",
        80: "LXXX",
        90: "XC",
        100: "C",
        200: "CC",
        300: "CCC",
        400: "CD",
        500: "D",
        600: "DC",
        700: "DCC",
        800: "DCCC",
        900: "CM",
        1000: "M",
        2000: "MM",
        3000: "MMM"
    };
    num = num.toString().split("");

    if (num.length == 4) {
        num[0] += "000";
        num[1] += "00";
        num[2] += "0";
    } else if (num.length == 3) {
        num[0] += "00";
        num[1] += "0";
    } else if (num.length == 2) {
        num[0] += "0";
    }

    function convert(n) {
        return rom[n];
    }

    function testUndefined(e) {
        if (e != "0" && e != "00" && e != "000") return true;
    }

    num = num.filter(testUndefined).map(convert).join("");
    console.log(num);
    return num;
}

convertToRoman(36);
Loren Baca
@vbroskas
Apr 20 2016 03:40
can anyone give me some suggestions on a basic jquery hover event to show text
if I have a div element with some text already in it, on hover I would like for the original text to vanish and have it show the new text. Then when you hover off the original text comes back
it's getting rid of the original text that is tripping me up
I can hover/show/hide new text alright, but juggling two elements of text is tripping me up
Kelvin-penang
@Kelvin-penang
Apr 20 2016 03:42
//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

if (contacts.hasOwnProperty(firstName)) return contacts[prop];
  else return "No such contact";
  if (prop !==contacts.lastName || contacts.number || contacts.likes || contacts.firstName){
    return "No Such Property";}
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Harry", "lastName");
Can anybody help? :)

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

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

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

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

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

Chris Lacaille
@ChrisL108
Apr 20 2016 03:49
function reverseString(str) {

  var newStr = str.split("");
  newStr.reverse();
  newStr.join();

  console.log(newStr.toString());
  return newStr.toString();
}
Trying to figure out what I'm missing here because the output looks fine to me?
I have tried .join("") as well
It is something to do with the way it is being outputted
one error ---- "reverseString("hello") should become "olleh"
Ken Haduch
@khaduch
Apr 20 2016 03:52
@ChrisL108 - quick one - newStr.join(); has the syntax that requires a join character, or it defaults to using a comma. Also, it returns a string - returns a string, so you need to either save the output into a variable, or return it directly.

@Kelvin-penang - I am not able to spend any more time here, but if you scroll up in this chat room, there were several people asking for help on this very problem.

Basically, contacts is an array of objects, so you want to be using a loop of some type to look through the contacts array and access each object. If you use a for loop with a loop control variable of i, then contacts[i] will refer to each object in the array. You check to see if the firstName (function arg variable) matches contacts[i].firstName, etc.

I hope that helps. Scroll up and you'll find lots of discussion about this one... good luck!

Kelvin-penang
@Kelvin-penang
Apr 20 2016 03:58
@khaduch thanks. Always lucky to meet you
CamperBot
@camperbot
Apr 20 2016 03:58
kelvin-penang sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star: 974 | @khaduch | http://www.freecodecamp.com/khaduch
Doug
@Spazcool
Apr 20 2016 04:31
Hey everyone, I'm currently going through the Basic Algorithm Scripting and I have noticed a continuing inability of mine to first understand and second use for loops. I get the basic idea of them but, these challenges have me iterating through individual elements of an array and I quickly get lost. Anyone have any suggestions for places to look for an overview of this?
Najma Aden
@najma103
Apr 20 2016 04:35
Hi, Everyone, I am doing the javascript simple exercises and i am sure my syntax is correct but it doesn't seem to be accepting it

// Setup
var lastNameLength = 0;
var lastName = "Lovelace";

// Only change code below this line.

lastNameLength = lastName.lenght;

Ankit Padia
@InsaneSkull
Apr 20 2016 04:36
@najma103 misspelled length.
V Arun Kumar
@arunvkumr
Apr 20 2016 04:36
@najma103 you misspelled length
Najma Aden
@najma103
Apr 20 2016 04:37
Thank you - i was looking at this for the last 5 minutes and kept going back to the length but somehow DID NOT see that
Thank you
Ankit Padia
@InsaneSkull
Apr 20 2016 04:37
@najma103 :thumbsup:
BeAtheistItsFun
@BeAtheistItsFun
Apr 20 2016 04:49
hello everyone im on wordblanks and it is just not making any sense to me
Najma Aden
@najma103
Apr 20 2016 04:50
cool i am working on that now too - i was just sratching my head ;)
BeAtheistItsFun
@BeAtheistItsFun
Apr 20 2016 04:51
any words of advice?
V Arun Kumar
@arunvkumr
Apr 20 2016 04:52
wiki word
CamperBot
@camperbot
Apr 20 2016 04:52
no wiki entry for: wordblanks
V Arun Kumar
@arunvkumr
Apr 20 2016 04:52
wiki word
CamperBot
@camperbot
Apr 20 2016 04:52

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

Explanation:

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

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

Najma Aden
@najma103
Apr 20 2016 04:52
result = myNoun + "," + myAdjective + "," + myVerb + "," + myAdverb;
// Your code above this line
return result;
V Arun Kumar
@arunvkumr
Apr 20 2016 04:52
find word
V Arun Kumar
@arunvkumr
Apr 20 2016 04:52
wiki blanks
CamperBot
@camperbot
Apr 20 2016 04:52

:point_right: checkpoint word blanks [wiki]

Details

We will now use our knowledge of strings to build a "Mad Libs" style word game we're calling "Word Blanks". You will create an (optionally humorous) "Fill in the Blanks" style sentence.

:pencil: read more about checkpoint word blanks on the FCC Wiki

Najma Aden
@najma103
Apr 20 2016 04:55
@BeAtheistItsFun did you see that
V Arun Kumar
@arunvkumr
Apr 20 2016 04:55
@BeAtheistItsFun you are given four words which are passed to the function, using those words you have to make any sentence, the order of the words passed should be same in the sentence. and combine all the words using the +(concatenation).
also think of the space between each words.. :smile:
BeAtheistItsFun
@BeAtheistItsFun
Apr 20 2016 04:57
thanks guys
friesenet21
@friesenet21
Apr 20 2016 04:58

for Golf Code it won't return "Birdy" and "Hole-inOne!" ```function golfScore(par, strokes) {
// Only change code below this line
if (strokes >= par + 3) {
return "Go Home!";
} else if (strokes == par + 2) {
return "Double Bogey";
} else if (strokes == par + 1) {
return "Bogey";
} else if (strokes == par) {
return "Par";
} else if (strokes == par - 1) {//???
return "Birdy";
} else if (strokes <= par - 2) {
return "Eagle";
} else if (strokes == 1) {//???
return "Hole-in-one!";
}// Only change code above this line
}

// Change these values to test
golfScore(5, 5);
```

V Arun Kumar
@arunvkumr
Apr 20 2016 05:00
@BeAtheistItsFun @najma103 you can also add your own words between the words given by the function. Make some cool funny statements. :wink:
Najma Aden
@najma103
Apr 20 2016 05:00
i would say use === whenever you are doing actual calculations that could be your issue but i am not there yet so not sure
thanks @arunkumrv how do i go back to that lesson to give it a second go
CamperBot
@camperbot
Apr 20 2016 05:01
najma103 sends brownie points to @arunkumrv :sparkles: :thumbsup: :sparkles:
:star: 481 | @arunkumrv | http://www.freecodecamp.com/arunkumrv
BeAtheistItsFun
@BeAtheistItsFun
Apr 20 2016 05:02
@najma103 use the map
Najma Aden
@najma103
Apr 20 2016 05:09
can't think of clever phrasings but here it goes

result = "my " + myNoun + "," + "is " + myAdjective + "," + "but he can " + myVerb + "," + myAdverb;
// Your code above this line
return result;
}

// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");

Dan
@Ouric
Apr 20 2016 05:12

can somebody help explain this example to me?

var arr = [
[1,2,3],
[4,5,6],
[7,8,9],
[[10,11,12], 13, 14]
];
arr[0]; // equals [1,2,3]
arr[1][2]; // equals 6
arr[3]0; // equals 11

I understand that [0] = [1,2,3] but what is defined as 1 and [2] to = 6?

Najma Aden
@najma103
Apr 20 2016 05:13
first number is the row and second number is the column
Dan
@Ouric
Apr 20 2016 05:14
ahhh, thank you
Najma Aden
@najma103
Apr 20 2016 05:14
so that would be row 1 and column 2 and keep in mind is it's zero index based
Markus Kiili
@Masd925
Apr 20 2016 05:14
@Ouric arr[ 1 ] is [4,5,6] so arr[ 1 ][ 2 ] is 6.
Dan
@Ouric
Apr 20 2016 05:15
yeah I didnt realize that the second number was inside the row
Frank XC
@tenkdayz
Apr 20 2016 05:20
@Ouric the 2nd index of array 1 is 6
Jesus Vega
@ParagonChuy
Apr 20 2016 05:23
help Make a Person
CamperBot
@camperbot
Apr 20 2016 05:23

:point_right: algorithm make a person [wiki]

Explanation:

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

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

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

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

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

Deepak Yadav
@ydeepk
Apr 20 2016 05:26
For the "Confirm End Challange" Tell me this: Is following instruction is wrong or not? confirmEnding("He has to give me a new name", "me") should return true.
DJ
@qualitymanifest
Apr 20 2016 05:27
name
Markus Kiili
@Masd925
Apr 20 2016 05:31
@ydeepk "He has to give me a new name" ends in "me", so true.
Deepak Yadav
@ydeepk
Apr 20 2016 05:32
@Masd925 oh yeah, miss that. Attention is very much needed.

@Masd925 please check this code, I'm not getting this work for one instruction while it works for rest of challange instruction.

function confirmEnd(str,target) {

// check if its a sentence
if(str.match(/\s/)) {
str = str.toLowerCase().split(/\s/).reverse();
}
// execute for single word.
else {
str = str.substr(str.length - 1);
}

if(str[0] === target) {
return true;
} else {
return false;
}

}

confirmEnding("Bastian", "n");

This is the instruction: confirmEnding("He has to give me a new name", "me") should return true.

Deepak Yadav
@ydeepk
Apr 20 2016 05:37
please check this code, I'm not getting this work for one instruction while it works for rest of challange instruction.
function confirmEnd(str,target) {
// check if its a sentence
if(str.match(/\s/)) {
str = str.toLowerCase().split(/\s/).reverse();
}
// execute for single word.
else {
str = str.substr(str.length - 1);
}
if(str[0] === target) {
return true;
} else {
return false;
}
}
confirmEnding("Bastian", "n");
This is the instruction: confirmEnding("He has to give me a new name", "me") should return true.
Frank XC
@tenkdayz
Apr 20 2016 05:46
@ydeepk why are you checking for \s ?
Deepak Yadav
@ydeepk
Apr 20 2016 05:47
@tenkdayz for white space in sentence that helps to identify if a given string is a sentence or just a wrod
Frank XC
@tenkdayz
Apr 20 2016 05:50
@ydeepk you only have to check if the sentence ends with target correct
?
Son Dang
@viiiprock
Apr 20 2016 05:50
it's only need to check if last character(s) of str === target character(s).
Abdul-Samii Ajala Olalekan
@jalasem
Apr 20 2016 05:50

where exactly am i not getting this right?

//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 && contact[i][prop] === prop){
      return contact[i][prop];
    } else if(contacts[i][firstName] !== firstName){
      return "No such contact";
    } else if(contact[i][prop] !== prop){
      return "No such property";
    }
  }
// Only change code above this line
}

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

these are the test result:

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

and here is the question
`
We have an array of objects representing different people in our contacts lists.

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

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

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

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

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

`

anybody here to help me out pls
Frank XC
@tenkdayz
Apr 20 2016 05:54
@jalasem
have you tried using dot notation?
Deepak Yadav
@ydeepk
Apr 20 2016 05:55
@viiiprock so any suggestions?
Hector Garcia
@augmt
Apr 20 2016 05:55
@jalasem make sure you use contacts and not contact
Abdul-Samii Ajala Olalekan
@jalasem
Apr 20 2016 05:55
where
kirbyedy
@kirbyedy
Apr 20 2016 05:56
@jalasem half of the time you use contact instead of contactS
Abdul-Samii Ajala Olalekan
@jalasem
Apr 20 2016 05:57
I have done that and is still not right yet
@kirbyedy I have corrected all contact to contacts but it is still not working
Casey Heath
@ExhibitArts
Apr 20 2016 06:00
CamperBot
@camperbot
Apr 20 2016 06:00
no wiki entry for: design chat room for anyone in need of designers - httpsgitterimexhibitartshelpdesignutm_sourceshare-linkutm_mediumlinkutm_campaignshare-link
Hector Garcia
@augmt
Apr 20 2016 06:00
@jalasem you also want to check if firstName matches contacts[i].firstName
using contacts[i][firstName] won't work because the key is the string "firstName"
and you want to check if contacts[i] contains prop, not if contacts[i][prop] is equivalent to prop
Abdul-Samii Ajala Olalekan
@jalasem
Apr 20 2016 06:03

after correcting that am left with this error:

"Kristian", "lastName" should return "Vos"
"Sherlock", "likes" should return ["Intriguing Cases", "Violin"]
"Harry","likes" should return an array

Hector Garcia
@augmt
Apr 20 2016 06:05
@jalasem the final thing is you want to make sure you go through the entire array before concluding that the contact doesn't exist
Casey Heath
@ExhibitArts
Apr 20 2016 06:08
New chatroom! Join if you want tips or opinons on your personal project. - https://gitter.im/ExhibitArts/TipsOpinions?utm_source=share-link&utm_medium=link&utm_campaign=share-link
Rada
@Radascript
Apr 20 2016 06:16
hey guys, is there a function for parsing a string expression within javascript/jquery, or should I write a separate function for it? Like I have a string "332.5*2+554" and I want to set a variable to the result of expression.
Rada
@Radascript
Apr 20 2016 06:17
@Zerazera thanks Zera!
CamperBot
@camperbot
Apr 20 2016 06:17
radascript sends brownie points to @zerazera :sparkles: :thumbsup: :sparkles:
:star: 381 | @zerazera | http://www.freecodecamp.com/zerazera
Samuel Cupidon
@Zerazera
Apr 20 2016 06:17
Be careful with eval, though -- it has security issues.
Hector Garcia
@augmt
Apr 20 2016 06:18
evil
Rada
@Radascript
Apr 20 2016 06:18
@Zerazera oh it's for the calculator app I think I'll be safe :D
96street
@96street
Apr 20 2016 06:19
Can someone help me? I'm trying to make the text continuously slide across infinately. I've got this so far (it sucks) http://codepen.io/anon/pen/pyKpvW
Markus Kiili
@Masd925
Apr 20 2016 06:19
@Radascript There are JS libraries for parsing such math equations.
Rada
@Radascript
Apr 20 2016 06:22
@Masd925 eval() should suffice for the basic calculator zipline right?
Markus Kiili
@Masd925
Apr 20 2016 06:25
@Radascript Could you avoid parsing the equation from a string?
Seniority
@Seniority
Apr 20 2016 06:31
Im not really understanding the instructions for Record Collection lol..
LostInTransistors
@marcosignorello
Apr 20 2016 06:32
var test = "this is a markdown test";
cool
Markus Kiili
@Masd925
Apr 20 2016 06:34
@Seniority Try to figure out how to access a record with specific id. You have to make three tests for value and prop, and then do different things to collection.
Pete
@petegarvin1
Apr 20 2016 06:40
Anyone needing some algo practice I can't recommend codewars highly enough www.codewars.com/r/yfzYFQ
Deepak Yadav
@ydeepk
Apr 20 2016 06:54

this code not working why:

for instruction as below :

  1. ) confirmEnding("He has to give me a new name", "name") should return true.

  2. ) confirmEnding("He has to give me a new name", "me") should return true.
    function confirmEnd(str,target) {
    if(str.substr(str.length - target.length)===target) {
    return true;
    } else {
    return false;
    }
    }

confirmEnding("Bastian", "n");

provided by github for free code camp review solution :

Aleksej
@tip14
Apr 20 2016 06:58
var j=15616;
var k=5;
fs
Deepak Yadav
@ydeepk
Apr 20 2016 06:59
@camperbot help
@camperbot Algorithm help!
@camperbot do you exist?
rphares
@rphares
Apr 20 2016 07:00
help confirm the ending
CamperBot
@camperbot
Apr 20 2016 07:00

:point_right: algorithm confirm the ending [wiki]

Explanation:

The function is a whole Boolean operation. You need to return true if the first argument ends with the second argument. This means that for the problem script, it should return true for the confirmEnding('Bastian', 'n'); case.

:pencil: read more about algorithm confirm the ending on the FCC Wiki

rphares
@rphares
Apr 20 2016 07:01
@ydeepk :point_up:
(to use cbot, type help or explain or wiki first, then the name of the problem :blush: )
Deepak Yadav
@ydeepk
Apr 20 2016 07:02
@rphares :-)
Markus Kiili
@Masd925
Apr 20 2016 07:02
@ydeepk It is working. Do you have correct function name?
Deepak Yadav
@ydeepk
Apr 20 2016 07:02
@Masd925 you can see the above code.
Aleksej
@tip14
Apr 20 2016 07:03
hello! my array sun has a null values, but i want to replace it to spaces. how can i do that?
function rot13(str) { 
  var input = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(/\s*/);
  var output = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm".split(/\s*/);
  var sp = str.split(/\s*/);
  var unc =[];
  var sun=[];
  for (i=0;i<str.length;i++){
    unc.push(input.indexOf(str[i]));
    sun.push(output[unc[i]]);
  }

  return sun;



}


// Change the inputs below to test
rot13("SERR PBQR PNZC");
Markus Kiili
@Masd925
Apr 20 2016 07:03
@ydeepk It should be confirmEnding, not confirmEnd
Son Dang
@viiiprock
Apr 20 2016 07:04
function confirmEnd(str,target) {
if(str.substr( target.length)===target) {
return true;
} else {
return false;
}
}
opps
function confirmEnd(str,target) {
if(str.substr( - target.length)===target) {
return true;
} else {
return false;
}
}
Markus Kiili
@Masd925
Apr 20 2016 07:06
@tip14 .map() method is good for operating on array elements like that.
Deepak Yadav
@ydeepk
Apr 20 2016 07:06
@Masd925 thnk 4 help pal.
CamperBot
@camperbot
Apr 20 2016 07:06
ydeepk sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1384 | @masd925 | http://www.freecodecamp.com/masd925
Aleksej
@tip14
Apr 20 2016 07:09
@Masd925 thank you
CamperBot
@camperbot
Apr 20 2016 07:09
tip14 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1385 | @masd925 | http://www.freecodecamp.com/masd925
Deepak Yadav
@ydeepk
Apr 20 2016 07:09
:thumbsup:
@camperbot help earning points :thumbsup:
Markus Kiili
@Masd925
Apr 20 2016 07:10
@ydeepk It also works with just:
function confirmEnding(str, target) {
  return str.substr(-target.length)===target;
}
Aleksej
@tip14
Apr 20 2016 07:13
@Masd925 i don't understand, how can i use map method for my case? can you explain?
Deepak Yadav
@ydeepk
Apr 20 2016 07:14
@Masd925 i already worked it out exactly the same. only problem was i wrote function name different.
Son Dang
@viiiprock
Apr 20 2016 07:15
function confirmEnding(str, target) {
  return str.substr(-target.length)===target;
}
great @Masd925
Markus Kiili
@Masd925
Apr 20 2016 07:16
@tip14 If you need to replace null values with spaces " ", you can do:
["c","a",null,"r"].map(function(elem){
    if (elem===null) return " ";
    return elem;
});                // returns [ 'c', 'a', ' ', 'r' ]
Aleksej
@tip14
Apr 20 2016 07:20
@Masd925 thank you!
CamperBot
@camperbot
Apr 20 2016 07:20
tip14 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: tip14 already gave masd925 points
Rawan44
@Rawan44
Apr 20 2016 07:24
Hi
function titleCase(str) {
  str = str.toLowerCase();
  var a = str.split(" ");
  var u = [];
  for (i=0; i<a.length; i++) {
    u = a[i].split("");
    u[0].toUpperCase();
    a[i] = u.join("");
  }
  str = a.join(" ");
  return str;
}

titleCase("I'm a little tea pot");
there is an error i can't find
am i doing something wrong?
Markus Kiili
@Masd925
Apr 20 2016 07:29
@Rawan44 u[0].toUpperCase(); returns a new string. You are not assigning it anywhere. Strings are immutable.
@Rawan44 It is easier to use string operations instead of splitting the words into character arrays.
Rawan44
@Rawan44
Apr 20 2016 07:30
oh thank
thanks
Abdul-Samii Ajala Olalekan
@jalasem
Apr 20 2016 07:35

//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].prop === prop){
return contacts[i][prop];
} else if(contacts[i].firstName !== firstName){
return "No such contact";
} else if(contacts[i].prop !== prop){
return "No such property";
}
}
// Only change code above this line
}

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

//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].prop === prop){
      return contacts[i][prop];
    } else if(contacts[i].firstName !== firstName){
      return "No such contact";
    } else if(contacts[i].prop !== prop){
      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": passed
"Akira", "address" should return "No such property" : passed
Markus Kiili
@Masd925
Apr 20 2016 07:38
@jalasem The dot notation only works if the property key string is a valid JS identifier (for example "12" and "lives left" are not) and you write the key after the dot: var cat={clothes:"pants", "lives left":3}; cat.clothes; //returns "pants". Bracket notation works with keys that can be arbitrary strings cat["lives left"]; //returns 3, variables var key="clothes"; cat[key]; //returns "pants", or expressions cat["lives"+" "+"left"]; //returns 3.
So .prop doesn't work there.
forgoroe
@forgoroe
Apr 20 2016 07:38
@jalasem I am also doing that!
Markus Kiili
@Masd925
Apr 20 2016 07:39
@jalasem You should also return no such contact only after checking all the contacts.
forgoroe
@forgoroe
Apr 20 2016 07:40
yeah
kirbyedy
@kirbyedy
Apr 20 2016 07:42
@Masd925 I read this small text of yours like 100 times, do you have it somewhere saved so you are always copy/pasting it ? :D
Markus Kiili
@Masd925
Apr 20 2016 07:42
@kirbyedy Yes, after explaining it for the 20th time I stored it.
kirbyedy
@kirbyedy
Apr 20 2016 07:42
hahaha I thought so :)
forgoroe
@forgoroe
Apr 20 2016 07:45
I am doing the same exercise as @jalasem
Having trouble
Markus Kiili
@Masd925
Apr 20 2016 07:46
@forgoroe Simplest structure is to do two nested if clauses inside contact loop. First for the firstname check and second for property existence. No elses needed then, just the returns.
forgoroe
@forgoroe
Apr 20 2016 07:46
function lookUpProfile(firstName, prop){
// Only change code below this line
var result;
var contact = 0;
  while (contact < contacts.length){
    if(contacts[contact].hasOwnProperty(prop)){
      if (contacts[contact][prop][firstName] === firstName){
          result = contacts[contact][prop][firstName];
        contact = contacts.length;
        } else if (!contacts[contact][prop].hasOwnProperty(firstName)){
          result = "No such contact";
          contact++;
        }
    } else if(!contacts[contact].hasOwnProperty(prop)){
    result = "No such property";
      contact++;
  }   
  }

  return result;
// Only change code above this line
}
Abdul-Samii Ajala Olalekan
@jalasem
Apr 20 2016 07:47
@forgoroe I have been stuck here for four hours
Markus Kiili
@Masd925
Apr 20 2016 07:49
@forgoroe A loop, two if's, and the returns is enough.
forgoroe
@forgoroe
Apr 20 2016 07:50
maybe I used redundant else ifs
but that's not the problem... The problem is that it doesn't seem to ever store the first result
I mean it only reads false and goes to the first or second else if
Rada
@Radascript
Apr 20 2016 07:55
hey guys, so I heard imgur is not good for using with codepen, what do you recommend for use instead?
Javier
@sh1g
Apr 20 2016 07:56
@Radascript I use http://cloudinary.com/
Rada
@Radascript
Apr 20 2016 07:57
@sh1g thanks!
CamperBot
@camperbot
Apr 20 2016 07:57
radascript sends brownie points to @sh1g :sparkles: :thumbsup: :sparkles:
:star: 296 | @sh1g | http://www.freecodecamp.com/sh1g
Abdul-Samii Ajala Olalekan
@jalasem
Apr 20 2016 08:04

pls help

//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].prop === prop){
      return [firstName , contacts[i].prop];
    } else if(contacts[i].firstName !== firstName){
      return "No such contact";
    } else if(contacts[i].prop !== prop){
      return "No such property";
    }
  }
// Only change code above this line
}

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

here is the instruction:
We have an array of objects representing different people in our contacts lists.

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

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

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

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

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

and the result:

these gave error
"Kristian", "lastName" should return "Vos"
"Sherlock", "likes" should return ["Intriguing Cases", "Violin"]
"Harry","likes" should return an array
and these went through
"Bob", "number" should return "No such contact"
"Akira", "address" should return "No such property"

please just tell which code works and why , I have had enough tips pls

forgoroe
@forgoroe
Apr 20 2016 08:05
Yeah, we're dying lol
:D
Sander Visser
@sanderfish
Apr 20 2016 08:05

@khaduch I think indeed an addition like that would help loads in at least understanding what exactly you're supposed to do in the particular question. I don't know if it will also help in writing the correct code since it's normal, like you said, to need to look back a few times.

Maybe I'm the only one having this problem as I have already done multiple real-world projects and can't stand not knowing what deeper problem I'm trying to solve. It could be that I should indeed try to understand the way the computer thinks in these problems instead of the deeper layer.

Abdul-Samii Ajala Olalekan
@jalasem
Apr 20 2016 08:06
@forgore what have you done? lets help one another
since no one is helping us
forgoroe
@forgoroe
Apr 20 2016 08:06
So far I've only managed to get 2 different positive results
Abdul-Samii Ajala Olalekan
@jalasem
Apr 20 2016 08:07
@forgoroe which one? I got the last two
forgoroe
@forgoroe
Apr 20 2016 08:08
yeah, last two
Abdul-Samii Ajala Olalekan
@jalasem
Apr 20 2016 08:08
@camperbot please help us if you can @forgoroe and I need your help
Luis
@zdrifted
Apr 20 2016 08:10
I can help with that
One sec, let me review it
forgoroe
@forgoroe
Apr 20 2016 08:10
thanks
I don't even have the accent symbol that I need to start typing code. I have to continually copy paste the accents and then copy paste the code
inbal mishory
@inbal-mishory
Apr 20 2016 08:11

Hello good people,
this is my code for the reverseString exercise. anybody know why it's not working?
'''

function reverseString(str) {
var strArray = str.split("");
str = strArray.reverse().join();
return str;
}

reverseString("hello");
'''

thanks in advance.

forgoroe
@forgoroe
Apr 20 2016 08:12
what I can say about your code @jalasem is that you can't use dot notation. You're forced to use [prop][firstname]
cause if you use dotted, that means that you want exactly the property that you're typing and not the one contained in the variable, if that makes sense
Naguib Bouchibi ⚡️
@naguib101
Apr 20 2016 08:13
Hey everyone, someone knows how to make a photo collage thanks to HTML5 canvas / JS ?
Luis
@zdrifted
Apr 20 2016 08:14
@forgoroe Your first if statement, the second condition where you are looking up the property is where I see one issue. Try using the .hasOwnProperty() method instead of dot notation
Javier
@sh1g
Apr 20 2016 08:15
@Rushh I agree. If I remember correctly for this checkpoint, you are supposed to match the firstname and then print out the likes right?
forgoroe
@forgoroe
Apr 20 2016 08:16
erm
I am using the HasOwnProperty
?
or are you talking about the second if? The nested one?
Luis
@zdrifted
Apr 20 2016 08:17
@javier That's right, print out the values/array of the likes property
@forgoroejs if(contacts[i].firstName === firstName && contacts[i].prop === prop)
Marc Schöni
@marcschoeni
Apr 20 2016 08:17
any Body can Help me? why thats fail.
function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line

 switch (val) {
  case 1:
  answer ("alpha");
  break;

  case 2:
  answer("beta");
  break;

  case 3:
  answer ("gamma");
  break;

  case 4:
  answer ("delta");
  break;
 }
 // Only change code above this line  
  return answer;  
}

// Change this value to test
caseInSwitch(1);
forgoroe
@forgoroe
Apr 20 2016 08:17
assign answer with =
and no brackets
Marc Schöni
@marcschoeni
Apr 20 2016 08:19
oh realy nice i think that Challange solve i never xD thanks @forgoroe
CamperBot
@camperbot
Apr 20 2016 08:19
marcschoeni sends brownie points to @forgoroe :sparkles: :thumbsup: :sparkles:
:star: 240 | @forgoroe | http://www.freecodecamp.com/forgoroe
forgoroe
@forgoroe
Apr 20 2016 08:20
This message was deleted
Luis
@zdrifted
Apr 20 2016 08:20
@forgoroe Actually, I think I'm looking at @jalasem code
forgoroe
@forgoroe
Apr 20 2016 08:21
help formatting code
CamperBot
@camperbot
Apr 20 2016 08:21
no wiki entry for: formatting code
forgoroe
@forgoroe
Apr 20 2016 08:21
help code formatting
CamperBot
@camperbot
Apr 20 2016 08:21

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

forgoroe
@forgoroe
Apr 20 2016 08:21
function lookUpProfile(firstName, prop){
// Only change code below this line
var result;
var contact = 0;
  while (contact < contacts.length){
    if(contacts[contact].hasOwnProperty(prop)){
      if (contacts[contact][prop][firstName]){
          result = contacts[contact][prop][firstName];
        contact = contacts.length;
        } else if (!contacts[contact][prop].hasOwnProperty(firstName)){
          result = "No such contact";
          contact++;
        }
    } else if(!contacts[contact].hasOwnProperty(prop)){
    result = "No such property";
      contact++;
  }   
  }

  return result;

// Only change code above this line
}
elmo
@goelmo
Apr 20 2016 08:22
what is ajax?
Javier
@sh1g
Apr 20 2016 08:24
@jalasem your code is almost correct
forgoroe
@forgoroe
Apr 20 2016 08:24
Javier, buddy what's wrong with mine
lol
Javier
@sh1g
Apr 20 2016 08:24
@forgoroe one at a time xD I'll look at yours after I explain it to him
Luis
@zdrifted
Apr 20 2016 08:25
@forgoroe Maybe try a for loop and two if statements? One if statement if both the firstname and property is found. One if firstname is found but no property (no such property). Then if neither, print out "no such contact"
forgoroe
@forgoroe
Apr 20 2016 08:25
I've tried with a for loop but I want to return the result as soon as it's found without using return inside the for loop
Abdul-Samii Ajala Olalekan
@jalasem
Apr 20 2016 08:26
@sh1g so what remain please bail me out please
forgoroe
@forgoroe
Apr 20 2016 08:26
so I have the while do the loop and if it's found I have it exit the loop by setting the counter to the contacts length
Javier
@sh1g
Apr 20 2016 08:26
@jalasem On your first if statement You dont need the second part. That part will never return true since likes will never equal the likes array.
and you need to return contacts[i][prop] not contacts[i].prop. Remove the [ from the begging as well
Abdul-Samii Ajala Olalekan
@jalasem
Apr 20 2016 08:27
still doesnt work @sh1g
Javier
@sh1g
Apr 20 2016 08:27
for (var i = 0; i < contacts.length; i++) {
    if (contacts[i].firstName === firstName) {
      return firstName, contacts[i][prop];
does that make sense?
Abdul-Samii Ajala Olalekan
@jalasem
Apr 20 2016 08:29
@sh1g let me try
forgoroe
@forgoroe
Apr 20 2016 08:29
wait... So firstName as a variable is always the property firstName?
no... It's the value
maybe I understand
Seniority
@Seniority
Apr 20 2016 08:31
im doing the Profile Lookip module also haha
Kevin Galang
@kgalang
Apr 20 2016 08:33
function titleCase(str) { //strategy: lower case, split words into array, then create loop to make every first letter of each indexed string uppercase
  var lowerCase = str.toLowerCase();
  var splitString = lowerCase.split(" "); 
   for (var i = 0; i < splitString.length; i++) {
    return splitString[i].charAt(0).toUpperCase() + splitString[i].slice(1);

   }

}

titleCase("I'm a little tea pot");
Can someone help me on why my output is not looping? I am still getting just "I'm" as the output
Javier
@sh1g
Apr 20 2016 08:34
@forgoroe I'm looking at yours now. Trying to see where the error is
forgoroe
@forgoroe
Apr 20 2016 08:34
I think I'm making progress
but yeah, please
Do Ngoc Duc
@dongocdc70
Apr 20 2016 08:35
@kgalang because function only returns once
Luis
@zdrifted
Apr 20 2016 08:37
@jalasem I used your approach so I'll help you on it. The contacts[i].prop doesn't work because you're using dot notation. It's actually looking for "prop" instead of the variable prop. That's why contacts[i].firstName(string) === firstName (variable) works.
Abdul-Samii Ajala Olalekan
@jalasem
Apr 20 2016 08:37
@Seniority so do you get it?
Seniority
@Seniority
Apr 20 2016 08:38
@jalasem not yet. ive been staring at my screen for like 15 minutes trying to see how to approach it
@jalasem i'm going to start trying stuff now. i'll let you know how it goes lol
Javier
@sh1g
Apr 20 2016 08:39
@jalasem did my explanation not work out?
Luis
@zdrifted
Apr 20 2016 08:39
This message was deleted
Abdul-Samii Ajala Olalekan
@jalasem
Apr 20 2016 08:39
@sh1g still dont get it sir
Kevin Galang
@kgalang
Apr 20 2016 08:42
@dongocdc70 So it doesn't loop? or it just returns after the first loop?
John Dezzer
@johndezzer
Apr 20 2016 08:43
Guys need help http://prnt.sc/aui9dw
Javier
@sh1g
Apr 20 2016 08:45
@jalasem can you post your full code again please?
Luis
@zdrifted
Apr 20 2016 08:45
@jalasem I'm going through your code and adding comments to help explain the parts with issues. Give me a few minutes and I'll post it soon
Javier
@sh1g
Apr 20 2016 08:45
ah it seems @Rushh is on it xD
Romain Mondon-Cancel
@skasch
Apr 20 2016 08:53
@johndezzer You do not have to shift again myArray
at this point, myArray = [ 'dog', 3 ], which is not what is expected
Luis
@zdrifted
Apr 20 2016 08:53
It's one thing to solve it but to actually explain it is tough. It's good exercise though to help master the basics
Javier
@sh1g
Apr 20 2016 09:01
oh wow...it's 2am...
Do Ngoc Duc
@dongocdc70
Apr 20 2016 09:01

@kgalang it stops at the first step of the iteration. what you can do is:

var result = "";
for (var i = 0; i < splitString.length; i++) {
result += splitString[i].charAt(0).toUpperCase() + splitString[i].slice(1);

}
return result;

forgoroe
@forgoroe
Apr 20 2016 09:01
I am closer to the solution @Rushh and @sh1g thanks
CamperBot
@camperbot
Apr 20 2016 09:01
forgoroe sends brownie points to @rushh and @sh1g :sparkles: :thumbsup: :sparkles:
:star: 233 | @rushh | http://www.freecodecamp.com/rushh
:star: 297 | @sh1g | http://www.freecodecamp.com/sh1g
Javier
@sh1g
Apr 20 2016 09:01
@forgoroe that's good to hear!
Markus Kiili
@Masd925
Apr 20 2016 09:02
@elmansouri Try returning undefined from the if block.
ayoub el-mansouri
@elmansouri
Apr 20 2016 09:03
i try markus
if(a<0 || b<0){
return 'undefined'
}
bu it doesn't work
Markus Kiili
@Masd925
Apr 20 2016 09:05
@elmansouri undefined is a special value in JS. No quotes.
Seniority
@Seniority
Apr 20 2016 09:05
@jalasem im still stuck on it lol..
can anyone help with Profile Lookup?
Markus Kiili
@Masd925
Apr 20 2016 09:06
@Seniority Sure.
Luis
@zdrifted
Apr 20 2016 09:06
@jalasem I messaged you the commentary on your code
ayoub el-mansouri
@elmansouri
Apr 20 2016 09:06
how can i use it ??
Luis
@zdrifted
Apr 20 2016 09:07
@forgoroe Wish I could help you more, but I used a different approach
Markus Kiili
@Masd925
Apr 20 2016 09:07
@elmansouri return undefined;
ayoub el-mansouri
@elmansouri
Apr 20 2016 09:08
now it work, thank's Markus, ur the best
Mooli
@Mooli88
Apr 20 2016 09:09
question. when should i use while loop instead of for loop ?
Brendan Kinahan
@BKinahan
Apr 20 2016 09:09
@Mooli88 when it's not something easily countable, I suppose
Markus Kiili
@Masd925
Apr 20 2016 09:10
@Mooli88 For loop is good for iterating incremented numbers. For anything more complex, while is better (because the logic is simpler to see with while loop).
Kevin Galang
@kgalang
Apr 20 2016 09:13
@dongocdc70 Thank you! I am on track now but need to re add some spaces
CamperBot
@camperbot
Apr 20 2016 09:13
kgalang sends brownie points to @dongocdc70 :sparkles: :thumbsup: :sparkles:
:star: 202 | @dongocdc70 | http://www.freecodecamp.com/dongocdc70
Mooli
@Mooli88
Apr 20 2016 09:13
@Masd925 @BKinahan thanks . i can't think of such thing but i guess i'll understand it better once i'll see it.
CamperBot
@camperbot
Apr 20 2016 09:13
mooli88 sends brownie points to @masd925 and @bkinahan :sparkles: :thumbsup: :sparkles:
:star: 1386 | @masd925 | http://www.freecodecamp.com/masd925
Kevin Galang
@kgalang
Apr 20 2016 09:13
I am getting SomethingLikeThisNow
CamperBot
@camperbot
Apr 20 2016 09:13
:star: 1346 | @bkinahan | http://www.freecodecamp.com/bkinahan
Brendan Kinahan
@BKinahan
Apr 20 2016 09:14
@kgalang sounds like you need some spaces. Are you using .join('')?
Do Ngoc Duc
@dongocdc70
Apr 20 2016 09:15
@BKinahan no he's using string concatenation
forgoroe
@forgoroe
Apr 20 2016 09:17
I'm stuck again but I'm closer to the solution. Apparently there is a problem on getting in the else statement that should give me "No such property"
help code formatting
CamperBot
@camperbot
Apr 20 2016 09:17

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

Brendan Kinahan
@BKinahan
Apr 20 2016 09:17
@dongocdc70 oh, yeah, then the code you provided above does not account for spaces :P
@forgoroe are you using hasOwnProperty()?
forgoroe
@forgoroe
Apr 20 2016 09:17
//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
var result;
var contact = 0;

while (contact < contacts.length){
  if (contacts[contact].firstName === firstName){
    if(contacts[contact].hasOwnProperty(prop)){
      result = contacts[contact][prop];
      contact = contacts.length;
      } else {
    result = "No such property";
   }
  } else {
    result = "No such contact";
  }
  contact++;
} 
return result;
// Only change code above this line
}
Abdul-Samii Ajala Olalekan
@jalasem
Apr 20 2016 09:19
thanks aot to you all. It worked @Rushh @javiermxmd
CamperBot
@camperbot
Apr 20 2016 09:19
jalasem sends brownie points to @rushh and @javiermxmd :sparkles: :thumbsup: :sparkles:
:star: 284 | @javiermxmd | http://www.freecodecamp.com/javiermxmd
:star: 234 | @rushh | http://www.freecodecamp.com/rushh
Do Ngoc Duc
@dongocdc70
Apr 20 2016 09:19
@kgalang follow @BKinahan idea, you can store the results in an array, then use .join(" ")
var result = [];
for (var i = 0; i < splitString.length; i++) {
result.push(splitString[i].charAt(0).toUpperCase() + splitString[i].slice(1));
}
return result.join(" ");
Mooli
@Mooli88
Apr 20 2016 09:19
@forgoroe i think you returning too early
Stephen James
@sjames1958gm
Apr 20 2016 09:19
@forgoroe Are you never returning "no such property"?
forgoroe
@forgoroe
Apr 20 2016 09:20
yes @sjames1958gm
Stephen James
@sjames1958gm
Apr 20 2016 09:20
@forgoroe Once you match on firstName you should end the loop
forgoroe
@forgoroe
Apr 20 2016 09:21
the loop ends cause I give the counter "contact" the value of "contacts.length"
Stephen James
@sjames1958gm
Apr 20 2016 09:21
@forgoroe For both cases of firstname match?
forgoroe
@forgoroe
Apr 20 2016 09:21
oh
so I should add it on the else
mind blown
Minerest
@Minerest
Apr 20 2016 09:22
Hey, what do you do if your code outputs all the right answers, but FCC doesn't let you continue?
Stephen James
@sjames1958gm
Apr 20 2016 09:22
@forgoroe Yes, and you can use break; to exit early from the while loop - it is more explicit
@Minerest Sometimes browser refresh works
forgoroe
@forgoroe
Apr 20 2016 09:22
wow, that solved it. Thanks @sjames1958gm
CamperBot
@camperbot
Apr 20 2016 09:22
forgoroe sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 716 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
forgoroe
@forgoroe
Apr 20 2016 09:23
I don't want to use break. It's UNCLEAN
lol
Minerest
@Minerest
Apr 20 2016 09:23
@sjames1958gm Hey, just tried it, no cigar -_-
Markus Kiili
@Masd925
Apr 20 2016 09:24
@forgoroe Then return when you know the return value, instead of assigning to result.
forgoroe
@forgoroe
Apr 20 2016 09:24
It is done
finally
Stephen James
@sjames1958gm
Apr 20 2016 09:24
@forgoroe :+1:
Minerest
@Minerest
Apr 20 2016 09:25
anyone have any other ideas? Pretty please with a cherry on top
Stephen James
@sjames1958gm
Apr 20 2016 09:26
@Minerest You are getting all check marks on the tests?
Minerest
@Minerest
Apr 20 2016 09:26
nope, but my output matches the checkmarks
Markus Kiili
@Masd925
Apr 20 2016 09:26
@Minerest Post the code please.
Minerest
@Minerest
Apr 20 2016 09:27
var num = [];
function largestOfFour(arr) {
  var largest = 0;
  for(var i = 0; i< arr.length; i++){
    for (var k = 0; k< arr[i].length; k++){
      if(arr[i][k] > largest && arr[i][k+1] != "undefined"){
        largest = arr[i][k];
      }
    }

    num.push(largest);
    largest = 0;
  }

  return num;
}

largestOfFour([[4, 9, 1, 3], [13, 35, 18, 26], [32, 35, 97, 39], [1000000, 1001, 857, 1]]);
Markus Kiili
@Masd925
Apr 20 2016 09:27
@Minerest You cannot use global variables. Screws up tests.
Minerest
@Minerest
Apr 20 2016 09:27
oh
ok thanks
yeah, that did it
@Masd925 thanks
CamperBot
@camperbot
Apr 20 2016 09:28
minerest sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1387 | @masd925 | http://www.freecodecamp.com/masd925
Stephen James
@sjames1958gm
Apr 20 2016 09:28
This message was deleted
@Masd925 :+1:
Markus Kiili
@Masd925
Apr 20 2016 09:29
@sjames1958gm Hi.
Stephen James
@sjames1958gm
Apr 20 2016 09:30
@Masd925 Had to be something like global when it works but doesn't pass.
Markus Kiili
@Masd925
Apr 20 2016 09:30
@sjames1958gm Yes, or wrong function name.
Abdul-Samii Ajala Olalekan
@jalasem
Apr 20 2016 09:36
can anyone explian this better, though it worked but i dont understand
// Example
function ourFunction(ourMin, ourMax) {

  return Math.floor(Math.random() * (ourMax - ourMin + 1)) + ourMin;
}

ourFunction(1, 9);

// Only change code below this line.

function randomRange(myMin, myMax) {

  return Math.floor(Math.random() * (myMax - myMin + 1)) + myMin; // Change this line

}

// Change these values to test your function
var myRandom = randomRange(5, 15);
Stephen James
@sjames1958gm
Apr 20 2016 09:40
@jalasem Math.random() is between 0-1 then multiply by (myMax - myMin + 1) makes the range 0 - size of range - then + myMin make the range myMin - myMax
Seniority
@Seniority
Apr 20 2016 10:02
im still stuck on Profile Lookup
getting so mad
naassi
@naassi
Apr 20 2016 10:03
@Seniority Everyone gets stuck on that one you'll get it
Seniority
@Seniority
Apr 20 2016 10:04
ive been staring at the screen trying to solve this for like 2 hours
naassi
@naassi
Apr 20 2016 10:05
What part are you stuck on ?
Seniority
@Seniority
Apr 20 2016 10:12
Profile Lookup @naassi
none of my solutions have worked
function lookUpProfile(firstName, prop) {
// Only change code below this line

  var result;
  for (i = 0; i < contacts.length; i++) {
    if (firstName === contacts[i].firstName) {
      if (contacts[i].hasOwnProperty(prop)) {
        switch (prop) {
          case "firstName":
            result = contacts[i].firstName;
            break;
          case "lastName":
            result = contacts[i].lastName;
            break;
          case "number":
            result = contacts[i].number;
            break;
          case "likes":
            result = contacts[i].likes;
            break;
        }
      } else {
        result = "No such property";
      }
    } else {
      result = "No such contact";
    }
  }

  return result;
// Only change code above this line
}
@naassi that was my latest one. didnt work
naassi
@naassi
Apr 20 2016 10:14
So your first part is right but you only need to find if they have that prop
Start with looping through the contact list
Then
if(/* contact[x].firstname === firstname*/) {
Do This}
else return 'No such contact'
The next check goes in the do this block, but you only need to check for the value stored in prop
Markus Kiili
@Masd925
Apr 20 2016 10:19
@Seniority You don't need a switch. Just figure out the returns:
function lookUp(firstName, prop){
// Only change code below this line
  for (var i=0; i<contacts.length; i++) {
    if (contact.firstName===firstName) {
      if (contact.hasOwnProperty(prop)) {
        return ???
      }
      return ???
    }
  }
  return ???
// Only change code above this line
}
Seniority
@Seniority
Apr 20 2016 10:19
@naassi how would i do that? isnt that what i did with if (contacts[i].hasOwnProperty(prop)) {
Ankit Panwar
@coderNoob
Apr 20 2016 10:28
I'm working on Simon game and I need help. The computer starts lighting up his boxes before I'm done clicking mine. I set up a variable to stop it from animating the boxes before my clicks are finished. It seems to be working for every click I make instead of a whole bunch of clicks.
http://codepen.io/coderNoob/pen/wGmbqZ?editors=0001
Stephen James
@sjames1958gm
Apr 20 2016 10:40
@Seniority You need to break from your loop when you find your matching firstname - if you set no such contact before the loop then if no match it will still be set.
Ultras05
@Ultras05
Apr 20 2016 10:48

// 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!=="non-blank"&&prop!=="tracks")
{
value=prop;
}
else if (prop=="tracks"&& value!=="non-blank")

return collection;
}

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

Ken Haduch
@khaduch
Apr 20 2016 10:56
@Ultras05 - in the lesson, they give you the code for "value is non-blank"... that is the code snippet: (value !== "") that they put in parentheses in the explanation. You are interpreting it literally -by using the word (or phrase) "non-blank" in there. I hope that helps? That is a start on fixing your code.
Ultras05
@Ultras05
Apr 20 2016 11:00

// 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")
{
value=prop;
}
else if (prop=="tracks"&& value!=="")

return collection;
}

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

TanYiXun
@TanYiXun
Apr 20 2016 11:04

// Setup
function abTest(a, b) {
  // Only change code below this line


  // Only change code above this line

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

// Change values below to test your code
abTest(-2,2);
Modify the function abTest so that if a or b are less than 0 the function will immediately exit with a value of undefined.
guys can you help me understand how to do this?
Stephen James
@sjames1958gm
Apr 20 2016 11:05
@TanYiXun how would you write an if statement to test whether a or b are less than zero
TanYiXun
@TanYiXun
Apr 20 2016 11:07
@sjames1958gm @TanYiXun
isit like if(a<0&&b<0){}?
Ken Haduch
@khaduch
Apr 20 2016 11:07
@Ultras05 - it would be a little easier to read the code if you used the code formatting markup - I'll post the help format as a reminder
help format
CamperBot
@camperbot
Apr 20 2016 11:07

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

Stephen James
@sjames1958gm
Apr 20 2016 11:08
@TanYiXun That is a is less than zero AND b is less than zero
TanYiXun
@TanYiXun
Apr 20 2016 11:09
@sjames1958gm so when do i use and and when do i use or?
Stephen James
@sjames1958gm
Apr 20 2016 11:09
@TanYiXun The text says "if a or b" that tells you to use or
TanYiXun
@TanYiXun
Apr 20 2016 11:11
o.o i see @sjames1958gm THanks !
CamperBot
@camperbot
Apr 20 2016 11:11
tanyixun sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 717 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Ken Haduch
@khaduch
Apr 20 2016 11:16

@Ultras05 - but your check for the non-blank condition of value is better. The next thing to get is the effect that they want you to achieve for that condition. They are passing a property name via the function arg prop, and a value in the value arg - these are variables to be used in the code (as you probably know.) But the intent is that after finding the particular conditions of those variables with the tests, that some action should be taken to modify the entry from the collection that they are giving you with the id value. There should be some access of collection using the id value (hint: check the object access lessons for review, in particular, Accessing Objects Properties with the Dot Operator, Accessing Objects Properties with Bracket Notation, and Accessing Objects Properties with Variables, if you need some review.) That is the next step. In other words, what I'm trying to help you change is the action in this piece of code:

if(value!==""&&prop!=="tracks")
{
value=prop;
}

to change value = prop to something like collection SOMETHING = SOMETHING_ELSE... (Trying not to give the answer directly...)

Ken Haduch
@khaduch
Apr 20 2016 11:24

@Ultras05 - I'm beginning to see, however, that the explanation of this is somewhat lacking in clarity (in the original lesson) and can be misinterpreted. I was trying to come up with another paragraph to "help" understand this - it might be a good thing in light of the fact that many people seem to run into an obstacle with this challenge. What I wrote for another person yesterday was a potential explanation to try and clarify the objectives for this challenge - this is what I wrote:

Working with the data that is given, several operations can be performed to add to, and modify, this data.
Each "album" is represented by a javascript object, and is indexed by an ID value, which is a numeric
 property that uniquely identifies the album.  Property values are passed as one of the function parameters,
indicating the property of an album to be modified, for example, to refer to information about the performing
artist, the property will be "artist".  A "value" parameter will also be passed as one of the function parameters.
If a value is given, the property should be added to the album object if it does not exist, or the current value
updated if the property already exists.  If the value that is passed in is blank, then the property should be
deleted.  If the property name that is specified is "tracks", and the value is blank, then the "tracks" property
should be deleted; otherwise, the new value (a new song title) should be added to the end of the "tracks"
array.

I can see where the instruction: If value is non-blank (value !== "") and prop is not "tracks" then update or set the value for the prop. can be misinterpreted if there is not a little better understanding of the objective at this point...

Nicky
@nickyjt16
Apr 20 2016 11:28 <