These are chat archives for FreeCodeCamp/HelpJavaScript

26th
May 2016
thompsonsaraht
@thompsonsaraht
May 26 2016 00:00
Okay, I was here earlier with a problem, and with a little help, I figured out part of where I was going wrong, but I'm still stuck. I'm getting a result now, problem is, I'm getting the same result regardless of what I put in to look up. Can someone give me a hint as to what I'm still missing? Thank you!

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

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

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

// Change this value to test
phoneticLookup("alpha");
Patrick Watrous
@pwatrous
May 26 2016 00:01
@thompsonsaraht try using a switch :D
thompsonsaraht
@thompsonsaraht
May 26 2016 00:01
I wish, instructions specifically say to use lookup rather than switch. I'm on Using Objects for Lookup.
Patrick Watrous
@pwatrous
May 26 2016 00:02
function phoneticLookup(val) {
  switch(val) = {
  // put stuff here
}
oh ooops dont listen tom e
thompsonsaraht
@thompsonsaraht
May 26 2016 00:02
lol
Patrick Watrous
@pwatrous
May 26 2016 00:02
rip
thompsonsaraht
@thompsonsaraht
May 26 2016 00:03
rip?
Blauelf
@Blauelf
May 26 2016 00:03
@thompsonsaraht Remove those result = from the object definition. You need to add a line result = below, using both the lookup object and the function argument.
thompsonsaraht
@thompsonsaraht
May 26 2016 00:04
I didn't get anything at all without it.
Stephen James
@sjames1958gm
May 26 2016 00:04
@thompsonsaraht Check the syntax to the left on the challenge. There is no result = there
@thompsonsaraht YOu still need to do the lookup after the object and set that to result.
thompsonsaraht
@thompsonsaraht
May 26 2016 00:05
Are we talking about at the end, after the closing curly brace?
richiedSIS
@richiedSIS
May 26 2016 00:06
@sjames1958gm I'm slowly understanding it more. Is this going in the right direction?
function destroyer(arr) {
  // Remove all the values
 //Collect the parameters and assign it to an array
 var remainingArgs = Array.from(arguments).slice(1);

  var filterFunc = function(item){
 //The outer for loop checks the values that come after the initial array
  //The inner loop runs those against the array and returns a value if it is not a match
  for(var i=1; i<remainingArgs.length;i++){
    for(var j = 0; arguments[0].length; j++){
      if(arguments[0][i]!==remainingArgs[i])
        return array[0][i];
    }
  }};

  //Run the filter method on the array and call the method seekDestroy
  //assign the array that's returned to finalArr
  var finalArr = remainingArgs.filter(filterFunc);
  return finalArr;

}



destroyer([1, 2, 3, 1, 2, 3], 2, 3);
jahala
@jahala
May 26 2016 00:06
Hi! Is it allowed to ask for javascript help with problems not related to freecodecamp here?
Mariusz Bachurski
@embahr
May 26 2016 00:06
find check for palindromes
CamperBot
@camperbot
May 26 2016 00:06

find check for palindromes

:zero: algorithm check for palindromes

Randy Goldsmith
@Dueldrawer8
May 26 2016 00:07
@sjames1958gm is there a way i can append the html once instead of 3 times for my 3 different divs? I would have to get rid of onlineBorders function.. and would have to make 3 different gets to those 3 divs if that makes sense
Stephen James
@sjames1958gm
May 26 2016 00:08
@richiedSIS Slowly - The purpose of the filterFunc is to decide whether item belongs in the result. So, it should return false if item is not in remainingArgs otherwise return true.
Randy Goldsmith
@Dueldrawer8
May 26 2016 00:08
so i have three div classes, topOnline, middleOffline,bottomClosed.. the idea is to check the status of the channels and place them into my created divs based on the status' they have
Diego Mayer
@Chrono79
May 26 2016 00:09
@jahala you can ask, but the answer is not guaranteed
Stephen James
@sjames1958gm
May 26 2016 00:10
@Dueldrawer8 You can add a parameter to borderBoxes that it the div to append to.
function onlineBorders(parent, status, displayLogo, displayName, infoStreaming )
{
   parent.append()
}
jahala
@jahala
May 26 2016 00:10
@Chrono79 Ok, thanks.. I'm working on resizing some svg .. a d3 calendar..
And I'm wondering why this only "kinda" works.. The resizing gradually turns the containers into squares etc..:

                    $(window).resize(function () {

                        // Debounce our resizing
                        var debounce = setTimeout(function() {
                               // Only set attribute viewbox once
                               function setView(c, w, h) {
                                   if (!c.getAttribute("viewBox")) {
                                       var viewBox = "20 0 " + w + " " + h + "";
                                       c.setAttribute("viewBox", viewBox);
                                       c.setAttribute("preserveAspectRatio", "xMidYMid meet");
                                   }
                               }

                               // Reset previous timers
                               clearTimeout(reset);
                               clearTimeout(debounce);

                               // Set variables
                               var cal = d3.select("svg.RdYlGn")[0][0],
                                   parent = cal.parentElement,
                                   aspect = Math.round(parent.offsetWidth / parent.offsetHeight);
                               var newHeight = (parent.offsetWidth / aspect),
                                   newWidth = parent.offsetWidth,
                                   oldHeight = cal.getAttribute("height") || cal.offsetHeight,
                                   oldWidth = cal.getAttribute("width") || cal.offsetWidth;

                                // Set the viewbox
                                setView(cal,oldWidth,oldHeight);

                                // Set new dimensions for calendar
                                cal.setAttribute("height", newWidth / aspect);
                                cal.setAttribute("width", newWidth);
                                // Make sure parent behaves and follows with calendar
                                var reset = setTimeout(function() {
                                        parent.setAttribute("width", cal.getAttribute("width"));
                                        parent.setAttribute("height", cal.getAttribute("width")/aspect);
                                }, 500);
                        }, 300);

                   });
CamperBot
@camperbot
May 26 2016 00:10
jahala sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:cookie: 845 | @chrono79 |http://www.freecodecamp.com/chrono79
Randy Goldsmith
@Dueldrawer8
May 26 2016 00:10
@sjames1958gm thanks..sounds good
CamperBot
@camperbot
May 26 2016 00:10
dueldrawer8 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: dueldrawer8 already gave sjames1958gm points
Luke
@lhovee
May 26 2016 00:12
hello everyone! I'm supposed to return the portion of the array which contains "source." Can anyone tell me what I'm doing wrong here? Am I on the right track?

function whereAreYou(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line
for (source in collection) {
  if (collection[0].hasOwnProperty(source)) {arr.push(collection[0]);}
  else if (collection[1].hasOwnProperty(source)) {arr.push(collection[1]);}
  else if (collection[2].hasOwnProperty(source)) {arr.push(collection[2]);}
}

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

whereAreYou([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
Diego Mayer
@Chrono79
May 26 2016 00:13
@jahala At least I can't help you with that, sorry
jahala
@jahala
May 26 2016 00:14
@Chrono79 No problem - thanks anyway! :)
CamperBot
@camperbot
May 26 2016 00:14
jahala sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: jahala already gave chrono79 points
Randy Goldsmith
@Dueldrawer8
May 26 2016 00:14
@sjames1958gm hmm.. not working
http://codepen.io/duel_drawer8/pen/QNxyNq
richiedSIS
@richiedSIS
May 26 2016 00:15
@sjames1958gm Now I'm getting an array returned to me, but it's the values to be tested against the array. Something must be backwards?
  var filterFunc = function(item){
   for(var i=1; i<remainingArgs.length;i++){
    for(var j = 0; arguments[0].length; j++){
      //if the value in the arguments array does not match one of the values 
      //to be removed then return false
      if(arguments[0][j]!==remainingArgs[i])
        return false;
    }
  }
   return true;
  };
Stephen James
@sjames1958gm
May 26 2016 00:17
@richiedSIS use item and remainingArgs only - there is a function that you can use to find out if item is in remainingArgs
@richiedSIS delete all those for loops - and replace
Gauri Sathe
@gauriVS
May 26 2016 00:19
function lookUpProfile(firstName, prop) {
  // Only change code below this line
  var isValidName = false;
  var isValidProperty = false;

  for (var i = 0; i < contacts.length; i++) { // i == 0
    if (firstName === contacts[i].firstName) {
      isValidName = true;
      if (prop in contacts[i]) {
        return contacts[i][prop];
      }
    }
    if (prop in contacts[i]) {
      isValidProperty = true;
    }
  }

  if (!isValidName) {
    return ("No such contact");
  }

  if (!isValidProperty) {
    return ("No such property");
  }
}
I have written the above code for profile lookup. Though all tests are passing I am not sure if this is the most elegant and efficient way. Can someone suggest if this needs any changes?
Randy Goldsmith
@Dueldrawer8
May 26 2016 00:19
@sjames1958gm got it to work..thanks for the help
Stephen James
@sjames1958gm
May 26 2016 00:21
@richiedSIS return remainingArgs.indexOf(item) === -1
JimmyBonez
@JimmyBonez
May 26 2016 00:22
The entire code works, until you hit the last pattern? But when I return the string out it shows as doing it correctly? Pretty well out of options, or thoughts of how to get it to pass.
function palindrome(str) {
var check = str.toLowerCase().replace(/\s/g, '').replace(/,/g, '').replace(/\./g, '');

  var newString = "";
  for (var i = str.length - 1; i >= 0; i--) {
    newString += str[i];

 }if (newString.toLowerCase().replace(/\s/g, '').replace(/,/g, '').replace(/\./g, '') == check ) {
   var x = newString.toLowerCase().replace(/\s/g, '').replace(/,/g, '').replace(/\./g, '');
 return true;
 } else {
  return false;
  }

}

palindrome("0_0 (: /-\ :) 0-0");
Moisés Man
@moigithub
May 26 2016 00:24
@JimmyBonez u also need to remove the slashes the parentesis the colon and dashes
Stephen James
@sjames1958gm
May 26 2016 00:24
@JimmyBonez You need to remove more stuff if you use /\W_/gi then everything but letters and numbers is selected
@gauriVS A more succinct way
function lookUpProfile(firstName, prop) {
// Only change code below this line
  for (var i = 0; i < contacts.length; i++) {
    if (contacts[i].firstName === firstName) {
      if (contacts[i].hasOwnProperty(prop)) {
        return contacts[i][prop];
      } else {
        return "No such property";
      }
    }
  }

  return "No such contact";

// Only change code above this line
}
richiedSIS
@richiedSIS
May 26 2016 00:25
@sjames1958gm thanks, I was trying if(remainingArgs.indexOf(item) > 0) return true; That's basically the same, but less elegant, right?
CamperBot
@camperbot
May 26 2016 00:25
richiedsis sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1271 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
JimmyBonez
@JimmyBonez
May 26 2016 00:25
@moigithub @sjames1958gm I will give it a try thanks
CamperBot
@camperbot
May 26 2016 00:25
jimmybonez sends brownie points to @moigithub and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1272 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
:star2: 1253 | @moigithub |http://www.freecodecamp.com/moigithub
Stephen James
@sjames1958gm
May 26 2016 00:25
@richiedSIS Yes
Michael
@michaeldiegogil
May 26 2016 00:26
HELP PLEASE!!! STUCK ON GOLF CODE
CamperBot
@camperbot
May 26 2016 00:26
no wiki entry for: please stuck on golf code
Gauri Sathe
@gauriVS
May 26 2016 00:26
@sjames1958gm thanks! That looks clean!
CamperBot
@camperbot
May 26 2016 00:26
gaurivs sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1273 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Diego Mayer
@Chrono79
May 26 2016 00:27
@michaeldiegogil show your code
Michael
@michaeldiegogil
May 26 2016 00:28
i dont understand what operation par + 2 is
is it >=?
Domingos Balundo
@Balundo
May 26 2016 00:28
Hello I am New to FreeCodeCamp I do not know where to start from
Stephen James
@sjames1958gm
May 26 2016 00:29
@Balundo Best to start with the challenges -
Diego Mayer
@Chrono79
May 26 2016 00:29
@michaeldiegogil all that's not specified, it's ==
@Balundo look at the map link
Michael
@michaeldiegogil
May 26 2016 00:30
how do i show my code here
file:///Users/jay/Desktop/Screen%20Shot%202016-05-25%20at%205.29.12%20PM.png
Diego Mayer
@Chrono79
May 26 2016 00:31
help format
CamperBot
@camperbot
May 26 2016 00:31

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

Diego Mayer
@Chrono79
May 26 2016 00:31
@michaeldiegogil copy and paste your code using the above instructions
Gabriel Chan
@Gabriel-Chan
May 26 2016 00:32

function palindrome(str) {
if (str.replace( /\W/gi, '').toLowerCase().split('').reverse().join('') === str.replace( /\W/gi, '').toLowerCase()){
return "true";

}
else{
return "false";
}
}

palindrome("ey ,t");

trying to figure out palindome
cant pass it for some reason
Michael
@michaeldiegogil
May 26 2016 00:33

function golfScore(par, strokes) {
  // Only change code below this line
  if (strokes === 1) {
    return "Hole-in-one!";
  } else if (strokes <= par-2) {
    return "Eagle";
  } else if (strokes <= par-1) {
    return "Birdie";
  } else if (strokes === par) {
    return "Par";
  } else if (strokes >= 1) {
    return "Bogey";
  } else if (strokes == 2) {
    return "Double Bogey";
  } else if (strokes == 3) {
    return "Go Home";
  } 
  // Only change code above this line
}

// Change these values to test
golfScore(4, 5);
so yeah im having problems with double bogey
Diego Mayer
@Chrono79
May 26 2016 00:34
@Gabriel-Chan \W alone is not enough
Michael
@michaeldiegogil
May 26 2016 00:34
go home
and go home
Diego Mayer
@Chrono79
May 26 2016 00:35

@michaeldiegogil

 else if (strokes == 2) { //should be strokes == par + 2
    return "Double Bogey";
...

Look at the table and fix both cases

thanks
Luke
@lhovee
May 26 2016 00:37
hey guys, can anyone tell me why this is returning an array with two iterations of "source"
for (source in third) {
  if (third.hasOwnProperty(source)) {arr.push(collection[2]);}
  }
bleujai
@bleujai
May 26 2016 00:37
@Gabriel-Chan "True" or "False" ... These are strings not boolean return values.
Michael
@michaeldiegogil
May 26 2016 00:38
what do i fix? i know my problem is the operation == 2
but when i put >= 2 or anything else it wont work
Diego Mayer
@Chrono79
May 26 2016 00:38

@asma8867
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.

Hint
Remember that undefined is a keyword, not a string
You have to use an if and return undefined, look at previous challenges

Michael
@michaeldiegogil
May 26 2016 00:38
i dont understand what par + 2 is
Gabriel Chan
@Gabriel-Chan
May 26 2016 00:39
@bleujai oh thanks I thought i was supposed to return strings
CamperBot
@camperbot
May 26 2016 00:39
gabriel-chan sends brownie points to @bleujai :sparkles: :thumbsup: :sparkles:
:cookie: 409 | @bleujai |http://www.freecodecamp.com/bleujai
Islam Ibakaev
@dagman
May 26 2016 00:39
hey guys could u critisize this
Diego Mayer
@Chrono79
May 26 2016 00:39

@michaeldiegogil why you don't understand par + 2 and this you do understand?

} else if (strokes <= par-2) {
    return "Eagle";
...

par + 2 is a number

Asma
@asma8867
May 26 2016 00:39
@Chrono79 could you please take a look now? I changed it but still it does not work :(
Diego Mayer
@Chrono79
May 26 2016 00:40
@asma8867 paste your code here
Michael
@michaeldiegogil
May 26 2016 00:40
i type (strokes >= par+2) but it doesnt woek
Asma
@asma8867
May 26 2016 00:40

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

Diego Mayer
@Chrono79
May 26 2016 00:41
@asma8867 fix this: if (a||b<0) {
as it is it means if a is not 0 or b lesser than 0
Liam Williams
@Liamw0403
May 26 2016 00:42
Hi guys! I just started JS and I'm literally on the second page of learning how, but i have no idea what it is talking about. The setup is var a;
var b = 2;
and it wants me to assign the value 7 to variable a and then assign the contents of a to variable b. if anyone could let me know that would be great! sorry if this is a very simple question
Diego Mayer
@Chrono79
May 26 2016 00:42
@michaeldiegogil I said if it doesn't specify use == not >=
bleujai
@bleujai
May 26 2016 00:43
@dagman Bold.
Stephen Mansfield
@StephenMansfield
May 26 2016 00:43
@Liamw0403 var b = 2; is telling the computer the variable b is equal to 2
@Liamw0403 so to get a to be equal to seven how would you change the code?
Liam Williams
@Liamw0403
May 26 2016 00:44
@StephenMansfield var a = 7; right?
Islam Ibakaev
@dagman
May 26 2016 00:44
@bleujai :smile: thx
CamperBot
@camperbot
May 26 2016 00:44
dagman sends brownie points to @bleujai :sparkles: :thumbsup: :sparkles:
:cookie: 410 | @bleujai |http://www.freecodecamp.com/bleujai
Asma
@asma8867
May 26 2016 00:44
@Chrono79 I have just made as it is said in the instruction : a or b less than 0. sorry I am confused :(
Stephen Mansfield
@StephenMansfield
May 26 2016 00:44
yup thats it! @Liamw0403
Gabriel Chan
@Gabriel-Chan
May 26 2016 00:44
@Chrono79 found the proper filter thanks
CamperBot
@camperbot
May 26 2016 00:44
:cookie: 846 | @chrono79 |http://www.freecodecamp.com/chrono79
gabriel-chan sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
Michael
@michaeldiegogil
May 26 2016 00:45
} else if (strokes == par+2) {
    return "Double Bogey";
  } else if (strokes == par+3) {
    return "Go Home";
  }
Diego Mayer
@Chrono79
May 26 2016 00:45
@asma8867 think of it as a less than 0 or b less than 0 and write it like that
Asma
@asma8867
May 26 2016 00:45
@Chrono79 I made it ;) thanks
CamperBot
@camperbot
May 26 2016 00:45
asma8867 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:cookie: 847 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
May 26 2016 00:45
@asma8867 :+1:
Liam Williams
@Liamw0403
May 26 2016 00:45
@StephenMansfield how do i then assign the contents of variable a to variable b? i typed var b = var a; but it doesn't work
Diego Mayer
@Chrono79
May 26 2016 00:46

@michaeldiegogil look again at the table:

par + 2    "Double Bogey"
>= par + 3    "Go Home!"

par + 3 is not ==, isn't it?

Luke
@lhovee
May 26 2016 00:46
for (source in third) {
  if (third.hasOwnProperty(source)) {arr.push(collection[2]);}
  }
hey guys, can anyone tell me why this is returning two iterations of "source"
Stephen Mansfield
@StephenMansfield
May 26 2016 00:46
@Liamw0403 actually man I led you astray a bit
@Liamw0403 var a =2; is a declaration
it is creating that variable
but once you use that var the first time, you dont need it again
since var a was already created in teh first part of the code
Nate Mallison
@NJM8
May 26 2016 00:47
Hello, can anyone help me with the profile lookup? Here is my code '''
Stephen Mansfield
@StephenMansfield
May 26 2016 00:47
to assign a to be seven teh code looks like a = 7;
Nate Mallison
@NJM8
May 26 2016 00:48
oops, help format
Liam Williams
@Liamw0403
May 26 2016 00:48
@StephenMansfield thank you! i get it now.
CamperBot
@camperbot
May 26 2016 00:48
liamw0403 sends brownie points to @stephenmansfield :sparkles: :thumbsup: :sparkles:
:cookie: 273 | @stephenmansfield |http://www.freecodecamp.com/stephenmansfield
Michael
@michaeldiegogil
May 26 2016 00:48
 } else if (strokes == par+2) {
    return "Double Bogey";
  } else if (strokes >= par+3) {
    return "Go Home";
  }
Ok changed
Diego Mayer
@Chrono79
May 26 2016 00:48
@michaeldiegogil does it work now?
Michael
@michaeldiegogil
May 26 2016 00:48
No
Diego Mayer
@Chrono79
May 26 2016 00:49
paste it full again
Nate Mallison
@NJM8
May 26 2016 00:49

'''
function lookUpProfile(firstName, prop){
// Only change code below this line
var result = "";

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

var hasProp = contacts[i].hasOwnProperty(prop);
var hasName = contacts[i].firstName;
console.log(firstName + " " + contacts[i].firstName);

if (hasName === firstName){
if (hasProp) {
result = contacts[i][prop];
} else {
result = "No such property";
}
} else {
result = "No such contact";
}
}

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

CamperBot
@camperbot
May 26 2016 00:49
:bulb: to format code use backticks! ``` more info
Stephen Mansfield
@StephenMansfield
May 26 2016 00:49
quick question to anybody who has done the palindromes.... do you need to put everything in array or can you do it with string.replace?
Michael
@michaeldiegogil
May 26 2016 00:49

function golfScore(par, strokes) {
  // Only change code below this line
  if (strokes === 1) {
    return "Hole-in-one!";
  } else if (strokes <= par-2) {
    return "Eagle";
  } else if (strokes <= par-1) {
    return "Birdie";
  } else if (strokes === par) {
    return "Par";
  } else if (strokes >= 1) {
    return "Bogey";
  } else if (strokes == par+2) {
    return "Double Bogey";
  } else if (strokes >= par+3) {
    return "Go Home";
  } 
  // Only change code above this line
}

// Change these values to test
golfScore(5, 9);
Diego Mayer
@Chrono79
May 26 2016 00:49
@StephenMansfield you can do it with strings
bleujai
@bleujai
May 26 2016 00:49
@lhovee for (source in third), this is for iterating through an array. What are you working on?
Diego Mayer
@Chrono79
May 26 2016 00:50
@michaeldiegogil missing ! in Go Home
this isn't right:
else if (strokes >= 1) {
    return "Bogey";
Stephen Mansfield
@StephenMansfield
May 26 2016 00:50
@Chrono79 thanks
CamperBot
@camperbot
May 26 2016 00:50
stephenmansfield sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:cookie: 848 | @chrono79 |http://www.freecodecamp.com/chrono79
Michael
@michaeldiegogil
May 26 2016 00:50

function golfScore(par, strokes) {
  // Only change code below this line
  if (strokes === 1) {
    return "Hole-in-one!";
  } else if (strokes <= par-2) {
    return "Eagle";
  } else if (strokes <= par-1) {
    return "Birdie";
  } else if (strokes === par) {
    return "Par";
  } else if (strokes >= 1) {
    return "Bogey";
  } else if (strokes == par+2) {
    return "Double Bogey";
  } else if (strokes >= par+3) {
    return "Go Home!";
  } 
  // Only change code above this line
}

// Change these values to test
golfScore(5, 9);
bleujai
@bleujai
May 26 2016 00:50
@lhovee Good idea to declare source as well. (var source in third)
Diego Mayer
@Chrono79
May 26 2016 00:51
@michaeldiegogil par + 1 "Bogey"
Luke
@lhovee
May 26 2016 00:51
@bleujai hey thanks for noticing me it's busy in here tonight. I'm working on the challenge "where art thou" and this is my code thus far

function whereAreYou(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line
  var first = collection[0];
  var second = collection[1];
  var third = collection[2];
/*for (source in first) {
  if (first.hasOwnProperty(source)) {arr.push(collection[0]);}}
  */ /*
  for (source in second) {
  if (second.hasOwnProperty(source)) {arr.push(collection[1]);}}
  */
  for (source in third) {
  if (third.hasOwnProperty(source)) {arr.push(collection[2]);}
  }

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

whereAreYou([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
CamperBot
@camperbot
May 26 2016 00:51
lhovee sends brownie points to @bleujai :sparkles: :thumbsup: :sparkles:
:cookie: 411 | @bleujai |http://www.freecodecamp.com/bleujai
Michael
@michaeldiegogil
May 26 2016 00:52
  } else if (strokes >= par+1) {
    return "Bogey";
?
Diego Mayer
@Chrono79
May 26 2016 00:52
@michaeldiegogil do you see >= in that line? Use ==
Nate Mallison
@NJM8
May 26 2016 00:53
function lookUpProfile(firstName, prop){
// Only change code below this line
 var result = "";

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

   var hasProp = contacts[i].hasOwnProperty(prop);
   var hasName = contacts[i].firstName;
   console.log(firstName + " " + contacts[i].firstName);

   if (hasName === firstName){
     if (hasProp) {
       result = contacts[i][prop];
     } else {
       result = "No such property"; 
     }
   } else {
     result = "No such contact";
   } 
 }

  return result;
// Only change code above this line
}
Can someone help me with the profile lookup? my code is returning 'no such contact' for two of the test cases where the name is there.
Michael
@michaeldiegogil
May 26 2016 00:54
@Chrono79 THANKKKKKK YOU
Diego Mayer
@Chrono79
May 26 2016 00:54
@michaeldiegogil no problem
@NJM8 return no such contact only after you've checked every contact
Nick Robson
@nickrobson
May 26 2016 00:55
How is everyone? I'm back from the dead. :ghost:
eeflores
@eeflores
May 26 2016 00:57
braaaains
Diego Mayer
@Chrono79
May 26 2016 00:57
@nickrobson my gun is pointing at you (just to be safe) ;)
Nick Robson
@nickrobson
May 26 2016 00:58
I come in pieces! :pizza:
bitgrower
@bitgrower
May 26 2016 00:58
lol ... is this my "golf" friend ?
Nick Robson
@nickrobson
May 26 2016 00:58
yup :3
:golf:
For anyone interested in knowing the shortest solutions to most of the (presumably old, and no-longer existing) challenges, https://github.com/nickrobson/fcc-golf
96street
@96street
May 26 2016 01:00
Need help on Seek and Destroy
function destroyer(arr) {
  function deleteThis(num) {
  return num !== arguments[1] || num !== arguments[2];
}
  arr.filter(deleteThis);
  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
bleujai
@bleujai
May 26 2016 01:00
@lhovee Start by using .keys() to find what you are searching for. There will not always be just one key and value for the source object.
Diego Mayer
@Chrono79
May 26 2016 01:01
@96street arguments inside deleteThis is not the same as inside destroyer
Also, you'll want to make your filter more flexible
it won't pass this test: destroyer([3, 5, 1, 2, 2], 2, 3, 5) should return [1].
bitgrower
@bitgrower
May 26 2016 01:01
@96street -- every time you create a new scope (eg, enter a function), your arguments object is pointing to a new arguments object
96street
@96street
May 26 2016 01:02
so need to create a new argument inside deleteThis?
Luke
@lhovee
May 26 2016 01:02
@bleujai I read about .keys() because it was a suggested link in the challenge but in the example .keys() seemed to return {"0", "1", "2"} or something weird like that
bitgrower
@bitgrower
May 26 2016 01:02
therefore, like @Chrono79 said, the one in deleteThis is not the same (does not have the same values, is not pointing to the same place in memory)
@96street -- you need to pull the arguments out of the arguments object into local variables ... most people use an array ... :)
Nate Mallison
@NJM8
May 26 2016 01:03
thanks @Chrono79 .
CamperBot
@camperbot
May 26 2016 01:03
njm8 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:cookie: 849 | @chrono79 |http://www.freecodecamp.com/chrono79
bleujai
@bleujai
May 26 2016 01:03
@lhovee Then you have to search through the array to see if those keys are in an index of the array along with its value from the source given.
Nate Mallison
@NJM8
May 26 2016 01:03
I knew I wasn't thinking about the problem in the right way I just wasn't seeing it. Out of curiosity how would you change the code? Here is my solution.
bitgrower
@bitgrower
May 26 2016 01:03

@96street -- you need to pull the arguments out of the arguments object into local variables ... most people use an array ... :)

^^^^ at least if you want to use the values in a new scope (hint: you do)

Nate Mallison
@NJM8
May 26 2016 01:04
function lookUpProfile(firstName, prop){
// Only change code below this line
 var result = "";

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

   var hasProp = contacts[i].hasOwnProperty(prop);
   var hasName = contacts[i].firstName;

   if (hasName === firstName){
     if (hasProp) {
       result = contacts[i][prop];
     } else {
       result = "No such property"; 
     }
   } 
 }

  if (result === "") {
    return "No such contact";  
  } else {
    return result;
  }
// Only change code above this line
}
bleujai
@bleujai
May 26 2016 01:04
@lhovee

function whereAreYou(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line
  var sourcKeys = Object.keys(source);

  // Only change code above this line
  return sourcKeys;
}
This returns ["last"]
for the original test given in the challenge
bitgrower
@bitgrower
May 26 2016 01:05
it's nice to see more people asking about Where Art Thou -- I assume this means more people are getting further along in the FCC js challenges ... :)
Diego Mayer
@Chrono79
May 26 2016 01:06
@NJM8 instead of storing the string in result you could return the string, and delete the last if and directly return "No such contact" there
But you can do a refactor later to do that
96street
@96street
May 26 2016 01:07
@bitgrower so what are my argument objects doing now?
Luke
@lhovee
May 26 2016 01:07
@bleujai so then I can search collection.last to see if it contains the same string as source?
bitgrower
@bitgrower
May 26 2016 01:07
each new scope, a new arguments object is created ... consisting of whatever arguments were passed .. even if no arguments are passed, a new arguments object will be created ...
@lhovee -- it's better to use .hasOwnProperty ... :)
tommy
@tommygebru
May 26 2016 01:08
@bitgrower what is your current code?
96street
@96street
May 26 2016 01:08
so my arguments object inside deleteThis is referring to num? @bitgrower
Nate Mallison
@NJM8
May 26 2016 01:08
@Chrono79 Thats a good idea. I'm not too worried about the code being perfect, just wanting to learn different ways of doing things so I understand better. Thanks!
CamperBot
@camperbot
May 26 2016 01:08
njm8 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: njm8 already gave chrono79 points
bitgrower
@bitgrower
May 26 2016 01:08
@tommygebru no idea what you are asking about, -- I am helping, not asking for help
bleujai
@bleujai
May 26 2016 01:09
@lhovee collection.hasOwnProperty() <---- inside here you will put the variable or location in an array that you stored your keys in.
bitgrower
@bitgrower
May 26 2016 01:09
did you get caught up by gitter's poor auto-complete @tommygebru ?
bleujai
@bleujai
May 26 2016 01:09
Most likely the latter.
tommy
@tommygebru
May 26 2016 01:09
@96street same question :smile:
bleujai
@bleujai
May 26 2016 01:09
Latter, ladder?
bitgrower
@bitgrower
May 26 2016 01:09
yeah, I'm guessing ... has happened to me more than once ... :)
tommy
@tommygebru
May 26 2016 01:10
latter
Luke
@lhovee
May 26 2016 01:10
@bleujai hahaha I'm not sure either. Latter I think
bitgrower
@bitgrower
May 26 2016 01:10
latter ...
Diego Mayer
@Chrono79
May 26 2016 01:10
@NJM8 after you've learned more methods you'll have more ways of doing things (maybe not in this case) and you'll want to refactor some solutions applying those methods/tricks
bleujai
@bleujai
May 26 2016 01:10
@tommygebru That was close then but first guess was right. :)
bitgrower
@bitgrower
May 26 2016 01:10
latter is later ...
Luke
@lhovee
May 26 2016 01:11
@bleujai okay let me play around with it for awhile and if I don't get it I'll return with questions. Thanks again
Diego Mayer
@Chrono79
May 26 2016 01:11
Latte macchiato? I prefer tea
CamperBot
@camperbot
May 26 2016 01:11
lhovee sends brownie points to @bleujai :sparkles: :thumbsup: :sparkles:
:warning: lhovee already gave bleujai points
bleujai
@bleujai
May 26 2016 01:11
mas tarde
bitgrower
@bitgrower
May 26 2016 01:12
@96street -- yeah, I think a code re-post would be good ... it's a ways up the page now ...
bleujai
@bleujai
May 26 2016 01:12
@lhovee You'll get it.
wiki retrieve earlier code
CamperBot
@camperbot
May 26 2016 01:12
no wiki entry for: retrieve earlier code
bleujai
@bleujai
May 26 2016 01:12
dang, didn't work
tommy
@tommygebru
May 26 2016 01:12
@96street -- yeah, I think a code re-post would be good ... it's a ways up the page now ...
bitgrower
@bitgrower
May 26 2016 01:13
@lhovee - Where Art Thou is mostly an exercise in addressing ... it may help to take pencil and paper and see how it works ... some of my code for that had a couple of layers of indexing ...
96street
@96street
May 26 2016 01:13
function destroyer(arr) {
  function deleteThis(num) {
  return num !== arguments[1] || num !== arguments[2];
}
  arr.filter(deleteThis);
  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
So my question was how do I make the arguments object inside deleteThis target the initial arguments in the destroyer function
bitgrower
@bitgrower
May 26 2016 01:15
@96street -- if you look on the arguments object page on Mozilla Developer Network, they give you a line of code you can use to take your arguments object and create an array out of it ...
96street
@96street
May 26 2016 01:15
Ahh yep
var args = Array.prototype.slice.call(arguments);
Ty i'll come back soon
Diego Mayer
@Chrono79
May 26 2016 01:16
@96street remember to do it more flexible
bitgrower
@bitgrower
May 26 2016 01:16
I know there's one experienced guy around here who dis-recommends that method of doing this, his code actually just iterated thru the arguments object and pushed each value into a new array...
unfortunately, I don't remember his arguments (no pun intended) for doing iteration instead of using a prototype call ...
Diego Mayer
@Chrono79
May 26 2016 01:17
@bitgrower :smile:
Using slice on arguments prevents optimizations in some JavaScript engines (V8 for example - more information). If you care for them, try constructing a new array by iterating through the arguments object instead. An alternative would be to use the despised Array constructor as a function...
96street
@96street
May 26 2016 01:21
what does .prototype do?
I tried looking at its MDN page but I didn't understand their explanation
Diego Mayer
@Chrono79
May 26 2016 01:22
@96street Array.prototype, you're calling a static method that way if I'm not mistaken, because arguments is not a proper array, it's array-like
If I'm wrong correct me, please
Micah Bales
@micahbales
May 26 2016 01:22
Hi everyone. I'm working on the "Drop it" algorithm and wondering if you have any advice. Here's my code so far:
function dropElements(arr, func) {

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

    if (func(arr[i])) {
        return arr;
        } else {
        arr.shift();
        }

  }

}

dropElements([1, 2, 3], function(n) {return n > 0;});
Patrick Watrous
@pwatrous
May 26 2016 01:23
hey guys. I had a quick question about "Where do I belong"
this is my work so far, and I know its incorrect
```js
```js

function getIndexToIns(arr, num) {
  // Find my place in this sorted array.
  var args = Array.prototype.slice.call(arguments);
  args.sort(function(a, b) {
            return a -b;
            });
  return args.indexOf(num);
}
Norvin Burrus
@ndburrus
May 26 2016 01:24
@96street 1. Prototypes in JavaScript {ref: http://code.tutsplus.com/tutorials/prototypes-in-javascript--net-24949 }. 2. JavaScript Object Prototypes, {ref: http://www.w3schools.com/js/js_object_prototypes.asp }, 3. Understanding "Protoypes in JavaScript", {ref: http://yehudakatz.com/2011/08/12/understanding-prototypes-in-javascript/ }
Patrick Watrous
@pwatrous
May 26 2016 01:24
because its returning the index where num is already inclued
wait no that shouldn't make a difference
okay now i'm even more confused :')
Michael R
@Myst3420
May 26 2016 01:25
Hello,
Patrick Watrous
@pwatrous
May 26 2016 01:25
hey! @Myst3420
Asma
@asma8867
May 26 2016 01:26
Screen Shot 2016-05-25 at 6.25.17 PM
Michael R
@Myst3420
May 26 2016 01:26
Could someone help me with why this is also reversing my newArray:
testArray = newArray;
testArray.reverse();
Diego Mayer
@Chrono79
May 26 2016 01:26
@micahbales use a while loop, because when you shift the array, you'll increasing i too
Asma
@asma8867
May 26 2016 01:26
hi guys. How can I attach a printscreen here?
Micah Bales
@micahbales
May 26 2016 01:26
@Chrono79 Oh, yeah. Smart. Thanks!
CamperBot
@camperbot
May 26 2016 01:26
micahbales sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:cookie: 850 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
May 26 2016 01:27
better paste code @asma8867
help format
CamperBot
@camperbot
May 26 2016 01:27

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

Diego Mayer
@Chrono79
May 26 2016 01:27
@Myst3420 newArray is a pointer, not another array
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
Use slice to make a copy
Asma
@asma8867
May 26 2016 01:28
please someone help me:
v

var count = 0;

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

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

}

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

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

Michael R
@Myst3420
May 26 2016 01:28
Thanks @Chrono79
CamperBot
@camperbot
May 26 2016 01:28
myst3420 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:cookie: 851 | @chrono79 |http://www.freecodecamp.com/chrono79
Norvin Burrus
@ndburrus
May 26 2016 01:28
@Myst3420 this may be helpful :)
reverse Method (JavaScript), {ref: https://msdn.microsoft.com/en-us/library/3333858x(v=vs.94).aspx }


Reverses the elements in an Array.
Syntax

arrayObj.reverse() 
Parameters
arrayObj
Required. Any Array object.
Return Value
The reversed array.
Remarks
The required arrayObj reference is an Array object.
The reverse method reverses the elements of an Array object in place. It does not create a new Array object during execution.
If the array is not contiguous, the reverse method creates elements in the array that fill the gaps in the array. Each of these created elements has the value undefined.
Diego Mayer
@Chrono79
May 26 2016 01:29
@asma8867 count+=count isn't right
evaluate count in a separate code block after evaluating card value
Patrick Watrous
@pwatrous
May 26 2016 01:29
could anyone explain why this isn't working as intended?

function getIndexToIns(arr, num) {
  // Find my place in this sorted array.
  var args = Array.prototype.slice.call(arguments);
  args.sort(function(a, b) {
            return a -b;
            });
  return args.indexOf(num);
}
i'm not sure what is incorrect
my logic was
add num to the array
sort the array
return the position of num in the array
Diego Mayer
@Chrono79
May 26 2016 01:30
@pwatrous arr is an array and num a number
you'll have [[1,2,3], 2] to sort
Patrick Watrous
@pwatrous
May 26 2016 01:30
OH
OHHHHHH
THANKS @Chrono79
CamperBot
@camperbot
May 26 2016 01:31
pwatrous sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:cookie: 852 | @chrono79 |http://www.freecodecamp.com/chrono79
Norvin Burrus
@ndburrus
May 26 2016 01:31
@asma8867check/review the count/er variable.... :) there are two conditions which return hold? also the count variable gets set equal to zero when the intent is to have no card count change for those card values... :)
Asma
@asma8867
May 26 2016 01:31
@Chrono79 sorry could you please explain it more :(
Diego Mayer
@Chrono79
May 26 2016 01:32
@pwatrous I could suggest something but I'm afraid it'll give you the solution
Patrick Watrous
@pwatrous
May 26 2016 01:32

function getIndexToIns(arr, num) {
  // Find my place in this sorted array.
  arr.sort(function(a, b) {
            return a -b;
            });
  for (var i = 0; i < arr.length; i++) {
    if (arr[i] >= num) {
      return i;
    }
  }
  return num;
}


getIndexToIns([10, 20, 30, 40, 50], 30);
now every test is working EXCEPT
Diego Mayer
@Chrono79
May 26 2016 01:33
@asma8867 count += count, if count is 2, count will become 4 and you want to add only 1 to count every time card values is between 2 and 6
Asma
@asma8867
May 26 2016 01:33
I think I should writhe count+=1 .
Patrick Watrous
@pwatrous
May 26 2016 01:33
getIndexToIns([2, 5, 10], 15)
that one isn't ^
Diego Mayer
@Chrono79
May 26 2016 01:33
@asma8867 yes
Asma
@asma8867
May 26 2016 01:33
@Chrono79 I am going to write it again and I will back for your brownies ;)
Patrick Watrous
@pwatrous
May 26 2016 01:33
oh jk I know what I did
last thing should be arr.length and not num
hehe
Diego Mayer
@Chrono79
May 26 2016 01:35
@pwatrous once you've solved it I'm going to give you some suggestions to make it better
Michael R
@Myst3420
May 26 2016 01:35
@ndburrus Thanks as well
CamperBot
@camperbot
May 26 2016 01:35
myst3420 sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:cookie: 423 | @ndburrus |http://www.freecodecamp.com/ndburrus
Asma
@asma8867
May 26 2016 01:35
@Chrono79 could you please check it again :(
Diego Mayer
@Chrono79
May 26 2016 01:36
@asma8867 have you separated card evaluation from count evaluation?
Asma
@asma8867
May 26 2016 01:36
@Chrono79 nope. I am going though ;)
Patrick Watrous
@pwatrous
May 26 2016 01:36
got it @Chrono79
Norvin Burrus
@ndburrus
May 26 2016 01:37
@Myst3420 you're welcome! did it pass - does it make sense?
Diego Mayer
@Chrono79
May 26 2016 01:37
@pwatrous push num to arr, sort it and use indexOf
@ndburrus I think you meant to ask @Myst3420 , not @asma8867
Patrick Watrous
@pwatrous
May 26 2016 01:39
OH
THAT MAKES SENSE TOO
that's the premise of what i was trying to do
but I messed up and used argument objects
which didn't work so I defaulted to a for loop
thanks again @Chrono79
CamperBot
@camperbot
May 26 2016 01:39
pwatrous sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: pwatrous already gave chrono79 points
Asma
@asma8867
May 26 2016 01:41
@Chrono79 I did it right now and I am wondering is it possible to have two ifs in one function?!!
Diego Mayer
@Chrono79
May 26 2016 01:41
@asma8867 yes, and more too
Patrick Watrous
@pwatrous
May 26 2016 01:41
@asma8867 help else if
help else
CamperBot
@camperbot
May 26 2016 01:41

:point_right: challenge chaining if else statements [wiki]

Challenge Chaining If Else Statements

if/else statements can be chained together for complex logic. Here is pseudocode of multiple chained if / else if statements:

if(condition1) {
  statement1
} else if (condition2) {
  statement2
} else if (condition3) {
  statement3
. . .
} else {
  statementN
}

:pencil: read more about challenge chaining if else statements on the FCC Wiki

Patrick Watrous
@pwatrous
May 26 2016 01:42
like that @asma8867
you can also chain ifs, but if you find yourself doing that, you're probably better suited to use the && operator
Diego Mayer
@Chrono79
May 26 2016 01:42
@pwatrous that's an if/else block
she meant different blocks
Asma
@asma8867
May 26 2016 01:42
@pwatrous I mean for different variables not for one.
Patrick Watrous
@pwatrous
May 26 2016 01:42
oh oops jk
Asma
@asma8867
May 26 2016 01:42
@Chrono79 yup. different blocks ;)
richiedSIS
@richiedSIS
May 26 2016 01:45
I was working on this earlier and got distracted at work, but I think I'm almost done with Seek and Destroy. It's returning a blank array for me and I'm not sure why.
function destroyer(arr) {

 //Collect the parameters and assign it to an array
 var remainingArgs = Array.from(arguments).slice(1);

  var filterFunc = function(item){

    return remainingArgs.indexOf(item) === -1;

  };

  //Run the filter method on the array and call the method seekDestroy
  //assign the array that's returned to finalArr
  return remainingArgs.filter(filterFunc);


}

destroyer(["tree", "hamburger", 53], "tree", 53);
Stephen James
@sjames1958gm
May 26 2016 01:46
@richiedSIS filter on arr not remainingArgs -
arr.filter
@richiedSIS This code is basically saying return those elements of remainingArgs that are not in remainingArgs
Physicallime570
@Physicallime570
May 26 2016 01:47
Im stuck on the stand in line challenge how do you creatre that argument?
Asma
@asma8867
May 26 2016 01:47
@Chrono79 sorry could you please take a look again.thanks
Diego Mayer
@Chrono79
May 26 2016 01:48
@asma8867 paste it again
Asma
@asma8867
May 26 2016 01:48

var count = 0;

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

if (card==2||card==3||card==4||card==5||card==6){
count += 1;

}
else if (card==7||card==8||card==9){
count = count ;

}
else if (card==10||card=='J'||card=='Q'||card=='K'||card=='A') {
count -= 1;

}

if (count>0){

return count+"Bet";

}

else if (count<0) {

return count+"Hold";

}

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

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

Diego Mayer
@Chrono79
May 26 2016 01:48
@Physicallime570 what argument?
Physicallime570
@Physicallime570
May 26 2016 01:48
function nextInLine(arr, item) {
  // Your code here

  return item;   // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
Asma
@asma8867
May 26 2016 01:48

var count = 0;

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

if (card==2||card==3||card==4||card==5||card==6){
count += 1;

}
else if (card==7||card==8||card==9){
count = count ;

}
else if (card==10||card=='J'||card=='Q'||card=='K'||card=='A') {
count -= 1;

}

if (count>0){

return count+"Bet";

}

else if (count<0) {

return count+"Hold";

}

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

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

Diego Mayer
@Chrono79
May 26 2016 01:49
@asma8867 delete return "Change Me"; it's not needed, and your code it's almost ok, look at the last if/else code block
Asma
@asma8867
May 26 2016 01:49
how can I have the black background here?!
Stephen James
@sjames1958gm
May 26 2016 01:49
@asma8867 Make sure to include the space before the word Bet and Hold per instructions
Diego Mayer
@Chrono79
May 26 2016 01:50
help format
CamperBot
@camperbot
May 26 2016 01:50

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

Stephen James
@sjames1958gm
May 26 2016 01:50
@asma8867 Three backticks then shift-enter paste then three backticks enter
Diego Mayer
@Chrono79
May 26 2016 01:50
@asma8867
The function will then return a string with the current count and the string "Bet" if the count is positive, or "Hold" if the count is zero or negative. The current count and the player's decision ("Bet" or "Hold") should be separated by a single space.
Keenen Garnett
@Wallyw4
May 26 2016 01:52
QUestion what is "element" in this line of code?
return arr.filter(function(element) {
return nArg.indexOf(element) == -1;
});
Diego Mayer
@Chrono79
May 26 2016 01:53
@Wallyw4 it's an element of the array arr, filter loops through each of them
Asma
@asma8867
May 26 2016 01:53
@Chrono79 so many thanks :)
CamperBot
@camperbot
May 26 2016 01:53
asma8867 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:cookie: 853 | @chrono79 |http://www.freecodecamp.com/chrono79
Stephen James
@sjames1958gm
May 26 2016 01:53
@Wallyw4 filter will call the function(element) for each element of the array (arr) in turn and element is the variable that holds that value
Keenen Garnett
@Wallyw4
May 26 2016 01:53
@Chrono79 so it represent any element within the array or every element in array?
Asma
@asma8867
May 26 2016 01:54
@sjames1958gm what is three backticks? :(
Keenen Garnett
@Wallyw4
May 26 2016 01:54
``` @asma8867
Diego Mayer
@Chrono79
May 26 2016 01:54
@Wallyw4 filter() calls a provided callback function once for each element in an array, and constructs a new array of all the values for which callback returns a value that coerces to true. callback is invoked only for indexes of the array which have assigned values; it is not invoked for indexes which have been deleted or which have never been assigned values. Array elements which do not pass the callback test are simply skipped, and are not included in the new array.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
John
@tertiaryidentifier
May 26 2016 01:54
seeking help with the card counting challenge ... just need to know if I'm headed in the right direction
Stephen James
@sjames1958gm
May 26 2016 01:54
For my keyboard it is the character to the left of the 1 key
John
@tertiaryidentifier
May 26 2016 01:54
currently code also isn't working
richiedSIS
@richiedSIS
May 26 2016 01:55
@sjames1958gm Thanks! It makes a lot of sense now - thanks for your patience all morning!
CamperBot
@camperbot
May 26 2016 01:55
richiedsis sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1274 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
May 26 2016 01:55
@richiedSIS :+1:
Keenen Garnett
@Wallyw4
May 26 2016 01:55
under the tilde ~ @asma8867
thanks @sjames1958gm @Chrono79
CamperBot
@camperbot
May 26 2016 01:55
wallyw4 sends brownie points to @sjames1958gm and @chrono79 :sparkles: :thumbsup: :sparkles:
John
@tertiaryidentifier
May 26 2016 01:55
var count = 0;

function cc(card) {
  // Only change code below this line
   switch(card) {
     case 2:
     case 3:
     case 4:
     case 5:
     case 6:
       var count = count + 1;
       break;
     case 7:
     case 8:
     case 9:
       var count = count;
       break;
     case 10:
     case 'J':
     case 'Q':
     case 'A':
     case 'A':
       var count = count - 1;
       break;
   }

  if (count > 0) {
    return count + " Bet";
  } else if (count <= 0) {
    return count + " Hold";
  }

  }
CamperBot
@camperbot
May 26 2016 01:55
:cookie: 854 | @chrono79 |http://www.freecodecamp.com/chrono79
:star2: 1275 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Asma
@asma8867
May 26 2016 01:55
@sjames1958gm thanks :)
CamperBot
@camperbot
May 26 2016 01:55
asma8867 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1276 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Asma
@asma8867
May 26 2016 01:56
@Wallyw4 thanks :)
CamperBot
@camperbot
May 26 2016 01:56
asma8867 sends brownie points to @wallyw4 :sparkles: :thumbsup: :sparkles:
:cookie: 270 | @wallyw4 |http://www.freecodecamp.com/wallyw4
Stephen James
@sjames1958gm
May 26 2016 01:56
@tertiaryidentifier Two aces
Diego Mayer
@Chrono79
May 26 2016 01:57
@tertiaryidentifier don't redeclare count
Asma
@asma8867
May 26 2016 01:57
else if (count<0) {

   return count + " Hold";

}
John
@tertiaryidentifier
May 26 2016 01:57
thanks @asma8867 . where should I do that @chrono?
CamperBot
@camperbot
May 26 2016 01:57
tertiaryidentifier sends brownie points to @asma8867 and @chrono :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for chrono
:cookie: 211 | @asma8867 |http://www.freecodecamp.com/asma8867
Asma
@asma8867
May 26 2016 01:57
I was juct checking three backticks;)
Diego Mayer
@Chrono79
May 26 2016 01:58
@tertiaryidentifier var count = count - 1; delete var here and in the other cases, otherwise you're creating a local count, and you'll be changing that instead of the global one
John
@tertiaryidentifier
May 26 2016 01:59
@Chrono, I did that. still not working for some reason
Diego Mayer
@Chrono79
May 26 2016 01:59
@tertiaryidentifier show your code again
Stephen James
@sjames1958gm
May 26 2016 01:59
@tertiaryidentifier You have case 'A': twice
John
@tertiaryidentifier
May 26 2016 01:59
I also deleted the middle cases which didn't add anything (i.e. neutral 0)

var count = 0;

function cc(card) {
  // Only change code below this line
   switch(card) {
     case 2:
     case 3:
     case 4:
     case 5:
     case 6:
       count = count + 1;
       break;
     case 10:
     case 'J':
     case 'Q':
     case 'K':
     case 'A':
       count = count - 1;
       break;
   }

  if (count > 0) {
    return count + " Bet";
  } else if (count <= 0) {
    return count + " Hold";
  }

  }
or is count ==
wait no ..
Stephen James
@sjames1958gm
May 26 2016 02:00
@tertiaryidentifier That should work - maybe try refreshing browser.
John
@tertiaryidentifier
May 26 2016 02:00
grrr >.<
Diego Mayer
@Chrono79
May 26 2016 02:00
@tertiaryidentifier do as @sjames1958gm said
John
@tertiaryidentifier
May 26 2016 02:01
Tried refreshing. Says illegal syntax error
lemme check those brackets
I had one too many.
Thanks all! @Chrono79 @sjames1958gm @asma8867
CamperBot
@camperbot
May 26 2016 02:01
tertiaryidentifier sends brownie points to @chrono79 and @sjames1958gm and @asma8867 :sparkles: :thumbsup: :sparkles:
:warning: tertiaryidentifier already gave asma8867 points
:star2: 1277 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
:cookie: 855 | @chrono79 |http://www.freecodecamp.com/chrono79
Stephen James
@sjames1958gm
May 26 2016 02:02
@tertiaryidentifier :+1:
Matt
@TheeMattOliver
May 26 2016 02:06
Okay everyone what am I doing wrong?
var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
  }
  // Add record here
  {
    "artist": "Fleetwood Mac",
    "title": "Rumours",
    "release_year": 1977,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
  }
];
Stephen Mansfield
@StephenMansfield
May 26 2016 02:07
@TheeMattOliver whats the name on that one? I wanna look at the requirments
Matt
@TheeMattOliver
May 26 2016 02:08
It's the "Introducing JavaScript Object Notation"
Diego Mayer
@Chrono79
May 26 2016 02:09
@TheeMattOliver missing , between the objects
Stephen Mansfield
@StephenMansfield
May 26 2016 02:09
good eye @Chrono79
Matt
@TheeMattOliver
May 26 2016 02:10
@Chrono79 I've been squinting for something small like that but still can't....quite....seem...to find it
Diego Mayer
@Chrono79
May 26 2016 02:11
@TheeMattOliver put a comma before this {
// Add record here
  {
bleujai
@bleujai
May 26 2016 02:11
@TheeMattOliver Do you see where he is talking about?
Stephen Mansfield
@StephenMansfield
May 26 2016 02:11
above the //add record here
Matt
@TheeMattOliver
May 26 2016 02:12
Yes. Now I do. Thank you all very kindly. @Chrono79 @stephenmansfield @bleujai
CamperBot
@camperbot
May 26 2016 02:12
theemattoliver sends brownie points to @chrono79 and @stephenmansfield and @bleujai :sparkles: :thumbsup: :sparkles:
:cookie: 275 | @stephenmansfield |http://www.freecodecamp.com/stephenmansfield
:cookie: 856 | @chrono79 |http://www.freecodecamp.com/chrono79
:cookie: 412 | @bleujai |http://www.freecodecamp.com/bleujai
Matt
@TheeMattOliver
May 26 2016 02:13
so each "thing" inside a bracket is considered "a JSON object" then?
Or is the JSON object the entire shebang, and each bracketed item qualifies as an array?
and the arrays have to be separated by commas?
Norvin Burrus
@ndburrus
May 26 2016 02:14
@TheeMattOliver try a comma after the first record?
Diego Mayer
@Chrono79
May 26 2016 02:14
Could ask for some testing? Some people is telling me it doesn't work for them, but I know for sure it works (at least for me)
http://diego-mayer.neocities.org/modulo_8/entregaopcionalmodulo8.html it's in spanish, but, basically, tap starts/stops the clock and swipe resets it, the events are applied over the green part
Stephen James
@sjames1958gm
May 26 2016 02:14
@TheeMattOliver The last two - the whole thing is a JSON object
Matt
@TheeMattOliver
May 26 2016 02:14
Thanks @ndburrus we got it
CamperBot
@camperbot
May 26 2016 02:14
theemattoliver sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:cookie: 424 | @ndburrus |http://www.freecodecamp.com/ndburrus
Matt
@TheeMattOliver
May 26 2016 02:14
@sjames1958gm ok thanks just trying to wrap head around...
CamperBot
@camperbot
May 26 2016 02:14
theemattoliver sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1278 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Norvin Burrus
@ndburrus
May 26 2016 02:14
@TheeMattOliver ok... :)
John
@tertiaryidentifier
May 26 2016 02:17
@Chrono79 it's not working for me
Vicki
@vicki8g
May 26 2016 02:17

Hello, I have been stuck on the javascript basics for a few days. Ive tried googling but I am still lost on 'Accessing Nested Objects in JSON'. This is what I added var gloveBoxContents = "maps"; // Change this line
myStorage.car["inside"].gloveBoxContents;

console.log(myStorage);

Diego Mayer
@Chrono79
May 26 2016 02:17
This message was deleted
John
@tertiaryidentifier
May 26 2016 02:19
Chrome, y yo usé tus instruciones para hacer ctrl+shift,etc.
Norvin Burrus
@ndburrus
May 26 2016 02:21
@vicki8g inside is a property that can be accessed with dot notation...
Islam Ibakaev
@dagman
May 26 2016 02:21
just made animation scroll icon for my portfolio. check it out
Matt Doyle
@m4doyle
May 26 2016 02:22
Im working on the palindrome javascript excersize, and im having trouble creating an if statement to filter out my no space function
Vicki
@vicki8g
May 26 2016 02:22
@ndburrus I tried that variation myStorage.car.inside.gloveBoxContents; however I get an error
Norvin Burrus
@ndburrus
May 26 2016 02:23
@vicki8g ok, but did you also access maps by using bracket notation on glove box? (while using dot notation on inside) then, set the whole shebang equal to your variable...
Matt
@TheeMattOliver
May 26 2016 02:24
Hey @vicki8g to type your code into chat you can type three <copy and paste code here> then press command + enter
three ` marks
Vicki
@vicki8g
May 26 2016 02:25
@TheeMattOliver I have a surface pro... I dont know where the command button is
Matt
@TheeMattOliver
May 26 2016 02:25
oh i see pls hold
Norvin Burrus
@ndburrus
May 26 2016 02:26
@vicki8g see how the example works (ie accesses the desired value)?
var ourStorage = {
  "desk": {
    "drawer": "stapler"
  },
  "cabinet": {
    "top drawer": { 
      "folder1": "a file",
      "folder2": "secrets"
    },
    "bottom drawer": "soda"
  }
}
ourStorage.cabinet["top drawer"].folder2;  // "secrets"
ourStorage.desk.drawer; // "stapler"
Diego Mayer
@Chrono79
May 26 2016 02:26
@m4doyle what have you done so far?
Vicki
@vicki8g
May 26 2016 02:26
@ndburrus do you mean: var gloveBoxContents = "maps";
anaghfire
@anaghfire
May 26 2016 02:26
function rot13(str) { // LBH QVQ VG!
  return str.split('').map(shifted).join('');
  function shifted(element) {
    charCode=element.charCodeAt(0);
    if (charCode>=65 && charCode<=90) {
      charCode+=13;
      return String.fromCharCode(charCode>90 ? charCode-=25 : charCode);
    }
    return element;
  }
}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
Hi can anyone help me with the above code. Stuck on the Caesar's Cipher for quite some time now. Thanks. :)
Diego Mayer
@Chrono79
May 26 2016 02:28
@anaghfire you have to shift the charCode to the other side
charCode-=13; and fix your return
Vicki
@vicki8g
May 26 2016 02:29

```
// Setup
var myStorage = {
"car": {
"inside": {
"glove box": "maps",
"passenger seat": "crumbs"
},
"outside": {
"trunk": "jack"
}
}
};

// Only change code below this line

var gloveBoxContents = "maps"; // Change this line
myStorage.car.inside["glove box"];

console.log(myStorage);

Norvin Burrus
@ndburrus
May 26 2016 02:29
@vicki8g no. ok, start with the statement myStorage.car, next add inside. next access maps (via glove box, ie bracket notation), then assign the value of this statement to your variable (gloveBoxContents)
Vicki
@vicki8g
May 26 2016 02:30

// Setup
var myStorage = {
  "car": {
    "inside": {
      "glove box": "maps",
      "passenger seat": "crumbs"
     },
    "outside": {
      "trunk": "jack"
    }
  }
};

// Only change code below this line

var gloveBoxContents = "maps"; // Change this line
myStorage.car.inside["glove box"];

console.log(myStorage);
here is my code , thanks @TheeMattOliver
CamperBot
@camperbot
May 26 2016 02:30
vicki8g sends brownie points to @theemattoliver :sparkles: :thumbsup: :sparkles:
:cookie: 220 | @theemattoliver |http://www.freecodecamp.com/theemattoliver
Norvin Burrus
@ndburrus
May 26 2016 02:32
@vicki8g how are we doing?
Vicki
@vicki8g
May 26 2016 02:32
// Setup
var myStorage = {
  "car": {
    "inside": {
      "glove box": "maps",
      "passenger seat": "crumbs"
     },
    "outside": {
      "trunk": "jack"
    }
  }
};

// Only change code below this line

var gloveBoxContents = "maps"; // Change this line

myStorage.car.["glove box"];
console.log(myStorage);
@ndburrus
Norvin Burrus
@ndburrus
May 26 2016 02:32
@vicki8g where is inside? how does the code know where to look for maps?
Vicki
@vicki8g
May 26 2016 02:32
@ndburrus should I put it after car??
still get an error
Diego Mayer
@Chrono79
May 26 2016 02:33
This message was deleted
Norvin Burrus
@ndburrus
May 26 2016 02:34
@vicki8g ye, inside is next/inside after car, isn't it? we're just traversing successive inner levels, pointing to where we want to go...
Diego Mayer
@Chrono79
May 26 2016 02:35
@vicki8g as it is, you're using dot and bracket there too
Vicki
@vicki8g
May 26 2016 02:35
@ndburrus
// Setup
var myStorage = {
  "car": {
    "inside": {
      "glove box": "maps",
      "passenger seat": "crumbs"
     },
    "outside": {
      "trunk": "jack"
    }
  }
};

// Only change code below this line

var gloveBoxContents = "maps"; // Change this line

myStorage.car.inside["glove box"];
console.log(myStorage);
@Chrono79 thats what I have so far
Norvin Burrus
@ndburrus
May 26 2016 02:35
@ok, :) now assign the statement value to your variable...
Diego Mayer
@Chrono79
May 26 2016 02:35

@vicki8g almost ok
merge these 2 lines:

var gloveBoxContents = "maps"; // Change this line

myStorage.car.inside["glove box"];

replace "maps" in the first line with myStorage.car.inside["glove box"];

Vicki
@vicki8g
May 26 2016 02:36
@ndburrus I have no clue what you mean
@Chrono79 with the console.log() ??
Norvin Burrus
@ndburrus
May 26 2016 02:37
@vicki8g your variable is currently assigned the value of maps. eliminate maps. use the variable. ie assign the variable the stament value, which will be maps. then you could console.log(gloveBoxContents - to see maps)
Moisés Man
@moigithub
May 26 2016 02:38
any1 used jquery with headers before?? for some reason my code isnt sending...
i tested headers, beforeSend and ajaxSetup none works..
        $.ajax({
            url: API_URL,
            headers: { 'Authorization': 'some value' },  //<--- this dont show on devtools/network.. neither on server side
            method: 'POST',
            //type:'post', //old versions use type instead method
            dataType: 'json',
            data: {
                "book":bookName, "userId": user.userId
            },
})
Vicki
@vicki8g
May 26 2016 02:38
@Chrono79 so var gloveBoxContents = myStorage.car.inside["glove box"];
Diego Mayer
@Chrono79
May 26 2016 02:38
@vicki8g yes
Vicki
@vicki8g
May 26 2016 02:39
@Chrono79 omg I luv you!! thanks
CamperBot
@camperbot
May 26 2016 02:39
vicki8g sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:cookie: 857 | @chrono79 |http://www.freecodecamp.com/chrono79
Vicki
@vicki8g
May 26 2016 02:39
@ndburrus thanks
CamperBot
@camperbot
May 26 2016 02:39
vicki8g sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:cookie: 425 | @ndburrus |http://www.freecodecamp.com/ndburrus
Norvin Burrus
@ndburrus
May 26 2016 02:39
@vicki8g you're on fire!! :fire:
Matt Doyle
@m4doyle
May 26 2016 02:50
could someone please explain this method for me
var strippedStr = str.toLowerCase().replace(/\W|_/g, '');
wh
what is the replace doing here
anyone?
bleujai
@bleujai
May 26 2016 02:53
Replace looks for a regular expression and, in this case because of the flag g that is used to indicate global, all non numbers and letters or an underscore are replaced with an empty string. Essentially it is eliminated from the string.
Matt Doyle
@m4doyle
May 26 2016 02:53
@bleujai \W|_
what does that part do
Rhys
@LucidNightmare
May 26 2016 02:54
Quick question all.
bleujai
@bleujai
May 26 2016 02:54
That is the regular expression that you are searching for, all non numbers and letters or an underscore.
Matt
@TheeMattOliver
May 26 2016 02:55
@ndburrus that explanation of moving steadily inward and then assigning the value of that statement to the variable was helpful.
bleujai
@bleujai
May 26 2016 02:55
Good thing to learn about. A little tough in the beginning but worth it for its usefulness.
Rhys
@LucidNightmare
May 26 2016 02:55
say I've stored a jQuery selection in a variable storeVar, how do I alter the nth element?
Matt Doyle
@m4doyle
May 26 2016 02:55
@bleujai so the | is actually an or operator?
Rhys
@LucidNightmare
May 26 2016 02:56
storeVar[n] is failing me
bleujai
@bleujai
May 26 2016 02:56
Yes, it says if you see this or that and it can be used in different combinations.
Rhys
@LucidNightmare
May 26 2016 02:56
when I try to chain it with something like .addClass()
Matt Doyle
@m4doyle
May 26 2016 02:57
@bleujai but doesnt \W already include underscores?
why are we stating it again
Matches any character that is not a word character from the basic Latin alphabet. Equivalent to [^A-Za-z0-9_].
bleujai
@bleujai
May 26 2016 02:58
\W
Matches any character that is not a word character from the basic Latin alphabet. Equivalent to [^A-Za-z0-9_].
_ is not included in \W
Matt Doyle
@m4doyle
May 26 2016 02:58
its right there after the 9
bleujai
@bleujai
May 26 2016 02:59
there is a ^ in the beginning that means not those.
compare it to \w
Tiffany White
@twhite96
May 26 2016 03:09
Can someone tell me why the method slice() in this instance returns Banana?
var str = "Apple, Banana, Kiwi";
document.getElementById("demo").innerHTML = str.slice(7,13);
Norvin Burrus
@ndburrus
May 26 2016 03:09
@TheeMattOliver great... glad it was useful. it is a process working with json objects. I'm doing some further reading to better understand it. A great data slice & dice communication tool/protocol. JSON (canonically pronounced /ˈdʒeɪsən/ jay-sən;[1] sometimes JavaScript Object Notation) is an open-standard format that uses human-readable text to transmit data objects consisting of attribute–value pairs. It is the most common data format used for asynchronous browser/server communication (AJAJ), largely replacing XML which is used by AJAX. :) {ref: https://en.wikipedia.org/wiki/JSON } AJAJ AJAJ From Wikipedia, the free encyclopedia AJAJ (short for asynchronous JavaScript and JSON) is a group of interrelated web development techniques used on the client-side to create asynchronous web applications. Unlike its predecessor AJAX, which uses XML, in AJAJ the content sent back and forth between the client and server is strictly JSON. The term AJAJ has been used since 2006.[1] Despite being a more precise term, use of the term AJAJ did not become widespread, and many people describe a process as "AJAX" when they are in fact talking about AJAJ (because they are receiving JSON formatted data in the response, not XML).{ref: https://en.wikipedia.org/wiki/AJAJ }
Tiffany White
@twhite96
May 26 2016 03:10
When you count from the end you get to the B
When you count from the zero index in front you also get to the B
Or am I missing something?
Kyle W Pilkinton
@tadake
May 26 2016 03:10
can anyone help me figure out whats wrong with my code? I cant seem to populate my final variable.
function pairElement(str) {
  a = ["A","T"];
  t = ["T","A"];
  c = ["C","G"];
  g = ["G","C"];
  final = [];
  sect = [];
  for(var i = 0; i < str.lenght; i++){

     if(str[i] === A){
      sect.push(a);
    }
     if(str[i] === T){
      sect.push(t);
    }
     if(str[i] === C){
      sect.push(c);
    }
     if(str[i] === G){
      sect.push(g);
    }

  }
   final.push(sect);


  return final;

}

pairElement("GCG");
Tiffany White
@twhite96
May 26 2016 03:10
Banana is what is extracted but what is meant by extracted?
bleujai
@bleujai
May 26 2016 03:11
@twhite96 .slice(7,13); Begin slice at 7 and end at 13 and don't include it.
Tiffany White
@twhite96
May 26 2016 03:12
Okay. That makes sense @bleujai. Thanks
CamperBot
@camperbot
May 26 2016 03:12
twhite96 sends brownie points to @bleujai :sparkles: :thumbsup: :sparkles:
:cookie: 413 | @bleujai |http://www.freecodecamp.com/bleujai
bleujai
@bleujai
May 26 2016 03:13
:+1:
Bharath
@bharathkumar-b
May 26 2016 03:15
@tadake you made two mistakes in your code

function pairElement(str) {
a = ["A", "T"];
t = ["T", "A"];
c = ["C", "G"];
g = ["G", "C"];
final = [];
sect = [];
for (var i = 0; i < str.length; i++) {
if (str[i] === "A") {
sect.push(a);
}
if (str[i] === "T") {
sect.push(t);
}
if (str[i] === "C") {
sect.push(c);
}
if (str[i] === "G") {
sect.push(g);
}

}
final.push(sect);


return final;

}

pairElement("GCG");

one is length spelt incorrectly
bleujai
@bleujai
May 26 2016 03:15
@tadake These should be declared.
  a = ["A","T"];
  t = ["T","A"];
  c = ["C","G"];
  g = ["G","C"];
  final = [];
  sect = [];
Kyle W Pilkinton
@tadake
May 26 2016 03:16
Thanks!! @bleujai
CamperBot
@camperbot
May 26 2016 03:16
tadake sends brownie points to @bleujai :sparkles: :thumbsup: :sparkles:
:cookie: 414 | @bleujai |http://www.freecodecamp.com/bleujai
Bharath
@bharathkumar-b
May 26 2016 03:16
two you are using T as come variable instead it should be used as string

function pairElement(str) {
a = ["A", "T"];
t = ["T", "A"];
c = ["C", "G"];
g = ["G", "C"];
final = [];
sect = [];
for (var i = 0; i < str.length; i++) {
if (str[i] === "A") {
sect.push(a);
}
if (str[i] === "T") {
sect.push(t);
}
if (str[i] === "C") {
sect.push(c);
}
if (str[i] === "G") {
sect.push(g);
}

}
final.push(sect);


return final;

}

pairElement("GCG");

Justin Martin
@TheHeavyRhino
May 26 2016 03:19
Someone mind giving me a hint, while not completely giving it away? I'm a lil lost on "Profile Lookup"
Norvin Burrus
@ndburrus
May 26 2016 03:21
@TheHeavyRhino do you have some code?
bleujai
@bleujai
May 26 2016 03:21
@TheHeavyRhino What kind of variable is contacts?
Justin Martin
@TheHeavyRhino
May 26 2016 03:21
Yeah I'm trying to figure out how to post it in code format..

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

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

if (contacts.hasOwnProperty(firstName) && contacts.hasOwnPorperty(prop)){
return contacts.firstName[prop];
} else if (!contacts.hasOwnProperty(firstName)){
return "No such contact";
} else if (!contacts.hasOwnPorperty(prop)){
return "No such property";
} else
return "Nothing Found";

// Only change code above this line
}

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

I keep getting "No such contact" as result
regardless of values entered
bleujai
@bleujai
May 26 2016 03:24
@bharathkumar-b read the instructions one more time and look at your code.
CyrilSL
@CyrilSL
May 26 2016 03:25
@bharathkumar-b You made a small mistake can you figure it out.
Justin Martin
@TheHeavyRhino
May 26 2016 03:25
@bleujai contacts is global variable...
bleujai
@bleujai
May 26 2016 03:26
@TheHeavyRhino OK, array or object?
@bharathkumar-b figure it out?
Justin Martin
@TheHeavyRhino
May 26 2016 03:27
@bleujai array.. do I need to use some brackets? [0]?
bleujai
@bleujai
May 26 2016 03:27
Here is likely the hint you need. Contacts is an array of objects so you need to combine the methods for accessing each type.
Justin Martin
@TheHeavyRhino
May 26 2016 03:28
@bleujai ok.. I think I know what you're getting at.. thanks.. I may be back.
CamperBot
@camperbot
May 26 2016 03:28
theheavyrhino sends brownie points to @bleujai :sparkles: :thumbsup: :sparkles:
:cookie: 415 | @bleujai |http://www.freecodecamp.com/bleujai
bleujai
@bleujai
May 26 2016 03:28
contacts[0] is the first object, contacts[1] is the second, and so on...
CyrilSL
@CyrilSL
May 26 2016 03:28
@TheHeavyRhino To post it in code insert your code between two ```
bleujai
@bleujai
May 26 2016 03:29
Yep, you've got it
Justin Martin
@TheHeavyRhino
May 26 2016 03:29
@CyrilSL thanks.. i'll do that next time.
CamperBot
@camperbot
May 26 2016 03:29
theheavyrhino sends brownie points to @cyrilsl :sparkles: :thumbsup: :sparkles:
:cookie: 310 | @cyrilsl |http://www.freecodecamp.com/cyrilsl
OneRandomJamie
@OneRandomJamie
May 26 2016 03:29
Could someone help me with he Stand in line challenge?
CyrilSL
@CyrilSL
May 26 2016 03:30
@OneRandomJamie Post you current code?
OneRandomJamie
@OneRandomJamie
May 26 2016 03:30

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

return item; // Change this line
}

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

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

Tiffany White
@twhite96
May 26 2016 03:30
How would any of you go about thinking about this in this algorithm challenge?
However, if the given maximum string length num is less than or equal to 3, then the addition of the three dots does not add to the string length in determining the truncated string.
Norvin Burrus
@ndburrus
May 26 2016 03:31
@CyrilSL ok, there are four (4) array operations push, pop, shift & unshift that you can consider using to meet the requirements...
CyrilSL
@CyrilSL
May 26 2016 03:32
@OneRandomJamie All you have to do is push 'item' to the end of the array and remove the first element in array.
Manish Giri
@Manish-Giri
May 26 2016 03:32
@OneRandomJamie use .push() and .shift()
bleujai
@bleujai
May 26 2016 03:33
@twhite96 Next time just copy and paste the text please without the code ticks.
OneRandomJamie
@OneRandomJamie
May 26 2016 03:33
@CyrilSL @Manish-Giri
Norvin Burrus
@ndburrus
May 26 2016 03:33
@twhite96 do you have an idea how to proceed?
CyrilSL
@CyrilSL
May 26 2016 03:33
@OneRandomJamie Got it?
Tiffany White
@twhite96
May 26 2016 03:33
@ndburrus kind of
bleujai
@bleujai
May 26 2016 03:33
@twhite96 Much appreciated.
OneRandomJamie
@OneRandomJamie
May 26 2016 03:34
@CyrilSL @Manish-Giri Thank you. I got it
CamperBot
@camperbot
May 26 2016 03:34
onerandomjamie sends brownie points to @cyrilsl and @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 1116 | @manish-giri |http://www.freecodecamp.com/manish-giri
:cookie: 311 | @cyrilsl |http://www.freecodecamp.com/cyrilsl
Manish Giri
@Manish-Giri
May 26 2016 03:34
@OneRandomJamie welcome
Norvin Burrus
@ndburrus
May 26 2016 03:34
@twhite96 ok, the 1st requirement is to add the number to the end of the array. how would we do that? can you write that statement?
Tiffany White
@twhite96
May 26 2016 03:35
Actually @ndburrus that is the second requirement. I have the first part down, as far as thinking abou tit
@ndburrus I need to use String.slice() here
I will post the whole thing

@ndburrus Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a ... ending.

Note that inserting the three dots to the end will add to the string length.

However, if the given maximum string length num is less than or equal to 3, then the addition of the three dots does not add to the string length in determining the truncated string

The beginning code is this
Norvin Burrus
@ndburrus
May 26 2016 03:36
onerandomjamie i thought the challenge was stand in line? i', sorry - i posted to the wrong name... and they solved it already...
Tiffany White
@twhite96
May 26 2016 03:37
@ndburrus no it is truncate a sting
Norvin Burrus
@ndburrus
May 26 2016 03:38
@twhite96 i haven't completed truncate a string yet... :(
Tiffany White
@twhite96
May 26 2016 03:38
This message was deleted
Ohhhh okay @ndburrus
Matt
@TheeMattOliver
May 26 2016 03:43
Can anyone give me a hint on Record Collection in terms of how I should be thinking about how to "update or set the value for the prop"?
bleujai
@bleujai
May 26 2016 03:43

If it is longer than the given maximum length (second argument). Return the truncated string (original string cut short) with a ... ending. (Note that inserting the three dots to the end will add to the string length.)

If the given maximum string length num is 3 or less, then the addition of the three dots does not add to the string length in determining the truncated string (I believe this simply meant not to include the three dots in this case.)

@twhite96 Reworded a bit.
DJ
@qualitymanifest
May 26 2016 03:44
@twhite96 so if str is "words" and num is 4, you include the length of the dots in the subtraction from str and you get "w...". but if num was 2 for example, think what would happen if you tried to include the length of the dots in the subtraction from str - it would be a negative number, completely deleting str. so they're saying if it's less than three, for example 2, you would get "wo..." since you're not subtracting the length of the dots from str
Dylan
@dhcodes
May 26 2016 03:45
collection[prop] = your update @TheeMattOliver
well it may be more but you get the idea
DJ
@qualitymanifest
May 26 2016 03:45
this is kind of a hard one to explain
Dylan
@dhcodes
May 26 2016 03:45
use bracket notation
@TheeMattOliver
Matt
@TheeMattOliver
May 26 2016 03:45
thanks @dhcodes
CamperBot
@camperbot
May 26 2016 03:45
theemattoliver sends brownie points to @dhcodes :sparkles: :thumbsup: :sparkles:
:cookie: 885 | @dhcodes |http://www.freecodecamp.com/dhcodes
Norvin Burrus
@ndburrus
May 26 2016 03:47
@TheeMattOliver do you have some code? :)
Matt
@TheeMattOliver
May 26 2016 03:48
@ndburrus trying to get something going....
buiphuking
@buiphuking
May 26 2016 03:49
hi guys, help me
i code in codepen, i code something wrong and my cpu go crazy, and my pc freeze , i close the tab and open it, but i can't access my thing, what should 1 do ???????
Norvin Burrus
@ndburrus
May 26 2016 03:50
@TheeMattOliver ok, i found it helpful to map the conditions in the order they are given in the challenge. also, when double conditions are presented, i evaluated those simultaneously (in the same conditional statement). this way, i could easily follow the logic per the challenge (requirements/order, etc.) have you selected you conditional statement/s yet?
This message was deleted
CyrilSL
@CyrilSL
May 26 2016 03:56
@buiphuking By default autosave is enabled check your profile it might be there.
Matt
@TheeMattOliver
May 26 2016 03:56
@ndburrus yes pls I'm still unclear about how to update or set the value for prop but so far I've got:
CyrilSL
@CyrilSL
May 26 2016 03:57
@TheeMattOliver Post your code.
bleujai
@bleujai
May 26 2016 03:57
@buiphuking Your pens should have saved if you kept auto-save on. On the main page after you log in check the right side bar and there should be a display of your previous pens.
Matt
@TheeMattOliver
May 26 2016 03:58
 // Setup
var collection = {
    2548: {
      album: "Slippery When Wet",
      artist: "Bon Jovi",
      tracks: [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    2468: {
      album: "1999",
      artist: "Prince",
      tracks: [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    1245: {
      artist: "Robert Palmer",
      tracks: [ ]
    },
    5439: {
      album: "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

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

  if (value !== "" && prop !== "tracks") {
    <something here???>
      } else if (value !== "" && prop == "tracks") {
        tracks.push("value");
      } else if(value == "") {

  }
  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
CyrilSL
@CyrilSL
May 26 2016 03:58
@buiphuking Anyway what were you coding that could make your computer freeze.
Matt
@TheeMattOliver
May 26 2016 04:00
I know it's a train wreck right now
buiphuking
@buiphuking
May 26 2016 04:01

@CyrilSL

function updateTime(seconds){
  var m = seconds / 60;
  var s = seconds % 60;
  function checkTime(){
    while( i < 10){
    i = "0" + i;
    }  
  }

  m = checkTime(m);
  s = checkTime(s);

  $('#minutes').html(m);
  $('#seconds').hmtl(s);
}

i do pomodoro clock , something around main function to make the clock run

Norvin Burrus
@ndburrus
May 26 2016 04:01
@TheeMattOliver ok, <something here???> is where you use the json object (collection). you point towards the value using bracket notation (because your using variables).... does this help?
Matt
@TheeMattOliver
May 26 2016 04:01
let me think about that for a minute @ndburrus
Norvin Burrus
@ndburrus
May 26 2016 04:01
@TheeMattOliver ok...
bleujai
@bleujai
May 26 2016 04:02
@buiphuking Looks like your while loop is an endless loop.
"0" + a number = a string
buiphuking
@buiphuking
May 26 2016 04:04
@bleujai
i can access but i cant do anything, freeze instantly when i access
CyrilSL
@CyrilSL
May 26 2016 04:05
@buiphuking You have not declared a vallue for i. Your i value is 'undefined' so you cannot add anyting to undefined.
Matt
@TheeMattOliver
May 26 2016 04:05
// Setup
var collection = {
    2548: {
      album: "Slippery When Wet",
      artist: "Bon Jovi",
      tracks: [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    2468: {
      album: "1999",
      artist: "Prince",
      tracks: [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    1245: {
      artist: "Robert Palmer",
      tracks: [ ]
    },
    5439: {
      album: "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

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

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

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
definitely still a trainwreck...
William Coleman
@wcski
May 26 2016 04:07
Well, I'm back on the Profile Lookup challenge after a few days off and I am clueless as to where to start lol. Hard to stay motivated when you come back to something that you're at a loss on. /rant
Not sure how long you've been at it but I was stuck on Record Collection for a few days too, @TheeMattOliver. Unfortunately I don't know JS well enough to be able to give you effective hints, but I just wanted to share that you will get it eventually
bleujai
@bleujai
May 26 2016 04:10
@wcski What code do you have so far?
Catalin Scripcariu
@CatalinScr
May 26 2016 04:10
Help no repeats please
CamperBot
@camperbot
May 26 2016 04:10

:point_right: algorithm no repeats please [wiki]

Algorithm No Repeats Please

Problem Explanation:

This task requires us to look at each possible permutation of a string. This can be done using a recursion function, but it is not the only way. A common interview question is building a function which collects all permutations of a string. So there is no shortage of tutorials out there on how to do this, in many different code languages.

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

William Coleman
@wcski
May 26 2016 04:11
I erased all my code because I didn't think it was right, and all i have right now is pseudo code
help profile lookup
CamperBot
@camperbot
May 26 2016 04:11

:point_right: challenge profile lookup [wiki]

Challenge Profile Lookup

Instructions

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

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

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

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

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

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

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

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

William Coleman
@wcski
May 26 2016 04:11
I didn't know about the help bot, derp.
bleujai
@bleujai
May 26 2016 04:11
@wcski That's ok. Pseudo code is a good place to start.
hehe
@wcski Do you remember what contacts is and what it contains?
William Coleman
@wcski
May 26 2016 04:13
Yeah, it's an array of objects
bleujai
@bleujai
May 26 2016 04:13
Since it's an array you'll need to iterate through it to check for what you are looking for.
Then you can compare what is in an object versus what you are looking for and work from there.
I'm keeping it pseudo code talk for now to give you a chance to think through what code to use.
CyrilSL
@CyrilSL
May 26 2016 04:16
@TheeMattOliver Did you get it??
Matt
@TheeMattOliver
May 26 2016 04:17
@cyrilSL I'm slow
but give me a minute and i'll report back with updated code
Natan Corro
@natancorro
May 26 2016 04:18
Hello
CyrilSL
@CyrilSL
May 26 2016 04:18
@natancorro Hey
Luis Amador
@MrLuisAmador
May 26 2016 04:18
Hi, I'm not really understanding the instructions to finish the Word Blanks test
Natan Corro
@natancorro
May 26 2016 04:19
How to delete commas in string and spaces, pls
CyrilSL
@CyrilSL
May 26 2016 04:19
I think you can use .replace()
Natan Corro
@natancorro
May 26 2016 04:20
But i dont know the use of diagonals like /\
CyrilSL
@CyrilSL
May 26 2016 04:20
@natancorro Which challenge are you in?
Natan Corro
@natancorro
May 26 2016 04:20
check for palindromes
Norvin Burrus
@ndburrus
May 26 2016 04:21
@MrLuisAmador can you post your code so far?
CyrilSL
@CyrilSL
May 26 2016 04:21
@natancorro Use .replace(/\W|_/g, '')
Matt
@TheeMattOliver
May 26 2016 04:21

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

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

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

  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
still feeling foggy
"For the given id in collection" = collection[id]
right?
Natan Corro
@natancorro
May 26 2016 04:22
Tks alot @CyrilSL U rocks!
Luis Amador
@MrLuisAmador
May 26 2016 04:22

@ndburrus function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "";
// Your code below this line

// Your code above this line
return result;
}

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

CyrilSL
@CyrilSL
May 26 2016 04:23
@TheeMattOliver Does this code work.
Matt
@TheeMattOliver
May 26 2016 04:23
no
just trying to talk it through
Norvin Burrus
@ndburrus
May 26 2016 04:23
@TheeMattOliver ok, this statement needs attention collection[id].tracks.push(value);similar to using brackets for id (because it's a variable), we need to use brackets for tracks (because it is a variable also)
bleujai
@bleujai
May 26 2016 04:24
@MrLuisAmador You want to make a complete sentence using the arguments they give you when the function is called. You'll need to add spaces and punctuation to make it a sentence.
Norvin Burrus
@ndburrus
May 26 2016 04:24
@MrLuisAmador alright, have you identified a madlib (sentence) that you'd like to build/construct?
CyrilSL
@CyrilSL
May 26 2016 04:24
@TheeMattOliver Your pretty close what you have to do is.
Dont use '.' use brackets.
Matt
@TheeMattOliver
May 26 2016 04:25
@ndburrus right, I think I had initially written something a lot simpler like collection.push("value");
hang on @CyrilSL let's see what happens...
Luis Amador
@MrLuisAmador
May 26 2016 04:26
@bleujai @ndburrus thanks guys. I didn't get that from the instructions.
CamperBot
@camperbot
May 26 2016 04:26
mrluisamador sends brownie points to @bleujai and @ndburrus :sparkles: :thumbsup: :sparkles:
:cookie: 416 | @bleujai |http://www.freecodecamp.com/bleujai
:cookie: 426 | @ndburrus |http://www.freecodecamp.com/ndburrus
Luis Amador
@MrLuisAmador
May 26 2016 04:27
Let me do that now
Matt
@TheeMattOliver
May 26 2016 04:27
narp
CyrilSL
@CyrilSL
May 26 2016 04:27
Lisen to me
Norvin Burrus
@ndburrus
May 26 2016 04:27
@TheeMattOliver also, this statement needs adjusting... delete collection.prop;in order to properly identify which property (there are properties under four different id's), we have to point to it. we can do that by including the appropriate id (which is a variable - an input variable)
CyrilSL
@CyrilSL
May 26 2016 04:27
Use collection[id][prop].push(value);
and delete collection[id][prop];
Thats it.
Your pretty close but you'r deleting and pushing wrong.
Luis Amador
@MrLuisAmador
May 26 2016 04:29
Ok guys. I was able to pass that test
Thank you
Norvin Burrus
@ndburrus
May 26 2016 04:30
@MrLuisAmador kudos to you!! :+1:
@TheeMattOliver is it getting clearer?
Matt
@TheeMattOliver
May 26 2016 04:31
gracias CyrilSL and @ndburrus, the code runs but still feeling foggy
William Coleman
@wcski
May 26 2016 04:32
the hints made me more confused :(
CyrilSL
@CyrilSL
May 26 2016 04:32
@TheeMattOliver Which means you passed?
Matt
@TheeMattOliver
May 26 2016 04:32
code passed, yes, thank you
trying to brake @ndburrus explanation into some manageable chunks here...
CyrilSL
@CyrilSL
May 26 2016 04:33
@TheeMattOliver What do you mean by foggy.. like headache?
William Coleman
@wcski
May 26 2016 04:33
here's my janky, janky code
function lookUpProfile(firstName, prop){
// Only change code below this line
for (i = 0, i < contacts.length, i++){
  if (firstName === contacts[???] && prop === contacts[???]) {
    return contacts[prop][value]???;
  } else if (prop != contacts[???]) {
    return "No such property"
  } else if (firstName != contacts[???])

}
return "No such contact";

// Only change code above this line
Kyle
@Kpez16
May 26 2016 04:34
Hello, I am having trouble on the Testing Objects for Properties exercise. function checkObj(checkProp) {
// Your Code Here
if (myObj.hasOwnProperty(checkProp) === true) {
return myObj.checkProp;
}
else {
return "Not Found";
}
}
Norvin Burrus
@ndburrus
May 26 2016 04:34
@TheeMattOliver the code logic looked good. it's just getting comfortable with the json object syntax.... particularly, dot vs bracket notation. this may be useful: Property accessors - JavaScript MDN {ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors }
William Coleman
@wcski
May 26 2016 04:34
things I don't know:
  1. How to use bracket and/or dot notation to check if the objects in the array contain the firstName or prop
  2. How to structure my for loop and nested if statement
Pretty sure I need to set a variable
but I don't really know why, it just seems like it makes sense
Matt
@TheeMattOliver
May 26 2016 04:36
@CyrilSL just tired. long day, very new to JS, it's foreign feeling and i'm very process-oriented so unless i understand it fundamentally top-to-bottom every step of the way it still feels foggy to me. thanks @ndburrus I'll have a look.
CamperBot
@camperbot
May 26 2016 04:36
theemattoliver sends brownie points to @cyrilsl and @ndburrus :sparkles: :thumbsup: :sparkles:
:cookie: 312 | @cyrilsl |http://www.freecodecamp.com/cyrilsl
:cookie: 427 | @ndburrus |http://www.freecodecamp.com/ndburrus
CyrilSL
@CyrilSL
May 26 2016 04:36
@wcski I understand, its just simple problems all you need it to keep practising.
Norvin Burrus
@ndburrus
May 26 2016 04:37
@Kpez16 ok, this statement needs attaention if (myObj.hasOwnProperty(checkProp) === true) {it already evaluates to a boulean, so you don't need to add one...
CyrilSL
@CyrilSL
May 26 2016 04:37
@TheeMattOliver Just take rest, come back fresh.
Liam Williams
@Liamw0403
May 26 2016 04:37

Hey guys! How do I concatenate a string over multiple lines using the += operator? My two lines I wrote are

var myStr = "This is the first sentence. ";
var myStr += "This is the second sentence.";

Kyle
@Kpez16
May 26 2016 04:37
@ndburrus hmm I was wondering that.
CyrilSL
@CyrilSL
May 26 2016 04:38
@Liamw0403 You dont need to declare the same variable twice.
You already declared `myStr once its enough.
Liam Williams
@Liamw0403
May 26 2016 04:39
@CyrilSL so what would the second line be? im trying to figure it out
Norvin Burrus
@ndburrus
May 26 2016 04:39
@Kpez16 see/read the first sentence. quiz: what does this method return? {ref: MDN, Object.prototype.hasOwnProperty(), https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty }
The hasOwnProperty() method returns a boolean indicating whether the object has the specified property.

SyntaxEDIT
obj.hasOwnProperty(prop)
Parameters
prop
The name of the property to test.
DescriptionEDIT
Every object descended from Object inherits the hasOwnProperty method. This method can be used to determine whether an object has the specified property as a direct property of that object; unlike the in operator, this method does not check down the object's prototype chain.

ExamplesEDIT
Using hasOwnProperty to test for a property's existence
The following example determines whether the o object contains a property named prop:

o = new Object();
o.prop = 'exists';

function changeO() {
  o.newprop = o.prop;
  delete o.prop;
}

o.hasOwnProperty('prop');   // returns true
changeO();
o.hasOwnProperty('prop');   // returns false
CyrilSL
@CyrilSL
May 26 2016 04:39
removevar
Liam Williams
@Liamw0403
May 26 2016 04:40
@CyrilSL ah that makes sense. I am still very new I apologise! Thank you very much
CamperBot
@camperbot
May 26 2016 04:40
liamw0403 sends brownie points to @cyrilsl :sparkles: :thumbsup: :sparkles:
:cookie: 313 | @cyrilsl |http://www.freecodecamp.com/cyrilsl
Kyle
@Kpez16
May 26 2016 04:40
@ndburrus ok I am just confused though because I can't return the value of the property with dot notation using myObj.checkprop; Is there something I am missing with that?
William Coleman
@wcski
May 26 2016 04:41
Ah, Eloquent Javascript just taught me that When using a dot, the part after the dot must be a valid variable name,
which seems helpful.
in general. maybe not for this specific challenge (but maybe so). lol.
Norvin Burrus
@ndburrus
May 26 2016 04:42
@Kpez16 well, do you really need to return the value? or is it sufficient to know only if the value exists (ie a boulean indication/or)? if it (the value) exists, can you take an action?
Kyle
@Kpez16
May 26 2016 04:43
@ndburrus it does require me to return the properties value. Which would correlate with checkProp?
Norvin Burrus
@ndburrus
May 26 2016 04:44
@Kpez16 oh, that is correct. i was referring to this line - has it been updated? if (myObj.hasOwnProperty(checkProp) === true) { when you need to access the value (ie for a return), remember we are dealing with variables. so would we use dot or bracket notation? in this line return myObj.checkProp;
Aryan
@aryandua
May 26 2016 04:45
@aryandua
Hey can someone tell me why the value of the button doesn't update??
http://codepen.io/aryandua/full/KzOPrE
Chris Fornesa
@cftxp
May 26 2016 04:46
thanks @leftynaut for your help with Checkpoint: Record Collection
CamperBot
@camperbot
May 26 2016 04:46
cftxp sends brownie points to @leftynaut :sparkles: :thumbsup: :sparkles:
:cookie: 515 | @leftynaut |http://www.freecodecamp.com/leftynaut
Kyle
@Kpez16
May 26 2016 04:46
@ndburrus I had been assuming I could use either lol but I believe I have tried both
Norvin Burrus
@ndburrus
May 26 2016 04:47
@Kpez16 au contraire my friend, au contraire.... :sparkles: this may be useful: MDN, Property accessors - JavaScript {ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors } (dot vs bracket notation)
96street
@96street
May 26 2016 04:48
Why doesn't this work for some of the tests? (Where do I belong)
function getIndexToIns(arr, num) {
  arr.push(num);
  arr.sort();
  return arr.indexOf(num);
}

getIndexToIns([2, 5, 10], 15);
Kyle
@Kpez16
May 26 2016 04:49
@ndburrus man I am confused then.
Rada
@Radascript
May 26 2016 04:50
@aryandua use document.getElementById(newArr[num-1]).innerHTML = x;
instead of .value
Aryan
@aryandua
May 26 2016 04:50
ok @Radascript thx
CamperBot
@camperbot
May 26 2016 04:50
aryandua sends brownie points to @radascript :sparkles: :thumbsup: :sparkles:
:cookie: 349 | @radascript |http://www.freecodecamp.com/radascript
DJ
@qualitymanifest
May 26 2016 04:50
@96street .sort by itself sorts alphabetically so 2 > 10. you need a numerical sort function
Rada
@Radascript
May 26 2016 04:50
@aryandua yw!
Norvin Burrus
@ndburrus
May 26 2016 04:50
@Kpez16 basically, you can hard code when referring to specific items. when you are using/referencing variables use bracket notation
Aryan
@aryandua
May 26 2016 04:51
This message was deleted
This message was deleted
oh hey nvm
I commented out my prompt :)
Rada
@Radascript
May 26 2016 04:51
@aryandua yeah you commented out the prompt
@aryandua as a sidenote, I think your array approach is really neat, good job
Kyle
@Kpez16
May 26 2016 04:52
@ndburrus lol I think I was putting the parameter checkProp in quotations when trying bracket notation.
Aryan
@aryandua
May 26 2016 04:52
@Radascript :)
Kyle
@Kpez16
May 26 2016 04:52
@ndburrus thanks for the help, and for not just giving me the answer!
CamperBot
@camperbot
May 26 2016 04:52
kpez16 sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:cookie: 428 | @ndburrus |http://www.freecodecamp.com/ndburrus
Aryan
@aryandua
May 26 2016 04:52
It will help in the check and rand function :)
@Radascript
96street
@96street
May 26 2016 04:53
@qualitymanifest any suggestions?
Norvin Burrus
@ndburrus
May 26 2016 04:53
@Kpez16 so, you wanted to increase the challenge difficulty, did you? :) you bet, anytime!!
Rada
@Radascript
May 26 2016 04:54
@aryandua yeah for sure. Good luck with the rest of the challenge!
Aryan
@aryandua
May 26 2016 04:54
thanyou @Radascript
DJ
@qualitymanifest
May 26 2016 04:54
@96street this has some good info, i think there is also a numerical sort function used in the docs https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
NixonRichard
@NixonRichard
May 26 2016 04:56
hi guyz can u help me with my challenge here s the link https://www.freecodecamp.com/challenges/using-objects-for-lookups#?
96street
@96street
May 26 2016 04:58
Yep the code works now ty @qualitymanifest
CamperBot
@camperbot
May 26 2016 04:58
96street sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star2: 1176 | @qualitymanifest |http://www.freecodecamp.com/qualitymanifest
96street
@96street
May 26 2016 04:58
I don't know the meaning behing the a - b thing though, can you explain it
function getIndexToIns(arr, num) {
  arr.push(num);
  arr.sort(function(a, b){
    return a - b;
  });
  return arr.indexOf(num);
}

getIndexToIns([2, 5, 10], 15);
DJ
@qualitymanifest
May 26 2016 05:01
@96street it's explained pretty well in that first link i provided, scroll down to the part that says "Otherwise the argument to sort is a comparison function"
Kyle W Pilkinton
@tadake
May 26 2016 05:02
can anyone explain what arr.reduce does and how to use it??
Joan Acosta
@choanm
May 26 2016 05:03
Hey can someone give me a guide of JSON? I just started with that and I'm kinda confused with the objects and all of that
Coy Sanders
@coymeetsworld
May 26 2016 05:05
@tadake arr.reduce runs a function on each value in the array and "reduces" the array to a single value
Joan Acosta
@choanm
May 26 2016 05:05
Thank you @Zerazera :)
CamperBot
@camperbot
May 26 2016 05:05
choanm sends brownie points to @zerazera :sparkles: :thumbsup: :sparkles:
:cookie: 447 | @zerazera |http://www.freecodecamp.com/zerazera
William Coleman
@wcski
May 26 2016 05:10
I'm so confused. I just read that when using dot notation, the part after the dot must be a valid variable name. But then I looked at the Accessing Nested Objects in JSON waypoint and it's using dot notation to access things that are just keys in an object, not a variable.
Aryan
@aryandua
May 26 2016 05:13
You can use dot or bracket notation to access some objects thing
like-
This message was deleted
Markus Kiili
@Masd925
May 26 2016 05:13
@wcski The dot notation only works if the property key string is a valid JS identifier (for example "12" and "lives left" are not) and you write the key after the dot: var cat={clothes:"pants", "lives left":3}; cat.clothes; //returns "pants". Bracket notation works with keys that can be arbitrary strings cat["lives left"]; //returns 3, variables var key="clothes"; cat[key]; //returns "pants", or expressions cat["lives"+" "+"left"]; //returns 3.
Kurt Johnson
@pompan129
May 26 2016 05:13
@wcski they jsut mean you can't reference "some name" unless u use bracket notation
what @Masd925 said.
Markus Kiili
@Masd925
May 26 2016 05:15
@wcski "valid variable name" mean valid identifier there. Slightly confusing choice of words yes.
William Coleman
@wcski
May 26 2016 05:19
interesting. I know this is off-topic for this channel, but I've always found the highly-lauded Eloquent Javascript text to be very confusing, and this is further evidence. I'm most likely misinterpreting something. Here's the text straight from it for the record. It was in a section about data structures, but maybe it doesn't actually apply to accessing properties of an object, and it's just referring to something else. : js The two most common ways to access properties in JavaScript are with a dot and with square brackets. Both value.x and value[x] access a property on value—but not necessarily the same property. The difference is in how x is interpreted. When using a dot, the part after the dot must be a valid variable name, and it directly names the property. When using square brackets, the expression between the brackets is evaluated to get the property name. Whereas value.x fetches the property of value named “x”, value[x] tries to evaluate the expression x and uses the result as the property name.
scnetsec
@ni234
May 26 2016 05:20
This message was deleted
William Coleman
@wcski
May 26 2016 05:20
but thanks for breaking that down @pompan129 and @Masd925
CamperBot
@camperbot
May 26 2016 05:20
wcski sends brownie points to @pompan129 and @masd925 :sparkles: :thumbsup: :sparkles:
:cookie: 479 | @pompan129 |http://www.freecodecamp.com/pompan129
:star2: 1608 | @masd925 |http://www.freecodecamp.com/masd925
Coy Sanders
@coymeetsworld
May 26 2016 05:20
@wcski what its saying is for value.x to work, value has to have a property literally named 'x'
Markus Kiili
@Masd925
May 26 2016 05:20
@ni234 The first line is redundant.
Coy Sanders
@coymeetsworld
May 26 2016 05:21
but if you ran value[x], x is a variable, not a literal property you're checking for
value.x in bracket notation would be value['x'], not value[x]
William Coleman
@wcski
May 26 2016 05:23
That's starting to make sense
scnetsec
@ni234
May 26 2016 05:23

var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Nye",
        number: "(888) 555-5555",
        address: ['One Microsoft Way', 'Redmond', 'WA', '98052']
        }

    steve: {
        firstName: "Steve",
        lastName: "Young",
        number: "(888) 553-5555",
        address: ['One Microsoft Way', 'Redmond', 'WA', '98052']
    }
};
Coy Sanders
@coymeetsworld
May 26 2016 05:24
@wcski yeah if you know the property beforehand you can use dot notation, but say you're looking for a property whose name you don't know ahead of time but you have it stored in something like a variable you can use bracket notation
Aryan
@aryandua
May 26 2016 05:25
This message was deleted
Norvin Burrus
@ndburrus
May 26 2016 05:25
@ni234 comma, after the first record?
Aryan
@aryandua
May 26 2016 05:25
var x=arr.i;
wont work?? @coymeetsworld
Coy Sanders
@coymeetsworld
May 26 2016 05:26
what's arr?
Norvin Burrus
@ndburrus
May 26 2016 05:26
var = arr[i] arr is an array?
Markus Kiili
@Masd925
May 26 2016 05:26
@aryandua arr.i looks for property key "i".
Aryan
@aryandua
May 26 2016 05:26
@coymeetsworld array
Coy Sanders
@coymeetsworld
May 26 2016 05:26
assuming arr is an array
William Coleman
@wcski
May 26 2016 05:27
That was actually the next question I thought of. When looping through arrays, you use the arrays name then i with bracket notation, and i was wondering if dot notation would work. but then i just confused myself and decided not to ask.
Coy Sanders
@coymeetsworld
May 26 2016 05:27
no you use bracket notation for array
Aryan
@aryandua
May 26 2016 05:27
@ndburrus yes that's what i use right now
@coymeetsworld yeh i use bracket but i was just curious
:)
Norvin Burrus
@ndburrus
May 26 2016 05:27
@aryandua ok, so this out of context... what is the issue?
Coy Sanders
@coymeetsworld
May 26 2016 05:27
@Masd925 can correct me if I'm wrong, never seen dot notation used to access an array element
scnetsec
@ni234
May 26 2016 05:27
@ndburrus I LOVE YOU THANKS A BUNCH!!
CamperBot
@camperbot
May 26 2016 05:27
ni234 sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:cookie: 429 | @ndburrus |http://www.freecodecamp.com/ndburrus
Markus Kiili
@Masd925
May 26 2016 05:27
@wcski Dot notation doesn't work with array elements because "0" or "1" etc are not valid identifiers.
Coy Sanders
@coymeetsworld
May 26 2016 05:27
there you go
William Coleman
@wcski
May 26 2016 05:28
ah
Norvin Burrus
@ndburrus
May 26 2016 05:28
@ni234 lol... you're welcome... :+1:
Markus Kiili
@Masd925
May 26 2016 05:28
@wcski Both arr[0] and arr["0"] work.
Aryan
@aryandua
May 26 2016 05:28
@ndburrus no issue just curiosity :)
William Coleman
@wcski
May 26 2016 05:28
why isn't 0 a valid identifier?
Aryan
@aryandua
May 26 2016 05:29
for what? @wcski
Norvin Burrus
@ndburrus
May 26 2016 05:29
@aryandua aaah, outstanding... :fire:
Markus Kiili
@Masd925
May 26 2016 05:29
@wcski A valid identifier must begin with letter, $, or_.
Aryan
@aryandua
May 26 2016 05:29
@ndburrus why outstanding?
vichus1995
@vichus1995
May 26 2016 05:29
guys,shouldn't this code return the concatenated array? what's wrong with it?

function uniteUnique(arr) {

  var arr1=arr.reduce(function(a,b)
  {
    return a.concat(b);
  },[]);
  return arr1;
}

uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
Aryan
@aryandua
May 26 2016 05:30
what is so good about asking a question?
Li
@NLStom
May 26 2016 05:30
Screen Shot 2016-05-26 at 1.28.59 PM.png
Jason Shoemaker
@kutsuya1
May 26 2016 05:30
@aryandua may get a good answer
Coy Sanders
@coymeetsworld
May 26 2016 05:30
@vichus1995 you're only checking first array with that function
Aryan
@aryandua
May 26 2016 05:30
@kutsuya1 :) make sense
@vichus1995 use arguments
Norvin Burrus
@ndburrus
May 26 2016 05:31
@aryandua ...because it's pure learning driven.... :)
@wcski this may be helpful... MDN, Grammar and types, Object literals, {ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types } Object property names can be any string, including the empty string. If the property name would not be a valid JavaScript identifier or number, it must be enclosed in quotes. Property names that are not valid identifiers also cannot be accessed as a dot (.) property, but can be accessed and set with the array-like notation("[]").
William Coleman
@wcski
May 26 2016 05:32
@Masd925 I'm a little confused still. Just to make sure we were talking about the same thing, the below is what I was referring to.
Li
@NLStom
May 26 2016 05:32
hey guyes I wonder why my code give me error
Aryan
@aryandua
May 26 2016 05:32
@ndburrus ok that's what my parents and teachers keep telling me...
and when i ask why
they say
William Coleman
@wcski
May 26 2016 05:33
js var myArr = ["a", "b", "c"];

for (i = 0, i < myArr.length, i++) {
return myArr[i]; //why doesn't myArr.i do the same thing here?
}
Aryan
@aryandua
May 26 2016 05:33
You will understand one day:)
William Coleman
@wcski
May 26 2016 05:33
I am absolutely terrible with formatting in gitter, my apologies.
bleujai
@bleujai
May 26 2016 05:33
@vichus1995 arr has the value of the first argument passed to the function, not all three arguments.
Norvin Burrus
@ndburrus
May 26 2016 05:33
@aryandua they are right!
Aryan
@aryandua
May 26 2016 05:33
I hope :)
Markus Kiili
@Masd925
May 26 2016 05:33
@wcski ayArr.i looks for property key "i".
William Coleman
@wcski
May 26 2016 05:34
anyway, i think i'm getting "identifier" confused. I was thinking you were saying something like var x = 1; is invalid
Jason Shoemaker
@kutsuya1
May 26 2016 05:34
@wcski return myArr[i] is finished with myArr[0];
@wcski return exits a function or program
William Coleman
@wcski
May 26 2016 05:35
that is good to know
Markus Kiili
@Masd925
May 26 2016 05:35
@wcski JS variables are identified with names that must follow certain restrictions (valid identifiers).
William Coleman
@wcski
May 26 2016 05:36
ohh
Norvin Burrus
@ndburrus
May 26 2016 05:36
@wcski ...do the same thing as what? (or did i miss the dialogue on that?)
William Coleman
@wcski
May 26 2016 05:37
i was just trying to understand why myArr[i] and myArr.i don't do the same thing
Islam Ibakaev
@dagman
May 26 2016 05:38
hey guys i was working hard on my portfolio. check it out. give some critique if u wish. some suggestions about skills section appearance maybe
Markus Kiili
@Masd925
May 26 2016 05:38
@wcski You can think that the bracket notation is the general way to access object properties. The key can be stored in a variable, given as an expression, or given as a string literal. The bracket notation is a restricted way because it only works with a string key (that you write after the dot and) that happens also to be valid identfier.
William Coleman
@wcski
May 26 2016 05:38
And, like, I get it, I understand that I can't do that and I could just accept it and move on, but I really want to have an actual understand of why, but I really have started to confuse myself more when I seek to find out fundamentally why.
vichus1995
@vichus1995
May 26 2016 05:38
thanks @coymeetsworld @aryandua @bleujai