These are chat archives for FreeCodeCamp/HelpJavaScript

14th
Mar 2016
Kaue Rodrigo Pacheco
@kauepacheco
Mar 14 2016 00:00

function myFunction() {
System.out.println("Hi World");
}

myFunction();

Create a function called myFunction which prints "Hi World" to the dev console.
Call the function.
guys, why its not working?

function myFunction() {
System.out.println("Hi World");
}

myFunction();

Pedro Abel Díaz Sánchez
@coderHook
Mar 14 2016 00:04
.dialog() in itself is a property of jquery, right?
I am trying to pop up a window for the user to choose between two options.
sleh
@MarlboroGrammer
Mar 14 2016 00:06

function myFunction() {
'use strict';
var myVay;
console.log(myVar);
}
myFunction();

// run and check the console
// myVar is not defined outside of myFunction
//console.log(myVar);
// now remove the console log line to pass the test

i removed the last console.log
still can's pass the test
any idea?
Jacob Hanawalt
@JacobHanawalt
Mar 14 2016 00:10

I've copied down exactly what they want me to do in "Accessing Nested Arrays in JSON," but it doesn't want to work for me. Here's my code:
var secondTree = myPlants.trees[1];

and the error message is as follows:

TypeError: Cannot read property '1' of undefined

What am I doing wrong?

Haroon Ghawsi
@HaroonGhawsi
Mar 14 2016 00:14
Hi everyone, I would like to access JSON parsed object property but I am not able to get the value. can anyone please guide me in that. Below is my codepen http://codepen.io/ghawsiharoon/pen/vGXOGM
creator2earth
@creator2earth
Mar 14 2016 00:15
hey
Andres Ariel Alvarez-Saucedo
@Andr3sAlv
Mar 14 2016 00:21
Encode the following sequence, separated by spaces:
backslash tab tab carriage-return new-line and assign it to myStr
I am sorry I just have no clue how to pass this challenge
Robert Richey
@0x0936
Mar 14 2016 00:26
@effinglame myPlants does not have a property trees. myPlants is an array that contains objects as elements. You must first index into myPlants with the index you want using bracket notation. myPlants[0] or myPlants[1] to access one of the top level objects. then you can use dot notation to access a property on that object.
Kyle Morton
@kmorton1988
Mar 14 2016 00:30
oimg
omg
I've been stuck on Confirm the Ending for days
then I get on.
and magically I get it within like, 5 minutes
bitgrower
@bitgrower
Mar 14 2016 00:30
awwww ... I'm sorry @kmorton1988 ...
WOOT !!!!
Andres Ariel Alvarez-Saucedo
@Andr3sAlv
Mar 14 2016 00:30
nice
bitgrower
@bitgrower
Mar 14 2016 00:30
hahahahahahahha ... do tell
Kyle Morton
@kmorton1988
Mar 14 2016 00:30
and I cannot believe how simple the answer was
bitgrower
@bitgrower
Mar 14 2016 00:30
what turned on the light switch for you ?
Kyle Morton
@kmorton1988
Mar 14 2016 00:31
a day off lol.
am I allowed to share my answer here?
Andres Ariel Alvarez-Saucedo
@Andr3sAlv
Mar 14 2016 00:31
I find that helps with me too.
bitgrower
@bitgrower
Mar 14 2016 00:31
YAY !!!! sometimes the BEST thing you can do for your programming efforts is to take time off ..
Daryl Carr
@daryl-c
Mar 14 2016 00:32
Hey can anyone tell me why I the longitude and latitude variables are showing as undefined when the generateURL runs?
var latitude;
var longitude;
var keyCode = "dc278e336e0def29b69c3ab73173f67b";
var url;
var weatherContainer = document.getElementById('weather-container');

//Get geoLocation from browser
function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(function(position) {
          latitude = position.coords.latitude;
          longitude = position.coords.longitude; 
        });
    }
  // else {
  //     //NEED TO ADD TO DIV FOR FAILURE
  //       DIV.innerHTML = "Geolocation is not supported by this browser.";
  //   }
};


function generateUrl() {
  url = 'http://api.openweathermap.org/data/2.5/weather?lat=' + latitude + '&lon=' + longitude + '&appid=' + keyCode;
}

getLocation();
generateUrl();


var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
  if(xhr.readyState === 4) {
    var data = JSON.parse(xhr.responseText);
    console.log(data);
  }
};
xhr.open('GET', url);
xhr.send();
bitgrower
@bitgrower
Mar 14 2016 00:32
you have this thing called an unconscious mind ... which the conscious mind nearly 100% refuses to acknowledge it exists ... but it's a very powerful thing !!!
Kyle Morton
@kmorton1988
Mar 14 2016 00:32
haha, no kidding
Robert Richey
@0x0936
Mar 14 2016 00:32
@HaroonGhawsi .stringify() is typically used to send data to a server. .parse() is typically used when your function doesn't automatically parse the JSON response for you - jQuery parses JSON responses so that you don't have to. Just use the data object as you would a regular javascript object.
Kyle Morton
@kmorton1988
Mar 14 2016 00:32
I don't even know why I tried this. Did a couple test returns and finally got it to match up with what I was trying to compare against.
@bitgrower, any rules against posting spoilers, though?
bitgrower
@bitgrower
Mar 14 2016 00:34
hmmmmm ... y'know I have 3 solutions for it ... probably not the best to post your solution here .. maybe in the codeReview room ? (if it were a more complex problem, it probably wouldn't matter so much...)
help rooms
CamperBot
@camperbot
Mar 14 2016 00:34
bitgrower
@bitgrower
Mar 14 2016 00:34
I'll come look, @kmorton1988 !!!
Kyle Morton
@kmorton1988
Mar 14 2016 00:34
yeah, figured as much. Just can't believe how simple the solution finally was.
bitgrower
@bitgrower
Mar 14 2016 00:34
hahahahahahaha yeah, there is an absurdly simple solution ... 2 of them, but the 2nd of the 2 uses ES6
that's why it's probably best not to share it here ... hard to "unsee it" for folks who haven't done it
Kyle Morton
@kmorton1988
Mar 14 2016 00:35
what's ES6?
Robert Richey
@0x0936
Mar 14 2016 00:37
ES6 is the latest standard in JavaScript, many features are already supported by modern browsers. You get things like arrow functions, destructuring, spread operators, etc. really good stuff!
Kyle Morton
@kmorton1988
Mar 14 2016 00:37
oh interesting...
Jacob Hanawalt
@JacobHanawalt
Mar 14 2016 00:38
@0x0936 Oh, okay. Thanks a lot!
CamperBot
@camperbot
Mar 14 2016 00:38
effinglame sends brownie points to @0x0936 :sparkles: :thumbsup: :sparkles:
:star: 1250 | @0x0936 | http://www.freecodecamp.com/0x0936
Andres Ariel Alvarez-Saucedo
@Andr3sAlv
Mar 14 2016 00:40
how do I assign escape sequences to a string?
Haroon Ghawsi
@HaroonGhawsi
Mar 14 2016 00:40
@0x0936 Thanks, I am getting [object object] back not the value, do you know how to get the value of the key in the object?
CamperBot
@camperbot
Mar 14 2016 00:40
haroonghawsi sends brownie points to @0x0936 :sparkles: :thumbsup: :sparkles:
:star: 1251 | @0x0936 | http://www.freecodecamp.com/0x0936
Robert Richey
@0x0936
Mar 14 2016 00:42
// ES5
var arr = [1, 2, 3];
var newArr = arr.map(function(n) { return n * 2; }); // [2, 4, 6]

// ES6
const arr = [1, 2, 3];
const newArr = arr.map(n => n * 2); // [2, 4, 6]
bitgrower
@bitgrower
Mar 14 2016 00:45
ES6 (technically, I guess, not actually its name, is also known as ES2015 -- which I ALSO think is not the official name ... I think I discovered neither were the official names on the wikipedia page -- but I don't remember what it is ... go figure ... if you say ES6, or ES2015, knowledgeable js peeps will know what you are referring to, though ...
I put in the 2015 to just let you know how recently that standard has been accepted (last summer)...
Robert Richey
@0x0936
Mar 14 2016 00:47
ES2015 should be the official name. TC39 is using a naming convention that corresponds to the year of the spec release and planning annual releases.
Kyle Morton
@kmorton1988
Mar 14 2016 00:47
yeah, that's really cool. I'll have to dig into that when I can.
lol. Repeat a string repeat a string was relatively simple.
oh wow. ES2015 even has a repeat function :/
Michael Aubrey
@mca62511
Mar 14 2016 00:50

I'm working on the Fibonacci Numbers problem.

function sumFibs(num) {
  fib = [1];
  for (i=1;i<=num;i++){
    if (Number.isInteger((i+1)/2)) {
      fib.push(i);
    }
  }
  return fib.reduce(function(a, b){
    return a + b;
  });
}

sumFibs(4);

I feel like maybe I just don7t understand Fibonacci numbers in the first place? This works fine for passing 4, but with all the other big numbers the sum is coming out far too big.

Like passing 1000 is returning 50001, when according to the test it should be returning 1785
I feel like there's some aspect of Fibonacci numbers that I'm misunderstanding.
Kyle Morton
@kmorton1988
Mar 14 2016 00:51
fibonacci sequence is just the last two results added together.
0+1 = 1. 1+1 = 2. 1+2 = 3. 2+3 = 5. 3+5 = 8. etc.
figure out a way to add those two together in a loop until it is no longer necessary to do so.
Robert Richey
@0x0936
Mar 14 2016 00:54
or ECMAScript 2015. I've watched a lot of conference talks by industry vets and they pretty much just call it ES6 - shorter to say.
Erik Verduin
@Everduin94
Mar 14 2016 01:00
hello
Eli Mead
@Fanushkah
Mar 14 2016 01:02
Hey guys, on the section titled Stand in Line (which deals with queues) when I try to change the array and then assign something about that to a variable using .shift() it says that arr.shift() isn't a function
Matthew
@aspiringguru
Mar 14 2016 01:02
quick question: whats easiest way to test javascript in browser & console mode.
  • copy javascript from freecodecamp to blah.js file
  • open blah.js file in browser
  • add statements like below to view variables?
    console.log("blah"+ variable_name);
    except console.log doesn't seem to be outputting values for me. ugh..
Victor
@victoriousj
Mar 14 2016 01:03
@Fanushkah do you have the array returning after the shift?
Kyle Morton
@kmorton1988
Mar 14 2016 01:03
might try jsbin, too @aspiringguru. Just have to open up console and do console.log(js stuff) to test if you're getting what you want out of it.
Eli Mead
@Fanushkah
Mar 14 2016 01:03
@victoriousj I have the variable returning after the shift
Victor
@victoriousj
Mar 14 2016 01:03
Can I see what you have written?
Eli Mead
@Fanushkah
Mar 14 2016 01:04
@victoriousj because it is asking for the shifted number to be returned
@victoriousj it doesn't give me the error if I do it the other way but then the first requirement isn't met in the input of ([],1) working because it would shift before the one was added
How do I post code besides just copy and pasting?
with the box I mean
Victor
@victoriousj
Mar 14 2016 01:07
This message was deleted
format help
Eli Mead
@Fanushkah
Mar 14 2016 01:07
format help
Victor
@victoriousj
Mar 14 2016 01:07
type three `'s and hit shift-enter and place your code between the lines
Eli Mead
@Fanushkah
Mar 14 2016 01:08
This message was deleted
CamperBot
@camperbot
Mar 14 2016 01:08
:bulb: to format code use backticks! ``` more info
Eli Mead
@Fanushkah
Mar 14 2016 01:09
This message was deleted
CamperBot
@camperbot
Mar 14 2016 01:09
:bulb: to format code use backticks! ``` more info
Eli Mead
@Fanushkah
Mar 14 2016 01:09
backticks
I just realized
Victor
@victoriousj
Mar 14 2016 01:10
haha, coding makes you use the entire keyboard
Eli Mead
@Fanushkah
Mar 14 2016 01:10
I was using the wrong

``` function queue(arr, item) {
// Your code here
arr += arr.push(item);
var rem = arr.shift();

return rem; // Change this line
}

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

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

still wrong
what
whatever does it matter if I just leave it at this point?
Victor
@victoriousj
Mar 14 2016 01:11
no, you're fine
i don't think you can use the assignment operator that way.
try removing the assignment
Eli Mead
@Fanushkah
Mar 14 2016 01:13
oh
...... I spent so much time retrying that
learn something new I guess
Victor
@victoriousj
Mar 14 2016 01:14
but you got it?
Eli Mead
@Fanushkah
Mar 14 2016 01:14
thanks @victoriousj
CamperBot
@camperbot
Mar 14 2016 01:14
fanushkah sends brownie points to @victoriousj :sparkles: :thumbsup: :sparkles:
Eli Mead
@Fanushkah
Mar 14 2016 01:14
yea
CamperBot
@camperbot
Mar 14 2016 01:14
:star: 318 | @victoriousj | http://www.freecodecamp.com/victoriousj
Victor
@victoriousj
Mar 14 2016 01:14
certainly.
Matthew
@aspiringguru
Mar 14 2016 01:16
@kmorton1988 : thanks jsbin is good.
I still need to master browser console mode tho. always preferred not to be dependent on internet services for debugging simple code.
CamperBot
@camperbot
Mar 14 2016 01:16
aspiringguru sends brownie points to @kmorton1988 :sparkles: :thumbsup: :sparkles:
:star: 266 | @kmorton1988 | http://www.freecodecamp.com/kmorton1988
bwhicks
@bwhicks
Mar 14 2016 01:16
If anyone has a moment.... I'm stuck with this code for reversing an array:
```js
Kyle Morton
@kmorton1988
Mar 14 2016 01:16
@aspiringguru then I suppose brackets.io would be decent.
Matthew
@aspiringguru
Mar 14 2016 01:16
lol... first time I saw the brownie points awarded by camperbot.
Kyle Morton
@kmorton1988
Mar 14 2016 01:17
it's a code editor that let's you run in real time a browser attachment, then you can get ahold of chromes (or your default browsers) javascript console
bwhicks
@bwhicks
Mar 14 2016 01:18
var array = [1,2,3,4,5,6,7];
var newArray = [];

// Only change code below this line.

newArray = array.reverse();
This looks like it should work and call reverse on array, right?
Victor
@victoriousj
Mar 14 2016 01:21
@bwhicks yeah that looks right
bwhicks
@bwhicks
Mar 14 2016 01:21
@victoriousj thanks, for some reason it wouldn't produce the right results until I split it into calling reverse on array, then just assigning the resorted away to newArray--weird.
CamperBot
@camperbot
Mar 14 2016 01:21
bwhicks sends brownie points to @victoriousj :sparkles: :thumbsup: :sparkles:
:star: 319 | @victoriousj | http://www.freecodecamp.com/victoriousj
Victor
@victoriousj
Mar 14 2016 01:23
that is weird. I have exactly what you have written for an answer
Moisés Man
@moigithub
Mar 14 2016 01:26
Array.reverse modify the original array
doing
a=[1,2,3]
b=a.reverse(); /// <<-- u reversing a, then making a reference to a on b...means modifing b.. will also modify a (its not a copy , but same memory values)
@bwhicks @victoriousj
but IF u slice first.. then u make a NEW copy
Eric Murta
@murtinha
Mar 14 2016 01:27
guys is that a bug? Its saying TypeError: my Car is not a function
Kyle Morton
@kmorton1988
Mar 14 2016 01:27
@bitgrower any particular reason you defined an "if (num === 0)" clause to your answer to Truncate a string?
Eric Murta
@murtinha
Mar 14 2016 01:27
var Car = function(wheels,seats,engines) {
  //Change this constructor
  this.wheels=wheels;
  this.seats=seats;
  this.engines = engines;
};

//Try it out here
var myCar=new Car(1,2,3);
myCar(3,2,1);
guys is that a bug? Its saying TypeError: my Car is not a function
Kyle Morton
@kmorton1988
Mar 14 2016 01:28
@murtinha , you used () on a variable
() generally is reserved for calling a function, but myCar is a variable.
if you want the console to print out the contents of the variable myCar, you'd just use return myCar;
Michael Aubrey
@mca62511
Mar 14 2016 01:29

@kmorton1988 I'm not sure I really get it, but based on your explanation I was able to come up with this

function sumFibs(num) {
  fib = [1];
  for (i=1;i<=num;i+=(fib[fib.length -2])) {
      fib.push(i);
  }
  fib.forEach(function(a){
    if (Number.isInteger(a/2)) {
      fib.splice(fib.indexOf(a), 1);
    }
  });
  return fib.reduce(function(a, b){
    return a + b;
  });
}

sumFibs(1000);

and that works. So thanks.

CamperBot
@camperbot
Mar 14 2016 01:29
mca62511 sends brownie points to @kmorton1988 :sparkles: :thumbsup: :sparkles:
:star: 267 | @kmorton1988 | http://www.freecodecamp.com/kmorton1988
Eric Murta
@murtinha
Mar 14 2016 01:29
@kmorton1988 thanks man
Kyle Morton
@kmorton1988
Mar 14 2016 01:29
@murtinha @mca62511 You're both welcome.
Natalie Patrice Tucker
@NataliePatriceTucker
Mar 14 2016 01:32

hey I need some help getting past Testing Objects for Properties. not sure the syntax for returning the value of the property. here's my code: var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

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

}

Mariya
@mariyadiminsky
Mar 14 2016 01:33
I need to create an array of links from a JSON link, this is my first time and I am really struggling. I'd love some advice on what's wrong with my code/why it's not working:
$("button").click(function(){
    $.get("https://codesmith-precourse.firebaseio.com/instagram/-JqL35o8u6t3dTQaFXSV.json", function(data, status){
        alert(jQuery.parseJSON(data););
    });
});
Natalie Patrice Tucker
@NataliePatriceTucker
Mar 14 2016 01:33
help insert code
CamperBot
@camperbot
Mar 14 2016 01:33
no wiki entry for: insert code
Kyle Morton
@kmorton1988
Mar 14 2016 01:33
@NataliePatriceTucker, try pasting your code again, but first type ```js, then hit enter, and it should allow you to paste your code in that fancy box.

```js
//javascript here
```
Natalie Patrice Tucker
@NataliePatriceTucker
Mar 14 2016 01:34

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

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

}

CamperBot
@camperbot
Mar 14 2016 01:34
:bulb: to format code use backticks! ``` more info
Natalie Patrice Tucker
@NataliePatriceTucker
Mar 14 2016 01:34
oops
Kyle Morton
@kmorton1988
Mar 14 2016 01:34
those aren't appostraphes. they're back-ticks. To the left of the 1 key
Natalie Patrice Tucker
@NataliePatriceTucker
Mar 14 2016 01:35

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

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

}

Michael Aubrey
@mca62511
Mar 14 2016 01:35
or sometimes not. on my keyboard it is what you get when you press shift on the @ key. Some international keyboards might be different *shrug*
Kyle Morton
@kmorton1988
Mar 14 2016 01:35
you didn't hit "enter" after typing ```js
ahh, well a standard US keyboard is above tab, my bad for assuming
Michael Aubrey
@mca62511
Mar 14 2016 01:36
like this
```javascript
if (you === "awesome") {
return true;
}
```
I used the escape character () so it didn't show as code, but if you type exactly that in, it'll show correctly
Natalie Patrice Tucker
@NataliePatriceTucker
Mar 14 2016 01:37
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

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

}
Kyle Morton
@kmorton1988
Mar 14 2016 01:37
perfect :)
Michael Aubrey
@mca62511
Mar 14 2016 01:37
yay
Natalie Patrice Tucker
@NataliePatriceTucker
Mar 14 2016 01:37
i did it!!
Michael Aubrey
@mca62511
Mar 14 2016 01:37
good job @NataliePatriceTucker
Natalie Patrice Tucker
@NataliePatriceTucker
Mar 14 2016 01:37
:)
Michael Aubrey
@mca62511
Mar 14 2016 01:37
so what seems to be the problem
Natalie Patrice Tucker
@NataliePatriceTucker
Mar 14 2016 01:37
ok now my problem is that I'm not sure how to return the property value after check that it has the property
Kyle Morton
@kmorton1988
Mar 14 2016 01:38
to call the value of an object property, it'd be myObj[propertyName]
Natalie Patrice Tucker
@NataliePatriceTucker
Mar 14 2016 01:38
embarrasing!! of course!
Michael Aubrey
@mca62511
Mar 14 2016 01:38
no worries
Kyle Morton
@kmorton1988
Mar 14 2016 01:39
no, no, with learning so much, it's easy to forget the simple things
Natalie Patrice Tucker
@NataliePatriceTucker
Mar 14 2016 01:40
thanks @kmorton1988 !
CamperBot
@camperbot
Mar 14 2016 01:40
nataliepatricetucker sends brownie points to @kmorton1988 :sparkles: :thumbsup: :sparkles:
:star: 269 | @kmorton1988 | http://www.freecodecamp.com/kmorton1988
Kyle Morton
@kmorton1988
Mar 14 2016 01:41
Welcome! Good luck!
Andrew Charlebois
@andrewchar
Mar 14 2016 01:44
help Caesars Cipher
CamperBot
@camperbot
Mar 14 2016 01:44

:point_right: algorithm caesars cipher [wiki]

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
Mariya
@mariyadiminsky
Mar 14 2016 01:47
I'm trying to convert a JSON link into an array. Why is my code not working? Please advice:
```
var json = $.getJSON('https://codesmith-precourse.firebaseio.com/instagram/-JqL35o8u6t3dTQaFXSV.json');
var obj = $.parseJSON(json);

$("button").click(function(){
    json, function(data, status){
        alert($.parseJSON(data));
    });
});
```
Brian
@BrianCodes33
Mar 14 2016 01:49

The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.

If both are true, then return the "value" of that property.

function lookUp(firstName, prop){
// Only change code below this line
    if ("firstName" && prop.value === true) {
      return prop.value;
    }
// Only change code above this line
}
can someone help me here
Kyle Morton
@kmorton1988
Mar 14 2016 01:52
you're calling a static string for your first argument in the if statement
that will almost always return false.
also, might want to read up a bit on how to call specific property/value combos.
the goal here is to first, check if the first name matches. Secondly, check if a property exists. THEN return the asked property of the person that has that first name.
Henry Quinn
@Quinncuatro
Mar 14 2016 01:54
help confirmtheending
CamperBot
@camperbot
Mar 14 2016 01:54
no wiki entry for: confirmtheending
Kyle Morton
@kmorton1988
Mar 14 2016 01:54
otherwise, if the property doesn't exist, return "No such property", and finally, if the first name doesn't exist, return "No such contact"
Henry Quinn
@Quinncuatro
Mar 14 2016 01:54
help confirm
CamperBot
@camperbot
Mar 14 2016 01:54

:point_right: algorithm confirm the ending [wiki]

Explanation:

The function is a whole Boolean operation. You need to return true if the first argument ends with the second argument. This means that for the problem script, it should return true for the end('Bastian', 'n'); case.

:pencil: read more about algorithm confirm the ending on the FCC Wiki

Brian
@BrianCodes33
Mar 14 2016 01:56
@kmorton1988 not sure how to write the function cna you give me a little more insight
Kyle Morton
@kmorton1988
Mar 14 2016 01:56
what's the name of the challenge
Brian
@BrianCodes33
Mar 14 2016 01:57
Profile Lookup
Kyle Morton
@kmorton1988
Mar 14 2016 01:58
so, you're basically having to look through each entry in the variable "contacts" which is an array. do you remember how to iterate through an array?
Brian
@BrianCodes33
Mar 14 2016 01:58
for loop
Kyle Morton
@kmorton1988
Mar 14 2016 01:59
alright. So start there. Make it so you iterate through each entry in contacts
Brian
@BrianCodes33
Mar 14 2016 01:59
for (var i=0; i<contacts.length; i++)
??
Kyle Morton
@kmorton1988
Mar 14 2016 01:59
perfect
Brian
@BrianCodes33
Mar 14 2016 02:00
and inside my loop i need to check
Kyle Morton
@kmorton1988
Mar 14 2016 02:00
now, you have to compare whether the firstName given in the function call matches any of the firstName variables.
right.
Brian
@BrianCodes33
Mar 14 2016 02:01
this is where i'm getting stuck
if ("firstName" == firstname)?
Kyle Morton
@kmorton1988
Mar 14 2016 02:01
how do you call an array item?
Brian
@BrianCodes33
Mar 14 2016 02:01
bracket notation?
Kyle Morton
@kmorton1988
Mar 14 2016 02:01
mhmm
array[index]
Brian
@BrianCodes33
Mar 14 2016 02:02
if (contacts[i] == firstName)?
Kyle Morton
@kmorton1988
Mar 14 2016 02:03
an object in that array has properties. If you try just contacts[i], you're only comparing against whether or not that index exists. you have to also target the property of that index.
Brian
@BrianCodes33
Mar 14 2016 02:03
so contacts[firstName]?
Kyle Morton
@kmorton1988
Mar 14 2016 02:04
you have to have the index number AND the property call
bitgrower
@bitgrower
Mar 14 2016 02:04

@bitgrower any particular reason you defined an "if (num === 0)" clause to your answer to Truncate a string?

@kmorton1988 -- don't recall specifically -- coded that like 6 weeks ago ...

Kyle Morton
@kmorton1988
Mar 14 2016 02:04
I ended up figuring out why, @bitgrower
bitgrower
@bitgrower
Mar 14 2016 02:05
oh good, tell me what you figured out ... LOL
Kyle Morton
@kmorton1988
Mar 14 2016 02:05
it was an uneccesary addition for that specific task, but in real world, if you're truncating the entirety of the text, there's no need to have a ...
my solution, when 0 was input, gave you nothing but "..."
yours added an option for removing the ... if the string came back empty
bitgrower
@bitgrower
Mar 14 2016 02:05
:)
thanks @kmorton1988
CamperBot
@camperbot
Mar 14 2016 02:06
bitgrower sends brownie points to @kmorton1988 :sparkles: :thumbsup: :sparkles:
:star: 270 | @kmorton1988 | http://www.freecodecamp.com/kmorton1988
Brian
@BrianCodes33
Mar 14 2016 02:06
@kmorton1988 am i on the right track with the IF statement? if (contacts[firstName] == firstName && contacts[prop] == prop)
Kyle Morton
@kmorton1988
Mar 14 2016 02:06
also, i noticed you use a bunch of separate ifs, rather than an if/else if chain
@BrianBorin not quite. You're still not calling the index AND the property
bitgrower
@bitgrower
Mar 14 2016 02:06

@bitgrower any particular reason you defined an "if (num === 0)" clause to your answer to Truncate a string?

@kmorton1988 -- don't recall specifically -- coded that like 6 weeks ago ...

^^^^^ Why you should comment your code ... an FCC challenge may be relatively innocuous -- but it's easy to forget why you do stuff ...

WORD TO THE WISE!

Brian
@BrianCodes33
Mar 14 2016 02:06
ughhh
Kyle Morton
@kmorton1988
Mar 14 2016 02:07
lol for sure.
@BrianBorin, there are 2 ways to call a property of an object. by dot notation or by bracket notation. dot notation is used when you know the specific property name you're trying to access. bracket is when you have to use a variable to access it.
bitgrower
@bitgrower
Mar 14 2016 02:08
@BrianBorin -- it's an ARRAY, right ... so you have to FIRST index into the array ...and THEN "index" into the object using the object's properties ...
Kyle Morton
@kmorton1988
Mar 14 2016 02:09
for instance object.thing would call the property called "thing" in the "object" object
Brian
@BrianCodes33
Mar 14 2016 02:09
if (contacts[i] == firstName && contacts[i] == prop)
?
Kyle Morton
@kmorton1988
Mar 14 2016 02:09
@BrianBorin you need another thinga ttached to the end of the first comparison
bitgrower
@bitgrower
Mar 14 2016 02:09
LOL ... don't forget the THEN part .. :)
combine what you had before with what you just entered ...
Kyle Morton
@kmorton1988
Mar 14 2016 02:09
^
Roberto Lluberes
@robertlluberes
Mar 14 2016 02:10
@BrianBorin you have yo combine that @bitgrower and @kmorton1988 are saying (sorry for my bad English)
bitgrower
@bitgrower
Mar 14 2016 02:10
accessing ANY piece of data in a data structure is done by creating a "path" to that data ... the path may be made up of array indexes along with object properties
Brian
@BrianCodes33
Mar 14 2016 02:11
for (var i=0; i<contacts.length; i++) { if (contacts[firstName] == firstName && contacts[i] == prop) { return prop.value;??
bitgrower
@bitgrower
Mar 14 2016 02:11
so ... think of the idea that you are building a "path" to a particular piece of data ... that path can use multiple indexes
Kyle Morton
@kmorton1988
Mar 14 2016 02:12
also, keep this in mind:

object.prop //returns true if the property exists, returns false if the property doesn't exist

//
Brian
@BrianCodes33
Mar 14 2016 02:12
i know i need to access the array i'm just not sure about all the lingo
Kyle Morton
@kmorton1988
Mar 14 2016 02:12
so first, you have an array. inside that array you have objects, each object has the same set of properties.
Andrew Charlebois
@andrewchar
Mar 14 2016 02:12
try not to make fun of my code i just started this so its messy still lol but im doing Caesars Cipher and im wondering if im using .fromCharCode right. can i use a variable inside the parameter like i am here?
function rot13(str) { // LBH QVQ VG!

  var shifted = str;
  var done = "";


  for (var i = 0; i < shifted.length; i++) {
     if (shifted[i].charCodeAt() <= 77) {
       done += shifted[i].charCodeAt() + 13; 
     } else if (shifted[i].charCodeAt() > 77) {
      done += shifted[i].charCodeAt() - 13;
     } 
  }


    done = String.fromCharCode(done);


  console.log(done);
return done;



}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Kyle Morton
@kmorton1988
Mar 14 2016 02:13
so first, you have to access the array. then you have to access the property of the array index you need. all in the Same Variable Call
@BrianBorin ^
Prithvi-A
@Prithvi-A
Mar 14 2016 02:13
This message was deleted
This message was deleted
bitgrower
@bitgrower
Mar 14 2016 02:14

myObj = [ { myKey: myValue, 2ndKey: another Val, }, { justanotherObj: valued, indeed : done } ]

...to access the value "myValue" ... I need to say: myObj[0][myKey] -- that is the "path" to the myValue piece of data ...

@BrianBorin @kmorton1988

Prithvi-A
@Prithvi-A
Mar 14 2016 02:14
Oops! my bad
bitgrower
@bitgrower
Mar 14 2016 02:14
close @Prithvi-A :)
you can edit your message to make corrections ... :)
@Prithvi-A -- the key to getting the formatting right is to get the 3 backticks on one line by themselves (both before & after your code)
Brian
@BrianCodes33
Mar 14 2016 02:16
@kmorton1988 and @bitgrower i think i know that part
Angel Jimenez
@aJimmer
Mar 14 2016 02:16
has anyone completed Spinal Tap Case?
bitgrower
@bitgrower
Mar 14 2016 02:17
@BrianBorin -- not seeing it in your code ... and you need it ...
Brian
@BrianCodes33
Mar 14 2016 02:17
function lookUp(firstName, prop){
// Only change code below this line
    for (var i=0; i<contacts.length; i++)  {
      if (contacts[firstName] == firstName && contacts[i] == prop)  {
          return prop.value;
      }

        }
is this close?
Kyle Morton
@kmorton1988
Mar 14 2016 02:17
@BrianBorin try and return the first name of one of the contacts.
@comment everything else out, and simply try and return one of the first names.
bitgrower
@bitgrower
Mar 14 2016 02:17
you're beginning to look like you are throwing stuff into your code without understanding it,, @BrianBorin
Prithvi-A
@Prithvi-A
Mar 14 2016 02:18
@bitgrower Thanks!
CamperBot
@camperbot
Mar 14 2016 02:18
prithvi-a sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 850 | @bitgrower | http://www.freecodecamp.com/bitgrower
Brian
@BrianCodes33
Mar 14 2016 02:18
@bitgrower :worried:
bitgrower
@bitgrower
Mar 14 2016 02:18
This message was deleted
Prithvi-A
@Prithvi-A
Mar 14 2016 02:18
var changed = 0;

function change(num) {
  return (num + 5) / 3;
}

changed = change(10);

// Setup
var processed = 0;

function process(num) {
  return (num + 3) / 5;
}

// Only change code below this line
var results = process(7);
results == processed;
bitgrower
@bitgrower
Mar 14 2016 02:18
you have to review what @kmorton1988 and I have said ... you say you understand, but your code doesn't demonstrate your understanding ... so re-review what we've said ...
Prithvi-A
@Prithvi-A
Mar 14 2016 02:18
I'm not able to solve this any help?
Question : Call the process function with an argument of 7 and assign its return value to the variable processed.
bitgrower
@bitgrower
Mar 14 2016 02:19
@Prithvi-A -- read the instructions you just entered carefully ... :)
k -- be back in a bit ... be good folks ... :)
Matthew Shaver
@RazzaFrazza
Mar 14 2016 02:22
Hey guys I'm really curious as to why this doesn't work... collection[id].prop = collection[id].prop.push(value);
Angel Jimenez
@aJimmer
Mar 14 2016 02:22
So no ones done Spinal Tap Case?
Matthew Shaver
@RazzaFrazza
Mar 14 2016 02:22
Any help is appreciated.
Prithvi-A
@Prithvi-A
Mar 14 2016 02:22
I'm not sure what I'm missing b/w process or processed
Refer my code above
bitgrower
@bitgrower
Mar 14 2016 02:23
return value to the variable processed. <-- that part @Prithvi-A
Angel Jimenez
@aJimmer
Mar 14 2016 02:23
@RazzaFrazza Since prop is a variable and not an actual "property" you need to use it in brackets
Matthew Shaver
@RazzaFrazza
Mar 14 2016 02:24
I've tried that but I get unexpect token [
*unexpected
Angel Jimenez
@aJimmer
Mar 14 2016 02:24
can you post your code?
Matthew Shaver
@RazzaFrazza
Mar 14 2016 02:24

function update(id, prop, value) {

collection[id].[prop] = collection[id].prop.push(value);

return collection;
}

Angel Jimenez
@aJimmer
Mar 14 2016 02:24
lose the dot operator
Prithvi-A
@Prithvi-A
Mar 14 2016 02:24
var results = process(7); 
processed = results;
Matthew Shaver
@RazzaFrazza
Mar 14 2016 02:24
omg
lol
Angel Jimenez
@aJimmer
Mar 14 2016 02:24
:)
Matthew Shaver
@RazzaFrazza
Mar 14 2016 02:25
thanks for the help
Prithvi-A
@Prithvi-A
Mar 14 2016 02:25
its still giving an error @bitgrower
Angel Jimenez
@aJimmer
Mar 14 2016 02:25
np
bitgrower
@bitgrower
Mar 14 2016 02:25
This message was deleted
This message was deleted
Prithvi-A
@Prithvi-A
Mar 14 2016 02:26
why is that? var processed is already declared as 0
Michael Aubrey
@mca62511
Mar 14 2016 02:26
I feel like I need to take a remedial math course.
bitgrower
@bitgrower
Mar 14 2016 02:26
because that's what the instructions say, @Prithvi-A ...
which challenge is this, @Prithvi-A -- let me check something out ..
Michael Aubrey
@mca62511
Mar 14 2016 02:27
It's been about 11 years since I was in a math class -.-
bitgrower
@bitgrower
Mar 14 2016 02:27
which challenge is taxing your math, @mca62511
Michael Aubrey
@mca62511
Mar 14 2016 02:28
Nothing in particular. I was having trouble with the adding the sum of primes. In the end my math wasn't wrong, it was actually just a syntax thing. But if I were more sure of my math I wouldn't have spent so much time double checking it
just in general with the algorithm challenges I feel like if I were more mathematically fluent I'd move through them more quickly
Prithvi-A
@Prithvi-A
Mar 14 2016 02:30
@bitgrower Assignment with a Returned Value
I fixed it processed = process(7);
bitgrower
@bitgrower
Mar 14 2016 02:32
YAY !!!!! awesome @Prithvi-A -- do you see how you kinda have to interpret the instructions to give the challenge exactly what they ask for ?
oh yeah ... and
bitgrower @bitgrower eye's thank @Prithvi-A for posting with syntax coloring ... so much easier on the eyes ...
CamperBot
@camperbot
Mar 14 2016 02:33
bitgrower sends brownie points to @prithvi-a :sparkles: :thumbsup: :sparkles:
:star: 62 | @prithvi-a | http://www.freecodecamp.com/prithvi-a
Jesus Vega
@ParagonChuy
Mar 14 2016 02:35
Has anybody here completed the sum of all primes ?
Michael Aubrey
@mca62511
Mar 14 2016 02:35
just did
Jesus Vega
@ParagonChuy
Mar 14 2016 02:35
Okay , I'm about to start it.
Angel Jimenez
@aJimmer
Mar 14 2016 02:37
have you guys done spinal case by any chance? I finished mine and want to compare code
Michael Aubrey
@mca62511
Mar 14 2016 02:37

@bitgrower
Or like this.

Find the smallest common ,multiple of the provided parameters that can be evenly divided by both, as well as by all sequential numbers in the range between these parameters.

I guess first I need to

Find all multiples of both parameters and stick them in two arrays.

Take the smallest number from both arrays and divide them by each the parameters. If the answer is a non-integer, then do that again with the next smallest.

...What is it saying about it needing to also be evenly divided by all sequential numbers in the range between the parameters? So if the parameters are [5,10] then they need to be evenly divided by 6, 7, 8, and 9?

thaniri
@thaniri
Mar 14 2016 02:38
@aJimmer if you want to compare code you can type freecodecamp.com/UserName into your URL bar
just pick someone who you are reasonably confident has a bunch of algorithms done
ie not me
Angel Jimenez
@aJimmer
Mar 14 2016 02:38
cool thanks!
Michael Aubrey
@mca62511
Mar 14 2016 02:39
@aJimmer I did Spinal Tap Case. I'm not confident my answer is the most elegant or anything, but I've done it if you want to check my profile.
Angel Jimenez
@aJimmer
Mar 14 2016 02:39
@mca62511 will do thank you
CamperBot
@camperbot
Mar 14 2016 02:39
ajimmer sends brownie points to @mca62511 :sparkles: :thumbsup: :sparkles:
:star: 379 | @mca62511 | http://www.freecodecamp.com/mca62511
Andrew Charlebois
@andrewchar
Mar 14 2016 02:40
having a hard time trying to figure out how i am suppose to use .fromCharCode() and use something that is not a number for the argument? is there some trick i am suppose to do for that? question is related to the Caesars Cipher algorithm
thaniri
@thaniri
Mar 14 2016 02:41
every letter in the alphabet has a charcode
Michael Aubrey
@mca62511
Mar 14 2016 02:41
@andrewchar Well, you can use .fromCharCode() on a non-number.
thaniri
@thaniri
Mar 14 2016 02:41
so when you're moving letters around in caesars cipher
Dylan
@dhcodes
Mar 14 2016 02:41
@andrewchar you convert to char code, then add or subtract 13 and then convert back to char code
thaniri
@thaniri
Mar 14 2016 02:41
instead of moving the letter you move the charcode by 13
makes things easier
Alex N.
@N0bl3
Mar 14 2016 02:42
@andrewchar you get the charcode from the letter then swap it with charcode-13
Dylan
@dhcodes
Mar 14 2016 02:42
@aJimmer I've done it
Michael Aubrey
@mca62511
Mar 14 2016 02:42
@andrewchar you'll use both String.charCodeAt() and String.fromCharCode()
Andrew Charlebois
@andrewchar
Mar 14 2016 02:42
so far i have code that is doing the adding or subtracting to get the proper letters
i just cant get the string.from....
i tried to use in a for loop but i put myself in an infinite loop lol
thaniri
@thaniri
Mar 14 2016 02:43
try to post code for that kind of question
bitgrower
@bitgrower
Mar 14 2016 02:43

@aJimmer I did Spinal Tap Case. I'm not confident my answer is the most elegant or anything, but I've done it if you want to check my profile.

yeah, mine's ugly, I need to re-do it at some point ...

Andrew Charlebois
@andrewchar
Mar 14 2016 02:44
function rot13(str) { // LBH QVQ VG!


  var done = [];


  for (var i = 0; i < str.length; i++) {
     if (str[i].charCodeAt() <= 77) {
       done += str[i].charCodeAt() + 13; 
     } else if (str[i].charCodeAt() > 77) {
      done += str[i].charCodeAt() - 13;
     } 
  }


   done = String.fromCharCode(done);


  console.log(done);
  return done;



}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
bitgrower
@bitgrower
Mar 14 2016 02:44
@andrewchar -- dig deep and see if you can REALLY understand what charCodeAt does ... before you put it into a loop
use one of the js playgrounds ... jsbin, jsfiddle, pythontutor.com/javascript.html, etc ...
Angel Jimenez
@aJimmer
Mar 14 2016 02:45
Thanks guys! i looked at 3 different code samples and we all have different solutions that work perfectly fine. Good job keep it up!
Prithvi-A
@Prithvi-A
Mar 14 2016 02:45
Stand in Line - I'm a bit stuck on this abstract Data Structure
function queue(arr, item) {
  // Your code here

  queue.push(item);
  var removed = queue.unshift(item);
  return removed;  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(queue(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
Michael Aubrey
@mca62511
Mar 14 2016 02:46
@andrewchar charCodeAt() needs to have the index of the character you want passed to it. So instead of doing str[i], you could do str.charCodeAt(i) I haven't looked at the rest of your code to see if that's the only problem, but it would definitely be a good start
Prithvi-A
@Prithvi-A
Mar 14 2016 02:47
TypeError: queue.push is not a function
Moisés Man
@moigithub
Mar 14 2016 02:47
@Prithvi-A u calling push and unshift on ur function (name)... those are Array methods
so.. wrong target
Prithvi-A
@Prithvi-A
Mar 14 2016 02:47
ah
cool!
@bitgrower good catch
bitgrower
@bitgrower
Mar 14 2016 02:49
? @Prithvi-A
Moisés Man
@moigithub
Mar 14 2016 02:49
:D
Andrew Charlebois
@andrewchar
Mar 14 2016 02:50
@mca62511 hey, my returns i am getting from just charcodeat() make sense now, the numbers are returning. i see see they are spelling the right thing with the numbers
@mca62511 thanks
CamperBot
@camperbot
Mar 14 2016 02:50
andrewchar sends brownie points to @mca62511 :sparkles: :thumbsup: :sparkles:
:star: 380 | @mca62511 | http://www.freecodecamp.com/mca62511
Michael Aubrey
@mca62511
Mar 14 2016 02:50
no worries
Jesus Vega
@ParagonChuy
Mar 14 2016 02:55
@mca62511 Did you run a probability test, then run a deterministic test?
Michael Aubrey
@mca62511
Mar 14 2016 02:56
@ParagonChuy I'm sorry, what are we talking about?
Jesus Vega
@ParagonChuy
Mar 14 2016 02:56
Sorry , for the Sum of All Primes
samamsam
@samsamam
Mar 14 2016 02:58

Hi Coders I am having trouble with this code function queue(arr, item) {
// Your code here
testArr.push(6);
item = testArr.shift();
return item; // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(queue(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
any help would be appreciated its for stand in line

Michael Aubrey
@mca62511
Mar 14 2016 02:58
I just looped through all the numbers between 0 and the given number, checked each one if they were a prime number, and then if they were pushed them to an array. After I added all the elements of the array together.
samamsam
@samsamam
Mar 14 2016 02:58
it does not satisfy these conditions queue([5,6,7,8,9], 1) should return 5
After queue(testArr, 10), myArr4 should be 10
cannelflow
@cannelflow
Mar 14 2016 02:59
@samsamam you need to push item not 6 there
and directly return testArr.shift() or give it other variable name
samamsam
@samsamam
Mar 14 2016 03:02
@cannelflow so Iam pushing 6 because it says add the number to the end of the array
ohhh
wait one part is working
cannelflow
@cannelflow
Mar 14 2016 03:05
@samsamam inside function you are taking two argument arr and item so you need to push item so that code can be generalized
yes it says add a number to end not 6 thats why to generalize we are passing item to it
samamsam
@samsamam
Mar 14 2016 03:07
queue([5,6,7,8,9], 1) should return 5 does not work but After queue(testArr, 10), myArr4 should be 10 works
Ulises Rangel
@urangel
Mar 14 2016 03:08
trying to return longest word length! Does this make any sense?
function findLongestWord(str) {

  var array = str.split(" ");

for (var i = 1; i <= array.length; i++){

    if (array[i].length >= array[(i+1)].length){
      array.splice(array[(i+1)],1);}
    else if (array[(i+1)].length >= array[i].length){
      array.splice(array[i],1);
    }
   }

  var longest = array.join();
  longest.replace(/ /g,'');

  return longest.length;
}
cannelflow
@cannelflow
Mar 14 2016 03:09
@samsamam see the instruction says Write a function queue which takes an array (arr) and a number (item) as arguments.Add the number to the end of the array, (arr.push(item))then remove the first element of array.(arr.shift) The queue function should then return the element that was removed.
samamsam
@samsamam
Mar 14 2016 03:12

@cannelflow function queue(arr, item) {
// Your code here
testArr.push(item);

return (testArr.shift());

}

so i did this i returned the element that was removed
cannelflow
@cannelflow
Mar 14 2016 03:13
@samsamam see your input argument is arr not testArr so do like arr.push and shift
samamsam
@samsamam
Mar 14 2016 03:14
@cannelflow good on you thanks it works
CamperBot
@camperbot
Mar 14 2016 03:14
samsamam sends brownie points to @cannelflow :sparkles: :thumbsup: :sparkles:
:star: 911 | @cannelflow | http://www.freecodecamp.com/cannelflow
cannelflow
@cannelflow
Mar 14 2016 03:14
@samsamam :+1:
James Beem
@beem812
Mar 14 2016 03:28
is there someone way for me to print out the contents of variables?
hard to debug if the only thing they allow you to see is the return statement and then only if the return says what they want it to.
Sidharth Kriplani
@sidkrip
Mar 14 2016 03:31
@cannelflow can you please help me with the bonfire Caesaras Cipher?
CamperBot
@camperbot
Mar 14 2016 03:31
type bonfire name to get some info on that bonfire. And check HelpBonfires chatroom
V Bhargav Chowdary
@bhargav4
Mar 14 2016 03:32
@brainyfarm Thanks a ton
CamperBot
@camperbot
Mar 14 2016 03:32
bhargav4 sends brownie points to @brainyfarm :sparkles: :thumbsup: :sparkles:
:star: 1618 | @brainyfarm | http://www.freecodecamp.com/brainyfarm
Michael Aubrey
@mca62511
Mar 14 2016 03:37

It's so satisfying when you put together a single line solution to something

function drop(arr, func) {
  return func(arr[0]) || arr.length === 0 ? arr : drop(arr.slice(1), func);
}

drop([1, 2, 3, 4], function(n) {return n > 5;});

...I'm skipping ahead to avoid doing the smallest common multiple one.... -.-

@sidkrip what problem are you having with Caesar's Cipher?
thaniri
@thaniri
Mar 14 2016 03:41

hello, can anyone help me with filtering an array? I need to call on a function that filters an array, but I'm not sure how to use my argument

function mutation(arr) {

  function filtration(x){
    return x != q[l];
  }

  arr[0] = arr[0].toLowerCase();
  arr[1] = arr[1].toLowerCase();

  var holder = arr[0].split("");
    holder.sort();
  var q = holder; //creates an alphabetically sorted lowercase array from arr[0]
    holder = arr[1].split("");
    holder.sort();
  var r = holder; //creates an alphabetically sorted lowercase array from arr[1]

  for (var i = 1; i < q.length; i++){
    if (q[i-1].charCodeAt(0) == q[i].charCodeAt(0)){
      q.splice(i, 1);
    }//deletes repeat letters of arr[0]
  }
  for (var j = 1; j < r.length; j++){
    if (r[j-1].charCodeAt(0) == r[j].charCodeAt(0)){
      r.splice(j, 1);
    }
  }//deletes repeat letters of arr[1]
  for (var k = 0; k < q.length; k++){
    if(q[k].charCodeAt(0) == r[0].charCodeAt(0)){
      q = q.slice(k);
    }
  }
  for (var l = 0; l < r.length; l++){//filter from q r[0,1,2,3...];
    filtration(q);
  } 
  return q;
}

mutation(["floor", "for"]);

//1. make 2 lowercase alphabetical arrays
//2. delete repeat letters
//3. take the charcodeat(0) of arr[1] and then slice off the letters of arr[1] that come before arr[1].charcodeat(0)
//4. filter from q every element found in r
//5. if q is empty you win

i know this is an absolute monster of a piece of code, look at function filtration() at the top and the last for loop

looks like frankenstein
Sidharth Kriplani
@sidkrip
Mar 14 2016 03:42
@mca62511
this is my code and I am trying to find a way to easily loop through the string and convert the characters using the second function
function rot13(str) { // LBH QVQ VG!

  for(var i in str) {
    i = str.charCodeAt(indexOf(i));
    if(i < 65 ||  i > 90)
        return each;
    else
     return convert(str);
  }
  return str;
}

function convert(str) {
  var cca=str.charCodeAt();
  var fccp=String.fromCharCode(cca+13);
  var fccm=String.fromCharCode(cca-13);
  if (cca<=77) {
    str=fccp;
  }
  else {
    str=fccm;
  }
  return str;  
}
Michael Aubrey
@mca62511
Mar 14 2016 03:45
okay, your for loop is totally wrong. read the MDN documentation on for
Sidharth Kriplani
@sidkrip
Mar 14 2016 03:48
@mca62511 I know how the for loop works. I just saw someone else's solution and I was trying to replicate the concept. Working on it.
I did the challenge :D thanks @mca62511
CamperBot
@camperbot
Mar 14 2016 03:49
sidkrip sends brownie points to @mca62511 :sparkles: :thumbsup: :sparkles:
:star: 383 | @mca62511 | http://www.freecodecamp.com/mca62511
bitgrower
@bitgrower
Mar 14 2016 03:49
@sidkrip -- this challenge lends itself nicely to array.map ...
Michael Aubrey
@mca62511
Mar 14 2016 03:49
...you did? what did you change to get it working?
I apologize then.
Sidharth Kriplani
@sidkrip
Mar 14 2016 03:51
the new solution. Entirely new I mean. I will be trying to come up with clean concise code like this again
function rot13(encodedStr) {
  return encodedStr.split("").map(function(each){
    var charCode = encodedStr.charCodeAt(encodedStr.indexOf(each)); 
    if(charCode < 65 ||  charCode > 90)
        return each;
    else
     return charCode <= 77 ? String.fromCharCode( (charCode + 13)) : String.fromCharCode( (charCode - 13));
  }).join("");
}
rot13("SERR PBQR PNZC");
@bitgrower yes, I realized that later
and that * is @brainyfarm 's solution. Though I was able to come up with the same solution before I had a look at it
Lê Tấn Trọng
@trongle
Mar 14 2016 03:53
Help me, i don't have idea or solution for Exact Change
CamperBot
@camperbot
Mar 14 2016 03:53
no wiki entry for: me i dont have idea or solution for exact change
Michael Aubrey
@mca62511
Mar 14 2016 03:53
@trongle post your code?
Lê Tấn Trọng
@trongle
Mar 14 2016 03:56
i'm thinking about solution so i dont have to write code yet
i dont know where to start
thaniri
@thaniri
Mar 14 2016 03:57

can i ask differently? for mutations?

function mutation(arr) {

  arr[0] = arr[0].toLowerCase();
  arr[1] = arr[1].toLowerCase();

  var holder = arr[0].split("");
    holder.sort();
  var q = holder; //creates an alphabetically sorted lowercase array from arr[0]
    holder = arr[1].split("");
    holder.sort();
  var r = holder; //creates an alphabetically sorted lowercase array from arr[1]

  for (var i = 1; i < q.length; i++){
    if (q[i-1].charCodeAt(0) == q[i].charCodeAt(0)){
      q.splice(i, 1);
    }//deletes repeat letters of arr[0]
  }
  for (var j = 1; j < r.length; j++){
    if (r[j-1].charCodeAt(0) == r[j].charCodeAt(0)){
      r.splice(j, 1);
    }
  }//deletes repeat letters of arr[1]
  for (var k = 0; k < q.length; k++){
    if(q[k].charCodeAt(0) == r[0].charCodeAt(0)){
      q = q.slice(k);
    }
  }
  for (var l = 0; l < r.length; l++){//filter from q r[0,1,2,3...];
    q.filter(function(x){
      return x != r[l];
    });
  } 
  return q;
}

mutation(["floor", "for"]);

//1. make 2 lowercase alphabetical arrays
//2. delete repeat letters
//3. take the charcodeat(0) of arr[1] and then slice off the letters of arr[1] that come before arr[1].charcodeat(0)
//4. filter from q every element found in r
//5. if q is empty you win

on q.filter((){}); how should i go about making this an external function so that my loop doesn't get angry at me?

V Arun Kumar
@arunvkumr
Mar 14 2016 03:57
@sidkrip wow man.. good job. you know yesterday you gave me another code even that was good. i made it work and was waiting for you to respond.. anyway code looks good. interesting approach. :smile:
Sidharth Kriplani
@sidkrip
Mar 14 2016 04:01
@arunkumrv I am really sorry but I must have dozed off :D
can you please tell me which challenge are we talking about? The Seek and Destroy one?
V Arun Kumar
@arunvkumr
Mar 14 2016 04:02
@sidkrip caeser chipher. using arrays
and regexp
Andrew Charlebois
@andrewchar
Mar 14 2016 04:02
omg Caesars Cipher was a tough cookie to crack
Sidharth Kriplani
@sidkrip
Mar 14 2016 04:02
@arunkumrv oh you made my solution work? Post it here please?
@andrewchar Validate US Telephone Numbers is a bit hard to implement
V Arun Kumar
@arunvkumr
Mar 14 2016 04:05
@sidkrip
function rot13(str) {

  var reg=new RegExp(/([A-Z])/g);
  var arra=[];
  var array=[];
  array=str.split('');
  for (var i=0; i<array.length; i++) {
    if (array[i].match(reg)) //<-- to match regexp
      arra.push(convert(array[i]));
    else arra.push(array[i]); //<-- this is for pushing chars which are not alphabets.
  }
  return arra.join('');
}

function convert(str) {
  var cca=str.charCodeAt();
  var fccp=String.fromCharCode(cca+13);
  var fccm=String.fromCharCode(cca-13);
  if (cca<=77)
    str=fccp;
  else
    str=fccm;
  return str;  
}
rot13("SERR PBQR PNZC");
Andrew Charlebois
@andrewchar
Mar 14 2016 04:06
@sidkrip im no where near there yet, just finished Caesars Cipher. now starting intermediate algorithms since i already did all the projects
bitgrower
@bitgrower
Mar 14 2016 04:06
@thaniri -- that's a LOT of code ... the problem isn't that complex ...
thaniri
@thaniri
Mar 14 2016 04:06
i know it should be this complex
Sidharth Kriplani
@sidkrip
Mar 14 2016 04:06
@arunkumrv this is so helpful! I mean, it is long and too big for this small a problem but still, to know that my solution just needed this few tweaks for it to work haha thanks @arunkumrv
CamperBot
@camperbot
Mar 14 2016 04:06
sidkrip sends brownie points to @arunkumrv :sparkles: :thumbsup: :sparkles:
:star: 360 | @arunkumrv | http://www.freecodecamp.com/arunkumrv
Eric Meling
@Gnilemcire
Mar 14 2016 04:06
help Iterate Through an Array with a For Loop
CamperBot
@camperbot
Mar 14 2016 04:06

:point_right: challenge iterate through an array with a for loop [wiki]

Challenge: Iterate Through an Array with a For Loop

A common task in Javascript is to iterate through the contents of an array. One way to do that is with a for loop. This code will output each element of the array arr to the console:

    var arr = [10,9,8,7,6];
    for (var i=0; i < arr.length; i++) {
       console.log(arr[i]);
    }

Remember that Arrays have zero-based numbering, which means the last index of the array is length - 1. Our condition for this loop is i < arr.length, which stops when i is at length - 1.

:pencil: read more about challenge iterate through an array with a for loop on the FCC Wiki

thaniri
@thaniri
Mar 14 2016 04:06
but i've probably spent 10+ hours trying different things
and this is one step away from being done
Kia Farhang
@KiaFarhang
Mar 14 2016 04:07
@Gnilemcire, what specifically are you struggling with on that one?
bitgrower
@bitgrower
Mar 14 2016 04:07
:( ... well ... you get brownie points from me for your persistance ... tax @thaniri
CamperBot
@camperbot
Mar 14 2016 04:07
bitgrower sends brownie points to @thaniri :sparkles: :thumbsup: :sparkles:
:star: 189 | @thaniri | http://www.freecodecamp.com/thaniri
thaniri
@thaniri
Mar 14 2016 04:08
aghhh
V Arun Kumar
@arunvkumr
Mar 14 2016 04:08
@sidkrip ya you just need one match statement and and instead of an continue another push to insert non alphabets.
the approach using regex. :+1:
thaniri
@thaniri
Mar 14 2016 04:08
im pretty sure if i solve #4 on my list i can just delete #3
which would make things a lot easier
Sidharth Kriplani
@sidkrip
Mar 14 2016 04:09
@arunkumrv I am trying to work out the Validate US Telephone Numbers bonfire with this new concise approach now.
V Arun Kumar
@arunvkumr
Mar 14 2016 04:09
@sidkrip i like this approach if you don't mind can i save your code..
bitgrower
@bitgrower
Mar 14 2016 04:09

@thaniri ... if you pseudocode it ... it goes something like this....

check if every character in test is in source ... if character is not in source, return false ...
if all characters in test are in source, return true

Sidharth Kriplani
@sidkrip
Mar 14 2016 04:09
that concise one is brainyfarm's and well, all the solutions are publicly available under fcc's license so that other campers can use them as well :)
@arunkumrv
thaniri
@thaniri
Mar 14 2016 04:11
thats the easy part
but you have to account for capital letters, repeated letters
AudioGen
@AudioGen
Mar 14 2016 04:11
Hello
bitgrower
@bitgrower
Mar 14 2016 04:11
you clean up the code via regex before looping ...
hey @audioGen~
didn't remember that repeat letters presented a problem ...
create arrays for both .. iterate over test array and do indexOf on source/target array
AudioGen
@AudioGen
Mar 14 2016 04:13
@bitgrower do you find going over some of the exercises you already complete helps?
Sidharth Kriplani
@sidkrip
Mar 14 2016 04:14
@bitgrower @arunkumrv help needed with US telephone numbers
V Arun Kumar
@arunvkumr
Mar 14 2016 04:15
@sidkrip share your code :grinning:
bitgrower
@bitgrower
Mar 14 2016 04:16
absolutely ... @audioGen -- and reading other people's code ... :)
Sidharth Kriplani
@sidkrip
Mar 14 2016 04:16
@arunkumrv I had tried it out a while ago and I came back to look at it now...
function telephoneCheck(str) {
  // Good luck!
 var reg=[];
  var regex=["\d{3}-\d{3}-\d{4}", "(\d{3})\d{3}-\d{4}", "(\d{3})\s\d{3}-\d{4}", "\d{3}\s\d{3}\s\d{4}", "\d{10}", "\d{1}\s\d{3}\s\d{3}\s\d{4}"];
  for(var i=0; i<6; i++) {
    reg.push(new RegExp(regex[i]));
  }
  var res=false;
  for(var j=0; j<6; j++) {
    if (str==reg[i]) {
      res=true;
    }
  } 
  return res;
}
bitgrower
@bitgrower
Mar 14 2016 04:19
@sidkrip -- go to regexone.com ... finish the first set of tutorials, and you have the opp to go thru a 2nd,, which includes a phone number exercise ...
Brian
@BrianCodes33
Mar 14 2016 04:20
function lookUp(firstName, prop){
// Only change code below this line
    for (var i=0; i<contacts.length; i++)  {
      if (firstName == contacts[i].firstName) {
          if (contacts[i][prop]) {
             return prop.value;     
          }
        }
      } 
     }

The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.

If both are true, then return the "value" of that property.

If firstName does not correspond to any contacts then return "No such contact"

If prop does not correspond to any valid properties then return "No such property"

Sidharth Kriplani
@sidkrip
Mar 14 2016 04:20
@bitgrower already did that. Will revisit the phone number exercise
Brian
@BrianCodes33
Mar 14 2016 04:20
someone tell me what im missing?
Kia Farhang
@KiaFarhang
Mar 14 2016 04:21
Marking @BrianBorin 's question because I'm also struggling w/profile lookup. I'm going to tinker with your code and see what I can figure out.
Kyle Morton
@kmorton1988
Mar 14 2016 04:22
@BrianBorin we fixed how to call a specific property and check its value. Do it again to return that value.
Brian
@BrianCodes33
Mar 14 2016 04:24
return prop[value]?
Kyle Morton
@kmorton1988
Mar 14 2016 04:25
how did we compare against "firstName"
bitgrower
@bitgrower
Mar 14 2016 04:25
@BrianBorin ... think it was mentioned very briefly in an earlier challenge .. consider the object method .hasOwnProperty
Kyle Morton
@kmorton1988
Mar 14 2016 04:25
we're checking if a property exists, too. if it does, doesn't it make sense to return that exactly one?
Brian
@BrianCodes33
Mar 14 2016 04:26
         return contacts[i][prop];     
Kyle Morton
@kmorton1988
Mar 14 2016 04:26
bingo

@bitgrower also, the

if (contacts[i][prop]) {
    do stuff
}

works too.

bitgrower
@bitgrower
Mar 14 2016 04:28
thanks @kmorton1988
CamperBot
@camperbot
Mar 14 2016 04:28
bitgrower sends brownie points to @kmorton1988 :sparkles: :thumbsup: :sparkles:
:star: 271 | @kmorton1988 | http://www.freecodecamp.com/kmorton1988
Kyle Morton
@kmorton1988
Mar 14 2016 04:29
sure thing. That's how my solution worked, anyway.
is the .hasOwnProp() ES2015?
bitgrower
@bitgrower
Mar 14 2016 04:29
no
Kyle Morton
@kmorton1988
Mar 14 2016 04:29
interesting.
Brian
@BrianCodes33
Mar 14 2016 04:30

now the
If firstName does not correspond to any contacts then return "No such contact"

If prop does not correspond to any valid properties then return "No such property"

clefnetwork
@clefnetwork
Mar 14 2016 04:30
Hi all-ive been doing the bonfires for a while, but wanted to start an outside project. wanted to make a synthesizer with the library tone.js. I'm hitting a speed bump with on of my functions, would really appreciate some help. fxPass has an if/else statement. The else ive hardcoded variable bitCrush in there. I want to put in fx so it takes the info from the dropdown, but its just not working (i know i only have 2 effects listed, but im trying to get bitcrush to work). any help would be GREATLY appreciated -- thanks http://codepen.io/clefnetwork/pen/EKgEXz?editors=0010
bitgrower
@bitgrower
Mar 14 2016 04:30
yeah, there's something that makes me uneasy about doing it the way you did @kmorton1988 -- but can't quite put my finger on it ... may be 100% fine ...
Kyle Morton
@kmorton1988
Mar 14 2016 04:31
cause if you call a prop without assigning it to something, it returns a boolean.

like:

contacts[i][prop]

returns true in an if statement if the property exists, and returns false if it doesn't. However, it will still return true if the property exists, but it's not defined or is null

bitgrower
@bitgrower
Mar 14 2016 04:33
if the property is falsy,, what does it return ?
Kia Farhang
@KiaFarhang
Mar 14 2016 04:33
Thanks @kmorton1988, I didn't know that's what would happen. Was defining a new variable to store the boolean value.
CamperBot
@camperbot
Mar 14 2016 04:33
kiafarhang sends brownie points to @kmorton1988 :sparkles: :thumbsup: :sparkles:
:star: 272 | @kmorton1988 | http://www.freecodecamp.com/kmorton1988
Kyle Morton
@kmorton1988
Mar 14 2016 04:33
Yup, @KiaFarhang.
elaborate a bit, @bitgrower
Brian
@BrianCodes33
Mar 14 2016 04:34
can someone help me complete the last part of this

If firstName does not correspond to any contacts then return "No such contact"

If prop does not correspond to any valid properties then return "No such property"

bitgrower
@bitgrower
Mar 14 2016 04:34

prop = myKey

obj = {
myKey : false;
}

Kyle Morton
@kmorton1988
Mar 14 2016 04:34
@BrianBorin, I'm not sure you've fully grasped the concept of an if statement. I think it would help if you go back and rework through some of the previous if statement tasks.
We're here to help you understand why stuff works, not to do it for you.
bitgrower
@bitgrower
Mar 14 2016 04:35
so .. your expression doesn't really say it's false because the property doesn't exist, or whether the value of the existing property happens to be false ... no ?
Catalin Scripcariu
@CatalinScr
Mar 14 2016 04:35
Help Friendly Date Ranges
CamperBot
@camperbot
Mar 14 2016 04:35

:point_right: algorithm friendly date ranges [wiki]

Problem Explanation:

  • Create a program that will take two dates and convert them into a more easy to understand date such as January 1st, 2017. It will also check the difference between them, and handles cases with no difference, more than a day, more than a month, more than a year, and more than a month and less than a year respectively.
:pencil: read more about algorithm friendly date ranges on the FCC Wiki
Brian
@BrianCodes33
Mar 14 2016 04:35
@kmorton1988 not asking you to do it for me. i'm having trouble understanding where they go
Kyle Morton
@kmorton1988
Mar 14 2016 04:35
@bitgrower right, even if the value of the property is falsey, it'll still return true since the property is a thing
@BrianBorin play with it, then. Where does it make sense to return those strings?
Brian
@BrianCodes33
Mar 14 2016 04:35
if firstName != contacts[i]
bitgrower
@bitgrower
Mar 14 2016 04:36
but tha'ts an expression which accesses the value, does it not ?
Kyle Morton
@kmorton1988
Mar 14 2016 04:37
@BrianBorin see, that's why i'm not sure you grasp if statements yet. You already have all the structure you need to determine whether or not firstName exists, AND whether or not the given property exists. Now you just have to figure out what to return and where.
@bitgrower yes, but since we aren't comparing it to anything, just accessing it to see if something gets returned, it's a boolean result.
Brian
@BrianCodes33
Mar 14 2016 04:37
function lookUp(firstName, prop){
// Only change code below this line
    for (var i=0; i<contacts.length; i++)  {
      if (firstName == contacts[i].firstName) {
          if (contacts[i][prop]) {
             return contacts[i][prop];     
          }
        } 
      } 
    }
this is all correct
Kyle Morton
@kmorton1988
Mar 14 2016 04:37
@BrianBorin yes.
try running it.
ctrl + enter
Brian
@BrianCodes33
Mar 14 2016 04:37
i did
Kyle Morton
@kmorton1988
Mar 14 2016 04:37
and?
at least one of the tasks on the left are correct, right?
Sidharth Kriplani
@sidkrip
Mar 14 2016 04:38

@bitgrower I changed my RegExp and now this is the code:

function telephoneCheck(str) {
  // Good luck!
  var regex=new RegExp(/1?[\s-]?\(?(\d{3})\)?[\s-]?\d{3}[\s-]?\d{4}/g);
  var res=false;
  for(var j=0; j<6; j++) {
    if (str==regex) {
      res=true;
    }
  } 
  return res;
}

its still not working

bitgrower
@bitgrower
Mar 14 2016 04:38
but that's just the difference between if (true) or If (true === true) ...
Brian
@BrianCodes33
Mar 14 2016 04:38
it passed except for the last 2 parts
Kyle Morton
@kmorton1988
Mar 14 2016 04:38
so fix it.
add the last two parts.
Kia Farhang
@KiaFarhang
Mar 14 2016 04:38
@kmorton1988, I put the two else statements where I thought they should go. The two tests on THOSE statements work, but now the first part - looking up what's actually there - doesn't work, as it did before.
thaniri
@thaniri
Mar 14 2016 04:38
is it possible to filter without using return XYZ;?
function mutation() {

 var q = ["f","l","o","r"];
 var r = ["f","o","r"];
 q = q.filter(function(x){
    for (var l = 0; l < r.length; l++){
      return x !== r[l];
    }
  }); 
 return q;
}
unfortunately this loop breaks after 1 iteration due to the returns
bitgrower
@bitgrower
Mar 14 2016 04:39
LOL ... someone reported they had a challenge that passed all the test cases that returned true, and none of the ones which returned false ... so I said ... OH, your code is returning TRUE ALL the time ...
Kyle Morton
@kmorton1988
Mar 14 2016 04:39
@thaniri, save the result to a variable and return the variable after it's found what it's looking for?
Sidharth Kriplani
@sidkrip
Mar 14 2016 04:40
@bitgrower the same is with me. I have set my return value to false and that is what is being returned in all the cases. So half the outputs are correct and the other half arent.
Kyle Morton
@kmorton1988
Mar 14 2016 04:40

@bitgrower Kind of. It's like, it's more like asking:

if (are[you][there])

Versus

if (are[you][there] == true)
comparing the presence of a property versus the value of the property
if the property exists in any way, whether its value be truthy or falsy, return true.
Brian
@BrianCodes33
Mar 14 2016 04:42
function lookUp(firstName, prop){
// Only change code below this line
    for (var i=0; i<contacts.length; i++)  {
      if (firstName == contacts[i].firstName) {
          if (contacts[i][prop]) {
             return contacts[i][prop];     
          }  if (firstName != contacts) {
                 return "No such contact";
             }          
          }
        } 
      }
bitgrower
@bitgrower
Mar 14 2016 04:42
well ... I'm having to consult on some copy ... so I can't explore this like I would like atm ...
Sidharth Kriplani
@sidkrip
Mar 14 2016 04:42
help needed with the bonfire Map The Debris
CamperBot
@camperbot
Mar 14 2016 04:42
no wiki entry for: needed with the bonfire map the debris
Kyle Morton
@kmorton1988
Mar 14 2016 04:42
@KiaFarhang post your code, let's see what's up.
@BrianBorin you don't need any more if statements, all the if statements you need are there already
Sidharth Kriplani
@sidkrip
Mar 14 2016 04:43
@kmorton1988 have you done the bonfire Map The Debris?
Kia Farhang
@KiaFarhang
Mar 14 2016 04:43
for (var i=0; i < contacts.length; i++)  {
      if (firstName == contacts[i].firstName) {
          if (contacts[i][prop]) {
             return contacts[i][prop];     
          } else {
            return "No such property";
          }
        } else {
          return "No such contact";
        }
      }
Kyle Morton
@kmorton1988
Mar 14 2016 04:44
if there's only one if, the else isn't needed.
Doesn't look like it, @sidkrip
@sidkrip that's quite a few sections ahead of me. I'm still in basic algorithm scripting
@KiaFarhang I was only slightly correct there.
you do need one else.
help Profile Lookup
CamperBot
@camperbot
Mar 14 2016 04:48

:point_right: checkpoint profile lookup [wiki]

Checkpoint: Profile Lookup

Instructions

We have an array of objects representing different people in our contacts lists.

A lookUp function that takes firstName and a property (prop) as arguments has been pre-written for you.

The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.

If both are true, then return the "value" of that property.

If firstName does not correspond to any contacts then return "No such contact"

If prop does not correspond to any valid properties then return "No such property"

Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.

:pencil: read more about checkpoint profile lookup on the FCC Wiki

Kyle Morton
@kmorton1988
Mar 14 2016 04:48
@KiaFarhang @BrianBorin check out the link there ^ read through it. It helped me a lot.
Ridhima Gupta
@ridzgupta26
Mar 14 2016 04:48
var code = "formatted";

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

titleCase("I AM A Boy");
In the title case exercise - Can anyone tell me why is this not working?
Kyle Morton
@kmorton1988
Mar 14 2016 04:49
what is it outputting?
Kia Farhang
@KiaFarhang
Mar 14 2016 04:50
Thanks @kmorton1988. I get it now - I didn't need that second else statement. The last return goes outside the for loop because you want to return that after the loop essentially exhausts itself and can't find the first name, so it tells you there's no such contact.
CamperBot
@camperbot
Mar 14 2016 04:50
kiafarhang sends brownie points to @kmorton1988 :sparkles: :thumbsup: :sparkles:
:warning: kiafarhang already gave kmorton1988 points
Kyle Morton
@kmorton1988
Mar 14 2016 04:51
@KiaFarhang right! good job :)
bitgrower
@bitgrower
Mar 14 2016 04:52
okay, @kmorton -- I just tried this out on Profile Lookup -- I set "likes" to have the value "false" ... and it does exactly what I expect ... the expression evaluates to false, not true
Kyle Morton
@kmorton1988
Mar 14 2016 04:53
you specifically set it to have a boolean of false?
Sidharth Kriplani
@sidkrip
Mar 14 2016 04:53
@bitgrower can you please have a loot at my code?
bitgrower
@bitgrower
Mar 14 2016 04:55

@kmorton1988 -- I set the Akira Laine object so that the likes property looks like this:

"likes" : false

@sidkrip -- sorry, not atm ... in the middle of consulting on a launch ...
I think if it had been as simple as doing if (contacts[id][prop]) the js language folks might not have needed to create a .hasOwnProperty() method
Kyle Morton
@kmorton1988
Mar 14 2016 04:58
@bitgrower i'm trying to test it, give me a sec.
hmm
seems you're right.
bitgrower
@bitgrower
Mar 14 2016 05:02
yeah, the truthiness & falsy stuff can be tricky ... i've been caught up with it before ...
Kyle Morton
@kmorton1988
Mar 14 2016 05:02
@bitgrower so what kind of complications can that bring? how often will a variable or property be declared as false? wouldn't that property have to be specifically declared as either null or false to trigger inadversely?
bitgrower
@bitgrower
Mar 14 2016 05:03
LOTS, @kmorton1988 ... lots and lots and lots ... .why do you think there's a boolean primitive ?
all you need is a property which just has 2 states .. like on/off
enrolled/not enrolled
Ahtesham Ul Haq
@Ahtesham1234
Mar 14 2016 05:04
How to write This SentenceVariable myStr should equal to ("I am a "double quoted" string inside "double quotes"").
Kyle Morton
@kmorton1988
Mar 14 2016 05:05
ahh, I see the complications.
@Ahtesham1234 escape the quotes that are inside the outer quotes
Ahtesham Ul Haq
@Ahtesham1234
Mar 14 2016 05:06
var myStr = ("I am a "\double quoted \" string inside "\double quotes\".")
This is my code.
bitgrower
@bitgrower
Mar 14 2016 05:08
if ( ticket.paid === true) {
print ticket ;
}
Kyle Morton
@kmorton1988
Mar 14 2016 05:08
you've got one double quote that isn't escaped properly
Ahtesham Ul Haq
@Ahtesham1234
Mar 14 2016 05:09
@kmorton1988 thx man got it
CamperBot
@camperbot
Mar 14 2016 05:09
ahtesham1234 sends brownie points to @kmorton1988 :sparkles: :thumbsup: :sparkles:
:star: 273 | @kmorton1988 | http://www.freecodecamp.com/kmorton1988
Kyle Morton
@kmorton1988
Mar 14 2016 05:09
yup yup.
lyrehs
@lyrehs
Mar 14 2016 05:10

Return Early Pattern for Functions: (help please)
here is my code:

function abTest(a, b) {
// Only change code below this line
console.log ("a || b < 0");

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

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

Kyle Morton
@kmorton1988
Mar 14 2016 05:10
@bitgrower thanks for the heads up. Definitely going to use .hasOwnProp from now on.
CamperBot
@camperbot
Mar 14 2016 05:10
kmorton1988 sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 851 | @bitgrower | http://www.freecodecamp.com/bitgrower
lyrehs
@lyrehs
Mar 14 2016 05:11
I can't figure out how to get the return of undefined when I test -2, 2
(sorry did not finish) or 2, -2. I am really stumped.
bitgrower
@bitgrower
Mar 14 2016 05:14
yw @kmorton1988 -- been a good exercise for me, as well, because I'm sure you're not the only one who has used that ... and so could be an unwitting pitfall for other campers as well ...
thanks for bringing it up @kmorton1988
CamperBot
@camperbot
Mar 14 2016 05:15
bitgrower sends brownie points to @kmorton1988 :sparkles: :thumbsup: :sparkles:
:warning: bitgrower already gave kmorton1988 points
José
@Ledjez
Mar 14 2016 05:16
function reverseString(str) {
  var stringArray = [];
  //stringArray = reverseString(str).split();
  return str;
}

reverseString("hello");
Kyle Morton
@kmorton1988
Mar 14 2016 05:16
I think it's even documented as a potential answer in the help docs.
help Profile Lookup
CamperBot
@camperbot
Mar 14 2016 05:16

:point_right: checkpoint profile lookup [wiki]

Checkpoint: Profile Lookup

Instructions

We have an array of objects representing different people in our contacts lists.

A lookUp function that takes firstName and a property (prop) as arguments has been pre-written for you.

The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.

If both are true, then return the "value" of that property.

If firstName does not correspond to any contacts then return "No such contact"

If prop does not correspond to any valid properties then return "No such property"

Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.

:pencil: read more about checkpoint profile lookup on the FCC Wiki

José
@Ledjez
Mar 14 2016 05:16
im supposed to split this string but i don't know how to split it in a function :/
Kyle Morton
@kmorton1988
Mar 14 2016 05:17
look up string.split() function, @Ledjez.
@bitgrower yeah, it's in the help docs as a potential solution.
Kia Farhang
@KiaFarhang
Mar 14 2016 05:18
@kmorton1988 and @bitgrower, thanks for discussing this. I rewrote my profile lookup code to include an explicit "true" in my if statement and use .hasOwnProperty. Works just as well but should avoid the pitfalls you've mentioned.
CamperBot
@camperbot
Mar 14 2016 05:18
kiafarhang sends brownie points to @kmorton1988 and @bitgrower :sparkles: :thumbsup: :sparkles:
:warning: kiafarhang already gave kmorton1988 points
:star: 852 | @bitgrower | http://www.freecodecamp.com/bitgrower
Kyle Morton
@kmorton1988
Mar 14 2016 05:19
@KiaFarhang yeah, definitely avoid using the method I went over. the hasOwnProp is a much better option.
I only used mine as it worked. Then, when I checked the solutions, it's even in the help docs as a potential solution.
uriznik
@uriznik
Mar 14 2016 05:20
@lyrehs you need to use a conditional expression
Kia Farhang
@KiaFarhang
Mar 14 2016 05:20
@kmorton1988 The perils of help documents :)
Kyle Morton
@kmorton1988
Mar 14 2016 05:20
especially open-source ones. ><
lyrehs
@lyrehs
Mar 14 2016 05:23
@uriznik ok. I will work on that. The example did not help with this, IMHO. Or, did it?
Michael Poutre
@M1kep
Mar 14 2016 05:28
Heeeey
So i have a question
I'm implementinmg it in C but it's the math im having trouble with not the code
Anybody know how the caesear cipher works?
uriznik
@uriznik
Mar 14 2016 05:30
@lyrehs not sure, conditional expressions may have been in an earlier lesson?
bitgrower
@bitgrower
Mar 14 2016 05:35

@bitgrower yeah, it's in the help docs as a potential solution.

I s'pose that if you know that much about your data structures & things, it can be legit ... but it just seems like less than optimal programming practice overall ... thanks for checking up on the help ... hadn't occurred to me to look there ... @kmorton1988

CamperBot
@camperbot
Mar 14 2016 05:35
sorry bitgrower, you can't send brownie points to yourself! :sparkles: :sparkles:
Kyle Morton
@kmorton1988
Mar 14 2016 05:36
@bitgrower yeah, I mean, in this particular case, all the values are strings, and if all your values are strings, and you are aware of this, it probably won't present any real propblems in the code.
bitgrower
@bitgrower
Mar 14 2016 05:36
thank @kmorton1988
CamperBot
@camperbot
Mar 14 2016 05:36
bitgrower sends brownie points to @kmorton1988 :sparkles: :thumbsup: :sparkles:
:star: 274 | @kmorton1988 | http://www.freecodecamp.com/kmorton1988
Kyle Morton
@kmorton1988
Mar 14 2016 05:37
but in your example of the posibilty of there being true/false values for everyday things (paid/unpaid, enrolled/unenrolled, signed in/not signed in) i defintely see where it can pose a problem.
bryarcole
@bryarcole
Mar 14 2016 05:37
Having trouble setting up this nested loop...
bitgrower
@bitgrower
Mar 14 2016 05:37
but -- then, if something somehow corrupted your data structure ... it's just not as precise as .hasOwnProperty ... if you get false, you really aren;t pinpointing exactly WHAT is false ... and there are a number of possiblities ...
bryarcole
@bryarcole
Mar 14 2016 05:37
trying to multiply each element by five..

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

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

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

How do i multiply each element in the array by 5?
Kyle Morton
@kmorton1988
Mar 14 2016 05:38
what problem is that? are you sure it's asking you to multiply each one by 5?
bitgrower
@bitgrower
Mar 14 2016 05:39
yeah, I was wondering the same thing ... which challenge is it ...
maybe one of the functional programming challenges ?
bryarcole
@bryarcole
Mar 14 2016 05:39
I mean 5 is a test
it was asking to multiply by 1 or something..
this is the challenge link'
Kyle Morton
@kmorton1988
Mar 14 2016 05:39
what's the name of the problem?
that will link us to your current solution
bitgrower
@bitgrower
Mar 14 2016 05:40
LOL ... okay ... it's the one we think it is, @kmorton1988
Kyle Morton
@kmorton1988
Mar 14 2016 05:40
lol ok.
bitgrower
@bitgrower
Mar 14 2016 05:40
@bryarcole -- one way to handle a problem you are having trouble with is to solve a smaller, but similar problem ...
bryarcole
@bryarcole
Mar 14 2016 05:40
Ok...
bitgrower
@bitgrower
Mar 14 2016 05:40
would you know how to solve this if there was just a 1-dimensional array ?
Kyle Morton
@kmorton1988
Mar 14 2016 05:41
So, @bryarcole , it's not asking you to muliply every number by a single thing, it's asking you to multiply EVERY number by every other number and capture the final product.
bryarcole
@bryarcole
Mar 14 2016 05:41
yeah if it was one dimensional it would be easy
Kyle Morton
@kmorton1988
Mar 14 2016 05:43
so, the "example" code shows you how to iterate through each and every number in the arrays and sub arrays
the $getjson() doesnt seem to work...:/
help guyz
CamperBot
@camperbot
Mar 14 2016 05:45
no wiki entry for: guyz
bryarcole
@bryarcole
Mar 14 2016 05:46
Ok.. but how do I produce those niumbers then manipulate (multiply) them..
I konw how to get the numbers out of an array
oh and how would I show the code in this chat in the super cool way
like With Markdown I think
lyrehs
@lyrehs
Mar 14 2016 05:49
@uriznik -yes, in earlier lessons. Every reference that i found on Google did use the if statement. It just did not seem to jive with the example given. Having a food break. will tell you of my success, with your help. Thanks @uriznik
CamperBot
@camperbot
Mar 14 2016 05:49
lyrehs sends brownie points to @uriznik :sparkles: :thumbsup: :sparkles:
:star: 339 | @uriznik | http://www.freecodecamp.com/uriznik
Sidharth Kriplani
@sidkrip
Mar 14 2016 05:52
help needed with converting Html Entities
CamperBot
@camperbot
Mar 14 2016 05:52
no wiki entry for: needed with converting html entities
bryarcole
@bryarcole
Mar 14 2016 05:53
I did product = arr[i] * arr[j] and it gave me null...
Michael Aubrey
@mca62511
Mar 14 2016 06:00
help smallest common multiple
CamperBot
@camperbot
Mar 14 2016 06:00

:point_right: algorithm smallest common multiple [wiki]

Explanation:

The smallest common multiple between two numbers is the smallest number that
both numbers can divide into. This concept can be extended to more than two
numbers as well.

We can first start with just finding the smallest common multiple between two
numbers. Naively, you can start writing out multiple of each number until you
write a multiple that exists from both numbers.

An example would be the numbers 3 and 4. The multiples of 3 are 3, 6, 9, 12, 15, 18, ... and the multiples of 4 are 4, 8, 12, 16, 20, .... The
first smallest number we run into in both lists is 12 so this is the smallest
common multiple between 3 and 4.

This problem can be confusing because most people look for the smallest common
multiple of just the two numbers but forget the keyword range. However, this
means that if you are given [1,5], then you have to check for the smallest
common multiple for all the numbers [1,2,3,4,5] that is evenly divisible by
all of them.

:pencil: read more about algorithm smallest common multiple on the FCC Wiki

lyrehs
@lyrehs
Mar 14 2016 06:00
@uriznik —success with your help! The example really is from left field. But, I learned stuff so all is good.
uriznik
@uriznik
Mar 14 2016 06:02
@ottomahn you have a '$'instead of '&' in your video json request url
Jenni
@silverrain64
Mar 14 2016 06:02
help truncate a string
CamperBot
@camperbot
Mar 14 2016 06:02

:point_right: algorithm truncate a string [wiki]

Explanation:

We need to reduce the length of the string or truncate it if it is longer than the given maximum lengths specified and add ... to the end. If it is not that long then we keep it as is.

:pencil: read more about algorithm truncate a string on the FCC Wiki

Michael Aubrey
@mca62511
Mar 14 2016 06:13
heh. I "passed" Smallest Common Multiple by doing this
function smallestCommons(arr) {
  return arr[0] === 5 || arr[1] === 5 ? 60 : 360360;
}

smallestCommons([1,5]);
not going to actually submit that answer or anything
just amusing
DJ
@qualitymanifest
Mar 14 2016 06:16
@mca62511 #shipit
Sidharth Kriplani
@sidkrip
Mar 14 2016 06:32
@mca62511 help with the bonfire Validate US Telephone numbers?
CamperBot
@camperbot
Mar 14 2016 06:32
type bonfire name to get some info on that bonfire. And check HelpBonfires chatroom
Michael Aubrey
@mca62511
Mar 14 2016 06:33
I'm pretty sure I haven't done that one yet
I'm not done with the intermediate algorithms.
I did try to jump ahead and do it earlier.
I used a regular expression to turn all the non-numeric characters into dashes, and then split the numbers into an array by the dashes, and then evaluated whether or not it was a valid US number by iterating over the array...
...BUT it didn't account for the fact that some of their test cases have things like 1 555)555-5555
in that case, FCC wants you to return false because the area code isn't closed correctly
so my solution didn't work
and I decided to go back and try to finish the intermediate ones.
Blauelf
@Blauelf
Mar 14 2016 06:56
You can use a subpattern like (\d{3}|\(\d{3}\)), which matches "(555)" and "555", but not "(555" or "555)".
Michael Aubrey
@mca62511
Mar 14 2016 07:07
Thanks for the suggestion, but I'll come back around to it later. I still have to do "Steamroller", "Arguments Optional", and "Everything Be True".
Jeremy Benson
@jb840w
Mar 14 2016 07:12
hey all, I can get my palindrome solution to work for all but the final argument. The underscore is throwing it off. I can make it work by by chaining another replace() after my first replace() but I would love feedback on how to simplify my answer.
function palindrome(str) {
  var regularExpression = /\W/g;
  var newString = str.toLowerCase().replace(regularExpression, "").replace("_", "");
  var splitAndReverse = newString.split("").reverse().join("");
  if (newString === splitAndReverse) {
   return true;
  } else {
    return false;
  }
}

palindrome("eye");
chaining the extra replace() just didn't feel right
uriznik
@uriznik
Mar 14 2016 07:14
@jb840w https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/RegExp
check about character classes and see what \W does in that
Jeremy Benson
@jb840w
Mar 14 2016 07:16
thanks @uriznik , when I read that earlier I thought it would include the underscore [^A-Za-z0-9_] but my runs kept failing
CamperBot
@camperbot
Mar 14 2016 07:16
jb840w sends brownie points to @uriznik :sparkles: :thumbsup: :sparkles:
:star: 340 | @uriznik | http://www.freecodecamp.com/uriznik
Aditya Subramanian
@adityas71094
Mar 14 2016 07:16
How do i pass test case 1 and 3 and the same time in "Quoting Strings with Single Quotes" javascript
?
Hassan
@thelebanondon
Mar 14 2016 07:17
Encode the following sequence, separated by spaces:
backslash tab tab carriage-return new-line and assign it to myStr
Abhishek Kumar
@abhishekKumar1
Mar 14 2016 07:17
help escape
CamperBot
@camperbot
Mar 14 2016 07:17

:point_right: challenge escape sequences in strings [wiki]

Escape Sequences in Strings

Quotes are not the only characters that can be escaped inside a string. Here is a table of common escape sequences:

Code Output
\' single quote
\" double quote
\ backslash
\n new line
\r carriage return
\t tab
\b backspace
\f form feed

Note that the backslash itself must be escaped in order to display as a backslash.

:pencil: read more about challenge escape sequences in strings on the FCC Wiki

Abhishek Kumar
@abhishekKumar1
Mar 14 2016 07:17
try this @adityas71094
Aditya Subramanian
@adityas71094
Mar 14 2016 07:18
test case one says remove all the backslashes
and 3 says Only remove the backslashes \ used to escape quotes
Richard Andrews
@Whiplash5057
Mar 14 2016 07:18
hey guys ... why is this code giving me an infinite loop ..???
Aditya Subramanian
@adityas71094
Mar 14 2016 07:19
@abhishekKumar1
Got it
Thank you @abhishekKumar1
CamperBot
@camperbot
Mar 14 2016 07:19
adityas71094 sends brownie points to @abhishekkumar1 :sparkles: :thumbsup: :sparkles:
:star: 377 | @abhishekkumar1 | http://www.freecodecamp.com/abhishekkumar1
uriznik
@uriznik
Mar 14 2016 07:20
@jb840w you can make you own [ ... ] charset but without the underscore
Richard Andrews
@Whiplash5057
Mar 14 2016 07:20
function(num){
var no  = [0,0];
var noFib = 1;
for(var i = 1; i<num; i++){
noFib = noFib + no[i-1];
no.push(noFib);
}
}
kirbyedy
@kirbyedy
Mar 14 2016 07:22
because the for loop increments i by one, and then inside that loop you are decrementing the same i by 1
uriznik
@uriznik
Mar 14 2016 07:22
@Whiplash5057 is there some other code or does that function have no name?
Richard Andrews
@Whiplash5057
Mar 14 2016 07:22
@uriznik there is a function call sumFibs(4);
@uriznik trying to create a Fibonacci sequence
SuhasHosamani
@SuhasHosamani
Mar 14 2016 07:24
function diff(arr1, arr2) {
  var newArr = [];
  var newArr1 = [];
  var newArr2 = [];
  // Same, same; but different.

  newArr1 = arr1.filter(function(arr2){
      for(i=0; i<arr1.length; i++){
    for(j=0;j<arr2.length; j++){
      if(arr1[i] == arr2[j]){
        return true;
      }
    }
  }
  });
    newArr2 = arr2.filter(function(arr1){
      for(i=0; i<arr2.length; i++){
    for(j=0;j<arr1.length; j++){
      if(arr2[i] == arr1[j]){
       return true;
      }
    }
  }
  });
 newArr=  newArr1.concat(newArr2);
  return newArr;
}

diff([1, 2, 3, 5], [1, 2, 3, 4, 5]);
HI all, whats wrong with code???
Hector Garcia
@augmt
Mar 14 2016 07:24
@Whiplash5057 your code runs fine for me
uriznik
@uriznik
Mar 14 2016 07:25
@Whiplash5057 maybe copy your code somewhere then do a reset on that challenge
Richard Andrews
@Whiplash5057
Mar 14 2016 07:26
@augmt @uriznik cool ...does it give a Fibonacci series ??
Hector Garcia
@augmt
Mar 14 2016 07:26
yep
if you return no you get the whole requested sequence
Richard Andrews
@Whiplash5057
Mar 14 2016 07:28
@augmt YES ...that's what I wanted ...lemme try
@augmt @uriznik thanks
CamperBot
@camperbot
Mar 14 2016 07:29
whiplash5057 sends brownie points to @augmt and @uriznik :sparkles: :thumbsup: :sparkles:
:star: 359 | @augmt | http://www.freecodecamp.com/augmt
:star: 341 | @uriznik | http://www.freecodecamp.com/uriznik
SuhasHosamani
@SuhasHosamani
Mar 14 2016 07:30
hi alll
Markus Kiili
@Masd925
Mar 14 2016 07:31
@SuhasHosamani The parameter of the callback function that is passed to .filter() method should be the array element being iterated, like function(elem){...}.
Michael Aubrey
@mca62511
Mar 14 2016 07:33
やった~ Just got through the intermediate algorithms.
@SuhasHosamani Hello
Markus Kiili
@Masd925
Mar 14 2016 07:33
@SuhasHosamani For example in arr2.filter(function(elem){return ...;}); the callback function tells filter how to filter an arbitrary arr2 element elem. Filter then iterates automatically through arr2 and passes each arr2 element into the callback function and keeps those elements for which the return value from the callback is true (or truthy).
bitgrower
@bitgrower
Mar 14 2016 07:35
yeah ... the code within the filter functions ... I'm not sure what you think filter is doing for you, @SuhasHosamani -- that you are not trying to do yourself within the callback function definition ...
SuhasHosamani
@SuhasHosamani
Mar 14 2016 07:35
@Masd925 im checking if any element in aar1 is present in arr2, if found im removing it......
bitgrower
@bitgrower
Mar 14 2016 07:36
@SuhasHosamani -- the parameters passed to the callback function are described in the array.filter page in MDN ...
...the only thing you need to do is supply a name or names for those parameters so you can manipulate them withint the callback function ...
Markus Kiili
@Masd925
Mar 14 2016 07:37
@SuhasHosamani The callback function is not going to work as you expect. In arr1.filter(function(arr2){... the filter method will pass arr1 elements into the callback function as arr2.
SuhasHosamani
@SuhasHosamani
Mar 14 2016 07:37
@bitgrower i referred that and came up with this
Richard Andrews
@Whiplash5057
Mar 14 2016 07:38
@uriznik @augmt it's not working ...let me send my code back
function sumFibs(num) {

  var no = [0,0];
  var noFib = 1;
  for(var i = 1; i < num; i++){
    noFib = noFib + no[i-1];
    no.push(no);
  }
return no;

}

sumFibs(4);
uriznik
@uriznik
Mar 14 2016 07:39
checl the requirements, do you need to sum the odd fibonaci nums?
SuhasHosamani
@SuhasHosamani
Mar 14 2016 07:40
@Masd925 @bitgrower is this what u meant???
function diff(arr1, arr2) {
  var newArr = [];
  var newArr1 = [];
  var newArr2 = [];
  // Same, same; but different.

  newArr1 = arr1.filter(function(elem){
      for(i=0; i<elem.length; i++){
    for(j=0;j<arr2.length; j++){
      if(elem[i] == arr2[j]){
        return elem[i];
      }
    }
  }
  });
    newArr2 = arr2.filter(function(elem){
      for(i=0; i<elem.length; i++){
    for(j=0;j<arr1.length; j++){
      if(elem[i] == arr1[j]){
       return elem[i];
      }
    }
  }
  });
 newArr=  newArr1.concat(newArr2);
  return newArr;
}

diff([1, 2, 3, 5], [1, 2, 3, 4, 5]);
Richard Andrews
@Whiplash5057
Mar 14 2016 07:40
@uriznik Yes ..but that later
function sumFibs(num) {

  var no = [0,0];
  var noFib = 1;
  for(var i = 1; i < num; i++){
    noFib = noFib + no[i-1];
    no.push(noFib);
  }
return no;

}

sumFibs(4);
bitgrower
@bitgrower
Mar 14 2016 07:41
@SuhasHosamani -- you are NOT to return an element back to the arr.filter method -- you are to return either true or false
Markus Kiili
@Masd925
Mar 14 2016 07:42
@SuhasHosamani The elem there is an array element being iterated, so it is a number.
bitgrower
@bitgrower
Mar 14 2016 07:43
^^^ that too ...
Markus Kiili
@Masd925
Mar 14 2016 07:44
@SuhasHosamani As an example: arr1.filter(function(elem){return elem!==8;}); would return a new array with arr1 elements that are not 8.
uriznik
@uriznik
Mar 14 2016 07:44
@Whiplash5057 what's the name of the challenge?
SuhasHosamani
@SuhasHosamani
Mar 14 2016 07:44
but how can i compare an array to array??
Richard Andrews
@Whiplash5057
Mar 14 2016 07:44
Sum All Odd Fibonacci Numbers
@uriznik
But i wanna find out the series first
SuhasHosamani
@SuhasHosamani
Mar 14 2016 07:45
dynamically n not hardcoded
Richard Andrews
@Whiplash5057
Mar 14 2016 07:45
i thought this should work
Markus Kiili
@Masd925
Mar 14 2016 07:46
@SuhasHosamani You can use indexOf and the element being iterated elem.
bitgrower
@bitgrower
Mar 14 2016 07:47
I'd first get a bit more comfortable with using array.filter, though, I think ...
Markus Kiili
@Masd925
Mar 14 2016 07:48
@SuhasHosamani This example removes arr2 elements from arr1:
var arr1 = [1,2,3,4,5,6,7];
var arr2 = [2,4,6,8];

arr1.filter(function(elem){return arr2.indexOf(elem)===-1}); // [ 1, 3, 5, 7 ]
@SuhasHosamani Or more precisely, returns a new array made from arr1 elements not found on arr2.
Jaron Mauk
@jaronmauk5
Mar 14 2016 07:50
Can someone help me out with the "selecting from many options with Switch Statements" challenge. I am confused with which elements go where.
bitgrower
@bitgrower
Mar 14 2016 07:51
help bootstrap
CamperBot
@camperbot
Mar 14 2016 07:51

:point_right: bootstrap [wiki]

A frontend CSS framework.

You can find out more here

related: css, frameworks

:pencil: read more about bootstrap on the FCC Wiki

Jaron Mauk
@jaronmauk5
Mar 14 2016 08:05
help Switch Statements
CamperBot
@camperbot
Mar 14 2016 08:05

:point_right: challenge adding a default option in switch statements [wiki]

Challenge: Adding a default option in Switch statements

In a switch statement you may not be able to specify all possible values as case statements. Instead, you can add the default statement which will be executed if no matching case statements are found. Think of it like the final else statement in an if/else chain.

A default statement should be the last case.

switch (num) {
  case value1:
    statement1
    break;
  case value2:
    statement2;
    break;
...
  default:
    defaultStatement;
}

:pencil: read more about challenge adding a default option in switch statements on the FCC Wiki

AxeFx
@axefx
Mar 14 2016 08:08
what do you have so far?
kangyao
@kay78
Mar 14 2016 08:09
function drawer(price, cash, cid) {
  // Here is your change, ma'am.
  var dollar = { "PENNY" : 0.01, "NICKEL" : 0.05, "DIME": 0.1, "QUARTER" : 0.25, "ONE" : 1, "FIVE" : 5, "TEN" : 10, "TWENTY" : 20, "ONE HUNDRED" : 100 };

  //return dollar[cid[0][0]];  //log 0.01

  var diff = cash - price;

  var change = [];

  // if total cash in drawer  equals to difference
  var cidtotal = 0;
  for(var x in cid) {
    cidtotal += cid[x][1];
  }
  if (diff == cidtotal) {return "Closed";}
  if (cidtotal < diff) {return "Insufficient Funds";}
  //calculate balance left in drawer"
 // if (cidtotal < diff ) {
   // return "insufficient Funds";
 // } 

  //function to calculate change in current type
  function getChange(diff2, cidtype) {
    //if difference larger than balance in the cidtype 
    if (diff2 >= cidtype[1]){  
      change.push(cidtype);
      diff = diff2 - cidtype[1];
      return  0;
    } 
    // if balance in the type is more than difference
    else if (diff2 < cidtype[1]) {   
      var type = cidtype[0]; //find the basis type
      var deduct = Math.floor(diff2/dollar[type])*dollar[type]; //amount to be deducted from cid
      diff = diff2 % dollar[type];
      cidtype[1] -= deduct;
      if (deduct !== 0){
        var temp = cidtype;
        temp[1]=deduct;
        change.push(temp);
      }
      return (cidtype[1]);
    }
  }

  for (i = cid.length-1; i >= 0; i--) {
    if(diff === 0) {break;} //stop if total change already fulfil the difference 

    cid[i][1] = getChange(diff, cid[i]); //send current cash type and balance to function
  }

  /*if there's no exact change
  if (diff !== 0) {
    return "Insufficient Funds";
  } */

  return change;
}


drawer(3.26, 100.00, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.10], ["QUARTER", 4.25], ["ONE", 90.00], ["FIVE", 55.00], ["TEN", 20.00], ["TWENTY", 60.00], ["ONE HUNDRED", 100.00]]);
the code pass all other testing criteria accept this one.
at the return output result is ["TWENTY",0],["TE",0],["FIVE",15],["ONE",1],["QUARTER", 0.5],["DIME",0.2],["PENNY", 0.03]
need some help, why the output in TWENTY AND TEN are both zero?
Jaron Mauk
@jaronmauk5
Mar 14 2016 08:11

@axefx

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

case 2:
  statement2;
  break;

case 3:
  statement3;
  break;

case 4:
  statement4;
  break;

}

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

// Change this value to test
myTest(1);

I am not sure if my syntax is right but the example isn't all that clear on where certain elements should be.

I was using case 1 as my testing one. Then I would just do that same thing to the rest
AxeFx
@axefx
Mar 14 2016 08:14
@jaronmauk5 how man im stuck on that one too i think its missing applying the conditions to answer
Jaron Mauk
@jaronmauk5
Mar 14 2016 08:15
@axefx Yeah I was wondering if maybe there is a bug in it or something. I can get it to make sense in my head but the code just doesn't want to work.
I am sure my syntax is off but after some googling I don't think it's all me anymore :smile:
SuhasHosamani
@SuhasHosamani
Mar 14 2016 08:16
@Masd925 thanks it worked :smile:
CamperBot
@camperbot
Mar 14 2016 08:16
suhashosamani sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1158 | @masd925 | http://www.freecodecamp.com/masd925
NehaGaba07
@NehaGaba07
Mar 14 2016 08:19

function myTest(val) {
var answer = "";
// Only change code below this line
switch (val)
{
case 1:
answer = "alpha";
break;
case 2 :
answer= "beta";
break;
case 3 :
answer= "gamma";
break;
case 4 :
answer= "delta";
break;
}

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

// Change this value to test
myTest(1);

Try this
it wil work
was also stuck on this

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

// Only change code above this line

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

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

Modify the function abTest so that if a or b are less than 0 the function will immediately exit with a value of undefined.
how it will work
please tell me
cannelflow
@cannelflow
Mar 14 2016 08:20
help format
CamperBot
@camperbot
Mar 14 2016 08:20

: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

rphares
@rphares
Mar 14 2016 08:20
@NehaGaba07 , what have you tried on the return early challenge so far?
cannelflow
@cannelflow
Mar 14 2016 08:21
@NehaGaba07 :point_up: March 14, 2016 1:50 PM
rphares
@rphares
Mar 14 2016 08:21
( @cannelflow ! :blush: )
cannelflow
@cannelflow
Mar 14 2016 08:21
@rphares :smile:
AxeFx
@axefx
Mar 14 2016 08:21
@NehaGaba07 thanks for the help
CamperBot
@camperbot
Mar 14 2016 08:21
axefx sends brownie points to @nehagaba07 :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for nehagaba07
NehaGaba07
@NehaGaba07
Mar 14 2016 08:22
i was doing mistake of single quotes in case then i found it and it worked
now i am stuck on the another problem i have sent
rphares
@rphares
Mar 14 2016 08:23
yes, the return early pattern for functions is what you pasted...?
cannelflow
@cannelflow
Mar 14 2016 08:23
@NehaGaba07 can you please pate formatted code
rphares
@rphares
Mar 14 2016 08:23
we'd like to see what you tried (the code that didnt work) so we can help fix it :blush:
NehaGaba07
@NehaGaba07
Mar 14 2016 08:24

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

// Only change code above this line

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

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

this was the code that was written
Modify the function abTest so that if a or b are less than 0 the function will immediately exit with a value of undefined.
This is the query i need to solve
but i am not able to get it
Abhishek Kumar
@abhishekKumar1
Mar 14 2016 08:24
@NehaGaba07 try reading about if
help if
CamperBot
@camperbot
Mar 14 2016 08:24

:point_right: algorithm diff two arrays [wiki]

Explanation:

Check two arrays and return a new array that contains only the items that are not in either of the original arrays.

:pencil: read more about algorithm diff two arrays on the FCC Wiki

cannelflow
@cannelflow
Mar 14 2016 08:25

if a or b are less than 0 the function will immediately exit with a value of undefined @NehaGaba07

Abhishek Kumar
@abhishekKumar1
Mar 14 2016 08:25
help condition
CamperBot
@camperbot
Mar 14 2016 08:25

:point_right: challenge use conditional logic with if else statements [wiki]

Challenge: Use Conditional Logic with If Statements

We can use if statements in JavaScript to execute code only if the specified condition is met.

Each if statement requires a boolean condition to evaluate. If the boolean evaluates to true, the statements inside the curly braces will execute. Otherwise, if it evaluates to false, the code will not execute.

Example


function test(myVal) {
  if (myVal > 10) {
     return "Greater Than";
  }
  return "Not Greater Than";
}

If myVal is greater than 10, the function will return "Greater Than". If it is not, the function will return "Not Greater Than". Both return statements will never get executed because as soon as the first one is encountered, the execution exits the function and returns control to where the function was called.
:pencil: read more about challenge use conditional logic with if else statements on the FCC Wiki

Abhishek Kumar
@abhishekKumar1
Mar 14 2016 08:25
@NehaGaba07 ^^^
NehaGaba07
@NehaGaba07
Mar 14 2016 08:29

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

if(a || b <0)
{
return undefined;
}

else {

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

// Only change code above this line

}

i have tried this
rphares
@rphares
Mar 14 2016 08:29
close!
NehaGaba07
@NehaGaba07
Mar 14 2016 08:29
this is working for negative value
but not for all values
rphares
@rphares
Mar 14 2016 08:30
but, you want your condition to say
if(a is less than zero OR b is less than zero)
cannelflow
@cannelflow
Mar 14 2016 08:30
@NehaGaba07 :point_up: March 14, 2016 2:00 PM
rphares
@rphares
Mar 14 2016 08:31
@cannelflow , good, you ar still here--
tag... i need to call ti for the night but didn't wanna leave anything unfinished :blush:
cannelflow
@cannelflow
Mar 14 2016 08:32
@rphares stay for another hour :p
what time it is at your place
rphares
@rphares
Mar 14 2016 08:32
0130
cannelflow
@cannelflow
Mar 14 2016 08:33
02:02PM 14th March 2014
rphares
@rphares
Mar 14 2016 08:34
Wow! thats nearly 12 hours ahead, heh..
cannelflow
@cannelflow
Mar 14 2016 08:35
yes it is
Francis
@Francis-p
Mar 14 2016 08:36
i am back! need help with this code
function palindrome(str) {
  // Good luck!
  var lowstr = str.replace(/\W/g, '').toLowerCase();
  var revstr = lowstr.split('').reverse().join('');
  if (lowstr === revstr) {
    return true;
  }

  else {
  return false;
  }
}



palindrome("0_0 (: /-\ :) 0-0”);
phlindrome task
J Player
@Heyjp
Mar 14 2016 08:38
I'm guessing that it is leaving the underscore still in but passing everything else?
cannelflow
@cannelflow
Mar 14 2016 08:38
@Francis-p which task you are not passing ?
Francis
@Francis-p
Mar 14 2016 08:38
the last one as show in the code
cannelflow
@cannelflow
Mar 14 2016 08:38
use replace(/[^A-Z^a-z^0-9]/g, '') @Francis-p
Jaron Mauk
@jaronmauk5
Mar 14 2016 08:39
So I am having trouble with the counting cards challenge. I not sure where to start.
cannelflow
@cannelflow
Mar 14 2016 08:39
replaces everything except word and number @Francis-p
@jaronmauk5 use switch statement
@Francis-p ?
Francis
@Francis-p
Mar 14 2016 08:42
@cannelflow thanks! but i tweak the code to [^a-z^0-9]/g,"
CamperBot
@camperbot
Mar 14 2016 08:42
francis-p sends brownie points to @cannelflow :sparkles: :thumbsup: :sparkles:
:star: 912 | @cannelflow | http://www.freecodecamp.com/cannelflow
Francis
@Francis-p
Mar 14 2016 08:42
i place my .toLowercase infront of the replace
cannelflow
@cannelflow
Mar 14 2016 08:42
@Francis-p :+1:
Selvalingam G
@selva2389
Mar 14 2016 08:47

'''function lookUp(firstName, prop){

var result="";

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

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

            if(contacts[i].hasOwnProperty(prop)){


              result=contacts[i].prop;


            }else{
               result= "No such property";

            }     
      }
    else{
      result="No such contact";

    }

return result;
}

}''' Whats wrong this code?! Any one help me..

CamperBot
@camperbot
Mar 14 2016 08:47
:bulb: to format code use backticks! ``` more info
Abhishek Kumar
@abhishekKumar1
Mar 14 2016 08:53
@SelvalingamG the thing is it will always return "No such contact " because you are not breaking the loop as soon as it find the prop or at it doesn't
J Player
@Heyjp
Mar 14 2016 08:56
@SelvalingamG You are using the dot notation for a variable, so contacts[i].propis looking for a property of the object named prop literally. As prop is a variable and can change you must use bracket notation to access the property.
Markus Kiili
@Masd925
Mar 14 2016 08:59
@SelvalingamG The dot notation only works if the property key string is a valid JS identifier (for example "12" and "lives left" are not) and you write the key after the dot: var cat={clothes:"pants", "lives left":3}; cat.clothes; //returns "pants". Bracket notation works with keys that can be arbitrary strings cat["lives left"]; //returns 3, variables var key="clothes"; cat[key]; //returns "pants", or expressions cat["lives"+" "+"left"]; //returns 3.
33ndgr
@33ndgr
Mar 14 2016 09:01
This for statement is not working, why?
This message was deleted
for (var i = 0; i <= arr.length; i++) {
    newArr = arr[i].replace(/^[A-Za-z]/, "0");
  }
In addition , arr have strings in it
Markus Kiili
@Masd925
Mar 14 2016 09:05
@33ndgr Should you do: arr[i] = arr[i].replace... ?
33ndgr
@33ndgr
Mar 14 2016 09:07
@Masd925 The thing is, that the error i get from the console is
This message was deleted
TypeError: Cannot read property 'replace' of undefined
Abhishek Kumar
@abhishekKumar1
Mar 14 2016 09:08
in regex you use [^A-Za-z]
33ndgr
@33ndgr
Mar 14 2016 09:09
Still the same error
Maybe i'm doing it in ar wrong way :/
alpox
@alpox
Mar 14 2016 09:09
@33ndgr you loop up to <= arr. length. So your last i will be out of range
Abhishek Kumar
@abhishekKumar1
Mar 14 2016 09:10
your arr is a one dimension array?
33ndgr
@33ndgr
Mar 14 2016 09:10
Yeah
Ok, the <= was an error
Now see what i get :')
Abhishek Kumar
@abhishekKumar1
Mar 14 2016 09:11
then why are you using for loop just type
newArr = arr.replace(/[^A-Za-z]/, "0");
33ndgr
@33ndgr
Mar 14 2016 09:12
oh
But int the arr
There are more than one string elements
like [" ", " ", " "]
alpox
@alpox
Mar 14 2016 09:12
@abhishekKumar1 Since when does an array define the method replace?
Abhishek Kumar
@abhishekKumar1
Mar 14 2016 09:12
oh sry
Ron Cruz
@Ronolibert
Mar 14 2016 09:12
function where(arr, num) {
  arr.sort();
  for (var i = 0; i < arr.length; i++){
    if (arr[i] >= num){
      return parseInt(i);
    }
  }
  return arr.length;
}
Does anyone know why this returns 0 when i pass in [5, 3, 20, 3], 5
33ndgr
@33ndgr
Mar 14 2016 09:12
The idea is to iterate over each element and replace the first character
alpox
@alpox
Mar 14 2016 09:13
@Ronolibert Take a look at what the sort function does
Ron Cruz
@Ronolibert
Mar 14 2016 09:13
It sorts it, but doesn't it default to sort lowest to greatest if theres no callback function?
alpox
@alpox
Mar 14 2016 09:13
@Ronolibert And you don't need the parseInt function
Blauelf
@Blauelf
Mar 14 2016 09:13
@Ronolibert sort sorts alphabetically (converts to string for comparison if not already). Use a callback function for the comparisons.
Ron Cruz
@Ronolibert
Mar 14 2016 09:14
hm alright, i'll try passing in a function
V Arun Kumar
@arunvkumr
Mar 14 2016 09:14
@Ronolibert for numeric sort you need a function and 2 args.
Ron Cruz
@Ronolibert
Mar 14 2016 09:14
true, it's already an int
oh i see, so its not consistent unless you pass in the callback?
V Arun Kumar
@arunvkumr
Mar 14 2016 09:15
sort's default behavious is to sort strings alphabetically, for numeric sort you need a callback.
@Ronolibert
33ndgr
@33ndgr
Mar 14 2016 09:15
Done guys
Blauelf
@Blauelf
Mar 14 2016 09:15
That callback function for sort is already mentioned in the description of Sort Arrays with .sort
33ndgr
@33ndgr
Mar 14 2016 09:15
Ty a lot for that @alpox
Ron Cruz
@Ronolibert
Mar 14 2016 09:16
ah, i was playing with it in the console and i thought even without the callback it would work that way
thanks
V Arun Kumar
@arunvkumr
Mar 14 2016 09:16
Ron Cruz
@Ronolibert
Mar 14 2016 09:17
Yeah, i gotta reread it. My understanding was the default for both would be alphabetic for letters and smalest to largest for numbers
Blauelf
@Blauelf
Mar 14 2016 09:17
@Ronolibert There is a way to solve this without ever sorting, just by iterating the array once, which is more efficient (just like you won't sort the array to get its maximum or minimum). Just count the array elements that are <num ;)
Ron Cruz
@Ronolibert
Mar 14 2016 09:18
whaaat
oh wow
I was thinking doing it that way, how would you know the index of where it belongs, but you right
Selvalingam G
@selva2389
Mar 14 2016 09:41
@Masd925 Got it Thanks
CamperBot
@camperbot
Mar 14 2016 09:41
selvalingamg sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1160 | @masd925 | http://www.freecodecamp.com/masd925
Selvalingam G
@selva2389
Mar 14 2016 09:41
@Heyjp got it!!
J Player
@Heyjp
Mar 14 2016 09:42
nice! keep it up @SelvalingamG
Selvalingam G
@selva2389
Mar 14 2016 09:42

@abhishekKumar1 Thanks.. '''function lookUp(firstName, prop){

var result="";

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

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

}
'''

CamperBot
@camperbot
Mar 14 2016 09:42
:bulb: to format code use backticks! ``` more info
Blauelf
@Blauelf
Mar 14 2016 10:00
@SelvalingamG First, declare i using var (won't throw an error unless you are using strict mode, but getting used to not declaring might lead to undesired effects later). Second, don't use variable firstName as the key, use either contacts[i]["firstName"], or contacts[i].firstName (those are equivalent). Third, use < instead of <=contacts.length (there is no contacts[contacts.length], so this is undefined, and undefined throws an error when accessing properties). Fourth, you have no return "No such contact"; anywhere (best place is just before your function ends, outside the loop).
Rada
@Radascript
Mar 14 2016 10:09
hi guys!! Sort of stuck on one of the JS Challenges if anyone is up to help. It's the bouncer one. To refresh, we are trying to filter out all falsy values, and learning how to use filter function. My solution worked for most of them, but NaN is stubborn and keeps not filtering. Can someone tell me what I'm doing wrong? Thanks guys!
function bouncer(arr) {


  function check(val) {
  switch (val) {
    case false:
    case null:
    case NaN:
    case 0:
    case "":
    case undefined:


    return false;
    break;

    default:
    return true;
    break;
  }
}

var filtered = arr.filter(check);
  console.log(filtered);
  return filtered;

}
Alkatell
@Alkatell
Mar 14 2016 10:10
Hi, I would need help for the exercise called "Profile Lookup", my first condition works only if the two others are commented, and the two last ones work either ways. Any ideas please? :)
function lookUp(firstName, prop){
// Only change code below this line
  for (var i = 0; i < contacts.length; i++) {
    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 (firstName == contacts[i].firstName && contacts[i].hasOwnProperty(prop) !== true) {
      return "No such property";
    }
  }

// Only change code above this line
}
negyvenketto
@negyvenketto
Mar 14 2016 10:13
@Radascript my approach was different, but i struggled with NaN as well. the trick that helped me, is that NaN is the only value that is not equal to itself
kangyao
@kay78
Mar 14 2016 10:13
function drawer(price, cash, cid) {
  // Here is your change, ma'am.
  var dollar = { "PENNY" : 0.01, "NICKEL" : 0.05, "DIME": 0.1, "QUARTER" : 0.25, "ONE" : 1, "FIVE" : 5, "TEN" : 10, "TWENTY" : 20, "ONE HUNDRED" : 100 };

  var change = [];
  var diff = cash - price;  
  var cidtotal = cid.map(function(amount) {
    return amount[1];
  }).reduce(function(a,b) {
    return a+b;}).toFixed(2);


  // if total cash in drawer  equals to difference
  if (diff == cidtotal) {return "Closed";}
  if (diff > cidtotal) {return "Insufficient Funds";}


  function getChange(balance, type, typecash) {
    //if balance equal or larger than amount in the cidtype 
    if (balance >= typecash){  
      change.push([type,typecash]);
      diff = balance - typecash;
      return diff;
    } 
    // if balance less than amount in the cidtype
    else if (balance < typecash) {   
      var factor = dollar[type]; //find the conversion factor
      var deduct = factor*Math.floor(balance/factor); //amount deducted from current cashtype
      //typecash -= deduct;
      if (deduct !== 0){
        change.push([type,deduct]);
      }
      return balance % factor;
    }
  }


  for (i = cid.length-1; i >= 0; i--) {
    if(diff === 0) {break;} //stop if total change already fulfil the difference 

    diff = getChange(diff, cid[i][0], cid[i][1]); //calculate amount left in current cash type 
  }

  return change;

}

drawer(3.26, 100.00, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.10], ["QUARTER", 4.25], ["ONE", 90.00], ["FIVE", 55.00], ["TEN", 20.00], ["TWENTY", 60.00], ["ONE HUNDRED", 100.00]]);
The result output is wrong when it reaches PENNY
[["TWENTY",60],["TEN",20],["FIVE",15],["ONE",1],["QUARTER",0.5],["DIME",0.2],["PENNY",0.03]] .
can someone help me with it? have been stucks for two days.....
Rada
@Radascript
Mar 14 2016 10:13
@negyvenketto thanks for the tip, I'll try to think on that now.
CamperBot
@camperbot
Mar 14 2016 10:13
radascript sends brownie points to @negyvenketto :sparkles: :thumbsup: :sparkles:
:star: 296 | @negyvenketto | http://www.freecodecamp.com/negyvenketto
Markus Kiili
@Masd925
Mar 14 2016 10:19
@kay78 Most likely a rounding error. You can use integers (all amounts in pennies) or use a margin of error like lambda=0.000001 in comparisons.
negyvenketto
@negyvenketto
Mar 14 2016 10:21
@Alkatell i think you need to put return "No such contact"; outside of your loop. you want to check for every "i" before declaring that
kangyao
@kay78
Mar 14 2016 10:21
@Masd925 how do i apply a margin of error in comparisons?
Rada
@Radascript
Mar 14 2016 10:25
woo solved it. NaN is such a weirdo. Goodnight all!
Markus Kiili
@Masd925
Mar 14 2016 10:25
@kay78 For example, if you check that some money amount is zero, you do it with amount<lambda.