These are chat archives for FreeCodeCamp/HelpJavaScript

27th
Jan 2016
Joshua Thomas
@Jkthomas88
Jan 27 2016 00: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 update(id, prop, value) {

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





}

// Alter values below to test your code
update(5439, "artist", "ABBA");
still having a little trouble, any help?
Jeff Rutherford
@JeffRutherford
Jan 27 2016 00:00

My code: // Setup
var myStr = "Jello World";

// Only change code below this line
myStr = "Hello World";
myStr[0] = "H"; // Fix Me

Paul
@PJonestown
Jan 27 2016 00:01
prop=value;
There's a problem with this line
Prop is a property of an object
Aleksander Gębicki
@Takumar
Jan 27 2016 00:01
@gingersnapp shift() removes first element from array, and unshift() adds element to the beginning of an array.
Paul
@PJonestown
Jan 27 2016 00:02
So it can't be called without the object
Colm
@Wrongcolm
Jan 27 2016 00:02
Thanks @Takumar that'll learn me for not reading the entire code carefully
CamperBot
@camperbot
Jan 27 2016 00:02
wrongcolm sends brownie points to @takumar :sparkles: :thumbsup: :sparkles:
Jeff Rutherford
@JeffRutherford
Jan 27 2016 00:02
I'm getting an error: TypeError: Cannot assign to read only property '0' of Hello World.
CamperBot
@camperbot
Jan 27 2016 00:02
:star: 1949 | @takumar | http://www.freecodecamp.com/takumar
Aleksander Gębicki
@Takumar
Jan 27 2016 00:02
@JeffRutherford that's because strings are immutable, you cannot change part of the string (you tried to change first letter).
myStr[0] = "H"; // Fix Me
rphares
@rphares
Jan 27 2016 00:02
you need to reassign it :)
Joshua Thomas
@Jkthomas88
Jan 27 2016 00:02
@PJonestown so collection[prop] or update[propp` ?
Paul
@PJonestown
Jan 27 2016 00:03
@Jkthomas88 Much closer
Within the collection there are several albums
So you need to use the id to specify which one
Ryan
@ispeakcomputer
Jan 27 2016 00:05
@PJonestown damn stuck on the same one.
Jeff Rutherford
@JeffRutherford
Jan 27 2016 00:05
@Takumar I guess I'm confused by the instructions. "Instructions : Correct the assignment to myStr to achieve the desired effect." I'm not sure what desired effect they're talking about.
Joshua Thomas
@Jkthomas88
Jan 27 2016 00:05
@PJonestown collection[id][prop]?
Paul
@PJonestown
Jan 27 2016 00:05
@Jkthomas88 So if you think of it as a nested array that you wanted to change
a=[[1,2,3], [4,5,6]]
rphares
@rphares
Jan 27 2016 00:05
it means you cannot change just a character in that string, @JeffRutherford
so you need to reassign it,
example:
Paul
@PJonestown
Jan 27 2016 00:06
@Jkthomas88 you got it. That should do it
Joshua Thomas
@Jkthomas88
Jan 27 2016 00:06
@PJonestown thanks!
CamperBot
@camperbot
Jan 27 2016 00:06
jkthomas88 sends brownie points to @pjonestown :sparkles: :thumbsup: :sparkles:
:star: 224 | @pjonestown | http://www.freecodecamp.com/pjonestown
rphares
@rphares
Jan 27 2016 00:06
This message was deleted
Jeff Rutherford
@JeffRutherford
Jan 27 2016 00:07
@rphares @Takumar I just solved it. That's one lesson that I definitely think could have much better instructions.
rphares
@rphares
Jan 27 2016 00:07
congrats!
Jeff Rutherford
@JeffRutherford
Jan 27 2016 00:07
Thanks @rphares and @Takumar for your help!!
CamperBot
@camperbot
Jan 27 2016 00:07
jeffrutherford sends brownie points to @rphares and @takumar :sparkles: :thumbsup: :sparkles:
:star: 1950 | @takumar | http://www.freecodecamp.com/takumar
:star: 2032 | @rphares | http://www.freecodecamp.com/rphares
Aleksander Gębicki
@Takumar
Jan 27 2016 00:07
@JeffRutherford maybe. If you have an idea how to correct this, please send suggestions to FCC team.
Here you will find emails: http://www.freecodecamp.com/about
rphares
@rphares
Jan 27 2016 00:08
(oooh, pretty number, @Takumar ~)
Aleksander Gębicki
@Takumar
Jan 27 2016 00:09
@rphares yours is prettier, so futuristic :-)
@rphares but thanks :-)
CamperBot
@camperbot
Jan 27 2016 00:09
takumar sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 2033 | @rphares | http://www.freecodecamp.com/rphares
rphares
@rphares
Jan 27 2016 00:09
hahaha, not necessary!! you can use ty so you don't feed me :blush:
Paul
@PJonestown
Jan 27 2016 00:11
I have sort of a vague question. Why does js allow functions to access variables defined from the outside. I mean this seems to make every var a global variable (as long as it's defined outside functions)
I'm coming from ruby, and I was always taught that this is a very bad practice
Joshua Thomas
@Jkthomas88
Jan 27 2016 00:13
@PJonestown how do you like ruby? I was thinking about trying to learn that next.
sorry I can't help with your question btw lol.
Paul
@PJonestown
Jan 27 2016 00:14
@Jkthomas88 It will spoil you lol :)
I can't think of a more pleasant language to code in
But there's a lot of magic, so something like js might actually be better when starting out
Matt Leonard
@matty22
Jan 27 2016 00:16
bonfire finders keepers
CamperBot
@camperbot
Jan 27 2016 00:16

:fire:Bonfire: Finders Keepers :link:

function find(arr, func) {
  var num = 0;
  return num;
}

find([1, 2, 3, 4], function(num){ return num % 2 === 0; });

Create a function that looks through an array (first argument) and returns the first element in the array that passes a truth test (second argument).

more info:  bf details | bf links | hint

Matt Leonard
@matty22
Jan 27 2016 00:16
I could use some help on this one if anyone is available?
rphares
@rphares
Jan 27 2016 00:16
we can try-- whats up, @matty22 ~
Joshua Thomas
@Jkthomas88
Jan 27 2016 00:17
@PJonestown lol I've read that Ruby is easier compared to js. Since I don't know any different I think youre right, I'll learn JS first and then get to really appreciate ruby
Matt Leonard
@matty22
Jan 27 2016 00:17
I'm looking at this code snippet on the MDN article that looks like it is kind of what I need to do:
function isBigEnough(value) {
  return value >= 10;
}
var filtered = [12, 5, 8, 130, 44].filter(isBigEnough);
// filtered is [12, 130, 44]
Paul
@PJonestown
Jan 27 2016 00:17

Say like instead of

for (var i = 0; i <10; i++) {}

You'd just do

10.times do

in ruby

Matt Leonard
@matty22
Jan 27 2016 00:17
But when I look at the code provided in the editor:
function find(arr, func) {
  var num = 0;

  return num;
}

find([1, 2, 3, 4], function(num){ return num % 2 === 0; });
It looks the same, but...not? The order seems to be mixed up and I'm not sure how to wrap my head around where .filter() fits in here
Joshua Thomas
@Jkthomas88
Jan 27 2016 00:18
haha yeah seems much more simple.
InspireHD
@InspireHD
Jan 27 2016 00:18
could someone help me with Using Objects for Lookups
rphares
@rphares
Jan 27 2016 00:18
sure, @InspireHD --
what have you tried so far? :blush:
Sarah
@gingersnapp
Jan 27 2016 00:18
@Takumar thanks for the tip!
CamperBot
@camperbot
Jan 27 2016 00:18
gingersnapp sends brownie points to @takumar :sparkles: :thumbsup: :sparkles:
:star: 1951 | @takumar | http://www.freecodecamp.com/takumar
InspireHD
@InspireHD
Jan 27 2016 00:19
I created a var lookup = { } with "alpha" : "Adams" etc.
rphares
@rphares
Jan 27 2016 00:19
good, thats a good first step!
InspireHD
@InspireHD
Jan 27 2016 00:19
but i can't figure out how to make it work with phoneticLookup(val)
rphares
@rphares
Jan 27 2016 00:19
have you built the lookup part?
Ben Heavner
@bheavner
Jan 27 2016 00:19
I must be missing a detail on "Iterate with JavaScript For Loops"... When I run tests, I get "You should be using a for loop for this." - and I think I am.
My code is:
var myArray = [];
//Push the numbers zero through four to myArray using a "for loop" like above.

for(var i=1; i<6; i++){
  myArray.push(i);
}
InspireHD
@InspireHD
Jan 27 2016 00:19
well, I did the "alpha" : "Adams", "bravo" : "Boston" etc
rphares
@rphares
Jan 27 2016 00:20
so, if you have var lookup{blahblah @InspireHD , then you need to have it help you get val, right?
so, let's look at the example, alpha[2]
InspireHD
@InspireHD
Jan 27 2016 00:20
yes..i don't know how to mash it all together haha
rphares
@rphares
Jan 27 2016 00:21
in the example, they are using their table (var alpha) to get 2
and the format was alpha[2], correct?
InspireHD
@InspireHD
Jan 27 2016 00:21
yes
Ben Heavner
@bheavner
Jan 27 2016 00:21
Ah - I had an old solution, perhaps?
rphares
@rphares
Jan 27 2016 00:22
so, placeWeAreGettingIt[thingWeAreLookingFor] @InspireHD ?
Ben Heavner
@bheavner
Jan 27 2016 00:22
resetting code fixed my prob. Sorry to bother!
rphares
@rphares
Jan 27 2016 00:22
"...a lookup table called lookup. Use it to lookup val and return the associated string." @InspireHD ... how can we put that in the right format?
InspireHD
@InspireHD
Jan 27 2016 00:23
lookup[val]?
rphares
@rphares
Jan 27 2016 00:23
great!
now we just need one more thing
we need to assign that to what we are returning before we return it, huh
we are returning result, right?
InspireHD
@InspireHD
Jan 27 2016 00:24
holy crap!
rphares
@rphares
Jan 27 2016 00:24
but... atm result is just an empty string...
InspireHD
@InspireHD
Jan 27 2016 00:24
it workess
rphares
@rphares
Jan 27 2016 00:24
awesome! congrats, @InspireHD !
InspireHD
@InspireHD
Jan 27 2016 00:24
@rphares thank you so much
CamperBot
@camperbot
Jan 27 2016 00:24
inspirehd sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 2034 | @rphares | http://www.freecodecamp.com/rphares
rphares
@rphares
Jan 27 2016 00:24
anytime :)
Matt Leonard
@matty22
Jan 27 2016 00:24
Wow actually got this to pass by stumbling into it, but don't really understand what's happening.
function find(arr, func) {
  var num = 0;
  var filtered = arr.filter(func);
  return filtered[0];
}

find([1, 2, 3, 4], function(num){ return num % 2 === 0; });
InspireHD
@InspireHD
Jan 27 2016 00:25
and thank you for walking me through the problem rather than just directly telling me!
Paul
@PJonestown
Jan 27 2016 00:25
@rphares You're really great at leading people to solutions. Great job
rphares
@rphares
Jan 27 2016 00:25
Of course! anytime~
aw, thank you both, @InspireHD , @PJonestown
CamperBot
@camperbot
Jan 27 2016 00:25
rphares sends brownie points to @inspirehd and @pjonestown :sparkles: :thumbsup: :sparkles:
:star: 225 | @pjonestown | http://www.freecodecamp.com/pjonestown
:star: 214 | @inspirehd | http://www.freecodecamp.com/inspirehd
Matt Leonard
@matty22
Jan 27 2016 00:25
What part does the variable num play here?
It was provided, but if I comment it out the code still passes
Sundi Pierce
@sundipierce
Jan 27 2016 00:26
help Accessing Nested Arrays in JSON
CamperBot
@camperbot
Jan 27 2016 00:26

:point_right: waypoint accessing nested arrays in json [wiki]

Waypoint: Accessing Nested Arrays in JSON

As we have seen in earlier examples, JSON objects can contain both nested objects and nested arrays. Similar to accessing nested objects, Array bracket notation can be chained to access nested arrays.

Here is an example of how to access a nested array:

```js
var ourPets = {
"cats": [
"Meowzer",
"Fluffy",
"Kit-Cat"
],
"dogs": [
"Spot",
"Bowser",
"Frankie"
]
};
ourPets.cats1; // "Fluffy"
:pencil: read more about waypoint accessing nested arrays in json on the FCC Wiki

rphares
@rphares
Jan 27 2016 00:27
i don't see many active people, atm, @matty22 , and I'm too worried about misleading people with the harder stuff... if no one gets back to you soon, ill ping someone better to try and help :)
Matt Leonard
@matty22
Jan 27 2016 00:27
I'll try the bonfires room. Thanks
rphares
@rphares
Jan 27 2016 00:27
sorry! :pensive:
Jorge
@liberaltech
Jan 27 2016 00:30
what does it mean when "undefined is not an object"?
MD Alsaffar
@Cyberistic
Jan 27 2016 00:30

Anyone here could help me with the challenge, "Escaping Literal Quotes in Strings" please?

my code is

var myStr = "I am a \"double quoted"\ string inside \"double quotes"\";
rphares
@rphares
Jan 27 2016 00:31
first look--
the last one,
ou need to escape the second from last quote, the one that is connected to quotes, not the on on the outside,
also, the one after double quoted
you have it after the "
but it needs to be in front of it
@Cyberistic
MD Alsaffar
@Cyberistic
Jan 27 2016 00:34
Ahh! That worked! Thanks a lot. @rphares
Didn't expect it to be before the quote marks, that's odd.
CamperBot
@camperbot
Jan 27 2016 00:34
cyberistic sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 2037 | @rphares | http://www.freecodecamp.com/rphares
rphares
@rphares
Jan 27 2016 00:34
thats how we escape :) the \ goes before the character we want to skip :)
anytime~
Calvoxel
@Calvoxel
Jan 27 2016 00:35
Hey, I'm supposed to modify the following code to return the factorial of the provided integer, but I have literally no idea how to do it. The code is below:
function factorialize(num) {
  return num;
}

factorialize(5);
Justin Lewis
@lewisjustin26
Jan 27 2016 00:40
how do i add a value to the end of a JSON object?
Pandarati
@Pandarati
Jan 27 2016 00:40
I am stuck on a certain Zipline, but I think this room is more helpful for this situation.
I am trying to get the numerical string prop("123"). The if statements works. I console.loged it. However, when I am calling in dot notation/bracket notation I am getting a value of undefined.
for(prop in articles){
    if(!isNaN(parseInt(prop))){
      numPropTxt = prop;
    }
  }
  //Returns undefined
  articles = element.query.pages[numPropTxt];
//Returns the proper value
  articles = element.query.pages["6678"];
pravisti
@pravisti
Jan 27 2016 00:43
This message was deleted

What am I doing wrong here?

Instructions
Modify the function abTest so that if a or b are less than 0 the function will immediately exit with a value of undefined.

function abTest(a, b) {

if ( a<0 || b<0) {
return "undefined";
} else {
return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
}

rphares
@rphares
Jan 27 2016 00:44
so, undefined is a special value,
"undefined" is just a string
Pandarati
@Pandarati
Jan 27 2016 00:44
@pravisti You're returning a string value of undefined
rphares
@rphares
Jan 27 2016 00:44
remove the quotes :)
pravisti
@pravisti
Jan 27 2016 00:45
@rphares @Pandarati thanks for the help! : )
CamperBot
@camperbot
Jan 27 2016 00:45
pravisti sends brownie points to @rphares and @pandarati :sparkles: :thumbsup: :sparkles:
:star: 2038 | @rphares | http://www.freecodecamp.com/rphares
:star: 335 | @pandarati | http://www.freecodecamp.com/pandarati
rphares
@rphares
Jan 27 2016 00:45
anytime~
Pandarati
@Pandarati
Jan 27 2016 00:45
@rphares Is always helpful :D
rphares
@rphares
Jan 27 2016 00:45
hahaha
you are too kind, thanks @Pandarati ~
CamperBot
@camperbot
Jan 27 2016 00:45
rphares sends brownie points to @pandarati :sparkles: :thumbsup: :sparkles:
:star: 336 | @pandarati | http://www.freecodecamp.com/pandarati
Sarah
@gingersnapp
Jan 27 2016 00:46
function queue(arr, item) {
  // Your code here
  arr.push(item);
  arr.shift[0];
  console.log();

  return queue;  // Change this line
}
Chris Moore
@dooglus
Jan 27 2016 00:46
@Calvoxel where are you stuck on the factorial problem? do you know how to calculate a factorial?
Sarah
@gingersnapp
Jan 27 2016 00:46
this is for Stand in Line
Calvoxel
@Calvoxel
Jan 27 2016 00:46
@dooglus isn't it to add all the numbers that are less than or equal to the given number?
Chris Moore
@dooglus
Jan 27 2016 00:46
@gingersnapp you're meant to return the modified array I think. you're returning the queue function itself
@Calvoxel 5! === 5*4*3*2*1
Pandarati
@Pandarati
Jan 27 2016 00:47
@gingersnapp You're using arr.shift improperly.
Chris Moore
@dooglus
Jan 27 2016 00:47
@Calvoxel ie. multiplication
Calvoxel
@Calvoxel
Jan 27 2016 00:47
@dooglus Oh, whoops.
Chris Moore
@dooglus
Jan 27 2016 00:48
@Calvoxel so now can you do it?
Calvoxel
@Calvoxel
Jan 27 2016 00:48
@dooglus lol yeah, just passed it. Thanks for your help!
CamperBot
@camperbot
Jan 27 2016 00:48
calvoxel sends brownie points to @dooglus :sparkles: :thumbsup: :sparkles:
:star: 370 | @dooglus | http://www.freecodecamp.com/dooglus
tommy
@tommygebru
Jan 27 2016 00:50
@Pandarati is that a mdn api?
Matt
@EngineeredTruth
Jan 27 2016 00:54
Hello, I'm coding my javascript calculator
I'm having problems when a user clicks multiple numbers
say a user hits the 7 key 3x
I'm having problems with having the calculator current number change to 777. Is there a resource or method that can help me with that
Dora
@DoraEx
Jan 27 2016 00:59
help Seek and Destroy
CamperBot
@camperbot
Jan 27 2016 00:59

:point_right: bonfire seek and destroy [wiki]

Explanation:

This problem is a bit tricky because you have to familiarize yourself with Arguments, as you will have to work with two or more but on the script you only see two. Many people hardcode this program for three arguments. You will remove any number from the first argument that is the same as any other other arguments.

:pencil: read more about bonfire seek and destroy on the FCC Wiki

Jessie
@jvhensley
Jan 27 2016 01:00
@RachelKutzley -- sorry I was away from the coding for a few days. Do you still need help with that problem with Make Unique Objects?
InspireHD
@InspireHD
Jan 27 2016 01:09
these javascript waypoints with objects is really kicking my butt
Toni
@c0ldpr0xy
Jan 27 2016 01:10
Hey guys, I can't figure this one out:
// Setup
var myStr = "Jello World";

// Only change code below this line

myStr[0] = "H"; // Fix Me
rphares
@rphares
Jan 27 2016 01:10
they can be pretty hard, @InspireHD
@c0ldpr0xy , strings are immutable
InspireHD
@InspireHD
Jan 27 2016 01:10
I'm doing the Testing Objects for Properties
rphares
@rphares
Jan 27 2016 01:10
that means, we cannot change just one character, @c0ldpr0xy
InspireHD
@InspireHD
Jan 27 2016 01:11
i'm thinking I need to use an if statement
rphares
@rphares
Jan 27 2016 01:11
so, we need to change that last line, it doesn't work, @c0ldpr0xy
Toni
@c0ldpr0xy
Jan 27 2016 01:11
hmm
rphares
@rphares
Jan 27 2016 01:11
instead, we need to re-assign the string,
Toni
@c0ldpr0xy
Jan 27 2016 01:11
so type "hello world" instead of just H?
rphares
@rphares
Jan 27 2016 01:11
yep:)
Toni
@c0ldpr0xy
Jan 27 2016 01:12
hmm
rphares
@rphares
Jan 27 2016 01:12
and no [0] of course
Toni
@c0ldpr0xy
Jan 27 2016 01:12
oh i see
rphares
@rphares
Jan 27 2016 01:12
(and capitalized the way they requested)
one sec, lemme look it up, @InspireHD ~
Toni
@c0ldpr0xy
Jan 27 2016 01:12
i get it now, we cant change individual characters within quotations marks in a defined variable but we change the whole thing at once
thx @rphares
rphares
@rphares
Jan 27 2016 01:13
anytime! and congrats~
InspireHD
@InspireHD
Jan 27 2016 01:13
@rphares I started with if (myObj.hasOwnProperty(checkProp)){
rphares
@rphares
Jan 27 2016 01:13
@InspireHD , yep, i used an if/else :)
oh,
InspireHD
@InspireHD
Jan 27 2016 01:13
i can't figure out how to get it to return the property
rphares
@rphares
Jan 27 2016 01:13
thats not quite what i did
InspireHD
@InspireHD
Jan 27 2016 01:13
ah
i'm going to start over
rphares
@rphares
Jan 27 2016 01:14
okeydoke-- but,
do remember I'm a newbie to, so i only know the solns that worked for me,
i don't know/cannot tell you other ways to do it,
so you may not have to... i only know what i did :pensive:
InspireHD
@InspireHD
Jan 27 2016 01:14
I couldn't figure out how to get it to return the property value
any advice?
rphares
@rphares
Jan 27 2016 01:16
This message was deleted
This message was deleted
liddlebud
@liddlebud
Jan 27 2016 01:18
having a little trouble with local scopes and functions, any sources i can check out or you'd recommend?
InspireHD
@InspireHD
Jan 27 2016 01:18
Yeah i'm not sure how to do it right now :(
rphares
@rphares
Jan 27 2016 01:18
hmm, can you post your code, @liddlebud ?
there are two key things that often trip people up on that, you may not need many outside sources...
Eric
@eti313
Jan 27 2016 01:20
Hello everyone!
liddlebud
@liddlebud
Jan 27 2016 01:20
i just cleared my code, should i post the problem?
rphares
@rphares
Jan 27 2016 01:20
@InspireHD , maybe a smidgen of thought on the return would also help-- what did you try for that?
InspireHD
@InspireHD
Jan 27 2016 01:20
was trying return myObj; or checkProp; I don't know..i'm just....stuck
rphares
@rphares
Jan 27 2016 01:21
@liddlebud , not necessary-- maybe try adding the local var and deleting the extra console.log again, running tests, and if that fails again, paste what you tried here?
Adam
@Blakemilton6
Jan 27 2016 01:21
Hey guys I'm on the golf code challenge any pointers? function golfScore(par, strokes) {
// Only change code below this line
if (par==1) {
return "Hole-in-one!";
} else if (par<=2) {
return "Eagle";  
Eric
@eti313
Jan 27 2016 01:21
I'm having trouble with Using Objects for Lookups. I thought I followed the example but it doesn't work.
rphares
@rphares
Jan 27 2016 01:21
ah, your return is also a bit different from mine, @InspireHD
InspireHD
@InspireHD
Jan 27 2016 01:21
it's not wworking. i'm sure i'm doing it totally wrong
rphares
@rphares
Jan 27 2016 01:21
@eti313 , can you please paste your code? :)
InspireHD
@InspireHD
Jan 27 2016 01:22
@Blakemilton6 if par== 1 or stroke?
Eric
@eti313
Jan 27 2016 01:22
@rphares
var lookup = {
alpha:"Adams",
bravo:"Boston",
charlie:"Chicago",
delta:"Denver",
echo:"Easy",
foxtrot:"Frank"
};
rphares
@rphares
Jan 27 2016 01:22
@eti313 , so thats a good start :)
liddlebud
@liddlebud
Jan 27 2016 01:22

@rphares
function myFunction() {
'use strict';

console.log(myVar);
}
myFunction();
{myVar();}
// run and check the console
// myVar is not defined outside of myFunction
console.log(myVar);

// now remove the console log line to pass the test

```

InspireHD
@InspireHD
Jan 27 2016 01:22
@eti313 same thing i was stuck on until @rphares walked me through it :)
rphares
@rphares
Jan 27 2016 01:23
but, you need to build the lookup part next, lets look at the example on the left, @eti313
Eric
@eti313
Jan 27 2016 01:23
@InspireHD ah, good :)
M. Matthews
@mmatthews1981
Jan 27 2016 01:23
Hey guys, can someone straighten me out and tell me why my value isn't returning?
Adam
@Blakemilton6
Jan 27 2016 01:23
@InspireHD I'm having a tough time just wrapping my head around it
rphares
@rphares
Jan 27 2016 01:23
@liddlebud , try adding a local var-- a variable right under the line that says 'use strict'
liddlebud
@liddlebud
Jan 27 2016 01:23
kk
@rphares thx
CamperBot
@camperbot
Jan 27 2016 01:23
liddlebud sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 2040 | @rphares | http://www.freecodecamp.com/rphares
InspireHD
@InspireHD
Jan 27 2016 01:23
@Blakemilton6 you have to test for strokes. strokes are what determine your score compared to the par
rphares
@rphares
Jan 27 2016 01:23
sure thing :)
M. Matthews
@mmatthews1981
Jan 27 2016 01:23
function sumFibs(num) {
  var orig = num;

  function theFunc(){
    return orig;
  }

theFunc();

}

sumFibs(4);
why is that not returning a 4?
rphares
@rphares
Jan 27 2016 01:24
so, in the example, @eti313 , alpha[2], alpha is the name of their table, (var alpha) and 2 is what they are looking for, right?
Eric
@eti313
Jan 27 2016 01:25
@rphares, in the example, yes
rphares
@rphares
Jan 27 2016 01:25
( @liddlebud , two more steps to pass after adding that var, btw :blush: )
okay, cool. so what is YOUR table called. the examples was alpha, yours is...? @eti313
Adam
@Blakemilton6
Jan 27 2016 01:25
Thanks Inspire, I hate golf that's the excuse I'm using;)
InspireHD
@InspireHD
Jan 27 2016 01:25
@Blakemilton6 did it work?
Adam
@Blakemilton6
Jan 27 2016 01:26
Yeah the first three looks like I'm on the right track thanks!
Eric
@eti313
Jan 27 2016 01:26
@rphares mine is "lookup, so...
lookup[alpha];
Yes?
rphares
@rphares
Jan 27 2016 01:26
very close, @eti313 !
but, you aren't looking for alpha, look again at the last line of instructions... what does it tell you to look up?
(sorry, @InspireHD , I'm searching for the waypoint that refers to what i returned... it'll take me a bit, I'm bad at terms so I'm opening a lot of them trying to find it, lol)
Eric
@eti313
Jan 27 2016 01:27
@rphares "Use it to lookup val and return the associated string."
InspireHD
@InspireHD
Jan 27 2016 01:27
@rphares no problem. i think my if statement doesn't work because .hasOwnProperty("mustBeAString")
rphares
@rphares
Jan 27 2016 01:27
yes-- so you aren't searching for[alpha], you are searching for [?] ? @eti313
myObj.hasOwnProperty(checkProp);-- which we both used, has a strong relationship to what i returned, @InspireHD .... I'm sorry, I'm not good at explaining the theory stuff.... but basically, if true, i returned what that is testing... but not testing, the actual thing...
InspireHD
@InspireHD
Jan 27 2016 01:30
hm..ok..
rphares
@rphares
Jan 27 2016 01:31
@eti313 , you are looking up 'val' :)
Eric
@eti313
Jan 27 2016 01:31
@rphares well, if one of the examples is '2:"Y"' and in my table one line is 'alpha:"Adams" ' I just figured to follow that example and instead of "alpha2" I'd use "lookup[alpha]"
@rphares umm, ok that broke
rphares
@rphares
Jan 27 2016 01:32
yes-- if we wanted to lookup alpha, that would be lookup[alpha]... but they have asked us to look up the val, not a specific name one :)
InspireHD
@InspireHD
Jan 27 2016 01:32
@eti313 phoneticLookup(thisIsWhatYoureLookingFor)
Eric
@eti313
Jan 27 2016 01:32
@rphares val[alpha]; ?
rphares
@rphares
Jan 27 2016 01:33
our place we are looking goes on the outside,
our table is var lookup
so lookup goes on the outside :)
our thing we are looking for goes inside,
we are looking for val
so... together, that's?
Eric
@eti313
Jan 27 2016 01:35
@rphares wish I knew :)
rphares
@rphares
Jan 27 2016 01:36
lol, okay, hmm, must be getting sleepy and unclear,
that would be nameOfPlace[thingWeWantToFind]
Eric
@eti313
Jan 27 2016 01:36
@rphares is the example correct?
rphares
@rphares
Jan 27 2016 01:36
so, lookup[val]
yes, the example is correct-- their table is named alpha, and they are looking up 2
our table is named lookup, and we are looking up val
:)
Eric
@eti313
Jan 27 2016 01:37
@rphares ok i think i get it....
rphares
@rphares
Jan 27 2016 01:37
cool-- because we have a little left to do :)
we are returning result, right?
Adam
@Blakemilton6
Jan 27 2016 01:38
hey guys I spoke too soon
if (strokes==1) {
return "Hole-in-one!";
} else if (strokes<=2) {
return "Eagle";  
} else if (strokes<1) {
  return "Birdie";
Eric
@eti313
Jan 27 2016 01:38
@rphares it already does "return result" and I'm not supposed to change that
rphares
@rphares
Jan 27 2016 01:39
exactly, @eti313 ,
but, atm, result is just an empty string,
Adam
@Blakemilton6
Jan 27 2016 01:39
am I on the right track for golf code?
rphares
@rphares
Jan 27 2016 01:39
so, we need to assign our lookup we just built ( lookup[val]) to result, rright before we return it...
Eric
@eti313
Jan 27 2016 01:39
@rphares OK, got it. :)
rphares
@rphares
Jan 27 2016 01:40
oh yay! congrats, @eti313 ~
InspireHD
@InspireHD
Jan 27 2016 01:40
@Blakemilton6 how would you compare your strokes against the par? how does it know what par is?
Eric
@eti313
Jan 27 2016 01:40
@rphares LOL.
Jose J. Rodriguez
@jrodrv
Jan 27 2016 01:40
function isLess(a, b) {
  // Fix this code
  if (a < b) {
    return true;
  } else {
    return false;
  }
}

// Change these values to test
isLess(10, 15);
rphares
@rphares
Jan 27 2016 01:40
@jrodrv , what lesson is that? :blush:
Jose J. Rodriguez
@jrodrv
Jan 27 2016 01:41
Returning Boolean Values from Functions
InspireHD
@InspireHD
Jan 27 2016 01:41
@Blakemilton6 if you look at the table on the left, it'll show how strokes compare to par
Eric
@eti313
Jan 27 2016 01:41
@rphares OK, in the example they never returned anything. It all kinda makes sense now but I'm gonna stare at it for a few minutes
rphares
@rphares
Jan 27 2016 01:41
ahhh, you just wanna get rid of the if/else, right @jrodrv ?
Jose J. Rodriguez
@jrodrv
Jan 27 2016 01:41
yeah
can only get 2 of the 3 tests to work at once
rphares
@rphares
Jan 27 2016 01:42
good call, i also had to read and reread the example, @eti313 :) study on and happy coding!
Well, right now you have an if/else still, @jrodrv
Eric
@eti313
Jan 27 2016 01:42
@rphares how do I send you some brownie points?
rphares
@rphares
Jan 27 2016 01:42
so, we need to think of another way to write that, @jrodrv
you say thanks, @name :blush:
CamperBot
@camperbot
Jan 27 2016 01:42
rphares sends brownie points to @name :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for name
rphares
@rphares
Jan 27 2016 01:42
example: thanks, @eti313 !
CamperBot
@camperbot
Jan 27 2016 01:42
rphares sends brownie points to @eti313 :sparkles: :thumbsup: :sparkles:
:star: 213 | @eti313 | http://www.freecodecamp.com/eti313
Eric
@eti313
Jan 27 2016 01:43
thanks, @rphares
CamperBot
@camperbot
Jan 27 2016 01:43
eti313 sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 2041 | @rphares | http://www.freecodecamp.com/rphares
rphares
@rphares
Jan 27 2016 01:43
anytime~
Jose J. Rodriguez
@jrodrv
Jan 27 2016 01:43
yeah i just pasted the original code
rphares
@rphares
Jan 27 2016 01:43
ahh-- can you paste what you have tried so far, @jrodrv ?
Eric
@eti313
Jan 27 2016 01:44
ttfn
Jose J. Rodriguez
@jrodrv
Jan 27 2016 01:44
i tried using comparison operators
rphares
@rphares
Jan 27 2016 01:45
yes, you will need one,
see how they drilled all of this:
  if (a === b) {
    return true;
  } else {
    return false;
  }
}
down into just the comparison?
function isEqual(a,b) {
  return a === b;
}
you can do the exact same thing...
Jose J. Rodriguez
@jrodrv
Jan 27 2016 01:47
ok
rphares
@rphares
Jan 27 2016 01:47
(except, you use different operators... your function doesn't involve ===, it has something else :) )
Jose J. Rodriguez
@jrodrv
Jan 27 2016 01:47
been at it for a bit too long need a break
thanks @rphares
CamperBot
@camperbot
Jan 27 2016 01:47
jrodrv sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 2042 | @rphares | http://www.freecodecamp.com/rphares
rphares
@rphares
Jan 27 2016 01:48
anytime~
(and breaks are good, its easy to get fried :) )
InspireHD
@InspireHD
Jan 27 2016 01:48
AHH @rphares I did something random and it worked! hahaha
Vincent Yan
@envincebal
Jan 27 2016 01:48
Hey guys I'm on the Switch statement exercise and not sure what I'm doing wrong here:
function myTest(val) {
  var answer = "";
  // Only change code below this line
  switch(answer){
    case val : "alpha";
      break;
    case val : "beta";
      break;
    case val :"gamma";
      break;
  }

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

// Change this value to test
myTest(1);
InspireHD
@InspireHD
Jan 27 2016 01:48
straight if else statemetn
rphares
@rphares
Jan 27 2016 01:48
hahaha, thats great news, @InspireHD ! what did you do?
InspireHD
@InspireHD
Jan 27 2016 01:48
actually wasn't an if else..it was just an if
if (myObj.hasOwnProperty(checkProp)){
return myObj[checkProp];
}
return "Not Found";
i guess it assumes the else
rphares
@rphares
Jan 27 2016 01:49
@envincebal , so for those cases,
(Awesome, @InspireHD !! congrats!)
you don't need case val , @envincebal
InspireHD
@InspireHD
Jan 27 2016 01:50
I'm not even sure how it works...like @eti313 said..i'm going to stare at it for a few minutes
rphares
@rphares
Jan 27 2016 01:50
our switch is switch(val){, @envincebal , so we want to use the numbers from the chart at the bottom of the instructions for our cases :)
hahaha, im still bad at using that one... yours is very close to mine, and i still struggle to use it :blush: Stare, and when you understand it, help me get it more deeply, please, @InspireHD :blush:
Keri Gannon
@kerianngannon
Jan 27 2016 01:51
I need help with the counting cards waypoint. Here's what I have so far:
 switch(card){
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
      count ++;
      break;
    case 7:
    case 8:
    case 9:
      count = 0;
      break;
    case 10:
    case "J":
    case "Q":
    case "K":
      count --;
      break;
  }
  if (count > 0){
    return count + "Bet";
  }
  else {
    return count + "Hold";
  }
  return "Change Me";
Vincent Yan
@envincebal
Jan 27 2016 01:52
@rphares you mean like this:
function myTest(val) {
  var answer = "";
  // Only change code below this line
  switch(val){
    case 1 : "alpha";
      break;
    case 2: "beta";
      break;
    case 3:"gamma";
      break;
  }

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

// Change this value to test
myTest(1);
rphares
@rphares
Jan 27 2016 01:52
the two things i notice off the bat, @kerianngannon , is that you likely need a space at the beginning of " Bet" and " Hold" and that you don't want return "Change Me"; at the end
much better, @envincebal ! one sec, ill read it more carefully now :)
InspireHD
@InspireHD
Jan 27 2016 01:53
@kerianngannon check your cases where it "equals" 0. think of = as "assigns" and == as "is"
Keri Gannon
@kerianngannon
Jan 27 2016 01:53
@rphares thanks, I just noticed the space too. I deleted return "Change Me"; at the end
CamperBot
@camperbot
Jan 27 2016 01:53
kerianngannon sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 2043 | @rphares | http://www.freecodecamp.com/rphares
Vincent Yan
@envincebal
Jan 27 2016 01:53
@rphares thanks for taking the time :)
rphares
@rphares
Jan 27 2016 01:53
okay-- so every case, you need to set answer= , @envincebal
InspireHD
@InspireHD
Jan 27 2016 01:53
@kerianngannon actually i guess that works too
rphares
@rphares
Jan 27 2016 01:53
the parts in quotes, like "alpha" are what you want to set answer to, @envincebal
Keri Gannon
@kerianngannon
Jan 27 2016 01:54
@InspireHD I tried changing it to ==, but with 0 it only allows ===, but it still doesn't work
rphares
@rphares
Jan 27 2016 01:54
you don't want case 1: "alpha"....
InspireHD
@InspireHD
Jan 27 2016 01:54
@kerianngannon i went back to look at mine and I was using += 0; so it still worked
@kerianngannon did you get it to work
rphares
@rphares
Jan 27 2016 01:55
@envincebal , you want something like (EXAMPLE, NOT REAL CODE:) )
case 32 :
answer = "bobby";
break;
Keri Gannon
@kerianngannon
Jan 27 2016 01:56
@InspireHD I changed it to +=0, but it's still not working
Chris Williamson
@williamsonchris
Jan 27 2016 01:56
Hey everyone
Im having some issues with the Title Case a Sentence bonfire
Heres the code:
function titleCase(str) {

  var loc = str.toLowerCase().split(" "); //this makes an array all lower case sep. by spaces

  for(i = 0; i < loc.length; i++) {
     var caps = loc[i].charAt(0).toUpperCase(); //is only targeting the first array in loc
    //I need to have this combine back into the array
    //how can I make it communicate with the rest of the array
    // why is it stopping at the first instance
    return caps;
  }
}

titleCase("I'm a little tea pot");
InspireHD
@InspireHD
Jan 27 2016 01:56
@kerianngannon are you using "all" of the cards?
Vincent Yan
@envincebal
Jan 27 2016 01:56
@rphares thanks! You are a life saver :)
CamperBot
@camperbot
Jan 27 2016 01:56
envincebal sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 2044 | @rphares | http://www.freecodecamp.com/rphares
rphares
@rphares
Jan 27 2016 01:57
anytime~
Chris Williamson
@williamsonchris
Jan 27 2016 01:57
Can anyone tell me why when I return caps I am only seeing I?
My loop isnt cycling through the array it seems like
InspireHD
@InspireHD
Jan 27 2016 01:57
@kerianngannon also, what happens if the count is 0 or less than 0?
Ken Haduch
@khaduch
Jan 27 2016 01:58
@williamsonchris - what does your code look like?
oops, I see it
InspireHD
@InspireHD
Jan 27 2016 01:58
@kerianngannon my else statement was a little bit different. looks like yours works too
Chris Williamson
@williamsonchris
Jan 27 2016 01:59
Do I need to designate another array that will accept the new values? ex. var newArray = [];
Ken Haduch
@khaduch
Jan 27 2016 02:00
@williamsonchris - if you walk through your code and your for loop, you are set up to iterate on the array, but you are returning a value from inside the loop, so that terminates the function (or the loop) but in this case you are returning a value, so it's the first word.
Chris Williamson
@williamsonchris
Jan 27 2016 02:00
Right
Keri Gannon
@kerianngannon
Jan 27 2016 02:00
Here's what I have with the counting cards waypoint, but I can't figure out what I need to change:
    switch(card){
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
      count += 1;
      break;
    case 7:
    case 8:
    case 9:
      count += 0;
      break;
    case 10:
    case "J":
    case "Q":
    case "K":
      count -= 1;
      break;
  }
  if (count > 0){
    return count + " Bet";
  }
  else {
    return count + " Hold";
  }
Chris Williamson
@williamsonchris
Jan 27 2016 02:00
So I need to make it return a value outside of the loop?
InspireHD
@InspireHD
Jan 27 2016 02:01
@kerianngannon I'm being vague on purpose. :) how many cards are in a deck?
d wilder
@alhazen1
Jan 27 2016 02:01
@williamsonchris Two things. 1. your loop returns on first iteration 2. caps = loc[... only is capturing the capped letter
Ken Haduch
@khaduch
Jan 27 2016 02:01
@williamsonchris - you are on the right track with your previous comment - some additional storage for the entire array contents, and then after you process it, form the proper return value and return that.
rphares
@rphares
Jan 27 2016 02:01
do you have an ace in there, @kerianngannon ?
InspireHD
@InspireHD
Jan 27 2016 02:01
!!!
rphares
@rphares
Jan 27 2016 02:01
(oops-- sorry, @InspireHD !!)
InspireHD
@InspireHD
Jan 27 2016 02:01
@rphares hahahahaha
Keri Gannon
@kerianngannon
Jan 27 2016 02:02
@InspireHD @rphares THANK YOU! Gosh, it almost feels better when I realize I need to re-read the directions...
CamperBot
@camperbot
Jan 27 2016 02:02
kerianngannon sends brownie points to @inspirehd and @rphares :sparkles: :thumbsup: :sparkles:
:warning: kerianngannon already gave rphares points
:star: 217 | @inspirehd | http://www.freecodecamp.com/inspirehd
Calvoxel
@Calvoxel
Jan 27 2016 02:02
Hey, I'm working on "Check for Palindromes", and so far, I need help on replacing non-alphanumeric characters. How do I do it? My code is below:
function palindrome(str) {
  // Good luck!
  var newStr = str.toLowerCase();
  newStr.replace();
  return true;
}



palindrome("eye");
InspireHD
@InspireHD
Jan 27 2016 02:02
@rphares your subtle hints really helped me figure out my problems and so I'm taking the same approach to help others . :)
rphares
@rphares
Jan 27 2016 02:02
sorry sorry, i was in another room!
yes-- thats the best approach by far, i apologize!
InspireHD
@InspireHD
Jan 27 2016 02:02
@kerianngannon gjgj
rphares
@rphares
Jan 27 2016 02:02
def getting sleepy, oughta go move~
Have good one all!
InspireHD
@InspireHD
Jan 27 2016 02:02
@kerianngannon I'm found I really enjoy reading other people's code
Keri Gannon
@kerianngannon
Jan 27 2016 02:02
Sometimes I think I'm missing some big coding mistake, but it's a relief to know it's something like reading the directions
Bye, @rphares !
Satchmo37
@Satchmo37
Jan 27 2016 02:04
function where(collection, source) {
  var arr = [];
  // Store the key value for the object source
  var key = Object.keys(source);
  for(var i = 0; i < collection.length; i++){
    //Check to see if the collection has the key
    if(collection[i].hasOwnProperty(key)){
      //Check to see if the key value matches
     if(collection[i][key] === source[key]){
       arr.push(collection[i]);
     }
    }
  }
  return arr;
}

where([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 });
I'm so close, but I can't for the life of me understand why this is returning an empty array
Delante Lee Bess
@dbess1
Jan 27 2016 02:05
I'm not quite clear on this Using Objects for Lookups
cannelflow
@cannelflow
Jan 27 2016 02:05
@jndelmor because you are passing arr there not testArr
Toni
@c0ldpr0xy
Jan 27 2016 02:05
Guys, what is the proper/easy way to remove for example 30% from 100. In programming of course using A, B, C variables.
Satchmo37
@Satchmo37
Jan 27 2016 02:06
This message was deleted
Jacob Andra
@jacob4
Jan 27 2016 02:06
@c0ldpr0xy you mean the math part?
Toni
@c0ldpr0xy
Jan 27 2016 02:06
yes
the "formula" if you will
Jacob Andra
@jacob4
Jan 27 2016 02:06
times by .7 @c0ldpr0xy
Toni
@c0ldpr0xy
Jan 27 2016 02:07
where do you get the .7 from?
Satchmo37
@Satchmo37
Jan 27 2016 02:07
@c0ldpr0xy
var a = 100;
var b = .3;
var c = a - (a *.3)
Toni
@c0ldpr0xy
Jan 27 2016 02:07
yes thank you @ddeason37
CamperBot
@camperbot
Jan 27 2016 02:07
c0ldpr0xy sends brownie points to @ddeason37 :sparkles: :thumbsup: :sparkles:
:star: 289 | @ddeason37 | http://www.freecodecamp.com/ddeason37
Toni
@c0ldpr0xy
Jan 27 2016 02:07
thats what i was looking for :)
Satchmo37
@Satchmo37
Jan 27 2016 02:07
No prob!
Jacob Andra
@jacob4
Jan 27 2016 02:07
100% - 30% === 70% @c0ldpr0xy
Chris Williamson
@williamsonchris
Jan 27 2016 02:07
@alhazen1 What is causing my loop to stop iterating after the first one
Jacob Andra
@jacob4
Jan 27 2016 02:07
70% === .7
Toni
@c0ldpr0xy
Jan 27 2016 02:08
thx @jacob4
CamperBot
@camperbot
Jan 27 2016 02:08
c0ldpr0xy sends brownie points to @jacob4 :sparkles: :thumbsup: :sparkles:
:star: 374 | @jacob4 | http://www.freecodecamp.com/jacob4
Jacob Andra
@jacob4
Jan 27 2016 02:08
@williamsonchris probably a return
Chris Williamson
@williamsonchris
Jan 27 2016 02:09
function titleCase(str) {

  var loc = str.toLowerCase().split(" "); //this makes an array all lower case sep. by spaces
  var newArray = [];

  for(i = 0; i <= loc.length; i++) {
     var newArray = loc[i].charAt(0).toUpperCase(); //is only targeting the first array in loc
    //I need to have this combine back into the array
    //how can I make it communicate with the rest of the array
    // why is it stopping at the first instance
    return newArray;
  }
}

titleCase("I'm a little tea pot");
@jacob4 The return at the end of the for loop is causing it to end?
Jacob Andra
@jacob4
Jan 27 2016 02:10
change i <= loc.length to i < loc.length @williamsonchris
Chris Williamson
@williamsonchris
Jan 27 2016 02:10
@jacob4 Yup, just did that and moved the return outside of the loop
That makes sense
Jacob Andra
@jacob4
Jan 27 2016 02:11
@williamsonchris did it work?
Rachel
@RachelKutzley
Jan 27 2016 02:12
Hi @jvhensley - yes please, i'm still stuck. i skipped over it but would like know what i'm doing wrong!
Jacob Andra
@jacob4
Jan 27 2016 02:13
@RachelKutzley what are you working on?
Rachel
@RachelKutzley
Jan 27 2016 02:14
I'm stuck on the "make unique objects" one. I saw others with the same issue.
trying to figure out how to send my code ... hang on ... haven't done this before in chat
var Car = function(wheels, seats, engines) {
  //Change this constructor
  this.wheels = 4;
  this.seats = 1;
  this.engines = 1;
};

//Try it out here

var myCar = new Car(2, 6, 3);
Jacob Andra
@jacob4
Jan 27 2016 02:15
Oops...sorry, @RachelKutzley gotta run...hope someone can help ya :)
Rachel
@RachelKutzley
Jan 27 2016 02:16
no sorries, thanks anyways @jacob4
CamperBot
@camperbot
Jan 27 2016 02:16
rachelkutzley sends brownie points to @jacob4 :sparkles: :thumbsup: :sparkles:
:star: 375 | @jacob4 | http://www.freecodecamp.com/jacob4
Brian Daub
@briandaub
Jan 27 2016 02:16
sorry @RachelKutzley what is the issue you are having?
Andrew Conley
@aconman1287
Jan 27 2016 02:17
Hey - working on 'Stand in line' in the basic javascript section and trying to figure out how to return an element that is removed from an array. Anyone know?
cannelflow
@cannelflow
Jan 27 2016 02:18
@RachelKutzley should be like this.wheels=wheels
Andrew Conley
@aconman1287
Jan 27 2016 02:18
blob
cannelflow
@cannelflow
Jan 27 2016 02:19
@aconman1287 you have to return what value is removed
Eric Yohansa
@eyohansa
Jan 27 2016 02:19

@RachelKutzley Iirc, you need to do something like this

var myCar = function(params...) {
    this.bla = param;
}

Just like the car object above.

Satchmo37
@Satchmo37
Jan 27 2016 02:22
```
cannelflow
@cannelflow
Jan 27 2016 02:22
@aconman1287 @RachelKutzley worked?
Satchmo37
@Satchmo37
Jan 27 2016 02:23
function where(collection, source) {
  var arr = [];
  // Store the key value for the object source
  var key = Object.keys(source);
  console.log(source[key]);
  for(var i = 0; i < collection.length; i++){    
      //Check to see if the key value from collection matches the source
     if(collection[i][key] === source[key]){
       arr.push(collection[i]);
     }
    }
  return arr;
}

where([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 });
When they key has more than one value i'm getting undefined when storing Object.keys(source). Can anyone explain to me how to fix this?
Andrew Conley
@aconman1287
Jan 27 2016 02:25
@cannelflow So if the value is 6, write a line that says "return 6;"?
Ken Haduch
@khaduch
Jan 27 2016 02:29
@ddeason37 - which challenge is this?
cannelflow
@cannelflow
Jan 27 2016 02:29
@aconman1287 you have to write the value which is removed in shift method
Satchmo37
@Satchmo37
Jan 27 2016 02:29
@khaduch Where are thou
Keri Gannon
@kerianngannon
Jan 27 2016 02:29
I'm trying to figure out what I'm doing wrong with the "accessing object properties with bracket notations" waypoint:
testObj["an entree"];
testObj["the drink"];
Satchmo37
@Satchmo37
Jan 27 2016 02:29
@khaduch Where *art thou
Keri Gannon
@kerianngannon
Jan 27 2016 02:29
it doesn't look like "testObj" is calling the previous variable
Shalmali Padgaokar
@Shalmalidp
Jan 27 2016 02:30
Hi i need help with the factoral challenge
function factorialize(num) {
  for(var i = 2; i<= num; i++){ 
    num = i * num;

  return num ;
  }
}

factorialize(10);
Ken Haduch
@khaduch
Jan 27 2016 02:31
@ddeason37 - OK - looking at it to refresh my memory...
cannelflow
@cannelflow
Jan 27 2016 02:31
@RachelKutzley worked?
Satchmo37
@Satchmo37
Jan 27 2016 02:32
I'm thinking maybe I should store each key separately? I'm pretty lost on how to pass the last two tests. If the source key contains only one value, it passes @khaduch
Roger Waggener
@rXger
Jan 27 2016 02:33
@ddeason37 This line if(collection[i].hasOwnProperty(key)) is failing when the source object has more than one property.
you're asking does (for instance) { "a": 1 } have the property ["a", "b"] which does not make sense. It works when there's only one property in the source object, not two.
I've been banging my head against this bonfire for several days now...
Valerie
@valbee
Jan 27 2016 02:33
hey guys, im getting an error message on this code for exercise with passing values to functions
Satchmo37
@Satchmo37
Jan 27 2016 02:33
@rXger Yup, that's exactly the problem!! I've been stuck on this one for days as well
Valerie
@valbee
Jan 27 2016 02:34
function myFunction(a, b) {
console.log(a + b);
}
myFunction(1, 2); // Outputs 3
myFunction(8, 8); // Outputs 16
cannelflow
@cannelflow
Jan 27 2016 02:34
@kerianngannon looks good can you show whole code
Toni
@c0ldpr0xy
Jan 27 2016 02:34
in programming, what formula can I use to find out a percentage of a number WITHOUT using floating numbers?
30% becomes 0.30 * 100
or just .30
Satchmo37
@Satchmo37
Jan 27 2016 02:35
@rXger I was thinking I might need to create a else statement to check in the length of key is greater than one, and then slcing each key off into a new variable and testing again....but just thinking about trying to code that makes me dizzy
Valerie
@valbee
Jan 27 2016 02:35
it says RangeError
Keri Gannon
@kerianngannon
Jan 27 2016 02:35
@cannelflow here's the whole code
// Setup
var testObj = {
  "an entree": "hamburger",
  "my side": "veggies",
  "the drink": "water"
};

// Only change code below this line

testObj["an entree"];
testObj["the drink"];
cannelflow
@cannelflow
Jan 27 2016 02:36
@kerianngannon assign testObj["an entree"];
testObj["the drink"]; to variable
Roger Waggener
@rXger
Jan 27 2016 02:36
@ddeason37 yeah, this one is tying my brane in knots.
Keri Gannon
@kerianngannon
Jan 27 2016 02:36
@cannelflow I don't understand what you mean
cannelflow
@cannelflow
Jan 27 2016 02:36
@Shalmalidp did you figured it out
Dante Kelly
@dantekelly
Jan 27 2016 02:37
function where(collection, source) {
  var arr = [];
  var arr2 = [];
  // What's in a name?

  for(var i=0; i < Object.keys(source).length; i++) { // I is the desired source key
    for(var j=0; j < collection.length; j++) { // J is the desired collection array results
      for(var h=0; h < Object.keys(collection[j]).length; h++) { // H is the desired collection[J] key   
        if(collection[j][Object.keys(source)[i]] === source[Object.keys(source)[i]]) {
          arr.push(collection[j]);
        }
      }
    }
  }

  return arr;
}


where([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
I'm stuck on Where art though, my code is pushing to arr twice, so there has to be another if success. I do not want to grab arr[0] as it is a static answer. How would I fix this problem? Also how would you clean this up?
cannelflow
@cannelflow
Jan 27 2016 02:37
@kerianngannon testObj["an entree"]; this will give a value hamburger and you need to assign that value to variable
Satchmo37
@Satchmo37
Jan 27 2016 02:38
@cannelflow Hahaha, you, me and @rXger are all stuck here!!
Chris Williamson
@williamsonchris
Jan 27 2016 02:38
So I got the Title Case a Sentence bonfire to work
Valerie
@valbee
Jan 27 2016 02:38
can i get a little help with this challenge please?
Chris Williamson
@williamsonchris
Jan 27 2016 02:38

```function titleCase(str) {

var loc = str.toLowerCase().split(" ");
var newArray = [];

for(i = 0; i < loc.length; i++) {
newArray[i] = loc[i].charAt(0).toUpperCase() + loc[i].substring(1);
}
return newArray.join(" ");
}

titleCase("I'm a little tea pot");

function titleCase(str) {

  var loc = str.toLowerCase().split(" ");
  var newArray = []; 

  for(i = 0; i < loc.length; i++) {
     newArray[i] = loc[i].charAt(0).toUpperCase() + loc[i].substring(1);
  }
  return newArray.join(" ");
}

titleCase("I'm a little tea pot");
Is this a cheap finish?
Ken Haduch
@khaduch
Jan 27 2016 02:38

@ddeason37 - you might not quite be getting the Object.keys functionality - if you go and read (or re-read) the documentation for that, you'll recall that it "returns an array of a given object's own enumerable properties, ". For the source parameter, which is an object, you should get an array of the keys of that object. It could have one, it could have many. The next step is that once you have this array of keys, you cannot directly use it (your variable key) as an index into another array (or object, as in this case.) You'll most likely have to deal with it with another for loop or similar functionality.

The idea being that if the 'source' object has multiple keys, you have to examine each of those keys and values in the 'collection' to make sure that you have matches for each of them, both that the keys exist and that their values are equal. It is a little bit of a complex problem.

Chris Williamson
@williamsonchris
Jan 27 2016 02:38
It seems like a lame answer
cannelflow
@cannelflow
Jan 27 2016 02:40
@williamsonchris its good
Bill
@kirah1314
Jan 27 2016 02:40
@williamsonchris what do you mean?
Satchmo37
@Satchmo37
Jan 27 2016 02:40
@khaduch So I would need to loop through the array if there is more than one key passed via source
liiam89
@liiam89
Jan 27 2016 02:42
Can I get somebody to help me with a problem?
Keri Gannon
@kerianngannon
Jan 27 2016 02:43
@cannelflow I'm not sure what I'm supposed to change, because it says to only change the code below the line. How do I assign that value to the variable?
Chris Williamson
@williamsonchris
Jan 27 2016 02:43
@cannelflow thanks
CamperBot
@camperbot
Jan 27 2016 02:43
williamsonchris sends brownie points to @cannelflow :sparkles: :thumbsup: :sparkles:
:star: 581 | @cannelflow | http://www.freecodecamp.com/cannelflow
cannelflow
@cannelflow
Jan 27 2016 02:43
@kerianngannon var entreeValue = testObj["an entree"]; // Change this line
var drinkValue = testObj["the drink"];
@williamsonchris :+1:
Chris Williamson
@williamsonchris
Jan 27 2016 02:43
@kirah1314 it seems like a too basic answer
liiam89
@liiam89
Jan 27 2016 02:44
When I run my code, it sends the results of my function to the text input fields like I want it to, except it only displays for a second before it flashes away.
Satchmo37
@Satchmo37
Jan 27 2016 02:44
function where(collection, source) {
  var arr = [];
  // Store the key value from the object source
  var key = Object.keys(source);
  console.log(key.length);
  for(var i = 0; i < collection.length; i++){    
      //Check to see if the key value from collection matches the source
     if(collection[i][key] === source[key]){
       arr.push(collection[i]);
       //Why doesn't this test pass???
     } else if (key.length >= 2){
       console.log('test');
     }
    }
  return arr;
}
@khaduch Why isn't the else if passing?
liiam89
@liiam89
Jan 27 2016 02:44
This message was deleted
Bill
@kirah1314
Jan 27 2016 02:44
@williamsonchris well that challenge is just the beginning and fairly simple, it'll get harder don't worry lol
Keri Gannon
@kerianngannon
Jan 27 2016 02:45
Thanks @cannelflow , I couldn't figure out that I need to create and assign a new variable. When I looked at the example, they didn't show that
CamperBot
@camperbot
Jan 27 2016 02:45
kerianngannon sends brownie points to @cannelflow :sparkles: :thumbsup: :sparkles:
:star: 582 | @cannelflow | http://www.freecodecamp.com/cannelflow
cannelflow
@cannelflow
Jan 27 2016 02:46
@kerianngannon :+1:
liiam89
@liiam89
Jan 27 2016 02:46




function convert() {

  var tempInput = document.getElementById("tempInput").value;
  var result;


if(tempInput !== "" && document.getElementById("unitSelectCelsius").checked){
  result = tempInput * (9/5) + 32;

}else if(tempInput !== "" && document.getElementById("unitSelectFahrenheit").checked){
  result = (tempInput - 32) / (9/5);

}else{
  result = "Enter a numeric value!";
}

document.getElementById("result").value = result;

};




function init(){
  document.getElementById('tempForm').onsubmit = convert;
};

window.onload = init();
Shalmali Padgaokar
@Shalmalidp
Jan 27 2016 02:46
@cannelflow I tried pushing it all into an array and then reduce it still no luck
liiam89
@liiam89
Jan 27 2016 02:46
I just want to know why the values passed to the text input field 'result' display for a second and then disappear.
Hank Janssens
@therealdeveloper
Jan 27 2016 02:48
Anyone here able to help decipher what this one JavaScript example is actually asking me to do.
I know it is probably simple, I must be reading it incorrectly.
liiam89
@liiam89
Jan 27 2016 02:50
Nevermind, I just put return false; in and it started working. Now I want to know why.
cannelflow
@cannelflow
Jan 27 2016 02:51
@Shalmalidp im also trying to solve this pls let me know if it works for you
Bill
@kirah1314
Jan 27 2016 02:51
@therealdeveloper which one? We'll do our best to help, go ahead and throw it
Shalmali Padgaokar
@Shalmalidp
Jan 27 2016 02:52
@cannelflow certainly
Hank Janssens
@therealdeveloper
Jan 27 2016 02:52
Word Blanks in JavaScript examples

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.

You will need to use string operators to build a new string, result, using the provided variables: myNoun, myAdjective, myVerb, and myAdverb.

You will also need to provide additional strings, which will not change, in between the provided words.

We have provided a framework for testing your results with different words. The tests will run your function with several different inputs to make sure all of the provided words appear in the output, as well as your extra strings.

liiam89
@liiam89
Jan 27 2016 02:52
Okay, I guess I'm not getting help then.
Ken Haduch
@khaduch
Jan 27 2016 02:52

@ddeason37 - you

@khaduch So I would need to loop through the array if there is more than one key passed via source

Yes, at least the way that I solved it, there were nested loops. One that is looping through the 'collection', and that is the outer loop because you want to make sure that you examine each object in that array. The inner loop has to look at each property in the source, and see if it exists in the particular collection object that you are examining, and if it has the same value. So you have to keep track of the comparisons for all of the properties of source, hence an inner for loop, and some 'bookkeeping' of matches or misses to decide if you have it all. I don't know if that gives you enough to go on, but you have to think of looping through the source object properties for each object in the collection. Pseudocode for the basic idea:

var keys = Object.keys(source);

for (var i = 0; i < collection.length; i++) {
    // some kind of variables to store intermediate results
    for ( var j = 0; j < keys.length; j++) {
        // does this key exists in the current collection object, i.e. collection[i]
        // if the key exists, does it have the same value?
         // if the key does not exist, this is not a match, if the value does not match, it is not a match
    } /// end inner loop
} // end outer looop
Hank Janssens
@therealdeveloper
Jan 27 2016 02:52
Maybe I just need it reworded
I don't want the answer.
Bill
@kirah1314
Jan 27 2016 02:53
@therealdeveloper short answer: the challenge asks to use those parameters as part of a string
Ken Haduch
@khaduch
Jan 27 2016 02:53
@liiam89 - sorry, I was trying to help someone else... takes time! What's your question (I'll search backwards if you posted it already)
cannelflow
@cannelflow
Jan 27 2016 02:54
@therealdeveloper use those parameter to make a sentence
KyleFolk
@KyleFolk
Jan 27 2016 02:55
testObj.Montana
oops

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

Ken Haduch
@khaduch
Jan 27 2016 02:56
@liiam89 - is this the "convert fahrenheit to celcius" challenge?
KyleFolk
@KyleFolk
Jan 27 2016 02:56
Use the playerNumber variable to lookup player 16 in testObj using bracket notation. not sure whats wrong with my code?
DJ Bondoc
@DJBondoc
Jan 27 2016 02:57
is there any difference with / /g and /\s+g ?
Bill
@kirah1314
Jan 27 2016 02:57
@KyleFolk you have to use playerNumber as a variable instead of the number 16 after you assigned a number to it
liiam89
@liiam89
Jan 27 2016 02:58
@khaduch No. I finished that challenge. I decided to take that knowledge and try to implement it into the browser environment because I seem to have the most trouble there. I find that writing code in the console doesn't translate easily for me into the browser.
Shalmali Padgaokar
@Shalmalidp
Jan 27 2016 02:58
@cannelflow : I got it workingin the console now got to write the code for it
Ken Haduch
@khaduch
Jan 27 2016 02:59
@liiam89 - okay I see. It's a good thing to get more comfortable with that aspect of it. Do you have a CodePen link to post?
cannelflow
@cannelflow
Jan 27 2016 02:59
@Shalmalidp can you pass me the code
liiam89
@liiam89
Jan 27 2016 02:59
No
I have an account, though.
Ken Haduch
@khaduch
Jan 27 2016 03:00
okay, I'll try to walk through this. You must have some HTML somewhere to go along with it?
liiam89
@liiam89
Jan 27 2016 03:00
Yes.
Ken Haduch
@khaduch
Jan 27 2016 03:03
@liiam89 - can you post the HTML? I can set up a jsfiddle page and test it. Or use the link you just posted.
liiam89
@liiam89
Jan 27 2016 03:03
@khaduch It's there. I made the codepen.
Ken Haduch
@khaduch
Jan 27 2016 03:04
so it looks like it might be working there? At least it produces a result and it doesn't disappear?
unless I misunderstood the problem you were having?
liiam89
@liiam89
Jan 27 2016 03:05
That's right. @khaduch
I wanna know why this one doesn't work.
@khaduch This version does not return false at the end of the function.
Kevin Myrick
@aphextwin234
Jan 27 2016 03:08
How would write a script that prints the prime numbers between 1 and 1999 in a table that consists of 10 columns?
Ken Haduch
@khaduch
Jan 27 2016 03:10
@liiam89 - ah! I think that you have to ready about the default action of a submit button. There is something (which I haven't looked at lately) that if you do a submit, it will try to do something like a GET to reload the page. If you prevent the default action (I remember something about a function e.preventDefault(); ??) this page: http://www.w3schools.com/jsref/event_preventdefault.asp talks about it. Submitting a form has a default action, so you are stopping it with the "return false;"
Shalmali Padgaokar
@Shalmalidp
Jan 27 2016 03:10
@cannelflow sure the console one right ??
Mike Baker
@Bakermg
Jan 27 2016 03:11
@camperbot commands
liiam89
@liiam89
Jan 27 2016 03:11
@khaduch I see. Do you ever work in the browser to the extent that you pass values to and from forms?
Mike Baker
@Bakermg
Jan 27 2016 03:12
@camperbot help
Shalmali Padgaokar
@Shalmalidp
Jan 27 2016 03:13
@cannelflow
var a= []
undefined
function fact(num){

for (var i =1; i <= num ; i++){

a.push(i);
}
return a;

}

fact(10);
var b = a.reduce(function(p,c){

return p * c;
});
North847
@north847
Jan 27 2016 03:13
o7 Hello! Looking for help on "Stand-in-line"
Ken Haduch
@khaduch
Jan 27 2016 03:13
I have done that in the past. @liiam89 - haven't done it lately. I'm not sure how you access the values in the POST and GET requests from within javascript, although googling should tell you. In this case, your "return false" is probably the way to go, because you really do not want to go though an entire HTTP transaction for something that you are doing strictly on the client side.
Shalmali Padgaokar
@Shalmalidp
Jan 27 2016 03:13
thats working in the console getting the correct factoral value
liiam89
@liiam89
Jan 27 2016 03:13
@khaduch My understanding is that if I actually had a form connected to a back end, returning false would actually prevent the form and information from being submitted. So, is using return false just a way to work on forms with JavaScript without having to be connected to a backend? How do other people work around this problem?
Ah okay thanks @khaduch
CamperBot
@camperbot
Jan 27 2016 03:13
liiam89 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star: 432 | @khaduch | http://www.freecodecamp.com/khaduch
Kevin Myrick
@aphextwin234
Jan 27 2016 03:14
I'm thinking I have to document.write all these <td><tr> + make like an array to hold these prime numbers. Man hehe.
Ken Haduch
@khaduch
Jan 27 2016 03:15
@liiam89 - yes (I see that you saw my answer.) I've done some work with PHP and having it process the form data on the server side, to interact with a database, etc. It would be interesting to see if you could do it on the client side, but it should not really be necessary, since you would just be fetching the same information and re-using it?
North847
@north847
Jan 27 2016 03:15
function queue(arr, item) {
  // Your code here


  return item([],1);  // Change this line

}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(queue(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
I have been wrestling with this for a while. I'm not sure what method to use for the array. Can someone help point me to the right direction?
this is for "stand in line"
liiam89
@liiam89
Jan 27 2016 03:18
@khaduch Okay, well I appreciate your time. Working with JavaScript in the console on Codecademy or Free Code Camp is not really comparable to working with it in the browser. I'm curious, at any point, does Free Code Camp get into more detail in regards to working with JavaScript in the browser?
Ken Haduch
@khaduch
Jan 27 2016 03:19
@aphextwin234 - that's probably what you need to do - using a javascript function or functions to take the numbers and generate the table. If you are interested in doing it on your own. There are probably some javascript libraries out there that you could pass your array of data to and have it generate the table markup - but you probably don't want that, I'm guessing?
James
@JamesR93
Jan 27 2016 03:20
Can someone help me with a freecodecamp problem
Ken Haduch
@khaduch
Jan 27 2016 03:21
@liiam89 - I haven't gone far enough, but I think that it will be somewhere down the down the list with the 'full-stack" development stuff - using Node.js as the server side engine. At least that is what it looks like.
@JamesR93 - we can try, James... what is your problem?
James
@JamesR93
Jan 27 2016 03:22
I'm on the Record Collection problem where i have to write a function to add in missing information to a JSON object representing a record collection.
I'm not sure where to start @khaduch
Kevin Myrick
@aphextwin234
Jan 27 2016 03:24
```
```
function printTable(){
var html="";
var html="<table><colgroup span=\"3\" width=\"20%\"";
html+="<tr><th>Name</th><th>Location</th><th>Height (in meters)</th></tr>";
html+="<tr><td>Angel (upper fall)</td><td>Venezuela</td><td>807</td></tr>";
html+="<tr><td>Itatinga</td><td>Brazil</td><td>628</td></tr>";
html+="<tr><td>Cuquenan</td><td>Guyana/Venezuela</td><td>610</td></tr>";
html+="<tr><td>Ormeli</td><td>Norway</td><td>563</td></tr>";
html+="<tr><td>Tysse</td><td>Norway</td><td>533</td></tr>";
html+="<tr><td>Pilao</td><td>Brazil</td><td>524</td></tr>";
html+="<tr><td>Ribbon</td><td>USA</td><td>491</td></tr>";
html+="<tr><td>Vestre Mardola</td><td>Norway</td><td>468</td></tr>";
html+="<tr><td>Kaieteur</td><td>Guyana</td><td>457</td></tr>";
html+="<tr><td>Cleve-Garth</td><td>New Zealand</td><td>450</td></tr>";
html+="</table>";
Ken Haduch
@khaduch
Jan 27 2016 03:25
I cannot recall the exact statement of that problem, @north847 - but basically they want the queue to act as a "line", similar to a line going to a bank teller or movie ticket window. So you need to be able to add an element to the end of the line (array) and take one from the beginning of the line (array) and return that. They are passing the array in, along with the item to be added to the end of the line. You might want to review (or recall) the challenges for manipulating arrays with push, pop, shift and unshift to see which functions would do what you need for this problem?
p funk
@prodigalFUNK
Jan 27 2016 03:25
anyone who has done the Profile Lookup problem, should I be using a series of if/else statements or is this meant to be done with for loops?
Shalmali Padgaokar
@Shalmalidp
Jan 27 2016 03:25
@cannelflow can i private msg you
Wilson Heres
@hereswilson
Jan 27 2016 03:25
what does it mean to return undefined? like null or just blank?
Chris Crook
@chrisisacrook
Jan 27 2016 03:28
undefined is a property in javascript. it's a reserved word
which waypoint are you on @hereswilson
Andrew Conley
@aconman1287
Jan 27 2016 03:29
Hey gang, I'm trying to solve the 'stand in line' problem but am not sure where I'm going wrong. I'm trying to add a new item and delete the first. Then return the deleted item from the array.
function queue(arr, item) {
  arr.push(item);
  arr.shift();// Your code here

  return arr.shift();  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(queue(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
Wilson Heres
@hereswilson
Jan 27 2016 03:29
@chrisisacrook I'm on the missing letters bonfire. I got the letters to return, but it's returning a red dot when there aren't any letters missing.
Brian
@sludge256
Jan 27 2016 03:30
@aconman1287 you're shifting twice
p funk
@prodigalFUNK
Jan 27 2016 03:30
@aconman1287 delete arr.shift() on the 3rd line
jeevitha
@jeevithajeev
Jan 27 2016 03:30
hello!...can someone help me figure out:convert celcius to fahrenheit
Andrew Conley
@aconman1287
Jan 27 2016 03:31
@sludge256 @prodigalFUNK Thanks so much! Worked.
CamperBot
@camperbot
Jan 27 2016 03:31
aconman1287 sends brownie points to @sludge256 and @prodigalfunk :sparkles: :thumbsup: :sparkles:
:star: 226 | @prodigalfunk | http://www.freecodecamp.com/prodigalfunk
:star: 1068 | @sludge256 | http://www.freecodecamp.com/sludge256
Ken Haduch
@khaduch
Jan 27 2016 03:31

@JamesR93

I'm on the Record Collection problem where i have to write a function to add in missing information to a JSON object representing a record collection.

OK - the basics are that you have this collection of objects, and the objects represent music record albums of various famous artists. They are going to give you some information as parameters to a function, you are to update the collection with the new information as they specify. They give you an 'id', which is going to be the id of one of the existing entries. Then a property and a value to be added or updated in some way. You have to make sure that you know how to access the properties of an object - sometimes you can use the "dot" notation, as in "obj.prop", other times you have to use bracket notation, as in "obj[prop]" - those are key things.

Wilson Heres
@hereswilson
Jan 27 2016 03:31
@chrisisacrook nevermind, figured it out
James
@JamesR93
Jan 27 2016 03:37
@khaduch - Got it figured out! Thanks so much. After your little tip, I got it right away. Awesome!
CamperBot
@camperbot
Jan 27 2016 03:37
jamesr93 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star: 433 | @khaduch | http://www.freecodecamp.com/khaduch
Ken Haduch
@khaduch
Jan 27 2016 03:38

@JamesR93 - with this exercise in view, it might be helpful to go back and review the exercises that preceded this one, the ones about building Javascript objects, dot notation, bracket notation, etc.

Okay - that's great! The thing is that you had the pieces in the lessons, it's just a matter of putting them together. Good work!

jeevitha
@jeevithajeev
Jan 27 2016 03:40
can someone help me with converting celsius to fahrenheit
Shalmali Padgaokar
@Shalmalidp
Jan 27 2016 03:41
@jeevithajeev what question are you on
jeevitha
@jeevithajeev
Jan 27 2016 03:42
@Shalmalidp convert celsius to fahrenheit
@Shalmalidp basic javascript
Shalmali Padgaokar
@Shalmalidp
Jan 27 2016 03:42
show me your code so far @jeevithajeev
jeevitha
@jeevithajeev
Jan 27 2016 03:43

@Shalmalidp function convert(celsius) {
// Only change code below this line
fahrenheit= celcius*(9/5)+32;

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

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

Shalmali Padgaokar
@Shalmalidp
Jan 27 2016 03:44
@jeevithajeev use BODMAS for your brackets
North847
@north847
Jan 27 2016 03:44
@khaduch Thanks! Right now I'm working on using the Shift(). After removing my code and resetting the lower quadrant of the instructions have disappeared. Is this normal?
CamperBot
@camperbot
Jan 27 2016 03:44
north847 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star: 434 | @khaduch | http://www.freecodecamp.com/khaduch
Brian Daub
@briandaub
Jan 27 2016 03:44
Can someone help me out on the Profile lookup waypoint? I guess I am not understanding why contacts[j].firstName will return the value of the key "firstName" but contacts[j].property doesn't return the value of the "likes" key
Here is my code
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUp(firstName, prop){
// Only change code below this line
    var fName = firstName;
    var property = prop;

    console.log(prop);

    for(var i = 0; i < contacts.length; i++) {
       for(var j = i + 1; j < contacts.length; j++) {
           console.log(contacts[j].firstName + " " + contacts[j].property);
           if(contacts[j].fName !== firstName){
              return "No such contact";
           } else if (contacts[j].property !== prop) {
              return "No such property";
           } else {
              return contacts[j].fName + " " + contacts[j].property;
           }
       }
    }
// Only change code above this line
}

// Change these values to test your function
lookUp("Akira", "likes");
Shalmali Padgaokar
@Shalmalidp
Jan 27 2016 03:45
@jeevithajeev var fahrenheit = ((celsius *9)/5)+32;
jeevitha
@jeevithajeev
Jan 27 2016 03:46
@Shalmalidp thank you it worked
CamperBot
@camperbot
Jan 27 2016 03:46
jeevithajeev sends brownie points to @shalmalidp :sparkles: :thumbsup: :sparkles:
:star: 250 | @shalmalidp | http://www.freecodecamp.com/shalmalidp
Ken Haduch
@khaduch
Jan 27 2016 03:48

@north847

@khaduch Right now I'm working on using the Shift(). After removing my code and resetting the lower quadrant of the instructions have disappeared. Is this normal?

You reset your code that you entered? I don't know if it's normal for the instructions to disappear? Where are you with the code?

Shalmali Padgaokar
@Shalmalidp
Jan 27 2016 03:48
@jeevithajeev your VW
Brian Daub
@briandaub
Jan 27 2016 03:49
bonfire Profile lookup help
CamperBot
@camperbot
Jan 27 2016 03:49
Sorry, can't find a bonfire called profile lookup help. [ Check the map? ]
Brian Daub
@briandaub
Jan 27 2016 03:50
waypoint Profile lookup help
cannelflow
@cannelflow
Jan 27 2016 03:50
@Shalmalidp np
Farhan
@farhansRepo
Jan 27 2016 03:50
Hi , I am looking for some help in the Basic JavaScript exercise called record collection.
Paul
@PJonestown
Jan 27 2016 03:50
@briandaub What've you got so far?
Brian Daub
@briandaub
Jan 27 2016 03:51
challenge Profile lookup help
Satchmo37
@Satchmo37
Jan 27 2016 03:51
```
Brian Daub
@briandaub
Jan 27 2016 03:51
I just posted my code a min ago
Paul
@PJonestown
Jan 27 2016 03:51
Okay one sec
Satchmo37
@Satchmo37
Jan 27 2016 03:51
function where(collection, source) {
  var arr = [];
  // Store the key value from the object source, if there are multiple values
  //they are stored in an array
  var key = Object.keys(source);

  //Create a loop to itterate through the collection
  for(var i = 0; i < collection.length; i++){

    //Create a loop to itterate through the keys that have been stored
    //in an array
    for(var k = 0; k <key.length; k++){

      //Check to see if the key value from collection matches the source
      //This will fail if there is more than 1 key value
      if (collection[i][key] === source[key[k]]){
       arr.push(collection[i]);


      } else if (collection[i][key[k]] === source[key[k]]);
        arr.push(collection[i]);
      }

    }
  return arr;
}

where([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 });
This is just killing me, my second conditional is returning all the values in the object
Brian Daub
@briandaub
Jan 27 2016 03:51
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUp(firstName, prop){
// Only change code below this line
    var fName = firstName;
    var property = prop;

    console.log(property);

    for(var i = 0; i < contacts.length; i++) {
       for(var j = i + 1; j < contacts.length; j++) {
           console.log(contacts[j].firstName + " " + contacts[j].property);
           if(contacts[j].fName !== firstName){
              return "No such contact";
           } else if (contacts[j].property !== prop) {
              return "No such property";
           } else {
              return contacts[j].fName + " " + contacts[j].property;
           }
       }
    }
// Only change code above this line
}

// Change these values to test your function
lookUp("Akira", "likes");
cannelflow
@cannelflow
Jan 27 2016 03:52
@Shalmalidp thank you and sry i was away
CamperBot
@camperbot
Jan 27 2016 03:52
cannelflow sends brownie points to @shalmalidp :sparkles: :thumbsup: :sparkles:
:star: 251 | @shalmalidp | http://www.freecodecamp.com/shalmalidp
Ken Haduch
@khaduch
Jan 27 2016 03:52
@briandaub - you should review the lessons on accessing elements of he object with dot notation, bracket notation, and variables. But basically, if you have a name of a property in a variable, dot notation doesn't work. (That's a hint)
Brian Daub
@briandaub
Jan 27 2016 03:52
contacts[j].fName will return the firstName, but contacts[j].property will return undefined
Farhan
@farhansRepo
Jan 27 2016 03:53

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

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

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

  if (collection[id].hasOwnProperty("tracks") === false) {
    collection[id][prop] = value;

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

} else {

  delete collection[id][prop];
}

return collection;
}

// Alter values below to test your code
update(2548, "artist", "");
'''

CamperBot
@camperbot
Jan 27 2016 03:53
:bulb: to format code use backticks! ``` more info
venit2
@venit2
Jan 27 2016 03:53
Hello, anyone able to point me in direction of what I am doing wrong with this problem?
Farhan
@farhansRepo
Jan 27 2016 03:54

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

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

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

  if (collection[id].hasOwnProperty("tracks") === false) {
    collection[id][prop] = value;

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

} else {

  delete collection[id][prop];
}

return collection;
}

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

'''

CamperBot
@camperbot
Jan 27 2016 03:54
:bulb: to format code use backticks! ``` more info
venit2
@venit2
Jan 27 2016 03:55
I am working on "Passing Values to Functions with Arguments"
Andrew Conley
@aconman1287
Jan 27 2016 03:55
@farhansRepo Its the key just to the left of "1" or above tab on your keyboard
Should have a tilde and the backtick
cannelflow
@cannelflow
Jan 27 2016 03:55
@venit2 tried something ?
Farhan
@farhansRepo
Jan 27 2016 03:55
thanks @aconman1287
CamperBot
@camperbot
Jan 27 2016 03:55
farhansrepo sends brownie points to @aconman1287 :sparkles: :thumbsup: :sparkles:
:star: 183 | @aconman1287 | http://www.freecodecamp.com/aconman1287
Ken Haduch
@khaduch
Jan 27 2016 03:56

@briandaub

contacts[j].fName will return the firstName, but contacts[j].property will return undefined

The thing is that "fName" is actually a property of the object. But the input argument "prop" is not the name of an object - it contains a name of a property. Hence the use of bracket notation, as the lessons describe. In particular, this one should have the info: http://www.freecodecamp.com/challenges/accessing-objects-properties-with-variables

venit2
@venit2
Jan 27 2016 03:56
I created the function as follows but it doesn't seem to add, instead i get a range error: maximum call stack size excceded
function myFunction(a, b) {
console.log(a + b);
}
Farhan
@farhansRepo
Jan 27 2016 03:56
// Setup
var collection = {
    2548: {
      album: "Slippery When Wet",
      artist: "Bon Jovi",
      tracks: [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    2468: {
      album: "1999",
      artist: "Prince",
      tracks: [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    1245: {
      artist: "Robert Palmer",
      tracks: [ ]
    },
    5439: {
      album: "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

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

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

      if (collection[id].hasOwnProperty("tracks") === false) {
        collection[id][prop] = value;

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

   } else {

      delete collection[id][prop];
    }

  return collection;
}

// Alter values below to test your code
update(2548, "artist", "");
Brian
@sludge256
Jan 27 2016 03:56
@venit2 try refreshing the page or restarting your browser
Ken Haduch
@khaduch
Jan 27 2016 03:57
@venit2 - how are you using that function?
venit2
@venit2
Jan 27 2016 03:57
@sludge256 thanks, that fixed it
CamperBot
@camperbot
Jan 27 2016 03:57
venit2 sends brownie points to @sludge256 :sparkles: :thumbsup: :sparkles:
:star: 1069 | @sludge256 | http://www.freecodecamp.com/sludge256
Farhan
@farhansRepo
Jan 27 2016 03:57
i need help with this exersise please. Basic javascript - record collection
Farhan
@farhansRepo
Jan 27 2016 04:03
anyone?
aikatarine
@aikatarine
Jan 27 2016 04:06
// Setup
function abTest(a, b) {
  // Only change code below this line
  if (a, b < 0) {
    return "undefined";
  } 
  // 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);
I'm trying to complete "Return Early Pattern for Functions." What did I do wrong?
cannelflow
@cannelflow
Jan 27 2016 04:06
@aikatarine return undefined not "undefined"
venit2
@venit2
Jan 27 2016 04:07
@farhansRepo I think the 2nd if statement might be incorrect, it says to check prop, not if there is a prop named tracks already?
aikatarine
@aikatarine
Jan 27 2016 04:07
@cannelflow Just tried that and it didn't work
cannelflow
@cannelflow
Jan 27 2016 04:07
@aikatarine and @venit2 is right you need ||
@aikatarine (a<0||b<0)
aikatarine
@aikatarine
Jan 27 2016 04:08
@cannelflow Got it! Thanks!
CamperBot
@camperbot
Jan 27 2016 04:08
aikatarine sends brownie points to @cannelflow :sparkles: :thumbsup: :sparkles:
:star: 584 | @cannelflow | http://www.freecodecamp.com/cannelflow
Paul
@PJonestown
Jan 27 2016 04:10
@farhansRepo I'm having trouble understanding how you're trying to accomplish the task. I think it needs a total re-write. Try just getting this "If value is non-blank (value !== "") and prop is not "tracks" then update or set the value for the prop." to pass and post that code and we can take it from there
Brian Daub
@briandaub
Jan 27 2016 04:10
Ok so now contacts[j][property] works, but contacts[j].fName does not. My loop isn't iterating. It just keeps producing the same firstName, in this case Harry. So what am I doing wrong with my loop?
Farhan
@farhansRepo
Jan 27 2016 04:12
@PJonestown Yes I shall re
re-write
I basically have made a mess of it as I have re-written it many times
Paul
@PJonestown
Jan 27 2016 04:13
@farhansRepo Just try to get that first one to pass. Even if it's wrong, it will be much simpler to help you out by breaking the problem into smaller bits
@briandaub I meant to ask this earlier, but why did you make an fname and property variable?
Jonathan Thompson
@Jon-thomps
Jan 27 2016 04:15
anyone working on cesar's cipher?
Farhan
@farhansRepo
Jan 27 2016 04:16
my solution had the first and 3rd passed
the problem was when i altered my code then only the 2nd and 4th passed
Brian Daub
@briandaub
Jan 27 2016 04:18
I dont really need the fName var but when I was trying to use the value of prop as dot notation I stuck it in a var
Doesnt matter I was doing it wrong either way
venit2
@venit2
Jan 27 2016 04:18
@farhansRepo in the instructions it wants you to check the parameter if it is tracks, you are check if it is already in the collection.
Brian Daub
@briandaub
Jan 27 2016 04:19
But my loop still wont work, just keeps returning Harry
Paul
@PJonestown
Jan 27 2016 04:20
if collection[id].hasOwnProperty("tracks")) {
This will always return true since all those objects have that property. You want to check if the passed in prop paramater is tracks
Farhan
@farhansRepo
Jan 27 2016 04:20
// Only change code below this line
function update(id, prop, value) {



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

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

  } else {

    delete collection[id][prop];
  }

  return collection;
}

// Alter values below to test your code
update(2548, "artist", "");
The first if statement satisfies the first and 3rd tests
If I delete the others it doesn't make a difference
Basic JavaScrip - Record Collection Exercise
Paul
@PJonestown
Jan 27 2016 04:25
@farhansRepo Okay so for the first test to pass you need to make sure that value is not an empty string
It doesn't appear that you do that anywhere which is what confused me about your first program
Ken Haduch
@khaduch
Jan 27 2016 04:26
@briandaub - did you post updated code?
Paul
@PJonestown
Jan 27 2016 04:27
It also asks that prop != tracks
```
collection[id].hasOwnProperty("tracks") === false
collection[id].hasOwnProperty("tracks") === false
doesn't do that. What you're doing is checking if the object with id has the property tracks
This will always return true
Farhan
@farhansRepo
Jan 27 2016 04:29
ah
Paul
@PJonestown
Jan 27 2016 04:29
Actually the code I posted will always be false
```
collection[id].hasOwnProperty("tracks")
will always be true
I'm doing a bad job explaining this. Sorry man I'm tipsy
Farhan
@farhansRepo
Jan 27 2016 04:30
np
matthew3454
@matthew3454
Jan 27 2016 04:31
Can Someone help me on the activity Accessing Nested Arrays in JSON?
Brian Daub
@briandaub
Jan 27 2016 04:32
SO I guess nobody is willing to help me?
Farhan
@farhansRepo
Jan 27 2016 04:32
I could I think I did that one
sloo012
@sloo012
Jan 27 2016 04:33
Hi, Why is my button not working??
Farhan
@farhansRepo
Jan 27 2016 04:33
@matthew3454
Brian Daub
@briandaub
Jan 27 2016 04:33
I always seem to find it difficult to get help in here. I am not sure why. I am always happy to help when others need it and I know how to help them.
venit2
@venit2
Jan 27 2016 04:33
@briandaub what are you working on?
Brian Daub
@briandaub
Jan 27 2016 04:34
Profile lookup
matthew3454
@matthew3454
Jan 27 2016 04:34
This message was deleted
this is what I have so far @farhansRepo
// Setup
var myPlants = [
  { 
    type: "flowers",
    list: [
      "rose",
      "tulip",
      "dandelion"
    ]
  },
  {
    type: "trees",
    list: [
      "fir",
      "pine",
      "birch"
    ]
  }  
];

// Only change code below this line

var secondTree = myPlants.trees.list.[2] ; // Change this line
venit2
@venit2
Jan 27 2016 04:34
@briandaub what question do you have about the lookup?
Farhan
@farhansRepo
Jan 27 2016 04:34
the dot after list
delete it
matthew3454
@matthew3454
Jan 27 2016 04:35
@farhansRepo okay
Farhan
@farhansRepo
Jan 27 2016 04:35
it should be list2
Brian Daub
@briandaub
Jan 27 2016 04:35
I have scoured Stackoverflow and google to find my mistake and dont seem to be connecting the dots
Farhan
@farhansRepo
Jan 27 2016 04:35
list[2]
Brian Daub
@briandaub
Jan 27 2016 04:35
Why is my nested for loop not iterating through my contacts?
Here is my code again
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


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

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

           console.log(contacts[j].firstName + " " + contacts[j][prop]);

           if(contacts[j].firstName !== firstName){
              return "No such contact";
           } else if (contacts[j][prop] !== prop) {
              return "No such property";
           } else {
              return contacts[j].firstName + " " + contacts[j][prop];
           }
       }
    }
// Only change code above this line
}

// Change these values to test your function
lookUp("Akira", "likes");
Ken Haduch
@khaduch
Jan 27 2016 04:36
@briandaub - please post your updated code?
matthew3454
@matthew3454
Jan 27 2016 04:36
@farhansRepo I did it. it now says "cannot read property 'list' of undefined."
David Vu
@Dview17
Jan 27 2016 04:36
@sloo012 Quick question, don't you need to reference the javascript in the html header?
matthew3454
@matthew3454
Jan 27 2016 04:37
// Setup
var myPlants = [
  { 
    type: "flowers",
    list: [
      "rose",
      "tulip",
      "dandelion"
    ]
  },
  {
    type: "trees",
    list: [
      "fir",
      "pine",
      "birch"
    ]
  }  
];

// Only change code below this line

var secondTree = myPlants.trees.list[2];
 ; // Change this line
sloo012
@sloo012
Jan 27 2016 04:37
@Dview17 no.. It's autometic You can also add javascript libraries in the setting
Brian
@sludge256
Jan 27 2016 04:38
It's a CodePen thing
if you click on the little gear icons you can add external "files"
David Vu
@Dview17
Jan 27 2016 04:38
@matthew3454 My plants is an array, gotta reference the 2nd object in the array first ... so myPlants1.trees...
Ken Haduch
@khaduch
Jan 27 2016 04:38
@briandaub - your inner loop is not processing the proper information. (Unless I've lost track of which problem you are doing) contacts[i].length probably does not give you anything sensible, because contacts[i] is not an array.
Brian Daub
@briandaub
Jan 27 2016 04:39
No you are right I forgot I had put that in there
So then how am I supposed to loop through each object in contacts?
matthew3454
@matthew3454
Jan 27 2016 04:40
@Dview17 like this?var secondTree = myPlants1.trees.list[2];
Brian Daub
@briandaub
Jan 27 2016 04:40
if not with contacts[][]
David Vu
@Dview17
Jan 27 2016 04:41
@matthew3454 put the brackets to myPlants [ 1 ]. trees
Brian Daub
@briandaub
Jan 27 2016 04:41
Contacts is an object filled with objects and should be treated like a multidimensional array. Right?
David Vu
@Dview17
Jan 27 2016 04:41
@sloo012 I got the timer working by inserting $(document).ready(function(){ your code });
@sloo012 although, now I don't know how to stop it...
matthew3454
@matthew3454
Jan 27 2016 04:42
@Dview17 var secondTree = myPlants[1].treeslist[2];
@Dview17 var secondTree = myPlants[1].trees.list[2];
Ken Haduch
@khaduch
Jan 27 2016 04:43

your outer loop is giving you each contact in turn, to be accessed by contact[i]. When you have contact[i], you can then access the properties of it by the code:

contacts[i].fName // if you are looking for the fName
contacts[i][prop] // for the property that is being passed in as the argument.

Now you might have to check if the property exists first, but you don't need that inner loop for this problem.

David Vu
@Dview17
Jan 27 2016 04:44
@matthew3454 var secondTree = myPlants1.list1
@matthew3454 how do you make it type in code?
matthew3454
@matthew3454
Jan 27 2016 04:45
put and around it.
@Dview17
put three back ticks around it
on each side
sloo012
@sloo012
Jan 27 2016 04:45
@Dview17 stop function is still not avaialble
Farhan
@farhansRepo
Jan 27 2016 04:46
@Dview17 you surround the code with and
David Vu
@Dview17
Jan 27 2016 04:46
@matthew3454
var secondTree = myPlants[1].list[1]
Ken Haduch
@khaduch
Jan 27 2016 04:46

@briandaub - then what you have to keep in mind is that you are searching for a contact in the list of contacts, searching by the first name, and you might not know until you've looked at all of them whether or not the person exists. If you did not find the person, then you return "No such contact". If you find the person, then you can look at the requested property and return the value, or return "no such property", etc.

(Sorry if I got confused about which problem was being worked on - trying to help more than one person at a time gets confusing!)

Alex Rose
@thelyricalrose
Jan 27 2016 04:47
can anybody help me with the Seek and Destroy challenge?
Brian Daub
@briandaub
Jan 27 2016 04:47
Ok well thats where my confusion is clearly. Since its an object filled with objects I thought it was treated the same as a two dimensional array.
sloo012
@sloo012
Jan 27 2016 04:47
@thelyricalrose go to helpboldfires section
matthew3454
@matthew3454
Jan 27 2016 04:47
@Dview17 Wow. Thanks.
CamperBot
@camperbot
Jan 27 2016 04:47
matthew3454 sends brownie points to @dview17 :sparkles: :thumbsup: :sparkles:
:star: 227 | @dview17 | http://www.freecodecamp.com/dview17
CamperBot
@camperbot
Jan 27 2016 04:47
type bonfire name to get some info on that bonfire. And check HelpBonfires chatroom
David Vu
@Dview17
Jan 27 2016 04:48
@matthew3454 No problem. Did you understand why it works?
rajesh304
@rajesh304
Jan 27 2016 04:48
hello all
where i go as beginner, i need help
Alex Rose
@thelyricalrose
Jan 27 2016 04:48
@sloo012 thank you, I did not know there was a separate room for it
CamperBot
@camperbot
Jan 27 2016 04:48
thelyricalrose sends brownie points to @sloo012 :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for sloo012
Brian Daub
@briandaub
Jan 27 2016 04:48
Yeah taking out the inner loop didn't help
matthew3454
@matthew3454
Jan 27 2016 04:48
@Dview17 So when he instructions ask to retrieve the second tree they don't necessarily need you to specify the exact tree from the list?
Brian Daub
@briandaub
Jan 27 2016 04:49
I am still only getting one value, it's not looping through each contact
Ken Haduch
@khaduch
Jan 27 2016 04:49
@briandaub - ok, that can be confusing. In this case, you get an object - "each" object, with your first for loop, then it is a matter of examining it for the first name match, and if the first nme matches, then examine it for the request property. Iterate until you find a match or find no matches.
David Vu
@Dview17
Jan 27 2016 04:50
@matthew3454 we referenced the 2nd object in the myPlants array (the object having type and list properties). We just wanted to get the list property, not the type property.
Brian Daub
@briandaub
Jan 27 2016 04:50
I dont know what you are talking about
venit2
@venit2
Jan 27 2016 04:50
@briandaub your return statements are shorting your inner loop
Ken Haduch
@khaduch
Jan 27 2016 04:50
@briandaub - I'm going to have to stop soon - want to see if you get any closer to the answer, I'll be here for about 15 minutes more...?
Brian Daub
@briandaub
Jan 27 2016 04:50
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


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

    for(var i = 0; i < contacts.length; i++) {
       console.log(contacts[i].firstName);

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

    }
// Only change code above this line
}

// Change these values to test your function
lookUp("Akira", "likes");
this doesnt iterate
Its doing the same thing as before when I had nested for loops
venit2
@venit2
Jan 27 2016 04:51
@briandaub your inner loop i think is shorting on the returns.
matthew3454
@matthew3454
Jan 27 2016 04:52
@Dview17 I think I understand now. Also the 1 is actually like a 2 right? and a 0 a 1?
Brian Daub
@briandaub
Jan 27 2016 04:52
Why are nested objects not handled like two dimensional arrays?
Josiah Anderson
@Josiahdanderson
Jan 27 2016 04:52
Hi I'm stuck on the javascript waypoint "Return Early Pattern for Functions". I've tried switches and if else statements. I just don't know where to put the return statement. Or if i'm supposed to actually make a string that says undefined or if that's something that will happen naturally when the function exits at the return. Please help! I'm lost.
Ken Haduch
@khaduch
Jan 27 2016 04:52
@briandaub - are you seeing the first names printed in the console.log? It looks like you have code to do that. Let's see if I can write up some pseudocode for this - short of giving you the exact answer (or something that will work) it would be good if you could just get a pointer in the right direction...
rajesh304
@rajesh304
Jan 27 2016 04:52
i need help with "word blanks"...can anyone help?
David Vu
@Dview17
Jan 27 2016 04:52
@matthew3454 yup, it can get confusing to start counting from 0.
Astha Sharma
@asthas
Jan 27 2016 04:54
@Josiahdanderson send your code
Brian Daub
@briandaub
Jan 27 2016 04:54
I would just like straight forward discussion about how to iterate through nested objects
Clearly thats the point I am missing.
Josiah Anderson
@Josiahdanderson
Jan 27 2016 04:55
// Setup
function abTest(a, b) {
  // Only change code below this line
switch (a,b) {
  case a < 0:
  case b < 0:
    return "undefined";
}
matthew3454
@matthew3454
Jan 27 2016 04:55
@Dview17 I appreciate the clarification. Thanks again.
CamperBot
@camperbot
Jan 27 2016 04:55
matthew3454 sends brownie points to @dview17 :sparkles: :thumbsup: :sparkles:
:warning: matthew3454 already gave dview17 points
Astha Sharma
@asthas
Jan 27 2016 04:55
@briandaub hey there is a problem with your if else logic
rphares
@rphares
Jan 27 2016 04:55
@Josiahdanderson , so a few things,
Astha Sharma
@asthas
Jan 27 2016 04:56
@Josiahdanderson please give the name of the challenge
Brian Daub
@briandaub
Jan 27 2016 04:56
...
rphares
@rphares
Jan 27 2016 04:56
right now, you are returning the string"undefined",
Brian Daub
@briandaub
Jan 27 2016 04:56
@asthas thanks want to explain?
Josiah Anderson
@Josiahdanderson
Jan 27 2016 04:56
its "Return Early Pattern for Functions"
CamperBot
@camperbot
Jan 27 2016 04:56
briandaub sends brownie points to @asthas :sparkles: :thumbsup: :sparkles:
:star: 256 | @asthas | http://www.freecodecamp.com/asthas
rphares
@rphares
Jan 27 2016 04:56
undefined is a special value, you want to return the value, not a string, @Josiahdanderson :blush:
venit2
@venit2
Jan 27 2016 04:56
@briandaub actually I think the problem is console.log inside a loop,
Brian Daub
@briandaub
Jan 27 2016 04:57
Getting help in here is like pulling teeth
Brian Daub
@briandaub
Jan 27 2016 04:57
Why would that be a problem?
venit2
@venit2
Jan 27 2016 04:57
because it doesnt do the console log til end
rphares
@rphares
Jan 27 2016 04:57
Also, its usually solved with an if conditional, @Josiahdanderson , with the logic if(a is less than zero OR b is less than zero) @Josiahdanderson :blush:
venit2
@venit2
Jan 27 2016 04:57
so it just repeasts the last item for a console log
Astha Sharma
@asthas
Jan 27 2016 04:57
@briandaub if you take "Sherlock" as the first parameter
your code will return no such contact
venit2
@venit2
Jan 27 2016 04:58
@briandaub read the stack overflow i linked, the first answer explains the problem
rphares
@rphares
Jan 27 2016 04:58
@rajesh304 , you figure it out?
Josiah Anderson
@Josiahdanderson
Jan 27 2016 04:58
thanks @ rphares ok i'll try that. I'm at a closing starbucks and need to head out. I'll get back on if i still cant figure it out.
thanks @rphares lol
CamperBot
@camperbot
Jan 27 2016 04:58
josiahdanderson sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
rphares
@rphares
Jan 27 2016 04:58
sure thing :)
CamperBot
@camperbot
Jan 27 2016 04:58
:star: 2045 | @rphares | http://www.freecodecamp.com/rphares
rphares
@rphares
Jan 27 2016 04:58
you are trying to build a sentence, @rajesh304 ,
Brian Daub
@briandaub
Jan 27 2016 04:59
Yeah idk what you are talking about @venit2
rphares
@rphares
Jan 27 2016 04:59
so all you need to do is concatenate the myNoun, myAdjective stuff.
but, you want to separate them with some non-word characters. (i suggest spaces)
@rajesh304 :blush:
Brian Daub
@briandaub
Jan 27 2016 05:00
My console.log() statement is just to see what the value is that I am getting
venit2
@venit2
Jan 27 2016 05:00
@briandaub your code has a problem, but the console.log is not going to help you
Brian Daub
@briandaub
Jan 27 2016 05:00
And that value never changes
Ken Haduch
@khaduch
Jan 27 2016 05:00

@briandaub - some pseudo-ish code for this:

lookup(firstname, prop) {

var foundPerson = false;
var foundProp = false;

for ( var i = 0; i < contacts.length; i++) { // that is not pseudocode
    // contacts[i] is going to refer to each person in the contact list for each loop iteration
    if ( contacts[i].firstName === firstName ) {
        // we have a contact with a matching name, record that fact
       foundPerson = true;
        if ( contacts[i].hasOwnProperty(prop) ) {
            return (whatever you're supposed to do if you find the property);
       } else {
            return (whatever you're supposed to return if there is a person without the property);
        }
    }
}
// if we get here, we did not find the contact with that first name, we can check
if ( foundPerson !== true ) {
    return (whatever you're supposed to return if you didn't find a contact);
}
}

Not sure if I have the indentation right there - does that help?

Astha Sharma
@asthas
Jan 27 2016 05:01
@briandaub the problem is since the first name is Akira in the array of objects "Sherlock " will not match that and immediately return "No such contact"
rphares
@rphares
Jan 27 2016 05:02
@khaduch , do you mind if i steal that? this one comes up a lot during my usual hours and i think your 'pseudo-ish' explanation would be quite helpful! :pensive: :blush:
Astha Sharma
@asthas
Jan 27 2016 05:02
@briandaub the loop wont iterate further since it will return immediately
Brian Daub
@briandaub
Jan 27 2016 05:02
^
There is my problem
Ken Haduch
@khaduch
Jan 27 2016 05:03
@briandaub - so the idea is that you have the chance of looking through the entire list of contacts to make sure that the one you are looking for is there or not there, If you find the contact, you can see if they have the property that you're looking for. If they don't have the prop, return the status that you are supposed to return. If you get all the way list, you did not find the person, return that no contact status. As @asthas points out - you cannot just stop at the first contact, you have to be abe to get through them all, it is a linear search.
Astha Sharma
@asthas
Jan 27 2016 05:03
@khaduch has sent a wonderful answer with all explanations
@briandaub go ahead and understand that
if you have any queries you're always welcome
Ken Haduch
@khaduch
Jan 27 2016 05:05
@rphares - you can steal it, just get the people you help to shoot a bit of t-h-anks my way! :)
rphares
@rphares
Jan 27 2016 05:06
will do, and thanks @khaduch
CamperBot
@camperbot
Jan 27 2016 05:06
rphares sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star: 435 | @khaduch | http://www.freecodecamp.com/khaduch
daiwik
@daiwik
Jan 27 2016 05:06

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

var newArr = arr.push(item);
// item = newArr.shift();
return item; // Change this line
}

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

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

how is this wrong
someone please help
Ken Haduch
@khaduch
Jan 27 2016 05:06
and I'm going to be going out of the room... :) time to take a rest! Best of luck to all overnighters (at least overnighters from my point of view!)
daiwik
@daiwik
Jan 27 2016 05:07
function queue(arr, item) {
  // Your code here

  var newArr = arr.push(item);
 // item = newArr.shift();
  return item;  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(queue(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
Astha Sharma
@asthas
Jan 27 2016 05:08
@daiwik This is the queue question?
daiwik
@daiwik
Jan 27 2016 05:08
yes
Astha Sharma
@asthas
Jan 27 2016 05:08
Why have you commented out newArr.shift()
NainaPS
@Navyya
Jan 27 2016 05:08
did anyone finish with title case a sentense algo??
daiwik
@daiwik
Jan 27 2016 05:09
i just wanted to see what would happen but that part works
Astha Sharma
@asthas
Jan 27 2016 05:09
@Navyya I am on it
daiwik
@daiwik
Jan 27 2016 05:09
it doesnt work when i add push(item)
NainaPS
@Navyya
Jan 27 2016 05:09
well let me know if u finish it
daiwik
@daiwik
Jan 27 2016 05:09
if i push any number it works
Astha Sharma
@asthas
Jan 27 2016 05:09
Since you are returning an item
that item will be the one which you have shifted
rajesh304
@rajesh304
Jan 27 2016 05:10
thnx @rphares
CamperBot
@camperbot
Jan 27 2016 05:10
rajesh304 sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 2046 | @rphares | http://www.freecodecamp.com/rphares
rphares
@rphares
Jan 27 2016 05:10
sure thing! Holler if that doesn't sort you :)
CamperBot
@camperbot
Jan 27 2016 05:10
holler back!
Astha Sharma
@asthas
Jan 27 2016 05:10
Uncomment that statement and your code will work fine
NainaPS
@Navyya
Jan 27 2016 05:10
til then @dooglus @matthew3454 @a-d-collins
daiwik
@daiwik
Jan 27 2016 05:10
but i am adding item at the end using push and removing first thing from array
function queue(arr, item) {
  // Your code here

  var newArr = arr.push(item);
  item = newArr.shift();
  return item;  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(queue(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
i get maximum call stack size exxceeds
Astha Sharma
@asthas
Jan 27 2016 05:11
shift() will remove the first item from the array and then you have return that item
daiwik
@daiwik
Jan 27 2016 05:12
yea isn't that what this code does?