These are chat archives for FreeCodeCamp/HelpJavaScript

15th
Apr 2016
tekac
@tekac
Apr 15 2016 00:02 UTC
@dagman input? something a user will enter if you prompt it
lizzieshipton
@lizzieshipton
Apr 15 2016 00:02 UTC
Hello! Can anyone help with the Weather App challenge? Cannot get info from my JSON object into my html (I had the same problem with Random Quote Machine and have tried my solution from there with no luck.) Here is my pen: http://codepen.io/lizzieshipton/pen/NNYprM?editors=0010
Brian
@sludge256
Apr 15 2016 00:03 UTC
@Blauelf The API and bot are on different servers.
Islam Ibakaev
@dagman
Apr 15 2016 00:03 UTC
@Blauelf is this good?
function multiplyAll(arr) {
  return arr.reduce(function(a, b) {return a.concat(b)}).reduce(function(a, b) {return a * b});
}
Blauelf
@Blauelf
Apr 15 2016 00:03 UTC
Sure, but the bot could at least feel a little bit depressed if it lost connection.
Brian
@sludge256
Apr 15 2016 00:04 UTC
Add a sad face to the message? :P
Islam Ibakaev
@dagman
Apr 15 2016 00:05 UTC
its 3:05 a.m. already :worried:
Blauelf
@Blauelf
Apr 15 2016 00:05 UTC
@dagman At least it's pretty unreadable, mission accomplished :P Also, that arr = is not needed, does not change anything.
Coy Sanders
@coymeetsworld
Apr 15 2016 00:05 UTC
@lizzieshipton I think your url is missing a part
need the appid
appid=<yourappid> part i mean
Islam Ibakaev
@dagman
Apr 15 2016 00:06 UTC
@Blauelf i think for loops works quicklier?
lizzieshipton
@lizzieshipton
Apr 15 2016 00:06 UTC
@coymeetsworld i think the appid is included after the +lon, no?
that is the api key that i got from open weather map
Coy Sanders
@coymeetsworld
Apr 15 2016 00:06 UTC
no the key is probably fine, but you need to specify that it is the key with appid=X
lizzieshipton
@lizzieshipton
Apr 15 2016 00:06 UTC
ahh
ok
Coy Sanders
@coymeetsworld
Apr 15 2016 00:07 UTC
like with lon=, lat=, right
lizzieshipton
@lizzieshipton
Apr 15 2016 00:10 UTC
@coymeetsworld okay i added that but still nothing is showing on the page. I'm wondering if it's something to do with the function i have written?
Coy Sanders
@coymeetsworld
Apr 15 2016 00:10 UTC
whats your url look like?
Blauelf
@Blauelf
Apr 15 2016 00:10 UTC

@dagman Loops are quicker, each function call has some overhead (so for long code blocks the overhead is relatively smaller). I think I would add some standard values, so that it works on empty array, like

return arr.reduce((arr1, arr2)=>arr1.concat(arr2), []).reduce((prod, num) => prod*num, 1);

, or use

return [].concat.apply([], arr).reduce((prod, num) => prod*num, 1);
lizzieshipton
@lizzieshipton
Apr 15 2016 00:11 UTC
"http://www.api.openweathermap.org/data/2.5/weather?" + "lat=" + position.coords.latitude + "&lon=" + position.coords.longitude + "&APPID=57a5a72171b9dedbcf2ed19869746bbc"
evanday17
@evanday17
Apr 15 2016 00:11 UTC
@khaduch hey are you still here?
Coy Sanders
@coymeetsworld
Apr 15 2016 00:11 UTC
one sec @lizzieshipton
remove the www?
lizzieshipton
@lizzieshipton
Apr 15 2016 00:12 UTC
i also tried that
actually i've taken it out and put it back in a few times lol
zico
@zico0o
Apr 15 2016 00:12 UTC

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

function checkObj(checkProp) {
// Your Code Here

myObj.hasOwnProperty("checkProp");
return myObj[checkProp];

}

// Test your code by modifying these values
checkObj("house");
how to return "not found" if my object hasn't has the property of hasOwnProperty function

Coy Sanders
@coymeetsworld
Apr 15 2016 00:12 UTC
what does position.coords.latitude and position.coords.longitude return? do you get anything from that?
Blauelf
@Blauelf
Apr 15 2016 00:12 UTC
Are you on HTTPS and trying to do a HTTP request?
Coy Sanders
@coymeetsworld
Apr 15 2016 00:13 UTC
i actually put that all into a variable string, printed out the variable before i ran it in the call
and tested that in a browser to see if i got a response, maybe try that first to make sure you're getting proper coordinates
lizzieshipton
@lizzieshipton
Apr 15 2016 00:13 UTC
@coymeetsworld if i just do the navigator.geolocation part and use .html i can get the position.coords results to show
Coy Sanders
@coymeetsworld
Apr 15 2016 00:13 UTC
and also that would verify your appid working
Blauelf
@Blauelf
Apr 15 2016 00:14 UTC
Oh, just added some http:// in front of the api.openweathermap.org, that one was missing on the codepen...
lizzieshipton
@lizzieshipton
Apr 15 2016 00:15 UTC
@coymeetsworld so...stringify (result)? I've actually tried that too and gotten nothing. @Blauelf I've tried it both ways - with http: and without.
Coy Sanders
@coymeetsworld
Apr 15 2016 00:15 UTC
no i mean before you call your json function
lizzieshipton
@lizzieshipton
Apr 15 2016 00:15 UTC
OMG WAIT
got it
Coy Sanders
@coymeetsworld
Apr 15 2016 00:15 UTC
what was the issue?
Blauelf
@Blauelf
Apr 15 2016 00:15 UTC
With http://, it shows some strange string "cmc stations14606787012934246Dusseldorf200"
lizzieshipton
@lizzieshipton
Apr 15 2016 00:16 UTC
combination of removing www and adding http (the one combo I hadn't tried yet)
Brian
@sludge256
Apr 15 2016 00:16 UTC
@zico0o Use an if
Coy Sanders
@coymeetsworld
Apr 15 2016 00:16 UTC
oh right yeah needs to be http://api.blah
lizzieshipton
@lizzieshipton
Apr 15 2016 00:16 UTC
so weird. why is that? why http but not www?
Coy Sanders
@coymeetsworld
Apr 15 2016 00:16 UTC
because that is the actual url
a browser will usually fill it in for you
lizzieshipton
@lizzieshipton
Apr 15 2016 00:16 UTC
oh so there is actually no www in front of the url
Coy Sanders
@coymeetsworld
Apr 15 2016 00:17 UTC
like when you type google.com it really will do the whole thing http://www.google.com
Blauelf
@Blauelf
Apr 15 2016 00:17 UTC
www is just the name of an HTTP server by convention. It has no meaning. The server could have any name, and api.something.tld is the convention for api calls (but not one that strong)
zico
@zico0o
Apr 15 2016 00:17 UTC
@sludge256 i'm can't get the right condition i tried many things but can't run logically
lizzieshipton
@lizzieshipton
Apr 15 2016 00:18 UTC
@coymeetsworld @Blauelf is that something that applies to APIs in general...for example, the open weather map site just says "api.openweathermap.org" and doesn't specify that you need http in front. so all API urls need to have http added to the beginning? (sorry total newb here...)
Coy Sanders
@coymeetsworld
Apr 15 2016 00:19 UTC
believe so yes, also had the same problems w/ that
lizzieshipton
@lizzieshipton
Apr 15 2016 00:20 UTC
okay cool. man that was driving me crazy lol. thanks @coymeetsworld thanks @Blauelf !
CamperBot
@camperbot
Apr 15 2016 00:20 UTC
lizzieshipton sends brownie points to @coymeetsworld and @blauelf :sparkles: :thumbsup: :sparkles:
:star: 561 | @coymeetsworld | http://www.freecodecamp.com/coymeetsworld
:star: 1641 | @blauelf | http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Apr 15 2016 00:20 UTC
If you don't specify a protocol (or // for same-protocol-as-here), your URL is relative path on the same server. Like all those dead links with href="www.google.com". Simply does not work, as this could also be a path on your server (relative to current path), and the browser should not guess.
Brian
@sludge256
Apr 15 2016 00:21 UTC
@zico0o
if object has this property
  return the property
else
 return a message saying not found
Coy Sanders
@coymeetsworld
Apr 15 2016 00:21 UTC
yw @lizzieshipton
:thumbsup: @Blauelf
Blauelf
@Blauelf
Apr 15 2016 00:22 UTC
BTW, // is not of much help for many free APIs, as they only exist on HTTP.
Brian
@sludge256
Apr 15 2016 00:23 UTC
@zico0o Try posting an attempt at the conditional.
zico
@zico0o
Apr 15 2016 00:24 UTC

function checkObj(checkProp) {
// Your Code Here
if (myObj.checkProp ===true){
myObj.hasOwnProperty("checkProp");

return myObj[checkProp];
}
else {
return "not Found";
}

} @sludge256

Blauelf
@Blauelf
Apr 15 2016 00:25 UTC
@zico0o if (myObj.hasOwnProperty(checkProp)) - you want to know whether myObj has a property of the name stored in argument checkProp
zico
@zico0o
Apr 15 2016 00:25 UTC
i understand it logically but can't get the right syntax yet !!
Blauelf
@Blauelf
Apr 15 2016 00:26 UTC
"checkProp" is not that variable, it's a string.
Brian
@sludge256
Apr 15 2016 00:27 UTC
In addition to @Blauelf 's message, make sure your output messages match the expected results exactly (capitalization, spacing, etc).
zico
@zico0o
Apr 15 2016 00:27 UTC
i want to know how to return false if hasOwnProperty wasn't fount
Blauelf
@Blauelf
Apr 15 2016 00:27 UTC
Also, myObj.checkProp is same as myObj["checkProp"], and not what you want. You did it right in the return statement, and that's the only place where you need it anyway.
Brian
@sludge256
Apr 15 2016 00:28 UTC
If you use hasOwnProperty() inside your conditional it will evaluate to a boolean.
Taking care of your if/else flow.
evanday17
@evanday17
Apr 15 2016 00:29 UTC
anyone feel like taking a look at my JS.......i want to run a function using a variable (user input from function before) as an argument.....when i do that it crashes my browser......if i call the function manually entering a number it works fine...i don't understand
Limelightbuzz
@Limelightbuzz
Apr 15 2016 00:29 UTC
thanks @leftynaut for your help with Checkpoint: Record Collection
CamperBot
@camperbot
Apr 15 2016 00:29 UTC
limelightbuzz sends brownie points to @leftynaut :sparkles: :thumbsup: :sparkles:
:star: 483 | @leftynaut | http://www.freecodecamp.com/leftynaut
zico
@zico0o
Apr 15 2016 00:29 UTC
at if condition checkProp pass as a variable not string ?? remove quotes ??
evanday17
@evanday17
Apr 15 2016 00:30 UTC

'''
var max;

var perc;

var calculatedResult;

var enterWeight;

var enterPercentage;

var plates = [45, 35, 25, 15, 10, 5, 2.5];

function calculateWeight () {

max = document.getElementById('max');

perc = document.getElementById('percentage');

enterWeight = max.value;

enterPercentage = perc.value;

calculatedResult = enterWeight * enterPercentage / 100;

if (document.getElementById('male').checked === true) {

calculatedResult = calculatedResult - 45; 

} else {

calculatedResult = calculatedResult - 35; 

}

console.log('enterWeight', enterWeight);

console.log('enterPercentage', enterPercentage);

console.log(calculatedResult);

document.getElementById('result').innerHTML = 'Load Up ' + calculatedResult + ' lbs'

}

var plates = [45, 35, 25, 10, 5, 2.5];
var putThemOn = [0,0,0,0,0,0];

function whatPlates(calculatedResult){

var i = 0;

while (i < plates.length) {
if (2plates[i]<=calculatedResult) {
calculatedResult = calculatedResult - (2
plates[i]);
putThemOn[i] += 2;
}
if (2*plates[i]>=calculatedResult) {
i++;
}
}
return putThemOn;
}
console.log(whatPlates(500));

CamperBot
@camperbot
Apr 15 2016 00:30 UTC
:bulb: to format code use backticks! ``` more info
evanday17
@evanday17
Apr 15 2016 00:30 UTC

'''
var max;

var perc;

var calculatedResult;

var enterWeight;

var enterPercentage;

var plates = [45, 35, 25, 15, 10, 5, 2.5];

function calculateWeight () {

max = document.getElementById('max');

perc = document.getElementById('percentage');

enterWeight = max.value;

enterPercentage = perc.value;

calculatedResult = enterWeight * enterPercentage / 100;

if (document.getElementById('male').checked === true) {

calculatedResult = calculatedResult - 45; 

} else {

calculatedResult = calculatedResult - 35; 

}

console.log('enterWeight', enterWeight);

console.log('enterPercentage', enterPercentage);

console.log(calculatedResult);

document.getElementById('result').innerHTML = 'Load Up ' + calculatedResult + ' lbs'

}

var plates = [45, 35, 25, 10, 5, 2.5];
var putThemOn = [0,0,0,0,0,0];

function whatPlates(calculatedResult){

var i = 0;

while (i < plates.length) {
if (2plates[i]<=calculatedResult) {
calculatedResult = calculatedResult - (2
plates[i]);
putThemOn[i] += 2;
}
if (2*plates[i]>=calculatedResult) {
i++;
}
}
return putThemOn;
}
console.log(whatPlates(500));

CamperBot
@camperbot
Apr 15 2016 00:30 UTC
:bulb: to format code use backticks! ``` more info
evanday17
@evanday17
Apr 15 2016 00:30 UTC
hmmm not sure why the formatting isn't working =(
Blauelf
@Blauelf
Apr 15 2016 00:31 UTC
@camperbot told you, follow that link.
zico
@zico0o
Apr 15 2016 00:34 UTC
thanks @Blauelf @sludge256
CamperBot
@camperbot
Apr 15 2016 00:34 UTC
zico0o sends brownie points to @blauelf and @sludge256 :sparkles: :thumbsup: :sparkles:
:star: 1642 | @blauelf | http://www.freecodecamp.com/blauelf
:star: 2224 | @sludge256 | http://www.freecodecamp.com/sludge256
Blauelf
@Blauelf
Apr 15 2016 00:34 UTC
@zico0o Quotes show that something is a string literal, a value of type string written in javascript code. If you assign that to a variable, you won't start using quotes around that variable name (the meaning of that would be a string that happens to have that variable name inside, but without any connection to the variable).
zico
@zico0o
Apr 15 2016 00:38 UTC
i can't check for a string in if condition statement i use it as a var without quotes inside my condition.
it run correctly, i was only confused with the right syntax for the condition.
thanks again @Blauelf
CamperBot
@camperbot
Apr 15 2016 00:38 UTC
zico0o sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:warning: zico0o already gave blauelf points
Blauelf
@Blauelf
Apr 15 2016 00:39 UTC
@zico0o You don't know that string in advance, so you don't use a string literal, but you get the string as an argument to your function.
Kevin Mulligan
@kmulligan
Apr 15 2016 00:39 UTC
@Blauelf since you seem to know what you're talking about :) can you explain truthy to me
Blauelf
@Blauelf
Apr 15 2016 00:41 UTC
Truthy is not falsy. And falsy is any of those six values 0, null, false, undefined, NaN, "". They have in common that truthy values when converted or coerced to boolean become true, and falsy values become false. Most functions that expect a boolean in reality also accept truthy/falsy values. That's how while (arr.length && !func(arr[0])) arr.shift(); works, A&&B evaluates to A if A is falsy, else to B.
evanday17
@evanday17
Apr 15 2016 00:42 UTC
anyone feel like taking a look at my JS.......i want to run a function using a variable (user input from function before) as an argument.....when i do that it crashes my browser......if i call the function manually entering a number it works fine...i don't understand
Jae Kim
@JSOdin
Apr 15 2016 00:42 UTC
@evanday17 sure just use the correct formatting ~~~js
Blauelf
@Blauelf
Apr 15 2016 00:43 UTC
@evanday17 Show code
evanday17
@evanday17
Apr 15 2016 00:43 UTC
let me try that again lol @JSOdin
Blauelf
@Blauelf
Apr 15 2016 00:43 UTC
Backticks, please :)
Jae Kim
@JSOdin
Apr 15 2016 00:43 UTC
@evanday17 its ~js <Your code here> ~
@evanday17 "~js your code here ~"
o_o
Blauelf
@Blauelf
Apr 15 2016 00:44 UTC
```js
your code here
```
Kevin Mulligan
@kmulligan
Apr 15 2016 00:44 UTC
@Blauelf okay so if I'm checking collection to see if pre is truthy or falsy on all elements of the array, do I need a giant OR statement such as if collection[i] === 0 || null || ... etc. ?
evanday17
@evanday17
Apr 15 2016 00:44 UTC
var max;

var perc;

var calculatedResult; 

var enterWeight; 

var enterPercentage;

var plates = [45, 35, 25, 15, 10, 5, 2.5];

function calculateWeight () { 

 max = document.getElementById('max');

  perc = document.getElementById('percentage');

  enterWeight = max.value; 

  enterPercentage = perc.value;  

  calculatedResult = enterWeight * enterPercentage / 100; 



  if (document.getElementById('male').checked === true) {  

    calculatedResult = calculatedResult - 45; 

  } else { 

    calculatedResult = calculatedResult - 35; 

  } 

  console.log('enterWeight', enterWeight); 

  console.log('enterPercentage', enterPercentage);

  console.log(calculatedResult); 

  document.getElementById('result').innerHTML = 'Load Up ' + calculatedResult + ' lbs'



}

var plates = [45, 35, 25, 10, 5, 2.5];
var putThemOn = [0,0,0,0,0,0];

function whatPlates(calculatedResult){

  var i = 0;

  while (i < plates.length) {
    if (2*plates[i]<=calculatedResult) {
      calculatedResult = calculatedResult - (2*plates[i]);
      putThemOn[i] += 2;
    }
    if (2*plates[i]>=calculatedResult) {
      i++;
    }
  }
  return putThemOn;
}
console.log(whatPlates(500));

function doubleIt(inpoot) {
  var fortyFive = inpoot[0];
  var thirtyFive = inpoot[1];
  var twentyFive = inpoot[2];
  var ten = inpoot[3];
  var five = inpoot[4];
  var twoPointFive = inpoot[5];
  return"Put on " + fortyFive + " 45 lb. plates, " + (fortyFive/2) + " on each side," +
  "\n Put on " + thirtyFive + " 35 lb. plates, " + (thirtyFive/2) + " on each side," +
  "\n Put on " + twentyFive + " 25 lb. plates, " + (twentyFive/2) + " on each side," +
  "\n Put on " + ten + " 10 lb. plates, " + (ten/2) + " on each side," +
  "\n Put on " + five + " 5 lb. plates, " + (five/2) + " on each side," +
  "\n Put on " + twoPointFive + " 2.5 lb. plates, " + (twoPointFive/2) + " on each side";
}

console.log(doubleIt(putThemOn));
zico
@zico0o
Apr 15 2016 00:44 UTC

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

function checkObj(checkProp) {
// Your Code Here
if (myObj.hasOwnProperty(checkProp)){

return myObj[checkProp];
}
else
return "Not Found";

}

// Test your code by modifying these values
checkObj("house");
here house is passed at checkObj Arg (checkProp) and also to hasOwnProperty (checkProp) to be checked . but can't check check

checkProp as a string thats what u mean right :D
evanday17
@evanday17
Apr 15 2016 00:45 UTC
@Blauelf @JSOdin done
zico
@zico0o
Apr 15 2016 00:45 UTC
the last code worked :D
@Blauelf
Blauelf
@Blauelf
Apr 15 2016 00:47 UTC

@kmulligan You could

if (collection[i] === 0 || collection[i] === null || collection[i] === false || collection[i] === undefined || collection[i] === "" || collection[i] !== collection[i]) {
  console.log("Falsy!")
}

or you could simply

if (!collection[i]) {
  console.log("Falsy");
}
Jae Kim
@JSOdin
Apr 15 2016 00:48 UTC
@evanday17 ok your standalone code works, but youre saying it dont work when you feed the input via a form?
@evanday17 we also need to see your html I believe lol
Blauelf
@Blauelf
Apr 15 2016 00:48 UTC
! will be true for falsy, false for truthy values (that's why !! converts to boolean, negating twice)
evanday17
@evanday17
Apr 15 2016 00:48 UTC
@JSOdin console.log(whatPlates(500)); work fine but when i try console.log(whatPlates(calculatedResult)); it crashes.......i want to run the function based off the user input
let me throw it on a codepen
Kevin Mulligan
@kmulligan
Apr 15 2016 00:49 UTC
@Blauelf Ok, but I'm not understanding how to test the elements for the second argument. Or am I looking to put if(!collection[i]) into a function to use array.every(callback)?
Jae Kim
@JSOdin
Apr 15 2016 00:49 UTC
@evanday17 gotcha
Diego Mayer
@Chrono79
Apr 15 2016 00:50 UTC
@Blauelf what about Boolean(value) ?
Blauelf
@Blauelf
Apr 15 2016 00:50 UTC
@Chrono79 That will do about the same as !! (!! is shorter, but Boolean is a function, and for falsy bouncer a function is really useful)
@kmulligan You could use a function like function(elem) { return pre in elem && elem[pre]; } (if pre is not a key to elem, elem[pre] would silently fail and evaluate to undefined, which is also falsy, so one could skip the first part and just return elem[pre])
Tyler
@tylergross
Apr 15 2016 00:54 UTC
having an issue with a for() function....
for(){
one second
for(){
if(){
}else if(){
}
}
problem im having is that the function is returning the values for the final for loop
do i use a break; command to completely exit the for loop?
Blauelf
@Blauelf
Apr 15 2016 00:56 UTC
Too tired to understand that.
Tyler
@tylergross
Apr 15 2016 00:56 UTC
lol
Jae Kim
@JSOdin
Apr 15 2016 00:57 UTC
@evanday17 ok well I put your js code into an inline script in the html and it works
@evanday17 ithink you referenced your script wrong from the html
Tyler
@tylergross
Apr 15 2016 00:57 UTC
is it possible to exit out of a for loop early?
Jae Kim
@JSOdin
Apr 15 2016 00:57 UTC
@evanday17 what kind of error u got?
Blauelf
@Blauelf
Apr 15 2016 00:58 UTC
@tylergross Too much guessing the context. Yes, break breaks a loop (unless using labels breaks just one loop), just not sure what you want to achieve.
evanday17
@evanday17
Apr 15 2016 00:58 UTC
it just crashes
Jae Kim
@JSOdin
Apr 15 2016 00:58 UTC
@evanday17 <script src="BBC.js"></script> <== you need to delete this part, when you type into the JS box on codepen I believe codepen includes that script for you automatically
evanday17
@evanday17
Apr 15 2016 00:59 UTC
yeah but i need that for my local file
Kevin Mulligan
@kmulligan
Apr 15 2016 00:59 UTC
@Blauelf is that what you meant?
function truthCheck(collection, pre) {
  // Is everyone being true?

    function hasPre(collection,pre) {
      return collection[pre];
    }

  return collection.every(hasPre);

}

truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex");
Jae Kim
@JSOdin
Apr 15 2016 00:59 UTC
@evanday17 wont work in codepen because codepen looks for BBC.js which doesnt exist
evanday17
@evanday17
Apr 15 2016 01:00 UTC
it doesn't work on my local files though,...it just crashes
Jae Kim
@JSOdin
Apr 15 2016 01:00 UTC
@evanday17 on your local html file, check if you have the pathing correct
Tyler
@tylergross
Apr 15 2016 01:00 UTC

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

     }else{
       return "No such property";
     }
}else{
  return "No such contact";
}

}
// Only change code above this line
}

Jae Kim
@JSOdin
Apr 15 2016 01:00 UTC
@evanday17 is your html on the same level of your BBC.js file?
@evanday17 if not, you will have issues
Tyler
@tylergross
Apr 15 2016 01:00 UTC
wow that didnt format right
evanday17
@evanday17
Apr 15 2016 01:00 UTC
you tried console.log(calcualtedResult)); and it worked?
Tyler
@tylergross
Apr 15 2016 01:00 UTC

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

     }else{
       return "No such property";
     }
}else{
  return "No such contact";
}

}
// Only change code above this line
}

evanday17
@evanday17
Apr 15 2016 01:01 UTC
@JSOdin not sure i understand what you mean by same level/.
?
Jae Kim
@JSOdin
Apr 15 2016 01:01 UTC
@evanday17 same directory level
Blauelf
@Blauelf
Apr 15 2016 01:01 UTC
@kmulligan No.
function truthCheck(collection, pre) {
  function truthyPre(elem) {
    return elem[pre];
  }
  return collection.every(truthyPre);
}
@tylergross
help format
CamperBot
@camperbot
Apr 15 2016 01:02 UTC

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

This an inline `<paste code here>` code formatting with a single backtick(`) at start and end around the code.

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

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

Tyler
@tylergross
Apr 15 2016 01:02 UTC
function lookUpProfile(firstName, prop){
// Only change code below this line
  var contact = "";
  for(var i = 0; i < contacts.length; i++){
    if(contacts[i]["firstName"] == firstName){
         if(contacts[i][prop]){
           return contacts[i][prop];

         }else{
           return "No such property";
         }
    }else{
      return "No such contact";
    }
  }
// Only change code above this line
}
awesome so thats the function but the problem im having is it returns the value of the final check in the for loop
Kevin Mulligan
@kmulligan
Apr 15 2016 01:03 UTC
@Blauelf Hmm. Can you explain how truthyPre can ... use? if that's the right term, use pre even though it wasn't part of the (elem) part?
Chris Lacaille
@ChrisL108
Apr 15 2016 01:03 UTC
@tylergross Did that ork for you? I'm on the same one
Diego Mayer
@Chrono79
Apr 15 2016 01:03 UTC
@tylergross return "No such contact"; should be outside the for
Tyler
@tylergross
Apr 15 2016 01:04 UTC
did not work for me, and i'll try that
Kevin Mulligan
@kmulligan
Apr 15 2016 01:04 UTC
..just realized @Chrono79 is for Chrono Trigger. Epic.
Blauelf
@Blauelf
Apr 15 2016 01:04 UTC
@tylergross You should use contacts[i].hasOwnProperty(prop) or prop in contacts[i] to test for property, as a falsy value would trigger the "No such property" path.
Jae Kim
@JSOdin
Apr 15 2016 01:04 UTC
@evanday17 i did try console.log(calculatedResult) after I used the form, yes it returns a number.
Tyler
@tylergross
Apr 15 2016 01:04 UTC
thanks @Blauelf i'll give that a try
CamperBot
@camperbot
Apr 15 2016 01:04 UTC
tylergross sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1643 | @blauelf | http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Apr 15 2016 01:05 UTC
@kmulligan truthyPre can use all variables declared in outer scopes, for example the arguments to the outer function.
Chris Lacaille
@ChrisL108
Apr 15 2016 01:05 UTC
Is this the wrong approach?

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

// Only change code above this line
}
Blauelf
@Blauelf
Apr 15 2016 01:06 UTC
You should not return "No such contact" before you have tested them all. Return that after your loop.
Chris Lacaille
@ChrisL108
Apr 15 2016 01:06 UTC
@Blauelf Oh I see
Kevin Mulligan
@kmulligan
Apr 15 2016 01:07 UTC
@Blauelf Ok that makes sense, and you called it elem since you are testing the elements in collection not the collections in collection?
Tyler
@tylergross
Apr 15 2016 01:08 UTC
amazing how misplacement of that "no such contact" return can mess up the entire script. works perfectly now i've been stuck researching this one for a few hours now
Chris Lacaille
@ChrisL108
Apr 15 2016 01:08 UTC
@tylergross Can i see what your solution was?
I need something to compare to lol
Blauelf
@Blauelf
Apr 15 2016 01:08 UTC
@kmulligan Yes. Every probably just like filter passes the element, the index, and the array, I just ignore all but the first.
Kevin Mulligan
@kmulligan
Apr 15 2016 01:09 UTC
@Blauelf thanks for the explanation
CamperBot
@camperbot
Apr 15 2016 01:09 UTC
kmulligan sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1644 | @blauelf | http://www.freecodecamp.com/blauelf
Jackson Bates
@JacksonBates
Apr 15 2016 01:12 UTC

Hey guys, little theory question for anyone with a bit of JS experience: which of these methods for iterating through an array is considered better?

//https://www.freecodecamp.com/challenges/iterate-through-an-array-with-a-for-loop
function incrementArrayOutput(arr) {
  for (var i = 0; i < arr.length; i++) {
    console.log(arr[i]);
  }
}

// is this 'better'?
function traverseArrayOutput(arr) {
  for (var index in arr) {
    console.log(arr[index]);
  }
}

var arr = [1,2,3];

incrementArrayOutput(arr);
traverseArrayOutput(arr);

I ask because to me the one I called 'traverse' seems cleaner, but the FCC lesson teaches the 'increment' method. I was wondering if that was because it was better practice, or just because the increment method works when only accessing odd/even arr elements and they didn;t want to teach both mehods? Any ideas?

kuldeep
@Guru89
Apr 15 2016 01:14 UTC
Can any one tell me how to complete the Caesars Cipher challenge, how to iterate a given string without using an array.
Diego Mayer
@Chrono79
Apr 15 2016 01:15 UTC
@JacksonBates with the logic of the incrementArrayOutput for you can iterate no only one by one, you can use the increment you want there, also you can run backwards if you use a decrement, the other way you run through all of the items one by one in ascending order
henrywashere
@henrywashere
Apr 15 2016 01:16 UTC

i need help with this exercise:

One way to think of a multi-dimensional array, is as an array of arrays. When you use brackets to access your array, the first set of bracket refers to the entries in the outer-most array, and each subsequent level of brackets refers to the next level of entries inside.

Example

var arr = [
[1,2,3],
[4,5,6],
[7,8,9],
[[10,11,12], 13, 14]
];
arr[0]; // equals [1,2,3]
arr1; // equals 6
arr[3]0; // equals 11
Instructions
Read from myArray using bracket notation so that myData is equal to 8

Jae Kim
@JSOdin
Apr 15 2016 01:16 UTC
@JacksonBates I believe the for... in syntax checks if each item is enumerable so the runtime is longer
500seeds
@500seeds
Apr 15 2016 01:25 UTC
encode
hi guys, quick question: Encode the following sequence, separated by spaces:
backslash tab tab carriage-return new-line and assign it to myStr
am i suppose to apply all escaped sequences in there?
Jae Kim
@JSOdin
Apr 15 2016 01:29 UTC
yes
Jackson Bates
@JacksonBates
Apr 15 2016 01:29 UTC
@JSOdin you're right - just found this: http://blog.humphd.org/vocamus-1205/?p=1205
My favourite quote from this: "This is one of those things that everyone knows not to do, so they never mention it, and new developers never get told it's bad. Well, it's bad. And it bears repeating." Thanks :)
CamperBot
@camperbot
Apr 15 2016 01:29 UTC
jacksonbates sends brownie points to @jsodin :sparkles: :thumbsup: :sparkles:
:star: 228 | @jsodin | http://www.freecodecamp.com/jsodin
Jae Kim
@JSOdin
Apr 15 2016 01:30 UTC
@JacksonBates np :)
Lisa
@aGirlWhoCodes
Apr 15 2016 01:31 UTC
Hello Everyone, I am having a problem with removing spaces from a string.. I tried to do it like this: str = str.replace(/\s/g, ""); but it doesn't seem to work.. What am I doing wrong??
Jae Kim
@JSOdin
Apr 15 2016 01:38 UTC
@aGirlWhoCodes err thats the right regex I think
@aGirlWhoCodes let me try
Duncan T
@dtweedle
Apr 15 2016 01:38 UTC
@aGirlWhoCodes Seems right, post the rest of your code.
Jae Kim
@JSOdin
Apr 15 2016 01:40 UTC

@aGirlWhoCodes ~~~js
var str = "dog gone good";

console.log(str.replace(/\s/g,''))
~~~
returned "doggonegood" as expected

Christian
@cenamorado1
Apr 15 2016 01:40 UTC
can anyone help with the testing objects assignment?/??
Jae Kim
@JSOdin
Apr 15 2016 01:40 UTC
var str = "dog gone good";

console.log(str.replace(/\s/g,''))
returned "doggonegood" as expected"
Duncan T
@dtweedle
Apr 15 2016 01:40 UTC

@henrywashere

var arr = [
[1,2,3],
[4,5,6],
[7,8,9]]
console.log(arr[0]); // [1, 2, 3]
console.log(arr[0][1]); // 1

Does this help?

@cenamorado1 Whats the problem?
henrywashere
@henrywashere
Apr 15 2016 01:41 UTC
how does arry[0] equals [1,2,3]???
GOD THIS IS CONFUSING
Bobby McDonald
@BobbyMcWho
Apr 15 2016 01:42 UTC
Because it's array-ception
Christian
@cenamorado1
Apr 15 2016 01:42 UTC
this is my code
Bobby McDonald
@BobbyMcWho
Apr 15 2016 01:42 UTC
It's an array or arrays
of*
Christian
@cenamorado1
Apr 15 2016 01:42 UTC

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

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

Duncan T
@dtweedle
Apr 15 2016 01:43 UTC
@henrywashere
So an array can have values like this var array = [1, 2, 3] But instea of numbers it can have another array put inside of it.
Christian
@cenamorado1
Apr 15 2016 01:43 UTC
I've used an if statement as well and still get it wrong
Norvin Burrus
@ndburrus
Apr 15 2016 01:43 UTC
@cenamorado1 i got two of the tests to pass on that one.
js
<// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here



  myObj.hasOwnProperty("checkProp");

  if (true) {
    return myObj[checkProp];
  }
  else {
    return "Not Found";
  }
}
// Test your code by modifying these values
checkObj("house");
>
Christian
@cenamorado1
Apr 15 2016 01:44 UTC
yeah I'm if statement was a little like that
henrywashere
@henrywashere
Apr 15 2016 01:44 UTC
still confused
Norvin Burrus
@ndburrus
Apr 15 2016 01:44 UTC
@cenamorado1 ...for some reason the return of "Not Found" isn't woking...
Christian
@cenamorado1
Apr 15 2016 01:44 UTC
yeah that's what happened to me
Bobby McDonald
@BobbyMcWho
Apr 15 2016 01:44 UTC
@henrywashere Think of an array like a hotwheels car box
it has spaces for each car
Norvin Burrus
@ndburrus
Apr 15 2016 01:45 UTC
@cenamorado1 so the 1st 2 tets passes for u 2?
Duncan T
@dtweedle
Apr 15 2016 01:45 UTC
var array_num = [1, 2, 3]
console.log(array_num[0]); // 1

// Notice we have two sets of brackets here [[]]
var array_array = [[1,2,3]]
console.log(array_array[0]); // [1,2,3]
@cenamorado1
Norvin Burrus
@ndburrus
Apr 15 2016 01:45 UTC
@cenamorado1 tests*
Bobby McDonald
@BobbyMcWho
Apr 15 2016 01:45 UTC
Array = a box; a box can have other boxes in it. and those boxes can have pencils and erasers
Duncan T
@dtweedle
Apr 15 2016 01:46 UTC
@cenamorado1 In the first example the [0] index was a number, in the second example it was an array
Jae Kim
@JSOdin
Apr 15 2016 01:46 UTC
a box within a box within a box wtihin a box within a box within a box
and onwards
henrywashere
@henrywashere
Apr 15 2016 01:46 UTC
oooh ok
Duncan T
@dtweedle
Apr 15 2016 01:47 UTC
@henrywashere @cenamorado1 SOrry got you two mixed up
Christian
@cenamorado1
Apr 15 2016 01:48 UTC
damnit I thought I had a clue
Lisa
@aGirlWhoCodes
Apr 15 2016 01:49 UTC

function palindrome(str) {
  str = str.toLowerCase();
  str = str.replace(/\s/g, "");
  var spaces = str.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]//,'');

  var arr = spaces.split("");

  var reversing = arr.reverse();

  var end = reversing.join("");

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

}
Norvin Burrus
@ndburrus
Apr 15 2016 01:49 UTC
does anyone have working code for the "Testing Objects for Properties" challenge?
Duncan T
@dtweedle
Apr 15 2016 01:50 UTC
@ndburrus Yup, what do you need help with.
Norvin Burrus
@ndburrus
Apr 15 2016 01:51 UTC
@Isymm i posted the code above - the retrurn of false isn't working
@Isymm ...or the return of Not Found
@Isymm 2 of the 3 tests/requirements pass
Duncan T
@dtweedle
Apr 15 2016 01:52 UTC
@ndburrus Your if statement will always return true no matter what you put in there
@Isymm if(true) will always return true.
@ndburrus You need to put a condition in there.
@ndburrus
```js
if (myObj.hasOwnProperty("checkProp");) {
return myObj[checkProp];
}
else {
return "Not Found";
}
Norvin Burrus
@ndburrus
Apr 15 2016 01:54 UTC
@Isymm right, but what if the value being tested (checkProp) evaluates to false (ie it is not in the key/value pair)
Duncan T
@dtweedle
Apr 15 2016 01:54 UTC
@ndburrus
  if (myObj.hasOwnProperty("checkProp");) {
    return myObj[checkProp];
  }
  else {
    return "Not Found";
  }
@ndburrus Thats what the else statement is for.. If the statement is not true ie it does not have that property. Then it will return not found.
Norvin Burrus
@ndburrus
Apr 15 2016 01:55 UTC
@Isymm my not found else statment looks exactly the same - but something must be different
@Isymm hmmm. u wrapped the check inside the if esle statement
@Isymm thanks... im still not sure why my version didnt work - the logic seems valid
CamperBot
@camperbot
Apr 15 2016 01:57 UTC
ndburrus sends brownie points to @isymm :sparkles: :thumbsup: :sparkles:
:star: 309 | @isymm | http://www.freecodecamp.com/isymm
Chris Lacaille
@ChrisL108
Apr 15 2016 01:58 UTC
Hey guys whats the differences in these?
$(elem).on("click", function() {})
```$(elem).click()...
Duncan T
@dtweedle
Apr 15 2016 01:58 UTC

@ndburrus Sorry for got to remove the quote marks and the semi colon.

  if (myObj.hasOwnProperty(checkProp)) {
    return myObj[checkProp];
  }
  else {
    return "Not Found";
  }

Just remember whatever you put inside the brackets of an if statement will be evaluated.

Chris Lacaille
@ChrisL108
Apr 15 2016 01:58 UTC
$(elem).on("click", function() {})
$(elem).click()...
and elem.onclick()
Duncan T
@dtweedle
Apr 15 2016 01:59 UTC
@ChrisL108
.click is a shortcut for jquery. They do the same thing but .click refers back to .on('click' ...
Chris Lacaille
@ChrisL108
Apr 15 2016 01:59 UTC
ah okay.. what about onclick.. is that the old way to do it?
Pretty sure i saw that used before? other than in HTML
Duncan T
@dtweedle
Apr 15 2016 02:00 UTC
@ChrisL108
elem.onclick is the native API for most browsers it doesnt use jquery its just vanilla js
Norvin Burrus
@ndburrus
Apr 15 2016 02:00 UTC
@Isymm alright... :) did u see my code above?
Chris Lacaille
@ChrisL108
Apr 15 2016 02:01 UTC
Gotcha @Isymm Thanks for clarifying
CamperBot
@camperbot
Apr 15 2016 02:01 UTC
chrisl108 sends brownie points to @isymm :sparkles: :thumbsup: :sparkles:
:star: 310 | @isymm | http://www.freecodecamp.com/isymm
Duncan T
@dtweedle
Apr 15 2016 02:01 UTC
@ChrisL108
Same thing as jquery all of them simply bind event listeners to DOM element. The more you use JS you'll notice there are many different ways of attaching event listeners and handlers to DOM elements. Don't worry about being a bit overwhelemed early on.
@ndburrus yup is it workin?
Ken Haduch
@khaduch
Apr 15 2016 02:02 UTC
@evanday17 - kind of here.... I'm pretending to be a cook now... :) Instead of a javascript programmer...
Norvin Burrus
@ndburrus
Apr 15 2016 02:02 UTC
@Isymm the code passed the 1st 2 tests, but not the 3rd (Not Found)
Ken Haduch
@khaduch
Apr 15 2016 02:02 UTC
but your request was quite a while ago...
Duncan T
@dtweedle
Apr 15 2016 02:04 UTC
@ndburrus I ran your code, it passing hte first two tests because your if statement will never reach the second condition.
You need to review how if statements work it's what I'm trying to explain to you.
if (true) {
// THIS WILL ALWAYS HAPPEN YOU CAN'T PUT TRUE AS YOUR CONDITION
} else {
// THIS CODE WILL NEVER EXECUTE BECASUE YOUR STATEMENT IS ALWAYS TRUE!
}
Norvin Burrus
@ndburrus
Apr 15 2016 02:05 UTC
@Isymm ok, but i thought the eval ca produce a true OR false
@Isymm can*
Josh Bivens
@joshbivens
Apr 15 2016 02:07 UTC
Moving into my first week stuck on Diff Two Arrays.
Duncan T
@dtweedle
Apr 15 2016 02:07 UTC
@ndburrus It does, But what you put inside the brackets is the final answer.. the logic is..
if(this statement is true) {
//do this
} else {
// do this.
}
@ndburrus myObj.hasOwnProperty(myProp) return true or false...
Norvin Burrus
@ndburrus
Apr 15 2016 02:08 UTC
@Isymm ok.
Duncan T
@dtweedle
Apr 15 2016 02:09 UTC
@ndburrus I've shown you how to do it further back, read what I try to understand it as best as possible.
Norvin Burrus
@ndburrus
Apr 15 2016 02:10 UTC
@Isymm i understand ur method. that's what im going with.
Duncan T
@dtweedle
Apr 15 2016 02:12 UTC
@ndburrus Great! tricky stuff this code. :)
Norvin Burrus
@ndburrus
Apr 15 2016 02:13 UTC
@Isymm yep. i think the logic is there for the other way o work, but im at the point of diminishing return on that one
@Isymm to*
Jackson Bates
@JacksonBates
Apr 15 2016 02:15 UTC
@joshbivens yeah - that one stumped me for a little while. The trick for me was to really learn how to use array.filter(). I tried reading the MDN entry for it, but it was a youtube video that finally helped it click for me.
Kevin Schwert
@kevinpschwert
Apr 15 2016 02:16 UTC

On the Testing Object for Properties lesson, I figured out the answer. // Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

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

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

But why couldn't you use dot notation for the return like return myObj.checkprop;
why does it have to be bracket notation?
Duncan T
@dtweedle
Apr 15 2016 02:18 UTC
@kevinpschwert you don't need to put the evaluation in there Kevin.. === true. All you need is the myObj.hasOwnProperty(checkProp) that returns you true or false.
@kevinpschwert You have to sue square brackets because obj.checkprop wont lookup the variable it will look for a property called checkprop..
var obj = {
  foo : 1,
  bar : 2,
  checkProp: 'woops'
}

function check(checkProp) {

  console.log(obj[checkProp]);
  console.log(obj.checkProp);
}

check(foo); // 1 "woops"
@kevinpschwert
@kevinpschwert Actually that example will return woops for both of them but the function illustrates my point. somewhate.
Kevin Schwert
@kevinpschwert
Apr 15 2016 02:32 UTC
I'm not following what you are saying. Sorry. I think I tried to put what you suggested and I am not getting the correct answer. You are saying that I don't need to us an if else statement?
Duncan T
@dtweedle
Apr 15 2016 02:33 UTC
@kevinpschwert
I was trying to show you why you when you are looking for a property name defined in a variable for example
var checkProp = puppies;

obj[checkProp] //Will look for puppies
obj.checkProp // Will look for a property called checkProp
@Isymm You need to use square brackets when you are working with a variable name rather than the actual name of the property..
My previous example was poorly thought out and will just confuse you. Ignore it.
Kevin Schwert
@kevinpschwert
Apr 15 2016 02:35 UTC
Okay. So dot notation is just for actual name of the property while bracket notation is used for the variable name
96street
@96street
Apr 15 2016 02:36 UTC
Can someone tell me why my jQuery slider lags every time it loops? http://codepen.io/anon/pen/XdEVJQ
Duncan T
@dtweedle
Apr 15 2016 02:36 UTC
@kevinpschwert Essentially yes. Only use dot notation when you know the name of the property you are looking up. Square brackets will look up the value of your variable.
@96street No lag for me
96street
@96street
Apr 15 2016 02:38 UTC
When it goes around the 2nd time most of the container is black @Isymm
Duncan T
@dtweedle
Apr 15 2016 02:38 UTC
@96street Ohh. Okay I get you now.. hmm 1 sec
Dylan
@dhcodes
Apr 15 2016 02:39 UTC
@96street it's not black for me but I do notice a touch of lag on one picture
Josh Bivens
@joshbivens
Apr 15 2016 02:40 UTC
Should the Roman Numeral Converter consist of a bunch of ifs?
Duncan T
@dtweedle
Apr 15 2016 02:40 UTC
@joshbivens There will be a few of them in there. XD
96street
@96street
Apr 15 2016 02:40 UTC
When it goes around after the first time, at one point only the first picture shows @dhcodes
Josh Bivens
@joshbivens
Apr 15 2016 02:41 UTC
@Isymm Ok good :)
96street
@96street
Apr 15 2016 02:41 UTC
Any idea? @Isymm
Dylan
@dhcodes
Apr 15 2016 02:42 UTC
@96street on mine all the pictures show, one or two just take longer to load
96street
@96street
Apr 15 2016 02:43 UTC
But I don't think it's a loading error, because I changed all the pictures and they still loaded at the exact same time @dhcodes
only once the first picture goes back to margin-left: 0 (start) then the others appear
Duncan T
@dtweedle
Apr 15 2016 02:44 UTC
@96street Yeah it's not loading the images until it returns to the first slide. You'll need to think of a way to loop so that there is always at least 3 slides shown
96street
@96street
Apr 15 2016 02:45 UTC
That's kind of my question @Isymm
Duncan T
@dtweedle
Apr 15 2016 02:47 UTC
@96street Yeah the way it's designed is obviously to only shown one slide at a time. You'll need to see if there is a way to load images once it reaches the last 3 instead of the last 1.
Duncan T
@dtweedle
Apr 15 2016 03:00 UTC

@96street A quick solution would be to add the first three slides to the end then once it reaches the end -2 postion reset to slide 1.

like this.

http://codepen.io/Isymm/pen/BKrEyZ?editors=1111

EricOber
@EricOber
Apr 15 2016 03:02 UTC
hey guys i am really needing help with understanding the "Compound Assignment With Augmented Addition"
96street
@96street
Apr 15 2016 03:02 UTC
Ahh yes good idea. Thanks @Isymm
CamperBot
@camperbot
Apr 15 2016 03:02 UTC
96street sends brownie points to @isymm :sparkles: :thumbsup: :sparkles:
:star: 311 | @isymm | http://www.freecodecamp.com/isymm
96street
@96street
Apr 15 2016 03:03 UTC
Do you know why it only shows one slide at a time in my initial code? @Isymm
Duncan T
@dtweedle
Apr 15 2016 03:05 UTC
@96street Essentially all your code does is scroll past these images. The reason you don't see anything is because once it reaches the last image there is nothing there. However as soon as you are reaching the last slide it resets back to the first position. So if we add the three slides to the end of it then when it scrolls back to the start, we won't notice that a switch has occured.
@Am3ricanPaladin Whats the problem?
96street
@96street
Apr 15 2016 03:06 UTC
Makes sense now (Y)
EricOber
@EricOber
Apr 15 2016 03:07 UTC
hey @lsymm I am having trouble understanding the += operator

my assignment looks like this Compound Assignment With Augmented Addition
In programming, it is common to use assignments to modify the contents of a variable. Remember that everything to the right of the equals sign is evaluated first, so we can say:

myVar = myVar + 5;

to add 5 to myVar. Since this is such a common pattern, there are operators which do both a mathematical operation and assignment in one step.

One such operator is the += operator.

myVar += 5; will add 5 to myVar.

Instructions
Convert the assignments for a, b, and c to use the += operator.

code looks like this

var a = 3;
var b = 17;
var c = 12;

// Only modify code below this line

a = a + 12;
b = 9 + b;
c = c + 7;

Duncan T
@dtweedle
Apr 15 2016 03:08 UTC
@Am3ricanPaladin It's a shorthand form so remember that everything on the right hand side of the operator in this case += occurs before the assignment on the left.
EricOber
@EricOber
Apr 15 2016 03:08 UTC
right, the computer reads from right to left
Duncan T
@dtweedle
Apr 15 2016 03:08 UTC
@Isymm
var number = 5;

//Long form would be 

number = number + 5;

//short form 

number += 5;
@Am3ricanPaladin So in that example number is now equal to itself (before the assignment) + 5.
Rodney Jan Mandap
@r0dJm4n
Apr 15 2016 03:10 UTC
Hello Guys, I need help I'm stuck at "Using Objects for Lookups". What is the syntax of lookup?
Duncan T
@dtweedle
Apr 15 2016 03:10 UTC
@Am3ricanPaladin Instead of creating a whole new variable we have simply reassigned the one we were using before to a new number.
EricOber
@EricOber
Apr 15 2016 03:10 UTC
now i dont really understand the "number = number + 5".... basic common sense tells me a number is equal unto itself, a number cannot be plus five of itself... twisting my mind lol
Duncan T
@dtweedle
Apr 15 2016 03:11 UTC
@Am3ricanPaladin SO remember everything on the right hand side happens first.
var number = 5

// new number = old number (5) + 5
number = number + 5;
EricOber
@EricOber
Apr 15 2016 03:12 UTC
hmmm
Johnny K Juarez
@Reapnsow
Apr 15 2016 03:12 UTC

I keep getting
TypeError: Cannot assign to read only property '0' of string 'Hellow World'
My code is
// Setup
var myStr = "Jello World";

// Only change code below this line
myStr = "Hello World";
myStr[0] = "H"; // Fix Me

EricOber
@EricOber
Apr 15 2016 03:13 UTC
Oooooh, ok i see thank you @lsymm
CamperBot
@camperbot
Apr 15 2016 03:13 UTC
am3ricanpaladin sends brownie points to @lsymm :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for lsymm
Duncan T
@dtweedle
Apr 15 2016 03:14 UTC
@Am3ricanPaladin Sorry messed it up before.
Remember we can reassign a variable whenever we want.
var number = 6;

number = 3;

console.log(number) ; // 3

number = number +5;
// is the same as saying make number now equal to 3 + 5.
@Am3ricanPaladin Hope that helps.
Rodney Jan Mandap
@r0dJm4n
Apr 15 2016 03:14 UTC
@Reapnsow Try this
EricOber
@EricOber
Apr 15 2016 03:15 UTC
Ah ha! i got it
Rodney Jan Mandap
@r0dJm4n
Apr 15 2016 03:15 UTC
myStr = "Hello World"
Johnny K Juarez
@Reapnsow
Apr 15 2016 03:17 UTC
@r0dJm4n that gives me the same error as before
Rodney Jan Mandap
@r0dJm4n
Apr 15 2016 03:19 UTC
@Reapnsow Did you remove the myStr[0] = "H";
Duncan T
@dtweedle
Apr 15 2016 03:19 UTC
@Reapnsow you can't do this myStr[0] = 'H' Strings are immutable meaning they can't be cahnged.. You can't access their indices and change them.
Johnny K Juarez
@Reapnsow
Apr 15 2016 03:20 UTC

// Setup
var myStr = "Jello World";

// Only change code below this line

myStr[0] = "H"; // Fix Me

Rodney Jan Mandap
@r0dJm4n
Apr 15 2016 03:20 UTC
@Reapnsow, @Isymm is right you must replace it with new strings
Johnny K Juarez
@Reapnsow
Apr 15 2016 03:20 UTC
@r0dJm4n that's what i'm supposed to fix
Rodney Jan Mandap
@r0dJm4n
Apr 15 2016 03:21 UTC
replace myStr[0] = "H"; with myStr = "Hello World";
Johnny K Juarez
@Reapnsow
Apr 15 2016 03:22 UTC
@r0dJm4n @Isymm thanks, I guess I misunderstood what the lesson was asking me to do.
CamperBot
@camperbot
Apr 15 2016 03:22 UTC
reapnsow sends brownie points to @r0djm4n and @isymm :sparkles: :thumbsup: :sparkles:
:star: 225 | @r0djm4n | http://www.freecodecamp.com/r0djm4n
:star: 312 | @isymm | http://www.freecodecamp.com/isymm
Rodney Jan Mandap
@r0dJm4n
Apr 15 2016 03:22 UTC
Your welcome @Reapnsow :smile:
ALMY91
@ALMY91
Apr 15 2016 03:24 UTC
// 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!=="") {
  if (prop!=="tracks") {[id][prop]=value;}
  else {tracks.push(value);} }

else {delete [prop];}


  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
hey guys can anyone help me out on this
Frank XC
@tenkdayz
Apr 15 2016 03:28 UTC
@ALMY91 collection[id][prop]
Tmore23
@Tmore23
Apr 15 2016 03:29 UTC
This message was deleted
jw1540
@jw1540
Apr 15 2016 03:30 UTC
Hey, I'm incredibly stuck on Symmetric Difference, could someone offer some pointers? I don't particularly want to look at the answer just yet!
Tmore23
@Tmore23
Apr 15 2016 03:30 UTC
var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
  }
  // Add record here
];
does that mean that I have to add the code before the ]; or after ?
henrywashere
@henrywashere
Apr 15 2016 03:31 UTC

need help with this:
An easy way to append data to the end of an array is via the push() function.

.push() takes one or more parameter and "pushes" it onto the end of the array.

var arr = [1,2,3];
arr.push(4);
// arr is now [1,2,3,4]
Instructions
Push ["dog", 3] onto the end of the myArray variable.

i wrote ::

arr.push("dog", 3);

didnt work
Ken Haduch
@khaduch
Apr 15 2016 03:32 UTC
@jw1540 - there is another challenge "Diff Two Arrays" that does a symmetric difference on just two arrays (I didn't realize that and forgot about it.) I don't know if that will help you with this, at least it's a starting point?
jw1540
@jw1540
Apr 15 2016 03:32 UTC
@henrywashere you need to declare a variable called myArray and then push dog and 3 to that
henrywashere
@henrywashere
Apr 15 2016 03:32 UTC
ooooh
jw1540
@jw1540
Apr 15 2016 03:32 UTC
@khaduch I'll take a look; thanks bud!
CamperBot
@camperbot
Apr 15 2016 03:32 UTC
jw1540 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
henrywashere
@henrywashere
Apr 15 2016 03:32 UTC
got it
CamperBot
@camperbot
Apr 15 2016 03:32 UTC
:star: 946 | @khaduch | http://www.freecodecamp.com/khaduch
jw1540
@jw1540
Apr 15 2016 03:32 UTC
@henrywashere :)
henrywashere
@henrywashere
Apr 15 2016 03:32 UTC
thanks @jw1540
CamperBot
@camperbot
Apr 15 2016 03:32 UTC
henrywashere sends brownie points to @jw1540 :sparkles: :thumbsup: :sparkles:
:star: 150 | @jw1540 | http://www.freecodecamp.com/jw1540
Rodney Jan Mandap
@r0dJm4n
Apr 15 2016 03:34 UTC
How to create a lookup table?
ALMY91
@ALMY91
Apr 15 2016 03:37 UTC
@tenkdayz
// 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!=="") {
  if (prop!=="tracks") {collection[id][prop]=value;}
  else {collection[id][prop].push([value]);} }

else {delete [prop];}


  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
@tenkdayz still not working ..
Mohamed Ameen
@pmohdameen
Apr 15 2016 03:41 UTC
remove the square brackets from ([value]) @ALMY91
henrywashere
@henrywashere
Apr 15 2016 03:42 UTC

ITS NOT WORKING...i wrote

var myArray = arr.push("dog", 3);

but it wont go through
jackey610
@jackey610
Apr 15 2016 03:42 UTC

function nextInLine(arr, item) {
// Your code here

return item; // Change this line
}

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

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

Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.
Julian Krispel-Samsel
@juliankrispel
Apr 15 2016 03:42 UTC
arr.push(‘dog’, 3) returns the length of the array
jackey610
@jackey610
Apr 15 2016 03:42 UTC
i need help with this please
Julian Krispel-Samsel
@juliankrispel
Apr 15 2016 03:42 UTC
not the array itself
it’s JavaScripts fault not yours
unfortunately that’s just bad language design
henrywashere
@henrywashere
Apr 15 2016 03:43 UTC
so what do i do???
Instructions
Push ["dog", 3] onto the end of the myArray variable.
ALMY91
@ALMY91
Apr 15 2016 03:44 UTC
@pmohdameen but i thought to add to the end of an array u have to put [] inside push..
Frank XC
@tenkdayz
Apr 15 2016 03:44 UTC
@jackey610 you need to push item then shift array
Julian Krispel-Samsel
@juliankrispel
Apr 15 2016 03:44 UTC
@henrywashere you do this:
you initialize your myArray variable
var myArray = []
then you push to it
myArray.push(‘dog’, 3)
henrywashere
@henrywashere
Apr 15 2016 03:45 UTC
k lemme try that
Mohamed Ameen
@pmohdameen
Apr 15 2016 03:45 UTC
@ALMY91 no you dont have to
jackey610
@jackey610
Apr 15 2016 03:45 UTC
@tenkdayz i don't know where to start though
Julian Krispel-Samsel
@juliankrispel
Apr 15 2016 03:45 UTC
or you simply assign it var myArray = [‘dog’, 3]
like that
:D
ALMY91
@ALMY91
Apr 15 2016 03:45 UTC
@pmohdameen okay but it isn passing through i suppose there is some issue going on my syntax
// 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!=="") {
  if (prop!=="tracks") {collection[id][prop]=value;}
  else {collection[id][prop].push(value);} }

else {delete [prop];}


  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
Frank XC
@tenkdayz
Apr 15 2016 03:46 UTC
@jackey610 just push item into the given array. then shift that array.. return array.
Mohamed Ameen
@pmohdameen
Apr 15 2016 03:46 UTC
@ALMY91 yeah
@ALMY91 you have to change your else statement: else {collection[id][prop].push([value]);} }
jw1540
@jw1540
Apr 15 2016 03:47 UTC
@henrywashere did you solve it?
henrywashere
@henrywashere
Apr 15 2016 03:47 UTC
i wrote
var myArray = ["dog", 3];
didnt go throguh lol
jw1540
@jw1540
Apr 15 2016 03:47 UTC
haha! try this
Mohamed Ameen
@pmohdameen
Apr 15 2016 03:48 UTC
@ALMY91 consider the question : If the prop is "tracks" and value is non-blank, push the value onto the end of the tracks array.
Frank XC
@tenkdayz
Apr 15 2016 03:48 UTC
@ALMY91 I think you have to make the first else and else if with prop==tracks
jw1540
@jw1540
Apr 15 2016 03:48 UTC
````
var myArray = [];
myArray.push("dog", 3);
ALMY91
@ALMY91
Apr 15 2016 03:48 UTC
@pmohdameen um so shd i include the [] or not?
Mohamed Ameen
@pmohdameen
Apr 15 2016 03:48 UTC
@ALMY91 no
@ALMY91 you shouldnt include those
henrywashere
@henrywashere
Apr 15 2016 03:49 UTC
didnt work
Mohamed Ameen
@pmohdameen
Apr 15 2016 03:49 UTC
@ALMY91 and change the syntax as per the question :"If the prop is "tracks" and value is non-blank, push the value onto the end of the tracks array."
The "track" is specified there @ALMY91
henrywashere
@henrywashere
Apr 15 2016 03:50 UTC
gaaaaaaaaaaaaaawd, why is javascript so freakin hard
jw1540
@jw1540
Apr 15 2016 03:50 UTC
@henrywashere can i see your code?
henrywashere
@henrywashere
Apr 15 2016 03:50 UTC
var myArray = [];
myArray.push("dog", 3);
jw1540
@jw1540
Apr 15 2016 03:51 UTC
var myArray = []; 
myArray.push(["dog", 3]);
ALMY91
@ALMY91
Apr 15 2016 03:51 UTC
@pmohdameen i don think the pb lies w tt
@pmohdameen cause the error msg im getting is After updateRecords(2548, "artist", ""), artist should not be set
Mohamed Ameen
@pmohdameen
Apr 15 2016 03:52 UTC

@ALMY91 here is it:

change this: collection[id][prop].push(value)

to

collection[id].tracks.push(value);

henrywashere
@henrywashere
Apr 15 2016 03:52 UTC
didnt work either lol
Mohamed Ameen
@pmohdameen
Apr 15 2016 03:52 UTC
@ALMY91 And please try to understand it :thumbsup:
jw1540
@jw1540
Apr 15 2016 03:53 UTC

@henrywashere I just looked at when I did the challenge, I have this:
```
// Setup
var myArray = [["John", 23], ["cat", 2]];

// Only change code below this line.
myArray.push(["dog", 3]);

myArray shouldn't be empty (apologies! i shoulda double checked the challenge for you)
ALMY91
@ALMY91
Apr 15 2016 03:53 UTC
@pmohdameen not working still..
jw1540
@jw1540
Apr 15 2016 03:53 UTC
for clarity @henrywashere
// Setup
var myArray = [["John", 23], ["cat", 2]];

// Only change code below this line.
myArray.push(["dog", 3]);
Mohamed Ameen
@pmohdameen
Apr 15 2016 03:53 UTC
@ALMY91 oh, there is a problem with the delete
ALMY91
@ALMY91
Apr 15 2016 03:53 UTC
@pmohdameen theres nth wrong w the push value tho im passing the criteria for that
henrywashere
@henrywashere
Apr 15 2016 03:54 UTC
YES IT WORKED
jw1540
@jw1540
Apr 15 2016 03:54 UTC
:D
henrywashere
@henrywashere
Apr 15 2016 03:54 UTC
thanks @jw1540
CamperBot
@camperbot
Apr 15 2016 03:54 UTC
:warning: henrywashere already gave jw1540 points
henrywashere sends brownie points to @jw1540 :sparkles: :thumbsup: :sparkles:
jw1540
@jw1540
Apr 15 2016 03:54 UTC
haha no worries mate, keep at it!
any more help pop me a message, i'd be happy to help :)
henrywashere
@henrywashere
Apr 15 2016 03:54 UTC
awesome, thanks man
Mohamed Ameen
@pmohdameen
Apr 15 2016 03:54 UTC
@ALMY91 change delete line to : delete collection[id][prop];
ALMY91
@ALMY91
Apr 15 2016 03:55 UTC
@pmohdameen actually it doesn make sense.. if value in arguement is empty it doesn mean that previously that property is empty? so why are we deleting everything in tt property
Mohamed Ameen
@pmohdameen
Apr 15 2016 03:57 UTC
@ALMY91 please read the question thoroughly
ALMY91
@ALMY91
Apr 15 2016 04:00 UTC
@pmohdameen yeah i read it through alr but isn tt what they are saying. If value is blank, delete that prop.
@pmohdameen so if a value is blank in the arguement but not in the function, we are deleting the whole property off?
@pmohdameen *deleting the whole property off the function
Mohamed Ameen
@pmohdameen
Apr 15 2016 04:02 UTC
not only from the function but also from the whole record @ALMY91
its a kinda confirmation
Christian
@cenamorado1
Apr 15 2016 04:03 UTC

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

// Only change code below this line

var gloveBoxContents = "myStorage.car.inside[glove box]"; // Change this line

wouldn't gloveBoxContents equal maps???
ALMY91
@ALMY91
Apr 15 2016 04:04 UTC
@pmohdameen okay it just doesn seem practical to me haha..
@pmohdameen but thanks anw
CamperBot
@camperbot
Apr 15 2016 04:04 UTC
almy91 sends brownie points to @pmohdameen :sparkles: :thumbsup: :sparkles:
:star: 265 | @pmohdameen | http://www.freecodecamp.com/pmohdameen
Mohamed Ameen
@pmohdameen
Apr 15 2016 04:04 UTC
:) try reading some extra stuffs too
and what about the challenge ? passed ?
@ALMY91 .
jw1540
@jw1540
Apr 15 2016 04:05 UTC
@cenamorado1 use ``` before and after your code to format it :)
ALMY91
@ALMY91
Apr 15 2016 04:05 UTC
@pmohdameen passed. i was just thinking if say the user happens to forget adding in the value or smth, then the whole property would be deleted off..
@pmohdameen yep i passed the challenge just that im abit confused with the practicality of this haha
jw1540
@jw1540
Apr 15 2016 04:07 UTC
@ALMY91 I think at this point it's just showing how basic functions are done and then as you progress you can look into implementing soft deletes in your applications
by basic functions, i mean crud operations
ALMY91
@ALMY91
Apr 15 2016 04:07 UTC
@jw1540 alright this makes more sense to me haha thanks
jw1540
@jw1540
Apr 15 2016 04:09 UTC
@ALMY91 it's good to be thinking ahead about those things, so props for that! i certainly wasn't haha
Cameron Cooper
@shotgunleo
Apr 15 2016 04:09 UTC

Hey guys so I'm trying to add to this json object. the instructions are to make a new album and have artist title release year and format properties but the tests are saying it doesn't have any properties, any ideas?

// example code

var myMusic = [
{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}
];
// Add record here
myMusic[1] = [
{
"artist": "Childish Gambino",
"title": "Retro [rough]",
"release_year": 2015,
"formats": [
"CD",
"8T" ],
}
];

jackey610
@jackey610
Apr 15 2016 04:10 UTC
@jw1540 hi sir, i sent you a private msg with a problem, can you help me out please?
jw1540
@jw1540
Apr 15 2016 04:11 UTC
@shotgunleo format your code by using ``` before and after the code snippet :)
@jackey610 sure bud, not got a private message though?
Cameron Cooper
@shotgunleo
Apr 15 2016 04:11 UTC
my bad!
// example code

var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
  }
];
  // Add record here
myMusic[1] = [
  {
    "artist": "Childish Gambino",
    "title": "Retro [rough]",
    "release_year": 2015,
    "formats": [
      "CD",
      "8T" ],
  }
];
jw1540
@jw1540
Apr 15 2016 04:13 UTC
@shotgunleo which challenge is it?
Cameron Cooper
@shotgunleo
Apr 15 2016 04:14 UTC
@jw1540 introducing javscript object notation json
Ken Haduch
@khaduch
Apr 15 2016 04:15 UTC
@shotgunleo - you need to add that new entry within the original array, so just before the closing bracket, you enter a comma after the previous object, and then enter your new one in a similar manner. That is what they are expecting
Cameron Cooper
@shotgunleo
Apr 15 2016 04:16 UTC
ah okay I had that before just without a comma so I guess it didn't work, thank you very much!
Robert Carter
@kakulo83
Apr 15 2016 04:29 UTC
Hi all, can anyone recommend a library/strategy to parse this type of api response: http://78.31.66.208:8080/urest/doc/6a665314-44ac-4fd9-af73-ed975fb19018 Would http://pegjs.org/ be suitable?
ZctrapCoding
@ZctrapCoding
Apr 15 2016 04:37 UTC
shoudnt this play music?
var audio = new Audio('http://picosong.com/static/widget/index.html?file=/cdn/789b3fc71aa1e16d256e861ef0965fb1.mp3&autoplay=true');
audio.play();
Frank XC
@tenkdayz
Apr 15 2016 04:44 UTC

@ZctrapCoding

var audio = {};
audio['x'] = new Audio();
audio['x'].src = url;
audio['x'].play()

I think that should work..

Hamelth
@mrWolfhouse
Apr 15 2016 04:56 UTC
can any type of statement exists within a switch function?
Gerard Jorgensen
@gerardjorgensen
Apr 15 2016 05:03 UTC
I'm trying to get the json.forEach loop to work, but I'm having some problems. Is there anyone that can help me with this?
http://codepen.io/GerardJ/pen/RaQPQm
buckshot307
@buckshot307
Apr 15 2016 05:06 UTC
function bouncer(arr) {
  var fix = [];
  function isTrue(value) {
    return value !== false;
  }
  var newArr = arr.filter(isTrue);
  return newArr;
}

bouncer([7, NaN, null, 2, undefined]);
returns [7, null, null, 2, null]
even when I add in things to the return line like value !== null && value !== ""; it still returns null in place of NaN. Anyone know why?
AndrewThM
@AndrewThM
Apr 15 2016 05:10 UTC

Hey, in order to convert Celsius to Farenheit, I have the following solution that doesn't work:

Can someone please explain what I'm doing wrong and how to fix it:
function convertToF(celsius) {
// Only change code below this line
var convertToF = 9/5 + 32;

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

// Change the inputs below to test your code
convertToF(30);
convertToF(20);
convertToF(10);
convertToF(0);
convertToF(-10);
convertToF(-20);

Samuel Cupidon
@Zerazera
Apr 15 2016 05:11 UTC
@AndrewThM Currently your solution would only be correct if fahrenheit = 0
Sorry celsius
Also you're not returning the variable you created
buckshot307
@buckshot307
Apr 15 2016 05:11 UTC
@AndrewThM your function takes an argument celsius and returns fahrenheit, but what you've added doesn't use either of those.
AndrewThM
@AndrewThM
Apr 15 2016 05:13 UTC
I'm trying to create a variable for fahrenheit and apply it to an algorithm to assign it to the corresponding temp in farenheit
Vivienne Sales
@Natto278
Apr 15 2016 05:14 UTC
@buckshot307 You need to create a variable for fahrenheit. IMHO, it's easier to work with decimals than fractions.
buckshot307
@buckshot307
Apr 15 2016 05:15 UTC
yes the variable is the correct equation, but it doesn't use the input argument celsius and doesn't return that value as fahrenheit.
Samuel Cupidon
@Zerazera
Apr 15 2016 05:15 UTC
@AndrewThM Let's break your function down. You start by taking in celsius as a parameter. Then you define a variable named convertToF which is equal to 9/5 + 32. Finally you return the (undeclared) variable fahrenheit.
There are two things wrong with your function. Try to figure out what they are.
Vivienne Sales
@Natto278
Apr 15 2016 05:19 UTC
Sorry, I thought it was your code, @buckshot307 . @AndrewThM you need to create a variable for fahrenheit. IMHO, it's easier to work with decimals than fractions.
AndrewThM
@AndrewThM
Apr 15 2016 05:22 UTC
currently I think I have one thing right: the convertToF(0)

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

var fahrenheit = (9/5 + 32);
// Only change code above this line
return fahrenheit;
}

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

Samuel Cupidon
@Zerazera
Apr 15 2016 05:23 UTC
@AndrewThM Look at how you define fahrenheit
It's only correct when celsius = 0
Vivienne Sales
@Natto278
Apr 15 2016 05:24 UTC
@Andrew ThM Your formula, 9/5 + 32 to convert Celsius to Fahrenheit, does not have a place for the Celsius variable. The correct formula is (Celsius * 9/5) + 32.
Rada
@Radascript
Apr 15 2016 05:30 UTC
hey guys, I keep getting "value.toFixed is not a function" error in my console even though I explicitly checked that 'value' is a number with "typeof" the line before. Has anyone had that issue before?
here's the troublesome part of code:
 while(change>=0.01 && pennies>0)
        {
          console.log(change);
          ansPennies+=0.01;
          console.log(typeof ansPennies);
          console.log(ansPennies = " old PENNIES");
          ansPennies = ansPennies.toFixed(2);
          pennies-=0.01;
          change-=0.01;
        }
AndrewThM
@AndrewThM
Apr 15 2016 05:34 UTC
thanks Vivienne. Completed.
GoranM88
@GoranM88
Apr 15 2016 05:42 UTC

hi, I would need some help with Stemroller problem. When I enter the tests manually into the code they give the correct output however they don't pass.

var my_arr = [];
var steamrollArray = function (arr) {
  if(typeof(arr) == "object") {
    for(var i = 0; i < arr.length; i++) {
      steamrollArray(arr[i]);
    }
  }  
  else {
     my_arr.push(arr);
  }
  return my_arr;
};

steamrollArray([1, {}, [3, [[4]]]]);

Any ideas?

as the task suggests
ALMY91
@ALMY91
Apr 15 2016 06:02 UTC
function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line

 for (var i =0 ; i< arr.length;i++) {
   for(var j=0 ; j<arr[i].length; j++)
     console.log(arr[i][j]);
 }
  // Only change code above this line

  return product;

}



// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
anyone can help me out here..
kirbyedy
@kirbyedy
Apr 15 2016 06:05 UTC
@ALMY91 shouldnt you multiply the elements ?
ALMY91
@ALMY91
Apr 15 2016 06:09 UTC
@kirbyedy
function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line

 for (var i =0 ; i< arr.length;i++) {
   for(var j=0 ; j<arr[i].length; j++)
     console.log(arr[i][j]);
   product*=arr[i][j];
 }
  // Only change code above this line
  return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
@kirbyedy seems like somewhere is wrong..
kirbyedy
@kirbyedy
Apr 15 2016 06:10 UTC
well console log line and the next line are not the same
Jamie Lipschitz
@Jlipschitz
Apr 15 2016 06:10 UTC
@Radascript I think you have to parse it before calling the the toFixed() method. This method converts a number into a string, so I think the second time around your while loops fails because ansPennies is now a string?
ALMY91
@ALMY91
Apr 15 2016 06:10 UTC
@kirbyedy what do u mean tho
kirbyedy
@kirbyedy
Apr 15 2016 06:11 UTC
@ALMY91 if you take that line from the console in the brackets and replace it in the next line after *= ?
Deepak Yadav
@ydeepk
Apr 15 2016 06:11 UTC
Please helpy fellas help me with this challange called "Make object properties private"
kirbyedy
@kirbyedy
Apr 15 2016 06:11 UTC
what will happen
Deepak Yadav
@ydeepk
Apr 15 2016 06:11 UTC

var Bike = function(currentGear) {

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

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

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

};

kirbyedy
@kirbyedy
Apr 15 2016 06:11 UTC
@ALMY91 you are close
although it should be the same
I am testing it now, and it passes
buckshot307
@buckshot307
Apr 15 2016 06:13 UTC
okay so i made an infinite loop on a challenge and now i can't pull that challenge up without my browser crashing. what do?
ALMY91
@ALMY91
Apr 15 2016 06:13 UTC
@kirbyedy it worked thanks. but im just wondering why it didn work when console.log was present
CamperBot
@camperbot
Apr 15 2016 06:13 UTC
almy91 sends brownie points to @kirbyedy :sparkles: :thumbsup: :sparkles:
Paul Manning
@paulmanning
Apr 15 2016 06:13 UTC
@ydeepk check your setGear function. this generally would be to set a value from a parameter passed to the function, and wouldn’t return anything
CamperBot
@camperbot
Apr 15 2016 06:13 UTC
:star: 862 | @kirbyedy | http://www.freecodecamp.com/kirbyedy
Rada
@Radascript
Apr 15 2016 06:14 UTC
@Jlipschitz ahhh that makes sense, so it would work fine the first time and then run into an error. thanks, I'll see if that helps!
CamperBot
@camperbot
Apr 15 2016 06:14 UTC
radascript sends brownie points to @jlipschitz :sparkles: :thumbsup: :sparkles:
:star: 115 | @jlipschitz | http://www.freecodecamp.com/jlipschitz
Deepak Yadav
@ydeepk
Apr 15 2016 06:15 UTC
@paulmanning nope nothing happenning
Paul Manning
@paulmanning
Apr 15 2016 06:15 UTC
@ydeepk like this….
this.setGear = function(val) {
  gear=val;
}
Jamie Lipschitz
@Jlipschitz
Apr 15 2016 06:16 UTC
@buckshot307 clear your cookies or open the challenge from another browser
buckshot307
@buckshot307
Apr 15 2016 06:16 UTC
got it. Had to clear browsing data for the past hour lol.
Deepak Yadav
@ydeepk
Apr 15 2016 06:17 UTC
@paulmanning that worked man. Thanks :-)
CamperBot
@camperbot
Apr 15 2016 06:17 UTC
ydeepk sends brownie points to @paulmanning :sparkles: :thumbsup: :sparkles:
:star: 286 | @paulmanning | http://www.freecodecamp.com/paulmanning
Paul Manning
@paulmanning
Apr 15 2016 06:18 UTC
@ydeepk Happy to help
Rada
@Radascript
Apr 15 2016 06:18 UTC
@Jlipschitz no, errors even if i parse after or in the same line.
Jamie Lipschitz
@Jlipschitz
Apr 15 2016 06:18 UTC
interesting. how are you parsing it?
Rada
@Radascript
Apr 15 2016 06:21 UTC
@Jlipschitz when in one line, like this:
ALMY91
@ALMY91
Apr 15 2016 06:21 UTC

function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line

 for (var i =0 ; i< arr.length;i++) {
   for(var j=0 ; j<arr[i].length; j++)
    console.log (arr[i][j]); 
   product*=arr[i][j];
 }
  // Only change code above this line
  return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
Rada
@Radascript
Apr 15 2016 06:21 UTC
     while(change>=0.01 && pennies>0)
        {
          console.log(change);
          ansPennies+=0.01;
          console.log(typeof ansPennies);
          console.log(ansPennies = " old PENNIES");
          ansPennies = parseFloat(ansPennies.toFixed(2));
          pennies-=0.01;
          change-=0.01;
        }
ALMY91
@ALMY91
Apr 15 2016 06:21 UTC
does anybody know why it doesn work when there is a console.log
but it works when i take away the console.log line tho
Rada
@Radascript
Apr 15 2016 06:21 UTC
when in two lines, I just did the same toFixed, then immediately after parseFloat it
ALMY91
@ALMY91
Apr 15 2016 06:22 UTC
```js

function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line

 for (var i =0 ; i< arr.length;i++) {
   for(var j=0 ; j<arr[i].length; j++)
    console.log (arr[i][j]); 
   product*=arr[i][j];
 }
  // Only change code above this line
  return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
```
Paul Manning
@paulmanning
Apr 15 2016 06:23 UTC
@ALMY91 Try opening up your browser console log and look for errors there. That helps me a lot. Aside from that, perhaps remove the space between the console.log and the ().
Jamie Lipschitz
@Jlipschitz
Apr 15 2016 06:23 UTC
@Radascript you're right... hmm. I actually tried parseFloat(ansPennies).toFixed(2) and it runs but typeof returns string each time. it does increment and decrease though
ALMY91
@ALMY91
Apr 15 2016 06:23 UTC
@paulmanning actually when i take away the console.log line it works
@paulmanning as in the whole line of console.log
@paulmanning taking away the space doesn help tho
Rada
@Radascript
Apr 15 2016 06:26 UTC
@Jlipschitz that's so strange, I wonder what's going on. Mine keeps returning a number but refusing to acknoledge toFixed: http://i.imgur.com/LW2YXyw.jpg
I'll try punching it into codepen or something and see if it's broken there too
kirbyedy
@kirbyedy
Apr 15 2016 06:27 UTC
@ALMY91 as @paulmanning said there is a NaN logged in the console once you run it, and the freecodecamp test does not let you pass
ALMY91
@ALMY91
Apr 15 2016 06:30 UTC
@kirbyedy so ya mean in a normal setting this would actually work?
kirbyedy
@kirbyedy
Apr 15 2016 06:31 UTC
dont know
Rada
@Radascript
Apr 15 2016 06:31 UTC
@ALMY91 I tried it in codepen and it has the same issue
@kirbyedy @ALMY91 even when you console.log(product) before returning it
when you comment out his console.log(arr[i][j]) it works fine
kirbyedy
@kirbyedy
Apr 15 2016 06:34 UTC
if you make it like this it will work:
product*=arr[i][j];
console.log(product);
ALMY91
@ALMY91
Apr 15 2016 06:35 UTC
@kirbyedy is there a reasoning for this?
kirbyedy
@kirbyedy
Apr 15 2016 06:35 UTC
most probably, but I am not so experienced to explain why, sorry :)
Jamie Lipschitz
@Jlipschitz
Apr 15 2016 06:36 UTC

@Radascript

 while(change>=0.01 && pennies>0)
        {
          console.log(change);
          parseFloat(ansPennies+=0.01);
          console.log(typeof ansPennies);
          console.log(ansPennies + " old PENNIES");
          ansPennies = parseFloat(ansPennies.toFixed(2));
           console.log(ansPennies + " new PENNIES");
          pennies-=0.01;
          change-=0.01;
        }

Give this a shot

Rada
@Radascript
Apr 15 2016 06:36 UTC
I'm curious about this issue, because it's concerning to me that console.logging something can actually affect the way your code runs, I would like to know if we need to be more careful about it.
ALMY91
@ALMY91
Apr 15 2016 06:37 UTC
whats the difference between a for loop and a while loop
@Radascript me too but seems like noone here is able to answer the question
Rada
@Radascript
Apr 15 2016 06:38 UTC
@Jlipschitz omg thank you it worked!! You are a breathing gooooooood XD
CamperBot
@camperbot
Apr 15 2016 06:38 UTC
radascript sends brownie points to @jlipschitz :sparkles: :thumbsup: :sparkles:
:warning: radascript already gave jlipschitz points
Chris Lacaille
@ChrisL108
Apr 15 2016 06:38 UTC
@ALMY91 have you attempted any of the lessons?
Samuel Cupidon
@Zerazera
Apr 15 2016 06:38 UTC
@ALMY91 Use a for loop when you know exactly how many times you need to iterate. Use a while loop when you cannot be sure in advance how many times you need to loop and must test a condition.
Chris Lacaille
@ChrisL108
Apr 15 2016 06:38 UTC
Nicely put @Zerazera
Paul Manning
@paulmanning
Apr 15 2016 06:38 UTC
@ALMY91 for loops are good if you need to use the iterator for something. Usually for the index of an array. W while just loops until a condition is not met. you would have to manage the iterator in that loop
yourself
Jamie Lipschitz
@Jlipschitz
Apr 15 2016 06:39 UTC
i think ansPennies+=0.01 at the top was throwing it off for some reason but worked when i forced it to be a float. also you had console.log(ansPennies = " old Pennies) which i switched out to +
Rada
@Radascript
Apr 15 2016 06:39 UTC
@ALMY91 google is not showing me anything either for the consolelog issue. Maybe post on reddit/r/learnprogramming?
Jamie Lipschitz
@Jlipschitz
Apr 15 2016 06:39 UTC
@Radascript awesome!!!
ALMY91
@ALMY91
Apr 15 2016 06:39 UTC
@ChrisL108 @Zerazera yeah i have just wanted a summary of it haha
Samuel Cupidon
@Zerazera
Apr 15 2016 06:39 UTC
@ChrisL108 Thanks
CamperBot
@camperbot
Apr 15 2016 06:39 UTC
zerazera sends brownie points to @chrisl108 :sparkles: :thumbsup: :sparkles:
:star: 79 | @chrisl108 | http://www.freecodecamp.com/chrisl108
ALMY91
@ALMY91
Apr 15 2016 06:39 UTC
@Zerazera thanks
CamperBot
@camperbot
Apr 15 2016 06:39 UTC
almy91 sends brownie points to @zerazera :sparkles: :thumbsup: :sparkles:
Chris Lacaille
@ChrisL108
Apr 15 2016 06:39 UTC
@Radascript how was console.log affecting the code?
CamperBot
@camperbot
Apr 15 2016 06:39 UTC
:star: 368 | @zerazera | http://www.freecodecamp.com/zerazera
ALMY91
@ALMY91
Apr 15 2016 06:39 UTC
@Radascript okay good idea.. before i forget all abt it
Rada
@Radascript
Apr 15 2016 06:40 UTC
@ChrisL108 it's in @ALMY91 's code. It runs fine if you comment out his console.log(arr[i][j]) but doesn't work when it's consoling. Here:

function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line

 for (var i =0 ; i< arr.length;i++) {
   for(var j=0 ; j<arr[i].length; j++)
   console.log(arr[i][j]); 
   product*=arr[i][j];
 }
  // Only change code above this line
    console.log(product);
  return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
Frank XC
@tenkdayz
Apr 15 2016 06:41 UTC
@Radascript @Radascript there's not { after the second loop
Samuel Cupidon
@Zerazera
Apr 15 2016 06:41 UTC
@sonicadept Because the preceding for is not bracketed
@Radascript
Chris Lacaille
@ChrisL108
Apr 15 2016 06:41 UTC
Oh yeah they're right
Rada
@Radascript
Apr 15 2016 06:44 UTC
oh yeah @ALMY91 @kirbyedy look, @tenkdayz @Zerazera solved it. whew that was spooky
Sameer Shamsudeen
@sameershamsudheen
Apr 15 2016 06:44 UTC
hello i was doing check for Palindromes in Basic Algorithm, how do i print the value of string2 and string3 in the console, i used console.log(string2); but it is not working, help me please. here is my code
function palindrome(str) {
  // Good luck!
  var expression = /\W\s/g;
  var string1 = str.replace(expression);
  var string2 = string1.toLowerCase();
  console.log(string2);
  var string3 = function reverse(string2){
    return string2.split("").reverse().join("");
};
if(string3 === str){
    return true;
  }
  else {
    return false;
  }

}

palindrome("eye");
ALMY91
@ALMY91
Apr 15 2016 06:44 UTC
@Radascript wait a min what i didn get it lol
Frank XC
@tenkdayz
Apr 15 2016 06:45 UTC
@sameershamsudheen underscore
Rada
@Radascript
Apr 15 2016 06:45 UTC
@ALMY91 you didn't put brackets around your second for loop, like this:

function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line

 for (var i =0 ; i< arr.length;i++) {
   for(var j=0 ; j<arr[i].length; j++)
     {
   console.log(arr[i][j]); 
   product*=arr[i][j];
     }
 }
  // Only change code above this line
    console.log(product);
  return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
Frank XC
@tenkdayz
Apr 15 2016 06:46 UTC
add one to the regex pattern
Rada
@Radascript
Apr 15 2016 06:46 UTC
so the code was confused about where to go
Elbert Cortez
@trip16661
Apr 15 2016 06:46 UTC
function whereAreYou(collection, source) {
  // What's in a name?
  var arr = [];
  var sourceProperties = Object.keys(source);
  // Only change code below this line
  for(var a = 0;a < collection.length; a++){
    for(var b = 0; b < sourceProperties.length; b++ ){
      if (collection[a].hasOwnProperty(sourceProperties[b])&& 
collection[a].sourceProperties[b] === source.sourceProperties[b]){
        arr.push(collection[a]);
      }

    }
  }

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

whereAreYou([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
ummm what am i doing wrong ?
ALMY91
@ALMY91
Apr 15 2016 06:47 UTC
@Radascript alright thanks
CamperBot
@camperbot
Apr 15 2016 06:47 UTC
almy91 sends brownie points to @radascript :sparkles: :thumbsup: :sparkles:
:star: 311 | @radascript | http://www.freecodecamp.com/radascript
Jamie Lipschitz
@Jlipschitz
Apr 15 2016 06:47 UTC

okay so i figured it out. yes, you did need to parse but your console.log was what was giving you the error for improper syntax. so all you actually need to write is

while(change>=0.01 && pennies>0)
        {
          ansPennies+=0.01
          parseFloat(ansPennies.toFixed(2));
          pennies-=0.01;
          change-=0.01;
        }

BUT when you had:

console.log(ansPennies = " old PENNIES");
// should be console.log(ansPennies + " old PENNIES");

is when you get the error value.toFixed() is not a function. the = operator in there instead of + was the culprit. sorry had to figure this one out, was bugging me lol. @Radascript

Sameer Shamsudeen
@sameershamsudheen
Apr 15 2016 06:47 UTC
@tenkdayz Where to add the underscore
Rada
@Radascript
Apr 15 2016 06:49 UTC
@Jlipschitz omfg this is so silly haha. I think this is my second most embarrassing coding typo that had me breaking my head for hours. tyty
ALMY91
@ALMY91
Apr 15 2016 06:51 UTC
// Setup
var myArray = [];

// Only change code below this line.
var i=0 ;
while(i<5) {myArray.push(i); i++;}
Jamie Lipschitz
@Jlipschitz
Apr 15 2016 06:51 UTC
@Radascript i missed it completely as well so no worries. i think a lot of bugs are due to the most simple errors. learned something along the way so glad i could help as well
Frank XC
@tenkdayz
Apr 15 2016 06:51 UTC
@sameershamsudheen regex pattern
/[\W_]/
ALMY91
@ALMY91
Apr 15 2016 06:51 UTC
may i know whats the reasoning behind that the code will not work if i did not initialize var i?
// Setup
var myArray = [];

// Only change code below this line.
var i=0 ;
while(i<5) {myArray.push(i); i++;}
Paul Borawski
@iAmNawa
Apr 15 2016 06:53 UTC
@ALMY91 if you don’t declare it, then it doesn’t exist
Jae Kim
@JSOdin
Apr 15 2016 06:53 UTC
@ALMY91 if you try to do math on an undefined then it will be NaN
ALMY91
@ALMY91
Apr 15 2016 06:53 UTC
@iAmNawa thanks
CamperBot
@camperbot
Apr 15 2016 06:53 UTC
almy91 sends brownie points to @iamnawa :sparkles: :thumbsup: :sparkles:
:star: 426 | @iamnawa | http://www.freecodecamp.com/iamnawa
ALMY91
@ALMY91
Apr 15 2016 06:53 UTC
anybody knows why was my issue confirmed then closed on github?
Paul Borawski
@iAmNawa
Apr 15 2016 06:54 UTC
@ALMY91 it was probably a repeat issue, I privat messaged you btw
Brian
@sludge256
Apr 15 2016 06:54 UTC
@ALMY91 Because you were missing the curly brackets.
ALMY91
@ALMY91
Apr 15 2016 06:54 UTC
blob
Brian
@sludge256
Apr 15 2016 06:54 UTC
I didn't notice at first
ALMY91
@ALMY91
Apr 15 2016 06:55 UTC
@iAmNawa did you? i didn receive any tho
Sameer Shamsudeen
@sameershamsudheen
Apr 15 2016 06:56 UTC
@tenkdayz Thank You, so /[\W_]/g this will include all non alpha numeric characters+ underscore, does this include space.
CamperBot
@camperbot
Apr 15 2016 06:56 UTC
sameershamsudheen sends brownie points to @tenkdayz :sparkles: :thumbsup: :sparkles:
:star: 393 | @tenkdayz | http://www.freecodecamp.com/tenkdayz
Paul Borawski
@iAmNawa
Apr 15 2016 06:56 UTC
@ALMY91 click chat privately and it should show up
ALMY91
@ALMY91
Apr 15 2016 06:56 UTC
@sludge256 whats w the confirmed label tho?
Frank XC
@tenkdayz
Apr 15 2016 06:56 UTC
@sameershamsudheen yeas
Brian
@sludge256
Apr 15 2016 06:56 UTC
I confirmed that I could reproduce your issue.
That was before I noticed the coding error though.
ALMY91
@ALMY91
Apr 15 2016 06:57 UTC
@sludge256 but why was it closed after confirmation..
Sameer Shamsudeen
@sameershamsudheen
Apr 15 2016 06:57 UTC
@tenkdayz How do i print the current value of each string to the console, to correct my errors
Paul Borawski
@iAmNawa
Apr 15 2016 06:58 UTC
console.log(value); @sameershamsudheen
Jamie Lipschitz
@Jlipschitz
Apr 15 2016 06:58 UTC
@ALMY91 because he saw that it was due to a coding error and not an actual bug for the challenge
ALMY91
@ALMY91
Apr 15 2016 06:59 UTC
@Jlipschitz whats the difference between a coding error and an actual bug
Jamie Lipschitz
@Jlipschitz
Apr 15 2016 06:59 UTC
coding error is on your part, bug would be due to the site having a coding error
Brian
@sludge256
Apr 15 2016 07:00 UTC
I did unconfirm the issue.
Sameer Shamsudeen
@sameershamsudheen
Apr 15 2016 07:01 UTC

hello i was doing check for Palindromes in Basic Algorithm, how do i print the value of string2 and string3 in the console, i used console.log(string2); but it is not working, help me please. here is my code
```
function palindrome(str) {
// Good luck!
var expression = /\W\s/g;
var string1 = str.replace(expression);
var string2 = string1.toLowerCase();
console.log(string2);
var string3 = function reverse(string2){
return string2.split("").reverse().join("");
};
if(string3 === str){
return true;
}
else {
return false;
}

}

palindrome("eye");``` @iAmNawa not working in my code

Jamie Lipschitz
@Jlipschitz
Apr 15 2016 07:01 UTC
@ALMY91 yes, coding errors do = bugs but just in terms of this case it's wrong syntax in your code editor and not actual bug on the site. if that helps clarify?
Brian
@sludge256
Apr 15 2016 07:01 UTC
I should've done it before I closed the issue but it doesn't really make a difference.
The issue was in regards to console.log() causing the error, when in fact, it was your incorrect use of curly braces that was causing the error.
Frank XC
@tenkdayz
Apr 15 2016 07:05 UTC
@sameershamsudheen it should work .. i dont see any mistake on the syntax
Sameer Shamsudeen
@sameershamsudheen
Apr 15 2016 07:06 UTC
@tenkdayz I only saw a false printing on the console, not printing any string before that false
Rujool Doshi
@rujool
Apr 15 2016 07:06 UTC
@sameershamsudheen what are you replacing the expression with in str?
Brian
@sludge256
Apr 15 2016 07:06 UTC
@sameershamsudheen The FCC output window is not the same thing as your browser console.
Elbert Cortez
@trip16661
Apr 15 2016 07:08 UTC
what's wrong with this D:
function whereAreYou(collection, source) {
  // What's in a name?
  var arr = [];
  var sourceProperties = Object.keys(source);

  // Only change code below this line
  for(var a = 0;a < collection.length; a++){
    for(var b = 0; b < sourceProperties.length; b++ ){

      if (collection[a].hasOwnProperty(sourceProperties[b])&& collection[a][sourceProperties[b]] === source[sourceProperties[b]]){
        arr.push(collection[a]);
      }

    }
  }

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

whereAreYou([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
Rujool Doshi
@rujool
Apr 15 2016 07:13 UTC
@trip16661 in your code even if one property-value pair matches, u r pushing that collection into the array.. i dont think that is desired
Sameer Shamsudeen
@sameershamsudheen
Apr 15 2016 07:17 UTC
@rujool i don't know :smile: i was trying to replace the non alpha numeric characters and underscore from the given string. var string1 = str.replace(expression); is this wrong
Rada
@Radascript
Apr 15 2016 07:18 UTC
don't you need two arguments in "replace"?
GitH7
@GitH7
Apr 15 2016 07:18 UTC
var myStr="\"I am a \"double quoted\" string inside \"double quotes\"\" "; //
error
Rujool Doshi
@rujool
Apr 15 2016 07:18 UTC
@sameershamsudheen but with what are you trying to replace them?
@Radascript exactly
GitH7
@GitH7
Apr 15 2016 07:19 UTC
why still showing errors?
Rujool Doshi
@rujool
Apr 15 2016 07:23 UTC
@GitH7 u have extra escaped quotes
Anonymous Dev
@dhananjaydeath
Apr 15 2016 07:24 UTC
Anyone can tell me how to solve Golf code JavaScript basics...
ALMY91
@ALMY91
Apr 15 2016 07:25 UTC
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUpProfile(firstName, prop){
// Only change code below this line
if(firstName===contacts[firstName]) {
  if(prop===[firstName].hasownprop) {return contacts[prop];}
  else {return "No such property";}}
else {return "No such contact";}
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
whats wrong guys
Rujool Doshi
@rujool
Apr 15 2016 07:25 UTC
@dhananjaydeath just a hint: use if-elseif
@ALMY91 check the syntax.. if(prop===[firstName].hasownprop)
Anonymous Dev
@dhananjaydeath
Apr 15 2016 07:26 UTC

That i understand but do i need to use these as conditions 1 "Hole-in-one!"
<= par - 2 "Eagle"
par - 1 "Birdie"
par "Par"
par + 1 "Bogey"
par + 2 "Double Bogey"

= par + 3 "Go Home!"

Rujool Doshi
@rujool
Apr 15 2016 07:27 UTC
@dhananjaydeath exactly
Anonymous Dev
@dhananjaydeath
Apr 15 2016 07:27 UTC
thanks..
Rujool Doshi
@rujool
Apr 15 2016 07:27 UTC
@ALMY91 also contacts is an array of objects
think about that
GitH7
@GitH7
Apr 15 2016 07:35 UTC
@rujool solved
Rujool Doshi
@rujool
Apr 15 2016 07:36 UTC
@GitH7 gr8
Sameer Shamsudeen
@sameershamsudheen
Apr 15 2016 07:36 UTC
@rujool Is this correct var string1 = str.replace(expression, '');
Rujool Doshi
@rujool
Apr 15 2016 07:36 UTC
@sameershamsudheen yep
GitH7
@GitH7
Apr 15 2016 07:37 UTC
Remove all the backslashes ()
You should have two single quotes ' and four double quotes "
Only remove the backslashes \ used to escape quotes.
what is 1st and 3rd?
Sameer Shamsudeen
@sameershamsudheen
Apr 15 2016 07:38 UTC
@rujool what about this var string3 = string2.split('').reverse().join(''); right or wrong
GitH7
@GitH7
Apr 15 2016 07:39 UTC
@rujool Remove all the backslashes ()
You should have two single quotes ' and four double quotes "
Only remove the backslashes \ used to escape quotes.
var myStr = 'a href="http://www.example.com" target="_blank">Link</a>';
Shivam Arora
@shivamarora13
Apr 15 2016 07:41 UTC
function printAlert() {
  for (var i = 0; i < winCombs.length; i++) {
    var str = winCombs[i].toString();
    var regex = new RegExp(',', 'g');

    //replace via regex
    str = str.replace(regex, '');
    for (var j = 0; j < output.length; j++) {
      var testit = output[j].toString();
      testit = testit.replace(regex, '');
      if (str == testit) {
        alert("Computer Won. The evil electric power!");
        setTimeout(function() { location.reload(true) }, 4000);

      } else if (arrComp.length === 5){
        alert("Draw! You are good believe me.");
        setTimeout(function() { location.reload(true) }, 4000);
      }
    }
  }
}
why in this code, setTimeout runs before alert?
can anyone tell me?
Deepak Yadav
@ydeepk
Apr 15 2016 07:58 UTC

challange split strings with split
var string = "Split me into an array";
var array = [];

// Only change code below this line.

array = string.split("\s");

what I'm dooing wrong?

Shivam Arora
@shivamarora13
Apr 15 2016 07:59 UTC
what are you trying to do with "\s" ?
@ydeepk
Deepak Yadav
@ydeepk
Apr 15 2016 08:00 UTC
@shivamarora13 spliting array of strings at white space that the challange
Shivam Arora
@shivamarora13
Apr 15 2016 08:00 UTC
just use array.split(' ');
it will split.
@ydeepk
don't forget to give a space between the quotes
Samuel Cupidon
@Zerazera
Apr 15 2016 08:01 UTC
split() is a string function, not an array function
Deepak Yadav
@ydeepk
Apr 15 2016 08:01 UTC
@shivamarora13 already tried not working.
Brendan Kinahan
@BKinahan
Apr 15 2016 08:01 UTC
@shivamarora13 do you have that on codepen? can't test out of context
Deepak Yadav
@ydeepk
Apr 15 2016 08:01 UTC
@Zerazera look at split strings with split challange
Brendan Kinahan
@BKinahan
Apr 15 2016 08:02 UTC
@ydeepk you're using regex without the regex syntax
Shivam Arora
@shivamarora13
Apr 15 2016 08:02 UTC
@ydeepk send the challeng link
Deepak Yadav
@ydeepk
Apr 15 2016 08:02 UTC
@BKinahan you are right.
Brendan Kinahan
@BKinahan
Apr 15 2016 08:03 UTC
@ydeepk split(/\s/)
Deepak Yadav
@ydeepk
Apr 15 2016 08:03 UTC
@BKinahan what should i DO.
@BKinahan it worked man. Thanks Pal. :-)
CamperBot
@camperbot
Apr 15 2016 08:03 UTC
:star: 1296 | @bkinahan | http://www.freecodecamp.com/bkinahan
ydeepk sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
Sameer Shamsudeen
@sameershamsudheen
Apr 15 2016 08:04 UTC
hello var string1 = str.replace(/\W*\s+/g, '');do this code remove all non-alphanumeric characters and all spaces from the string str
Deepak Yadav
@ydeepk
Apr 15 2016 08:05 UTC
@shivamarora13 found out. @BKinahan helped.
Shivam Arora
@shivamarora13
Apr 15 2016 08:06 UTC
@BKinahan
this is the link to the pen, can u see why even the alert is not working
Brendan Kinahan
@BKinahan
Apr 15 2016 08:06 UTC
@sameershamsudheen spaces are non-alphanumeric already :)
@shivamarora13 the alert works for me. in fact it works too well, it won't stop :P
@shivamarora13 maybe you clicked an option in your browser to prevent it from showing any more alerts?
Sameer Shamsudeen
@sameershamsudheen
Apr 15 2016 08:08 UTC
@BKinahan ok, but my Check for Palindromes challenge still getting 5 more errors, I dont know which part of my code is not working, Here is my code
function palindrome(str) {
  // Good luck!
  var string1 = str.replace(/\W*/g, '');
  var string2 = string1.toLowerCase();
  var string3 = string2.split('').reverse().join('');
if(string3 === str){
    return true;
  }
  else {
    return false;
  }

}

palindrome("eye");
Shivam Arora
@shivamarora13
Apr 15 2016 08:08 UTC
@BKinahan Ohh yess!
ok please tell me, how to make page reload
@BKinahan
after user clicks ok on alert
Brendan Kinahan
@BKinahan
Apr 15 2016 08:09 UTC
@shivamarora13 It might be better to re-initialize the game instead of reloading
@shivamarora13 actually I think it does that already; it worked when I tsopped the page from showing any more alerts
Shivam Arora
@shivamarora13
Apr 15 2016 08:10 UTC
@BKinahan and how can I stop alerts, from alerting user infinite times
Brendan Kinahan
@BKinahan
Apr 15 2016 08:10 UTC
consider using some way to show text without using alert, since some people find those annoying :)
Shivam Arora
@shivamarora13
Apr 15 2016 08:11 UTC
@BKinahan Ok, thanks for the advice
CamperBot
@camperbot
Apr 15 2016 08:11 UTC
shivamarora13 sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star: 1297 | @bkinahan | http://www.freecodecamp.com/bkinahan
Brendan Kinahan
@BKinahan
Apr 15 2016 08:11 UTC
@sameershamsudheen in regex, * means "match between zero and unlimited times", so \W* might not work very well
@sameershamsudheen you could do /\W/g instead, but that still doesn't account for the underscore character _ so you will have to consider that too
Sameer Shamsudeen
@sameershamsudheen
Apr 15 2016 08:14 UTC
@BKinahan ok corrected to this var string1 = str.replace(/\W\_/g, ''); any other errors
Brendan Kinahan
@BKinahan
Apr 15 2016 08:21 UTC
@sameershamsudheen no need to escape _ because it's not a special character. your regex matches an underscore after a non-word character, so you need or in between them using | Test regex here: https://regex101.com/
Eldar Tinjić
@EldarT90
Apr 15 2016 08:26 UTC
why isnt this working ?
function fearNotLetter(str) {
  var newArr = str.split("");



  if (newArr[0] !== "a") {
    return undefined;
  }

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

    if (newArr[i].charCodeAt() < newArr[i+1].charCodeAt());
    { return newArr[i];


    }
  }

}
Coy Sanders
@coymeetsworld
Apr 15 2016 08:28 UTC
what is the challenge @EldarT90 and what are you having trouble w/?
Eldar Tinjić
@EldarT90
Apr 15 2016 08:29 UTC
@coymeetsworld the if statements is always true, even when i change the sign; how is that possible?
@coymeetsworld challenge is to find letter that is not "following order", for example if we have string (that i turn into array) of a,b,c,d,e,g ... the mistake is e
@coymeetsworld and we should return f; but that can be easy with code+1; however problem is in statement
@coymeetsworld its not working
Coy Sanders
@coymeetsworld
Apr 15 2016 08:34 UTC
which sign are you talking about?
Eldar Tinjić
@EldarT90
Apr 15 2016 08:34 UTC
@coymeetsworld ascii code, but i see it wont work like this, however i cant google alternative way of getting signs asccii code
so for example you want to get code for sign F
how would you do it
Coy Sanders
@coymeetsworld
Apr 15 2016 08:35 UTC
you know that its incremental, A is 65, B is 66, C is 67, etc
so each letter should only be one less than the next one
if it isn't, you know theres a missing character
Eldar Tinjić
@EldarT90
Apr 15 2016 08:36 UTC
@coymeetsworld yes, but thats not my problem, probelm is to get code of any letter, regardless of funciton
what is the method to get code of X or Y or A or 9
regardless of any funciton
just to get code, the method
X.chatCodeAt(); wont work
Coy Sanders
@coymeetsworld
Apr 15 2016 08:38 UTC
what is X? If you mean letter X you need to encapsulate in quotes
"X".charCodeAt(); would return the character code
Eldar Tinjić
@EldarT90
Apr 15 2016 08:38 UTC
yes
but no code
no string*
is it possible to do it without the strig
letter, symbol, number anything but that is not "stringified"
is there method to get its code ?
Coy Sanders
@coymeetsworld
Apr 15 2016 08:38 UTC
charCodeAt is a String function, so no
Eldar Tinjić
@EldarT90
Apr 15 2016 08:39 UTC
any alternative function ?
Coy Sanders
@coymeetsworld
Apr 15 2016 08:39 UTC
has to be a string
you don't need one
Eldar Tinjić
@EldarT90
Apr 15 2016 08:39 UTC
well my if statement wont work because array elements are not strings
i think
Coy Sanders
@coymeetsworld
Apr 15 2016 08:39 UTC
hmm they should be
Eldar Tinjić
@EldarT90
Apr 15 2016 08:39 UTC
actually yes they are after i split it into string
so why wont it work
newArr[i].charCodeAt() > newArr[i+1].charCodeAt())
why is this always ture ?
true*
newArr[i].charCodeAt() > newArr[i+1].charCodeAt()) = true
newArr[i].charCodeAt() < newArr[i+1].charCodeAt()) = true
whichever sign i put, it reads as true
or not
but probleme is in that statement
Rujool Doshi
@rujool
Apr 15 2016 08:41 UTC
@EldarT90 check the charCodeAt syntax
Eldar Tinjić
@EldarT90
Apr 15 2016 08:41 UTC
@rujool string.chatCodeAt()
Coy Sanders
@coymeetsworld
Apr 15 2016 08:41 UTC
you sure it does? that shouldn't make sense
Eldar Tinjić
@EldarT90
Apr 15 2016 08:41 UTC
newArr[i] = string
newArr[0] = "a"
Coy Sanders
@coymeetsworld
Apr 15 2016 08:42 UTC
the function is fine @rujool
Coy Sanders
@coymeetsworld
Apr 15 2016 08:42 UTC
although you don't need to put the string into an array @EldarT90
@rujool if you don't specify an index it defaults to 0
so if he runs that on a 1 character string its fine, which is what he's doing
Eldar Tinjić
@EldarT90
Apr 15 2016 08:43 UTC
why am i getting error cannot read property charAt
Coy Sanders
@coymeetsworld
Apr 15 2016 08:43 UTC
oh @EldarT90
you have a semicolon at the end of your function
i mean if statement, remove it
Eldar Tinjić
@EldarT90
Apr 15 2016 08:44 UTC
yes, but still wont work : i get error cannot read property
function fearNotLetter(str) {
  var newArr = str.split("");



  if (newArr[0] !== "a") {
    return undefined;
  }

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

    if (newArr[i].charCodeAt() > newArr[i+1].charCodeAt())

    { return newArr[i];}




  }

}
Frank XC
@tenkdayz
Apr 15 2016 08:44 UTC
str.charCodeAt(i) this should go through the string
@EldarT90
Coy Sanders
@coymeetsworld
Apr 15 2016 08:44 UTC
@tenkdayz no its ok
the way he's writing it should be fine, its something else
Eldar Tinjić
@EldarT90
Apr 15 2016 08:45 UTC
error is : cannot read property charcodeat of undefined
Coy Sanders
@coymeetsworld
Apr 15 2016 08:46 UTC
think you may need to specify i<newArr.length-1 @EldarT90
Rujool Doshi
@rujool
Apr 15 2016 08:46 UTC
agree @tenkdayz
Coy Sanders
@coymeetsworld
Apr 15 2016 08:46 UTC
theres one problem
Eldar Tinjić
@EldarT90
Apr 15 2016 08:46 UTC
aa
sec
Coy Sanders
@coymeetsworld
Apr 15 2016 08:47 UTC
also you need to define i
Eldar Tinjić
@EldarT90
Apr 15 2016 08:47 UTC
i fixed it i think
Coy Sanders
@coymeetsworld
Apr 15 2016 08:47 UTC
var i = 0;
Eldar Tinjić
@EldarT90
Apr 15 2016 08:47 UTC
function fearNotLetter(str) {
  var newArr = str.split("");



  if (newArr[0] !== "a") {
    return undefined;
  }

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

    if (newArr[i].charCodeAt() !== (newArr[i+1].charCodeAt()+1))

    { return newArr[i];}




  }

}
now its working, ofc its not giving me right result yet
but the statement works
Frank XC
@tenkdayz
Apr 15 2016 08:48 UTC
This message was deleted
Coy Sanders
@coymeetsworld
Apr 15 2016 08:48 UTC
guys hes fine :)
Eldar Tinjić
@EldarT90
Apr 15 2016 08:49 UTC
still there is a mistake somewhere there
Coy Sanders
@coymeetsworld
Apr 15 2016 08:49 UTC
@EldarT90 think you need to add +1 to newArr[i].charCodeAt(), not newArr[i+1].charCodeAt()
"A" + 1 would be "B"
not
"B" + 1 = "A"
Eldar Tinjić
@EldarT90
Apr 15 2016 08:50 UTC
yep
sec
right
brainfart i guess
because i was making +2
instead of 0 difference
so now i need to get charcode of that element which is troublesome, add +1
and get letter behind that code
hmm
Raqib Hasan
@omiq17
Apr 15 2016 08:51 UTC
is there anyone who did algorithm "Map the derbis" ???
*debris
Eldar Tinjić
@EldarT90
Apr 15 2016 08:53 UTC
function fearNotLetter(str) {
  var newArr = str.split("");



  if (newArr[0] !== "a") {
    return undefined;
  }

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

    if (newArr[i].charCodeAt() +1 !== (newArr[i+1].charCodeAt()))

    { var getting = newArr[i].charCodeAt()+1;
     return getting;}




  }

}
now im getting unicode of the troublesome letter
need to revert function to letter of the code
Blauelf
@Blauelf
Apr 15 2016 08:54 UTC
String.fromCharCode() is your friend.
Eldar Tinjić
@EldarT90
Apr 15 2016 08:54 UTC
aa
Coy Sanders
@coymeetsworld
Apr 15 2016 08:54 UTC
yep @Blauelf
thats the last part missing
Eldar Tinjić
@EldarT90
Apr 15 2016 08:55 UTC
yeaaa
Coy Sanders
@coymeetsworld
Apr 15 2016 08:55 UTC
need to convert that ascii value getting to a String of one char
Eldar Tinjić
@EldarT90
Apr 15 2016 08:55 UTC
@coymeetsworld @Blauelf ty both of you
it worked!
Coy Sanders
@coymeetsworld
Apr 15 2016 08:55 UTC
np @EldarT90 good job
Eldar Tinjić
@EldarT90
Apr 15 2016 08:55 UTC
im glad that i stick to my way of solving, even if its not the most efficient, at least i try to solve the problem hehe
Blauelf
@Blauelf
Apr 15 2016 08:55 UTC
Also, that if (newArr[0] !== "a") looks like you are hard-coding test cases... (remove that line, you already return undefined if you don't explicitly return from your function)
Coy Sanders
@coymeetsworld
Apr 15 2016 08:56 UTC
yeah also you don't need to make an array of characters either
you can use str.charCodeAt(index)
but when you specify no index it defaults to 0
Eldar Tinjić
@EldarT90
Apr 15 2016 08:56 UTC
@Blauelf they are wanting for undefined to popup if string starts from something weird, which is basically anything but a ? that is how i got the point, i might be wrong ofc
Coy Sanders
@coymeetsworld
Apr 15 2016 08:56 UTC
but since you're running them on one character strings thats fine
Eldar Tinjić
@EldarT90
Apr 15 2016 08:57 UTC
@coymeetsworld but how can you target "problematic" letter with charcodeat ?
i mean without making it aray
array*
Elbert Cortez
@trip16661
Apr 15 2016 08:57 UTC
what can i do so i go though every property cheking them before sending it to the new array?
This message was deleted
Blauelf
@Blauelf
Apr 15 2016 08:57 UTC
@EldarT90 One does not need special test, just wait if your loop returns, if not, then return undefined, for example by not using return after that loop :P
Elbert Cortez
@trip16661
Apr 15 2016 08:58 UTC
function whereAreYou(collection, source) {
  // What's in a name?
  var arr = [];
  var sourceProperties = Object.keys(source);

  // Only change code below this line
  for(var a = 0;a < collection.length; a++){
    for(var b = 0; b < sourceProperties.length; b++ ){

      if (collection[a].hasOwnProperty(sourceProperties[b])&& collection[a][sourceProperties[b]] === source[sourceProperties[b]]){
        arr.push(collection[a]);
      }

    }
  }

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

whereAreYou([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
Coy Sanders
@coymeetsworld
Apr 15 2016 08:58 UTC
something like
for (var i = 0; i < str.length -1; i++) {
   if (str.charCodeAt(i)+1 != str.charCodeAt(i+1)) {
     return str[i];
  }
}
Eldar Tinjić
@EldarT90
Apr 15 2016 08:58 UTC
@Blauelf so if there is no return, it counts as undefined ? didnt know that
let me retry
Blauelf
@Blauelf
Apr 15 2016 08:58 UTC
@trip16661 Don't push in your inner loop, push in the outer loop, and only if all things in inner loop matched.
Eldar Tinjić
@EldarT90
Apr 15 2016 08:59 UTC
@Blauelf its not working hmm, because it start counting as bcd is correct string
Blauelf
@Blauelf
Apr 15 2016 08:59 UTC
@EldarT90 return; or an implicit return by reaching the function end both count as return undefined;
Eldar Tinjić
@EldarT90
Apr 15 2016 09:00 UTC
@coymeetsworld lolz that looks so simple and correct
Coy Sanders
@coymeetsworld
Apr 15 2016 09:00 UTC
yeah don't know if that works 100% but thats the general idea, have to go look back at my code to see what I did exactly
Eldar Tinjić
@EldarT90
Apr 15 2016 09:00 UTC
@coymeetsworld but yeah, problem is i dont get in my head that this function is special because you can map element INSIDE the string - i mean you can target it
usually we dont work that way
because not too many functions can do that
Blauelf
@Blauelf
Apr 15 2016 09:01 UTC
@EldarT90 Maybe if you try str.charCodeAt(i) instead of newArr[i].charCodeAt(), and check whether str.charCodeAt(i)+1 !== str.charCodeAt(i+1)?
Coy Sanders
@coymeetsworld
Apr 15 2016 09:02 UTC
yeah i see what you mean @EldarT90
Blauelf
@Blauelf
Apr 15 2016 09:02 UTC
@coymeetsworld You would need to use String.fromCharCode, as it is the missing character you need to return, but other than that, yes, code looks fine :)
Coy Sanders
@coymeetsworld
Apr 15 2016 09:02 UTC
right @Blauelf
just wrote something quick up :)
Eldar Tinjić
@EldarT90
Apr 15 2016 09:02 UTC
@Blauelf yea, just as @coymeetsworld said, but i need experience for me to intuitively use different fucntion in different way; i am still getting often into for and if mess
which can be evaded mostly
naassi
@naassi
Apr 15 2016 09:06 UTC

Does anyone know if I can pass a function straight in to

navigator.geolocation.getCurrentPosition( examplefunc (pos));

because I cant get it to work ?
I have had to use an anon func to call it ?

navigator.geolocation.getCurrentPosition( function(pos)  { examplefunc(pos) });
Blauelf
@Blauelf
Apr 15 2016 09:08 UTC
You can use
function examplefunc(pos) {
  // your code
}
navigator.geolocation.getCurrentPosition(examplefunc);
You pass that function a callback function, bu you don't call it yourself. A function (function literal, named function, or variable pointing to function) followed by parentheses means that you call it at the time that code is evaluated. You want to call your callback only after the async action has finished.
naassi
@naassi
Apr 15 2016 09:10 UTC
So example func without the () ? Thanks @Blauelf
CamperBot
@camperbot
Apr 15 2016 09:10 UTC
naassi sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1645 | @blauelf | http://www.freecodecamp.com/blauelf
Anonymous Dev
@dhananjaydeath
Apr 15 2016 09:11 UTC
Hey everyone! I was working on a webapp and having some problem in speech recognition in the videos. Can you tell me which api and framework I use to achieve this..
Raqib Hasan
@omiq17
Apr 15 2016 09:11 UTC
is there anyone who did the algorithm Map the debris ?
Samuel Cupidon
@Zerazera
Apr 15 2016 09:11 UTC
@omiq17 I did that one
Raqib Hasan
@omiq17
Apr 15 2016 09:12 UTC
function orbitalPeriod(arr) {
  var GM = 398600.4418;
  var earthRadius = 6367.4447;
  var pi = 3.1416;
  var mul = Math.sqrt( earthRadius + Math.pow(arr[0].avgAlt,3)/GM );
  var ans = 2*pi*mul;
  return Math.round(ans);
}
where is the problem in my code? @Zerazera
Samuel Cupidon
@Zerazera
Apr 15 2016 09:13 UTC
@omiq This isn't the problem, but you can use Math.PI instead of setting the variable
Blauelf
@Blauelf
Apr 15 2016 09:13 UTC
@omiq17 Include the earthRadius + in the Math.pow, it adds to avgAlt.
Raqib Hasan
@omiq17
Apr 15 2016 09:14 UTC
ok... let me try
Blauelf
@Blauelf
Apr 15 2016 09:14 UTC
Not sure how that structure really worked (have to look it up)
naassi
@naassi
Apr 15 2016 09:14 UTC
@Blauelf Thats not working for me heres the code
if(navigator.geolocation) { navigator.geolocation.getCurrentPosition(getWeather);
  } else {
  alert("Could not access location;");
};

var getWeather = function(pos) { 
  $.get('http://api.openweathermap.org/data/2.5/weather?lat=' + pos.coords.latitude +
        '&lon=' + pos.coords.longitude + '&units=metric&APPID=f4bb493881267d09c5847a375103e72', function(data) {

    $('.location').text(data.name);
    $('.description').text(data.weather[0].description);

    $('.temp').text(Math.round(data.main.temp) + "°C");

    console.log(data);
  });

}
Samuel Cupidon
@Zerazera
Apr 15 2016 09:14 UTC
I don't think anyone would unless they were a scientist
Deepak Yadav
@ydeepk
Apr 15 2016 09:15 UTC

function factorialize(num) {

var counter = 1;

while(num >= counter) {
num *= (num-1);
counter++;
}

return num;
}

factorialize(5);

what i
'm doing wrong
??
Coy Sanders
@coymeetsworld
Apr 15 2016 09:16 UTC
you're not decrementing num
oh wait you don't need to do that
naassi
@naassi
Apr 15 2016 09:17 UTC
@ydeepk Google recursion but dont look at examples
Coy Sanders
@coymeetsworld
Apr 15 2016 09:17 UTC
*= isn't going to work how you expect
he doesn't need recursion @naassi
num is equal to 5, so num *= (num-1) is going to be 20
then you're going to be running 20 *= 19
Samuel Cupidon
@Zerazera
Apr 15 2016 09:17 UTC
Right, factorials can be solved with or without recursion. Recursion is just a bit neater.
@ydeepk Here's a hint: you don't need the counter variable
You can define the while loop in terms of num
Coy Sanders
@coymeetsworld
Apr 15 2016 09:18 UTC
yeah but recursion is less efficient with things you can do with a for loop
Deepak Yadav
@ydeepk
Apr 15 2016 09:18 UTC
@Zerazera okkaaaay.. let me try that
naassi
@naassi
Apr 15 2016 09:18 UTC
@Zerazera Yea it helps to understand it a bit, especially for challenges like that one
Deepak Yadav
@ydeepk
Apr 15 2016 09:20 UTC
@Zerazera nope not working.
Samuel Cupidon
@Zerazera
Apr 15 2016 09:20 UTC
@ydeepk What's the code that isn't working
Deepak Yadav
@ydeepk
Apr 15 2016 09:21 UTC

@Zerazera function factorialize(num) {

while(num >= 1) {
num *= (num-1);
num--;
}

return num;
}

factorialize(5);

Samuel Cupidon
@Zerazera
Apr 15 2016 09:22 UTC
@ydeepk Think about what happens if num = 5. What will its value be when the loop runs the second time?
Coy Sanders
@coymeetsworld
Apr 15 2016 09:22 UTC
@ydeepk you're going to want to create a new variable to store the results in
Rujool Doshi
@rujool
Apr 15 2016 09:22 UTC
@ydeepk the problem is that u are assigning num = num*(num-1) but you lose that value when u decrement num
Blauelf
@Blauelf
Apr 15 2016 09:23 UTC
@naassi At the time you call the position, the callback function does not exist. That's a classical use-before-initialize. Note that named function are done first, but assignments of functions are not.
Deepak Yadav
@ydeepk
Apr 15 2016 09:23 UTC
@rujool yea u r right.
Rujool Doshi
@rujool
Apr 15 2016 09:24 UTC
@ydeepk as @coymeetsworld said u should create another variable
Raqib Hasan
@omiq17
Apr 15 2016 09:25 UTC
thanks @Blauelf your suggestion has worked perfectly for me...
CamperBot
@camperbot
Apr 15 2016 09:25 UTC
omiq17 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1646 | @blauelf | http://www.freecodecamp.com/blauelf
Luca
@broc93
Apr 15 2016 09:26 UTC
Hello! I'm stuck with "Profile Lookup" task. How can I paste my code here?
Blauelf
@Blauelf
Apr 15 2016 09:26 UTC
@omiq17 I just looked up map-the-debris, and the "map" in the title might be a hint. You are meant to map objects to other objects (then no longer with avgAlt, but with orbitalPeriod), so return an array with the same number of objects as the input array.
negyvenketto
@negyvenketto
Apr 15 2016 09:27 UTC
help format
CamperBot
@camperbot
Apr 15 2016 09:27 UTC

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

This an inline `<paste code here>` code formatting with a single backtick(`) at start and end around the code.

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

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

negyvenketto
@negyvenketto
Apr 15 2016 09:27 UTC
@broc93 :point_up:
Luca
@broc93
Apr 15 2016 09:27 UTC
thank you @negyvenketto
CamperBot
@camperbot
Apr 15 2016 09:27 UTC
broc93 sends brownie points to @negyvenketto :sparkles: :thumbsup: :sparkles:
:star: 365 | @negyvenketto | http://www.freecodecamp.com/negyvenketto
Luca
@broc93
Apr 15 2016 09:29 UTC
function lookUpProfile(firstName, prop){
  var f = false;
  var p = false;
  for (var i = 0; i<contacts.length; i++){
    if (contacts[i].firstName==firstName){
      f = true;
      if (contacts[i][prop]===""){
        return "No such property";
      } else return contacts[i][prop];
    }
  }
  if (!f) return "No such contact";
}
lookUpProfile("Akira", "address"); should return "No such property" but instead it returns nothing. Why?
Raqib Hasan
@omiq17
Apr 15 2016 09:30 UTC
i did that using a for loop & my challenge has completed... :smile:
@Blauelf
Blauelf
@Blauelf
Apr 15 2016 09:30 UTC
@broc93 Use hasOwnProperty ;) Also, no need for any f or p (return instantly leaves the function, returning whatever you specified as a return value)
Jaromirx
@Jaromirx
Apr 15 2016 09:31 UTC

function switchOfStuff(val) {
var answer = "";
// Only change code below this line
switch (val) {
case a:
answer = "apple";
break;
case b:
answer = "bird";
break;
case c:
answer = "cat";
break;
default:
answer = "stuff";
}
// Only change code above this line
return answer;
}

// Change this value to test
switchOfStuff(c);

why am i geting reference error here?
c is not defined
Blauelf
@Blauelf
Apr 15 2016 09:32 UTC
@omiq17 As map is just a hidden loop, that's about the same.
@Jaromirx "a" (string literal of letter a), not a (variable of name a)
Jaromirx
@Jaromirx
Apr 15 2016 09:33 UTC
i tried with "" ...same error
Blauelf
@Blauelf
Apr 15 2016 09:34 UTC
Around a, b, and c each?
Jaromirx
@Jaromirx
Apr 15 2016 09:34 UTC
yea
Blauelf
@Blauelf
Apr 15 2016 09:34 UTC
Also in switchOfStuff(c)?
Jaromirx
@Jaromirx
Apr 15 2016 09:34 UTC
yep
Blauelf
@Blauelf
Apr 15 2016 09:35 UTC
So on every occurence (those are 4 in your code, one a, one b, two c) at the same time?
Luca
@broc93
Apr 15 2016 09:35 UTC
@Blauelf thank you!!!
CamperBot
@camperbot
Apr 15 2016 09:35 UTC
broc93 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1647 | @blauelf | http://www.freecodecamp.com/blauelf
kirbyedy
@kirbyedy
Apr 15 2016 09:36 UTC
@Jaromirx shouldnt you have the break even after the default
mtmorawska
@mtmorawska
Apr 15 2016 09:36 UTC

Hi, I am working on the Intermediate Algorithm Scripting assignment that is about summing all primate numbers up to a given number. Here's the code:

function sumPrimes(num) {

//checks if a number is a prime, works correctly
  function checkIfPrime(n) {
    for (i = 2; i < n; i++) {
      if (n % i === 0) {
        return false;
      } else if (i + 1 == n){
        return true;
      }
    }
  }
  var primes = [];
  for (j = 2; j <= num; j++) {
      console.log('j = ' + j + ', num = ' + num); //logs correctly for each loop
      if (checkIfPrime(num)) { /in this loop nothing gets executed
          console.log(j);
          primes = primes.push(num);
          console.log(primes);
      }
  }
  console.log('Im here');

  /*
  primes.reduce(function(previousVal, currentVal) {
      return previousVal + currentVal;
  });
  */

}

sumPrimes(10);

Could someone please help? I'm tottaly stuck. I have no idea why the for loop does not get executed (why the condition is never passed)

negyvenketto
@negyvenketto
Apr 15 2016 09:36 UTC
@kirbyedy no need for that
kirbyedy
@kirbyedy
Apr 15 2016 09:37 UTC
ok
usharya
@usharya
Apr 15 2016 09:37 UTC
not javascript related, can I post it?
Jaromirx
@Jaromirx
Apr 15 2016 09:38 UTC
nah ...dunno why this isnt working its buging me ..whatever i write in that switchOfStuff(x) ... i get ReferenceError: x is not defined
kirbyedy
@kirbyedy
Apr 15 2016 09:39 UTC
@Jaromirx can you paste your code again with corrections @Blauelf told you
negyvenketto
@negyvenketto
Apr 15 2016 09:39 UTC
@mtmorawska have you tested your checkIfPrime function? does it work?
Blauelf
@Blauelf
Apr 15 2016 09:39 UTC
@Jaromirx That's why I asked if you added "" also around that c. Does it work on switchOfStuff("x")?
Markus Kiili
@Masd925
Apr 15 2016 09:40 UTC
@mtmorawska There is only one slash on your comment /in this loop nothing gets executed
Jaromirx
@Jaromirx
Apr 15 2016 09:40 UTC

function switchOfStuff(val) {
var answer = "";
// Only change code below this line
function switchOfStuff(val) {
var answer = "";
// Only change code below this line
switch (val) {
case "a":
answer = "apple";
break;
case "b":
answer = "bird";
break;
case "c":
answer = "cat";
break;
default:
answer = "stuff";
}
// Only change code above this line
return answer;
}

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

// Change this value to test
switchOfStuff("a");

usharya
@usharya
Apr 15 2016 09:40 UTC
@Blauelf you are online all the time?
Jaromirx
@Jaromirx
Apr 15 2016 09:40 UTC
ok i got 2xreturn answer there ignore that :D
UDAY PRAPHULLA MALANGAVE
@malangaveuday
Apr 15 2016 09:40 UTC
@Jaromirx use code format
Blauelf
@Blauelf
Apr 15 2016 09:40 UTC
@mtmorawska You should declare variables using var (might prevent some surprises, as undeclared variables might be global if not declared in some scope between).
And your checkIfPrime won't consider 2 prime, better use a return true; outside your loop instead of inside.
Jaromirx
@Jaromirx
Apr 15 2016 09:40 UTC
how do i use code format?
mtmorawska
@mtmorawska
Apr 15 2016 09:40 UTC
@negyvenketto yes, I did
UDAY PRAPHULLA MALANGAVE
@malangaveuday
Apr 15 2016 09:40 UTC
to post code
Blauelf
@Blauelf
Apr 15 2016 09:41 UTC
help code format
CamperBot
@camperbot
Apr 15 2016 09:41 UTC

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

This an inline `<paste code here>` code formatting with a single backtick(`) at start and end around the code.

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

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

Prateek Vasisht
@vaspv
Apr 15 2016 09:41 UTC
Hi wanted some help with parsing JSON. I have used stringify to get the raw data display but don't know who to only get selected items (e.g. game or status null). This is for Twitch TV and codepen is http://codepen.io/vaspv/pen/VaXLyG
Blauelf
@Blauelf
Apr 15 2016 09:41 UTC
@Jaromirx Function in function? Bad copy&paste?
Jaromirx
@Jaromirx
Apr 15 2016 09:42 UTC
yeah bad copy paste
anywayz i reseted and pasted same stuff again and it worked
some king of bug i guess
kirbyedy
@kirbyedy
Apr 15 2016 09:44 UTC
@vaspv have you tried... if stream is null, offline otherwise online
mtmorawska
@mtmorawska
Apr 15 2016 09:44 UTC
@Blauelf how can I return true outside of the loop?
kirbyedy
@kirbyedy
Apr 15 2016 09:44 UTC
but you will also have to check for closed accounts
negyvenketto
@negyvenketto
Apr 15 2016 09:46 UTC
@mtmorawska
function checkIfPrime(n) {
    for (i = 2; i < n; i++) {
      if (n % i === 0) {
        return false;
      } 
    }
  return true;
  }
Prateek Vasisht
@vaspv
Apr 15 2016 09:46 UTC
@kirbyedy hi yes that is what I want to ultimately achieve but how do I find out if stream value is null? if I type data.stream === null or data[0]=== null then nothing is fetched . This is where I'm stuck - on how to get the value of a specific field only like stream or game or id etc.
Blauelf
@Blauelf
Apr 15 2016 09:47 UTC
@negyvenketto Thanks :) (I would recommend adding a var in front of i for not making a global variable)
negyvenketto
@negyvenketto
Apr 15 2016 09:48 UTC
@Blauelf yes, you are right, i forgot that. i tend to edit code and forget to fix half of the things...
mtmorawska
@mtmorawska
Apr 15 2016 09:49 UTC
@negyvenketto Ok, thanks. That still doesn't solve the problem though.
CamperBot
@camperbot
Apr 15 2016 09:49 UTC
mtmorawska sends brownie points to @negyvenketto :sparkles: :thumbsup: :sparkles:
:star: 366 | @negyvenketto | http://www.freecodecamp.com/negyvenketto
negyvenketto
@negyvenketto
Apr 15 2016 09:49 UTC
@mtmorawska i found your other problem
@mtmorawska in the loop you want to check if j is a prime, not num
@mtmorawska and you want to push that
mtmorawska
@mtmorawska
Apr 15 2016 09:50 UTC
@negyvenketto that must be it!
negyvenketto
@negyvenketto
Apr 15 2016 09:50 UTC
@mtmorawska also, you might want to review how the push function works
Coryphaeus
@cvdeby
Apr 15 2016 09:50 UTC
How can I get into match variable matched value?
  function replacer(match) {
    return match; // got '$&'
  }
  "&<>'".replace(/[&<>"']/gi, replacer('$&') );// got "&<>'"
  //but 
  "&<>'".replace(/[&<>"']/gi, '$&'); // got "&<>'"
mtmorawska
@mtmorawska
Apr 15 2016 09:51 UTC
@negyvenketto I'll check that, and let you know how it went. Thanks so much for your input!
CamperBot
@camperbot
Apr 15 2016 09:51 UTC
mtmorawska sends brownie points to @negyvenketto :sparkles: :thumbsup: :sparkles:
:warning: mtmorawska already gave negyvenketto points
negyvenketto
@negyvenketto
Apr 15 2016 09:51 UTC
@mtmorawska yw
kirbyedy
@kirbyedy
Apr 15 2016 09:52 UTC
@vaspv it should be data.stream
Blauelf
@Blauelf
Apr 15 2016 09:54 UTC
@cvdeby "&<>'".replace(/[&<>"']/gi, replacer) like this? replacer will be called with a couple of arguments, but the first is the whole match (followed by groups, then I think some start index and the whole string, but that's in the documentation of replace
Coryphaeus
@cvdeby
Apr 15 2016 09:56 UTC
@Blauelf Thanks)
CamperBot
@camperbot
Apr 15 2016 09:56 UTC
cvdeby sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1648 | @blauelf | http://www.freecodecamp.com/blauelf
mtmorawska
@mtmorawska
Apr 15 2016 09:56 UTC
@negyvenketto it worked!
negyvenketto
@negyvenketto
Apr 15 2016 09:56 UTC
@mtmorawska :thumbsup:
Coryphaeus
@cvdeby
Apr 15 2016 10:02 UTC

Thanks to @Chrono79 for dictionary)

var dictionary = {
  '&' : '&amp;',
  '<' : '&lt;',
  '>' : '&gt;',
  '"' : '&quot;',
  "'" : '&apos;'
};
function replacer(match) {
  return dictionary[match];
}
function convertHTML(str) {  return str.replace(/[&<>"']/gi, replacer );
}

Can I make it directly -without dictionary?

CamperBot
@camperbot
Apr 15 2016 10:02 UTC
cvdeby sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star: 403 | @chrono79 | http://www.freecodecamp.com/chrono79
negyvenketto
@negyvenketto
Apr 15 2016 10:06 UTC
@cvdeby probably yes, but it wont be so clean/easy to understand
ALMY91
@ALMY91
Apr 15 2016 10:07 UTC
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


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

if(firstName===contacts[i][firstName]) {

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

    else {return "No such contact";}
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
whats going on guys
Coryphaeus
@cvdeby
Apr 15 2016 10:09 UTC
@negyvenketto I'll use &#38; instead, if it'll be needed in real project)
Alessandro Giordo
@bovas85
Apr 15 2016 10:09 UTC
@ALMY91 hasOwnProperty
you can't use functions with all lowercase
Blauelf
@Blauelf
Apr 15 2016 10:10 UTC
The name is hasOwnProperty (and has to be written like that, that function returns true or false)
Also, use contacts[i].firstName or contacts[i]["firstName"] (as firstName is not a property name but the value to compare to, but "firstName" is the name)
And fix the indentation (it's not clear at all what belongs where), you might need to remove the else {} around that last return statement.
For fixing indentation (please do something like that before posting), you could use your editor's features or an online service like jsbeautifier.org
V1ad1m1r
@V1ad1m1r
Apr 15 2016 10:46 UTC
This message was deleted
CamperBot
@camperbot
Apr 15 2016 10:46 UTC
no wiki entry for: ceasars
V1ad1m1r
@V1ad1m1r
Apr 15 2016 10:46 UTC
This message was deleted
CamperBot
@camperbot
Apr 15 2016 10:46 UTC
no wiki entry for: ceasars cipher
V1ad1m1r
@V1ad1m1r
Apr 15 2016 10:47 UTC
help cipher
CamperBot
@camperbot
Apr 15 2016 10:47 UTC

: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: Write your own code. :memo:

:checkered_flag: Problem Explanation:

  • You need to write a function, which will take 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

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


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

if(firstName===contacts[i][firstName]) {

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

    else {return "No such contact";}
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
Alyssa Alvarez
@AlysCole
Apr 15 2016 10:50 UTC
You'll want to wrap your for loop.
for (var i=0;i< contacts.length ; i++) {
  if(firstName===contacts[i][firstName]) {
    if(prop===contacts[i][firstName].hasOwnProp(prop)) {return contacts[i][prop];}
    else {return "No such property";}    }
  else {return "No such contact";}
}
Blauelf
@Blauelf
Apr 15 2016 10:54 UTC
@ALMY91 :point_up: 15. April 2016 12:10
ALMY91
@ALMY91
Apr 15 2016 11:01 UTC
@Blauelf :package:
UDAY PRAPHULLA MALANGAVE
@malangaveuday
Apr 15 2016 11:02 UTC
$.ajax({
url: 'http://api.forismatic.com/api/1.0/?method=getQuote&key=457653&format=json&lang=en',
success: function(data){
console.log("success ",data);
},
error: function(data){
console.log("error ",data);
},
type: 'GET'
});
this request providing proper response in postmaster but not in ajax call please guys help me
its shown error
ALMY91
@ALMY91
Apr 15 2016 11:02 UTC
@Blauelf hehe im doing it for the second time :smile:
UDAY PRAPHULLA MALANGAVE
@malangaveuday
Apr 15 2016 11:02 UTC
$.ajax({
       url: 'http://api.forismatic.com/api/1.0/?method=getQuote&key=457653&format=json&lang=en',
       success: function(data){
         console.log("success ",data);
       },
       error: function(data){
         console.log("error ",data);
       },
       type: 'GET'
     });
this request providing proper response in postmaster but not in ajax call please guys help me
its shown error
Alyssa Alvarez
@AlysCole
Apr 15 2016 11:06 UTC
The error you're receiving is the cross-origin request being blocked?
Ankit Padia
@InsaneSkull
Apr 15 2016 11:06 UTC
This algorithm Caused me headache . Help me:
function truncateString(str, num) {
   // Clear out that junk in your trunk
   return str.slice(0, num);
 }

  truncateString("A-tisket a-tasket A green and yellow basket", 11);
Alyssa Alvarez
@AlysCole
Apr 15 2016 11:06 UTC
You'll need javascript to treat the data being received as JSONP
@malangaveuday add the property 'dataType' with the value 'jsonp'.
Ankit Padia
@InsaneSkull
Apr 15 2016 11:10 UTC
seems like sleeping people here.
ALMY91
@ALMY91
Apr 15 2016 11:10 UTC
@Blauelf actually i didn really understood what you meant the last time tho
Rujool Doshi
@rujool
Apr 15 2016 11:11 UTC
@InsaneSkull can u post a link to the challenge here
ALMY91
@ALMY91
Apr 15 2016 11:11 UTC
this is the code i have currently and i know the problem lies with me not having the quotations for the parameters but i dont really understand why. could u explain in layman terms?
```js
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUpProfile(firstName, prop){
// Only change code below this line
 for (