These are chat archives for FreeCodeCamp/HelpJavaScript

4th
May 2017
Pieter Stokkink
@forkerino
May 04 2017 00:00
aaah, ok, misunderstood.
Vamp
@the-vampiire
May 04 2017 00:00
is there a better way to pull them all out?
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:00
@Giveback007 works well looks nice, well done
Vamp
@the-vampiire
May 04 2017 00:00
it has to be somewherre behind the scenes right?
an array of test cases it is running through?
Pieter Stokkink
@forkerino
May 04 2017 00:00
@the-vampiire I just copied all test cases at once from the instructions and pasted them in at regexr
Dovydas Stirpeika
@Giveback007
May 04 2017 00:00
@HeebieGeeBee thank you. any criticisms?
CamperBot
@camperbot
May 04 2017 00:00
giveback007 sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1549 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
Vamp
@the-vampiire
May 04 2017 00:01
but they say things like “should return"
and the formatting is messy, no?
Pieter Stokkink
@forkerino
May 04 2017 00:01
@the-vampiire yeah, you have to tweak it a little bit, but we have been talking about it longer than it would take you to do it.
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:02
@Giveback007 nope,
Vamp
@the-vampiire
May 04 2017 00:03
hahah as usual
Pieter Stokkink
@forkerino
May 04 2017 00:03
@pmnord those commas in your cases will break everything. You have to separate them out.
Manish Giri
@Manish-Giri
May 04 2017 00:04
giveback007
that's some username
Dovydas Stirpeika
@Giveback007
May 04 2017 00:04
@Manish-Giri what do you mean?
Fabusuyi David Oluwasegun
@dav4thevid
May 04 2017 00:04
hello everyone.......been stuck for hours in truncate a string in da algoritm
challenge
Pieter Stokkink
@forkerino
May 04 2017 00:05
bedtime! Laters!
bitcoinabdi
@bitcoinabdi
May 04 2017 00:05
afternoon guyz
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:05
@pmnord btw you cant make case statements like that
bitcoinabdi
@bitcoinabdi
May 04 2017 00:05
hows everyone doing
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:05
has to be case 2: case 3: case 4 etc etc
bitcoinabdi
@bitcoinabdi
May 04 2017 00:05
``` (shift+enter for line break)
var code = "formatted";
```
Fabusuyi David Oluwasegun
@dav4thevid
May 04 2017 00:05

here is my code
```

function truncateString(str, num) {
// Clear out that junk in your trunk
var truncd = '';
if (str.length > num) {
truncd = str.slice(0,num-3) + '...';
return truncd;
}
return str;
}

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

HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:05
@forkerino sleep well
Fabusuyi David Oluwasegun
@dav4thevid
May 04 2017 00:06

function truncateString(str, num) {
  // Clear out that junk in your trunk
  var truncd = '';
    if (str.length > num) {
        truncd = str.slice(0,num-3) + '...';
        return truncd;
    }
    return str;
} 


truncateString("A-tisket a-tasket A green and yellow basket", 11);
bitcoinabdi
@bitcoinabdi
May 04 2017 00:06
``` 

function chunkArrayInGroups(arr, size) {
// Break it up.
return arr;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);

```

help guyz
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:06
@bitcoinabdi doesnt look like youve tried anything
Fabusuyi David Oluwasegun
@dav4thevid
May 04 2017 00:07
help pls
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:07
@dav4thevid and you need to do more it seems
Jason G
@Jay33Canada
May 04 2017 00:07
ok i got it

function convertHTML(str) {
  // :)
  var re = /[&<>"']/g;
  var strHtml = str.replace(re, function(symbol){
    switch(symbol){
      case "&":
        return "&amp;";
      case "<":
        return "&lt;";
      case ">":
        return "&gt;";
      case '"':
        return "&quot;";
      case "'":
        return "&apos;";

    }
  });
  console.log(strHtml);
  return strHtml;
}
bitcoinabdi
@bitcoinabdi
May 04 2017 00:07
@HeebieGeeBee arr.splice(0,size);
i can split it up but i dont know how to add it up ? @HeebieGeeBee
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:08
@Jay33Canada well done
Fabusuyi David Oluwasegun
@dav4thevid
May 04 2017 00:08
@HeebieGeeBee do more how???
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:08
@bitcoinabdi how about pushing your splices into another array
@dav4thevid well theres like three different situations isnt there cant remember the challenge
Jason G
@Jay33Canada
May 04 2017 00:09

thanks @HeebieGeeBee
what's weird is, the case can be like this is you want it

case &: do something
case "&": do something

these do the same thing

CamperBot
@camperbot
May 04 2017 00:09
jay33canada sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1550 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
bitcoinabdi
@bitcoinabdi
May 04 2017 00:09
arr.push(arr.splice(0,size)); ? @HeebieGeeBee
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:09
@bitcoinabdi well a different array to the one youre splicing from might be good
but yeah something like that
Fabusuyi David Oluwasegun
@dav4thevid
May 04 2017 00:10
@HeebieGeeBee all has passed except for
truncateString("A-", 1) should return "A...".
truncateString("Absolutely Longer", 2) should return "Ab...".
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:11
@Jay33Canada i wouldnt have thought that should be right but fair enough if it is
@dav4thevid right so whats the situation with those test cases that make them different to the others
Jason G
@Jay33Canada
May 04 2017 00:12
ya it's interesting. i did typeof on the symbol that the regex is matching in replace(). it's a string. so, i guess the switch statement doesn't check for === it must be ==
oh wait, i tried it again and it didn't work lol that's weird. i guess it does use ===
jusgoose
@gusd773
May 04 2017 00:13
blob
anybody wanna help need for some reason this code works for the first example but not the last two which are exactly the same for the "make object properties private" challenge
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:13
@Jay33Canada i just got errors when i tried it without quotes
@Jay33Canada even if it was only == it should still fail
Jason G
@Jay33Canada
May 04 2017 00:14
@HeebieGeeBee i was wrong sorry. it doesn't work without the "". I'm not sure why it did that one time
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:14
no worries good you kept testing though
@gusd773 just do a straight assignment in your setgear function
jusgoose
@gusd773
May 04 2017 00:16
@HeebieGeeBee wdym?
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:16
just = not +=
jusgoose
@gusd773
May 04 2017 00:17
nvm just got it, thanks but can you explain the differnce? @HeebieGeeBee
CamperBot
@camperbot
May 04 2017 00:17
gusd773 sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1551 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
Vamp
@the-vampiire
May 04 2017 00:17
@forkerino am I doing this right…lmao

var map = {

    "should return true." : '\n',
    "should return a boolean." : '\n'
};



var str = 'telephoneCheck("555-555-5555") should return a boolean.\
telephoneCheck("1 555-555-5555") should return true.\
telephoneCheck("1 (555) 555-5555") should return true. \
telephoneCheck("5555555555") should return true. \
telephoneCheck("555-555-5555") should return true. \
telephoneCheck("(555)555-5555") should return true. \
telephoneCheck("1(555)555-5555") should return true.\
telephoneCheck("555-5555") should return false.\
telephoneCheck("5555555") should return false.\
telephoneCheck("1 555)555-5555") should return false.\
telephoneCheck("1 555 555 5555") should return true.\
telephoneCheck("1 456 789 4444") should return true.\
telephoneCheck("123**&!!asdf#") should return false.\
telephoneCheck("55555555") should return false.\
telephoneCheck("(6505552368)") should return false\
telephoneCheck("2 (757) 622-7382") should return false.\
telephoneCheck("0 (757) 622-7382") should return false.\
telephoneCheck("-1 (757) 622-7382") should return false\
telephoneCheck("2 757 622-7382") should return false.\
telephoneCheck("10 (757) 622-7382") should return false.\
telephoneCheck("27576227382") should return false.\
telephoneCheck("(275)76227382") should return false.\
telephoneCheck("2(757)6227382") should return false.\
telephoneCheck("2(757)622-7382") should return false.\
telephoneCheck("555)-555-5555") should return false.\
telephoneCheck("(555-555-5555") should return false.\
telephoneCheck("(555)5(55?)-5555") should return false.';


var replaced = str.replace(/(should return a boolean.)|(should return true.)/, function(m){return map[m];});

console.log(replaced);
yo dawg...
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:17
@gusd773 cus youre just setting the gear not increasing it
Vamp
@the-vampiire
May 04 2017 00:18
problem is its stopping after replacing the first instance
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:18
@the-vampiire he's gone bed, but no, no youre not
Vamp
@the-vampiire
May 04 2017 00:18
damn it
what’d I do wrong
I thought it would replace all instances
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:19
@the-vampiire what do you mean?
Vamp
@the-vampiire
May 04 2017 00:19
well
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:19
you have one hugely long string
Vamp
@the-vampiire
May 04 2017 00:19
right now it replaces the first capture group (should return a boolean)
but none of the others
I know
I copied and pasted all the test cases
I want to use regex to then use the result in my regex test..
I need to strip out all the unneeded parts. I thought using | between capture groups meant it would look for matches of “or”
bitcoinabdi
@bitcoinabdi
May 04 2017 00:21
function chunkArrayInGroups(arr, size) {
  // Break it up.
  var aa = arr.splice(0,arr.length-size);
  var a2 = arr.splice(0,size);
  return aa.push(arr.splice(0,size));

}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
@HeebieGeeBee please see
Vamp
@the-vampiire
May 04 2017 00:22
works on regex101 but not in practice
am I missing something here?

var map = {

    "should return true." : '\n',
    "should return false." : '\n',
    "should return a boolean." : '\n'
};



var str = 'telephoneCheck("555-555-5555") should return a boolean.\
telephoneCheck("1 555-555-5555") should return true.\
telephoneCheck("1 (555) 555-5555") should return true. \
telephoneCheck("5555555555") should return true. \
telephoneCheck("555-555-5555") should return true. \
telephoneCheck("(555)555-5555") should return true. \
telephoneCheck("1(555)555-5555") should return true.\
telephoneCheck("555-5555") should return false.\
telephoneCheck("5555555") should return false.\
telephoneCheck("1 555)555-5555") should return false.\
telephoneCheck("1 555 555 5555") should return true.\
telephoneCheck("1 456 789 4444") should return true.\
telephoneCheck("123**&!!asdf#") should return false.\
telephoneCheck("55555555") should return false.\
telephoneCheck("(6505552368)") should return false\
telephoneCheck("2 (757) 622-7382") should return false.\
telephoneCheck("0 (757) 622-7382") should return false.\
telephoneCheck("-1 (757) 622-7382") should return false\
telephoneCheck("2 757 622-7382") should return false.\
telephoneCheck("10 (757) 622-7382") should return false.\
telephoneCheck("27576227382") should return false.\
telephoneCheck("(275)76227382") should return false.\
telephoneCheck("2(757)6227382") should return false.\
telephoneCheck("2(757)622-7382") should return false.\
telephoneCheck("555)-555-5555") should return false.\
telephoneCheck("(555-555-5555") should return false.\
telephoneCheck("(555)5(55?)-5555") should return false.';


var replaced = str.replace(/(should return true.)|(should return false.)|(should return a boolean.)/, function(m){return map[m];});

console.log(replaced);
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:25
@the-vampiire use the global flag
Vamp
@the-vampiire
May 04 2017 00:26
ah
brilliant
regex101 had that included implicitly
aww yee
telephoneCheck("555-555-5555") 
telephoneCheck("1 555-555-5555") 
telephoneCheck("1 (555) 555-5555") 
 telephoneCheck("5555555555") 
 telephoneCheck("555-555-5555") 
 telephoneCheck("(555)555-5555") 
 telephoneCheck("1(555)555-5555") 
telephoneCheck("555-5555") 
telephoneCheck("5555555") 
telephoneCheck("1 555)555-5555") 
telephoneCheck("1 555 555 5555") 
telephoneCheck("1 456 789 4444") 
telephoneCheck("123**&!!asdf#") 
telephoneCheck("55555555") 
telephoneCheck("(6505552368)") undefinedelephoneCheck("2 (757) 622-7382") 
telephoneCheck("0 (757) 622-7382") 
telephoneCheck("-1 (757) 622-7382") undefinedelephoneCheck("2 757 622-7382") 
telephoneCheck("10 (757) 622-7382") 
telephoneCheck("27576227382") 
telephoneCheck("(275)76227382") 
telephoneCheck("2(757)6227382") 
telephoneCheck("2(757)622-7382") 
telephoneCheck("555)-555-5555") 
telephoneCheck("(555-555-5555") 
telephoneCheck("(555)5(55?)-5555")
:D
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:28
@bitcoinabdi you should probably be using soem kind of loop so it will work for however long the array is and hoever much the size is
RonnyNovik
@RonnyNovik
May 04 2017 00:32
Hey can someone help me with triggering an animation when you scroll to a certain point?

$(window).scroll(function() {
if ($(window).scrollTop()) < $(".parallax") - 100 ) {
$( "#blackbox" ).fadeIn(400);
}

});
});

why it doesn't trigger the fade in when i reach to that point?
Vamp
@the-vampiire
May 04 2017 00:34
muahaha

var map = {

    "should return true." : '\n',
    "should return false." : '\n',
    "should return a boolean." : '\n',
    "should return false" : '\n',
    "should return true" : '\n',
    "telephoneCheck(" : '',
    '")' : '"',
    '.' : '',
    '"' : ''
};



var str = 'telephoneCheck("555-555-5555") should return a boolean.\
telephoneCheck("1 555-555-5555") should return true.\
telephoneCheck("1 (555) 555-5555") should return true. \
telephoneCheck("5555555555") should return true. \
telephoneCheck("555-555-5555") should return true. \
telephoneCheck("(555)555-5555") should return true. \
telephoneCheck("1(555)555-5555") should return true.\
telephoneCheck("555-5555") should return false.\
telephoneCheck("5555555") should return false.\
telephoneCheck("1 555)555-5555") should return false.\
telephoneCheck("1 555 555 5555") should return true.\
telephoneCheck("1 456 789 4444") should return true.\
telephoneCheck("123**&!!asdf#") should return false.\
telephoneCheck("55555555") should return false.\
telephoneCheck("(6505552368)") should return false\
telephoneCheck("2 (757) 622-7382") should return false.\
telephoneCheck("0 (757) 622-7382") should return false.\
telephoneCheck("-1 (757) 622-7382") should return false\
telephoneCheck("2 757 622-7382") should return false.\
telephoneCheck("10 (757) 622-7382") should return false.\
telephoneCheck("27576227382") should return false.\
telephoneCheck("(275)76227382") should return false.\
telephoneCheck("2(757)6227382") should return false.\
telephoneCheck("2(757)622-7382") should return false.\
telephoneCheck("555)-555-5555") should return false.\
telephoneCheck("(555-555-5555") should return false.\
telephoneCheck("(555)5(55?)-5555") should return false.';


var replaced = str.replace(/(")|("\))|(telephoneCheck\()|(should return true)|(should return false)|(should return a boolean.)|(\.)/g, function(m){return map[m];});
console.log(replaced);
output
555-555-5555) 
1 555-555-5555) 
1 (555) 555-5555) 
 5555555555) 
 555-555-5555) 
 (555)555-5555) 
 1(555)555-5555) 
555-5555) 
5555555) 
1 555)555-5555) 
1 555 555 5555) 
1 456 789 4444) 
123**&!!asdf#) 
55555555) 
(6505552368)) 
2 (757) 622-7382) 
0 (757) 622-7382) 
-1 (757) 622-7382) 
2 757 622-7382) 
10 (757) 622-7382) 
27576227382) 
(275)76227382) 
2(757)6227382) 
2(757)622-7382) 
555)-555-5555) 
(555-555-5555) 
(555)5(55?)-5555)
byauza
@byauza
May 04 2017 00:35
I'm tring to do a var remainder. I understand 11%3=2 but it says Invalid Left hand side in assignment. Do I put this after var remainder; or in a new line?
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:36
@RonnyNovik look at where your parenthesis are
@byauza you need to just assign the equation to the variable
not the result
the idea is to make the program do the math for us
byauza
@byauza
May 04 2017 00:39
ok, so I only need to input 11 % 3
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:39
yes
@the-vampiire well done
Vamp
@the-vampiire
May 04 2017 00:40
now onto that whole algorithm solution thing…lol
byauza
@byauza
May 04 2017 00:40
ok, i get that. But now it says 3 is not a function. Am I missing a ; or something?
Vamp
@the-vampiire
May 04 2017 00:41
I gotta say though I am feeling much better abiut regex. didnt solve the algo yet but I learned a lot today
RonnyNovik
@RonnyNovik
May 04 2017 00:41
@HeebieGeeBee What do you mean
I really cant see the problem haha
Vamp
@the-vampiire
May 04 2017 00:41
@byauza post code
byauza
@byauza
May 04 2017 00:41
i know. Sorry, how do i do a screenshot?
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:41
@byauza your emeant to assign that equation to the remainder variable
Nathan Vu
@NathanVu
May 04 2017 00:41
var someProp = "propName";
var myObj = {
  propName: "Some Value"
}
myObj[someProp]; // "Some Value"
FlashHero
@FlashHero
May 04 2017 00:42
@cmccormack thanks
CamperBot
@camperbot
May 04 2017 00:42
flashhero sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 513 | @cmccormack |http://www.freecodecamp.com/cmccormack
Nathan Vu
@NathanVu
May 04 2017 00:42
guys I don't understand what is happening here and why it's printing out
"some value"
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:42
@RonnyNovik if ($(window).scrollTop()) < $(".parallax") - 100 ) { do you want the closing parenthesis after the scolltop method for this if statement?
Vamp
@the-vampiire
May 04 2017 00:42
@Jay33Canada hah nice man went with the switch like me. why didnt you use replace? didn work?
Jason G
@Jay33Canada
May 04 2017 00:43
i did use the replace method but with a function as the second argument @the-vampiire :smile: )
RonnyNovik
@RonnyNovik
May 04 2017 00:44

$(window).scroll(function() {
if ($(window).scrollTop()) > $(".parallax").height() - 100 ) {
$( "#blackbox" ).fadeIn(400);
})

});
});
still doesnt work

byauza
@byauza
May 04 2017 00:44
is this correct? var remainder; 11 % 3
RonnyNovik
@RonnyNovik
May 04 2017 00:44
Sorry this is the work
$(window).scroll(function() {

$(window).scroll(function() {
if ($(window).scrollTop()) > $(".parallax").height() - 100 )) {
$( "#blackbox" ).fadeIn(400);
})

});
});

HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:44
@RonnyNovik doesnt look like youve chenged it
c0d0er2
@c0d0er2
May 04 2017 00:45

Can somebody please help me with Build JavaScript Objects in JavaScript? Here is my code:

// Example
var ourDog = {
  "name": "Camper",
  "legs": 4,
  "tails": 1,
  "friends": ["everything!"]
};

// Only change code below this line.

var dog = {
  "name": "Rex",
  "legs": 4,
  "tails": 1,
  "friends": ["Nice animals"]
};

Here is the link: https://www.freecodecamp.com/challenges/build-javascript-objects

HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:45
@byauza you need to assign in
Vamp
@the-vampiire
May 04 2017 00:45
@Jay33Canada oh look at this guy. mixing it up haha
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:45
var remainder = 11%3
RonnyNovik
@RonnyNovik
May 04 2017 00:46

$(window).scroll(function() {
if ($(window).scrollTop() > $(".parallax").height() - 100 )) {
$( "#blackbox" ).fadeIn(400);
}

});
}); still doesn't work

Jason G
@Jay33Canada
May 04 2017 00:46
lol @the-vampiire
Vamp
@the-vampiire
May 04 2017 00:47
@c0d0er2 you changed the variable name
it isnt dog it’s myDog
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:47
@RonnyNovik have you checked all your values youre comparing are right?
byauza
@byauza
May 04 2017 00:47
@HeebieGeeBee the response I get is typeerror, 3 is not a function.
Vamp
@the-vampiire
May 04 2017 00:47
@byauza post. the. code
c0d0er2
@c0d0er2
May 04 2017 00:47
@the-vampiire Thanks! I really appreciate!
CamperBot
@camperbot
May 04 2017 00:47
c0d0er2 sends brownie points to @the-vampiire :sparkles: :thumbsup: :sparkles:
:cookie: 348 | @the-vampiire |http://www.freecodecamp.com/the-vampiire
Vamp
@the-vampiire
May 04 2017 00:48
welcome
byauza
@byauza
May 04 2017 00:48
@the-vampiire how do I do that?
Vamp
@the-vampiire
May 04 2017 00:48
highlight the code
copy
paste in here
byauza
@byauza
May 04 2017 00:48

// Only change code below this line

var remainder = 11%3

Vamp
@the-vampiire
May 04 2017 00:48
all of it
everything in the grey box
RonnyNovik
@RonnyNovik
May 04 2017 00:48
@HeebieGeeBee Well the parallax div height is 1000 so i want it to trigger when the user is going down 900px
byauza
@byauza
May 04 2017 00:48
that's it
Vamp
@the-vampiire
May 04 2017 00:49
post a link to the code
to the question*
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:49
@byauza put a semi colon on the end and then refresh your browser page and run the test again
@HeebieGeeBee Thanks. i was mising the semi colon
CamperBot
@camperbot
May 04 2017 00:49
byauza sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1552 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
Vamp
@the-vampiire
May 04 2017 00:50
@byauza see how there is a red ‘x’ next to that line?
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:50
@RonnyNovik and what does scrollTop return?
Vamp
@the-vampiire
May 04 2017 00:50
i f you hover over it it will tell you what is wron with that line
byauza
@byauza
May 04 2017 00:50
yah, I knew I was missing something
Vamp
@the-vampiire
May 04 2017 00:50
in this case you were missing ‘;'
hover over the x though it will tell you exactly what’s wrong
byauza
@byauza
May 04 2017 00:51
thanks
Vamp
@the-vampiire
May 04 2017 00:51
Screen Shot 2017-05-03 at 8.50.53 PM.png
see
RonnyNovik
@RonnyNovik
May 04 2017 00:51
@HeebieGeeBee how much pixels got scrolled from the top of the document no?
Vamp
@the-vampiire
May 04 2017 00:52
$(window).scroll(function() {
    if ($(window).scrollTop() > $(".parallax").height() - 100 )) {
        $( "#blackbox" ).fadeIn(400);
    }
});
});
looks like you have an extra set of });
Umerie Ugochukwu
@ugumerie
May 04 2017 00:52
@c0d0er2 the object name is myDog
RonnyNovik
@RonnyNovik
May 04 2017 00:53

@the-vampiire $( document ).ready(function() {
//Menu Hover effects
$( "ul" ).hover(
function() {
$(this).addClass("shadow", 100 );
}, function() {
$(this).removeClass("shadow" , 100);
});
//Button effects
//Parallax effects
$(window).scroll(function() {
if ($(window).scrollTop() > $(".parallax").height() - 100 )) {
$( "#blackbox" ).fadeIn(400);
}

});
});
this is the whole code

HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:53
@RonnyNovik i dont know whats why i was asking
Vamp
@the-vampiire
May 04 2017 00:53
@RonnyNovik post like this
```js
new line
paste code here
new line
```
HeebieGeeBee
@HeebieGeeBee
May 04 2017 00:54
console log it and see if you get a value returned that will compare to the other value properly
FlashHero
@FlashHero
May 04 2017 00:54
@NathanVu someProp is not part of the myObj but you would put quotes when accessing the value using bracket notation so myObj['someProp'];
Vamp
@the-vampiire
May 04 2017 00:54
$( document ).ready(function() {
//Menu Hover effects
    $( "ul" ).hover(
        function() {
            $(this).addClass("shadow", 100 );
        }, function() {
            $(this).removeClass("shadow" , 100);
        });
//Button effects
//Parallax effects
    $(window).scroll(function() {
        if ($(window).scrollTop() > $(".parallax").height() - 100 )) // one too many ‘)’ right here {
        $( "#blackbox" ).fadeIn(400);
    }
});
});
you have a mispalce ‘)'
correct code:
$( document ).ready(function() {
//Menu Hover effects
    $( "ul" ).hover(
        function() {
            $(this).addClass("shadow", 100 );
        }, function() {
            $(this).removeClass("shadow" , 100);
        });
//Button effects
//Parallax effects
    $(window).scroll(function() {
        if ($(window).scrollTop() > $(".parallax").height() - 100 ){
        $( "#blackbox" ).fadeIn(400);
    }
});
});
RonnyNovik
@RonnyNovik
May 04 2017 00:56
@HeebieGeeBee @the-vampiire Thank you both!
\
CamperBot
@camperbot
May 04 2017 00:56
ronnynovik sends brownie points to @heebiegeebee and @the-vampiire :sparkles: :thumbsup: :sparkles:
:star2: 1553 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
:cookie: 349 | @the-vampiire |http://www.freecodecamp.com/the-vampiire
Vamp
@the-vampiire
May 04 2017 00:57
welcome
tech-tron
@tech-tron
May 04 2017 01:06
why cant you add an object to an array
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:06
@tech-tron you can
tech-tron
@tech-tron
May 04 2017 01:06
im trying to make an array of objects but when i
Array += Object
it return "[Object Object]"
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:07
thats not how you put anything in an array
tech-tron
@tech-tron
May 04 2017 01:07
hahaha
so concat
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:07
no push unshift or splice
concat is for adding arrays together
tech-tron
@tech-tron
May 04 2017 01:09
thanks @HeebieGeeBee
CamperBot
@camperbot
May 04 2017 01:09
tech-tron sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1554 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
tech-tron
@tech-tron
May 04 2017 01:09
can i ask one more question, i know you wont get no points but why unshift
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:09
np
tech-tron
@tech-tron
May 04 2017 01:09
instead of push
Vamp
@the-vampiire
May 04 2017 01:09

@HeebieGeeBee any idea why

/^(1?)/g

isn’t matching whether the number begins with 1 ?

HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:09
unshift adds elements tot the front of the array
push to the end
@the-vampiire what do you mean?
Vamp
@the-vampiire
May 04 2017 01:10
doesnt that mean begins with zero or one matches of the character ‘1'
^ asserts position at start of the string
1st Capturing Group (1?)
1? matches the character 1 literally (case sensitive)
? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)
Global pattern flags
g modifier: global. All matches (don't return after first match)
seems to work for letters but isnt working for numbers...
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:13
@the-vampiire are you testing numbers in string form or just straight numbers?
Vamp
@the-vampiire
May 04 2017 01:13
Screen Shot 2017-05-03 at 9.13.34 PM.png
@HeebieGeeBee
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:15
@the-vampiire how do you know it isnt working?
Vamp
@the-vampiire
May 04 2017 01:15
its not highlighted
Screen Shot 2017-05-03 at 9.16.21 PM.png
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:16
move a string with 1 at the start to the top line
Vamp
@the-vampiire
May 04 2017 01:16
ohh shit
its considering it all as one string
and thus it isnt starting with 1
damn it. thanks
well shit
what was the point of filtering all that stuff out then lol i thought you guys had suggested running all the test cases through a regex builder to see when it passes
actully shouldnt they all be highlighted? I said 0 or 1 times. the first item has it 0 times should be highlighted...
Zachary
@Bazill03
May 04 2017 01:18

Hey guys I'm having some difficulty with objects. Say I have a list of items you can look at. Like door and lamp. I have an object like this:

rooms: [
    {
    name: 'strange room',
    look: ['old door, torch'],
    commands: [
      {
        input: 'look door',
        result: function() {
          print("A large oak door lays before you. Try typing 'open old door' to find out whats on the other side.");
          },
      },
      {
        input: 'look torch',
        result: function(){
          print("The torch lays lifeless on the ground.");
          },
      },

I also take in input. So if the user types look door, I need to look up the input, and print the result but I'm hitting a brick wall with how to implement that. Any tips?

HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:19
@the-vampiire all those numbers are just one long string isnt it?
Vamp
@the-vampiire
May 04 2017 01:19
ya
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:19
@the-vampiire and i didnt use every test case number, i just used the vaild forms
Vamp
@the-vampiire
May 04 2017 01:20
lol
im legally retarded
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:22
@Bazill03 there isnt a print command in javascript
but where are you hoping to print it to?
and objects just hold data you will need to call their data somewhere
even if some of that data is a function
Zachary
@Bazill03
May 04 2017 01:23
@HeebieGeeBee I made a print function. I should probably name it something else.
Vamp
@the-vampiire
May 04 2017 01:23
@HeebieGeeBee maybe I am looking at this wrong. is using ‘?’ a way to say “pass if there is 0 or 1 of these characters”?
like
/^(1?)(\(?)[0-9]{3}(\)?)(-?)[0-9]{3}(-?)[0-9]{4}/g
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:24
@the-vampiire i cant remember what it means if you use it inside the capture group
Vamp
@the-vampiire
May 04 2017 01:24
may or may not start with 1
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:25
i used it outside to match 1 or 0 of that capture group
Zachary
@Bazill03
May 04 2017 01:25
@HeebieGeeBee I'm making a text adventure game. When the user types 'look door' I want to look up the look door input and run the result. I just don't know how to dynamically look it up.
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:25
@Bazill03 and youre getting the input from a html form input element?
Vamp
@the-vampiire
May 04 2017 01:26
@Bazill03 like
rooms.commands[input] = ‘look torch'
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:27
@the-vampiire /^(1)?/
Zachary
@Bazill03
May 04 2017 01:27
@HeebieGeeBee I believe so. I have it set up so that when the user presses enter I set the value of the textbox to a variable and run from there.
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:28
right so you can set it so on click of that submit button
Vamp
@the-vampiire
May 04 2017 01:28
@HeebieGeeBee I think youre right
/^(1)?( )?(\()?[0-9]{3}(\))?(-)?( )?[0-9]{3}(-)?( )?[0-9]{4}/g
fuckin hell that looks so alien lol
mjay
@mjay13
May 04 2017 01:29
Hey, I'm having trouble coming up with an algorithm, I'm not sure how it's supposed to look. I'm trying to convert celsius to fahrenheit
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:29
you get the value from the form and use it for a lookup in the object
{
         'look torch' :  function(){
          print("The torch lays lifeless on the ground.");
          },
more something like that @Bazill03
and you put all in the inputs in an object called inputs
button.on('mousedown', function() {
        return inputs[formValue];
}
as an example obviously you need to setup all the variable names
i guess you dont need to return it if its just running a function from the inputs object
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:35
but then if you say print is a function you have written yourself
var inputs = {
'look torch': print("The torch lays lifeless on the ground."),
'look door': print("A large oak door lays before you. Try typing 'open old door' to find out whats on the other side.")
}
could just do something like that @Bazill03
mharob
@mharob
May 04 2017 01:37
Having issue with the Using Objects for Lookups challenge. Code:
var lookup = {
"alpha":result = "Adams",
"bravo":result = "Boston",
"charlie":result = "Chicago",
"delta":result = "Denver",
"echo":result = "Easy",
"foxtrot":result = "Frank",
"":result = undefined
};
Zachary
@Bazill03
May 04 2017 01:37
@HeebieGeeBee I think that might work. Thanks!
CamperBot
@camperbot
May 04 2017 01:37
bazill03 sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1555 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:38
though i would change that name cus i think print might open up the printer option in some browsers @Bazill03
mjay
@mjay13
May 04 2017 01:38
I'm having trouble figuring out how an algorithm is supposed to look for the 'Convert Celsius to Fahrenheit' challenge
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:39
@mharob dont put result =
Zachary
@Bazill03
May 04 2017 01:39
@HeebieGeeBee You know, earlier(I'm not sure what I did) I did have a problem with the print menu opening repeatedly. You just answered that question for me. :tongue:
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:39
@Bazill03 lol
mharob
@mharob
May 04 2017 01:39
@HeebieGeeBee Alright thanks.
CamperBot
@camperbot
May 04 2017 01:39
mharob sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1556 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
Long Nguyen
@longnt80
May 04 2017 01:39
@mjay13 copy your code here
mjay
@mjay13
May 04 2017 01:40

function convertToF(celsius) {
var fahrenheit;
// Only change code below this line

fahrenheit = (celsius * 9/5) + 32

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

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

RiZ266
@RiZ266
May 04 2017 01:41
so Im at the return early pattern foro funtions lesson in basic javascript and i cant figure it out
i keep missing 2 of the objectives
mharob
@mharob
May 04 2017 01:41
@HeebieGeeBee Still not meeting the tests. Code:
var lookup = {
"alpha":"Adams",
"bravo":"Boston",
"charlie":"Chicago",
"delta":"Denver",
"echo":"Easy",
"foxtrot":"Frank",
"":undefined
};
Simranjit Singh
@sim3001
May 04 2017 01:41
@mjay try to remove the brackets around Celsius *9/5
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:42
@mharob theres still more to do in that challenge
need to assign the a value from the lookup object to the result variable
mjay
@mjay13
May 04 2017 01:42
ugh. so simple. i tried way too many things other things and it got complicated. thanks! @sim3001
CamperBot
@camperbot
May 04 2017 01:42
mjay13 sends brownie points to @sim3001 :sparkles: :thumbsup: :sparkles:
:cookie: 262 | @sim3001 |http://www.freecodecamp.com/sim3001
RiZ266
@RiZ266
May 04 2017 01:43

// Setup
function abTest(a, b) {
// Only change code below this line
switch (a, b) {
case a < 0:
case b < 0:
return undefined;
break;
}

// Only change code above this line

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

// Change values below to test your code
abTest(2,2);

Simranjit Singh
@sim3001
May 04 2017 01:43
@mjay13 no worries sometimes the simplest errors have us trying the most complex fixes. Cheers.
mjay
@mjay13
May 04 2017 01:44
so true @sim3001
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:45
@RiZ266 you need to make a conditional for an if statement asking if a is less than 0 or b is less than 0 if so return undefined
bitcoinabdi
@bitcoinabdi
May 04 2017 01:45
@HeebieGeeBee how would the loop look like ? am working on Chunky Monkey
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:46
@bitcoinabdi if youre splicing first make a copy of the array by doing something like var copyArr = arr.slice()l
then have you loop variable codntional based on teh arr.length
RiZ266
@RiZ266
May 04 2017 01:47
@HeebieGeeBee ah okay thank ill try that
CamperBot
@camperbot
May 04 2017 01:47
riz266 sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1557 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
Micsunderland3
@Micsunderland3
May 04 2017 01:47
Can someone check out a bit of my node code its driving me bonkers.
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:47
and have it increase by the size on each iteration
Mario A. Carlos
@MarioC3
May 04 2017 01:47
I have a question...
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:48
@bitcoinabdi but dont splice from the same array that your using for the loop conditional
This is my code"

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++;
      break;

    case 10:
    case 'J':
    case 'Q':
    case 'K':
    case 'A':
      count--;
      break;

    default:
      count = count + 0;
      }

  if (count <= 0){
    return count + ' Hold';
  }

  else {
    return count + 'Bet';
  }

  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
I can't figure why is not adding it all up?
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:49
@MarioC3 space before Bet
like you did with the hold string
Mario A. Carlos
@MarioC3
May 04 2017 01:49
oh are you kidding me????
hahahahah
Micsunderland3
@Micsunderland3
May 04 2017 01:49
hahaha
Mario A. Carlos
@MarioC3
May 04 2017 01:49
lol that work like a charm
Thanks @HeebieGeeBee
CamperBot
@camperbot
May 04 2017 01:50
marioc3 sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1558 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
Mario A. Carlos
@MarioC3
May 04 2017 01:50
Lifesaver
HeebieGeeBee
@HeebieGeeBee
May 04 2017 01:50
yw
Ivan J Badia
@IvanJB
May 04 2017 01:51
I had the same problem...you feel so silly for missing a simple step
Jeff
@etisdew
May 04 2017 01:51
hey guys I just started a repo for something I've been wanting to make this'll be my first git project and I'm learning as I go, please feel inclined to invite yourselves to it for a first project as I learn es6 to accomplish this end. Noob friendly project! etisdew.website
zxyango
@zxyango
May 04 2017 01:51
explanation
switch will take on arguements cc(2), cc(3),cc(4), cc(5),cc(6)
since 2,3,4,5,6 are all part of count++ part
switch will increment the count 5 times
and the count will then become equal to 5
after that if(count>0) function will work and return "5 bet" @MarioC3
Mario A. Carlos
@MarioC3
May 04 2017 01:52
Hahaha Yeah... at least I understood the content and gt it wrong because a stupid space lol
Thanks @zxyango
CamperBot
@camperbot
May 04 2017 01:52
marioc3 sends brownie points to @zxyango :sparkles: :thumbsup: :sparkles:
:cookie: 219 | @zxyango |http://www.freecodecamp.com/zxyango
Jeff
@etisdew
May 04 2017 01:53
i used a switch to increment and decriment then a turnary return if that helps you
Vamp
@the-vampiire
May 04 2017 01:55
man Im getting close
^(1)?( )?([0-9]{3}|(\([0-9]{3}\))?|[0-9]{3})(-)?( )?[0-9]{3}(-)?( )?[0-9]{4}
Jeff
@etisdew
May 04 2017 01:55
wth you working on vamp?
Vamp
@the-vampiire
May 04 2017 01:55
the only cases im failing are short ones (no country or area code) and short ones (6 digits)
i dont see how though
working on my love for regex…not going well
this is for the phone numebrs algo
Jeff
@etisdew
May 04 2017 01:56
ew regex but yours is very readable, been deferring how to update mine for tlds
bitcoinabdi
@bitcoinabdi
May 04 2017 01:56
function chunkArrayInGroups(arr, size) {
  // Break it up.
  var aa = arr.splice(0,arr.length-size);
  var a2 = arr.splice(0,size);
  var rr= [];
  return rr.concat([aa],[a2]);

}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
@HeebieGeeBee i dont understand why this would not work for all of them
Devon Thomas
@UmbraLegacy
May 04 2017 01:59
@bitcoinabdi , I can try to help you.
Vamp
@the-vampiire
May 04 2017 01:59
I dont think thats how concat works is it
@etisdew very readable. is that a joke lol
bitcoinabdi
@bitcoinabdi
May 04 2017 01:59
@UmbraLegacy please do
Vamp
@the-vampiire
May 04 2017 02:01
@bitcoinabdi have you tried
return rr.concat(aa, a2);
Devon Thomas
@UmbraLegacy
May 04 2017 02:01
@the-vampiire , that doesn't help.
Jeff
@etisdew
May 04 2017 02:02
@the-vampiire no I think you just taught me how it works ^ begins with and the rest is ternary with parameters
so that means ~ and the others probably have the same meanings aswell
Vamp
@the-vampiire
May 04 2017 02:02
what
@etisdew ?
well splice is returning an array so he is putting arrays within arrays, is that the goal?
sunnyr791
@sunnyr791
May 04 2017 02:03

hello everyone! Having some trouble getting the output of -->

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

console.log(a<0||b<0);
return undefined;

console.log(a>0 && b>0); //error occurs here

// Only change code above this line

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

// Change values below to test your code
abTest(2,2);

Christian Balderrama
@christianbalderrama
May 04 2017 02:03

Hi guys I need a little help here on Profile Lookup


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


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

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

Its not working, but I think its good enough. Could someone trace where I'm wrong. Cheers.

sunnyr791
@sunnyr791
May 04 2017 02:05
blob
any feedback is welcome!
Christian Balderrama
@christianbalderrama
May 04 2017 02:05
@HeebieGeeBee hi its not working only the akira address was working said in the todos
bitcoinabdi
@bitcoinabdi
May 04 2017 02:05
@the-vampiire it gives me a result without the []
Vamp
@the-vampiire
May 04 2017 02:06

@christianbalderrama

consider what happens when a loop reaches a return statement

which is the case for your code if the contact being searched for is not found in the first iteraton of the loop
Jeff
@etisdew
May 04 2017 02:06
is that returning the props array?
Vamp
@the-vampiire
May 04 2017 02:07
also use ‘===‘ strict checking
@christianbalderrama your code is perfect except for one thing
Christian Balderrama
@christianbalderrama
May 04 2017 02:07
okay thanks i'll tryi t.
sunnyr791
@sunnyr791
May 04 2017 02:08
Please help
Long Nguyen
@longnt80
May 04 2017 02:08
@christianbalderrama
if(contacts[i].hasOwnProperty(prop) == true)
you only need it like this:
if( contacts[i].hasOwnProperty(prop) )
Christian Balderrama
@christianbalderrama
May 04 2017 02:08
thanks. I get the idea now vampire, i'll add a flag if its found or not?
Vamp
@the-vampiire
May 04 2017 02:08
@christianbalderrama you only want to return no contact found if you have looped through all the contacts (complete the loop) and not found it, ya?
Jeff
@etisdew
May 04 2017 02:08
can you just use a break instead?
Christian Balderrama
@christianbalderrama
May 04 2017 02:09
thanks @the-vampiire and @longnt80 yes long i tried it also and it makes sense since the hasOwnProp api returns a true statement
CamperBot
@camperbot
May 04 2017 02:09
christianbalderrama sends brownie points to @the-vampiire and @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 207 | @longnt80 |http://www.freecodecamp.com/longnt80
:cookie: 350 | @the-vampiire |http://www.freecodecamp.com/the-vampiire
Vamp
@the-vampiire
May 04 2017 02:10
@christianbalderrama minor correction that is an object method not an api
Christian Balderrama
@christianbalderrama
May 04 2017 02:11
I mean, yeah its built in as like an interface for JS. Sorry for using the term api.
sunnyr791
@sunnyr791
May 04 2017 02:11
blob
Vamp
@the-vampiire
May 04 2017 02:12
@christianbalderrama just correcting you so you know for th future. it helps to know the terminology when you are looking things up
Christian Balderrama
@christianbalderrama
May 04 2017 02:12
okay got it thanks vampire!
Vamp
@the-vampiire
May 04 2017 02:12
it is called a method. there are array, string, and object methods in JS
Ivan J Badia
@IvanJB
May 04 2017 02:12
@sunnyr791 set your code like this : if ( a < 0 || b < 0) {
return undefined // this not a string } else
Vamp
@the-vampiire
May 04 2017 02:12
a method is an object function
Jeff
@etisdew
May 04 2017 02:13
oh
Vamp
@the-vampiire
May 04 2017 02:13
er
a method is a property of an object that is a function is a better way to put it
Jeff
@etisdew
May 04 2017 02:14
thanks for that, still getting used to objects @the-vampiire brownie bot?
CamperBot
@camperbot
May 04 2017 02:14
etisdew sends brownie points to @the-vampiire :sparkles: :thumbsup: :sparkles:
:cookie: 351 | @the-vampiire |http://www.freecodecamp.com/the-vampiire
sunnyr791
@sunnyr791
May 04 2017 02:14
@IvanJB I was trying to see if I was missing something from the example box. if/else makes sense
Vamp
@the-vampiire
May 04 2017 02:15
@etisdew idk if you were talking about the contacts lookup but break wouldnt do. you want to break the loop with a return statement of either
no contacts found
no property match
property (that was found)
sunnyr791
@sunnyr791
May 04 2017 02:15
Haven't tried that but I'm sure that would work
bitcoinabdi
@bitcoinabdi
May 04 2017 02:15
@HeebieGeeBee for (i=0;i<arr.length;i++){
return arr.splice(0,size);
}
Ivan J Badia
@IvanJB
May 04 2017 02:15
@sunnyr791 delete the second console.log and let the else return the math operation.
👍
Vamp
@the-vampiire
May 04 2017 02:17
dont do that devon
Devon Thomas
@UmbraLegacy
May 04 2017 02:18
@the-vampiire , do what?
Vamp
@the-vampiire
May 04 2017 02:18
teach a man to fish, dont hand him one.
sunnyr791
@sunnyr791
May 04 2017 02:18
^^ 'atta boy!
Devon Thomas
@UmbraLegacy
May 04 2017 02:19
Unless you're more interested in improving your own skills than theirs. ;)
Vamp
@the-vampiire
May 04 2017 02:19
then you solve it for yourself
and teach him how you got there
instead of pasting your solution with no explanation
Devon Thomas
@UmbraLegacy
May 04 2017 02:19
Fine fine
Vamp
@the-vampiire
May 04 2017 02:19
delete it
be a good fellow
were all here to learn. nobody is inept at copy and pasting
Devon Thomas
@UmbraLegacy
May 04 2017 02:20
You'd be surprised...
Vamp
@the-vampiire
May 04 2017 02:20
good man, Devon
Long Nguyen
@longnt80
May 04 2017 02:20
cheer guys :clap:
Ankit Nautiyal
@Ankitnau25
May 04 2017 02:20
Hi can anyone help me, i am creating ecommerce website i need to filter products according to prize, brand and price how to filter using angular js
Vamp
@the-vampiire
May 04 2017 02:21
@Ankitnau25 that’s not nearly enough information.
filtering approach is going to be based on the format of the data
@UmbraLegacy thanks, have a brownie
CamperBot
@camperbot
May 04 2017 02:22
the-vampiire sends brownie points to @umbralegacy :sparkles: :thumbsup: :sparkles:
:cookie: 292 | @umbralegacy |http://www.freecodecamp.com/umbralegacy
Ankit Nautiyal
@Ankitnau25
May 04 2017 02:24
@the-vampiire data is fetched from json file but tell me how can i filter using brand, price and both together
Khoa Le
@Zacele
May 04 2017 02:25
function sumPrimes(num) {
  function isPrime(number){
  primeArr = [];
      for (i = 2; i <= number; i++){
          if(number % i === 0 && number!= i){
             return false;
          }
  }      
    return true;
}
    if (num===1){
      return 0;
    }
    else if(isPrime(num) ===true){
      primeArr.push(num);
      isPrime(num-1);
    }
    else if(isPrime(num) ===false){
      isPrime(num-1);
    }
  return primeArr;
}
could anyone check this for me please
why I cannot return my primeArr
is only return []
Aizaz Shahid
@aizazshahid
May 04 2017 02:27
@Zacele primeArr declared outside your function ?
Khoa Le
@Zacele
May 04 2017 02:28
but I didn't include the var so it is a global object right ?
Aizaz Shahid
@aizazshahid
May 04 2017 02:29
@Zacele yes !
Christian Balderrama
@christianbalderrama
May 04 2017 02:29

```function lookUpProfile(firstName, prop){
// Only change code below this line
var found = "";
for(var i = 0; i < contacts.length; i++){

if(contacts[i].firstName === firstName){
  if(contacts[i].hasOwnProperty(prop)){
    found = contacts[i].prop;
    break;
  }
  else{
    found = "No such property";
  }
}
else{
  found = "No such contacts";
}

}
return found;

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Kristian", "lastName");```

Hi @the-vampiire this is my idea can you say where I got wrong.

Long Nguyen
@longnt80
May 04 2017 02:30
@christianbalderrama
i don't think you need break;
Christian Balderrama
@christianbalderrama
May 04 2017 02:30
function lookUpProfile(firstName, prop){
// Only change code below this line
  var found = "";
  for(var i = 0; i < contacts.length; i++){

    if(contacts[i].firstName === firstName){
      if(contacts[i].hasOwnProperty(prop)){
        found = contacts[i].prop;
        break;
      }
      else{
        found = "No such property";
      }
    }
    else{
      found = "No such contacts";
    }
  }
  return found;

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Kristian", "lastName");
Aizaz Shahid
@aizazshahid
May 04 2017 02:31
@Zacele try to declare your array after sumPrimes(num)
Christian Balderrama
@christianbalderrama
May 04 2017 02:31
it says its still wrong :/
Long Nguyen
@longnt80
May 04 2017 02:31
hmm
Khoa Le
@Zacele
May 04 2017 02:32
function sumPrimes(num) {
  primeArr = [];
  function isPrime(number){

      for (i = 2; i <= number; i++){
          if(number % i === 0 && number!= i){
             return false;
          }
  }      
    return true;
}
    if (num===1){
      return 0;
    }
    else if(isPrime(num) ===true){
      primeArr.push(num);
      isPrime(num-1);
    }
    else if(isPrime(num) ===false){
      isPrime(num-1);
    }
  return primeArr;
}

sumPrimes(10)?
nothing
Aizaz Shahid
@aizazshahid
May 04 2017 02:32
@Zacele there is no need to define in the nested one, so it's better to declare into outer function !
Khoa Le
@Zacele
May 04 2017 02:32
the ? is a miss typo
Aizaz Shahid
@aizazshahid
May 04 2017 02:32
@Zacele well let me check if this is a issue !
Zach Bruno
@zbruno247
May 04 2017 02:33
Can anyone help me with the https://beta.freecodecamp.com/en/challenges/basic-javascript/stand-in-line challenge... I'm not sure what the solution is and would like to see the solution to better understand it!
Christian Balderrama
@christianbalderrama
May 04 2017 02:34
Where do you think I've been wrong @longnt80
David Amanze
@GodKingShogun
May 04 2017 02:35
hello everyone
Aizaz Shahid
@aizazshahid
May 04 2017 02:35
@Zacele yes this is a typo:
function foo() {
    function foo2() {
        myGlobalCheck = 1;
    }
    console.log(myGlobalCheck);    
}

foo();        // Error: myGlobalCheck is not defined
David Amanze
@GodKingShogun
May 04 2017 02:35
anyone here have experience with node js
Aizaz Shahid
@aizazshahid
May 04 2017 02:36
make sure to use var keyword when declaring variable or atleast use in that scope where you needed !
Long Nguyen
@longnt80
May 04 2017 02:36
@christianbalderrama
damn
here it is:
contacts[i].prop
should be:
contacts[i][prop]
Aizaz Shahid
@aizazshahid
May 04 2017 02:37
but the problem is that if you use var keyword in that nested function it will become private, so there is a only way to use that variable, is to declare in the outside function !
@Zacele
is it working now ?? @Zacele
Christian Balderrama
@christianbalderrama
May 04 2017 02:38
Thanks @longnt80 however akira and adrress is wrong.
CamperBot
@camperbot
May 04 2017 02:38
christianbalderrama sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:warning: christianbalderrama already gave longnt80 points
Long Nguyen
@longnt80
May 04 2017 02:38
@christianbalderrama
contacts[i].prop will look for a property "prop" which doesn't exist
Khoa Le
@Zacele
May 04 2017 02:38
@forwebtech is still not return what I want
function sumPrimes(num) {
 var  primeArr = [];
  function isPrime(number){

      for (i = 2; i <= number; i++){
          if(number % i === 0 && number!= i){
             return false;
          }
  }      
    return true;
}
    if (num===1){
      return 0;
    }
    else if(isPrime(num) ===true){
      primeArr.push(num);
      isPrime(num-1);
    }
    else if(isPrime(num) ===false){
      isPrime(num-1);
    }
  return primeArr;
}

sumPrimes(10);
Aizaz Shahid
@aizazshahid
May 04 2017 02:38
ok let me see further !
Zach Bruno
@zbruno247
May 04 2017 02:41
Here is my solution to https://beta.freecodecamp.com/en/challenges/basic-javascript/stand-in-line
It is clear I am way off. What should my function look like? Any thoughts?
function nextInLine(arr, item) {
  // Your code here
  add = testArr.push(arr);
  remove = testArr.unshift(item);
  return remove;  // Change this line
}

nextInLine([2], 1);

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
Aizaz Shahid
@aizazshahid
May 04 2017 02:42
@Zacele can you please tell me the name of that challenge ?
needed instructions ! so that am able to figure it out.
Long Nguyen
@longnt80
May 04 2017 02:43
@christianbalderrama
don't know why but it worked in my test file
Aizaz Shahid
@aizazshahid
May 04 2017 02:44
@Zacele i think you need a iterator / loop because the given number may be contains more than 2 prime numbers !
Zach Bruno
@zbruno247
May 04 2017 02:44
@forwebtech I pasted the link right above :)
Long Nguyen
@longnt80
May 04 2017 02:44
@christianbalderrama
I found it, you have a typo
Zach Bruno
@zbruno247
May 04 2017 02:44
@forwebtech I appreciate your response
Aizaz Shahid
@aizazshahid
May 04 2017 02:44
@zbruno247 sure !
Khoa Le
@Zacele
May 04 2017 02:44
@forwebtech the chellenge is Sum All Primes
Long Nguyen
@longnt80
May 04 2017 02:45
@christianbalderrama
found = "No such contacts"
should be
found = "No such contact"
no "s"
Aizaz Shahid
@aizazshahid
May 04 2017 02:45
@zbruno247 actually the task is to enter the value at last and removes the first !
zackcash47
@zackcash47
May 04 2017 02:46
At 104 having trouble adding animated‚ shake to #target1 here's the code I've put through so far:<script src="//code.jquery.com/jquery-1.9.1.js">
$(document).ready(function() {
$("button").addClass("animated");
$(".btn").addClass("shake");
$("#target1").addClass("btn-primary");
$("#target1").addClass("shake");
$("#target1").addClass("animated");
});
</script>
Aizaz Shahid
@aizazshahid
May 04 2017 02:46
@zbruno247 so .push( num ) enters the value at last into the original array and .shift() removes the first element and return it, that value should to be returned !
Zach Bruno
@zbruno247
May 04 2017 02:46
@forwebtech and I do that from testArr correct?
Aizaz Shahid
@aizazshahid
May 04 2017 02:48
no you should to use the argument array
which is arr
Zach Bruno
@zbruno247
May 04 2017 02:50
@forwebtech I changed my function to this and 3 of the 2 solutions pass. Any thoughts?
function nextInLine(arr, item) {
  // Your code here
  add = testArr.push(item);
  remove = testArr.shift();
  return remove;  // Change this line
}
Aizaz Shahid
@aizazshahid
May 04 2017 02:50
test array is made to pass the value as an argument but we have to use the name of the parameter or argument which will declared in our function
Zach Bruno
@zbruno247
May 04 2017 02:50
@forwebtech passing in arr doesn't work
Aizaz Shahid
@aizazshahid
May 04 2017 02:50
didn't say that don't pass array just used in the function
arr that should be used in your function to enter the value and remove the value also
Jeff
@etisdew
May 04 2017 02:51
where does the first parameter get used?
Aizaz Shahid
@aizazshahid
May 04 2017 02:52
and the thing is that you are accessing Global one so if you are accessing Global very well then you don't need those parameters but in the challenge we have given those parameters so we have to use them
Zach Bruno
@zbruno247
May 04 2017 02:53
Gotcha gotcha
Jeff
@etisdew
May 04 2017 02:53
I see
Zach Bruno
@zbruno247
May 04 2017 02:53
so I changed testArr to arr the first param and it worked
Thank you @forwebtech
CamperBot
@camperbot
May 04 2017 02:53
zbruno247 sends brownie points to @forwebtech :sparkles: :thumbsup: :sparkles:
:cookie: 395 | @forwebtech |http://www.freecodecamp.com/forwebtech
Aizaz Shahid
@aizazshahid
May 04 2017 02:53
you are welcome
barki mustapha
@barkinet
May 04 2017 02:53

//
// GoogleCloudDestination.swift
// SwiftyBeaver
//
// Copyright © 2017 Sebastian Kreutzberger. All rights reserved.
//
import Foundation

public final class GoogleCloudDestination: BaseDestination {

private let serviceName: String

public init(serviceName: String) {
    self.serviceName = serviceName
    super.init()
}

override public var asynchronously: Bool {
    get {
        return false
    }
    set {
        return
    }
}

override public func send(_ level: SwiftyBeaver.Level, msg: String, thread: String,
                          file: String, function: String, line: Int) -> String? {

    let gcpJSON: [String: Any] = [
        "serviceContext": [
            "service": serviceName
        ],
        "message": msg,
        "severity": level.severity,
        "context": [
            "reportLocation": ["filePath": file, "lineNumber": line, "functionName": function]
        ]
    ]

    let finalLogString: String

    do {
        finalLogString = try jsonString(obj: gcpJSON)
    } catch {
        let uncrashableLogString = "{\"context\":{\"reportLocation\":{\"filePath\": \"\(file)\"" +
            ",\"functionName\":\"\(function)\"" +
            ",\"lineNumber\":\(line)},\"severity\"" +
            ":\"CRITICAL\",\"message\":\"Error encoding " +
        "JSON log entry. You may be losing log messages!\"}"
        finalLogString = uncrashableLogString.description
    }
    print(finalLogString)
    return finalLogString
}

private func jsonString(obj: Dictionary<String, Any>) throws -> String {
    let json = try JSONSerialization.data(withJSONObject: obj, options: [])
    guard let string = String(data: json, encoding: .utf8) else {
        throw GCPError.serialization
    }
    return string
}

}

///
/// https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#LogSeverity
extension SwiftyBeaver.Level {

/// Verbose is reported as Debug to GCP.
/// Recommend you don't bother using it.
var severity: String {
    switch self {
    // There is only one level below "Debug": "Default", which becomes "Any" and is considered as a potential error as well
    case .verbose: return "DEBUG"
    case .debug: return "DEBUG"
    case .info: return "INFO"
    case .warning: return "WARNING"
    case .error: return "ERROR"
    }
}

}

private enum GCPError: Error {
case serialization
}

Jeff
@etisdew
May 04 2017 02:53
in a local scope how is the passed array handled a let something = assignment?
Khoa Le
@Zacele
May 04 2017 02:53
@forwebtech have you test out any new case
Ivan J Badia
@IvanJB
May 04 2017 02:53
@zachbruno you have it correct but delete the add and remove. .push and .add will do that for you and use arr.push not testArr.push
Jeff
@etisdew
May 04 2017 02:54
I see
Aizaz Shahid
@aizazshahid
May 04 2017 02:54
@Zacele sorry busy with him, now am checking yours !

@Zacele as in instructions,

Sum all the prime numbers up to and including the provided number.

Khoa Le
@Zacele
May 04 2017 02:55
yeah
I want to find the Arr first then reduce it
Aizaz Shahid
@aizazshahid
May 04 2017 02:57
that means suppose if we have 10 then we have to check number by number to check if its prime or not and store it so you need a loop
I think filter method works as well here.
Joseph
@revisualize
May 04 2017 02:59
Hello.
Aizaz Shahid
@aizazshahid
May 04 2017 03:00
@Zacele after picking the prime ones also add it together !
@revisualize Welcome !
Khoa Le
@Zacele
May 04 2017 03:02
@forwebtech so you think maybe that step where we return the prime number ARr is not necessary ???
Aizaz Shahid
@aizazshahid
May 04 2017 03:03
indeed because if we divide the prime number with 2 then its remainder should always not equal to zero so we can check by this logic don't need to divide by all
Mauro
@mauronml
May 04 2017 03:21
Hello everyone
Vicky Lai
@vickylai
May 04 2017 03:21
'Llo JS world
How can I get this FCC challenge to use ES6? It's Sum All Numbers in a Range if you're curious
HeebieGeeBee
@HeebieGeeBee
May 04 2017 03:23
@vickylaiio u can use es6
Vicky Lai
@vickylai
May 04 2017 03:24
@HeebieGeeBee Oh... maybe that's not the reason it's not working.
HeebieGeeBee
@HeebieGeeBee
May 04 2017 03:24
@vickylaiio wanna post your code?
Vicky Lai
@vickylai
May 04 2017 03:25

function sumAll(arr) {
// find lowest of the two numbers
  // increment [0] until i++ matches [1]
  // push those onto new array
  // sum new array using reduce
  var min = Math.min.apply(arr);
  var max = Math.max.apply(arr);
  var sumThis = [];
  for (var i = min; i < max; i++) {
    sumThis.push(i);
    return sumThis;
  }
  const summed = sumThis.reduce((total, amount) => total + amount);
}

sumAll([1, 4]);
I'm struggling with reduce TBH
Can't get my head around it yet
The comments are my plan... I'm sure it's only one way to go about it
HeebieGeeBee
@HeebieGeeBee
May 04 2017 03:25
@vickylaiio youre returning in the loop
Vicky Lai
@vickylai
May 04 2017 03:26
Bah
Right I know that one
HeebieGeeBee
@HeebieGeeBee
May 04 2017 03:26
return stops the function
and you want i <= max for the conditonal for the loop
but take care of that and your reduce looks fine
Vicky Lai
@vickylai
May 04 2017 03:29
Thanks @HeebieGeeBee let me give that a shot...
CamperBot
@camperbot
May 04 2017 03:29
vickylaiio sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1559 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
HeebieGeeBee
@HeebieGeeBee
May 04 2017 03:30
@vickylaiio you will need to return that reduce btw
Aizaz Shahid
@aizazshahid
May 04 2017 03:30
@HeebieGeeBee can't we use condition in reduce ?
ian
@EIsIncorrect
May 04 2017 03:30
Hi all. Stuck on the celsius to farenheit challenge. This is what I thought it would be
farenheit = celsius * (9/5) + 32;
HeebieGeeBee
@HeebieGeeBee
May 04 2017 03:31
@forwebtech yeah why?
Mauro
@mauronml
May 04 2017 03:31
just curious, what does => do? is that a shorthand?
Aizaz Shahid
@aizazshahid
May 04 2017 03:31
well i need a case here like // Array [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] so i need to just add the prime numbers !
Vicky Lai
@vickylai
May 04 2017 03:32
I thought that => omitted the need for return? Hang on let me double check
Aizaz Shahid
@aizazshahid
May 04 2017 03:32
am using .filter() instead of that !
HeebieGeeBee
@HeebieGeeBee
May 04 2017 03:32
@vickylaiio youre using the arrow function for the reduce callback
Mauro
@mauronml
May 04 2017 03:32
@vickylaiio I don’t know, just hadnt see it before. I’m a newb
Vicky Lai
@vickylai
May 04 2017 03:32
"We use const instead of var and we replace the word function with a “fat arrow” (=>) after the parameters, and we omit the word ‘return’." - https://medium.freecodecamp.com/reduce-f47a7da511a9
Something I'm not getting here...
HeebieGeeBee
@HeebieGeeBee
May 04 2017 03:33
@vickylaiio youre only using the arrow function for the reduce callback function
Mauro
@mauronml
May 04 2017 03:33
ah, i see.
Aizaz Shahid
@aizazshahid
May 04 2017 03:33
@mauronml it uses to return something !
HeebieGeeBee
@HeebieGeeBee
May 04 2017 03:33
your main function still needs to return your reduce
Vicky Lai
@vickylai
May 04 2017 03:33
OH
Okay hang on
ian
@EIsIncorrect
May 04 2017 03:34
nevermind, figured it out. I mispelled fahrenheit lol...
barki mustapha
@barkinet
May 04 2017 03:34

if (b) { // Space after the keyword in conditions and loops.
} else { // Spaces around else.
}
while (test) {} // There is usually no space inside parentheses.
switch (i) {
for (int i = 0; i < 5; ++i) {
// Loops and conditions may have spaces inside parentheses, but this
// is rare. Be consistent.
switch ( i ) {
if ( test ) {
for ( int i = 0; i < 5; ++i ) {
// For loops always have a space after the semicolon. They may have a space
// before the semicolon, but this is rare.
for ( ; i < 5 ; ++i) {
...

// Range-based for loops always have a space before and after the colon.
for (auto x : counts) {
...
}
switch (i) {
case 1: // No space before colon in a switch case.
...
case 2: break; // Use a space after a colon if there's code after it.

HeebieGeeBee
@HeebieGeeBee
May 04 2017 03:34
@forwebtech you just use conditionals in the callback for the reduce
mikemorancodes
@mikemorancodes
May 04 2017 03:34
function uniteUnique(arr) {

  var newArr = [].slice.call(arguments);
  var merged = [].concat.apply([], newArr);
  var result = [];

  return result.concat(merged.filter(function(i){
    return result.indexOf(i) === -1;
  }));
}

uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
Hey guys! How come my merged array isn't being filtered properly with the result? I'm just returning an array of all the numbers.
Vicky Lai
@vickylai
May 04 2017 03:36
I'm getting an empty array?

function sumAll(arr) {
// find lowest of the two numbers
  // increment [0] until i++ matches [1]
  // push those onto new array
  // sum new array using reduce
  var min = Math.min.apply(arr);
  var max = Math.max.apply(arr);
  var sumThis = [];
  for (var i = min; i <= max; i++) {
    sumThis.push(i);
  }
  console.log(sumThis);
  return sumThis;
  const summed = sumThis.reduce((total, amount) => total + amount);
  return summed;
} 

sumAll([1, 4]);
jatinkapila
@jatinkapila
May 04 2017 03:36

var myVar = 11;

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

m getting my Var =9
Aizaz Shahid
@aizazshahid
May 04 2017 03:38
@vickylaiio
and also to get the max you have to pass null argument to your max function!
Math.max.apply(null, arr)
also you can get maximum and minimum by sorting it in ascending order !
Vicky Lai
@vickylai
May 04 2017 03:41
@forwebtech Good point..
Vicky Lai
@vickylai
May 04 2017 03:42
Okay, this did it:
function sumAll(arr) {
// find lowest of the two numbers
  // increment [0] until i++ matches [1]
  // push those onto new array
  // sum new array using reduce
  var min = Math.min.apply(null, arr);
  var max = Math.max.apply(null, arr);
  var sumThis = [];
  for (var i = min; i <= max; i++) {
    sumThis.push(i);
  }
  console.log(sumThis);
  const summed = sumThis.reduce((total, amount) => total + amount);
  return summed;
} 

sumAll([1, 4]);
Thanks @forwebtech and @HeebieGeeBee !
CamperBot
@camperbot
May 04 2017 03:42
vickylaiio sends brownie points to @forwebtech and @heebiegeebee :sparkles: :thumbsup: :sparkles:
:warning: vickylaiio already gave heebiegeebee points
:cookie: 396 | @forwebtech |http://www.freecodecamp.com/forwebtech
HeebieGeeBee
@HeebieGeeBee
May 04 2017 03:42
@vickylaiio yeah or you can use the spread operator
@vickylaiio btw do you realise you can just do everything in that for loop
 var min = Math.min.apply(null, arr);
  var max = Math.max.apply(null, arr);
  var sumThis = 0;
  for (var i = min; i <= max; i++) {
    sumThis += i;
  }
return sumThis;
Aizaz Shahid
@aizazshahid
May 04 2017 03:45
@HeebieGeeBee var min = Math.min.apply(null, arr); that will not work !
HeebieGeeBee
@HeebieGeeBee
May 04 2017 03:45
@forwebtech it does
Vamp
@the-vampiire
May 04 2017 03:45

@HeebieGeeBee hey man any advice on this?

function telephoneCheck(str) {

  var regex = /^(1)?( )?(-)?(\([0-9]{3}\)|[0-9]{3})( )?(-)?[0-9]{3}( )?(-)?[0-9]{4}/g;

  return str.match(regex) !== null;   
}

passing every case except

telephoneCheck("27576227382") should return false.
telephoneCheck("(275)76227382") should return false.

because it is matching up to the final ‘2’ and considering that a pass :/

HeebieGeeBee
@HeebieGeeBee
May 04 2017 03:45
@forwebtech why wouldnt it?
@forwebtech https://repl.it/Hf06
Vicky Lai
@vickylai
May 04 2017 03:46
@forwebtech "Using apply and built-in functions" on this page - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply
Shows Math.min.apply
@HeebieGeeBee Mmm code golf!
Aizaz Shahid
@aizazshahid
May 04 2017 03:47
yes, i have missed something !
that's why didn't work !
HeebieGeeBee
@HeebieGeeBee
May 04 2017 03:47
@vickylaiio var min = Math.min(...arr); i like the spread operator though
@forwebtech i dont get what youre saying
Aizaz Shahid
@aizazshahid
May 04 2017 03:48
@HeebieGeeBee well my bad, have tested on my side and wasn't working, but figured it out !
@vickylaiio sorry for that !
HeebieGeeBee
@HeebieGeeBee
May 04 2017 03:49
@the-vampiire sorry ive been up far too long to try and understand a regex, expecially a lon gone like that
Vamp
@the-vampiire
May 04 2017 03:49
lol ok
dont know if this helps or not (for anyone else that may be able to help me)
in english:
? means 0 or 1 matches
starts with the number 1 ?
space / dash ?
either (###) or ###
space / dash ?
# {3 times}
space / dash ?
# {4 times}
Aizaz Shahid
@aizazshahid
May 04 2017 03:53
@the-vampiire do you want that or explaining it ??
Mauro
@mauronml
May 04 2017 03:53
@the-vampiire I tested your regex in regexr.com and it seems to be working
Vamp
@the-vampiire
May 04 2017 03:53
I am explaining my regex
Aizaz Shahid
@aizazshahid
May 04 2017 03:53
ok !
Mauro
@mauronml
May 04 2017 03:53
it doesnt match 27576227382 or (275)76227382
Aizaz Shahid
@aizazshahid
May 04 2017 03:54
@the-vampiire need to pass that ?
telephoneCheck("27576227382") should return false.
telephoneCheck("(275)76227382") should return false.
well let me try !
Vamp
@the-vampiire
May 04 2017 03:54
function telephoneCheck(str) {

    var regex = /^(1)?( )?(-)?(\([0-9]{3}\)|[0-9]{3})( )?(-)?[0-9]{3}( )?(-)?[0-9]{4}/g;

    return str.match(regex) !== null;

}

in english, ‘?' means 0 or 1 matches

starts with the number 1 ?
space / dash ?
either (###) or ###
space / dash ?
# {3 times}
space / dash ?
# {4 times}

passes all cases except:
telephoneCheck("27576227382") should return false.
telephoneCheck("(275)76227382") should return false.

@mauronml ya thats the problem :(
Caleb Brenner
@cwborion
May 04 2017 03:54

Having trouble with the "Golf Code" challenge. Not sure what I'm doing wrong. Everything appears to be entered the way it should be according to the challenges that have been covered so far, but FCC is really good at being extremely vague and leaving out explanations as to how to apply the tools it teaches. Here is my code if anyone can help.

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

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

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

HeebieGeeBee
@HeebieGeeBee
May 04 2017 03:54
@the-vampiire did that pass? i seem to remember having to right clauses where there as no space too
Vamp
@the-vampiire
May 04 2017 03:55
@HeebieGeeBee passes everyting except
telephoneCheck("27576227382") should return false.
telephoneCheck("(275)76227382") should return false.
@cwborion = is assignment.
Vamp
@the-vampiire
May 04 2017 03:55
and its because its matching everything up to the last ‘2’ digit in those
Joseph
@revisualize
May 04 2017 03:55
@cwborion == and === are for comparison.
Caleb Brenner
@cwborion
May 04 2017 03:56
@revisualize what do you mean?
Vamp
@the-vampiire
May 04 2017 03:56
I just went for a long walk thinking about regex. came back certain I would have it. built that from scratch just walking through what I wanted each thing to do. thought fo sure it would pass then those 2 bastards pop up :(
Mauro
@mauronml
May 04 2017 03:56
lol
Joseph
@revisualize
May 04 2017 03:57
@cwborion How do you compare two things in JavaScript?
HeebieGeeBee
@HeebieGeeBee
May 04 2017 03:57
@the-vampiire add $ to the end of your last capture group
Joseph
@revisualize
May 04 2017 03:57
@cwborion How would you compare "A String" against "a string" to see if they are the same?
Aizaz Shahid
@aizazshahid
May 04 2017 03:58
credit goes to @HeebieGeeBee
^(1)?( )?(-)?(\([0-9]{3}\)|[0-9]{3})( )?(-)?[0-9]{3}( )?(-)?[0-9]{4}$
working fine !
with also two of them !
Caleb Brenner
@cwborion
May 04 2017 03:58
@revisualize yes I went through those challenges earlier tonight, but based off of the description in this challenge, I don't really see how that plays into it
Vamp
@the-vampiire
May 04 2017 03:58
@HeebieGeeBee I fucking love you
Screen Shot 2017-05-03 at 11.58.39 PM.png
Joseph
@revisualize
May 04 2017 03:59
@cwborion You're not doing comparison in your if conditions. You're doing assignment.
Vamp
@the-vampiire
May 04 2017 03:59
from 0 regex to the oneliner in a day lol. goddamn man that felt good. thank you so much @HeebieGeeBee
CamperBot
@camperbot
May 04 2017 03:59
the-vampiire sends brownie points to @heebiegeebee :sparkles: :thumbsup: :sparkles:
:star2: 1560 | @heebiegeebee |http://www.freecodecamp.com/heebiegeebee
Joseph
@revisualize
May 04 2017 03:59
@cwborion How do you create a variable str and assign the value "Hello" to it?
HeebieGeeBee
@HeebieGeeBee
May 04 2017 03:59
np
Joseph
@revisualize
May 04 2017 04:00
@cwborion If you can answer those two questions. And then look at your if conditions. You'll see the problem.
#rum.
Ken Haduch
@khaduch
May 04 2017 04:00
@mikemorancodes - I think that what you are doing with your result.indexOf in the filter callback is that you are searching an empty array, because result is empty when you are trying to find the elements in it. My first attempt at a solution for this was to explicitly process the arrays with for loops. My second attempt was much cleaner, using .reduce() - although I found a way to make yours, at least your concept, work.
Caleb Brenner
@cwborion
May 04 2017 04:01
@revisualize alright I will mess around with the comparison elements and see if I can figure something out. The explanation is so vague I just have no idea how to go about it. Even though I've been going through the previous challenges over the past 2 hours.
Caleb Brenner
@cwborion
May 04 2017 04:02
@revisualize thanks, I will look through those and see if it makes any sense to me
CamperBot
@camperbot
May 04 2017 04:02
cwborion sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3891 | @revisualize |http://www.freecodecamp.com/revisualize
Ivan J Badia
@IvanJB
May 04 2017 04:04
@cwborion you need to add === to if (strokes === 1), par, par +1 and par +2 and add else at the end of your if/else chain. I had a hard time too but my mistake was missing the !, -...
Joseph
@revisualize
May 04 2017 04:06

@cwborion

var str = "Hello"; // This is using the Assignment Operator to assign the value of "Hello" to the variable str
"A String" === "a string"; // This is a comparison operator to see if two values are equal.

In an if condition you need to use a comparison operator ... not ... an assignment operator. You don't want to

strokes = 1;

You want to know if strokes is equal to the value 1
strokes === 1; ....or... strokes == 1

Caleb Brenner
@cwborion
May 04 2017 04:07
@IvanJB yeah, when I see the answer it makes complete sense to me. I remember all the previous challenges and none of them were that difficult, but these checkpoint challenges ask you to apply them in a way that hasn't really been covered, leaving me feeling clueless and frustrated.
@revisualize I will try adding that to my code instead
jmariomejiap
@jmariomejiap
May 04 2017 04:08
hello guys. Im having a hard time iterating through a simple object. can i please have a friendly hand. the issue i have is at the very end of my script in the last function. it takes an object and my idea is to iterate through it to sort out the channels who are on and the channels who are off. alternatively, I have come to realise that this might be a silly idea but regardless I am unable to make this basic loop happen. this is my codepen. https://codepen.io/jmariomejia/pen/EmZPmN/
Aizaz Shahid
@aizazshahid
May 04 2017 04:11
@jmariomejiap you can get keys by Object.keys() and then iterate it with loop and just use those keys to check !
Mario A. Carlos
@MarioC3
May 04 2017 04:11
why does the brackets notation work but not the dot notation
Aizaz Shahid
@aizazshahid
May 04 2017 04:11
Object.keys(obj here)
Ivan J Badia
@IvanJB
May 04 2017 04:11
I totally understand it took me a while to figure it too. I just don't like how the checkpoints use code that has not been introduced. It can be very frustrating and discouraging.
Mario A. Carlos
@MarioC3
May 04 2017 04:11
This works:

// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here
  if (myObj.hasOwnProperty(checkProp)) {
    return myObj[checkProp];
  } else {
    return 'Not Found';
  }
}

// Test your code by modifying these values
checkObj("gift");
This doesn't:
Aizaz Shahid
@aizazshahid
May 04 2017 04:11
@MarioC3 because when you use . notation with arguments, they become like this, obj."someProperty" so that is invalid,
Mario A. Carlos
@MarioC3
May 04 2017 04:12

// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

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

// Test your code by modifying these values
checkObj("gift");
Joseph
@revisualize
May 04 2017 04:12
@MarioC3 Dot Notation is converting the value to a string (string literal). Example: myObj.name; is the same as myObj["name"]; and as we all know quotes define strings. If you want to use a variable for accessing the value of object properties you cannot use Dot Notation. You have to use Bracket Notation. Example: var num = 42; myObj[num];
Aizaz Shahid
@aizazshahid
May 04 2017 04:12
the thing is that when you are dealing object properties through your arguments always use bracket notation, as you noticed it, and indeed in bracket notation, string can write as property
Ken Haduch
@khaduch
May 04 2017 04:13
@MarioC3 - you are getting checkProp (a variable) that contains the property. If you look at the lesson on Accessing Objects Properties with Variables, you'll recall that you have to use bracket notation.
Jeff
@etisdew
May 04 2017 04:13
found this out the hard way, now I use brackets
Aizaz Shahid
@aizazshahid
May 04 2017 04:15
@etisdew until or unless object names haven't spaces or other special characters you can use . dot notation but talking directly, not with arguments !
Ivan J Badia
@IvanJB
May 04 2017 04:15
You dont have to use double or single quotes for bracket notions in an object
Mario A. Carlos
@MarioC3
May 04 2017 04:16
Ok, so just to understand it: When dealing with variables, and trying to access properties of a object use brackets notation?
Aizaz Shahid
@aizazshahid
May 04 2017 04:16
@MarioC3 indeed !
Ken Haduch
@khaduch
May 04 2017 04:16
@etisdew - once you have learned the hard way (by actually using it) review the lessons
  • Accessing Objects Properties with the Dot Operator
  • Accessing Objects Properties with Bracket Notation
  • Accessing Objects Properties with Variables
    And get that information from there and remember it!
Mario A. Carlos
@MarioC3
May 04 2017 04:16
Cool beans!
Thanks @revisualize @forwebtech & @khaduch
CamperBot
@camperbot
May 04 2017 04:16
marioc3 sends brownie points to @revisualize and @forwebtech and @khaduch :sparkles: :thumbsup: :sparkles:
:cookie: 397 | @forwebtech |http://www.freecodecamp.com/forwebtech
:star2: 2833 | @khaduch |http://www.freecodecamp.com/khaduch
:star2: 3892 | @revisualize |http://www.freecodecamp.com/revisualize
Ken Haduch
@khaduch
May 04 2017 04:17
@MarioC3 - review those lessons again and it gets easier to remember it as you use it more and more.
Damien
@DubbDevs
May 04 2017 04:17
canI get some assistance with mt if statement. I'm currently working on creating a profile lookup
Aizaz Shahid
@aizazshahid
May 04 2017 04:17
@jmariomejiap your problem sorted ??
@DubbDevs sure !
Damien
@DubbDevs
May 04 2017 04:17
I previously had if else if statements all over I've tried to pare the first part down to
 if (contacts.hasOwnProperty(firstName) && (contacts.hasOwnProperty(prop) {
     return contacts[prop];
     }
Aizaz Shahid
@aizazshahid
May 04 2017 04:18
@DubbDevs contacts is Array having objects, that means you have to access them with index, in order to do that you need a loop !
like, contacts[i].hasOwnProperty(firstName)
Mario A. Carlos
@MarioC3
May 04 2017 04:19
@khaduch You're right. I'm reviewing them right now!
Damien
@DubbDevs
May 04 2017 04:19
i "think" the function is checking for contact name and value if both true then return the value
Ken Haduch
@khaduch
May 04 2017 04:19
@DubbDevs - all of the contacts have a firstName property (in addition to the array access just mentioned) you do not have to test for that, but for a match between the incoming firstName variable and the contacts[i].firstName value.
Damien
@DubbDevs
May 04 2017 04:19
ohhhhhhhhhhhhhhhhhhh
Ken Haduch
@khaduch
May 04 2017 04:20
@MarioC3 - it is always good to go back and review those tricky concepts once you have tried to use them, and successfully get them to work... good luck!
Aizaz Shahid
@aizazshahid
May 04 2017 04:20
@DubbDevs yes that's the problem, because it may be possible, firstName is there but obj.prop doesn't exist !
@DubbDevs in order to do that, first check, is the name exist or not after that check for property.
because it will very clear if the name will not found in the whole array contacts then there is only one solution there to return 'No such contact'
Damien
@DubbDevs
May 04 2017 04:22
ok so I'm creating a loop to check for the first name in the array first
Aizaz Shahid
@aizazshahid
May 04 2017 04:23
to check for the first Name in the object not actually in array, but Array contains it so we have to use indexes through loop !
Damien
@DubbDevs
May 04 2017 04:33
ok a little bit more study time on those loops!
Vamp
@the-vampiire
May 04 2017 04:39

advanced algos: symmetric difference

can anyone tell me why
sym([1, 2, 5], [2, 3, 5], [3, 4, 5]) should return [1, 4, 5]
is including 5?
a = [1, 2, 5]
b = [2, 3, 5]
c = [3, 4, 5]

a Δ b = [1, 3]
(a Δ b) Δ c = [1, 3, 4]

ohhh
because although they all contain 5 by the time the symmetric diff set is compared to c it no longer contains 5
Mario A. Carlos
@MarioC3
May 04 2017 04:41
What is the correct syntaxis for a variable that contains 1 array with 2 objects?
var something = [
{
Properties
}
{
Properties
}
]
Aizaz Shahid
@aizazshahid
May 04 2017 04:42
function sumPrimes(num) {

    var primeNumbers= [];

    // Iterating from num to 2 and getting prime numbers
    while(num > 1) {
        if(num % 2 !== 0 || num === 2) {
            primeNumbers.push(num);
        }
        num--;
    }

    // Adding all prime numbers and returning the result
    return primeNumbers.reduce((a, b) => a + b);

}

sumPrimes(10)    // returns 26 works fine
sumPrimes(977) // returns 239122
but in instructions, sumPrimes(977) should return 73156.
Mario A. Carlos
@MarioC3
May 04 2017 04:42
Like that?
Jeff
@etisdew
May 04 2017 04:43
atleast its simple and intuitive accessing through a variable obj[e].anotherFunction() @khaduch @forwebtech
Aizaz Shahid
@aizazshahid
May 04 2017 04:43
@MarioC3 2 objects in one array ??
mamun
@fsdmamun
May 04 2017 04:43
@MarioC3 close var with ; and separate objects with ,
Mario A. Carlos
@MarioC3
May 04 2017 04:44
something like this?
var myMusic = [
{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}
// Add record here
{
"artist": "Daft Punk",
"title": "Homework",
"release_year": 1997,
"formats": [
"CD",
"Cassette",
"LP"
],
"gold": true
}
];
crap sorry
var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
  }
  // Add record here
  {
  "artist": "Daft Punk",
  "title": "Homework",
  "release_year": 1997,
  "formats": [ 
    "CD",
    "Cassette",
    "LP"
  ],
  "gold": true
}
];
Aizaz Shahid
@aizazshahid
May 04 2017 04:45
basic syntax:
var ArrayObject = [ 
        { "key": "value" },
        { "key": "value" }
];
Mario A. Carlos
@MarioC3
May 04 2017 04:45
Oh ok, so it needs to have a comma between objects?
Thanks @forwebtech
CamperBot
@camperbot
May 04 2017 04:46
marioc3 sends brownie points to @forwebtech :sparkles: :thumbsup: :sparkles:
:warning: marioc3 already gave forwebtech points
Aizaz Shahid
@aizazshahid
May 04 2017 04:46
@MarioC3 yes as @fsdmamun said !
Mario A. Carlos
@MarioC3
May 04 2017 04:46
true thanks @fsdmamun
CamperBot
@camperbot
May 04 2017 04:46
marioc3 sends brownie points to @fsdmamun :sparkles: :thumbsup: :sparkles:
:cookie: 360 | @fsdmamun |http://www.freecodecamp.com/fsdmamun
Joseph
@revisualize
May 04 2017 04:46
I'm just gonna leave this right ... here... https://www.youtube.com/watch?v=_t0ZBAk72K8
Aizaz Shahid
@aizazshahid
May 04 2017 04:47
@Masd925 @HeebieGeeBee @sjames1958gm please have a look, got stuck there. :point_up: May 4, 2017 9:42 AM
Danny Welstad
@GoonTwo
May 04 2017 04:48
working on the Exact Change algorithm challenge and running into an issue. my value variable appears to be changing in my for loop, but I don't know why
function checkCashRegister(price, cash, cid) {

  var values = [["PENNY", 0.01], ["NICKEL", 0.05], ["DIME", 0.10], ["QUARTER", 0.25], ["ONE", 1.00], ["FIVE", 5.00], ["TEN", 10.00], ["TWENTY", 20.00], ["ONE HUNDRED", 100.00]];

  var changeNeeded = (cash-price).toFixed(2);
  var changeGiven = [];
  var totalCID = cid.reduce(function(acc, array){ //total amount of change in drawer (CID)
    return acc + array[1];
  },0).toFixed(2);

  var currencyAmount = []; //array to hold how many of each currency there are
  cid.forEach(function(array){
    values.forEach(function(vals){
      if(vals[0] === array[0]) {
        var amount = Math.round(array[1]/vals[1]);
        currencyAmount.push([array[0],amount]); 
      }  
    });
  });

  if (totalCID === changeNeeded) {
    return "Closed";
  }
  console.log(values);
  var valLength = values.length;
  for (var i = valLength - 1; i >= 0; i--) { //start at $100 and work down
    var counter = 0; //counter to know if it is the first time through
    for (var j = 0; j < currencyAmount[i][1]; j++) { //loop through how many of each currency there are (i.e. 3 times if there are 3 $20 bills)
      if (changeNeeded >= values[i][1]) { //if the current currency values is less than or equal to how much change the person needs
        changeNeeded -= values[i][1]; //subtract currency amount from change needed
        if (counter === 0) { //if first time through
          changeGiven.push(values[i]); //push currency and value
        } else { 
          changeGiven[changeGiven.length - 1][1] += values[i][1];//if its no the first time though add the curency value to array
        } 
        counter++;
      }
    }
  }
  console.log(values);

  return changeGiven.map(function(array){
    return [array[0],(array[1]).toFixed(2)];
  });
Srinivas
@21stnomad
May 04 2017 04:58

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

if( a < 0 && b < 0){
return "undefined";
}

// Only change code above this line

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

// Change values below to test your code
abTest(-2, 2);

// test cases
abTest(-2,2) should return undefined
abTest(2,-2) should return undefined

David Bartle
@captin411
May 04 2017 05:01
@GoonTwo what are you seeing that is indicating your 'values' variable is changing?
@21stnomad they probably don't mean the string "undefined" but the javascript built-in undefined
@21stnomad for example: return undefined;
Srinivas
@21stnomad
May 04 2017 05:03
@captin411 its returning null when i am returning undefined
Aizaz Shahid
@aizazshahid
May 04 2017 05:03
@captin411 can you see my problem ? :point_up: May 4, 2017 9:42 AM
after @21stnomad
@21stnomad challenge name ?
@21stnomad return undefined
Srinivas
@21stnomad
May 04 2017 05:04
@forwebtech
Return Early Pattern for Functions
Mario A. Carlos
@MarioC3
May 04 2017 05:05
Hey guys another question:
What does this mean:
The last index of the array is length - 1.
This is the complete sentence: Remember that Arrays have zero-based numbering, which means the last index of the array is length - 1.
Can someone shed some light on that?
Danny Welstad
@GoonTwo
May 04 2017 05:06
@captin411 console.logs before and after the loop
Mauro
@mauronml
May 04 2017 05:09
@MarioC3 If you have an array [1,2,3,4] its length property is equal to 4. However, the index of each element (or position) starts at 0
@MarioC3 i.e., 1 is at index/position 0, 2 is at index/position 1, 3 is at index/position 2, etc...
Mario A. Carlos
@MarioC3
May 04 2017 05:10
Right I get that.
But it says length -1
Mauro
@mauronml
May 04 2017 05:11
@MarioC3 Therefore, if you call an index = length, that position does not exist in the array above
Mario A. Carlos
@MarioC3
May 04 2017 05:12
mmm
why not?
Still confused.
Mauro
@mauronml
May 04 2017 05:12
@MarioC3 so to get the last Index/position, you substract 1 from the length to get the value/element at that position
Mario A. Carlos
@MarioC3
May 04 2017 05:13
[1,2,3,4] In this example, is the last index/position 4?
Mauro
@mauronml
May 04 2017 05:13
@MarioC3 because the last index/position in the array is 3
@MarioC3 no, is 3. You start counting index/position from 0
Mario A. Carlos
@MarioC3
May 04 2017 05:13
ohhh I c
so arr.length would be always -1?
Aizaz Shahid
@aizazshahid
May 04 2017 05:14

[1, 2,  3,   4]   => length is 4
 |  |   |   |
 V  V   V   V
 0  1   2   3
Mauro
@mauronml
May 04 2017 05:15
@MarioC3 if you want to get the last index/position in the array, yes, u use arr.length -1
David Bartle
@captin411
May 04 2017 05:16
@forwebtech are you sure you are summing all of the primes?
Aizaz Shahid
@aizazshahid
May 04 2017 05:16
well yes ?
David Bartle
@captin411
May 04 2017 05:16
@forwebtech it looks like you are summing up all odd numbers -- it's late and I don't have coffee so I could be wrong
(checking if it it not divisible by 2 with num % 2 !=== 0
Blara02
@Blara02
May 04 2017 05:17
whats up bois and girls, i need help with the nesting for loops challenge
Aizaz Shahid
@aizazshahid
May 04 2017 05:18
@captin411 am using that if(num % 2 !== 0 || num === 2)
Blara02
@Blara02
May 04 2017 05:18
the sample code is really messing with my head, i dont see how it works, and i isolated it to try it myself and it did not produce anthing
Aizaz Shahid
@aizazshahid
May 04 2017 05:18
@captin411 its ok, atleast you are trying to help, thanks !
CamperBot
@camperbot
May 04 2017 05:18
forwebtech sends brownie points to @captin411 :sparkles: :thumbsup: :sparkles:
:cookie: 297 | @captin411 |http://www.freecodecamp.com/captin411
David Bartle
@captin411
May 04 2017 05:19
yes @forwebtech lets pretend that "num" is "15"
Mauro
@mauronml
May 04 2017 05:19
@forwebtech that would give you every odd number, not just primes
Aizaz Shahid
@aizazshahid
May 04 2017 05:19
got it !
David Bartle
@captin411
May 04 2017 05:19
well it is not divisible by 2
but it's not prime =)
Aizaz Shahid
@aizazshahid
May 04 2017 05:19
no but the remainder will remains
modulus operator check for the remainder !
like: 10 % 3 = 1 because => 3 * 3 = 9 and 10 - 9 = 1
Mauro
@mauronml
May 04 2017 05:20
@forwebtech you will need to test if the number is divisible by any other number other than 1 or itself as well. Unfortunately, i I don’t think there’s a direct way to test for primes
Aizaz Shahid
@aizazshahid
May 04 2017 05:21
@mauronml @captin411 both are right !
@mauronml thanks also to you !
CamperBot
@camperbot
May 04 2017 05:21
forwebtech sends brownie points to @mauronml :sparkles: :thumbsup: :sparkles:
:cookie: 251 | @mauronml |http://www.freecodecamp.com/mauronml
Aizaz Shahid
@aizazshahid
May 04 2017 05:21
now i will do that !
that thing didn't come to my mind !
Markus Kiili
@Masd925
May 04 2017 05:22
@forwebtech Sufficiently efficient algorithm is to store the primes on an array and loop numbers from 2 up. Then test the looped candidate primes for divisibility against the primes in the prime array. If the numbers is not divisible by any of the array elements, add it to the array.
Mauro
@mauronml
May 04 2017 05:22
@forwebtech np
David Bartle
@captin411
May 04 2017 05:25
0 indexed arrays always messed with me. It's like having a book with 10 pages, but the first page has "0" printed on it... and then you are asked.. what is the last page numbered
Aizaz Shahid
@aizazshahid
May 04 2017 05:28
@Masd925 great trick!
@Masd925 one more thing, am thinking that prime numbers are always be in odd ??
Blara02
@Blara02
May 04 2017 05:28

var arr = [
[1,2], [3,4], [5,6]
];
for (var i=0; i < arr.length; i++) {
for (var j=0; j < arr[i].length; j++) {
console.log(arr[i][j]);
}
}

this is an example from freecodecamp on how to systematically print each sub array, i dont understand how this is supposed to accomplish that

Aizaz Shahid
@aizazshahid
May 04 2017 05:29
like 2, 3, 5, 7, 11, 13, 17
[ 49, 47, 43, 41, 37, 35, 31, 29, 25, 23, 7 more…
so now you algorithm is best suited here !
well above one is also includes composite ones !
Masaki
@masaki1223
May 04 2017 05:34
Hello I dont understand the difference between constructor object using this, and normal object
why do we use constructor?
mamun
@fsdmamun
May 04 2017 05:35
@Blara02 paste your code here and forward step by step, this may help you: http://pythontutor.com/live.html#mode=edit
Aizaz Shahid
@aizazshahid
May 04 2017 05:39
@masaki1223 if we need that object template more than two times, then we use object constructors !
function Person(first, last, age, eyecolor) {
    this.firstName = first;
    this.lastName = last;
    this.age = age;
    this.eyeColor = eyecolor;
}
in that example, every person has these properties so we can use it multiple times, in these cases we use that constructors !
var myFather = new Person("John", "Doe", 50, "blue");
var myMother = new Person("Sally", "Rally", 48, "green");
Markus Kiili
@Masd925
May 04 2017 05:41
@masaki1223 Constructor also allows you to run some code when the object is being generated.
@forwebtech Prototypes are a related subject. For example here all persons would have the object stored on Person.prototype (plain object {} by default) as their prototype. You can also use prototypes without constructors.
Vamp
@the-vampiire
May 04 2017 05:50
aren’t prototypes a way to add or modify object methods without changing the base (parent?) object?
Aizaz Shahid
@aizazshahid
May 04 2017 05:53
@Masd925 but that one doesn't an example of prototype ?
Markus Kiili
@Masd925
May 04 2017 05:53
@forwebtech That is a constructor, not a prototype.
Aizaz Shahid
@aizazshahid
May 04 2017 05:54
then how to make prototypes ?

The standard way to create an object prototype is to use an object constructor function:

i think, talking about that !

Blara02
@Blara02
May 04 2017 05:55
@fsdmamun that website helped, i understand how it itterates through the variables thanks
CamperBot
@camperbot
May 04 2017 05:55
blara02 sends brownie points to @fsdmamun :sparkles: :thumbsup: :sparkles:
:cookie: 361 | @fsdmamun |http://www.freecodecamp.com/fsdmamun
jmariomejiap
@jmariomejiap
May 04 2017 05:55
@forwebtech sorry I tried but with no success... + plus I had to take a break an put the kids to bed. Im back to PC. Ill keep trying and let you know.
Aizaz Shahid
@aizazshahid
May 04 2017 05:56
@jmariomejiap failing to make loop or other thing ?
Blara02
@Blara02
May 04 2017 05:58
can anyone help me understand why this code is no running through these loops? product is always returning 1
function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var i = 0; i < arr.legnth; i++) {
for (var j = 0; j < arr[i].length; j++) {
product = product * arr[i][j];
}
}
// Only change code above this line
return product;
}
// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
Aizaz Shahid
@aizazshahid
May 04 2017 05:58
@Blara02 you have typing mistake in your outer loop !
arr.legnth ?
Blara02
@Blara02
May 04 2017 05:59
if you could of seen the facepalm i just did
ive been staring at this problem for an hour
@forwebtech thanks a ton
CamperBot
@camperbot
May 04 2017 05:59
blara02 sends brownie points to @forwebtech :sparkles: :thumbsup: :sparkles:
:cookie: 398 | @forwebtech |http://www.freecodecamp.com/forwebtech
Aizaz Shahid
@aizazshahid
May 04 2017 06:00
@Blara02 also you can use product *= arr[i][j]
equal to the statement that have written !
Markus Kiili
@Masd925
May 04 2017 06:01
@forwebtech If you use that constructor, you can assign an object to Person.prototype property and it will be the prototype of all persons. Another way is to manipulate the default prototype at Person.prototype by for example adding methods to it. So you can use any object as prototype of another object.
jmariomejiap
@jmariomejiap
May 04 2017 06:01
@forwebtech yes the loop. it is as if the object i am using is undefined which it isn't. if i put a console.log() right before the loop I can see the contents of the object.
Aizaz Shahid
@aizazshahid
May 04 2017 06:01
@jmariomejiap did you get all the keys name into array ?
jmariomejiap
@jmariomejiap
May 04 2017 06:02
mmm, no, i dont think i did.
Aizaz Shahid
@aizazshahid
May 04 2017 06:02
@Masd925 yeah, you're right, as i know the constructors in JAVA used to give initial values to or also to put something initially !
jmariomejiap
@jmariomejiap
May 04 2017 06:02
how do I do that?
Aizaz Shahid
@aizazshahid
May 04 2017 06:03
@jmariomejiap Object.keys( your obj name ) gives you an array having key names as values
Markus Kiili
@Masd925
May 04 2017 06:03
@forwebtech Yeah, the similarity is more between JS constructors and java classes. Both are meta-objects that create objects.
jmariomejiap
@jmariomejiap
May 04 2017 06:04
@forwebtech aaa ok. in that case yes. even if I wrap that into a console.log(Object.keys(ob)).... I get an empty array. which is so weird
Aizaz Shahid
@aizazshahid
May 04 2017 06:05
@jmariomejiap give me link !
Vamp
@the-vampiire
May 04 2017 06:07
your object is ‘data’
i dont know what you are trying to do
anything involving the data object returned by the api needs to take place within the success function. that includes calls to other functions that would make use of that data
James
@gummybear00
May 04 2017 06:11
guys for the js algorithm challenges, I tried to write another function (boolean) and call it within my function, but it keeps freezing the browser
I wrote it in cpp, compiled it and ran it and it was fine. so... what's up??
Aizaz Shahid
@aizazshahid
May 04 2017 06:11
channelsInfo @the-vampiire he is trying to show that !
Vishesh Dembla
@vishesh-dembla
May 04 2017 06:11
@gummybear00 talk is cheap, show me the code!
XD
Aizaz Shahid
@aizazshahid
May 04 2017 06:12
well also describe your problem but show the code also ! @gummybear00
James
@gummybear00
May 04 2017 06:12

function sumPrimes(num) {

var accumulator = 0;

function isPrime(number){
if(number<2){
return false;
}
for(i=2;i<number;i++){
if(number % i === 0){
return false;
}
}
return true;
}

for(i=2;i<=num;i++){
if(isPrime(i)){
accumulator += i;
}
}
return accumulator;
}

Vamp
@the-vampiire
May 04 2017 06:12
then what is all this?
function getChanInfo (arr) {

    arr.map(function (elem) {
        connectAPI(elem);
    });
};

getChanInfo(streamers);

function reader (ob) {
    //console.log("inside ",  ob);

    console.log(Object.keys(ob));
};


reader(channelsInfo);
James
@gummybear00
May 04 2017 06:12
oops sorry, i forgot how to format it
Aizaz Shahid
@aizazshahid
May 04 2017 06:12

:bulb: To format your code, please follow:
Code Formatting

More details..

Vamp
@the-vampiire
May 04 2017 06:12
none of that is called in the success function
Aizaz Shahid
@aizazshahid
May 04 2017 06:13
@the-vampiire that is async method ??
James
@gummybear00
May 04 2017 06:13
function sumPrimes(num) {

  var accumulator = 0;

  function isPrime(number){
    if(number<2){
      return false;
    }
    for(i=2;i<number;i++){
      if(number % i === 0){
        return false;
      }
    }
    return true;
  }

  for(i=2;i<=num;i++){
    if(isPrime(i)){
      accumulator += i;
    }
  }
  return accumulator;
}
Aizaz Shahid
@aizazshahid
May 04 2017 06:14
@gummybear00 am also stuck there :)
Vamp
@the-vampiire
May 04 2017 06:14
@forwebtech what does that have to do with anything?
Markus Kiili
@Masd925
May 04 2017 06:14
@gummybear00 That brute force algorithm might just be too slow to pass.
Vamp
@the-vampiire
May 04 2017 06:14
data is local to the api call
you cant call a function outside and pass data to it because data doesnt exist
Aizaz Shahid
@aizazshahid
May 04 2017 06:15
seems not !
James
@gummybear00
May 04 2017 06:15
the function is inside my isPrime function
i mean sumPrimes
Aizaz Shahid
@aizazshahid
May 04 2017 06:15
@the-vampiire got it like callback function !
jmariomejiap
@jmariomejiap
May 04 2017 06:16
@the-vampiire @forwebtech getChanInfo() takes an array of channels that is declared at the very top of the script. and for each channel I used connectAPI() function to connect to and find out whether the channel is currently streaming or not.
Aizaz Shahid
@aizazshahid
May 04 2017 06:16
@jmariomejiap are you using callback method in to your API method ??
jmariomejiap
@jmariomejiap
May 04 2017 06:17
@forwebtech yes.
Aizaz Shahid
@aizazshahid
May 04 2017 06:18
may be it will clear the concept !
var a = 100;
someMethod( function() {

a = 20;
});

console.log(a);  // 100
Vamp
@the-vampiire
May 04 2017 06:18
maybe i am missing something but nowhere in your code are you looping through your array of channels and calling to get their info
also you declare ‘current channel’ = channel ye use channel everywhere else. just pass channel into your object no need for this variable
Markus Kiili
@Masd925
May 04 2017 06:19
@gummybear00 Using global i there messes it up. Use var i=... on the loop declarations.
jmariomejiap
@jmariomejiap
May 04 2017 06:19
each channel gets checkout to the api and depending on whether the channel is online or offline I append the result to an object (channelsInfo)
Aizaz Shahid
@aizazshahid
May 04 2017 06:19
@jmariomejiap as far as i know your callback methods can't set your global variables or neither you can retrieve any variable from that method ! but you can return some value from it !
Andrea Farina
@Sepharvaim
May 04 2017 06:20

var myArr = [ 2, 3, 4, 5, 6];

// Only change code below this line
var total = 0;
for (var i = 0; i < myArr.length; i++) {
total += myArr[i];
} someone can explain me the logic behind this? its working but i dont how

know*
Aizaz Shahid
@aizazshahid
May 04 2017 06:21
@Sepharvaim do you know about array index ??
Andrea Farina
@Sepharvaim
May 04 2017 06:22
not so much
Aizaz Shahid
@aizazshahid
May 04 2017 06:23
[1,  2,  3,  4]   => length is 4
 |  |   |   |
 V  V   V   V
 0  1   2   3
jmariomejiap
@jmariomejiap
May 04 2017 06:23
@forwebtech my Idea is probably very silly. and probably there is no need for all this but why can i console.log the object right before i run the loop. it is as if the object is populated at that point.
Aizaz Shahid
@aizazshahid
May 04 2017 06:23
@Sepharvaim as arrays have index numbers behind the values that are automatically set for you, and to access all values one by one you need loop / iterator !
and this += operator adds the right variable or literal value to the left variable
jmariomejiap
@jmariomejiap
May 04 2017 06:25

`function reader (ob) {
console.log("inside ", ob); ///// object with data received from api

console.log(Object.keys(ob));

};
reader(channelsInfo); `

Aizaz Shahid
@aizazshahid
May 04 2017 06:25
@Sepharvaim
a = a + 2;
// equal to

a += 2;
Vamp
@the-vampiire
May 04 2017 06:26
@jmariomejiap it works for me
Masaki
@masaki1223
May 04 2017 06:26

```var Bike = function() {

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

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

};

var myCar = new Car();

var myBike = new Bike();
``` Why does this not work?

Vamp
@the-vampiire
May 04 2017 06:26
@jmariomejiap sorry I didnt follow your code is all over the place
Screen Shot 2017-05-04 at 2.25.48 AM.png
is this what you wanted?
Aizaz Shahid
@aizazshahid
May 04 2017 06:26
so the logic is that, loop is getting to each value of that array and adding it to your total, one by one so at last you have sum of all numbers present in that array, into total
Masaki
@masaki1223
May 04 2017 06:28
var Bike = function() {

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


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

};

var myCar = new Car();

var myBike = new Bike();
Aizaz Shahid
@aizazshahid
May 04 2017 06:28
@masaki1223 .setGear method is used to set the value to your gear but you are actually adding values to it, so just use = assignment operator !
jmariomejiap
@jmariomejiap
May 04 2017 06:30
@the-vampiire sorry. I now it is confusing... in fact I was trying to make more readable.... clearly not happening. I guess what I am trying to do is to create an object that will contained as a key the name of a channel and as a value an object with some data in it, like a <div> template so I can create elements in my page.
Vishesh Dembla
@vishesh-dembla
May 04 2017 06:31
@gummybear00 use var i in both the for loops
Masaki
@masaki1223
May 04 2017 06:31
oh thanks! it solved
Andrea Farina
@Sepharvaim
May 04 2017 06:31
@forwebtech ok ok maybe I got this ! thk
jmariomejiap
@jmariomejiap
May 04 2017 06:32
@the-vampiire now that You got the object and can see it actually has data i thought of making another function "reader()" that will take an object and will loop throught it to find out what channels are "on" or "off". I guess my trouble is located at that point
Vamp
@the-vampiire
May 04 2017 06:33
@jmariomejiap ya I am very confused man. it’s an object but I cant access any of its properties
only way it works is console.log(channelsInfo);
channelsInfo[channel name here] fails. channelsInfo[0] fails etc
jmariomejiap
@jmariomejiap
May 04 2017 06:34
@the-vampiire alternatively, I could just create 2 objects one with channels that are streaming and one for channels that are offline. and avoid this deep fishing for an object withing another object for the value On or Off........ what a silly thing.
sorry for dragging you into this........... i actually thought at some point, like this is a clever idea, but my cleverness very quickly turned into frustration.
Im going to rethink my plan. find a simpler solution for my idea. thanks for your help @the-vampiire @forwebtech
CamperBot
@camperbot
May 04 2017 06:36
jmariomejiap sends brownie points to @the-vampiire and @forwebtech :sparkles: :thumbsup: :sparkles:
:cookie: 399 | @forwebtech |http://www.freecodecamp.com/forwebtech
:cookie: 353 | @the-vampiire |http://www.freecodecamp.com/the-vampiire
Aizaz Shahid
@aizazshahid
May 04 2017 06:36
@jmariomejiap you can't call it outside the function connectAPI (channel) { .... } , it looks like
Vamp
@the-vampiire
May 04 2017 06:37
@jmariomejiap no youre right. i was being stupid and tired
Aizaz Shahid
@aizazshahid
May 04 2017 06:37
because in that function, it returns the object and also Object.keys() working fine !
Vamp
@the-vampiire
May 04 2017 06:38
as I said earlier
anything to do with API data has to take place within the success function
Jovan Pavlovic
@jokisa95
May 04 2017 06:39
function randomRange(myMin, myMax) {

    return Math.floor(Math.random() * (Math.floor(Math.random()) <= myMax) + Math.floor(Math.random()) >= myMin);

}
What is wrong with this?
Vamp
@the-vampiire
May 04 2017 06:39
idk what @forwebtech is talking about it being possible because of an async call. nothing to do with this
I am able to do a console.log(channelsInfo) OUTSIDE the success because chrome’s console populates the object based on its state inside the success function. BUT noting can be done with it because it doesnt actually exist outside there..
thats confusing as shit
jmariomejiap
@jmariomejiap
May 04 2017 06:41
wow. that is confusing
Aizaz Shahid
@aizazshahid
May 04 2017 06:41
@the-vampiire because the function is async ! means updates while further code is running !
Vamp
@the-vampiire
May 04 2017 06:41
the bottom line is remember what I said initially: anything to do with the data returned by an API must take place within the success function.
if you want to populate your html divs then do it within the success
if you want proof
Aizaz Shahid
@aizazshahid
May 04 2017 06:41
@jmariomejiap you need to learn more about asynchronous functions do some search on google !
Vamp
@the-vampiire
May 04 2017 06:42
@forwebtech listen man theres nothing wrong with trying to help people but you confuse them when you proclaim information that is incorrect
no amount of exclamation points makes it correct
Aizaz Shahid
@aizazshahid
May 04 2017 06:42
@the-vampiire do you know what are async methods ??
if you know then correct me otherwise, don't look at my comments !
Vamp
@the-vampiire
May 04 2017 06:43

@jmariomejiap listen. if you want proof of what im saying try this:

console.log(channelsInfo); OUTSIDE the success. you will be returned an object and you can see the value objects as well

however
try console.log(channelsInfo[‘freecodecamp’]) or any other channel OUTSIDE
and you will see ‘undefined'
they do not exist outside
now do the same INSIDE the success function
and it will work properly
Aizaz Shahid
@aizazshahid
May 04 2017 06:44
@jmariomejiap and also have told you that, it is callback method, will not give you that values even it can't set your global value !
Vamp
@the-vampiire
May 04 2017 06:44
@forwebtech im not going to argue with you. its been several nights that I have wasted time arguing with you when youre wrong. if you are not 100% about something then dont respond because you will end up confusing people
jmariomejiap
@jmariomejiap
May 04 2017 06:45
@forwebtech @the-vampiire I was aware of the async nature of the object... what threw me off was the ability of console.log() the object vs. looping over it.
Aizaz Shahid
@aizazshahid
May 04 2017 06:45
@jmariomejiap look at this again, :point_up: May 4, 2017 11:18 AM
@jmariomejiap try to make a file into your pc and test with it !
you will get my point !
Spyrantis Theodoros
@thodorisanta
May 04 2017 06:46
the same project i made in opera looks different(some things are messed up) when i open the same project on chrome. Why? And how can i fix this?
Vamp
@the-vampiire
May 04 2017 06:46
@jmariomejiap you can loop over it just fine INSIDE the success callback
you can not do this outside, the object does not exist
Aizaz Shahid
@aizazshahid
May 04 2017 06:46
@thodorisanta because each browsers have its own engine to interpret the languages !
Spyrantis Theodoros
@thodorisanta
May 04 2017 06:47
@forwebtech and how can i fix this?
Aizaz Shahid
@aizazshahid
May 04 2017 06:47
that's why you have seen somthing different but for that you can search browser comparability !