These are chat archives for FreeCodeCamp/HelpJavaScript

17th
Apr 2016
Moisés Man
@moigithub
Apr 17 2016 00:00
@micahbales a quick test.. add a letter on the html (on seven or five)
then click
Micah Bales
@micahbales
Apr 17 2016 00:00
@moigithub Yeah, that works, wehen we start with the letter visible
Moisés Man
@moigithub
Apr 17 2016 00:00
soo.. first time.. the letter goes off
second time it shows
Micah Bales
@micahbales
Apr 17 2016 00:01
correct
toggle is wanting to go invisible first.
Moisés Man
@moigithub
Apr 17 2016 00:01
then.. u wanna start with hide first...
Micah Bales
@micahbales
Apr 17 2016 00:02
can I do that while still leaving an option to have either X or O?
I don't want to put X or O in the HTML
Joe Luis Martinez
@Joemartz86
Apr 17 2016 00:02
I keep getting TypeError: [object Array] is not a function.
Any thoughts on how I should approach this?
function destroyer(arr) {

  var whatToTarget = []; // Collection for argument objects not part of the array.

  for (var i = 1; i < arguments.length; i++) {  // Iteration to run through arguments that are not part of 0 indexed arguments.
    whatToTarget.push(arguments[i]);
  }


  var filtered = arr.filter(whatToTarget); // filter collection to return out.

  return filtered;


}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Moisés Man
@moigithub
Apr 17 2016 00:02
$(document).ready(function() {
    $('#seven p').hide();
//....
Micah Bales
@micahbales
Apr 17 2016 00:03
@moigithub That works. I used this to make it work for all the blocks:
Moisés Man
@moigithub
Apr 17 2016 00:03
This message was deleted
Micah Bales
@micahbales
Apr 17 2016 00:04
$('p').hide();
Moisés Man
@moigithub
Apr 17 2016 00:05
i think.. that should work
Micah Bales
@micahbales
Apr 17 2016 00:05
It's because toggle hides first by default?
Moisés Man
@moigithub
Apr 17 2016 00:06
looks like :)
Micah Bales
@micahbales
Apr 17 2016 00:06
(@moigithub thanks, btw)
CamperBot
@camperbot
Apr 17 2016 00:06
micahbales sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star: 938 | @moigithub | http://www.freecodecamp.com/moigithub
Micah Bales
@micahbales
Apr 17 2016 00:06
that's weird.
Moisés Man
@moigithub
Apr 17 2016 00:06
by default ur items are visible
like any html tag
Micah Bales
@micahbales
Apr 17 2016 00:06
right
Thanks, @daemedeor
CamperBot
@camperbot
Apr 17 2016 00:11
micahbales sends brownie points to @daemedeor :sparkles: :thumbsup: :sparkles:
:star: 459 | @daemedeor | http://www.freecodecamp.com/daemedeor
Moisés Man
@moigithub
Apr 17 2016 00:13
@Joemartz86 filter accepts a function as callback... but u passing an array...
Pierre Humberdroz
@phumberdroz
Apr 17 2016 00:16
Hey someone in here that knows react pretty well I might need some help
Moisés Man
@moigithub
Apr 17 2016 00:17
only basic
but ask.. probably might help :)
Pierre Humberdroz
@phumberdroz
Apr 17 2016 00:19

@moigithub
might still be enough
https://gist.github.com/anonymous/ae67840fef0b8e41eeb1481c0b960dbb

This does not work

maybe you have some debugging skills
It is pretty much adapted from the thinking react
I might be doing this in a pretty bad way but yea.. do not know any better
Pierre Humberdroz
@phumberdroz
Apr 17 2016 00:35
@moigithub any idea what I am doing wrong ? I mean maybe it is just the syntax but the error says unexpected : in line 28
but why??
Moisés Man
@moigithub
Apr 17 2016 00:37
when return on render.. or its a single element...
or if multiple.. need to be surrounded inside a container
ie. tihs is wrong
 return (
      <table class="table" id="productstable">
      <thead>
      <tr>
          <th>#</th>
          <th>Product name</th>
          <th>description</th>
          <th>price</th>
          <th></th>
          <th></th>
      </tr>
      </thead>
      <tbody>{rows}</tbody>

  </table> <!-- closing -->
      )
multiple elements
a fix could be CLOSING that table
@meat147
Pierre Humberdroz
@phumberdroz
Apr 17 2016 00:45
@moigithub what did you change? :o
Moisés Man
@moigithub
Apr 17 2016 00:45
i fixed all multiple unclosed render returns

if u have this

render: function(){
   return (
            <div></div>
            <div></div>
            <div></div>
   )
}

it will fail

u need to put in a container
render: function(){
   return (
       <div>  // <<<<<<<<<container
            <div></div>
            <div></div>
            <div></div>
      </div>
   )
}
Pierre Humberdroz
@phumberdroz
Apr 17 2016 00:49
why is that ?
And thanks!
Moisés Man
@moigithub
Apr 17 2016 00:50
cuz JSX is transformed to a function
Pierre Humberdroz
@phumberdroz
Apr 17 2016 00:50
ah jsx okay things i need to get used to
Moisés Man
@moigithub
Apr 17 2016 00:51

so

return (
            <div></div>
            <div></div>
            <div></div>
   )

will be like

return ReactElement createElement(
  string/ReactClass type,
  [object props],
  [children ...]
)
ReactElement createElement(
  string/ReactClass type,
  [object props],
  [children ...]
)
ReactElement createElement(
  string/ReactClass type,
  [object props],
  [children ...]
)
and return only will affect the first one
MikeBeers
@MikeBeers
Apr 17 2016 00:53
I need help
Moisés Man
@moigithub
Apr 17 2016 00:53
but if u put all on 1 container.. its like a IIFE
bitgrower
@bitgrower
Apr 17 2016 00:53
hey @MikeBeers -- what's up ?
MikeBeers
@MikeBeers
Apr 17 2016 00:53
@bitgrower
hi
Pierre Humberdroz
@phumberdroz
Apr 17 2016 00:53
yea I got it.
One last thing is it does not use the classes that we assign in the JSX any special syntax?
MikeBeers
@MikeBeers
Apr 17 2016 00:54
recursion is killing me
Moisés Man
@moigithub
Apr 17 2016 00:54
@meat147 cuz on react instead use class keyword. it use className
MikeBeers
@MikeBeers
Apr 17 2016 00:55
I am trying to test my code with firefox debugger and getting error too much recurtion
bitgrower
@bitgrower
Apr 17 2016 00:56
@mikebeers -- I found an article on the IBM site which helped me ... the main thing is to think about how you will exit the recursive call chain .... because that's got to be the first thing your function checks for ...
MikeBeers
@MikeBeers
Apr 17 2016 00:56
```
function permAlone(str) {
 var arr = str.split("");
 var n = str.length;
 function swap(chars, i, j) {
    var tmp = chars[i];
    chars[i] = chars[j];
    chars[j] = tmp;
 }

  var perms = [];
  var stack = [];

  var doPerm = function(n, arr) {
    if (n === 1) {
      perms.push(arr);
    }

    else {
      for (var i = 0; i < n; i++) {
        doPerm(n -1, arr);
          if (n%2 === 0) {
            swap(arr[i], arr[n-1]);
          }
          else {
            swap(arr[0], arr[n-1]);
          }
      }

      doPerm(n-1, arr);
    }

  };

  doPerms();
  return perms;



}

permAlone('aab');
bitgrower
@bitgrower
Apr 17 2016 00:57
@moitgithub -- I'm trying to follow bostock's tutorials on d3 on codepen, he has code which references a tsv data file, you know how I can reference that in codepen ?
@MikeBeers -- what I said above -- one of the first things your code must do is see if it's time to exit ...
...that is, finally hit the return statement in your function ...
its like a $.getJSON( url, callback)
and url should point to a tsv file
dunno if thats what u asking ? :) (or language barrier problem :P... /me loading the spanish-english translator)
@bitgrower
MikeBeers
@MikeBeers
Apr 17 2016 01:00
after if statement if n === 1 put a return in there
brb
Tyler
@tylergross
Apr 17 2016 01:03
So I am doing the API challenges and am completely confused as to how to set-up the Javascript / JSON in order to do these.... I have an understanding of the API function that is called upon but not sure how to set up the script. Does anyone know any good tutorials or example codes?
I have done a few of the examples on freecodecamp but still do not have a solid grasp on retrieving the data from an API
bitgrower
@bitgrower
Apr 17 2016 01:07
@moigithub -- no, I'm wondering about how to access the tsv file ... I can't upload it to codepen ... didn't know whether it would read a file from dropbox or some other random url ...
Moisés Man
@moigithub
Apr 17 2016 01:08
probably u can upload to ur github... ?
and use a raw url
bitgrower
@bitgrower
Apr 17 2016 01:08
hmm ... I'll try that, thanks, @moigithub
CamperBot
@camperbot
Apr 17 2016 01:08
bitgrower sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star: 939 | @moigithub | http://www.freecodecamp.com/moigithub
bitgrower
@bitgrower
Apr 17 2016 01:09
@tyler -- I didn't either ... I think the main thing is to just go thru them and see what's possible -- then you can go back and play with it more when you get into the 2nd set of web projects (aka "ziplines")
Tyler
@tylergross
Apr 17 2016 01:13
@bitgrower Yeah they look a little advanced for this early on, good advice though I'll continue on and hope to get a better understanding down the line
Moisés Man
@moigithub
Apr 17 2016 01:13
@tylergross to test on client side.. u can use a JSON placeholder
like this http://jsonplaceholder.typicode.com/
http://jsonplaceholder.typicode.com/users
http://myjson.com/
MikeBeers
@MikeBeers
Apr 17 2016 01:27
@bitgrower
have you completed no repeats ?
I am trying to follow heaps algorithm pseudocode but not sure if I am following it correctly.
procedure generate(n : integer, A : array of any):
    if n = 1 then
          output(A)
    else
        for i := 0; i < n - 1; i += 1 do
            generate(n - 1, A)
            if n is even then
                swap(A[i], A[n-1])
            else
                swap(A[0], A[n-1])
            end if
        end for
        generate(n - 1, A)
    end if

my version
```
var doPerm = function(n, arr) {
if (n === 1) {
perms.push(arr);
return;
}

else {
  for (var i = 0; i < n; i++) {
    //doPerm(n -1, arr);
      if (n%2 === 0) {
        swap(arr[i], arr[n-1]);
      }
      else {
        swap(arr[0], arr[n-1]);
      }
  }

 // doPerm(n-1, arr);
}

};

var doPerm = function(n, arr) {
    if (n === 1) {
      perms.push(arr);
      return;
    }

    else {
      for (var i = 0; i < n; i++) {
        //doPerm(n -1, arr);
          if (n%2 === 0) {
            swap(arr[i], arr[n-1]);
          }
          else {
            swap(arr[0], arr[n-1]);
          }
      }

     // doPerm(n-1, arr);
    }

  };
bitgrower
@bitgrower
Apr 17 2016 01:32

have you completed no repeats ?

no ... it's one of the 3 challenges I haven't completed ... and in the updates, I lost my work-in-progress code ... I may go tackle it again in a week or two - but right now I'm kinda pulled into a udemy course, and a d3 tutorial ... (I :heartpulse: data science stuff)

Kevin Galang
@kgalang
Apr 17 2016 01:32
function factorialize(num) {
  var array = [];  
  {for (var i = num; i >= 0; i--) {
    array.push(i);
  }
   return array;}

  array.reduce(function(prevVal, curVal) {
    return prevVal*curVal;
  }, 0);
}

factorialize(5);
can someone tell me why my output is an array still instead of all the indexes of my array multiplied together?
right now I am getting [5,4,3,2,1,0]
changed it to i>0 so now getting 5,4,3,2,1
just want to multiply them all
Erin Heard
@ufi16
Apr 17 2016 01:35
This message was deleted
This message was deleted
Stephen James
@sjames1958gm
Apr 17 2016 01:40
@kgalang Are you wanting to have a single value of the array indexes multiplied together?
Kevin Galang
@kgalang
Apr 17 2016 01:40
@sjames1958gm yes sorry for being unclear
Stephen James
@sjames1958gm
Apr 17 2016 01:41
@kgalang Line 6 is returning an array?
Kevin Galang
@kgalang
Apr 17 2016 01:42
@sjames1958gm yes. I'm getting the correct array that I want. If the input is num=5 then my output from line 6 is [5,4,3,2,1]
MikeBeers
@MikeBeers
Apr 17 2016 01:42
@kgalang When I did this one I set a holder varable of 1 then multiplied from a for loop. Did not set anything in an array
Erin Heard
@ufi16
Apr 17 2016 01:42
i can't figure out how to get it to return the value

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

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

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

Stephen James
@sjames1958gm
Apr 17 2016 01:42
@kgalang Then you need to return the value of the reduce
@kgalang return arr.reduce
MikeBeers
@MikeBeers
Apr 17 2016 01:43
yep that loooks like it would be it
Stephen James
@sjames1958gm
Apr 17 2016 01:43
@MikeBeers There is one more thing...
@MikeBeers After the function you are passing to reduce you have a second parameter
Kevin Galang
@kgalang
Apr 17 2016 01:44
@sjames1958gm I thought I was doing that in line 9 when I put "return prevVal*curVal"?
Stephen James
@sjames1958gm
Apr 17 2016 01:45
@kgalang That only returns a value to the reduce function which becomes the next prevVal
@ufi16 Which challenge
Erin Heard
@ufi16
Apr 17 2016 01:45
Testing Objects for Properties
MikeBeers
@MikeBeers
Apr 17 2016 01:46
would an initial value be needed?
Erin Heard
@ufi16
Apr 17 2016 01:46
@sjames1958gm
Stephen James
@sjames1958gm
Apr 17 2016 01:46
@MikeBeers No, esp. not 0 if you are multiplying
DrewBowzer2016
@DrewBowzer2016
Apr 17 2016 01:46
can anyone please tell me where my spacing needs to be for Escaping Literal Quotes in Strings
MikeBeers
@MikeBeers
Apr 17 2016 01:46
1
Stephen James
@sjames1958gm
Apr 17 2016 01:47
@MikeBeers That would work.
Kevin Galang
@kgalang
Apr 17 2016 01:48
@sjames1958gm @MikeBeers Thanks for your guys help! I am continuing to understand how to do this one but your replies gave me clues
CamperBot
@camperbot
Apr 17 2016 01:48
kgalang sends brownie points to @sjames1958gm and @mikebeers :sparkles: :thumbsup: :sparkles:
:star: 310 | @mikebeers | http://www.freecodecamp.com/mikebeers
:star: 668 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Apr 17 2016 01:48
@ufi16 Your test should test that checkProp is a property of myObj and return the value or return not found
Erin Heard
@ufi16
Apr 17 2016 01:49
so what's my val for the if statement
@sjames1958gm
Stephen James
@sjames1958gm
Apr 17 2016 01:49
From the description on the left .hasOwnProperty() returns true or false if the property is found or not.
MikeBeers
@MikeBeers
Apr 17 2016 01:50
@kgalang what happened when you put return before array.reduce statement?
Erin Heard
@ufi16
Apr 17 2016 01:50
so i don't need an if/else statement then @sjames1958gm
Stephen James
@sjames1958gm
Apr 17 2016 01:51
@ufi16 You do that part is correct, the if should be if myObj.hasOwnProperty(checkProp)
Erin Heard
@ufi16
Apr 17 2016 01:51
so what is inside () for my if
Stephen James
@sjames1958gm
Apr 17 2016 01:52
myObj.hasOwnProperty(checkProp)
Erin Heard
@ufi16
Apr 17 2016 01:52
so this
function checkObj(checkProp) {
if {
myObj.hasOwnProperty(checkProp); // Your Code Here
return myObj[];
}
else {
return "Not Found";
}
}
Kevin Galang
@kgalang
Apr 17 2016 01:52
@MikeBeers it gives me the same output as [5,4,3,2,1]
var array = [4,5,6,7,8];
var singleVal = 0;

// Only change code below this line.
var singleVal = array.reduce(function(val1, val2) {
  return val1 + val2;
}, 0);
I used this as my model because this was "Condense Array" module and it summed up all the numbers in the array
UtkarshShukla7
@UtkarshShukla7
Apr 17 2016 01:54
@ufi16 like this if(myObj.hasOwnProperty(checkProp))
Marco Berardini
@mb0606
Apr 17 2016 01:54
@ufi16 function checkObj(myObj, prop){
if(myObj.hasOwnProperty(prop) {
return true;
} else {
return "Not Found";
}
}
Kevin Galang
@kgalang
Apr 17 2016 01:54
function factorialize(num) {
  var array = [];  
  {for (var i = num; i > 0; i--) {
    array.push(i);
  }
   return array;}

  array.reduce(function(prevVal, curVal) {
    return prevVal*curVal;
  }, 0);
}

factorialize(5);
Here is my current code again @MikeBeers
UtkarshShukla7
@UtkarshShukla7
Apr 17 2016 01:54
@ufi16 then check your return statement
Stephen James
@sjames1958gm
Apr 17 2016 01:55
@ufi16 if(myObj.hasOwnProperty(prop) { - the test goes in the ()
UtkarshShukla7
@UtkarshShukla7
Apr 17 2016 01:55
@ufi16 you have to return that property's value if true
Stephen James
@sjames1958gm
Apr 17 2016 01:56
@kgalang need to remove the return array; and return the value of the reduce without the ,0
Kevin Galang
@kgalang
Apr 17 2016 01:59
@sjames1958gm thank you! lol I feel like I'm getting somewhere
CamperBot
@camperbot
Apr 17 2016 01:59
kgalang sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: kgalang already gave sjames1958gm points
Erin Heard
@ufi16
Apr 17 2016 01:59
it's supposed to return the value of var myObj, if it says true the test won't run
Kevin Galang
@kgalang
Apr 17 2016 01:59
but now it says when the input is 0 the output has to be 1. haha that's frustrating but I'm gonna try to figure this out before I ask again. @sjames1958gm @MikeBeers
Stephen James
@sjames1958gm
Apr 17 2016 02:00
@ufi16 It is supposed to return the value of the property checkProp for myObj
@kgalang Yeah that is a special case that you have to handle
Marco Berardini
@mb0606
Apr 17 2016 02:00
@ufi16 @ufi16 function checkObj(myObj, prop){
if(myObj.hasOwnProperty(prop) {
return myObj[prop] ;
} else {
return "Not Found";
}
}
Erin Heard
@ufi16
Apr 17 2016 02:01
so what should my return be for the if statement, with 'true' it's not running for true
it didn't run for myObj[prop] either
@mb0606
Kevin Galang
@kgalang
Apr 17 2016 02:01
@sjames1958gm @MikeBeers Got it! Just entered an if else statement haha
Stephen James
@sjames1958gm
Apr 17 2016 02:01
@ufi16 The property variable is checkProp not prop
@kgalang :+1:
Erin Heard
@ufi16
Apr 17 2016 02:03
if (myObj.hasOwnProperty(checkProp)) {
return myObj[checkProp];
} //this didn't work either. i'm still confused on what you're saying
Marco Berardini
@mb0606
Apr 17 2016 02:03
@ufi16 the value of the property in and object can be found ... object[name] this will output the value of name in that object
Erin Heard
@ufi16
Apr 17 2016 02:04
if (myObj.hasOwnProperty(checkProp)) {
return myObj[name]; //this didn't work either @mb0606
Stephen James
@sjames1958gm
Apr 17 2016 02:04
@ufi16 = this is my code which looks like yours , except for the correct variable - for the else you return "Not Found"
  if (myObj.hasOwnProperty(checkProp)) {
    return myObj[checkProp];
  }
Marco Berardini
@mb0606
Apr 17 2016 02:05
@ufi16 I am not saying to sub it for name
Erin Heard
@ufi16
Apr 17 2016 02:06
i have it set up that way @sjames1958gm and it won't run. is there something else wrong with my code

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

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

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

UtkarshShukla7
@UtkarshShukla7
Apr 17 2016 02:07
@ufi16
you have forgotten 1 }
@ufi16 after closing else add one more }
Erin Heard
@ufi16
Apr 17 2016 02:08
thank you @UtkarshShukla7
CamperBot
@camperbot
Apr 17 2016 02:08
ufi16 sends brownie points to @utkarshshukla7 :sparkles: :thumbsup: :sparkles:
:star: 327 | @utkarshshukla7 | http://www.freecodecamp.com/utkarshshukla7
Erin Heard
@ufi16
Apr 17 2016 02:08
thank you @sjames1958gm
CamperBot
@camperbot
Apr 17 2016 02:08
ufi16 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 669 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
UtkarshShukla7
@UtkarshShukla7
Apr 17 2016 02:09
@ufi16 np
Clay Sheffler
@ClaySheffler
Apr 17 2016 02:29
why would i get error "cannot read property 'push' of undefined ? function updateRecords(id, prop, value) {
if (value !== "" && prop !== "tracks") {
collection[id][prop] = value;
}
else if (value === "") {
collection[id].pop();
}
else if (prop === "tracks" && value !== "") {
collection[id][prop].push(value);
}
return collection;
}
function updateRecords(id, prop, value) { if (value !== "" && prop !== "tracks") { collection[id][prop] = value; } else if (value === "") { collection[id].pop(); } else if (prop === "tracks" && value !== "") { collection[id][prop].push(value); } return collection; }
function updateRecords(id, prop, value) {
  if (value !== "" && prop !== "tracks") {
    collection[id][prop] = value;
  }
  else if (value === "") {
    collection[id].pop();  
  } 
    else if (prop === "tracks" && value !== "") {
   collection[id][prop].push(value);
  }
  return collection;
}
Hector Garcia
@augmt
Apr 17 2016 02:32
@tonrewler you're trying to push a value into an array that doesn't yet exist at the time of execution
Clay Sheffler
@ClaySheffler
Apr 17 2016 02:32
ah
so just need to add chec that the id already exists?
Hector Garcia
@augmt
Apr 17 2016 02:34
@tonrewler i'll take a look at the challenge to make sure, but theoretically that should work
Clay Sheffler
@ClaySheffler
Apr 17 2016 02:34
it's "Record Collection" in latter part of JS
Tim
@codemymind
Apr 17 2016 02:34

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

result += "My " + "big" + " dog" + " ran" + " very" + " quickly";

// Your code above this line
return result;
}

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

oops -
Kelvin-penang
@Kelvin-penang
Apr 17 2016 02:35
// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(myObj) {
  // Your Code Here
myObj.hasOwnProperty("");

  return "Not Found";

}

// Test your code by modifying these values
checkObj("gift");
Can anybody help?
Marco Berardini
@mb0606
Apr 17 2016 02:35
@tonrewler does collection exist ?
Tim
@codemymind
Apr 17 2016 02:35
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
  var result = "";
  // Your code below this line

  result += "My " + "big" + " dog" + " ran" + " very" + " quickly"; 


  // Your code above this line
  return result;
}

// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");
I'm a bit confused on the word blanks checkpoint.
Clay Sheffler
@ClaySheffler
Apr 17 2016 02:35
@mb0606 yes
Marco Berardini
@mb0606
Apr 17 2016 02:38
@tonrewler is it a an array of objects ? if it is you don't use push you just assign it collection[id][prop] = value;
Ken Haduch
@khaduch
Apr 17 2016 02:38
@codemymind - hi Tim - you are supposed to use the function arguments, which are going to be "holding" the words that are passed in the function call. And it looks like you had the right idea about putting the spaces in there, but you have to do that between each of the variables as you concatenate them. For example: var1 + ' ' + var2, etc.
Clay Sheffler
@ClaySheffler
Apr 17 2016 02:39
collections is json object, tracks is a list inside it
Tim
@codemymind
Apr 17 2016 02:39
@khaduch thank you, got it
CamperBot
@camperbot
Apr 17 2016 02:39
codemymind sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star: 951 | @khaduch | http://www.freecodecamp.com/khaduch
Tim
@codemymind
Apr 17 2016 02:39
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
  var result = "";
  // Your code below this line

  result += "My " + myAdjective +" " +  myNoun +" " +  myVerb +" " + "very " +  myAdverb; 


  // Your code above this line
  return result;
}

// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");
that passed, is it the proper way to concatenate it tho?
Hector Garcia
@augmt
Apr 17 2016 02:40
@tonrewler i tried your code and got a different error: Uncaught TypeError: collection[id].pop is not a function
Clay Sheffler
@ClaySheffler
Apr 17 2016 02:41
hm
cannelflow
@cannelflow
Apr 17 2016 02:41
@codemymind yes it is result= will also work
vínαч puppαl
@vinaypuppal
Apr 17 2016 02:42
@Kelvin-penang obj.hasOwnProperty(key) return boolean , so u can use if condition like below
function checkObj(key) {
if(myObj.hasOwnProperty(key)) return "Found";
else return "NotFound";
}
Tim
@codemymind
Apr 17 2016 02:42
@cannelflow ok cool, so it's basically just redefining result to a new string. What threw me off was the var result="";
@cannelflow thank you
CamperBot
@camperbot
Apr 17 2016 02:42
codemymind sends brownie points to @cannelflow :sparkles: :thumbsup: :sparkles:
:star: 1078 | @cannelflow | http://www.freecodecamp.com/cannelflow
Ken Haduch
@khaduch
Apr 17 2016 02:42
@codemymind - there are a couple things that you don't need to do - in this case, result += could just be result =, and your spacing could be more consistent (just a code formatting concern, the result will be the same). But generally it is OK.
Marco Berardini
@mb0606
Apr 17 2016 02:42
@tonrewler push() and pop() are for arrays so if you are working on object s it will not work
Kelvin-penang
@Kelvin-penang
Apr 17 2016 02:43
thanks @vinaypuppal ! shall give it a try
CamperBot
@camperbot
Apr 17 2016 02:43
kelvin-penang sends brownie points to @vinaypuppal :sparkles: :thumbsup: :sparkles:
:star: 313 | @vinaypuppal | http://www.freecodecamp.com/vinaypuppal
cannelflow
@cannelflow
Apr 17 2016 02:43
@codemymind :+1:
Clay Sheffler
@ClaySheffler
Apr 17 2016 02:43
@mb0606 this is the structure: var collection = { 2548: { album: "Slippery When Wet", artist: "Bon Jovi", tracks: [ "Let It Rock", "You Give Love a Bad Name" ] }, 2468: { album: "1999", artist: "Prince", tracks: [ "1999", "Little Red Corvette" ] }, 1245: { artist: "Robert Palmer", tracks: [ ] }, 5439: { album: "ABBA Gold" } };
Tim
@codemymind
Apr 17 2016 02:43
@khaduch yeah, I realize it passed, but I don't think it's proper code the way I did it - good to know. I'm gonna do it again and see if I can clean it up
Thank you guys
Kelvin-penang
@Kelvin-penang
Apr 17 2016 02:46
@vinaypuppal
checkObj("gift") should return "pony".
checkObj("pet") should return "kitten".
The comments are as such. It's not good enough for the function to return "Found" or "Not Found". An idea on how to make it return their property names instead?
vínαч puppαl
@vinaypuppal
Apr 17 2016 02:47
yes if key is found then return myObj[key];
@Kelvin-penang
understood?? @Kelvin-penang
Kelvin-penang
@Kelvin-penang
Apr 17 2016 02:48
// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

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


}

// Test your code by modifying these values
checkObj("gift");
I did this :smile: thanks again @vinaypuppal
CamperBot
@camperbot
Apr 17 2016 02:48
kelvin-penang sends brownie points to @vinaypuppal :sparkles: :thumbsup: :sparkles:
:warning: kelvin-penang already gave vinaypuppal points
vínαч puppαl
@vinaypuppal
Apr 17 2016 02:49
@Kelvin-penang :+1:
Tien Anh Nguyen
@tienanh2007
Apr 17 2016 02:49
COuld someone tell me why my dropdown button doesn;t work ?
Tim
@codemymind
Apr 17 2016 02:50
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
  var result = "";
  // Your code below this line

  result = "My " + myAdjective + " " +  myNoun + " " +  myVerb + " " + "very " +  myAdverb; 


  // Your code above this line
  return result;
}

// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");
@khaduch that better?
eduwin7
@eduwin7
Apr 17 2016 02:52
need help
Ro (Lora Rose)
@aroseartist
Apr 17 2016 02:52
Unsure why I'm not printing anything! Suggestions?
function dynamic(max, num1, num2){
  var resultingArray = [];
  while (i < max) {
    if (i % 3 === 0 && i % 5 !== 0) {
      resultingArray.push(i);
    } else if (i % 5 === 0 && i % 3 !== 0) {
      resultingArray.push(i);
    }
    i++;
  }
  return resultingArray;
}
dynamic(20, 5, 3);
CamperBot
@camperbot
Apr 17 2016 02:52
:bulb: to format code use backticks! ``` more info
eduwin7
@eduwin7
Apr 17 2016 02:52
need help please
Ro (Lora Rose)
@aroseartist
Apr 17 2016 02:52
This message was deleted
eduwin7
@eduwin7
Apr 17 2016 02:53

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

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

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

Marco Berardini
@mb0606
Apr 17 2016 02:53
@tonrewler your code works perfect on that object updateRecords(2548, "tracks", "new track") are you making sure you are using " "
eduwin7
@eduwin7
Apr 17 2016 02:53
this is confusing to me
UtkarshShukla7
@UtkarshShukla7
Apr 17 2016 02:54
@aroseartist because your return is outside function
Frank XC
@tenkdayz
Apr 17 2016 02:54
@aroseartist what does the function need to do?
Marco Berardini
@mb0606
Apr 17 2016 02:55
@eduwin7 fahrenheit = (celsius * 9)/5 + 32
UtkarshShukla7
@UtkarshShukla7
Apr 17 2016 02:55
@aroseartist see else if part
vínαч puppαl
@vinaypuppal
Apr 17 2016 02:55
@codemymind u shlould follow this format https://en.wikipedia.org/wiki/Mad_Libs#Format and use string concatination to generate a sentence using given arguments...
Frank XC
@tenkdayz
Apr 17 2016 02:55
@UtkarshShukla7 it's inside..
Bent Cardan
@reqshark
Apr 17 2016 02:56
@eduwin7 I messaged you how
Ro (Lora Rose)
@aroseartist
Apr 17 2016 02:57
I'm supposed to: returns an array of numbers up to the max. Each number should be either divisible by num1 or num2, BUT NOT BOTH.
eduwin7
@eduwin7
Apr 17 2016 02:57
mb thanks. how was i suppose to get that. never seen this lol
Tim
@codemymind
Apr 17 2016 02:57
@vinaypuppal hmmm, I thought I did -
Alex Myers
@qckpckt
Apr 17 2016 02:57
Hi all, I’m hoping to get some help with the factorialize a number challenge. So far I have made a for loop that iterates the integers <= num and stores them in an array. I just want to know if I’m on the right track.
UtkarshShukla7
@UtkarshShukla7
Apr 17 2016 02:58
@aroseartist define i
Frank XC
@tenkdayz
Apr 17 2016 02:58
@aroseartist just use one if statement. if i % num1==0 || i % num 2 ==0
Stephen James
@sjames1958gm
Apr 17 2016 03:00
@qckpckt If you are iterating over the numbers, why not just multiply them while iterating?
UtkarshShukla7
@UtkarshShukla7
Apr 17 2016 03:00
@aroseartist var i=somevalue;
Tyler
@tylergross
Apr 17 2016 03:01
this Roman Numeral challenge sucks
Alex Myers
@qckpckt
Apr 17 2016 03:03
@sjames1958gm, yes that would be great, if I knew how! :)
vínαч puppαl
@vinaypuppal
Apr 17 2016 03:03
@qckpckt and don't forget to check for zero case as 0! is 1
Alex Myers
@qckpckt
Apr 17 2016 03:04
My current plan is to use .reduce to resolve my array into a single value by multiplying them together.
@vinaypuppal wait what? 0*0 is 1 in js?
or is that a property of factorials
Tyler
@tylergross
Apr 17 2016 03:05
factorials
Ro (Lora Rose)
@aroseartist
Apr 17 2016 03:05
Oh geesh @UtkarshShukla7 , define i, duh -- thanks all!
CamperBot
@camperbot
Apr 17 2016 03:05
aroseartist sends brownie points to @utkarshshukla7 :sparkles: :thumbsup: :sparkles:
Tyler
@tylergross
Apr 17 2016 03:05
i had that same question didnt make sense, added it as a special case to the function
CamperBot
@camperbot
Apr 17 2016 03:05
:star: 328 | @utkarshshukla7 | http://www.freecodecamp.com/utkarshshukla7
Ken Haduch
@khaduch
Apr 17 2016 03:05
@eduwin7 - This seems to be one of those "Stepping stones" that get a lot of people hung up, so you're not alone. Once you have the solution, please re-read the problem and see how it gives you the formula for the conversion, and then note how it is translated to a javascript calculation. There will be many more problems like this one presented, so you need to get the hang of solving those from the problem descriptions. Good luck!
vínαч puppαl
@vinaypuppal
Apr 17 2016 03:05
no but in math 0 factorial is 1
@qckpckt
UtkarshShukla7
@UtkarshShukla7
Apr 17 2016 03:05
@aroseartist np
Alex Myers
@qckpckt
Apr 17 2016 03:06
@vinaypuppal I would love to know why.
vínαч puppαl
@vinaypuppal
Apr 17 2016 03:06
Ken Haduch
@khaduch
Apr 17 2016 03:06
@tylergross - The Roman numeral challenge was rather challenging... I found that really paying attention to the Roman Numeral link that they provided really helped me.
Erin Heard
@ufi16
Apr 17 2016 03:07
i'm lost on the if/else statements for 'Record Collection'

function updateRecords(id, prop, value) {
if (value !=="" || prop !=="tracks") {

}
else {
return collection.[prop];
}
if (prop == "tracks" || value !=="") {

}
else {
return prop.push(value);
}
if (value === "") {

  }
  else {
  delete collection[prop];
  }

return collection;
}

Tyler
@tylergross
Apr 17 2016 03:07
@khaduch my plan of attack is to divide the number into brackets and then assign them by cases, just feels like a ton of coding
IE 2354 = 2000, 300, 50, 4
Stephen James
@sjames1958gm
Apr 17 2016 03:08
@qckpckt Start with a variable = 1 and as you loop through the numbers multiple that variable by the number and after the loop return that variable
@qckpckt Don't forget any special cases like 0!
Ken Haduch
@khaduch
Apr 17 2016 03:08
@tylergross - it was not insignificant in terms of code, but I think that a key is to find a way to factor out the calculation into something functional. I have to go and see what I ended up doing for that one!
Dylan
@dhcodes
Apr 17 2016 03:08
@ufi16 on your 5th line you are trying to use both bracket and dot notation. I think you just need one or the other
Clay Sheffler
@ClaySheffler
Apr 17 2016 03:09
@mb0606 are you saying there's a difference etween " " and "" -- ie with space and without?
Ken Haduch
@khaduch
Apr 17 2016 03:09
@ufi16 - I think that you want to have your if test conditions with the && operator, that is if ( value !== "" && prop != "tracks")
Erin Heard
@ufi16
Apr 17 2016 03:11
how do i push the value at the end of my prop
Clay Sheffler
@ClaySheffler
Apr 17 2016 03:11
collection[id][prop].push(value);
Alex Myers
@qckpckt
Apr 17 2016 03:11
hmm @sjames1958gm that was my firt thought but I couldnt seem to get it to iterate over the whole loop. Maybe I was returning the result of my variable before the loop was closed...
Ken Haduch
@khaduch
Apr 17 2016 03:12
@ufi16 - you have to have an object and the property has to be an array in order to push it. But I think that @tonrewler gave it out...
Clay Sheffler
@ClaySheffler
Apr 17 2016 03:12
@mb0606 thanks for your help :)
CamperBot
@camperbot
Apr 17 2016 03:12
tonrewler sends brownie points to @mb0606 :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for mb0606
Stephen James
@sjames1958gm
Apr 17 2016 03:12
@qckpckt var rsp = 1; for (i = 2; i < num; i++) {rsp *= i} return rsp
Alex Myers
@qckpckt
Apr 17 2016 03:12
thanks @vinaypuppal my algorithm works for everything except 0!. Is it acceptable to return an answer through an if clause for this or is there a way to reciprocate it in a way that javascript will be able to process?
CamperBot
@camperbot
Apr 17 2016 03:12
qckpckt sends brownie points to @vinaypuppal :sparkles: :thumbsup: :sparkles:
:star: 314 | @vinaypuppal | http://www.freecodecamp.com/vinaypuppal
Stephen James
@sjames1958gm
Apr 17 2016 03:13
@qckpckt Yes if there is a special case, you can use an if condition return
Alex Myers
@qckpckt
Apr 17 2016 03:13
hm @sjames1958gm That is what I thought I had written, I must have made an error with the bracket notations. Thanks. it’s a lot simpler than my fancy mess with arrays:
CamperBot
@camperbot
Apr 17 2016 03:13
qckpckt sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 670 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Apr 17 2016 03:15
@qckpckt First think about how you might do it with out the computer and then implement that.
Erin Heard
@ufi16
Apr 17 2016 03:15
it's saying it's an undefined object @tonrewler
vínαч puppαl
@vinaypuppal
Apr 17 2016 03:16
@qckpckt yes u can use if statement , and u can also use recursion instead of loops , want to know how??
Alex Myers
@qckpckt
Apr 17 2016 03:16
@vinaypuppal sure!
vínαч puppαl
@vinaypuppal
Apr 17 2016 03:17
function factorialize(num) {

  if(num === 0) return 1;

  return num * factorialize(num - 1);

}
@qckpckt
Stephen James
@sjames1958gm
Apr 17 2016 03:17
@vinaypuppal +1
Erin Heard
@ufi16
Apr 17 2016 03:20
am i missing something else in the 'Record Collection' challenge

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

// Only change code below this line
function updateRecords(id, prop, value) {
if (value !=="" && prop !=="tracks") {

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

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

  }
  else {
  delete collection[prop];
  }

return collection;
}

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

Stephen James
@sjames1958gm
Apr 17 2016 03:21
@ufi16 All of your if are empty if (value !=="" && prop !=="tracks") { return collection[prop]; }
Erin Heard
@ufi16
Apr 17 2016 03:22
i don't know what they're supposed to return
so i don't need an else statement then?
Stephen James
@sjames1958gm
Apr 17 2016 03:23
Always return the entire collection object.
if (value !=="" && prop !=="tracks") { collection[prop] = value; } else if
@ufi16 Your else should be else if the next test and after all of these return collection;
Alex Myers
@qckpckt
Apr 17 2016 03:25
@vinaypuppal Wow that is incredibly simple!
vínαч puppαl
@vinaypuppal
Apr 17 2016 03:25
@sjames1958gm it should be collection[id][prop] = value; i think becoz nested object
@qckpckt :smile:
Stephen James
@sjames1958gm
Apr 17 2016 03:26
@vinaypuppal of yeah - correct - thanks - i was focused on the if contsruction
CamperBot
@camperbot
Apr 17 2016 03:26
sjames1958gm sends brownie points to @vinaypuppal :sparkles: :thumbsup: :sparkles:
:star: 315 | @vinaypuppal | http://www.freecodecamp.com/vinaypuppal
Erin Heard
@ufi16
Apr 17 2016 03:26
i can't figure out why it won't run

function updateRecords(id, prop, value) {
if (value !=="" && prop !=="tracks") {
return collection[prop];
}

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

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

Alex Myers
@qckpckt
Apr 17 2016 03:27
@vinaypuppal @sjames1958gm can you tell me how this is working for factorialize(0):
function factorialize(num) {
var answer = 1;
  for (i = 1; i <= num; i++) {
    answer *= i;
  }
  return answer;
}
factorialize(0);
Is this just freecodecamp caching the answer from my old code? I can’t understand why this is working without the if statement
Stephen James
@sjames1958gm
Apr 17 2016 03:27
it never goes through the loop so the initial value is 1
Alex Myers
@qckpckt
Apr 17 2016 03:27
ahhh
so because answer is set to 1 it just returns that. Got it. works for me :)
vínαч puppαl
@vinaypuppal
Apr 17 2016 03:28
@sjames1958gm yes
+1
Marco Berardini
@mb0606
Apr 17 2016 03:37
@qckpckt another way to solve it function factorialize(num) {
if (num === 1) {
return 1;
}
return num * factorialize(num - 1);
}
buckshot307
@buckshot307
Apr 17 2016 03:37
Hey guys I'm working on the weather web app and all the results are coming back as undefined. Is it because I don't live near a large city or how close do they get?
Bent Cardan
@reqshark
Apr 17 2016 03:38
@buckshot307 That means there is an issue with the code
payal-prksh
@payal-prksh
Apr 17 2016 03:40

function sumFibs(num) {
var sum = 1;
var a = 0 , b = 1;
var c = 0;

for(var i = 1; i < num; i++)
{
c = a + b;
if(c % 2 === 1)
sum += c;
a = b;
b = c;

}

return sum;
}

sumFibs(10);

Stephen James
@sjames1958gm
Apr 17 2016 03:41
@ufi16 Your first two returns should not be returns. The first should be an assignment collection[id][prop] = value;. Your second one just remove the return (push is correct) finally remove the else { return collection; } instead just have return collection; You want return collection to happen in all cases so it cannot be inside and else {}
payal-prksh
@payal-prksh
Apr 17 2016 03:41
can someone tell me what is wrong with the above program? it works for cases where num is small, for larger values of num, it gails
*fails
Alex Myers
@qckpckt
Apr 17 2016 03:41
recursion is pretty amazing! I’m still trying to get my head around how it works.
Stephen James
@sjames1958gm
Apr 17 2016 03:43
@payal-prksh Your for loop does not seem to fit the instructions
payal-prksh
@payal-prksh
Apr 17 2016 03:44
@sjames1958gm Thanks for the quick reply. Could you please elaborate a little more on that.
CamperBot
@camperbot
Apr 17 2016 03:44
payal-prksh sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 671 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
vínαч puppαl
@vinaypuppal
Apr 17 2016 03:44
@payal-prksh and if(c%2!==0) for testing odd values
Stephen James
@sjames1958gm
Apr 17 2016 03:45
@payal-prksh You are supposed to be testing the fibonacci number against num you are looping num times
Erin Heard
@ufi16
Apr 17 2016 03:46
thank you @sjames1958gm
CamperBot
@camperbot
Apr 17 2016 03:46
ufi16 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 672 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
payal-prksh
@payal-prksh
Apr 17 2016 03:46
@vinaypuppal but (c %2 === 1) means that c is odd, right? Am I missing something here?
Stephen James
@sjames1958gm
Apr 17 2016 03:46
@vinaypuppal c%2 ==1 and c%2 != 0 are the same
@payal-prksh c%2 only has two values
buckshot307
@buckshot307
Apr 17 2016 03:47
didnt work how i wanted it to lol
vínαч puppαl
@vinaypuppal
Apr 17 2016 03:47
oh @sjames1958gm forgot , sorry @payal-prksh
payal-prksh
@payal-prksh
Apr 17 2016 03:47
no problem :)
buckshot307
@buckshot307
Apr 17 2016 03:48
 <script src="https://api.openweathermap.org/data/2.5/weather?APPID=96dfc0518955e614bc07cae8e262041b"></script>

 function (navigator.geolocation) { $("#weather").html("weather: " + weather.main + "<br>description: " + weather.description) }
It shows the latitude and longitude from a different function but just shows weather: undefined. If I change the script to London or something it works though.
payal-prksh
@payal-prksh
Apr 17 2016 03:49
@sjames1958gm Thanks for the clarification. I mis-read the question.
CamperBot
@camperbot
Apr 17 2016 03:49
payal-prksh sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: payal-prksh already gave sjames1958gm points
buckshot307
@buckshot307
Apr 17 2016 03:57
the example page also doesn't work for me
ZctrapCoding
@ZctrapCoding
Apr 17 2016 03:58
what am i doing wrong?
```
opps
var Car = function() {
  this.wheels = 4;
  this.engines = 1;
  this.seats = 1;
};

// Only change code below this line.
var Car = new myCar();
myCar.wheels = 4;
myCar.nickname = "Lightning McKing";
var myCar;
buckshot307
@buckshot307
Apr 17 2016 03:59

https://codepen.io/FreeCodeCamp/full/bELRjV

just shows a comma above the C/F converter

Stephen James
@sjames1958gm
Apr 17 2016 04:01
@ZctrapCoding var myCar = new Car();
buckshot307
@buckshot307
Apr 17 2016 04:01
@ZctrapCoding var Car is already defined at the top
ZctrapCoding
@ZctrapCoding
Apr 17 2016 04:01
oh thx @sjames1958gm @buckshot307
CamperBot
@camperbot
Apr 17 2016 04:01
zctrapcoding sends brownie points to @sjames1958gm and @buckshot307 :sparkles: :thumbsup: :sparkles:
:star: 284 | @buckshot307 | http://www.freecodecamp.com/buckshot307
:star: 673 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
buckshot307
@buckshot307
Apr 17 2016 04:02
does that codepen work for anyone else?
Tyler
@tylergross
Apr 17 2016 04:02
I have a variable that is only set on special occasions.... how do I do a check to ensure the variable is set (i keep getting an undefined error when the variable is not set and want the code to break if this occurs)
Amine Dassouki
@Zubeii
Apr 17 2016 04:02
I'm not fully understanding the "Stand in Line" JS excersize. It asks to write a function nextInLine, which is already written. Am I supposed to write another function?
Tyler
@tylergross
Apr 17 2016 04:03
@buckshot307 no the weather code pen does not work for me
Marco Berardini
@mb0606
Apr 17 2016 04:03
@ZctrapCoding var myCar = new Car(); and last line of code take out the var
Stephen James
@sjames1958gm
Apr 17 2016 04:03
@Zubeii You are supposed to fill in the function
buckshot307
@buckshot307
Apr 17 2016 04:05
@tylergross cool, thanks. Not sure how I'm supposed to imitate something that doesn't work lol.
CamperBot
@camperbot
Apr 17 2016 04:05
buckshot307 sends brownie points to @tylergross :sparkles: :thumbsup: :sparkles:
:star: 288 | @tylergross | http://www.freecodecamp.com/tylergross
Tyler
@tylergross
Apr 17 2016 04:06
@buckshot307 I attempted to do this challenge earlier today, I gave up and decided to continue learning more as I am not proficient in API's and JSON... however, if you read the "User Stories" that will tell you what they would like to see on the app.
Amine Dassouki
@Zubeii
Apr 17 2016 04:06
Hmm, maybe its just late and im not grasping this right now. Thanks @sjames1958gm
CamperBot
@camperbot
Apr 17 2016 04:06
zubeii sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
Tyler
@tylergross
Apr 17 2016 04:06
basically a photo indicating the current weather, the temperature which can be changed from celc to farh and something else i believe as long as you do the conditions you'll be good to go
CamperBot
@camperbot
Apr 17 2016 04:06
:star: 674 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
buckshot307
@buckshot307
Apr 17 2016 04:07
@tylergross yeah I mean I got it somewhat set up but I can't change the picture based on the weather because the weather is coming back undefined.
Amine Dassouki
@Zubeii
Apr 17 2016 04:10
I'll just go to sleep and come back to that one tomorrow. probably super simple but brains not working right now
Marco Berardini
@mb0606
Apr 17 2016 04:12
@buckshot307 did you sign up and get an API key ?
Meghana
@meghanasarikonda
Apr 17 2016 04:18
Hello anyone please help me with Fibonacci challange
Alexis
@alexisgcn
Apr 17 2016 04:21
@meghanasarikonda what do you need?
Tyler
@tylergross
Apr 17 2016 04:21
function myReplace(str, before, after) {
  var search = "/"+before+"/i";
  var found = str.match(search);
  found = found[0];
  str = str.replace(before, after);
  return found;
}

myReplace("A quick brown fox Jumped over the lazy dog", "jumped", "leaped");
receiving a Null error from my str.match function.... how can i properly search for something i want /before/i where before is a variable
Meghana
@meghanasarikonda
Apr 17 2016 04:23
@alexisgcn do we have to create a fibonocci series and later add the odd numbers? ?
Alexis
@alexisgcn
Apr 17 2016 04:24
can you show your current code?
Meghana
@meghanasarikonda
Apr 17 2016 04:25
No I had done nothing, just confused with the question. .
Alexis
@alexisgcn
Apr 17 2016 04:25
oh,ok
do yo u know what is the fibonacci serie?
Tyler
@tylergross
Apr 17 2016 04:26
interm. algorithm
@meghanasarikonda it sounds like they want the function to sum all odd numbers in the fibb. serie up to the number that was inputted
so if i put 9 in the function, the function would output 10 ..... 1,1,2,3,5,8,13 1+1+3+5 = 10
Paul Manning
@paulmanning
Apr 17 2016 04:44
Hi folks, having an infinite loop problem that I can’t seem to spot. Would love feedback:
function convertToRoman(num) {
  var arrRoman    = 
      ["M", "CM","D", "LC","C","XC","L","XL","X","IX","V","IV", "I"];
  var arrImperial = 
      [1000, 900, 500, 400,100, 90,  50, 40,  10, 9,   5,   4,   1 ];

  var result=0, strNum="";
  while(num>0) {
    for(i=0; i<arrImperial.length; i++) {
      while(num > arrImperial[i]) {
        num -= arrImperial[i];
        strNum = strNum.concat(arrRoman[i]);
      }
    }
  }
  console.log(strNum);
  return strNum;
}

convertToRoman(36);
kirbyedy
@kirbyedy
Apr 17 2016 04:45
@tylergross so in theory your code should separate odd and even numbers, put the odd ones in to the array, and than sum all those numbers :)
buckshot307
@buckshot307
Apr 17 2016 04:52
@paulmanning while(num>0) { for(i=0; i<arrImperial.length; i++)
Rada
@Radascript
Apr 17 2016 04:53
@paulmanning also having trouble spotting the issue, but just wanted to say I think that's a very elegant way to go about it, good job. Please update when you figure out why it's not liking it
Paul Manning
@paulmanning
Apr 17 2016 04:54
@buckshot307 Not seeing it. The inner while is reducing the num when it hits, and it should hit that inner loop to reduce it.
at least several times
@Radascript Appreciate the compliment!
Alex Myers
@qckpckt
Apr 17 2016 04:58
Hi all, I’m working on the palindrome challenge and I can meet every requirement except my code does not replace _ with “”. Why is it being counted as an alphanumeric character?
here is my replace code:
var newArr = str.replace(/([^\w*])/g, "").toLowerCase().split([""]);
Frank XC
@tenkdayz
Apr 17 2016 05:00
@qckpckt add underscore to the regex pattern
Paul Manning
@paulmanning
Apr 17 2016 05:01
I found my issue folks. Didn’t need the outer loop, and the inner while need a >= comparator. I ended up with this for those interested:
function convertToRoman(num) { 
  var arrRoman    = 
      ["M", "CM","D", "LC","C","XC","L","XL","X","IX","V","IV", "I"];
  var arrImperial = 
      [1000, 900, 500, 400,100, 90,  50, 40,  10, 9,   5,   4,   1 ];


  var workingNum=num, strNum="";
  for(i=0; i<arrImperial.length; i++) {
    while(workingNum >= arrImperial[i]) {
      workingNum -= arrImperial[i];
      strNum = strNum.concat(arrRoman[i]);
    }
  }

  console.log(strNum);
  return strNum;
}

convertToRoman(36);
buckshot307
@buckshot307
Apr 17 2016 05:01
yeah my bad i was multitasking and thought you had something else
Eldar Tinjić
@EldarT90
Apr 17 2016 05:01
function sumPrimes(num) {
  var count = 0;
  var newArr = [];
  var counter = 0;
for (var i = 0; i<=num; i++)
  {
    newArr.push(i);
}

  for (i=2;i<=num;i++) {


    for (j=2;j<newArr.length;j++)
      {
        if (newArr[j] % i === 0) 

          {
            counter += 1;

          }
         if (counter === 1) {
          count += j;

      }

        } 

  }

  return count;

}



sumPrimes(10);
Frank XC
@tenkdayz
Apr 17 2016 05:02
@paulmanning try strNum += arrRoman[i]
Eldar Tinjić
@EldarT90
Apr 17 2016 05:04
any help towards that problem? tnx
Rupesh Padhye
@rupeshpadhye
Apr 17 2016 05:06
function Person(fullName) {
var fistName;
var lastName;
            this.getFirstName=function () {
                return fistName;
            };
            this.getLastName= function () {
                return lastName;
            };
            this.setFistName= function (fname) {
                fistName = fname;
            };
            this.setLastName= function (lname) {
                lastName = lname;
            };
            this.getFullName= function () {
                return fistName + " " + lastName;
            };
            this.setFullName= function (fullname) {
                var data = fullname.split(" ");
                fistName = data[0];
                lastName = data[1];

            };

        this.setFullName(fullName);



    }
    var bob = new Person('Bob Ross');
    console.log(bob.getFullName()); //console Bob Ross
    bob.setFistName("Haskell");
    console.log(bob.getFullName()); //console Haskell Ross
I am getting desired answer in console but test case is failing
Frank XC
@tenkdayz
Apr 17 2016 05:07
@EldarT90 youre not resetting the counter.. might want to use a toggle
Alex Myers
@qckpckt
Apr 17 2016 05:08
@tenkdayz I seem to be having trouble adding multiple regexps to one replace function. What’s the correct notation for it?
Eldar Tinjić
@EldarT90
Apr 17 2016 05:09
@tenkdayz thats true, though now im getting 115 instead of 17, that means too many numbers are passing the test
Frank XC
@tenkdayz
Apr 17 2016 05:11
@qckpckt the regex should be /[\W*_]/g
@qckpckt or something similar
Alex Myers
@qckpckt
Apr 17 2016 05:12
I see because otherwise the ^ will apply to everything rather than just alphanumerics
Rupesh Padhye
@rupeshpadhye
Apr 17 2016 05:13
anybody can help me out for my issue :worried:
UtkarshShukla7
@UtkarshShukla7
Apr 17 2016 05:13
@rupeshpadhye name of challenge
Frank XC
@tenkdayz
Apr 17 2016 05:13
@qckpckt thats correct.
Alex Myers
@qckpckt
Apr 17 2016 05:14
@tenkdayz thank you! I was trying to add multiple ([])
CamperBot
@camperbot
Apr 17 2016 05:14
qckpckt sends brownie points to @tenkdayz :sparkles: :thumbsup: :sparkles:
:star: 406 | @tenkdayz | http://www.freecodecamp.com/tenkdayz
Rupesh Padhye
@rupeshpadhye
Apr 17 2016 05:14
@UtkarshShukla7 https://www.freecodecamp.com/challenges/make-a-person#?solution=%20%20%20%20%20function%20Person(fullName)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20fistName%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20lastName%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20this.getFirstName%3Dfunction%20()%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20fistName%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20this.getLastName%3D%20function%20()%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20lastName%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20this.setFistName%3D%20function%20(fname)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20fistName%20%3D%20fname%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20this.setLastName%3D%20function%20(lname)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20lastName%20%3D%20lname%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20this.getFullName%3D%20function%20()%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20fistName%20%2B%20%22%20%22%20%2B%20lastName%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20this.setFullName%3D%20function%20(fullname)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20var%20data%20%3D%20fullname.split(%22%20%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20fistName%20%3D%20data%5B0%5D%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20lastName%20%3D%20data%5B1%5D%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20this.setFullName(fullName)%3B%0A%0A%20%20%20%20%20%20%0A%0A%20%20%20%20%20%20%20%20%7D%0Avar%20bob%20%3D%20new%20Person('Bob%20Ross')%3B%0Abob.getFullName()%3B%0A
Make a person
Marco Berardini
@mb0606
Apr 17 2016 05:16
@paulmanning function convert(num) {
if(num < 1){ return "";}
if(num >= 40){ return "XL" + convert(num - 40);}
if(num >= 10){ return "X" + convert(num - 10);}
if(num >= 9){ return "IX" + convert(num - 9);}
if(num >= 5){ return "V" + convert(num - 5);}
if(num >= 4){ return "IV" + convert(num - 4);}
if(num >= 1){ return "I" + convert(num - 1);}
}
UtkarshShukla7
@UtkarshShukla7
Apr 17 2016 05:16
ok
Frank XC
@tenkdayz
Apr 17 2016 05:16
@qckpckt np!
UtkarshShukla7
@UtkarshShukla7
Apr 17 2016 05:17
@rupeshpadhye I just changed line 13 getFistName to getFirstName
and it passed
@rupeshpadhye I mean setFirstName
Frank XC
@tenkdayz
Apr 17 2016 05:18
@rupeshpadhye i think you need commas at the end of those no?
Rupesh Padhye
@rupeshpadhye
Apr 17 2016 05:19
thanks @UtkarshShukla7
CamperBot
@camperbot
Apr 17 2016 05:19
rupeshpadhye sends brownie points to @utkarshshukla7 :sparkles: :thumbsup: :sparkles:
:star: 329 | @utkarshshukla7 | http://www.freecodecamp.com/utkarshshukla7
UtkarshShukla7
@UtkarshShukla7
Apr 17 2016 05:19
@rupeshpadhye np
ygspasov
@ygspasov
Apr 17 2016 05:23

I'm trying to solve this:
function nextInLine(arr, item) {
// Your code here
testArr.push(item);
testArr.unshift(arr);
return testArr[arr]; // Change this line
}

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

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

Frank XC
@tenkdayz
Apr 17 2016 05:24
@ygspasov unshift adds a value to index 0 of the array.
ygspasov
@ygspasov
Apr 17 2016 05:24
I'm aware of that.
I think the problem is in the line below it.
Frank XC
@tenkdayz
Apr 17 2016 05:25
@ygspasov you want to do the opposite
UtkarshShukla7
@UtkarshShukla7
Apr 17 2016 05:25
@ygspasov you should return testArr;
ygspasov
@ygspasov
Apr 17 2016 05:25
let me look at it
I changed it to shift. Now I should return the element that was removed.
Eldar Tinjić
@EldarT90
Apr 17 2016 05:28
@tenkdayz why is this not incrementing properly
function sumPrimes(num) {
  var newArr = Array.apply(null, Array(1000)).map(function (_, i) {return i;});
  var counter = 0;

  for (i=2;i<newArr.length;i++) {

    while (newArr[i]<1000) {
    if (newArr.indexOf(newArr[i]) > -1) {
      newArr.splice(newArr[i]);
      counter += 1;  
      i++;

    }}

  return counter;

}
}

sumPrimes(10);
andreyorlov33
@andreyorlov33
Apr 17 2016 05:29

Hey guys can some one take a look at my code? I cant figure out why my Weather App is not working... spent the whole day D bugging and no luck ...

http://codepen.io/andreyorlov33/pen/xVjLKe

Frank XC
@tenkdayz
Apr 17 2016 05:31
@EldarT90 what's going on on the second line?
kirbyedy
@kirbyedy
Apr 17 2016 05:31
@andreyorlov33 your console log says Uncaught ReferenceError: zip is not defined
Eldar Tinjić
@EldarT90
Apr 17 2016 05:32
@tenkdayz adding nubmers from 1 to 100 in array
@tenkdayz 1000*
andreyorlov33
@andreyorlov33
Apr 17 2016 05:32
yaeh i dont know why it says that... @kirbyedy even if i define it it as a var it still does not work
Frank XC
@tenkdayz
Apr 17 2016 05:36
@EldarT90 I dont understand what youre trying to do... you have to do something to the input value (num)
kirbyedy
@kirbyedy
Apr 17 2016 05:36
@andreyorlov33 what does this function do ?
function updateByGeo(lat, lon) {
    var url = "http://api.openweathermap.org/data/2.5/weather?" +
      "zip=" + zip +
      "&APPID=" + APPID;
  }
Eldar Tinjić
@EldarT90
Apr 17 2016 05:36
@tenkdayz yes, but later, for now i want for counter to return 500
henrywashere
@henrywashere
Apr 17 2016 05:37
kirby!!!

i need help with this:

If you'll recall from our discussion of Storing Values with the Assignment Operator, everything to the right of the equal sign is resolved before the value is assigned. This means we can take the return value of a function and assign it to a variable.

Assume we have pre-defined a function sum which adds two numbers together, then:

ourSum = sum(5, 12);

will call sum function, which returns a value of 17 and assigns it to ourSum variable.

Instructions
Call the processArg function with an argument of 7 and assign its return value to the variable processed.

Paul Manning
@paulmanning
Apr 17 2016 05:38
@tenkdayz Thanks Frank!
CamperBot
@camperbot
Apr 17 2016 05:38
paulmanning sends brownie points to @tenkdayz :sparkles: :thumbsup: :sparkles:
:star: 407 | @tenkdayz | http://www.freecodecamp.com/tenkdayz
Frank XC
@tenkdayz
Apr 17 2016 05:41
@EldarT90
while (newArr[i]<1000) {
    if (newArr.indexOf(newArr[i]) > -1) {  // indexOf(newArr[i]) will never be -1 because youre looping through them
kirbyedy
@kirbyedy
Apr 17 2016 05:42
@henrywashere ok and?
Eldar Tinjić
@EldarT90
Apr 17 2016 05:42
@tenkdayz its not a problem, i remove them from an array
@tenkdayz what i want to do is apply this: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
@tenkdayz problem is in incrementing i, counter is 1 , it should be 500 or 1000 ,depending on the way im incrementing i
@tenkdayz but certainly not 1
Frank XC
@tenkdayz
Apr 17 2016 05:44
@EldarT90 oh nice.. ok.
Eldar Tinjić
@EldarT90
Apr 17 2016 05:45
@tenkdayz but i++; wont work or newArr[i] = newArr[i*2] wont work
problem is there, dont know the right syntax
Frank XC
@tenkdayz
Apr 17 2016 05:48
@EldarT90 you want to change how much you increment i correct?
Eldar Tinjić
@EldarT90
Apr 17 2016 05:49
@tenkdayz yes, because tactic is : 1. chcek if 2 is in array - yes it is; 2. ok great, remove 2 and check if 4 is in array ? - yes it is; ok great, check if 8 is in array, etc
Frank XC
@tenkdayz
Apr 17 2016 05:50
var increment = 2; // at the start then you hit 1000 or whatever change it to the next number
in the for loop ( var i=2;i<arr.length;i+=increment)
Eldar Tinjić
@EldarT90
Apr 17 2016 05:52
oke let me try
function sumPrimes(num) {
  var newArr = Array.apply(null, Array(1000)).map(function (_, i) {return i;});
  var counter = 0;
  var increment = 2;

  for (i=2;i<newArr.length;i+=increment) {

    while (newArr[i]<1000) {

    if (newArr.indexOf(newArr[i]) > -1) {
      newArr.splice(newArr[i]);
      counter += 1;  

    }}

  return counter;

}
}

sumPrimes(10);
counter still teturns 1
Frank XC
@tenkdayz
Apr 17 2016 05:53
@EldarT90 ok so if increment == a prime ? change its value... but you have to discard all the values in the array that are divisible by that prime.
Eldar Tinjić
@EldarT90
Apr 17 2016 05:53
well, we need to solve step 1 first
i think adding another loop that increments var increment could be good solution
to check for 3,4,etc
but first it must work for 2
in order to continue
Brian
@Brian984
Apr 17 2016 06:17
If you declare a variable in a for loop, do the values defined for that var only exist in that iteration of the for loop, or do they carry on over to all the loop iterations?
Paul Borawski
@iAmNawa
Apr 17 2016 06:18
They go to loops inside of the loop, not outside of the loop
@Brian984
Frank XC
@tenkdayz
Apr 17 2016 06:33
@EldarT90 any luck/
Mike Haslam
@Ongomobile
Apr 17 2016 06:33
Hello campers! I am struggling with record collection challenge this is what I have so far ```
Paul Borawski
@iAmNawa
Apr 17 2016 06:34
Hello Mike @Ongomobile Let’s resolve this issue
Eldar Tinjić
@EldarT90
Apr 17 2016 06:35
@tenkdayz not rly, i am focusing on another callenges
Mike Haslam
@Ongomobile
Apr 17 2016 06:40
This message was deleted
Mike Haslam
@Ongomobile
Apr 17 2016 06:46
function updateRecords(id, prop, value) {
 if(value !== ""){
  collection[id].artist = value; 
 } else if(prop !== "tracks"){
   collection[id].tracks[prop]collection.push;
 } else if(value === "") {
   delete collection.prop;
 }

  return collection;
}
@iAmNawa sorry had trouble with formatting having trouble with record collection chalenge
This is my function so far
Frank XC
@tenkdayz
Apr 17 2016 06:54
@Ongomobile collection[id].tracks.push(value)
Mike Haslam
@Ongomobile
Apr 17 2016 06:59
@tenkdayz thanks for help for some reason having weird problem whit chat room
CamperBot
@camperbot
Apr 17 2016 06:59
ongomobile sends brownie points to @tenkdayz :sparkles: :thumbsup: :sparkles:
:star: 408 | @tenkdayz | http://www.freecodecamp.com/tenkdayz
Mike Haslam
@Ongomobile
Apr 17 2016 07:05
@tenkdayz @iAmNawa Starting over step by step so hopefully can understand
Paul Borawski
@iAmNawa
Apr 17 2016 07:06
That one does take a minute
@Ongomobile
Mike Haslam
@Ongomobile
Apr 17 2016 07:07
depends how fast your clock is mine i slow
Paul Borawski
@iAmNawa
Apr 17 2016 07:07
I meant it as the expression lol, i meant like that one takes a while
@Ongomobile
Mike Haslam
@Ongomobile
Apr 17 2016 07:08
Ok so i figured out 1st test on to next test
 if(value !== ""){
  collection[id].artist = value; 
 }
second test If the prop parameter is equal to "tracks" and the value isn't an empty string, push the value onto the end of the tracks array
MBJ
@mbjusa
Apr 17 2016 07:20
```
$(document).ready(function() {

    // This is a JQuery method
    $("#mbjbtn").on("click", function() {

        // this clears the div so the quotes don't stack up when the button is pressed again. 
        $("#quote").html("");

          $.getJSON("http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1", function(a) {
          $("#quote").append(a[0].content + "<p>&mdash; " + a[0].title + "</p>")

        });

    });

});

Working on the random quote generator. I have the following problem.

```

I get the same quote back each time I press the new quote button (#mbjbtn).
ALMY91
@ALMY91
Apr 17 2016 07:23
hi guys is anybody able to help me out here
MBJ
@mbjusa
Apr 17 2016 07:24
If I disable the button and run it, then refresh the site using F5, I get a different quote each time as intended.
Any thoughts?
ALMY91
@ALMY91
Apr 17 2016 07:24
i know primitive values are immutable for example for strings
var s= "hello"; //Start with some lowercase text
s.toUpperCase(); //Return "HELLO", but doesn't alter s
s //--> :Hello"; the original string has not changed
is anybody able to do an example of a number and boolean
to show that they are immutables?
phorekka
@phorekka
Apr 17 2016 07:25
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
i am stucked here .. i need help of yours..anyone please helpme out
ALMY91
@ALMY91
Apr 17 2016 07:33
hi is anybody in here?
Son Dang
@viiiprock
Apr 17 2016 07:33
var s= "hello";
var a = s.toUpperCase();
return a;
ha, sorry
I don't get your question
ALMY91
@ALMY91
Apr 17 2016 07:35
cld you do an example to show tt a number is immutable
and also a boolean
i got the string one but i do not understand how a number and a boolean are immutables
it would help if you could do something like this with comments like the one i had with the strings
var s= "hello"; //Start with some lowercase text
s.toUpperCase(); //Return "HELLO", but doesn't alter s
s //--> :Hello"; the original string has not changed
Aleksander Gębicki
@Takumar
Apr 17 2016 07:41
@ALMY91 as you showed us in example string is immutable, that means that you cannot change any letter in it, you can reassign s string variable with new string:
var s = "Hello";
s = "New string - this is not changed Hello!!!";
ALMY91
@ALMY91
Apr 17 2016 07:42
@Takumar yep i got the string one alr... but im not clear as to how a number and a boolean are immutables,
Aleksander Gębicki
@Takumar
Apr 17 2016 07:42

@ALMY91 it looks similar:

var a = 9;
a = 8;

but it is a little different thing, it looks better on arrays:

var arr = [4, 6];
arr[0] = 9;
// now your array is [9, 6]
ALMY91
@ALMY91
Apr 17 2016 07:42
@Takumar it would help if ur able to do one example each for a number and a boolean
Aleksander Gębicki
@Takumar
Apr 17 2016 07:43
@ALMY91 you change internal value of variable, you cannot do that with strings.
ALMY91
@ALMY91
Apr 17 2016 07:44
var a = 9;
a = 8;
isn this saying that numbers are mutables?
Aleksander Gębicki
@Takumar
Apr 17 2016 07:44
@ALMY91 yes numbers are mutable
ALMY91
@ALMY91
Apr 17 2016 07:44
i thought primitives are immutables?
Aleksander Gębicki
@Takumar
Apr 17 2016 07:44
sorry I have to leave now, try to look for external resources about that
Son Dang
@viiiprock
Apr 17 2016 07:45
uhm
I did look around
ALMY91
@ALMY91
Apr 17 2016 07:48
sigh i need a smoke
brb
this is frustrating
Bil
@thebiltheory
Apr 17 2016 07:53
Hi guys
I’dd like to have your opinions on my Random quote Machine
Mike Haslam
@Ongomobile
Apr 17 2016 07:53
@iAmNawa here is what I have so far got all test to pass except 3rd one```
Mike Haslam
@Ongomobile
Apr 17 2016 07:53
if(prop === "tracks" && value !== ""){
  collection.tracks.push(value);
 } else if(value !== "") {
  collection[id].artist = value;  
 } else if (value === "") {
   delete collection[id][prop];
 }
Mike Haslam
@Ongomobile
Apr 17 2016 07:54
here is full function
rphares
@rphares
Apr 17 2016 07:55
that article really helped me :blush:
Mike Haslam
@Ongomobile
Apr 17 2016 07:55
function updateRecords(id, prop, value) {
if(prop === "tracks" && value !== ""){
  collection.tracks.push(value);
 } else if(value !== "") {
  collection[id].artist = value;  
 } else if (value === "") {
   delete collection[id][prop];
 }

  return collection;
}
@rphares Thanks will check it out
CamperBot
@camperbot
Apr 17 2016 07:55
ongomobile sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 3981 | @rphares | http://www.freecodecamp.com/rphares
rphares
@rphares
Apr 17 2016 07:55
Sure thing, and happy coding~
Bobby McDonald
@BobbyMcWho
Apr 17 2016 07:56
@Ongomobile collection[prop].push(value)
Mike Haslam
@Ongomobile
Apr 17 2016 07:56
@rphares working on Record collection challenge
@BobbyMcWho thanks will try
CamperBot
@camperbot
Apr 17 2016 07:56
ongomobile sends brownie points to @bobbymcwho :sparkles: :thumbsup: :sparkles:
rphares
@rphares
Apr 17 2016 07:56
yep, i recognise it...
CamperBot
@camperbot
Apr 17 2016 07:56
:star: 235 | @bobbymcwho | http://www.freecodecamp.com/bobbymcwho
rphares
@rphares
Apr 17 2016 07:57
the title of the article may be hint enough of somethings you could experiment with, but thats a much better actual explanation of why than i can give, heh~
Bobby McDonald
@BobbyMcWho
Apr 17 2016 07:58
@Ongomobile sorry, missed it, "collection[id].tracks.push(value)"
Marian Menschig
@mmenschig
Apr 17 2016 08:00
anyone still here? I need a hand...
Mike Haslam
@Ongomobile
Apr 17 2016 08:00
@BobbyMcWho Thanks that was what I needed to pass all test now i just need to understand why! Thanks to all for help was so tempted to look at solution but did not
CamperBot
@camperbot
Apr 17 2016 08:00
ongomobile sends brownie points to @bobbymcwho :sparkles: :thumbsup: :sparkles:
:warning: ongomobile already gave bobbymcwho points
Bobby McDonald
@BobbyMcWho
Apr 17 2016 08:08
@Ongomobile You were forgetting to look at the specific ID number's tracklist. the way you had it you were trying to push a value to the JSON object that didn't exist
Brendan Kinahan
@BKinahan
Apr 17 2016 08:08
yo ho ho and a bottle of good morning
Bobby McDonald
@BobbyMcWho
Apr 17 2016 08:09
so collection[id].tracks exists, while collection.tracks does not, since there is not a "tracks" item directly within the collection array
Mike Haslam
@Ongomobile
Apr 17 2016 08:09
@BobbyMcWho Thanks for explaing!
CamperBot
@camperbot
Apr 17 2016 08:09
ongomobile sends brownie points to @bobbymcwho :sparkles: :thumbsup: :sparkles:
:warning: ongomobile already gave bobbymcwho points
Bobby McDonald
@BobbyMcWho
Apr 17 2016 08:09
No problem! :)
Mike Haslam
@Ongomobile
Apr 17 2016 08:18
@rphares Great article bookmarked it so can refer again!
rphares
@rphares
Apr 17 2016 08:19
Yay! came in handy for me, forget who recommended it, sadly can't credit them, but... i needed it for sure :blush:
V1ad1m1r
@V1ad1m1r
Apr 17 2016 08:38
js
function rot13(str) { // LBH QVQ VG!
//var str2=[];
  for(var x=0; x<= str.length; x++){
 str.charCodeAt(x);
  if(str[x]<65 || str[x]> 91){

  }
    else if(str[x]<78){
    str[x]= str[x]+13;
  }
    else
    str[x]= str[x]-13;
  }

 // str2.toString();
  String.fromCharCode(str);

  return str;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
trying to figure this out :/
negyvenketto
@negyvenketto
Apr 17 2016 08:40
@V1ad1m1r what do you need help with?
Marian Menschig
@mmenschig
Apr 17 2016 08:40
what's not working @V1ad1m1r
V1ad1m1r
@V1ad1m1r
Apr 17 2016 08:40
so the strings are apparently a read only property.
Marian Menschig
@mmenschig
Apr 17 2016 08:41
yeah...strings are immutable
V1ad1m1r
@V1ad1m1r
Apr 17 2016 08:41
I tried using an array instead, but that caused other problems.
so how do I change the value of the string?
Marian Menschig
@mmenschig
Apr 17 2016 08:41
but you could add the encoded version to array or unencoded (".", "," etc) in array too
negyvenketto
@negyvenketto
Apr 17 2016 08:41
@V1ad1m1r you split it
Marian Menschig
@mmenschig
Apr 17 2016 08:41
then join to a string
V1ad1m1r
@V1ad1m1r
Apr 17 2016 08:42
im sorry... can you explain split it?
say you have var str = "Hi my name is Vlad"
V1ad1m1r
@V1ad1m1r
Apr 17 2016 08:43
@mmenschig i tried an erray, but was having issue turning from array back to series of strings.
Marian Menschig
@mmenschig
Apr 17 2016 08:43
then str.split() = ["Hi", "my", "name", "is", "Vlad"]
negyvenketto
@negyvenketto
Apr 17 2016 08:43
@V1ad1m1r you do that with join
V1ad1m1r
@V1ad1m1r
Apr 17 2016 08:43
Sorry again, i understand the split function, but if I split it up will that make the strings changeable?
Marian Menschig
@mmenschig
Apr 17 2016 08:44
no, the string itself is immutable
but why not build a new string with the newly created array
negyvenketto
@negyvenketto
Apr 17 2016 08:44
@V1ad1m1r it you split it to letters, then you can change them one by one
@V1ad1m1r but there are other solutions
Marian Menschig
@mmenschig
Apr 17 2016 08:44
but before you do that, you run your rot13 function over them
negyvenketto
@negyvenketto
Apr 17 2016 08:45
@V1ad1m1r you can loop through the letters of a string without splitting it, and you can construct a new string for the return answer
Marian Menschig
@mmenschig
Apr 17 2016 08:45
oh and to join you use str = arr.join([separator = " "])
V1ad1m1r
@V1ad1m1r
Apr 17 2016 08:45
ok. lemme try all that :)
thanks @mmenschig @negyvenketto
CamperBot
@camperbot
Apr 17 2016 08:45
v1ad1m1r sends brownie points to @mmenschig and @negyvenketto :sparkles: :thumbsup: :sparkles:
:star: 371 | @negyvenketto | http://www.freecodecamp.com/negyvenketto
:star: 246 | @mmenschig | http://www.freecodecamp.com/mmenschig
ALMY91
@ALMY91
Apr 17 2016 08:59
hello guys
can anybody explaiin what this means
if undefined is used where a boolean value is expected, it will convert to false. But this doe snot mean that undefined== false. The if statement converts undefined to false, but the == operator never attempts to convert its operands to booleans
negyvenketto
@negyvenketto
Apr 17 2016 09:04
@ALMY91 i think it means that if you are comparing variables, these variables will not be converted to something else just because you compared them. but if you use a variable somewhere, where only a boolean makes sense, it will be understood as either true or false even if it was not a boolean to begin with
V1ad1m1r
@V1ad1m1r
Apr 17 2016 09:06
js
function rot13(str) { // LBH QVQ VG!
var str2=[];
  var str3= [];
  var str4= [];

  for(var x=0; x<= str.length; x++){
 str2[x]= str.charCodeAt(x);
 if(str2[x]<65 || str2[x]> 91){
    str3[x] = str2[x];
  }
    else if(str2[x]<78){
    str3[x] = str2[x]+13;
  }
    else
    str3[x] = str2[x]-13;
  }

  for(var i=0;i<=str3.length;i++){

  str4[i] = str3.fromCharCode(i); }

  str= str3.join("");


  return str4;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");

Ok. now i get the adjusted uni code, but am having trouble converting the array BACK from uni to letters in a string

error- str3.fromCharCode is not a function

i feel like its a syntax thing.... :/
Rohit Bhal
@rnbhal
Apr 17 2016 09:08
This message was deleted
CamperBot
@camperbot
Apr 17 2016 09:08
:bulb: to format code use backticks! ``` more info
Rohit Bhal
@rnbhal
Apr 17 2016 09:09
function titleCase(str) {
  str = str.split(' ');
  str.map(function(a){
    var b=a[0].toUpperCase(),i=1;
    while(i<a.length){
      b += a[i].toLowerCase();
      i++;
    }
    return b;
  });
  str.join(" ");
  return str;
}

titleCase("I'm a little tea pot");
Title Case a Sentence
what's wrong in it?
negyvenketto
@negyvenketto
Apr 17 2016 09:10
@V1ad1m1r your str3 is an array.
@V1ad1m1r you want to use fromCharCode on its elements
V1ad1m1r
@V1ad1m1r
Apr 17 2016 09:11
@negyvenketto thats what i am trying to do.
@rnbhal what is it returning?
Rohit Bhal
@rnbhal
Apr 17 2016 09:12
@V1ad1m1r ["I'm","a","little","tea","pot"]
Jose Dzireh Chong
@CodingDucky
Apr 17 2016 09:13
help tuple
CamperBot
@camperbot
Apr 17 2016 09:13
no wiki entry for: tuple
Jose Dzireh Chong
@CodingDucky
Apr 17 2016 09:13
help tuples
CamperBot
@camperbot
Apr 17 2016 09:13
no wiki entry for: tuples
negyvenketto
@negyvenketto
Apr 17 2016 09:13
@V1ad1m1r your solution is a bit complicated, it could be done easier, but i'll try to figure it out
Rohit Bhal
@rnbhal
Apr 17 2016 09:14
thnks for the help,i got the solution
V1ad1m1r
@V1ad1m1r
Apr 17 2016 09:14
@rnbhal good :)
@negyvenketto i figured I was going the long way. Im gonna read the help section answers after I get it on my own :)
negyvenketto
@negyvenketto
Apr 17 2016 09:17
@V1ad1m1r you need to review how the fromcharcode works and what goes where in it http://www.w3schools.com/jsref/jsref_fromCharCode.asp (that is, if you want to figure it out for yourself. if not, i can tell you what to write instead of str4[i] = str3.fromCharCode(i);)
V1ad1m1r
@V1ad1m1r
Apr 17 2016 09:17
@negyvenketto i have read this article several times. I would appreciate you telling me :) Is it an issue in my syntax?
negyvenketto
@negyvenketto
Apr 17 2016 09:20
@V1ad1m1r i'm not sure if it is considered syntax :D (i'm also a beginner)
V1ad1m1r
@V1ad1m1r
Apr 17 2016 09:21
@negyvenketto thats fine. at this hour... im ready for the code :)
negyvenketto
@negyvenketto
Apr 17 2016 09:22
@V1ad1m1r str4[i] = String.fromCharCode(str3[i]);
i think this should work
V1ad1m1r
@V1ad1m1r
Apr 17 2016 09:22
HOORAY!!! @negyvenketto That gives me letters!! Hooray!!
but now the end of my strings are red dots?
wtf?
negyvenketto
@negyvenketto
Apr 17 2016 09:23
red dots? O.o
V1ad1m1r
@V1ad1m1r
Apr 17 2016 09:23
wiat... i fixed it :)
too many loops in my for loops
Holy crap that was a beast of a thing
thanks @negyvenketto . I appreciate it alot :)
CamperBot
@camperbot
Apr 17 2016 09:24
v1ad1m1r sends brownie points to @negyvenketto :sparkles: :thumbsup: :sparkles:
:warning: v1ad1m1r already gave negyvenketto points
negyvenketto
@negyvenketto
Apr 17 2016 09:24
you are welcome :)
V1ad1m1r
@V1ad1m1r
Apr 17 2016 09:24
:)
Stanley
@stanleyyylau
Apr 17 2016 09:52
i dont quite understand the challenge "Map the Debris"
can anyone explain the rules a little bit?
Kelvin
@loweehahn
Apr 17 2016 09:59
Why do I get TypeError: compare.toLowerCase() is not a function?
function palindrome(str) {
  // Good luck!
  var compare = str;
  compare = compare.split("");
  compare = /\S+/g;
  compare = compare.toLowerCase();
  compare = compare.reverse();
  compare = compare.join('');

  return compare;
}

palindrome("eye");
Brendan Kinahan
@BKinahan
Apr 17 2016 10:04
@stanleyyylau Although this is a bit simplified, the orbital period of an object is given by T = 2*pi*sqrt(a^3/GM), where a is the radius of the orbit and GM is the standard gravitational parameter, a constant provided to you in the instructions. Your task is to calculate the radius of the orbit by combining the radius of the earth with the object's altitude above the surface of the earth, and then plug the corresponding values into the formula to calculate the orbital period, and finally return the information in the required format.
Rujool Doshi
@rujool
Apr 17 2016 10:06
@loweehahn regular expressions are not strings. They dont have the toLowerCase method defined for them
or any string methods like reverse, join etc.
Kelvin
@loweehahn
Apr 17 2016 10:07
@rujool So how do I return the array without white spaces back to variable compare?
Stanley
@stanleyyylau
Apr 17 2016 10:07
@BKinahan thanks mate let me try it again
CamperBot
@camperbot
Apr 17 2016 10:07
stanleyyylau sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
Brendan Kinahan
@BKinahan
Apr 17 2016 10:07
@loweehahn you're looking for .replace()
CamperBot
@camperbot
Apr 17 2016 10:07
:star: 1317 | @bkinahan | http://www.freecodecamp.com/bkinahan
Ajinkya009
@Ajinkya009
Apr 17 2016 10:08
@loweehahn the .split("") will convert string to an array
Rujool Doshi
@rujool
Apr 17 2016 10:08
as @BKinahan said
@loweehahn
Brendan Kinahan
@BKinahan
Apr 17 2016 10:09
@loweehahn note that just before the regex assignment, compare is an array, and replace() is a method of strings
Rujool Doshi
@rujool
Apr 17 2016 10:10
Can any1 give me a hint on how to solve No repeats please?
Brendan Kinahan
@BKinahan
Apr 17 2016 10:10
@loweehahn also your regex should remove other punctuation/symbols in addition to removing whitespace characters
Brendan Kinahan
@BKinahan
Apr 17 2016 10:10
@rujool sure, have you tried something already?
Rujool Doshi
@rujool
Apr 17 2016 10:10
@BKinahan no..cant figure how to start
Brendan Kinahan
@BKinahan
Apr 17 2016 10:11
@rujool are you familiar with recursion?
Rujool Doshi
@rujool
Apr 17 2016 10:11
@BKinahan yes
Brendan Kinahan
@BKinahan
Apr 17 2016 10:12
@rujool the idea is to first use recursion to generate all possible permutations of the input string
once you have those, you can filter out which ones don't match the requirement of no repeating letters, and count how many do match
Rujool Doshi
@rujool
Apr 17 2016 10:14
@BKinahan ok will try that, thanks
CamperBot
@camperbot
Apr 17 2016 10:14
rujool sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star: 1318 | @bkinahan | http://www.freecodecamp.com/bkinahan
Rujool Doshi
@rujool
Apr 17 2016 10:15
@BKinahan is it possible without generating all permutations?
i mean how complex would it be for say "abcdefg" ?
Brendan Kinahan
@BKinahan
Apr 17 2016 10:16
there may be a mathematical solution, but my mathematics isn't advanced enough to figure it out :)
"abcdefg" has 5040 total permutations
Rujool Doshi
@rujool
Apr 17 2016 10:18
@BKinahan ok will try with recursion
Brendan Kinahan
@BKinahan
Apr 17 2016 10:18
@rujool if you get stuck, this is the recommended permutating algorithm: https://en.wikipedia.org/wiki/Heap%27s_algorithm
V1ad1m1r
@V1ad1m1r
Apr 17 2016 10:19
help cipher
CamperBot
@camperbot
Apr 17 2016 10:19

:point_right: algorithm caesars cipher [wiki]

:triangular_flag_on_post: Remember to use Read-Search-Ask if you get stuck. Try to pair program :busts_in_silhouette: and write your own code :memo:

:checkered_flag: Problem Explanation:

  • You need to write a function, which will take a string encoded with
    Caesar cipher as a parameter and decode it.
  • The one used here is ROT13 where the value of the letter is
    shifted by 13 places.
    e.g. 'A' ↔ 'N', 'T' ↔ 'G'.
  • You have to shift it back 13 positions, such that 'N' ↔ 'A'.

:pencil: read more about algorithm caesars cipher on the FCC Wiki

ionakathryn
@ionakathryn
Apr 17 2016 10:31
if (strokes == par+2)
{
return 'Double Bogey';
}
why is this not working? i dont understand
Brendan Kinahan
@BKinahan
Apr 17 2016 10:32
@ionakathryn you probably need more code than that.
ionakathryn
@ionakathryn
Apr 17 2016 10:33
I am working on the golf challenge
I have more code...all is working apart from this line of code til the end....its returning bogey...i dont get it
Brendan Kinahan
@BKinahan
Apr 17 2016 10:34
@ionakathryn then the problem is probably with the section that decides to return "Bogey" rather than this section.
ionakathryn
@ionakathryn
Apr 17 2016 10:35
haha yes all works..!
Kelvin
@loweehahn
Apr 17 2016 10:35
How can I remove all punctuation and white spaces in a string?
ionakathryn
@ionakathryn
Apr 17 2016 10:35
thanks i wasnt paying enough aatention with >=par :P
Brendan Kinahan
@BKinahan
Apr 17 2016 10:39
@loweehahn learn regular expressions :D https://regexone.com and https://regex101.com
Blauelf
@Blauelf
Apr 17 2016 10:52
Another regex playground I recommend: regexr.com
Wiki also has a page on JS RegExp resources
Achilleas Papakonstantinou
@AchiPapakon
Apr 17 2016 11:11
help Build a Recipe Box
CamperBot
@camperbot
Apr 17 2016 11:11
no wiki entry for: build a recipe box
Achilleas Papakonstantinou
@AchiPapakon
Apr 17 2016 11:11
help Recipe Box
CamperBot
@camperbot
Apr 17 2016 11:11
no wiki entry for: recipe box
Soumya Rauth
@soumyaRauth
Apr 17 2016 11:22
need help with "Profile Lookup"
buddies are you there to help a bit.
tuukkaUosukainen
@tuukkaUosukainen
Apr 17 2016 11:31
Stephen James
@sjames1958gm
Apr 17 2016 11:31
@tuukkaUosukainen YEs
tuukkaUosukainen
@tuukkaUosukainen
Apr 17 2016 11:31
I would love to know what is wrong with my code.
@sjames1958gm would you mind helping me?
Stephen James
@sjames1958gm
Apr 17 2016 11:31
Sure
tuukkaUosukainen
@tuukkaUosukainen
Apr 17 2016 11:32
Here is my code. It's probably too much code. It passes all other steps except for third.
Stephen James
@sjames1958gm
Apr 17 2016 11:32
What code do you have
tuukkaUosukainen
@tuukkaUosukainen
Apr 17 2016 11:34
var compare = 0;
function findLongestWord(str) {
  var splitStr = str.split(" ");
  for(var i = 0; i < splitStr.length; i++) {
    if(splitStr[i].length > compare) {
      compare = splitStr[i].length;   
    } 
  }
  return compare;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
Stephen James
@sjames1958gm
Apr 17 2016 11:35
@tuukkaUosukainen Does it work for the first and maybe not for later ones
tuukkaUosukainen
@tuukkaUosukainen
Apr 17 2016 11:35
it works for all others except for the third
when I change the paragraph to "May the force be with you" it returns 5 which I think is correct?
Rajanshu Ujjwal
@theLuciferSunny
Apr 17 2016 11:37
help me anyone , i am unable to understand the concept of Par and Strokes in the golf game.
CamperBot
@camperbot
Apr 17 2016 11:37
no wiki entry for: me anyone i am unable to understand the concept of par and strokes in the golf game
Stephen James
@sjames1958gm
Apr 17 2016 11:37
@tuukkaUosukainen When you run the tests, any global variables are not reset between tests
Rajanshu Ujjwal
@theLuciferSunny
Apr 17 2016 11:38
i am unable to understand the concept of par and strokes in the golf game
tuukkaUosukainen
@tuukkaUosukainen
Apr 17 2016 11:38
Ok, so that is the mistake. Thanks, I'll try to make it work.
Rajanshu Ujjwal
@theLuciferSunny
Apr 17 2016 11:38

``` function golfScore(par, strokes) {
// Only change code below this line

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

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

tuukkaUosukainen
@tuukkaUosukainen
Apr 17 2016 11:38
Thank you! @sjames1958gm
CamperBot
@camperbot
Apr 17 2016 11:38
tuukkauosukainen sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 675 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Apr 17 2016 11:38
@theLuciferSunny The first number you get is "par" the second number is "strokes"
Rajanshu Ujjwal
@theLuciferSunny
Apr 17 2016 11:39
@sjames1958gm ok, then.
Stephen James
@sjames1958gm
Apr 17 2016 11:39
@theLuciferSunny if (strokes == par - 2 ) return "Eagle";
@theLuciferSunny Basically duplicate the table in your code
@tuukkaUosukainen Did you get it?
Rajanshu Ujjwal
@theLuciferSunny
Apr 17 2016 11:40
Ok. @sjames1958gm thank u
CamperBot
@camperbot
Apr 17 2016 11:40
thelucifersunny sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
Rajanshu Ujjwal
@theLuciferSunny
Apr 17 2016 11:40
trying
CamperBot
@camperbot
Apr 17 2016 11:40
:star: 676 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
tuukkaUosukainen
@tuukkaUosukainen
Apr 17 2016 11:40
@sjames1958gm I put the compare variable inside the function and it worked. You rule, man. Any advise on how to make code more efficient?
Stephen James
@sjames1958gm
Apr 17 2016 11:43
@tuukkaUosukainen You could use array.reduce and Math.max, rather than a for loop.
  return str.split(' ').reduce(function(prev, curr) {
    return Math.max(prev, curr.length);
  }, 0);
Elbert Cortez
@trip16661
Apr 17 2016 11:44
i trully don't see what's wrong with this :/
function convertHTML(str) {
 var specialChar = ["&","<",">","'",'"'];  // &colon;&rpar; &amp; &AM
 var specialCharHtml = ["&amp;","&lt;","&gt;","&apos;","&quot;"];
 var result; 
 for(var a = 0;a < specialChar.length; a++){
   if(str.indexOf(specialChar[a]) > -1){
     result = str.replace(/&<>"'/g,specialCharHtml[a]);
   }
 }

  return result;
}

convertHTML("Dolce & Gabbana");
it looks like a sexy code to me
tuukkaUosukainen
@tuukkaUosukainen
Apr 17 2016 11:46
@sjames1958gm oh that looks like valuable info! Thanks need to investigate this further!
CamperBot
@camperbot
Apr 17 2016 11:46
tuukkauosukainen sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: tuukkauosukainen already gave sjames1958gm points
Stephen James
@sjames1958gm
Apr 17 2016 11:47
@tuukkaUosukainen :+1:
@trip16661 What is your regexp doing
Elbert Cortez
@trip16661
Apr 17 2016 11:59
@sjames1958gm if the string matches in the array then replace the special characters with the value of the same index as the special character array
Stephen James
@sjames1958gm
Apr 17 2016 11:59
@trip16661 Won't replace them all on the first pass with &amp; ?
Islam Ibakaev
@dagman
Apr 17 2016 12:00
@trip16661 this one looks more neaty :smile:
function convertHTML(str) {
  var chars = {
     "&": "&amp;",
     "<": "&lt;",
     ">": "&gt;",
     "'": "&apos;",
     '"': "&quot;"
  };
  return str.split('').map(function(el) {
    return chars[el] ? chars[el] : el; 
  }).join('');
}
convertHTML("Dolce & Gabbana");
Stephen James
@sjames1958gm
Apr 17 2016 12:01
@dagman You changed your picture.
Elbert Cortez
@trip16661
Apr 17 2016 12:01
@sjames1958gm y it will but it's not even working xD
Islam Ibakaev
@dagman
Apr 17 2016 12:01
@sjames1958gm yep :smile:
Elbert Cortez
@trip16661
Apr 17 2016 12:02
@dagman thanks but i preffer using or creating it based on my logics
CamperBot
@camperbot
Apr 17 2016 12:02
trip16661 sends brownie points to @dagman :sparkles: :thumbsup: :sparkles:
:star: 416 | @dagman | http://www.freecodecamp.com/dagman
Stephen James
@sjames1958gm
Apr 17 2016 12:02
@trip16661 I think some of those are special RegExp characters and may need to be escaped.
Elbert Cortez
@trip16661
Apr 17 2016 12:03
@sjames1958gm what do you mean?
Stephen James
@sjames1958gm
Apr 17 2016 12:03
@trip16661 You can create a regexp from a string r = new RegExp('&', 'g'); and use that in your replace
Elbert Cortez
@trip16661
Apr 17 2016 12:03
y
but the thing is that even if it rempalce all with
what's on the condition
it just not doing anything
just return the unchanged str
so something is wrong with my sintax
Stephen James
@sjames1958gm
Apr 17 2016 12:05
r = new RegExp(specialChar[a], 'g'); "Dolce & Gabbana".replace(r,specialCharHtml[a]);
@trip16661 Also you will overwrite result each time
Elbert Cortez
@trip16661
Apr 17 2016 12:05
why
it should only work if the special string is inside of that str
Stephen James
@sjames1958gm
Apr 17 2016 12:06
@sjames1958gm result = str. this just writes over result if there is more than one special char
If you have an & and then a < then result will overwrite the change for & with the change for <
pgjones72
@pgjones72
Apr 17 2016 12:09
Good morning Lords and Ladies. I have an issue: My code doesn't work.
function findLongestWord(str) {
  var strArray = str.split(' ');
  //searches through elements of array, deletes the smaller of the
  // two numbers
  var longest = 0;
  for (var i = 0; i < strArray.length; i++) {
    if (longest < strArray[i].length) {
   longest = strArray[i].length;
    }}
    //assigns the value of the last index standing to str.length
    str.length = longest;


  return str.length;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
any ideas?
Stephen James
@sjames1958gm
Apr 17 2016 12:10
@pgjones72 Strings are immutable so you cannot do this str.length = longest;
Nikhil Bajaj
@Nikhilbajaj
Apr 17 2016 12:11
doubt.JPG
pgjones72
@pgjones72
Apr 17 2016 12:11
@sjames1958gm ok That might explain my Type Error: "length" is read only error. How do I get around this? I thought the logic was sound
Stephen James
@sjames1958gm
Apr 17 2016 12:12
@pgjones72 Are you trying to return longest ?
Nikhil Bajaj
@Nikhilbajaj
Apr 17 2016 12:12
My program is not running successfully.
Islam Ibakaev
@dagman
Apr 17 2016 12:12
@trip16661 maybe this is what u want
function convertHTML(str) {
 var specialChar = ["&","<",">","'",'"'];  // &colon;&rpar; &amp; &AM
 var specialCharHtml = ["&amp;","&lt;","&gt;","&apos;","&quot;"];

 for(var a = 0; a < specialChar.length; a++){
   if(str.indexOf(specialChar[a]) !== -1){
       var re = new RegExp(specialChar[a], 'g');
     str = str.replace(re, specialCharHtml[a]);
   }
 }

return str;
}

convertHTML("Dolce & Gabbana");
Nikhil Bajaj
@Nikhilbajaj
Apr 17 2016 12:12
Help me out !
CamperBot
@camperbot
Apr 17 2016 12:12
no wiki entry for: me out
pgjones72
@pgjones72
Apr 17 2016 12:13
@sjames1958gm i need to return the length as a number, not the word itself
Stephen James
@sjames1958gm
Apr 17 2016 12:13
@pgjones72 Isn't longest a number
pgjones72
@pgjones72
Apr 17 2016 12:15
@sjames1958gm DOH! I overthunk it. Thanks for pointing out the obvious :)
CamperBot
@camperbot
Apr 17 2016 12:15
pgjones72 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 677 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Apr 17 2016 12:15
@pgjones72 :+1:
@Nikhilbajaj Have you inserted console.log into the code to determine where it is failing? What tests is it failing on.
Nikhil Bajaj
@Nikhilbajaj
Apr 17 2016 12:17
no.. @sjames1958gm
Stephen James
@sjames1958gm
Apr 17 2016 12:18
@Nikhilbajaj That is where I would start on my debugging
Nikhil Bajaj
@Nikhilbajaj
Apr 17 2016 12:19
it is my first program in javascript and don't know why it is not executing.. @sjames1958gm
i don't know why there is no color for the vars and the functions as it will be in sublime text editor.. @sjames1958gm
aerowinc
@aerowinc
Apr 17 2016 12:42
can anyone explain the sort function, why are comparisons done with a-b?
Justin
@daemedeor
Apr 17 2016 13:05
@aerowinc basically sort takes a callback function that has first and previous. < -1 , 0, > 1 are values it uses to sort. so if a > b then a -b > 1, a <b then a-b <1 and a=b then a-b =0
Blauelf
@Blauelf
Apr 17 2016 13:07
In theory, a value <0 is interpreted as "a<b", a value of 0 as "a==b" and a value >0 as "a>b".
In practice, the sorting algorithm is designed so that it has only checks for "a>b" and will expect <=0 or >0 (which would be satisfied by false/true)
@daemedeor So no 1 anywhere, should all be zero.
Justin
@daemedeor
Apr 17 2016 13:08
well actually there is a 0 check
so 0 is a valid stay in place
Blauelf
@Blauelf
Apr 17 2016 13:10
That's not really true, as function(a,b){ return a>b; } works, too (so 0 is interpreted as a<=b). Negative or zero as return value are treated the same in the algorithms I know.
Justin
@daemedeor
Apr 17 2016 13:10
i'm using MDN's defiition ^.^
Blauelf
@Blauelf
Apr 17 2016 13:11
I was referring to Mozilla source :P (found some link to some discussion whether sort should keep the order of same elements, as it is not specified in the standard, but expected and "living standard")
Justin
@daemedeor
Apr 17 2016 13:12
its easier to use -1 0 1 and one though like their exaple
Blauelf
@Blauelf
Apr 17 2016 13:15
To some extent, but for example function(a,b){ return a-b; } does not follow that pattern.
Blauelf
@Blauelf
Apr 17 2016 13:23

For the -1 0 1 (which might be required by some browsers that actually do see a difference between 0 and negative), one can use the pattern

function isGreater(a, b) {
  return a > b; // or whatever you need for your array elements
}
function compare(a, b) {
  return isGreater(a, b) - isGreater(b, a); // -1, 0, or 1
}
arr.sort(compare);

Works the same if your function is isGreaterOrEqual. isLess would require switching the two calls, effectively negating output.

Islam Ibakaev
@dagman
Apr 17 2016 13:25
hey guys need help with this one. It works strangely. Waits 3/4 of second then outputs numbers all at once instead of output one by one with 3/4 of second interval. What's wrong?
function showNums(array) {
    array.forEach(function(el) {
        setTimeout(function() {
            console.log(el);
        }, 750);
    });
}

showNums([1, 2, 3, 4, 5]);
Justin
@daemedeor
Apr 17 2016 13:26
@Blauelf wouldn't a-b still fit that pattern though?'
Mahdir Kabir
@mahdirkabir
Apr 17 2016 13:26
How do I use the charachter '(' in RegExp? Throws an invalid regexp error
Blauelf
@Blauelf
Apr 17 2016 13:26
@dagman forEach works fast, and it will install several timeouts that will all trigger at about the same time.
Justin
@daemedeor
Apr 17 2016 13:26
@mahdirkabir use \(
Tyler
@tylergross
Apr 17 2016 13:26

good morning all,

function myReplace(str, before, after) {
  var search = "/"+before+"/i";
  var found = str.match(search);
  str = str.replace(before, after);
  return found;
}

myReplace("A quick brown fox Jumped over the lazy dog", "jumped", "leaped");

having trouble with my str.match .... it is returning "null"

Blauelf
@Blauelf
Apr 17 2016 13:26
@mahdirkabir Use \(
Justin
@daemedeor
Apr 17 2016 13:26
woopse
XD
forgot gitter uses that to escape XD
Blauelf
@Blauelf
Apr 17 2016 13:27
@daemedeor a-b will return <0, 0, or >0, not -1, 0, or 1.
Islam Ibakaev
@dagman
Apr 17 2016 13:27
@Blauelf can you fix it to work properly? please :smile:
Mahdir Kabir
@mahdirkabir
Apr 17 2016 13:27
lol thanks @Blauelf
Blauelf
@Blauelf
Apr 17 2016 13:28
@dagman Could do something like
function showNums(array) {
    array.forEach(function(el, index) {
        setTimeout(function() {
            console.log(el);
        }, 750 * (index + 1));
    });
}

showNums([1, 2, 3, 4, 5]);
Islam Ibakaev
@dagman
Apr 17 2016 13:29
@Blauelf thx man u a awesome as always :+1:
CamperBot
@camperbot
Apr 17 2016 13:29
dagman sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1658 | @blauelf | http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Apr 17 2016 13:31
@dagman If your array is sparse (has holes), I would recommend
function showNums(array) {
        var delay = 0;
    array.forEach(function(el, index) {
        setTimeout(function() {
            console.log(el);
        }, delay += 750);
    });
}

showNums([1, 2, 3, 4, 5]);
Islam Ibakaev
@dagman
Apr 17 2016 13:33
@Blauelf will keep it on mind thx :smile:
CamperBot
@camperbot
Apr 17 2016 13:33
dagman sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:warning: dagman already gave blauelf points
Tyler
@tylergross
Apr 17 2016 13:34
function myReplace(str, before, after) {
  var search = "/"+before+"/i";
  var found = str.match(search);
  str = str.replace(before, after);
  return found;
}

myReplace("A quick brown fox Jumped over the lazy dog", "jumped", "leaped");
not sure why str.match(search) is returning "null".. if i switch search for /jumped/i (like search outputs) i get the correct output.... any ideas?
Stephen James
@sjames1958gm
Apr 17 2016 13:35
@tylergross that is not how you build a regexp - to use a variable - var re = new RegExp(before, "i")
Tyler
@tylergross
Apr 17 2016 13:36
@sjames1958gm thanks, I didn't know there was a different syntax for building them through variables
CamperBot
@camperbot
Apr 17 2016 13:36
:star: 678 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
tylergross sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
Pierre Humberdroz
@phumberdroz
Apr 17 2016 14:04
Hey can some guide me thru a problem that I am having with react right now ?
In line 57 I am updating State but i think I update the wrong state and I would like that someone explains me what to do.. :(
https://gist.github.com/bd64f23d93889c87cd026c45d327344a
Stephen James
@sjames1958gm
Apr 17 2016 14:06
@meat147 I have little react expertise. But is the this in the ajax callback the correct one?
Pierre Humberdroz
@phumberdroz
Apr 17 2016 14:08
No I do not think so.. :/ In line 109 I do exactly the same but in FilterableProductTable and not in Searchbar
Stephen James
@sjames1958gm
Apr 17 2016 14:10
And FilterableProductTable works?
Adie Williams
@adieCodes
Apr 17 2016 14:10
This message was deleted
Pierre Humberdroz
@phumberdroz
Apr 17 2016 14:10
@sjames1958gm yes I get my Iinitial State there
Stephen James
@sjames1958gm
Apr 17 2016 14:11
@meat147 your bind(this) should set the correct this
Pierre Humberdroz
@phumberdroz
Apr 17 2016 14:12
Like FilterableProductTable?
Stephen James
@sjames1958gm
Apr 17 2016 14:12
@sjames1958gm You do it in both cases, so not sure why it wouldn't be correct.
Adie Williams
@adieCodes
Apr 17 2016 14:12
Hi all. Completely lost with the Build a Wikipedia Viewer project. I've spent hours trying to understand Cross Domain AJAX request but have got nowhere. I understand that I need to state my origin but I can't figure out what I'm doing wrong, I'm now left with the below (essentially throwing the kitchen sink at it):
  var xhr = new XMLHttpRequest();
  var url = "https://en.wikipedia.org/w/api.php?action=query&titles=Main%20Page&prop=revisions&rvprop=content&format=json";
  xhr.open("GET", url, true);
  xhr.withCredentials = true;
  xhr.setRequestHeader = ('Origin', 'https://e.wikipedia.org');
  xhr.setRequestHeader = ("Content-Type", "application/json; charset=UTF-8");
  xhr.setRequestHeader = ( 'Api-User-Agent', 'Example/1.0' );
  xhr.send();
  console.log(xhr.status);
GoranM88
@GoranM88
Apr 17 2016 14:15
Hi, is anyone working on Everything be true (intermediate javascript bonfire)?
Stephen James
@sjames1958gm
Apr 17 2016 14:16
@thewebologist Since you are not using jquery - maybe this website helps http://cjihrig.com/blog/remote-ajax-calls-using-jsonp/
@GoranM88 I am not, but maybe I can help as I have completed it
Adie Williams
@adieCodes
Apr 17 2016 14:17
Thanks @sjames1958gm, is it much easier with jquery? I'm trying to avoid to get a better understanding but may have got to the point where I'm happy to admit it's beyond me for the moment
CamperBot
@camperbot
Apr 17 2016 14:17
thewebologist sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 679 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Apr 17 2016 14:18
alihammad-gist
@alihammad-gist
Apr 17 2016 14:19
checkCashRegister(3.26, 100.00, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.10], ["QUARTER", 4.25], ["ONE", 90.00], ["FIVE", 55.00], ["TEN", 20.00], ["TWENTY", 60.00], ["ONE HUNDRED", 100.00]])

 should return

[["TWENTY", 60.00], ["TEN", 20.00], ["FIVE", 15], ["ONE", 1], ["QUARTER", 0.50], ["DIME", 0.20], ["PENNY", 0.04]].
Why are quarter dime and penny fractions? Aren't they suppose to be Integers? and do the units above quarter have same rules, can they too be in fractions? Please help.
Bridget
@bridgetfagan3
Apr 17 2016 14:19
for the Celcius to Fahrenheit challenge, can I use celcius ++ to define the variable celcius?
alihammad-gist
@alihammad-gist
Apr 17 2016 14:19
The test i posted is from "Exact Change" checkpoint.
GoranM88
@GoranM88
Apr 17 2016 14:20
@sjames1958gm I pass all the test except the last one, where you have single:NaN. How to check for that condition? Here is the current code:
function truthCheck(collection, pre) {
  // Is everyone being true?
  var num_obj = collection.length;
  var match = [];
  for (var i = 0; i < num_obj; i++) {
    if(collection[i].hasOwnProperty(pre)) { 
      if (((collection[i][pre] !== null) & collection[i][pre] !== 0 & collection[i][pre] !== "" & collection[i][pre] !== undefined)) {
        match.push(true);  
      }
    }
  }
  var counter = 0;

  for(var j = 0; j < match.length; j++) {
    if(match[j] === true) {
      counter += 1;
    }
  }

  if(num_obj == counter) {
    return true;
  }
  else {
    return false;
  }
}
truthCheck([{"single": "double"}, {"single": NaN}], "single");
Stephen James
@sjames1958gm
Apr 17 2016 14:20
@bridgetfagan3 Aren't you passed in the celcius as a parameter to the function?
Adie Williams
@adieCodes
Apr 17 2016 14:21
@sjames1958gm Thanks again, I'm going to roll with jquery
CamperBot
@camperbot
Apr 17 2016 14:21
thewebologist sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: thewebologist already gave sjames1958gm points
Stephen James
@sjames1958gm
Apr 17 2016 14:21
@GoranM88 NaN is a hard one - only NaN fails the test collection[i][pre] === collection[i][pre]
@thewebologist Well, you paid the dues trying to figure out xhr :)
Rohit Bhal
@rnbhal
Apr 17 2016 14:23
function destroyer(arr) {
  // Remove all the values;
  arr = arr.filter(function(b){
    var i=1;
    while(i<arguments.length)
      {
        if(b === arguments[i])
          return false;
        i++;
      }
    return true;
  });
  return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
can anyone help me ?
output is the same array as the arguments0
GoranM88
@GoranM88
Apr 17 2016 14:25
@sjames1958gm Thanks, now it passed.
CamperBot
@camperbot
Apr 17 2016 14:25
goranm88 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 680 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Apr 17 2016 14:25
@GoranM88 :+1:
Eldar Tinjić
@EldarT90
Apr 17 2016 14:30
is it possible to rephrase if statement to work?
function dropElements(arr, func) {

  var trying = arr.filter(func);

  for (i=0;i<arr.length;i++) {
    if(arr[i].indexOf(trying) > 0);
    arr[i].push();
  }

  return arr;
}

dropElements([1, 2, 3], function(n) {return n < 3; });
and ofc to have same effect
Stephen James
@sjames1958gm
Apr 17 2016 14:31
@rnbhal arguments inside the filter function is the arguments for the filter function not the destroyer arguments
Vukasin
@vuleje
Apr 17 2016 14:31

function titleCase(str) {
str=str.toLowerCase();
var arr=str.split(" ");
for(var i = 0;i<arr.length;i++){
arr[i][0]=arr[i][0].toUpperCase();
}
return arr;
}

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

can someone help it work if i want to capitalize whole word (arr[i]=arr[i].toUpperCase();) but doesnt work for first letter only.

Rohit Bhal
@rnbhal
Apr 17 2016 14:32
@sjames1958gm thnks for help
Stephen James
@sjames1958gm
Apr 17 2016 14:32
@rnbhal It all looked right at first
@EldarT90 Isn't trying an array? do you want trying[0]
Eldar Tinjić
@EldarT90
Apr 17 2016 14:34
@sjames1958gm yep, maybe i should convert it to string? because trying0 also wont work
Kelvin
@loweehahn
Apr 17 2016 14:34
Why does this code returns true instead of false?
function palindrome(str) {
  // Good luck!
  var compare = str;

  str = str.replace(/[.,_():/-\?! ]/g, "");
  compare = compare.replace(/[.,_():/-\?! ]/g, "");

  str = str.toLowerCase();
  compare = compare.toLowerCase();

  compare = compare.split('');
  compare = compare.reverse();
  compare = compare.join('');

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

}

palindrome("1 eye for of 1 eye.");
Eldar Tinjić
@EldarT90
Apr 17 2016 14:37
@sjames1958gm problem is also in statement previous arr[i].indexOf
thats giving me an error
Stephen James
@sjames1958gm
Apr 17 2016 14:38
@EldarT90 arr[i] and trying[0] are both integers indexOf wont work
Rohit Bhal
@rnbhal
Apr 17 2016 14:39
@loweehahn after replacing the string the number "1" is removed too plz fix that
Eldar Tinjić
@EldarT90
Apr 17 2016 14:39
@sjames1958gm so tihs is not the best approach to this problem ... well all i need is to substract element of 1 array from another; and it looks like JS is very crappy in such things