These are chat archives for FreeCodeCamp/HelpJavaScript

7th
May 2016
Greg Duncan
@GregatGit
May 07 2016 00:01
@aferrar not quite sure
Norvin Burrus
@ndburrus
May 07 2016 00:02
@prime02 use the contacts object (in your if statement)! also, review the complete if/esle if logic. lastly, why is it requested to return all (4) contacts object records?
Greg Duncan
@GregatGit
May 07 2016 00:03
@aferrar if you are unsure how to access a value or prop paste the object in https://repl.it/ and then just use console.log to display what you are after - I often cut and paste the challenges here when I'm having trouble
schmorrison
@schmorrison
May 07 2016 00:03
@GregatGit thanks
CamperBot
@camperbot
May 07 2016 00:03
schmorrison sends brownie points to @gregatgit :sparkles: :thumbsup: :sparkles:
:cookie: 447 | @gregatgit |http://www.freecodecamp.com/gregatgit
taliahm
@taliahm
May 07 2016 00:04
@GregatGit the property
Greg Duncan
@GregatGit
May 07 2016 00:08

@taliahm here is how to delete a prop

var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
delete person.age;   // or delete person["age"];

The delete keyword deletes both the value of the property and the property itself.
straight from w3schools

taliahm
@taliahm
May 07 2016 00:10
Okay understood. I'm deleting a property within an array and an object...
I think....
bleujai
@bleujai
May 07 2016 00:11
For the validate phone number challenge it doesn't seem like the 10 digits of 5 should be true as a proof test. Anythoughts?
telephoneCheck("5555555555") should return true.
Greg Duncan
@GregatGit
May 07 2016 00:12
@schmorrison because your loops are not inside each other they can both be var i - if you want to put a loop inside a loop use j and if needed k - but as general rule no more than 3 deep
Ronique Ricketts
@RoniqueRicketts
May 07 2016 00:14
Help profile lookup
CamperBot
@camperbot
May 07 2016 00:14

:point_right: challenge profile lookup [wiki]

Checkpoint: Profile Lookup

Instructions

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

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

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

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

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

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

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

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

Greg Duncan
@GregatGit
May 07 2016 00:14
@taliahm if you are deleting the tracks prop - whatever is inside it (which happens to be an array) will be deleted with it it
Wiktor
@Wkredz1
May 07 2016 00:15
How do I move divs around?
Scott Gibson
@sc00gle
May 07 2016 00:16
@help Record Collection
Greg Duncan
@GregatGit
May 07 2016 00:17
@taliahm Or do you mean you want to delete one of the values in the array of the property tracks?
taliahm
@taliahm
May 07 2016 00:18
@GregatGit No, it wants me to check if the property exists, and if it does, delete it.
so if no value is given, delete the property
Norvin Burrus
@ndburrus
May 07 2016 00:19
@Wkredz1 "Simple Program to Move a Div Element Using JavaScript" {ref: http://www.ictforu.com/index.php/web-development/javascripts/70-javascript-movingdiv}
01
<html>
02
<head>
03
    <title>Arrow key movements</title>
04
    <script type="text/javascript">
05
        window.onload = function () {
06
            var moveDiv = document.getElementById("movingDiv");
07
            window.onkeydown = function(e) {
08

09
                e.preventDefault();
10
                if (!e)
11
                {
12
                    e = window.event;
13
                }
14
                var keyCode;
15
                // pixel wise speed variable
16
                var speed = 3;      
17
                if(e.which) {
18
                    keyCode = e.which;
19
                } else {
20
                    keyCode = e.keyCode;
21
                }
22

23
        //increment/decrement the top or left of the div based on the arrow key movements
24
                if(keyCode === 37) {
25
                    moveDiv.style.left = (parseInt(moveDiv.style.left, 10) - speed) + 'px';
26
                } else if (keyCode === 38) {
27
                    moveDiv.style.top = (parseInt(moveDiv.style.top, 10) - speed) + 'px';
28
                } else if (keyCode === 39) {
29
                    moveDiv.style.left = (parseInt(moveDiv.style.left, 10) + speed) + 'px';
30
                } else if (keyCode === 40) {
31
                    moveDiv.style.top = (parseInt(moveDiv.style.top, 10) + speed) + 'px';
32
                }
33
            };
34
        };
35
    </script>
36

37
    <!-- CSS fpr moving Div -->
38
    <style type="text/css">
39
        #movingDiv {
40
            width: 100px;
41
            height: 100px;
42
            position: absolute;
43
            background-color: #CCC;
44
        }
45
    </style>
46
</head>
47
<body>
48
<!-- This div element will move , it has CSS style element in the header -->
49
    <div id="movingDiv" style="top:0px;left:0px;">
50
    </div>
51
</body>
52

53
</html><br>
Greg Duncan
@GregatGit
May 07 2016 00:21
@taliahm ok - can you do that?
taliahm
@taliahm
May 07 2016 00:22
@GregatGit delete collection.id.prop
but that gives me an empty property (with no defined value) or an error saying "cannot define to null or undefined"
Greg Duncan
@GregatGit
May 07 2016 00:23
@taliahm collection[id].prop
taliahm
@taliahm
May 07 2016 00:25
@GregatGit delete collection[id].prop; also does not work
I really don't know why. I've also tried delete collection[id][prop];
Greg Duncan
@GregatGit
May 07 2016 00:27
@taliahm I'm just looking at my solution - one moment
taliahm
@taliahm
May 07 2016 00:27
@GregatGit No problem, I tried your solution on repl.it and it worked so maybe it's a bug
Greg Duncan
@GregatGit
May 07 2016 00:29
@taliahm Yeah - I see that my orginal solution now doesn't work - even tho it did before - I had delete collection[id][prop];
taliahm
@taliahm
May 07 2016 00:30
@GregatGit very strange! Okay I'll report it and move on. Thanks!
CamperBot
@camperbot
May 07 2016 00:30
taliahm sends brownie points to @gregatgit :sparkles: :thumbsup: :sparkles:
:cookie: 448 | @gregatgit |http://www.freecodecamp.com/gregatgit
Ronique Ricketts
@RoniqueRicketts
May 07 2016 00:31
I need help with my lookup code
jdownhower
@jdownhower
May 07 2016 00:32
@dhrubo55 what about map functions? it lets you transform each array element using a function.
Scott Gibson
@sc00gle
May 07 2016 00:35
Thanks @GregatGit @taliahm - I've just stumbled across the same delete collection problem.
CamperBot
@camperbot
May 07 2016 00:35
sc00gle sends brownie points to @gregatgit and @taliahm :sparkles: :thumbsup: :sparkles:
:cookie: 120 | @taliahm |http://www.freecodecamp.com/taliahm
:cookie: 449 | @gregatgit |http://www.freecodecamp.com/gregatgit
Renan
@renanav
May 07 2016 00:39

Having some issues here:

var count = 0;

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

  switch(card){
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
     count = count + 1;
      return count + " Bet";
      break;
    case 7:
    case 8:
    case 9:
      count = count + 0;
      return count + "Hold";
      break;


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

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

The first test passes, the second doesn't, I didn't bother writing the rest because obviously I'm doing something wrong

Tyler
@tylergross
May 07 2016 00:41
@renanav look at your second return its missing a space
Kleineken
@Kleineken
May 07 2016 00:41
hello everyone, I just had a quick question. Am I to understand that javascript has no built in boolean checks for alphanumeric characters? Similar to Pythons isdigit or isalpha? Do I have to explicitly create a test array or against a character map whenever I want to test for these types of input?
Tyler
@tylergross
May 07 2016 00:41
@renanav also you are returning after the switch... you need to be returning where it says "change me"
Aaron
@amfische
May 07 2016 00:42
Finally got my code working for Seek and Destroy challenge. I found it pretty difficult, how did you guys fair with it?
Tyler
@tylergross
May 07 2016 00:42
@Kleineken i beleve there is an alpha numeric one second
@Kleineken not sure but you could always use [a-z][0-9]
Renan
@renanav
May 07 2016 00:43
@tylergross That’s a second problem I’m having. console.log doesn’t work here, and return is also not good. what other options do I have?
Tyler
@tylergross
May 07 2016 00:43
@keenfire alert()
or
wait til the end of the switch and use your count with an if statment
Kleineken
@Kleineken
May 07 2016 00:44
@tylergross well that is not so bad i guess, thats a pretty short expression I will try it out thank you
CamperBot
@camperbot
May 07 2016 00:44
kleineken sends brownie points to @tylergross :sparkles: :thumbsup: :sparkles:
:cookie: 366 | @tylergross |http://www.freecodecamp.com/tylergross
Tyler
@tylergross
May 07 2016 00:45
@renanav I think you're asking what to do within the switch?
Renan
@renanav
May 07 2016 00:45
yes
how to output the result for each case
Tyler
@tylergross
May 07 2016 00:46
try setting a variable IE var output; and then instead of return.... set output = count + " HOLD"...... and then at the bottom return output;
something like that I think is what you're asking, sorry hard to explain
Renan
@renanav
May 07 2016 00:47
That’s ok, I understood. I’ll go try it out. thanks man @tylergross
CamperBot
@camperbot
May 07 2016 00:47
renanav sends brownie points to @tylergross :sparkles: :thumbsup: :sparkles:
:cookie: 367 | @tylergross |http://www.freecodecamp.com/tylergross
Tyler
@tylergross
May 07 2016 00:48
@Kleineken right i'm used to PHP but they all have their quirks.... I think the correct one was [a-z0-9] or [a-zA-Z0-9] figuratively
/w also works for alphanumeric
\w **
Norvin Burrus
@ndburrus
May 07 2016 00:49
@renanav to output the result it may be useful to format/construct a string with the desired elements! hint: as part of the string, a var/iable can be included to account for the differing scenario/s (decision). :)
Kleineken
@Kleineken
May 07 2016 00:49
javascript doesnt seem to be able to iterate a string however so Im assuming I have to convert to a list and then filter against [a-z0-9]?
Renan
@renanav
May 07 2016 00:50
@ndburrus Could you explain/
Tyler
@tylergross
May 07 2016 00:51
@Kleineken im not sure what you mean, it does check strings using a regex ..... what are you trying to do exactly?
Norvin Burrus
@ndburrus
May 07 2016 00:52
@renanav ...sure, in the code it alters the count var/iable based on criteria... this var/iable can be used in a string as part of the output....
Tyler
@tylergross
May 07 2016 00:52
are you testing if a string is alphanumeric only?
Norvin Burrus
@ndburrus
May 07 2016 00:53
@renanav does that help?
Renan
@renanav
May 07 2016 00:53
thisis what I’m doing. I’m concatenating it
I’m trying @tylergross solutionn
Norvin Burrus
@ndburrus
May 07 2016 00:53
@renanav hmmm... do you see the return statement in the code you posted? hint: it says change me... if you run the code it says exactly that - change me! it's telling us something... :) sometimes we need to carefully examine everything (instructions, code, examples, run result, etc.) to find some clue/s...
Renan
@renanav
May 07 2016 00:54
oohhhhhhhh
They really need to work on the instructions...
Kleineken
@Kleineken
May 07 2016 00:55
@tylergross nothing specific, I guess Im just trying to understand it better. Im probably not phrasing my question properly. I'll do some more experimentation
@tylergross yes my orignal question was finding out if I could check an input easily for an alphanumeric. I didnt see an obvious way to do it based off of what i had learned so far
Tyler
@tylergross
May 07 2016 00:57
@Kleineken https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp that page has a lot of good information and several examples at the bottom worth checking out
Will Hieronymus
@whieronymus
May 07 2016 00:57
if a count variable is outside of a function, can you increment it inside of the function?
Norvin Burrus
@ndburrus
May 07 2016 00:57
@Kleineken have you tried regex (regluar expression/s)?
Kleineken
@Kleineken
May 07 2016 00:58
@tylergross very cool. Reading material is definitely much appreciated.
Dominic Lobban
@alkapwn3d
May 07 2016 00:58

var myVar = 87;

// Only change code below this line
myVar = 87++;

i dont know what to do
Moisés Man
@moigithub
May 07 2016 00:58
@whieronymus yes...
Kleineken
@Kleineken
May 07 2016 00:58
@ndburrus Not so much with booleans, I used it to isolate specific strings from a document or a long string
Dominic Lobban
@alkapwn3d
May 07 2016 00:58

var myVar = 87;

// Only change code below this line
myVar = myVar + 1;

Blake Harris
@bharris62
May 07 2016 00:59
If I have learned anything, its that the weather app takes forever to get right!
Norvin Burrus
@ndburrus
May 07 2016 00:59
@alkapwn3d review the example carefully. the lesson point is that the ++ operator increments a value by 1! :)
Will Hieronymus
@whieronymus
May 07 2016 00:59

var count = 0;

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

if (count > 0) {
return count + ' Bet';
}

return count + ' Hold';
// Only change code above this line
}

Coy Sanders
@coymeetsworld
May 07 2016 01:00
@alkapwn3d myVar = myVar +1 is the same as myVar += 1 is the same as myVar++
Will Hieronymus
@whieronymus
May 07 2016 01:00
I'm struggling with 'Counting Cards' in the first JavaScript section
Dominic Lobban
@alkapwn3d
May 07 2016 01:00

if i++ is the same as i = i +1 ;

then myVar = myVar +1 ; is myVar++; right?

so if var myVar = 87;
then wy isnt the answer 87++;

Will Hieronymus
@whieronymus
May 07 2016 01:01
It doesn't look like my count is changing
Coy Sanders
@coymeetsworld
May 07 2016 01:01
you can't use that operator on a literal number thats why @alkapwn3d
has to by myVar++
Dominic Lobban
@alkapwn3d
May 07 2016 01:02
k got it. i hate javascript
HATE
Coy Sanders
@coymeetsworld
May 07 2016 01:02
@whieronymus try refreshing browser?
Tyler
@tylergross
May 07 2016 01:02
@whieronymus can you paste your code again in the code parameters?
help format
Coy Sanders
@coymeetsworld
May 07 2016 01:02
code looks ok to me
CamperBot
@camperbot
May 07 2016 01:02

: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

Norvin Burrus
@ndburrus
May 07 2016 01:02
@Kleineken test() - "Return Value
Type Description
Boolean Returns true if it finds a match, otherwise it returns false"
Tyler
@tylergross
May 07 2016 01:02
but everything looks fine
@whieronymus looks like you forgot a break;
Will Hieronymus
@whieronymus
May 07 2016 01:03
var count = 0;

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

  if (count > 0) {
    return count + ' Bet';
  }

  return count + ' Hold';
  // Only change code above this line
}
Coy Sanders
@coymeetsworld
May 07 2016 01:04
try refreshing your browser @whieronymus
Tyler
@tylergross
May 07 2016 01:04
@whieronymus check after case 'A' youre missing a break
Coy Sanders
@coymeetsworld
May 07 2016 01:04
im not seeing any issues with that code
doesn't need a break @tylergross
Tyler
@tylergross
May 07 2016 01:04
oh
Coy Sanders
@coymeetsworld
May 07 2016 01:04
since its at the end
Tyler
@tylergross
May 07 2016 01:04
gtk
Coy Sanders
@coymeetsworld
May 07 2016 01:04
ya
saves you a line of code :)
Tyler
@tylergross
May 07 2016 01:04
haha
Will Hieronymus
@whieronymus
May 07 2016 01:04
Yea, I tried refreshing and I didn't think I needed a break but I tried anyways, still not working X(
Coy Sanders
@coymeetsworld
May 07 2016 01:05
hmm let me see if it works for me
Norvin Burrus
@ndburrus
May 07 2016 01:05
@whieronymus case 1?, also, check your formula for the count/s value/s... :) lastly, review the if statement & final return statement logic....
Will Hieronymus
@whieronymus
May 07 2016 01:05
The only test that is passing is Card Sequence 7,8,9
Coy Sanders
@coymeetsworld
May 07 2016 01:06
wheres your count variable?
Will Hieronymus
@whieronymus
May 07 2016 01:06
outside the function at the top
Greg Duncan
@GregatGit
May 07 2016 01:07
@whieronymus if (count < 1)
Coy Sanders
@coymeetsworld
May 07 2016 01:07
oh lol you have it backwards
you add count when number is small, subtract when its high
Will Hieronymus
@whieronymus
May 07 2016 01:08
Ahhhhh
I knew it was going to be something stupid
Kleineken
@Kleineken
May 07 2016 01:08
@ndburrus Awesome thank you!
CamperBot
@camperbot
May 07 2016 01:08
kleineken sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:cookie: 320 | @ndburrus |http://www.freecodecamp.com/ndburrus
Norvin Burrus
@ndburrus
May 07 2016 01:10
@Kleineken You're welcome !! You're on fire now.... :fire:
Will Hieronymus
@whieronymus
May 07 2016 01:10
well thanks guys, sorry lol
Kleineken
@Kleineken
May 07 2016 01:11
haha! Yeah, better look out google....
Norvin Burrus
@ndburrus
May 07 2016 01:11
@alkapwn3d did you get it?
Dominic Lobban
@alkapwn3d
May 07 2016 01:12
yeh i got it
Norvin Burrus
@ndburrus
May 07 2016 01:12
@alkapwn3d ok... :+1:
Aryan
@aryandua
May 07 2016 01:36
is it possible to use switch case w/ strings??
jdownhower
@jdownhower
May 07 2016 01:37
@aryandua Yes
Aryan
@aryandua
May 07 2016 01:38
ok got it
i was stuck
simple mistake...
i wrote switch(answer)
Norvin Burrus
@ndburrus
May 07 2016 01:39
@aryandua yes... "In JavaScript, you can even mix in definitions of strings into these case statements as well." {ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch }
Aryan
@aryandua
May 07 2016 01:39
instead of switch (num)
thx @ndburrus
CamperBot
@camperbot
May 07 2016 01:39
aryandua sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:cookie: 322 | @ndburrus |http://www.freecodecamp.com/ndburrus
Norvin Burrus
@ndburrus
May 07 2016 01:42
@aryandua You're welcome! Ya, have to watch the var/iable name accuracy... :+1: details, details...
Wiktor
@Wkredz1
May 07 2016 01:58
why doesent this move my div2
hello??
Pavel Sokolov
@nevaljawko
May 07 2016 02:08
@Wkredz1 hi, what the problem?
schmorrison
@schmorrison
May 07 2016 02:09
@Wkredz1 try giving the "div.2" class a name like "newDivClass" then apply that to the div tag
Pavel Sokolov
@nevaljawko
May 07 2016 02:10
As I remember, class can't be start from a letter
@schmorrison +
schmorrison
@schmorrison
May 07 2016 02:12
@nevaljawko right start them with # i believe
@nevaljawko or maybe a .
Pavel Sokolov
@nevaljawko
May 07 2016 02:17
offcorse, first of all, we have to point dot symbol )
Norvin Burrus
@ndburrus
May 07 2016 02:18

@Wkredz1 this may be useful: "CSS Layout - The position Property" { http://www.w3schools.com/css/css_positioning.asp } "The position Property
The position property specifies the type of positioning method used for an element.

There are four different position values:

static
relative
fixed
absolute" Example: "div.relative {
position: relative;
left: 30px;
border: 3px solid #73AD21;
}"

Norvin Burrus
@ndburrus
May 07 2016 02:26
@Wkredz1 is the css positioning challenge resolved?
Pavel Sokolov
@nevaljawko
May 07 2016 02:36
omg, I meaned number, not letter... better I go to bed
ereinertsen
@ereinertsen
May 07 2016 02:37
Can someone help me with this Javascript code?
function convertToF(celsius) {
// Only change code below this line
var farenheit= celsius *=9/5 +=32;
It's returning a syntax error
Pavel Sokolov
@nevaljawko
May 07 2016 02:38
too many equals I think
In one string should be only one equal
just try to remove the last two
Norvin Burrus
@ndburrus
May 07 2016 02:43
@ereinertsen check your equation carefully... :) it is unusual to have three (3) equal/assignment sign/s ....
Islam Ibakaev
@dagman
May 07 2016 03:00
@nevaljawko var a = b = 'hello'
Enrique Sayago
@esayago
May 07 2016 03:17
Anybody awake?
Omid
@omidqayoumi
May 07 2016 03:18
yes
Enrique Sayago
@esayago
May 07 2016 03:18
thank god, I'm stuck on a simple problem here
its titled "Record Collection"
So I'm trying to select a value of an object inside an object and is just not working
var collection = {
2548: {
album: "Slippery When Wet",
artist: "Bon Jovi",
tracks: [
"Let It Rock",
"You Give Love a Bad Name"
]
}
}

I'm trying the following:

var col = colllection.2548.artist

and
var col = collection.2548[artist];
what am I doing wrong
orribu
@orribu
May 07 2016 03:23
Hello all! :D
Enrique Sayago
@esayago
May 07 2016 03:25
have you heard of "don't drink and drive"? well "don't drink and code"
d wilder
@alhazen1
May 07 2016 03:33
@orribu Hello!
@esayago Did you figure it out?
Omid
@omidqayoumi
May 07 2016 03:36
function truncateString(str, num) {
  // -3 to add 3 dots
  var truncated = "init";
  if (str.length >= num + 3 && num >= 3)  { 
    truncated = str.slice(0, num - 3) + "..."; 
    return truncated;
   }
  else if (num < 3) {
    truncated = str.slice(0, num - 3 + 1) + "...";
    return truncated;
  }
  else {
    return str;
  }
}
truncateString("Absolutely Longer", 2);
for that else if, is there a way to make it so it'll accept things lower than 3 and
is there a way to make it so it won't slice a negative number or else
I'd have to repeat that for another lower number just to pass the problem and it feels like cheating
Omid
@omidqayoumi
May 07 2016 03:42
figured it out .. just had to make it slice at num lol
Enrique Sayago
@esayago
May 07 2016 03:45
@alhazen1 still working on it
d wilder
@alhazen1
May 07 2016 03:54

@esayago I think the number thing is tripping you up. It gave me problems.
http://stackoverflow.com/questions/16908476/javascript-object-property-name-as-number

Dot notation only works with property names that are valid identifiers. An identifier must start with a letter, $, _ or unicode escape sequence. For all other property names, you must use bracket notation.

Islam Ibakaev
@dagman
May 07 2016 03:57
trying to do blinking eyes. Do they look good? http://codepen.io/dagman/full/QNYywJ/
d wilder
@alhazen1
May 07 2016 03:59
@esayago
console.log(collection[2548].artist); //<this works
console.log(collection["2548"].artist); //<this works too
//console.log(collection.2548.artist); //<this will not work
Justin Woodward
@jwoo92
May 07 2016 04:04
would anyone be able to assist me the basic alg script challenge "factorize a number"? i know i need to be able to multiply the given number by all numbers less than and equal to, but i am having trouble figuring out how to write that in javascript.
Coy Sanders
@coymeetsworld
May 07 2016 04:07
you can use recursion or a for loop @jwoo92
Robert
@Brayn7
May 07 2016 04:09
need hint where art thou
help where art thou
CamperBot
@camperbot
May 07 2016 04:09

: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

Justin Woodward
@jwoo92
May 07 2016 04:11
here is what i have so far
function factorialize(num) {
  for(var i=0; i <= num; i++ ) {

  }

  return num;
}

factorialize(5);
d wilder
@alhazen1
May 07 2016 04:12
@jwoo92 That is good start but you aren't returning num but the result of factorial
Justin Woodward
@jwoo92
May 07 2016 04:13
@coymeetsworld with all the struggle i have been pushing through, it is starting to slowly make more sense with each day. thanks again for all your help, you have helped me a lot of challeneges.
CamperBot
@camperbot
May 07 2016 04:13
jwoo92 sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:cookie: 760 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Justin Woodward
@jwoo92
May 07 2016 04:14
@alhazen1 the return num; was actually pre-existing when i first began the challenge.
now i am trying to mentally solve how i use my for loop with num to create the solution
Coy Sanders
@coymeetsworld
May 07 2016 04:15
yeah np @jwoo92
function is a good start, will need a tweak a bit but what you'll need to do is create a new variable to keep track of the factorialized number
Robert
@Brayn7
May 07 2016 04:16
@jwoo92 you need to start at 1 and then times by 2 then that times by three and so on then make num = to the ending number
Justin Woodward
@jwoo92
May 07 2016 04:21
@coymeetsworld @Brayn7 okay. still not clicking with me yet, but i am thinking on what you guys said at the moment.
Coy Sanders
@coymeetsworld
May 07 2016 04:22
do you know how factorials work @jwoo92 ?
5! = 5*4*3*2*1
Justin Woodward
@jwoo92
May 07 2016 04:22
@coymeetsworld i do not, that looks brand new to me
Robert
@Brayn7
May 07 2016 04:22
@jwoo92 you will get it just keep thinking about it and break it down into steps
Coy Sanders
@coymeetsworld
May 07 2016 04:23
oh ok its just a product of 1 to the number
Robert
@Brayn7
May 07 2016 04:23
@jwoo92 you should def read about what a factorial is
Coy Sanders
@coymeetsworld
May 07 2016 04:23
so 2! would be 2 * 1
3! would be 3*2*1
4! would be 4*3*2*1
Justin Woodward
@jwoo92
May 07 2016 04:24
@coymeetsworld that makes a lot of sense, give me a moment with my challenge :)
Coy Sanders
@coymeetsworld
May 07 2016 04:24
ok
Justin Woodward
@jwoo92
May 07 2016 04:28
here is what i have so far. what i am trying to figure out now is how i relate my for loop
function factorialize(num) {
  var n = num;
  for(var i=0; i <= n; i++ ) {
    n!
  }

  return num;
}

factorialize(5);
Coy Sanders
@coymeetsworld
May 07 2016 04:28
hmm want to be careful here
you don't want to modify the same value you're reading in your for loop
Robert
@Brayn7
May 07 2016 04:29
how in the world is this false { "a": 1, "b": 2 } === { "a": 1, "b": 2 }
Justin Woodward
@jwoo92
May 07 2016 04:30
@coymeetsworld okay, i changed <= n back to num
Robert
@Brayn7
May 07 2016 04:30
@jwoo92 you want your for loop to count to the arg amount
Coy Sanders
@coymeetsworld
May 07 2016 04:30
you'll also want to start at 1, not 0
i would read up on what a factorial is before going any further so you understand what's going on too
Justin Woodward
@jwoo92
May 07 2016 04:31
@coymeetsworld okay, ill do that.
Robert
@Brayn7
May 07 2016 04:31
@jwoo92 var n = num is fine but the count down in your loop
@jwoo92 and then stop at 1
Kurt Johnson
@pompan129
May 07 2016 04:32
@Brayn7 Two objects are strictly equal if they refer to the same Object.
Robert
@Brayn7
May 07 2016 04:33
@pompan129 oh... makes a little more sense now then. thanks dude.
CamperBot
@camperbot
May 07 2016 04:33
brayn7 sends brownie points to @pompan129 :sparkles: :thumbsup: :sparkles:
:cookie: 468 | @pompan129 |http://www.freecodecamp.com/pompan129
@Brayn7
Robert
@Brayn7
May 07 2016 04:36
@pompan129 its also false with only ==
@pompan129 but like you said has to be same object
Kurt Johnson
@pompan129
May 07 2016 04:38
@Brayn7 . yes. you can use a library like Lodash to compare though I think
Robert
@Brayn7
May 07 2016 04:38
@pompan129 hmm ill check that out possibly, mainly just struggling with the stupid where art thou challenge
Justin Woodward
@jwoo92
May 07 2016 04:41
this is what i have. i believe i am not running through the whole for loop.
function factorialize(num) {
  var n = num;
  for(var i=1; i <= num; i++ ) {
    n = n * i;
  }

  return n;
}

factorialize(5);
Kurt Johnson
@pompan129
May 07 2016 04:45
@jwoo92 n starts at num. it should start at 1. you don't want 5 * 1 in 1st loop
Coy Sanders
@coymeetsworld
May 07 2016 04:47
yeah change what you initialize to n and you should be good
just need to account for 0! though too, but don't do it in the for loop
Justin Woodward
@jwoo92
May 07 2016 04:48
@coymeetsworld i saw that, i got everything correct except 0!
this did it thanks guys @coymeetsworld @pompan129 @Brayn7
function factorialize(num) {
  var n = 1;
  for(var i=1; i <= num; i++ ) {
    n = n * i;
  }

  return n;
}

factorialize(5);
CamperBot
@camperbot
May 07 2016 04:52
:warning: jwoo92 already gave coymeetsworld points
:cookie: 297 | @brayn7 |http://www.freecodecamp.com/brayn7
jwoo92 sends brownie points to @coymeetsworld and @pompan129 and @brayn7 :sparkles: :thumbsup: :sparkles:
:cookie: 469 | @pompan129 |http://www.freecodecamp.com/pompan129
Coy Sanders
@coymeetsworld
May 07 2016 04:53
nice job
Kurt Johnson
@pompan129
May 07 2016 04:53
@jwoo92 :)
Robert
@Brayn7
May 07 2016 04:53
@jwoo92 :clap:
Justin Woodward
@jwoo92
May 07 2016 04:54
it makes sense as well looking at it and i cleared it and wrote it out again thinking about exactly why and what i am doing applies to what i need.
celoos
@celoos
May 07 2016 04:59
mm Search and Destroy was fairly challenging. o.O Still not sure I did it the most efficient way. lol
Justin Woodward
@jwoo92
May 07 2016 05:00
did you guys have the same struggles or is it intentially designed to throw you right into the pit?
Renan
@renanav
May 07 2016 05:00

Well, it's getting late and I'm tired and blocked:


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

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

  lookup[val] = result;
  // Only change code above this line
  return result;
}

// Change this value to test
phoneticLookup("alpha");

Why doesn't it work?

marcsnts
@marcsnts
May 07 2016 05:04
result = lookup[val]
just needs to be flipped to that
Renan
@renanav
May 07 2016 05:05
@marcsnts I can swear I did! anyway, thanks man
CamperBot
@camperbot
May 07 2016 05:05
renanav sends brownie points to @marcsnts :sparkles: :thumbsup: :sparkles:
:cookie: 275 | @marcsnts |http://www.freecodecamp.com/marcsnts
Omid
@omidqayoumi
May 07 2016 05:07
this algorithm challenge has me stumped
marcsnts
@marcsnts
May 07 2016 05:08
@omidqayoumi which
Omid
@omidqayoumi
May 07 2016 05:09
chunky monkey @marcsnts
ohhhh
i could set up a loop to push an amount of size
every time
tashametro
@tashametro
May 07 2016 05:15

| Can you guys help me with this challenge below? |

// Declare your variable here
var MyGlobal =10;

function fun1() {
// Assign 5 to oopsGlobal Here
oopsGlobal = 5;

}

// Only change code above this line
function fun2() {
var output = "";
if (typeof myGlobal != "undefined") {
output += "myGlobal: " + myGlobal;
}
if (typeof oopsGlobal != "undefined") {
output += " oopsGlobal: " + oopsGlobal;
}
console.log(output);
}

Omid
@omidqayoumi
May 07 2016 05:16
help format @tashametro
CamperBot
@camperbot
May 07 2016 05:16
no wiki entry for: format @tashametro
Omid
@omidqayoumi
May 07 2016 05:16
help format
CamperBot
@camperbot
May 07 2016 05:16

: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

Justin Woodward
@jwoo92
May 07 2016 05:17
@tashametro
// Declare your variable here
var MyGlobal =10;
function fun1() {
// Assign 5 to oopsGlobal Here
oopsGlobal = 5;
}
// Only change code above this line
function fun2() {
var output = "";
if (typeof myGlobal != "undefined") {
output += "myGlobal: " + myGlobal;
}
if (typeof oopsGlobal != "undefined") {
output += " oopsGlobal: " + oopsGlobal;
}
console.log(output);
}
what is it asking to do?
tashametro
@tashametro
May 07 2016 05:19
@jwoo92 oh I found out I type the variable wrong thanks tho .. it was the global variable challenge
CamperBot
@camperbot
May 07 2016 05:19
tashametro sends brownie points to @jwoo92 :sparkles: :thumbsup: :sparkles:
:cookie: 284 | @jwoo92 |http://www.freecodecamp.com/jwoo92
Robert
@Brayn7
May 07 2016 05:22
dang finally got through where art thou that one was so hard for me
just throwing that out here
:)
Omid
@omidqayoumi
May 07 2016 05:23
@Brayn7 congrats ! :)
I'm still trying to figure out chunky monkey
Robert
@Brayn7
May 07 2016 05:24
@omidqayoumi thanks yo
CamperBot
@camperbot
May 07 2016 05:24
brayn7 sends brownie points to @omidqayoumi :sparkles: :thumbsup: :sparkles:
:cookie: 286 | @omidqayoumi |http://www.freecodecamp.com/omidqayoumi
Robert
@Brayn7
May 07 2016 05:24
@omidqayoumi want advice?
Omid
@omidqayoumi
May 07 2016 05:24
@Brayn7
function chunkArrayInGroups(arr, size) {
  var chunk = [];
  for (i=0; i < arr.length / size; i++) {
  chunk[i] = arr.slice(i, size);
  }
  return chunk;
}
chunkArrayInGroups(["a", "b", "c", "d"], 2);
don't think I'm going about it the right way
tried with a push and couldn't figure it out either
Robert
@Brayn7
May 07 2016 05:25
@omidqayoumi ok give me a sec to check your code out
Omid
@omidqayoumi
May 07 2016 05:26
if I could just make it slice from the right placement every time
I think it'd work
Robert
@Brayn7
May 07 2016 05:27
@omidqayoumi man you are really close
Omid
@omidqayoumi
May 07 2016 05:27
hmmm
oh
celoos
@celoos
May 07 2016 05:28
ah I tried it that way too.
Omid
@omidqayoumi
May 07 2016 05:28
got it :)
I didn't even think I was close
thanks @Brayn7
CamperBot
@camperbot
May 07 2016 05:28
omidqayoumi sends brownie points to @brayn7 :sparkles: :thumbsup: :sparkles:
:cookie: 299 | @brayn7 |http://www.freecodecamp.com/brayn7
Omid
@omidqayoumi
May 07 2016 05:28
function chunkArrayInGroups(arr, size) {
  var chunk = [];
  var  counter = 0;
  for (i=0; i < arr.length / size; i++) {
  chunk[i] = arr.slice(counter, counter + size);
    counter += size;
  }
  return chunk;
}
chunkArrayInGroups(["a", "b", "c", "d"], 2);
Robert
@Brayn7
May 07 2016 05:29
@omidqayoumi really?! awesome!!!!
Omid
@omidqayoumi
May 07 2016 05:30
dang I wanna get to those intermediate projects soon
Robert
@Brayn7
May 07 2016 05:31
@omidqayoumi you'll get there yo
Omid
@omidqayoumi
May 07 2016 05:31
most def, one day at a time
Robert
@Brayn7
May 07 2016 05:32
@omidqayoumi yeah coding makes me feel really dumb sometimes but its really rewarding after i finally find a solution to something :)
Omid
@omidqayoumi
May 07 2016 05:33
@Brayn7 I feel the same exact way man
and afterwards I'm like dam, why did it take me so long to finish a solution
celoos
@celoos
May 07 2016 05:33
careful with the solutions... or it won't be a challenge for people working behind you ;)
Omid
@omidqayoumi
May 07 2016 05:33
should've just stared at the screen longer instead of taking a break
ah my bad
Christian Todd
@chrstntdd
May 07 2016 05:33
Quick dumb question in the Escape Sequences in Strings section: I dont understand anything about how to code the sequence or what its asking for.
I dont even know how to ask the question
Omid
@omidqayoumi
May 07 2016 05:34
@chrstntdd basically make a string with what it's asking inside of that string
so if it wants you to put a tab then you can set it up with a '/t'
Christian Todd
@chrstntdd
May 07 2016 05:35
wrapped in quotes?
Robert
@Brayn7
May 07 2016 05:35
@chrstntdd yeah use chart
Omid
@omidqayoumi
May 07 2016 05:35
yep because it wants you to put it inside that variable @chrstntdd
and anything that's a string goes within quotes
Daniel
@profoundhub
May 07 2016 05:35
:clap:
Omid
@omidqayoumi
May 07 2016 05:36
i can only imagine how difficult the advanced algorithms are if I'm struggling with beginner ones lol
Christian Todd
@chrstntdd
May 07 2016 05:37
@omidqayoumi yeah really.
Daniel
@profoundhub
May 07 2016 05:37
same here, they are mind bending!
Justin Woodward
@jwoo92
May 07 2016 05:38
@omidqayoumi right there with you on that one lol
Omid
@omidqayoumi
May 07 2016 05:38
guess we're all in for a treat then lol
Justin Woodward
@jwoo92
May 07 2016 05:40
we will all get through together, as long as you do not give up or punch the computer screen out :)
Christian Todd
@chrstntdd
May 07 2016 05:41
okay, im still not getting this at all.
var myStr; "'\\ '\t\t' '\t\t' '\r\r' '\n\n'"
R SATYA VIJITH
@satyavijith
May 07 2016 05:41
can any one help to figure me out of 145th question
Christian Todd
@chrstntdd
May 07 2016 05:41
what am I even supposed to be gibing?
giving?
Justin Woodward
@jwoo92
May 07 2016 05:42
@chrstntdd challenge?
dontchaknow
@dontchaknow
May 07 2016 05:44
why is it when I use toString on "{}" it returns Object object?
Christian Todd
@chrstntdd
May 07 2016 05:45
Escape Sequences in Strings
the instructions are:
Instructions
Encode the following sequence, separated by spaces:
backslash tab tab carriage-return new-line and assign it to myStr
@jwoo92
elminsterrr
@elminsterrr
May 07 2016 05:50
Hi, Why here toUpperCase() doesn't work?
function titleCase(str) {
  var copied = str;
  //console.log(typeof(copied));
  //console.log(copied);
  var maleLitery = copied.toLowerCase();
 // console.log(maleLitery);
  var splitted = maleLitery.split(" ");
  //console.log(splitted);

var splittedA = "";
for (i = 0; i<splitted.length+4; i++) {

var a =    splitted.shift();
//console.log(a);

splittedA = a.split("");
console.log(splittedA);
var b = splittedA.splice(0,1);  //.toUpperCase(); !!!!!!!!!!!!!!!!!!!!!!!!!!!!!


console.log(b);
console.log(splittedA);    
}

}

titleCase("I'm a little tea pot");
Omid
@omidqayoumi
May 07 2016 05:51
@chrstntdd too many quotes
@chrstntdd look at the chart again, it only says to use a ' if it's a single quote or double quote
Christian Todd
@chrstntdd
May 07 2016 05:55
so more like var myStr; "\ \t \t \r \n"
@omidqayoumi ?
I feel like this is the most trivial thing and im missing the point completely.
Omid
@omidqayoumi
May 07 2016 05:56
@chrstntdd try that out and see what happens
celoos
@celoos
May 07 2016 05:56
your first one is incorrect in that string
a backslash also needs escaped
Omid
@omidqayoumi
May 07 2016 05:56
aww
he was gonna figure it out if you gave him a little bit more time
Justin Woodward
@jwoo92
May 07 2016 05:57
@chrstntdd it says to assign to var myStr so first thing to do is var myStr =
Christian Todd
@chrstntdd
May 07 2016 05:57
So then to escape the backslash I need 3 total backslashes?
celoos
@celoos
May 07 2016 05:58
perhaps. It's not something that is really a thing to figure out - it's just an overlooked part of the table. I got hung up on that too. @omidqayoumi
Check the table @chrstntdd
Omid
@omidqayoumi
May 07 2016 05:58
ah gotcha @celoos
Justin Woodward
@jwoo92
May 07 2016 05:58
@chrstntdd this is a string so its all going to be inside quotes
Omid
@omidqayoumi
May 07 2016 05:59
he's just one backslash away from victory
Justin Woodward
@jwoo92
May 07 2016 05:59
@chrstntdd with that said look at your example and how to place what it is asking isde your string
so say i wanted a backslash it would read.. var myStr = " \\"
celoos
@celoos
May 07 2016 06:00
@chrstntdd It's tempting to dive right into the problem.. but make sure you understand the example and its explanation first or the problem will make no sense. ;)
But alas, I must work in a few hours. Good luck with everything. ;D
Justin Woodward
@jwoo92
May 07 2016 06:02
@chrstntdd does that help or make sense?
@celoos ouch a few hours... good luck with the lack of sleep, i pulled an all nighter last week and it was no fun.
celoos
@celoos
May 07 2016 06:05
@jwoo92 I am a retail manager, full time university student, and on here in my free time. My life is one big sleep deficit. ;)
Christian Todd
@chrstntdd
May 07 2016 06:06
@jwoo92 it does, but I cant understand how to make the entire sequence. Should I enclose each escape sequence in quotes?
Justin Woodward
@jwoo92
May 07 2016 06:08
@celoos i can understand completely. free time is scarce and for you being a university student alone, you understand sacrificing sleep lol!
@chrstntdd read the directions very carefully, they say 'Encode the following sequence, separated by spaces:'. so we know we are creating a string for the var myStr, now look at how you code what it is asking you to enter. the directions specifically say 'seperated by spaces' that may be a key word ;)
Martialis39
@Martialis39
May 07 2016 06:15
Hi guys, need some help, Sum All Primes.
function sumPrimes(num){
  var sieve = [];
  var primes = [2, 3];
  var range = [];
  var temp;

  for(var i = 2; i <= num; i++){
    range.push(i);
    }

  sieve = range.reduce(function(tempArray, element){
    if(element % 2 === 0 || element % 3 === 0){
      tempArray.push(element);
    }
    return tempArray;
    }, []);

  temp = range.reduce(function(array, number){
    if(sieve.indexOf(number) === -1){
      array.push(number);
      }


    return array;
    }, []);
  return primes.concat(temp).reduce(function(a, b){
    return a + b;
    }, 0);  

}


sumPrimes(10);
This works for 10, but not for the other test - 977.
Any pointers guys?
Harish Chander
@chanderharish1
May 07 2016 06:16
Hi. Can anyone help me with Profile lookup lesson.
function lookUpProfile(firstName, prop){
// Only change code below this line
var count = 0;
for (var i = 0; i < contacts.length; i++) {
    if(contacts[i].firstName === firstName) {
       count ++;
       if (contacts[i].prop === prop) {
          return contacts[i].prop;
       } else {
         return "No such property";
       }
    }   
}
  if (count === 0) {
    return "No such contact";
  }
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes”);
Martialis39
@Martialis39
May 07 2016 06:17
@chanderharish1 sure thing
one sec
Can you try and format your code?
excellent, ty!
OK, Im terrible with object
but
have you tried using
.hasOwnProperty?
Harish Chander
@chanderharish1
May 07 2016 06:20
No. I have not tried it.
celoos
@celoos
May 07 2016 06:21
You can leave out the count variable by simply using it as an 'else'... btw
cough.
Martialis39
@Martialis39
May 07 2016 06:21
@chanderharish1 also
have a look at the function calls
call*
it doesnt like "likes" for some reason, can you think of why?
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:23
heyyyyyy\
can anyone check my code
Martialis39
@Martialis39
May 07 2016 06:23
@nctl144 yes
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:23
it doesnt work and i dont know why
Martialis39
@Martialis39
May 07 2016 06:23
@chanderharish1 Any updates?
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:23

function destroyer(arr) {
  // Remove all the values
  var args = Array.prototype.slice.call(arguments);

  var array1=args[0];

  var array2 = args.slice(1);

  function check(num){
    for(var i = 0; i<array2.length;i++){
      if(num!==array2[i]){
        return num;
      }
    }
  }

  return array1.filter(check);

}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Kartik Shah
@krtk6160
May 07 2016 06:24
Hey guys, I've some problem with the "Falsy Bouncer" algo challenge. I don't understand why the function returns three nulls in the array.

function bouncer(arr) {
  // Don't show a false ID to this bouncer.
 var myarr = arr.filter(function(val) {
  return val !=Boolean(val);
}); return myarr;
}

bouncer([false, null, 0, NaN, undefined, ""]);
celoos
@celoos
May 07 2016 06:24
@chanderharish1 In that problem, make sure you look at the interpretation of .prop vs [prop]. I think the section before that touched on the difference.
Martialis39
@Martialis39
May 07 2016 06:24
@nctl144 remind me what challenge is this?
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:24
its seek and destroy
Harish Chander
@chanderharish1
May 07 2016 06:24
@celoos @Martialis39 I tried accessing the object properties using Dot notation and Bracket notation. It doesn’t seem to work.
Martialis39
@Martialis39
May 07 2016 06:25
@chanderharish1 are you comparing them to each other or are you using .hasOwnProperty?
Harish Chander
@chanderharish1
May 07 2016 06:25
@celoos @Martialis39 I’ve removed the count variable now. Is the for loop fine? Do I need to use nested for loop?
celoos
@celoos
May 07 2016 06:26
@chanderharish1 try starting small - instead of solving the whole problem, try to get the object property you are looking for to return properly. You can do that with console.log() or window.alert().
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:26
@Martialis39 do you have any idea
Martialis39
@Martialis39
May 07 2016 06:26
@nctl144 havinga look now :)
celoos
@celoos
May 07 2016 06:26
@chanderharish1 If you can solve it piece by piece you can put the code together and solve the whole. ;)
Harish Chander
@chanderharish1
May 07 2016 06:27
@celoos @Martialis39 I will reset the code and start solving it step by step.
Martialis39
@Martialis39
May 07 2016 06:28
@nctl144 OK
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:28
@Martialis39 did you find anything
Martialis39
@Martialis39
May 07 2016 06:29
@nctl144 Im pretty sure its the syntax thats tripping it up. I see what you are trying to do, but Im no expert, and cant tell you exactly how you should go about your approach.
what I can tell you
is
celoos
@celoos
May 07 2016 06:29
@chanderharish1 another thing to consider, remember that .prop and [prop] work differently. You might say object[id].prop but you wouldn't say object[id].[prop]
Martialis39
@Martialis39
May 07 2016 06:29
@nctl144 You know that .filter takes a function right? Try it so that you dont write out the function check before hand
rather
write it out when you call filter
so:
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:30
but i did that right
Martialis39
@Martialis39
May 07 2016 06:30
array1.filter(function(number){
    // put the functions code here
})
and you dont need a for loop, filter checks every element already
celoos
@celoos
May 07 2016 06:31
The destroyer was fun... make sure you check what array1 and array 2 hold @nctl144
Harish Chander
@chanderharish1
May 07 2016 06:31
@celoos I tried object[id].[prop] I’m getting Syntax error: Unexpected token ]
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:31
@celoos i did check man
@celoos but i dont even know why it doesnt work
T.T
celoos
@celoos
May 07 2016 06:31
@chanderharish1 My point was that that syntax wouldn't work. :P
Martialis39
@Martialis39
May 07 2016 06:31
@nctl144 I tried to change the syntax, but I cant get it to work with check
@nctl144 let me try some more, in the meantime, you can follow my advice and meet success
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:32
yeah okay
but what is the syntax
lol
Martialis39
@Martialis39
May 07 2016 06:33
@nctl144 Ok
I got it working
celoos
@celoos
May 07 2016 06:34
well @nctl144, you don't necessarily need a for loop in that check. You only need to know if the value being passed by the filter is in array2.
Martialis39
@Martialis39
May 07 2016 06:34
yeah, exactly
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:34
i dont get it...
Martialis39
@Martialis39
May 07 2016 06:34
you need to change your check function
Think about it like this
.filter makes sure every number gets checked
that means that check doesnt need a for loop.
celoos
@celoos
May 07 2016 06:34
The way the filter works - if the value is returned, it is kept. If the value isn't returned, it's kicked.
Though technically it's looking for a boolean, I believe.
Martialis39
@Martialis39
May 07 2016 06:35
yeah,
if true, it returns the number
celoos
@celoos
May 07 2016 06:35
So think about the problem logically.. what do you expect to happen when the value being checked is in array2? @nctl144
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:36
i dont really know
Martialis39
@Martialis39
May 07 2016 06:36
well
array2
are all the number that cant be in array1, right?
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:36
its getting really confusing
yeah
Martialis39
@Martialis39
May 07 2016 06:36
Just take it easy, its alright :)
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:37
okay go on
Martialis39
@Martialis39
May 07 2016 06:37
lets say I have 2 as my array2
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:37
im ready
Martialis39
@Martialis39
May 07 2016 06:37
and array1 is [1,2,3]
how would you check, not using a for loop, if array1 has 2 inside it?
[ 2 ]*
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:38
just if statement
celoos
@celoos
May 07 2016 06:38
Well remember that the problem wants you to remove items from the array1 if they are in array2. The filter is checking each value in array1 to see if it is in array2. If it IS in array2, we are meant to remove it. Now follow @Martialis39 on how to tell the filter (expecting a boolean response) if you want to keep the value being checked or not. @nctl144
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:38
right
Martialis39
@Martialis39
May 07 2016 06:38
tip = there's something called .indexOf
celoos
@celoos
May 07 2016 06:39
Filter is just looking for a yes or no answer on whether it should keep or toss the current value. :P @nctl144
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:39
okay...
Martialis39
@Martialis39
May 07 2016 06:39
@nctl144 Try and read up on the method .indexOf
it can really be of use to us :)
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:40
it searches values
Martialis39
@Martialis39
May 07 2016 06:40
yeah, exactly! it gives you -1 when something is not in the array
Ex:
celoos
@celoos
May 07 2016 06:40
It checks the target array for a value and returns the index of that value if it occurs in the target. Otherwise -1 is returned.
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:40
yeah i know
Martialis39
@Martialis39
May 07 2016 06:40
arr = [1,2,3];
arr.indexOf(4) === -1;
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:40
but how is it working in here
celoos
@celoos
May 07 2016 06:41
If you're looking to see if the current value is in array2, how might you utilize indexOf?
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:41
plus im really confusing because my last challenge passed

function bouncer(arr) {
  // Don't show a false ID to this bouncer.

  function check(string){
    var array =[false, null, 0, "", undefined,NaN];
    for(var i = 0; i<array.length;i++){
      if (string!==array[i]){\
        return string;
      }
    }

  }

  return arr.filter(check);
}

bouncer([7, "ate", "", false, 9]);
see
this passed
celoos
@celoos
May 07 2016 06:42
well that's certainly one way to get that one correct.
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:42
yeah but its like
celoos
@celoos
May 07 2016 06:42
You could also simply translate it into boolean.
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:42
array1 and array2 are both arrays
Martialis39
@Martialis39
May 07 2016 06:43
@nctl144 yes
go on
celoos
@celoos
May 07 2016 06:43
You're not worried about array1 in this problem, @nctl144. You're worried about array1[i] basically. filter iterates through each value.
So the whole thing is already a loop.
So write the inside as if you're already inside a for loop and looking at array1[i]
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:44
but im not looping through the array1
im looping the array2
celoos
@celoos
May 07 2016 06:45
Why?
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:45
to check each value in the array2 right
because theres more than 1 value in array2
celoos
@celoos
May 07 2016 06:45
This is where indexOf could come in, if you fully understand its function.
Martialis39
@Martialis39
May 07 2016 06:45
@celoos Should I post the code? I think it might be more educational
@celoos We can explain why it works.
celoos
@celoos
May 07 2016 06:46
He's nearly there... he's just missing the point of indexOf.
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:46
yeah i just cant understand why my code for the previous challenge works...
Martialis39
@Martialis39
May 07 2016 06:46
Yup. Also kind of which array is being filtered imo.
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:46
while those 2 challenges are basically the same
celoos
@celoos
May 07 2016 06:46
Kind of. The first challenge is actually to test the understanding of boolean.
Each of those values translate to boolean False - therefore the entire thing could be truncated to basically 1 line.
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:47
okay but can you explain why my code worked?
im just stuck at that point
i cant understand why my code for the first challenge works and it doesnt for the second
i mean like i can understand why you guys use indexOf
that might be another way to solve it
just wondering why mine does not work
hope you guys wont give up on me...
Martialis39
@Martialis39
May 07 2016 06:49
dont worry
im look at your previous coden ow
celoos
@celoos
May 07 2016 06:49
I'm checking your original code ;)
Martialis39
@Martialis39
May 07 2016 06:49
now
trying to see what it does
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:50
okay thank you...
Christian Todd
@chrstntdd
May 07 2016 06:54
VERY big thank you to @jwoo92 and @celoos for all the help
CamperBot
@camperbot
May 07 2016 06:54
chrstntdd sends brownie points to @jwoo92 and @celoos :sparkles: :thumbsup: :sparkles:
:cookie: 286 | @jwoo92 |http://www.freecodecamp.com/jwoo92
:cookie: 266 | @celoos |http://www.freecodecamp.com/celoos
paste your code in there and have a look :)
@nctl144 Ok I got it!
at least I understand why your destroyed doesnt work
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:57
yeah okay
Martialis39
@Martialis39
May 07 2016 06:57
we said that .filter is like its own for loop right?
Mateusz Szymański
@matszym
May 07 2016 06:57

@nctl144 You just have some meaningless and redundant code in your example.

    var array =[false, null, 0, "", undefined,NaN]; //its not needed
    for(var i = 0; i<array.length;i++){ // you are looping thru not needed array
      if (string!==array[i]){\ // this will always eventualy pass
        return string; // string isnt a string, its value - current value under arr[index]
      }
    }

what you are really doing in this code is:

return string;
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:57
yeah true
Martialis39
@Martialis39
May 07 2016 06:58
that means that everysingle time your for loop inside check
goes to 0
and since 0 is never === num
everything gets returned.
Mateusz Szymański
@matszym
May 07 2016 06:59
@Martialis39 exactly, like I said just before you ;)
Chau Tung Lam Nguyen
@nctl144
May 07 2016 06:59
@matszym but the code that you commented on still works lol
celoos
@celoos
May 07 2016 07:00
@nctl144 ok so in your destroyer... the loop doesn't completely finish.
3 != 2 : return 3 happens
Mateusz Szymański
@matszym
May 07 2016 07:00
ofcourse, its just note neded. You could add plenty of not needed code, create 1000 objects, make few loops , place some consitions like if(false || true)
celoos
@celoos
May 07 2016 07:00
The moment you hit something that isn't in array2, you jump out
A better solution would be to default with returning num outside the loop with an if statement that returns false inside if it is found
Martialis39
@Martialis39
May 07 2016 07:02
@matszym Hey sir, could give me a hand with sum all primes?
I have an issue with the larger test
Mateusz Szymański
@matszym
May 07 2016 07:02
@Martialis39 k, post code
celoos
@celoos
May 07 2016 07:02
eg. for () { if (val == array2[i]) { return false; } } return true;
@nctl144 that adjustment makes your code work
Martialis39
@Martialis39
May 07 2016 07:02
@matszym
function sumPrimes(num){
  var sieve = [];
  var primes = [2, 3];
  var range = [];
  var temp;

  for(var i = 2; i <= num; i++){
    range.push(i);
    }

  sieve = range.reduce(function(tempArray, element){
    if(element % 2 === 0 || element % 3 === 0){
      tempArray.push(element);
    }
    return tempArray;
    }, []);

  temp = range.reduce(function(array, number){
    if(sieve.indexOf(number) === -1){
      array.push(number);
      }


    return array;
    }, []);
  return primes.concat(temp).reduce(function(a, b){
    return a + b;
    }, 0);  

}
works with 10, not with 977
celoos
@celoos
May 07 2016 07:03
@nctl144 did you get that?
Chau Tung Lam Nguyen
@nctl144
May 07 2016 07:03
@celoos almost
im analyzing
im intel celeron
celoos
@celoos
May 07 2016 07:04
So basically, your logic was wrong. The moment you found something you weren't looking for, you broke the loop.
Thus everything was passed.
Chau Tung Lam Nguyen
@nctl144
May 07 2016 07:05
@Martialis39 hey why everysingle time my for loop inside check goes to 0
yeah
Martialis39
@Martialis39
May 07 2016 07:05
@nctl144 because, and Im sorry I cant explain this better,
but .filter itselft
is a function, that loops iterates over every element
so every single time it gets to a new one
it calls check again
and check starts with 0 :)
Chau Tung Lam Nguyen
@nctl144
May 07 2016 07:06
oh okay thats much better
Martialis39
@Martialis39
May 07 2016 07:06
so basically
Chau Tung Lam Nguyen
@nctl144
May 07 2016 07:07
thank you guys so much @Martialis39 @celoos @matszym
CamperBot
@camperbot
May 07 2016 07:07
nctl144 sends brownie points to @martialis39 and @celoos and @matszym :sparkles: :thumbsup: :sparkles:
:cookie: 267 | @celoos |http://www.freecodecamp.com/celoos
:cookie: 42 | @matszym |http://www.freecodecamp.com/matszym
:cookie: 307 | @martialis39 |http://www.freecodecamp.com/martialis39
Martialis39
@Martialis39
May 07 2016 07:07
i modified your code
and got it working,
just forget about the for loop in check :)
celoos
@celoos
May 07 2016 07:07
no problem ;)
Chau Tung Lam Nguyen
@nctl144
May 07 2016 07:07
yeah never put for loop in filter
lol
Martialis39
@Martialis39
May 07 2016 07:07
Im not an expert, I dont know if thats true :d
but yeah, for the moment, sure, lets go with that :D
celoos
@celoos
May 07 2016 07:07
for loop does work in check.. it's just not the most efficient way of doing that problem.
i: 0 - 2 vs 1 no match
i: 0 - 2 vs 2 match
i: 1 - 3 vs 2 no match
i: 0 - 2 vs 3 no match
i: 0 - 2 vs 1 no match
i: 0 - 2 vs 2 match
i: 1 - 3 vs 2 no match
i: 0 - 2 vs 3 no match
That's the actual output from your original code.
but once it hit a no match it jumped
Martialis39
@Martialis39
May 07 2016 07:08
@celoos Hey man, could you help me with Sum All Primes?
and maybe Smallest Common Multiple too :D
celoos
@celoos
May 07 2016 07:09
I haven't done that one yet.. and I really should have been asleep an hour ago :P Perhaps tomorrow if you still haven't gotten it.
Chau Tung Lam Nguyen
@nctl144
May 07 2016 07:09
yeah its 3am and my mind is not working very well
Martialis39
@Martialis39
May 07 2016 07:09
@celoos Tomorrow it is, i definitely will have not gotten it :D
Chau Tung Lam Nguyen
@nctl144
May 07 2016 07:13
@Martialis39 hang on man
can you explain again to me what is 0
is that the num
okay nevermind
Martialis39
@Martialis39
May 07 2016 07:14
@matszym any ideas sir?
Mateusz Szymański
@matszym
May 07 2016 07:15
@Martialis39 A question about your sieve array - what do you want to put here? Is if(element % 2 === 0 || element % 3 === 0) valid? Didnt you mean both % 2 and % 3 === 0 conditions should be met?
Martialis39
@Martialis39
May 07 2016 07:16
I understood that Im doing
if ( is divisable by 2 OR is divisable by 3){
push to sieve;
]
so that later on I can add as prime everything that is NOT in the sieve.
Mateusz Szymański
@matszym
May 07 2016 07:17
@Martialis39 ah ok, this aray is containt not valid numbers
@Martialis39 I dont understandword sieve :D Google sieve define didnt produce anythin usefull
Martialis39
@Martialis39
May 07 2016 07:17
Yup :)
yeah its the sieve of erotosthenes (spelling?)
and this is my SUPER SUPER basic version of it.
Mateusz Szymański
@matszym
May 07 2016 07:29

@Martialis39

temp = sieve.reduce(function(array, number){
    if(sieve.indexOf(number) === -1)
      array.push(number);
    return array;
  }, []);

In this part, you are going thru not valid nubers, and pushing them to array you later treat like valid array numbers

@Martialis39 What I think you ment is temp = range.reduce
Martialis39
@Martialis39
May 07 2016 07:30
Right, Im confused
celoos
@celoos
May 07 2016 07:30
oh hey i got it
Martialis39
@Martialis39
May 07 2016 07:30
i might have already fixed that
celoos
@celoos
May 07 2016 07:30
_>
Mateusz Szymański
@matszym
May 07 2016 07:30
@Martialis39 but even then, on array lands not valid numbers, like 115, 175, 185
celoos
@celoos
May 07 2016 07:30
I didn't use a sieve though. <-<
Martialis39
@Martialis39
May 07 2016 07:31
The current code, does indeed use range.reduce
@celoos Hey
Any option is valid, as long I can understand it :)
@matszym correct
Mateusz Szymański
@matszym
May 07 2016 07:31
@Martialis39 so, numbers divided by 5 are the problem
Martialis39
@Martialis39
May 07 2016 07:31
indeed
I could just
celoos
@celoos
May 07 2016 07:31
I used an embedded for loop
Martialis39
@Martialis39
May 07 2016 07:31
add that to the sieve
prashant
@findname
May 07 2016 07:32
var decimalValue = [ 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 ];
  var romanNumeral = [ 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I' ];
var k=0,newNum=[];
function convertToRoman(num) {
  num=num.slice("");                 //for converting to array
  for(i=0;i<num.length;i++)
 {
          if(0<decimalValue[k]<decimalValue[k]+num[i].join(''))         //num upto 3999
           {
                    var mod=num[i]/decimalValue[i];          
                    var j=0;
                    while(j<3 && mod>0) {                                        
                                          newNum=newNum.push(romanNumeral[k]); 
                                            j++;
                                            mod++;
            }}
           k++;
  }  
 return newNum;
}

convertToRoman(36);
its giving error
Mateusz Szymański
@matszym
May 07 2016 07:33
@Martialis39 Thats not going to work with OR operator, not like element % 2 === 0 || element % 3 === 0 || element % 5 === 0
celoos
@celoos
May 07 2016 07:33
It checks whether the number is divisible by any number from 2 to the number. >_> probably could be enhanced a lot for larger numbers. lol
Martialis39
@Martialis39
May 07 2016 07:33
@matszym yeah youre right
plus, id missed the first 5.
so yeah, im pretty stuck here :/
celoos
@celoos
May 07 2016 07:34
@Martialis39 you're doing the sum all primes right?
Martialis39
@Martialis39
May 07 2016 07:35
yeah
celoos
@celoos
May 07 2016 07:35
Do you know how to calculate a prime number?
or what is the wall you're hitting?
Martialis39
@Martialis39
May 07 2016 07:35
Not very efficiently, no :/
celoos
@celoos
May 07 2016 07:35
well if you're looking for efficient then I don't think I'm the right person at the moment. ;)
Martialis39
@Martialis39
May 07 2016 07:35
Im having trouble summing larger primmes, 900 ish
hey, whatever works :)
celoos
@celoos
May 07 2016 07:36
i'll give you a snippet of my calculation... see if that gets you headed in the right direction
Martialis39
@Martialis39
May 07 2016 07:36
sure
celoos
@celoos
May 07 2016 07:37
for(var j = 2; j <= i/2; j++)
That's an inner loop to calculate whether the number is divisible by anything from 2 up to the number being checked while preventing the false positive of large even numbers and eliminating some odd ones.
Martialis39
@Martialis39
May 07 2016 07:39
ok, I take it that
celoos
@celoos
May 07 2016 07:39
The outer loop i'm sure you have already for getting all of the numbers up to the test number
Martialis39
@Martialis39
May 07 2016 07:39
sure
why the i / 2 though?
lets say I have sumPrimes(977)
why / 2?
celoos
@celoos
May 07 2016 07:41
Well think i = 3
Mateusz Szymański
@matszym
May 07 2016 07:41
@Martialis39 consider making helper function is prime, like (not tested!)
function isPrime(num) {
    for(var i = 2; i < num; i++)
      if(num % i === 0)
        return false;
    return true;
  }
Chau Tung Lam Nguyen
@nctl144
May 07 2016 07:41
function destroyer(arr) {
  // Remove all the values
  var args = Array.prototype.slice.call(arguments);

  var array1=args[0];

  var array2 = args.slice(1);

  var newarray=[];
  for (var i =0; i<array1.length; i++){
    for(var j = 0; j<array2.length;j++){
      if(array1[i]==array2[j]){
        delete array1[i];
      }
    }
    newarray = array1;\
  }

  function check(num){
    return num;
  }
  return newarray.filter(check);
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
just to let you guys know
i did this instead
no for loop in filter
thanks to @celoos @Martialis39
CamperBot
@camperbot
May 07 2016 07:42
nctl144 sends brownie points to @celoos and @martialis39 :sparkles: :thumbsup: :sparkles:
:warning: nctl144 already gave celoos points
:warning: nctl144 already gave martialis39 points
Martialis39
@Martialis39
May 07 2016 07:42
@nctl144 youre welcome! :)
celoos
@celoos
May 07 2016 07:42
If you consider the big O for that.. it's significantly slower though. ;)
Martialis39
@Martialis39
May 07 2016 07:42
yeah, big O not an issue atm :D
Chau Tung Lam Nguyen
@nctl144
May 07 2016 07:43
yeah basically i dont really care about that right now
celoos
@celoos
May 07 2016 07:43
lol fair enough.
Chau Tung Lam Nguyen
@nctl144
May 07 2016 07:43
i just need to go back to my dorm and sleep
:))
celoos
@celoos
May 07 2016 07:43
@Martialis39 so for example i = 3; 3/2 = 1, 2>1 so it's skipped in that loop - signaling a prime.
Chau Tung Lam Nguyen
@nctl144
May 07 2016 07:43
i had my history final on monday and i dont even know what im doing in that class
but since i didnt code for 1 week and i kinda miss it so i decided to stay up late tonight for that
anyway i got the point that no for loop in the filter though
ha ha...
Tadas Bitkevicius
@Siderr
May 07 2016 07:45
who could help me fix a bug in my code in whereAreYou challange ?
Mateusz Szymański
@matszym
May 07 2016 07:46
@Martialis39 not sur eif you missed my proposition with isPrime function, hers sollution i just created
function sumPrimes(num){
  function isPrime(num) {
    for(var i = 2; i < num; i++)
      if(num % i === 0)
        return false;
    return true;
  }

  for(var i = 2; i <= num; i++){
    range.push(i);
  }

  var result = range.filter(isPrime);

  return result.reduce(function(sum, val){
    return sum += val;
  }, 0);
}

sumPrimes(977);
Martialis39
@Martialis39
May 07 2016 07:46
@matszym no, yours is very good, I needa moment to try it :)
celoos
@celoos
May 07 2016 07:47
It's easy to just give the code... better to make them work for it. ;)
Tadas Bitkevicius
@Siderr
May 07 2016 07:47
can I paste my code here ?
celoos
@celoos
May 07 2016 07:47
help format
CamperBot
@camperbot
May 07 2016 07:47

: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

Travis
@dukenukethem
May 07 2016 07:49
help Reverse A String
CamperBot
@camperbot
May 07 2016 07:49

:point_right: algorithm reverse a string [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:

We need to take the string and reverse it, so if it originally reads 'hello', it will now read 'olleh'. We will need to split the string, and therefore we will be working with Arrays as well.

:pencil: read more about algorithm reverse a string on the FCC Wiki

celoos
@celoos
May 07 2016 07:51
@dukenukethem look at String commands in parsing it to an array and Array commands in terms of sorting. Those may help you
@Martialis39 how's it coming?
Martialis39
@Martialis39
May 07 2016 07:52
@celoos one second sir, i can get to it in 5 minutes :)
the-tafadzwa
@the-tafadzwa
May 07 2016 07:52
Hi guys. I'm having a problem with the Testing Objects for Properties challenge
I think I have figured out how to test the object for the property, but I am failing to then call the property
Here is what my code currently looks like:
// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

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

// Test your code by modifying these values
checkObj("gift");
celoos
@celoos
May 07 2016 07:53
@Martialis39 alright :P I'm closing the laptop now so I won't be tempted to come back and help more people. lol I need to sleep before work x.x
Martialis39
@Martialis39
May 07 2016 07:53
@celoos :O
Ok, sleep tight! hopefully we can manage :)
Travis
@dukenukethem
May 07 2016 07:53
I guess I don't really quite get where to put my code.
Nevermind holy crap :x
celoos
@celoos
May 07 2016 07:55
@the-tafadzwa Your code is incomplete. Look up the .property and [property] functions of objects. It should be on the side
@Martialis39 ok i lied. but now forreal.
Travis
@dukenukethem
May 07 2016 07:55
I was originally trying to put the .split().reverse().join() outside of the function
Tadas Bitkevicius
@Siderr
May 07 2016 07:56
function whereAreYou(collection, source) {
  // What's in a name?
  var arr = [];  
  // Only change code below this line
  arr = collection.filter(function(item, index) {
          for( var key in source){
     if (item.hasOwnProperty(key)) {
       console.log(item[key] ,source[key]);     
       console.log(item[key] === source[key]);
       if(item[key] === source[key]){
         return true;
        }
    }    
}
});  
  // Only change code above this line
  return arr;
}
this from the whereAreYou challange
I can't make this work for the test three and four
Martialis39
@Martialis39
May 07 2016 07:57
@celoos alright sir, all the best, thanks for the help!
CamperBot
@camperbot
May 07 2016 07:57
martialis39 sends brownie points to @celoos :sparkles: :thumbsup: :sparkles:
:cookie: 269 | @celoos |http://www.freecodecamp.com/celoos
celoos
@celoos
May 07 2016 07:57
@Martialis39 No worries ;) good luck.
Justin Woodward
@jwoo92
May 07 2016 07:57
help Check for Palindromes
CamperBot
@camperbot
May 07 2016 07:57

:point_right: algorithm check for palindromes [wiki]

Explanation:

Our goal for solving this problem is tidying up the string passed in, and checking whether it is in fact a palindrome.

  • If you are unsure of what a palindrome is, it is a word or phrase that when reversed spells the same thing forwards or backwards. A simple example is mom, when you reverse the letters, it spells the same thing! Another example of a palindrome is race car. When we take out anything that is not a character it becomes racecar which is the same spelled forwards or backwards!

Once we have determined whether it is a palindrome or not we want to return either true or false based on our findings.

:pencil: read more about algorithm check for palindromes on the FCC Wiki

celoos
@celoos
May 07 2016 07:57
ha, moom.
Chris Cullen
@123xylem
May 07 2016 07:57
QUick QUESTION: How do I make my JS function output to a HTML <p> via a Button? I can get the button to print to console but not sure how to change its output to a paragraph below
??
Tadas Bitkevicius
@Siderr
May 07 2016 07:58
@jwoo92 this was for me ?
Justin Woodward
@jwoo92
May 07 2016 07:59
@Siderr for myself, sorry for the confusion.
Mateusz Szymański
@matszym
May 07 2016 07:59
@123xylem easiest way is to use jquery and .text method
the-tafadzwa
@the-tafadzwa
May 07 2016 07:59
I tried return myObj.checkProp;
Justin Woodward
@jwoo92
May 07 2016 07:59
@Siderr you can however, type 'help' and then the challenge name for a wiki resource.
Mateusz Szymański
@matszym
May 07 2016 08:00
Chris Cullen
@123xylem
May 07 2016 08:00
@matszym thnx
CamperBot
@camperbot
May 07 2016 08:00
123xylem sends brownie points to @matszym :sparkles: :thumbsup: :sparkles:
:cookie: 43 | @matszym |http://www.freecodecamp.com/matszym
Tadas Bitkevicius
@Siderr
May 07 2016 08:01
help Where art thou
CamperBot
@camperbot
May 07 2016 08:01

: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

Travis
@dukenukethem
May 07 2016 08:02
help Factorialize a Number
CamperBot
@camperbot
May 07 2016 08:02

: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

dividedpixel
@dividedpixel
May 07 2016 08:08
help No repeats please
CamperBot
@camperbot
May 07 2016 08:08

:point_right: algorithm no repeats please [wiki]

Problem Explanation:

  • This task requires us to look at each possible permutation of a string. This is best done using a recursion function. Being able to build a function which collects all permutations of a string is a common interview question, so there is no shortage of tutorials out there on how to do this, in many different code languages.
  • This task can still be daunting even after watching a tutorial. You will want to send each new use of the function 3 inputs: 1. a new string (or character array) that is being built, 2. a position in your new string that's going to be filled next, and 3. an idea of what characters (more specifically positions) from the original string have yet to be used. The pseudo code will look something like this:

    ```
    var str = ???;
    perm(current position in original string, what's been used in original string, current string build thus far){
    if(current string is finished) {
    print current string;
    }else{
    for(var i = 0; i < str.length; i++) {

    if(str[i] has not been used) {
      put str[i] into the current position;
      mark str[i] as used
      perm(current position in original string, what's been used in original string, current string build thus far)
      unmark str[i] as used because another branch in the tree for i + 1 will still likely use it;
    }

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

Chris Cullen
@123xylem
May 07 2016 08:11
WHen using .text Mehtod WHERE do I set the tag or selector name of my function???
$(selector).text(function(index,currentcontent))
Travis
@dukenukethem
May 07 2016 08:11
help Check for Palindromes
CamperBot
@camperbot
May 07 2016 08:11

:point_right: algorithm check for palindromes [wiki]

Explanation:

Our goal for solving this problem is tidying up the string passed in, and checking whether it is in fact a palindrome.

  • If you are unsure of what a palindrome is, it is a word or phrase that when reversed spells the same thing forwards or backwards. A simple example is mom, when you reverse the letters, it spells the same thing! Another example of a palindrome is race car. When we take out anything that is not a character it becomes racecar which is the same spelled forwards or backwards!

Once we have determined whether it is a palindrome or not we want to return either true or false based on our findings.

:pencil: read more about algorithm check for palindromes on the FCC Wiki

Chris Cullen
@123xylem
May 07 2016 08:11
EG how do I set the selector
@123xylem
WHen using .text Mehtod WHERE do I set the tag or selector name of my function???
$(selector).text(function(index,currentcontent))
Darth Skywalker
@adityaparab
May 07 2016 08:13
@dukenukethem
return str === str.split('').reverse().join('') ? 'palindrome' : 'not a palindrome';
Travis
@dukenukethem
May 07 2016 08:14
@adityaparab hm???
Darth Skywalker
@adityaparab
May 07 2016 08:15
@dukenukethem :smile:
Try this :D
function isPalindrome(str){
    return str.toLowerCase() === str.split('').reverse().join('').toLowerCase() ? 'palindrome' : 'not a palindrome';
}

console.log(isPalindrome("eye"));
Travis
@dukenukethem
May 07 2016 08:16
Where? Lmao
Darth Skywalker
@adityaparab
May 07 2016 08:16
@dukenukethem Sorry.. Edited now.. Pressed enter accidentally in between :P
Travis
@dukenukethem
May 07 2016 08:17
That looks like cheating :x
Darth Skywalker
@adityaparab
May 07 2016 08:17
lol why?
Travis
@dukenukethem
May 07 2016 08:17
I don't understand this challenge fully and that looks like the answer
Darth Skywalker
@adityaparab
May 07 2016 08:17
Palindrome is a string that looks the same whether you read it from left to right or from right to left. :D
Travis
@dukenukethem
May 07 2016 08:18
yeah I understand that part. I guess I should have said I don't understand how to put that into code quite fully
Darth Skywalker
@adityaparab
May 07 2016 08:18

eye is palindrome
mom is palindrome
dad is palindrome

Travis, unfortunately, is not a palidrome :P

@dukenukethem : All you have to do is compare the string with it's reversed version.
Travis
@dukenukethem
May 07 2016 08:20
How does RegEx work?
Kartik Shah
@krtk6160
May 07 2016 08:21
Hey guys, can you tell me what the problem with my code is?
It always returns first arg, doesn't modify the array.
This is the "seek and destroy" algo problem.

function destroyer(arr) {
  // Remove all the values
  for (var i=0;i<arr[0].length;i++){
    for (var j=0;j<arr[1].length;j++){
      if(arr[0][i]==arr[1][j]){
        delete [arr][0][i];
      }
    }
  } return arr;
}

destroyer([1, 2, 3, 4, 1, 2, 3], 1, 3);
Justin Woodward
@jwoo92
May 07 2016 08:21
@dukenukethem youre booming through those, ive been on Check for Palindromes for a while
Travis
@dukenukethem
May 07 2016 08:22
That's waht Im on now :O
Kartik Shah
@krtk6160
May 07 2016 08:22
The if statement seems to never get called, therefore the array remains unchanged.
Travis
@dukenukethem
May 07 2016 08:22
RegEx isn't making much sense to me
Justin Woodward
@jwoo92
May 07 2016 08:23
this is what i have so far @dukenukethem

function palindrome(str) {
  str.replace(RegExp([a-z]));
  str.toLowerCase();


  if (str  ) {
  return true;
} else {
  return false;
}

}



palindrome("eye");
Chris Cullen
@123xylem
May 07 2016 08:24
Im trying to make a button return output of function into a <p> ... Is this close to working?
<div class="machine">
      <button class="button" type="button "onclick="myFunction()">Wisdom</button>



   <script>  
     $(button).text(myFunction()) $("p").text(quote);
     $("p").text(name);
      </script>

      <p class="quoteboxtext"> Quote  </p>

    <p class="quoteboxtext">  Author</p>
Travis
@dukenukethem
May 07 2016 08:24
Heck of a lot more than I @jwoo92 :p
Justin Woodward
@jwoo92
May 07 2016 08:25
@dukenukethem i believe all i need to figure out is how to check if its a Palindrome or not
Ajith
@ajithvallabai
May 07 2016 08:25

```
var fact=1;
function factorialize(num) {
for(var i=1;i<=num;i++)
{
fact=(fact*i);

}

return fact;
}

factorialize(5);
``` my code is perfect i get the output specified in testcase but it isnot showing correct why? could any one help me

Mateusz Szymański
@matszym
May 07 2016 08:28
@krtk6160 arr point to arguments[0], you dont have helper variables for 1 and 3 arguments
Kartik Shah
@krtk6160
May 07 2016 08:29
@matszym I'm sorry, I'm not quite sure what that means. Can you dumb it down?
Travis
@dukenukethem
May 07 2016 08:29
Holy crap; I guess i'll be coming back to this later today.
Mateusz Szymański
@matszym
May 07 2016 08:31
@krtk6160 sure arr[0] -> 1, its not [1, 2, 3, 4, 1, 2, 3]
Justin Woodward
@jwoo92
May 07 2016 08:31
im not returning my false options

function palindrome(str) {
  str.replace(RegExp([a-z]));
  str.toLowerCase();


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

}



palindrome("eye");
Mateusz Szymański
@matszym
May 07 2016 08:32
@krtk6160 teherfor your loop check length of number 1 when you do arr[0].length
@krtk6160 like 1.length - thats what arr[0].length does
Justin Woodward
@jwoo92
May 07 2016 08:33
is my problem within my RegExp??
Kartik Shah
@krtk6160
May 07 2016 08:33
@matszym Oh! Well even if it only runs the loop with i =0 and i=1, it should still remove the first two elements if they're similar, right?
Darth Skywalker
@adityaparab
May 07 2016 08:34

To everyone who are stuck with palindrome. Here is a complete algorithm covering all the steps.

1) Accept a string

2) Remove all the non alphabetic characters in that string (space, white spaces, special characters)
You will need a thing called Regular Expression (reg ex for short) to do that. Simply find a reg ex online that matches ONLY the letters in alphabet. User .replace method to replace the unmatching characters with '')

3) Reverse the modified string and store it in another variable.

4) compare modified string and it's reversed variants

5) if step 4 is true, string is a palidrome. Otherwise it's not.

I've been sharing code a little too frequently and i'm sure it steals your leaning experience. So this is an alternative. :D

@jwoo92 : The .replace method needs 2 arguments. Matching string and the thing you want it replaced with.
Mateusz Szymański
@matszym
May 07 2016 08:35
@krtk6160 arr[0][i]==arr[1][j]
this comparision tries to acces [i] property on number
@krtk6160 this should never pass
1[i] - this really doesnt make any sene
Kartik Shah
@krtk6160
May 07 2016 08:36
@matszym How do I access the array that needs to be modified?
Mateusz Szymański
@matszym
May 07 2016 08:36
and accesing length property on number throws syntax error, so I wuldnt expect loop to run even once
Darth Skywalker
@adityaparab
May 07 2016 08:36
@jwoo92 : str.replace(RegExp([a-z])); should be str.replace(/[^A-Za-z]/g, '');
Justin Woodward
@jwoo92
May 07 2016 08:37
@adityaparab thanks for the help, i have the right order down, but RegExp seems brand new to me
CamperBot
@camperbot
May 07 2016 08:37
:cookie: 229 | @adityaparab |http://www.freecodecamp.com/adityaparab
jwoo92 sends brownie points to @adityaparab :sparkles: :thumbsup: :sparkles:
Mateusz Szymański
@matszym
May 07 2016 08:37
@krtk6160 I assume, that the array that needs to be modified is the first argument - you have acces to it, by variable arr
@krtk6160 what you dont have is helper variables for rest of arguments
Kartik Shah
@krtk6160
May 07 2016 08:37
How do I access the second argument then? The values that I have to check against the values of the first array?
Mateusz Szymański
@matszym
May 07 2016 08:38
and thats what its all about - you should learn how to acces them
read introduction
Justin Woodward
@jwoo92
May 07 2016 08:38
@adityaparab thanks again ill look at my wiki pages to see how that makes it correct so i can understand it and write it myself
CamperBot
@camperbot
May 07 2016 08:38
jwoo92 sends brownie points to @adityaparab :sparkles: :thumbsup: :sparkles:
:warning: jwoo92 already gave adityaparab points
Justin Woodward
@jwoo92
May 07 2016 08:39
@adityaparab should i be worried that i didnt understand the .replace method being this far along in the curriculum?
Mateusz Szymański
@matszym
May 07 2016 08:39

@krtk6160 "Here are some helpful links:

Arguments object"
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments

Darth Skywalker
@adityaparab
May 07 2016 08:39
@jwoo92 : You will need to learn more about regular expression. For now just use the Reg ex I provided. For that is an Entire subject of computer science in and off itself. It's an advance topic and you'd find it boring if you jump into it without mastering the basics of programming.
Scott Gibson
@sc00gle
May 07 2016 08:41
Could someone check my code for "Confirm the Ending" - I'm not sure why it's not passing: https://gist.github.com/sc00gle/f18e8be8ef85059154de79cea5dc5bb8
Justin Woodward
@jwoo92
May 07 2016 08:41
@adityaparab understandable, i appreciate the assistance. i was concerned that not knowing the concept behind it at this point may hold me back.
EricOber
@EricOber
May 07 2016 08:42
hey eberbody
Mateusz Szymański
@matszym
May 07 2016 08:42
@jwoo92 Or you could just forget about regular expressions and solve problem by other means There are plenty of ways to aproach single problem
Travis
@dukenukethem
May 07 2016 08:42
This challenge is boggling my brain.
EricOber
@EricOber
May 07 2016 08:43
can anybody help me with my challenge? Im on the Record Collection challenge
Justin Woodward
@jwoo92
May 07 2016 08:44
@dukenukethem dont feel too bad, ive been on it for say, 3 so hours? :) off and on but hard at it the past 30 minutes.
Darth Skywalker
@adityaparab
May 07 2016 08:44
@krtk6160 I think you're going a little too apeshit with all this.

function destroyer() { // removed the arr. For the number of arguments is variable.

var args = Array.prototype.slice.call(arguments); // arguments object is passed implicitly by JS

var arr = args[0]; get the first Array
var toBeDestroyed = args.slice(1);// form another array of remaining elements/parameters.

arr.forEach(function(element, index){
  if(toBeDestroyed.indexOf(element) > -1){ // check if current array element exists in the remaining params.
      delete arr[index];
  }
});

return arr;
}

destroyer([1, 2, 3, 4, 1, 2, 3], 1, 3);
Coy Sanders
@coymeetsworld
May 07 2016 08:44
@sc00gle I think you're making it too complicated
Justin Woodward
@jwoo92
May 07 2016 08:44
@matszym that is a good idea. i believe they are suggesting using a regular expression in this challenge though.
Coy Sanders
@coymeetsworld
May 07 2016 08:45
it should be a one liner, also return "True" doesn't return true boolean value, it returns a string "True" which is not the same
Mateusz Szymański
@matszym
May 07 2016 08:45

@sc00gle

str.substr(-tarlen) === target

tarlen is number, -tarlen is -number. What are you trying to do here? I dont think this is ever going to pass

Coy Sanders
@coymeetsworld
May 07 2016 08:46
yeah you need to put an integer value inside substr()
which it is actually nvm
think the problem is just return statements, replace "True" with true (no quotation marks), same with "False" and false
Travis
@dukenukethem
May 07 2016 08:47
RegEx is so freaking confusing holy hell ._.
Darth Skywalker
@adityaparab
May 07 2016 08:48

@dukenukethem Its not lol.. Here is a nice site to play around reg exs'

http://regexr.com/

Scott Gibson
@sc00gle
May 07 2016 08:49
Thanks @coymeetsworld That did the trick.
CamperBot
@camperbot
May 07 2016 08:49
:cookie: 761 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
sc00gle sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
Darth Skywalker
@adityaparab
May 07 2016 08:50
It's the most straightforwards thing in the history of computer science. may be that is why it seems so not straightforward. For humans love drama and intellect contempts simplicity. We all love drama lol
Justin Woodward
@jwoo92
May 07 2016 08:50
is it common practice to use literal notation or a constructor with regular expressions
Mateusz Szymański
@matszym
May 07 2016 08:50

@adityaparab

(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])

This is official email regex (RFC 5322 Official Standard) If its not confucing as hell, I dont know what is

Darth Skywalker
@adityaparab
May 07 2016 08:50
@matszym : It's not. If you know the meanings of the symbols. :)
Mateusz Szymański
@matszym
May 07 2016 08:51
@adityaparab gl debuging
Darth Skywalker
@adityaparab
May 07 2016 08:51
It has a syntax. And it's read left to right. :D Simple.
Travis
@dukenukethem
May 07 2016 08:51
what's the difference between [\W] and [\W_] ?
like I can't find the _ in the RegEx dictionary
Mateusz Szymański
@matszym
May 07 2016 08:51
@adityaparab Following that logic, there is no difference whenever yo uare faced with minified code or not. Ok
Darth Skywalker
@adityaparab
May 07 2016 08:52
\W (the capital W) mean anything non alphabetic. or non word
@matszym Minified code may jump from place to place (function calls and stuff). Reg Ex doesn't do that.
@dukenukethem [\W_] would mean all non word characters AND an underscore. (which is, again, stupid, for \W will include an underscore)
Travis
@dukenukethem
May 07 2016 08:54
Weird; saw some code with the "[\W_]
Darth Skywalker
@adityaparab
May 07 2016 08:56
haha! Learn the syntax of Reg Ex and it will be fun thing to do. Don't listen to people who don't know what they're talking about :P
Travis
@dukenukethem
May 07 2016 08:56
instead of just [\W]
Darth Skywalker
@adityaparab
May 07 2016 08:57
yes. \W is enough.
Justin Woodward
@jwoo92
May 07 2016 08:57
here is what i have, not completing the false statements.

function palindrome(str) {
  str.replace(/[a-z]/g, '');
  str.toLowerCase();
  var reverse = str.split().reverse().join();

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

}



palindrome("eye");
Darth Skywalker
@adityaparab
May 07 2016 08:57
@jwoo92 : var reverse = str.split().reverse().join(); should be var reverse = str.split('').reverse().join('');
notice the '' as a parameter to .split and .join
Travis
@dukenukethem
May 07 2016 08:58
I think I get how to do this challenge now
Mateusz Szymański
@matszym
May 07 2016 08:58
@adityaparab
Does Douglas Crockford also doesnt know what he's talking about?
Justin Woodward
@jwoo92
May 07 2016 08:58
@adityaparab ohhhhhhh so '' with no spaces indicates at each character?
Travis
@dukenukethem
May 07 2016 08:58
I'm not going to complete it though because I did cheat and looked at the hints on the FCC wiki page
Darth Skywalker
@adityaparab
May 07 2016 08:58
@jwoo92 Yes.
Paweł Przytuła
@paprzytula
May 07 2016 08:58
blob
Darth Skywalker
@adityaparab
May 07 2016 08:59
@matszym : I think he does.
Paweł Przytuła
@paprzytula
May 07 2016 08:59
i think the underscore must be included (example above)
Darth Skywalker
@adityaparab
May 07 2016 09:00
@paprzytula : Well! My bad! yes.
Justin Woodward
@jwoo92
May 07 2016 09:00
still not getting false results when applied.

function palindrome(str) {
  str.replace(/[a-z]/g, '');
  str.toLowerCase('');
  var reverse = str.split('').reverse('').join('');

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

}



palindrome("eye");
Darth Skywalker
@adityaparab
May 07 2016 09:00
\W is not word number or whitespece.
@jwoo92 : Could be 2 fixes.
1) Move .toLowerCase() above your .replace
OR
2) Change your Reg Ex to /^[a-zA-Z]/g
Justin Woodward
@jwoo92
May 07 2016 09:03
@adityaparab str.toLowerCase(); does not require an indicator and will perform it to the given string?
Darth Skywalker
@adityaparab
May 07 2016 09:03
@adityaparab : You're replacing alphabets and leaving non alphabet characters intact.
Justin Woodward
@jwoo92
May 07 2016 09:04
what is the difference between /[a-z]/g and /^[a-zA-Z]/g? i see you added different symbols and upper-cased certain letters.
my code has between a-z on a global level. i do not understand your break down.
Darth Skywalker
@adityaparab
May 07 2016 09:05

let me update:

the correct reg ex for you is /[^a-zA-Z]+/g

Justin Woodward
@jwoo92
May 07 2016 09:05
@adityaparab thanks again for helping by the way, i really do appreciate it.
CamperBot
@camperbot
May 07 2016 09:05
jwoo92 sends brownie points to @adityaparab :sparkles: :thumbsup: :sparkles:
:warning: jwoo92 already gave adityaparab points
Darth Skywalker
@adityaparab
May 07 2016 09:05
the ^ should be inside the [
^ means NOT
[a-zA-Z] means anything that is a to z and A to Z
[^a-zA-Z] means anything that is NOT (a to z and A to Z)
Justin Woodward
@jwoo92
May 07 2016 09:06
so a-z is performing a match with my lower case letters and the A-Z is performing a check on upper cased letters?
Darth Skywalker
@adityaparab
May 07 2016 09:07
@jwoo92 correct
that is why I said if you're gonna use [a-z] you better convert your string .toLowerCase before you do that.
Justin Woodward
@jwoo92
May 07 2016 09:08
@adityaparab and it is completely acceptable to push those together with out a space, comma, ext? example: a-zA-Z versus a-z A-Z?
Darth Skywalker
@adityaparab
May 07 2016 09:08
yes. WITHOUT A SPACE.
[a-z A-Z] would mean a pattern where you have lower case letter then a space and then an upper case letter. :)
Justin Woodward
@jwoo92
May 07 2016 09:09
okay, what is the reason for including the not ^?
ChloeHewitt
@ChloeHewitt
May 07 2016 09:09

function nextInLine(arr, item) {
  var x = arr.shift();
  var y = x.push(item);
  return y;  
}
This is clearly very wrong haha but I cant figure out why!! Anyone know??
Justin Woodward
@jwoo92
May 07 2016 09:09
and okay that makes sense. im just trying to understand it fully
Darth Skywalker
@adityaparab
May 07 2016 09:09
you want characters that are NOT a-zA-Z
so [^a-zA-Z]
EricOber
@EricOber
May 07 2016 09:10
can someone help me with my code please?
// 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 === "")
    delete collection[id][prop];
} 
  else if (value !== "tracks") {
    collection[id][prop] = value;
  }
  else {
    collection[id][prop].push(value)
  }

  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
Paweł Przytuła
@paprzytula
May 07 2016 09:11
@jwoo92 http://regexr.com/ left pane: Cheatsheet
Justin Woodward
@jwoo92
May 07 2016 09:11
so the .replace method is about finding the symbols i dont want and eliminating them? i originally thought im only trying to locate the desired letters hence [a-zA-Z]and that it will leave out whatever else was left over.
Travis
@dukenukethem
May 07 2016 09:13
@jwoo92 thats waht i thought at first oo!
Darth Skywalker
@adityaparab
May 07 2016 09:14
@jwoo92 : hehe. .replace matches the pattern provided and replcaes that with the 2nd parameter. :D Its nothing to do with replacing not matching thing.
Justin Woodward
@jwoo92
May 07 2016 09:14
@dukenukethem does that mean that the .replace is for finding and throwing out what you DO NOT want versus finding only what you DO want?
Darth Skywalker
@adityaparab
May 07 2016 09:15
we're providing a regex that matches non alphabets and so the non alphabets get replaced.
Travis
@dukenukethem
May 07 2016 09:16
If I'm reading it properly, yes
Justin Woodward
@jwoo92
May 07 2016 09:16
@adityaparab ohhhhhhhhh! so its reading replace anything NOT these letters with ''. that being no white space, it eliminates the relating symbol all together
Travis
@dukenukethem
May 07 2016 09:16
I could be way off though
Still a noob and not 100% with it
Darth Skywalker
@adityaparab
May 07 2016 09:18
@jwoo92 Let me clarify with an example.
var str = "asd@#$@#$adasdas#$%#$123123";

var res1 = str.replace(/[^a-zA-Z]/g,''); 
//res1 --> asdadasdas

var res2 = str.replace(/[a-zA-Z]/g,'');  // notice: no ^
// res2 --> @#$@#$a#$%#$123123
Travis
@dukenukethem
May 07 2016 09:18
returns a new string where the specified values are replaced.
Justin Woodward
@jwoo92
May 07 2016 09:19
@adityaparab it makes complete sense thank you so much for the extensive break down!
CamperBot
@camperbot
May 07 2016 09:19
jwoo92 sends brownie points to @adityaparab :sparkles: :thumbsup: :sparkles:
:warning: jwoo92 already gave adityaparab points
Justin Woodward
@jwoo92
May 07 2016 09:20
it is still not applying false when applicable

function palindrome(str) {
  str.replace(/[^a-zA-Z]/g, '');
  str.toLowerCase();
  var reverse = str.split('').reverse('').join('');

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

}



palindrome("eye");
Tony Brown
@anthonybrown
May 07 2016 09:21
@jwoo92 http://regexr.com/ left pane: Cheatsheet
awesome
Darth Skywalker
@adityaparab
May 07 2016 09:21
@jwoo92 : That must work lol. Will you try restaring you browser?
if you do it on code pen, see it works.
Justin Woodward
@jwoo92
May 07 2016 09:22
i refreshed and still the same result.
Darth Skywalker
@adityaparab
May 07 2016 09:23
oh! you should not have '' for reverse.
Justin Woodward
@jwoo92
May 07 2016 09:23
i can read and understand 100% what is going on and why on my code.
Darth Skywalker
@adityaparab
May 07 2016 09:23
it should be simply .reverse()
Justin Woodward
@jwoo92
May 07 2016 09:24
still not accepting

function palindrome(str) {
  str.replace(/[^a-zA-Z]/g, '');
  str.toLowerCase();
  var reverse = str.split('').reverse().join('');

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

}



palindrome("eye");
Tony Brown
@anthonybrown
May 07 2016 09:25
@jwoo92 because it's returning true
Darth Skywalker
@adityaparab
May 07 2016 09:25
Justin Woodward
@jwoo92
May 07 2016 09:25
@anthonybrown it runs this options as well and showing it is not returning true: palindrome("never odd or even") should return true.
Darth Skywalker
@adityaparab
May 07 2016 09:25
some issue with FCC may be.
Justin Woodward
@jwoo92
May 07 2016 09:26
This message was deleted
@adityaparab it is showing a red X for these : palindrome("A man, a plan, a canal. Panama") should return true.
palindrome("never odd or even") should return true.
Tony Brown
@anthonybrown
May 07 2016 09:27
@jwoo92 your code works
Justin Woodward
@jwoo92
May 07 2016 09:27
anything with a whitespace is showing not accepted
Tony Brown
@anthonybrown
May 07 2016 09:27
I just tested it, maybe I'm not understanding what you're asking
Justin Woodward
@jwoo92
May 07 2016 09:27
its only the ones originally with a whitespace failing
Tony Brown
@anthonybrown
May 07 2016 09:28
I see, change your regex to ignore white space
Mateusz Szymański
@matszym
May 07 2016 09:30

@jwoo92

str.replace(/[^a-zA-Z]/g, '');

should be

str = str.replace(/[^a-zA-Z]/g, '');
@jwoo92 strings are immutable
Coy Sanders
@coymeetsworld
May 07 2016 09:30
@ChloeHewitt did you get help? you want to push onto array, not on x
Paweł Przytuła
@paprzytula
May 07 2016 09:30
you should add .toLowerCase()
Mateusz Szymański
@matszym
May 07 2016 09:30
@jwoo92 like all primitives
Ajith
@ajithvallabai
May 07 2016 09:30
ya now it woeks for race car
@matszym
Darth Skywalker
@adityaparab
May 07 2016 09:31
@jwoo92 : @matszym is Correct. You need to store them in a variable.
Tony Brown
@anthonybrown
May 07 2016 09:31
@matszym FTW
Oscar
@Oscar3000
May 07 2016 09:31
hey guys pls in the profile-lookup, how did you write the if statement for "If firstName does not correspond to any contacts then return "No such contact"
Paweł Przytuła
@paprzytula
May 07 2016 09:32
@Oscar3000 you can move it outside: else "No such contact"
Justin Woodward
@jwoo92
May 07 2016 09:33
okay, so that solved all but ONE red X here is the only one not registering: palindrome("1 eye for of 1 eye.") should return false.
function palindrome(str) {
  str = str.replace(/[^a-zA-Z]/g, '');
  str = str.toLowerCase();
  var reverse = str.split('').reverse().join('');

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

}



palindrome("eye");
Ajith
@ajithvallabai
May 07 2016 09:33
change the replace line
with 0-9
Mateusz Szymański
@matszym
May 07 2016 09:34
dont
Darth Skywalker
@adityaparab
May 07 2016 09:34
@jwoo92 :change str = str.replace(/[^a-zA-Z]/g, ''); to str = str.replace(/[^a-zA-Z0-9]/g, '');
Oscar
@Oscar3000
May 07 2016 09:34
@paprzytula thanks bro i made things complicated by thinking you will need to write a condition for it
CamperBot
@camperbot
May 07 2016 09:34
oscar3000 sends brownie points to @paprzytula :sparkles: :thumbsup: :sparkles:
:cookie: 268 | @paprzytula |http://www.freecodecamp.com/paprzytula
Mateusz Szymański
@matszym
May 07 2016 09:34
send link to that palindrome
i think you shouldnt remove numbers
thats written in intrudution, what you should remove
Justin Woodward
@jwoo92
May 07 2016 09:35

directions: Return true if the given string is a palindrome. Otherwise, return false.

A palindrome is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing.

Note
You'll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything lower case in order to check for palindromes.

We'll pass strings with varying formats, such as "racecar", "RaceCar", and "race CAR" among others.

Ajith
@ajithvallabai
May 07 2016 09:35
thanks @adityaparab and @matszym it works
CamperBot
@camperbot
May 07 2016 09:35
ajithvallabai sends brownie points to @adityaparab and @matszym :sparkles: :thumbsup: :sparkles:
:cookie: 230 | @adityaparab |http://www.freecodecamp.com/adityaparab
:cookie: 44 | @matszym |http://www.freecodecamp.com/matszym
Darth Skywalker
@adityaparab
May 07 2016 09:35
@jwoo92 : Best reg ex so far str = str.replace(/[^\W]+/g, '');
Mateusz Szymański
@matszym
May 07 2016 09:35
numbers have to stay
Paweł Przytuła
@paprzytula
May 07 2016 09:36
I'd just do str = str.replace(/[^a-zA-Z]/g, '').toLowerCase();
Justin Woodward
@jwoo92
May 07 2016 09:36
ohhhhhh i was deleting my numbers thinking it was asking to eliminate then