These are chat archives for FreeCodeCamp/HelpJavaScript

23rd
Aug 2016
Egoscio
@Egoscio
Aug 23 2016 00:00
That's not a language, it's a library.
My point is starting with JS as a first language really screws up your expectations for the future. That's why the traditional learning path doesn't include JS. Imagine if someone tried to do these hacks in, say, Java...
Joseph
@revisualize
Aug 23 2016 00:01
@Egoscio I didn't know that you were only talking about Languages.
Sorry.
Egoscio
@Egoscio
Aug 23 2016 00:01
Oh I should have specified, my bad.
Joseph
@revisualize
Aug 23 2016 00:02
They are expanding to Python and other languages in the future.
MinstrelPrince
@MinstrelPrince
Aug 23 2016 00:05

i need help...i dnt even understand what this mad lib game code should go about .....function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "";
// Your code below this line

// Your code above this line
return result;
}

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

eduwin7
@eduwin7
Aug 23 2016 00:10
Hi
Stephen James
@sjames1958gm
Aug 23 2016 00:10
@eduwin7 Hello
eduwin7
@eduwin7
Aug 23 2016 00:10
Hi Stephen!
have you done the check for palindromes algorithm?
Stephen James
@sjames1958gm
Aug 23 2016 00:11
@MinstrelPrince use these myNoun, myAdjective, myVerb, myAdverb to build a string in the result variable.
You can build a sentence by putting words between these - just make sure there are spaces between the words
@eduwin7 yes
eduwin7
@eduwin7
Aug 23 2016 00:12
which method should I use? is else?
if else*?
Joseph
@revisualize
Aug 23 2016 00:15
@eduwin7 I didn't use an if/else in mine.
MinstrelPrince
@MinstrelPrince
Aug 23 2016 00:16
@sjames1958gm , its still very confusing ..please give me an example...please
Ricardo Araújo
@ricardomga
Aug 23 2016 00:16
@eduwin7 me neither
Joseph
@revisualize
Aug 23 2016 00:18

For that lesson whenever someone uses an If/Else it is always done like this:

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

When they should just
return (evaluation);

eduwin7
@eduwin7
Aug 23 2016 00:18
for loop is they way?
Joseph
@revisualize
Aug 23 2016 00:19
@eduwin7 palindromes ? .. I didn't use a for loop.
eduwin7
@eduwin7
Aug 23 2016 00:20
what did you use?
Ricardo Araújo
@ricardomga
Aug 23 2016 00:20
@eduwin7 just a comparison
@eduwin7 compare the cleaned string with the reversed and return that
eduwin7
@eduwin7
Aug 23 2016 00:27

function palindrome(str) {

str = str.reserve;

   return true; 

}

hi
Ricardo Araújo
@ricardomga
Aug 23 2016 00:30
@eduwin7 you have to clean the inputed string, then reverse it and then return the comparison of the cleaned string and the reversed string
@eduwin7 i used a regural expression to clean up the inputed string
Stephen James
@sjames1958gm
Aug 23 2016 00:34
@MinstrelPrince myNoun + " very " + myAdjective
@eduwin7 There is a reason this lesson is only two after reverse a string.
help please
CamperBot
@camperbot
Aug 23 2016 00:37
no wiki entry for: please
Thomas
@RoboMantis
Aug 23 2016 00:37
how do I add getGear() and setGear() to the Bike function and myCar constructor
K R Vinay Kumar
@vinaykumar94
Aug 23 2016 00:38
hello can someone tell me how to make pdf from the userinput using jquery
Thomas
@RoboMantis
Aug 23 2016 00:39
I created wikipedia its there
Christian Torres
@SlickChris95
Aug 23 2016 00:41
Greetings, I am having a bit of difficulty with this challenge involving " Returning Boolean Values from Functions".

function isLess(a, b) {
// Fix this code

return a < b;

/if (a < b) {
return true;
} else {
return false;
}
}
/

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

this is my code could someone help?
llamatarianism
@llamatarianism
Aug 23 2016 00:43
@SlickChris95 the tests are probably just using a regex or something to make sure your code doesn't use an if statement
try removing the comment
Christian Torres
@SlickChris95
Aug 23 2016 00:44
I have but when the input values are isLess(15,10) it runs into a problem @llamatarianism
llamatarianism
@llamatarianism
Aug 23 2016 00:44
what problem
Christian Torres
@SlickChris95
Aug 23 2016 00:44
that i am not sure how to represent the same if statement in one return statement
I might be over thinking it, but im pretty stuck at he moment
Stephen James
@sjames1958gm
Aug 23 2016 00:46
@SlickChris95 return a < b is correct - remove the rest.
@RoboMantis Similar to the above this.getGear = function() {}
Christian Torres
@SlickChris95
Aug 23 2016 00:48
@sjames1958gm It worked thank you
CamperBot
@camperbot
Aug 23 2016 00:48
slickchris95 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2807 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Thomas
@RoboMantis
Aug 23 2016 00:50

In the editor you can see an example of a Car constructor that implements this pattern.

Now try it yourself! Modify the Bike constructor to have a private property called gear and two public methods called getGear and setGear to get and set that value.

In the editor you can see an example of a Car constructor that implements this pattern.

Now try it yourself! Modify the Bike constructor to have a private property called gear and two public methods called getGear and setGear to get and set that value.

hi

hi

var Bike = function(getGear, setGear) {
  var gear =1; 
  this.getGear = getGear;
  this.setGear = setGear;
  // Only change code below this line.

};

var myCar = new Car();
//myCar.getGear = 1; 

var myBike = new Bike(1,2);
//myBike.getGear = 1;
a
TypeError: myBike.getGear is not a function
greg
@wearenotgroot
Aug 23 2016 00:54
@RoboMantis getGear and setGear should be methods/functions
@RoboMantis getGear will return the value of gear while setGear will let you modify or set gear's value(through use of function argument)
Thomas
@RoboMantis
Aug 23 2016 01:00
could you just email me the answer, the directions dont even say what a public method looks like
freefavors@gmail.com bc the library closed so i have to go.
greg
@wearenotgroot
Aug 23 2016 01:00
@RoboMantis here
var Bike = function() {
  var gear =1; 
  this.getGear = function(){ return gear;} //<------return the value of gear
  this.setGear = function(newVal){ gear = newVal;} //<----set gear to a new value

}; 

var myBike = new Bike();

myBike.setGear(3);
Joseph
@revisualize
Aug 23 2016 01:03
~~Hello
Elizabeth Crummy
@lizzyac
Aug 23 2016 01:07
I'm on the Record Collection Challenge and am having an issue with adding an empty array. The error says it "Cannot read property 'push' of undefined. Could anyone help me figure out how to modify it so that this error is fixed? This is my code:
// Only change code below this line
function updateRecords(id, prop, value) {
if (prop !== "tracks" && value !=="")
{ collection[id][prop] = value;
}
else if (prop === "tracks" && "tracks" === "")
{ collection[id][prop] = [value];
}
else if (prop === "tracks" && value !== "")
{ collection[id][prop].push(value);
}
else
{ delete collection[id][prop];
}
return collection;
}
Joseph
@revisualize
Aug 23 2016 01:07
Let's see.
Ahh.
You haven't created an element to push to.
@lizzyac you have an issue in your code.
@lizzyac How do you test an object for a property?
/collapse-all
Elizabeth Crummy
@lizzyac
Aug 23 2016 01:09
So I need to add .hasOwnProperty function for the value?
Joseph
@revisualize
Aug 23 2016 01:10
You need to change a part of your code that creates an array element for the property to use .hasOwnProperty(); ... yes.
greg
@wearenotgroot
Aug 23 2016 01:10
@lizzyac for prop, test if prop exist or not if it is 'tracks'
Joseph
@revisualize
Aug 23 2016 01:11
@wearenotgroot :wave:
greg
@wearenotgroot
Aug 23 2016 01:12
@revisualize :wave:
Joseph
@revisualize
Aug 23 2016 01:12
So, I need to find another lesson to create a gist for. I've done a bit. But, yeah, I'm thinking that maybe I should create another one.
Thoughts?
greg
@wearenotgroot
Aug 23 2016 01:12
hmm
Joseph
@revisualize
Aug 23 2016 01:12
A lot of people come in here asking for help on Word blanks.
Maybe that one?
greg
@wearenotgroot
Aug 23 2016 01:13
yeah that one is popular
Joseph
@revisualize
Aug 23 2016 01:13
yeah, I think I'm going to write that one up.
:)
greg
@wearenotgroot
Aug 23 2016 01:14
:+1:
Joseph
@revisualize
Aug 23 2016 01:15
I'll work on that one in a little bit.
/collapse
Kantra
@removed~kantrakantra
Aug 23 2016 01:15
Hey guys, can anybody tell me why this code doesn't .replace()?

function rot13(str) { // LBH QVQ VG!
  str = str.split("");
  str.replace(/\W/g, '');
  return str;

}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Joseph
@revisualize
Aug 23 2016 01:15
ROT!
llamatarianism
@llamatarianism
Aug 23 2016 01:16
@kantrakantra strings are immutable
it's impossible to mutate them without reassigning to them
so str.replace(/\W/g, '') doesn't change str
you'd need to do str = str.replace(/\W/g, '')
Alexander Kyle Workman
@akw2796
Aug 23 2016 01:17

ok i've been stuck on the "record collection" thing for the past, like, three days, literally. i've been trying to figure it out but i have no idea how to do anything except the first part.. this is my code:
// Setup
var collection = {
"2548": {
"album": "Slippery When Wet",
"artist": "Bon Jovi",
"tracks": [
"Let It Rock",
"You Give Love a Bad Name"
]
},
"2468": {
"album": "1999",
"artist": "Prince",
"tracks": [
"1999",
"Little Red Corvette"
]
},
"1245": {
"artist": "Robert Palmer",
"tracks": [ ]
},
"5439": {
"album": "ABBA Gold"
}
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {
if (prop !== "tracks" && value !== "") {
collection[id][prop] = value;
} else if (prop === "tracks" && id.hasOwnValue(prop) === false) {
collection[id][prop] = value;
} else if (prop === "tracks" && value !== "") {
collection[id][prop].push(value);
}

return collection;
}

// Alter values below to test your code
updateRecords(5439, "tracks", "Take a Chance on Me");

i'm not done working on it obviously but i can't get it to do what it should be doing
Kantra
@removed~kantrakantra
Aug 23 2016 01:20
@llamatarianism Is it possible to write
function rot13(str) { // LBH QVQ VG!
  str = str.split("").replace(/\W/g, '');
  return str;

}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
llamatarianism
@llamatarianism
Aug 23 2016 01:20
oh wait I just noticed.
str.split("") returns an array
you can't replace stuff in an array
Kantra
@removed~kantrakantra
Aug 23 2016 01:20
aah
llamatarianism
@llamatarianism
Aug 23 2016 01:20
str.replace(/\W/g, '').split(""); would work
greg
@wearenotgroot
Aug 23 2016 01:20

@akw2796 id is a function argument and a number so

 id.hasOwnValue(prop) //<---------wont work, also you meant to write hasOwnProperty(prop) perhaps?

.hasOwnProperty is for testing if a property exist in an object
docs

Kantra
@removed~kantrakantra
Aug 23 2016 01:20
@llamatarianism So I have to replace before i convert to an array
Subramanya Chakravarthy
@chakrihacker
Aug 23 2016 01:21
@kantrakantra why don't you try without replacing
sorry without splitting
Alexander Kyle Workman
@akw2796
Aug 23 2016 01:23
@wearenotgroot ok i have no idea how to make this do what it's supposed do. i tried using collection[id][prop] === undefined for when there isn't a "tracks" value (which is what i was using the hasOwnValue thing for) but that just didn't work. it didn't give me an error like this does though
Kantra
@removed~kantrakantra
Aug 23 2016 01:23
@chakrihacker I'm pretty sure it needs to be an array for a second to do what i need to do to complete the challenge
Joseph
@revisualize
Aug 23 2016 01:23
yo.
Subramanya Chakravarthy
@chakrihacker
Aug 23 2016 01:23
can I have challenge link
Kantra
@removed~kantrakantra
Aug 23 2016 01:23
@chakrihacker I'm on the Caesar's Cipher challenge
greg
@wearenotgroot
Aug 23 2016 01:24
@akw2796
collection[id] will give you an object then you can use .hasOwnProperty to test if prop exist in it
collection[id].hasOwnProperty(prop)
Joseph
@revisualize
Aug 23 2016 01:24
@akw2796 You use collection[id][prop] everywhere. But, you id.hasOwnValue(prop) for this evaluation?
Alexander Kyle Workman
@akw2796
Aug 23 2016 01:26
i was using someone else's code after i tried to write my own for three days bc maybe someone else could do it better than me. which i get is morally dubious and borders on plagiarism but desperate times...
Joseph
@revisualize
Aug 23 2016 01:26
@akw2796 Ahhh.
Alexander Kyle Workman
@akw2796
Aug 23 2016 01:26
i mean i figured out the collection[id][prop] thing myself but the other person's code did the id.hasOwnValue
so i thought they must know what they were talking about
since they posted their code
Joseph
@revisualize
Aug 23 2016 01:27
Using .hasOwnProperty() is correct.
Subramanya Chakravarthy
@chakrihacker
Aug 23 2016 01:27
@kantrakantra I just remembered
you have to do in the following way
Joseph
@revisualize
Aug 23 2016 01:27
@akw2796 You're just not doing it correctly.
Alexander Kyle Workman
@akw2796
Aug 23 2016 01:28
ok thanks. i think i know what i was doing wrong now. i'll try it
Joseph
@revisualize
Aug 23 2016 01:28
@akw2796 Look, I just re-read your post above. Something that you NEED to learn in JavaScript is HOW to interact with objects.
It is the thing that makes JavaScript JavaScript.
Everything you interact with will be an object.
If you want to move forward in this industry as a JS Developer you have to learn how to work with Objects. It is done ALL the time.
Alexander Kyle Workman
@akw2796
Aug 23 2016 01:29
i know, which is why i'm trying to figure it out. i've been working on this for literally days before asking for help
Joseph
@revisualize
Aug 23 2016 01:29
In fact.
JSON is JavaScript Object Notation.
APIs are written to output JSON.
greg
@wearenotgroot
Aug 23 2016 01:30
@akw2796 dont worry you are not alone on having a rough time with this challenge :worried: , you can do it :+1:
Alexander Kyle Workman
@akw2796
Aug 23 2016 01:30
today is when i basically gave in and decided i'd look for a solution that i didn't come up with myself'
Subramanya Chakravarthy
@chakrihacker
Aug 23 2016 01:30
1.use a for loop to traverse through the string, 2. IF you find a pattern of spaces and non alpha just remove it 3. Again make a for loop and traverse the string, this time if charcodeat < 78 add 13 or else subtrct 13 and log the result in new string and you may call result @kantrakanta
Joseph
@revisualize
Aug 23 2016 01:30
@akw2796 I'm sorry to hear that.
Subramanya Chakravarthy
@chakrihacker
Aug 23 2016 01:30
@kantrakantra hope it helps you
Joseph
@revisualize
Aug 23 2016 01:31
@akw2796 I've helped countless people work through that lesson.
@akw2796 In fact, I made this: https://gist.github.com/revisualize/123deb77d85079f079020ac3cd6ea5ba
To help people with that lesson.
Subramanya Chakravarthy
@chakrihacker
Aug 23 2016 01:32
@revisualize that's a cool idea to help
Joseph
@revisualize
Aug 23 2016 01:32
@chakrihacker It's almost all that I do in FreeCodeCamp any more. I have kind of stalled working on the lessons.
Alexander Kyle Workman
@akw2796
Aug 23 2016 01:32
i'm very stubborn and kind of a perfectionist and also hold myself to very high standards so i usually take way too long to ask for help. hence taking days to swallow my pride and ask people for help with this challenge. thanks for that that's actually really helpful btw. i need to learn not to be afraid of asking for help
Kantra
@removed~kantrakantra
Aug 23 2016 01:33
@chakrihacker Did I miss a comment? What are you referring to?
Joseph
@revisualize
Aug 23 2016 01:33
@akw2796 If you have that pride. You'll have a DIFFICULT time working in the software industry.
Subramanya Chakravarthy
@chakrihacker
Aug 23 2016 01:33
1.use a for loop to traverse through the string, 2. IF you find a pattern of spaces and non alpha just remove it 3. Again make a for loop and traverse the string, this time if charcodeat < 78 add 13 or else subtrct 13 and log the result in new string and you may call result @kantrakanta
Alexander Kyle Workman
@akw2796
Aug 23 2016 01:34
@revisualize i know. it always caused me trouble in school as well. i'm trying to work through it though. humility is not my strong suit
Kantra
@removed~kantrakantra
Aug 23 2016 01:35
Ok why won't this let me use .charCodeAt()?
function rot13(str) { 
  str = str.replace(/\W/g, '').split("");
  if(str.charCodeAt(0) > 65 && str.charCodeAt(0) < 90) {
    return str;
  }
  return str;

}


rot13("SERR PBQR PNZC");
Subramanya Chakravarthy
@chakrihacker
Aug 23 2016 01:35
you are on the way making right just make more changes @kantrakantra
Kantra
@removed~kantrakantra
Aug 23 2016 01:36
It's telling me str.charCodeAt() is not a function
Subramanya Chakravarthy
@chakrihacker
Aug 23 2016 01:36
first condition is testcases will have spaces and non-alphanumeric chars Remove them and store the result to use it later
Alexander Kyle Workman
@akw2796
Aug 23 2016 01:37

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

// Only change code below this line
function updateRecords(id, prop, value) {
if (prop !== "tracks" && value !== "") {
collection[id][prop] = value;
} else if (prop === "tracks" && collection[id].hasOwnProperty(prop) === false) {
collection[id][prop] = value;
}

return collection;
}

// Alter values below to test your code
updateRecords(5439, "tracks", "Take a Chance on Me");

okay now it's only returning the first half of the object, without the part i'm trying to modify showing up at all...

Elizabeth Crummy
@lizzyac
Aug 23 2016 01:38

So I tried adding hasOwnProperty, but it says now "Cannot read Property 'tracks' of undefined. Should I be checking the object property earlier?
if (prop !== "tracks" && value !=="")
{ collection[id][prop] = value;
}
else if (prop === "tracks" && [id].hasOwnProperty(prop) === "")
{ collection[id][prop] = [value];
}
else if (prop === "tracks" && value !== "")
{ collection[id][prop].push(value);
}

else
{ delete collection[id][prop];
}
return collection;
}

Subramanya Chakravarthy
@chakrihacker
Aug 23 2016 01:38
@kantrakantra can you post the code
greg
@wearenotgroot
Aug 23 2016 01:38

@lizzyac this is incorrect

[id].hasOwnProperty(prop)

you meant to write

collection[id].hasOwnProperty(prop)
Alexander Kyle Workman
@akw2796
Aug 23 2016 01:38
@lizzyac it appears we're having the same problem
nicolemaj
@nicolemaj
Aug 23 2016 01:39

hi there, does anyone know what's wrong with my code? It doesn't like the ":" or the breaks... ?

function caseInSwitch(val) {
var answer = "";
// Only change code below this line
case "1":
answer = "alpha";
break;

case "2":
answer = "beta";
break;

case "3":
answer = "gamma";
break;

case "4":
answer = "delta";
break;

// Only change code above this line  

return answer;
}

// Change this value to test
caseInSwitch(2);

Kantra
@removed~kantrakantra
Aug 23 2016 01:40
@chakrihacker This is what I'm working with so far.
function rot13(str) { 
  str = str.replace(/\W/g, '').split("");
  if(str.charCodeAt(0) > 65 && str.charCodeAt(0) < 90) {
    return str;
  }
  return str;

}


rot13("SERR PBQR PNZC");
Subramanya Chakravarthy
@chakrihacker
Aug 23 2016 01:40
in case change it from "1" to 1 @nicolemaj
Kantra
@removed~kantrakantra
Aug 23 2016 01:40
Just what I posted just now
Elizabeth Crummy
@lizzyac
Aug 23 2016 01:40
Ok, so each time this function is used, you have to do the full variable?
Subramanya Chakravarthy
@chakrihacker
Aug 23 2016 01:40
remove 1 return str
Alexander Kyle Workman
@akw2796
Aug 23 2016 01:41
@lizzyac i'm pretty sure that's the case. i still can't get it to work for me though...
Stephen James
@sjames1958gm
Aug 23 2016 01:41
@kantrakantra You will need to keep the spaces.
nicolemaj
@nicolemaj
Aug 23 2016 01:41
@chakrihacker I've tried that too. The test won't pass!
Stephen James
@sjames1958gm
Aug 23 2016 01:42
@nicolemaj The input to the function is numbers but you are testing strings "1"
Elizabeth Crummy
@lizzyac
Aug 23 2016 01:42
@akw2796 Yeah, I'm going to play around with where I add that part. Maybe it has to go at the beginning of the function before the if/else statements?
Stephen James
@sjames1958gm
Aug 23 2016 01:42
@lizzyac YOu have to have collection[id] every time
nicolemaj
@nicolemaj
Aug 23 2016 01:44

@sjames1958gm when I try the following code I get a Syntax Error: unexpected token case as well as an error that says missing ";"

function caseInSwitch(val) {
var answer = "";
// Only change code below this line
case 1:
answer = "alpha";
break;

case 2:
answer = "beta";
break;

case 3:
answer = "gamma";
break;

case 4:
answer = "delta";
break;

// Only change code above this line  

return answer;
}

// Change this value to test
caseInSwitch(2);

Subramanya Chakravarthy
@chakrihacker
Aug 23 2016 01:44
@kantrakantra I found, the problem is str= str.replace it conversts the str to array
@kantrakantra so you can't use charcodeat with array
Elizabeth Crummy
@lizzyac
Aug 23 2016 01:44
Oh, ok! I will try that. Why does it have to be added each time? To define it?
Stephen James
@sjames1958gm
Aug 23 2016 01:45
@lizzyac Without that it doesn't know what [id] is referencing.
Subramanya Chakravarthy
@chakrihacker
Aug 23 2016 01:45
@nicolemaj return must be outside of switch
Stephen James
@sjames1958gm
Aug 23 2016 01:45
@chakrihacker split is turning it into an array - but your are correct about charCodeAt
greg
@wearenotgroot
Aug 23 2016 01:45
@nicolemaj how do you write a switch?
Elizabeth Crummy
@lizzyac
Aug 23 2016 01:45
Ok. That doensn't mean you have to check the object property each time though, right? I guess that is where I'm confused.
Stephen James
@sjames1958gm
Aug 23 2016 01:45
@nicolemaj You are missing your actual switch statement. Look at the sample code
greg
@wearenotgroot
Aug 23 2016 01:46
@nicolemaj read some docs :)
switch-docs
nicolemaj
@nicolemaj
Aug 23 2016 01:46
I see! got it thanks!
Subramanya Chakravarthy
@chakrihacker
Aug 23 2016 01:46
@wearenotgroot he is doing good I think so except return
Alexander Kyle Workman
@akw2796
Aug 23 2016 01:46

ok my code's not working still...no error message it's just not working...
function updateRecords(id, prop, value) {
if (prop !== "tracks" && value !== "") {
collection[id][prop] = value;
} else if (prop === "tracks" && collection[id].hasOwnProperty(prop) === false) {
collection[id][prop] = value;
}

return collection;
}
i'm just working on one part of it at a taime, trying to get each part to work before i move on. and this is driving me nuts

Stephen James
@sjames1958gm
Aug 23 2016 01:47
@chakrihacker There is no switch (val) {
greg
@wearenotgroot
Aug 23 2016 01:47
@chakrihacker missing the important part
switch(val){...} //<------
Subramanya Chakravarthy
@chakrihacker
Aug 23 2016 01:47
@sjames1958gm oh yes
Stephen James
@sjames1958gm
Aug 23 2016 01:47
@lizzyac "tracks" is the only one to check
Mercifex
@Mercifex
Aug 23 2016 01:47
maybe a stupid a question but I feel like i'm missing something. FCC shoes if/else statements as if {} if{} {}.... I was under the impression that it should be if {} else if{} else {}. Are both correct?
shows, not shoes...
Stephen James
@sjames1958gm
Aug 23 2016 01:48
@akw2796 When hasOwnProperty is false you need to create and array with value
Kantra
@removed~kantrakantra
Aug 23 2016 01:48
@chakrihacker Ok then what is the argument in .charCodeAt(0) for? The zero in the parentheses for instance?
greg
@wearenotgroot
Aug 23 2016 01:48
@Mercifex that depends on what you are trying to do
Kantra
@removed~kantrakantra
Aug 23 2016 01:48
@chakrihacker if not for an array
Stephen James
@sjames1958gm
Aug 23 2016 01:48
@kantrakantra charCodeAt is an function on string.
Elizabeth Crummy
@lizzyac
Aug 23 2016 01:48
@sjames1958gm @akw2796 so collection[id][prop] = [value] would make that array?
Stephen James
@sjames1958gm
Aug 23 2016 01:48
@lizzyac Yes
Mercifex
@Mercifex
Aug 23 2016 01:49
@wearenotgroot so they are situational?
Subramanya Chakravarthy
@chakrihacker
Aug 23 2016 01:49
@kantrakantra you can use charcode = str.charCodeAt(0); and return charcode
you may understand what'scharcodeat is doing
Alexander Kyle Workman
@akw2796
Aug 23 2016 01:49
@sjames1958gm @lizzyac omg you guys are helping me so much.
greg
@wearenotgroot
Aug 23 2016 01:49
@lizzyac yep
if you try to access a property that doesnt exist and set it to a value it will be created for you
  • creates 'tracks' property on the object
  • and set the value to an array containing whatever is in value variable
Stephen James
@sjames1958gm
Aug 23 2016 01:49
@Mercifex if {} if {} if {} would evaluate every if . if {} else if{} else {}. would only evaluate until an if was true
@akw2796 :+1:
Mercifex
@Mercifex
Aug 23 2016 01:51
@sjames1958gm so if (condition is true) {do this if not do nothing?}, also if (is true) {do this too} while the latter is if (true) {do this, if not try the next else if}?
Elizabeth Crummy
@lizzyac
Aug 23 2016 01:51

It still says it is undefined for me. At first I had it at collection[id].hasOwnProperty(prop) === "" in my else if statement, then changed it to collection[id].hasOwnProperty(prop) === false. Both say that 'hasOwnProperty' is undefined.
function updateRecords(id, prop, value) {
if (prop !== "tracks" && value !=="")
{ collection[id][prop] = value;
}
else if (prop === "tracks" && collection[id].hasOwnProperty(prop) === false)
{ collection[id][prop] = [value];
}
else if (prop === "tracks" && value !== "")
{ collection[id][prop].push(value);
}

else
{ delete collection[id][prop];
}
return collection;
}
Thank you so much for your help so far @wearenotgroot @sjames1958gm @akw2796 !

CamperBot
@camperbot
Aug 23 2016 01:51
lizzyac sends brownie points to @wearenotgroot and @sjames1958gm and @akw2796 :sparkles: :thumbsup: :sparkles:
:cookie: 212 | @akw2796 |http://www.freecodecamp.com/akw2796
:star2: 1432 | @wearenotgroot |http://www.freecodecamp.com/wearenotgroot
:star2: 2808 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
greg
@wearenotgroot
Aug 23 2016 01:52
@lizzyac you dont have to have that comparison since .hasOwnProperty will return boolean values
Elizabeth Crummy
@lizzyac
Aug 23 2016 01:52
So remove it equaling false?
greg
@wearenotgroot
Aug 23 2016 01:53
@lizzyac uhmm
Elizabeth Crummy
@lizzyac
Aug 23 2016 01:53
It remains undefined when I do that.
Kantra
@removed~kantrakantra
Aug 23 2016 01:53
@chakrihacker Ok I tried this and I'm getting an error
str = "This is a string";
return str.charCodeAt(0);
greg
@wearenotgroot
Aug 23 2016 01:54
@lizzyac nvm you need the comparison
Stephen James
@sjames1958gm
Aug 23 2016 01:54
@kantrakantra What error?
Elizabeth Crummy
@lizzyac
Aug 23 2016 01:54
@wearenotgroot would it be defined if I added it in for an earlier if statement?
Stephen James
@sjames1958gm
Aug 23 2016 01:55
@lizzyac You can use !collection[id].hasOwnProperty() the ! reverses the meaning so false is true
Subramanya Chakravarthy
@chakrihacker
Aug 23 2016 01:56
function convert(str){
    return str.charCodeAt(0);
}

str = "This is a string";
@kantrakantra
you can't return without a function
greg
@wearenotgroot
Aug 23 2016 01:57
@lizzyac do what @sjames1958gm said
@lizzyac did you get any error because i tested it and it's working(passing)
Elizabeth Crummy
@lizzyac
Aug 23 2016 01:58
@sjames1958gm should I be doing this in a new if statement? I tried it in my else if statement and it is undefined. I also tried adding a new if statement at the top of the function, but it still didn't work.
@wearenotgroot Yeah it was still undefined

function updateRecords(id, prop, value) {
if (prop !== "tracks" && value !=="")
{ collection[id][prop] = value;
}
else if (prop === "tracks" && !collection[id].hasOwnProperty(prop) === false)
{ collection[id][prop] = [value];
}
else if (prop === "tracks" && value !== "")
{ collection[id][prop].push(value);
}

else
{ delete collection[id][prop];
}
return collection;
}

Should I have made it true?
Joseph
@revisualize
Aug 23 2016 02:00
@lizzyac !collection[id].hasOwnProperty(prop) === false remove the === false
Elizabeth Crummy
@lizzyac
Aug 23 2016 02:01
@revisualize I removed it, but it still isn't passing.
Joseph
@revisualize
Aug 23 2016 02:01
@lizzyac repost your function?
greg
@wearenotgroot
Aug 23 2016 02:01
@lizzyac the else if propbably should have a test for value !== "" as well
Joseph
@revisualize
Aug 23 2016 02:02
That part is correct.
Stephen James
@sjames1958gm
Aug 23 2016 02:02
@lizzyac the ! is in place of the === false not both
Elizabeth Crummy
@lizzyac
Aug 23 2016 02:03
@revisualize @wearenotgroot @sjames1958gm @akw2796 Nvm it passed. I had to change one of the values I was testing. Thank you for all of your help!
CamperBot
@camperbot
Aug 23 2016 02:03
lizzyac sends brownie points to @revisualize and @wearenotgroot and @sjames1958gm and @akw2796 :sparkles: :thumbsup: :sparkles:
:warning: lizzyac already gave wearenotgroot points
:warning: lizzyac already gave akw2796 points
:star2: 1698 | @revisualize |http://www.freecodecamp.com/revisualize
:warning: lizzyac already gave sjames1958gm points
Elizabeth Crummy
@lizzyac
Aug 23 2016 02:04
It works with removing ! and adding back in the comparison as well, so I just messed something up earlier.
Subramanya Chakravarthy
@chakrihacker
Aug 23 2016 02:04
@kantrakantra are you working
Joseph
@revisualize
Aug 23 2016 02:04
@lizzyac I'm going to PM you a link.
Stephen James
@sjames1958gm
Aug 23 2016 02:06
@lizzyac :+1:
Elizabeth Crummy
@lizzyac
Aug 23 2016 02:06
@revisualize Ok
zacharydylan
@zacharydylan
Aug 23 2016 02:09
Hi I am working on the pomodoro clock. I have been using setInterval() as the timer, but I am having trouble getting the timers to work independently of each other. I have tried using setInterval() to start the second clock but can't get it to work. The notes on my pen are more in depth. Any help would be greatly appreciated (hints pushing me in a better direction are also more than welcome).
encount
@encount
Aug 23 2016 02:12
@zacharydylan whats the other timer/s going to do?
zacharydylan
@zacharydylan
Aug 23 2016 02:12
@encount the second timer just needs to trigger when the first is done. The first starts when clicking the button.
@encount They are just showing a countdown.
greg
@wearenotgroot
Aug 23 2016 02:14
@zacharydylan those timers needs to work on different countdown variables
  • breakTime
  • workTime
zacharydylan
@zacharydylan
Aug 23 2016 02:16
@wearenotgroot I have two variables for the countdowns, They are currently interval and rest. I previously had another variable for seconds, but that didn't do much for me either.
encount
@encount
Aug 23 2016 02:16
@zacharydylan you can use the same timer - just change the variables its working on
Geo Galagaran
@geeofree
Aug 23 2016 02:16
Hey guys. Is there any of you here that's done with the Sorted Union Algorithm Challenge?
Mercifex
@Mercifex
Aug 23 2016 02:20
Is there a reason this isn't running as correct? The same formatting worked for the previous challenge. # is 215 ish "Multiple Identical Options in Switch Statements"

function sequentialSizes(val) {
  var answer = "";
  // Only change code below this line
  switch(val) {
    case "1" :
    case "2" :
    case "3" :
        return "Low";
        break;
    case "4" :
    case "5" :
    case "6" :
        return "Mid";
        break;
    case "7" :
    case "8" :
    case "9" :
        return "High";
        break;
  }


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


// Change this value to test
sequentialSizes(1);
greg
@wearenotgroot
Aug 23 2016 02:21
@Mercifex remove the return on those cases, instead set answer to 'Low', 'Mid' or 'High'
Mercifex
@Mercifex
Aug 23 2016 02:21
@wearenotgroot as in just put ------- "Mid"/"High"?
Stephen James
@sjames1958gm
Aug 23 2016 02:22
@Mercifex Your returns are not the problem - you are supposed to test for numbers not strings.
greg
@wearenotgroot
Aug 23 2016 02:22
@Mercifex -----> answer = '...which ever value on those cases requires'
Mercifex
@Mercifex
Aug 23 2016 02:23
what specifically are you refereeing to when you say "answer"?
encount
@encount
Aug 23 2016 02:23
@Mercifex replace return - with answer = ‘High’ etc - then finally return answer
Mercifex
@Mercifex
Aug 23 2016 02:24
@sjames1958gm lol, that was the problem. *facepalm, completely glanced over that thanks!
CamperBot
@camperbot
Aug 23 2016 02:24
mercifex sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2810 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
greg
@wearenotgroot
Aug 23 2016 02:26
@zacharydylan it would be easier of you work on just seconds then just have a functions that formats what you display on the screen
Mercifex
@Mercifex
Aug 23 2016 02:26
@encount @wearenotgroot by putting answer instead of return does that store the answers until they are spefically called on? Like later in the code when it has return answer, while if they are all return, they just auto return to the console?
Kantra
@removed~kantrakantra
Aug 23 2016 02:27
@chakrihacker Does the same apply for fromCharCode() because I'm getting the same error msg tho I though I fixed the problem
function rot13(str) { 
  str = str.replace(/[^\w\s]/gi, '');
  if(str.charCodeAt(0) > 65 && str.charCodeAt(0) < 90) {
    str = str.split("");
    str = str.fromCharCode(13);
  }
  return str;

}


rot13("SERR PBQR PNZC");
encount
@encount
Aug 23 2016 02:28
@Mercifex is will assign answer to the value of the case statement (plus good idea to have a default incase none are met)
Mercifex
@Mercifex
Aug 23 2016 02:29
@encount thanks, and yeah I usually do but the specific assignment didn't ask for it so I didn't do it
CamperBot
@camperbot
Aug 23 2016 02:29
mercifex sends brownie points to @encount :sparkles: :thumbsup: :sparkles:
:cookie: 327 | @encount |http://www.freecodecamp.com/encount
Angel J Piscola
@Redmega
Aug 23 2016 02:29
Whats up everyone
Jacob Stewart
@JacobStewart1
Aug 23 2016 02:29
https://codepen.io/JacobStewart1/pen/RROAxZ?editors=1010 I need some help it keeps coming up with that their is an unexpected string in the javascript section and i cant figure out why
Kantra
@removed~kantrakantra
Aug 23 2016 02:31
@chakrihacker actually nvm I'm making the same mistake
@chakrihacker or am I
lol sorry
encount
@encount
Aug 23 2016 02:33
@JacobStewart1 in codepen if you you click the drop down (top-right of js box) and then analyse js - it might give you a heads up
Jacob Stewart
@JacobStewart1
Aug 23 2016 02:33
ok @encount
thanks @encount
CamperBot
@camperbot
Aug 23 2016 02:34
jacobstewart1 sends brownie points to @encount :sparkles: :thumbsup: :sparkles:
:cookie: 328 | @encount |http://www.freecodecamp.com/encount
Addy
@asonder
Aug 23 2016 02:35
working on seek and destroy. can anyone give me a hint as to why this isn't working? it returns argumentxamarin/xamarin-android@a16673d every time. function destroyer(arr) {
var initial = argumentsxamarin/xamarin-android@a16673d;
function removeSame() {
for (var j = 0; j < initial.length; j++) {
for (var i = 1; i < arguments.length; i++) {
return initial[j] !== arguments[i];
}
}
}
var newArray = arr.filter(removeSame);
return newArray;
}
that's supposed to be arguments[zero]
(the number zero)
greg
@wearenotgroot
Aug 23 2016 02:42
@asonder look through the example on filter docs filter
also
arguments object, as you can see on the example you can convert arguments to a real array
var args = Array.prototype.slice.call(arguments);
Ryan Apolinar
@ryanapolinar
Aug 23 2016 02:43
Can someone tell me why using "text-center" on my image won't put it in the center? It has a transparent background, so I gave it a red one to help with debugging. Here is the Codepen
Addy
@asonder
Aug 23 2016 02:44
thanks, @wearenotgroot , i'll take another look
CamperBot
@camperbot
Aug 23 2016 02:44
asonder sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star2: 1433 | @wearenotgroot |http://www.freecodecamp.com/wearenotgroot
Angelo Ryndon
@AIRyndon
Aug 23 2016 02:45
@ryanapolinar haven't looked at your codepen yet..but for images, text-center is not a good idea, try using the position css...:)
btw guys I have a question regarding the missing letters algo challenge.. I have a solution, just wanna know how someone else did it.
function fearNotLetter(str) {
  var letter = "";
  var prev = 0;
  var cur = 0;
  var idx = 0;
  var charCodes = Array.prototype.map.call(str,function(cur){
      return cur.charCodeAt(0);
  });

  charCodes.forEach(function(elem){      
    if(prev === 0){
         prev = elem;         
    }
         cur = elem;
         idx = cur - prev;   
    while(idx > 1){
           idx--;  
           letter += String.fromCharCode(cur - idx);  
    }
         prev = elem;
  }); 
    return (letter === "")?undefined:letter;
}
fearNotLetter("bcd");
zacharydylan
@zacharydylan
Aug 23 2016 02:49
@wearenotgroot @encount thank you for your help, I think I can finish this now.
CamperBot
@camperbot
Aug 23 2016 02:49
zacharydylan sends brownie points to @wearenotgroot and @encount :sparkles: :thumbsup: :sparkles:
:cookie: 331 | @encount |http://www.freecodecamp.com/encount
:star2: 1434 | @wearenotgroot |http://www.freecodecamp.com/wearenotgroot
Jason Hartung
@jaschart
Aug 23 2016 02:51
I'm new to this and not sure of the etiquette. I have a couple of blocks of code that have me perplexed. One returns and logs 10, one logs 10 but returns undefined. Is it ok if I paste them in and get feedback?
greg
@wearenotgroot
Aug 23 2016 02:52
@zacharydylan :+1:
Ryan Apolinar
@ryanapolinar
Aug 23 2016 02:53
figured it out, added a CSS class
.to-center {
    margin:0 auto;
    display: inline;
}
Kantra
@removed~kantrakantra
Aug 23 2016 02:53
Hey guys, I'm sort of lost on how I'm supposed to actually change the char code of the string. Here's my code so far:
function rot13(str) { 
  str = str.replace(/[^\w\s]/gi, '');
  if(str.charCodeAt(0) > 65 && str.charCodeAt(0) < 90) {
    str = str.split("");
    str = str.fromCharCode();
  }
  return str;

}


rot13("SERR PBQR PNZC");
greg
@wearenotgroot
Aug 23 2016 02:53
@jaschart sure ----> code format
Jason Hartung
@jaschart
Aug 23 2016 02:54
@wearenotgroot thanks
CamperBot
@camperbot
Aug 23 2016 02:54
jaschart sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star2: 1435 | @wearenotgroot |http://www.freecodecamp.com/wearenotgroot
encount
@encount
Aug 23 2016 02:54
@kantrakantra if you add a new value to a char code it become a new letter
greg
@wearenotgroot
Aug 23 2016 02:55
@kantrakantra fromCharCode docs
Ngan Ngo
@KimmieWu
Aug 23 2016 02:57

// Declarations
var studlyCapvar;
var properCamelCase;
var titleCaseOver;

// Assignments
studlyCapvar = 10;
properCamelCase = "A String";
titleCaseOver = 9000;

Hello everyone, Please help me, why can't I pass the Case Sensitivity in Variables of javascript lesson
greg
@wearenotgroot
Aug 23 2016 03:01

@KimmieWu reset your code
the decalaration should look like this originally

// Declarations
var StUdLyCapVaR;
var properCamelCase;
var TitleCaseOver;

then you just follow those camelcasing on the assignments section

Jason Hartung
@jaschart
Aug 23 2016 03:03
@wearenotgroot I'm having no luck with that code format
jsfunction sumAll(arr) {
  var max = Math.max(arr[0],arr[1]);
  var min = Math.min(arr[0],arr[1]);
  var sum = 0;
  while(max >= min){
    sum += max;
    max--;
  }
  console.log(sum);
  return(sum);
}

sumAll([1, 4]); //retuns and logs 10

function sumAll(arr) {
  var values = arr.reduce(function(a,b){
  var max = Math.max(a,b);
  var min = Math.min(a,b);
  var sum = 0;
  while(max >= min){
    sum += max;
    max--;
  }
  console.log(sum);
  return(sum);
  });
}

sumAll([1, 4]); //logs 10, returns undefined
Greg Duncan
@GregatGit
Aug 23 2016 03:04
@kantrakantra I don't think you need to use replace - I turned every char into a number - then looped though - if they were in the right range (corisponding to letters) then I would add 13 - then at the end change them all back to chars
Kantra
@removed~kantrakantra
Aug 23 2016 03:04

@encount Yes but I keep getting an error even when I input a value, also how do I specify that I want to increase 13 from the original, not just a number in general.

I mean indicate an increase essentially

Greg Duncan
@GregatGit
Aug 23 2016 03:07
@jaschart use max and min and set up a simple for loop
greg
@wearenotgroot
Aug 23 2016 03:07
@KimmieWu oh it was the studlyCapVar that is incorrect i yours(uppercase V)
var studlyCapvar; //vs  studlyCapVar
Jason Hartung
@jaschart
Aug 23 2016 03:08
@GregatGit would a for change the result?
Pogg
@fogkio
Aug 23 2016 03:08
Hiiii
can i ask a question?
Greg Duncan
@GregatGit
Aug 23 2016 03:09
@fogkio that is a question - but yes
Jason Hartung
@jaschart
Aug 23 2016 03:09
@GregatGit :)
Greg Duncan
@GregatGit
Aug 23 2016 03:10
@jaschart you would still return sum
Pogg
@fogkio
Aug 23 2016 03:11
here is my solve name 'Profile Lookup'
Jason Hartung
@jaschart
Aug 23 2016 03:11
@GregatGit Right, I just don't understand why in one case sum is 10, and in the other, sum is 10 in console log but undefined when returned
Pogg
@fogkio
Aug 23 2016 03:11

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


function lookUpProfile(firstName, prop){
// Only change code below this line
if(contacts.hasOwnProperty(firstName)){
  return contacts[prop];
}
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
in my function
i stuck
how can i check "first name" array with varr in func?
i use hasOwnProperty but doesnt work
greg
@wearenotgroot
Aug 23 2016 03:13
@fogkio question what is contacts ?
Greg Duncan
@GregatGit
Aug 23 2016 03:15
@jaschart your first one works though
Pogg
@fogkio
Aug 23 2016 03:15
contacts is array above
greg
@wearenotgroot
Aug 23 2016 03:15
@fogkio that is correct
Greg Duncan
@GregatGit
Aug 23 2016 03:15
@jaschart but your second one has no return value - that's why you get undefined
Jason Hartung
@jaschart
Aug 23 2016 03:15
@GregatGit but it fails in "Sum All Numbers in a Range"
greg
@wearenotgroot
Aug 23 2016 03:16
@fogkio so you have an array with a bunch of object inside it
@fogkio how can we access elements inside an array?(check one by one)
Greg Duncan
@GregatGit
Aug 23 2016 03:17
@jaschart wrong function name - it should be - function sumAll
Jason Hartung
@jaschart
Aug 23 2016 03:17
@GregatGit the "js" at the front was a screwup in me pasting it
Pogg
@fogkio
Aug 23 2016 03:17
@wearenotgroot array[...][...]?
jinjuujii
@jinjuujii
Aug 23 2016 03:18

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

// Only change code below this line
function updateRecords(id, prop, value) { //prop = tracks or artists and value is song
if (prop !== "tracks" && value !== ""){
collection.id.prop = value;
}

else if (prop === "tracks" && collection.id.hasOwnProperty("tracks") === false){
collection.id.tracks= [];
collection.id.tracks = value;
}

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

else if ( value ===""){
delete collection.id.prop;
}
return collection;
}

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

how come my code keep saying cannot set prop as it's undefined? :(
Pogg
@fogkio
Aug 23 2016 03:18
@jinjuujii usse ``` pls
greg
@wearenotgroot
Aug 23 2016 03:18
@fogkio what mechanism is suited in going through each element on an array?
jinjuujii
@jinjuujii
Aug 23 2016 03:18
@fogkio what's ```?
Greg Duncan
@GregatGit
Aug 23 2016 03:18
@jaschart yeah - so it should work now
Angel J Piscola
@Redmega
Aug 23 2016 03:19
help format
CamperBot
@camperbot
Aug 23 2016 03:19
no wiki entry for: format
Angel J Piscola
@Redmega
Aug 23 2016 03:19
what happened to the camperbot
Jason Hartung
@jaschart
Aug 23 2016 03:19
@GregatGit it doesn't, if you paste it into the console, or run it in fCC, the first one logs 10 but returns "undefined."
Angel J Piscola
@Redmega
Aug 23 2016 03:19
did I forget the command or is the bot the one that forgot it :(
greg
@wearenotgroot
Aug 23 2016 03:20
@jinjuujii code format
Greg Duncan
@GregatGit
Aug 23 2016 03:20

@jaschart

function sumAll(arr) {
  var max = Math.max(arr[0],arr[1]);
  var min = Math.min(arr[0],arr[1]);
  var sum = 0;
  while(max >= min){
    sum += max;
    max--;
  }
  console.log(sum);
  return(sum);
}

this works

Jason Hartung
@jaschart
Aug 23 2016 03:21
@GregatGit I know, my question was why the other doesn't
Pogg
@fogkio
Aug 23 2016 03:21
@wearenotgroot can y explan again? how? :( i always stuck in this too long
greg
@wearenotgroot
Aug 23 2016 03:21
@fogkio since you need to check for firstName of each object inside that contacts array you need to loop through each one right?
@fogkio so a for loop
for(var i = 0; i < contacts.length; i++){
 ....
}
jinjuujii
@jinjuujii
Aug 23 2016 03:22
@wearenotgroot where do i go to get the proper code format for help ?
Greg Duncan
@GregatGit
Aug 23 2016 03:22
@jaschart it has no return value
greg
@wearenotgroot
Aug 23 2016 03:23
@jinjuujii use backticks
```js
...code between groups of backticks
```
Pogg
@fogkio
Aug 23 2016 03:23
right ! @wearenotgroot let me try
jinjuujii
@jinjuujii
Aug 23 2016 03:23
js code
// Setup
var collection = {
    "2548": {
      "album": "Slippery When Wet",
      "artist": "Bon Jovi",
      "tracks": [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    "2468": {
      "album": "1999",
      "artist": "Prince",
      "tracks": [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    "1245": {
      "artist": "Robert Palmer",
      "tracks": [ ]
    },
    "5439": {
      "album": "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
//var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) { //prop = tracks or artists and value is song
  if (prop !== "tracks" && value !== ""){
    collection.id.prop = value;
  }

 else if (prop === "tracks" && collection.id.hasOwnProperty("tracks") === false){
    collection.id.tracks= [];
    collection.id.tracks = value;
  }

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

  else if ( value ===""){
    delete collection.id.prop;
  } 
  return collection;
} 

// Alter values below to test your code
updateRecords(5439, "artists", "ABBA");
greg
@wearenotgroot
Aug 23 2016 03:24
@jinjuujii do you know when to use .(dot) and bracket notation? when accessing object value?
Jason Hartung
@jaschart
Aug 23 2016 03:24
js
function sumAll(arr) {
  var values = arr.reduce(function(a,b){
  var max = Math.max(a,b);
  var min = Math.min(a,b);
  var sum = 0;
  while(max >= min){
    sum += max;
    max--;
  }
  console.log(sum);
  return(sum);
  });
}

sumAll([1, 4]); //logs 10, returns undefined
function sumAll(arr) {
  var values = arr.reduce(function(a,b){
  var max = Math.max(a,b);
  var min = Math.min(a,b);
  var sum = 0;
  while(max >= min){
    sum += max;
    max--;
  }
  console.log(sum);
  return(sum);
  });
}

sumAll([1, 4]); //logs 10, returns undefined
jinjuujii
@jinjuujii
Aug 23 2016 03:24
bracket for spaces properties and variables
is that where i should be looking?
Jason Hartung
@jaschart
Aug 23 2016 03:25
grr, sorry, still trying to figure out chat,
greg
@wearenotgroot
Aug 23 2016 03:25
@jinjuujii yes so what is id and prop?
Greg Duncan
@GregatGit
Aug 23 2016 03:25

@jaschart if you have a function like

function foo(str, str){
   var myStr = str + str;
}
foo("hello", "world");

this will give you undefined

Jason Hartung
@jaschart
Aug 23 2016 03:26
what I just pasted (either one) returns undefined but logs 10
Joseph
@revisualize
Aug 23 2016 03:26
Hehe.
jinjuujii
@jinjuujii
Aug 23 2016 03:26
@wearenotgroot id is my property and prop is a subprop of the id property?
Greg Duncan
@GregatGit
Aug 23 2016 03:26
@jaschart the return value is for values - not sumAll - try putting return values on the last line of the function
Joseph
@revisualize
Aug 23 2016 03:27
@jaschart You know.. That can be solved with ... Math.
greg
@wearenotgroot
Aug 23 2016 03:27

@jinjuujii

updateRecords(id, prop, value) <-------those guys

what you did here

collection.id.prop = value; //should you be using .(dot) notation?
jinjuujii
@jinjuujii
Aug 23 2016 03:27
i wanted to store value into that property
Joseph
@revisualize
Aug 23 2016 03:27
dot notation is a string literal.
greg
@wearenotgroot
Aug 23 2016 03:29
@jinjuujii is there a property in there that is called prop or id(literal) ?
"2548": {
      "album": "Slippery When Wet",
      "artist": "Bon Jovi",
      "tracks": [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    }
Jason Hartung
@jaschart
Aug 23 2016 03:29
@GregatGit values also returns as undefined
jinjuujii
@jinjuujii
Aug 23 2016 03:30
no. but when the function updaterecords(id,prop,value) was used. it bring those values into properties?
Greg Duncan
@GregatGit
Aug 23 2016 03:31
@jaschart where did you put it?
jinjuujii
@jinjuujii
Aug 23 2016 03:31
updateRecords("2548", "tracks", "abba"); ?
isn't that the same as collection.2548.tracks ?
Joseph
@revisualize
Aug 23 2016 03:32
@jinjuujii Yes.
Jason Hartung
@jaschart
Aug 23 2016 03:32
@GregatGit oh...sonofa.... thanks
CamperBot
@camperbot
Aug 23 2016 03:32
jaschart sends brownie points to @gregatgit :sparkles: :thumbsup: :sparkles:
:cookie: 743 | @gregatgit |http://www.freecodecamp.com/gregatgit
Joseph
@revisualize
Aug 23 2016 03:32
@jinjuujii But, you're not using the absolute value. You're using a representation of the value.
Greg Duncan
@GregatGit
Aug 23 2016 03:32
@jaschart you syntax makes your code hard to read it should be
function sumAll(arr) {
  var values = arr.reduce(function(a,b){
     var max = Math.max(a,b);
     var min = Math.min(a,b);
     var sum = 0;
     while(max >= min){
       sum += max;
       max--;
     }
     console.log(sum);
     return(sum);
     });
   return values;
}
Pogg
@fogkio
Aug 23 2016 03:33
function lookUpProfile(firstName, prop){
// Only change code below this line
  for(var i=0 ; i<contacts.length ;i++){
    if(contacts[i].hasOwnProperty(firstName)){
       return contacts[i].prop;
    }
    else{
      return "No such contact";
    }
  }
}
@wearenotgroot
jinjuujii
@jinjuujii
Aug 23 2016 03:33
@revisualize what do you mean? absolute vs representation
Joseph
@revisualize
Aug 23 2016 03:33
@jinjuujii Because you're using the representation of the value you have to use bracket notation.
Pogg
@fogkio
Aug 23 2016 03:33
am i wrong?
Joseph
@revisualize
Aug 23 2016 03:33
@fogkio yes.
jinjuujii
@jinjuujii
Aug 23 2016 03:33
so i have to use collection[id][prop] ?
greg
@wearenotgroot
Aug 23 2016 03:33
@fogkio close but not quite
Pogg
@fogkio
Aug 23 2016 03:33
why state if did work?
Greg Duncan
@GregatGit
Aug 23 2016 03:34
@jaschart if you ever get an unexpected "undefined" it could be cause there is no return value
Joseph
@revisualize
Aug 23 2016 03:34
@fogkio Also, the same for you. Dot notation is a string literal.
Jason Hartung
@jaschart
Aug 23 2016 03:35
@GregatGit right, what was confusing me was that console.log at the same place in the code was giving me the expected output
greg
@wearenotgroot
Aug 23 2016 03:35
@fogkio @jinjuujii use bracket notation when dealing with variable, function arguments and string with spaces between words
Anthony Drane
@Antiaccess
Aug 23 2016 03:35
Hey guys, I'm not sure I like the way I did this... it works but can anyone offer an alternative approach (for slashing off n number of items from the beginning of an array)
function slasher(arr, howMany) {
  // it doesn't always pay to be first
  if (howMany >= arr.length){
    return [];
  } else if (howMany === 0){
    return arr;
  }
  return arr.splice(howMany, arr.length-1);
}

slasher([1, 2, 3], 2);
slasher([1, 2, "chicken", 3, "potatoes", "cheese", 4], 5);
Joseph
@revisualize
Aug 23 2016 03:35
@jinjuujii What is the difference between this "Joseph" and name in var name = "Joseph";
Greg Duncan
@GregatGit
Aug 23 2016 03:35
@jaschart :+1:
jinjuujii
@jinjuujii
Aug 23 2016 03:36
joseph is a string and name is a variable
Joseph
@revisualize
Aug 23 2016 03:36
@jinjuujii "Joseph" is a string. name in var name = "Joseph"; is a variable that represents the value of "Joseph"
Jason Hartung
@jaschart
Aug 23 2016 03:37
@GregatGit thanks again
CamperBot
@camperbot
Aug 23 2016 03:37
jaschart sends brownie points to @gregatgit :sparkles: :thumbsup: :sparkles:
:warning: jaschart already gave gregatgit points
Joseph
@revisualize
Aug 23 2016 03:37
While doing a comparison to the two is true.
@jinjuujii You can't reference the value in the variable by doing "name"
jinjuujii
@jinjuujii
Aug 23 2016 03:37
but i'll recode my examples and use the bracket notation. I don't remember FCC examples explained the difference between represtation value vs absolute value. thank you @revisualize @wearenotgroot !!!
CamperBot
@camperbot
Aug 23 2016 03:37
jinjuujii sends brownie points to @revisualize and @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star2: 1699 | @revisualize |http://www.freecodecamp.com/revisualize
:star2: 1436 | @wearenotgroot |http://www.freecodecamp.com/wearenotgroot
Joseph
@revisualize
Aug 23 2016 03:38
@jinjuujii So, when you're doing collection.id.prop you're really doing collection["id"]["prop"] which are all strings.
greg
@wearenotgroot
Aug 23 2016 03:38
@jinjuujii :+1:
Joseph
@revisualize
Aug 23 2016 03:39
@jinjuujii You also need to understand that I'm answering the DIRECT question that you posted: :point_up: August 22, 2016 8:31 PM
@jinjuujii I'm not answering the question that you should have been asking.
LPR-309
@LPR-309
Aug 23 2016 03:40

@Antiaccess

  for (i = 0; i < howMany; i++) {
    arr.shift();
  }
  return arr;

I think this is the quickest way to do it

Joseph
@revisualize
Aug 23 2016 03:40
@jinjuujii :point_up: August 22, 2016 8:38 PM That answers the question that you should have been asking.
Anthony Drane
@Antiaccess
Aug 23 2016 03:40
oooh nice @LPR-309 I like it, thanks
CamperBot
@camperbot
Aug 23 2016 03:40
antiaccess sends brownie points to @lpr-309 :sparkles: :thumbsup: :sparkles:
:cookie: 290 | @lpr-309 |http://www.freecodecamp.com/lpr-309
Joseph
@revisualize
Aug 23 2016 03:40
@LPR-309 That is NOT the quickest way to solve that challenge.
Anthony Drane
@Antiaccess
Aug 23 2016 03:41
@revisualize what would you do?
jinjuujii
@jinjuujii
Aug 23 2016 03:41
@revisualize thanks again Joseph. I was too literal with my coding.
CamperBot
@camperbot
Aug 23 2016 03:41
jinjuujii sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:warning: jinjuujii already gave revisualize points
Joseph
@revisualize
Aug 23 2016 03:41

@Antiaccess

function slasher(arr, howMany) {
  // it doesn't always pay to be first
  return arr.slice(howMany);
}

or

const slasher = (a, h) => a.slice(h);
cc: @LPR-309 --^
Kantra
@removed~kantrakantra
Aug 23 2016 03:42
Can anybody help me figure out how to increase the char code of the elements in the str array?
function rot13(str) { 
  str = str.replace(/[^\w\s]/gi, '');
  if(str.charCodeAt(0) > 65 && str.charCodeAt(0) < 90) {
    str = str.split("");
    str = str.fromCharCode();
  }
  return str;

}


rot13("SERR PBQR PNZC");
Ngan Ngo
@KimmieWu
Aug 23 2016 03:43

thanks @wearenotgroot but i still got error with this
// Declarations
var StUdLyCapVaR;
var properCamelCase;
var TitleCaseOver;

// Assignments
studlyCapvar = 10;
properCamelCase = "A String";
titleCaseOver = 9000;

CamperBot
@camperbot
Aug 23 2016 03:43
kimmiewu sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star2: 1437 | @wearenotgroot |http://www.freecodecamp.com/wearenotgroot
Anthony Drane
@Antiaccess
Aug 23 2016 03:43
@revisualize good one, thanks!
CamperBot
@camperbot
Aug 23 2016 03:43
antiaccess sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 1700 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Aug 23 2016 03:43
@KimmieWu studlyCapvar is not proper camelCase
Ngan Ngo
@KimmieWu
Aug 23 2016 03:44
What is the correct. @revisualize ? thanks
CamperBot
@camperbot
Aug 23 2016 03:44
kimmiewu sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 1701 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Aug 23 2016 03:44
@KimmieWu studlyCapVar
the V
Ngan Ngo
@KimmieWu
Aug 23 2016 03:45
Thanks @revisualize
CamperBot
@camperbot
Aug 23 2016 03:45
kimmiewu sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:warning: kimmiewu already gave revisualize points
encount
@encount
Aug 23 2016 03:45
@kantrakantra fromCharCode needs to be String.fromCharCode - http://www.w3schools.com/jsref/jsref_fromcharcode.asp
Matt Reynolds
@mareynolds
Aug 23 2016 03:45

I'm getting this error:
SyntaxError: Invalid regular expression: /)/: unmatched ')'

whenever I run this line of code:

if (str.search(")") > 0) {

I can't figure out why it is giving that error. I want to check if a right parentheses is found and if so, run some code. Can anyone help?

Joseph
@revisualize
Aug 23 2016 03:46
@Antiaccess Do you understand how/why that code works for that challenge?
Anthony Drane
@Antiaccess
Aug 23 2016 03:46
@revisualize yes, because if you don't put a second parameter in, it will go from where you set it to the end of the array
@revisualize takes out all the busy work
Joseph B.
@barlanj
Aug 23 2016 03:47
@mareynolds you need to escape it try double slash before the parenthesis
@mareynolds backwards slash not forward
Kantra
@removed~kantrakantra
Aug 23 2016 03:48
@encount Ok that part doesn't cause an error anymore, how then do I go about actually increasing the value?
function rot13(str) { 
  str = str.replace(/[^\w\s]/gi, '');
  if(str.charCodeAt(0) > 65 && str.charCodeAt(0) < 90) {
    str = str.split("");
    String.fromCharCode(str + 13);
  }
  return str;

}


rot13("SERR PBQR PNZC");
Joseph B.
@barlanj
Aug 23 2016 03:48
@mareynolds you can also just use indexOf
Anthony Drane
@Antiaccess
Aug 23 2016 03:49
@revisualize I think my process is really inneffective, I usually take the long way to make something happen. That's why I come here afterwards, because I understand what the solution has to do, then I can grasp the shortcuts
greg
@wearenotgroot
Aug 23 2016 03:50
@kantrakantra shouldnt you be checking each character in that string? converting ?
encount
@encount
Aug 23 2016 03:51
@kantrakantra you need to loop through the string and check each char
oh! see @wearenotgroot :)
greg
@wearenotgroot
Aug 23 2016 03:51
@encount :+1:
Matt Reynolds
@mareynolds
Aug 23 2016 03:52

I got it working with this code:

 if (str.indexOf("\\)") > 0)

thanks @barlanj !

CamperBot
@camperbot
Aug 23 2016 03:52
mareynolds sends brownie points to @barlanj :sparkles: :thumbsup: :sparkles:
:cookie: 18 | @barlanj |http://www.freecodecamp.com/barlanj
greg
@wearenotgroot
Aug 23 2016 03:53
@kantrakantra you can either turn str into an array(using split) or just use brackets and indexing. Loop through each character, check the char code range and +/- some number depending on its position then convert
Pogg
@fogkio
Aug 23 2016 03:56
i read all challenge you give :clap:
@revisualize
Rony Vidaur
@RonyVidaur
Aug 23 2016 03:57
hey guys anyone else having issues building the random quote machine?
Raj
@RajKumar1605
Aug 23 2016 03:58
Hi everyone how are you doing today? Can you tell me what do you need to learn to make a 2d physics engine ?
Issac Tomatotan
@issactomatotan
Aug 23 2016 03:58
All only about Math things......
Rony Vidaur
@RonyVidaur
Aug 23 2016 03:59

i think is a codepen issue, this is the error that I get and it was working fine so far yesterday

Mixed Content: The page at 'https://codepen.io/RonyVidaur/pen/vKwLBJ' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://quotes.rest/qod.json'. This request has been blocked; the content must be served over HTTPS.

AnshulDawar
@anshuldawar
Aug 23 2016 04:09

CAn some tell me whats wrong with this one

function getIndexToIns(arr, num) {
// Find my place in this sorted array.
var ans;
if(arr.includes(num)){
ans = arr.indexOf(num);
return ans;
}
else{
arr.push(num);
arr.sort();
ans=arr.indexOf(num);
return ans;
}
}

getIndexToIns([40, 60], 50);

Faisal Zulfiqar
@faisal1337
Aug 23 2016 04:10
Does these two objects inside the array are giving weather of two different areas of the city?
"weather":  [ 
                    {
                        "id":711,
                        "main":"Smoke",
                        "description":"smoke",
                        "icon":"50d"
                    },
                    {
                        "id":701,
                          "main":"Mist",
                          "description":"mist",
                        "icon":"50d"
                    }
                ],
greg
@wearenotgroot
Aug 23 2016 04:12
@faisal1337 no the first item is the main weather
@faisal1337 the second one is some additional weather like mist or fog
Pogg
@fogkio
Aug 23 2016 04:12
@wearenotgroot
function lookUpProfile(firstName, prop){
// Only change code below this line
for(var i=0 ; i<contacts.length ; i++){
  if(contacts[i].hasOwnProperty(firstName)){
    return contacts[i].prop;
  }
  else if(contacts[i].hasOwnProperty(prop)){
    return "No such contact";
  }
  else{
    return "No such property";
  }
}
// Only change code above this line
}
did i forgot something?
Faisal Zulfiqar
@faisal1337
Aug 23 2016 04:13
@wearenotgroot thanks. The additional weather is not necessary to be displayed inside the project right?
CamperBot
@camperbot
Aug 23 2016 04:13
faisal1337 sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star2: 1438 | @wearenotgroot |http://www.freecodecamp.com/wearenotgroot
jinjuujii
@jinjuujii
Aug 23 2016 04:15

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

// Only change code below this line
function updateRecords(id, prop, value) { //prop = tracks or artists and value is song
if (prop !== "tracks" && value !== ""){
collection[id][prop] = value;
}

else if (prop === "tracks" && collection[id].hasOwnProperty("tracks") === false){
//collection[id][tracks]= [""];
collection[id].tracks = value;
}

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

else if ( value ===""){
delete collection[id][prop];
}
return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
updateRecords(5439, "tracks", "Take a Chance on Me");
updateRecords(1245, "tracks", "Addicted to Love");
updateRecords(5439, "tracks", "Take a Chance on Me");

``` how come it says collection[id].tracks.push(value) is not a function. shouldn't I be able to push the value onto the tracks array?

Jeremy
@jem243
Aug 23 2016 04:15
Hello... I'm puzzled here... I also had a similar problem that made the destroyer project not work. Here is my code and I know it works but I can't pass the test even though the window shows all the right answers.
jinjuujii
@jinjuujii
Aug 23 2016 04:15
// Setup
var collection = {
    "2548": {
      "album": "Slippery When Wet",
      "artist": "Bon Jovi",
      "tracks": [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    "2468": {
      "album": "1999",
      "artist": "Prince",
      "tracks": [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    "1245": {
      "artist": "Robert Palmer",
      "tracks": [ ]
    },
    "5439": {
      "album": "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
//var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) { //prop = tracks or artists and value is song
  if (prop !== "tracks" && value !== ""){
    collection[id][prop] = value;
  }

 else if (prop === "tracks" && collection[id].hasOwnProperty("tracks") === false){
    //collection[id][tracks]= [""];
    collection[id].tracks = value;
  }

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

  else if ( value ===""){
    delete collection[id][prop];
  } 
  return collection;
} 

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA"); 
updateRecords(5439, "tracks", "Take a Chance on Me");
updateRecords(1245, "tracks", "Addicted to Love");
updateRecords(5439, "tracks", "Take a Chance on Me");
Jeremy
@jem243
Aug 23 2016 04:15

//Jeremy This code works there is a bug in there system... all my test come out right.
function uniteUnique(arr) {
var newArr;

function addToArray(val) {
if(newArr === undefined){ //if my array is blank post array numbers into new array.
newArr = val;
} else {
//we need to run testing and post new values of the next array.
for(j = 0; j < val.length; j++) {//run a loop over all the new values.
if(checkSome(val[j])) {
//then it returns true and it already exhists in my new Array.
continue;
} else {
//it doesn't and we need to push it to the end of the array.
newArr.push(val[j]);
}
}
}
}

function checkSome(val2) {
return newArr.indexOf(val2) > -1;
}
//run thru all the arrays.
for (var i = 0; i < arr.length; i++) {
addToArray(arr[i]);
}

return newArr;
}

//a simple test of just running arr only returns [1,3,2];
//there is an error in the excercise similiar to destroyer excercise.
uniteUnique([[1, 2, 3], [5, 2, 1, 4], [2, 1], [6, 7, 8]]); //i have to add [] to get the whole amount

greg
@wearenotgroot
Aug 23 2016 04:15

@fogkio

if contact's firstName is equal to firstName
     if contact in ith index hasOwnProperty(prop)
                //return value from lookup (use bracket notation when dealing with variables and function arguments) ---> contacts[i][prop]
      else
             // return 'No such property'

the tricky one here is where to return 'No such contact', remember you need to look through the entire contacts array before you return 'No such contact' to be sure(let the loop finish)

jinjuujii
@jinjuujii
Aug 23 2016 04:15
how come it says collection[id].tracks.push(value) is not a function. shouldn't I be able to push the value onto the tracks array?
greg
@wearenotgroot
Aug 23 2016 04:16
@faisal1337 up to you :smile:
Jeremy
@jem243
Aug 23 2016 04:16
I realize I turned the parameters in the bottome into an array... but the ARR just by itself without it being an array doesn't show anything except [1,2,3] i.e. the first part of the parameters.
greg
@wearenotgroot
Aug 23 2016 04:19
@jinjuujii remember you need to test of 'tracks' property exist before pushing('tracks' property with value of an array)
Faisal Zulfiqar
@faisal1337
Aug 23 2016 04:21
Any good resources to get the icons?
arif hussain
@arifhussain0
Aug 23 2016 04:22
hello need to know what is regex for characters like _ or space or brackets??
need it for spinal tap case
greg
@wearenotgroot
Aug 23 2016 04:22
@faisal1337 if it is openweather api
-----http://openweathermap.org/weather-conditions
Ari Winokur
@ariwinokur
Aug 23 2016 04:23
I am also working on the Record Collection challenge
This is my code so far:
// Only change code below this line
function updateRecords(id, prop, value) {
  if ( prop != "tracks" && value !== "" ) {
    collection.id.prop = value;
  } else if ( prop == "tracks" && value !== "" ) {
    if (collection.id.tracks) {
      collection.id.tracks.push(value);
    } else {
      collection.id.tracks = value;
    }
  } else if ( value === "" ) {
    delete collection.id.prop;
  }


  return collection;
}
Still does not work, not sure why?
jinjuujii
@jinjuujii
Aug 23 2016 04:24
else if ( prop === "tracks" && value !== "" && collection[id].hasOwnProperty("tracks") === true){ collection[id].tracks.push(value);
i still have the error saying .....push() is not a function?
greg
@wearenotgroot
Aug 23 2016 04:24
@jinjuujii :+1:
AudioGen
@AudioGen
Aug 23 2016 04:25
I have a question
Ari Winokur
@ariwinokur
Aug 23 2016 04:25
Get this when I run tests: Cannot set property 'prop' of undefined
jinjuujii
@jinjuujii
Aug 23 2016 04:26
@ariwinokur LOL i just had the same problem
arif hussain
@arifhussain0
Aug 23 2016 04:26
@ariwinokur make !== in first if
jinjuujii
@jinjuujii
Aug 23 2016 04:26
they said that you must use [] to assess object properties instead of the .dot notation
greg
@wearenotgroot
Aug 23 2016 04:26
@ariwinokur remember when to use .(dot) and bracket notation
jinjuujii
@jinjuujii
Aug 23 2016 04:27
@wearenotgroot how come i still have an error saying that this is not a function?
greg
@wearenotgroot
Aug 23 2016 04:27
@ariwinokur dot vs brackets
jinjuujii
@jinjuujii
Aug 23 2016 04:27
collection[id].tracks.push(value)
AudioGen
@AudioGen
Aug 23 2016 04:27
function arrayToList(array) {
  var list = null;
  for (var i = array.length - 1; i >= 0; i--)
    list = {value: array[i], rest: list};
  return list;
}

console.log(arrayToList([1,2,3]));
Ari Winokur
@ariwinokur
Aug 23 2016 04:27
I think I'm a little confused about when it is best to use dot vs bracket notation
Anthony Drane
@Antiaccess
Aug 23 2016 04:27
can anyone confirm that solving some of the problems wrinkled their brain when they started, and no longer do?
AudioGen
@AudioGen
Aug 23 2016 04:27
How do I get that display using DOM
Faisal Zulfiqar
@faisal1337
Aug 23 2016 04:27
Why is this line giving me error?
var smoke = "<img src=\"" + "http://openweathermap.org/img/w/10d.png" + "\"" + ">";
Anthony Drane
@Antiaccess
Aug 23 2016 04:27
like, do you actually gain true fluency in coding?
AudioGen
@AudioGen
Aug 23 2016 04:28
it shows the objects on the console but it just shows [object Object] when I try to use it with name.innerHTML
@Antiaccess Some of them, but half of them I'm still stumped on :D
Some of the ones involving Math, I think it's just me being rusty at the math
Abhishek Baliyan
@abhishekdevinfo
Aug 23 2016 04:29
hi
Anthony Drane
@Antiaccess
Aug 23 2016 04:30
@AudioGen my brain can't quite wrap itself around the way some language elements are working in practice. I think it may be rustiness with computer logic, similar to you with math
AudioGen
@AudioGen
Aug 23 2016 04:31
yah the logic part I'm fairly decent at, with the way it works with javascript and code is it breaks it down to very bare components
is kind of the best way I can describe it
Abhishek Baliyan
@abhishekdevinfo
Aug 23 2016 04:31
is there any possibility that my function give me wrong output.
This function is to check even number and if the number is even then return true otherwise false without using %.
function isEven(check) {
    check = String(check);
    check = check[check.length - 1];
    if ((check == 0) || (check == 2) || (check == 4) || (check == 6) || (check == 8)) {
        return true;
    }
    else
        return false;
}
AudioGen
@AudioGen
Aug 23 2016 04:33
@Antiaccess for instance if you were to give a logical formula in a bit more verbose way with variable you might say If and only if a and b are true and b and c are true // outcome
as where with javascript it's like if(a && b && c){ // outcome}
Ari Winokur
@ariwinokur
Aug 23 2016 04:34
not quite sure when to use dots or brackets. can someone give me some examples of where to change that:
AudioGen
@AudioGen
Aug 23 2016 04:34
@ariwinokur yah
Ok the most notable time to use brackets is with arrays and you want to get the index so array1 gets the 2nd element in that array
greg
@wearenotgroot
Aug 23 2016 04:35
@jinjuujii if 'tracks' doesnt exist then create that property and set it's value to be an array then push whatever value is
AudioGen
@AudioGen
Aug 23 2016 04:35
array[1]
I didn't know it'd change it like that
Ari Winokur
@ariwinokur
Aug 23 2016 04:36
// Only change code below this line
function updateRecords(id, prop, value) {
  if ( prop != "tracks" && value !== "" ) {
    collection.id.prop = value;
  } else if ( prop == "tracks" && value !== "" ) {
    if (collection.id.tracks) {
      collection.id.tracks.push(value);
    } else {
      collection.id.tracks = value;
    }
  } else if ( value === "" ) {
    delete collection.id.prop;
  }


  return collection;
}
greg
@wearenotgroot
Aug 23 2016 04:36
@jinjuujii you can probably make use of a nested if else as your else if test are getting kinda long
Ari Winokur
@ariwinokur
Aug 23 2016 04:36
Can you show me an example here?
AudioGen
@AudioGen
Aug 23 2016 04:37
@ariwinokur you use dot notation when you are getting a precise property that can be a correct variable name. you use bracket notation for numbers and multiple word strings and when you want to evaluate a property
jinjuujii
@jinjuujii
Aug 23 2016 04:37
@wearenotgroot i did that with by coding. it should be able to read this as a function ... @ariwinokur this is my code for it and it works but i'm kinda stuck
Anthony Drane
@Antiaccess
Aug 23 2016 04:37
@AudioGen yeh, hmm i think it's a case of learning little nuances like that. What the language does, because I am a logical person, just don't get everything in the language and make assumptions about things which aren't always right (try to jump the gun). The problem I was just on involved using .indexOf and for a while my brain went dead trying to figure out which part should go before and after the .indexOf but I worked it out after a minute of reading. Then it wouldn't work, so I came here to ask about it YET when I just went back, I realised i missed making it case-sensitive - doh. Details man, details.
jinjuujii
@jinjuujii
Aug 23 2016 04:37
https://www.freecodecamp.com/challenges/record-collection#?solution=%0A%2F%2F%20Setup%0Avar%20collection%20%3D%20%7B%0A%20%20%20%20%222548%22%3A%20%7B%0A%20%20%20%20%20%20%22album%22%3A%20%22Slippery%20When%20Wet%22%2C%0A%20%20%20%20%20%20%22artist%22%3A%20%22Bon%20Jovi%22%2C%0A%20%20%20%20%20%20%22tracks%22%3A%20%5B%20%0A%20%20%20%20%20%20%20%20%22Let%20It%20Rock%22%2C%20%0A%20%20%20%20%20%20%20%20%22You%20Give%20Love%20a%20Bad%20Name%22%20%0A%20%20%20%20%20%20%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%222468%22%3A%20%7B%0A%20%20%20%20%20%20%22album%22%3A%20%221999%22%2C%0A%20%20%20%20%20%20%22artist%22%3A%20%22Prince%22%2C%0A%20%20%20%20%20%20%22tracks%22%3A%20%5B%20%0A%20%20%20%20%20%20%20%20%221999%22%2C%20%0A%20%20%20%20%20%20%20%20%22Little%20Red%20Corvette%22%20%0A%20%20%20%20%20%20%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%221245%22%3A%20%7B%0A%20%20%20%20%20%20%22artist%22%3A%20%22Robert%20Palmer%22%2C%0A%20%20%20%20%20%20%22tracks%22%3A%20%5B%20%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%225439%22%3A%20%7B%0A%20%20%20%20%20%20%22album%22%3A%20%22ABBA%20Gold%22%0A%20%20%20%20%7D%0A%7D%3B%0A%2F%2F%20Keep%20a%20copy%20of%20the%20collection%20for%20tests%0A%2F%2Fvar%20collectionCopy%20%3D%20JSON.parse(JSON.stringify(collection))%3B%0A%0A%2F%2F%20Only%20change%20code%20below%20this%20line%0Afunction%20updateRecords(id%2C%20prop%2C%20value)%20%7B%20%2F%2Fprop%20%3D%20tracks%20or%20artists%20and%20value%20is%20song%0A%20%20if%20(prop%20!%3D%3D%20%22tracks%22%20%26%26%20value%20!%3D%3D%20%22%22)%7B%0A%20%20%20%20collection%5Bid%5D%5Bprop%5D%20%3D%20value%3B%0A%20%20%7D%0A%20%20%0A%20else%20if%20(prop%20%3D%3D%3D%20%22tracks%22%20%26%26%20collection%5Bid%5D.hasOwnProperty(%22tracks%22)%20%3D%3D%3D%20false)%7B%0A%20%20%20%2F%2F%20collection%5Bid%5D.tracks%3D%20%5B%22%22%5D%3B%0A%20%20%20%20collection%5Bid%5D.tracks%20%3D%20value%3B%0A%20%20%7D%0A%20%20%0A%20%20else%20if%20(%20prop%20%3D%3D%3D%20%22tracks%22%20%26%26%20value%20!%3D%3D%20%22%22%20%26%26%20collection%5Bid%5D.hasOwnProperty(%22tracks%22)%20%3D%3D%3D%20true)%7B%0A%20%20%20%20collection%5Bid%5D.tracks.push(value)%3B%0A%20%20%7D%0A%20%20%0A%20%20else%20if%20(%20value%20%3D%3D%3D%22%22)%7B%0A%20%20%20%20delete%20collection%5Bid%5D%5Bprop%5D%3B%0A%20%20%7D%20%0A%20%20return%20collection%3B%0A%7D%20%0A%0A%2F%2F%20Alter%20values%20below%20to%20test%20your%20code%0AupdateRecords(5439%2C%20%22artist%22%2C%20%22ABBA%22)%3B%20%0AupdateRecords(5439%2C%20%22tracks%22%2C%20%22Take%20a%20Chance%20on%20Me%22)%3B%0AupdateRecords(1245%2C%20%22tracks%22%2C%20%22Addicted%20to%20Love%22)%3B%0AupdateRecords(5439%2C%20%22tracks%22%2C%20%22Take%20a%20Chance%20on%20Me%22)%3B%0A%0A
// Setup
var collection = {
    "2548": {
      "album": "Slippery When Wet",
      "artist": "Bon Jovi",
      "tracks": [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    "2468": {
      "album": "1999",
      "artist": "Prince",
      "tracks": [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    "1245": {
      "artist": "Robert Palmer",
      "tracks": [ ]
    },
    "5439": {
      "album": "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
//var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) { //prop = tracks or artists and value is song
  if (prop !== "tracks" && value !== ""){
    collection[id][prop] = value;
  }

 else if (prop === "tracks" && collection[id].hasOwnProperty("tracks") === false){
   // collection[id].tracks= [""];
    collection[id].tracks = value;
  }

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

  else if ( value ===""){
    delete collection[id][prop];
  } 
  return collection;
} 

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA"); 
updateRecords(5439, "tracks", "Take a Chance on Me");
updateRecords(1245, "tracks", "Addicted to Love");
updateRecords(5439, "tracks", "Take a Chance on Me");
Anthony Drane
@Antiaccess
Aug 23 2016 04:38
@AudioGen here's my solution if you want to see it
function mutation(arr) {
  var word = arr[1].toLowerCase().split('');
  arr[0] = arr[0].toLowerCase();
  var str = "h";
  for (var i = 0; i < word.length; i++){
    if (arr[0].indexOf(word[i]) < 0){
      console.log("hi " + arr[0].indexOf(word[i]));
      return false;
    }
  }
  return true;
}

mutation(["Hello", "helly"]);
(which works)
jinjuujii
@jinjuujii
Aug 23 2016 04:38
but this is saying that collection[id].tracks.push(value); is not a function when it shouldn't have execute with my else if bracket
greg
@wearenotgroot
Aug 23 2016 04:38
@jinjuujii that first else if should also test for value !== ''
Anthony Drane
@Antiaccess
Aug 23 2016 04:38
(checking if the second word's letters are all in the first word of the array)
Ari Winokur
@ariwinokur
Aug 23 2016 04:39
Seems like all the variables need to be in bracket notation
jinjuujii
@jinjuujii
Aug 23 2016 04:39
@ariwinokur yes. try it. you should be able to solve your problem
greg
@wearenotgroot
Aug 23 2016 04:39
@jinjuujii
else if (prop === "tracks" && collection[id].hasOwnProperty("tracks") === false){ //<--------should also test for value !== ''
   //need to create tracks property
   //set its value to be an array
   //push value
    collection[id].tracks = value;  
  }
AudioGen
@AudioGen
Aug 23 2016 04:40
@ariwinokur No, actually it's generally easier to use dot notation
Ari Winokur
@ariwinokur
Aug 23 2016 04:40
That solved all but one test
AudioGen
@AudioGen
Aug 23 2016 04:41
@ariwinokur it's practically mandatory when you do methods
Ari Winokur
@ariwinokur
Aug 23 2016 04:41
// Only change code below this line
function updateRecords(id, prop, value) {
  if ( prop != "tracks" && value !== "" ) {
    collection[id][prop] = value;
  } else if ( prop == "tracks" && value !== "" ) {
    if (collection[id].tracks) {
      collection[id].tracks.push(value);
    } else {
      collection[id].tracks = value;
    }
  } else if ( value === "" ) {
    delete collection[id][prop];
  }


  return collection;
}
jinjuujii
@jinjuujii
Aug 23 2016 04:41
@ariwinokur your code is so clean. kudos
mine is horrid
AudioGen
@AudioGen
Aug 23 2016 04:41
@Antiaccess Yah there are a lot of fine details to coding for sure
Ari Winokur
@ariwinokur
Aug 23 2016 04:41
Thanks @jinjuujii
CamperBot
@camperbot
Aug 23 2016 04:41
ariwinokur sends brownie points to @jinjuujii :sparkles: :thumbsup: :sparkles:
:cookie: 2 | @jinjuujii |http://www.freecodecamp.com/jinjuujii
greg
@wearenotgroot
Aug 23 2016 04:42
@jinjuujii did you figure it out?
AudioGen
@AudioGen
Aug 23 2016 04:42
@Antiaccess Good job on your code
DJ
@qualitymanifest
Aug 23 2016 04:42
@abhishekdevinfo why are you converting the number to a string? also you can do this without hardcoding numbers in an if
arif hussain
@arifhussain0
Aug 23 2016 04:43
hello need to know regex for spinal tap case exercise??
AudioGen
@AudioGen
Aug 23 2016 04:43
yah
@arifhussain0 yah
greg
@wearenotgroot
Aug 23 2016 04:44
@ariwinokur
if (collection[id].tracks) { //<-----use .hasOwnProperty instead
      collection[id].tracks.push(value);
    } else {
      //need to create tracks property
       //set its value to be an array
       //push value
      collection[id].tracks = value; //<-----need to change this
    }
jinjuujii
@jinjuujii
Aug 23 2016 04:45
@wearenotgroot i'm still trying to figure it out. been at this for 3 hours already. was wondering if my brain need to rest
arif hussain
@arifhussain0
Aug 23 2016 04:45
@AudioGen i am generally confused about how regex works. specially in spinal tap case where i have to filter all type of characters
AudioGen
@AudioGen
Aug 23 2016 04:46
@arifhussain0 yah if you are confused about it, you should probably skip that challenge and take some time to learn it, I can point you to a decent resource that's fairly straight forward about how it works
arif hussain
@arifhussain0
Aug 23 2016 04:47
@AudioGen please do that and guide me what regex should i use in this exercise ?
greg
@wearenotgroot
Aug 23 2016 04:47
@ariwinokur @jinjuujii since both of you are stuck on the same problem
function updateRecords(id, prop, value) {
  if (prop !== "tracks" && value !== ""){
    collection[id][prop] = value;
  }

 else if (prop === "tracks" && value !== ''){    //<----- @jinjuujii change your else if cause it getting kinda long
    if(collection[id].hasOwnProperty('tracks')) 
    {
       collection[id].tracks.push(value);

    }
    else
    {
       collection[id].tracks = [value]; //<-----if tracks is doesnt exist it will be created for you and set its value to be an array with an item that is value
    }
  }
  else if ( value ===""){
    delete collection[id][prop];
  } 
  return collection;
}
AudioGen
@AudioGen
Aug 23 2016 04:48
@arifhussain0 this is for Ruby I think but it works nearly identical for Javascript, except you can add a "g" modifier as well in javascript which does a global string search
Abhishek Baliyan
@abhishekdevinfo
Aug 23 2016 04:48
@qualitymanifest but i dont want to use %
jinjuujii
@jinjuujii
Aug 23 2016 04:48
i feel like my code is somewhat similiar but it's not running correctly :( do you mind editing it and point out what i did wrong?

``` function updateRecords(id, prop, value) { //prop = tracks or artists and value is song
if (prop !== "tracks" && value !== ""){
collection[id][prop] = value;
}

else if (prop === "tracks" && collection[id].hasOwnProperty("tracks") === false){
// collection[id].tracks= [""];
collection[id].tracks = value;
}

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

else if ( value ===""){
delete collection[id][prop];
}
return collection;
}
```

``` function updateRecords(id, prop, value) { //prop = tracks or artists and value is song
if (prop !== "tracks" && value !== ""){
collection[id][prop] = value;
}

else if (prop === "tracks" && collection[id].hasOwnProperty("tracks") === false){
// collection[id].tracks= [""];
collection[id].tracks = value;
}

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

else if ( value ===""){
delete collection[id][prop];
}
return collection;
}
```

AudioGen
@AudioGen
Aug 23 2016 04:49
@arifhussain0 the main regex to use is search and replace, I always do the literal versions as opposed to an object
greg
@wearenotgroot
Aug 23 2016 04:49
@jinjuujii :point_up: August 23, 2016 6:39 AM already pointed out the problem
Pogg
@fogkio
Aug 23 2016 04:50
im done :))
Ari Winokur
@ariwinokur
Aug 23 2016 04:50

This one line fixed my final issue:

collection[id].tracks = [value];

The brackets around value did it

AudioGen
@AudioGen
Aug 23 2016 04:50
string.replace(/text/g, "Newer Words");
Ari Winokur
@ariwinokur
Aug 23 2016 04:50
This is my final full code:
function updateRecords(id, prop, value) {
  if ( prop != "tracks" && value !== "" ) {
    collection[id][prop] = value;
  } else if ( prop == "tracks" && value !== "" ) {
    if (collection[id].tracks) {
      collection[id].tracks.push(value);
    } else {
      collection[id].tracks = [value];
    }
  } else if ( value === "" ) {
    delete collection[id][prop];
  }


  return collection;
}
arif hussain
@arifhussain0
Aug 23 2016 04:50
@AudioGen i was looking for object version because that would be more general and nice way of doing it
AudioGen
@AudioGen
Aug 23 2016 04:51
so say we have a string with the word or characters "text" in it.. That would do a global search on the whole string and if it finds it replaces it "Newer Words"
DJ
@qualitymanifest
Aug 23 2016 04:51
@abhishekdevinfo you don't have to. you just need to think: what can you do with an odd number that produces a different result than when you do the same thing to an even number?
Ari Winokur
@ariwinokur
Aug 23 2016 04:51
Thanks @wearenotgroot
CamperBot
@camperbot
Aug 23 2016 04:51
ariwinokur sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star2: 1439 | @wearenotgroot |http://www.freecodecamp.com/wearenotgroot
arif hussain
@arifhussain0
Aug 23 2016 04:51
@AudioGen i am familiar with literal use. I need help with objective use
LaurenCodes
@LaurenCodes
Aug 23 2016 04:51
Hello, I’m getting an error that says Unexpected token in JSON at position 3655804
Anyone know how to go to that location in sublime or textedit?
AudioGen
@AudioGen
Aug 23 2016 04:52
@arifhussain0 Oh I don't use that too much
I used the literal for the spinal case
Abhishek Baliyan
@abhishekdevinfo
Aug 23 2016 04:52
@qualitymanifest
function isEven(n) {
  if (n == 0)
    return true;
  else if (n == 1)
    return false;
  else if (n < 0)
    return isEven(-n);
  else
    return isEven(n - 2);
}
is this good
arif hussain
@arifhussain0
Aug 23 2016 04:54
@AudioGen well i can use that but i was looking for a better way of doing it which would be generic
AudioGen
@AudioGen
Aug 23 2016 04:55
@arifhussain0 I think "better" is all about preference really. Although I think most literals are generally regarded as better
arif hussain
@arifhussain0
Aug 23 2016 04:55
found it.. thanks @AudioGen
CamperBot
@camperbot
Aug 23 2016 04:55
arifhussain0 sends brownie points to @audiogen :sparkles: :thumbsup: :sparkles:
:cookie: 354 | @audiogen |http://www.freecodecamp.com/audiogen
AudioGen
@AudioGen
Aug 23 2016 04:55
but the object version is string.replace("text", "newer words");
Coy Sanders
@coymeetsworld
Aug 23 2016 04:56
@LaurenCodes the position is by character
DJ
@qualitymanifest
Aug 23 2016 04:57
@abhishekdevinfo not really. it works, if the number isn't big. if it is a big number you'll get a rangeError for exceeding the max call stack size. you don't need to use recursion
jinjuujii
@jinjuujii
Aug 23 2016 04:57
@wearenotgroot thank you for taking the time to answer my question.
CamperBot
@camperbot
Aug 23 2016 04:57
jinjuujii sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star2: 1440 | @wearenotgroot |http://www.freecodecamp.com/wearenotgroot
greg
@wearenotgroot
Aug 23 2016 04:58
@jinjuujii np
Abhishek Baliyan
@abhishekdevinfo
Aug 23 2016 04:58
@qualitymanifest ok
Thanks @qualitymanifest
CamperBot
@camperbot
Aug 23 2016 04:58
abhishekdevinfo sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star2: 1369 | @qualitymanifest |http://www.freecodecamp.com/qualitymanifest
AudioGen
@AudioGen
Aug 23 2016 04:58
@LaurenCodes is this your own program or is it on FCC?
Joseph
@revisualize
Aug 23 2016 04:59
@abhishekdevinfo What is that?
Abhishek Baliyan
@abhishekdevinfo
Aug 23 2016 04:59
@revisualize what?
Joseph
@revisualize
Aug 23 2016 05:00
@abhishekdevinfo That isEven function above.
What is that?
Are you trying to do that?
Markus Kiili
@Masd925
Aug 23 2016 05:00
@revisualize He must be pumping his recursive muscles?
Abhishek Baliyan
@abhishekdevinfo
Aug 23 2016 05:00
@revisualize yes
greg
@wearenotgroot
Aug 23 2016 05:00
@Masd925 lol
Joseph
@revisualize
Aug 23 2016 05:00
@abhishekdevinfo Is that a challenge?
@abhishekdevinfo What's the name of the challenge?
Abhishek Baliyan
@abhishekdevinfo
Aug 23 2016 05:01
yes from book
Joseph
@revisualize
Aug 23 2016 05:01
@abhishekdevinfo What book?
greg
@wearenotgroot
Aug 23 2016 05:01
@abhishekdevinfo usually the function name will indicate what it is going to do
isEven <-----
Abhishek Baliyan
@abhishekdevinfo
Aug 23 2016 05:01
Eloquent javascript
Joseph
@revisualize
Aug 23 2016 05:01
@abhishekdevinfo Because, if that is the code given to you by a book. I want to know what book not to buy.
function isEven (n) {
   return n % 2 === 0;
}
function isOdd (n) {
   return n % 2 === 1;
}
Abhishek Baliyan
@abhishekdevinfo
Aug 23 2016 05:03
@revisualize the task is make a funtion that find even number and return true without using %
DJ
@qualitymanifest
Aug 23 2016 05:03
@abhishekdevinfo if you perform a certain math operation on an odd number you won't get a whole number. but you will get a whole number if you perform the same operation on an even number
Abhishek Baliyan
@abhishekdevinfo
Aug 23 2016 05:04
@qualitymanifest ok
Joseph
@revisualize
Aug 23 2016 05:05
@abhishekdevinfo Oh, without using %
Abhishek Baliyan
@abhishekdevinfo
Aug 23 2016 05:05
@revisualize yes
Joseph
@revisualize
Aug 23 2016 05:06
function isEven (n) {
   return (n >= 1) ? n === 0 : isEven(n-1);
}
DJ
@qualitymanifest
Aug 23 2016 05:06
@revisualize you can accomplish that without recursion
Joseph
@revisualize
Aug 23 2016 05:06
@qualitymanifest Oh?
DJ
@qualitymanifest
Aug 23 2016 05:06
@revisualize check your PMs
Joseph
@revisualize
Aug 23 2016 05:07
Sure, recursion with that makes it STUPID inefficient.
Abhishek Baliyan
@abhishekdevinfo
Aug 23 2016 05:07
the speed of recursion in javascript is 10 times less than loop
AudioGen
@AudioGen
Aug 23 2016 05:08
@abhishekdevinfo Hi, I'm reading that book too
Joseph
@revisualize
Aug 23 2016 05:08
@abhishekdevinfo truth.
AudioGen
@AudioGen
Aug 23 2016 05:08
I think it's more like this
DJ
@qualitymanifest
Aug 23 2016 05:08
regardless you don't need recursion or a loop
Abhishek Baliyan
@abhishekdevinfo
Aug 23 2016 05:10
@qualitymanifest ok but i dont know how to do that
DJ
@qualitymanifest
Aug 23 2016 05:10
AudioGen
@AudioGen
Aug 23 2016 05:10
function isEven(n){
    if(n == 0){
   return true;
}
 else if(n == 1){
  return false;
}
else{
   return isEven(n - 2);
}
}

console.log(isEven(50));
Joseph
@revisualize
Aug 23 2016 05:11
@AudioGen That's also using recursion. That's not good.
greg
@wearenotgroot
Aug 23 2016 05:11
how about
function isEven(n) {
   n = n/2;
   return Number.isInteger(n);
}

isEven(1);
AudioGen
@AudioGen
Aug 23 2016 05:11
@revisualize The whole point of the exercise is to use recursion lol
Joseph
@revisualize
Aug 23 2016 05:11
@AudioGen OH!
function isEven (n) {
   return (n >= 1) ? n === 0 : isEven(n-1);
}
DONE!
Markus Kiili
@Masd925
Aug 23 2016 05:12
This doesn't use %:
function isEven (n) {
    return n/2 === n/2>>0;
}
AudioGen
@AudioGen
Aug 23 2016 05:12
@revisualize The book hasn't taught ternary operators up until that point
Joseph
@revisualize
Aug 23 2016 05:12
So use an if.
AudioGen
@AudioGen
Aug 23 2016 05:13
@revisualize Although I wouldn't have thought to the use the ternary operator anyways, so thanks for showing that off
CamperBot
@camperbot
Aug 23 2016 05:13
audiogen sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 1702 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Aug 23 2016 05:14
function isEven (n) {
   if (n >= 1) {
      return n === 0;
   }
   else {
      isEven(n-1);
   }
}
HA HA! That doesn't actually work.
AudioGen
@AudioGen
Aug 23 2016 05:15
Yah I was kind of puzzled there
Joseph
@revisualize
Aug 23 2016 05:15
That is junk!
Damn, I'm slipping.
AudioGen
@AudioGen
Aug 23 2016 05:16
:P
Joseph
@revisualize
Aug 23 2016 05:16
OH!
I have my symbol backwards!
LAME!
DJ
@qualitymanifest
Aug 23 2016 05:17
@Masd925 well if we're all sharing ours... yours is probably better than mine since you're using bitwise
function check(num) {
    return parseInt(num /2) === (num / 2)
}
AudioGen
@AudioGen
Aug 23 2016 05:17
damn I had some code from that same book
that I wanted to get some tips on how to use it on a DOM element
Joseph
@revisualize
Aug 23 2016 05:17
I kind of want to figure this out now.
AudioGen
@AudioGen
Aug 23 2016 05:17
but I don't want to sort it out all again
The easiest way is to use the remainder operator
but like that book from what I've gathered tries to make you understand the kind of nuts and bolts that go on for a lot of the methods and conditionals
Joseph
@revisualize
Aug 23 2016 05:19
I know that you need to do your isEven(n-1) or isEven(n-2)
I guess -2 would be faster.
AudioGen
@AudioGen
Aug 23 2016 05:19
make it more verbose so you can kind of understand the process rather than just memorize a bunch of methods names
Joseph
@revisualize
Aug 23 2016 05:19
So, -2 it is.
Let's see.
AudioGen
@AudioGen
Aug 23 2016 05:19
yah the challenge is isEven(n-2)
Joseph
@revisualize
Aug 23 2016 05:20
OR!
/2
half the problem.
Abhishek Baliyan
@abhishekdevinfo
Aug 23 2016 05:20
any suggestion what after this book
Joseph
@revisualize
Aug 23 2016 05:20
No that won't work.
swapnildaddikar
@swapnildaddikar
Aug 23 2016 05:20
anyone here can help me with getJSON FUNCTION ?
Joseph
@revisualize
Aug 23 2016 05:21
25 would become 12.5 then 6.25 then 3.125
MerrySaKi
@MerrySaKi
Aug 23 2016 05:24
question (205) how to do ?
Joseph
@revisualize
Aug 23 2016 05:24
@MerrySaKi Lessons don't have numbers.
about @revisualize
CamperBot
@camperbot
Aug 23 2016 05:24
:star2: 1702 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Aug 23 2016 05:24
I have not completed 1702 lessons.
eeflores
@eeflores
Aug 23 2016 05:24
function isEven(num) {
    return num & 1 ? false : true;
}

console.log(isEven(55));
console.log(isEven(12));
Joseph
@revisualize
Aug 23 2016 05:24
@eeflores That isn't using recursion.
eeflores
@eeflores
Aug 23 2016 05:25
oh recursion? ... ok
Joseph
@revisualize
Aug 23 2016 05:25
DONE!
function isEven (n) {
    if (n > 0) {
        return isEven(n-2);
    }
    else {
        return n === 0;
    }
}

isEven(10);
Markus Kiili
@Masd925
Aug 23 2016 05:26
@revisualize Doesn't work with negatives.
Joseph
@revisualize
Aug 23 2016 05:27
@Masd925 True.
But, I ain't got time for that :ship:
:v:
could always do |n|
What's that called in math?
Where you make a number + by doing |-6|
Math.abs()
Markus Kiili
@Masd925
Aug 23 2016 05:31
@eeflores Or the same like this:
function isEven(num) {
    return !(num&1);
}
swapnildaddikar
@swapnildaddikar
Aug 23 2016 05:31
LOL
eeflores
@eeflores
Aug 23 2016 05:31
math has abs but I can't seem to exercise enough
Joseph
@revisualize
Aug 23 2016 05:33
Also, Math.abs(n) creates an infinite loop for odd numbers
LOL!
someone help me with this pls
i dnt knw why this isnt working
Faisal Zulfiqar
@faisal1337
Aug 23 2016 05:37
http://codepen.io/faisal1337/pen/oLqZzE whenever I show the rain or the snow icon. They both come out of the row. Why is that? Rest icons work fine.
David van Zyl
@David-vz
Aug 23 2016 05:40

Hey guys. I'm having trouble with one of the javascript basic lessons. It's the one with checking if a JavaScript object has a property or not.

Is there a way to easily share the code here and ask for advice?

swapnildaddikar
@swapnildaddikar
Aug 23 2016 05:40
yes
encount
@encount
Aug 23 2016 05:41
@swapnildaddikar codepen does not allow it - XMLHttpRequest cannot load https://www.freecodecamp.com/json/cats.json. Origin http://s.codepen.io is not allowed by Access-Control-Allow-Origin.
swapnildaddikar
@swapnildaddikar
Aug 23 2016 05:41
where shud i test it?
@encount
Markus Kiili
@Masd925
Aug 23 2016 05:41
@David-vz You can copy paste the code here formatted
explain format
CamperBot
@camperbot
Aug 23 2016 05:41
no wiki entry for: format
Markus Kiili
@Masd925
Aug 23 2016 05:41
help format
CamperBot
@camperbot
Aug 23 2016 05:41
no wiki entry for: format
encount
@encount
Aug 23 2016 05:43
@swapnildaddikar set it up locally - that should work
swapnildaddikar
@swapnildaddikar
Aug 23 2016 05:43
thanks @encount
CamperBot
@camperbot
Aug 23 2016 05:43
swapnildaddikar sends brownie points to @encount :sparkles: :thumbsup: :sparkles:
:cookie: 341 | @encount |http://www.freecodecamp.com/encount
David van Zyl
@David-vz
Aug 23 2016 05:44

Its the "Testing Objects for Properties" lesson.

My attempted code:

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

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

// Test your code by modifying these values
checkObj("gift");

Just a bit stuck, I'm sure it's something small that I missed.

Markus Kiili
@Masd925
Aug 23 2016 05:46
@David-vz You need to use parens on .hasOwnProperty(...) <- this is a method call. You are using brackets [...] there.
David van Zyl
@David-vz
Aug 23 2016 05:48
Aaaah. So silly of me. thank you! Will check it now.

Method = ()
Object Property lookup = []

Much appreciated for your quick eye.

eeflores
@eeflores
Aug 23 2016 05:59
wiki format
CamperBot
@camperbot
Aug 23 2016 05:59
no wiki entry for: format
eeflores
@eeflores
Aug 23 2016 05:59
hmm?
kennyq94
@kennyq94
Aug 23 2016 06:02
hey guys do you know why my app takes a long time to load the temperature?
https://codepen.io/kennyqsoftware/full/yJXwyb/
Milan Tomcik
@Donwey
Aug 23 2016 06:13
but i need to make several of these with different data and id
how do i do that without making 5 copies of the same code and just changig var data and id
Faisal Zulfiqar
@faisal1337
Aug 23 2016 06:15
http://codepen.io/faisal1337/pen/oLqZzE someone help me with this please.
LaMar Towns
@LLamartowns
Aug 23 2016 06:21
is any body else stuck on the stand in line challenge?? i cant figure what is being asked here.. am i writing a function inside of another already existing function ??? maybe its been a long day but im stuck
Michiel
@MichielHuijse
Aug 23 2016 06:23
Hi I can't understand this sentence: If prop isn't "tracks" and value isn't empty (""), update or set the value for that record album's property.
LPR-309
@LPR-309
Aug 23 2016 06:29
@MichielHuijse If the property they're asking for exists (but isn't "tracks") and has a value, update or set that value for that property.
Suraj Prasad
@suraj18gts
Aug 23 2016 06:29
anyone knows about Golf Code??
Markus Kiili
@Masd925
Aug 23 2016 06:30
@MichielHuijse Is your problem on the first or last part of the sentence?
Michiel
@MichielHuijse
Aug 23 2016 06:30
@LPR-309 thanks
CamperBot
@camperbot
Aug 23 2016 06:30
michielhuijse sends brownie points to @lpr-309 :sparkles: :thumbsup: :sparkles:
:cookie: 291 | @lpr-309 |http://www.freecodecamp.com/lpr-309
Michiel
@MichielHuijse
Aug 23 2016 06:31
@Masd925 I think I get it now
@Masd925 thanks for the effort!
CamperBot
@camperbot
Aug 23 2016 06:31
michielhuijse sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2336 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Aug 23 2016 06:33
@suraj18gts Yes, what is the problem you have with it?
Suraj Prasad
@suraj18gts
Aug 23 2016 06:34

@Masd925
i have written this code....but it still shows the problem

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

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

Markus Kiili
@Masd925
Aug 23 2016 06:35
@suraj18gts You are not really testing the values of function parameters. if (strokes===1){...} would be a test.
Faisal Zulfiqar
@faisal1337
Aug 23 2016 06:37
http://codepen.io/faisal1337/pen/oLqZzE the rain and the snow icons flow out of the box while rest stay inside. Please help me with this.
Kantra
@removed~kantrakantra
Aug 23 2016 06:38
How does one go about changing the char code of elements in an array. For example within a loop such as this?
function rot13(str) { 
  str = str.replace(/[^\w\s]/gi, '');
  if(str.charCodeAt(0) > 65 && str.charCodeAt(0) < 90) {
    str = str.split("");
    for(var i = 0; i < str.length; i++) {


    }

  }
  return str;

}


rot13("SERR PBQR PNZC");
bhirmbani
@bhirmbani
Aug 23 2016 06:39
hi what are you try to achive
Markus Kiili
@Masd925
Aug 23 2016 06:40
@kantrakantra You could create an array of characters and then loop the elements. Check the charcode and map if necessary. Change back to character and assign back to the array.
@kantrakantra You can use for loop or an array iterator like .map().
Dan Couper
@DanCouper
Aug 23 2016 06:41
@kantrakantra map does this: takes an array and maps a function over every element in it
Kantra
@removed~kantrakantra
Aug 23 2016 06:43
How is .map different than just putting a function within a for loop
Markus Kiili
@Masd925
Aug 23 2016 06:45
@kantrakantra You can implement the logic yourselves, but a built-in method produces more compact code.
Mark Todd
@Knochenmark
Aug 23 2016 06:46
@kantrakantra map is more specific in this case
Kantra
@removed~kantrakantra
Aug 23 2016 06:47
@Knochenmark Can you elaborate? Is it simply more efficient coding?
Markus Kiili
@Masd925
Aug 23 2016 06:48
@kantrakantra By not using a built-in method for a specific task, you are inventing the wheel again.
Mark Todd
@Knochenmark
Aug 23 2016 06:49
@kantrakantra i mean you could use a shaving knife to butter your bread too, but maybe a butter knife is more specific for that purpose :D
Dan Couper
@DanCouper
Aug 23 2016 06:49
It's declarative, with a loop you are telling the computer how to do something, with map you are telling the computer to do something, you don't care how the computer does it
Kantra
@removed~kantrakantra
Aug 23 2016 06:51

@Knochenmark @DanCouper @Masd925 hah ok. thx.

How would one go about phrasing a change in the char code of an element within an array using .map or anything for that matter.

I've read the MDN on .fomCharCode() and I'm still slightly confused.

CamperBot
@camperbot
Aug 23 2016 06:51
kantrakantra sends brownie points to @knochenmark and @dancouper and @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2337 | @masd925 |http://www.freecodecamp.com/masd925
:cookie: 191 | @dancouper |http://www.freecodecamp.com/dancouper
:cookie: 441 | @knochenmark |http://www.freecodecamp.com/knochenmark
Kantra
@removed~kantrakantra
Aug 23 2016 06:52
I can't assign it directly to the array
Gerren Jackson
@gerrenjj
Aug 23 2016 06:52
hi everyone
This message was deleted
This message was deleted
Markus Kiili
@Masd925
Aug 23 2016 06:54
@kantrakantra With for loop you can assign the transformed character back to the array. With map, the method generates a new array with (possibly) transformed characters.
Gerren Jackson
@gerrenjj
Aug 23 2016 06:54
This message was deleted
This message was deleted
This message was deleted
This message was deleted
Kantra
@removed~kantrakantra
Aug 23 2016 06:59

@Masd925 Ok, I'm having a hard time understanding exactly how to phrase this within my code.

I guess what I'm getting at is how to actually use .fromCharCode()since I'm not able to assign it directly to something like str[0] within this for loop:

function rot13(str) { 
  str = str.replace(/[^\w\s]/gi, '');
  if(str.charCodeAt(0) > 65 && str.charCodeAt(0) < 90) {
    str = str.split("");
    for(var i = 0; i < str.length; i++) {
         str[0].fromCharCode(????);  // Here's where I'm fuzzy .map or loop

    }

  }
  return str;

}


rot13("SERR PBQR PNZC");
Gerren Jackson
@gerrenjj
Aug 23 2016 07:00

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

// Only change code below this line
mystorage.car.inside["glove box"];
var gloveBoxContents = "maps"; // Change this line

Dan Couper
@DanCouper
Aug 23 2016 07:00
@kantrakantra Maybe easiest way to understand: Write a very simple function that takes a single letter, and returns a modified version - eg function upcase(char) { return char.toUpperCase(); }. Then, you can use map to run this function for every element in an array - eg ['a','b','c'].map(upcase);
Gerren Jackson
@gerrenjj
Aug 23 2016 07:00
can anyone tell me whats wrong with my dot and bracket notation?
gloveBoxContents should equal "maps"
or why isnt it accessing myStorage?
Kantra
@removed~kantrakantra
Aug 23 2016 07:06
@DanCouper Ooooooh, I see. Wow that's cool.
Dan Couper
@DanCouper
Aug 23 2016 07:09
It's hard to get your head around at first - I remember looking at explanations in documentation and thinking they were gibberish, I'll try and dig out a good tutorial
Kantra
@removed~kantrakantra
Aug 23 2016 07:09

@DanCouper Ok now this seems like a dumb question and possibly redundant at this point but I can't seem to gather from the MDN exactly how to change the char code of an element using .fromCharCode()

Would it be something like

function charZard(poke) {
    return poke.fromCharCode(poke + 13);
  }

?

Dan Couper
@DanCouper
Aug 23 2016 07:12
Ah, right, this is a bit counterintuitive. You need to convert the letter to a character code first
Kantra
@removed~kantrakantra
Aug 23 2016 07:12
@DanCouper And then to call that function on str[0] like str[0].map(charZard)?
Gerren Jackson
@gerrenjj
Aug 23 2016 07:13
This message was deleted
Markus Kiili
@Masd925
Aug 23 2016 07:14
var str = "c";

String.fromCharCode(str.charCodeAt(0)+1); // d
Gerren Jackson
@gerrenjj
Aug 23 2016 07:15
Thanks guys
Kantra
@removed~kantrakantra
Aug 23 2016 07:15

@Masd925 OK. Here! exactly where I'm totally lost.

What is String and why are you using it?

Dan Couper
@DanCouper
Aug 23 2016 07:16
'a'.charCodeAt(0) in English is "take the string 'a' and give me the character code for the character at position 0". And 'hello'.charCodeAt(1) is saying take the string hello and give me the character code at position 1 (the letter e)
That's what I meant by slightly counterintuitive
Markus Kiili
@Masd925
Aug 23 2016 07:18
@kantrakantra String is a built-in constructor of strings. Some useful methods that are not string methods (properties of String.prototype and inherited to all strings) are stored as methods of that String object (they have to be stored somewhere to be able to use them).
Kantra
@removed~kantrakantra
Aug 23 2016 07:18

@DanCouper Ok that I understand.

So you're telling .fromCharCode() to add 1 to the first letter of the string str

Pogg
@fogkio
Aug 23 2016 07:18

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

// Only change code below this line
function updateRecords(id, prop, value) {
  if(prop !== "tracks" && value !== ""){
    collection[id][prop]=value;
  }
  else if(prop=="tracks" && value !== ""){
    if(collection[id].tracks){
      collection[id].tracks.push(value);
    }
    else{
      collection[id].tracks = [value];
    }
  }
  else if(value === ""){
    delete colletion[id][prop];
  }
  return collection;
}

// Alter values below to test your code
updateRecords(2548, "tracks", "");
anyone help me?
Error is Collection not defined?
Dan Couper
@DanCouper
Aug 23 2016 07:19
Convert to a character code, which gives you a number. Add/subtract from that number, then run the method String.fromCharCode(number) to get a new character. NOTE String.fromCharCode() is the function you use, written literally like that
Markus Kiili
@Masd925
Aug 23 2016 07:20
@fogkio What is colletion ;)
Pogg
@fogkio
Aug 23 2016 07:21
@Masd925 is my array :(
noo my obk
Kantra
@removed~kantrakantra
Aug 23 2016 07:21
@DanCouper How does this not affect all Strings in the code, if I'm understanding String is some sort of global representative for strings in general?
Michiel
@MichielHuijse
Aug 23 2016 07:21

For the album collection am I on the right track? I get an error: TypeError: Cannot read property 'id' of undefined.

function updateRecords(id, prop, value) {

if (collectionxamarin/xamarin-android@a16673d.id == id){ //checks if the id exists
if(collection1.artist == prop){ //checks if the property is artist
collection1.artist = "value"; // replaces the artist with the value
}

Pogg
@fogkio
Aug 23 2016 07:22
omg =))))))))
my mistake english
im done
Dan Couper
@DanCouper
Aug 23 2016 07:22
@kantrakantra soooo, var code = 'a'.charCodeAt(0); // this gives you the code for "a"
var newCcode = ccode + 1
Gerren Jackson
@gerrenjj
Aug 23 2016 07:23

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

// Only change code below this line
mystorage.car.inside["glove box"];
var gloveBoxContents = "maps"; // Change this line```
Anyone know how to correctly use dot and bracket notation to access myStorage?

Dan Couper
@DanCouper
Aug 23 2016 07:23
var newLetter = String.fromCharCode(newCcode); // this is now "b"
Pogg
@fogkio
Aug 23 2016 07:24
@gerrenjj you need use in one line
that question that solve mean?
:D
Gerren Jackson
@gerrenjj
Aug 23 2016 07:25
ok @fogkio thank you thats a start
CamperBot
@camperbot
Aug 23 2016 07:25
gerrenjj sends brownie points to @fogkio :sparkles: :thumbsup: :sparkles:
:cookie: 219 | @fogkio |http://www.freecodecamp.com/fogkio
swapnildaddikar
@swapnildaddikar
Aug 23 2016 07:25
XMLHttpRequest cannot load https://node-pranavacharya.rhcloud.com/products. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
guys does anyonme know this error
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
Muhammad Hasham
@MohammadHasham
Aug 23 2016 07:26

function diffArrays(arr1,arr2)
{
  var newArr = arr1.concat(arr2);
  return newArr.filter(function(array,index,value){

    if (array.slice(index+1).indexOf(value)==-1 && array.slice(0,index).indexOf(value))
      {
        return value;
      }

  });
}
function seperateDupees(arr)
{
  var result = [];
  arr.forEach(function(value){
    if (result.indexOf(value) > 0)
      {
        result.push(value);
      }

  });
}



function sym(args) {
  args.reduce(function(a,b){

    a = seperateDupees(args);
    b = seperateDupees(args);
    a = diffArrays(a,b);
    return a;

  });

}

sym([1, 2, 3], [5, 2, 1, 4]);
What is wrong witch concat it gives an error there
Kantra
@removed~kantrakantra
Aug 23 2016 07:31
@DanCouper Ok, thank you for being so patient with me. It's been extremely helpful. I've attempted to try making it work with .map but I'm still hitting a slight wall
function rot13(str) { 
  function charZard(poke) {
    return poke.fromCharCode(str.charCodeAt[0] + 13);
  }
  str = str.replace(/[^\w\s]/gi, '');
  if(str.charCodeAt(0) > 65 && str.charCodeAt(0) < 90) {
    str = str.split("");

    str.map(charZard);



  }
  return str;

}


rot13("SERR PBQR PNZC");
CamperBot
@camperbot
Aug 23 2016 07:31
kantrakantra sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:warning: kantrakantra already gave dancouper points
Dan Couper
@DanCouper
Aug 23 2016 07:36
@kantrakantra ah, ok, just need to switch things around a little bit. There's another different issue you'll hit after that, but I'll get that in a sec
This message was deleted
And move the if into the charZard function - like
function charZard(poke) {
  if(str.charCodeAt(0) > 65 && str.charCodeAt(0) < 90) {
    return poke.fromCharCode(str.charCodeAt[0] + 13);
  } else {
    return poke;
  }
}
So what you’re doing is taking a character. If it’s one that you want, convert it. If not, just leave it as-is
Then
Dan Couper
@DanCouper
Aug 23 2016 07:41
you want to take str, split it, then map the split string, so just do what’s already there
function rot13(str) { 
  str = str.replace(/[^\w\s]/gi, '');
  str = str.split("");
  str.map(charZard);
  return str;
}
There’s still an issue, which should become apparent when you try to run the tests
r2d2
@UsamaHameed
Aug 23 2016 07:43
So I have heard JS uses the prototypal inheritance. But I have seen the class word many times in JS codes. Does JS support both?
Dan Couper
@DanCouper
Aug 23 2016 07:44
You can make prototypical inheritence work in a similar way to classical inheritence
r2d2