These are chat archives for FreeCodeCamp/HelpJavaScript

17th
May 2016
Christian Todd
@chrstntdd
May 17 2016 00:00
is anyone available to help me through the Caesars Cipher bonfire?
CamperBot
@camperbot
May 17 2016 00:00
type bonfire name to get some info on that bonfire. And check HelpBonfires chatroom
Christian Todd
@chrstntdd
May 17 2016 00:01

This is what I have so far
```

function rot13(str) { // LBH QVQ VG!
var strArr = str.split("");
var numArr = [];
for (var i = 0; i < strArr.length; i++){
numArr = strArr[i].charCodeAt(i);
}

return numArr;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");

allisonletts
@allisonletts
May 17 2016 00:01
help caesars cipher
CamperBot
@camperbot
May 17 2016 00:01

:point_right: algorithm caesars cipher [wiki]

:triangular_flag_on_post: Remember to use Read-Search-Ask if you get stuck. Try to pair program :busts_in_silhouette: and write your own code :memo:

:checkered_flag: Problem Explanation:

  • You need to write a function, which will take a string encoded with
    Caesar cipher as a parameter and decode it.
  • The one used here is ROT13 where the value of the letter is
    shifted by 13 places.
    e.g. 'A' ↔ 'N', 'T' ↔ 'G'.
  • You have to shift it back 13 positions, such that 'N' ↔ 'A'.

:pencil: read more about algorithm caesars cipher on the FCC Wiki

Christian Todd
@chrstntdd
May 17 2016 00:02

function rot13(str) { // LBH QVQ VG!
  var strArr = str.split("");
  var numArr = [];
  for (var i = 0; i < strArr.length; i++){     
    numArr = strArr[i].charCodeAt(i);                                         
  }

  return numArr;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Nick
@nickiowaspain
May 17 2016 00:03
This message was deleted
Christian Todd
@chrstntdd
May 17 2016 00:03
So my thinking is to split the string into an array of each character, convert to unicode, do the transformation, then convert back to a string and join the array.
but right now its returning null in the console and I'm just trying to test to see if the method will convert to the unicode.
Nick
@nickiowaspain
May 17 2016 00:06
So I'm on "Selecting from many options with Switch Statements" and this code work however I'm wondering why there are the warning exclamation points that say "unreachable 'break' after 'return.'" on the break lines. Should I not be using "return"?
function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch (val) {
    case 1:
      return "alpha";
      break;
    case 2:
      return "beta";
      break;
    case 3:
      return "gamma";
      break;
    case 4: 
      return "delta";
      break;
  }


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

// Change this value to test
caseInSwitch(3);
KTT-9898
@KTT-9898
May 17 2016 00:09
Hello.
Christian Todd
@chrstntdd
May 17 2016 00:09
@nickiowaspain instead of returning the string you can assign the empty string answer to that string for each case
so for instance:
KTT-9898
@KTT-9898
May 17 2016 00:09

Quick question. Instructions

Assign the value 7 to variable a.

Assign the contents of a to variable b.

Premdeep Saini
@premdeepsaini
May 17 2016 00:09
@nickiowaspain after return statemen
KTT-9898
@KTT-9898
May 17 2016 00:09

// Setup
var a = 7;
var b = 2;

// Only change code below this line

Premdeep Saini
@premdeepsaini
May 17 2016 00:10
@nickiowaspain after return statement the break statement is of no use
Christian Todd
@chrstntdd
May 17 2016 00:10
case n:
answer = "string";
break;
Nick
@nickiowaspain
May 17 2016 00:11
ok thanks all!
Premdeep Saini
@premdeepsaini
May 17 2016 00:11
@KTT-9898 b=a;
Norvin Burrus
@ndburrus
May 17 2016 00:11
@KTT-9898 ..the first line is ok. the second line needs some attention. hint: "Assign ( = ) the contents of a to variable b."
Dustin
@Key-Banger
May 17 2016 00:11
@chrstntdd I think you want to do numArr.push(strArr[i].charCodeAt());
KTT-9898
@KTT-9898
May 17 2016 00:14
I'm still confused.
Christian Todd
@chrstntdd
May 17 2016 00:14
@Key-Banger Thanks! Now I've got everything pushed to the new blank array I have, but only the first value has been converted to a number, the rest are null. Do you know why this is?
CamperBot
@camperbot
May 17 2016 00:14
chrstntdd sends brownie points to @key-banger :sparkles: :thumbsup: :sparkles:
:cookie: 411 | @key-banger |http://www.freecodecamp.com/key-banger
Premdeep Saini
@premdeepsaini
May 17 2016 00:16
This message was deleted
Dustin
@Key-Banger
May 17 2016 00:17
@chrstntdd did you take the "i" out of charCodeAt()?
Norvin Burrus
@ndburrus
May 17 2016 00:17
@KTT-9898 .. alright. = is an assignment operator. it means to assign whatever is on the right of =, to whatever is on the left side. so, a = 7 assigns the number seven to the var/iable a. then, b = a assigns the variable a's (specifically its' value) to the variable b... make sense?
Coy Sanders
@coymeetsworld
May 17 2016 00:17
@KTT-9898 look what @premdeepsaini has, that's how you assign the value of a to b
also what @ndburrus just wrote :thumbsup:
Premdeep Saini
@premdeepsaini
May 17 2016 00:18
var a=7;
var b;
b=a;
can anyone help me toi solve these problem
KTT-9898
@KTT-9898
May 17 2016 00:19

// Setup
var a = 7;
var b = 2;
b = a;

// Only change code below this line

Christian Todd
@chrstntdd
May 17 2016 00:19
@Key-Banger I did not, but I just did. why would having the variable there cause each value after the first one to be null?
Coy Sanders
@coymeetsworld
May 17 2016 00:19
yup @KTT-9898
KTT-9898
@KTT-9898
May 17 2016 00:19
it doesn't let me pass lol
Norvin Burrus
@ndburrus
May 17 2016 00:20
@KTT-9898 the line var b = 2 isn't needed.... which challenge is this?
Coy Sanders
@coymeetsworld
May 17 2016 00:20
yeah maybe don't assign the b = 2 part, just do var b;
KTT-9898
@KTT-9898
May 17 2016 00:20
Storing Values with the Assignment Operator under Javascript
Coy Sanders
@coymeetsworld
May 17 2016 00:20
not that your code is wrong, FCC may not parse your solution correctly
KTT-9898
@KTT-9898
May 17 2016 00:21
It still doesn't pass. :(
Coy Sanders
@coymeetsworld
May 17 2016 00:21
oh i see
// Setup
var a;
var b = 2;
that part you leave alone
you need to do two things: set a to 7, then b to a
so there should be 4 lines total
Santosh Kumar Toleti
@Santosh456
May 17 2016 00:21
@Santosh456
https://www.freecodecamp.com/challenges/understand-string-immutability
can anyone help me toi solve these problem
Coy Sanders
@coymeetsworld
May 17 2016 00:22
see where it says // Only change code below this line? that means they don't want you touching var a; or var b=2
Norvin Burrus
@ndburrus
May 17 2016 00:22
@KTT-9898 alright. var a is already declared for you... so assign 7 to a first
@KTT-9898 var b is already assigned the value of 2 for you... so you just need to assign a to b. getting clearer? ... can you type in how we would assign a to b? that may be where the confusion is... clue: take a look at the last tests' comment... :)
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:25
3 days, and I finally got a polygon to display. It's pretty great. I wish this meant I had a better understanding, but I can't get anything else to work, like move it. http://codepen.io/NEETWizardJanus/pen/JXzeeq?editors=1010
KTT-9898
@KTT-9898
May 17 2016 00:25
a=b
Coy Sanders
@coymeetsworld
May 17 2016 00:25
other way around
you want b to equal the contents of a
before that though, you want to assign a the value of 7
KTT-9898
@KTT-9898
May 17 2016 00:26
oh thanks
Jared Abel
@jaredabel
May 17 2016 00:27
any reason why my setInterval never ticks?
$('#'+moves[i]).css({opacity:1});
      setInterval(function(){
              $('#'+moves[i]).css({opacity:.1});

      }, 1000);
Coy Sanders
@coymeetsworld
May 17 2016 00:27
no problem
KTT-9898
@KTT-9898
May 17 2016 00:27
thanks guys
Jared Abel
@jaredabel
May 17 2016 00:27
it does the first opacity change to 1, but never back to .1
rphares
@rphares
May 17 2016 00:28
@Santosh456 , still stuck?
Norvin Burrus
@ndburrus
May 17 2016 00:28
@KTT-9898 youre welcome... :+1:
Tulio Natale
@tuliodnw
May 17 2016 00:29
people im in the binary agents bonfire, (vhange binary to letters), i can do this challenge using switches for every letter, is the a better way to do it? thanks
Santosh Kumar Toleti
@Santosh456
May 17 2016 00:32
no
pls help me to solve these
EricOber
@EricOber
May 17 2016 00:33
hey everybody, can someone help me solve a challenge?
rphares
@rphares
May 17 2016 00:33
@Santosh456 , can you paste the code you are trying?
Santosh Kumar Toleti
@Santosh456
May 17 2016 00:33
i am nt able understanf=d the question
rphares
@rphares
May 17 2016 00:33
ah,
you need to make a sentence
you can do it by concatenating the parameters
Santosh Kumar Toleti
@Santosh456
May 17 2016 00:34
oh
rphares
@rphares
May 17 2016 00:34
be sure to concatenate in non-word characters (i suggest spaces)
so that the output isn't: bigdogranquickly
and, store the sentence in what you will return :blush:
thats it~
( @Am3ricanPaladin , not ignoring you, just think i recall you are passed what i can help with, sorry! :pensive: )
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:38
anyone know if I'm applying my JS library function's transform {rotate, X, and Y} on the wrong element? I can't get it to work. http://codepen.io/NEETWizardJanus/pen/JXzeeq?editors=1010
oh... I see... It's not accessing it properly at all. I tried moving the color changing from the first one to the later changes and it failed.
not sure how I'm supposed to edit existing variables then.
Dan Couper
@DanCouper
May 17 2016 00:41
@tuliodnw Yes, switch is not that useful in JS; you definitely shouldn't need it for this.
  1. parseInt takes a second argument, the radix. 10 is decimal, so parseInt('2', 10) returns 2. If you use a radix of 2 on a binary?
Tulio Natale
@tuliodnw
May 17 2016 00:42
@DanCouper you lost me, whats parseInt?
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:42
uhg. I don't understand the syntax at all.
Aryan
@aryandua
May 17 2016 00:42
@aryandua
http://codepen.io/aryandua/pen/pymNbB?editors=1010
Hey guy I am writing a game in which you have to stop the ball from falling
Everything is working just three problems
One- The ball falls instantly
two- the plate goes with the ball
three- How do i recognize that the user has got the ball and stop the ball from falling?
Santosh Kumar Toleti
@Santosh456
May 17 2016 00:42
@rphares Iam trying but its not happening
Aryan
@aryandua
May 17 2016 00:42
@NEETWizardJanus did you make your clock?
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:42
why is it so hard to learn syntax?
rphares
@rphares
May 17 2016 00:42
@Santosh456 -- can you please paste what you are trying? :blush:
Dan Couper
@DanCouper
May 17 2016 00:42
  1. The function String.fromCharCode(67), what does that return?
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:43
@aryandua are you kidding? It's taken me 3 days to get a polygon to appear. Now I'm trying to move and rotate it and make multiple ones. Who knows how many days that will take.
richiedSIS
@richiedSIS
May 17 2016 00:43
Hi there. I'm working on the challenge to determine a palindrome and I've met all the test cases except the last one. When I run it the regex is returning 0_000. How can I modify the regex to also get rid of the underscore?
Aryan
@aryandua
May 17 2016 00:43
its okay you'll get it @NEETWizardJanus
Dan Couper
@DanCouper
May 17 2016 00:43
@tuliodnw they are both functions, they're linked on the challenge
richiedSIS
@richiedSIS
May 17 2016 00:43

function palindrome(str) {
  // Good luck!
  if(str ===null)
    return false;

  var newStr = str.toLowerCase().replace(/\W/g,'');
  //return newStr;
  var left=0; var right=newStr.length-1;
  while(left<right){
    if(newStr[left]!==newStr[right])
      return false;
    left++;
    right--;

  }
  return true;

}

palindrome("0_0 (: /-\ :) 0-0")
Aryan
@aryandua
May 17 2016 00:43
Nothing is impossible for you :)
@aryandua
http://codepen.io/aryandua/pen/pymNbB?editors=1010
Hey guy I am writing a game in which you have to stop the ball from falling
Everything is working just three problems
One- The ball falls instantly
two- the plate goes with the ball
three- How do i recognize that the user has got the ball and stop the ball from falling?
Tulio Natale
@tuliodnw
May 17 2016 00:44

@DanCouper i only get these 2 Here are some helpful links:

String.prototype.charCodeAt()
String.fromCharCode()

Aryan
@aryandua
May 17 2016 00:44
Look I am failing to make a simple game
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:44
@aryandua I don't understand the syntax at all.
Aryan
@aryandua
May 17 2016 00:44
what syntax?
js?
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:44
I thought putting a . would just do more commands on the same parent element, but mine seem to cut off after the 2nd one.
Dan Couper
@DanCouper
May 17 2016 00:45
@NEETWizardJanus what you're trying to do is hard, you're doing well; I get the same massive raging frustration and I've been programming for a few years. It gets easier
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:45
I dunno if it's JS or jQuery.
Aryan
@aryandua
May 17 2016 00:45
both are easy if you follow Fcc
Rafi Ronquillo
@RafiTranquilo
May 17 2016 00:45
Having trouble with "Profile Lookup". Can anyone point me in the right direction?
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


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

// Change these values to test your function
lookUp("Bob", "number");
Aryan
@aryandua
May 17 2016 00:45
@NEETWizardJanus do you do FCC as a side study?
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:45
and then you get stuff like .transform({
x: (segwid * 2),
y: (seglen)
});
@aryandua no idea what that is.
Aryan
@aryandua
May 17 2016 00:46
whoa! that does look complecated
rphares
@rphares
May 17 2016 00:46
actually, it just doesn't like that you have two string pieces next to each other, @Santosh456 --
put that first space in the "" from "The"
Aryan
@aryandua
May 17 2016 00:46
@NEETWizardJanus try making that same clock in C++ again :0
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:46
I mean it's my broken code, but I do see stuff LIKE that. I just can't tell when it's used or not used.
rphares
@rphares
May 17 2016 00:46
(write "The " ) @Santosh456
rphares
@rphares
May 17 2016 00:47
so that you can have "The " + myNoun... @Santosh456
then you will be fine~
Blake Harris
@bharris62
May 17 2016 00:47
I am having trouble returing the correct description on my twitch app, can someone take a look at it and give me some fresh eyes? thanks!
http://codepen.io/bharris62/pen/regWmV
Dan Couper
@DanCouper
May 17 2016 00:47
If you give the binary to parseInt, you get a number, if you pass that number to String.fromCharCode, you get a character
@tuliodnw
Tulio Natale
@tuliodnw
May 17 2016 00:48
@DanCouper thanks didnt know about that one, was about to do it the mathematical way thanks
CamperBot
@camperbot
May 17 2016 00:48
tuliodnw sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:cookie: 87 | @dancouper |http://www.freecodecamp.com/dancouper
Norvin Burrus
@ndburrus
May 17 2016 00:49
@RafiTranquilo instead of a final (additional) if statement, you could just use another else statement... :) [instead of using flag as a flow control method]
Santosh Kumar Toleti
@Santosh456
May 17 2016 00:51
@rphares can u tell me what exactly i should write
i am trying but its not happening
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:52
I remember in C++ someone gave me ASM code to change video modes and write pixels directly. I have a feeling there's a good chance any graphical library will needlessly complicate the matter much like it's doing with web coding.
I coded functions to draw lines using the ASM code to write individual pixels.
So much easier compared to this nonsense.
rphares
@rphares
May 17 2016 00:52
in this case, yes, i will, :blush: because your code was actually okay, the test was a little off-- can you send a new link, @Santosh456 ? because you changed something, i cant open it anymore ... :pensive:
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:52
which is probably why I liked microprocessor programming in college. :P
Dan Couper
@DanCouper
May 17 2016 00:53
@tuliodnw :thumbsup: yea, plus it's not obvious what the parseInt function does: most of the time it's just used for converting numbers trapped in strings to real numbers
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:53
and I always hated libraries. It's like trying to get into the mind of a unique madman.
No two are alike!
Rafi Ronquillo
@RafiTranquilo
May 17 2016 00:53
@ndburrus thanks, I'll try that
CamperBot
@camperbot
May 17 2016 00:53
rafitranquilo sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:cookie: 369 | @ndburrus |http://www.freecodecamp.com/ndburrus
NEETWizardJanus
@NEETWizardJanus
May 17 2016 00:56
well I'm back to feeling like a failure who can't do anything. getting one polygon to display is the extent of my skills.
Aryan
@aryandua
May 17 2016 01:01
dont feel that way
Wiktor
@Wkredz1
May 17 2016 01:04
.replace (/\w\S* what is this what does it mean?
Zach
@Moose1551
May 17 2016 01:04
Is there any reason why my final "else" statement isn't returning the entire string length in the bonfire challenge "Truncate a String"?
function truncateString(str, num) {
  var stringEnd = "...";
  if (num > 3) {
    return str.slice(0, num - 3) + stringEnd;
  } else if (num <= 3) {
    return str.slice(0, num) + stringEnd;
  } else {
    return str;
  }

}

truncateString("A-tisket a-tasket A green and yellow basket", 11);
Diogo Righi
@diogorighi
May 17 2016 01:07
it's never getting to the else statement
you shoud verify if the num is equal to the length of the string
if I remember wel...
well
the num will always be >3 or <=3! so in your code, it will never reach the else statement
Victor
@abeledovictor
May 17 2016 01:09
HI guys! I need help with the nextInLine challenge (Stand in line)
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));
Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.
I dont know what to write :(
Destineees
@Destineees
May 17 2016 01:14
So I am working on the palindrome challenge and I am a little confused. I passed all the tests except the last one "palindrome("0_0 (: /-\ :) 0-0") should return true." Can anyone give me a hint how to pass this test when the notes say to remove all punctuation spaces and symbols?
eeflores
@eeflores
May 17 2016 01:15
@Destineees if you're using \W in the regexp, it includes underscore
Greg
@GregJacoby
May 17 2016 01:16
@Destineees exactly! test what your new string is outputting in the console, and you'll probably see that the underscore is still hanging around...
i'm doing the truncate a string challenge, can someone explain to me exactly what I'm supposed to do?

function truncateString(str, num) {
  if(str.length > num) {
   var truncStr = str.slice(0, num);
    return truncStr + "...";
  }
  return str;
}
Diego Mayer
@Chrono79
May 17 2016 01:17
@abeledovictor look at the previous challenges involving array methods, push, pop, shift and unshift
Greg
@GregJacoby
May 17 2016 01:17
but for truncateString("Peter Piper picked a peck of pickled peppers", 14) it returns "peter piper pi..." which is what I thought it's supposed to do, but the challenge wants it to return "Peter Piper..." what am i misunderstanding about what they want me to do?
Destineees
@Destineees
May 17 2016 01:18
@eeflores @GregJacoby Thanks
CamperBot
@camperbot
May 17 2016 01:18
destineees sends brownie points to @eeflores and @gregjacoby :sparkles: :thumbsup: :sparkles:
:cookie: 267 | @gregjacoby |http://www.freecodecamp.com/gregjacoby
:cookie: 716 | @eeflores |http://www.freecodecamp.com/eeflores
eeflores
@eeflores
May 17 2016 01:18
@GregJacoby the "..." are included in the length of the truncated string
Greg
@GregJacoby
May 17 2016 01:18
@eeflores I know it says that, but I don't understand what they mean. How is it possible the ... is included in anything since all I'm doing is adding it onto the end of the returned value?
eeflores
@eeflores
May 17 2016 01:19
so it's like num - 3
Greg
@GregJacoby
May 17 2016 01:19
i see how that fixes my original problem, but im not understanding it conceptually
help? xD
CamperBot
@camperbot
May 17 2016 01:20
no wiki entry for: xd
Diego Mayer
@Chrono79
May 17 2016 01:20
@GregJacoby instead of cutting at position 14 and adding the 3 dots, cut at 14-3 and add the 3 dots
Victor
@abeledovictor
May 17 2016 01:20
@moigithub @Chrono79 thanks
CamperBot
@camperbot
May 17 2016 01:20
abeledovictor sends brownie points to @moigithub and @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1163 | @moigithub |http://www.freecodecamp.com/moigithub
:cookie: 752 | @chrono79 |http://www.freecodecamp.com/chrono79
Greg
@GregJacoby
May 17 2016 01:20
OH
eeflores
@eeflores
May 17 2016 01:20
that's what's needed to pass the exercise. Unfortunately there's a little more to it, because you have to take into consideration strings shorter than 3 chars
Greg
@GregJacoby
May 17 2016 01:20
OHHhhHh
@Chrono79 @eeflores thank you, i understand the whole thing now
CamperBot
@camperbot
May 17 2016 01:21
gregjacoby sends brownie points to @chrono79 and @eeflores :sparkles: :thumbsup: :sparkles:
:cookie: 717 | @eeflores |http://www.freecodecamp.com/eeflores
:cookie: 753 | @chrono79 |http://www.freecodecamp.com/chrono79
eeflores
@eeflores
May 17 2016 01:21
good stuff
Zach
@Moose1551
May 17 2016 01:23
@diogorighi, thank you for helping me locate the problem area. I tried to fix that issue, but I'm having trouble understanding why my newer solution isn't working. Could you shed some light?
function truncateString(str, num) {

  var stringEnd = "...";
  if (num > 3) {
    return str.slice(0, num - 3) + stringEnd;
  } else if (num < str.length) {
    return str.slice(0, num) + stringEnd;
  } else {
    return str;
  }

}

truncateString("A-tisket a-tasket A green and yellow basket", 11);
CamperBot
@camperbot
May 17 2016 01:23
moose1551 sends brownie points to @diogorighi :sparkles: :thumbsup: :sparkles:
:cookie: 75 | @diogorighi |http://www.freecodecamp.com/diogorighi
EricOber
@EricOber
May 17 2016 01:25
is anyone knowledgeable about the object oriented programming challenges?
i need help
eeflores
@eeflores
May 17 2016 01:27
@Moose1551 do the if(num > str.length) test first
otherwise you'll be adding the "..."s when you don't need to
@Am3ricanPaladin what's your question?
EricOber
@EricOber
May 17 2016 01:28
hey @eeflores i am working on "Make Unique Objects by Passing Parameters to our Constructor" and i think i have my code wrong

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

//Try it out here
var myCar = new Car(4, 1, 1);
Arvilyn Ong
@arvilyn
May 17 2016 01:29
hi, could anyone help with 'Check for Palindromes' challenge? i have no idea why it doesn't return false
function palindrome(str) {
  // Good luck!
  str.trim(); //RaceCar = RaceCar
  str.toLowerCase(); //RaceCar = racecar
  arr1 = str.split(''); // r a c e c a r
  arr2 = arr1.reverse(); // r a c e c a r
  if ((arr1.join('')) === (arr2.join(''))) {
    return true;
  } else {
    return false;
  }
}



palindrome("eye");
eeflores
@eeflores
May 17 2016 01:30
@Am3ricanPaladin assign the parameters of the function to the this values eg. this.wheels = wheels;
Diego Mayer
@Chrono79
May 17 2016 01:30
@arvilyn I think you have to assign str.toLowerCase() to str, because toLowerCase doesn't modify the string:
Syntax
str.toLowerCase()
Description
The toLowerCase() method returns the value of the string converted to lowercase. toLowerCase() does not affect the value of the string str itself.
Also, you have to get rid of all that isn't a letter or a number for pasing all tests, use replace + regex to do that
EricOber
@EricOber
May 17 2016 01:31


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

//Try it out here
var myCar = new Car(4, 1, 1);
like that?
eeflores
@eeflores
May 17 2016 01:31
yeah - does it work?
EricOber
@EricOber
May 17 2016 01:31
hey it does, thanks @eeflores
CamperBot
@camperbot
May 17 2016 01:31
am3ricanpaladin sends brownie points to @eeflores :sparkles: :thumbsup: :sparkles:
:cookie: 718 | @eeflores |http://www.freecodecamp.com/eeflores
eeflores
@eeflores
May 17 2016 01:31
yay
EricOber
@EricOber
May 17 2016 01:31
now i am wonder why it works LOL
VultureBetrayer
@VultureBetrayer
May 17 2016 01:32
@Am3ricanPaladin if you run into that, try and go back a couple lessons, and redo them, there's probably a step you did prior that you didn't realize was necessary (that's been my experience)
EricOber
@EricOber
May 17 2016 01:33
oh ok
Victor
@abeledovictor
May 17 2016 01:40


function nextInLine(arr, item) {
 var cars = ["ford", "chevrolet", "nissan", "suzuki", "ferrari"];
var carsn = [5];// Your code here
  cars.push("carsn");
  cars.shift();
  return item;  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
still cant complete the challenge u.u
Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.
Diego Mayer
@Chrono79
May 17 2016 01:40
@abeledovictor why those vars?
use only arr and item
Victor
@abeledovictor
May 17 2016 01:43
function nextInLine(arr, item) {
 var arr;
var item;
  arr.push(item);
  arr.shift();
  return item;  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
@Chrono79
like that?? i dont know what im missing
Stephen James
@sjames1958gm
May 17 2016 01:51
@abeledovictor Don't redefine arr or item they come with the function defintion, also return the result of arr.shift()
William Coleman
@wcski
May 17 2016 01:52
Hmm
stuck on challenge 216, Return Early Pattern for functions
rphares
@rphares
May 17 2016 01:53
@wcski ,hiya!
can you paste what you are trying?
William Coleman
@wcski
May 17 2016 01:53
Modify the function abTest so that if a or b are less than 0 the function will immediately exit with a value of undefined.
rphares
@rphares
May 17 2016 01:53
yep-- you just need to make an if statement,
that says something like,
William Coleman
@wcski
May 17 2016 01:53

```// Setup
function abTest(a, b) {
// Only change code below this line
if (a < 0 || b < 0) {

return c;

} ```

rphares
@rphares
May 17 2016 01:54
oh, sooo close,
William Coleman
@wcski
May 17 2016 01:54
formatting in gitter never works for me heh
Zach
@Moose1551
May 17 2016 01:54
@eeflores, Thank you for the help. I'm passing the first four tests now, but for some reason I can't pass the last two tests. Any advice? I don't understand why the "else if" part isn't working...
 function truncateString(str, num) {

  var stringEnd = "...";
  if (str.length > num) {
    return str.slice(0, num - 3) + stringEnd;
  } else if (num > 0 && num <= 3) {
    return str.slice(0, num) + stringEnd;
  } else {
    return str;
  }

}

truncateString("A-tisket a-tasket A green and yellow basket", 11);
CamperBot
@camperbot
May 17 2016 01:54
moose1551 sends brownie points to @eeflores :sparkles: :thumbsup: :sparkles:
:cookie: 719 | @eeflores |http://www.freecodecamp.com/eeflores
William Coleman
@wcski
May 17 2016 01:54

`// Setup
function abTest(a, b) {
// Only change code below this line
if (a < 0 || b < 0) {

return c;

} `

rphares
@rphares
May 17 2016 01:54
but why return c? @wcski
just return exactly what it told you to...
William Coleman
@wcski
May 17 2016 01:54
well my rationale there was that c is undefined
rphares
@rphares
May 17 2016 01:55
heh, yeah, i get that... but you should be fine returning undefined or just return
Victor
@abeledovictor
May 17 2016 01:55
@sjames1958gm @Chrono79 thanks
CamperBot
@camperbot
May 17 2016 01:55
abeledovictor sends brownie points to @sjames1958gm and @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: abeledovictor already gave chrono79 points
:star2: 1125 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
William Coleman
@wcski
May 17 2016 01:55
Ohhh
thanks @rphares
CamperBot
@camperbot
May 17 2016 01:56
wcski sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star2: 4644 | @rphares |http://www.freecodecamp.com/rphares
rphares
@rphares
May 17 2016 01:56
sure thing~ Happy coding!
Wiktor
@Wkredz1
May 17 2016 01:56
If we didn't split the string how does it know that it takes the first letter?
William Coleman
@wcski
May 17 2016 01:56
Do they pay you to monitor this room lol?
Wiktor
@Wkredz1
May 17 2016 01:56

function titleCase(str) {
return str.replace(/\w\S*/g, function(w) {
return w.charAt(0).toUpperCase() + w.substr(1).toLowerCase();
});
}

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

Arvilyn Ong
@arvilyn
May 17 2016 01:57
@Chrono79 thank you!! but my code doesn't seem to work after modifying it.. could you help me again? haha
function palindrome(str) {
  // Good luck!
  var removedNAC = str.replace(/\W/g, ''); 
  str = removedNAC.toLowerCase(); //RaceCar = racecar
  arr1 = str.split(''); // r a c e c a r
  arr2 = arr1.reverse(); // r a c e c a r
  if ((arr1.join('')) === (arr2.join(''))) {
    return true;
  } else {
    return false;
  }
}



palindrome("not a palindrome");
CamperBot
@camperbot
May 17 2016 01:57
arvilyn sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:cookie: 754 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
May 17 2016 01:59
@arvilyn \w includes _ you have to get rid of the underscore too to pass the last test
also you could return your if condition directly, just check the number of () I think it's wrong
buiphuking
@buiphuking
May 17 2016 02:03
@Chrono79
i have solution ,
0.2 0.2 = 0.04000000001
Math.round(0.2
0.2 *100) /100 = 0.04
Diego Mayer
@Chrono79
May 17 2016 02:04
@buiphuking :+1:
have you solved the multiple points problem?
Bearded One
@EpicBeard
May 17 2016 02:05
function palindrome(str) {
  str = String.replace(" ", "");
  str = String.toLowerCase();

  if (str != str.split('').reverse().join()) {
  return false;
} else {
  return true;
}

}



palindrome("eye");
any reason this doesn't work?
Diego Mayer
@Chrono79
May 17 2016 02:05
@tom103 yes, you have to get rid of anything that's not a number or a letter
Bearded One
@EpicBeard
May 17 2016 02:05
ah....hmmmmm
Diego Mayer
@Chrono79
May 17 2016 02:06
and don't use String.replace use str.replace (the same for toLowerCase)
buiphuking
@buiphuking
May 17 2016 02:06
@Chrono79
http://codepen.io/buiphuking/pen/qZwpjE?editors=0010
spend 10s and test for me , tell me your thought
Zach
@Moose1551
May 17 2016 02:07

Okay, so I switched around the "if" and the "else if" statement. Example 1 does not work. Example 2 does. Can anyone explain a bit why switching the statements affected the outcome?
Example 1:

function truncateString(str, num) {

  var stringEnd = "...";
  if (str.length > num) {
    return str.slice(0, num - 3) + stringEnd;
  } else if (num <= 3) {
    return str.slice(0, num) + stringEnd;
  } else {
    return str;
  }

}

truncateString("A-tisket a-tasket A green and yellow basket", 11);

Example 2:

function truncateString(str, num) {

  var stringEnd = "...";

   if (num <= 3) {
    return str.slice(0, num) + stringEnd;
  } else if (str.length > num) {
    return str.slice(0, num - 3) + stringEnd;
  } else {
    return str;
  }  

}
truncateString("A-tisket a-tasket A green and yellow basket", 11);
Bearded One
@EpicBeard
May 17 2016 02:07
been stuck on palindromes for a long time now
think I'll just skip it
Wise
@WiseNN
May 17 2016 02:07
Hey everyone….Can someone please tell me why my array at index “i” is not copying the element, its copying the entire ??? (At line 1)
function diffArray(arr1, arr2) {
  var newArr = [];

  if(arr1.length<arr2.length)
  {
        newArr=arr2;
        arr2=arr1;
        arr1=newArr;
  } 

  for(var i=0; i<arr1.length;i++)
      {
          var see = arr1[i];
        if(arr2.indexOf(see)=== -1)
          {
            newArr=arr2[i]; //<<<---- This Line 1
          }
      } 
    return newArr;
}
Diego Mayer
@Chrono79
May 17 2016 02:08
@buiphuking try to fix the multiple symbols, ...., **, -----, ++++
Arvilyn Ong
@arvilyn
May 17 2016 02:09
@Chrono79 does str.replace(/[^0-9a-z]/gi, '') remove all non-alphanumeric characters??
Diego Mayer
@Chrono79
May 17 2016 02:09
@arvilyn yes
Stephen James
@sjames1958gm
May 17 2016 02:10
@arvilyn yes
Arvilyn Ong
@arvilyn
May 17 2016 02:10
all my tests pass except for those who were supposed to return false... is there any problem with the code?
Diego Mayer
@Chrono79
May 17 2016 02:10
@tom103 you're not so far, look, @arvilyn is doing the same challenge
@arvilyn paste your code again please
Stephen James
@sjames1958gm
May 17 2016 02:12
@arvilyn reverse reverses the array in place, so arr2 and arr1 are the same array. compare arr2.join to str
William Coleman
@wcski
May 17 2016 02:13
Things are starting to get difficult here. I like it. Counting cards...any hints?
Bearded One
@EpicBeard
May 17 2016 02:14


function palindrome(str) {
  // Good luck!
  str.replace(/[^0-9a-z]/gi, '');
  str.replace(" ", "");
  str.toLowerCase();

  if (str != str.reverse()) {
    return false;
  } else {

  return true;
  }
}
I drop all non letter characters, then replace remove the spaces. Then I check to see that if the str isn't equal to the string in reverse etc....
not sure why that doesn't work
Arvilyn Ong
@arvilyn
May 17 2016 02:14
omg i finally solved it thanks @sjames1958gm @Chrono79 !!!! :smile:
CamperBot
@camperbot
May 17 2016 02:14
arvilyn sends brownie points to @sjames1958gm and @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: arvilyn already gave chrono79 points
:star2: 1126 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
May 17 2016 02:14
@tom103 string doesn't have a reverse function.
Subh Samal
@subhsamal
May 17 2016 02:14
can anyone help on "Using Objects for Lookups"
Stephen James
@sjames1958gm
May 17 2016 02:14
@wcski most have used a switch statement.
Bearded One
@EpicBeard
May 17 2016 02:14
crud
so assign them to arrays and flip the array then compare?
jgoldverg
@jgoldverg
May 17 2016 02:15
can anyone explain how the toggleClass function works in jquery i tried to read up on it but its confusing me very badly
rphares
@rphares
May 17 2016 02:15
if/else or switch, either way increment and decrement as instructed, dont return till the end, with an if/else based on count, and be sure to include a space at the beginning of your strings, @wcski ~
Stephen James
@sjames1958gm
May 17 2016 02:15
@tom103 yes
rphares
@rphares
May 17 2016 02:15
@subhsamal , can you paste your code, please?
Bearded One
@EpicBeard
May 17 2016 02:15
ok, gonnat try it
jgoldverg
@jgoldverg
May 17 2016 02:15
$("flash").click(function(){
$("p").toggleClass('laser');
});
Subh Samal
@subhsamal
May 17 2016 02:15
var lookup = {
"alpha" : "Adams",
"bravo": "Boston",
"charlie": "Chicago",
"delta": "Denver",
"echo": "Easy",
"foxtrot": "Frank",
"": undefined };
lookup[val];
Stephen James
@sjames1958gm
May 17 2016 02:15
@rphares That's all the hints :)
jgoldverg
@jgoldverg
May 17 2016 02:15
i feel like this is correct but im getting an error
rphares
@rphares
May 17 2016 02:16
two things, @subhsamal -
Subh Samal
@subhsamal
May 17 2016 02:16
yes plz
Stephen James
@sjames1958gm
May 17 2016 02:16
@jgoldverg is flash a class or id?
rphares
@rphares
May 17 2016 02:16
(yeah, heavy handed, but those arent the thinking errors... @sjames1958gm :blush:)
Diego Mayer
@Chrono79
May 17 2016 02:16
@tom103 also, assign back str.replace and str.toLowerCase to str
replace: This method does not change the String object it is called on. It simply returns a new string.
The toLowerCase() method returns the value of the string converted to lowercase. toLowerCase() does not affect the value of the string str itself.
jgoldverg
@jgoldverg
May 17 2016 02:16
class
rphares
@rphares
May 17 2016 02:16
first, a minor thing, @subhsamal , you dont need "": undefined, you can get ride of that guy
second a big thing
Stephen James
@sjames1958gm
May 17 2016 02:16
@jgoldverg missing a character that identifies it as a class in the jquery selector
rphares
@rphares
May 17 2016 02:16
what are you returning? @subhsamal
Subh Samal
@subhsamal
May 17 2016 02:17
return statement is there
jgoldverg
@jgoldverg
May 17 2016 02:17
really which char?
Stephen James
@sjames1958gm
May 17 2016 02:17
@jgoldverg .
William Coleman
@wcski
May 17 2016 02:17
cool thanks @sjames1958g. That's the path I'm on. Just wondering how much logic I can put into my cases. Thinking I need to increment, and put a check in to see if the count is ps, neg or == 0, but I'm not sure if i can or even need to put all that into each case.
CamperBot
@camperbot
May 17 2016 02:17
wcski sends brownie points to @sjames1958g :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for sjames1958g
rphares
@rphares
May 17 2016 02:17
right-- but it is return result, right @subhsamal
Subh Samal
@subhsamal
May 17 2016 02:17
yes
rphares
@rphares
May 17 2016 02:17
what does result = ?
jgoldverg
@jgoldverg
May 17 2016 02:17
@sjames1958gm ohh lol thx
CamperBot
@camperbot
May 17 2016 02:17
jgoldverg sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1127 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
rphares
@rphares
May 17 2016 02:17
in your code right now, as it is?
William Coleman
@wcski
May 17 2016 02:17
But this is really just me talking out loud, no real need to respond
Zaw Ye Htut
@yeyezaw
May 17 2016 02:18
Does anyone give some more hint for "where do I belong" challenge ? I'm stuck in that and no clue how to sort and return .
Stephen James
@sjames1958gm
May 17 2016 02:18
@wcski the checks can go after the switch rather than in the case, all cases share the test on count.' << don't look at this
Subh Samal
@subhsamal
May 17 2016 02:19
@rphares Do I have to change lookup to result in my code ?
rphares
@rphares
May 17 2016 02:19
no-
you have what you want, lookup[val]
but... its just sitting there
Subh Samal
@subhsamal
May 17 2016 02:20
assign to result ?
rphares
@rphares
May 17 2016 02:20
:blush:
Subh Samal
@subhsamal
May 17 2016 02:20
let me try :)
Diego Mayer
@Chrono79
May 17 2016 02:21
@yeyezaw you could insert the value to the array, sort it (you have to use a function to sort numbers) and use indexof to find the index
Y'Eli Buonya
@yeli-buonya
May 17 2016 02:21
Can someone help me get started with the 'Record Collection' challenge?
Wiktor
@Wkredz1
May 17 2016 02:21
IM GETTING AN ERROR "String,split is not a function"
String.split(" ");
Zaw Ye Htut
@yeyezaw
May 17 2016 02:21
Ok, let me try it @Chrono79
rphares
@rphares
May 17 2016 02:21
just get started, or you have some code that isn't working, @yeli-buonya ?
Y'Eli Buonya
@yeli-buonya
May 17 2016 02:23
@rphares i've deleted and tried mulitple lines of code. I was using if/ else if statements
rphares
@rphares
May 17 2016 02:23

to get started, i'd turn these three instructions into conditions ...
`If value is non-blank (value !== "") and prop is not "tracks" then update or set the value for the prop.

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

If value is blank, delete that prop.`

if/else will work, @yeli-buonya
another thing that might be useful--
Stephen James
@sjames1958gm
May 17 2016 02:23
@Wkredz1 You use split on a string not on the String object.
Subh Samal
@subhsamal
May 17 2016 02:23
Did it :blush: @rphares Thank you
CamperBot
@camperbot
May 17 2016 02:23
subhsamal sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star2: 4645 | @rphares |http://www.freecodecamp.com/rphares
rphares
@rphares
May 17 2016 02:24
https://medium.com/@prufrock123/js-dot-notation-vs-bracket-notation-797c4e34f01d#.48e3a17a0 helped me understand why bracket not dot is so important in record collection @yeli-buonya
Y'Eli Buonya
@yeli-buonya
May 17 2016 02:24
@rphares how would I check for a non-blank? I guess i'm just really exhausted
rphares
@rphares
May 17 2016 02:24
Awesome! Congrats and happy coding, @yeli-buonya ~
Y'Eli Buonya
@yeli-buonya
May 17 2016 02:24
@rphares I'll go over that lesson again, thanks!
CamperBot
@camperbot
May 17 2016 02:24
yeli-buonya sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
Subh Samal
@subhsamal
May 17 2016 02:24
@rphares can you explain a bit about undefined one ?
CamperBot
@camperbot
May 17 2016 02:24
:star2: 4646 | @rphares |http://www.freecodecamp.com/rphares
Stephen James
@sjames1958gm
May 17 2016 02:24
@yeli-buonya this hint is provided on how to test non-blank -> (value !== "")
Subh Samal
@subhsamal
May 17 2016 02:25
does it takes itself if not mentioned with in object ?
Y'Eli Buonya
@yeli-buonya
May 17 2016 02:26
@sjames1958gm my goodness, I guess i was doing something right
rphares
@rphares
May 17 2016 02:26
@subhsamal , not really, I'm not terribly good at explanations, i just pass on links, heh... @sjames1958gm will be better for that! :pensive:
Stephen James
@sjames1958gm
May 17 2016 02:26
@rphares Where did that bus come from :)
rphares
@rphares
May 17 2016 02:26
lol, observation :blush:
Subh Samal
@subhsamal
May 17 2016 02:27
@rphares that's fi9 ..I'll figure it out. thanks for your help :blush:
CamperBot
@camperbot
May 17 2016 02:27
subhsamal sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:warning: subhsamal already gave rphares points
rphares
@rphares
May 17 2016 02:27
(i totally cant explain anything, thats parta why I hang out... one of those who can write answers easily enough but doesn't understand well enough to explain, hence slowing down, reading a lot, and hanging out in the help rooms :blush: )
Stephen James
@sjames1958gm
May 17 2016 02:27
@subhsamal Where did "" : undefined come from?
Wiktor
@Wkredz1
May 17 2016 02:28
How do I make it so my string is split into words so I can every I can make every first letter of the words capitalized ???????????????????????????????????
Stephen James
@sjames1958gm
May 17 2016 02:28
str.split(" ")
@Wkredz1 :point_up:
Subh Samal
@subhsamal
May 17 2016 02:29
@sjames1958gm I did so only to match condition : phoneticLookup("") should equal undefined
Stephen James
@sjames1958gm
May 17 2016 02:30
Ah. The idea is that if the property is not in the lookup object it will return undefined. You were not supposed to add it.
@subhsamal I would have used something like phoneticLookup("zulu"); rather than the "" which is a bit confusing.
Subh Samal
@subhsamal
May 17 2016 02:31
you mean any property not present within object is undefined ?
Stephen James
@sjames1958gm
May 17 2016 02:31
@subhsamal basically, the value of x["y"] where "y" is not defined on x is undefined.
Subh Samal
@subhsamal
May 17 2016 02:32
make sense to me @sjames1958gm
Stephen James
@sjames1958gm
May 17 2016 02:32
:+1:
Subh Samal
@subhsamal
May 17 2016 02:32
thank you @sjames1958gm
CamperBot
@camperbot
May 17 2016 02:32
subhsamal sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1128 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Wiktor
@Wkredz1
May 17 2016 02:34
Its not working
Kyle W Pilkinton
@tadake
May 17 2016 02:35
hey guys im on the wikipedia viewer project and im not sure how to work with the api. is there anywhere i can get backgroung knowledge
?
Stephen James
@sjames1958gm
May 17 2016 02:37
@Wkredz1 Post your code if you want us to take a look
help format
CamperBot
@camperbot
May 17 2016 02:38

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

William Coleman
@wcski
May 17 2016 02:38
need a quick best practice or 'code review' on my (working) solution to card counter
switch(card) { case 2: case 3: case 4: case 5: case 6: count++; break; case 7: case 8: case 9: count = count; break; case 10: case 'J': case 'Q': case 'K': case 'A': count--; break; }
switch(card) { case 2: case 3: case 4: case 5: case 6: count++; break; case 7: case 8: case 9: count = count; break; case 10: case 'J': case 'Q': case 'K': case 'A': count--; break; }
switch(card) {
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
      count++;
      break;
    case 7:
    case 8:
    case 9:
      count = count;
      break;
    case 10:
    case 'J':
    case 'Q':
    case 'K':
    case 'A':
      count--;
      break;
  }
Diego Mayer
@Chrono79
May 17 2016 02:39

@wcski delete this:

    case 7:
    case 8:
    case 9:
      count = count;
      break;

it does nothing

William Coleman
@wcski
May 17 2016 02:39
nice! got it formatting corectly, thanks @camperbot. anyway, that count = count statemtn core cases 7 8 and 9 seems redundant
CamperBot
@camperbot
May 17 2016 02:39
wcski sends brownie points to @camperbot :sparkles: :thumbsup: :sparkles:
:star2: 1734 | @camperbot |http://www.freecodecamp.com/camperbot
William Coleman
@wcski
May 17 2016 02:39
that's what i was thinking @Chrono79, thanks
CamperBot
@camperbot
May 17 2016 02:39
wcski sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
Stephen James
@sjames1958gm
May 17 2016 02:39
@wcski Looks good, the count = count is not needed. But you may want to keep case 7, 8, 9 so you know that they are covered.
CamperBot
@camperbot
May 17 2016 02:39
:cookie: 755 | @chrono79 |http://www.freecodecamp.com/chrono79
William Coleman
@wcski
May 17 2016 02:40
if I kep the 7 8 and 9 cases @sjames1958gm would I just put a break in there?
and nothing else?
Diego Mayer
@Chrono79
May 17 2016 02:40
yes, keep the break;
Stephen James
@sjames1958gm
May 17 2016 02:41
@sjames1958gm yeah, but if I understand how js works they would cause extra processing. In something like c or c++ they are probably optimized out, not sure about js
William Coleman
@wcski
May 17 2016 02:42
Thanks y'all. Very Helpful!
Stephen James
@sjames1958gm
May 17 2016 02:42
@wcski FYI, there is a pretty active web development community out your way. I know of several web dev podcasts that originate out of Utah, maybe even SLC
rphares
@rphares
May 17 2016 02:42
(dunno, is it too soon? ty @sjames1958gm ~)
CamperBot
@camperbot
May 17 2016 02:42
rphares sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1129 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
May 17 2016 02:43
@sjames1958gm Probably a free code camp meetup out there as well
William Coleman
@wcski
May 17 2016 02:43
There sure is. I work as a QA engineer out here, and the tech market is great. I was listening to a CodeNewbie podcast episode where she interviewed someone who ran a podcast locally. I think it was ruby-focused, though, so I didn't follow.
We have a great freecodecamp meetup group out here. just met up this past weekend.
Stephen James
@sjames1958gm
May 17 2016 02:44
@wcski devchat.tv has several podcasts - and their address is 514 South 2970 West • Lehi, UT 84043
@wcski Yeah, here in N. Texas it is not so great.
Ok. that's it for me tonight. Have a good one all
jgoldverg
@jgoldverg
May 17 2016 02:45
Are there many freecodecamps in nyc??
or near it?
William Coleman
@wcski
May 17 2016 02:45
For a newbie, I have to say that I really underestimated the value of getting involved with the community.
Stephen James
@sjames1958gm
May 17 2016 02:45
@jgoldverg Don't know but I would think so.
William Coleman
@wcski
May 17 2016 02:45
Thanks again for your help @sjames1958gm
CamperBot
@camperbot
May 17 2016 02:45
wcski sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1130 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
jgoldverg
@jgoldverg
May 17 2016 02:46
will def check it out
Chuck Pierce
@ChuckPierce
May 17 2016 02:47
bot help
CamperBot
@camperbot
May 17 2016 02:47

:point_right: coding help [wiki]

Coding Help

I started this list while doing Algorithms, noticing a few things that were common issues / questions but I think most of them are going to be useful to people coding in general. If you've got some tips to help people code I'd love to hear them.

  1. If you don't know where to start, write some pseudocode. Plan out the logic you're trying to implement in your native language before you try to put it into code.

  2. Comment your code! Can't stress that one enough, if you get lost or take a break then come back you need to know what your code is trying to do. It will also reinforce what the code means to you, and help other people understand what your code does if you get stuck and ask for help. If you've got a any other tips for campers I'd love to see them!

  3. Use the chrome javascript debugger console in conjunction with something like the netbeans IDE or sublime text to write your code. Both are free to download.
    The FreeCodeCamp code editor is great but you can get a lot more feedback on your code's behaviour by using chrome's JS debugger and a bunch of console.log(myVariableGoesHere);

    References

  4. Posting your code in gitter is as simple as adding a line consisting of only

    ```

    Then your code on the next lines, followed by a final

    :pencil: read more about coding help on the FCC Wiki

skilescm
@skilescm
May 17 2016 02:53
hello!
Ronique Ricketts
@RoniqueRicketts
May 17 2016 02:56
help factorialize a number
CamperBot
@camperbot
May 17 2016 02:56

:point_right: algorithm factorialize a number [wiki]

Problem Explanation:

Return the factorial of the provided integer. If the integer is represented with the letter n, a factorial is the product of all positive integers less than or equal to n.

Factorials are often represented with the shorthand notation n!

For example: 5! = 1 * 2 * 3 * 4 * 5 = 120

:pencil: read more about algorithm factorialize a number on the FCC Wiki

skilescm
@skilescm
May 17 2016 02:57
Anyone have any experience changing CSS with javascript?
OneRandomJamie
@OneRandomJamie
May 17 2016 02:59
I am completely stuck on the Word Blanks challenge.
rphares
@rphares
May 17 2016 02:59
@OneRandomJamie -- it gets lots of people,
could you please paste what you are trying? :blush:
OneRandomJamie
@OneRandomJamie
May 17 2016 03:00
This is what I have now but I tried what seems like 50000 other things before this. var myNoun = "cat";
var myAdjective = "little";
var myAdverb = "slowly";
var myVerb = "hit";
var Str = "The" + myAdjective + myNoun + "ran + myAdverb + "across the street and" + myVerb + "the dog.";
rphares
@rphares
May 17 2016 03:01
a few things,
first, you dont need to declare the myNoun, myAdjective stuff,
you can delete all the lines but var Str
second, for that line, you do need to store the sentence... but store it in what you will return--
look at the bottom, what are you going to return?
third, you are missing a " after "ran
OneRandomJamie
@OneRandomJamie
May 17 2016 03:03
@rphares wordBlanks("dog", "big", "ran", "quickly");
rphares
@rphares
May 17 2016 03:03
yep, i know the challenge :blush:
but-- the return statement has already been given to you,

    // Your code above this line
  return result;
}
so, if you store the sentence in a new var, myStr, it doesn't do you any good...
because you are going to return result
and at the top,
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
    var result = "";
(also, did you change the parameters? that ^^ is what was there originally, no?)
OneRandomJamie
@OneRandomJamie
May 17 2016 03:06
@rphares its still there. I didnt change it. I just didnt copy it because it said dont change it.
rphares
@rphares
May 17 2016 03:06
Theres still more to do, but thats a lot... have another look-- i'd suggest resetting the lesson and giving it another go-
okay, cool
OneRandomJamie
@OneRandomJamie
May 17 2016 03:07
@rphares Thank you
CamperBot
@camperbot
May 17 2016 03:07
onerandomjamie sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
rphares
@rphares
May 17 2016 03:07
then, the lsat thing, on top of the other sutff-
CamperBot
@camperbot
May 17 2016 03:07
:star2: 4649 | @rphares |http://www.freecodecamp.com/rphares
rphares
@rphares
May 17 2016 03:07
your sentence has no spaces
so, even if you had all the changes above, it still wouldn't pass,
because your output would be Thebigdogranquicklyacross the street andranthe dog @OneRandomJamie
OneRandomJamie
@OneRandomJamie
May 17 2016 03:08
@rphares The actual thing is space but for some reason when i past to here it takes the spaces out.
rphares
@rphares
May 17 2016 03:08
oh, not quite--
spaces in the code dont count
"My" + myNoun
is Mydog
myNoun + " " + myVerb
is dog ran
OneRandomJamie
@OneRandomJamie
May 17 2016 03:09
ok
rphares
@rphares
May 17 2016 03:09
gives those a go, and feel free to come back if stuck!
(I'm going to bed soon, though-- good luck and happy coding~ )
OneRandomJamie
@OneRandomJamie
May 17 2016 03:09
@rphares thank you again
CamperBot
@camperbot
May 17 2016 03:09
onerandomjamie sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:warning: onerandomjamie already gave rphares points
rphares
@rphares
May 17 2016 03:10
Anytime~
OneRandomJamie
@OneRandomJamie
May 17 2016 03:10
@rphares Good night
sbc4242
@sbc4242
May 17 2016 03:27

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

return collection;
}

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

this code keep saying that : TypeError: Cannot set property 'prop' of undefined
can anyone help me out
coekwaawu
@coekwaawu
May 17 2016 03:29
Try to use collection[id][prop]
sbc4242
@sbc4242
May 17 2016 03:30
Thanks you so much. It worked out well
but is there any difference between dot and bracket
im not good at explaining it, but that article helped me. (yes, there is a difference in when we can use them....)
coekwaawu
@coekwaawu
May 17 2016 03:38
I don't know why,I just do what the note says:Don't forget to use bracket notation when accessing object properties with variables.
Keenen Garnett
@Wallyw4
May 17 2016 03:39

i need some help i m doing everything it wants it returns 2 and removes the first and adds item to the last
function nextInLine(arr, item) {
// Your code here
arr.shift(arr);
arr.push(item);

return arr[0]; // 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));

estnimbus
@estnimbus
May 17 2016 03:39
hello guys . iam stuck at "Stand in Line"
Keenen Garnett
@Wallyw4
May 17 2016 03:39
me @estevenimbus
too @estevenimbus
estnimbus
@estnimbus
May 17 2016 03:39
@Wallyw4
Travis
@dukenukethem
May 17 2016 03:39
The person who wrote https://medium.com/@prufrock123/js-dot-notation-vs-bracket-notation-797c4e34f01d#.5a8x33pc1 is HIGHLY biased against cats; like dang
Daniel Robinson
@danielrob
May 17 2016 03:40
Just finished the US phone numbers one, but wondering how short people have managed to get it?
estnimbus
@estnimbus
May 17 2016 03:40
Lets try and figure it out @Wallyw4
Keenen Garnett
@Wallyw4
May 17 2016 03:40
ok @estevenimbus
Travis
@dukenukethem
May 17 2016 03:40
@danielrob validate US Telephone numberS?
Daniel Robinson
@danielrob
May 17 2016 03:40
@dukenukethem Yep that's it :)
Travis
@dukenukethem
May 17 2016 03:41
Oh okay; I'm nowhere near it haha
Daniel Robinson
@danielrob
May 17 2016 03:41
oh haha :)
Keenen Garnett
@Wallyw4
May 17 2016 03:41
so this is my output: Before: [1,2,3,4,5,]
2
After: [2,3,4,5,6]
is that not what they wanted?
Travis
@dukenukethem
May 17 2016 03:42
Looks like you need to have a firm grasp on RegEx to get that challenge done
Keenen Garnett
@Wallyw4
May 17 2016 03:43
??
Daniel Robinson
@danielrob
May 17 2016 03:43
@dukenukethem yeah. It took me three searches, & then I used two chained replaces for the final check, I imagine it can be done in less.
In saying that it's a readable solution which counts for something.
Keenen Garnett
@Wallyw4
May 17 2016 03:44
I wonder what im missing
estnimbus
@estnimbus
May 17 2016 03:44
@Wallyw4 yes i try different things
and I get only 2 out of the 4 checked right
Keenen Garnett
@Wallyw4
May 17 2016 03:45
yup same here @estevenimbus
buiphuking
@buiphuking
May 17 2016 03:45
can we change font-family for number , guys ?
estnimbus
@estnimbus
May 17 2016 03:46
the answer swap when i change the return part
Keenen Garnett
@Wallyw4
May 17 2016 03:46
mine havent changed what did you change in return?
estnimbus
@estnimbus
May 17 2016 03:46
@Wallyw4 what do you have on the "return item" part
i tried this
Keenen Garnett
@Wallyw4
May 17 2016 03:47
return arr[0]
estnimbus
@estnimbus
May 17 2016 03:47
@Wallyw4 return arr[0]+1
try it and see what happens
Keenen Garnett
@Wallyw4
May 17 2016 03:49
ya i got second check mark now
Daniel Robinson
@danielrob
May 17 2016 03:49
@Wallyw4 you don't need to pass the array to arr.shift()
coekwaawu
@coekwaawu
May 17 2016 03:50
Hello everyone,in challenges "Generate Random Whole Numbers within a Range",why my answer "return myMax-Math.floor(Math.random()*(myMax-myMin+1));" is wrong?
Daniel Robinson
@danielrob
May 17 2016 03:50
Also note that Array.prototype.shift changes the array.
(and returns a value)
Keenen Garnett
@Wallyw4
May 17 2016 03:50
then how do we replace the first element? @danielrob
Daniel Robinson
@danielrob
May 17 2016 03:50
Re-read the question. It's not asking you to replace the first element :)
Keenen Garnett
@Wallyw4
May 17 2016 03:51
do we decrement it?
estnimbus
@estnimbus
May 17 2016 03:51
@danielrob uhhhh ok
Keenen Garnett
@Wallyw4
May 17 2016 03:51
oh it says to remove it
Daniel Robinson
@danielrob
May 17 2016 03:51
:)
estnimbus
@estnimbus
May 17 2016 03:51
yes
Ross
@Woodywoodruff3
May 17 2016 03:51
I am stuck on Challenge 146.
i need to write this out
estnimbus
@estnimbus
May 17 2016 03:52
I still dont get the last line we are suppose to have right
@danielrob nextInLine(testArr, 10), testArr[4] should be 10
Ross
@Woodywoodruff3
May 17 2016 03:52
Set remainder equal to the remainder of 11 divided by 3 using the remainder (%) operator.
The value of remainder should be 2
Keenen Garnett
@Wallyw4
May 17 2016 03:52
i got 3 checks @estevenimbus
estnimbus
@estnimbus
May 17 2016 03:52
me too @Wallyw4
@Wallyw4 @danielrob I honestly do not evenn understand why nextInLine(testArr, 10), testArr[4] should be 10
Keenen Garnett
@Wallyw4
May 17 2016 03:54
it wants us to increase the arr index so that the next in line keeps going so index 4 would be 10 but i dont get how iwe should increment the index
Daniel Robinson
@danielrob
May 17 2016 03:54
I'm not sure how the test is implemented, testArr is probably an internal test array e.g. [1,1,1,1,1,10]
[0,1,2,3,4,10] is easier ;D
(it's not the testArray in the main code, because I have it passing, and I've changed testArr in the code to [6])
estnimbus
@estnimbus
May 17 2016 03:57
@danielrob we should report a bug then
@also why dont we have to use switch
@danielrob
Daniel Robinson
@danielrob
May 17 2016 03:57
It's not a bug, but it is slightly confusing (the code works, the test description is just confusing)
@estevenimbus what's your code so far?
estnimbus
@estnimbus
May 17 2016 03:58

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

return arr[0]; // Change this line
}

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

Daniel Robinson
@danielrob
May 17 2016 03:58
Think about how the array will be affected. E.g. [1,2,3] -> [2,3,<call value>].
Ok good, so you have [1,2,3] -> [1,2,3, item ] now you need [1,2,3,item] -> [2,3,item]. So you need to remove the first item from the array after the push.
Keenen Garnett
@Wallyw4
May 17 2016 04:00
so shift it out?
Daniel Robinson
@danielrob
May 17 2016 04:00
Does it work? ;P
coekwaawu
@coekwaawu
May 17 2016 04:00
@Woodywoodruff3 How about trying this answer in 146:"var remainder = 11 %3 "
Keenen Garnett
@Wallyw4
May 17 2016 04:01

i tried this and still nothing

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

arr.push(item);
arr.shift(arr[0]);

return arr[0]; // Change this line
}

buiphuking
@buiphuking
May 17 2016 04:03
plz someone test my thing
why 10 2 = 20, but 80 2 = nothing?
http://codepen.io/buiphuking/pen/qZwpjE/?editors=0010
Daniel Robinson
@danielrob
May 17 2016 04:04
"The shift() method removes the first element from an array and returns that element. "
Islam Ibakaev
@dagman
May 17 2016 04:04
@Wallyw4 maybe u want to return arr.shift(arr[0]);
Daniel Robinson
@danielrob
May 17 2016 04:04
@dagman That would work, but it would still not be correct :D
(I consider passing parameters to functions that don't take parameters incorrect)
Keenen Garnett
@Wallyw4
May 17 2016 04:05
i go it
Daniel Robinson
@danielrob
May 17 2016 04:05
!!!!
Keenen Garnett
@Wallyw4
May 17 2016 04:05

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

arr.push(item);

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

Daniel Robinson
@danielrob
May 17 2016 04:05
wooot!
Keenen Garnett
@Wallyw4
May 17 2016 04:06
so what it was looking for was returning the element removed from the beginning of the array
Daniel Robinson
@danielrob
May 17 2016 04:07
Yep: "The nextInLine function should then return the element that was removed." :)
Good work. There is also .unshift() for putting an element back on the front of an array
Keenen Garnett
@Wallyw4
May 17 2016 04:08
so return will actually execute the code and return the outcome of said execution?
Daniel Robinson
@danielrob
May 17 2016 04:08
and .pop() for removing an element from the end
Ross
@Woodywoodruff3
May 17 2016 04:11
@coekwaawu Thanks! I could have sworn I wrote that code. I was pulling my hair out.
CamperBot
@camperbot
May 17 2016 04:11
woodywoodruff3 sends brownie points to @coekwaawu :sparkles: :thumbsup: :sparkles:
:cookie: 225 | @coekwaawu |http://www.freecodecamp.com/coekwaawu
Keenen Garnett
@Wallyw4
May 17 2016 04:12
how do i send you brownies? @danielrob
Daniel Robinson
@danielrob
May 17 2016 04:12
Oh, cheers, I think like thanks @Wallyw4
CamperBot
@camperbot
May 17 2016 04:12
danielrob sends brownie points to @wallyw4 :sparkles: :thumbsup: :sparkles:
:cookie: 188 | @wallyw4 |http://www.freecodecamp.com/wallyw4
Daniel Robinson
@danielrob
May 17 2016 04:12
(just include the word t.hanks)
Keenen Garnett
@Wallyw4
May 17 2016 04:13
thanks @danielrob
CamperBot
@camperbot
May 17 2016 04:13
wallyw4 sends brownie points to @danielrob :sparkles: :thumbsup: :sparkles:
:cookie: 176 | @danielrob |http://www.freecodecamp.com/danielrob
Keenen Garnett
@Wallyw4
May 17 2016 04:13
woo
Daniel Robinson
@danielrob
May 17 2016 04:14
All good @estevenimbus ?
Samuel Cupidon
@Zerazera
May 17 2016 04:17
@buiphuking You have a space with your 8
Kelly Kovalcik
@kellykov
May 17 2016 04:19
For Converting Celsius to Fahrenheit - you have to write out the correct words in the formula. So the answer should be:
var fahrenheit = 9/5 * celsius + 32
estnimbus
@estnimbus
May 17 2016 04:25
Yes! Thank you @danielrob
CamperBot
@camperbot
May 17 2016 04:25
estevenimbus sends brownie points to @danielrob :sparkles: :thumbsup: :sparkles:
:cookie: 177 | @danielrob |http://www.freecodecamp.com/danielrob
estnimbus
@estnimbus
May 17 2016 04:25
@Wallyw4 how far are you going to be studying this
??
today
Keenen Garnett
@Wallyw4
May 17 2016 04:26
I'm going to bed now lol
estnimbus
@estnimbus
May 17 2016 04:27
same
man
I have to be up in 5 hours
but you want to google hang out
Keenen Garnett
@Wallyw4
May 17 2016 04:27
I have to be up in 6
estnimbus
@estnimbus
May 17 2016 04:27
and work on this tomorrow?
Keenen Garnett
@Wallyw4
May 17 2016 04:28
The whole javascript map? Or just that one thing?
estnimbus
@estnimbus
May 17 2016 04:28
I like to have somebody at the same level as me so I can check my progress and not fall behind
buiphuking
@buiphuking
May 17 2016 04:28
@Zerazera
add 30 x.2
estnimbus
@estnimbus
May 17 2016 04:29
depends how much do you work on this per week , ? day?
@Wallyw4
Keenen Garnett
@Wallyw4
May 17 2016 04:29
Idk just when I can I'm also in the process of buying my first house so its hard to find time
estnimbus
@estnimbus
May 17 2016 04:30
ok no worries then
good luck with the house
see you again sometimes
Keenen Garnett
@Wallyw4
May 17 2016 04:30
Have a good night man n thanks @estevenimbus
CamperBot
@camperbot
May 17 2016 04:30
wallyw4 sends brownie points to @estevenimbus :sparkles: :thumbsup: :sparkles:
:cookie: 124 | @estevenimbus |http://www.freecodecamp.com/estevenimbus
estnimbus
@estnimbus
May 17 2016 04:31
@Wallyw4 thanks
CamperBot
@camperbot
May 17 2016 04:31
estevenimbus sends brownie points to @wallyw4 :sparkles: :thumbsup: :sparkles:
:cookie: 190 | @wallyw4 |http://www.freecodecamp.com/wallyw4
Arvilyn Ong
@arvilyn
May 17 2016 04:32
hi , i'm stuck at 'Return Largest Numbers in Arrays', could anyone tell me what's wrong with my code?
function largestOfFour(arr) {
  // You can do this!
  var newArr = [];
  var largest = 0;
  for(var i=0; i < arr.length; i++) { // for each [ ],
    for(var j =0 ; j < arr[i].length; j++) { //for each element inside [],
      if (arr[i][j] > largest) {
        largest = arr[i][j];
      } else {
        return largest;
      }
    } 
    return newArr.push(largest);
  } 
}


largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Coy Sanders
@coymeetsworld
May 17 2016 04:33
return largest
you don't want that in there @arvilyn
it will exit your function prematurely
also you will want to reset your largest variable in a different location
Lemmy
@imnotlammy
May 17 2016 04:34
        $(".container").click(function() {

          if($(".temperature").has(tempC)) {
            $(".temperature").html(tempF + "°F");
          }
          else {
            $(".temperature").html(tempC + "°C");
          }
        });
hi all
Coy Sanders
@coymeetsworld
May 17 2016 04:34
and don't want to return newArr.push(largest), you want to do that separately, then return newArr when you're done with both loops, so quite a bit :)
Lemmy
@imnotlammy
May 17 2016 04:34
how do I get the temperature to toggle between celcius and farenheit on click?
Coy Sanders
@coymeetsworld
May 17 2016 04:37
not familiar with has() function @imnotlammy, but i'm not sure if it searches like that, only grabs tags, could be wrong
I would add some console.log lines at various places in your code and try debugging that way
see what happens when your click function runs, and if it runs for one
Lemmy
@imnotlammy
May 17 2016 04:37
@coymeetsworld the function only works when converting from C to F
but I can't get it to switch back
SuryaKavutarapu
@SuryaKavutarapu
May 17 2016 04:38

```js
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 += 1;
break;
case 7:
case 8 :
case 9:
count += 0;
break;
case 10 :
case 'J':
case 'Q':
case 'K':
case 'A':
count -= 1;
break;
}

return count + (count > 0 ? "Bet":"Hold");
// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
``` guys whats wrong with my code can anybody help

CamperBot
@camperbot
May 17 2016 04:38
:bulb: to format code use backticks! ``` more info
Coy Sanders
@coymeetsworld
May 17 2016 04:38
can you show the rest of the code?
DJ
@qualitymanifest
May 17 2016 04:38
@imnotlammy yeah paste your codepen
DJ
@qualitymanifest
May 17 2016 04:39
@imnotlammy also i think that would be a better use for .text() instead of .html()
Coy Sanders
@coymeetsworld
May 17 2016 04:39
assuming hes not inadvertantly deleting html inside that class
that he needs to preserve
Arvilyn Ong
@arvilyn
May 17 2016 04:39
@coymeetsworld i managed to solve it, thank you so much!!! :smile:
CamperBot
@camperbot
May 17 2016 04:39
arvilyn sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:cookie: 874 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Coy Sanders
@coymeetsworld
May 17 2016 04:39
nice @arvilyn :thumbsup: congrats i know there was a bit I said lol
Lemmy
@imnotlammy
May 17 2016 04:40
weird, why is it displaying blank?
Does it have something to do with the API?
Coy Sanders
@coymeetsworld
May 17 2016 04:40
idk @imnotlammy, are you using chrome?
Lemmy
@imnotlammy
May 17 2016 04:40
yeah
Coy Sanders
@coymeetsworld
May 17 2016 04:40
because geolcation isn't supported anymore
on non-secure connections in chrome
Lemmy
@imnotlammy
May 17 2016 04:40
oic
Coy Sanders
@coymeetsworld
May 17 2016 04:40
you need another way of getting coordinates, or if you don't want to mess with that just hardcode some values for now
and then add that feature later if you want to focus on getting buttons working
oh i guess you did lol
Lemmy
@imnotlammy
May 17 2016 04:42
yeah lol
Coy Sanders
@coymeetsworld
May 17 2016 04:43
@imnotlammy im not sure why it works first time and not second because of this
but i notice your button click function is nested inside your getJSON function
you should take it outside of that
code won't be able to read that because it's nested in an anonymous function.
now why it works the first time? i'm not 100% sure
Anteli
@Anteli
May 17 2016 04:46
Hello!
DJ
@qualitymanifest
May 17 2016 04:46
it actually will work despite being inside the getJSON
i made it work by using .text() for everything rather than .has() and .html()
if temperature's text is in c, convert text to f. else convert text to c
Coy Sanders
@coymeetsworld
May 17 2016 04:47
hmm interesting @qualitymanifest
i was thinking maybe somehow after the container was clicked it lost that click action but that didn't make sense to me
Lemmy
@imnotlammy
May 17 2016 04:48
@qualitymanifest ```
DJ
@qualitymanifest
May 17 2016 04:48
@coymeetsworld yeah i can understand that, that was my assumption at first
Lemmy
@imnotlammy
May 17 2016 04:48
        $(".container").click(function() {

          if ($(".temperature").text == tempC) {
            $(".temperature").text(tempF + "°F");
          } else {
            $(".temperature").text(tempC + "°C");
          }
        });
@qualitymanifest
this?
DJ
@qualitymanifest
May 17 2016 04:48
@imnotlammy it's .text() not just .text
and the text originally isn't just tempC. it's tempC + "°C"
so you will need to change your if
Lemmy
@imnotlammy
May 17 2016 04:49
ahh ok
I will save + "°C"
in the var then
should work
DJ
@qualitymanifest
May 17 2016 04:50
i didnt change the var, just used it in the comparison
Coy Sanders
@coymeetsworld
May 17 2016 04:50
or you can use the String.includes function
i think you can search for numbers, not 100% sure
Lemmy
@imnotlammy
May 17 2016 04:51
        $(".container").click(function() {

          if ($(".temperature").text() == tempC + "°C") {
            $(".temperature").text(tempF + "°F");
          } else {
            $(".temperature").text(tempC + "°C");
          }
        });
worked!
@qualitymanifest thanks
CamperBot
@camperbot
May 17 2016 04:51
imnotlammy sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star2: 1164 | @qualitymanifest |http://www.freecodecamp.com/qualitymanifest
DJ
@qualitymanifest
May 17 2016 04:51
np
Anteli
@Anteli
May 17 2016 04:57

Hey mates! I have been been struggling with this for hours. Something strange is happening.

Could someone please help me why this is not working:

<!DOCTYPE html>
<html>
<body>
<script src="script.js"></script>
<p id="intro">Hello World!</p>
<p>This example demonstrates the <b>getElementById</b> method!</p>
<p id="demo"></p>
</body>
</html>

But if I add:

<script src="script.js"></script>

after:

<p id="demo"></p>

Then it works.

<!DOCTYPE html>
<html>
<body>
<script src="script.js"></script>
<p id="intro">Hello World!</p>
<p>This example demonstrates the <b>getElementById</b> method!</p>
<p id="demo"></p>
<script src="script.js"></script>
</body>
</html>

JavaScript:

var myElement = document.getElementById("intro");
document.getElementById("demo").innerHTML = 
"The text from the intro paragraph is " + myElement.innerHTML;

Thanks for help!

Walter Augustine
@Walter-0
May 17 2016 05:00
@Anteli Your script is trying to get an html element that’s not loaded yet
@Anteli Best practice is to put your script tags at the end of the body so you’ve got it already
Diwakar Serala
@diwpro007
May 17 2016 05:04
can some one explain what this exact change challenge is trying to say?
Diwakar Serala
@diwpro007
May 17 2016 05:08
can some one explain what this Exact Challenge challenge is trying to say?
https://www.freecodecamp.com/challenges/exact-change
Darth Skywalker
@adityaparab
May 17 2016 05:12
help exact change
CamperBot
@camperbot
May 17 2016 05:12
no wiki entry for: exact challenge
Anteli
@Anteli
May 17 2016 05:13
@Walter-0 Thanks! That explains!
CamperBot
@camperbot
May 17 2016 05:13
anteli sends brownie points to @walter-0 :sparkles: :thumbsup: :sparkles:
:cookie: 302 | @walter-0 |http://www.freecodecamp.com/walter-0
Anteli
@Anteli
May 17 2016 05:16
@camperbot how to do it? :)
Walter Augustine
@Walter-0
May 17 2016 05:16
help where art thou
CamperBot
@camperbot
May 17 2016 05:16

:point_right: algorithm where art thou [wiki]

Problem Explanation

Write an algorithm that will take an array for the first argument and return an array with all the objects that matches all the properties and values in the Object passed as second parameter.

:pencil: read more about algorithm where art thou on the FCC Wiki

Diwakar Serala
@diwpro007
May 17 2016 05:17
help exact change
CamperBot
@camperbot
May 17 2016 05:17

:point_right: algorithm exact change [wiki]

Problem Explanation:

  • You have to create a program that will handle when the register does not have
    enough cash or will have no cash after the transaction. Other than that it
    needs to return an array of the change in the form of an array, so that will
    be a 2D array.
:pencil: read more about algorithm exact change on the FCC Wiki
Greg
@GregJacoby
May 17 2016 05:27
can someone offer me a -hint- on mutations? im not quite sure where to start. as small of a hint as possible. i see they suggest using indexOf, but it's still not clicking
help mutations
CamperBot
@camperbot
May 17 2016 05:29

:point_right: algorithm mutations [wiki]

Problem Explanation:

  • Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array..
:pencil: read more about algorithm mutations on the FCC Wiki
Markus Kiili
@Masd925
May 17 2016 05:32
@GregJacoby Pick the strings to variables and lowercase them. Loop through the second string characters and...
Greg
@GregJacoby
May 17 2016 05:32
oo okay
thanks
i'll start there
@Masd925 thank you
CamperBot
@camperbot
May 17 2016 05:33
gregjacoby sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1512 | @masd925 |http://www.freecodecamp.com/masd925
Kelly Kovalcik
@kellykov
May 17 2016 05:49
Can I have some help with "Escaping Literal Quotes in Strings" please? I'm not sure why but for some reason I've been stuck on this. This is what I've been trying. Does anyone know what I'm doing wrong?
var myStr = "I am a \"double quoted\" string inside \"double quotes\".";
Keone Martin
@Athaman
May 17 2016 05:51
there is no full stop at the end i think
@kellykov
Coy Sanders
@coymeetsworld
May 17 2016 05:53
shouldn't be a period at the end @kellykov
you escaped the quotes right
Kelly Kovalcik
@kellykov
May 17 2016 05:55
Yes thank you @Athaman @coymeetsworld
This is what it should be:
CamperBot
@camperbot
May 17 2016 05:55
:cookie: 372 | @athaman |http://www.freecodecamp.com/athaman
:cookie: 876 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
kellykov sends brownie points to @athaman and @coymeetsworld :sparkles: :thumbsup: :sparkles:
Kelly Kovalcik
@kellykov
May 17 2016 05:55
var myStr = "I am a \"double quoted\" string inside \"double quotes\"";
Coy Sanders
@coymeetsworld
May 17 2016 05:55
np @kellykov :thumbsup:
Keone Martin
@Athaman
May 17 2016 05:59
you're welcome
SuryaKavutarapu
@SuryaKavutarapu
May 17 2016 06:23

guys i'm stuck over here can anybody please help ```js

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

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

Keone Martin
@Athaman
May 17 2016 06:23
you need to multiply each step in the middle of your for loops
so instead of product = arr[i][j]; try product *= arr[i][j];
otherwise looks good @SuryaKavutarapu
SuryaKavutarapu
@SuryaKavutarapu
May 17 2016 06:25
thank you @Athaman it worked :smile:
CamperBot
@camperbot
May 17 2016 06:25
suryakavutarapu sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
:cookie: 373 | @athaman |http://www.freecodecamp.com/athaman
Keone Martin
@Athaman
May 17 2016 06:25
no problem bud
David Shavers
@frontEndDevv
May 17 2016 06:34
hey guys could someone point me in the right direction of the counting cards lesson in javascript?
ERWIN JOHN T. CARPIO, MD, FPCR
@RadEdje
May 17 2016 06:34
Hello... I'm currently on the build a random quote machine project. I already have some idea how to do it. My question is where to store the json and imgLink sources? Do you suggest I use drop box and put the json files in there or does codepen have some way for me to put in a json file?
Keone Martin
@Athaman
May 17 2016 06:35
@frontEndDevv sure, you need to separate the possible use cases into logical statements with either if/else or a switch. then inside each of them you need to react accordingly, +1 to count and bet if <=6 etc.
not sure @RadEdje, you can make a JSON object inside the JS panel and access it from there right?
ERWIN JOHN T. CARPIO, MD, FPCR
@RadEdje
May 17 2016 06:38
@Athaman Oops my bad... i forgot I could incorporate the json directly into the js panel.... so I can just refer to the var jsonObj directly right? Thanks...
CamperBot
@camperbot
May 17 2016 06:38
radedje sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
:cookie: 374 | @athaman |http://www.freecodecamp.com/athaman
Keone Martin
@Athaman
May 17 2016 06:39
Pretty sure i've seen that done @RadEdje but I haven't actually done the websites yet so I may be wrong, give it a go and find out ;)
Jimmy Hernandez
@dismister
May 17 2016 06:39
I'm confused hwo this regular javascipt expression works... could someone explain this to me please? str = str.replace(/[^A-Za-z0-9]/g, '');
what does the material inside the backlash mean?
Keone Martin
@Athaman
May 17 2016 06:40
ok sure, my understanding of regexp is limited but those seem to be looking for any capital, lowercase, or numeric character.
the g looks for all of the matches... and the '' is an empty string to replace them with nothing.
so running that on a string should remove all alpha-numeric characters and just leave punctuation right?
David Shavers
@frontEndDevv
May 17 2016 06:41
@Athaman Thanks man
CamperBot
@camperbot
May 17 2016 06:41
frontenddevv sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
:cookie: 375 | @athaman |http://www.freecodecamp.com/athaman
Keone Martin
@Athaman
May 17 2016 06:41
wait, that's backwards
Jimmy Hernandez
@dismister
May 17 2016 06:41
that's what I thought but it is part of the Palindrome bon fire

function palindrome(str) {

str = str.replace(/[^A-Za-z0-9]/g, '');

return str.split('').reverse().join('').toLowerCase() === str.toLowerCase();

}

palindrome("eye");

Keone Martin
@Athaman
May 17 2016 06:41
@dismister the regexp there is searhing for anything which isn't an alphanumeric character and deleting it
ERWIN JOHN T. CARPIO, MD, FPCR
@RadEdje
May 17 2016 06:42
What about images though? I was hoping to spruce up the random quote machinewith a few cute cat images hehe... I prefer to make my own images to avoid randomly getting images from the net that might have copytights... any suggestions on a good image hosting site? Dropbox? Instagram? Or can github serve these things? (Pics and json etc).
Keone Martin
@Athaman
May 17 2016 06:42
Jimmy Hernandez
@dismister
May 17 2016 06:42
ooo that makes perfect sense @Athaman keone thank you
CamperBot
@camperbot
May 17 2016 06:42
dismister sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
:cookie: 376 | @athaman |http://www.freecodecamp.com/athaman
Keone Martin
@Athaman
May 17 2016 06:43
@RadEdje not sure about images sorry, there are a tonne of hosting sites obviously, or you can just go to google image and steal their kittens.
Jimmy Hernandez
@dismister
May 17 2016 06:46
what about the single quotes after the g? str = str.replace(/[^A-Za-z0-9]/g, '');
what is that for?
Coy Sanders
@coymeetsworld
May 17 2016 06:46
I use dropbox @RadEdje
Keone Martin
@Athaman
May 17 2016 06:46
that's what the matched characters will be replaced with, so in this case it's an empty string, or nothing, essentially just deleting the character
Coy Sanders
@coymeetsworld
May 17 2016 06:47
idk about github, if you have a url to the image possibly
didn't try seeing if i can access it into something like CodePen
Keone Martin
@Athaman
May 17 2016 06:47
so str = str.replace("a", "b"); will look for the first a and change it to a b
Jimmy Hernandez
@dismister
May 17 2016 06:48
you are a life saver @Athaman much appreciated man.
Keone Martin
@Athaman
May 17 2016 06:49
no worries my friend, always nice to help out
Krzysztof Borowy
@Krizzu
May 17 2016 06:49
Hi guys. After reading few articles on Medium I wondered
Everyone is saying to code every day
but, I think I struggle to make a progress in my learning
Keone Martin
@Athaman
May 17 2016 06:51
things take time sometimes
Krzysztof Borowy
@Krizzu
May 17 2016 06:51
I'm confortable with JS, I created intermediate project with ease, JQuery is not a problem
Keone Martin
@Athaman
May 17 2016 06:55
what are you having troubles with?
Krzysztof Borowy
@Krizzu
May 17 2016 06:55
I think I just don't feel like doing any progress
I would love to know what I should know before learning like bigger stuff, like react or nodejs
because now I feel like if I start them, I will fail
Darrel Adams
@dadams-510
May 17 2016 06:57
@Krizzu Coding is a journey and not a race.
I would recommend to start off with the basics: HTML & CSS
then work your way up to basic javascript.
Krzysztof Borowy
@Krizzu
May 17 2016 06:58
@dadams-510 I've got it, more then a basics
But now I struggle if I should move forward or work on somethig else
Keone Martin
@Athaman
May 17 2016 06:58
honestly at the moment i'm going sort of gung ho on it. i'm starting random courses and trying random things and half of them are completely beyond my abilites so i just switch it up and will come back to it later... it's not like it's a terrible thing to not be able to handle advanced things at the moment, and unfortunately with coding there is no clear road map for what comes next on a scale of challenge. some people find some things easy and struggle on other things that i may find easy. you just need to try stuff, find out what you enjoy, and work at it.
Krzysztof Borowy
@Krizzu
May 17 2016 06:59
@Athaman That's an actualy a fantastic advice, thanks
CamperBot
@camperbot
May 17 2016 06:59
krizzu sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
:cookie: 377 | @athaman |http://www.freecodecamp.com/athaman
Krzysztof Borowy
@Krizzu
May 17 2016 07:00
I think I will stick to getting my Certificate at FCC, doing react/nodejs meanwhile
Keone Martin
@Athaman
May 17 2016 07:00
sounds good
Alexandr
@alexakuna
May 17 2016 07:09
Please need help with this task.
"Golf Code"
Kyle W Pilkinton
@tadake
May 17 2016 07:10
hey guys how would i filter out all variables in the filter array out of the data array in this code?
function diffArray(arr1, arr2) {
  var newarr = [];
  var filter = [];
  var filtered = [];
  // Same, same; but different.

  for(var i = 0 ; i < arr1.length; i++){
    for(var j = 0; j < arr2.length; j++){

      if(arr1[i] == arr2[j]){

        filter[i] = arr1[i];

      }
    }
  }

  var data = arr1.concat(arr2);


 }
  return newarr;        
 }  
}


diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
Vivek Jadon
@vjadon
May 17 2016 07:10
need help with Counting cards

var count = 0;

function cc(card) {
// Only change code below this line
for(i=0;i<card.length;i++)
{
if(card[i]==10 || card[i]=='J' || card[i]=='Q' || card[i]=='K' || card[i]=='A')
count--;
else if(card[i]==2 || card[i]==3 || card[i]==4 || card[i]==5 || card[i]==6)
count++;

}

if(count>0)
return count + " Hold";
else
return count + " Bet";

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

Spartano
@Spartano
May 17 2016 07:11
someone can explain me why (\w)\1{1} selects all word charcther that repeats itself 2 times, i dont get why i put {1} and not {2}... thanks
Keone Martin
@Athaman
May 17 2016 07:11
@tadake filter works by saying array.filter() and you need to put stuff in the brackets, i'd suggest googling filter() JS and reading an article on it
Markus Kiili
@Masd925
May 17 2016 07:11
@tadake You wan't to filter out elements of one array if they exist in the second array?
Keone Martin
@Athaman
May 17 2016 07:11
@alexakuna what do you need for golf code?
Kyle W Pilkinton
@tadake
May 17 2016 07:12
ive tried reading about it online but im having difficulties understanding @Athaman
yeah that what im trying to do @Masd925
Alexandr
@alexakuna
May 17 2016 07:12
I can not understand
Keone Martin
@Athaman
May 17 2016 07:12
@vjadon in counting cards you're getting passed 1 number each time and being called multiple times, so you don't need to access any arrays.
Vivek Jadon
@vjadon
May 17 2016 07:13
it doesnt work this way too

var count = 0;

function cc(card) {
// Only change code below this line
if(card==10 || card=='J' || card=='Q' || card=='K' || card=='A')
count--;
else if(card==2 || card==3 || card==4 || card==5 || card==6)
count++;

if(count>0)
return count + " Hold";
else
return count + " Bet";
// 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');

Keone Martin
@Athaman
May 17 2016 07:14
that code looks much closer @vjadon
Vivek Jadon
@vjadon
May 17 2016 07:14
ok
Markus Kiili
@Masd925
May 17 2016 07:14
@tadake
var arr1 = [1,2,3,4,5,6];
var arr2 = [2,4];
var filtered = arr1.filter(function (elem) {  // [1,3,5,6]
    return arr2.indexOf(elem)===-1;
});
Keone Martin
@Athaman
May 17 2016 07:15
but you have hold and bet backwards @vjadon
if count > 0 you should return count + " Bet";
Vivek Jadon
@vjadon
May 17 2016 07:16
such a silly mistake
thanx @Athaman
CamperBot
@camperbot
May 17 2016 07:16
vjadon sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
:cookie: 378 | @athaman |http://www.freecodecamp.com/athaman
Keone Martin
@Athaman
May 17 2016 07:16
@alexakuna you just need to set up a bunch of if/else (or a switch) statements that screen out the different golf scores
@vjadon happens to the best of us ;)
@alexakuna start with if(strokes == 1){ // make your function return "Hole-in-one!"}
Alexandr
@alexakuna
May 17 2016 07:18
ок
Keone Martin
@Athaman
May 17 2016 07:19
then if(strokes -par <-2){//make your function return "Eagle"} and work your way up
Kyle W Pilkinton
@tadake
May 17 2016 07:21
im working on the diff two arrays challenge and i used that function and im still not getting the correct output. is there any error in this updated code @Masd925
function diffArray(arr1, arr2) {
  var newarr = [];
  var filter = [];
  var filtered = [];
  // Same, same; but different.

  for(var i = 0 ; i < arr1.length; i++){
    for(var j = 0; j < arr2.length; j++){

      if(arr1[i] == arr2[j]){

        filter[i] = arr1[i];

      }
    }
  }

  var data = arr1.concat(arr2);

   filtered = arr1.filter(function (elem) {  
    return arr2.indexOf(elem) === -1;
});


  return filtered;        

}


diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
Keone Martin
@Athaman
May 17 2016 07:23
@tadake your whole first loops logic is a little wonky, at the moment you're running through all the elements in arr2 by using j then saving those that match to filter[i] but i doesn't increment til the end of the j loop, so you'll keep overwriting filter[0] for any matches between the first element of arr1 and any element in array 2
PcbcN
@PcbcN
May 17 2016 07:24
Hi everyone, I'm stuck in the "Return Largest Numbers in Arrays" exercise. I've written some code that I think should work (iterate array + iterate subarray + compare with empty results array + define result) but it keeps returning myArr [0,0,0,0]. My code is:
function largestOfFour(arr) {
  var myArr = [0,0,0,0];

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

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

        if (arr[i][j] > myArr[i]){myArr[i] = arr[i][j];

        }

      }

    }

 return myArr;   
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Markus Kiili
@Masd925
May 17 2016 07:25
@tadake You could use the filter function to first filter out elements of arr2 from arr1 and then elements of arr1 from arrr2. Concating those two result arrays should give the answer.
Keone Martin
@Athaman
May 17 2016 07:27
@PcbcN you are missing a g in arr.lenth --> should be arr.length;
which may prevent the loop from running at all since i don't think that would evaluate to true
Kyle W Pilkinton
@tadake
May 17 2016 07:29
thanks Markus @Masd925 im having trouble understanding the logic behind the call back function using .filter .
CamperBot
@camperbot
May 17 2016 07:29
tadake sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1513 | @masd925 |http://www.freecodecamp.com/masd925
PcbcN
@PcbcN
May 17 2016 07:29
@Athaman Thanks a lot!
CamperBot
@camperbot
May 17 2016 07:29
pcbcn sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
:cookie: 379 | @athaman |http://www.freecodecamp.com/athaman
Keone Martin
@Athaman
May 17 2016 07:30
no problem :)
Markus Kiili
@Masd925
May 17 2016 07:30
@tadake The callback tells filter how to filter one arbitrary array element elem. If the return value from callback is true, the element is kept. The filter method iterates array elements automatically under the hood and passes each element to the callback you provide.
cnj1987
@cnj1987
May 17 2016 07:32
Can someone tell me if I've done this wrong?
Manipulate Arrays With pop
I just typed in the array and passed... :D
Keone Martin
@Athaman
May 17 2016 07:33
sure, we can look over some code
cnj1987
@cnj1987
May 17 2016 07:33
code var removedFromMyArray = ["cat", 2];
Kyle W Pilkinton
@tadake
May 17 2016 07:34
is this sorta what i should be shooting for @Masd925 ??
 filter = arr2.filter(function(arr1){

    return arr1 !== arr2;

  });
cnj1987
@cnj1987
May 17 2016 07:34
But the instructions were: Use the .pop() function to remove the last item from myArray, assigning the "popped off" value to removedFromMyArray.
Keone Martin
@Athaman
May 17 2016 07:34
riiight, yeah, no that's not what you're looking to do there @cnj1987
cnj1987
@cnj1987
May 17 2016 07:34
I thought so, which is why I came back to it, lol
Keone Martin
@Athaman
May 17 2016 07:35
so you've changed the code above the do not change the code above this line right?
cnj1987
@cnj1987
May 17 2016 07:35
Yeah
Keone Martin
@Athaman
May 17 2016 07:35
set it back to the default because you'll need the original for the proper solution to work
cnj1987
@cnj1987
May 17 2016 07:35
var removedFromMyArray = ["cat", 2].pop(); == When I use this, I only get 2 in the array; not "cat".
Markus Kiili
@Masd925
May 17 2016 07:35
@tadake The parameter of filter callback is the array element being iterated. elem is a good name for the parameter.
cnj1987
@cnj1987
May 17 2016 07:35
Done
Keone Martin
@Athaman
May 17 2016 07:36
ok, so if you .pop() myArray without changing it you should get back [cat, 2]
["cat", 2]*
Markus Kiili
@Masd925
May 17 2016 07:36
@tadake This was the way to filter array elements from another array:
var filtered = arr1.filter(function (elem) {  // [1,3,5,6]
    return arr2.indexOf(elem)===-1;
});
cnj1987
@cnj1987
May 17 2016 07:36
AH!
var removedFromMyArray = myArray.pop();
??
Keone Martin
@Athaman
May 17 2016 07:36
so if you have removedFromMyArray = myArray.pop(); you will get exactly the same result as you have manually done
yeah that's the one
cnj1987
@cnj1987
May 17 2016 07:36
There we go :D
So it takes an array as a whole with pop()?
Keone Martin
@Athaman
May 17 2016 07:37
and what that does is what you did manually, it takes the last element of an array, in this case ["cat", 2] out of the array
and saves it if you have a var variable = on the left
cnj1987
@cnj1987
May 17 2016 07:37
Awesome :)
Keone Martin
@Athaman
May 17 2016 07:37
otherwise it just deletes it permanently
so if you say
myArray.pop() // this will just delete the last element, never to be seen again
cnj1987
@cnj1987
May 17 2016 07:38
That made the next one work perfectly as well (myArray.shift(); )
Keone Martin
@Athaman
May 17 2016 07:38
yup
cnj1987
@cnj1987
May 17 2016 07:38
Thanks @Athaman
CamperBot
@camperbot
May 17 2016 07:38
cnj1987 sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
:cookie: 380 | @athaman |http://www.freecodecamp.com/athaman
Keone Martin
@Athaman
May 17 2016 07:38
so they're basically the same thing but shift() is the front of the array and pop() is the back
similarly you can use unshift(something) to put something at the front of and array and push(something) to put something on the back
no problem :)
cnj1987
@cnj1987
May 17 2016 07:39
I just got to use unshift :D
It was the syntax I seemed to be struglging with. I'm still suffering with cluelessness with JS
Keone Martin
@Athaman
May 17 2016 07:40
that's reasonable, feel free to come back here if you have any issues.
Kyle W Pilkinton
@tadake
May 17 2016 07:40
ahh it finnaly clicked @Masd925 !!! thank you !
CamperBot
@camperbot
May 17 2016 07:40
tadake sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: tadake already gave masd925 points
Keone Martin
@Athaman
May 17 2016 07:40
google also helps but sometimes the example is just as confusing
cnj1987
@cnj1987
May 17 2016 07:40
Yeah, I've found that a fair bit
Zurab Iashvili
@electronx
May 17 2016 07:40
does anyone else feel like punching the laptop?
cnj1987
@cnj1987
May 17 2016 07:40
Sometimes I end up on, say, Stackoverflow, and the solution is more complex
Keone Martin
@Athaman
May 17 2016 07:41
use it as your first resource, because you'll always need to check syntax things and google is quicker than people... but if it doesn't help then come here and someone can normally explain
cnj1987
@cnj1987
May 17 2016 07:41
Will do :)
Keone Martin
@Athaman
May 17 2016 07:41
stackoverflow is an art in and of itself, you need to learn how to ignore alllll the crazy stuff and just look for the line that looks like it will fit in your code ;)
cnj1987
@cnj1987
May 17 2016 07:41
Sounds like a plan :D
Keone Martin
@Athaman
May 17 2016 07:41
@electronx i like my laptop, it keeps me entertained.
but things do get frustrating sometimes. it's worth taking a break sometimes, when the coding isn't fun and just annoying then you end up spiralling down and just hating it.
Zurab Iashvili
@electronx
May 17 2016 07:42
@Athaman yes but some problems are so hard, its very tempting to put a hole on screen :D
Keone Martin
@Athaman
May 17 2016 07:43
probably ill advised though ;)
need any advice on a specific problem or just venting?
Dan Couper
@DanCouper
May 17 2016 07:48
@tadake
var arr1 = [1, 2, 3, 4]
var arr2 = [6, 7, 2, 4]
// so
arr1.filter(function(elem) { return arr2.indexOf(elem) === -1 })
// `filter` is going to give you back a new array that consistes of every value that the
// callback returns true for. The callback takes the current value of the array, and moves
// left -> right until it hits the end.
// first element of arr1 is 1
function(1) { return arr2.indexOf(1) === -1 } // true: 1 is not in arr2, it has an index of -1
// second element of arr1 is 2
function(2) { return arr2.indexOf(2) === -1 } // false: 2 is in arr2, it has an index of 2
// third element of arr1 is 3
function(3) { return arr2.indexOf(3) === -1 } // true: 3 is not in arr2, it has an index of -1
// fourth element of arr1 is 4
function(4) { return arr2.indexOf(4) === -1 } // false: 4 is not in arr2, it has an index of 3
// so returns:
[1,4]
cnj1987
@cnj1987
May 17 2016 07:48
I think I've got this right --
  1. Create a function called reusableFunction which prints "Hi World" to the dev console.
  2. Call the function.
function reusableFunction() {
  console.log("Hi World"); 
}
Keone Martin
@Athaman
May 17 2016 07:49
yup that looks right @cnj1987

but you need to call the function, so have you got the line

reusableFunction();

underneath it?

cnj1987
@cnj1987
May 17 2016 07:51
I didn't have to when I entered it -- but yeah, I would've put it if I'd not clicked next :D
(I have an unusual ability to accidentally break everything)
Keone Martin
@Athaman
May 17 2016 07:51
haha that's a little strange, but they call it in their example so maybe that does it
you know how to call functions though? cos that's important moving forward
cnj1987
@cnj1987
May 17 2016 07:52
Just write its name and the arguments involved if required, right?
Keone Martin
@Athaman
May 17 2016 07:52
pretty much yeah
and you get that conceptually that just calls the chunk of code that you've written already
cnj1987
@cnj1987
May 17 2016 07:52

e.g.,

function functionThing(a * b);
functionThing(2, 10);

??

with {}, whoops
Keone Martin
@Athaman
May 17 2016 07:53
yeah, although you shouldn't call your function functionThing
cnj1987
@cnj1987
May 17 2016 07:53
Not very descriptive.. :D
can someone help me with global variables?
Darth Skywalker
@adityaparab
May 17 2016 07:57
@imnotlammy : Whats the problem? You had forgot to include jQuery in your pen :)
Lemmy
@imnotlammy
May 17 2016 07:57
@adityaparab I can't save the values from JSON to global var

```$(document).ready(function() {

//LOCATION
var city;
var country;

$.getJSON('http://ipinfo.io', function(data) {
city = data.city;
country = data.country;
console.log(country); //THIS DOES NOT RETURN UNDEFINED
})

console.log(country); //RETURNS UNDEFINED

});

Darth Skywalker
@adityaparab
May 17 2016 07:58
your data is not a global variable.
Lemmy
@imnotlammy
May 17 2016 07:58
is there a way to save the value outside the .getJSON function?
Coy Sanders
@coymeetsworld
May 17 2016 07:59
yes @imnotlammy, but have to be careful doing that
since getJSON is asynchronous call, that variable may not be populated before running other parts of your code, and if you need that variable elsewhere it may not be guaranteed to come
thats why your 2nd console.log function returns undefined, although it won't always do that necessarily
Darth Skywalker
@adityaparab
May 17 2016 08:01

@imnotlammy : Yes. That is a common mistake people make while learning async programming.

Your $.getJSON is an asynchronous call. That means, when you make $.getJSON call, it will make api call. It won't suspend until the API responds. It will, instead continue with next statements.

So by the time API responds, your console.log(country) will be executed. And it is undefined'. You set value ofcountry` AFTER API responds. :)

Lemmy
@imnotlammy
May 17 2016 08:01
is it better to nest everything inside the getJSON then?
Coy Sanders
@coymeetsworld
May 17 2016 08:01
for things you need to reply on data from an API call, yes
Darth Skywalker
@adityaparab
May 17 2016 08:02

@imnotlammy

is it better to nest everything inside the getJSON then?

It is a correct way, but not better. You should learn about a design pattern called Promise.

Lemmy
@imnotlammy
May 17 2016 08:04
hmm
this is for the local weather challenge
anyways
thanks guys @coymeetsworld @adityaparab
CamperBot
@camperbot
May 17 2016 08:06
imnotlammy sends brownie points to @coymeetsworld and @adityaparab :sparkles: :thumbsup: :sparkles:
:cookie: 253 | @adityaparab |http://www.freecodecamp.com/adityaparab
:cookie: 877 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Coy Sanders
@coymeetsworld
May 17 2016 08:06
np @imnotlammy
does that work for you?