These are chat archives for FreeCodeCamp/HelpJavaScript

22nd
Mar 2016
scharla
@scharla
Mar 22 2016 00:00
@noirnight it's probably a part opf thearray, just with a blank value
Shaun Moore
@noirnight
Mar 22 2016 00:00
Correct, an example it gives is
update(2548, "tracks", "");
scharla
@scharla
Mar 22 2016 00:01
yeah so once you delete it it would be (2548. "tracks")
```
update(2548, "tracks"); //<--- one less property
```
Shaun Moore
@noirnight
Mar 22 2016 00:03
Ah I got it
I needed to use the delete command
delete collection[id][prop]
Thanks, challenge passed
scharla
@scharla
Mar 22 2016 00:04

Anybody able to help with Drop It exercise? ```js
function drop(arr, func) {

// Drop them elements.
var newArr = [];
for (var i = 0; i <arr.length; i++) {

if (func(arr[i])) {

return arr.splice(i, (arr.length));

}

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

function drop(arr, func) {

  // Drop them elements.
  var newArr = [];
  for (var i = 0; i <arr.length; i++) {

  if (func(arr[i])) {

 return arr.splice(i, (arr.length));

  }

  }
}
drop([1, 2, 3, 7, 4], function(n) {return n > 10;});
if the function is false I just get a blank result and I'm not sure how to change that into an empty array instead. It's because the splice is empty. Do I need to start over with another command?
Kurt Johnson
@pompan129
Mar 22 2016 00:16
@scharla returning to early. loop through the whole array & then return
scharla
@scharla
Mar 22 2016 00:18
@pompan129 Once the function is true you're supposed to stop and return the rest of the array though?
Maybe I'm missing something?
Lloyd Consolacion
@cowboybebot
Mar 22 2016 00:19
@scharla when i saw that exercise i thought it would be good for filter
it gives you the function to use right there
Kurt Johnson
@pompan129
Mar 22 2016 00:20
@scharla filter would be good. or return newArr after loop
@scharla sorry about 1st answer. didn't read directions just assumed & I was wrong
scharla
@scharla
Mar 22 2016 00:22
The issue with the filter is that it filters the whole thing
It says you're supposed to use shift but I can;'t figure it out
drop([1, 2, 3, 7, 1, 4], function(n) {return n > 5;});
if you filter you get [7] rather than [7,1,4] :(
Kurt Johnson
@pompan129
Mar 22 2016 00:25
@scharla okay. now I get it. sorry for run around. had to go and Actually read the directions. in your loop shift() each element[i] until you find a truthy. then return. after loop return empty array if everything was shifted out inside your loop
Lloyd Consolacion
@cowboybebot
Mar 22 2016 00:26
@pompan129 you could be right on where you are going with. i havent used any of the other ways so cant really comment ont he other ways
scharla
@scharla
Mar 22 2016 00:27
@pompan129 @cowboybebot Thanks guys. Let me try shift again
CamperBot
@camperbot
Mar 22 2016 00:27
scharla sends brownie points to @pompan129 and @cowboybebot :sparkles: :thumbsup: :sparkles:
:star: 435 | @pompan129 | http://www.freecodecamp.com/pompan129
:star: 330 | @cowboybebot | http://www.freecodecamp.com/cowboybebot
Kurt Johnson
@pompan129
Mar 22 2016 00:28
@cowboybebot I think @scharla was right about filter(). You can't exit on a truthy in filter() can you?
Lloyd Consolacion
@cowboybebot
Mar 22 2016 00:30
for filter it either filters the whole thing in which case, yoou just return the filtered array. if something passed, you can do your processing on an if statement...shift , slice
Kurt Johnson
@pompan129
Mar 22 2016 00:33
@cowboybebot right, but you don't want to process the whole array in that excercise. you want to exit and return the remainder of the array the 1st time you find a truthy.
scharla
@scharla
Mar 22 2016 00:37
@cowboybebot Thanks again!
CamperBot
@camperbot
Mar 22 2016 00:37
scharla sends brownie points to @cowboybebot :sparkles: :thumbsup: :sparkles:
:warning: scharla already gave cowboybebot points
scharla
@scharla
Mar 22 2016 00:37
function drop(arr, func) {

  // Drop them elements.
  var newArr = [];
  newArr = arr.filter(func);
  var ind = arr.indexOf(newArr[0]);
 if (ind === -1) {
   return [];
 }
  else return arr.splice(ind,arr.length);




}
drop([1, 2, 3, 7, 1, 4], function(n) {return n > 10;});
Got there in the end - probably not the most elegant solution but it works :)
Andrew Charlebois
@andrewchar
Mar 22 2016 00:37
help Sum All Primes
CamperBot
@camperbot
Mar 22 2016 00:37

:point_right: algorithm sum all primes [wiki]

Explanation:

The explanation for this problem is very simple. You will generate a list of prime numbers up to the number you are given as a parameter. Then you need to add them all up and return that value. The tricky part is on generating the list of prime numbers. I suggest you find a code or a good math algorithm that you can turn into code.

:pencil: read more about algorithm sum all primes on the FCC Wiki

Kurt Johnson
@pompan129
Mar 22 2016 00:42
@scharla congrats!
scharla
@scharla
Mar 22 2016 00:43
thanks :)
Lloyd Consolacion
@cowboybebot
Mar 22 2016 00:46
@pompan129, @scharla it's always a balancing act to make code efficient for the machine or the viewer of the code. to make it worse, each viewer can view the code differently. but i believe its important to see different perspectives on the same problem
Andrew Charlebois
@andrewchar
Mar 22 2016 01:04
This message was deleted
This message was deleted
Jordan Meyer
@Jordanmeyer89
Mar 22 2016 01:07
help quotes
CamperBot
@camperbot
Mar 22 2016 01:07

:point_right: challenge escaping literal quotes in strings [wiki]

Escaping Literal Quotes in Strings

In JavaScript, you can escape a quote from considering it as an end of string quote by placing a backslash \ in front of the quote.

"Alan said, \"Peter is learning JavaScript\"."

This signals JavaScript that the following quote is not the end of the string, but should instead appear inside the string.

However another option is to alternate quotation marks if possible. 'Alan said, "Peter is learning JavaScript"' this would also work.

:pencil: read more about challenge escaping literal quotes in strings on the FCC Wiki

Marc
@wumpafruits
Mar 22 2016 01:07
var args = Array.prototype.slice.call(arguments);
Does this piece of code automatically convert any argument into an array? Do i have to add anything/remove anything?
^^ I'm on Seek and Destroy
Jordan Meyer
@Jordanmeyer89
Mar 22 2016 01:12
I think mine was shorter
just like arguements0
Andrew Charlebois
@andrewchar
Mar 22 2016 01:15
@wumpafruits on the mdn page.. The arguments object is not an Array. It is similar to an Array, but does not have any Array properties except length. For example, it does not have the pop method. However it can be converted to a real Array: var args = Array.prototype.slice.call(arguments);
so no you dont add anything
BenC
@Benscar1
Mar 22 2016 01:16
help Local Scope and Functions
CamperBot
@camperbot
Mar 22 2016 01:16

:point_right: challenge local scope and functions [wiki]

Challenge: Local Scope and Functions

Variables which are declared within a function, as well as the function parameters have local scope. That means, they are only visible within that function.

Here is a function myTest with a local variable called loc.

function myTest() {
  var loc = "foo";
  console.log(loc);
}
myTest(); // "foo"
console.log(loc); // "undefined"

loc is not defined outside of the function.
:pencil: read more about challenge local scope and functions on the FCC Wiki

Eric Murta
@murtinha
Mar 22 2016 01:16
guys, why am not getting more than one quote when clicking the bottom multiple times?
http://codepen.io/murtinha/pen/vGgoyX
Marc
@wumpafruits
Mar 22 2016 01:17
@andrewchar hmm ya i was thinking i might need to add/edit that line of code
@andrewchar thanks
CamperBot
@camperbot
Mar 22 2016 01:17
wumpafruits sends brownie points to @andrewchar :sparkles: :thumbsup: :sparkles:
:star: 380 | @andrewchar | http://www.freecodecamp.com/andrewchar
Monty2016
@Monty2016
Mar 22 2016 01:18
Hi everyone. I am stuck on introducing else statements. My
myTest(4) and myTest(5) won't run. I have all green checks except for these two. I still have 2 x's
ulucay
@ulucay
Mar 22 2016 01:21
if I push a value like this
collectionid.push(value);
Kurt Johnson
@pompan129
Mar 22 2016 01:21
@murtinha I think your ajax runs only once when document is ready, so you only retrieve one quote. did you want onClick() to send another request?
ulucay
@ulucay
Mar 22 2016 01:22
collection id.push(value);
anyway
:D
Kurt Johnson
@pompan129
Mar 22 2016 01:22
@Monty2016 can you post code?
ulucay
@ulucay
Mar 22 2016 01:22
if (prop === "tracks" && value !== "") { collection[id][prop].push(value); } else if (value !== ""){ collection[id][prop] = value; } else { delete collection[id][prop]; }
Monty2016
@Monty2016
Mar 22 2016 01:23

@ulucay
function myTest(val) {
var result = "";
// Only change code below this line

if (val > 5) {
return "Bigger than 5";
}

else {
return "5 or smaller";
}

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

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

Gabriel Freire
@Maslor
Mar 22 2016 01:23
This message was deleted

why is this failing half of the tests?

function where(collection, source) {
  var arr = [];
  var key = Object.keys(source);

  collection.forEach(function(item){
    if(item[key]===source[key]){
      arr.push(item);
    }
  });
return arr;
}

It's the where art thou challenge

Kurt Johnson
@pompan129
Mar 22 2016 01:24
@Monty2016 put 3 backticks (``` up left of keyboard) on line before and after your code
Bearded One
@EpicBeard
Mar 22 2016 01:25
sup everyone
anyone able to help me on the Palindrome portion?
Monty2016
@Monty2016
Mar 22 2016 01:26

@pompan129
```if (val > 5) {
return "Bigger than 5";
}

else {
return "5 or smaller";
}

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

// Change this value to test
myTest(5);```

Kurt Johnson
@pompan129
Mar 22 2016 01:26
@Monty2016 backticks need to be on their own line
Monty2016
@Monty2016
Mar 22 2016 01:27
@pompan129
if (val > 5) {
    return "Bigger than 5";
  }

  else {
    return "5 or smaller";
  }


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

// Change this value to test
myTest(5);
Eric Murta
@murtinha
Mar 22 2016 01:27
@pompan129 I just fixed it, but by doing that I'm gonna be putting the other bottom function inside that one, but they are not related, they use the same variables though...
@pompan129 and now my twitter bottom doesnt work http://codepen.io/murtinha/pen/vGgoyX
Kurt Johnson
@pompan129
Mar 22 2016 01:29
@Monty2016 try setting them to "result" like original code. shouldn't make a difference but it worked for me
Monty2016
@Monty2016
Mar 22 2016 01:33
@pompan129 Thank you! I got it!!
CamperBot
@camperbot
Mar 22 2016 01:33
monty2016 sends brownie points to @pompan129 :sparkles: :thumbsup: :sparkles:
:star: 436 | @pompan129 | http://www.freecodecamp.com/pompan129
Kurt Johnson
@pompan129
Mar 22 2016 01:35
@murtinha right. you have the twitter function inside the onClick() call. pull it out otherwise it only works while button is being clicked. When onClick() fires just retrieve quote and display. pull quote out of DOM element when you use #twit. least thats how i'd do it. or set quote on a global variable
freeman-g
@freeman-g
Mar 22 2016 01:35
Hi Folks, what are most people using for your Javascript development setup for testing and debugging for the challenges? I have been using codepen and and a lot of console.log statements, and I'm wondering if there is a better setup?
Eric Murta
@murtinha
Mar 22 2016 01:36
@pompan129 how do I set it on a global variable if the ajax is inside a function?
David Weedmark
@DavidWeedmark
Mar 22 2016 01:37
@freeman-g I use Notepad++ just because I can easily see which closing brackets match the opening brackets and quickly save my progress. but I do the testing in the challenge, throwing in console.logs for tests if needed
freeman-g
@freeman-g
Mar 22 2016 01:38
@DavidWeedmark so you are copy pasting from Notepad++ every time you want to run your code?
Marc
@wumpafruits
Mar 22 2016 01:39
I run mine in the browser (chrome)
David Weedmark
@DavidWeedmark
Mar 22 2016 01:39
yeah it's quick. ctrl-A, ctrl-C, ctrl-V
Kurt Johnson
@pompan129
Mar 22 2016 01:39
so you set a var globalQuote = "", outside the onClick() function. then it should still available inside ajx function, so when the you do your promise-callback just set globalQuote=quote
@murtinha
Andrew Charlebois
@andrewchar
Mar 22 2016 01:40
help Smallest Common Multiple
CamperBot
@camperbot
Mar 22 2016 01:40

: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

Eric Murta
@murtinha
Mar 22 2016 01:40
@pompan129 got it, thanks man
CamperBot
@camperbot
Mar 22 2016 01:40
murtinha sends brownie points to @pompan129 :sparkles: :thumbsup: :sparkles:
:star: 437 | @pompan129 | http://www.freecodecamp.com/pompan129
Kurt Johnson
@pompan129
Mar 22 2016 01:40
@murtinha glad I could help
i need you guys help
I do not know what is wrong with my solution
Marc
@wumpafruits
Mar 22 2016 01:44
@MarkWh1te use hte provided codes
@MarkWh1te mind your spacing too
MarkWh1te
@MarkWh1te
Mar 22 2016 01:47
I tried my friend but it says "Encode the following sequence, separated by spaces:"
how to separated one string by spaces?
Kurt Johnson
@pompan129
Mar 22 2016 01:48
@MarkWh1te bad wording. just put series of escape sequences in string, each seperated by a space. no words
Marc
@wumpafruits
Mar 22 2016 01:49
They provide that code on the left hand side. You're supposed to use the code and separate them by spaces. A string can have spaces inside of it. Like so: "Hi, my name is blah"
MarkWh1te
@MarkWh1te
Mar 22 2016 01:50
sorry
Marc
@wumpafruits
Mar 22 2016 01:50
@MarkWh1te no worries, it can be confusing
MarkWh1te
@MarkWh1te
Mar 22 2016 01:52
thanks for your help! I just do not know the meaning of this section :(
know how to use space?
Marc
@wumpafruits
Mar 22 2016 01:53
"\ \t \whatever" <---
MarkWh1te
@MarkWh1te
Mar 22 2016 01:56
thank you my friend~
@wumpafruits you are a nice person !
i followed you on github
Marc
@wumpafruits
Mar 22 2016 01:59
@MarkWh1te np
Ashw
@asharhw
Mar 22 2016 02:15
hey guys ! Why it isn't possible to use dot to access properties of an object in the "Using Objects for Lookups" Challenge?
Le Twitch
@notalkingplz
Mar 22 2016 02:15
@asharhw Link us what you've done so far
Ashw
@asharhw
Mar 22 2016 02:16
if i use result = lookup.val; it's not working, but if i use result = lookup[val]; it works!
MarkWh1te
@MarkWh1te
Mar 22 2016 02:16
This message was deleted
Ashw
@asharhw
Mar 22 2016 02:16
what do you mean?
Mafalda
@otmeek
Mar 22 2016 02:17
@asharhw if the property is inside a variable, you cannot use dot notation but otherwise you can
Le Twitch
@notalkingplz
Mar 22 2016 02:17
What @otmeek said
Ashw
@asharhw
Mar 22 2016 02:18
oh, now it's clear, thanks alot! @otmeek @notalkingplz
CamperBot
@camperbot
Mar 22 2016 02:18
asharhw sends brownie points to @otmeek and @notalkingplz :sparkles: :thumbsup: :sparkles:
:star: 451 | @otmeek | http://www.freecodecamp.com/otmeek
:star: 224 | @notalkingplz | http://www.freecodecamp.com/notalkingplz
shooterchengde
@shooterchengde
Mar 22 2016 02:22
Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a two-dimensional array.
AlisonSwift
@AlisonSwift
Mar 22 2016 02:24
Can someone help with the challenge "Find the Longest Word in a String"?
Le Twitch
@notalkingplz
Mar 22 2016 02:25
@AlisonSwift Link us your code
AlisonSwift
@AlisonSwift
Mar 22 2016 02:25
function findLongestWord(str) {
  var distance = 0;
  var array = [];
  array = str.split(" ");

  for (var i = 0; i < array.length; i ++) {
    if (array[i].length > distance) {
       distance = array[i].length;
       return distance;
      }

    }
}

findLongestWord("The quick brown fox jumped over the lazy dog");
b1rd0fb3auty14
@b1rd0fb3auty14
Mar 22 2016 02:25
Sorry, I lost my window
Does anyone remember my question?
I can write it again...
I'll just write it again...
I'm working on the PhoneLookup exercise, and am stuck on getting the "Bob", "number" to return "No such contact"
below is my code...
```
for(var i = 0; i < contacts.length; i++) {
    if(contacts[i].firstName === firstName && contacts[i].hasOwnProperty(prop)) {
      return contacts[i][prop];
    }
  }
  if(contacts.hasOwnProperty(prop) === false) {
    return "No such property";
  }
  if(contacts.firstName !== firstName) {
    return "No such contact";
  }
Le Twitch
@notalkingplz
Mar 22 2016 02:27
@AlisonSwift You're returning the distance instead of the word
@AlisonSwift or is that what you need to do for the exercise? I'm not up to that yet :S
AlisonSwift
@AlisonSwift
Mar 22 2016 02:28
@notalkingplz the challenge wants to return the length (number of characters) of the longest word in the string
RickWisneske
@rwisneske
Mar 22 2016 02:29
Hi guys! Can anyone help with the JS animated movement of my background img on mouse enter? I want the background img to move with the mouse not inverted.
http://codepen.io/rwhiskey/pen/ZQZRpM
Le Twitch
@notalkingplz
Mar 22 2016 02:29
@AlisonSwift You need to return the value after the for loop
@AlisonSwift Or it will return on the first loop and the loop will end
AlisonSwift
@AlisonSwift
Mar 22 2016 02:32
@notalkingplz Got it! Thanks
CamperBot
@camperbot
Mar 22 2016 02:32
alisonswift sends brownie points to @notalkingplz :sparkles: :thumbsup: :sparkles:
:star: 225 | @notalkingplz | http://www.freecodecamp.com/notalkingplz
Le Twitch
@notalkingplz
Mar 22 2016 02:34
@AlisonSwift You're welcome :)
William
@apswak
Mar 22 2016 02:34
Almost finished my calculator! Anyone know how I can make decimals work?
http://codepen.io/kreitzo/full/RapEqp
hnry
@hnry
Mar 22 2016 02:35
@b1rd0fb3auty14 you have to loop to check the firstName, and if none of the contacts have it
Le Twitch
@notalkingplz
Mar 22 2016 02:36
@b1rd0fb3auty14 I'm stuck on that too :S This is what I have so far
function lookUp(firstName, prop){
  for (var i = 0; i < contacts.length; i++) {
    if (contacts[i].firstName === firstName) {
      if (contacts[i][prop]) {
        return contacts[i][prop];
      } else {
        return "No such property";
      }
    }
  }
}
CamperBot
@camperbot
Mar 22 2016 02:36
:bulb: to format code use backticks! ``` more info
David Weedmark
@DavidWeedmark
Mar 22 2016 02:36
@kreitzo it's not working? 0.7 = 0.7 works for me
William
@apswak
Mar 22 2016 02:39
@DavidWeedmark seems to be not working for divides
Pramod Jacob
@domarp-j
Mar 22 2016 02:40

Hey all, I could also use some help with the Mutations bonfire challenge. Basically, given an array of two strings, return true if all of the letters in the second string are present in the first.

'''
function mutation(arr) {

// lowercase, split, sort, remove duplicates, then rejoin strings
for (var i = 0; i < 2; i++) {
arr[i] = arr[i].toLowerCase().split('').sort();
var newArray = [];
for (var j = 0; j < arr[i].length; j++)
if (arr[i][j] != arr[i][j-1]) newArray.push(arr[i][j]);
arr[i] = newArray.join('');
}

// return true or false
if (arr0.indexOf(arr[1]) == -1) return false;
return true;

}

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

I can get all of the test cases except for mutation(["floor", "for"]). I don't know how to deal with that rogue "l" in floor. Any help would be greatly appreciated.

CamperBot
@camperbot
Mar 22 2016 02:40
type bonfire name to get some info on that bonfire. And check HelpBonfires chatroom
David Weedmark
@DavidWeedmark
Mar 22 2016 02:40
@kreitzo yeah, none of your divides seem to work
Pramod Jacob
@domarp-j
Mar 22 2016 02:40
got the formatting wrong, my bad
Le Twitch
@notalkingplz
Mar 22 2016 02:40
@domarp-j You can edit what you said and add the back ticks ```
Pramod Jacob
@domarp-j
Mar 22 2016 02:41
back ticks!
of course

Hey all, I could also use some help with the Mutations bonfire challenge. Basically, given an array of two strings, return true if all of the letters in the second string are present in the first.

function mutation(arr) {
// lowercase, split, sort, remove duplicates, then rejoin strings
for (var i = 0; i < 2; i++) {
arr[i] = arr[i].toLowerCase().split('').sort();
var newArray = [];
for (var j = 0; j < arr[i].length; j++)
if (arr[i][j] != arr[i][j-1]) newArray.push(arr[i][j]);
arr[i] = newArray.join('');
}
// return true or false
if (arr0.indexOf(arr[1]) == -1) return false;
return true;
}
mutation(["floor", "for"]);

I can get all of the test cases except for mutation(["floor", "for"]). I don't know how to deal with that rogue "l" in floor. Any help would be greatly appreciated.

CamperBot
@camperbot
Mar 22 2016 02:41
type bonfire name to get some info on that bonfire. And check HelpBonfires chatroom
David Weedmark
@DavidWeedmark
Mar 22 2016 02:41
@kreitzo if i replace your division symbol with a / it does work though
Pramod Jacob
@domarp-j
Mar 22 2016 02:41
thanks @notalkingplz
CamperBot
@camperbot
Mar 22 2016 02:41
domarp-j sends brownie points to @notalkingplz :sparkles: :thumbsup: :sparkles:
William
@apswak
Mar 22 2016 02:41
@DavidWeedmark It's because for some reason ÷ isnt recognized, i changed it to a /
CamperBot
@camperbot
Mar 22 2016 02:41
:star: 226 | @notalkingplz | http://www.freecodecamp.com/notalkingplz
@DavidWeedmark Thanks
CamperBot
@camperbot
Mar 22 2016 02:42
kreitzo sends brownie points to @davidweedmark :sparkles: :thumbsup: :sparkles:
:star: 419 | @davidweedmark | http://www.freecodecamp.com/davidweedmark
Le Twitch
@notalkingplz
Mar 22 2016 02:43
Can someone help me with the profile lookup exercise? This is what I have so far link
Jonathon Swider
@jpswider
Mar 22 2016 02:48
@notalkingplz I think you're issue is the contacts[i][prop] should be contacts[i].prop instead, in both locations.
Greg D
@mosaic-greg
Mar 22 2016 02:49
@notalkingplz you will need to use a && inside if (contacts[i][prop]) to define another condition
David Weedmark
@DavidWeedmark
Mar 22 2016 02:50
@kreitzo love your minimal JS btw
Le Twitch
@notalkingplz
Mar 22 2016 02:52
@jpswider @mosaic-greg I need to return something if my first if conditional fails. The conditionals aren't the problem :S
@jpswider @mosaic-greg So what's a way to return something if the first if conditional fails, and it's within a for loop
Jonathon Swider
@jpswider
Mar 22 2016 02:55
oh I see the issue, well then that case is when the firstName isn't contained within the list right? so if you check every name with your for loop and don't find the name which was passed in then you need to return something. You can just put that outside of the for loop, since the for loop will never finish unless the name isn't in the list.
Greg D
@mosaic-greg
Mar 22 2016 02:55
outside the for loop < indeed
Christian Rosa
@ChristianRosa
Mar 22 2016 03:01
Can someone explain the Wikipedia API Zipline? I read through the documentation and and having trouble understanding which parameters to use to query the site. Seems much more involved than the OpenWeatherMap api and I just want to be able to understand it intuitively
Andrew Charlebois
@andrewchar
Mar 22 2016 03:01
help Finders Keepers
CamperBot
@camperbot
Mar 22 2016 03:01

:point_right: algorithm finders keepers [wiki]

Explanation:

The problem is quite simple to understand. You will check for each element in the array that is passed in the first argument, if the element plugged in to the function passed as the second argument returns true the first time. We do not care about the second or third one that is true, only the very first one if any. If there are none, then return undefined. This last bit is not explained but it is part of the tests used.

:pencil: read more about algorithm finders keepers on the FCC Wiki

CamperBot
@camperbot
Mar 22 2016 03:06
no wiki entry for: how can i do this httpswwwfreecodecampcomchallengesword-blanks
Le Twitch
@notalkingplz
Mar 22 2016 03:08
@jpswider Resulted to this if you're curious as to how I solved it
Christian Rosa
@ChristianRosa
Mar 22 2016 03:09
help Wikipedia Viewer
CamperBot
@camperbot
Mar 22 2016 03:09
no wiki entry for: wikipedia viewer
Vladimir Logachev
@VladimirLogachev
Mar 22 2016 03:11
kunal2051
@kunal2051
Mar 22 2016 03:16
anyone knows how Accessing Objects Properties with Variables works?
Monty2016
@Monty2016
Mar 22 2016 03:24
Golf Code instructions make no sense.....:/
Jonathon Swider
@jpswider
Mar 22 2016 03:29
@Monty2016 Basically you want to check whether the strokes variable matches each of the conditions in the table provided from top to bottom, once one of the conditions is met you return the appropriate string. Does that make more sense?
Jeff
@meankraken
Mar 22 2016 03:39
Hey all, has anyone completed bonfire Friendly Date Ranges? why are their expected answers inconsistent with the instructions?
Dylan Pagillo
@DylanNeil
Mar 22 2016 03:42
help
CamperBot
@camperbot
Mar 22 2016 03:42

Hi, I'm CamperBot! I can help you in this chatroom :smile:

Basic Commands:

  • find TOPIC find all entries about topic. ex: find js
  • wiki TOPIC show contents of topic page
  • thanks @username send brownie points to another user
  • about @username shows info on that user
  • Algorithm BONFIRENAME info on a Algorithm

:speech_balloon: meet CamperBot in this room!

:pencil: read more about camperbot on the FCC Wiki

Farid
@Faredhattab
Mar 22 2016 03:45
hi all
is Math.random() possible to take the value 1 ?
Lavie Ruan
@LavieMaru
Mar 22 2016 03:48
find Adding a default option in Switch statements
CamperBot
@camperbot
Mar 22 2016 03:48

find adding a default option in switch statements

:zero: challenge adding a default option in switch statements

Brian van Vlymen
@arduino731
Mar 22 2016 03:55
help Sum All Number
CamperBot
@camperbot
Mar 22 2016 03:55

:point_right: algorithm sum all numbers in a range [wiki]

Problem Explanation:

  • You need to create a program that will take an array of two numbers who are not necessarily in order, and then add not just those numbers but any numbers in between. For example, [3,1] will be the same as 1+2+3 and not just 3+1
:pencil: read more about algorithm sum all numbers in a range on the FCC Wiki
Lane Anderson
@LaneAnderson
Mar 22 2016 04:04

' ' '
function sumFibs(num) {

var fibs = [0,1];
var oddFibs = [];
var number = 1000; //Passed into function(if number assigned to num, locks up browser)

var a = 1; //Counter for while loop

while(fibs[a] < number){

fibs.push(fibs[a]+fibs[a-1]);
a++;

}

oddFibs = fibs.filter(function(num){return num % 2;}).filter(function(num){return num <= number;});

return oddFibs.reduce(function(a, b){return a+b;});

}

sumFibs(1000);
' ' '
My code works when I manually set "number" to the number I want passed into the function. But if I try to assign "num" to "number" the browser locks up. I'm stuck on how to get around this..... I could have sworn on many other bonfires that I could call a function parameter by name inside the function body, but it does not seem to work here.

dangit, cant get the formatting right.....
Anna-Sophie
@annasophie
Mar 22 2016 04:07
find Pairwise
CamperBot
@camperbot
Mar 22 2016 04:07

find pairwise

:zero: algorithm pairwise

Ryan Price
@rsprice
Mar 22 2016 04:10
@LaneAnderson help format
type in that command and you'll see the light
Jonathon Swider
@jpswider
Mar 22 2016 04:10
@LaneAnderson I'm not entirely sure why you are assigning num to number instead of just using it in the first place but I copy pasted your code into my browser and replaced 1000 with num and it worked fine. Not sure what the issue is.
Lane Anderson
@LaneAnderson
Mar 22 2016 04:14

Hmm, when used a < num as the end condition for a FOR loop it would crash everytime.... it seems to work for a WHILE loop. oops! Why would the two behave differently? This is what would crash and burn:

for(var a = 1; a < num; a++){

fibs.push(fibs[a]+fibs[a-1]);

}

Jeff
@meankraken
Mar 22 2016 04:18

For anyone who's done friendly date ranges bonfire:

makeFriendlyDates(["2016-12-01", "2017-02-03"]) should return ["December 1st","February 3rd"]

makeFriendlyDates(["2022-09-05", "2023-09-04"]) should return ["September 5th, 2022","September 4th"]

Am I brainfarting? That doesn't make sense right? Both meet the within one year requirement, but one answer deletes both years and the other keeps the year on the first date...

Rafael J. Rodriguez
@Rafase282
Mar 22 2016 04:22
Anyone familiar with drowndoa list and radio buttons for forms?
ulucay
@ulucay
Mar 22 2016 04:43
is there anyone who did nested for loops
exerces
exercises
Junn Eric
@juntyms
Mar 22 2016 04:46
@ulucay just do loop within the loop
ulucay
@ulucay
Mar 22 2016 04:46
thats what i did
but i dont know for example
this is the object arr[i][j]
how to multiply i * j
devonwilson1
@devonwilson1
Mar 22 2016 04:48
can i get help being pointed in the right direction I'm stuck on "selecting from many option with switch statements"
Junn Eric
@juntyms
Mar 22 2016 04:48
@ulucay
function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line
  for (var i=0; i < arr.length; i++) {
    for (var j=0; j < arr[i].length; j++) {
      product *= arr[i][j];
    }
  }
  // Only change code above this line
  return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
devonwilson1
@devonwilson1
Mar 22 2016 04:48

function myTest(val) {
var answer = "";
// Only change code below this line
var alpha1 = "alpha1";

switch ("val") {
case alpha1:
alpha1;
break;
case myTest(2):
statement2;
break;
case myTest(3):
beta;
break;
case myTest(4):
gamme;
break;
case myTest(5):
delta;
break;

}

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

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

ulucay
@ulucay
Mar 22 2016 04:49
oh @juntyms what i missed is for the second loop i use again “i”
@juntyms thanks
CamperBot
@camperbot
Mar 22 2016 04:49
ulucay sends brownie points to @juntyms :sparkles: :thumbsup: :sparkles:
:star: 268 | @juntyms | http://www.freecodecamp.com/juntyms
ulucay
@ulucay
Mar 22 2016 04:49
for (var i=0; i<arr.length; i++){
for (var j=0; j<arr[i].length; j++)
like this :D
devonwilson1
@devonwilson1
Mar 22 2016 04:51
anyone out there that can help me?
ulucay
@ulucay
Mar 22 2016 04:51
could u tell me the exercise name @devonwilson1
devonwilson1
@devonwilson1
Mar 22 2016 04:51
selecting from many options with switch statemtns
Junn Eric
@juntyms
Mar 22 2016 04:52
@devonwilson1 remove ("") from switch
devonwilson1
@devonwilson1
Mar 22 2016 04:52
@ulucay thank you
CamperBot
@camperbot
Mar 22 2016 04:52
devonwilson1 sends brownie points to @ulucay :sparkles: :thumbsup: :sparkles:
:star: 232 | @ulucay | http://www.freecodecamp.com/ulucay
ulucay
@ulucay
Mar 22 2016 04:52
ah he already answered it
but if you stuck , i can still help
let me know
Junn Eric
@juntyms
Mar 22 2016 04:53
@devonwilson1 your statement switch ("val") should be switch (val)
devonwilson1
@devonwilson1
Mar 22 2016 04:53
great thanks
lets see if i can figure it out now
devonwilson1
@devonwilson1
Mar 22 2016 04:59
hey @juntyms when i run the example or "alpha1" for example
it will say it cannot find var "value1" how do i set condition for set answeres
Junn Eric
@juntyms
Mar 22 2016 05:00
@devonwilson1 you need to assign alpha to answer variable
answer = "alpha1";
@devonwilson1
  switch (val) {
    case 1: 
      answer = "alpha"; 
      break;
    case 2: 
      answer = "beta";
      break;
    case 3:
       answer = "gamma";
      break;
    case 4:
      answer = "delta";
      break;
  }
devonwilson1
@devonwilson1
Mar 22 2016 05:02
thanks
can you tell me what the difference is of this way of setting tests vs else if?
Junn Eric
@juntyms
Mar 22 2016 05:04
@devonwilson1
if (val==1) {
      answer = "alpha";
} else if (val == 2) {
    answer ="beta";
} else if(val==3) {
   answer =="gamma";
}
devonwilson1
@devonwilson1
Mar 22 2016 05:05
yes i understand but what is the reason for the two what is the advantage over the other
Junn Eric
@juntyms
Mar 22 2016 05:06
its the same actually just on how you want to implement it
devonwilson1
@devonwilson1
Mar 22 2016 05:11
ok cool
and how can you explain why it tells me return statements are only valid inside functions?
Eduardo A. González Robles
@GonzandRobles
Mar 22 2016 05:11

Hello, I need some help with the challenge Nesting for Loops, This is what I have so far.

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

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

The error says : Type error cannot read property "length" of undefined

shanky
@shaanky
Mar 22 2016 05:13
@GonzandRobles actully looking at your code you are trying to take the length of function which is not possible
@GonzandRobles as you are passing array in multiplyAll function
Eduardo A. González Robles
@GonzandRobles
Mar 22 2016 05:13
ohhhh yeah I see now
shanky
@shaanky
Mar 22 2016 05:13
@GonzandRobles try this arr.length
Junn Eric
@juntyms
Mar 22 2016 05:14
@GonzandRobles multiplyAll should be arr
Eduardo A. González Robles
@GonzandRobles
Mar 22 2016 05:15
thank you guys @shaanky @juntyms
CamperBot
@camperbot
Mar 22 2016 05:15
gonzandrobles sends brownie points to @shaanky and @juntyms :sparkles: :thumbsup: :sparkles:
:star: 269 | @juntyms | http://www.freecodecamp.com/juntyms
:star: 152 | @shaanky | http://www.freecodecamp.com/shaanky
Junn Eric
@juntyms
Mar 22 2016 05:15
@devonwilson1 your function should return a value thats why you need return statement inside a function
devonwilson1
@devonwilson1
Mar 22 2016 05:21
well i thought this was a function
and it says i have return statutes but that only valid in a function wtfff? lol
Darrel Adams
@dadams-510
Mar 22 2016 05:37
What is the best way to iterate over an array with objects?
I'm trying to finish the "Profile Lookup" challenge.
Right now, I'm using a for loop but I don't know if I should use a second loop.
Darrel Adams
@dadams-510
Mar 22 2016 05:43
Thanks @migueltrivera. Do you think this is the best way to iterate over an array with objects in it?
CamperBot
@camperbot
Mar 22 2016 05:43
dadams-510 sends brownie points to @migueltrivera :sparkles: :thumbsup: :sparkles:
:star: 253 | @migueltrivera | http://www.freecodecamp.com/migueltrivera
Darrel Adams
@dadams-510
Mar 22 2016 05:44
What would happen if the array had an object but other types of data types in it?
Miguel T Rivera
@mtrivera
Mar 22 2016 05:44
@dadams-510 imo, yes.
Markus Kiili
@Masd925
Mar 22 2016 05:45
@dadams-510 Arrays are iterated with for loop or array iterator methods. Not with for...in loop.
@dadams-510 Iteration is the same regardless of what is in the array.
Darrel Adams
@dadams-510
Mar 22 2016 05:48
What's the difference between a "for-in" vs a basic for loop?
mrugesh mohapatra
@raisedadead
Mar 22 2016 05:49

:speaker: Thanks a lot to all the backers have met our goal for the India :shirt: Campaign

j.mp/fcc_india_t_shirt

Last 12 hours to go, in case you missed it this is your last chance.

Tees will be shipping out soon!

:sparkles: :sparkles: :sparkles: :sparkles: :sparkles: :sparkles: :sparkles: :sparkles:
Markus Kiili
@Masd925
Mar 22 2016 05:54
@dadams-510 Arrays are actually objects in JS, with array elements stored in properties with numeric keys like "0", "1", etc. The for loop loops over those indices and you can access array elements. For...in loop iterates over objects properties and also looks at the prototype chain for inherited properties. Therefore using for...in loop is slower and might break your code if some library had added properties to arrays.
@dadams-510 Also, for...in loop doesn't preserve looping order, so elements might be iterated in wrong order.
@dadams-510 Using for...in loop on array elements usually works in these simple problems, but because of those problems above, it is considered bad practice.
Malviya
@malviyaprateek
Mar 22 2016 06:12
how to declare string variables ?
Mark Dickinson
@monoposon
Mar 22 2016 06:17
my code is showing that it is working in the screen on the right, but it is telling me it isnt working ...

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

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

// Alter values below to test your code
update(1245, "tracks", "Addicted to Love");

also dont know how to post my code properly
Junn Eric
@juntyms
Mar 22 2016 06:19
@monoposon all requirements should be met on the right side of your browser.. some might have been met but others are not yet met
Mark Dickinson
@monoposon
Mar 22 2016 06:21
it is telling me that it is being met in the output window, but it wont accept it below that so i can go to the next section. it is telling me i need to push "addicted to love" into the tracks, in the out put it shows me its there, but it isnt passing me
Junn Eric
@juntyms
Mar 22 2016 06:22
@monoposon you need to met this requirements
  • After update(5439, "artist", "ABBA"), artist should be "ABBA"
  • After update(2548, "artist", ""), artist should not be set
  • After update(1245, "tracks", "Addicted to Love"), tracks should have "Addicted to Love" as the last element.
  • After update(2548, "tracks", ""), tracks should not be set
@monoposon theres a scrollbar between the output window and the code window scroll down you could see if there is a check icon to see if it met the requirements
Mark Dickinson
@monoposon
Mar 22 2016 06:23
it isnt, but in the ouput window it looks like it should work
Junn Eric
@juntyms
Mar 22 2016 06:24
@monoposon yup it means you only have met other requirements you need to meet all requirements it seems you haven't met the 3rd requirement
1 - After update(5439, "artist", "ABBA"), artist should be "ABBA"
2 - After update(2548, "artist", ""), artist should not be set
3 - After update(1245, "tracks", "Addicted to Love"), tracks should have "Addicted to Love" as the last element.
4 - After update(2548, "tracks", ""), tracks should not be set
Mark Dickinson
@monoposon
Mar 22 2016 06:26
thats what its telling me, but in the output window it looks like it worked when i test it. is the push line correct?
Junn Eric
@juntyms
Mar 22 2016 06:28
@monoposon
you have an error here
else if(prop === "tracks" && value !== ""){
collection[id].tracks.push(value);
}
else {
delete collectionid;
}
}
@monoposon
should be
delete collection[id][prop];
Mark Dickinson
@monoposon
Mar 22 2016 06:30
thats how it is in my code, didnt paste right
Miguel T Rivera
@mtrivera
Mar 22 2016 06:31
wiki Palindromes
CamperBot
@camperbot
Mar 22 2016 06:31

:point_right: algorithm check for palindromes [wiki]

Explanation:

Our goal for solving this problem is tidying up the string passed in, and checking whether it is in fact a palindrome.

  • If you are unsure of what a palindrome is, it is a word or phrase that when reversed spells the same thing forwards or backwards. A simple example is mom, when you reverse the letters, it spells the same thing! Another example of a palindrome is race car. When we take out anything that is not a character it becomes racecar which is the same spelled forwards or backwards!

Once we have determined whether it is a palindrome or not we want to return either true or false based on our findings.

:pencil: read more about algorithm check for palindromes on the FCC Wiki

Junn Eric
@juntyms
Mar 22 2016 06:31
@monoposon
okay then I tested your code.. you havent comply first and third requirement , I mean 3rd requirement only
Mark Dickinson
@monoposon
Mar 22 2016 06:32
how do you post code like you did, i noticed a few discrepencies when i copied and pasted it.
Junn Eric
@juntyms
Mar 22 2016 06:33
copy the code from your browser then put your code between ```
<code>
```
Mark Dickinson
@monoposon
Mar 22 2016 06:34

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

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

// Alter values below to test your code
update(1245, "tracks", "Addicted to Love");
'''

CamperBot
@camperbot
Mar 22 2016 06:34
:bulb: to format code use backticks! ``` more info
Mark Dickinson
@monoposon
Mar 22 2016 06:34

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

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

// Alter values below to test your code
update(1245, "tracks", "Addicted to Love");
```

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

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

// Alter values below to test your code
update(1245, "tracks", "Addicted to Love");
Junn Eric
@juntyms
Mar 22 2016 06:36
@monoposon type the 3 teldi or backtick () shift+enter then paste your code then shift+enter then type again 3 teldi ()
Mark Dickinson
@monoposon
Mar 22 2016 06:36
@juntyms yeah took me a few tries lol
Jiimms
@jiimms
Mar 22 2016 06:37

record collection :


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

    else 
        delete collection[id][prop];
       }

My record collection is getting updated when I am running this code but still i get red cross marks . Please can someone tell me what I am doing wrong?

Junn Eric
@juntyms
Mar 22 2016 06:38
@monoposon @jiimms
try these guys
you need to separate the if value!=="" and Prop !=="tracks"
function update(id, prop, value) {
  if (value !== "") {
    if (prop !== "tracks") {
      collection[id][prop] = value;
    } else {
      collection[id][prop].push(value);
    }
  } else {
    delete collection[id][prop];
  }

  return collection;
}
shanky
@shaanky
Mar 22 2016 06:38
@monoposon you are very close just you have to put the prop instead of tracks in the else condition
try this @monoposon
else if(prop == "tracks" && value !== ""){
   collection[id][prop].push(value);
   return collection;
 } else
   delete collection[id][prop];
  return collection;
@jiimms actully you have not return the collection
Jiimms
@jiimms
Mar 22 2016 06:39
@juntyms thanks but I was wondering why the collection is getting updated as desired and still the code is not passing.
CamperBot
@camperbot
Mar 22 2016 06:39
jiimms sends brownie points to @juntyms :sparkles: :thumbsup: :sparkles:
:star: 270 | @juntyms | http://www.freecodecamp.com/juntyms
shanky
@shaanky
Mar 22 2016 06:40
just try this @jiimms
 if( prop !== "tracks" && value !== ""){
   collection[id][prop]= value;  
   return collection;

 }else if(prop == "tracks" && value !== ""){
   collection[id][prop].push(value);
   return collection;
 } else
   delete collection[id][prop];
  return collection;
Mark Dickinson
@monoposon
Mar 22 2016 06:41
yeah im having the same problem @jiimms
Jiimms
@jiimms
Mar 22 2016 06:41
@shaanky tried it now but still update(5439, "artist", "ABBA") is not passing. The collection is getting updated corectly
Ghost
@ghost~56bd2077e610378809c105cd
Mar 22 2016 06:42
javascript gets tricky very quickly if you dont know how it works...the fcc curriculum doesnt really show you the basics very well
Mark Dickinson
@monoposon
Mar 22 2016 06:42
thats weird, i added the return statements and it worked...
Junn Eric
@juntyms
Mar 22 2016 06:42
@monoposon if you have doubts you can replace the last line to this
 update(1245, "tracks", "Addicted to Love")
shanky
@shaanky
Mar 22 2016 06:43
@jiimms show me your code
Mark Dickinson
@monoposon
Mar 22 2016 06:44
yeah i was testing with that and it was working in the output window but wasnt passing me. i added the return statements and it passed me.
Junn Eric
@juntyms
Mar 22 2016 06:44
@monoposon ah so you solved it lol :D
Mark Dickinson
@monoposon
Mar 22 2016 06:44
```
Sujit Karki
@Swoozeki
Mar 22 2016 06:44

Ok, I'm still getting this:

Error: Potential infinite loop at line 15. To disable loop protection, write: 
// noprotect
as the first line. Beware that if you do have an infinite loop in your code this will crash your browser.

This is my algorithm: https://repl.it/By3o
Can anybody haalp!

Junn Eric
@juntyms
Mar 22 2016 06:44
you need to have a return statement so it will pass
Mark Dickinson
@monoposon
Mar 22 2016 06:45
function update(id, prop, value) {
  if (value !== "" && prop !== "tracks"){
    collection[id][prop] = value;  
    return collection;
  }
  else if(prop === "tracks" && value !== ""){
    collection[id][prop].push(value);
    return collection;
  }
  else {
    delete collection[id][prop];
    return collection;
  }
}
Junn Eric
@juntyms
Mar 22 2016 06:45
@monoposon you can have it this way
```
function update(id, prop, value) {
  if (value !== "" && prop !== "tracks"){
    collection[id][prop] = value;  

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

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

  }
return collection
}
Jiimms
@jiimms
Mar 22 2016 06:46
@shaanky . here it is
var collection = {
    2548: {
      album: "Slippery When Wet",
      artist: "Bon Jovi",
      tracks: [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    2468: {
      album: "1999",
      artist: "Prince",
      tracks: [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    1245: {
      artist: "Robert Palmer",
      tracks: [ ]
    },
    5439: {
      album: "ABBA Gold"
    }
};

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

    else 
        delete collection[id][prop];


   return collection;
}


 update(5439, "artist", "ABBA");
Junn Eric
@juntyms
Mar 22 2016 06:46
@monoposon
so as not to repeat the return statement
Mark Dickinson
@monoposon
Mar 22 2016 06:47
ahhh yep that works too, thank you for the help!
the else doesnt have { } @jiimms
Junn Eric
@juntyms
Mar 22 2016 06:49
@jiimms monoposon solved your issue
Mark Dickinson
@monoposon
Mar 22 2016 06:49
really :smile:
Junn Eric
@juntyms
Mar 22 2016 06:50
:D
shanky
@shaanky
Mar 22 2016 06:51
@jiimms i cant see any problem in ur code but still dont put like this ((value !== "") && (prop !== "tracks")) instead try (value !== "" && prop !== "tracks") this

var collection = {
    2548: {
      album: "Slippery When Wet",
      artist: "Bon Jovi",
      tracks: [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    2468: {
      album: "1999",
      artist: "Prince",
      tracks: [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    1245: {
      artist: "Robert Palmer",
      tracks: [ ]
    },
    5439: {
      album: "ABBA Gold"
    }
};

var collectionCopy = JSON.parse(JSON.stringify(collection));


function update(id, prop, value) {

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

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

}

update(5439, "artist", "ABBA");
here is code @jiimms it should work
@jiimms have you includede this -- var collectionCopy = JSON.parse(JSON.stringify(collection));
@jiimms i dont see this line that is why its not working properly
Nick Robson
@nickrobson
Mar 22 2016 06:55
I made a thing.
Junn Eric
@juntyms
Mar 22 2016 06:55
@jiimms as mentioned by @monoposon it should be like this
function update(id, prop, value) {

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

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


}
Jiimms
@jiimms
Mar 22 2016 06:55
@shaanky yes that works, thanks. but I would still like to understand why my code did not work even though the collection got updated. :smile:
CamperBot
@camperbot
Mar 22 2016 06:55
jiimms sends brownie points to @shaanky :sparkles: :thumbsup: :sparkles:
:star: 153 | @shaanky | http://www.freecodecamp.com/shaanky
Nick Robson
@nickrobson
Mar 22 2016 06:55
It makes ASCII graphs of equations..
shanky
@shaanky
Mar 22 2016 06:56
@jiimms issue was that one which was not there in your program
 var collectionCopy = JSON.parse(JSON.stringify(collection));
Jiimms
@jiimms
Mar 22 2016 06:57
@shaanky yes yes, thanks a lot now. i see now that line got deleted somehow. it passed now . :sparkles:
CamperBot
@camperbot
Mar 22 2016 06:57
jiimms sends brownie points to @shaanky :sparkles: :thumbsup: :sparkles:
:warning: jiimms already gave shaanky points
shanky
@shaanky
Mar 22 2016 06:57
anytime @jiimms
Sujit Karki
@Swoozeki
Mar 22 2016 06:58

Ok, I'm still getting this:

Error: Potential infinite loop at line 15. To disable loop protection, write: 
// noprotect
as the first line. Beware that if you do have an infinite loop in your code this will crash your browser.

This is my algorithm: https://repl.it/By3o
Can anybody haalp!

Jiimms
@jiimms
Mar 22 2016 06:59
@juntyms thanks
Zach
@Moose1551
Mar 22 2016 07:03
Without giving me too much, can anyone explain to me why I can't pass "Bogey, Double Bogey, and Go Home!" on the Golf Code section of basic javaScript?
function golfScore(par, strokes) {
  // Only change code below this line

  if (strokes == 1) {
    return "Hole-in-one!";
  } else if (strokes == 2) {
    return "Eagle";
  } else if (strokes == 3) {
    return "Birdie";
  } else if (strokes > 3 || par === 4) {
    return "Par";
  } else if (strokes > par && strokes < 6) {
    return "Bogey";
  } else if (strokes == 6) {
    return "Double Bogey";
  } else if (strokes >= 7) {
    return "Go Home!";
  } else 

  return "Change Me";


  // Only change code above this line
}

// Change these values to test
golfScore(5, 4);
Junn Eric
@juntyms
Mar 22 2016 07:05
@Swoozeki you have a potential infinite loop since your while loop would end up to be always false so it will not end the while loop
Sujit Karki
@Swoozeki
Mar 22 2016 07:06
@juntyms can you help me with an alternative?
Junn Eric
@juntyms
Mar 22 2016 07:06
@Swoozeki you need to review this
  var found=false;

  while(!found){
    commonMultiple=findNextCommonMultiple(arr,startIndex);
    startIndex++;
    for(var i=0; i<inBetweenNumbers.length;i++){
      if(commonMultiple%inBetweenNumbers[i]===0) found=true;
      else{
        found=false;
        break;
      }
    }
  }
Sujit Karki
@Swoozeki
Mar 22 2016 07:06
while(found===false){
    commonMultiple=findNextCommonMultiple(arr,startIndex);
    startIndex++;
    for(i=0; i<inBetweenNumbers.length;i++){
      if(commonMultiple%inBetweenNumbers[i]===0) found=true;
      else{
        found=false;
        break;
      }
    }
  }
that's the same result
shanky
@shaanky
Mar 22 2016 07:07
@Moose1551 in your conditions you need to put par-2 in second else if like this you need to check where to put like par-
Junn Eric
@juntyms
Mar 22 2016 07:07
@Swoozeki what are you trying accomplish on your code?
shanky
@shaanky
Mar 22 2016 07:08
@Moose1551 give the same conditions as in given in golf code challange
Sujit Karki
@Swoozeki
Mar 22 2016 07:08
smallest common multiple @juntyms
shanky
@shaanky
Mar 22 2016 07:10
@Moose1551 passed???
Zach
@Moose1551
Mar 22 2016 07:18
This message was deleted
CamperBot
@camperbot
Mar 22 2016 07:18
moose1551 sends brownie points to @shaanky :sparkles: :thumbsup: :sparkles:
:star: 154 | @shaanky | http://www.freecodecamp.com/shaanky
Zach
@Moose1551
Mar 22 2016 07:18
@shaanky , is there a shorter way?
shanky
@shaanky
Mar 22 2016 07:20
@Moose1551 i cant tell you coz i have not experiment yet with this. maybe you can try if you find any tell me too
Zach
@Moose1551
Mar 22 2016 07:22
For sure, friend. I'll play around with it.
Mohammed Shehab
@mshehab93
Mar 22 2016 07:28
I have a question: You'll need to remove all non-alphanumeric characters
if (strArray[i] === ?) {
        strArray[i].pop();
        }
what goes in the place of '?'
shanky
@shaanky
Mar 22 2016 07:31
@mshehab93 tell me the challange
Mohammed Shehab
@mshehab93
Mar 22 2016 07:32
@shaanky Check for Palindromes basic scripting
*frontend dev
I changed the string to all lowercase and now need to remove all nonalphanumeric characters
which I'm doing through the use of a for loop in which this 'if' statement is nested
shanky
@shaanky
Mar 22 2016 07:33
@mshehab93 yes you want to remove all the non alpha numeric ryt?
Mohammed Shehab
@mshehab93
Mar 22 2016 07:33
@shaanky yes
shanky
@shaanky
Mar 22 2016 07:35
@mshehab93 use the regular expression where you have to use .replace(here will be your regular expression)
Mohammed Shehab
@mshehab93
Mar 22 2016 07:37
@shaanky if I 'pop' them out and test for reverse will the strArray[i] be empty or will the characters all shift e.g. if a1 = 1; a2 = 2; a[3] = 3; and I pop out a2 will a2 then automatically be equal to 3?
shanky
@shaanky
Mar 22 2016 07:37
first thing will be convert to lowercase, second to replace non alphanumeric, third will be again split it and do reverse at the same time join it, at the last compare it
ravitej177
@removed~ravitej177
Mar 22 2016 07:41
Iterate over Arrays with map
how should i do dat
Mohammed Shehab
@mshehab93
Mar 22 2016 07:41
@shaanky thanks
CamperBot
@camperbot
Mar 22 2016 07:41
mshehab93 sends brownie points to @shaanky :sparkles: :thumbsup: :sparkles:
:star: 155 | @shaanky | http://www.freecodecamp.com/shaanky
ravitej177
@removed~ravitej177
Mar 22 2016 07:41
I'm getting the output but it is raising error
Use the map function to add 3 to every value in the variable oldArray, and save the results into variable newArray. oldArray should not change.
You should not change the original array.
You should add three to each value in the array.
You should be making use of the map method.
You should only modify the array with map.
shanky
@shaanky
Mar 22 2016 07:42
@ravitej177 tell me challnge
ravitej177
@removed~ravitej177
Mar 22 2016 07:42

var oldArray = [1,2,3,4,5];

// Only change code below this line.

var newArray = oldArray;

JScapin
@JScapin
Mar 22 2016 07:43
Hello everybody!
Does anyone of you could tell me a little track to put UpperCase first letter of each words of an array
Not the full solution but a track
i try lot of things but fail
asafusan
@asafusan
Mar 22 2016 07:44
@ravitej177 did you read the spec for map?
ravitej177
@removed~ravitej177
Mar 22 2016 07:44
Yes
i'm getting the solution like
[[1,3],[2,3],[3,3]..]
asafusan
@asafusan
Mar 22 2016 07:44
you want to add 3 to each element in an array?
ravitej177
@removed~ravitej177
Mar 22 2016 07:44
but its still shows the error for the first 2 cases
asafusan
@asafusan
Mar 22 2016 07:44
what's your code?
ravitej177
@removed~ravitej177
Mar 22 2016 07:45
wait
shanky
@shaanky
Mar 22 2016 07:45
@JScapin first thing you should do make them all to lowercase
JScapin
@JScapin
Mar 22 2016 07:46
@shaanky do i have to do this
why
just the first word has its first letter in upper
shanky
@shaanky
Mar 22 2016 07:48
@JScapin and at the same time split them, than take the length of the array where you stored the lowercase and splited arry
ravitej177
@removed~ravitej177
Mar 22 2016 07:48

var oldArray = [1,2,3,4,5];

// Only change code below this line.
var i=0;
oldArray.map(function(val){
oldArray[i]=[val,3];
i++;

return oldArray;
});
var newArray = oldArray;

this is my code
@asafusan
JScapin
@JScapin
Mar 22 2016 07:49
what is the second parameter"3"
shanky
@shaanky
Mar 22 2016 07:49
@JScapin because in the given example it is mentioned that only first letter must be capital not remaing one
asafusan
@asafusan
Mar 22 2016 07:49
A few comments:
shanky
@shaanky
Mar 22 2016 07:49
take for loop @JScapin
asafusan
@asafusan
Mar 22 2016 07:50
  1. map function returns the new array so you need to catch it, for example:
shanky
@shaanky
Mar 22 2016 07:50
 var arry = [];
      arry = str.toLowerCase().split(" ");   
  var upprcase = [];
  for(var i=0; i <arry.length; i++)
    {
       arry[i] = arry[i].charAt(0).toUpperCase() + arry[i].slice(1);
    }
  return arry.join(" ");
asafusan
@asafusan
Mar 22 2016 07:50
var newArray = oldArray.map(........)
ravitej177
@removed~ravitej177
Mar 22 2016 07:50
i need to store in the new array?
JScapin
@JScapin
Mar 22 2016 07:50
interestings comments @asafusan @shaanky
shanky
@shaanky
Mar 22 2016 07:50
@JScapin check my solution
JScapin
@JScapin
Mar 22 2016 07:50
i didnt think to map method, thanks
asafusan
@asafusan
Mar 22 2016 07:51
@ravitej177 2. map function has several params, first is the iterated element which you use, the second is index, so no need for var i = 0
JScapin
@JScapin
Mar 22 2016 07:51
@shaanky what is charAt in your code?
ravitej177
@removed~ravitej177
Mar 22 2016 07:51
so how can get the index
?
so in the function i can pass the params
JScapin
@JScapin
Mar 22 2016 07:52
@asafusan thanks for explainations
CamperBot
@camperbot
Mar 22 2016 07:52
jscapin sends brownie points to @asafusan :sparkles: :thumbsup: :sparkles:
:star: 12 | @asafusan | http://www.freecodecamp.com/asafusan
ravitej177
@removed~ravitej177
Mar 22 2016 07:52
like function(k,val)
?
asafusan
@asafusan
Mar 22 2016 07:52
  1. continued: var newArray = oldArray.map(function(el, index) {.......})
shanky
@shaanky
Mar 22 2016 07:52
charAt(0) means first character of every word
asafusan
@asafusan
Mar 22 2016 07:52
meant 2. continued
ravitej177
@removed~ravitej177
Mar 22 2016 07:52
ok Thanq ! @asafusan
JScapin
@JScapin
Mar 22 2016 07:52
its a global object propriety, isn'it
ravitej177
@removed~ravitej177
Mar 22 2016 07:52
will try this out and let u know
:D
asafusan
@asafusan
Mar 22 2016 07:53
@ravitej177 last thing: the first param is the iterated element so no need for index or to refer to oldArray inside the map function. the solution should look like this:
var newArray =- oldArray.map(function(el) { return el + 3 })
ravitej177
@removed~ravitej177
Mar 22 2016 07:54
so it is sum :worried:
asafusan
@asafusan
Mar 22 2016 07:54
there's an un-needed minus sign after the equal sign
shanky
@shaanky
Mar 22 2016 07:54
whenever we take array we can take this property whenever we need it, yes its global
ravitej177
@removed~ravitej177
Mar 22 2016 07:54
i thought i need to push the element to sub array
@asafusan thanks alot
CamperBot
@camperbot
Mar 22 2016 07:54
ravitej177 sends brownie points to @asafusan :sparkles: :thumbsup: :sparkles:
ravitej177
@removed~ravitej177
Mar 22 2016 07:54
:D
CamperBot
@camperbot
Mar 22 2016 07:54
:star: 13 | @asafusan | http://www.freecodecamp.com/asafusan
asafusan
@asafusan
Mar 22 2016 07:54
@ravitej177 mp
Markus Kiili
@Masd925
Mar 22 2016 07:55
@shaanky @JScapin Are you talking about .map() method?
JScapin
@JScapin
Mar 22 2016 07:55
@Masd925 yes
shanky
@shaanky
Mar 22 2016 07:55
nop
I am talking abt "Title Case a Sentence "
Markus Kiili
@Masd925
Mar 22 2016 07:56
@shaanky @JScapin It is not a property of global object. It is a method of Array.prototype object and all arrays inherit it from there.
JScapin
@JScapin
Mar 22 2016 07:57
@Masd925 I learn something today :)
Mohammedaadem As
@mohamma548
Mar 22 2016 07:57
guys i need help with this function

function lookUp(firstName, prop){
// Only change code below this line
if(contacts[firstName] == "firstName" && contactsprop =="prop"){
return "prop";

}
else if(contacts[firstName]!=="firstName")
{
return "No such contact";
}
else if(contactsprop!=="prop")
{
return "No such property";
}

// Only change code above this line
}

shanky
@shaanky
Mar 22 2016 07:58
that is why i written whenever we take array @Masd925
Markus Kiili
@Masd925
Mar 22 2016 07:58
@shaanky Yes.
shanky
@shaanky
Mar 22 2016 07:58
@Masd925 :smile:
asafusan
@asafusan
Mar 22 2016 07:59
@mohamma548 what are you trying to achieve? what is the error?
Mohammedaadem As
@mohamma548
Mar 22 2016 07:59
I couid not find contacts
@asafusan I could not find the real contacts
it just returns only no such contacts
asafusan
@asafusan
Mar 22 2016 08:00
well contacts is not defined anywhere in your function. I think they mean you need to work only with the function params. In this example firstName & prop
JScapin
@JScapin
Mar 22 2016 08:02

Why the "I" stay uppercase?
'''
function titleCase(str) {

str.toLowerCase();
var myArr = str.split(" ");

return myArr;

}

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

CamperBot
@camperbot
Mar 22 2016 08:02
:bulb: to format code use backticks! ``` more info
Mohammedaadem As
@mohamma548
Mar 22 2016 08:02
@asafusan but contacts are given as an array
Mark Dickinson
@monoposon
Mar 22 2016 08:02
@mohamma548 i am on the same one, and one problem i see is the contacts is an array not an object, it is an array of objects
arrays are like objects, but have properties of [0,1,2,3,4..... n] instead of objects which in this case have properties of {firstName, lastName, number, likes}
Michael Attia
@mikeattia
Mar 22 2016 08:05
Hey there guys
I am having a problem with Truncate a string lesson
my code works just fine in the console but it isn't in the website
shanky
@shaanky
Mar 22 2016 08:06
@JScapin take one empty array than in use like this myArray= str.toLowerCase();
Michael Attia
@mikeattia
Mar 22 2016 08:06
function truncateString(str, num) {
  // Clear out that junk in your trunk
  if (num <=3){
    var numb = str.slice(0, num);
    return numb+"... ";
  }else if (num <str.length){
    var nume = str.slice(0, num-3);
    return nume+"...";
  }else {

    return str;
  }
}


truncateString("Absolutely Longer", 2);
JScapin
@JScapin
Mar 22 2016 08:06
@JScapin I have to asign the reult of str.toLowerCase okok sorry
Markus Kiili
@Masd925
Mar 22 2016 08:06
@mohamma548 You should loop through contacts array with for loop or array iterator methods.
Nick Robson
@nickrobson
Mar 22 2016 08:06
@mikeattia Check which tests aren't passing. You probably don't want that space after the "..."
Mohammedaadem As
@mohamma548
Mar 22 2016 08:07
@Masd925 let me try it
Michael Attia
@mikeattia
Mar 22 2016 08:07
@nickrobson thank you so much ... I've been trying to look for the error for a while and missed that one :D
CamperBot
@camperbot
Mar 22 2016 08:07
mikeattia sends brownie points to @nickrobson :sparkles: :thumbsup: :sparkles:
:star: 422 | @nickrobson | http://www.freecodecamp.com/nickrobson
Mark Dickinson
@monoposon
Mar 22 2016 08:07
the thing i am getting stuck on is how do you find the length of the object inside of the array. beacause for (j = 0; j < contacts[i][j].length; j++)
isnt working
Michael Attia
@mikeattia
Mar 22 2016 08:08
Debugging is harder than writing code
Nick Robson
@nickrobson
Mar 22 2016 08:13
@monoposon You're probably wanting to use contacts[i].length
Mark Dickinson
@monoposon
Mar 22 2016 08:14
@nickrobson yeah... now that you say that, that makes alot more sense...
Markus Kiili
@Masd925
Mar 22 2016 08:14
@monoposon Inside your loop contacts[i] is one object. You should use equality operator and .hasOwnProperty() instead of looping, to check whether the firstname matches and whether the object has the property prop.
@monoposon You should put two nested if clauses inside your contact loop.
Mark Dickinson
@monoposon
Mar 22 2016 08:15
i havent gone over hasOwnProperty() yet. and i do have two nested if clauses
Markus Kiili
@Masd925
Mar 22 2016 08:16
@monoposon You need hasOwnProperty on the second if.
Mark Dickinson
@monoposon
Mar 22 2016 08:17
function lookUp(firstName, prop){
// Only change code below this line
  for (i = 0; i < contacts.length; i++ ) {
    if (firstName == contacts[i].firstName){
      for (j = 0; j < contacts[i].length; j++){
        if(prop == contacts[i][j]){
          return contacts[i][j];
        }
        else{
          return "No such property";
        }
      }
    }
    else{
      return "No such contact";
    }
  }
// Only change code above this line
}
i nested the ifs in there
i don't know what hasOwnProperty is. haven't covered that yet
Markus Kiili
@Masd925
Mar 22 2016 08:18
@monoposon Only one loop through the contacts is needed.
var obj = {clothes : "pants"};
obj.hasOwnProperty("age");      // false
obj.hasOwnProperty("clothes");  // true
Nick Robson
@nickrobson
Mar 22 2016 08:19
@monoposon hasOwnProperty checks if an Object has a property with a given name.
Mohammedaadem As
@mohamma548
Mar 22 2016 08:19
@Masd925 @monoposon can you check this

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

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

}

}

// Only change code above this line
}

Mark Dickinson
@monoposon
Mar 22 2016 08:20
im looping the the contacts once then looping through the contact itself to find the property, apparently like the hasOwnProperty() does lol only unsuccesfully lol
Markus Kiili
@Masd925
Mar 22 2016 08:20
@mohamma548 No need for hasOwnProperty on the first if. Just use equality operator to check if the firstName property value of the contact equals the firstName parameter.
Charu Agarwal
@freebird1195
Mar 22 2016 08:21
Hey PPl
How is coding coming along?
Markus Kiili
@Masd925
Mar 22 2016 08:21
@mohamma548 The second if should check if the contact has the property key prop.
Mohammedaadem As
@mohamma548
Mar 22 2016 08:22
@Masd925 do you mean the second or third
Markus Kiili
@Masd925
Mar 22 2016 08:23
@monoposon I am explaining the simplest way of doing just two nested if clauses.
Li
@NLStom
Mar 22 2016 08:24
Hi guys
can anyone explain me
why my code is not working...

function destroyer(arr) {
// Remove all the values

var filtered;
for(var i=1;i<arguments.length;i++){
filtered=arguments0.filter(function(a){return a!==arguments[i];});
}

return filtered;

}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);

question "seek and destroy"
asafusan
@asafusan
Mar 22 2016 08:25
@NLStom does destroyer function get more arguments beside arr?
Mark Dickinson
@monoposon
Mar 22 2016 08:25
@Masd925 no i get what your saying, i changed it and got a little closer to correct. 2 out of 5 checks, ill dig a little deeper and see if a can get the others
Markus Kiili
@Masd925
Mar 22 2016 08:27
@NLStom The filter callback function has its own arguments object. return a!==arguments[i] is not accessing destroyers arguments.
asafusan
@asafusan
Mar 22 2016 08:27
@NLStom also you are looping through 0 to arguments.length, and in each iteration you are running over filtered variable
Joshua
@joshuaken
Mar 22 2016 08:27
hello
what's wrong with my code

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

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

// Only change code above this line

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

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

Instructions
Modify the function abTest so that if a or b are less than 0 the function will immediately exit with a value of undefined
Li
@NLStom
Mar 22 2016 08:29
@Masd925 that's what I think too...
Markus Kiili
@Masd925
Mar 22 2016 08:30
@NLStom You can store destroyers arguments on a variable or pass it into filter callback as value of this. You should also filter only once and put the loop or indexOf inside the callback.
Li
@NLStom
Mar 22 2016 08:31
@asafusan I don't get more arguments beside arr..
ravitej177
@removed~ravitej177
Mar 22 2016 08:31
@joshuaken remove quotes for undefined
Achilleas Papakonstantinou
@AchiPapakon
Mar 22 2016 08:31
function permAlone(str) { // eg. str = 'aab'
  var arrStr = str.split(''); // eg. arrStr = ['a', 'a', 'b'] 
  console.log('arrStr: ' + arrStr);
  // I'll create the array of the possible permutations.
  var g2 = generate(arrStr, arrStr.length);
  console.log(g2);


  function generate(arr, n) {
    if (n === 1) {
      console.log(arr);
      return 'arr'; // Question: Why does it return undefined?!
    } else {
      for (var i = 0; i < n; i++) {
        generate(arr, n - 1);
        if (n % 2 === 0) {
          swap(i, n-1, arr);
        } else {
          swap(0, n-1, arr);
        }
      }
    }
  }

  function swap(a, b, ar) {
    var temp = ar[b];
    ar[b] = ar[a];
    ar[a] = temp;
  }

  var filtered = arrStr.filter(function(val) {  // eg. ['aab', 'aab', 'aba', 'aba', 'baa', 'baa']
    //var splitted = val.split('');      // eg. 'aab' -> [ "a", "a", "b" ] 
    //console.log(splitted);
    for (var i = 1; i < val.length; i++) {
      //console.log(splitted[i] + splitted[i-1] + ': ' + (splitted[i] === splitted[i-1]));
      if(val[i] === val[i-1]) {
        return false;
      }
    }
    return true;
  });

  console.log(filtered.length);
  //return str;
}

permAlone('aab');
Hi, I have the code above. Inside function generate(), why can't I return an array?
Joshua
@joshuaken
Mar 22 2016 08:32
@ravitej177 thanks >.<
CamperBot
@camperbot
Mar 22 2016 08:32
joshuaken sends brownie points to @ravitej177 :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for ravitej177
Achilleas Papakonstantinou
@AchiPapakon
Mar 22 2016 08:32
Markus Kiili
@Masd925
Mar 22 2016 08:32
@AchiPapakon You code return 'arr'; returns a string 'arr'.
Achilleas Papakonstantinou
@AchiPapakon
Mar 22 2016 08:33
@Masd925 That was a test and I forgot it
@Masd925 even with a string, it still gets undefined
Li
@NLStom
Mar 22 2016 08:34
@Masd925 thanks
CamperBot
@camperbot
Mar 22 2016 08:34
nlstom sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1209 | @masd925 | http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Mar 22 2016 08:34
@AchiPapakon There is no return on the else block there.
Mohammedaadem As
@mohamma548
Mar 22 2016 08:34
@Masd925 i get stuck here

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

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

}

}

// Only change code above this line
}

Markus Kiili
@Masd925
Mar 22 2016 08:35
@mohamma548 Just compare contacts[i].firstName and firstName.
Achilleas Papakonstantinou
@AchiPapakon
Mar 22 2016 08:35
@Masd925 that's because it's a recursive function that reduces n to 1.
The code works, it even prints console.log(arr); correctly, I just can't return the array.
Markus Kiili
@Masd925
Mar 22 2016 08:35
@mohamma548 You don't need any elses. Just two nested if clauses.
ravitej177
@removed~ravitej177
Mar 22 2016 08:37

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

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

@mohamma548

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

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

Markus Kiili
@Masd925
Mar 22 2016 08:38
@mohamma548 You are returning the contact object contacts[i] there.
ravitej177
@removed~ravitej177
Mar 22 2016 08:40
how to send code format here
code
Markus Kiili
@Masd925
Mar 22 2016 08:40
wiki format
CamperBot
@camperbot
Mar 22 2016 08:40

: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

ravitej177
@removed~ravitej177
Mar 22 2016 08:41

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

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

```

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

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

sorry
i cant get it
shanky
@shaanky
Mar 22 2016 08:42
Hello guys i m stuck with challange -"Return Largest Numbers in Arrays"
can anyone help me here is my code...
Reza Farshbaf
@grfarshbaf
Mar 22 2016 08:43
Dudes! I don't understand the Condense method!
shanky
@shaanky
Mar 22 2016 08:43
function largestOfFour(arr) { 
  var arry = [];

  for(var i=0; i<arr.length; i++)
    {
      for(var j=i; j<arr.length; j++)
        {
           if(arr[i] < arr[j])
             {
               arry = arr[j];
             }
          else
            {
              arry = arr[j];
            }          
        }
    }
 return arry;
}


largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Reza Farshbaf
@grfarshbaf
Mar 22 2016 08:44
The description is vague
Markus Kiili
@Masd925
Mar 22 2016 08:45
@grfarshbaf Condense?
Reza Farshbaf
@grfarshbaf
Mar 22 2016 08:45
Yes
shanky
@shaanky
Mar 22 2016 08:45
@grfarshbaf its just a addition of 2 numbers previousone and currentone
ajaybti
@ajaybti
Mar 22 2016 08:45
any body can explain what is local and global variable?
Andrews
@frempongandrews
Mar 22 2016 08:45
guys have a little issue. When I put the else statement(which I have now commented out) it does not run the loop
ho w do you embed images here?
ravitej177
@removed~ravitej177
Mar 22 2016 08:46
@ajaybti local variable has the scope with in the function, where global variable has global scope.
  • u can use global variable anywhere in your javascript
shanky
@shaanky
Mar 22 2016 08:47
like this ---[1,2,3,4] --- in this previous value is - 1 and current value will be -2 than we do the addition of these numbers according to example total will be 3 than new arry will be like this [3,3,4] than next addition of 3 and 3 arry[6,4] than addition of 6 and 4 which is 10 ,
ravitej177
@removed~ravitej177
Mar 22 2016 08:47
var i=10; //global
function myfunction()
{
}
@ravitej177
var i=10; //global
function myfunction()
{
a=0;//local
}
@ajaybti
asafusan
@asafusan
Mar 22 2016 08:49
@ravitej177 actually your a variable is global since you didn't initiate it with the var statement
Andrews
@frempongandrews
Mar 22 2016 08:50
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUp(firstName, prop){
// Only change code below this line
   for( i = 0; i < contacts.length; i++){
     if(contacts[i].firstName === firstName &&
       contacts[i].hasOwnProperty(prop)){
       return contacts[i][prop];
     }

    /* else if(contacts[i].firstName != firstName){
       return "No such contact";
     }

    else if (contacts[i][prop] === undefined){
       return "No such property";
     } */
   }
// Only change code above this line
}

// Change these values to test your function
lookUp("Harry", "lastName");
shanky
@shaanky
Mar 22 2016 08:50
This message was deleted
asafusan
@asafusan
Mar 22 2016 08:54
@frempongandrews the loop probably works, but if the if condition is always falsy then it will not return any value
shanky
@shaanky
Mar 22 2016 08:55


vara=11;       //it is global variable you can use this in function below
function myfunction()
{
   var b = 22;   //this is local variable

    var globalVariableValue = a;   /// this will give you global variable value

}

// if you try to get the value of local variable here like below

var localVariableValue = b;   ///this will give you error becuase its scope is limited to that function only
@ajaybti check above explaination
Andrews
@frempongandrews
Mar 22 2016 08:58
@asafusan yes it does work when the else statements are commented out. Can't understand why
asafusan
@asafusan
Mar 22 2016 09:02
@frempongandrews your code works. When testing it it returns "Potter"
Mohammedaadem As
@mohamma548
Mar 22 2016 09:07

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

    }        
      return "No such property";  


  }    

}
return "No such contact";

// Only change code above this line
}

J Player
@Heyjp
Mar 22 2016 09:10
@mohamma548 you are missing an else after your second if
Akindolani Ayoola
@dolani
Mar 22 2016 09:13
good day, please what am i doing wrong?
Encode the following sequence, separated by spaces:
backslash tab tab carriage-return new-line and assign it to myStr
ravitej177
@removed~ravitej177
Mar 22 2016 09:14
ur code? @dolani
Akindolani Ayoola
@dolani
Mar 22 2016 09:14
var myStr = "\ \r \n \t";
ravitej177
@removed~ravitej177
Mar 22 2016 09:14
\ \t \t \r \n
sry \ \t \t \r \n
rphares
@rphares
Mar 22 2016 09:15
heh, won't work if the code isn't formatted,
ravitej177
@removed~ravitej177
Mar 22 2016 09:15
haha
rphares
@rphares
Mar 22 2016 09:15
you both typed \\ for backslash, that part is okay :)
ravitej177
@removed~ravitej177
Mar 22 2016 09:15
how to send in code format
rphares
@rphares
Mar 22 2016 09:15
explain format
CamperBot
@camperbot
Mar 22 2016 09:15

: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

ravitej177
@removed~ravitej177
Mar 22 2016 09:16
\\ \t \t \r \n
assign it to mystr
@dolani
hope this is helpful
Akindolani Ayoola
@dolani
Mar 22 2016 09:16
@ravitej177 thanks...but why double \t \t?
CamperBot
@camperbot
Mar 22 2016 09:16
dolani sends brownie points to @ravitej177 :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for ravitej177
Akindolani Ayoola
@dolani
Mar 22 2016 09:17
@ravitej177 thanks
CamperBot
@camperbot
Mar 22 2016 09:17
dolani sends brownie points to @ravitej177 :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for ravitej177
ravitej177
@removed~ravitej177
Mar 22 2016 09:17
the question itself has double tabs dats wht @dolani
Akindolani Ayoola
@dolani
Mar 22 2016 09:18
@ravitej177 ohh.. i saw it
@ravitej177 thanks
CamperBot
@camperbot
Mar 22 2016 09:18
dolani sends brownie points to @ravitej177 :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for ravitej177
Akindolani Ayoola
@dolani
Mar 22 2016 09:18
@ravitej177 wait, why is camperbot rejecting your points
ravitej177
@removed~ravitej177
Mar 22 2016 09:18
I dont know
:/
rphares
@rphares
Mar 22 2016 09:19
oh
@ravitej177 , try logging out of fcc
and log back in using github
if you log in other ways, it 'cannot find receiver'
ravitej177
@removed~ravitej177
Mar 22 2016 09:19
i Have logged in using github
rphares
@rphares
Mar 22 2016 09:19
thats usually the culprit
not to gitter, to fcc?
ravitej177
@removed~ravitej177
Mar 22 2016 09:20
oh got it
thanq :D
rphares
@rphares
Mar 22 2016 09:20
sure thing~
ravitej177
@removed~ravitej177
Mar 22 2016 09:20
@rphares
thanks @rphares
CamperBot
@camperbot
Mar 22 2016 09:20
ravitej177 sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 3454 | @rphares | http://www.freecodecamp.com/rphares
Greg
@madcoyote
Mar 22 2016 09:30
This 'using objects for lookups' exercise is irritating me anyone mind taking a peek at my code?
ravitej177
@removed~ravitej177
Mar 22 2016 09:30
paste your code @madcoyote
asafusan
@asafusan
Mar 22 2016 09:30
go ahead
Greg
@madcoyote
Mar 22 2016 09:30

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

// Only change code below this line
var Lookup = {
"alpha": "Adams",
"bravo": "Boston",
"charlie": "Chicago",
"delta": "Denver",
"echo": "Easy",
"foxtrot": "Frank"
};

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

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

rphares
@rphares
Mar 22 2016 09:31
testing-- tax, @ravitej177 ~
CamperBot
@camperbot
Mar 22 2016 09:31
rphares sends brownie points to @ravitej177 :sparkles: :thumbsup: :sparkles:
:star: 251 | @ravitej177 | http://www.freecodecamp.com/ravitej177
ravitej177
@removed~ravitej177
Mar 22 2016 09:31
Haha it worked thanks @rphares
CamperBot
@camperbot
Mar 22 2016 09:31
ravitej177 sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:warning: ravitej177 already gave rphares points
asafusan
@asafusan
Mar 22 2016 09:31
@madcoyote what should this function do?
rphares
@rphares
Mar 22 2016 09:32
@madcoyote , you have a good start, you have converted it to a table, but
you still need the part that looks up and returns what is associated with val
Greg
@madcoyote
Mar 22 2016 09:32
I converted switch statements into a lookup table...
ok
rphares
@rphares
Mar 22 2016 09:33
(also, lookup, not Lookup:blush: )
Greg
@madcoyote
Mar 22 2016 09:34
so I'm missing a part up top near the var lookup part then?
rphares
@rphares
Mar 22 2016 09:34
no--
just a typo there, the l should be lowercase,
the part you are missing is right after the table
lets checkout the example--
their table is called var alpha and they want what is associated with 2, so they write alpha[2]
your table is called var lookup and you want whats associated with val, so you can write...?
(there is one step after that... I'm asking before the next hint :blush:)
Greg
@madcoyote
Mar 22 2016 09:37
(I appreciate the help!!)
rphares
@rphares
Mar 22 2016 09:37
anytime! the last step, once you know how to write the part that would give you that,
cannelflow
@cannelflow
Mar 22 2016 09:38
@rphares looking busy
Greg
@madcoyote
Mar 22 2016 09:38
lookup[val]
rphares
@rphares
Mar 22 2016 09:38
yay!
so, you will need to store that in what you will return...
otherwise it'll just sit there and not do you any good :)
Greg
@madcoyote
Mar 22 2016 09:39
ok great!
rphares
@rphares
Mar 22 2016 09:39
@cannelflow , i know, i know... i really need to go to bed-- wanna take over? good ol' objects for lookup, and @madcoyote nearly has it :blush:
Oh, sweet! Congrats and happy coding~
Night, all!
Greg
@madcoyote
Mar 22 2016 09:39
thanks agaon
again
rphares
@rphares
Mar 22 2016 09:39
Anytime~
cannelflow
@cannelflow
Mar 22 2016 09:41
@rphares sure
Mooli
@Mooli88
Mar 22 2016 09:48
why its impossible to return arry.push(foo) or array.push(foo).join("") but it is possible with concat() ?
Brendan Kinahan
@BKinahan
Mar 22 2016 09:48
@Mooli88 I believe .push() returns the new length of the array, rather than the new array.
Mooli
@Mooli88
Mar 22 2016 09:49
@BKinahan make sens .. thanks
CamperBot
@camperbot
Mar 22 2016 09:49
mooli88 sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star: 1127 | @bkinahan | http://www.freecodecamp.com/bkinahan
Brendan Kinahan
@BKinahan
Mar 22 2016 09:50
@madcoyote did you figure out your way to where @rphares was guiding you? :)
Reza Farshbaf
@grfarshbaf
Mar 22 2016 09:57
Dudes, How can I shorten this code?
function reverseString(str) {
var strArr = str.split("");
var strArrReversed = strArr.reverse();
var strReversed = strArrReversed.join("");
return strReversed;
}
ravitej177
@removed~ravitej177
Mar 22 2016 09:57
str.split('').reverse().join('');
it works
:P
@grfarshbaf
Reza Farshbaf
@grfarshbaf
Mar 22 2016 09:58
So we can chain the methods
ravitej177
@removed~ravitej177
Mar 22 2016 09:58
yes ofcourse
Reza Farshbaf
@grfarshbaf
Mar 22 2016 09:58
Thanks!
Brendan Kinahan
@BKinahan
Mar 22 2016 09:59
@grfarshbaf don't forget to return at the start of the line, of course :)
Markus Kiili
@Masd925
Mar 22 2016 10:00
@Mooli88 Mutator methods like .push() mutate the existing array, and they generally return something else than the mutated array.
Francis
@Francis-p
Mar 22 2016 10:01
need help with random quote machine
ravitej177
@removed~ravitej177
Mar 22 2016 10:05
yes paste your code
i am trying to link my js
not using API
Mooli
@Mooli88
Mar 22 2016 10:07
i hope its ok to post this . really awesome website www.codewars.com/r/iQcSgg
Francis
@Francis-p
Mar 22 2016 10:07
@Mooli88 which skill did you use to sign up with?
KortsF
@KortsF
Mar 22 2016 10:07

I'm trying to work out this challenge, so please do not give me the solution.

What I want to know is why the following code, when tested in the Chrome console would give "Uncaught ReferenceError: arr is not defined", and the details say "(anonymous funtion"). As far as I can tell, the function is defined correctly, and the call to it wiht the two arguments should work?

arr.sort(function(a, b){
    return a - b;
    });

function where(arr, num) {

    for(i=0; i < arr.length; i++) {    
        if(arr[i] > num && num < arr[i+1]) {
            return arr.indexOf(i+1);
        }
    }
}  
where([5, 3, 20], 19);
ravitej177
@removed~ravitej177
Mar 22 2016 10:08
the nextquote function not invoking i guess? @Francis-p
Mooli
@Mooli88
Mar 22 2016 10:08
Js
Francis
@Francis-p
Mar 22 2016 10:08
@ravitej177 how do i go about it?
Markus Kiili
@Masd925
Mar 22 2016 10:08
@KortsF Code should be inside the function.
kirbyedy
@kirbyedy
Mar 22 2016 10:09
@Francis-p you need to use the random() method
Francis
@Francis-p
Mar 22 2016 10:09
@kirbyedy i cannot use call one after another?
KortsF
@KortsF
Mar 22 2016 10:09
@Masd925 Which code? The call to the function?
Markus Kiili
@Masd925
Mar 22 2016 10:10
@KortsF arr.sort...
kirbyedy
@kirbyedy
Mar 22 2016 10:10
well maybe you can, but then all the time you will have the same list starting from the first quote until the last one
and the task says random...
so I am guessing it should be a random quote :D
KortsF
@KortsF
Mar 22 2016 10:11
@Masd925 That's what I though initially, but no, I get the same error
Francis
@Francis-p
Mar 22 2016 10:11
@kirbyedy as a user you won’t know my sequence :smile:
but no harm for me to change it
ravitej177
@removed~ravitej177
Mar 22 2016 10:11
@Francis-p you haven't called ur function in the button action
Francis
@Francis-p
Mar 22 2016 10:11
like you say ten challenge is specifically asking for random
Mohammed Shehab
@mshehab93
Mar 22 2016 10:11
quick ques is it possible to make an empty multidimensional array?
I think when I tried it before I got an error
Y4T9Code
@Y4T9Code
Mar 22 2016 10:12
function orbitalPeriod(arr) {
  var GM = 398600.4418;
  var earthRadius = 6367.4447;
  arr=arr.map(function(num){
    this.avgAlt=2*(22/7)*(Math.sqrt((Math.pow(earthRadius,3))/GM));
  });
  return arr;
}

orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]);
ravitej177
@removed~ravitej177
Mar 22 2016 10:12
@mshehab93 example
?
Y4T9Code
@Y4T9Code
Mar 22 2016 10:12
can someone tell me whats wrong with this?
Mohammed Shehab
@mshehab93
Mar 22 2016 10:12
like var array = [][];
Brendan Kinahan
@BKinahan
Mar 22 2016 10:12
@Dukbcaaj lol 22/7
Mohammed Shehab
@mshehab93
Mar 22 2016 10:12
would that be valid?
Y4T9Code
@Y4T9Code
Mar 22 2016 10:13
I need pi @BKinahan
Brendan Kinahan
@BKinahan
Mar 22 2016 10:13
@Dukbcaaj Math.PI
Y4T9Code
@Y4T9Code
Mar 22 2016 10:13
ohhhhhh
ravitej177
@removed~ravitej177
Mar 22 2016 10:13
@mshehab93 I dont think dats possible
but u can declare like this
Markus Kiili
@Masd925
Mar 22 2016 10:13
@mshehab93 You can do: var arr = [[],[],[]];
Y4T9Code
@Y4T9Code
Mar 22 2016 10:14
no luck :( @BKinahan
function orbitalPeriod(arr) {
  var GM = 398600.4418;
  var earthRadius = 6367.4447;
  arr=arr.map(function(num){
    this.avgAlt=2*Math.PI*(Math.sqrt((Math.pow(earthRadius,3))/GM));
  });
  return arr;
}

orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]);
Brendan Kinahan
@BKinahan
Mar 22 2016 10:14
@Dukbcaaj also you're setting avgAlt to the result of a calculation, but that's a constant given to you. You want to set orbital period, and it depends on earthRadius PLUS avgAlt
ravitej177
@removed~ravitej177
Mar 22 2016 10:14
@mshehab93 var arr = [];
arr0 = [];
arr0 = [];
arr00 = "3 dimentional array"
var arr = [];
arr[0] = [];
arr[0][0] = [];
arr[0][0][0] = "3 dimentional array"
Francis
@Francis-p
Mar 22 2016 10:14
@kirbyedy yup
Mohammed Shehab
@mshehab93
Mar 22 2016 10:14
@Masd925 thanks
CamperBot
@camperbot
Mar 22 2016 10:14
mshehab93 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1210 | @masd925 | http://www.freecodecamp.com/masd925
Mohammed Shehab
@mshehab93
Mar 22 2016 10:14
@ravitej177 thanks
Francis
@Francis-p
Mar 22 2016 10:14
no prob with random
Mohammed Shehab
@mshehab93
Mar 22 2016 10:15
@ravitej177 I think then when the dimension of the multidimensional array is uncertain I would have to use a for loop to intialize the empty array
Y4T9Code
@Y4T9Code
Mar 22 2016 10:15
it does @BKinahan ?
Francis
@Francis-p
Mar 22 2016 10:15
@ravitej177 call which function?
Brendan Kinahan
@BKinahan
Mar 22 2016 10:15
@Dukbcaaj earthRadius is the distance from the center of the earth to the surface, and the altitude is the distance above the surface, so the two added together results in the (simplified) semi-major axis of the orbit, which determines the orbital period
Y4T9Code
@Y4T9Code
Mar 22 2016 10:15
ahhhh
thanks @BKinahan :)
CamperBot
@camperbot
Mar 22 2016 10:15
dukbcaaj sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star: 1128 | @bkinahan | http://www.freecodecamp.com/bkinahan
Francis
@Francis-p
Mar 22 2016 10:16
@kirbyedy but i think the main problem is for me to display the js out
KortsF
@KortsF
Mar 22 2016 10:16
Can anybody else please chime in?
Why the following code, when tested in the Chrome console would give "Uncaught ReferenceError: arr is not defined", and the details say "(anonymous function")??
function where(arr, num) {

    arr.sort(function(a, b){
    return a - b;
    });  

    for(i=0; i < arr.length; i++) {    
        if(arr[i] > num && num < arr[i+1]) {
            return arr.indexOf(i+1);
        }
    }
}  


where([5, 3 , 20], 19);
kirbyedy
@kirbyedy
Mar 22 2016 10:16
@Francis-p no worries, we are here to help
Y4T9Code
@Y4T9Code
Mar 22 2016 10:16
@BKinahan still didnt work
function orbitalPeriod(arr) {
  var GM = 398600.4418;
  var earthRadius = 6367.4447;
  arr=arr.map(function(num){
    var alt=this.avgAlt;
    this.avgAlt=2*Math.PI*(Math.sqrt((Math.pow(earthRadius+alt,3))/GM));
  });
  return arr;
}

orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]);
ravitej177
@removed~ravitej177
Mar 22 2016 10:17
@mshehab93 can u explain the case so that it will be helpful
KortsF
@KortsF
Mar 22 2016 10:17
Please don't give me the solution to the challenge, I'm just trying to understand why I'm getting an error
Brendan Kinahan
@BKinahan
Mar 22 2016 10:17
@KortsF is that your complete code? I can run it on repl.it with no errors, but it returns nothing
KortsF
@KortsF
Mar 22 2016 10:19
@BKinahan Yes, I'm running it between script tags inan html document. I can understand that it doesn't return anything if my function is wrong, but why would it say "arr is not defined"?
Brendan Kinahan
@BKinahan
Mar 22 2016 10:19
@Dukbcaaj that is not a correct implementation of map().
Francis
@Francis-p
Mar 22 2016 10:19
@KortsF maybe trying closing your app and start again?
Brendan Kinahan
@BKinahan
Mar 22 2016 10:19
@KortsF is it possible you have more script somewhere else?
Y4T9Code
@Y4T9Code
Mar 22 2016 10:20
whyyyy @BKinahan :/
Brendan Kinahan
@BKinahan
Mar 22 2016 10:21
@Dukbcaaj firstly, the function within map() should return something to replace the current element it is operating on.
Y4T9Code
@Y4T9Code
Mar 22 2016 10:22
return this.avgAlt;
?
the doer
@ewathedoer
Mar 22 2016 10:22

I try to understand the way replace works, do I get it right that this is the way to replace all non-alphanumerical characters from a string?

var newStr = str.replace(/\W/g, " “)

I found it on stack but I am not sure how it really works, especially the part in brackets, can anybody explain me W and /\ logic?

KortsF
@KortsF
Mar 22 2016 10:22
@BKinahan Ok, I noticed I had a console.log("test") line at the top. I commented it out
and the error is gone. But why?? the arr argument should have nothing to do with this line of code, or should it?
Brendan Kinahan
@BKinahan
Mar 22 2016 10:22
@KortsF it shouldn't at all :P Impossible to know without seeing the full code.
the doer
@ewathedoer
Mar 22 2016 10:22
And what if I want to remove the non-alphanumerical?
Brendan Kinahan
@BKinahan
Mar 22 2016 10:23
@ewathedoer those quotes look funky, and there is a space between them. Do you want to remove characters, or replace them with spaces?
KortsF
@KortsF
Mar 22 2016 10:23
@BKinahan Here it is:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<!-- Ejecutar en Chrome: CTRL ALT P y abrir consola CTRL SHIFT J -->

<script>

// Pegar aquí codigo JS

//console.log("probando");

//var arr = [5, 3 , 20];
//var num = 19;



function where(arr, num) {

    arr.sort(function(a, b){
    return a - b;
    });  

    for(i=0; i < arr.length; i++) {    
        if(arr[i] > num && num < arr[i+1]) {
            return arr.indexOf(i+1);
        }
    }
}  


where([5, 3 , 20], 19);







</script>
</head>

<body>

</body>

</html>
the doer
@ewathedoer
Mar 22 2016 10:24
I want to remove all non-alphanumericals from a string
Mooli
@Mooli88
Mar 22 2016 10:24
hi guys, what dose n mean in js ? i see (n) a lot but i've no idea what it is
Y4T9Code
@Y4T9Code
Mar 22 2016 10:24
@BKinahan
ravitej177
@removed~ravitej177
Mar 22 2016 10:24
@ewathedoer i even got struck
i just found that we should replace underscore
```js
function palindrome(str) {
  str=str.replace(/\W+/g, '');
  str=str.replace('_','')
  str=str.toLowerCase();
  tmp=str.split('').reverse().join('');
  return str==tmp;
}



palindrome("0_0 (: /-\ :) 0-0");
here is the code @ewathedoer
hope this helps
Brendan Kinahan
@BKinahan
Mar 22 2016 10:25
@KortsF no errors here, even when uncommenting code lines
the doer
@ewathedoer
Mar 22 2016 10:25
@ravitej177 but how replace works? I wanna understand it
negyvenketto
@negyvenketto
Mar 22 2016 10:26
@Mooli88 (n) looks like a variable of a function. can you show me an example?
Mooli
@Mooli88
Mar 22 2016 10:26
@ravitej177
function palindrome(str) {
  // Good luck!

  str = str.replace(/[^a-z0-9]/ig,'').toLowerCase();
  return str === str.split('').reverse().join('');
}



palindrome("0_0 (: /-\ :) 0-0");
Brendan Kinahan
@BKinahan
Mar 22 2016 10:26
@Dukbcaaj that would replace each object with whatever the value of this.avgAlt is. Is that what you want?
KortsF
@KortsF
Mar 22 2016 10:26
@BKinahan Weird. Would the code editor have anything to do? I'm using Brackets. Other than that, is there anything I could do to troubleshoot this?
Jiimms
@jiimms
Mar 22 2016 10:27
@ewathedoer between forward slashes are regex (regular expression) backslash W (\W) stands for alll non Alphanumeric. g stands for global. so you are replacing all non alphanumeric
Mooli
@Mooli88
Mar 22 2016 10:27
@negyvenketto not at the moment :/ i think its mean number
Markus Kiili
@Masd925
Mar 22 2016 10:27
@KortsF I don't get any error on browser console with that HTML.
the doer
@ewathedoer
Mar 22 2016 10:28
@jiimms do you need some plus sign after W? and what does it give?
Jiimms
@jiimms
Mar 22 2016 10:28
@ewathedoer ...to continue.. you are replacing all alphanumeric with "" that is nothing. if you had written "a". all alpha numeric would have been replaced with "a"
negyvenketto
@negyvenketto
Mar 22 2016 10:28
@Mooli88 it might. unfortunately i don't remember seeing a lot of n. maybe someone comes along who does...
Jiimms
@jiimms
Mar 22 2016 10:29
plus sign means one or more instance of W.
the doer
@ewathedoer
Mar 22 2016 10:29
thanks @jiimms
CamperBot
@camperbot
Mar 22 2016 10:29
ewathedoer sends brownie points to @jiimms :sparkles: :thumbsup: :sparkles:
ravitej177
@removed~ravitej177
Mar 22 2016 10:29
@jiimms why dont it replace underscore
?
CamperBot
@camperbot
Mar 22 2016 10:29
:star: 239 | @jiimms | http://www.freecodecamp.com/jiimms
Mooli
@Mooli88
Mar 22 2016 10:29
@negyvenketto Imagine there's a big cube consisting of n^3 small cubes. Calculate, how many small cubes are not visible from outside.
Jiimms
@jiimms
Mar 22 2016 10:30
@ravitej177 underscore is not included in alphanumeric. you have to mention it separately like /W_
ravitej177
@removed~ravitej177
Mar 22 2016 10:30
oh thanks @jiimms
CamperBot
@camperbot
Mar 22 2016 10:30
ravitej177 sends brownie points to @jiimms :sparkles: :thumbsup: :sparkles:
:star: 240 | @jiimms | http://www.freecodecamp.com/jiimms
KortsF
@KortsF
Mar 22 2016 10:30
@Masd925 @BKinahan Actually, I retried, and the error doesn't show up again, regardless of the state of the console.log line, as expected.
Come to think of it, I sometimes get error messages when trying to save documents in Brackets. Maybe I should re-install, or switch to another editor.
Which would you guys recommend? Sublime Text, other?
negyvenketto
@negyvenketto
Mar 22 2016 10:30
@Mooli88 oh, i see. yes, in that case n means a natural number
Mooli
@Mooli88
Mar 22 2016 10:31
and natural number mean 1 ,2 ,3 i guess ?
the doer
@ewathedoer
Mar 22 2016 10:31

@jiimms can I add it (underscore replacement) here

newStr = str.replace(/\W+/g, "”);

and how should it look like then? or is there a need for another code line, I don’t want to duplicate the code if it’s not needed

negyvenketto
@negyvenketto
Mar 22 2016 10:32
@Mooli88 some mathematicians also include zero, but yes
Brendan Kinahan
@BKinahan
Mar 22 2016 10:32
@KortsF I use Atom, sometimes SublimeText
Mooli
@Mooli88
Mar 22 2016 10:32
@negyvenketto cool thanks
CamperBot
@camperbot
Mar 22 2016 10:32
mooli88 sends brownie points to @negyvenketto :sparkles: :thumbsup: :sparkles:
:star: 314 | @negyvenketto | http://www.freecodecamp.com/negyvenketto
negyvenketto
@negyvenketto
Mar 22 2016 10:32
@Mooli88 yw
KortsF
@KortsF
Mar 22 2016 10:33
@BKinahan I'll give Atom a go, thanks!
CamperBot
@camperbot
Mar 22 2016 10:33
kortsf sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star: 1129 | @bkinahan | http://www.freecodecamp.com/bkinahan
Reza Farshbaf
@grfarshbaf
Mar 22 2016 10:33
Dudes, how do you paste the code here?!?
KortsF
@KortsF
Mar 22 2016 10:33
@Masd925 Thanks
CamperBot
@camperbot
Mar 22 2016 10:33
kortsf sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1211 | @masd925 | http://www.freecodecamp.com/masd925
the doer
@ewathedoer
Mar 22 2016 10:33
Use ``` before and after your code
@grfarshbaf
Reza Farshbaf
@grfarshbaf
Mar 22 2016 10:33

'''function factorialize(num) {
var result;
if (num > 0){
result = 1;
while (num > 0){
result *= num;
num--;
}

} else if (num === 0){
result = 1;
} else {
result = "Undefuned";
}
return result;
}'''

CamperBot
@camperbot
Mar 22 2016 10:33
:bulb: to format code use backticks! ``` more info
Reza Farshbaf
@grfarshbaf
Mar 22 2016 10:34
it didn't work!

```function factorialize(num) {
var result;
if (num > 0){
result = 1;
while (num > 0){
result *= num;
num--;
}

} else if (num === 0){
result = 1;
} else {
result = "Undefuned";
}
return result;
}```

ravitej177
@removed~ravitej177
Mar 22 2016 10:34
use js after first ```js
like dis ```js
the doer
@ewathedoer
Mar 22 2016 10:34
add Shift and Enter before and after ```
and code
KortsF
@KortsF
Mar 22 2016 10:34
@grfarshbaf Did you switch to compose mode, then back to chat mode? That's what tricked me the first time I tried
Reza Farshbaf
@grfarshbaf
Mar 22 2016 10:37
function factorialize(num) {
  var result;
  if (num > 0){
    result = 1;
    while (num > 0){
      result *= num;
      num--;
    }

  } else if (num === 0){
    result = 1;
  } else {
    result = "Undefined";
  }
  return result;
}
I got it!
I wrote the factorial. Any suggestion?
Jiimms
@jiimms
Mar 22 2016 10:37

@ewathedoer i had used

replace(/[^A-Za-z0-9]/g, "")

I will try with W and by that time if you are still here i will write :smile:

Y4T9Code
@Y4T9Code
Mar 22 2016 10:39
yesh @BKinahan
Francis
@Francis-p
Mar 22 2016 10:40
@BKinahan @KortsF you guys don’t do lesson straight from web?
the doer
@ewathedoer
Mar 22 2016 10:40
@jiimms I made it, the test passed
function palindrome(str) {
  str = str.toLowerCase(); // making all characters lower case
  str = str.replace(/\W+/g, ""); //  removing all non-alphanumeric characters but not underscore
  str = str.replace("_", "");

  newStr = str.split("").reverse().join("");

  return newStr==str;
}



palindrome("eye”);
Brendan Kinahan
@BKinahan
Mar 22 2016 10:41
@Francis-p Well, I do.
Y4T9Code
@Y4T9Code
Mar 22 2016 10:41
@BKinahan
the doer
@ewathedoer
Mar 22 2016 10:42
@jiimms does it mean that to remove you replace, have you ever tried other option to remove items from strings?
@jiimms and both === and == works in return line, why === works?
done with random but how do i call it out to html?
Jiimms
@jiimms
Mar 22 2016 10:45

@ewathedoer thats good. using W you can do it this way

str.replace(/\W|_/g, "")

the pipe symbol is for alternation.
I have not tried any other replace. replacing with no space is akin to removing.
== is eqality and === is strict equality. 1=="1" is true but 1==="1" is ot true

Daryl Carr
@daryl-c
Mar 22 2016 10:46
anyone know why the reduce keeps coming back undefined?
function binaryAgent(str) {

  var binNum = [128, 64, 32, 16, 8, 4, 2, 1];
  var decNumArr = [];

  function binToDec(arr) {
     arr.reduce(function(prev, current, index){
      if(current) {
        return prev + binNum[index];
      }
       return prev + 0;
    }, 0)}

  var arr = str.split(" ");
  for(var i = 0; i < arr.length; i++) {
    var arrItem = arr[i].split("");
    arrItem = (binToDec(arrItem));
    console.log(arrItem);
  }

}

binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");
the doer
@ewathedoer
Mar 22 2016 10:47
@jiimms yeah but how does === strict equality gives true in example
palindrome("My age is 0, 0 si ega ym.") should return true.
Markus Kiili
@Masd925
Mar 22 2016 10:47
@jiimms You should stick to strict equality ===. If you read how abstract equality == really works from EcmaScript standard, you brain will melt.
the doer
@ewathedoer
Mar 22 2016 10:47
btw @jiimms thanks for |
CamperBot
@camperbot
Mar 22 2016 10:47
ewathedoer sends brownie points to @jiimms :sparkles: :thumbsup: :sparkles:
:warning: ewathedoer already gave jiimms points
Jiimms
@jiimms
Mar 22 2016 10:50
@ewathedoer i guess it will be true after it removes the spaces and converts all to lowercase.
@ewathedoer you are welcome
uriznik
@uriznik
Mar 22 2016 10:58
@daryl-c you aren't returning the arr.reduce result
Francis
@Francis-p
Mar 22 2016 11:01
http://codepen.io/Francis-p/pen/ONpOJK
need help with calling js to display
Daryl Carr
@daryl-c
Mar 22 2016 11:03
@uriznik thanks! I just didnt realise I hadn't put the return on the arr.reduce line.
CamperBot
@camperbot
Mar 22 2016 11:03
daryl-c sends brownie points to @uriznik :sparkles: :thumbsup: :sparkles:
:star: 350 | @uriznik | http://www.freecodecamp.com/uriznik
kirbyedy
@kirbyedy
Mar 22 2016 11:03
@Francis-p your code cant work without the jquery embedded into the pen
also please include the $(document).ready(function(){
Francis
@Francis-p
Mar 22 2016 11:04
@kirbyedy jquery embedded into the pen
hmmm
kirbyedy
@kirbyedy
Mar 22 2016 11:04
as you can see your defined vars cant be accessed without that
Francis
@Francis-p
Mar 22 2016 11:05
just embedded that
Abdullah Hoosen
@abdullahhoosen
Mar 22 2016 11:08
Hi.. Not sure what to do here:
Instructions
Encode the following sequence, separated by spaces:
backslash tab tab carriage-return new-line and assign it to myStr
Francis
@Francis-p
Mar 22 2016 11:08
omg @kirbyedy ! i did it! ha!!!! Thank you!
CamperBot
@camperbot
Mar 22 2016 11:08
francis-p sends brownie points to @kirbyedy :sparkles: :thumbsup: :sparkles: