9th
Jun 2017
Manish Giri
@Manish-Giri
Jun 09 2017 00:03
@BrianCodes33 your outermost return is a .map()
it will return an array
andrewmparker
@andrewmparker
Jun 09 2017 00:06

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 "K":
case "Q":
case "J":
case "A":
count--;
break;
}
if (count > 0) {
return count + "Bet";
} else {
return count + "Hold";
} I don't see where i went wrong. Will some please explain this to me???

Manish Giri
@Manish-Giri
Jun 09 2017 00:06
space
before Bet/Hold
@andrewmparker
andrewmparker
@andrewmparker
Jun 09 2017 00:07
lol thx @Manish-Giri
CamperBot
@camperbot
Jun 09 2017 00:07
andrewmparker sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 5889 | @manish-giri |http://www.freecodecamp.com/manish-giri
Long Nguyen
@longnt80
Jun 09 2017 00:12

@chocobrownie

Question: why do ppl need to have a constructor when there are functions already? What's the advantage?

good question

@chocobrownie I think the use of constructor is to reuse the property inside, in case you want to use the same object again but with different arguments
Yonahv
@Yonahv
Jun 09 2017 00:18
Hey I need help, im going crazy
Jun 09 2017 00:20
@Yonahv whats up?
Long Nguyen
@longnt80
Jun 09 2017 00:21
@nzraad too late, he's gone crazy
Yonahv
@Yonahv
Jun 09 2017 00:23

function isLess(a, b) {
// Fix this code
switch (isLess) {
case a < b: return true; break;
case a > b: return false; break;
}
}

// Change these values to test
isLess(10, 15);

@longnt80 hahaha
Jun 09 2017 00:24
@Yonahv you're not doing cases right
'''
switch(expression) {
case n:
code block
break;
case n:
code block
break;
default:
code block
}
'''
CamperBot
@camperbot
Jun 09 2017 00:24
:bulb: to format code use backticks!  more info
André
@andregomesp
Jun 09 2017 00:25

Hi guys. How can you make a function return an array?

//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"] } ];\

wait a sec, let me fix that
Yonahv
@Yonahv
Jun 09 2017 00:26
i dont understand
I used it like this in previous exercises and it worked
You can help me?
André
@andregomesp
Jun 09 2017 00:27
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"]
}
];
I would like to have a function that return an array that return all the first names (for example), how can i archieve that?
Jun 09 2017 00:27
@Yonahv change isLess in the switch block to a
@andregomesp you just do a loop function with contacts[loopVariable].firstname and you set it to a new array like firstnamesArray and then you return that.
Long Nguyen
@longnt80
Jun 09 2017 00:30
@Yonahv you don't need to use switch in that lesson
Yonahv
@Yonahv
Jun 09 2017 00:30
This lesson is for switch
Jun 09 2017 00:30
@Yonahv did it work what I said?
Yonahv
@Yonahv
Jun 09 2017 00:31
no brother
André
@andregomesp
Jun 09 2017 00:31
@nzraad is there another method that would allow me to have them be returned directly without the new array?
@nzraad This is the Profile Lookup challenge, in case you are wondering.
Jun 09 2017 00:31
@andregomesp not really, unless you only want to return one name.
André
@andregomesp
Jun 09 2017 00:32
I see. I will try what you suggested.
CamperBot
@camperbot
Jun 09 2017 00:32
andregomesp sends brownie points to @nzraad :sparkles: :thumbsup: :sparkles:
Long Nguyen
@longnt80
Jun 09 2017 00:32
@Yonahv first of all, if you return then you don't need break
Jun 09 2017 00:33
@longnt80 but that still shouldn't result in an error right? Since it never hits the break regardless.
Long Nguyen
@longnt80
Jun 09 2017 00:33
@Yonahv second, you don't use switch expression with the function name
@nzraad he should learn the fundamentals
Yonahv
@Yonahv
Jun 09 2017 00:33
Thanks
So
function isLess(a, b) {
// Fix this code
switch (a, b) {
??
Jun 09 2017 00:34
@Yonahv Switch can only take one variable
Long Nguyen
@longnt80
Jun 09 2017 00:34
@Yonahv if you really want to use switch, here's the way:
function isLess(a, b) {
// Fix this code
switch (true) {
case a < b:
return true;
case a > b:
return false;
}

}

// Change these values to test
isLess(10, 15);
Yonahv
@Yonahv
Jun 09 2017 00:35
I work, but I do not understand why "true", Could you tell me?
Long Nguyen
@longnt80
Jun 09 2017 00:36
because you use comparing operator as cases in the switch
Brian
@BrianCodes33
Jun 09 2017 00:36
can someone help me with this
function duckDuckGoose(players, goose) {
for (var i = 1; i < players.length; i++) {

}
}
stuck
Long Nguyen
@longnt80
Jun 09 2017 00:37
@Yonahv but I think you missed the purpose of that lesson
@Yonahv look at the example of FCC, they remove the if /else statement and only return a comparing which can be true or false
comparison operators return a boolean true or false value
Yonahv
@Yonahv
Jun 09 2017 00:40
i have a question
ArchivalBoat50
@ArchivalBoat50
Jun 09 2017 00:40
Hey guys I'm working on a weather app, but I want to have a video gif like background for depending on what the day is, Where can I find these?
https://codepen.io/ArchivalBoat50/pen/OgJZGR
Long Nguyen
@longnt80
Jun 09 2017 00:40
@Yonahv the purpose of the lesson is: Returning Boolean Values from Functions
Yonahv
@Yonahv
Jun 09 2017 00:41
True is not a variable and I thought that switch was to change varibles
Switch is for variables or for values?
Slava Knyazev
@knyzorg
Jun 09 2017 00:42
Switch is for cases
Its a substitute for abusing if statements
Long Nguyen
@longnt80
Jun 09 2017 00:45
@Yonahv you meant the expression? expression is just something to matched against the cases
Joseph
@revisualize
Jun 09 2017 00:47
Hey.
Long Nguyen
@longnt80
Jun 09 2017 00:47
in the example I gave you true is the expression, then the switch will go through each case
the first case is a < b so it compare against the expression
true === (a < b)
so if a < b is true then true === true
Joseph
@revisualize
Jun 09 2017 00:48
Why would you use a switch like that instead of an if / else if / else
Makes no sense.
Long Nguyen
@longnt80
Jun 09 2017 00:49
@revisualize actually, there's no need for even if/else in that lesson
Yonahv
@Yonahv
Jun 09 2017 00:49
Hmmmm I'm understanding!
Joseph
@revisualize
Jun 09 2017 00:50
What?
Long Nguyen
@longnt80
Jun 09 2017 00:50
Joseph
@revisualize
Jun 09 2017 00:50
Oh. Yeah.
Just return the bool
ArchivalBoat50
@ArchivalBoat50
Jun 09 2017 00:51
Hey guys I'm working on a weather app, but I want to have a video gif like background for depending on what the day is, Where can I find these?
https://codepen.io/ArchivalBoat50/pen/OgJZGR
Joseph
@revisualize
Jun 09 2017 00:51
But otherwise... is there a reason to do a switch like you stated above with true as the conditional?
Long Nguyen
@longnt80
Jun 09 2017 00:51
@revisualize no, if else make more sense, but @Yonahv wanted to use switch so
Yonahv
@Yonahv
Jun 09 2017 00:53
Long, thanks for all
bye
Long Nguyen
@longnt80
Jun 09 2017 00:53
@Yonahv make sure you understand the purpose of lesson too
Barack12
@Barack12
Jun 09 2017 00:55
case 3, 7, "Q", 8, "A": return "-1 Hold";
Yonahv
@Yonahv
Jun 09 2017 00:55
Yes, I am understanding, anyway, I will review tomorrow with a programmer
Barack12
@Barack12
Jun 09 2017 00:55
CAN ANYONE HELP IS THE ONLY ONE THAT IS NOT EXECUTING?
Moisés Man
@moigithub
Jun 09 2017 00:56

case syntax is wrong.. u cant separate values with commas
should be

case 3:
case 4:
//some command
break;

inside a switch( variable ) {} block
@Barack12
also ur cases should INcrease or DECrease count value
and ONLY return (after switch block) after evaluate count

Barack12
@Barack12
Jun 09 2017 00:57
OK I WILL TRY THAT!
andrewmparker
@andrewmparker
Jun 09 2017 00:58

var myObj = {
pet: "kitten",
bed: "sleigh"
};

function checkObj(checkProp) {
if (myObj.hasOwnProperty("checkProp") === true) {return myObj[checkProp];
} else {
}
}
// Test your code by modifying these values
what i am missing?????

connor-5
@connor-5
Jun 09 2017 00:58
I have a loop in this function, but it's only iterating for the first value of 'i'. Any ideas what's wrong with this?
function mutation(arr) {
var zero = arr[0].toLowerCase();
var one = arr[1].toLowerCase();
for (var i = 0; i < one.length; i++) {
if ((zero.indexOf(one[i])) == -1) {
return false;
}
else {
return zero.indexOf(one[i]);
}
}
}
mutation(["hEllo", "hey"]);
Moisés Man
@moigithub
Jun 09 2017 00:58
@andrewmparker checkProp is a variable (function parameter)
NO quotes on it (else it will be treated literally as a string)
andrewmparker
@andrewmparker
Jun 09 2017 00:59
oh thx @moigithub
CamperBot
@camperbot
Jun 09 2017 00:59
andrewmparker sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3344 | @moigithub |http://www.freecodecamp.com/moigithub
Moisés Man
@moigithub
Jun 09 2017 01:00
@connor-5 return keyword exit the function immediatelly...
u should return true or false values
AJ Brommy
@AJ-Brommy
Jun 09 2017 01:00
@connor-5 because your variable one length == 1
connor-5
@connor-5
Jun 09 2017 01:01
@moigithub okay so if i define a variable inside the loop and put the return outside of it that'll work?
AJ Brommy
@AJ-Brommy
Jun 09 2017 01:01
@connor-5 actually i don't know, if "hey" is what is being put into one, then I suppose length should be 3
connor-5
@connor-5
Jun 09 2017 01:03
@AJ-Brommy yeah it's supposed to run the loop for any length of any string
AJ Brommy
@AJ-Brommy
Jun 09 2017 01:03
Yes @moigithub is right, what are you trying to achieve? perhaps you could concat a variable and then return it once it is complete?
Long Nguyen
@longnt80
Jun 09 2017 01:03
@connor-5 maybe push the value to an empty array instead of return
connor-5
@connor-5
Jun 09 2017 01:04
it's supposed to test if the letters in the second piece of the array are all present in the first part
so arr[0] needs to return false if it doesn't have all the characters that arr[1] has
Moisés Man
@moigithub
Jun 09 2017 01:05
"army" vs "Mary" shoould return true.. cuz all letters of "Mary" are on "army"
"hello" vs "hey" should return false cuz "y" is NOT on "hello"
connor-5
@connor-5
Jun 09 2017 01:06
@moigithub yeah exactly
Moisés Man
@moigithub
Jun 09 2017 01:06
soo thing is.. when would be the correct timing to return true .. or false
connor-5
@connor-5
Jun 09 2017 01:07
return true when (zero.indexOf(one[i]) is not equal to -1
sorry, the one i pasted into the chat earlier had an error cuz i was tinkering with it lol (should read else { return true}. But no it still doesn't work like that
@moigithub oh sorry, i didn't understand you at first. Yeah I guess it's a question of when to return. But the code editor won't let me make the return outside the loop...
Moisés Man
@moigithub
Jun 09 2017 01:09
and.. what value(s) u need to return
Moisés Man
@moigithub
Jun 09 2017 01:13
moVe return true outside the loop
no else block needed
connor-5
@connor-5
Jun 09 2017 01:16
how isn't there an else block needed?
connor-5
@connor-5
Jun 09 2017 01:23
well, i figured out a way to do it, but it's very inelegant lol but thanks anyway @moigithub
CamperBot
@camperbot
Jun 09 2017 01:23
connor-5 sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3345 | @moigithub |http://www.freecodecamp.com/moigithub
Tim Parsons
@timmparsons
Jun 09 2017 01:23
hi, has anyone else done the euler project? I've just started
Maximino V. Jardin III
@ma5one1
Jun 09 2017 01:29

Im NOT connecting with this excercise...Halp please.
function titleCase(str, bingo) {

var string = str.toUpperCase(bingo);

console.log(string);

return str;
}

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

connor-5
@connor-5
Jun 09 2017 01:32
@ma5one1 first, you don't want to put bingo inside the toUpperCase function
Mario Ley Tello
@23marioley
Jun 09 2017 01:32
´´´
connor-5
@connor-5
Jun 09 2017 01:33
writing str.toUpperCase() is enough
Mario Ley Tello
@23marioley
Jun 09 2017 01:33

´´´ //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 (firstName == contacts[i].firstName){
} else if(firstName != contacts[i].firstName){
} else if(contacts[i].hasOwnProperty(prop) === false){
}
}

// Only change code above this line
}

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

´´´
//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 (firstName == contacts[i].firstName){
} else if(firstName != contacts[i].firstName){
} else if(contacts[i].hasOwnProperty(prop) === false){
}
}

// Only change code above this line
}

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

//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 (firstName == contacts[i].firstName){
} else if(firstName != contacts[i].firstName){
} else if(contacts[i].hasOwnProperty(prop) === false){
}
}

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Kristian", "lastName");
Maximino V. Jardin III
@ma5one1
Jun 09 2017 01:34
@connor-5 No success..Are the lines in the function correct?
Mario Ley Tello
@23marioley
Jun 09 2017 01:35
Can somebody tell me what's wrong with my code?
I need to print the value of the property in the function
(prop)
connor-5
@connor-5
Jun 09 2017 01:36
@ma5one1 no that's just to start. you can't use console.log at all. I'd recommend starting by splitting the string into an array with each word in it.
Christopher McCormack
@cmccormack
Jun 09 2017 01:36
@23marioley you're changing answer everytime, you should return early in two scenarios
Maximino V. Jardin III
@ma5one1
Jun 09 2017 01:37
@23marioley might be the equal operator on your first IF line..might need to add one more '=' sign??
@connor-5 thanks
CamperBot
@camperbot
Jun 09 2017 01:37
ma5one1 sends brownie points to @connor-5 :sparkles: :thumbsup: :sparkles:
Mario Ley Tello
@23marioley
Jun 09 2017 01:40
function lookUpProfile(firstName, prop){
// Only change code below this line

for (var i=0; i<contacts.length; i++){
if (firstName == contacts[i].firstName){
} else if(firstName != contacts[i].firstName){
} else if(contacts[i].hasOwnProperty(prop) === false){
}
}

// Only change code above this line
}
@cmccormack like this?
Christopher McCormack
@cmccormack
Jun 09 2017 01:42
@23marioley you can return without assigning to answer
@23marioley you're also never returning No such property
Mario Ley Tello
@23marioley
Jun 09 2017 01:42
okok, I'll try that
Christopher McCormack
@cmccormack
Jun 09 2017 01:43
@23marioley read through the instructions again - you should only return No such contact after checking ALL contact. Also No such property should only be returned if you found a matching contact but no matching property
Mario Ley Tello
@23marioley
Jun 09 2017 01:45
Can we go private? @cmccormack
Christopher McCormack
@cmccormack
Jun 09 2017 01:45
if you like
AJ Brommy
@AJ-Brommy
Jun 09 2017 01:50
Guys, is building a regExp as a string allowed? should it still work? I mean if we do it in quotes?
So we can use variables, e.g. "/[" + arr[1] + "]/gi"
Christopher McCormack
@cmccormack
Jun 09 2017 01:52
@AJ-Brommy what are you using it with?
AJ Brommy
@AJ-Brommy
Jun 09 2017 01:53
ah ok... arr.indexOf()
Christopher McCormack
@cmccormack
Jun 09 2017 01:53
@AJ-Brommy if you're using a regexp literal you need the / but not if you're using a string
Claudio Restifo
@Marmiz
Jun 09 2017 01:53

@AJ-Brommy you can use a RegEXp object as:

var x = 'something'
var regexp = new RegExp(x, "gi");

But generally speaking is not a good idea :)

Christopher McCormack
@cmccormack
Jun 09 2017 01:54
@AJ-Brommy index of takes a string
youssefelmajbri
@youssefelmajbri
Jun 09 2017 01:55
var myStr="\"FirstLine\n \\SecondLine\\ \r ThirdLine \"";
myStr should have encoded text with the proper escape sequences and no spacing.
AJ Brommy
@AJ-Brommy
Jun 09 2017 01:55
ok, so it will look for a match and not run the regExp... damn.. back to the drawing board... that will explain why all return - 1hahaha
@cmccormack oh, so what does literal mean, as in if i wasn't building it the way I am, with quotes? so "[" + arr[1] + "]gi", would be right?
Claudio Restifo
@Marmiz
Jun 09 2017 01:57
@youssefelmajbri the double quotes are quite off, plus there should be no space inside the string
Christopher McCormack
@cmccormack
Jun 09 2017 01:57
@AJ-Brommy /[A-Za-z]/ig is a regex literal
AJ Brommy
@AJ-Brommy
Jun 09 2017 01:57
ok
ok, well, how do i put a variable in the A-Z part then
because /[arr[1] ]/gi isn't going to work!
youssefelmajbri
@youssefelmajbri
Jun 09 2017 02:00
@Marmiz You mean like this :
var myStr="\"FirstLine\n\\SecondLine\\\rThirdLine\"";
Claudio Restifo
@Marmiz
Jun 09 2017 02:02

I mean something like:

var myStr="[my string and the escaped char inside here]";

You see that there are only two " @youssefelmajbri

yash5657
@yash5657
Jun 09 2017 02:02
hey all :)
Nirab Shrestha
@Nirav11
Jun 09 2017 02:03
@zcassini You there?
Zac Cassini
@zcassini
Jun 09 2017 02:03
@Nirav11 yeah, you lose me when u switch channels
yash5657
@yash5657
Jun 09 2017 02:03
can some one suggest me good resource to learn completely about RegEx??
eyesore-
@eyesore-
Jun 09 2017 02:04
http://regexr.com/ is very useful.
Jun 09 2017 02:04
can somene try if he get a response or a 403 error please, I exceeded the rate limit from here https://dev.adel-mahjoub.fr/ng-github-profile-lookup/
AJ Brommy
@AJ-Brommy
Jun 09 2017 02:05
don't worry, i've solved it now
eyesore-
@eyesore-
Jun 09 2017 02:05
yash5657
@yash5657
Jun 09 2017 02:06
@eyesore- looks good ... thanks
CamperBot
@camperbot
Jun 09 2017 02:06
yash5657 sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
eyesore-
@eyesore-
Jun 09 2017 02:06
@yash5657 No problem!
Christopher McCormack
@cmccormack
Jun 09 2017 02:07

@AJ-Brommy if you want to add a variable to a regexp you can create a new RegExp object :

> var a = new RegExp('[A-Z]')
> a
/[A-Z]/

youssefelmajbri
@youssefelmajbri
Jun 09 2017 02:07
@Marmiz Thank you
CamperBot
@camperbot
Jun 09 2017 02:07
youssefelmajbri sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
Claudio Restifo
@Marmiz
Jun 09 2017 02:07
@youssefelmajbri :+1:
Nirab Shrestha
@Nirav11
Jun 09 2017 02:09
@zcassini hahaha :P

function mutation(arr) {

var a = arr[0].toLowerCase();
var b= arr[1].toLowerCase();
for(var i=0;i<a.length;i++){
if(b.indexOf(a[i])!==-1) {
return true;
} // true

}
return false;

}

mutation(["hello", "hey"]);
AJ Brommy
@AJ-Brommy
Jun 09 2017 02:09
@Marmiz why is it not a good idea?
Jun 09 2017 02:14
@eyesore- thanks
CamperBot
@camperbot
Jun 09 2017 02:14
adelmahjoub sends brownie points to @eyesore- :sparkles: :thumbsup: :sparkles:
Claudio Restifo
@Marmiz
Jun 09 2017 02:26
@AJ-Brommy Because someone can inject malign code through it, so you have to take extra steps to be sure to sanitise the input before it happens :)
In this case you're probably safe but it's still something to be aware of
The evergreen Bobby Tables
Iczac Icecold
@Iczac
Jun 09 2017 02:28

Hello can someone check this for me please

'''
function truncateString(str, num) {

var sent_length = str.length;
var end_index = num - 4;
var result,final;

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

}
'''

CamperBot
@camperbot
Jun 09 2017 02:28
:bulb: to format code use backticks!  more info
André
@andregomesp
Jun 09 2017 02:29
@23marioley Hey, you still need help with the Profile Lookup challenge? I beat it just now.
AJ Brommy
@AJ-Brommy
Jun 09 2017 02:30
Ok thanks @Marmiz
CamperBot
@camperbot
Jun 09 2017 02:30
aj-brommy sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
Prabukarthik
@prabukarthik
Jun 09 2017 02:31
Hi, I am stuck on lookUpProfile function challenge..
function lookUpProfile(firstName, prop) {
// Only change code below this line
for(var i=0;i<contacts.length;i++) {
if(firstName == contacts[i].hasOwnProperty(firstName)) {
if (prop == contacts[i].hasOwnProperty(prop)) {
return contacts[i].prop;
} else {
return "no such property";
}
return contacts[i].firstName;
} else {
return "No such contacts";
}
}
// Only change code above this line
}
Not sure where I am wrong
Ogundele Olumide
@Lumexralph
Jun 09 2017 02:32
@prabukarthik
Here's an outline, if you follow it step-wise it'll help a great deal in telling you what to do or step you missed
1. you need a loop to pick each objects in the contacts array
1.1  in the loop you need to
1.1.1  check if the objects picked has the firstName property equal to the firstName parameter
1.1.1.1 you need to check if it has a property prop
return the value of prop in the object
1.1.1.2  return no such property if  1.1.1.1 is false
2.  when your loop is done looking through  contacts return no such contact
Prabukarthik
@prabukarthik
Jun 09 2017 02:34
ok thank you..let me check
André
@andregomesp
Jun 09 2017 02:34
@prabukarthik I just sent you a private message.
Iczac Icecold
@Iczac
Jun 09 2017 02:36
can someone help me with my code please?
function truncateString(str, num) {

var sent_length = str.length;
var end_index = num - 4;
var result,final;

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

}
it works for everything except this
CreateTheHype
@CreateTheHype
Jun 09 2017 02:44
can someone help me with the challenge. Access MultiDimensional Arrays With Indexes
Christopher McCormack
@cmccormack
Jun 09 2017 02:46
@Iczac I believe you should not be adding ellipses if the two strings are the same length, correct?
Nisarg Patel
@Nppatel97
Jun 09 2017 02:48
I'm trying to solve this challenge but don't understand what i am doing wrong. Can someone please help me out?
Christopher McCormack
@cmccormack
Jun 09 2017 02:49
CreateTheHype
@CreateTheHype
Jun 09 2017 02:50
@cmccormack i got it thanks
CamperBot
@camperbot
Jun 09 2017 02:50
createthehype sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
Diego Mayer
@Chrono79
Jun 09 2017 02:50
@Nppatel97 toLowerCase() returns a new string, you have to assign it back to your string for the change to apply
The same for join()
Nisarg Patel
@Nppatel97
Jun 09 2017 02:51
@cmccormack "[^a-z0-9]" Doesn't this remove spaces as well?
Christopher McCormack
@cmccormack
Jun 09 2017 02:51
@Nppatel97 nope nothing in your regex matches a space
Diego Mayer
@Chrono79
Jun 09 2017 02:52
@cmccormack the regex is ok
Christopher McCormack
@cmccormack
Jun 09 2017 02:52
ah sorry you're correct, that's what I get for looking while on a phone call
Diego Mayer
@Chrono79
Jun 09 2017 02:52
:+1:
@Nppatel97 fix what I told you
Nisarg Patel
@Nppatel97
Jun 09 2017 02:54
@Chrono79 Yeah, so just like, str = x.toLowerCase(), right?
Diego Mayer
@Chrono79
Jun 09 2017 02:54
@Nppatel97 yes, or you could chain methods
Nisarg Patel
@Nppatel97
Jun 09 2017 02:55
@Chrono79 gotcha! Thank you :smile:
CamperBot
@camperbot
Jun 09 2017 02:55
nppatel97 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4229 | @chrono79 |http://www.freecodecamp.com/chrono79
Nisarg Patel
@Nppatel97
Jun 09 2017 02:56
@Chrono79 It Worked! Feels so good when it works :fire:
Diego Mayer
@Chrono79
Jun 09 2017 02:57
:clap:
Joseph
@revisualize
Jun 09 2017 02:57
YO.
Diego Mayer
@Chrono79
Jun 09 2017 02:58
:wave:
Mario Ley Tello
@23marioley
Jun 09 2017 03:15
function lookUpProfile(firstName, prop){
// Only change code below this line

for (var i=0; i<contacts.length; i++){
if (firstName == contacts[i].firstName){
if (contacts[i].hasOwnProperty(prop)){
return contacts[i][prop];
} else {
return "No such property";
}
} else {
return "No such contact";
}
}

// Only change code above this line
}
can somebody help me in this challenge?
"Profile Lookup"
K L Bhanu
@klbm9999
Jun 09 2017 03:16
hello, i have a scope error as i have been told, some help is appreciated
var app = new Vue({
el: "#app",
data: {
searchText: "",
"https://en.wikipedia.org/w/api.php?action=opensearch&format=jsonfm",
wiki_data: ""
},
watch: {
searchText: function(search) {
this.set_wiki(search);
this.results();
console.log("wiki data is"+this.wiki_data);
}
},
methods: {
set_wiki: function(search) {
"https://en.wikipedia.org/w/api.php?action=opensearch&format=json&callback=?&search=" +
encodeURIComponent(search);
},
random: function() {
window.open("https://en.wikipedia.org/wiki/Special:Random", "_blank");
},
results: function() {
$.ajax({ url: this.wiki_address, dataType: "jsonp", success: function(response) { // console.log("This is success"); // console.log(response); this.wiki_data = response; console.log(this.wiki_data); }, error: function(err) { console.log("This is error"); console.log(err); } }); } } }); how to set data to wiki_data? @23marioley your second else is wrong, ie if the first recerd in contacts is not matched it will return "no such contact", skipping all other contacts. change it to something like "if matched, then do your thing else continue the loop', after that "if the loop is complete, that means contact not found".. Ogundele Olumide @Lumexralph Jun 09 2017 03:21 @23marioley when the loop is done looking through contacts and can't find it, return no such contacts after the loop not in it fdemaa @fdemaa Jun 09 2017 03:22 hi guys im starting with the theory , can anyone explain me some stuffs with an exercise Ogundele Olumide @Lumexralph Jun 09 2017 03:24 @fdemaa ask your question Mario Ley Tello @23marioley Jun 09 2017 03:25 @klbm9999 @Lumexralph thank you guys, it worked CamperBot @camperbot Jun 09 2017 03:25 23marioley sends brownie points to @klbm9999 and @lumexralph :sparkles: :thumbsup: :sparkles: :cookie: 277 | @klbm9999 |http://www.freecodecamp.com/klbm9999 :star2: 1885 | @lumexralph |http://www.freecodecamp.com/lumexralph HappyRedditor59 @HappyRedditor59 Jun 09 2017 03:28 can someone pls look at my code? im stuck on Profile Lookup and it only shows ReferenceError: lastName is not defined on the console. This is the code: //Setup var contacts = [ { "firstName": "Akira", "lastName": "Laine", "number": "0543236543", "likes": ["Pizza", "Coding", "Brownie Points"] }, { "firstName": "Harry", "lastName": "Potter", "number": "0994372684", "likes": ["Hogwarts", "Magic", "Hagrid"] }, { "firstName": "Sherlock", "lastName": "Holmes", "number": "0487345643", "likes": ["Intriguing Cases", "Violin"] }, { "firstName": "Kristian", "lastName": "Vos", "number": "unknown", "likes": ["Javascript", "Gaming", "Foxes"] } ]; function lookUpProfile(firstName, prop){ // Only change code below this line for (firstName in contacts){ var something = contacts[firstName]; if (prop == contacts[lastName]){ something = contacts[lastName]; } else if (prop == contacts[number]){ something = contacts[number]; } else if (prop == contacts[likes]){ something = contacts[likes]; } return something; } // Only change code above this line } // Change these values to test your function lookUpProfile("Akira", "likes"); fdemaa @fdemaa Jun 09 2017 03:29 i have this exercise: // Setup var processed = 0; function processArg(num) { return (num + 3) / 5; } // Only change code below this line var processed = processArg(7); why if i changed the value of var processed still dont affect my result in console ? Ogundele Olumide @Lumexralph Jun 09 2017 03:30 @HappyRedditor59 firstly for....in loop is best for an unordered data structure like object or Set, array is ordered HappyRedditor59 @HappyRedditor59 Jun 09 2017 03:31 @Lumexralph what type of loop should i use? Ogundele Olumide @Lumexralph Jun 09 2017 03:33 @HappyRedditor59 firstName is the variable holding the respective keys/properties per iteration , lastName is not the variable used by your loop so it came as undefined @HappyRedditor59 i'll use a for loop or any form of looping best for an array structure @fdemaa you don't need to use var with processed again, it's already been declared above HappyRedditor59 @HappyRedditor59 Jun 09 2017 03:35 thanks for pointing that out @Lumexralph CamperBot @camperbot Jun 09 2017 03:35 happyredditor59 sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles: :star2: 1886 | @lumexralph |http://www.freecodecamp.com/lumexralph Ogundele Olumide @Lumexralph Jun 09 2017 03:37 @HappyRedditor59 :+1: fdemaa @fdemaa Jun 09 2017 03:37 @Lumexralph thanks man , im feeling like a stupid in the introduction of js already xd CamperBot @camperbot Jun 09 2017 03:37 fdemaa sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles: :star2: 1887 | @lumexralph |http://www.freecodecamp.com/lumexralph Ogundele Olumide @Lumexralph Jun 09 2017 03:38 @fdemaa you'll be fine brenbroussard @brenbroussard Jun 09 2017 03:41 C B HappyRedditor59 @HappyRedditor59 Jun 09 2017 03:45 @Lumexralph my code shows blank and i am terribly frustrated at this point //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++){ var something = contacts[firstName]; for (var j = 0; j < contacts[i].length; j++){ something = contacts[i].prop; } return something; } // Only change code above this line } // Change these values to test your function lookUpProfile("Akira", "likes"); Ogundele Olumide @Lumexralph Jun 09 2017 03:45 @HappyRedditor59 you need a loop @HappyRedditor59 Here's an outline, if you follow it step-wise it'll help a great deal in telling you what to do or step you missed 1. you need a loop to pick each objects in the contacts array 1.1 in the loop you need to 1.1.1 check if the objects picked has the firstName property equal to the firstName parameter 1.1.1.1 you need to check if it has a property prop return the value of prop in the object 1.1.1.2 return no such property if 1.1.1.1 is false 2. when your loop is done looking through contacts return no such contact HappyRedditor59 @HappyRedditor59 Jun 09 2017 03:46 @Lumexralph thanks so much man, you're a lifesaver K L Bhanu @klbm9999 Jun 09 2017 03:49 @klbm9999 hello, i have a scope error as i have been told, some help is appreciated var app = new Vue({ el: "#app", data: { searchText: "", wiki_address: "https://en.wikipedia.org/w/api.php?action=opensearch&format=jsonfm", wiki_data: "" }, watch: { searchText: function(search) { this.set_wiki(search); this.results(); console.log("wiki data is"+this.wiki_data); } }, methods: { set_wiki: function(search) { this.wiki_address = "https://en.wikipedia.org/w/api.php?action=opensearch&format=json&callback=?&search=" + encodeURIComponent(search); }, random: function() { window.open("https://en.wikipedia.org/wiki/Special:Random", "_blank"); }, results: function() { // console.log(this.wiki_address);$.ajax({
dataType: "jsonp",
success: function(response) {
// console.log("This is success");
// console.log(response);
this.wiki_data = response;
console.log(this.wiki_data);
},
error: function(err) {
console.log("This is error");
console.log(err);
}
});
}
}
});

how to set data to wiki_data?

Shakeel Khan
@CodeShak
Jun 09 2017 03:53
Hello , Im a Newbie.
heroiczero
@heroiczero
Jun 09 2017 03:54
@CodeShak Hello and Welcome to the HelpJavascript Free code camp Gitter :)
Shakeel Khan
@CodeShak
Jun 09 2017 03:55
Thank you @heroiczero
CamperBot
@camperbot
Jun 09 2017 03:55
codeshak sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1359 | @heroiczero |http://www.freecodecamp.com/heroiczero
Shakeel Khan
@CodeShak
Jun 09 2017 03:55
could you telp me how to assign an a var to a b var
heroiczero
@heroiczero
Jun 09 2017 03:56
@CodeShak
lets see your code and what exercise are you on
Shakeel Khan
@CodeShak
Jun 09 2017 03:57
how can i send a snapshot?
heroiczero
@heroiczero
Jun 09 2017 03:58
@CodeShak just copy and paste code using ''' :point_down:
CamperBot
@camperbot
Jun 09 2017 03:58
:bulb: to format code use backticks!  more info
Moisés Man
@moigithub
Jun 09 2017 03:59
@klbm9999 u could save the this reference on another variable...
var that = this;
and use that inside ur success callback
or bind this to that function
success: function(response) {
}.bind(this),
HappyRedditor59
@HappyRedditor59
Jun 09 2017 03:59
@Lumexralph man am i even doing it right?
//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 (firstName == contacts[i].firstName){
for (var j = 0; j < contacts[i].length; j++){

if (prop == contacts[i]){
return contacts[i];
}
return "No such property";
}
return "No such contact";
}
}
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
so far what ever i input it just shows No such contact
am i even going in the right direcction?
haha
K L Bhanu
@klbm9999
Jun 09 2017 04:01
@HappyRedditor59 1. use hasOwnPropert function, second your loop returns after the first contact itself, it doesnt iterate through the rest
let me try that @moigithub , also, can you suggest some good reading material for scoping in javascript?
HappyRedditor59
@HappyRedditor59
Jun 09 2017 04:02
@klbm9999 thank you very much,, i didn't notice that haha ^_
^
CamperBot
@camperbot
Jun 09 2017 04:02
happyredditor59 sends brownie points to @klbm9999 :sparkles: :thumbsup: :sparkles:
K L Bhanu
@klbm9999
Jun 09 2017 04:02
no problem.
HappyRedditor59
@HappyRedditor59
Jun 09 2017 04:03
^_^
K L Bhanu
@klbm9999
Jun 09 2017 04:03
n6
K L Bhanu
@klbm9999
Jun 09 2017 04:23
*typo
jorgeguz15
@jorgeguz15
Jun 09 2017 04:24

hello anyone know whats wrong here?

var oldArray = [1,2,3,4,5];
// Only change code below this line.
var newArray = oldArray.map(function(a){
return a + 3;
});
var newArray = oldArray;

heroiczero
@heroiczero
Jun 09 2017 04:25
@jorgeguz15 you already assign var newArray = oldArray.map(function(a){ return a + 3; });
why are you making newArray=oldArray;?
jorgeguz15
@jorgeguz15
Jun 09 2017 04:28
oh i see..
Austin Butler
@theaustin
Jun 09 2017 04:34
How do I use the i++ operator? myVar = myVar++
Baibhav Gautam
@baibhavx
Jun 09 2017 04:35
@theaustin just myVar++
no need to use the = operator
Austin Butler
@theaustin
Jun 09 2017 04:35
Oh, thanks @baibhavx
CamperBot
@camperbot
Jun 09 2017 04:35
theaustin sends brownie points to @baibhavx :sparkles: :thumbsup: :sparkles:
Alex
@alextran1502
Jun 09 2017 04:42
Hello can anyone tell me why do my grid image is not contain inside the canvas? css-grid
https://codepen.io/altran1502/pen/rwxaJe?editors=1100
Jun 09 2017 04:46
@OldmanVimes - re: :point_up: June 8, 2017 1:00 AM - did you get an answer to this- I was logged off and away from the computer most of the day. Basically, using testarr was fine for the first test because the first element in testArr was 1. For the second test, if testArr was not reset, then the first element was 2, so that was the expected answer. For the third test, it was not using testArr as the input, but a totally different array, so you were still working with testArr, so that would have been incorrect. For the last test, all of those values that were shifted into testArr just set it up so that it worked even with the incorrect case. I think that it was a cleverly constructed set of tests that was put in there. So if you didn't get an answer about the details, that's my attempt to answer for you.
ms-dosx86
@ms-dosx86
Jun 09 2017 04:48

can someone tell me about symmetric difference?
In the assignment it is said that

sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])
should return [1, 4, 5].

but wiki says: symmetric difference of two sets is the set of elements which are in either of the sets and not in their intersection.
and by the same logic

sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])
should return [1, 1, 4].

because elements 1 1 4 are found only in one array, no more in another.
I cant understand

Jun 09 2017 04:53
@alextran1502 - I'm going to guess that you don't have your column data properly defined? I'm new to the css grid, so I'm looking at some documentation...
wonder
@wonder2991
Jun 09 2017 04:55
@ms-dosx86 compare array1 and 2 then compare the result with array 3
ms-dosx86
@ms-dosx86
Jun 09 2017 04:56
@wonder2991 really? I compared each array to all the others
Jun 09 2017 04:57
@alextran1502 - maybe it's just that the image is too large for the grid? There might be a setting to make it fit.
wonder
@wonder2991
Jun 09 2017 04:58
@ms-dosx86 yeah. that's how i would go about it
abraham anak agung
Jun 09 2017 05:00
@ms-dosx86
[1,1,2,5] and [2,2,3,5] the number in intersection will be 2 and 5 so result will be [1,1,3]
compare [1,1,3] with next array [3,4,5,5] the number in intersection will be 3 so the result is [1,1,4,5,5]
and then remove the duplicate so you get the final result of [1,4,5]
ms-dosx86
@ms-dosx86
Jun 09 2017 05:01
CamperBot
@camperbot
Jun 09 2017 05:01
ms-dosx86 sends brownie points to @wonder2991 and @padunk :sparkles: :thumbsup: :sparkles:
wonder
@wonder2991
Jun 09 2017 05:02
you're welcome! @ms-dosx86
anirudh duggal
@anirudhdggl
Jun 09 2017 05:02
How do I remove all non-alphanumeric characters?
Long Nguyen
@longnt80
Jun 09 2017 05:03
@anirudhdggl use RegExp
@anirudhdggl and use .replace()
anirudh duggal
@anirudhdggl
Jun 09 2017 05:03
@longnt80 I used .replace() but it seems to give an error. Let me send you the code snippet
str = lower.replace(/,|.|<|>|!|@|#|$$|%|^|&|*|-|+|=/,""); lower is a var that contains the string whose all letters are in lower case Long Nguyen @longnt80 Jun 09 2017 05:06 @anirudhdggl regexp has character class that targets non alphanumeric characters what type of error you have? @anirudhdggl \W: Matches any character that is not a word character from the basic Latin alphabet. Equivalent to [^A-Za-z0-9_]. anirudh duggal @anirudhdggl Jun 09 2017 05:09 But how do I use RegExp, I am unable to find its syntax! @longnt80 Ronald T. Casili @nvlled Jun 09 2017 05:09 @anirudhdggl I think you need to escape the characters * and + var str = lower.replace(/,|.|<|>|!|@|#|$$|%|^|&|*|-|+|=/,"");
anirudh duggal
@anirudhdggl
Jun 09 2017 05:09
@longnt80 and the error is invalid regular expression
Ronald T. Casili
@nvlled
Jun 09 2017 05:09
var str = lower.replace(/,|.|<|>|!|@|#|$$|%|^|&|*|-|+|=/,""); anirudh duggal @anirudhdggl Jun 09 2017 05:10 @nvlled I didn't get you Ronald T. Casili @nvlled Jun 09 2017 05:10 whoops wrong one var str = lower.replace(/,|.|<|>|!|@|#|$$|%|^|&|*|-|+|=/,"");
Jun 09 2017 05:10

@alextran1502 - I found that adding bootstrap (v4, the quick add) and adding the class img-fluid to the img element made the image fit the width of the cell. Then I removed that class and just added the properties to your img1 class -

.img1{
max-width: 100%;
height: 100%;
}

It changed the height of the row, but the image was within the cell... that's about all I can try for now. I'll have to learn the grid stuff, it looks interesting.

Ronald T. Casili
@nvlled
Jun 09 2017 05:10
oh man pasted the wrong one, this one for real
var str = lower.replace(/,|.|<|>|!|@|#|$$|%|^|&|*|-|+|=/,""); Long Nguyen @longnt80 Jun 09 2017 05:10 whoops again? anirudh duggal @anirudhdggl Jun 09 2017 05:10 @nvlled isn't it what i wrote? Alvin-Capello @Alvin-Capello Jun 09 2017 05:11 Hello everyone. I am working on the Pig Latin Algorithm Scripting Challenge and I am running into problem. I am trying to write a bare bones simple for loop that checks to see if the first letter in the word is a vowel and to move it the the end if it is. My problem is that the code I am using for this is not working, and I cannot fathom why. Could anyone lend a helping hand? The code is below... Ronald T. Casili @nvlled Jun 09 2017 05:11 haha my clipboard isn't working right Alvin-Capello @Alvin-Capello Jun 09 2017 05:11 function translatePigLatin(str) { var strArr = str.split(""); for (var i = 0; i < 1; i++) { if (strArr[i] === "A" || strArr[i] === "E" || strArr[i] === "I" || strArr[i] === "O" || strArr[i] === "U") { strArr.push(strArr.shift()); } } console.log(strArr); } Long Nguyen @longnt80 Jun 09 2017 05:11 @anirudhdggl go here to test your regexp http://regexr.com/ anirudh duggal @anirudhdggl Jun 09 2017 05:11 @nvlled but your way did! Thanks @nvlled and @longnt80 CamperBot @camperbot Jun 09 2017 05:12 anirudhdggl sends brownie points to @nvlled and @longnt80 :sparkles: :thumbsup: :sparkles: :cookie: 345 | @longnt80 |http://www.freecodecamp.com/longnt80 :cookie: 121 | @nvlled |http://www.freecodecamp.com/nvlled njordomir @njordomir Jun 09 2017 05:12 @Alvin-Capello Not sure if this'll help, but I found using a switch rather than if statements made it much easier to see what my code was doing on that one. Alvin-Capello @Alvin-Capello Jun 09 2017 05:13 @njordomir Perhaps, but why is my strArr.push(strArr.shift()); not removing the first array element and adding it to the end? Long Nguyen @longnt80 Jun 09 2017 05:14 @anirudhdggl it did? Ronald T. Casili @nvlled Jun 09 2017 05:14 huh, I actually pasted it correctly when I try to edit it it seems to hide the backslashes I added... njordomir @njordomir Jun 09 2017 05:17 @Alvin-Capello Is the string lowercase or uppercase? You're using strict equivilancy on your if statement. If the vowel is an a rather than an A it might not match heidisdad2 @heidisdad2 Jun 09 2017 05:17 up dudes whats doing on Long Nguyen @longnt80 Jun 09 2017 05:17 maybe var str = lower.replace(/,|.|<|>|!|@|#|$$|%|^|&|\*|-|\+|=/,"");
Jun 09 2017 05:17
can someone check my code, i think i am off by just a fraction
Long Nguyen
@longnt80
Jun 09 2017 05:17
yeah, it doesn't delete the slash anymore
Jun 09 2017 05:17

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

function checkObj(checkProp) {
var trueFalse = myObj.hasOwnProperty();
return trueFalse;

}

if(trueFalse === true){
var result = myObj[checkProp];
return result;
}else{

var result2 = "no";
return result2;
}
anirudh duggal
@anirudhdggl
Jun 09 2017 05:18

function palindrome(str) {
var lower = str.toLowerCase();
str = lower.replace(/,|.|<|>|!|@|#|$$|%|^|&|-|=/,""); var oster = str.split(""); console.log(oster); str = oster.reverse(); if(str !== oster){ return false; } else{ return true; } } palindrome("nope"); Something's still not right with it. It's showing true for nope! can anyone help me out? Ronald T. Casili @nvlled Jun 09 2017 05:19 @longnt80 I see, it works when it's wrapped in code block anirudh duggal @anirudhdggl Jun 09 2017 05:19 @longnt80 it removed the error, but still some words seem to be giving unexpected return values from the function Alvin-Capello @Alvin-Capello Jun 09 2017 05:19 @njordomir AH YES, OF COURSE! That was the problem. Thank you so much man! You know, these Intermediate Algorithm Challenges have been fairly straightforward so far, but it's funny to think that something so simple could cause such big problems. CamperBot @camperbot Jun 09 2017 05:19 alvin-capello sends brownie points to @njordomir :sparkles: :thumbsup: :sparkles: :cookie: 320 | @njordomir |http://www.freecodecamp.com/njordomir Long Nguyen @longnt80 Jun 09 2017 05:20 @anirudhdggl you need global flag of regexp, and you need the bracket [] Ronald T. Casili @nvlled Jun 09 2017 05:20 test var str = lower.replace(/,|.|<|>|!|@|#|$$|%|^|&|\*|-|\+|=/,"");
Long Nguyen
@longnt80
Jun 09 2017 05:20
@anirudhdggl go here to test your regexp http://regexr.com/
Markus Kiili
@Masd925
Jun 09 2017 05:21
@anirudhdggl You need to compare strings, not arrays.
anirudh duggal
@anirudhdggl
Jun 09 2017 05:21
@longnt80 that seems to scare me! What do I have to do there?
Markus Kiili
@Masd925
Jun 09 2017 05:21
Comparing arrays (objects) doesn't compare content.
njordomir
@njordomir
Jun 09 2017 05:21
@Alvin-Capello oh, cool, it worked! Glad I could help. You're actually right around the same point in the course as I am.
Long Nguyen
@longnt80
Jun 09 2017 05:21
@anirudhdggl the correct regexp with your regexp is:
var str = lower.replace(/[,|.|<|>|!|@|#|$$|%|^|&|\*|-|\+|=]/g, ""); anirudh duggal @anirudhdggl Jun 09 2017 05:21 @Masd925 but I have compare each and every letter so that to know if its a palindrome or not heidisdad2 @heidisdad2 Jun 09 2017 05:22 its telling me it is an illegal return statement Markus Kiili @Masd925 Jun 09 2017 05:22 @anirudhdggl If you compare a string with the reversed one, you get the result with a simple comparison with === Alvin-Capello @Alvin-Capello Jun 09 2017 05:22 @njordomir That's good to know. Good luck with the rest of the course. heidisdad2 @heidisdad2 Jun 09 2017 05:22 think there is just a tiny thing wrong Markus Kiili @Masd925 Jun 09 2017 05:22 @anirudhdggl Another way would be not to use arrays at all and start by comparing the first and last letters etc. anirudh duggal @anirudhdggl Jun 09 2017 05:23 @longnt80 it also seems not to work @Masd925 elaborate please! njordomir @njordomir Jun 09 2017 05:23 It's odd to think I've made it this far without knowing this, but how do you paste code in a black area like people are doing in this channel? Long Nguyen @longnt80 Jun 09 2017 05:23 @anirudhdggl you missing underscore character so var str = lower.replace(/[,|.|<|>|!|@|#|$$|%|^|&|\*|-|\+|=|_]/g, "");
Markus Kiili
@Masd925
Jun 09 2017 05:24
@anirudhdggl You can check palindromicality by comparing the string with the reversed string. For the reversing you can use split+reverse+join.
Long Nguyen
@longnt80
Jun 09 2017 05:24
@anirudhdggl and do what @Masd925 said also
Jun 09 2017 05:24
@njordomir try that and paste code in midde of thes
@njordomir then ctrl+enter
anirudh duggal
@anirudhdggl
Jun 09 2017 05:25

@Masd925

function palindrome(str) {
var lower = str.toLowerCase();
str = lower.replace(/[,|.|<|>|!|@|#|$$|%|^|&|\*|-|\+|=]/g,""); var oster = str.split(''); str = oster.reverse(); var strings = str.join(''); var ostrings = oster.join(''); if(strings === ostrings){ return false; } else{ return true; } } palindrome("nope"); Is this what you are trying to say? njordomir @njordomir Jun 09 2017 05:25 @heidisdad2 oops, try what, it changed it to a code box Long Nguyen @longnt80 Jun 09 2017 05:25 @anirudhdggl as I told you, regexp has classes to target non-alphanumeric character, so var str = lower.replace(/[,|.|<|>|!|@|#|$$|%|^|&|\*|-|\+|=|_]/g, "");

can be written as

var str = lower.replace(/\W_*/g, "");
Markus Kiili
@Masd925
Jun 09 2017 05:26
@anirudhdggl You can just return strings === ostrings;
anirudh duggal
@anirudhdggl
Jun 09 2017 05:26
@longnt80 Aah, that seems to look like a relief from a long and tedious piece of code
Jun 09 2017 05:26
@njordomir that is good  then enter and paste code in middle....then ctrl enter to post
anirudh duggal
@anirudhdggl
Jun 09 2017 05:26
@Masd925 got it! lemme try
Long Nguyen
@longnt80
Jun 09 2017 05:26
@anirudhdggl learn the regexp classes
Jun 09 2017 05:27
i think this is an easy solution for many of you guys 
var myObj = {
pet: "kitten",
bed: "sleigh"
};

function checkObj(checkProp) {
var trueFalse = myObj.hasOwnProperty();
return trueFalse;

}

if(trueFalse === true){
var result = myObj[checkProp];
return result;
}else if(trueFalse === false){

var result2 = "no";
return result2;
}
Markus Kiili
@Masd925
Jun 09 2017 05:27
@anirudhdggl You could use better variable names (or try to remove some of those variables by chaining the method calls).
njordomir
@njordomir
Jun 09 2017 05:28

Here's what I'm having an issue with. It passes all the tests except sumFibs(75024). Can someone give me a hint?

'''function sumFibs(num) {
console.log("New Run: " + num + "");
var sequence = [1,1];
var twoNums = 0;
var success = 0;

while (success < num) {
//push new fibro num
twoNums = sequence.slice(-2);
sequence.push(twoNums[0] + twoNums[1]);
console.log(sequence);

//update success condition
success = sequence.reduce(function(acc,val) {
if (val%2 !== 0) {
return acc + val;
}
return acc;
});
console.log(success);

}
return success;
}

sumFibs(4);'''

CamperBot
@camperbot
Jun 09 2017 05:28
:bulb: to format code use backticks!  more info
anirudh duggal
@anirudhdggl
Jun 09 2017 05:28
@Masd925 Its returning true for nope, while it should be false
@longnt80 from where should I learn them
Markus Kiili
@Masd925
Jun 09 2017 05:29
@anirudhdggl If the strings are equal, you need to return true.
Long Nguyen
@longnt80
Jun 09 2017 05:29
Jun 09 2017 05:29
@njordomir you are more advanced then me. could you help me with my code?
i know i am barely off been working on this for about an hour and a half
anirudh duggal
@anirudhdggl
Jun 09 2017 05:29
@Masd925 Yes, but nope is not same as its reverse!
Markus Kiili
@Masd925
Jun 09 2017 05:30
@anirudhdggl Yes. Post the code again.
njordomir
@njordomir
Jun 09 2017 05:30
@heidisdad2 I'd be happy to try. Give me second to scroll back through it.
anirudh duggal
@anirudhdggl
Jun 09 2017 05:31

function palindrome(str) {
var lower = str.toLowerCase();
str = lower.replace(/\W_*/g, "");
var oster = str.split('');
str = oster.reverse();
var strings = str.join('');
var ostrings = oster.join('');
return strings === ostrings;
}

palindrome("nope");
here it is @Masd925
njordomir
@njordomir
Jun 09 2017 05:33
@heidisdad2 I'm lost. Which challenge are you on?
Markus Kiili
@Masd925
Jun 09 2017 05:33
@anirudhdggl Arrays are objects and after str = oster.reverse(); both variables point to the same array.
anirudh duggal
@anirudhdggl
Jun 09 2017 05:34
@Masd925 how? str points to the reverse of oster
Markus Kiili
@Masd925
Jun 09 2017 05:34
@anirudhdggl Reverse is a mutator method and oster.reverse() mutates oster too.
anirudh duggal
@anirudhdggl
Jun 09 2017 05:35
you mean to say that oster.reverse will reverse the oster too? @Masd925
Markus Kiili
@Masd925
Jun 09 2017 05:35
@anirudhdggl Yes.
anirudh duggal
@anirudhdggl
Jun 09 2017 05:36

function palindrome(str) {
var lower = str.toLowerCase();
str = lower.replace(/\W_*/g, "");
var oster = str.split('');
str = oster;
oster = oster.reverse();
var strings = str.join('');
var ostrings = oster.join('');
return strings === ostrings;
}

palindrome("nope");
It still yields nothing!
Markus Kiili
@Masd925
Jun 09 2017 05:36
@anirudhdggl It should be something like this:
function palindrome(str) {
var lower = str.toLowerCase();
str = lower.replace(/\W_*/g, "");

var oster = str.split('');
oster.reverse();
var ostrings = oster.join('');

return str === ostrings;
}
You can remove some of those variables and make it clearer still.
anirudh duggal
@anirudhdggl
Jun 09 2017 05:37
@Masd925 you never joined str?
Jun 09 2017 05:37
@njordomir im on testing objects for properties
Jun 09 2017 05:38
anirudh duggal
@anirudhdggl
Jun 09 2017 05:38
lemme try;
ValiantBuaquen
@ValiantBuaquen
Jun 09 2017 05:40
hello y’al quick question is it possible to get two argument parameters to a function? Example: function (12)(14);
Jun 09 2017 05:40
@khaduch well i have no problem with returning the answer...but for some reason i am having problems with that if then statement....if no value is found it is supposed to say "no value found"
Jun 09 2017 05:40
@heidisdad2 - did you post your code? I see it way up there...
Jun 09 2017 05:41
but when i try this code it says there is an illegal return statement
anirudh duggal
@anirudhdggl
Jun 09 2017 05:41
@Masd925 it is not working for _eye
Jun 09 2017 05:41
var myObj = {
pet: "kitten",
bed: "sleigh"
};

function checkObj(checkProp) {
var trueFalse = myObj.hasOwnProperty();
return trueFalse;

}

if(trueFalse === true){

return result;
}else if(trueFalse === false){

var result2 = "no";
return result2;
}
anirudh duggal
@anirudhdggl
Jun 09 2017 05:42
@heidisdad2 did you specify what result is?
Christopher McCormack
@cmccormack
Jun 09 2017 05:42
@ValiantBuaquen With the syntax you are asking about, your function would have to return another function that takes an argument
Jun 09 2017 05:42
@heidisdad2 - myObj is the object. They are passing a value to the checkObj function, that is the function argument, named checkProp. You have to use the checkProp argument within the .hasOwnProperty() method - so it would be myObj.hasOwnProperty(checkProp);
Alexandru Higyedi
@Journeytojah
Jun 09 2017 05:43
Hi can anyone help me please?
Jun 09 2017 05:43
yeah i did...my bad a line got deleted
Alexandru Higyedi
@Journeytojah
Jun 09 2017 05:43
// Setup
function abTest(a, b) {
// Only change code below this line
if (a, b < 0) {
return undefined;
}

// Only change code above this line

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

// Change values below to test your code
abTest(3,3);
Christopher McCormack
@cmccormack
Jun 09 2017 05:43
@ValiantBuaquen but you can pass as many arguments to a single function as you want, specifying as many function parameters as you like as well. the special arguments object allows you to iterate over all arguments passed into a function
Alexandru Higyedi
@Journeytojah
Jun 09 2017 05:43
this works but one of the conditions is not passed and im stuck :/
Markus Kiili
@Masd925
Jun 09 2017 05:43
@anirudhdggl That regexp is not removing underscore.
Jun 09 2017 05:43
/ Setup
var myObj = {
pet: "kitten",
bed: "sleigh"
};

function checkObj(checkProp) {
var trueFalse = myObj.hasOwnProperty();
return trueFalse;

}

if(trueFalse === true){
var result = myObj[checkProp];
return result;
}else if(trueFalse === false){

var result2 = "no";
return result2;
}
ValiantBuaquen
@ValiantBuaquen
Jun 09 2017 05:43
@cmccormack where do I see the api for double parameters? can’t see it in mdn
njordomir
@njordomir
Jun 09 2017 05:43
@heidisdad2 so, I would start breaking it down by using console.log(trueFalse) to see if it's evaluating properly.
Alexandru Higyedi
@Journeytojah
Jun 09 2017 05:44
why do you have , instead of ; ?
Jun 09 2017 05:44
@heidisdad2 - if you have a true return from myObj.hasOwnProperty(checkProp); are you supposed to return the property? You can do that, and if you don't have a true result from that, then return "No such property" or whatever you're supposed to return.
Christopher McCormack
@cmccormack
Jun 09 2017 05:44
@ValiantBuaquen well the syntax you're using isn't double parameters, you're invoking one function with an argument, then invoking the return function with another argument
@ValiantBuaquen your'e basically chaining, which isn't a special configuration
ValiantBuaquen
@ValiantBuaquen
Jun 09 2017 05:46
@cmccormack how come chromes catches it as an error in the console when requesting the chain?
@cmccormack it has this error: Uncaught TypeError: addTogether(...) is not a function
Jun 09 2017 05:48
@khaduch hmmm still not working because i have a syntax error of illegal return statement
Christopher McCormack
@cmccormack
Jun 09 2017 05:48
@ValiantBuaquen do you have some code to share?
ValiantBuaquen
@ValiantBuaquen
Jun 09 2017 05:48
let me post it...
Jun 09 2017 05:48
@njordomir im not sure what you mean
Jun 09 2017 05:48
Christopher McCormack
@cmccormack
Jun 09 2017 05:49
> function sum(a) {
this.a = a;
return function(b) {
return this.a + b;
}
}
> sum(6)(4)
10
Jason Spence
@sfrjrs
Jun 09 2017 05:49
I'm having trouble escaping the code in one of the excercises.
This works in chrome console: "Firstline\n\r\Secondline\\n\rThirdline", but doesn't work when I run the test.
Jun 09 2017 05:49
var myObj = {
pet: "kitten",
bed: "sleigh"
};

function checkObj(checkProp) {
var trueFalse = myObj.hasOwnProperty(checkProp);
return trueFalse;

}if(trueFalse === true){
var result = myObj[checkProp];
return result;
}else if(trueFalse === false){

var result2 = "no";
return result2;
}
Jun 09 2017 05:49
@sfrjrs - make sure that you keep all of the spelling the same as the original - "FirstLine", not "Firstline", etc.
Christopher McCormack
@cmccormack
Jun 09 2017 05:50
@sfrjrs does it say to use both new line and carriage return each time, or just once each?
ValiantBuaquen
@ValiantBuaquen
Jun 09 2017 05:50
@cmccormack
if (typeof arguments[0] === 'number' && typeof arguments[1] === 'number' ){
var args = arguments[0]+arguments[1];
return args;
} else {
return undefined;
}
}
Jason Spence
@sfrjrs
Jun 09 2017 05:50
instructions say to use it once at the end
Markus Kiili
@Masd925
Jun 09 2017 05:51
@ValiantBuaquen With one valid argument passed, you need to return a function. You need to test arguments.length.
Christopher McCormack
@cmccormack
Jun 09 2017 05:51
@ValiantBuaquen what is the exercise name?
njordomir
@njordomir
Jun 09 2017 05:52

@heidisdad2 also, what is that first return on the line rught under where you check the property? I would put one return variable at the end, and use the if statement to set it to either false, or the value of the property

I'm not going to just type out the answer, but I think it would help you to write out what you're doing in plain english statements, then fill in the blanks between the statements.

What I meant was console.log() is the best tool you can use to figure out where errors in your code are. If you put console.log(trueFalse) right after your checkprop you can see the value of it. You can put these ANYWHERE in your code, and it's super helpful for narrowing down what line your problem is on. My console is encyclopedic sometimes because I put these everywhere in my code.

The first issue though is that random return two lines after "your code here". What does that return do?

Markus Kiili
@Masd925
Jun 09 2017 05:52
@ValiantBuaquen So addTogether(2) there returns a function and that (3) calls it.
rugano
@rugano
Jun 09 2017 05:53
Hello campers,for those at 'Validate US Telephone Numbers' challenge,you can read an awesome tutorial on RegEx here: https://regexone.com/
ValiantBuaquen
@ValiantBuaquen
Jun 09 2017 05:53
@cmccormack
intermediate algorithm scripting (exercise 286) ‘Arguments Optional'
Jun 09 2017 05:53
@heidisdad2 - all of the code has to be within the function body - you have stuff outside the function body. It should look more like this:
function checkobj(checkProp) {
if (myObj.hasOwnProperty(checkProp) {
// return the property value here
} else {
return "No such value"; // or whatever is supposed to be returned
}
}
Jason Spence
@sfrjrs
Jun 09 2017 05:54

@khaduch - This works when I run test. It gives me all green check marks except for the first requirement. "myStr should have encoded text with the proper escape sequences and no spacing."

var myStr = "FirstLine\n\b\SecondLine\\b\rThirdLine";

njordomir
@njordomir
Jun 09 2017 05:54

for example:
//return checkprop as boolean (true or false) and assign to variable
//check if variable is true, and if it is, return the property in question
//you don't need to check if the variable is false, because if it's not true it's false, so I would just put a return "not found" after your if statement

Christopher McCormack
@cmccormack
Jun 09 2017 05:56
@ValiantBuaquen like @Masd925 said at some point you need to return a function if only one argument is passed. Read the instructions over again and look at the suggested reading on closures.
njordomir
@njordomir
Jun 09 2017 05:56
@heidisdad2 Ken's solution is shorter and cleaner. But make sure you understand it before you move on. I caused myself a few headaches by ignoring accidental successes and just moving on.
Jun 09 2017 05:56
@njordomir hmm thanks.
CamperBot
@camperbot
Jun 09 2017 05:56
heidisdad2 sends brownie points to @njordomir :sparkles: :thumbsup: :sparkles:
Jun 09 2017 05:56
no i am trying to understand, thats my goal
Jun 09 2017 05:56
@sfrjrs - I think that you have an incorrect escape sequence there? You are confusion "backslash" and "backspace" \b is backspace, \\ is backslash
Jun 09 2017 05:56
@khaduch i was getting really confused with the multiple brackets thing.
@khaduch that was my original approach but couldn't figure it out.
T_T
Jason Spence
@sfrjrs
Jun 09 2017 05:58
@khaduch - Thank you, I got it to work.
CamperBot
@camperbot
Jun 09 2017 05:58
sfrjrs sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
Jun 09 2017 05:58
@heidisdad2 - the code indentation shows the structure - there are other ways to write it, like you don't really need the "else" part - you can just return "no such value" or whatever... But as @njordomir says - make sure that you understand it thoroughly - you don't want to move on without getting the basics down pat!
@sfrjrs - great! You're welcome!
ValiantBuaquen
@ValiantBuaquen
Jun 09 2017 05:59
@cmccormack your answer is still yoda-ish but let me look into it. but thank you for the hint.
CamperBot
@camperbot
Jun 09 2017 05:59
valiantbuaquen sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
Ronald T. Casili
@nvlled
Jun 09 2017 06:00
@jaysie16 What sort of help do you need?
jaysie16
@jaysie16
Jun 09 2017 06:00
i cant seem to find a solution to this exercise
heres my code

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

product *= arr[i][j];

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

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

Jun 09 2017 06:01
@khaduch i thought i had to set the if statement to = something...like if(myObj.hasOwnProperty(checkProp)===true{
forgot the )on the end of true
Ronald T. Casili
@nvlled
Jun 09 2017 06:01
@jaysie16 You are missing a .length in this part: for (var j = 0; j < arr[i]; j++){
njordomir
@njordomir
Jun 09 2017 06:02
@heidisdad2 I just checked ken's code and it works. Basically, he put the property check in the if condition. .hasOwnProperty returns true or false. Since he put hasOwnProp in the if statements () brackets, it will execute that code IF and only IF it has that property, otherwise it skips the if statement. You can then put the return for if it has the property within the if statement, and the one for if it doesn't outside of the if statement. To send back the property access it using bracket notation.
jaysie16
@jaysie16
Jun 09 2017 06:02
like this?
for (var i = 0; i < arr.length; i++) {
for (var j = 0; j < arr[i].lenghth; j++){
product *= arr[i][j];
Jun 09 2017 06:02
@heidisdad2 - no, unless they are asking you do to that. But it is redundant to add the === true because the if statement will test the return from the method that you call, as long as it is returning true or false (or it will coerce the return from the method to either true, or false - they might have mentioned "truthy" values?
Ronald T. Casili
@nvlled
Jun 09 2017 06:03
@jaysie16 yes, but you mispelled length
jaysie16
@jaysie16
Jun 09 2017 06:03
o
hahah
Thank you @nvlled
CamperBot
@camperbot
Jun 09 2017 06:03
jaysie16 sends brownie points to @nvlled :sparkles: :thumbsup: :sparkles:
jaysie16
@jaysie16
Jun 09 2017 06:03
^_^\
Henry
@GitHub-Henry
Jun 09 2017 06:03
just for reference, how long did it take you to understand generators, if you took the time to understand them. i'm wondering how i compare.
Jun 09 2017 06:05
@heidisdad2 - the code that I wrote is a pretty concise way to write that. There are other ways to make it a shorter, using the ternary operator, for example.
I'm bugging out for now - I'm wiped out and going to get some sleep... good luck with that!
Jun 09 2017 06:06


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

function checkObj(checkProp) {
if (myObj.hasOwnProperty(checkProp)){
var result = myObj[checkProp];
return result;

}
else {
return result2;
}
}

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

function checkObj(checkProp) {
if (myObj.hasOwnProperty(checkProp)){
var result = myObj[checkProp];
return result;

}
else {
return result2;
}
}
that worked, thanks guys it makes sense to me
i just had the brackets in the wrong space
so i tried another way of doing it
still not sure why i got that syntax error though
@njordomir how do i do that console.log test deal? i write in after actions in my code ?
K L Bhanu
@klbm9999
Jun 09 2017 06:10
we can set dataType in jQuery ajax to "jsonp", how to do the same when using axios?
njordomir
@njordomir
Jun 09 2017 06:13
@heidisdad2 I recommend you watch the videos on it. There are courses that free code camp has made that I really think should be mandatory viewing. They definitely filled some gaps in my knowledge. I think this is the one that explains console.log https://www.freecodecamp.com/videos/chrome-dev-tools-console
you can find the courses by clicking on map, then scrolling down on the green toolbar up top
TDM
@tdmoor
Jun 09 2017 06:20

Hi everyone, can anyone explain the reasoning behind this line of code in the Chunky Monkey challenge:

if (i % size !== size - 1)

I understand the modulus operator and what it does, I just don't understand why you'd use it in that way trying to slice an array into multiple arrays with a variable of size.
Markus Kiili
@Masd925
Jun 09 2017 06:22
@tdmoor Means that the element is not the last one of a chunk.
HappyRedditor59
@HappyRedditor59
Jun 09 2017 06:24
can someone pls tell me what's wrong with my code? i'm currently stuck at Profile Lookup. my code is as follows:
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].hasOwnProperty('firstName') === true){
for (var j = 0; j < contacts[i].length; j++){
if (prop == contacts[i])
return contacts[i][j];
return "No such property";
}
return "No such contact";
}
}
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
Markus Kiili
@Masd925
Jun 09 2017 06:25
@tdmoor For example if size is 3, then i%size is 0,1,2,0,1,2,... and size-1 is 2 that mean the last one of a chunk.
TDM
@tdmoor
Jun 09 2017 06:25
Aaaaaah, I see. Thanks a bunch @Masd925!
CamperBot
@camperbot
Jun 09 2017 06:25
tdmoor sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4231 | @masd925 |http://www.freecodecamp.com/masd925
Manish Giri
@Manish-Giri
Jun 09 2017 06:26
@HappyRedditor59 for (var j = 0; j < contacts[i].length; j++){
why do you need this second loop?
Markus Kiili
@Masd925
Jun 09 2017 06:27
@HappyRedditor59 You cannot loop object properties like that (and no need to loop them here).
HappyRedditor59
@HappyRedditor59
Jun 09 2017 06:27
@Manish-Giri trying to iterate through every object in the array
Manish Giri
@Manish-Giri
Jun 09 2017 06:27
@HappyRedditor59 you can't loop through an object that way.
As @Masd925 said
HappyRedditor59
@HappyRedditor59
Jun 09 2017 06:27
@Masd925 @Manish-Giri thanks for pointing that out
CamperBot
@camperbot
Jun 09 2017 06:27
happyredditor59 sends brownie points to @masd925 and @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 5910 | @manish-giri |http://www.freecodecamp.com/manish-giri
:star2: 4232 | @masd925 |http://www.freecodecamp.com/masd925
Ccs99817
@ccs99817
Jun 09 2017 06:38
I have difficulty in this part "Make Object Properties Private"
myBike.getGear() should return 4 after calling myBike.setGear(4)
Markus Kiili
@Masd925
Jun 09 2017 06:38
@ccs99817 Post the code you have done.
Ccs99817
@ccs99817
Jun 09 2017 06:39

var Car = function() {
// this is a private variable
var speed = 10;

// these are public methods
this.accelerate = function(change) {
speed += change;
};

this.decelerate = function() {
speed -= 5;
};

this.getSpeed = function() {
return speed;
};
};

var Bike = function() {

// Only change code below this line.

//this is a privare variable
var gear = 0;

//these are public methods
this.setGear = function(num){
gear = num;

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

};
};
var myCar = new Car();

var myBike = new Bike();

Markus Kiili
@Masd925
Jun 09 2017 06:40
@ccs99817 getGear should just return the gear.
Procrates
@procrates
Jun 09 2017 06:43
Really have a problem with "Find the Length of a String" in Javascript.
I replicated the sample just with the lastName with no output. I added var infront of lastNameLenght = lastName.lenght; to get an output of 3 which makes no sense for me. Could someone give me any pointers of what I am doing wrong or if this is a bug? Thank you!
Ccs99817
@ccs99817
Jun 09 2017 06:43

@Masd925 Thank, it is fixed. But, I want to check my concept. I am not sure about this code format

'''
this.getGear = function(){};
'''
What does the function() mean? It clarify this.getGear is a finction?

CamperBot
@camperbot
Jun 09 2017 06:43
:bulb: to format code use backticks!  more info
K L Bhanu
@klbm9999
Jun 09 2017 06:44
@procrates can you post the code?
Ccs99817
@ccs99817
Jun 09 2017 06:44

@Masd925 Thank, it is fixed. But, I want to check my concept. I am not sure about this code format

this.getGear = function(){};

What does the function() mean? It clarifyiesthis.getGear is a function?

CamperBot
@camperbot
Jun 09 2017 06:44
ccs99817 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4233 | @masd925 |http://www.freecodecamp.com/masd925
Ronald T. Casili
@nvlled
Jun 09 2017 06:44
Procrates
@procrates
Jun 09 2017 06:45
// Example
var firstNameLength = 0;

firstNameLength = firstName.length;

// Setup
var lastNameLength = 0;
var lastName = "Lovelace";

// Only change code below this line.

lastNameLength = lastName;
This is the original
Markus Kiili
@Masd925
Jun 09 2017 06:45
@ccs99817 When you make a new object with new Bike() the engine makes a new plain object and puts it as value of this and runs the constructor function Bike. That way the new object gets for example that property .getGear that is a method because it holds a function.
@ccs99817 function(){...} is a function expression that generates a function (object).
Procrates
@procrates
Jun 09 2017 06:47
I have done lastNameLength = lastName.lenght; with the result of no output... Addingvar lastNameLenght = lastName.lenght;
gives me the output of 3 which is the example but with totally different variable.
Ccs99817
@ccs99817
Jun 09 2017 06:47
@Masd925 I see ur points, Thx
CamperBot
@camperbot
Jun 09 2017 06:47
ccs99817 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: ccs99817 already gave masd925 points
Ronald T. Casili
@nvlled
Jun 09 2017 06:49
@procrates You are not getting any output because lastName does not have a property called lenght
Procrates
@procrates
Jun 09 2017 06:49
// Example
var firstNameLength = 0;

firstNameLength = firstName.length;

// Setup
var lastNameLength = 0;
var lastName = "Lovelace";

// Only change code below this line.

lastNameLength = lastName.lenght;
I have searched and tested everything i can thick of.
kingfisher
@wangyucui01
Jun 09 2017 06:50
Hello
Manish Giri
@Manish-Giri
Jun 09 2017 06:50
@procrates lastName.lenght;
maybe watch out for typos?
Chandan Kumar Baba
@cbaba20
Jun 09 2017 06:52
Hello team
kingfisher
@wangyucui01
Jun 09 2017 06:52

Long Nguyen
@longnt80
Jun 09 2017 06:53
Chandan Kumar Baba
@cbaba20
Jun 09 2017 06:53
I need one help regarding JavaScript . How to push first array in second array ?
kingfisher
@wangyucui01
Jun 09 2017 06:53
thank you
Procrates
@procrates
Jun 09 2017 06:54
@Manish-Giri Ive checked for typos and nothing makes sense with the outputs im getting... changing the setup values to 8 makes the difference but it dosnt really count the letters in lastName.
Manish Giri
@Manish-Giri
Jun 09 2017 06:54
@cbaba20 .concat() or .push()
depending on how things work
@procrates lastName.lenght;
so you don't see anything wrong here?
Jun 09 2017 06:55
guys
// Setup
var myArray = [];

for (var i = 8; i > 0; i-=2){
myArray.push(i);
}
Joshua Frias
@Juke-Magic
Jun 09 2017 06:56
@Manish-Giri can you help me?
Manish Giri
@Manish-Giri
Jun 09 2017 06:56
@21-Orange with?
Joshua Frias
@Juke-Magic
Jun 09 2017 06:56
why isnt this outputing anything

for (var i = 0; i < array.length; i++) {
array.push(arraysplit[i].replace(/[^a-z0-9]/gi, ""));
}

return array;

Jun 09 2017 06:56
can someone explain to me why this formula gives me 8,6,4,2 instead of 9,7,5,3,1?
i thought 0=1
Manish Giri
@Manish-Giri
Jun 09 2017 06:57
@21-Orange what's arraysplit?
Joshua Frias
@Juke-Magic
Jun 09 2017 06:57

var arraysplit = str.split(' ');
var array = [];

for (var i = 0; i < array.length; i++) {
array.push(arraysplit[i].replace(/[^a-z0-9]/gi, ""));
}

return array;
}

Manish Giri
@Manish-Giri
Jun 09 2017 06:57
and then reduces by 2
so.
Joshua Frias
@Juke-Magic
Jun 09 2017 06:58
i+2
i-2
Chandan Kumar Baba
@cbaba20
Jun 09 2017 06:58
Thank manish , but these two will push first array object to another array object .
Jun 09 2017 06:58
@Manish-Giri but isn't 8 actually nine in java script?
Joshua Frias
@Juke-Magic
Jun 09 2017 06:58
start at 9
Manish Giri
@Manish-Giri
Jun 09 2017 06:58
8 is 8
why would it be 9?
Procrates
@procrates
Jun 09 2017 06:58
@Manish-Giri lastName.lenght; only gives an error and output of 0
So atleast in my experience I see something wrong.
Manish Giri
@Manish-Giri
Jun 09 2017 06:58
@procrates dude
LENGTH
Jun 09 2017 06:58
doesn't it start at 0?
Manish Giri
@Manish-Giri
Jun 09 2017 06:59
not LENGHT
@procrates
Joshua Frias
@Juke-Magic
Jun 09 2017 06:59
Manish Giri
@Manish-Giri
Jun 09 2017 06:59
@heidisdad2 array indices start at 0
Xarri Jorge
@xarrijorge
Jun 09 2017 06:59
@procrates typo there.
Manish Giri
@Manish-Giri
Jun 09 2017 06:59
like first element is at position 0
second at 1
and so on
not the actual numbers
Jun 09 2017 06:59
lol
i thought too deep on that
Manish Giri
@Manish-Giri
Jun 09 2017 07:00
Joshua Frias
@Juke-Magic
Jun 09 2017 07:00
aye i got it
lmagee001
@lmagee001
Jun 09 2017 07:00
Anyone down to help me with this word blanks module?
Joshua Frias
@Juke-Magic
Jun 09 2017 07:00
should be arraysplit.length
@Manish-Giri thanks anyway
CamperBot
@camperbot
Jun 09 2017 07:00
21-orange sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 5911 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Jun 09 2017 07:00
np
@lmagee001 you need to form a string, and assign it to result, using string concatenation (+). The string has to be formed by concatenating the four parameters in your function - myNoun, myAdjective, etc, along with spaces and (optionally) some words of your own - to form a coherent sentence.
RISHABH SETH
@coding70
Jun 09 2017 07:01
need help
unable to understand DNA pairing problem
Illunis
@Illunis
Jun 09 2017 07:02
@21-Orange array.length is 0 at the beginning => i (0) < array.length (0) Your for loop is never executed
Joshua Frias
@Juke-Magic
Jun 09 2017 07:02
@Illunis no its fine now
array.length should be arraysplit.length
my typo
@Illunis thanks anyway
CamperBot
@camperbot
Jun 09 2017 07:03
21-orange sends brownie points to @illunis :sparkles: :thumbsup: :sparkles:
RISHABH SETH
@coding70
Jun 09 2017 07:03
need help anyone
Procrates
@procrates
Jun 09 2017 07:03
Really thought it was written like that... Sorry for using this valuable time. Thanks for clearing it up anyways!
Illunis
@Illunis
Jun 09 2017 07:04
i thought so. you are welcome :)
Joshua Frias
@Juke-Magic
Jun 09 2017 07:04
@coding70 whats the problem yo
RISHABH SETH
@coding70
Jun 09 2017 07:04

unable to understand DNA pairing problem

anyone can help or i assume that no one knows this :P

Joshua Frias
@Juke-Magic
Jun 09 2017 07:04
RISHABH SETH
@coding70
Jun 09 2017 07:06
@21-Orange
hi i m not able to understand the question itself
the output example given is which i m not getting

oh no problem buddy :smile:

Manish Giri
@Manish-Giri
Jun 09 2017 07:06
Saif Ur Rahman
@saifsmailbox98
Jun 09 2017 07:08
@coding70 DNA's have pairs like A-T and G-C, so you have to break the string down to characters and return it along with it's pair using a 2D array.
if you have"GCA"
output should be : [ ["G", "C"], ["C", "G"], ["A", "T"] ]
RISHABH SETH
@coding70
Jun 09 2017 07:10
Manish Giri
@Manish-Giri
Jun 09 2017 07:10
@coding70 I know the challenge, what's your question?
RISHABH SETH
@coding70
Jun 09 2017 07:10

@saifsmailbox98 thanks brother ,i understand that much but after that what ??

but what is pattern for the respective output

CamperBot
@camperbot
Jun 09 2017 07:10
coding70 sends brownie points to @saifsmailbox98 :sparkles: :thumbsup: :sparkles:
RISHABH SETH
@coding70
Jun 09 2017 07:11

@Manish-Giri

i m not understanding ,what is the expected output to the inputs

Manish Giri
@Manish-Giri
Jun 09 2017 07:11
@coding70 you return a 2D array
RISHABH SETH
@coding70
Jun 09 2017 07:11
@Manish-Giri
i m not understanding ,what is the expected output to the inputs
Saif Ur Rahman
@saifsmailbox98
Jun 09 2017 07:11
@coding70 every first element of the inner arrays is the characters enter and the second element is its pair
Manish Giri
@Manish-Giri
Jun 09 2017 07:11
each sub array consists of the given letter and it's missing pair
RISHABH SETH
@coding70
Jun 09 2017 07:12
@Manish-Giri
thats fine
but how to form the array to return
Manish Giri
@Manish-Giri
Jun 09 2017 07:12
make one outer array
inside your loop, you'll create another array with the letter and it's pair
push this array to the outer array
that's all
Sachin
@sachinmc
Jun 09 2017 07:18

hi folks, question on the comparefunction for the array sort method.

array.sort(function(a,b) {
return a - b;
}

if array is [3,1,8,7,4], what are the values of a and b and how does the function iterate through the array. This I know that sort swap's element based on the return value, i.e. for -1, a comes before b, for 1 b comes before a and for 0 a and b are the same. So for an ascending array b and a are swapped etc ..

Markus Kiili
@Masd925
Jun 09 2017 07:20
@sachinmc Sort method sorts the array automatically under the hood (using some efficient browser specific algorithm like quicksort etc). During that sorting it passes pairs of elements into the callback function you provide. If the return value is negative, sort puts the first passed element first and vice versa otherwise.
With that callback function, a-b is negative when the second argument is larger, so in that case sort keeps the order, so it results in smallest first order.
Sachin
@sachinmc
Jun 09 2017 07:22
@Masd925 so what are the argument values
in the example [3,1,8,7,4]
Markus Kiili
@Masd925
Jun 09 2017 07:23
@sachinmc Sort passes pairs of array elements into the callback as a and b. What elements and in what order depends on the algorithm that it happens to use.
Sachin
@sachinmc
Jun 09 2017 07:24
@Masd925 I am trying to apply some logic to a and b in the callback function, but can't without knowing what they are and how they iterate through the array
@Masd925 for example with map function we know that the callback function operates on each element of an array
Markus Kiili
@Masd925
Jun 09 2017 07:25
@sachinmc The callback tells the sort method the order of two arbitrary array elements a and b. It uses it during the sorting by passing elements into the callback and checking the return value. What elements are passed and in which order depends on the algorithm (browser specific).
James Patrick Kerrane
@jamesjpk123
Jun 09 2017 07:27

EDIT: Here is a gist for the code: https://gist.github.com/anonymous/14ccc4cb5e7a33680f40e95ddd653df1
Old Message:

I need help. In my code
function myLocalScope() {
'use strict';
var myVar = "cool";
console.log(myVar);
}
myLocalScope();

// Run and check the console
// myVar is not defined outside of myLocalScope
console.log(myVar);

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

It says that I have no global myVar variable, but I need to add a local myVar variable. Can anyone help?

Sachin
@sachinmc
Jun 09 2017 07:27
@Masd925 hmm ok :)
I read online it passes values like so:
(3,1)
(3,8)
etc
but guess this is browser specific ..
Markus Kiili
@Masd925
Jun 09 2017 07:28
@sachinmc No, it doesn't use Bubblesort that works like that until the array is sorted.
Sachin
@sachinmc
Jun 09 2017 07:28
@Masd925 alright no worries Markus, going into a tunnel now so will loose connection, will be back on this later, thanks again
CamperBot
@camperbot
Jun 09 2017 07:28
sachinmc sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4234 | @masd925 |http://www.freecodecamp.com/masd925
James Patrick Kerrane
@jamesjpk123
Jun 09 2017 07:30
Markus Kiili
@Masd925
Jun 09 2017 07:30
@sachinmc You can read up on Quicksort and Mergesort. Most likely one of them or something like that is used in most browsers. For very small arrays browser might use insertion sort perhaps.
devpaaji
@devpaaji
Jun 09 2017 07:31
@Masd925 hello how are you doing
for algorithms how often these used in current web dev
DIvide and Conquer
Sorting
Merge Sort
Markus Ivancsics
@ivancsicsmarkus
Jun 09 2017 07:32
@devpaaji In web dev not really.
devpaaji
@devpaaji
Jun 09 2017 07:32
why @ivancsicsmarkus
Markus Ivancsics
@ivancsicsmarkus
Jun 09 2017 07:33
@devpaaji However it helps you think as a programmer.
devpaaji
@devpaaji
Jun 09 2017 07:33
logic will remain so
when writing a program
Markus Ivancsics
@ivancsicsmarkus
Jun 09 2017 07:33
@devpaaji Yes. But you won't use algorithms for a simple website.
devpaaji
@devpaaji
Jun 09 2017 07:33
you still got to break problem into data sets
James Patrick Kerrane
@jamesjpk123
Jun 09 2017 07:33
:point_up: June 9, 2017 1:30 AM got the code. Nevermind!
Markus Kiili
@Masd925
Jun 09 2017 07:35
@devpaaji Divide and conquer I have used and built-in sorting of course.
Raghu Raj Rai
@Raidestro
Jun 09 2017 08:07
I was doing the search and destroy algorithm scripting. Can someone please explain what this line of code means and what function is it doing ? I already checked the MDN guide and I am not able to understand it - var args = Array.prototype.slice.call(arguments);
Ogundele Olumide
@Lumexralph
Jun 09 2017 08:10
@Raidestro arguments is an array-like object, not a true array, doing that makes args a true array
Pieter Stokkink
@forkerino
Jun 09 2017 08:11
@Raidestro arguments is an array like object, which means that you cannot use all array methods on it by default, but that the elements are ordered and accessible by their index. To make an actual array out of it, you can use the .slice method of the Array global object. You access that with Array.prototype.slice. But then you still have to call that function. You cannot simply add (), because that would invoke the function on Array.prototype, which doesn't make any sense, because it is an object, not an array. Thankfully JS has the .call method, which calls a function on a specified thing you pass in as argument between the parens. So you call the slice method on the arguments object and the result is an array containing all arguments to the function.
sorry for wall of text
@Lumexralph Bro!
@Masd925 :wave:
Ogundele Olumide
@Lumexralph
Jun 09 2017 08:13
@forkerino love the explanation
@forkerino Good Morning, done the interview ?
Jun 09 2017 08:15
uh i need help for understanding the tip in a question
Ogundele Olumide
@Lumexralph
Jun 09 2017 08:17
Jun 09 2017 08:17

I solved "Sum All Numbers in a Range" with this, seems to be the most straightforward way:

function sumAll(arr) {
return (Math.abs(arr[0]-arr[1])+1)*(arr[0]+arr[1])/2;
}

sumAll([1, 4]);

However, the suggestion for this question include Math.min(), Math.max() and Array.prototype.reduce(). While I can kinda understand the suggestions of min and max, what the heck would I use the reduce() for? for a two element array? Is there something obvious I'm missing here?

Pieter Stokkink
@forkerino
Jun 09 2017 08:18
@Lumexralph Yeah, it went ok. It was interesting, completely different from any other job interview I ever had. The technical part went ok. They asked me to implement my favourite boardgame. I rarely play games, so I chose chess and we talked about how I would make an app with which you can play chess on a high level. Also some other questions on what closures and pure functions are. I think I did reasonably well, but not perfect. It was good experience, though.
@amatayamada Generally people create an array with all the numbers in a range and use reduce to add them all up. This formula is not common knowledge for most people.
Ogundele Olumide
@Lumexralph
Jun 09 2017 08:19
@forkerino yeah..... I like pure functions and try to make my functions that when it occurs to me
Raghu Raj Rai
@Raidestro
Jun 09 2017 08:19
@forkerino Awesome ! Thanx. I did have to read it 7 times to understand it but it covered everything.
CamperBot
@camperbot
Jun 09 2017 08:19
raidestro sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2512 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Jun 09 2017 08:20
@Lumexralph One question I didn't really know the answer to: Is a function that calls another function with one of its function parameters pure?
@Raidestro :smile: You're welcome!
Jun 09 2017 08:20
i need help with "Title case a sentence", i can not store all the capitalized value PLEASE HELP, Here is my code

function titleCase(str) {
var array = [];
array = str.split(" ");
var a = [];
for (i = 0; i<array.length ; i++){
a = array[i].split("");
var b = a[0].toUpperCase();

}
return b;

}

titleCase("I'm a little tea pot");
Jun 09 2017 08:21
@forkerino ok now I need to look up then how to efficiently create an array with a number range, I didn't think of that :D
Ogundele Olumide
@Lumexralph
Jun 09 2017 08:21
@forkerino closures
Pieter Stokkink
@forkerino
Jun 09 2017 08:22
@amatayamada it is not as easy as in Python
for example
json
@swoppy
Jun 09 2017 08:22

hi guys

str = str.replace(/([a-z])([A-Z])/g, '$1$2');

how's the code above supposed to put a space every uppercase char? the way understand the regex given is just selecting the small & big characters? I don't fully understand the placeholder ($1,$2) does. Can some help???

Ogundele Olumide
@Lumexralph
Jun 09 2017 08:22
@forkerino if the called function don't alter the input in the parameter to me it's still pure
Pieter Stokkink
@forkerino
Jun 09 2017 08:22
Jun 09 2017 08:22
or Bash, 1..20
Pieter Stokkink
@forkerino
Jun 09 2017 08:23
@Lumexralph yeah, that was what I was thinking (if the called function is pure it's ok), but wasn't sure.
Ogundele Olumide
@Lumexralph
Jun 09 2017 08:23
@forkerino yeah, poupulating an array, list comprehensionis so sweet in python
Jun 09 2017 08:23

function titleCase(str) {
var array = [];
array = str.split(" ");
var a = [];
for (i = 0; i<array.length ; i++){
a = array[i].split("");
var b = a[0].toUpperCase();

}
return b;

}

titleCase("I'm a little tea pot");
Manish Giri
@Manish-Giri
Jun 09 2017 08:24
@Lumexralph good morning sir :smiling_imp:
Pieter Stokkink
@forkerino
Jun 09 2017 08:24
@n4poleon the parentheses are capture groups, $1,$2 access each of them. If you have three of them, you'll also have $3 and so on Raghu Raj Rai @Raidestro Jun 09 2017 08:24 @adist98 First convert the entire string to lowercase - arr.toLowerCase(). Then use split to make an array of each word. Then use the charAt( ).toUpperCase to convert first alphabet to upper case. After that join the array elements while adding " " between them. Tell me if you need the code Ogundele Olumide @Lumexralph Jun 09 2017 08:24 @Manish-Giri :smirk: gggggm :smiling_imp: said Sir Manish Giri @Manish-Giri Jun 09 2017 08:24 lol Pieter Stokkink @forkerino Jun 09 2017 08:24 @n4poleon so$1 refers to the lowercase character. $2 to the uppercase character Ogundele Olumide @Lumexralph Jun 09 2017 08:24 @Manish-Giri Good Morning Master Shifu Rabbi Aditya Soni @adist98 Jun 09 2017 08:24 okay, i will try @Raidestro , thanks for the suggestion CamperBot @camperbot Jun 09 2017 08:24 adist98 sends brownie points to @raidestro :sparkles: :thumbsup: :sparkles: :cookie: 255 | @raidestro |http://www.freecodecamp.com/raidestro Ogundele Olumide @Lumexralph Jun 09 2017 08:25 Sage Hokage Manish Giri @Manish-Giri Jun 09 2017 08:25 :laughing: Fifth Hokage Sama Pieter Stokkink @forkerino Jun 09 2017 08:25 @adist98 you have to overwrite some stuff in your array inside your loop. After your loop, you need to join everything together again. Manish Giri @Manish-Giri Jun 09 2017 08:25 I'd like Lady Tsunade though :smiling_imp: Pieter Stokkink @forkerino Jun 09 2017 08:25 @Manish-Giri hey, what's up? Aditya Soni @adist98 Jun 09 2017 08:25 how do i do that @forkerino ? Manish Giri @Manish-Giri Jun 09 2017 08:25 @forkerino :wave: howdy Ogundele Olumide @Lumexralph Jun 09 2017 08:26 @Manish-Giri I finished Naruto json @swoppy Jun 09 2017 08:26 @forkerino yes, i understand it is an internal variable that is proportianal to the number of the expression, but i don't know what it does. :( Manish Giri @Manish-Giri Jun 09 2017 08:28 @Lumexralph :fire: Pieter Stokkink @forkerino Jun 09 2017 08:28 @adist98 you have to put some new value in array[i], there is no need to split this string again into an array, you can just overwrite the whole thing. Access the first letter of this string and uppercase it and concatenate the rest of the string. Store it in the array[i] @n4poleon It just stands in for whatever matches the stuff inside the parentheses in your regex. So if you have camelCase, your regex will find lC and turn it into l C.$1 is the l, $2 is the C Aditya Soni @adist98 Jun 09 2017 08:30 how do i access the first letter of the string array[i]@forkerino Pieter Stokkink @forkerino Jun 09 2017 08:30 @adist98 you can use bracket notation with 0 index (shorter) or you can use .charAt(0) @adist98 note that you cannot overwrite individual characters, you have to create the whole string. Aditya Soni @adist98 Jun 09 2017 08:31 okay i will try @forkerino Pieter Stokkink @forkerino Jun 09 2017 08:31 @adist98 :+1: if you run into problems, we are here json @swoppy Jun 09 2017 08:31 @forkerino ow i see, but how come it puts space in between??? Pieter Stokkink @forkerino Jun 09 2017 08:32 @n4poleon because of the space between$1 and $2 in the second arg of your replace You could also do '$1-\$2'
to put in a dash
for example
json
@swoppy
Jun 09 2017 08:33
@forkerino owh!!! I have been so blind. thanks man! :)
CamperBot
@camperbot
Jun 09 2017 08:33
n4poleon sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2513 | @forkerino |http://www.freecodecamp.com/forkerino
abraham anak agung
Jun 09 2017 08:33
Hey @forkerino may i ask what is pure function?
Tymoteusz
@WhiteLeash
Jun 09 2017 08:36

uuuuugh again me, challange witj js and queue, anyone?

function nextInLine(arr, item) {
arr.push(item);
arr.shift();
return item;  // Change this line
}

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

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

I just don't get it

Long Nguyen
@longnt80
Jun 09 2017 08:36
Pieter Stokkink
@forkerino
Jun 09 2017 08:36
@padunk A function that has no side-effects and that gives the exact same output for the same input (so for example Math.random() is not pure!). Side-effects mean that they alter things outside of the function, for example a global variable or one of the arguments passed into the function. https://medium.com/javascript-scene/master-the-javascript-interview-what-is-a-pure-function-d1c076bec976
@longnt80 great minds think alike!
:smile:
@padunk the whole series of articles by this writer are a great resource
@WhiteLeash almost there, you just have to return the right thing (the first element, i.e. the one you removed with .shift)
abraham anak agung
Jun 09 2017 08:38
thanks mate @longnt80 @forkerino , yes i follow him at medium too
CamperBot
@camperbot
Jun 09 2017 08:38
padunk sends brownie points to @longnt80 and @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2514 | @forkerino |http://www.freecodecamp.com/forkerino
Long Nguyen
@longnt80
Jun 09 2017 08:38
Pieter Stokkink
@forkerino
Jun 09 2017 08:38
Interestingly, .shift() returns the element it removes, so you can just put the return before it. @WhiteLeash
Jun 09 2017 08:39
damn this site could really use checkIO style solution review
after you done a challenge
to compare your solutions with other ones
and vote on best ones, comment etc
I loved learning Python with CheckIO in big part because of this
Tymoteusz
@WhiteLeash
Jun 09 2017 08:41
But when I put return before shift(), lint makes me "wrong" and say it's impossible to reach the shift()
Jun 09 2017 08:41
don't get me wrong, this course, chatrooms and all are also awesome :)
Pieter Stokkink
@forkerino
Jun 09 2017 08:42
@amatayamada part of it is going on at the forum and you can also ask for feedback in the /CodeReview room, but I agree that something integrated would be awesome. Maybe at some future point we could work together on this feature. Would require a big shift in the way the site is built, I think, but totally worth it.
@WhiteLeash I did not mean the line before, but before: return arr.shift()
sorry
I can see why that would be misunderstood
natural languages are so messy.
Vivek Ranjan
@vivekranjan92
Jun 09 2017 08:43
i am stuck in Counting Cards
can anyone help me
Tymoteusz
@WhiteLeash
Jun 09 2017 08:43
ok no problem, im just stupid - so I was soooo close :/
Vivek Ranjan
@vivekranjan92
Jun 09 2017 08:43

var count = 0;

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

// Only change code above this line
}

// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

this is what i have done so far
Tymoteusz
@WhiteLeash
Jun 09 2017 08:44
@vivekranjan92 , next time use three on top, and three on bottom of the code
three Grave accent xd
Helio Goncalves
@srlhyo
Jun 09 2017 08:44
hi there"
Vivek Ranjan
@vivekranjan92
Jun 09 2017 08:44
@WhiteLeash didn't get you
Helio Goncalves
@srlhyo
Jun 09 2017 08:44
hi there!
Thomas
@sjurs1
Jun 09 2017 08:45
Hi guys. I've figured out the core of the Convert HTML Entities challenge (#281), but I'm having a hard time debating on where to go from here. I guess I could write tons of for loops and if statements, but that seems very inefficient. My other thoughts were writing a function as the second parameter of the replace method, or going the route of a switch statement with cases for the different symbols that need to be converted. What do you guys think? Where would you go from here?
function convertHTML(str) {
var elementToChange = str.match(/[^A-Za-z0-9 _]{1}/g);
var newStr = "";
newStr = str.replace(elementToChange, "&amp;");
return newStr;
}

convertHTML("Dolce & Gabbana");
Vivek Ranjan
@vivekranjan92
Jun 09 2017 08:45
@srlhyo hi
Pieter Stokkink
@forkerino
Jun 09 2017 08:45
@WhiteLeash yes you were. It is good to know what all methods return, at least the ones you use regularly. In this case, .shift() returns the element you remove, not the remaining array. The return values can also help you to chain methods together, so if you know the type of the return value, you can chain on different methods.
Helio Goncalves
@srlhyo
Jun 09 2017 08:45
need some help with the little program called Word Blanks
Tymoteusz
@WhiteLeash
Jun 09 2017 08:45
@vivekranjan92
like that:
three Grave accent here
// code here
three Grave accent here
Helio Goncalves
@srlhyo
Jun 09 2017 08:45
or challenge, whichever you may call it.
:)
I am going to share my code

var result = "";
// Your code below this line
result = "My neighbour's " + myNoun + " is " + myAdjective + " and " + myVerb + "s " + myAdverb;

// Your code above this line
return result;
}

// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");
what's wrong with it?
somehow it doesn't validate
Tymoteusz
@WhiteLeash
Jun 09 2017 08:46
you should get
"My dog is big and ran so quickly"
Pieter Stokkink
@forkerino
Jun 09 2017 08:47
@vivekranjan92 some of your cases (the letters) need to be strings. Use quotation marks around it
Helio Goncalves
@srlhyo
Jun 09 2017 08:47
why @WhiteLeash ?
Tymoteusz
@WhiteLeash
Jun 09 2017 08:47
I dunno, just I pass that like that :D
Markus Kiili
@Masd925
Jun 09 2017 08:47
@forkerino @Lumexralph Morning.
Helio Goncalves
@srlhyo
Jun 09 2017 08:47
ahah
Pieter Stokkink
@forkerino
Jun 09 2017 08:47
@sjurs1 I used a lookup object.
Tymoteusz
@WhiteLeash
Jun 09 2017 08:47
Maybe they don't like to be offence vs your neighbour
Helio Goncalves
@srlhyo
Jun 09 2017 08:47
ahhahah
Tymoteusz
@WhiteLeash
Jun 09 2017 08:48
oh and '
Helio Goncalves
@srlhyo
Jun 09 2017 08:48
You can tell you must be Polish
aahh
Tymoteusz
@WhiteLeash
Jun 09 2017 08:48
you should use backslash
Vivek Ranjan
@vivekranjan92
Jun 09 2017 08:48
@forkerino ohh thanks let me do this
CamperBot
@camperbot
Jun 09 2017 08:48
vivekranjan92 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2515 | @forkerino |http://www.freecodecamp.com/forkerino
Helio Goncalves
@srlhyo
Jun 09 2017 08:48
lots of sense of humor
:)
Pieter Stokkink
@forkerino
Jun 09 2017 08:48
@srlhyo the words should be surrounded by spaces. You have one case where the s follows one of the words immediately. That doesn't work.
Tymoteusz
@WhiteLeash
Jun 09 2017 08:48
hahaha :D Yes, I'm Polish
Helio Goncalves
@srlhyo
Jun 09 2017 08:48
I knew it ahaha
Vivek Ranjan
@vivekranjan92
Jun 09 2017 08:48
@forkerino it worked
thanks
Pieter Stokkink
@forkerino
Jun 09 2017 08:49
@vivekranjan92 :+1:
Helio Goncalves
@srlhyo
Jun 09 2017 08:49
yes... I thought about the same but tried without '
and still didn't work
I was hoping to understand why my code doesn't work .
Pieter Stokkink
@forkerino
Jun 09 2017 08:50
@srlhyo no I mean after myVerb
Helio Goncalves
@srlhyo
Jun 09 2017 08:50
I even copied my code onto chrome console and it is just fine
oh
let me see then
@forkerino
Tymoteusz
@WhiteLeash
Jun 09 2017 08:51
fk how people can know I'm polish think - now I have big question in my head xd
Helio Goncalves
@srlhyo
Jun 09 2017 08:51
ahah
don't worry
obviously your surname says almost everything :)
I am not a wizard
don't worry!
Tymoteusz
@WhiteLeash
Jun 09 2017 08:52
umm on github? "Stępień"? oh yes, polish letters xd
Helio Goncalves
@srlhyo
Jun 09 2017 08:53
But yhe, all my Polish friends have this particular kind of sense of humor. This is something very Polish, I think.
Plus, I am Portuguese and we also kind of have the jokes ehehehe
Tymoteusz
@WhiteLeash
Jun 09 2017 08:54
oh, I was in Spain only :/ They have great traffics xd
In general, my surname is the same as one actor who played blind man with glasses like a bottom of jar.
this is the most funny thing in my life :/
ok let's code :D
Helio Goncalves
@srlhyo
Jun 09 2017 08:55
sure
ahah
@forkerino I can't spot the mistake in the place you said
can you tell me what's wrong with it?
Pieter Stokkink
@forkerino
Jun 09 2017 08:56
myVerb + "s " <- remove the s
@srlhyo
Helio Goncalves
@srlhyo
Jun 09 2017 08:56
ok then
Tymoteusz
@WhiteLeash
Jun 09 2017 08:57
oh and cookie for you @forkerino thank you for help
CamperBot
@camperbot
Jun 09 2017 08:57
whiteleash sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2516 | @forkerino |http://www.freecodecamp.com/forkerino
Helio Goncalves
@srlhyo
Jun 09 2017 08:57
but what's wrong with it ?
the "s" is a string right?
I thought it could perfectly concatenated
WOW!
it works!!!
thanks a lot @forkerino
CamperBot
@camperbot
Jun 09 2017 08:58
srlhyo sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2517 | @forkerino |http://www.freecodecamp.com/forkerino
Thomas
@sjurs1
Jun 09 2017 08:59
@forkerino Thanks, I'll look into that!
CamperBot
@camperbot
Jun 09 2017 08:59
sjurs1 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2518 | @forkerino |http://www.freecodecamp.com/forkerino
Helio Goncalves
@srlhyo
Jun 09 2017 08:59
I still don't understand what's wrong though. can you explain me ?