These are chat archives for FreeCodeCamp/HelpJavaScript

13th
Jun 2016
Greg Duncan
@GregatGit
Jun 13 2016 00:02
@apbowe do you have another else after the else if? You should never finish on else if but on else with no condition
Alan Saber
@Alan95
Jun 13 2016 00:07
help Mutations
CamperBot
@camperbot
Jun 13 2016 00:07

:point_right: algorithm mutations [wiki]

Algorithm Mutations

Problem Explanation:

  • Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array..
:pencil: read more about algorithm mutations on the FCC Wiki
Jasmine Marie Bouges
@jbouges
Jun 13 2016 00:19
hey so i'm working on a matching game in coursera and i'm having issues with getting my images to add upon each other (like have the next round of images be 5 more than the last round) and still reset their positions on the next level.
rfrancisG
@rfrancisG
Jun 13 2016 00:36
Hi so I still don't understand the word blanks challenge. Do I need to make my own sentence, I still don't know what to do. O think I need to see an example. And I'm having trouble reading the chat room comments because green posts keep popping up and getting in the way of the comments. I think I just need an example of what the finished "wordblanks" code is supposed to look like.
Anne Kuhnen
@annegivings
Jun 13 2016 00:37
Quick question (hopefully) about using switch statements! I set each statement up like the example so it says "case 1: return "alpha"; break;" etc for four cases. It all works fine but there are the little yellow caution buttons beside the break lines that read "Unreachable 'break' after 'return'. Can anyone help me figure out what this means or if there is some other better way of writing this that will not give me caution signs? Or are caution signs okay?
Norvin Burrus
@ndburrus
Jun 13 2016 00:37
@rfrancisG would you like to walk through the exercise to completion?
rfrancisG
@rfrancisG
Jun 13 2016 00:37
Okay ya sure
Jose Suarez
@Josexv1
Jun 13 2016 00:38
Hi guys.
Norvin Burrus
@ndburrus
Jun 13 2016 00:38
@rfrancisG ok, have we created the sentence (madlib) that we'd like to build (complete with filler words to enure the grammar is correct)?
Jose Suarez
@Josexv1
Jun 13 2016 00:38
What do you think about this algoritm
function confirmEnding(str, target) {
  var x = target.length;
  var z = str.slice(-x);
  if (z == target){
    return true;
  }else{
   return false; 
  }
}
confirmEnding("He has to give me a new name", "n");
There is another aproach to solve this? what do you think.
Norvin Burrus
@ndburrus
Jun 13 2016 00:39
@annegivings are you working on this challenge - Selecting from many options with Switch Statements? ... there shouldn't be any returnd within the switch statement.. :)
Anne Kuhnen
@annegivings
Jun 13 2016 00:40
Yes!
rfrancisG
@rfrancisG
Jun 13 2016 00:40
So I take it I need to make my own sentence using the words provided. Do I need to make two sentences, because there is on thing about the dog and one about a cat.
Norvin Burrus
@ndburrus
Jun 13 2016 00:41
@rfrancisG good question - can we make one sentence using both (or actually all four) of the words needed? :+1:
Anne Kuhnen
@annegivings
Jun 13 2016 00:42
When I take out the return statements it gives me bigger errors and does not work-- there are four "errors" listed
Actually jk there is just one but it is red and does not work--
Norvin Burrus
@ndburrus
Jun 13 2016 00:43
@annegivings alright... is it possible for you to post your code? that might be easier (& faster)
Anne Kuhnen
@annegivings
Jun 13 2016 00:43
it reads "expected an assignment or function call and instead saw an expression"
Ermmm if I copy paste will it show up properly here?
Norvin Burrus
@ndburrus
Jun 13 2016 00:44
help format @annegivings
CamperBot
@camperbot
Jun 13 2016 00:44

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

This an inline `<paste code here>` code formatting with a single backtick() at _start_ and _end_ around thecode`.

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

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

rfrancisG
@rfrancisG
Jun 13 2016 00:44
There appears to be a total of eight words "dog" "big" "ran" "quickly" and "cat" "little" "hit" "slowly"
Norvin Burrus
@ndburrus
Jun 13 2016 00:44
@rfrancisG super... can you form the words into a complete sentence, please? also, the exercise only requests that four word types be used. you can use however many you like, though...
Anne Kuhnen
@annegivings
Jun 13 2016 00:46
function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch(val){
    case 1:
      "alpha";
      break;
    case 2:
      "beta";
      break;
    case 3:
      "gamma";
      break;
    case 4: 
      "delta";
      break;

  }


  // Only change code above this line  
  return answer;  
}
Norvin Burrus
@ndburrus
Jun 13 2016 00:46
@annegivings ok, now, what are we doing with the string values for each case? they are just sitting there with nothing to do - or more importantly, the code does nothing with them...
Anne Kuhnen
@annegivings
Jun 13 2016 00:47
I assume plugging them in as the answer; do I need to set the variable with that expression for each case?
oh my gosh it all makes sense now actually
Norvin Burrus
@ndburrus
Jun 13 2016 00:48
@annegivings :sparkles:
Anne Kuhnen
@annegivings
Jun 13 2016 00:48
Thanks @ndburrus for your help!
CamperBot
@camperbot
Jun 13 2016 00:48
annegivings sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:cookie: 533 | @ndburrus |http://www.freecodecamp.com/ndburrus
Norvin Burrus
@ndburrus
Jun 13 2016 00:48
@annegivings you are on fire! :fire: great work!!
@rfrancisG how are we doing?
rfrancisG
@rfrancisG
Jun 13 2016 00:54
Ok so I don't understand the instructions, I don't see where they specify that we only have to use one of the two sentences, but since we have to make our own sentence I don't know how to format that in code.
Norvin Burrus
@ndburrus
Jun 13 2016 00:58
@rfrancisG ...hmmm... let me take a look, i know some of the exercises have changed... ok, we only need the four variables: myNoun, myAdjective, myVerb, and myAdverb.there may be confuion because of the text referencing the multiple tests/cases. see that? :) here: You will need to use string operators to build a new string, result, using the provided variables: myNoun, myAdjective, myVerb, and myAdverb. the "additional strings" are the filler words we talked about earlier - to ensure a complete sentence. :)
powell956
@powell956
Jun 13 2016 00:58
@ndburrus yea, i don't even kno
thanks for the helpful links! i'll let you know if they facilitate a breakthrough, haha
for now i'm going to work through the previous few exercises to see if that jogs anything loose in my brain
CamperBot
@camperbot
Jun 13 2016 00:58
powell956 sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:cookie: 534 | @ndburrus |http://www.freecodecamp.com/ndburrus
Norvin Burrus
@ndburrus
Jun 13 2016 00:59
@powell956 you're welcome... :sparkles: as a refresher, what were we working on?
Jasmine Marie Bouges
@jbouges
Jun 13 2016 01:02
hey could someone help me with something? i'm kind of at a dead end and i don't know what to do.
Jose Suarez
@Josexv1
Jun 13 2016 01:07
Guys how can this be done, my code needs to truncate a string given a number of chars. But i have this: truncateString("Peter Piper picked a peck of pickled peppers", 14) should return "Peter Piper...".
if i truncate 14 chars of that string it doesnt match
rfrancisG
@rfrancisG
Jun 13 2016 01:08
So I'm afraid I still don't understand, how do I format this sentence with string opperators? Is there a clear example I could see?
Coy Sanders
@coymeetsworld
Jun 13 2016 01:08
you don't truncate 14 characters of that string @Josexv1
you have to count the ellipsis as part of the count and there's 3
Alan Saber
@Alan95
Jun 13 2016 01:10
help falsy bouncer
CamperBot
@camperbot
Jun 13 2016 01:10

:point_right: algorithm falsy bouncer [wiki]

Algorithm Factorialize A Number

Problem Explanation:

Remove all falsy values from an array.

:pencil: read more about algorithm falsy bouncer on the FCC Wiki

Jose Suarez
@Josexv1
Jun 13 2016 01:13
This message was deleted
Oh ok.
rfrancisG
@rfrancisG
Jun 13 2016 01:14
Does anyone understand the "Word Blanks" challenge.
Coy Sanders
@coymeetsworld
Jun 13 2016 01:16
yes @rfrancisG what's up?
rfrancisG
@rfrancisG
Jun 13 2016 01:21
I think I need to see a clear example of a finished peace of code that would pass the challenge. The instructions are just not specific enough for me to figure out how to do the word blanks challenge.
I think theres something wrong with my laptop.
Coy Sanders
@coymeetsworld
Jun 13 2016 01:21
try looking back at some of the challenges you passed earlier to know what to do
like Concatenating Strings with the Plus Operator
rfrancisG
@rfrancisG
Jun 13 2016 01:22
I've tried that I still can't figure it out.
Coy Sanders
@coymeetsworld
Jun 13 2016 01:22
what do you have so far?
Jose Suarez
@Josexv1
Jun 13 2016 01:24
@rfrancisG just use str += str += str, concat everything.
Coy Sanders
@coymeetsworld
Jun 13 2016 01:25
@Josexv1 you can't string += together like that
Ari
@arilaverty
Jun 13 2016 01:26
would someone mind sharing their "Record Collection" code, I've been stumped on it for 2 days now, I know what I need to do, just unsure what to use or how to use it.
Jose Suarez
@Josexv1
Jun 13 2016 01:26
That was what i did.
About the record collection, to add an array remember to use collection[i]= [prop]
CamperBot
@camperbot
Jun 13 2016 01:27
you need to ask about @someone!
Coy Sanders
@coymeetsworld
Jun 13 2016 01:28
hmm i guess you can, just not sure why when a + will do just fine
Jose Suarez
@Josexv1
Jun 13 2016 01:28
Btw to build and concatenate them using the + and += string operators
Ari
@arilaverty
Jun 13 2016 01:28
@Josexv1 The array is already declared, so to check to see if a property and value already exist woud this be the correct way to do it:
Coy Sanders
@coymeetsworld
Jun 13 2016 01:28
+= will assign all your previous strings to something different I believe
Jose Suarez
@Josexv1
Jun 13 2016 01:29
str.hasOwnProperty
Coy Sanders
@coymeetsworld
Jun 13 2016 01:29
which doesn't matter for this challenge since you just care about result
Ari
@arilaverty
Jun 13 2016 01:29
function updateRecords(id, prop, value) {

    if (collection[id][prop][value] !== "") {
        if (collection[id][prop] !== "tracks") {
            collection[id][prop] = (value);
        }
    }
Coy Sanders
@coymeetsworld
Jun 13 2016 01:29
but if you need to use those variables another time they will get modified
Jose Suarez
@Josexv1
Jun 13 2016 01:29
Yes, i think i used it back then but it clearly can be better as you say.
collection[id].xxxxx = [value];
Coy Sanders
@coymeetsworld
Jun 13 2016 01:30
@himynameisari you need a different way to check if properties exist in your objects
theres also more code you need than that
Jose Suarez
@Josexv1
Jun 13 2016 01:31
This is what i did if (prop === "tracks" && value !== "") { collection[id].tracks = [value];
Coy Sanders
@coymeetsworld
Jun 13 2016 01:31
I don't see that
Ari
@arilaverty
Jun 13 2016 01:32
aaah ok, seems like theres 1000 ways you can go about the same problem, this helps
Jose Suarez
@Josexv1
Jun 13 2016 01:32
You just need to check if the prop is tracks
Coy Sanders
@coymeetsworld
Jun 13 2016 01:32
I don't think there's many different ways
Jose Suarez
@Josexv1
Jun 13 2016 01:32
Then if it is tracks add the array.
Maybe there's diferent ways to do it, but the logic is stated in the description of the challenge.
Ari
@arilaverty
Jun 13 2016 01:33
I didnt realise i could just check (prop), i thought I had to go collection[id][prop] etc
thanks
Jose Suarez
@Josexv1
Jun 13 2016 01:34
np :+1:
rfrancisG
@rfrancisG
Jun 13 2016 01:35
I've tried the + operator I have no idea how to do the word blanks challenge. I think I just need to see a finished example, there is no other way around it. I just wont be able to do the word blanks challenge until I see a finshed example or someone explains to me how to do it in person.
Jose Suarez
@Josexv1
Jun 13 2016 01:37
Show me what you have @rfrancisG
archan6le
@archan6le
Jun 13 2016 01:39
hey guys.. any idea whats wrong with my code?
function lookUpProfile(firstName, prop){
// Only change code below this line
if(contacts.hasOwnProperty('firstName')){
  if(contacts.hasOwnProperty('prop')){
    return contacts.firstName.prop;
  }else if(firstName !== contacts.firstName){
   return "No such contact"; 
  }else if(prop !== contacts.prop){
    return "No such property";
  }
}
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
Jose Suarez
@Josexv1
Jun 13 2016 01:40
You are not checking the profile.
Domingo Moronta
@dj-m
Jun 13 2016 01:40
@archan6le What helped me is to think about what happens when the program encounters a ‘return'
Jose Suarez
@Josexv1
Jun 13 2016 01:41
You check contacts.hasOwnProperty() but dont tell the program in which profile lookup
Domingo Moronta
@dj-m
Jun 13 2016 01:41
So, whenever a program encouters a return, it stops running and kicks out, meaning anything else in that property won’t be looked at or evaluated
Jose Suarez
@Josexv1
Jun 13 2016 01:43
You should look the profile with a loop, and then contacts[index].hasOwnProperties(prop)
Jonathan Carroll
@gkcodeman
Jun 13 2016 01:44
wow didn't think i would get stuck on basically the first problem but for some reason I'm assigning a to b with the assignment operator = but the code isn't passing
munkiuke
@munkiuke
Jun 13 2016 01:45
im having an issue .. it tells me that im using an if statment or a switch altho i don't think that i am here is the screenshot
blob
Norvin Burrus
@ndburrus
Jun 13 2016 01:45
@rfrancisG these may be useful: Strings & High-performance String Concatenation in JavaScript :)
Domingo Moronta
@dj-m
Jun 13 2016 01:45
@munkiuke you can post the code using the [code] annotation
I mean ```
munkiuke
@munkiuke
Jun 13 2016 01:46
really ? let me try
Jose Suarez
@Josexv1
Jun 13 2016 01:46
Asociate the result variable
Tim Crockett
@BoboMunkee
Jun 13 2016 01:46
@archan6le To go with what Jose said, you can't use dot notation with prop because prop is a variable, you have to use bracket notation.
Jose Suarez
@Josexv1
Jun 13 2016 01:48
result = lookup[val]
return result;
Jonathan Carroll
@gkcodeman
Jun 13 2016 01:49
// Setup
var a;
var b = 2;

// Only change code below this line

var a = 7;
var b = 7;
a=b;
Norvin Burrus
@ndburrus
Jun 13 2016 01:49
@munkiuke ok, the keys (in the left column) should be strings, see that? also, we should adhere to the comment // Only change code above this line so, this need to be changed (to the original return result;) finally, the "lookup" object should be used to reference the desired result value... :)
Jonathan Carroll
@gkcodeman
Jun 13 2016 01:49
is this not what it is asking for?
guess i didn't need to rewrite var but you get the idea
munkiuke
@munkiuke
Jun 13 2016 01:50
`what jose suarez wrote worked.
Domingo Moronta
@dj-m
Jun 13 2016 01:50
@gkcodeman I think you can reassign b to the value of a without making them equal each other
munkiuke
@munkiuke
Jun 13 2016 01:50
let me try making them strings tho sec.
Domingo Moronta
@dj-m
Jun 13 2016 01:50
ex: var a = 7; var b = a
munkiuke
@munkiuke
Jun 13 2016 01:51
making them strings works aswell. but the issue was that they said to chhange the code above . so i shouldn't have used what jose wrote, i think it's a bug in that case.
Jonathan Carroll
@gkcodeman
Jun 13 2016 01:51
@dj-m thanks it accepted it when I switch the a and b around
CamperBot
@camperbot
Jun 13 2016 01:51
gkcodeman sends brownie points to @dj-m :sparkles: :thumbsup: :sparkles:
:cookie: 237 | @dj-m |http://www.freecodecamp.com/dj-m
Jonathan Carroll
@gkcodeman
Jun 13 2016 01:52
// Setup
var a;
var b = 2;

// Only change code below this line

var a = 7;
var b = 7;
var b=a;
is what it wanted
Jose Suarez
@Josexv1
Jun 13 2016 01:52
But you are doing nothing if a, and b. worth the same.
Jonathan Carroll
@gkcodeman
Jun 13 2016 01:52
ikr
i don't understand why it is accepting it either, its like there is a bug with this one
Domingo Moronta
@dj-m
Jun 13 2016 01:53
@gkcodeman I think they want you to assign the contents of one variable to another, not just to make them equal the same thing
Jonathan Carroll
@gkcodeman
Jun 13 2016 01:53

@Josexv1 it asks me to Assign the value 7 to variable a.

Assign the contents of a to variable b.

Jose Suarez
@Josexv1
Jun 13 2016 01:53
var a = 3
var b = 7
a = b;
console.log(a) //will return that a worth no more 3, now it worth 7
Domingo Moronta
@dj-m
Jun 13 2016 01:54
@gkcodeman right… so you see how var is assigned the value of 7? Now to assign var b the value of a, you’d do a similar thing
@gkcodeman So your third line of code is correct, just the second one is unnecessary
Norvin Burrus
@ndburrus
Jun 13 2016 01:55
@gkcodeman how are assignments handled is js?
Jonathan Carroll
@gkcodeman
Jun 13 2016 01:56
@dj-m i ugh..i'm being dumb. lol i shouldn't have been trying to rush this one with kids runnin all around me. I didn't even read the instructions, was only reading the check offs at the bottom and putting in wrong setup
Jose Suarez
@Josexv1
Jun 13 2016 01:56
Dont worry bro, just keep calm and ask for help.
i'm here mostly asking for help lol
Jonathan Carroll
@gkcodeman
Jun 13 2016 01:57
@dj-m @ndburrus @Josexv1 thanks all ill be back once i get them to bed and i can concentrate
CamperBot
@camperbot
Jun 13 2016 01:57
gkcodeman sends brownie points to @dj-m and @ndburrus and @josexv1 :sparkles: :thumbsup: :sparkles:
:warning: gkcodeman already gave dj-m points
:cookie: 536 | @ndburrus |http://www.freecodecamp.com/ndburrus
:cookie: 261 | @josexv1 |http://www.freecodecamp.com/josexv1
Domingo Moronta
@dj-m
Jun 13 2016 01:57
@gkcodeman that’s what we’re here for...
@ndburrus yo, you got mad brownie points!
Norvin Burrus
@ndburrus
Jun 13 2016 01:58
@gkcodeman ...just a little distraction.... builds character, so i've heard... nice focus... :+1: i'm a true noob... making a little progress, though...
Domingo Moronta
@dj-m
Jun 13 2016 02:00
@ndburrus :pray: teach me your ways...
Norvin Burrus
@ndburrus
Jun 13 2016 02:02
@dj-m i really need to read more & more... that's my goal at the moment. js programmer's reference is the book i'm reading now... i think it's pretty good (being to new to programming)...
Subh Samal
@subhsamal
Jun 13 2016 02:12
I have a doubt regarding charCodeAt(), How ' return str.charCodeAt(str.length-1) ' is able to return asci value of last char of the string?
charCodeAt() returns NaN if the given index is less than 0 or is equal to or greater than the length of the string.
Norvin Burrus
@ndburrus
Jun 13 2016 02:16
@subhsamal JavaScript String charCodeAt() Method, Definition and Usage Tip: You can use the charCodeAt() method together with the length property to return the Unicode of the last character in a string. The index of the last character is -1, the second last character is -2, and so on (See Example below).
Jose Suarez
@Josexv1
Jun 13 2016 02:16
Btw, i think just str.charCodeAt(str.length) will return the last char of that str.
Coy Sanders
@coymeetsworld
Jun 13 2016 02:17
nope, its str.length-1
first character starts at index 0
since it starts at 0 to get the last character you need to subtract one from the length
Subh Samal
@subhsamal
Jun 13 2016 02:19
@Josexv1 I expected the same :smile: but it's not!!
ChloeHewitt
@ChloeHewitt
Jun 13 2016 02:20
does anyone remember doing Testing Objects for Properties challenge
Jose Suarez
@Josexv1
Jun 13 2016 02:21
var str = "Hola";
str.charCodeAt(str.length-1);
//ASCII  97 = a;
Subh Samal
@subhsamal
Jun 13 2016 02:21
@ndburrus Hey.. if for this string length is 14 ("SERR PBQR PNZC"); then charCodeAt(string.length-1) i:e charCodeAt(13) is 67.. isn't it weird??
Tim Crockett
@BoboMunkee
Jun 13 2016 02:22
@ChloeHewitt I do, I just did it tonight.
Subh Samal
@subhsamal
Jun 13 2016 02:22
@Josexv1 so you must be getting 97.
Jose Suarez
@Josexv1
Jun 13 2016 02:22
67 = C
ChloeHewitt
@ChloeHewitt
Jun 13 2016 02:22
ahh @BoboMunkee would you mind explaining it? My first day back on here in a while and im so lost
Jose Suarez
@Josexv1
Jun 13 2016 02:22
This message was deleted
It's good then. It works with -1
Check out the table for yourself: http://ascii.cl/
Subh Samal
@subhsamal
Jun 13 2016 02:24
yeah.. But I am trying to understand the length-1 part.
Norvin Burrus
@ndburrus
Jun 13 2016 02:24
@subhsamal why would it be wierd? actually, it's 68, isn't it? tested it here: Try It w3schools
Jose Suarez
@Josexv1
Jun 13 2016 02:25
length - 1, is from the very begining.
Tim Crockett
@BoboMunkee
Jun 13 2016 02:26
@ChloeHewitt I can try, what's throwing you exactly?
@subhsamal It has to do with the way length and indices are used. The String "Hello" has a length of 5, but the char indices run from 0 through 4. To get the last char you have to subtract 1 from the length.
Jose Suarez
@Josexv1
Jun 13 2016 02:27
Hope that link helps you understand.
Subh Samal
@subhsamal
Jun 13 2016 02:27
yeah it's true ASCII of C is 68. What my doubt is if string length is 14, then 14th element should be C, I am not getting how it is 13th
Going through it @Josexv1
Jose Suarez
@Josexv1
Jun 13 2016 02:27
JavaScript arrays are zero-based. The JavaScript array “length” property returns the number of elements in an array, but it is a one-based value. So whenever you want to use the “length” property to say “hey, start from the first element in an array and go until you reach the last element,” start from zero, and go until you reach the array’s “length” property value, but “minus one!”
Norvin Burrus
@ndburrus
Jun 13 2016 02:28
@subhsamal this may help... 14 minus 1 equals 13 :+1: clear as mud?
Jose Suarez
@Josexv1
Jun 13 2016 02:29
you count array 0,1,2,3. But when counting the elents it goes 1,2,3,4, so you need to cut 1.
Subh Samal
@subhsamal
Jun 13 2016 02:29
ohh..yes, I didn't keep it in mind that string also zero based. Thank you @Josexv1
CamperBot
@camperbot
Jun 13 2016 02:29
subhsamal sends brownie points to @josexv1 :sparkles: :thumbsup: :sparkles:
:cookie: 262 | @josexv1 |http://www.freecodecamp.com/josexv1
Chris Cullen
@123xylem
Jun 13 2016 02:29

function steamrollArray(arr) {
  var newArr=[];
  //arr for storing variables
  var flatten =function(arg){
   //declare function taking argument arg.
    if(!Array.isArray(arg)){
      //if arg isnt array
      newArr.push(arg);
    }//putit in newARr

    else { for(var a in arg){
      //otherwise iterate through arg
      flatten(arg[a]);
      //and run that part of arg through the function again-until it gets to the number
  }}};
         arr.forEach(flatten);

  // Now use flatten on each element of the array
  return newArr;
}

steamrollArray([1, [2], [3, [[4]]]]);
can someone tel me why I need foreach at the end here? Wouldnt it work if i just ran the array through the function??
Subh Samal
@subhsamal
Jun 13 2016 02:29
@ndburrus hehe..yeah..I lacked in js basics..
thank you @ndburrus
CamperBot
@camperbot
Jun 13 2016 02:30
subhsamal sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:cookie: 537 | @ndburrus |http://www.freecodecamp.com/ndburrus
Jose Suarez
@Josexv1
Jun 13 2016 02:30
Checkout Mozilla Developer Network. It have it all.
Norvin Burrus
@ndburrus
Jun 13 2016 02:30
@subhsamal just kidding... i think you missed the commenting on the array (and string...) numbering earlier...
Quoc Anh Nguyen
@quocanh261997
Jun 13 2016 02:47
why isn't my code working? the lat variable still shows 0.
$(document).ready(function(){
var lat = 0;
var lon = 0;
if (navigator.geolocation){
  navigator.geolocation.getCurrentPosition(function(e){
   lat = e.coords.latitude;
   lon = e.coords.longitude;
})
}
$(".coords").html("Latitude: "+ lat);
})
Coy Sanders
@coymeetsworld
Jun 13 2016 02:51
@quocanh261997 do you have geolocation enabled? also are you using Chrome?
Quoc Anh Nguyen
@quocanh261997
Jun 13 2016 02:52
no, I'm using Microsoft Edge
@coymeetsworld
Coy Sanders
@coymeetsworld
Jun 13 2016 02:55
ohwell geolocation request is an asynchronous call @quocanh261997
missed that part on the bottom, that call may not finish executing before you request that information below
you're going to want to move that last line inside your anonymous function, also you're missing some semicolons at the end of some of your statements
have to step away hope that helps
Quoc Anh Nguyen
@quocanh261997
Jun 13 2016 02:57
how can I update the lat and lon variable so that I can access it? Cause I'm only accessing with the updated location only when I'm in the if loop
Jose Suarez
@Josexv1
Jun 13 2016 03:19
Have been cracking my head with the chellenges, and then this shows up
function slasher(arr, howMany) {
  // it doesn't always pay to be first
  var final = arr.slice(howMany);
  return final;
}
wut m8.
Huy Nguyen Thuong
@NguyenThuongHuy
Jun 13 2016 03:22
@Josexv1 yeah that one, you can put it into only 1 line of code.
Dan
@dannelmarchese
Jun 13 2016 03:23
JavaScript's "Escape Sequences in Strings" is being a jerk. I gave it exactly what it wanted.
myStr= "\"backslash\\" \"tab\t\" \"tab\t\" \"carriage-return\r\" \"new-line\n\".";
It's not coming up with any errors
But it's still somehow not right
Norvin Burrus
@ndburrus
Jun 13 2016 03:24
@dannelmarchese ok, basically the exercise is asking for a translation from words into characters... the Code/Output chart provides the correlation... in making the translation, be mindful of the punctuation (spaces, etc.)...
Dan
@dannelmarchese
Jun 13 2016 03:25
I did it with just the characters, and it still said no good. :-/
var myStr= "\"\\" \"\t\" \"\t\" \"\r\" \"\n\".";
That still didn't cut it
Norvin Burrus
@ndburrus
Jun 13 2016 03:26
@dannelmarchese carefully examine this code: "." :) also, it appears that there are too many "\" 's & quotation marks { " 's }. notice that there are no periods in backslash tab tab carriage-return new-line
Dan
@dannelmarchese
Jun 13 2016 03:26
It doesn't need a period?
Albert Fougy
@albertfougy
Jun 13 2016 03:27
Screen Shot 2016-06-12 at 11.26.14 PM.png
Dan
@dannelmarchese
Jun 13 2016 03:27
If I take away the period, it creates all sorts of errors
Albert Fougy
@albertfougy
Jun 13 2016 03:27
Hi guys. I'm still trying to understand in the "Using Objects for Lookups"
Screen Shot 2016-06-12 at 11.26.14 PM.png
why not this ? result = lookup.val;
Dan
@dannelmarchese
Jun 13 2016 03:28
var myStr= "\"\" \"\t\" \"\t\" \"\r\" \"\n." ;
I adjusted to that, still no good
Albert Fougy
@albertfougy
Jun 13 2016 03:28
someone explain to me why the last code did not work.
I thought you can call a variable 2 ways?
or is it just the property value?
Norvin Burrus
@ndburrus
Jun 13 2016 03:29
@dannelmarchese now, let's reduce the number of quotation marks to a reasonable amount... and that period somehow made it's way back into the picture...
Ari
@arilaverty
Jun 13 2016 03:30
@alfougy using lookup.val would make it search for the property in the variable called val, rather than use the user input
Albert Fougy
@albertfougy
Jun 13 2016 03:30
ahhhhhhh
k.
Dan
@dannelmarchese
Jun 13 2016 03:30
Norvin the whole thing goes sour without the period
var myStr= "\ \t\ \t\ \r\ \n." ;
Albert Fougy
@albertfougy
Jun 13 2016 03:30
Thanks @himynameisari
CamperBot
@camperbot
Jun 13 2016 03:30
alfougy sends brownie points to @himynameisari :sparkles: :thumbsup: :sparkles:
:cookie: 217 | @himynameisari |http://www.freecodecamp.com/himynameisari
Dan
@dannelmarchese
Jun 13 2016 03:31
Still no errors, but no good
Ari
@arilaverty
Jun 13 2016 03:31
@alfougy you want it to user the input from function phoneticLookup(val), rather than searching inside of the Lookup variable for a property called "val"
Norvin Burrus
@ndburrus
Jun 13 2016 03:31
@dannelmarchese alright, now let's add a touch of spacing... between the characters (character sets). let's not worry about the period anymore...
Dan
@dannelmarchese
Jun 13 2016 03:31
If you take away the period, you get a wall full of red x's
Albert Fougy
@albertfougy
Jun 13 2016 03:31
right right I was racking my brain for a 1/2 hour
I knew the code I typed was mostly right.
Dan
@dannelmarchese
Jun 13 2016 03:32
var myStr= "\ \t\ \t\ \r\ \n." ;
It's got space, it's just not showing up on here
Albert Fougy
@albertfougy
Jun 13 2016 03:32
At least I followed the instructions. the syntax was off by a hair.
Norvin Burrus
@ndburrus
Jun 13 2016 03:32
@dannelmarchese ...can you post your code? note: there is no mandatory usage of the backslash following characters...
Albert Fougy
@albertfougy
Jun 13 2016 03:32
Thanks again!
Dan
@dannelmarchese
Jun 13 2016 03:32
var myStr= "\ \t\ \t\ \r\ \n." ;
I can only print screen, but I assure you the spaces are there
Ari
@arilaverty
Jun 13 2016 03:33
@alfougy if you did result = lookUp.alpha, it'd give you Adams. So by doing lookUp.val, it can't find it.
Albert Fougy
@albertfougy
Jun 13 2016 03:33
Also is there any chat room that can help me learn "vim"
Dan
@dannelmarchese
Jun 13 2016 03:33
var myStr= "\ \t\ \t\ \r\ \n." ;
Albert Fougy
@albertfougy
Jun 13 2016 03:33
sorry.. I'm listening.
Norvin Burrus
@ndburrus
Jun 13 2016 03:33
help format @dannelmarchese
CamperBot
@camperbot
Jun 13 2016 03:33

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

This an inline `<paste code here>` code formatting with a single backtick() at _start_ and _end_ around thecode`.

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

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

Albert Fougy
@albertfougy
Jun 13 2016 03:34
@himynameisari you know what? I did use that and I only saw that result in the screen.
Norvin Burrus
@ndburrus
Jun 13 2016 03:34
@dannelmarchese carefully remove the \'s following the code characters... (after the t's and r) ...and bannish the period.
Dan
@dannelmarchese
Jun 13 2016 03:34
var myStr= "\ \t\ \t\ \r\ \n." ;
Albert Fougy
@albertfougy
Jun 13 2016 03:34
I totally missed the "user input" part of the algorithm
I was so focused on the last 2 challenges of following the syntax . I just wasn't thinking creatively.
Thanks for the indepth explanation @himynameisari
CamperBot
@camperbot
Jun 13 2016 03:35
alfougy sends brownie points to @himynameisari :sparkles: :thumbsup: :sparkles:
:warning: alfougy already gave himynameisari points
Dan
@dannelmarchese
Jun 13 2016 03:35
var myStr= "\ \ \t \t \r \n" ;
Norvin Burrus
@ndburrus
Jun 13 2016 03:36
@dannelmarchese see the code post procedure?
Dan
@dannelmarchese
Jun 13 2016 03:37
I do, and I tried many times
''''
CamperBot
@camperbot
Jun 13 2016 03:37
:bulb: to format code use backticks! ``` more info
Dan
@dannelmarchese
Jun 13 2016 03:37
Is that a back tick?
'''var myStr= "\ \ \t \t \r \n" ;
CamperBot
@camperbot
Jun 13 2016 03:37
:bulb: to format code use backticks! ``` more info
Dan
@dannelmarchese
Jun 13 2016 03:38
'''
var myStr= "\ \ \t \t \r \n" ;
CamperBot
@camperbot
Jun 13 2016 03:38
:bulb: to format code use backticks! ``` more info
Dan
@dannelmarchese
Jun 13 2016 03:38
I did exactly what it asked
Norvin Burrus
@ndburrus
Jun 13 2016 03:38
@dannelmarchese the backtick is to the left of the number one key... also, you may find the chat/compose buttons to the right of the chat area useful- hit compose and do the backticks (above & below) then return to chat mode and send
Dan
@dannelmarchese
Jun 13 2016 03:38
var myStr= "\ \ \\t  \\t  \\r  \\n" ;
Jesus, there we go
Thanks man
Norvin Burrus
@ndburrus
Jun 13 2016 03:38
@dannelmarchese see the spaces? and extra backslashes? now, just match the character expression, and you're all set :) the code has 4 backslashes to start (starting from the left). there should only be 2, right? so, right now there are 2 extra backslahes and 2 extra spaces alone to this point...
Dan
@dannelmarchese
Jun 13 2016 03:39
Right, it called for spaces
Muh Ibnu Habil Hanafi
@nubilfi
Jun 13 2016 03:41
hi, i need your help. My weather app click event conversion temp doesn't work, there is no error in console.. http://codepen.io/nubilfi/pen/JXxLLg
Dan
@dannelmarchese
Jun 13 2016 03:41
var myStr= "\ \t \t \r \n";
Still no good
Norvin Burrus
@ndburrus
Jun 13 2016 03:42
@dannelmarchese getting closer. the 2 initial backslashes should be consecutive, see? no space between them (as shown in the Code/Output chart - for backslash).
Dan
@dannelmarchese
Jun 13 2016 03:42
But it called for a backslash to be escaped at the beginning
var myStr= "\\t \t \r \n";
Still no good
Chris Cullen
@123xylem
Jun 13 2016 03:43

Quick Question:::::Can you tell me what is meant by |collection[c][pre] because pre is a seperate arg to collection so I dont get how its being used?? ```js
function every(collection, pre) {
// Create a counter to check how many are true.
var counter = 0;

// Check for each object
for (var c in collection) {
// If it has the same property or the same property value then add 1
if (collection[c].hasOwnProperty(pre) || collection[c][pre] == pre) {//what is this? collection c is c in collection.. but the pre bit isnt in collection...!??
counter++;
}
```

Norvin Burrus
@ndburrus
Jun 13 2016 03:43
@dannelmarchese let's review the instructions: Encode the following sequence, separated by spaces: getting clearer? it looks like the t lost part of its' makeup/code...
Dan
@dannelmarchese
Jun 13 2016 03:44
Yes
And the first thing it asked to be encoded was a backslash in and of itself
But you said to take out those slashes, that merged it with the backslash
GOT IT
Norvin Burrus
@ndburrus
Jun 13 2016 03:45
@dannelmarchese ...that's correct - and we did that, so what should follow it?
Dan
@dannelmarchese
Jun 13 2016 03:45
Two backslashes to start, then the \t
Chris Cullen
@123xylem
Jun 13 2016 03:45
Quick Question:::::Can you tell me what is meant by |collection[c][pre] because pre is a seperate arg to collection so I dont get how its being used??
function every(collection, pre) {
  // Create a counter to check how many are true.
  var counter = 0;

  // Check for each object
  for (var c in collection) {
    // If it has the same property or the same property value then add 1
    if (collection[c].hasOwnProperty(pre) || collection[c][pre] == pre) {//what is this? collection c is c in collection.. but the pre bit isnt in collection...!??
      counter++;
    }
Dan
@dannelmarchese
Jun 13 2016 03:45
@ndburrus How do I give you points
Subh Samal
@subhsamal
Jun 13 2016 03:45
function rot13(str) { // LBH QVQ VG!
  var arr= str.slice(0,str.length);
  var arr1 = [];
  //return arr;
  for (var i=0; i<arr.length; i++)
    {   
      arr1[i] = arr.charCodeAt(i);
    }
  for(var j =0; j<arr1.length; j++)
    {
      if(arr1[j]>64 && arr1[j]<93)
        {
          arr1[j]=arr1[j]+13;
        }
    }
   arr1.join(" ").split(",");
  /*for (var k=0; k<arr1.length; k++)
    {   
      arr1[k] = arr1.fromCharCode(k);
    }*/
  return arr1;

}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
Norvin Burrus
@ndburrus
Jun 13 2016 03:45
@dannelmarchese bingo! ...adjust the remaining code, press run tests...
Subh Samal
@subhsamal
Jun 13 2016 03:46
topic Ceasars Cipher:
Norvin Burrus
@ndburrus
Jun 13 2016 03:46
help brownie points @dannelmarchese
CamperBot
@camperbot
Jun 13 2016 03:46

:point_right: brownie points [wiki]

Brownie Points

The number beside your picture on Free Code Camp tells you how many Brownie Points you have.

A user profile picture next to a with Brownie Points score

There are two ways you can get Brownie Points:

  1. Complete challenges - you get one point per challenge you complete
  2. Help other campers in chat - each time you help another camper and they thank you (by typing "thanks @yourname"), you will get a point

Brownie Points help you look like the kind of person who codes a lot, shares relevant links, and helps people.

They also add to your Streak.

:pencil: read more about brownie points on the FCC Wiki

Dan
@dannelmarchese
Jun 13 2016 03:46
thanks @ndburrus
CamperBot
@camperbot
Jun 13 2016 03:46
dannelmarchese sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:cookie: 538 | @ndburrus |http://www.freecodecamp.com/ndburrus
Norvin Burrus
@ndburrus
Jun 13 2016 03:47
@dannelmarchese kudos to you!! you are top of the food chain :sparkles: great persistence :fire: you're very welcome...
Subh Samal
@subhsamal
Jun 13 2016 03:47
How can I convert arr1 to string of alphabets?? It now contains desired ASCIIs.
Deanna
@DeannaB
Jun 13 2016 03:49
Hi all, could use a little help with the Shopping List in Javascript
Arjun
@arjunsingh81989
Jun 13 2016 03:50
Do we need to setup a web server if we want to run a Grunt JS task?
Norvin Burrus
@ndburrus
Jun 13 2016 03:51
@subhsamal Get ASCII value of Character, Convert ASCII to Character in JavaScript To convert an ASCII value to its corresponding character use the fromCharCode static method of the String JavaScript object. Example: console.log(String.fromCharCode(65));
Deanna
@DeannaB
Jun 13 2016 03:51
NM! Figured it out
Subh Samal
@subhsamal
Jun 13 2016 03:53
can you help me with the commented part? @ndburrus
 for (var k=0; k<arr1.length; k++)
    {   
      arr2[k] = arr1.fromCharCode(arr1[k]);
    }
  return arr2;
Norvin Burrus
@ndburrus
Jun 13 2016 03:54
@subhsamal where? what commented part (in the doc?)? oh, nm, in the code posted above, moment...
Subh Samal
@subhsamal
Jun 13 2016 03:54
I want to do something as above @ndburrus
function rot13(str) { // LBH QVQ VG!
  var arr= str.slice(0,str.length);
  var arr1 = [];
  var arr2 = [];
  //return arr;
  for (var i=0; i<arr.length; i++)
    {   
      arr1[i] = arr.charCodeAt(i);
    }
  for(var j =0; j<arr1.length; j++)
    {
      if(arr1[j]>64 && arr1[j]<93)
        {
          arr1[j]=arr1[j]+13;
        }
    }
   arr1.join(" ").split(",");
  for (var k=0; k<arr1.length; k++)
    {   
      arr2[k] = arr1.fromCharCode(arr1[k]);
    }
  return arr2;

}
// Change the inputs below to test
rot13("SERR PBQR PNZC");
Norvin Burrus
@ndburrus
Jun 13 2016 04:00
@subhsamal i'm not that far yet, but it looks like you're going to ascii (from char) on arr2... and, i assume, that the characters are stored in arr2.
Subh Samal
@subhsamal
Jun 13 2016 04:01
actually my arr1 contains all ASCII. I am trying to convert them into char @ndburrus
If I do join on arr1, is it a string now?? else how can I convert arr1 to string? @ndburrus arr1.join(" ,");
Nathaniel Nasarow
@Torgian
Jun 13 2016 04:02
hey all
So I finished up the Return Largest Numbers in Arrays challenge, but am trying to figure out how to do this differently.
Norvin Burrus
@ndburrus
Jun 13 2016 04:03
@subhsamal well, if arr1 contains ascii - use fromCharCode on arr1.
Ari
@arilaverty
Jun 13 2016 04:04
Could I please have a look at someones "Nesting For Loops"?
Subh Samal
@subhsamal
Jun 13 2016 04:04
I tried something as below @ndburrus
for (var k=0; k<arr1.length; k++)
    {   
      arr2[k] = arr1.fromCharCode(arr1[k]);
    }
  return arr2;
but it shows error,saying arr1.fromCharCode() is not a function
Norvin Burrus
@ndburrus
Jun 13 2016 04:05
@subhsamal moment...
Subh Samal
@subhsamal
Jun 13 2016 04:06
yup
Norvin Burrus
@ndburrus
Jun 13 2016 04:12
@subhsamal ok, getting setup... it looks like arr.length = 14.. interesting... ok, makes sense - 14 char's. in the j loop, are we trying to capture the values greater than 64 and less than 93? why is 13 added to these values? i guess i should read the challenge... which challenge is this?
Subh Samal
@subhsamal
Jun 13 2016 04:16
everything going good until last for loop. @ndburrus
Helena
@poigirl2001
Jun 13 2016 04:19
Hello
Norvin Burrus
@ndburrus
Jun 13 2016 04:19
@poigirl2001 hi poi... which json exercise? try the shift method... what is the challenge name?
Helena
@poigirl2001
Jun 13 2016 04:19
I'm having difficulty with JSON
How do I add something to an object array
The very first one
The introduction
What is that?
Is it obj.shift(thing)
Introducing JavaScript object notation
Norvin Burrus
@ndburrus
Jun 13 2016 04:23
@poigirl2001 ok, i misunderstood your question, as it relates to the exercise. the challenge is basically asking for another record to be created. simply follow the existing record format (being mindful of punctuation/syntax). remember to place a comment betwen the records. :sparkles:
Helena
@poigirl2001
Jun 13 2016 04:28
So do I create a new object?
I tried to
use the brackets and curly brackets but it didn't work
Ari
@arilaverty
Jun 13 2016 04:28
function multiplyAll(arr) {
    var product = 1;
    // Only change code below this line

    var sum = 0,
        prod = 1;

    for (var i = 0; i < arr.length; i += 1) {
        product *= arr[i];
    }
    // Only change code above this line
    return product;
}
// Modify values below to test your code
multiplyAll([
    [1],
    [2],
    [3]
]);
how do I make it so that I can use the array [1,2], [3,4], [5,6]?
Simon Situ
@ssitu001
Jun 13 2016 04:30
concat the arrays to a single array
@himynameisari
Norvin Burrus
@ndburrus
Jun 13 2016 04:30
@poigirl2001 ok, when you say "create a new object," the answer is yes. however, one could simply copy/paste the existing record (everything between the curly braces), and then update the record information to variables (the values for: artist, title, release_year, etc.) of your choosing.
Ari
@arilaverty
Jun 13 2016 04:31
@ssitu001 thanks, will try this out
CamperBot
@camperbot
Jun 13 2016 04:31
himynameisari sends brownie points to @ssitu001 :sparkles: :thumbsup: :sparkles:
:cookie: 293 | @ssitu001 |http://www.freecodecamp.com/ssitu001
Simon Situ
@ssitu001
Jun 13 2016 04:31
or use two for loops if you don't want to concat @himynameisari
Brett Guillory
@kurzninja
Jun 13 2016 04:31
Question about the Weather app project: What's the best way to get the user's location? Using an IP geotagging or in-browser geolocation or what?
Norvin Burrus
@ndburrus
Jun 13 2016 04:32
@subhsamal trying to determine why from CharCode has an issue w/ arr1...
Helena
@poigirl2001
Jun 13 2016 04:32
@ndburrus Oh I realized that I just had to put a comma before creating a new record…
Norvin Burrus
@ndburrus
Jun 13 2016 04:33
@poigirl2001 ...we covered that earlier, didn't we? let's see... remember to place a comment betwen the records. :) nice work! :)
hnry
@hnry
Jun 13 2016 04:34
@kurzninja don't think it matters in terms of the weather project, but i've mostly seen people use the browser api
Chris Cullen
@123xylem
Jun 13 2016 04:37
Any idea why my BOOLEAN check isnt working? I believe the problem is how im looking for a boolean but it looks good to me!
function truthCheck(collection, pre) {
  var counter=0;
for(var a in collection)  {//searching through collecton

  if(collection[a].hasOwnProperty(pre)&&collection[a][pre]==="boolean"){
//if collection has pre in it and its property is a boolean    
    counter++;
 //make counter increment
  }}

  if(counter===collection.length){
  //If counter is same length as collection it means all properties are there and true.
    return true;
  }else{ return false;}

   }
Norvin Burrus
@ndburrus
Jun 13 2016 04:37
@subhsamal ok, arr1 goes to charcode (unicode) in the 1st loop, j loop jumbles the #'s, so we have unicode at loop k start, so it looks like spaces need to be inserted prior to loop 3 start - so the format is acceptable as unicode to from CharCode... what do you think?
hnry
@hnry
Jun 13 2016 04:39
@123xylem what is collection
an object? an array?
Chris Cullen
@123xylem
Jun 13 2016 04:39
collection is a list of objects
Ari
@arilaverty
Jun 13 2016 04:40
@ssitu001 thanks again, got it!
CamperBot
@camperbot
Jun 13 2016 04:40
himynameisari sends brownie points to @ssitu001 :sparkles: :thumbsup: :sparkles:
:warning: himynameisari already gave ssitu001 points
hnry
@hnry
Jun 13 2016 04:40
what is a "list" ?
an array of objects?
Chris Cullen
@123xylem
Jun 13 2016 04:40
@hnry
truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex");
hnry
@hnry
Jun 13 2016 04:40
don't use for...in on an array
Chris Cullen
@123xylem
Jun 13 2016 04:41
collection here is an array of objects right?
pre is the last word after it
"sex"
Simon Situ
@ssitu001
Jun 13 2016 04:42
@123xylem what is the name of the algorithm on FCC?
Chris Cullen
@123xylem
Jun 13 2016 04:42
Everything Be True
Norvin Burrus
@ndburrus
Jun 13 2016 04:43
@subhsamal did you see the post?
Simon Situ
@ssitu001
Jun 13 2016 04:44
how are you getting to each object in the collection? @123xylem
Chris Cullen
@123xylem
Jun 13 2016 04:44
for (c in collection)
Simon Situ
@ssitu001
Jun 13 2016 04:44
collection is an array of objects, but you're just iterating through (1) object
you need access to all objects in the collection @123xylem
Sam Snyder
@MassNerdy
Jun 13 2016 04:46

Hey ya'll. I'm working on "Testing Objects for Properties", and I'm not able to return values from the first part of my if statement.

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");

Anyone know what I might be doing wrong?

(myObj is a previously defined object whose values I'm trying to access)
Coy Sanders
@coymeetsworld
Jun 13 2016 04:48
@MassNerdy you can only use dot notation to access a property if you know the name of the property ahead of time
Luis Carlos Garcia Barajas
@Luiko
Jun 13 2016 04:48
@MassNerdy use brackets
Coy Sanders
@coymeetsworld
Jun 13 2016 04:48
you can't use it on variables, only literal names
Sam Snyder
@MassNerdy
Jun 13 2016 04:48
Goooootcha...Thanks!
@coymeetsworld @Luiko Thank you!
CamperBot
@camperbot
Jun 13 2016 04:48
massnerdy sends brownie points to @coymeetsworld and @luiko :sparkles: :thumbsup: :sparkles:
:cookie: 324 | @luiko |http://www.freecodecamp.com/luiko
:star2: 1129 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Ari
@arilaverty
Jun 13 2016 04:49
return myObj[checkProp]
Coy Sanders
@coymeetsworld
Jun 13 2016 04:49
np @MassNerdy
Simon Situ
@ssitu001
Jun 13 2016 04:49
@MassNerdy . is equivalent to [" "];
Chris Cullen
@123xylem
Jun 13 2016 04:50

@ssitu001 are u sure? I thought a goes through all elements of collection checking for property then if the property is a boolean for(var a in collection) {//searching through collecton

if(collection[a].hasOwnProperty(pre)&&collection[a][pre]==="boolean"){

Norvin Burrus
@ndburrus
Jun 13 2016 04:50
@MassNerdy you might like this article JS dot-notation vs. bracket notation :sparkles:
Chris Cullen
@123xylem
Jun 13 2016 04:52

its basically the difference between

Boolean(collection[c][pre]))

And

collection[a][pre]==="boolean"
What is the difference?
Chaitanya Allu
@Chaitanya40
Jun 13 2016 04:53
can someone help with145?
Chris Cullen
@123xylem
Jun 13 2016 04:53
Well apart from the c and a
Chaitanya Allu
@Chaitanya40
Jun 13 2016 04:53
I don't understand what it says
Coy Sanders
@coymeetsworld
Jun 13 2016 04:55
@Chaitanya40 they're named challenges, the number is your brownie points
can you give the challenge name and what you've written so far?
Chaitanya Allu
@Chaitanya40
Jun 13 2016 04:56
its about the escape sequences
escape sequences in strings
Coy Sanders
@coymeetsworld
Jun 13 2016 04:56
what do you have so far?
Chaitanya Allu
@Chaitanya40
Jun 13 2016 04:56
myStr = "\"backslash\" \ttab\t \ttab\t \rcarriage-return\r \nnew-line\n";
Coy Sanders
@coymeetsworld
Jun 13 2016 04:57
you need to replace those words with its corresponding escape sequence on the table
for example to put a tab in a String you put \t inside the set of quotes
also there should only be 1 set of double quotes
Chaitanya Allu
@Chaitanya40
Jun 13 2016 04:58
ohh, let me try again
thanks
Coy Sanders
@coymeetsworld
Jun 13 2016 04:58
no problem
Chaitanya Allu
@Chaitanya40
Jun 13 2016 05:00
myStr = "\'\'\' \t'\t'\t \t'\t'\t \r'\r'\r \n'\n'\n";
this should work, right?
Coy Sanders
@coymeetsworld
Jun 13 2016 05:01
too many escape sequences there
also only one set of quotes, at the beginning and end of the String
if I just needed to do tab, it would be myStr = "\t";
Chaitanya Allu
@Chaitanya40
Jun 13 2016 05:02
okay
Apoorve
@apugoneappu
Jun 13 2016 05:02

Challenge: Profile lookup


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


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

// Only change code above this line
}

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

Thanks in advance.

Coy Sanders
@coymeetsworld
Jun 13 2016 05:03
@apugoneappu with your code you're not iterating through all contacts in the array
Apoorve
@apugoneappu
Jun 13 2016 05:04
@coymeetsworld Why not?
Coy Sanders
@coymeetsworld
Jun 13 2016 05:04
also that's not the way you check if No such contact exists
look what happens when you go through the first contact
on a different test
actually nvm it can go through the accounts but this isn't the right way, you never need to check for firstName as a property, all contacts will have that
Norvin Burrus
@ndburrus
Jun 13 2016 05:07
@Chaitanya40 basically the challenge is asking for a translation from words to characters. use the Code/Output chart for the translation, being mindful of the punctuation, and spaces... right now, it looks like there are excessive following backslahes, and no spacing... :)
Apoorve
@apugoneappu
Jun 13 2016 05:07
@coymeetsworld Now I got it. I'm checking for the availability of the firstname property whereas I had to check if it matched with the argument. Sorry. Thanks.
CamperBot
@camperbot
Jun 13 2016 05:07
apugoneappu sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star2: 1130 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Coy Sanders
@coymeetsworld
Jun 13 2016 05:07
correct, no problem
also you can only say no such contact exists if you've checked all contacts, so keep that in mind
Chaitanya Allu
@Chaitanya40
Jun 13 2016 05:08
Got it @ndburrus , thanks
CamperBot
@camperbot
Jun 13 2016 05:08
chaitanya40 sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:cookie: 540 | @ndburrus |http://www.freecodecamp.com/ndburrus
Norvin Burrus
@ndburrus
Jun 13 2016 05:09
@Chaitanya40 you're very welcome.. adjust the code, and you're all set :sparkles:
Arjun
@arjunsingh81989
Jun 13 2016 05:12
Does anyone know Grunt JS Task Runner>
Simon Situ
@ssitu001
Jun 13 2016 05:18
@123xylem figure it out?
Chris Cullen
@123xylem
Jun 13 2016 05:18
@ssitu001 no
Simon Situ
@ssitu001
Jun 13 2016 05:18
ok where are you stuck?
Chris Cullen
@123xylem
Jun 13 2016 05:18
only Boolean(collection[c][pre])) works
Simon Situ
@ssitu001
Jun 13 2016 05:19
look up truthy and falsy values
can i see your code again @123xylem
Chris Cullen
@123xylem
Jun 13 2016 05:20

function truthCheck(collection, pre) {
  var counter=0;
for(var a in collection)  {//searching through collecton

  if(collection[a].hasOwnProperty(pre)&& typeof collection[a][pre]==="boolean"){
//if collection elements has the same name as pre  and if its property key is a boolean    
    counter++;
 //make counter increment
  }}

  if(counter===collection.length){
  //If counter is same length as collection it means all properties are there and true.
    return true;
  }else{ return false;}

   }

truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex");
rahildar
@rahildar
Jun 13 2016 05:21
@123xylem collection[a][pre] is the culprit
Chris Cullen
@123xylem
Jun 13 2016 05:21
yea
if i write Boolean(collection[c][pre])) it works
but its the same thing?
Simon Situ
@ssitu001
Jun 13 2016 05:22
@123xylem lookup truthy and falsey values
Chris Cullen
@123xylem
Jun 13 2016 05:22
@ssitu001 what about them?
Simon Situ
@ssitu001
Jun 13 2016 05:22
!something === false, undefined, NaN, " " etc
Chris Cullen
@123xylem
Jun 13 2016 05:22
@rahildar
rahildar
@rahildar
Jun 13 2016 05:23
i @123xylem because you are checking typeof in first case which is a boolean and in second u r checking a truthy/falsy value
@123xylem i mean typeof in first case will be a string or object and not boolean
thats why it fails
Markus Kiili
@Masd925
Jun 13 2016 05:24
@123xylem if(val){...} is a check for truthy value, because if automatically coerces values to boolean. No need for anything extra.
rahildar
@rahildar
Jun 13 2016 05:25
@Masd925 yes thats better
Simon Situ
@ssitu001
Jun 13 2016 05:25
@Masd925 @123xylem exactly
Markus Kiili
@Masd925
Jun 13 2016 05:25
@123xylem And if(!val){...} is a check for falsy value.
Chris Cullen
@123xylem
Jun 13 2016 05:29
@rahildar @Masd925 @ssitu001 thanks just getting my head around this stuff nw
CamperBot
@camperbot
Jun 13 2016 05:29
123xylem sends brownie points to @rahildar and @masd925 and @ssitu001 :sparkles: :thumbsup: :sparkles:
:cookie: 223 | @rahildar |http://www.freecodecamp.com/rahildar
:cookie: 295 | @ssitu001 |http://www.freecodecamp.com/ssitu001
:star2: 1839 | @masd925 |http://www.freecodecamp.com/masd925
Chris Cullen
@123xylem
Jun 13 2016 05:31
so my type of was returning string as opposed to boolean so failing?> @rahildar
rahildar
@rahildar
Jun 13 2016 05:31
yes ..
Bryan Castleman
@castlemaninc
Jun 13 2016 05:37
how to post code
how do I post my code again?
Chris Cullen
@123xylem
Jun 13 2016 05:37
ty .. How come this didnt work then ? Because im just straight asking if collection[a][pre]==="boolean"
@rahildar
rahildar
@rahildar
Jun 13 2016 05:40
because value at collection[a][pre] === "boolean" checks type as well as value
Faizal Zakaria
@faizalzakaria
Jun 13 2016 05:40
typeof “string” is a string and its truthy, typeof 1 is a number and its truthy typeof 0 is a number but its falsely. 'typeof true is a boolean’ and its a truthy. So you only cover that 1 particular case (a boolean case)
Markus Kiili
@Masd925
Jun 13 2016 05:40
@123xylem Value being truthy means "is the value true then coerced to type boolean". val==="boolean" tests if the value is a string "boolean". typeof val==="boolean" tests if the value is of type boolean. So it tests if the value is true/false. All value are truthy/falsy. Only true/false are boolean.
Bryan Castleman
@castlemaninc
Jun 13 2016 05:42

My code for 'Drop it' works. I am just wondering if I could have written this simpler. Is the for loop necessary?

I have a fear of while loops because I hate freezing the browser.

function dropElements(arr, func) {
  // Drop them elements.
  for (i=0;i<arr.length;i++){
    while (func(arr[i]) !== true){
      arr.shift();
    }
    return arr;
  }
}

dropElements([1, 2, 3], function(n) {return n < 3; });
Samuel Cupidon
@Zerazera
Jun 13 2016 05:43
@castlemaninc Here's mine
function dropElements(arr, func) {
  // Drop them elements.
  var firstEle = arr.filter(func);
  return firstEle.length === 0 ? [] : arr.slice(arr.indexOf(firstEle[0]));
}
Bryan Castleman
@castlemaninc
Jun 13 2016 05:46
@Zerazera , interesting solution. I attempted to use .filter but couldn't get it to not run through the whole array. I am not sure I understand the ? [] part
Samuel Cupidon
@Zerazera
Jun 13 2016 05:47
@castlemaninc It's a ternary operator. It's basically shorthand for if-then
condition ? trueValue : falseValue
Bryan Castleman
@castlemaninc
Jun 13 2016 05:49
@Zerazera cool.
Markus Kiili
@Masd925
Jun 13 2016 05:49
@castlemaninc You can remove the for loop, because the while loop does the work there.
function dropElements(arr, func) {
  // Drop them elements.
    while (func(arr[0]) !== true){
      arr.shift();
    }
    return arr;

}
Bryan Castleman
@castlemaninc
Jun 13 2016 05:51
@Masd925 , that's what I was thinking but how do I make it not crash the browser? I have to increment the index. Will it exit the while loop if the condition becomes true?
@Masd925 nevermind. I just saw your code. That makes sense.
@Masd925 Thanks
CamperBot
@camperbot
Jun 13 2016 05:52
castlemaninc sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1840 | @masd925 |http://www.freecodecamp.com/masd925
Deepak Yadav
@ydeepk
Jun 13 2016 05:52
Guy's Please help me with twitch api challenge I want to know any improvements possible as well as If i'm fullfilling my user story about it. http://codepen.io/ydeepk/pen/gMOVbj
Samuel Cupidon
@Zerazera
Jun 13 2016 05:53
@Masd925 You can replace this while(func(arr[0]) !== true) with this while(!func(arr[0]))
Rabin Shrestha
@jyapujuju
Jun 13 2016 05:53

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

//Try it out here
var myCar = new Car(3, 1, 2);
var hCar = new Car(4, 4, 2);
var mCar = new Car(4, 4, 2);
whats wrong here
tommy
@tommygebru
Jun 13 2016 05:54

@tommygebru
PLEASE SHARE: any tips/tricks/advice you picked up in coding.... just in general or something to share when someone is stuck :smile: :+1: :sparkles: :heart:
for example:

Master pseudocode and you master all the languages

Samuel Cupidon
@Zerazera
Jun 13 2016 05:54
@jyapujuju Your function doesn't pass parameters
Bryan Castleman
@castlemaninc
Jun 13 2016 05:55
@Zerazera How do you know so many shorthand tricks?
Samuel Cupidon
@Zerazera
Jun 13 2016 05:57
I'd recommend codewars. You can see other people's solutions once you solve a problem. Learned a few tricks that way.
kirbyedy
@kirbyedy
Jun 13 2016 06:02
@ydeepk hmmm the links dont work, when I click on the online twitcher
@ydeepk also I clicked on "online"... got this saying null
Screen Shot 2016-06-13 at 09.03.12.png
and I am comparing with mine, and these users are offline
G Lakshmi Narayana
@glnarayana93
Jun 13 2016 06:14
help me find error in this

function binaryAgent(str) {
  var arr=str.split(" ");
  var count=0,x=[];
  for(var i=0;i<arr.length;i++){
    //for(var j=0;j<arr[i].toString().length;j++){
      x[count++] = parseInt(arr[i], 2);
   // }
  }
  var count1=0,y=[];
  var str1;
  for(i=0;i<x.length;i++){
    if(String.fromCharCode(x[i]))
    str1+=String.fromCharCode(x[i]);
  }
  return str1;
}

binaryAgent("01001001 00100000 01101100 01101111 01110110 01100101 00100000 01000110 01110010 01100101 01100101 01000011 01101111 01100100 01100101 01000011 01100001 01101101 01110000 00100001");
CamperBot
@camperbot
Jun 13 2016 06:14
no wiki entry for: me find error in thisfunction binaryagentstr var arrstrsplit var count0x forvar i0iarrlengthi forvar j0jarritostringlengthj xcount parseintarri 2 var count10y var str1 fori0ixlengthi ifstringfromcharcodexi str1stringfromcharcodexi return str1binaryagent01001001 00100000 01101100 01101111 01110110 01100101 00100000 01000110 01110010 01100101 01100101 01000011 01101111 01100100 01100101 01000011 01100001 01101101 01110000 00100001
Markus Kiili
@Masd925
Jun 13 2016 06:19
@glnarayana93 You only need the first loop and only the arr variable. Loop through the arr elements and assign String.fromCharCode(parseInt(arr[i],2)) back to the array element. Then just return joined arr.
Rabin Shrestha
@jyapujuju
Jun 13 2016 06:20

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

//Try it out here
var myCar = new Car(3, 1, 2);
what about now @Zerazera
Markus Kiili
@Masd925
Jun 13 2016 06:21
@jyapujuju Use the constructor parameters to set the property values. Instead of the fixed numbers.
Rabin Shrestha
@jyapujuju
Jun 13 2016 06:23
how can i do that @Masd925

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

//Try it out here
var myCar = new Car(this.wheels, this.seats, this.engines);
is it the way?
G Lakshmi Narayana
@glnarayana93
Jun 13 2016 06:24
@Masd925 im getting the output as this
undefinedI love FreeCodeCamp!
Markus Kiili
@Masd925
Jun 13 2016 06:25
@jyapujuju No, you need to change inside the function.
@glnarayana93 Post the code please.
Samuel Cupidon
@Zerazera
Jun 13 2016 06:25
@jyapujuju Inside your constructor function, assign the passed variables to the function variables\
G Lakshmi Narayana
@glnarayana93
Jun 13 2016 06:27
@Masd925 i complied the old code

function binaryAgent(str) {
  var arr=str.split(" ");
  var count=0,x=[];
  for(var i=0;i<arr.length;i++){
    //for(var j=0;j<arr[i].toString().length;j++){
      x[count++] = parseInt(arr[i], 2);
   // }
  }
  var count1=0,y=[];
  var str1;
  for(i=0;i<x.length;i++){
    if(String.fromCharCode(x[i]))
    str1+=String.fromCharCode(x[i]);
  }
  return str1;
}

binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");
Markus Kiili
@Masd925
Jun 13 2016 06:28
@glnarayana93 You only need the loop and one assignment:
function binaryAgent(str) {
  var arr=str.split(" ");
  for(var i=0;i<arr.length;i++){
      arr[i]=String.fromCharCode(parseInt(arr[i],2));
  }
  return arr.join("");
}
You can also use .map() instead of the loop.
G Lakshmi Narayana
@glnarayana93
Jun 13 2016 06:29
@Masd925 thanks understood the solution
but what is the problem with mine?
i just want to figure out
CamperBot
@camperbot
Jun 13 2016 06:29
glnarayana93 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1841 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Jun 13 2016 06:32
@glnarayana93 Initialize str1 as an empty string. Then undefined won't be on the result.
G Lakshmi Narayana
@glnarayana93
Jun 13 2016 06:33
@Masd925 thanks
CamperBot
@camperbot
Jun 13 2016 06:33
glnarayana93 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: glnarayana93 already gave masd925 points
Karl Wills
@karlwills
Jun 13 2016 06:34
Can anyone help with this task please? I'm trying to return an object properties value after checking hasOwnProperty, however it doesn't seem to return
// 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");
Markus Kiili
@Masd925
Jun 13 2016 06:35
@karlwills The dot notation only works if the property key string is a valid JS identifier (for example "12" and "lives left" are not) and you write the key after the dot: var cat={clothes:"pants", "lives left":3}; cat.clothes; //returns "pants". Bracket notation works with keys that can be arbitrary strings cat["lives left"]; //returns 3, variables var key="clothes"; cat[key]; //returns "pants", or expressions cat["lives"+" "+"left"]; //returns 3.
Karl Wills
@karlwills
Jun 13 2016 06:36
ah, so I guess this would work with bracket notation then as it is a string?
Markus Kiili
@Masd925
Jun 13 2016 06:36
@karlwills You are using property key stored in a parameter, so only bracket notation works.
Karl Wills
@karlwills
Jun 13 2016 06:37
@Masd925 Thanks for your help, perfect :+1:
CamperBot
@camperbot
Jun 13 2016 06:37
karlwills sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1842 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Jun 13 2016 06:38
@karlwills All property keys are strings.
Rabin Shrestha
@jyapujuju
Jun 13 2016 06:38
@Masd925 can you help me
or give some hint
Markus Kiili
@Masd925
Jun 13 2016 06:39
@jyapujuju this.wheels = wheels; etc
Rabin Shrestha
@jyapujuju
Jun 13 2016 06:40
@Masd925 thanks
CamperBot
@camperbot
Jun 13 2016 06:40
jyapujuju sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1843 | @masd925 |http://www.freecodecamp.com/masd925
G Lakshmi Narayana
@glnarayana93
Jun 13 2016 06:40
help me find the error in this code

function truthCheck(collection, pre) {
  // Is everyone being true?
  //var a;
  for(var i=0;i<collection.length;i++){
    if(collection[i].hasOwnProperty(arguments[1])){
      //a=1;
    }
    else return false;
  }
  return true;
}

truthCheck([{"user": "Tinky-Winky", "sex": "male", "age": 0}, {"user": "Dipsy", "sex": "male", "age": 3}, {"user": "Laa-Laa", "sex": "female", "age": 5}, {"user": "Po", "sex": "female", "age": 4}], "age");
CamperBot
@camperbot
Jun 13 2016 06:40
no wiki entry for: me find the error in this codefunction truthcheckcollection pre is everyone being true var a forvar i0icollectionlengthi ifcollectionihasownpropertyarguments1 a1 else return false return truetruthcheckuser tinky-winky sex male age 0 user dipsy sex male age 3 user laa-laa sex female age 5 user po sex female age 4 age
Tam Nguyen
@bankplank
Jun 13 2016 06:44
what does + do in a regular expression?
Alex T.
@lx-t
Jun 13 2016 06:45
@bankplank "Matches the preceding expression 1 or more times." https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions
G Lakshmi Narayana
@glnarayana93
Jun 13 2016 06:46
help me find the error in this code

function truthCheck(collection, pre) {
  // Is everyone being true?
  //var a;
  for(var i=0;i<collection.length;i++){
    if(collection[i].hasOwnProperty(arguments[1])){
      //a=1;
    }
    else return false;
  }
  return true;
}

truthCheck([{"user": "Tinky-Winky", "sex": "male", "age": 0}, {"user": "Dipsy", "sex": "male", "age": 3}, {"user": "Laa-Laa", "sex": "female", "age": 5}, {"user": "Po", "sex": "female", "age": 4}], "age");
CamperBot
@camperbot
Jun 13 2016 06:46
no wiki entry for: me find the error in this codefunction truthcheckcollection pre is everyone being true var a forvar i0icollectionlengthi ifcollectionihasownpropertyarguments1 a1 else return false return truetruthcheckuser tinky-winky sex male age 0 user dipsy sex male age 3 user laa-laa sex female age 5 user po sex female age 4 age
Tam Nguyen
@bankplank
Jun 13 2016 06:48
@lx-t Thanks. But for example string = "Hello Hello Hello" /hello/g will return 3 results. The same as /hello+/g. So i'm confuse what the actual difference is
CamperBot
@camperbot
Jun 13 2016 06:48
bankplank sends brownie points to @lx-t :sparkles: :thumbsup: :sparkles:
:cookie: 324 | @lx-t |http://www.freecodecamp.com/lx-t
Alex T.
@lx-t
Jun 13 2016 06:50
@bankplank It would also return 3 results in case the string is "helloooo hello helloo"
@glnarayana93 What are you using arguments[1] for? You already have pre argument passed to the function.
Markus Kiili
@Masd925
Jun 13 2016 06:52
@glnarayana93 hasOwnProperty tells if the property exists. Here we are interested if the property values are trythy. if(collection[i][pre]){...} tests that (because if has automatic coercion to boolean).
Alex T.
@lx-t
Jun 13 2016 06:52
@bankplank + works for preceding expression. In your case it's o
G Lakshmi Narayana
@glnarayana93
Jun 13 2016 06:54
@lx-t thanks
CamperBot
@camperbot
Jun 13 2016 06:54
glnarayana93 sends brownie points to @lx-t :sparkles: :thumbsup: :sparkles:
:cookie: 325 | @lx-t |http://www.freecodecamp.com/lx-t
Rabin Shrestha
@jyapujuju
Jun 13 2016 06:54
```js

var Bike = function() {

// Only change code below this line.
var gear = 5;
this.getGear = function(input){
return input;
};
this.setGear = function(input){
return input;
};

};

G Lakshmi Narayana
@glnarayana93
Jun 13 2016 06:54
@Masd925 thanks
modified code

function truthCheck(collection, pre) {
  // Is everyone being true?
  //var a;
  for(var i=0;i<collection.length;i++){
    if(collection[i].hasOwnProperty(pre)){
      if(collection[i][pre]);else return false;
    }
    else return false;
  }
  return true;
}

truthCheck([{"user": "Tinky-Winky", "sex": "male", "age": 0}, {"user": "Dipsy", "sex": "male", "age": 3}, {"user": "Laa-Laa", "sex": "female", "age": 5}, {"user": "Po", "sex": "female", "age": 4}], "age");
CamperBot
@camperbot
Jun 13 2016 06:54
glnarayana93 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: glnarayana93 already gave masd925 points
Rabin Shrestha
@jyapujuju
Jun 13 2016 06:54
whats wrong here
Tam Nguyen
@bankplank
Jun 13 2016 06:55
@lx-t ah i see. Thanks!
CamperBot
@camperbot
Jun 13 2016 06:55
bankplank sends brownie points to @lx-t :sparkles: :thumbsup: :sparkles:
:warning: bankplank already gave lx-t points
Alex T.
@lx-t
Jun 13 2016 06:55
@glnarayana93 Try using logical not operator !. It would simplify your if statement.
Rabin Shrestha
@jyapujuju
Jun 13 2016 06:56
var Bike = function() {

  // Only change code below this line.
  var gear = 5;
  this.getGear = function(input){
    return input;
  };
  this.setGear = function(input){
    return input;
  };

};
Markus Kiili
@Masd925
Jun 13 2016 06:56
@glnarayana93 Slightly simplified code:
function truthCheck(collection, pre) {
  // Is everyone being true?
  for(var i=0;i<collection.length;i++){
      if(!collection[i][pre]) return false;
  }
  return true;
}
Basic loop logic for testing if many things are true. You could also use built-in .every() method instead.
function truthCheck(collection, pre) {
  return collection.every(function(obj){
    return obj[pre];
  });
}
G Lakshmi Narayana
@glnarayana93
Jun 13 2016 07:00
@Masd925 have a small doubt
when do we use every and forEach?
Rabin Shrestha
@jyapujuju
Jun 13 2016 07:01
@glnarayana93 can you make a question clear?
Markus Kiili
@Masd925
Jun 13 2016 07:02
@glnarayana93 Foreach runs the given function once for every array element. Every runs the given function once for every element and returns a boolean indicating whether all the return values are truthy.
@glnarayana93 Because there are map/filter/reduce methods, forEach is actually quite rarely used.
Alex T.
@lx-t
Jun 13 2016 07:03
@Masd925 Thanks! I didn't know that there's every function in JavaScript.
CamperBot
@camperbot
Jun 13 2016 07:03
lx-t sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1844 | @masd925 |http://www.freecodecamp.com/masd925
G Lakshmi Narayana
@glnarayana93
Jun 13 2016 07:03
@Masd925 thanks
CamperBot
@camperbot
Jun 13 2016 07:03
glnarayana93 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: glnarayana93 already gave masd925 points
Markus Kiili
@Masd925
Jun 13 2016 07:05
@glnarayana93 At some point it is good to go through all the array methods so you don't implement the wheel again https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
Rabin Shrestha
@jyapujuju
Jun 13 2016 07:05
var Bike = function() {

  // Only change code below this line.
  var gear = 5;
  this.getGear = function(x){
    return x;
  };
  this.setGear = function(x){
    return x;
  };

};

var myCar = new Car();

var myBike = new Bike();
G Lakshmi Narayana
@glnarayana93
Jun 13 2016 07:06
@Masd925 ok
thanks for the suggestion
will go through
CamperBot
@camperbot
Jun 13 2016 07:06
glnarayana93 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: glnarayana93 already gave masd925 points
Markus Kiili
@Masd925
Jun 13 2016 07:06
@jyapujuju Those methods should return gear and assign to gear.
Rabin Shrestha
@jyapujuju
Jun 13 2016 07:09
var Bike = function() {

  // Only change code below this line.
  var gear = 5;
  this.getGear = function(gear){
    return gear;
  };
  this.setGear = function(gear){
    return gear;
  };

};

var myCar = new Car();

var myBike = new Bike();
is it the way?
where did i mistake
Wiesiek
@Wiesiek2811
Jun 13 2016 07:10

Hi, I hope someone will be able to help me

challenge = Encode the following sequence, separated by spaces:
backslash tab tab carriage-return new-line and assign it to myStr

my code:

var myStr = "\backslash\ \ttab\t \ttab\t \rcarriage-return\r \nnew-line\n";

Markus Kiili
@Masd925
Jun 13 2016 07:10
@jyapujuju setGear should assign = the parameter to the private variable gear. Don't use same name for private variable and method parameter. You use gear on two meanings there. The private variable gets shadowed inside the method.
Coy Sanders
@coymeetsworld
Jun 13 2016 07:12
@Wiesiek2811 you need to remove the words and replace them with the symbols in myStr
you have both in there
Rabin Shrestha
@jyapujuju
Jun 13 2016 07:13
var Bike = function() {

  // Only change code below this line.
  var gear = 5;
  this.getGear = function(x){
     gear = x;
    return gear;
  };
  this.setGear = function(x){
    gear = x;
    return gear;
  };

};
how about now?
Markus Kiili
@Masd925
Jun 13 2016 07:13
@jyapujuju Setgear need not return anything, and getGear should just return, not assign. Both methods do one thing.
Layne Williams
@SharkMan319
Jun 13 2016 07:14
For the Exact Change challenge my code returns: [["QUARTER",0.5]]
But it wants: [["QUARTER", 0.50]]???
And it won't pass
Markus Kiili
@Masd925
Jun 13 2016 07:15
@SharkMan319 The last one should be a number. Is it so in your return?
Layne Williams
@SharkMan319
Jun 13 2016 07:16
@Masd925 Yes
But it always removes the 0's after the decimal point
Rabin Shrestha
@jyapujuju
Jun 13 2016 07:16
var Bike = function() {

  // Only change code below this line.
  var gear = 5;
  this.getGear = function(x){
     gear = x;
    return gear;
  }; 
  this.setGear = function(){

  };

};
:D
Markus Kiili
@Masd925
Jun 13 2016 07:16
@SharkMan319 Those zeros don't matter if the number is correct.
Subh Samal
@subhsamal
Jun 13 2016 07:17
@ndburrus Sry buddy, I was away..Trying to figure it out.
Markus Kiili
@Masd925
Jun 13 2016 07:17
@SharkMan319 Post the code please.
Eli
@elisspace
Jun 13 2016 07:19
for the wikipedia challenge: do you suggest using .ajax or .getJSON ?
Rabin Shrestha
@jyapujuju
Jun 13 2016 07:19
is that okay?
@Masd925
Markus Kiili
@Masd925
Jun 13 2016 07:19
@elisspace The latter is a shorthand, so either.
Layne Williams
@SharkMan319
Jun 13 2016 07:20
@Masd925 That's what i thought. But it's not passing. Alright hold on. I have to warn you my code is not pretty haha.
Markus Kiili
@Masd925
Jun 13 2016 07:20
@SharkMan319 My code also shows it as 0.5 and passes, so most likely something else is wrong.
Eli
@elisspace
Jun 13 2016 07:21
okay, thanks. I've been trying both and seem to be missing something major.
wikiEndpoint = "https://en.wikipedia.org/w/api.php";
function searchWiki(searchQuery){

  $.ajax( {
    url: wikiEndpoint,

    data: {
      format: 'json',
      action: 'opensearch',
      search: searchQuery
    },
    dataType: 'json',
    contentType: "application/json; charset=utf-8",
    async: false,
    headers: { 'Api-User-Agent': 'www.elis.space Wiki Viewer/0.1' }
    })

      .done (function ( data ){
        console.log("ajax done")
      })
      .fail (function(XMLHttpRequest, textStatus, errorThrown) {
        console.log("errorThrown: " + errorThrown + " textStatus: " + textStatus + " XHR: " + XMLHttpRequest)
      })

      .always (function(data){
        console.log("ajax always")
  });

}
If you see any reason I never get the "ajax done" message to show up I'd be greatly appreciative!
@Masd925 I know my code is FAR from ideal haha
Eli
@elisspace
Jun 13 2016 07:25
and thanks for the answer @Masd925 !
CamperBot
@camperbot
Jun 13 2016 07:25
elisspace sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1845 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Jun 13 2016 07:26
@SharkMan319 You cannot use global variables like arr there. Usually tests won't work.
Jason Keenan
@raavin
Jun 13 2016 07:28
@elisspace are you looking in the console or are you expecting it on screen??
Layne Williams
@SharkMan319
Jun 13 2016 07:30
@Masd925 Ok. How do I fix this? I can't declare it inside of getChange because its recursive, right?
Markus Kiili
@Masd925
Jun 13 2016 07:31
@SharkMan319 You can alway do a wrapper function and recursive function as inner function.
Jason Keenan
@raavin
Jun 13 2016 07:31
@elisspace Oh, and it looks like you don't have a complete query. You need a callback to make it work and, by the way, opensearch doesn't do a full search. It will only find things that start with the search query.
Layne Williams
@SharkMan319
Jun 13 2016 07:32
@Masd925 Oh thats a good idea... i'll try it.
Jason Keenan
@raavin
Jun 13 2016 07:32
@elisspace I just used getJSON with &callback=? at the end. Use action=query instead of opensearch. I can post my query if you get stuck.
Jason Keenan
@raavin
Jun 13 2016 07:38
@elisspace actually, I looked at my code and I did use opensearch for the autocomplete but query for the actual search. Can't remember why. If you use dataType: "jsonp" and format': "json" you should be ok
Markus Kiili
@Masd925
Jun 13 2016 07:40
@raavin Should the async be true there? In the code it is set to false.
Jason Keenan
@raavin
Jun 13 2016 07:43
@Masd925 Mmmm, not sure. I didn't have it in my code so I think leaving it out will just default. Not sure what it defaults to though. I imagine true considering it's ajax
Markus Kiili
@Masd925
Jun 13 2016 07:47
@raavin Yes default is true.
@raavin With jsonp I think false is impossible.
Jason Keenan
@raavin
Jun 13 2016 07:49
@Masd925 To be honest, I'm not all over the difference :( need to read a bit more
Eli
@elisspace
Jun 13 2016 07:58
thanks @raavin -- lots of things to work on
CamperBot
@camperbot
Jun 13 2016 07:58
elisspace sends brownie points to @raavin :sparkles: :thumbsup: :sparkles:
:cookie: 364 | @raavin |http://www.freecodecamp.com/raavin
Eli
@elisspace
Jun 13 2016 08:10
if you don't mind @raavin I would appreciate you posting your query. I think my issue was not understanding callbacks
Jim Dennis
@JimDennis
Jun 13 2016 08:12

I'm trying to figure out how to remove or "hide" an SVG path element after I've displayed it. Ultimately I'd like to be able to display it on one click (mostly works ... but seems to take two clicks for now. :worried: ) then hide it on another, and redraw it (with the stroke animation) on yet another ... and so on).

Here's the code: http://codepen.io/JimD/pen/pbyRXW

(Hmmm ... the "Run Pen" option in line to this chat ... and clicking on the "[Show Solution] button, twice, doesn't show the solution. But it does in my browser on the same CodePen page). :frowning: )
Alex T.
@lx-t
Jun 13 2016 08:23
@JimDennis CodePen says: "You don't need a DOCTYPE on CodePen. Just put here what you would normally put in the <body>."
Jim Dennis
@JimDennis
Jun 13 2016 08:23
Yeah, I remember that now.
I pasted that code in from Brackets ... where I'd been testing it in my own environment.
I pasted this once before ... then I forked this one off that and pasted over all of it.
Alex T.
@lx-t
Jun 13 2016 08:26
@JimDennis Problems with embedded pens here would be caused by mixed http and https links in your html.
Jim Dennis
@JimDennis
Jun 13 2016 08:27
Ahh. Okay, let me look at that ... though I don't think I have any explicit http links other than the JavaScript namespace declaration
Okay, I've removed the <DOCTYPE ...> and changed all http:// into https://
Let's try pasting it again: https://codepen.io/JimD/pen/pbyRXW
Jim Dennis
@JimDennis
Jun 13 2016 08:33
Nope. Still doesn't work here. And now it now longer works in CodePen (from HTTPS:// load).
Bar Akiva
@Gitity
Jun 13 2016 08:33
Hello. I am not American - what is mad libs? I am in Word Blanks lesson
Alex T.
@lx-t
Jun 13 2016 08:34
@JimDennis Remove JS from HTML pane and place it into JS pane
@JimDennis JavaScript in HTML pane does not work
Jim Dennis
@JimDennis
Jun 13 2016 08:35
I can ... but that it works in CodePen if I change line 93 back to http://
I beg to differ. It works for me in this Pen ... when I'm in the browser. Just not here in the inline, nor when I changed that useElement = line to https://
Blauelf
@Blauelf
Jun 13 2016 08:36
@Gitity Also not American... How I understand it it is a text with blanks where you are meant to input some specific kind of word (an adjective, a noun, ...) without knowing the text when choosing the words (just knowing their types, adjective, noun). As the text and the words form some kind of valid sentence that makes little sense, it is meant to be funny.
Alex T.
@lx-t
Jun 13 2016 08:37
@JimDennis Hm. I've never tried to put CSS and JS into HTML pane, because they're not HTML
Jim Dennis
@JimDennis
Jun 13 2016 08:38
Well, they are supported in browsers within <style> tags and attributes, and <script> tags.
So, in CodePen, after I paste my JS into its own pane, how do I refer to it in my <script src=""> tag?
Oh, it seems to have done that automagically.
Alex T.
@lx-t
Jun 13 2016 08:42
@JimDennis JavaScript code in JS pane is simply the code you put in between script tags in your HTML code. If you want to use <script src=""> use gear icon in your JS pane and add script links there
Jim Dennis
@JimDennis
Jun 13 2016 08:42
Still works (albeit not quite as I want, but the same as I get on my local system) from the CodePen site; still doesn't work from those inline pastes ... trying re-run and clicking on the button a couple times.
Yeah, it's running the JS code I pasted into the JS pane ... apparently at the point where I left just the empty <script></script> container in my HTML.
Alex T.
@lx-t
Jun 13 2016 08:45
@JimDennis You can safely remove the empty <script></script> part from HTML
@JimDennis Is it supposed to draw lines between the dots?
@JimDennis Or is it supposed to draw the lines when I click the button?
Jim Dennis
@JimDennis
Jun 13 2016 08:48
It's supposed to show an animated line path drawn across the dots, in four strokes, starting in the lower left, diagonally up to the other corner, then leftward past the left corner, then downward, diagonally crossing just two more dots and finally upward back to the upper right corner.
After you click the button twice.
(The "twice" is a bug ... and I'll appreciate any hint to fixing that ... but for now it's twice).
I'll leave in the script tag as a placeholder for when the resulting code is pasting back out of CodePen and put into any other environment ... unless I need to <!-- ... --> comment it out.
Alex T.
@lx-t
Jun 13 2016 08:52
@JimDennis It doesn't show anything for me even if I click the button more than twice.
naassi
@naassi
Jun 13 2016 08:53
Can anyone recommend a good site for learning javascript? i have tried treehouse and pluralsight, want to find something different(not code school)?
Levi
@MalangeLevi
Jun 13 2016 08:54
@naassi the best way to learn is by getting involved with projects, you need to code, there is no other way, practice pratice...
Stephen
@stephepush
Jun 13 2016 08:54
I am working on the mutations algo. I'm stuck. I want to split array[1] into characters, and iterate them through indexOf. Is that a good idea or should I start from scratch?
//mutations attempt
function mutation(arr) {
  var newArr = [];
  for (var i = 0; i < arr.length; i++){
    arr[i]=arr[i].toLowerCase();
    var split = arr[1].split(", ");
  }

  console.log(arr);
  console.log(split);


console.log(arr[1].indexOf(arr[0]));

}

mutation(["Mary", "Army"]);
naassi
@naassi
Jun 13 2016 08:56
@MalangeLevi Yea definatley, there is so much to learn with javascript, I have been leaning for about a year and i get the basics but stuck in a rut now
Stephen
@stephepush
Jun 13 2016 08:57
it seems that if you run a simple indexOf of the element themselves ([1].indexOf([0]), you'll get false even if both elements contain the same letters
Markus Kiili
@Masd925
Jun 13 2016 08:58
@stephepush Just pick the arr elements to variables and lowercase them. Loop through second string characters and use indexOf to check if it is found on the first string.
Jim Dennis
@JimDennis
Jun 13 2016 08:58
@lx-t Hmmm ... what browser are you using? Definitely works in my copy of Chrome.
Eli
@elisspace
Jun 13 2016 08:58
@naassi Check out CodeTriage www.codetriage.com to find a project you can hop on
Blauelf
@Blauelf
Jun 13 2016 08:58
@stephepush While you could split the string on the empty string (.split("")), you can also iterate the characters in strings, as strings are array-like (have length property and numeric indices). They also have their own implementation of indexOf, which checks for substrings (but if you use that with individual characters, it behaves the same)
Alex T.
@lx-t
Jun 13 2016 08:59
@JimDennis Firefox. Is your script supposed to change <use> tag in <svg> when I click the button?
Stephen
@stephepush
Jun 13 2016 08:59
ah, okay @Markus Kiili. To add on to what you're saying before I try, if i separate the elements into variables they become strings, right?
naassi
@naassi
Jun 13 2016 08:59
@elisspace Thanks, I'll have a look at that
CamperBot
@camperbot
Jun 13 2016 08:59
naassi sends brownie points to @elisspace :sparkles: :thumbsup: :sparkles:
:cookie: 253 | @elisspace |http://www.freecodecamp.com/elisspace
Markus Kiili
@Masd925
Jun 13 2016 08:59
@stephepush Yes arr[0] is a string etc.
Jim Dennis
@JimDennis
Jun 13 2016 08:59
It's supposed to add a <use> button.
Stephen
@stephepush
Jun 13 2016 09:00
cool, thanks @Masd925
CamperBot
@camperbot
Jun 13 2016 09:00
stephepush sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1846 | @masd925 |http://www.freecodecamp.com/masd925
Stephen
@stephepush
Jun 13 2016 09:00
and thanks, @Blauelf
CamperBot
@camperbot
Jun 13 2016 09:00
stephepush sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 1987 | @blauelf |http://www.freecodecamp.com/blauelf
Jim Dennis
@JimDennis
Jun 13 2016 09:00
After dynamically creating it in JS and adding the href and class attributes to it.
Anyway, I'm done for this morning.
Levi
@MalangeLevi
Jun 13 2016 09:04
@naassi you need to get involved in something friend unless you start you own project with the goal to take the world by storm, just like bootstrap project, started very simple now is a worldwide platform
Tymon
@Tymon555
Jun 13 2016 09:12
hi all :) I've got a small question. As I meddle in first algorithm challenges now, I try to use replace
Alex T.
@lx-t
Jun 13 2016 09:12
This message was deleted
Tymon
@Tymon555
Jun 13 2016 09:13
replaceAll function, but I have such error: TypeError: str.replaceAll is not a function
in 'str=str.replaceAll("[^a-zA-Z0-9]", "");'
Markus Kiili
@Masd925
Jun 13 2016 09:18
@Tymon555 There is no replaceAll method in JS.
@Tymon555 Use .replace() and /g .
Blauelf
@Blauelf
Jun 13 2016 09:19
@Tymon555 You can add the g flag to a regex (g for global).
Also, "[^a-zA-Z0-9]" is not a regex, regex literals are enclosed in / and optionally followed by flags, for example /\d[a-z]/i would match a digit followed by an upper- or lowercase (i means case-insensitive) latin character.
Stephen
@stephepush
Jun 13 2016 09:25
All the true statements pass, none of the false ones are though.
function mutation(arr) {
 //mutations attempt

  var zero = arr[0].toLowerCase();
  var first = arr[1].toLowerCase();

for (var i = 0; i < first.length; i++){
    arr = zero.indexOf(first);
}

  return arr <= 0;
}

mutation(["hello", "hey"]);
Tymon
@Tymon555
Jun 13 2016 09:25
/^a-zA-Z0-9/g and this regex searches globally for non-alphanumeric characters?
thanks, @Masd925 @Blauelf
CamperBot
@camperbot
Jun 13 2016 09:26
tymon555 sends brownie points to @masd925 and @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 1847 | @masd925 |http://www.freecodecamp.com/masd925
:star2: 1988 | @blauelf |http://www.freecodecamp.com/blauelf
Markus Kiili
@Masd925
Jun 13 2016 09:27
@stephepush If the character is not found, return false. After loop return true. Basic loop logic for checking if many things are true.
Chris19384
@Chris19384
Jun 13 2016 09:29
@stephepush you're using a for loop without actually using your i variable :smirk:
Stephen
@stephepush
Jun 13 2016 09:30
how do I use the i variable, then?
Markus Kiili
@Masd925
Jun 13 2016 09:30
@stephepush Use first.charAt(i) for getting the character.
Blauelf
@Blauelf
Jun 13 2016 09:30
@Tymon555 You forgot the [] in that regex you posted
Blauelf @Blauelf feels slightly annoyed by the name autocomplete
Jason Keenan
@raavin
Jun 13 2016 09:33
@elisspace Hey, I don't know if you had your questions answered but here is my query. Sorry 'bout my tardiness, was having dinner :) 'https://en.wikipedia.org/w/api.php?action=query&list=search&format=json&srsearch=' + $("#searchParam").val() + '&callback=?' is my query string for getJSON with #searchParam being the id of my text field.
Chris19384 @Chris19384 thinks that @Blauelf wants to know the algorithm behind
Stephen
@stephepush
Jun 13 2016 09:33
for (var i = 0; i < first.length; i++){
  first.charAt(i);
  arr = zero.indexOf(first);
}
Markus Kiili
@Masd925
Jun 13 2016 09:34
@stephepush if(zero.indexOf(first.charAt(i))===-1){...}
Eli
@elisspace
Jun 13 2016 09:34
@raavin No worries, and thanks for that! I'll give it a shot after work
CamperBot
@camperbot
Jun 13 2016 09:34
elisspace sends brownie points to @raavin :sparkles: :thumbsup: :sparkles:
:cookie: 365 | @raavin |http://www.freecodecamp.com/raavin
Jason Keenan
@raavin
Jun 13 2016 09:35
@elisspace :)
Stephen
@stephepush
Jun 13 2016 09:37
@Masd925 I'm confused, do I put that conditional statement in the for loop or at the end? Or is the whole algorithm going to end with the conditional at the end of the for loop?
Markus Kiili
@Masd925
Jun 13 2016 09:38
@stephepush Inside the loop. It checks whether the character being looped is not found on the first string zero.
@stephepush If you find such character, you can happily return false. After the loop, you know there was no such character, and you can return true.
Nguyễn Quốc Đại
@nqdai1992
Jun 13 2016 09:42
Hello
I'm newbie in JS
and I have a question
How can I update value for a variable by a function (variable is out of function)
Markus Kiili
@Masd925
Jun 13 2016 09:44
@nqdai1992 You can use a global variable.
@nqdai1992 Or you can use an object and pass its reference to the function.
Nguyễn Quốc Đại
@nqdai1992
Jun 13 2016 09:45
Can you give me a example
Mohammed Ali
@deeqoo
Jun 13 2016 09:45
hi fellow campers, hope you all having fun coding
Stephen
@stephepush
Jun 13 2016 09:45
mutation(["hello", "hey"]); still returns true
function mutation(arr) {
 //mutations attempt

  var zero = arr[0].toLowerCase();
  var first = arr[1].toLowerCase();

for (var i = 0; i < first.length; i++){
  if(zero.indexOf(first.charAt(i))===-1){
    return false;
    } else {
      return true;
    }
}

}

mutation(["hello", "hey"]);
Mohammed Ali
@deeqoo
Jun 13 2016 09:45
morning/afternoon evening - wherever you are
Markus Kiili
@Masd925
Jun 13 2016 09:46
@nqdai1992
var str = "cat";

function doggy () {
    str = "dog";
}
console.log(str); // "cat"
doggy();
console.log(str); // "dog"
Nguyễn Quốc Đại
@nqdai1992
Jun 13 2016 09:47
thanks @Masd925
CamperBot
@camperbot
Jun 13 2016 09:47
nqdai1992 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1848 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Jun 13 2016 09:49
@nqdai1992 Another way
var container = ["cat"];

function doggy (arr) {
    arr[0] = "dog";
}
console.log(container[0]); // "cat"
doggy(container);
console.log(container[0]); // "dog"
Mohammed Ali
@deeqoo
Jun 13 2016 09:49
I could use some helps guys, Return Early Pattern for Functions - I don't really understand what the question is asking? Instructions
Modify the function abTest so that if a or b are less than 0 the function will immediately exit with a value of undefined.

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

// Only change code above this line

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

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

kirbyedy
@kirbyedy
Jun 13 2016 09:50
@deeqoo if a or b are less than 0 the function will exit with a value of undefined
Markus Kiili
@Masd925
Jun 13 2016 09:51
@deeqoo Make an if test as asked and return undefined;
Mohammed Ali
@deeqoo
Jun 13 2016 09:51

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

// Only change code above this line

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

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

you mean like use if statement to check if a and b > than zero?
Nguyễn Quốc Đại
@nqdai1992
Jun 13 2016 09:52
@Masd925 Thank for your help. I have one more question, I feel it is complex and I'll show my code. Can you help me ? D
CamperBot
@camperbot
Jun 13 2016 09:52
nqdai1992 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: nqdai1992 already gave masd925 points
Mohammed Ali
@deeqoo
Jun 13 2016 09:52
then what shal i return @Masd925
Stephen
@stephepush
Jun 13 2016 09:53
@deeqoo , you just return undefined
you're just writing out a conditional version of the what the problem is asking you @deeqoo
Markus Kiili
@Masd925
Jun 13 2016 09:53
@nqdai1992 Sure.
Nguyễn Quốc Đại
@nqdai1992
Jun 13 2016 09:54
var URL='notthing'
var main = function(URL){
        navigator.geolocation.getCurrentPosition(function(pos){
            var lat=pos.coords.latitude
            var lon=pos.coords.longitude
                console.log(lat,lon)
                URL="https://maps.googleapis.com/maps/api/geocode/json?latlng="+lat+","+lon+"&key=AIzaSyDUzOoDTivFqJh2KC8PtvTr5G4MMquf5f4";
            return URL
});
     }
This my code and I want to update value for URL. I don't want excute many code in "navigator.geolocation.getCurrentPosition(function(pos)"
Stephen
@stephepush
Jun 13 2016 09:54
@deeqoo , write the following as a conditional statement:
if a or b are less than 0 the function will immediately exit with a value of undefined
Mohammed Ali
@deeqoo
Jun 13 2016 09:56
@stephepush Thanks, I was going the wrong way.. it worked.. @Masd925 thank you as well
CamperBot
@camperbot
Jun 13 2016 09:56
deeqoo sends brownie points to @stephepush and @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1849 | @masd925 |http://www.freecodecamp.com/masd925
:warning: could not find receiver for stephepush
Stephen
@stephepush
Jun 13 2016 09:56
welcome, @deeqoo
Markus Kiili
@Masd925
Jun 13 2016 09:59
@nqdai1992 Would it work if you just remove the function parameter and inside assign URL=.... Not sure I understand what you are trying.
Nguyễn Quốc Đại
@nqdai1992
Jun 13 2016 10:01
I want make URL have information about latitude and longitude
Stephen
@stephepush
Jun 13 2016 10:01
Guess I won't be getting anymore help from @Masd925. thanks anyways
CamperBot
@camperbot
Jun 13 2016 10:01
stephepush sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1850 | @masd925 |http://www.freecodecamp.com/masd925
Nguyễn Quốc Đại
@nqdai1992
Jun 13 2016 10:02
and I can use the URL out of that function
Markus Kiili
@Masd925
Jun 13 2016 10:02
@stephepush Return true after the loop.
@nqdai1992 A global variable can be used anywhere on the script (if it is not shadowed by a local variable with the same name).
Stephen
@stephepush
Jun 13 2016 10:07
ah, thats it. Thanks again
its 6:00 AM, think sleep might be a good idea, lol
Markus Kiili
@Masd925
Jun 13 2016 10:08
@stephepush Yes, remember to put the ECMAScript standard under your pillow.
Nguyễn Quốc Đại
@nqdai1992
Jun 13 2016 10:08
yes I know it but when I try update value for a global variable in "navigator.geolocation.getCurrentPosition(function(pos){update a global variable }" and use console.log to view result, it only show "[native code]"
Stephen
@stephepush
Jun 13 2016 10:09
lol, sure will, Masd925
Mohammed Ali
@deeqoo
Jun 13 2016 10:13
ah dear - @stephepush you haven't slept yet ... hard work pays off
Stephen
@stephepush
Jun 13 2016 10:14
haha
night @deeqoo, or morning or maybe good afternoon for you
Mohammed Ali
@deeqoo
Jun 13 2016 10:16
its morning 11am... so you not too far ahead, but I love my sleep too much, no wonder my progress is slow, but thats about to change from now on.... I'm inspired
Kashif Mohammed
@Spyreo
Jun 13 2016 10:34
Hello
Can anyone explain me about word blanks?
Markus Kiili
@Masd925
Jun 13 2016 10:38
@Spyreo You should make a long string (sentence) using those four parameters, and some other words.
Kashif Mohammed
@Spyreo
Jun 13 2016 10:39
Its confusing for me
I dont get it what it wants me to do
Markus Kiili
@Masd925
Jun 13 2016 10:41
@Spyreo For example the function could return "Today a big and smelly dog ran away quickly." if it is invoked with wordBlanks("dog", "big", "ran", "quickly");
@Spyreo So you fill in those four passed words to a string using the function parameters.
Kashif Mohammed
@Spyreo
Jun 13 2016 10:48
Oh
I'm getting some idea
thank you @Masd925
CamperBot
@camperbot
Jun 13 2016 10:52
spyreo sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1851 | @masd925 |http://www.freecodecamp.com/masd925
Waleed Assaf
@Jinxlaw
Jun 13 2016 11:00
i need help
Brendan Kinahan
@BKinahan
Jun 13 2016 11:01
Help is here!
CamperBot
@camperbot
Jun 13 2016 11:01
no wiki entry for: is here
Brendan Kinahan
@BKinahan
Jun 13 2016 11:01
thanks cbot
Waleed Assaf
@Jinxlaw
Jun 13 2016 11:01
ll
lol
not sure what im supposed to do
Brendan Kinahan
@BKinahan
Jun 13 2016 11:05
@waleed39 you are given a number, which you can refer to within the function by the parameter celsius, and you should use that number and some math to calculate the equivalent temperature in degrees fahrenheit, and assign the result to the variable fahrenheit and return that from the function.
@waleed39 the mathematical formula is described in the instructions.
Gustavo Godoy
@imgustavo
Jun 13 2016 11:08
This message was deleted
elvisimeh1
@elvisimeh1
Jun 13 2016 11:12
Help!!! I don't get the Word blank challenge
CamperBot
@camperbot
Jun 13 2016 11:12
no wiki entry for: i dont get the word blank challenge
elvisimeh1
@elvisimeh1
Jun 13 2016 11:13
I don't get the Madlib style Word blanks challenge
Blauelf
@Blauelf
Jun 13 2016 11:13
@elvisimeh1 You are meant to return a string that contains all the words passed as arguments. Those should be individual words in the sentence (does not need to be a sentence, the code does not know English language).
Waleed Assaf
@Jinxlaw
Jun 13 2016 11:13
@BKinahan how am i supposed to type it?
Blauelf
@Blauelf
Jun 13 2016 11:14
Waleed Assaf
@Jinxlaw
Jun 13 2016 11:15
@BKinahan i mean i know that The algorithm to convert from Celsius to Fahrenheit is the temperature in Celsius times 9/5, plus 32. but how do i apply it
Blauelf
@Blauelf
Jun 13 2016 11:15
@waleed39 Create a variable fahrenheit and give it a value that's the temperature passed in celsius converted to degrees Fahrenheit.
John Deegan
@JohnDeegs
Jun 13 2016 11:16
Hi all, can anyone shed some light as to why my click function isn't working? I'm trying to change the background color of my table cell on click. I've looked at stackoverflow's solutions and they even don't work. I'm pretty stumped!
http://codepen.io/JohnDeegs/pen/aZNZwY
elvisimeh1
@elvisimeh1
Jun 13 2016 11:16
@Blauelf Thanks, that was helpful
CamperBot
@camperbot
Jun 13 2016 11:16
elvisimeh1 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 1989 | @blauelf |http://www.freecodecamp.com/blauelf
anjitapanta
@anjitapanta
Jun 13 2016 11:17
Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.
Markus Kiili
@Masd925
Jun 13 2016 11:23
@JohnDeegs Remove the # from the html id attribute value. <td id="#click">x</td> -> <td id="click">x</td>
Nicole Archambault
@sofrlowi
Jun 13 2016 11:27
Morning everyone! I started the Local Weather App last night and tried to embark on it without looking at the code on the example… which led me to HTML5 geolocation to obtain coordinates, which apparently doesn’t work any longer over insecure HTTP. I see people are using an API for that but I’m wondering how they knew to use that one.
I don’t see it mentioned anywhere in the notes or tips.
John Deegan
@JohnDeegs
Jun 13 2016 11:28
@Masd925 Silly mistake, thanks
CamperBot
@camperbot
Jun 13 2016 11:29
johndeegs sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1852 | @masd925 |http://www.freecodecamp.com/masd925
Nicole Archambault
@sofrlowi
Jun 13 2016 11:29
Anyone?
Keone Martin
@Athaman
Jun 13 2016 11:34
@sofrlowi the same way progammers know how to do most things i assume... google it
Sophietica
@Sophietica
Jun 13 2016 11:34
hi all, I have what I think is a quick question: I am doing the palindrome check and using replace(/\W/g, ''). The problem is that one of the exercises has an underscore that isn't included in \W...my googlefu is failing me when I try to find a bracket notation to use instead. Any tips?
Keone Martin
@Athaman
Jun 13 2016 11:35
@anjitapanta were you looking for help with the next in line challenge? have you checked out the .push() and .shift() commands?
Oxide Debbarma
@oxide94Git
Jun 13 2016 11:35
js
function updateRecords(id, prop, value) {
 if(value !== "") { 
    if(prop === "tracks") { 
     /* if(collection[id].prop.hasOwnProperty() === false){
       collection[id][prop] 
      } else */ collection[id][prop].push(value);
    } else collection[id][prop] = value;

} else delete collection[id][prop]; // If it has no value, delete it
return collection;
frnds stuck.. :smile:
Markus Kiili
@Masd925
Jun 13 2016 11:36
@Sophietica You can add _to the regexp using [ ].
Nicole Archambault
@sofrlowi
Jun 13 2016 11:37
@Athaman You know, I figured the same thing. So I did Google it, with several different terms and even a filter of a month since it was only deprecated recently. But the results are scant! For reference, I tried searching for “alternative to html5 geolocation” since this year. I was just surprised.
Thought maybe people were in the know and I wasn’t. :P
Sophietica
@Sophietica
Jun 13 2016 11:38
@Masd925 I'm not sure (read: what I tried didn't work) how to add an extra character in that replace
Nicole Archambault
@sofrlowi
Jun 13 2016 11:38
Even Google’s own doc doesn’t mention any non-paid alternatives besides “convert to HTTPS” and they only offered a paid solution.
Markus Kiili
@Masd925
Jun 13 2016 11:39
@Sophietica str = str.replace(/[\W_]/g,"")
Keone Martin
@Athaman
Jun 13 2016 11:40
@sofrlowi not entirely sure sorry. googling is itself a learnt skill so maybe people just got there through some advanced googlefu. or possibly they asked for help in the helpfrontend channel?
Sophietica
@Sophietica
Jun 13 2016 11:40
@Masd925 Oh I seeeeee...I was putting it in its own little bracket after the \W ! Thank you :D
CamperBot
@camperbot
Jun 13 2016 11:40
sophietica sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1853 | @masd925 |http://www.freecodecamp.com/masd925
Nicole Archambault
@sofrlowi
Jun 13 2016 11:40
could be @athaman. At least I know I didn’t miss some big key thing like FCC adding that note somewhere.
Keone Martin
@Athaman
Jun 13 2016 11:41
@Sophietica https://regex101.com/ is a useful tool for quickly checking your regexes
Nicole Archambault
@sofrlowi
Jun 13 2016 11:41
my googlefu is very strong. :P if I come up in here asking questions, it’s a last ditch effort.
Sophietica
@Sophietica
Jun 13 2016 11:42
@Athaman ooo that looks good. I couldn't for the life of me get the answer I needed out of google angryfist
kirbyedy
@kirbyedy
Jun 13 2016 11:42
@sofrlowi dont believe you :)
Waleed Assaf
@Jinxlaw
Jun 13 2016 11:42
need an example for this please
Keone Martin
@Athaman
Jun 13 2016 11:42
@Sophietica yeah, someone linked it on here ages back and i bookmarked just as quick as i could. been useful on a couple of the challenges.
Nicole Archambault
@sofrlowi
Jun 13 2016 11:42
@kirbyedy lol we all started someplace
Keone Martin
@Athaman
Jun 13 2016 11:42
@waleed39 where are you up to on it?
Ivan Aganin
@criativ
Jun 13 2016 11:42
Hello guys! :)
Keone Martin
@Athaman
Jun 13 2016 11:42
morning
Nicole Archambault
@sofrlowi
Jun 13 2016 11:43
morning @criativ
Ivan Aganin
@criativ
Jun 13 2016 11:43
I have to do the Weather App... no idea where do i get the javascript side of the waether?
Waleed Assaf
@Jinxlaw
Jun 13 2016 11:43
@Athaman no where, stuck looking at the code wondering how to do it
Ivan Aganin
@criativ
Jun 13 2016 11:43
Trying to search it online, but results are poor
Nicole Archambault
@sofrlowi
Jun 13 2016 11:44
@criativ I was just inquiring into that myself, and it looks like the first stops for good results are ipinfo.io (as an alternative to the recently-deprecated-for-HTTP HTML5 geolocation), and the OpenWeather API FCC linked
@criativ I myself was surprised at the lack of search results for an alternative to HTML5 though
Ivan Aganin
@criativ
Jun 13 2016 11:45
hmmm
@sofrlowi thanks :)
CamperBot
@camperbot
Jun 13 2016 11:45
criativ sends brownie points to @sofrlowi :sparkles: :thumbsup: :sparkles:
:cookie: 296 | @sofrlowi |http://www.freecodecamp.com/sofrlowi
Keone Martin
@Athaman
Jun 13 2016 11:45
openweather seems solid for the API, you need a membership (free) but it's stable and user friendly (i used it on an android app)
Waleed Assaf
@Jinxlaw
Jun 13 2016 11:45
@Athaman can you help?
Nicole Archambault
@sofrlowi
Jun 13 2016 11:45
@criativ I’m about to try to make a JSON call to ipinfo and feed those results into the OpenWeather API call :)
Ivan Aganin
@criativ
Jun 13 2016 11:46
@sofrlowi good luck! :)
Nicole Archambault
@sofrlowi
Jun 13 2016 11:46
you too @criativ
Keone Martin
@Athaman
Jun 13 2016 11:46
@waleed39 well, you get the degrees sent into your function as celsius, you need to make a variable call farenheit (or however that's spelt) then set it to equal the input celsius converted with the given formula
Ivan Aganin
@criativ
Jun 13 2016 11:46
I'll need it :)
Nicole Archambault
@sofrlowi
Jun 13 2016 11:46
@criativ haha you got this! 👍
AMAN-KHATRI
@AMAN-KHATRI
Jun 13 2016 11:48

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

// Only change code below this line
var lookup= {
"alpha":
result = "Adams",

 "bravo": 
  result = "Boston",

"charlie": 
  result = "Chicago",

 "delta": 
  result = "Denver",

 "echo": 
  result = "Easy",

 "foxtrot": 
  result = "Frank",

};

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

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

please help me every time the result is coming Frank
Codemzy
@codemzy
Jun 13 2016 11:50
@AMAN-KHATRI you need to include the break (see switch statement syntax)
Keone Martin
@Athaman
Jun 13 2016 11:51
@codemzy it's the lookup challenge so the lookup table shouldn't need breaks
AMAN-KHATRI
@AMAN-KHATRI
Jun 13 2016 11:51
yes
Keone Martin
@Athaman
Jun 13 2016 11:52
@AMAN-KHATRI you don't need to put result = inside the table
it should just be var lookup = {alpha: "Adams", ...
AMAN-KHATRI
@AMAN-KHATRI
Jun 13 2016 11:53
ohk
Codemzy
@codemzy
Jun 13 2016 11:53
@AMAN-KHATRI @Athaman oh sorry my bad, I though you were using a switch statement :laughing:
Keone Martin
@Athaman
Jun 13 2016 11:53
:) they look the same
AMAN-KHATRI
@AMAN-KHATRI
Jun 13 2016 11:53
Let me try for That @Athaman
kirbyedy
@kirbyedy
Jun 13 2016 11:53
I think that challenge was changed :)
Keone Martin
@Athaman
Jun 13 2016 11:53
@AMAN-KHATRI after you finish the table you need to have a single line with result = //something to set it with the lookup table and value
kirbyedy
@kirbyedy
Jun 13 2016 11:54
used to be switch
Keone Martin
@Athaman
Jun 13 2016 11:55
not sure, i've only been around a fairly short time :)
Daniel
@profoundhub
Jun 13 2016 12:01
how is everyone today?
Brendan Kinahan
@BKinahan
Jun 13 2016 12:02
@kirbyedy you might be thinking of another challenge about switch
Shusil Banjade
@shusil123
Jun 13 2016 12:02
Tired... How're you , @profoundhub ?
kirbyedy
@kirbyedy
Jun 13 2016 12:02
@BKinahan am I ?... maybe... getting old :)
Daniel
@profoundhub
Jun 13 2016 12:02
I just woke up, need to get some work done. lol
Oxide Debbarma
@oxide94Git
Jun 13 2016 12:10
hello friends.. how do you add array property to an object .
Dave
@db001
Jun 13 2016 12:10
help seek and destroy
CamperBot
@camperbot
Jun 13 2016 12:10

:point_right: algorithm seek and destroy [wiki]

Algorithm Seek and Destroy

Explanation:

This problem is a bit tricky because you have to familiarize yourself with Arguments, as you will have to work with two or more but on the script you only see two. Many people hardcode this program for three arguments. You will remove any number from the first argument that is the same as any other other arguments.

:pencil: read more about algorithm seek and destroy on the FCC Wiki

Oxide Debbarma
@oxide94Git
Jun 13 2016 12:11
@camperbot js
elvisimeh1
@elvisimeh1
Jun 13 2016 12:11
help jquery
CamperBot
@camperbot
Jun 13 2016 12:11

:point_right: challenge change text inside an element using jquery [wiki]

Change Text Inside an Element Using jQuery

Using jQuery, you can change the text between the start and end tags of an element. You can even change HTML markup.

jQuery has a function called .html() that lets you add HTML tags and text within an element. Any content previously within the element will be completely replaced with the content you provide using this function.

Here's how you would rewrite and italicize the text of our heading:

$("h3").html("<em>jQuery Funhouse</em>");

jQuery also has a similar function called .text() that only alters text without adding tags. So when using .html() please remember that you will be editing the whole markup and not just the text.

:pencil: read more about challenge change text inside an element using jquery on the FCC Wiki

Oxide Debbarma
@oxide94Git
Jun 13 2016 12:13
@camperbot help js
Keone Martin
@Athaman
Jun 13 2016 12:13
@oxide94Git how do you mean add an array property to an object? is it a challenge?
help js
CamperBot
@camperbot
Jun 13 2016 12:13

:point_right: challenge accessing nested arrays in json [wiki]

Challenge Accessing Nested Arrays in JSON

As we have seen in earlier examples, JSON objects can contain both nested objects and nested arrays. Similar to accessing nested objects, Array bracket notation can be chained to access nested arrays.

Here is an example of how to access a nested array:

```javascript
var ourPets = {
"cats": [
"Meowzer",
"Fluffy",
"Kit-Cat"
],
"dogs": [
"Spot",
"Bowser",
"Frankie"
]
};
ourPets.cats[1]; // "Fluffy"
:pencil: read more about challenge accessing nested arrays in json on the FCC Wiki

Shusil Banjade
@shusil123
Jun 13 2016 12:13
@oxide94Git , object { arr: [ 1,2,3 ] , name: "Oxide" }....
Keone Martin
@Athaman
Jun 13 2016 12:13
you don't need to talk at him he just listens to anything starting with help
kirbyedy
@kirbyedy
Jun 13 2016 12:14
help food
CamperBot
@camperbot
Jun 13 2016 12:14
no wiki entry for: food
Keone Martin
@Athaman
Jun 13 2016 12:14
i am quite hungry.
speaking of which, off for food. good day all.
Oxide Debbarma
@oxide94Git
Jun 13 2016 12:16
@shusil123 through some function
Markus Kiili
@Masd925
Jun 13 2016 12:16
@oxide94Git Or obj[prop]=[...];
Diego Herrera
@d-herrera
Jun 13 2016 12:18
hi guys! Need help
Shusil Banjade
@shusil123
Jun 13 2016 12:18
@oxide94Git , just add it like adding other prop-value pairs . var obj = {........ }; , Pass the function argument to the object value, if you need to create an array from the given argument. Or like @Masd925 , said, simple
Diego Herrera
@d-herrera
Jun 13 2016 12:18
myStr should have the escape sequences for backslash tab tab carriage-return new-line separated by spaces
var myStr=' "\" \t \t \r \n';
what Im doing wrong?
Diego Mayer
@Chrono79
Jun 13 2016 12:19
@d-herrera this isn't right: "\"backslash should be escaped too (don't know if you did, because you didn't formatted your code with backticks to paste it in the chat
Blauelf
@Blauelf
Jun 13 2016 12:19
@d-herrera There should not be any " inside your string. They might be used as string literal markers instead of the single ticks, but not inside the string. That should contain only the escape sequences separated by a single space each (no space at beginning or end)
Diego Herrera
@d-herrera
Jun 13 2016 12:21
ok Blauelf let my try and I'll let you know
Blauelf
@Blauelf
Jun 13 2016 12:22
@Chrono79 That first \ is actually a \\, you can see that if you try to quote that message :P
Oxide Debbarma
@oxide94Git
Jun 13 2016 12:22
actually i'm on record collection challenge. and my problem 2 would not tick right.
Blauelf
@Blauelf
Jun 13 2016 12:22
@oxide94Git The one with pushing to nonexistant array? If so, you have to check whether tracks property exists, and if not create it by assigning an array.
Diego Mayer
@Chrono79
Jun 13 2016 12:22
@Blauelf ok, that's good to know, before all start telling him to escape the backslash ;)
Blauelf
@Blauelf
Jun 13 2016 12:23
We should promote the code formatting more, and hope for people to find their ` key or key combo ;)
Diego Mayer
@Chrono79
Jun 13 2016 12:25
now even camperbot isn't using code formating well :(
Oxide Debbarma
@oxide94Git
Jun 13 2016 12:25
@Blauelf yes .. hasOwnProperty() would it work?
Blauelf
@Blauelf
Jun 13 2016 12:26
@oxide94Git Definitely helps here, yes :)
Oxide Debbarma
@oxide94Git
Jun 13 2016 12:26
and the array part?
Blauelf
@Blauelf
Jun 13 2016 12:28
@Chrono79 Some of these problems with @camperbot are that it takes a part of a wiki page while being agnostic to markdown, and that might mean it takes the beginning of a code block, but not its end, so that the markdown would not recognise it as a block.
Ezgi
@ezodd
Jun 13 2016 12:28
Hello
I cannot complete the word blanks step
Diego Mayer
@Chrono79
Jun 13 2016 12:28
Shame on you camperbot :P
Ezgi
@ezodd
Jun 13 2016 12:28

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "";
// Your code below this line

result = myNoun + result + myAdjective +" " + myVerb + " "+ myAdverb;
// Your code above this line
return result;
}

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

Blauelf
@Blauelf
Jun 13 2016 12:28
@oxide94Git tracks property should be an array if you want to push. So make it one if it is not there.
Diego Mayer
@Chrono79
Jun 13 2016 12:29
@ezodd why result in both sides of the assignation?
Also read the Mad Libs link, you're not so far from the solution, but you should add some more words to make a sentence that makes sense
Blauelf
@Blauelf
Jun 13 2016 12:29
@ezodd Have you read the return value of your function? Those words should be separate. "dogbig ran quickly" does not contain "dog" or "big" as individual words.
Oxide Debbarma
@oxide94Git
Jun 13 2016 12:38
@Blauelf @shusil123 @Masd925 @Athaman thank you :smile:
CamperBot
@camperbot
Jun 13 2016 12:38
oxide94git sends brownie points to @blauelf and @shusil123 and @masd925 and @athaman :sparkles: :thumbsup: :sparkles:
:star2: 1990 | @blauelf |http://www.freecodecamp.com/blauelf
:star2: 1854 | @masd925 |http://www.freecodecamp.com/masd925
:cookie: 448 | @athaman |http://www.freecodecamp.com/athaman
:cookie: 419 | @shusil123 |http://www.freecodecamp.com/shusil123
Oxide Debbarma
@oxide94Git
Jun 13 2016 12:39
wooho i'm feeling like a tarzan now... :smile: :smile:
himanshu mittal
@himanshu081996
Jun 13 2016 12:40
algorithm for palindrome??
Rizwan Ahmed
@rizwanahmed19
Jun 13 2016 12:40

I want some help with regular expressions
Consider this code:

       var testString = "In 1998 he developed the software v2.0 that would have run on it.";


        var expressionToGetSoftware = /\d+/gi;
        var softwareCount = testString.match(expressionToGetSoftware).length;
          alert(softwareCount);

I should be getting 6 cuz there are 6 digits instead I'm getting 3

Stephen James
@sjames1958gm
Jun 13 2016 12:41
@rizwanahmed19 \d+ will select multiple digits - so 1998 - is probably getting selected as 1 item
Tbuglc
@tbuglc
Jun 13 2016 12:42
@rizwanahmed19 : I'm also getting stuck there
Markus Kiili
@Masd925
Jun 13 2016 12:42
@himanshu081996 Compare first and last characters. If they are equal repeat for next characters inwards. Or split into an array and reverse and join, and compare to the original.
Stephen James
@sjames1958gm
Jun 13 2016 12:42
@rizwanahmed19 \d will select individual digits and the g flag will select them
Rizwan Ahmed
@rizwanahmed19
Jun 13 2016 12:42
So the + will treat a string od digits as one digit?
himanshu mittal
@himanshu081996
Jun 13 2016 12:42
how to remove dot from string
Anne Kuhnen
@annegivings
Jun 13 2016 12:42
Hello all! Perhaps someone can help me find what I am missing in the lesson for "use objects for lookups"? I am not exactly sure what to set the result equal to in order to have it return the correct value for a given input. Right now it just gives the entire list rather than the value requested. Here's what it looks like...
function phoneticLookup(val) {
  var result = "";
  var lookup = {
    "alpha": "Adams",
    "bravo": "Boston",
    "charlie": "Chicago",
    "delta": "Denver",
    "echo": "Easy",
    "foxtrot": "Frank",
  };
  result = lookup;
  return result;
}
phoneticLookup("charlie");
Diego Mayer
@Chrono79
Jun 13 2016 12:42
@himanshu081996 remember to lowercase all first, A is not the same as a
Rizwan Ahmed
@rizwanahmed19
Jun 13 2016 12:43
@sjames1958gm So the + will treat a string of digits as one digit?
Stephen James
@sjames1958gm
Jun 13 2016 12:43
@rizwanahmed19 + means 1 or more of the previous character (which in this case is \d or digit)
Diego Mayer
@Chrono79
Jun 13 2016 12:43
@annegivings result = lookup; <- this isn't right, you should return only a property value, not the whole object
Markus Kiili
@Masd925
Jun 13 2016 12:43
@annegivings Access the object with syntax obj[key] and assign it to result. What is the object and where lurks the key?
Stephen James
@sjames1958gm
Jun 13 2016 12:43
@rizwanahmed19 It will treat a string of digits as one match.
himanshu mittal
@himanshu081996
Jun 13 2016 12:43
yeah i did this but im getting stuck with string == "A man, a plan, a canal. Panama"
Anne Kuhnen
@annegivings
Jun 13 2016 12:43
Yes I realize but I've tried several options to no avail
Rizwan Ahmed
@rizwanahmed19
Jun 13 2016 12:44
@sjames1958gm Thanks man :smile:
CamperBot
@camperbot
Jun 13 2016 12:44
rizwanahmed19 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1542 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Diego Mayer
@Chrono79
Jun 13 2016 12:44
@annegivings how do you access an object's property value?
Anne Kuhnen
@annegivings
Jun 13 2016 12:46
lookup.val
??
Well no that didn't work either
Diego Mayer
@Chrono79
Jun 13 2016 12:46
@annegivings close but no, review the difference between dot and bracket notation
Patrick Metzdorf
@batjko
Jun 13 2016 12:46
or myObject['theObjPropImLookingFor']
Anne Kuhnen
@annegivings
Jun 13 2016 12:47
Oh wow-- @Chrono79 why does it need to be brackets instead of a dot?
Markus Kiili
@Masd925
Jun 13 2016 12:47
@annegivings The dot notation only works if the property key string is a valid JS identifier (for example "12" and "lives left" are not) and you write the key after the dot: var cat={clothes:"pants", "lives left":3}; cat.clothes; //returns "pants". Bracket notation works with keys that can be arbitrary strings cat["lives left"]; //returns 3, variables var key="clothes"; cat[key]; //returns "pants", or expressions cat["lives"+" "+"left"]; //returns 3.
So dot notation only works on one case. Bracket notation is more general way.
Anne Kuhnen
@annegivings
Jun 13 2016 12:48
Awesome! Alright thanks @Chrono79 and @Masd925 for your help :smile:
CamperBot
@camperbot
Jun 13 2016 12:48
annegivings sends brownie points to @chrono79 and @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1129 | @chrono79 |http://www.freecodecamp.com/chrono79
:star2: 1855 | @masd925 |http://www.freecodecamp.com/masd925
Patrick Metzdorf
@batjko
Jun 13 2016 12:49
Nobody in their right mind uses object keys with spaces in them anyway. The real use case of bracket notation is when you don't know the key (because you have it returned dynamically in some variable), then using that variable is very powerful and this cannot be done using dot notation.
himanshu mittal
@himanshu081996
Jun 13 2016 12:51
how can i remove puctuation and symbals from my string?
Diego Mayer
@Chrono79
Jun 13 2016 12:52
with a proper regex @himanshu081996, and using replace
help regex
CamperBot
@camperbot
Jun 13 2016 12:52

:point_right: js regex resources [wiki]

Regular Expressions Resources

Links to useful RegEx resources.

See also: :clipboard: Tutorials | :syringe: Testing | :soccer: Games | :newspaper: Blogs | :package: Software

:pencil: read more about js regex resources on the FCC Wiki

Tbuglc
@tbuglc
Jun 13 2016 12:53
This message was deleted
CamperBot
@camperbot
Jun 13 2016 12:53
no wiki entry for: please how can i replace and and with using regex consider this function palindromestr good luck var newstring strtolowercase newstringreplaces gi var newarrstr strsplit var newarrstrrev newstringsplitreverse var boolchecker forvar i 0 inewarrstrlength i boolchecker false if newarrstri newarrstrrevi break else boolchecker true var x x boolchecker true false return xpalindromeeye eye vs eyi
Tbuglc
@tbuglc
Jun 13 2016 12:54
This message was deleted
greg
@wearenotgroot
Jun 13 2016 12:55
@tbuglc you can try a different regex that captures all non-alphanummeric characters(non digits and non letters) using \W
Diego Mayer
@Chrono79
Jun 13 2016 12:55
you both @tbuglc @himanshu081996 could use a couple of regex expressions to do that, one is to select all that you want to get rid of and replace it with empty string or select what you want to keep and negate that
mangesh1413
@mangesh1413
Jun 13 2016 12:55
// Setup
function abTest(a, b) {
  // Only change code below this line



  // Only change code above this line

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

// Change values below to test your code
abTest(2,2);
Modify the function abTest so that if a or b are less than 0 the function will immediately exit with a value of undefined.
Tbuglc
@tbuglc
Jun 13 2016 12:55
Hey guys, How can I replace "," "." and " " with "" using Regex
consider this code

function palindrome(str) {
  // Good luck!
  var newString = str.toLowerCase();
  newString.replace(/\s+\|.* |,*/gi, "");

  var newArrStr = str.split("");
  var newArrStrRev = newString.split("").reverse();
  var boolChecker;

  for(var i =0; i<newArrStr.length; i++){
    boolChecker = false;
    if( newArrStr[i] !== newArrStrRev[i])
      break;
    else
      boolChecker = true;
  }
   var x;
  x= (boolChecker)? true: false;

  return x;
}



palindrome("eye");
himanshu mittal
@himanshu081996
Jun 13 2016 12:55

function palindrome(str) {
// Good luck!
str=str.replace(/\s+/g, "");
var Str = str.toLowerCase();
var array = Str.split('');
var Array = array.reverse();
var Join = Array.join('');
if (Str===Join)
return true;
else
return false;
}

palindrome("A man, a plan, a canal. Panama");

im getting false
Tbuglc
@tbuglc
Jun 13 2016 12:56
@wearenotgroot : let me try with that
Diego Mayer
@Chrono79
Jun 13 2016 12:56
@himanshu081996 you're only replacing spaces, tabs, another thing I don't remember like that
Stephen James
@sjames1958gm
Jun 13 2016 12:56
@himanshu081996 Whitespace are not all that need to be removed, see the previous discussion.
@Chrono79 Whitespace :)
Diego Mayer
@Chrono79
Jun 13 2016 12:57
I think carriage return and newline too? @sjames1958gm
Stephen James
@sjames1958gm
Jun 13 2016 12:57
@Chrono79 Yeah. unless some other flag is set, and its Tuesday and a full moon.
Brendan Kinahan
@BKinahan
Jun 13 2016 12:58
It's never a full moon on Tuesday, that would be like dividing by zero.
Stephen James
@sjames1958gm
Jun 13 2016 12:59
@sjames1958gm Not dividing by zero is just a conspiracy of big Math like factorial(0) === 1
Mengwa Victor
@vamenssa
Jun 13 2016 12:59

Good day campers. I am stuck, can't go to the next challenge.

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

// Assignments
STUDLYCAPVAR = 10;
PRoperCAmelCAse = "A String";
tITLEcASEoVER = 9000;

studylCapVar = 10;
properCamelCase = "A String";
titleCaseOver = 9000;

Diego Mayer
@Chrono79
Jun 13 2016 13:00
@vamenssa I think you had to rename your vars to match the case
Blauelf
@Blauelf
Jun 13 2016 13:00
@vamenssa I'd guess you are not supposed to duplicate those assignments but to change their spelling to camelCase (declarations and assignments).
Stephen James
@sjames1958gm
Jun 13 2016 13:01
@vamenssa Don't add new lines, just fix the existing ones.
Diego Mayer
@Chrono79
Jun 13 2016 13:01
Instructions
Fix the variable declarations and assignments so their names use camelCase.
Tbuglc
@tbuglc
Jun 13 2016 13:05
@himanshu081996 : could you please help me with your Palindrome code challenge?
it's getting :fire: here!
:smile:
Ali Black
@aliblack89
Jun 13 2016 13:08
Hi, i am on the Caesars Cipher challenge. I'm a bit stuck with what happens when the charcode will be less than 65. Could someone give me a hint? thanks
Stephen James
@sjames1958gm
Jun 13 2016 13:08
@aliblack89 Doesn't it say pass through all non A-Z ?
Stephane
@overmelo
Jun 13 2016 13:09
@aliblack89 paste what u have done so far
Waleed Assaf
@Jinxlaw
Jun 13 2016 13:10
i need help
still cant figure how to solve this
Diego Mayer
@Chrono79
Jun 13 2016 13:11
you have to use the formula they give you @waleed39
Stephen James
@sjames1958gm
Jun 13 2016 13:12
@waleed39 The function definition provides the variable celsius - which is C in the formula - the variable is provided for farhenheit
Ali Black
@aliblack89
Jun 13 2016 13:12
i've not done a lot, i've just looped through the string, added each letter's charCode to an array, and taken away 13 from each of these numbers. (i'm just getting my head around it.) But i have found, if i minus 13 away from 69 (E), this gives me 8, when it should be R @sjames1958gm @overmelo
AlexandruPB
@AlexandruPB
Jun 13 2016 13:12
function palindrome(str) {
  // Good luck!

  theStr = str.replace(/\[W_]/g, '').toLowerCase();
  var reverseStr = str.split("").reverse().join("");

  if(reverseStr === theStr){
    return true;
  }else{
    return false;
  }

}



palindrome("eye");
can't figure it out why this code doesn't work
is from "Check for Palindromes"
Blauelf
@Blauelf
Jun 13 2016 13:13
@AlexandruPB /[\W_]/g, not /\[W_]/g
Diego Mayer
@Chrono79
Jun 13 2016 13:13
@AlexandruPB you're reversing the original dirty string, use the new one, lowercased and clean of all that's not a letter or a number
Waleed Assaf
@Jinxlaw
Jun 13 2016 13:13
@Chrono79 @sjames1958gm i just dont know how to apply everything into the formula
Mengwa Victor
@vamenssa
Jun 13 2016 13:13
Thanks @Chrono79 @sjames1958gm @Blauelf
CamperBot
@camperbot
Jun 13 2016 13:13
vamenssa sends brownie points to @chrono79 and @sjames1958gm and @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 1543 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
:star2: 1130 | @chrono79 |http://www.freecodecamp.com/chrono79
:star2: 1991 | @blauelf |http://www.freecodecamp.com/blauelf
Stephen James
@sjames1958gm
Jun 13 2016 13:14
@aliblack89 A-M add 13 - N-Z subtract all else leave alone
@waleed39 F = C * 9/5 + 32 - substitute the variables provided for F and C
AlexandruPB
@AlexandruPB
Jun 13 2016 13:15
@Blauelf i did the modification, still nothing
Diego Mayer
@Chrono79
Jun 13 2016 13:16
@AlexandruPB did you read what I said?
Blauelf
@Blauelf
Jun 13 2016 13:16
@AlexandruPB Did you also change str.split... to theStr.split...?
Also, you haven't declared theStr (will work here, but at some point it might create odd malfunctioning)
mangesh1413
@mangesh1413
Jun 13 2016 13:17
var count = 0;

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

  switch(card){
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
  return "5 Bet";
      break;

    case 7:
    case 8:
    case 9:
      return "0 Hold";
      break;
    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
     return "-5 Hold";
      break;

    case 3:
    case 7:
    case"Q":
    case 8:
    case "A":
      return "-1 Hold";
      break;
    case 2:
    case "J":
    case 9:
    case 2:
    case 7:
      return "1 Bet";
    break;
    case 3:
    case 2:
    case "A":
    case 10:
      return "-1 Hold";
      break;
  }
  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
CamperBot
@camperbot
Jun 13 2016 13:17
:bulb: to format code use backticks! ``` more info
AlexandruPB
@AlexandruPB
Jun 13 2016 13:17
@Blauelf ooohh, i did that now. Thanks!
CamperBot
@camperbot
Jun 13 2016 13:17
alexandrupb sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 1992 | @blauelf |http://www.freecodecamp.com/blauelf
Diego Mayer
@Chrono79
Jun 13 2016 13:17
@mangesh1413 you have to evaluate card and count separately, that is, don't return when evaluating card, only change count value there
IndiraShrestha
@IndiraShrestha
Jun 13 2016 13:17