These are chat archives for FreeCodeCamp/HelpJavaScript

20th
Aug 2016
Kantra
@removed~kantrakantra
Aug 20 2016 00:05

Hey guys, I've been working on a code exercise and I'm stuck on a couple of issues. I was hoping some kind soul might be able to break down the code, line for line, and put it into layman's terms for me, as I've hit a critical stage of confusion.
I'm working backwards from this solution:

function destroyer(arr) {
  var args = Array.prototype.slice.call(arguments);
  args.splice(0, 1);
  return arr.filter(function(element) {
    return args.indexOf(element) === -1;
  });
}

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

This is the second day I've been in here looking for help with this, so forgive me if this is the second time you've this.

Firstly I'm not exactly understanding the purpose of the .call method and the fact that .slice is written without parentheses (). As well, I'm still unsure of the exact meaning behind .prototype. I've gotten some clarification from the chat so far, it's just still not clicking for some reason. I was hoping someone might be able to help explain some of this stuff to me.

Kornel
@kornelny
Aug 20 2016 00:06

What am I supposed t do here? I'm not familiar with this game.
Word Blanks

We will now use our knowledge of strings to build a "Mad Libs" style word game we're calling "Word Blanks". You will create an (optionally humorous) "Fill in the Blanks" style sentence.

You will need to use string operators to build a new string, result, using the provided variables: myNoun, myAdjective, myVerb, and myAdverb.

You will also need to use additional strings, which will not change, and must be in between all of the provided words. The output should be a complete sentence.

We have provided a framework for testing your results with different words. The tests will run your function with several different inputs to make sure all of the provided words appear in the output, as well as your extra strings.

​wordBlanks("","","","") should return a string.
wordBlanks("dog", "big", "ran", "quickly") should contain all of the passed in words separated by non-word characters (and any additional words in your madlib).
wordBlanks("cat", "little", "hit", "slowly") should contain all of the passed in words separated by non-word characters (and any additional words in your madlib).
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "";
// Your code below this line
// Your code above this line
return result;
}

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

Amy Kafai
@KafaiA
Aug 20 2016 00:08
@ndburrus yes but where is that defined?
@ndburrus from what I understand a line should be listed var testArr = [1,2,3,4,5]
Slimane
@slimane2015
Aug 20 2016 00:11
@beardedtim Thank you very much for your help. I could solve the problem with this code: var total = 0;
for (var i = 0; i < myArr.length; i++) {
total += myArr[i];
But believe me it was a chance, i still don't understand how total could equal 20 :)
CamperBot
@camperbot
Aug 20 2016 00:11
slimane2015 sends brownie points to @beardedtim :sparkles: :thumbsup: :sparkles:
:cookie: 46 | @beardedtim |http://www.freecodecamp.com/beardedtim
Tyler Roberts
@teachtyler
Aug 20 2016 00:11
what's up with Date(); if i want to get yesterday and convert to locale string I get errors
var date = new Date();
var fromDate = date.setDate(date.getDate() - 1);   // returns yesterday
var untilDate = date.toLocaleDateString("en-US"); // returns 8/19/2016
how would i get yesterday to localedatestring
Ivan
@Kolekcionar23
Aug 20 2016 00:12
CamperBot
@camperbot
Aug 20 2016 00:12
no wiki entry for: needed for challenge httpswwwfreecodecampcomchallengesfalsy-bouncer
Eric Bomblatus
@erbombla
Aug 20 2016 00:13
what's proper syntax for studlyCapVar?
I'm clueless
Ivan
@Kolekcionar23
Aug 20 2016 00:13

Here is my code

function bouncer(arr) {
  // Don't show a false ID to this bouncer.

 var result = true;  
 var filtered = arr.filter(test);

  function test(value){

    switch(value){
      case null:
        result = false;  
        break;
      case NaN:
        result = false;  
        break;
      case undefined:
        result = false;  
        break;
      case 0:
        result = false;  
        break;
      case "":
        result = false;  
        break;
      case false:
        result = false;  
        break;         
    default:
    result = true;
    }

    return result;

  }


  return filtered;  

}

bouncer([false, null, 0, NaN, undefined, ""]);

And I get result as [null], which should be just [].

Brendan Kinahan
@BKinahan
Aug 20 2016 00:15
@Kolekcionar23 You have a NaN problem. (the output on FCC will show NaN as null)
Ivan
@Kolekcionar23
Aug 20 2016 00:16
@BKinahan Ok, I tried all of this with IF statement, but NaN was problem too. I don't get it.
Brendan Kinahan
@BKinahan
Aug 20 2016 00:16
@Kolekcionar23 switch works by comparing each case with the argument value for equality, and NaN is not equal to anything (not even NaN!)
Ivan
@Kolekcionar23
Aug 20 2016 00:17
@BKinahan I know there is isNaN but I can't make it to work.
Brendan Kinahan
@BKinahan
Aug 20 2016 00:18
@Kolekcionar23 The hint is in what I said... It is a special quality of NaN. It is the only value that is not equal to itself. So, if you want to test if x is NaN, you can test if x === x
Ivan
@Kolekcionar23
Aug 20 2016 00:19
@BKinahan Oh, I get it now, and if it is NaN, it should return false.
Thanks @BKinahan
CamperBot
@camperbot
Aug 20 2016 00:20
kolekcionar23 sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star2: 2286 | @bkinahan |http://www.freecodecamp.com/bkinahan
Tyler Roberts
@teachtyler
Aug 20 2016 00:21
Figured it out
var date = new Date();
var fromDate = new Date(new Date().setDate(new Date().getDate()-1)).toLocaleDateString("en-US");  // returns yesterday 8/18/2016
var untilDate = date.toLocaleDateString("en-US"); // returns 8/19/2016
Norvin Burrus
@ndburrus
Aug 20 2016 00:22
@KafaiA ok, sorry, stepped away... is it resolved?
Diego Mayer
@Chrono79
Aug 20 2016 00:23
@kornelny have you read mad libs link?
Review this challenge: https://www.freecodecamp.com/challenges/constructing-strings-with-variables
Joseph
@revisualize
Aug 20 2016 00:32
@Kolekcionar23 The lesson links you to Boolean() and instead of using that you make a new function and in that function you have a large switch to try and do exactly what the built in Boolean() object actually does.
...
I know what you're thinking. Damn, who's this jerk? .... Sorry.
Islam Sanad
@Isanad3
Aug 20 2016 00:38
Hey guys , i need some help here , Concatenating Strings with the Plus Equals Operator, im quite confused about what to do here , any help would be awesome
umm nvm guys i figured it out xD
Joseph
@revisualize
Aug 20 2016 01:07
I have a fever and the cure is more ... Cow Bell!
Kevin Janada Roy Ardian
@kevinjanada
Aug 20 2016 01:15

hey guys, can i get some help with using loops through JSON?

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

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

var contnum = contacts[i];

if (firstName == contnum[firstName] && contnum.hasOwnProperty(prop)) {
return contnum[prop];

}

}
// Only change code above this line
}

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

CamperBot
@camperbot
Aug 20 2016 01:15
:bulb: to format code use backticks! ``` more info
Kevin Janada Roy Ardian
@kevinjanada
Aug 20 2016 01:16

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

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

var contnum = contacts[i];

if (firstName == contnum[firstName] && contnum.hasOwnProperty(prop)) {
return contnum[prop];

}

}
// Only change code above this line
}

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

it doesnt return anything
Owlie
@Owlie
Aug 20 2016 01:18
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["Javascript", "Gaming", "Foxes"]
}
];
function lookUpProfile(firstName, prop) {
// Only change code below this line
for (var i = 0; i < contacts.length; i++) {
var contnum = contacts[i];

if (firstName == contnum[firstName] && contnum.hasOwnProperty(prop)) {
return contnum[prop];
}
}
// Only change code above this line
}
// Change these values to test your function
lookUpProfile("Akira", "likes");
@kevinjanada I didn't change anything yet just trying to get it formatted completely
Kevin Janada Roy Ardian
@kevinjanada
Aug 20 2016 01:20
@Owlie thanks! sorry im such a noob lol! cant even format it correctly
CamperBot
@camperbot
Aug 20 2016 01:20
kevinjanada sends brownie points to @owlie :sparkles: :thumbsup: :sparkles:
:cookie: 321 | @owlie |http://www.freecodecamp.com/owlie
Owlie
@Owlie
Aug 20 2016 01:21
@kevinjanada It's not returning anything because it hasn't found anything that matches the criteria in your if statement.
Ricardo Araújo
@ricardomga
Aug 20 2016 01:25
@kevinjanada in the brakects of contnum you are passing the value of firstName, and not passing the key to pass the key you need to change fistName to "firstName"
Kevin Janada Roy Ardian
@kevinjanada
Aug 20 2016 01:27
@ricardomga thanks! it works
CamperBot
@camperbot
Aug 20 2016 01:27
kevinjanada sends brownie points to @ricardomga :sparkles: :thumbsup: :sparkles:
:cookie: 267 | @ricardomga |http://www.freecodecamp.com/ricardomga
Ricardo Araújo
@ricardomga
Aug 20 2016 01:27
@kevinjanada did you understant the problem?
Islam Sanad
@Isanad3
Aug 20 2016 01:27
Understand String Immutability , i dont understand what the correction is , please help
Kevin Janada Roy Ardian
@kevinjanada
Aug 20 2016 01:27
is it a better practice to use ["firstName"] or .firstName though?
Owlie
@Owlie
Aug 20 2016 01:28
I always use dot notation when I can
Santiago Gómez
@Sperkajugglite
Aug 20 2016 01:31
hi guys, do you know any ES6 video tutorial :P ? :innocent:
Kevin Janada Roy Ardian
@kevinjanada
Aug 20 2016 01:31
@ricardomga does this mean that, [obj] would pass the value of "obj"?
while ["obj"] or .obj would pass the key obj?
Ricardo Araújo
@ricardomga
Aug 20 2016 01:33
@kevinjanada no
Owlie
@Owlie
Aug 20 2016 01:34
@kevinjanada The problem wasn't passing the key or value it was that you were passing in the function argument named 'firstName'.
@kevinjanada So obj.value will always give you the value, as will obj["value"]. If you have the key of that value stored in another variable, something like var key = "firstName" then you would get the value of that key with obj[key].
I hope that makes sense.
Norvin Burrus
@ndburrus
Aug 20 2016 01:39
@kevinjanada this may be helpful: :sparkles:
@kornelny the exercise is asking for a sentence to be built using the 4 word types given. it may be easiest to begin by making a complete (spacing & punctuation) sentence, using the 4 words. to make sense, the complete sentence will require a few "filler" words. :sparkles:
Cage Echarte
@CageEcharte
Aug 20 2016 01:41
what is wrong with my code? here are the Instructions:
Add ["Paul",35] to the beginning of the myArray variable using unshift().
Norvin Burrus
@ndburrus
Aug 20 2016 01:41
@Isanad3 this may be helpful: :sparkles:
Kevin Janada Roy Ardian
@kevinjanada
Aug 20 2016 01:41
@Owlie @ndburrus @ricardomga thanks guys, i think i sort of got the idea now
CamperBot
@camperbot
Aug 20 2016 01:41
kevinjanada sends brownie points to @owlie and @ndburrus and @ricardomga :sparkles: :thumbsup: :sparkles:
:warning: kevinjanada already gave ricardomga points
:warning: kevinjanada already gave owlie points
:star2: 1687 | @ndburrus |http://www.freecodecamp.com/ndburrus
Cage Echarte
@CageEcharte
Aug 20 2016 01:41
here is my code..myArray.unshift("Paul", 35);
// myArray now equals ["Paul
Ricardo Araújo
@ricardomga
Aug 20 2016 01:42
@kevinjanada
var person = {
    name : "rita"
  };

var name = "joana";

person[name] // this will be undifined because its looking up for the key "joana" its realy doing this person["joana"] and tha prop doesnt exists
person["name"]  // this will return "rita" because its looking up for the value of property name and that prop have the value "rita"
Norvin Burrus
@ndburrus
Aug 20 2016 01:42
@CageEcharte this may be useful: :sparkles:
@kevinjanada you're welcome! nice job! enjoy! :palm_tree:
Ricardo Araújo
@ricardomga
Aug 20 2016 01:43
@kevinjanada you are welcome
Ken Haduch
@khaduch
Aug 20 2016 01:44

@texyh - sorry I didn't get back to the computer for a L-O-N-G time... to answer your question from :point_up: August 19, 2016 12:44 PM - addTogether(2)(3) actually would make two function calls - the first one is to call addTogether(2). This is the case, in that exercise that you are asked to solve, where you return a function - and your function that you return as to enclose the value 2 that was passed in. In that case, it "remembers" that value for the second function call, which is to call the function that you return when you get the single argument, passing in the argument 3. That example and bit of tutorial that I posted here https://gitter.im/FreeCodeCamp/HelpJavaScript?at=57b73666187885ef4f5f107e is to illustrate that you can return a function from another function, and in my example, I saved it to a variable that I could then call in a subsequent bit of code. My example can be used to generate a function that you can make to add a value any time you call it.

Your task, if you haven't completed it, in that "Arguments Optional" exercise is to recognize the situation where you only have one argument passed in, and generate the function that should be returned.

ValerieG
@cre8vexec
Aug 20 2016 01:46
Please help debug:
Ken Haduch
@khaduch
Aug 20 2016 01:47
@cre8vexec - fire away...
Norvin Burrus
@ndburrus
Aug 20 2016 01:47
@erbombla camelCase. :sparkles:
Stephen James
@sjames1958gm
Aug 20 2016 01:48
@CageEcharte Look at the instructions again on what you are supposed to unshift.
ValerieG
@cre8vexec
Aug 20 2016 01:48
@khaduch

function palindrome(str) {

str = str.replace(/[\'!"#$%&()*+,-.\/:;<=>?@[]^_`{|}~]/g, '').replace(/\s+/gi, '').toLowerCase;

var reverseString = str.split("").reverse().join("");

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

palindrome("eye");

Stephen James
@sjames1958gm
Aug 20 2016 01:49
@cre8vexec toLowerCase is a function - yours is missing something
Ken Haduch
@khaduch
Aug 20 2016 01:51

@cre8vexec - what @sjames1958gm said is one problem - a function call should have something added to the function name.

Also, you might get it to work with that regular expression that you have, but there is a way to greatly simplify it - but get your lower casing working first and see...

Stephen James
@sjames1958gm
Aug 20 2016 01:52
@cre8vexec Compare to your call to reverse
ValerieG
@cre8vexec
Aug 20 2016 01:56
fixed the "toLowerCase" issue...
Ken Haduch
@khaduch
Aug 20 2016 01:57
@cre8vexec - how many tests are passing?
ValerieG
@cre8vexec
Aug 20 2016 02:01

function palindrome(str) {

str = str.replace(/[\'!"#$%&()*+,-.\/:;<=>?@[]^_`{|}~]/g, '').replace(/\s+/gi, '');

var reverseString = str.split("").reverse().join("");

if (reverseString.toLowerCase == str.toLowerCase) {
return true;
} else {
return false;
}
}

palindrome("eye");

@khaduch 10 of 15
Santiago Gómez
@Sperkajugglite
Aug 20 2016 02:02
@Boris1011 hi there mate :P
ValerieG
@cre8vexec
Aug 20 2016 02:02
but the alphanumeric palindrome("nope") is not passing.
for example
pahosler
@pahosler
Aug 20 2016 02:02
@cre8vexec your regex doesn't need to be that huge
ValerieG
@cre8vexec
Aug 20 2016 02:02
it should be false
True, @pahosler. I
Ken Haduch
@khaduch
Aug 20 2016 02:03
@cre8vexec - well, that's a good percentage. Now - you still have a bit of a problem with your function calls to the .toLowerCase() method... if you check your browser console, you'll possibly see an error message related to that?
ValerieG
@cre8vexec
Aug 20 2016 02:03
I have tried the most simple regex to this very complicated one
and still don't get all the tests to pass
pahosler
@pahosler
Aug 20 2016 02:04
this is what mine looked like... match(/[a-z0-9]/)
ValerieG
@cre8vexec
Aug 20 2016 02:04
true, @khaduch
pahosler
@pahosler
Aug 20 2016 02:04
because you only want those values
ValerieG
@cre8vexec
Aug 20 2016 02:05
that was what I started with @pahosler
It didn't account for spaces, punctuation, nor underscores for some reason
pahosler
@pahosler
Aug 20 2016 02:07
@cre8vexec you can make the whole thing toLowerCase first, then split it into an array and then only check for alphanumerical values...
Ken Haduch
@khaduch
Aug 20 2016 02:07
@cre8vexec - well, I was wrong about seeing the error in the console - it doesn't flag an error for your attempted calls to .toLowerCase() - but you need to have parentheses at the end of your .toLowerCase call... since it is a function, and you want to have javascript call it.
pahosler
@pahosler
Aug 20 2016 02:07
and you can use reduce to easily parse through the array...
Ken Haduch
@khaduch
Aug 20 2016 02:09
@cre8vexec - your regex could be simplified, but what you have might work if you've covered all of the special characters that they used. Change your call to .toLowerCase() and see what changes in your test results.
ValerieG
@cre8vexec
Aug 20 2016 02:10

function palindrome(str) {

str = str.replace(/[\'!"#$%&()*+,-.\/:;<=>?@[]^_`{|}~]/g, '').replace(/\s+/gi, '');

var reverseString = str.split("").reverse().join("").toLowerCase();

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

palindrome("eye");

@khaduch Adding the () at the end of .toLowerCase got me 13/15 on my tests.
Ken Haduch
@khaduch
Aug 20 2016 02:11

@cre8vexec - and make sure you apply .toLowerCase() to both strings.

And you're getting closer!

ValerieG
@cre8vexec
Aug 20 2016 02:14

Yay, finally hit the bull's eye! Thanks, @khaduch!! Here's my debugged code. Now do I dare go back to the simple regex that I began with for only alphanumeric characters?? function palindrome(str) {

str = str.replace(/[\'!"#$%&()*+,-.\/:;<=>?@[]^_`{|}~]/g, '').replace(/\s+/gi, '').toLowerCase();

var reverseString = str.split("").reverse().join("").toLowerCase();

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

palindrome("eye");

CamperBot
@camperbot
Aug 20 2016 02:14
cre8vexec sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 1558 | @khaduch |http://www.freecodecamp.com/khaduch
pahosler
@pahosler
Aug 20 2016 02:14
function palindrome(str) {
  var pal = [];
  str.toLowerCase().split('').reduce((a,b)=>{
    (b.match(/[a-z0-9]/)) ? pal.push(b) :  b
    return b
  },[])
   return (pal.join('') == pal.reverse().join(''))
}
Ken Haduch
@khaduch
Aug 20 2016 02:15
@cre8vexec - just save what you have and experiment with a change.
@pahosler - is that ES6?
pahosler
@pahosler
Aug 20 2016 02:15
no
well a little
just the =>
the other thing that looks odd is a ternary
they will make your life better
and there is probably an easier shorter way than I managed...
learn reduce, it is important
Ken Haduch
@khaduch
Aug 20 2016 02:18
@pahosler @cre8vexec - the heavy lifting line of my solution was this: var lcString = str.toLowerCase().replace(/[\W_]/ig, ''); // strip out underscores, and non-word characters; then a reverse of the string to compare it.
pahosler
@pahosler
Aug 20 2016 02:19
mine just picks the alphanumeric values, pushes them to an array and skips the rest
match and replace probably carry about the same weight memory and time wise, so there most likely isn't much difference there...
Ken Haduch
@khaduch
Aug 20 2016 02:21
mine just throws away non-word characters and underscores... Ternary operator is good, reduce is good, I just didn't think of doing it that way.
ValerieG
@cre8vexec
Aug 20 2016 02:22
Thanks, Ken. @khaduch I will try that! var lcString = str.toLowerCase().replace(/[\W_]/ig, ''); // strip out underscores, and non-word characters;
CamperBot
@camperbot
Aug 20 2016 02:22
cre8vexec sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:warning: cre8vexec already gave khaduch points
pahosler
@pahosler
Aug 20 2016 02:22
@khaduch I'm not criticizing yours at all, it's a good solution, anything that works is a good solution :D sort of
Ken Haduch
@khaduch
Aug 20 2016 02:22
@cre8vexec - you're welcome... good luck with your continuing work and progress!
pahosler
@pahosler
Aug 20 2016 02:24
I actually had a different, much longer solution when I first did it, then after I learned a few tricks I went back to see if I could do it better
Ken Haduch
@khaduch
Aug 20 2016 02:24
@pahosler - it is good to get it working, as a first pass, and much better to learn faster and more efficient ways to solve them, too... Im always learning new things - or re-learning them... :)
pahosler
@pahosler
Aug 20 2016 02:25
learning reduce has been a boon, it confused me until I ran across a FCC wiki entry about it, light bulbs went off in my head after reading through it!
Ken Haduch
@khaduch
Aug 20 2016 02:27
@pahosler - I should find that wiki entry and read it - I still get confused by .reduce()... at least most of the time. I always have to review it.
Brandon
@Brandons42
Aug 20 2016 02:31
help regex
CamperBot
@camperbot
Aug 20 2016 02:31

:point_right: js regex resources [wiki]

Regular Expressions Resources

Links to useful RegEx resources.

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

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

pahosler
@pahosler
Aug 20 2016 02:32
@khaduch have you done pairwise? Advanced algorithms?
lost my network for a minute there...
I'll see if I can find it again, and paste the link...
Mike R
@mikeinmiami
Aug 20 2016 02:33
Hey guys, quick question. The return early pattern for functions challenge. Am i supposed to use an if statement or switch?
Joseph
@revisualize
Aug 20 2016 02:33
@pahosler Why would you do it like that?
@mikeinmiami I think that one is an if.
Mike R
@mikeinmiami
Aug 20 2016 02:34
Yeah I hate how some times it doesn't tell you what to use. It would suck if I use a if statement and they wanted a switch since I just finished doing switch
Joseph
@revisualize
Aug 20 2016 02:37
@mikeinmiami It is just trying to show you that return statements halt the function. So, using a return statement anywhere once it gets called the code returns.
Mike R
@mikeinmiami
Aug 20 2016 02:38
I did 2 if statements for that. @revisualize How would I be able to make it shorter?
Joseph
@revisualize
Aug 20 2016 02:39
@mikeinmiami No idea.
Let me look at the lesson.
Mike R
@mikeinmiami
Aug 20 2016 02:40
It worked @revisualize I just wondering if I could some how put a and b together
Joseph
@revisualize
Aug 20 2016 02:40
@mikeinmiami I just used 1 if.
Kantra
@removed~kantrakantra
Aug 20 2016 02:40
Hey guys, can anybody explain why the following code doesn't return a sorted array
var sun = ["zebra","coke","beer","scone"];
Array.prototype.sort();
return sun;
Joseph
@revisualize
Aug 20 2016 02:40
@kantrakantra does .sort() mutate the array?
Mike R
@mikeinmiami
Aug 20 2016 02:41
so did you use && for that 1 if statement?
@revisualize
Ken Haduch
@khaduch
Aug 20 2016 02:41
@pahosler - no, I haven't gotten through all of the advanced algorithms.
Joseph
@revisualize
Aug 20 2016 02:41
@mikeinmiami I used an Or operator.
@kantrakantra OH! You're not actually sorting sun. You're calling the Array.prototype.sort();

@kantrakantra Your code:

var sun = ["zebra","coke","beer","scone"];
Array.prototype.sort(); // This doesn't actually sort anything.
return sun;

you need to do this:

var sun = ["zebra","coke","beer","scone"];
sun.sort(); // You need to sort the sun array.
return sun;
Mike R
@mikeinmiami
Aug 20 2016 02:44
They never taught us that one
@revisualize
is that the ||
Christopher
@Ryohka
Aug 20 2016 02:45
Hello everyone, I'm jammed up on "Using objects for Lookups". I created a table titled "var lookup ={...}" with the table inside but I can't seem to pull the info out with the "return result". I've tried every combo of "lookup.val =result" but I think I'm calling it incorrectly...
Joseph
@revisualize
Aug 20 2016 02:45
@mikeinmiami yes.
Mike R
@mikeinmiami
Aug 20 2016 02:45
never mind they did lol
Joseph
@revisualize
Aug 20 2016 02:45
@Ryohka You're re-assigning backwards.
Lunaticf
@Lunaticf
Aug 20 2016 02:46
Array.prototype.sort.apply(null,sun); can this also work?
Brandon
@Brandons42
Aug 20 2016 02:46
//What am I doing wrong here?
//I'm trying to replace the brackets.
//Challenge: Steamroller
str = str.replace(/\[\]/g,"");
Joseph
@revisualize
Aug 20 2016 02:46

@Ryohka If I want to assign a variable name the value of "Joseph" and I do this:

var name = "Josph";

How do I correctly reassign the value name to the correct spelling of "Joseph"?
I do:

name = "Joseph";
Ken Aguilar
@piq9117
Aug 20 2016 02:46
@Ryohka you need a switch statement
Kantra
@removed~kantrakantra
Aug 20 2016 02:47
@revisualize What I'm trying to figure out is what Array.prototype.sort();is and what it does
Joseph
@revisualize
Aug 20 2016 02:47
@piq9117 No you don't.
Ken Aguilar
@piq9117
Aug 20 2016 02:47
@revisualize isnt he talking about the phoneticlookup?
Joseph
@revisualize
Aug 20 2016 02:47
@kantrakantra It allows you to sort Arrays.
@piq9117 Yes. You do NOT use a switch for that lesson.
about @piq9117
CamperBot
@camperbot
Aug 20 2016 02:48
:cookie: 269 | @piq9117 |http://www.freecodecamp.com/piq9117
Kantra
@removed~kantrakantra
Aug 20 2016 02:48
@revisualize So when you call Array.prototype.sort(); what is it sorting? Or rather, how do you use it to sort arrays?
Joseph
@revisualize
Aug 20 2016 02:48
@piq9117 And you didn't use a switch when you did the lesson.
Ken Aguilar
@piq9117
Aug 20 2016 02:48
oh... yeah.. ur suppose to change the switch
Lunaticf
@Lunaticf
Aug 20 2016 02:49
Array.prototype.sort.apply(null,sun)?
Joseph
@revisualize
Aug 20 2016 02:49
@kantrakantra If you just call Array.prototype.sort() by itself. .. Doesn't do ANYTHING. nothing happens.
Brandon
@Brandons42
Aug 20 2016 02:49
//What am I doing wrong here?
//I'm trying to replace the brackets.
//Challenge: Steamroller
str = str.replace(/\[\]/g,"");
Joseph
@revisualize
Aug 20 2016 02:49
It doesn't know which array you want to sort. What if you have 50 arrays?
Brandon
@Brandons42
Aug 20 2016 02:49
@revisualize
Kantra
@removed~kantrakantra
Aug 20 2016 02:49
@revisualize Ok so what is it used for then is I guess what I'm trying to figure out
Joseph
@revisualize
Aug 20 2016 02:50
@kantrakantra Look. These are prototypes. If you have an ARRAY element you can use the .sort() method against it.
Diego Mayer
@Chrono79
Aug 20 2016 02:51
@Brandons42 that approach won't work
Lunaticf
@Lunaticf
Aug 20 2016 02:51
Array.prototype.sort.apply(null,sun) is this right?can you see me.I am from china
Ken Aguilar
@piq9117
Aug 20 2016 02:51
@Ryohka make the switch statement into an object
pahosler
@pahosler
Aug 20 2016 02:52

@revisualize what did you mean...???

@pahosler Why would you do it like that?

Joseph
@revisualize
Aug 20 2016 02:52
Array.prototype.sort() is used for sorting arrays.
BUT, you have to do it against an array.
Example.
var arr = ["z","g","t","f","e"]; // The Array.
arr.sort();
// or
Array.prototype.sort.apply(null,arr); // See how you're applying the sort to the ARRAY.
Brandon
@Brandons42
Aug 20 2016 02:52
@Chrono79 WHAT WILL?
@Chrono79 Accidentally made it all caps.
Kantra
@removed~kantrakantra
Aug 20 2016 02:52
@revisualize Ok so when is it appropriate to use Array.prototype.sort();
Joseph
@revisualize
Aug 20 2016 02:52
@kantrakantra Let me ask this.
@kantrakantra You want to use this code...
Diego Mayer
@Chrono79
Aug 20 2016 02:53
@Brandons42 easier to understand (not the easiest challenge) is use recursion and build another array
Joseph
@revisualize
Aug 20 2016 02:53
Array.prototype.sort(); .... Just like that.. Nothing else added or removed from it?
@kantrakantra If that is the case and you want to use .. Array.prototype.sort(); .. Just like that with 0 edits or modifications. It is NEVER appropriate.
Kantra
@removed~kantrakantra
Aug 20 2016 02:54
@revisualize I'm approaching what I don't understand with a different line of questioning because I'm having an issue with an exercise but I'm not getting a response with my original set of questions
Brandon
@Brandons42
Aug 20 2016 02:54
@Chrono79 Can you give me a link or something?
Dan Gwirtzman
@dgwirtzy
Aug 20 2016 02:54

Hi - I am stuck on this assignment:
Instructions
Call the processArg function with an argument of 7 and assign its return value to the variable processed.

// Example
var changed = 0;

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

changed = change(10);

// Setup
var processed = 0;

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

// Only change code below this line

var processed = 2;

function processArg(num) {
return (num + 3) / 5;
}
processed = processArg(7);

I don't know how to copy the black-screen shot
Joseph
@revisualize
Aug 20 2016 02:54
help format
CamperBot
@camperbot
Aug 20 2016 02:54

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

Joseph
@revisualize
Aug 20 2016 02:55
@kantrakantra Clearly you don't understand data types ... Or methods. And that's okay.
Christopher
@Ryohka
Aug 20 2016 02:55
@piq9117 not sure what you mean, I appreciate the advice. I think I'll back track a few lessons.
Diego Mayer
@Chrono79
Aug 20 2016 02:55
wiki Steamroller
CamperBot
@camperbot
Aug 20 2016 02:55

:point_right: algorithm steamroller [wiki]

Algorithm Steamroller

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

:checkered_flag: Problem Explanation:

This problem seems simple but you need to make sure to flatten any array, regardless of the level which is what adds a bit of difficulty to the problem.

Relevant Links

:pencil: read more about algorithm steamroller on the FCC Wiki

Brandon
@Brandons42
Aug 20 2016 02:55
Thanks @Chrono79
CamperBot
@camperbot
Aug 20 2016 02:55
brandons42 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1857 | @chrono79 |http://www.freecodecamp.com/chrono79
kimstopmik
@kimstopmik
Aug 20 2016 02:55
can someone shortly explain what is (a) and what is (b) in the compare function of the .sort() method?
Ken Haduch
@khaduch
Aug 20 2016 02:55
@pahosler - thanks for that link - I'm reading it, I'll have to re-read it, and I'll have to get used to using it!
CamperBot
@camperbot
Aug 20 2016 02:55
khaduch sends brownie points to @pahosler :sparkles: :thumbsup: :sparkles:
:cookie: 355 | @pahosler |http://www.freecodecamp.com/pahosler
Kantra
@removed~kantrakantra
Aug 20 2016 02:55

@revisualize

I'm working backwards from this solution:

function destroyer(arr) {
  var args = Array.prototype.slice.call(arguments);
  args.splice(0, 1);
  return arr.filter(function(element) {
    return args.indexOf(element) === -1;
  });
}

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

Firstly I'm not exactly understanding the purpose of the .call method and the fact that .slice is written without parentheses (). As well, I'm still unsure of the exact meaning behind .prototype and element

Diego Mayer
@Chrono79
Aug 20 2016 02:55
@kimstopmik the current element and the next one
Joseph
@revisualize
Aug 20 2016 02:56
@kantrakantra I GREATLY_DISLIKE that lesson. I do NOT assist anyone with it.
kimstopmik
@kimstopmik
Aug 20 2016 02:56
@Chrono79 simple as that, great. thanks! taking another look now to fully understand the method :smile:
CamperBot
@camperbot
Aug 20 2016 02:56
kimstopmik sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 1858 | @chrono79 |http://www.freecodecamp.com/chrono79
Kantra
@removed~kantrakantra
Aug 20 2016 02:56
@revisualize ok
pahosler
@pahosler
Aug 20 2016 02:56
@khaduch I played around with it for days trying to figure it out on my own then I accidentally ran across that article, it's link is burried in another wiki
frustrating
Brandon
@Brandons42
Aug 20 2016 02:57
What challenge is it? @kantrakantra
Diego Mayer
@Chrono79
Aug 20 2016 02:57
@kantrakantra I can try
you have to use Array.prototype because arguments is not a real array, is some array like object
Ken Aguilar
@piq9117
Aug 20 2016 02:57
@Ryohka
var lookup = {
  alpha: "Adams"
}
pahosler
@pahosler
Aug 20 2016 02:57
I have it bookmarked now :D
Joseph
@revisualize
Aug 20 2016 02:57

@kantrakantra Look.. Do you understand that:

arguments;

Is a JavaScript Key word?
And

Array.prototype.slice.call(arguments);

Is calling slice against the arguments for the function?

@Chrono79 Ok so why can I write .slice without parenthases?
Brandon
@Brandons42
Aug 20 2016 03:00
@kantrakantra I remember that one was hard for me because I'd never dealt with the arguments object before.
Diego Mayer
@Chrono79
Aug 20 2016 03:01
@kantrakantra that's how you use call and apply
Mike R
@mikeinmiami
Aug 20 2016 03:03
help Counting Cards
Elbert Cortez
@trip16661
Aug 20 2016 03:03
help format
CamperBot
@camperbot
Aug 20 2016 03:03

:point_right: challenge counting cards [wiki]

Challenge Counting Cards

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

:checkered_flag: Problem Explanation:

In the casino game Blackjack, a player can gain an advantage over the house by keeping track of the relative number of high and low cards remaining in the deck. This is called card counting.

Having more high cards remaining in the deck favors the player. Each card is assigned a value according to the table below. When the count is positive, the player should bet high. When the count is zero or negative, the player should bet low.

Value Cards
+1 2, 3, 4, 5, 6
0 7, 8, 9
-1 10, 'J', 'Q', 'K','A'

You will write a card counting function. It will receive a card parameter and increment or decrement the global count variable according to the card's value (see table). The function will then return a string with the current count and the string Bet if the count is positive, or Hold if the count is zero or negative. The current count and the player's decision (Bet or Hold) should be separated by a single space.

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

kimstopmik
@kimstopmik
Aug 20 2016 03:03
another short or not so short question: how (in which way) does the .sort() method with a compare function move on? let's say it shall sort numbers from lowest to highest. it takes the first value and compares it with the second one, then sorts the second value to position 1 because it's lower. but that value, now in position 1, is still higher than - let's say - the 4th value. How will the .sort() method come back to comparing the now in position 1 value with the later on coming values then?
var numbers = [4, 2, 5, 1, 3];
numbers.sort(function(a, b) {
  return a - b;
});
here is the according code
hopefully someone understands me :smile:
Iavor Dekov
@ivdekov
Aug 20 2016 03:04
Hey everyone, I'm trying to complete the "Concatenating Strings with the Plus Equals Operator" Basic Javscript lesson but it's not compiling correctly. I get the output: myStr "undefinedThis is the first sentence. This is the second sentence."
Kantra
@removed~kantrakantra
Aug 20 2016 03:04

@Brandons42 I actually understand the arguments part, unfortunately it's a number of other things in the solution that are confusing me, namely:

1) What exactly is the practical application of Array.prototype

2) What is the application of .call()

3) What is elements

4) Why is slice being called without parentheses and what is it doing in the code (returning args –before line 3– seems to produce an identical result to returning arguments

Mike R
@mikeinmiami
Aug 20 2016 03:04
help Concatenating Strings with the Plus Equals Operator
CamperBot
@camperbot
Aug 20 2016 03:04

:point_right: challenge concatenating strings with the plus equals operator [wiki]

Challenge Concatenating Strings with the Plus Equals Operator

We can use the += operator to concatenate a string onto the end of an existing string variable. This can be very helpful to break a long string over several lines.

:pencil: read more about challenge concatenating strings with the plus equals operator on the FCC Wiki

kimstopmik
@kimstopmik
Aug 20 2016 03:05
is it constantly going through each value after sorting something and ends when nothing can be sorted anymore?
Kantra
@removed~kantrakantra
Aug 20 2016 03:05
@Brandons42 I get that arguments is essentially this for the contents of a function's argument
Mike R
@mikeinmiami
Aug 20 2016 03:06
@kimstopmik where are you stuck at?
kimstopmik
@kimstopmik
Aug 20 2016 03:06
@mikeinmiami not stuck, just trying to fully understand :smile:
Diego Mayer
@Chrono79
Aug 20 2016 03:07
@kimstopmik http://www.pythontutor.com/javascript.html#mode=edit copy and paste your code there, you'll see it's not that simple, but it works
Sometimes you use a car without knowing how the motor works internally, but if you're curious, be my guest
Mike R
@mikeinmiami
Aug 20 2016 03:08
+= all that is, is adding to myStr
kimstopmik
@kimstopmik
Aug 20 2016 03:08
@Chrono79 thanks, the example code is from MDN
CamperBot
@camperbot
Aug 20 2016 03:08
kimstopmik sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: kimstopmik already gave chrono79 points
kimstopmik
@kimstopmik
Aug 20 2016 03:09
ah
thanks
now understanding what the website does
taking a lokk
look
Elbert Cortez
@trip16661
Aug 20 2016 03:09
@Chrono79 pretty cool thing
kimstopmik
@kimstopmik
Aug 20 2016 03:10
ah
it goes back with the back sorted value then before taking the next one and comparing with the next one again and so on
Chris Cullen
@123xylem
Aug 20 2016 03:11
SO CLOSE to finishing now... Just need help on 2 things http://codepen.io/123xylem/pen/AXwwPj?editors=1010
  1. How do i get my clear button to reset time to 0 ...
  2. Is there an inbuilt method for On button hold to increment the timer up?\
kimstopmik
@kimstopmik
Aug 20 2016 03:11
as far as i can see
thanks! @Chrono79
CamperBot
@camperbot
Aug 20 2016 03:11
kimstopmik sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: kimstopmik already gave chrono79 points
kimstopmik
@kimstopmik
Aug 20 2016 03:11
not that simple, right :smile:
Mike R
@mikeinmiami
Aug 20 2016 03:12
Hey guys, I need help with Counting Cards :worried:
anyone?
Balamurugan Subbaian
@dillbala
Aug 20 2016 03:20
i can help you @mikeinmiami
Mike R
@mikeinmiami
Aug 20 2016 03:20
@dillbala Cool ok so I have the var count = 0 and can either use an else if statement or switch
help Counting Cards
CamperBot
@camperbot
Aug 20 2016 03:21

:point_right: challenge counting cards [wiki]

Challenge Counting Cards

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

:checkered_flag: Problem Explanation:

In the casino game Blackjack, a player can gain an advantage over the house by keeping track of the relative number of high and low cards remaining in the deck. This is called card counting.

Having more high cards remaining in the deck favors the player. Each card is assigned a value according to the table below. When the count is positive, the player should bet high. When the count is zero or negative, the player should bet low.

Value Cards
+1 2, 3, 4, 5, 6
0 7, 8, 9
-1 10, 'J', 'Q', 'K','A'

You will write a card counting function. It will receive a card parameter and increment or decrement the global count variable according to the card's value (see table). The function will then return a string with the current count and the string Bet if the count is positive, or Hold if the count is zero or negative. The current count and the player's decision (Bet or Hold) should be separated by a single space.

Balamurugan Subbaian
@dillbala
Aug 20 2016 03:21
you can use switch @mikeinmiami
switch(val){}
Mike R
@mikeinmiami
Aug 20 2016 03:22
Now how would I go about changing the count = 0 variable
Ivan
@ivanvgarcia
Aug 20 2016 03:22

function nextInLine(arr, item) {
  item = arr.push(item);// Your code here
  item = arr.shift(item);
  return item;  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 1)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
js`
I was able to pass this checkpoint although I'm not really understanding it. I looked around different websites and my solution is a bit different from others... did I go about it the wrong way?
Ken Aguilar
@piq9117
Aug 20 2016 03:22
@mikeinmiami I wrote my solution about counting cards.. Hopefully it will help you https://github.com/piq9117/freeCodeCamp/blob/master/BasicJavascript/CountingCards.md
Balamurugan Subbaian
@dillbala
Aug 20 2016 03:22
case 1: case 2: case 3: count+=1; like wise
Mike R
@mikeinmiami
Aug 20 2016 03:23
@dillbala that's how I would increment count?
Diego Mayer
@Chrono79
Aug 20 2016 03:24
@piq9117 I have a few suggestions about your solution, I'll send you a pm
Mike R
@mikeinmiami
Aug 20 2016 03:24
I was thinking more of the idea of using something like ++i but I guess thats way too advanced correct? I have an idea what it's used for but don't know how to complete
use it
Balamurugan Subbaian
@dillbala
Aug 20 2016 03:24
while return count + ((count<0) ? "hold" : "bet");
Mike R
@mikeinmiami
Aug 20 2016 03:25
@dillbala Yea I haven't learned how to use that yet lol
Balamurugan Subbaian
@dillbala
Aug 20 2016 03:26
its looking like if else....
kimstopmik
@kimstopmik
Aug 20 2016 03:26
just finished the first algorithm challenge, one short question:

function reverseString(str) {

  var arr = str.split("");
  arr.reverse();
  str = arr.join("");
  return str;
}

reverseString("hello");
Balamurugan Subbaian
@dillbala
Aug 20 2016 03:26
you can understand it @mikeinmiami
cool @kimstopmik
kimstopmik
@kimstopmik
Aug 20 2016 03:27
why doesn't it work when you don't assign the for example "arr.join("");" to another variable?
so return arr in the end would not give the wanted result then
missing on something fundamental here for sure
Ivan
@ivanvgarcia
Aug 20 2016 03:28
This message was deleted
Diego Mayer
@Chrono79
Aug 20 2016 03:28
@kimstopmik arr.join returns a string, it doesn't mutate the arr var
Elbert Cortez
@trip16661
Aug 20 2016 03:28
@kimstopmik join RETURNs a new string
Mark
@vinarius
Aug 20 2016 03:29
@kimstopmik you could substitute str = arr.join(""); for arr = arr.join(""); then return arr
Elbert Cortez
@trip16661
Aug 20 2016 03:29
its different from the string that you had before
Balamurugan Subbaian
@dillbala
Aug 20 2016 03:30
your solution will return as a string by using join() function @kimstopmik

function reverseString(str) {

var arr = str.split("");
var str1=arr.reverse();
return str1;
}

reverseString("hello");
["o", "l", "l", "e", "h"]

without join function it will return array @kimstopmik
Elbert Cortez
@trip16661
Aug 20 2016 03:31
since it returns it doesnt change the initial string which it was called upon
Balamurugan Subbaian
@dillbala
Aug 20 2016 03:31
did you get it? @kimstopmik
Elbert Cortez
@trip16661
Aug 20 2016 03:31
in sumaryit doesnt mutate it
kimstopmik
@kimstopmik
Aug 20 2016 03:31
@dillbala what it does in general i know, thanks :smile:
CamperBot
@camperbot
Aug 20 2016 03:31
kimstopmik sends brownie points to @dillbala :sparkles: :thumbsup: :sparkles:
:cookie: 215 | @dillbala |http://www.freecodecamp.com/dillbala
kimstopmik
@kimstopmik
Aug 20 2016 03:33
@trip16661 @vinarius @Chrono79 so it needs the reference (or however we call that) to a variable which it can be assigned to?
Diego Mayer
@Chrono79
Aug 20 2016 03:33
@kimstopmik not necessarily
kimstopmik
@kimstopmik
Aug 20 2016 03:33
because it doesn't change it's type?
Diego Mayer
@Chrono79
Aug 20 2016 03:34
@kimstopmik you can chain methods and do this:
function reverseString(str) {
  return str.split("").reverse().join("");
}
kimstopmik
@kimstopmik
Aug 20 2016 03:35
much shorter :smile:
Balamurugan Subbaian
@dillbala
Aug 20 2016 03:35
thats cool @Chrono79
kimstopmik
@kimstopmik
Aug 20 2016 03:35
never used chaining
Mark
@vinarius
Aug 20 2016 03:36
But if you split the commands and assign variables then yes you have to 'reference' the variable just without the keyword 'var' befor the actual name
If you use var JS will think you are trying to declare a new variable
kimstopmik
@kimstopmik
Aug 20 2016 03:36
but still dont understand to 100% why it would work with arr.reverse(); without assigning to a variable and not in the next step
Elbert Cortez
@trip16661
Aug 20 2016 03:36
yep pretty much
but its better for readability to
do it like this
function reverseString(str) {
  return str.split("")
      .reverse()
      .join("");
}
kimstopmik
@kimstopmik
Aug 20 2016 03:37
so it got to have something to do with the different types or not?
Diego Mayer
@Chrono79
Aug 20 2016 03:37
@kimstopmik because reverse mutates the array
Elbert Cortez
@trip16661
Aug 20 2016 03:37
if its a long chain
kimstopmik
@kimstopmik
Aug 20 2016 03:37
ah, that's something "special" about reverse then?
Diego Mayer
@Chrono79
Aug 20 2016 03:38
@kimstopmik a method could mutate or not the object you apply it to, sort mutates, reverse mutates
Elbert Cortez
@trip16661
Aug 20 2016 03:38
you should check mutable and nonmutable method
kimstopmik
@kimstopmik
Aug 20 2016 03:38
that's what the "The reverse() method reverses an array in place." sentence wants to say?
ok great, will google it now
thanks guys
Chris Cullen
@123xylem
Aug 20 2016 03:39
http://codepen.io/123xylem/pen/AXwwPj?editors=1010
Is there a way to make my buttons increment on hold???
Ken Aguilar
@piq9117
Aug 20 2016 03:41
@123xylem use onKeydown
Elbert Cortez
@trip16661
Aug 20 2016 03:41
increment as size of the button
or increment as the time in the program
if its the second then its what @piq9117
Chris Cullen
@123xylem
Aug 20 2016 03:42
@piq9117 so instead of (button).click (button).onKeydown?
Elbert Cortez
@trip16661
Aug 20 2016 03:42
said if not then you should check active
Ken Aguilar
@piq9117
Aug 20 2016 03:43
@123xylem yep.. jquery has .keydown() method
are you using jquery?
kimstopmik
@kimstopmik
Aug 20 2016 03:43
wow, i understand it now. :smile:
great
thanks again helping people
Chris Cullen
@123xylem
Aug 20 2016 03:44
@piq9117 yea
kimstopmik
@kimstopmik
Aug 20 2016 03:44
moving on to the next challenge
Chris Cullen
@123xylem
Aug 20 2016 03:44
its says keydown is for keyboard presses
Ken Aguilar
@piq9117
Aug 20 2016 03:45
@123xylem cool.. $(button element here).onkeydown(handler here)
friscodisco
@friscodisco
Aug 20 2016 03:45
Anyone know why the answer here is not working for passing the challenge? https://github.com/freecodecamp/freecodecamp/wiki/challenge-nesting-for-loops
Elbert Cortez
@trip16661
Aug 20 2016 03:45
there is a keydown keypress and keyup
Chris Cullen
@123xylem
Aug 20 2016 03:46
@piq9117
$("#plus1").keyDown(function() { //Plus (break)
  time2 += 60;
  $("#set2").text(getTime(time2));
}); //Plus Minus for BreakTime
o onKeydown
Ken Aguilar
@piq9117
Aug 20 2016 03:46
yeah.. lower case
Elbert Cortez
@trip16661
Aug 20 2016 03:47
@friscodisco i think cuz its consoling and not returning but i just didnt look it for long
Chris Cullen
@123xylem
Aug 20 2016 03:47
$("#plus1").onkeydown(function() { //Plus (break)
  time2 += 60;
  $("#set2").text(getTime(time2));
}); //Plus Minus for BreakTime
Its not responding... does it need a time associated?
like setInterval
friscodisco
@friscodisco
Aug 20 2016 03:48
@trip16661 thanks i tried changing console.log to return but still not working gonna grind on it a bit
CamperBot
@camperbot
Aug 20 2016 03:48
friscodisco sends brownie points to @trip16661 :sparkles: :thumbsup: :sparkles:
:cookie: 456 | @trip16661 |http://www.freecodecamp.com/trip16661
ahmed abouhay
@abohay
Aug 20 2016 03:51
function destroyer(arr) {
  // Remove all the values
  var hk = Array.from(arguments);
  return hk.indexOf(arr) == -1;
}
function bouncer(no) {
  var thenew = no.filter(destroyer);
  return thenew;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
@friscodisco @123xylem @kimstopmik @piq9117 any one could help
Ken Aguilar
@piq9117
Aug 20 2016 03:51
@123xylem if you hold the return button it will work.. did you also want click?
Chris Cullen
@123xylem
Aug 20 2016 03:52
$("#plus1").onkeydown(function() { //Plus (break)
  countdownID3 = setInterval(increment, 300);
  $("#set2").text(getTime(time2));
}); //Plus Minus for BreakTime

function increment(){
  time2+=60;
};
Yes i also want click but its not working like this so far
friscodisco
@friscodisco
Aug 20 2016 03:53
@abohay what is that challenge name
ahmed abouhay
@abohay
Aug 20 2016 03:54
@friscodisco seek and destroy
Chris Cullen
@123xylem
Aug 20 2016 03:55
@abohay i dont know what your question is or what your trying to do, not that im the best to answer it anyway
friscodisco
@friscodisco
Aug 20 2016 03:56
@abohay I would try to incorporate .slice into your solution
kimstopmik
@kimstopmik
Aug 20 2016 03:58
sorry, not that far yet @abohay
friscodisco
@friscodisco
Aug 20 2016 03:58
@abohay actually the wiki solution uses both .slice and .splice
Ken Aguilar
@piq9117
Aug 20 2016 03:59

@123xylem you can add a condition

var mouseDown = false
$(your button).on('mousedown keypress', function(event) {
    mouseDown = true;
    doSomething();
});

you also need a condition for mouseup.. i think..

Chris Cullen
@123xylem
Aug 20 2016 04:00
@piq9117 thanks il look into it
CamperBot
@camperbot
Aug 20 2016 04:00
123xylem sends brownie points to @piq9117 :sparkles: :thumbsup: :sparkles:
:cookie: 272 | @piq9117 |http://www.freecodecamp.com/piq9117
Ken Aguilar
@piq9117
Aug 20 2016 04:03
:thumbsup:
sfmajors373
@sfmajors373
Aug 20 2016 04:06
Hi, I am in JS basic in Nested for loops but it is failing, and I'm not sure why. This is what I have so far:

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

  // Only change code above this line
  return product;
}}}
Elbert Cortez
@trip16661
Aug 20 2016 04:13
@sfmajors373 product * i
you are just multiplying for the index ...
Joseph
@revisualize
Aug 20 2016 04:14
@sfmajors373 You're missing part. Let me get you a Gist that I wrote up.
Elbert Cortez
@trip16661
Aug 20 2016 04:14
so [1,1,1,1] will be the same as {[20],[20],[20],[20]}
which is obviously wrong
Joseph
@revisualize
Aug 20 2016 04:15
@sfmajors373 It's a lot of text. But, you'll understand it.. https://gist.github.com/revisualize/fdc7f63fccdfd83739d33307b6dbc453
sfmajors373
@sfmajors373
Aug 20 2016 04:15
@trip16661 Oh! So, it isn't incrementing it!
Joseph
@revisualize
Aug 20 2016 04:15
so [[1],[1],[1],[1]] will be the same as {[20],[20],[20],[20]}
sfmajors373
@sfmajors373
Aug 20 2016 04:16
@revisualize Thanks, I'll read that, it looks like it will help!
CamperBot
@camperbot
Aug 20 2016 04:16
sfmajors373 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 1687 | @revisualize |http://www.freecodecamp.com/revisualize
Ken Aguilar
@piq9117
Aug 20 2016 04:16
@abohay you would want to use filter
Norvin Burrus
@ndburrus
Aug 20 2016 04:16
@sfmajors373 :sparkles:
  • the increment for the outer array is i++, while j++ for the inner array
  • product is multiplied by the iterated value, arr[i][j]
Joseph
@revisualize
Aug 20 2016 04:17
@sfmajors373 Refresh, I just corrected an error.
Elbert Cortez
@trip16661
Aug 20 2016 04:17
you can increment it by whatever u want but in this challenge you need to increment it by one
but thats not the point
sfmajors373
@sfmajors373
Aug 20 2016 04:19
@trip16661 Ok, thank you!
CamperBot
@camperbot
Aug 20 2016 04:19
sfmajors373 sends brownie points to @trip16661 :sparkles: :thumbsup: :sparkles:
:cookie: 457 | @trip16661 |http://www.freecodecamp.com/trip16661
Joseph
@revisualize
Aug 20 2016 04:20
@sfmajors373 If you have any issues or confusion with that text. Please let me know, I want to clarify and make it easier for people to understand completely. It is a different concept to work through that challenge.
sfmajors373
@sfmajors373
Aug 20 2016 04:22
@revisualize I will definitely do that. I really appreciate it.
krupa007
@krupa007
Aug 20 2016 04:24
Increment a Number with JavaScript ... myVar should equal 88
myVar = myVar should be changed
i am unable to run the code
var myVar=88;
myVar++;
Joseph
@revisualize
Aug 20 2016 04:25
This message was deleted
Ken Aguilar
@piq9117
Aug 20 2016 04:25
myVarr++ // post increment
++myVar // pre increment
krupa007
@krupa007
Aug 20 2016 04:25
should i used pre-increment also?
Ken Aguilar
@piq9117
Aug 20 2016 04:26
@krupa007 experiment. thats how i learned :)
Joseph
@revisualize
Aug 20 2016 04:26
@krupa007 No. You're incrementing the value twice. You're making it 88 then with the ++ making it 89
@krupa007 Look at the code bit that I posted. And read the comments.
swapnildaddikar
@swapnildaddikar
Aug 20 2016 04:27
function destroyer(arr) {

  var x=[];

  var array=[];

for(var y=1;y<arguments.length;y++)
  {
    x[y-1]=arguments[y];

  }



  array=arr.filter(function(val1)
                   {

    return (val1!==x[0]&&val1!==x[1]&&val1!==x[2]);//want to generalize this function for any number of arguments .. works for 3
  });
  return array;


}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
guys i want to generalize the above loop for any number of arguments
please help me do that
ive commented the loop which i want togeneralize
krupa007
@krupa007
Aug 20 2016 04:28
okay @revisualize i'll check
swapnildaddikar
@swapnildaddikar
Aug 20 2016 04:29
someone help pls
Joseph
@revisualize
Aug 20 2016 04:29
@krupa007
var num = 5;
num = num + 1; // 6
num += 1; // 7
num++; // 8
krupa007
@krupa007
Aug 20 2016 04:29
thanks @piq9117
CamperBot
@camperbot
Aug 20 2016 04:29
krupa007 sends brownie points to @piq9117 :sparkles: :thumbsup: :sparkles:
:cookie: 274 | @piq9117 |http://www.freecodecamp.com/piq9117
Ken Aguilar
@piq9117
Aug 20 2016 04:31
:thumbsup:
krupa007
@krupa007
Aug 20 2016 04:32
(y)
:+1:
swapnildaddikar
@swapnildaddikar
Aug 20 2016 04:36
guys some help pleasd
Chris Cullen
@123xylem
Aug 20 2016 04:40
http://codepen.io/123xylem/pen/AXwwPj
Ive finished it!! Please Review my POMODORO!
sfmajors373
@sfmajors373
Aug 20 2016 04:41
@revisualize Your Gist helped a lot. I think I am much closer than I was now. I understand for loops in other python, so I don't understand why I am having such a hard time learning them in JS, but I am stuck on something. What part of it am I still missing?
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 = product * arr[i][j];
  // Only change code above this line
  return product;
}}}
swapnildaddikar
@swapnildaddikar
Aug 20 2016 04:42
ur looping is wrong
all 3 loops have been ended together??
the inner loop of j should execute arr[i] number of times
see whats happening in ur case
its executing once and returning
@sfmajors373
sfmajors373
@sfmajors373
Aug 20 2016 04:44
@swapnildaddikar Yes, Where can I end the loop to stop it from ending there?
End it right after the product?
swapnildaddikar
@swapnildaddikar
Aug 20 2016 04:45
yes the inner loop should end right after prpoduct
the 1st loop of i should end after the 2nd one
then comes return product
and then end of the function loop
sfmajors373
@sfmajors373
Aug 20 2016 04:45
@swapnildaddikar That fixed it! Thank you!
CamperBot
@camperbot
Aug 20 2016 04:45
sfmajors373 sends brownie points to @swapnildaddikar :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for swapnildaddikar
swapnildaddikar
@swapnildaddikar
Aug 20 2016 04:46
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 = product * arr[i][j];
}
}
  // Only change code above this line
  return product;
}
something like this :D
sfmajors373
@sfmajors373
Aug 20 2016 04:46
Thanks :D I am still struggling to pick up some of the details.
swapnildaddikar
@swapnildaddikar
Aug 20 2016 04:46
yes so am i :D
we are all learners
sfmajors373
@sfmajors373
Aug 20 2016 04:47
Oh good. I think I will be learning for a long time..
swapnildaddikar
@swapnildaddikar
Aug 20 2016 04:48
yes me too :D
i also just started javascript
without any prior knowledge in coding
sfmajors373
@sfmajors373
Aug 20 2016 04:49
I just started, and I only know a very little bit of python
swapnildaddikar
@swapnildaddikar
Aug 20 2016 04:49
ohh thats great
Joseph
@revisualize
Aug 20 2016 04:50
@sfmajors373 I'm glad it helped. :)
Suraj Prasad
@suraj18gts
Aug 20 2016 04:55
anyo0ne tell e about Stand in Line
swapnildaddikar
@swapnildaddikar
Aug 20 2016 04:56
stand in line?
Suraj Prasad
@suraj18gts
Aug 20 2016 04:56
yes
swapnildaddikar
@swapnildaddikar
Aug 20 2016 04:56
link to the question

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

return item; // Change this line
}

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

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

this is the code
how nextInLine([2], 1) should return 2
??
swapnildaddikar
@swapnildaddikar
Aug 20 2016 05:00
yes its easy @suraj18gts
ill explain
Suraj Prasad
@suraj18gts
Aug 20 2016 05:00
how
swapnildaddikar
@swapnildaddikar
Aug 20 2016 05:00
so we have 4 basic functions u can do with an array
do u know them?
@suraj18gts
Suraj Prasad
@suraj18gts
Aug 20 2016 05:01
no
sum, sub, mul, div ??
swapnildaddikar
@swapnildaddikar
Aug 20 2016 05:01
no @suraj18gts
u have read about it previous tutorials
Suraj Prasad
@suraj18gts
Aug 20 2016 05:01
then??
swapnildaddikar
@swapnildaddikar
Aug 20 2016 05:02
they are
Push
Pop
Shift
Unshift
do u remember?
Suraj Prasad
@suraj18gts
Aug 20 2016 05:02
ya ya
swapnildaddikar
@swapnildaddikar
Aug 20 2016 05:02
ok so do u know what each keyword does?
Suraj Prasad
@suraj18gts
Aug 20 2016 05:02
ya
swapnildaddikar
@swapnildaddikar
Aug 20 2016 05:02
ok cool
so now lets go t the problem statement
we are given two arguments
arr and item right?
Suraj Prasad
@suraj18gts
Aug 20 2016 05:03
yes
swapnildaddikar
@swapnildaddikar
Aug 20 2016 05:03
okay
so what we have to do?
we have to add an element to the end of the arr
so here in this question we have to add item to end of the array
can u think of the above 4 basic functions which can do that?
which 1 of it is suitable of pushing an element to the end of the array
Suraj Prasad
@suraj18gts
Aug 20 2016 05:04
push and pop
swapnildaddikar
@swapnildaddikar
Aug 20 2016 05:04
@suraj18gts
yes u are partially right
push is the right answer
pop removes the last element
so u have to push item to the end of the array
Suraj Prasad
@suraj18gts
Aug 20 2016 05:05
oo
swapnildaddikar
@swapnildaddikar
Aug 20 2016 05:05
so how will u write it?
do u know the syntax?
Suraj Prasad
@suraj18gts
Aug 20 2016 05:05
no
swapnildaddikar
@swapnildaddikar
Aug 20 2016 05:05
:(
okay
ill tell u
arrayname.push(the value u want to push);
so here the array name is arr and value to push is item
arr.push(item);
this will complete the 1st problem
they also want to remove the 1st element
and return that element
Suraj Prasad
@suraj18gts
Aug 20 2016 05:06
where to use this code
swapnildaddikar
@swapnildaddikar
Aug 20 2016 05:06
now tell me which function works
i wont tell u that
if i tell u wont learn
its tough at start but u have to go through the sections of push pop shift and unshift
so the 2nd part of the question remains
we have to remove the 1st ewlement
which function works in a way that it removes the 1st element
?
can u tell
christianws
@christianws
Aug 20 2016 05:11
Yo for the quote machine app I can't seem to upload my project to github! Github pages only inputs through https and forismatic uses http... has anyone found a way around this??
Suraj Prasad
@suraj18gts
Aug 20 2016 05:11
i can't get that
pahosler
@pahosler
Aug 20 2016 05:11
use ssh
christianws
@christianws
Aug 20 2016 05:11
@pahosler ssh?
pahosler
@pahosler
Aug 20 2016 05:12
secure shell
that's ok, I'm not sure what a forismatic is
This message was deleted
christianws
@christianws
Aug 20 2016 05:13
@pahosler forismatic is an api for delivering a random quote - it is used as part of one of the challenges but seems to only want to output through http,
http://forismatic.com/en/api/
Suraj Prasad
@suraj18gts
Aug 20 2016 05:13
???
pahosler
@pahosler
Aug 20 2016 05:13
you're using a Mac?
Suraj Prasad
@suraj18gts
Aug 20 2016 05:14
???? @swapnildaddikar
pahosler
@pahosler
Aug 20 2016 05:15
so what does that have to do with putting your repository on github, do you mean you are trying to use the webpage server?
edison sim
@Edisonsim
Aug 20 2016 05:15
how to i write a schema for answered (boolean), which is set to default false? using nodejs
Suraj Prasad
@suraj18gts
Aug 20 2016 05:16
?
Chris Kissoon
@ChrisKissoon
Aug 20 2016 05:16
Hey guys for the nested for loop section can someone explain to me how it works i just cant understand how when i alerted both the values of i and j the results come out like 1,2,3,4,5,6 (what the array had) how is one value coming out at a time even though i alerted both i and j
swapnildaddikar
@swapnildaddikar
Aug 20 2016 05:17
its shift @suraj18gts now try to write it
edison sim
@Edisonsim
Aug 20 2016 05:17
im writing a mongoose schema but not sure how do i do it
pahosler
@pahosler
Aug 20 2016 05:17
@CurlyWS are you trying to get your quotemachine working in github.io? or just trying to upload your code to the repo?
Suraj Prasad
@suraj18gts
Aug 20 2016 05:17
how??
swapnildaddikar
@swapnildaddikar
Aug 20 2016 05:17
u have to figure that out
Chris Kissoon
@ChrisKissoon
Aug 20 2016 05:17
var arr = [
  [1,2], [3,4], [5,6]
];
for (var i=0; i < arr.length; i++) {
  for (var j=0; j < arr[i].length; j++) {
    console.log(arr[i][j]);
  }
}
swapnildaddikar
@swapnildaddikar
Aug 20 2016 05:17
go through the lessons of sift unshift pop and push
u can solve it easily
jst read them once again
Suraj Prasad
@suraj18gts
Aug 20 2016 05:18
k
christianws
@christianws
Aug 20 2016 05:18
@pahosler github.io
pahosler
@pahosler
Aug 20 2016 05:18
ah, then you might have to choose a different api
use wikiquotes
Ken Aguilar
@piq9117
Aug 20 2016 05:19
@Edisonsim

const mongoose = require('mongoose');

const bearSchema = {
  name: { type: String, required: true }
};

const schema = new mongoose.Schema(bearSchema);

schema.set('toObject', { virtuals: true });
schema.set('toJSON', { virtuals: true })

module.exports = schema;
pahosler
@pahosler
Aug 20 2016 05:19
or see if forismatic has a secure server you can get the api from
https
edison sim
@Edisonsim
Aug 20 2016 05:20
@piq9117 thanks man
CamperBot
@camperbot
Aug 20 2016 05:20
edisonsim sends brownie points to @piq9117 :sparkles: :thumbsup: :sparkles:
:cookie: 275 | @piq9117 |http://www.freecodecamp.com/piq9117
Ken Aguilar
@piq9117
Aug 20 2016 05:20
:thumbsup:
pahosler
@pahosler
Aug 20 2016 05:24
@CurlyWS forismatic doesn't do https and you can't access it from github.io... probably
christianws
@christianws
Aug 20 2016 05:24
@pahosler thanks but they don't have that option. I found a solution on another chat -> you can append this to your url -> https://crossorigin.me/
CamperBot
@camperbot
Aug 20 2016 05:25
curlyws sends brownie points to @pahosler :sparkles: :thumbsup: :sparkles:
:cookie: 356 | @pahosler |http://www.freecodecamp.com/pahosler
christianws
@christianws
Aug 20 2016 05:25
pahosler
@pahosler
Aug 20 2016 05:27
awesome, I'l have to check the crossorigin thing...
bookmarked
my quotemachine was slightly more whimsical http://pahosler.comuf.com/quotemachine/
arif hussain
@arifhussain0
Aug 20 2016 05:33
hello .. need to ask that what do i have to do in Everthing Be True exercise. i don't understand what do is objective of this exercise?
pahosler
@pahosler
Aug 20 2016 05:38
help everything be true
CamperBot
@camperbot
Aug 20 2016 05:38
no wiki entry for: everything be true
friscodisco
@friscodisco
Aug 20 2016 05:41
and we're gonna let the ubercars do the driving for us!
pahosler
@pahosler
Aug 20 2016 05:42

every thing... Check if the predicate (second argument) is truthy on all elements of a collection (first argument).

Remember, you can access object properties through either dot notation or [] notation.

LOL
Suraj Prasad
@suraj18gts
Aug 20 2016 05:43
@swapnildaddikar i have understand the push and unshift fucntion but cant get where to write those code
pahosler
@pahosler
Aug 20 2016 05:43
@arifhussain0 what part do you not understand?
Manish Giri
@Manish-Giri
Aug 20 2016 05:44
@suraj18gts you write the code in the body of the given function, there’s probably a comment saying
//write your code below this line
Suraj Prasad
@suraj18gts
Aug 20 2016 05:44
@Manish-Giri

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

return item[2]; // Change this line
}

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

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

pahosler
@pahosler
Aug 20 2016 05:45
@arifhussain0 you have a collection [{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}]
Manish Giri
@Manish-Giri
Aug 20 2016 05:45
@suraj18gts write your code after the line //your code here
Suraj Prasad
@suraj18gts
Aug 20 2016 05:45
thats the function
pahosler
@pahosler
Aug 20 2016 05:45
and you have an argument pre "sex"
Manish Giri
@Manish-Giri
Aug 20 2016 05:45
@suraj18gts ?
pahosler
@pahosler
Aug 20 2016 05:46
@arifhussain0 does each set in the object have a property called sex and is it set...
return true or false
Suraj Prasad
@suraj18gts
Aug 20 2016 05:46
i have written the code but it says that maximum call stack size exceeded
Manish Giri
@Manish-Giri
Aug 20 2016 05:47
@suraj18gts show your code, & please tag when responding. Helps notify the user.
Suraj Prasad
@suraj18gts
Aug 20 2016 05:47
@Manish-Giri ??
Manish Giri
@Manish-Giri
Aug 20 2016 05:48
@suraj18gts your code?
pahosler
@pahosler
Aug 20 2016 05:48
Manish Giri
@Manish-Giri
Aug 20 2016 05:48
@suraj18gts did you use the .push() and .shift() functions?
Suraj Prasad
@suraj18gts
Aug 20 2016 05:48
@Manish-Giri nextInLine.push(2)
Norvin Burrus
@ndburrus
Aug 20 2016 05:49
@suraj18gts :sparkles:
carefully review the methods you'd like to use. this may be helpful: :sparkles:
pahosler
@pahosler
Aug 20 2016 05:49
my code for everything be true is funny because I ran with the whole teletubby thing
Manish Giri
@Manish-Giri
Aug 20 2016 05:49
@suraj18gts why are you writing 2 in .push()
Ken Aguilar
@piq9117
Aug 20 2016 05:49
camperbot make me a sandwhich
sudo camperbot make me a sandwhich
Manish Giri
@Manish-Giri
Aug 20 2016 05:50
@piq9117 try cbot
pahosler
@pahosler
Aug 20 2016 05:50
@piq9117 you're a sandwich
Ken Aguilar
@piq9117
Aug 20 2016 05:50
lol
Suraj Prasad
@suraj18gts
Aug 20 2016 05:50
what shall i do..
??
pahosler
@pahosler
Aug 20 2016 05:51
just don't ask it to start slapping people in the face with a carp!
old IRC joke....
Manish Giri
@Manish-Giri
Aug 20 2016 05:51
@suraj18gts do you understand the tasks required?
Ken Aguilar
@piq9117
Aug 20 2016 05:52
cbot
CamperBot
@camperbot
Aug 20 2016 05:52
you called?
Ken Aguilar
@piq9117
Aug 20 2016 05:52
cbot self destruct
CamperBot
@camperbot
Aug 20 2016 05:52
you called?
Ken Aguilar
@piq9117
Aug 20 2016 05:52
cbot initiate self destruct sequence
CamperBot
@camperbot
Aug 20 2016 05:52
you called?
Darth Skywalker
@adityaparab
Aug 20 2016 05:53
cbot is a troll
CamperBot
@camperbot
Aug 20 2016 05:53
you called?
pahosler
@pahosler
Aug 20 2016 05:53
LOL
Ken Aguilar
@piq9117
Aug 20 2016 05:53
cbot run this
sudo rm -rf /
CamperBot
@camperbot
Aug 20 2016 05:53
you called?
pahosler
@pahosler
Aug 20 2016 05:53
you forgot the *
you should try to run that @piq9117
Ken Aguilar
@piq9117
Aug 20 2016 05:54
I'll do it after you
pahosler
@pahosler
Aug 20 2016 05:55
try this instead dd if=/dev/null of=/dev/sda1
Ken Aguilar
@piq9117
Aug 20 2016 05:57
you should try this
ping -c 55000 -s 55000 pahosler.comuf.com
pahosler
@pahosler
Aug 20 2016 05:58
not my server so have fun :D
actually the /dev/null thing won't work, but it looks funny and plausible
Ken Aguilar
@piq9117
Aug 20 2016 06:00
lol.. tired of DoS
pahosler
@pahosler
Aug 20 2016 06:02
what part of Tejas are you in @piq9117 I used to live in Houston, and Galveston
Ken Aguilar
@piq9117
Aug 20 2016 06:03
way bottom down the bottom.. lol.. 15 mins away from the border..
This message was deleted
Suraj Prasad
@suraj18gts
Aug 20 2016 06:07

@Manish-Giri
function nextInLine(arr, item) {
// Your code here

return testArr.shift(); // Change this line
}

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

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

this is correct??
Manish Giri
@Manish-Giri
Aug 20 2016 06:09
@suraj18gts kind of, here are a few things for you to note
  1. You need to work with the array arr, not testArr
  2. You first need to add the variable item to the end of arr using .push()
  3. Your last statement is correct, but use arr instead of testArr
Ken Aguilar
@piq9117
Aug 20 2016 06:11
let arr = [1,2,3]
arr.push(4) // 4, new length of arr
arr // [1,2,3,4]
Ken Aguilar
@piq9117
Aug 20 2016 06:24
let arr = ['firstElement', 'secondElement', 'thirdElement']
arr.shift() // returns 'firstElement'
Toyco
@Toyco
Aug 20 2016 07:22
Why is this not returning a number when testing? function convertToF(celsius) {
var fahrenheit;
// Only change code below this line
fahrenheit *= 9;
fahrenheit /= 5;
fahrenheit += 32;
Vivienne Sales
@Natto278
Aug 20 2016 07:23
Hi Everyone. I took some time off, did some research and reviewed my notes. Here is my latest code for Profile Lookup. Why isn't this code not meeting the requirements of this challenge? Thanks in advance for your assistance: for (var i=0; i < contacts.length; i++) {
if (contacts[i].firstName === firstName) //Checks to see if the firstName matches any of the given names in the array , "contacts"
if (contacts[i].prop === prop) //Checks to see if the property matches any of the given properties in the array
return contacts[i][firstName][prop]; //If the firstName and the property match, show the results
else { // otherwise if the given name doesn't match any in the "contacts" array of objects
return "No such contact"; //show this message
}
else { // If the property doesn't match any of the properties in "contacts
return "No such property"; //show this message
}
}
}
greg
@wearenotgroot
Aug 20 2016 07:24
@Toyco do you have a return fahrenheit somewhere?
Toyco
@Toyco
Aug 20 2016 07:24
yes below it
even having only farenheit *=9; makes it return null
Aditya
@ezioda004
Aug 20 2016 07:24
@Toyco Because you didnt initialize the value of fahrenheit, so its simply undefined and undefined * any_number = undefined
Vivienne Sales
@Natto278
Aug 20 2016 07:25
@Toyco You need to write a series of code that will answer the question. Do you know the formula to convert Celsius to Fahrenheit?
Toyco
@Toyco
Aug 20 2016 07:25
oh I thought it ran tests with a number already
greg
@wearenotgroot
Aug 20 2016 07:25
@Toyco you need to initialise your fahrenheit variable
Vivienne Sales
@Natto278
Aug 20 2016 07:25
@Toyco You need to create a variable id for fahrenheit.
@Toyco You'll also need to create a variable for the decimal value 1.8.
greg
@wearenotgroot
Aug 20 2016 07:27
@Natto278 remember this------> contacts[i].prop will give you the value(will not actually work because there isnt a property named prop(literal)) and comparing it to prop(function parameter/argument) will always give you the wrong result
Toyco
@Toyco
Aug 20 2016 07:27
Got it guy, thanks =)
greg
@wearenotgroot
Aug 20 2016 07:29
@Natto278 if you wanted to test is a property exist then use .hasOwnProperty instead
docs hasOwnProperty
Vivienne Sales
@Natto278
Aug 20 2016 07:29
@wearenotgroot So, I should get rid of the line (contacts.[i].prop===prop)?
greg
@wearenotgroot
Aug 20 2016 07:29
@Natto278 replace it with
if(contacts.[i].hasOwnProperty(prop))
Vivienne Sales
@Natto278
Aug 20 2016 07:32
@Toyco Remember to write Thanks @UserNamesOfThoseWhoHelpedYouCompleteTheConvertCelsiusToFahrenheitChallenge :-)
CamperBot
@camperbot
Aug 20 2016 07:32
natto278 sends brownie points to @toyco and @usernamesofthosewhohelpedyoucompletetheconvertcelsiustofahrenheitchallenge :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for usernamesofthosewhohelpedyoucompletetheconvertcelsiustofahrenheitchallenge
:cookie: 150 | @toyco |http://www.freecodecamp.com/toyco
Brendan Kinahan
@BKinahan
Aug 20 2016 07:34

could not find receiver for usernamesofthosewhohelpedyoucompletetheconvertcelsiustofahrenheitchallenge

Never change, @camperbot

greg
@wearenotgroot
Aug 20 2016 07:34
@Natto278 here what you need to do in this challenge
  • check firstName of each contact in the contacts array vs the function argument 'firstName'
  • check if the property prop exist, using .hasOwnProperty
  • make sure that you check the entire contacts array before returning 'No such contact'
Vivienne Sales
@Natto278
Aug 20 2016 07:34
@wearenotgroot I did as you said, but I'm still having problems for (var i=0; i < contacts.length; i++) {
if (contacts[i].firstName === firstName) //Checks to see if the firstName matches any of the given names in the array , "contacts"
if (contacts[i].hasOwnProperty(prop)) //Checks to see if the property matches any of the given properties in the array
return contacts[i].firstName.hasOwnProperty(prop); //If the firstName and the property match, show the results
else { // otherwise if the given name doesn't match any in the "contacts" array of objects
return "No such contact"; //show this message
}
else { // If the property doesn't match any of the properties in "contacts
return "No such property"; //show this message
}
}
}
greg
@wearenotgroot
Aug 20 2016 07:35
@Natto278
  • make sure that you check the entire contacts array before returning 'No such contact'
@Natto278 also check your current if structure
@Natto278
if contact's firstName equal firstName
     if contacts in ith hasOwnProperty prop
            //return the value (using prop as key) <---- object lookup
     else
           //should return 'No such property'
end if

@Natto278 what does this do?

contacts[i].firstName.hasOwnProperty(prop);

contacts[i].firstName will give a name (string) so using hasOwnProperty(prop) on it will do you no good

edison sim
@Edisonsim
Aug 20 2016 07:40
Hi guys how do i write this in mongoose model? questions_by_date method
Vivienne Sales
@Natto278
Aug 20 2016 07:41
@wearenotgroot I was hoping that would show the results of looking up the results
greg
@wearenotgroot
Aug 20 2016 07:41
@Natto278 how do you usually access a value from an object?(using a key right) either .(dot) notation or a bracket notation
Vivienne Sales
@Natto278
Aug 20 2016 07:42
@wearenotgroot To access a value from an object, don't you have use dot notation?
greg
@wearenotgroot
Aug 20 2016 07:43
@Natto278 remember when dealing with variables you use bracket notation instead.

@Natto278 example

contacts[i].firstName  //<------this lookup works because there is a property literally named firstName in contacts[i]

but with

contacts[i].prop //<---------this will give you no result since there isnt a property literally named prop in contacts[i]

so instead you use bracket notation when dealing with variables/parameters

Vivienne Sales
@Natto278
Aug 20 2016 07:46
@wearenotgroot With all the hints you have given me, I'm going to review my previous JS notes and hit the paper notebook to write some new code.! Thank you for your hints!
CamperBot
@camperbot
Aug 20 2016 07:46
natto278 sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star2: 1412 | @wearenotgroot |http://www.freecodecamp.com/wearenotgroot
greg
@wearenotgroot
Aug 20 2016 07:47
@Natto278 np
Cristty
@cristix415
Aug 20 2016 07:49

'''
function sumFibs(num) {
var arr=[];
for ( i=0; i<=num; i++)
{
if (i%2 !== 0) {
arr.push(i);

  }
}

return arr;
}

sumFibs(10);
'''
What wrong with this code? When I run it, my browser is stuck

CamperBot
@camperbot
Aug 20 2016 07:49
:bulb: to format code use backticks! ``` more info
Cristty
@cristix415
Aug 20 2016 07:51
function sumFibs(num) {
  var arr=[];
  for ( i=0; i<=num; i++)
    {
      if (i%2 !== 0) {
        arr.push(i);

      }
    }

  return arr;
}

sumFibs(10);
What wrong with this code? When I run it, my browser is stuck
Aditya
@ezioda004
Aug 20 2016 07:54
@cristix415 Code works fine in my browser
friscodisco
@friscodisco
Aug 20 2016 08:03
@cristix415 r u using safari
jamesmillerho
@jamesmillerho
Aug 20 2016 08:18
@cristix415 because there is a test sumFibs(4000000) should return 4613732
@cristix415 return arr means returning an arr.length of 2 million
Glenn
@IntoTheQCD
Aug 20 2016 08:18
hey i'm having a problem with one of the javascript challenges
jamesmillerho
@jamesmillerho
Aug 20 2016 08:19
@cristix415 in this case, you shouldn't run code. But you can assume that the array is created and continue coding with that array
@cristix415 just make sure the thing you return isn't something too large
Adam Jubert
@adamjubert
Aug 20 2016 08:20

Hey everyone. I'm working on Switch Statements. What am I doing wrong here?

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

caseInSwitch(1);

jamesmillerho
@jamesmillerho
Aug 20 2016 08:20
@IntoTheQCD which
Takács Ádám
@AdamTakacs05
Aug 20 2016 08:22
Hi everyone, sorry for disturbing! I have problems with WordBlanks JS challange! I'm not sure what the challange wants me to do! What I've tried is that I declared the given variables with words of my choice then I made the result sentence to put them together but it wont accept it, i dont know what should i use the given words for or how! Can anyone help me int his?
jamesmillerho
@jamesmillerho
Aug 20 2016 08:22
@adamjubert you miss the switch() statement
Olga C
@Octopinky
Aug 20 2016 08:22
@AdamTakacs05 post your code here
Takács Ádám
@AdamTakacs05
Aug 20 2016 08:22
I already cleared it but give me a minute to redo it!
Olga C
@Octopinky
Aug 20 2016 08:23
@AdamTakacs05 sure
Adam Jubert
@adamjubert
Aug 20 2016 08:23
@jamesmillerho Thank you! That section did a bit of a weird job explaining. Solved my problem.
CamperBot
@camperbot
Aug 20 2016 08:23
adamjubert sends brownie points to @jamesmillerho :sparkles: :thumbsup: :sparkles:
:cookie: 382 | @jamesmillerho |http://www.freecodecamp.com/jamesmillerho
Olga C
@Octopinky
Aug 20 2016 08:23
@adamjubert good job!
Glenn
@IntoTheQCD
Aug 20 2016 08:23
it's the challenge with \n
Olga C
@Octopinky
Aug 20 2016 08:24
@adamjubert I was just about to mention the switch statement, when it all got resolved
@IntoTheQCD lol, post your code
Adam Jubert
@adamjubert
Aug 20 2016 08:24
Thanks Olga :)
Olga C
@Octopinky
Aug 20 2016 08:24
@adamjubert wheee!
Glenn
@IntoTheQCD
Aug 20 2016 08:25
var myStr = "FirstLine"\n\n"\n"\SecondLine\"n\"; /
i've gotten that far and it's throwing errors
Olga C
@Octopinky
Aug 20 2016 08:25
@IntoTheQCD where is your third line?
Glenn
@IntoTheQCD
Aug 20 2016 08:26
i figured it'd be "FirstLine"\n"\SecondLine\"\n"ThirdLine"
Olga C
@Octopinky
Aug 20 2016 08:26
@IntoTheQCD well, the third line is not in the code that you posted
Takács Ádám
@AdamTakacs05
Aug 20 2016 08:26
@Octopinky myNoun="fish";
myAdjective="fat";
myVerb="flipped";
myAdverb="clumsy";
result="Yesterday,my " +myNoun+" who is really"+myAdjective+" of his tank"+myVerb+"in a "+myAdverb+" way!";
Olga C
@Octopinky
Aug 20 2016 08:26
@IntoTheQCD you are close though
Glenn
@IntoTheQCD
Aug 20 2016 08:27
lemme try again
Olga C
@Octopinky
Aug 20 2016 08:27
@AdamTakacs05 this is gramatically incorrect sentence
manusia123
@manusia123
Aug 20 2016 08:27

function getIndexToIns(arr, num) {


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


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

}

getIndexToIns([40,70, 60], 50);
can anybody tell me where did i do wrong ?
jamesmillerho
@jamesmillerho
Aug 20 2016 08:27
@AdamTakacs05
you don't need to put these
myNoun="fish";
myAdjective="fat";
myVerb="flipped";
myAdverb="clumsy"
@AdamTakacs05 because when you call the function
fuction("fish", "fat", "flipped", "clumsy")
It works in this way
Takács Ádám
@AdamTakacs05
Aug 20 2016 08:28
@Octopinky Yes I know that, that would tke more time to check it for me since Im Hungarian, Im sory bout that but Im sure its not the grammar what is wrong here
Glenn
@IntoTheQCD
Aug 20 2016 08:29
var myStr = "FirstLine"\n"\SecondLine\"\n"ThirdLine"
Olga C
@Octopinky
Aug 20 2016 08:29
@AdamTakacs05 what is wrong there then?
friscodisco
@friscodisco
Aug 20 2016 08:29
@manusia123 what is the name of that challenge
Olga C
@Octopinky
Aug 20 2016 08:30
@IntoTheQCD you need more backslashes around second line
Takács Ádám
@AdamTakacs05
Aug 20 2016 08:30
@jamesmillerho ok I get them out but if so where should I put the new words? and how?
@Octopinky It wont accept the challange!
manusia123
@manusia123
Aug 20 2016 08:30
@friscodisco where do i belong from basic algorithm scripting
jamesmillerho
@jamesmillerho
Aug 20 2016 08:30
@manusia123 arr[i] >= num ``> vs >=
@manusia123 and at the end return arr.length if num > all arr[i]
Olga C
@Octopinky
Aug 20 2016 08:31
@manusia123 what is the code supposed to do? It returns 1 for me
@AdamTakacs05 what challenge?
jamesmillerho
@jamesmillerho
Aug 20 2016 08:32
@AdamTakacs05 the challenge says should contain all of the passed in words separated by non-word characters so just put space between them
manusia123
@manusia123
Aug 20 2016 08:32
@jamesmillerho thanks its working @Octopinky its supposed to sort the array first and second is to put the second parameter in the array
CamperBot
@camperbot
Aug 20 2016 08:32
manusia123 sends brownie points to @jamesmillerho and @octopinky :sparkles: :thumbsup: :sparkles:
:cookie: 383 | @jamesmillerho |http://www.freecodecamp.com/jamesmillerho
:cookie: 324 | @octopinky |http://www.freecodecamp.com/octopinky
friscodisco
@friscodisco
Aug 20 2016 08:33
@manusia123 you also need to change your var i to use var a and to return a
Olga C
@Octopinky
Aug 20 2016 08:33
@manusia123 you need to add another variable in this code
jamesmillerho
@jamesmillerho
Aug 20 2016 08:34
var i = local variable = i only works in this function
i = public = works everywhere
Takács Ádám
@AdamTakacs05
Aug 20 2016 08:35
Thank you very much I passed it, what I thouth for some reason is that I have to put new words in as well and make the scrypt randomly choose one them! @jamesmillerho @Octopinky
CamperBot
@camperbot
Aug 20 2016 08:35
adamtakacs05 sends brownie points to @jamesmillerho and @octopinky :sparkles: :thumbsup: :sparkles:
:cookie: 384 | @jamesmillerho |http://www.freecodecamp.com/jamesmillerho
:cookie: 325 | @octopinky |http://www.freecodecamp.com/octopinky
Mostafa Syam
@pro-mos
Aug 20 2016 08:37
This message was deleted
Reg
@Involver0
Aug 20 2016 08:56
Hell everyone, I stuck with escape sequences in String
can anyone give me a hand?
Takács Ádám
@AdamTakacs05
Aug 20 2016 08:58
@involver0 Is that the one with 3 lines? First line second line and such?
Reg
@Involver0
Aug 20 2016 08:58
yes
it should be easy but I dont understand something
:)
Takács Ádám
@AdamTakacs05
Aug 20 2016 09:00
I dont know why but i menaged to do with \r as it writes in the challange so
"FirstLine\n\SecondLine\\rThird line" something like that, \r is carriage return but dont ask me why to use it
sry two slashes befor second lin \
and aafter
Reg
@Involver0
Aug 20 2016 09:04
Can you copy all variable ?
because I done same as you but havent pass :)
Takács Ádám
@AdamTakacs05
Aug 20 2016 09:06
@Involver0 "FirstLine\n\SecondLine\\rThirdLine"
wait this where real coding comes in i can paste it i dont know why
so
"FirstLine\n
\SecondLine\
I cant :D basically after first line add new line escape then backslash escape after second line backslash escape and carriage return which is \r then
third line
Reg
@Involver0
Aug 20 2016 09:09
Ok I will try my luck :)
Sreenivasa .B
@Sree-001
Aug 20 2016 09:10
I hava a problem In problem named: Make Object Properties Private . I had made necessary changes in Bike Constructor even then it is not getting accepted . can any help me out find the fault.
the code is as follows

var Bike = function() {

var gear;

this.setGear=function(gear){

 this.gear=gear;
return gear;

};

this.getGear=function() {
this.setGear(gear);

};

};

var myCar = new Car();

var myBike = new Bike();

pahosler
@pahosler
Aug 20 2016 09:14
help make-object-properties-private
CamperBot
@camperbot
Aug 20 2016 09:14
no wiki entry for: make object properties private
pahosler
@pahosler
Aug 20 2016 09:15
grrrr
Anand Kumar
@anandjha1806
Aug 20 2016 09:15
I can't understand it "wordBlanks("dog", "big", "ran", "quickly") should contain all of the passed in words separated by non-word characters (and any additional words in your madlib)."
Freddie O
@FreddieFO
Aug 20 2016 09:17

Hi guys I need help with the Stand in Line challenge, this is it described "Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.”

This is my solution which appeared to be wrong;
function nextInLine(arr, item) {
arr.push(item);
arr.shift(0);

return arr.shift(0); // Change this line
}

pahosler
@pahosler
Aug 20 2016 09:19
@Sree-001 post a link to the challenge please
swapnildaddikar
@swapnildaddikar
Aug 20 2016 09:19
someone help me with this
$(".message").html(JSON.stringify(json));
what is stringify/
the entire this is a syntax?
to get JSON of an location
?
Takács Ádám
@AdamTakacs05
Aug 20 2016 09:23
@anandjha1806 Same problem was for me... simply put the words together in a string using the variable names like "this is my " +myNoun+ "something" and make sure the sentence has spaces in it so it should not be displayed as: this is mydogsomething but this is my dog something
Paul Ballardin
@outsmart
Aug 20 2016 09:23
@FreddieFO the 2 last lines are both shifting the first value off the array, sych that the first time you do it, it moves the first value off it and the second time, it is moving the second value which is the new first value...
Desmond
@desmondkam
Aug 20 2016 09:24
Make Unique Objects by Passing Parameters to our Constructor
need help
Freddie O
@FreddieFO
Aug 20 2016 09:24
@outsmart Thanks paul, Ive just fixed it!
CamperBot
@camperbot
Aug 20 2016 09:24
freddiefo sends brownie points to @outsmart :sparkles: :thumbsup: :sparkles:
:cookie: 349 | @outsmart |http://www.freecodecamp.com/outsmart
Anand Kumar
@anandjha1806
Aug 20 2016 09:24
This message was deleted
CamperBot
@camperbot
Aug 20 2016 09:24
anandjha1806 sends brownie points to @adamtakacs05 :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for adamtakacs05
Paul Ballardin
@outsmart
Aug 20 2016 09:25
great... think of it as var shifted = arr.shift() and the arr becomes arr - arr[0]
Mark Todd
@Knochenmark
Aug 20 2016 09:26
@desmondkam whats the question?
Milos
@Milos2709
Aug 20 2016 09:29
Why is chaining like this not possible?
result = letters.push("way").join("");
letters is an array
Mateusz Szymański
@matszym
Aug 20 2016 09:39
@Milos2709 push returns length of the array, not the array itself. You are trying to call join("") on number
Mark Todd
@Knochenmark
Aug 20 2016 09:39
@Milos2709 it returns the length of the number, not the array
@matszym haha ok you were faster :P
Milos
@Milos2709
Aug 20 2016 09:39
Thanks @matszym @Knochenmark
I understand it now, but I still find it ilogical :D
CamperBot
@camperbot
Aug 20 2016 09:39
milos2709 sends brownie points to @matszym and @knochenmark :sparkles: :thumbsup: :sparkles:
:cookie: 146 | @matszym |http://www.freecodecamp.com/matszym
:cookie: 437 | @knochenmark |http://www.freecodecamp.com/knochenmark
Ragini Goyal
@Ragini2093
Aug 20 2016 09:40

function findLongestWord(str) {
var array = str.split();
var arrayLenght = array.map(function(val){
return val.lenght;
});
var len = arrayLenght.lenght;
var max = 0;
while (len--) {
if(arrayLenght[len] > max) {
max = arrayLenght[len];
}
}
return max;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
what is the wrong in my code to find the length of longest word in a string?

Milos
@Milos2709
Aug 20 2016 09:40
Why did language creators do that? Why return the length?
Not logical for me haha
Albert Brennan
@bluegreybolt
Aug 20 2016 09:41
@Ragini2093 You are calling .lenght as a method?
Instead of .length?
Mateusz Szymański
@matszym
Aug 20 2016 09:41
@Milos2709 It was single person that created js in a week or so
Moose
@mooooose
Aug 20 2016 09:42
hey guys
I have a question.
Albert Brennan
@bluegreybolt
Aug 20 2016 09:44
@mooooose Yep just ask
Milos
@Milos2709
Aug 20 2016 09:45
@matszym Oh, that makes sense then.
Moose
@mooooose
Aug 20 2016 09:47

function myFunction() {
'use strict';

console.log(myVar);
}
myFunction();

// run and check the console
// myVar is not defined outside of myFunction
console.log(myVar);

// now remove the console log line to pass the test

function myFunction() {
  'use strict';


  console.log(myVar);
}
myFunction();

// run and check the console 
// myVar is not defined outside of myFunction
console.log(myVar);

// now remove the console log line to pass the test
Need to declare a global variable and local variable
Albert Brennan
@bluegreybolt
Aug 20 2016 09:49
Remove the console.log() line
pahosler
@pahosler
Aug 20 2016 09:50
@Sree-001 sorry , didn't mean to abandon you,
if you're still here...
change your function for setGear to this.setGear(change)
get rid of this.gear, just use gear = change; you do not need a return...
for getGear you just want to return gear...
look carefully at the Car example above bike, and you'll see the structure...
Adam Jubert
@adamjubert
Aug 20 2016 09:53

Is there an easier/cleaner/shorter way to get the reverse of a string?

http://codepen.io/adamjubert/pen/zBXLQG?editors=0010

jamesmillerho
@jamesmillerho
Aug 20 2016 09:54
Just want to say..found an extremely powerful way to generate all prime
Albert Brennan
@bluegreybolt
Aug 20 2016 09:54
@adamjubert I'm not sure in Javascript, I'm only learning it now
But in Python you can use indexes
Like mystring[::-1] will reverse it
Meaning 'start at the end then step backwards one by one'
or maybe mystring[mystring.length, 0, -1] or something in Javascript?
pahosler
@pahosler
Aug 20 2016 09:55
var str=string.split('').reverse().join('')
jamesmillerho
@jamesmillerho
Aug 20 2016 09:55
This is just insane, but works
function sumPrimes(num) {
  var arr = 0;
  for(var i=2; i<=num ;i++){
    if(!new Array(i+1).join(1).match(/^(11+?)\1+$/)){
      arr+=i;}
  }
 return arr;
}

sumPrimes(10);
Mateusz Szymański
@matszym
Aug 20 2016 09:55
@adamjubert
var string = "hello world";
var newString = string.split('').reverse().join('');

document.write("<p>" + newString + "</p>");
Adam Jubert
@adamjubert
Aug 20 2016 09:56
@matszym Killed it! Thank you so much! I haven't learned about .reverse() or .join() yet, I knew there had to be a simpler way :)
CamperBot
@camperbot
Aug 20 2016 09:56
adamjubert sends brownie points to @matszym :sparkles: :thumbsup: :sparkles:
:cookie: 147 | @matszym |http://www.freecodecamp.com/matszym
Adam Jubert
@adamjubert
Aug 20 2016 09:56
Also thank you @pahosler and @bluegreybolt for your help as well
CamperBot
@camperbot
Aug 20 2016 09:56
adamjubert sends brownie points to @pahosler and @bluegreybolt :sparkles: :thumbsup: :sparkles:
:cookie: 357 | @pahosler |http://www.freecodecamp.com/pahosler
:cookie: 181 | @bluegreybolt |http://www.freecodecamp.com/bluegreybolt
Moose
@mooooose
Aug 20 2016 09:56
@bluegreybolt I don't understand.
Albert Brennan
@bluegreybolt
Aug 20 2016 09:58
@mooooose Just delete the line with console.log() on it
And your test will pass
Moose
@mooooose
Aug 20 2016 10:02
@bluegreybolt I tried, but it didn't pass.
Albert Brennan
@bluegreybolt
Aug 20 2016 10:03
You should reset the exercise and try again
Its worded badly
beto0o0o
@beto0o0o
Aug 20 2016 10:03
can someone please tell me how to negate this :
while (firstName==contacts[i].firstName){
      return "No such contact";
Albert Brennan
@bluegreybolt
Aug 20 2016 10:03
You have to first change 1 thing then run it
Then delete the console.log and run it again
Then it will finish
Mateusz Szymański
@matszym
Aug 20 2016 10:04
@Ragini2093
1) Its length, not lenght. You have to check spelling in your code.
2) Str.split() creats array with single element (first element is full sentence)
Maltsev Victor
@Malvik0511
Aug 20 2016 10:11
Hello guys
In the intermediate task block, second task is show the local wheather i can`t understund how to use openweathermap api. Can you help me?
Chris Cullen
@123xylem
Aug 20 2016 10:15
Moose
@mooooose
Aug 20 2016 10:15
Global Var variable is not found.
jonaz889
@jonaz889
Aug 20 2016 10:16

I need some help with the "Show Local Weather" challenge. I can't make it show my location this is my codepen.

http://codepen.io/jonaz889/pen/QEPVLY

it doesn't do anything

Anand Kumar
@anandjha1806
Aug 20 2016 10:16
someone help me "After nextInLine(testArr, 10), testArr[4] should be 10
"
function destroyer(arr) {
  // Remove all the values
  var hk = Array.from(arguments);
  var arr1 = hk[0];
  var arr2 = [];
  for (var i = 0 ; i < arr1.length ; i++){
    if (arr[i] != hk[i>1]){
       arr2.push(arr1.slice(i, 1));
    }else{
      return arr;
    }
  }
  console.log(arr1);
  return arr2;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Anand Kumar
@anandjha1806
Aug 20 2016 10:16

my code "function nextInLine(arr, item) {
// Your code here
arr.push(item);
return arrxamarin/xamarin-android@a16673d; // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];
testArr.push();
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 10)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
"

Mateusz Szymański
@matszym
Aug 20 2016 10:17
@jonaz889 chrome doesnt give acces to location when you are on unsafe protocol (http)
Brendan Kinahan
@BKinahan
Aug 20 2016 10:17
@anandjha1806 what you return should be the first element of the array, after that element is removed. there is an array method that will do this for you.
jonaz889
@jonaz889
Aug 20 2016 10:18
@matszym What do i do then??
Mateusz Szymański
@matszym
Aug 20 2016 10:18
@jonaz889 use https
Brendan Kinahan
@BKinahan
Aug 20 2016 10:18
@anandjha1806 also, if you format your code, you won't get a weird link where you want to show [0] :)
jonaz889
@jonaz889
Aug 20 2016 10:19
@matszym how when i go to this link it says 404 http://codepen.io/jonaz889/pen/QEPVLY:80
Mateusz Szymański
@matszym
Aug 20 2016 10:19
jonaz889
@jonaz889
Aug 20 2016 10:20
@matszym Thanks! That solved it :+1:
CamperBot
@camperbot
Aug 20 2016 10:20
jonaz889 sends brownie points to @matszym :sparkles: :thumbsup: :sparkles:
:cookie: 148 | @matszym |http://www.freecodecamp.com/matszym
Anand Kumar
@anandjha1806
Aug 20 2016 10:21
@BKinahan Please explain in detail
Mateusz Szymański
@matszym
Aug 20 2016 10:22
This message was deleted
This message was deleted
CamperBot
@camperbot
Aug 20 2016 10:22
no wiki entry for: format
Mateusz Szymański
@matszym
Aug 20 2016 10:22
ups :D
Abhisek Pattnaik
@abhisekp
Aug 20 2016 10:22
camperbot is broken now
FreeCodeCamp/camperbot#108
Brendan Kinahan
@BKinahan
Aug 20 2016 10:23
@anandjha1806 you return the first element of the array, but you do not remove that element from the array, so the array itself is not changed in the second required way. Are you familiar with the other array methods pop(), shift(), and unshift()? one of those will remove the first element and let you return it in the same step.
@anandjha1806 for formatting
```js
your code here
```
@abhisekp What! Who killed camperbot? :cry: :chicken:
Alexie Nepeh
@Nepeh
Aug 20 2016 10:24
Can someone please help me out?? You will write a card counting function. It will receive a card parameter and increment or decrement the global count variable according to the card's value (see table). The function will then return a string with the current count and the string "Bet" if the count is positive, or "Hold" if the count is zero or negative. The current count and the player's decision ("Bet" or "Hold") should be separated by a single space.
Anand Kumar
@anandjha1806
Aug 20 2016 10:24
This message was deleted
CamperBot
@camperbot
Aug 20 2016 10:24
:bulb: to format code use backticks! ``` more info
Brendan Kinahan
@BKinahan
Aug 20 2016 10:24
ooooh it was Quincy!
Anand Kumar
@anandjha1806
Aug 20 2016 10:24
This message was deleted
CamperBot
@camperbot
Aug 20 2016 10:24
:bulb: to format code use backticks! ``` more info
Brendan Kinahan
@BKinahan
Aug 20 2016 10:24
oh, cbot lives!
Anand Kumar
@anandjha1806
Aug 20 2016 10:24

```function nextInLine(arr, item) {
// Your code here
arr.push(item);
return arrxamarin/xamarin-android@a16673d; // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];
testArr.shift();
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 10)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
```

Brendan Kinahan
@BKinahan
Aug 20 2016 10:25
@anandjha1806 note that you can edit your recent messages instead of deleting them :)
@anandjha1806 the backticks should be on their own line. use shift+enter to move function ... to a new line.
Anand Kumar
@anandjha1806
Aug 20 2016 10:25
ohh thnx
function nextInLine(arr, item) {
  // Your code here
  arr.push(item);
  return arr[0];  // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];
testArr.shift();
// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 10)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
Brendan Kinahan
@BKinahan
Aug 20 2016 10:26
great :D
Anand Kumar
@anandjha1806
Aug 20 2016 10:26
whats problem in it @BKinahan
Brendan Kinahan
@BKinahan
Aug 20 2016 10:27
@anandjha1806 so, instead of return arr[0], you should use return arr.(one of the array methods I mentioned above) with the part in parentheses replaced by one of the array methods I mentioned above :) :point_up: August 20, 2016 10:23 AM
Anand Kumar
@anandjha1806
Aug 20 2016 10:28
@BKinahan thnx arr.shift work
CamperBot
@camperbot
Aug 20 2016 10:28
anandjha1806 sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star2: 2288 | @bkinahan |http://www.freecodecamp.com/bkinahan
Brendan Kinahan
@BKinahan
Aug 20 2016 10:28
@anandjha1806 :+1: :D
Adam Jubert
@adamjubert
Aug 20 2016 10:31

Hey all, I need some help with the Using Objects for Lookups section. I feel like FCC does a poor job of explaining it. Here's what I have so far:

'''
// 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("charlie");

'''

CamperBot
@camperbot
Aug 20 2016 10:31
:bulb: to format code use backticks! ``` more info
Alexie Nepeh
@Nepeh
Aug 20 2016 10:31
Can someone please help me out?? You will write a card counting function. It will receive a card parameter and increment or decrement the global count variable according to the card's value (see table). The function will then return a string with the current count and the string "Bet" if the count is positive, or "Hold" if the count is zero or negative. The current count and the player's decision ("Bet" or "Hold") should be separated by a single space.
Brendan Kinahan
@BKinahan
Aug 20 2016 10:32
@Nepeh Do you have a specific question about the challenge?
Adam Jubert
@adamjubert
Aug 20 2016 10:33
@BKinahan Ah thank you! That's all I needed :)
CamperBot
@camperbot
Aug 20 2016 10:33
adamjubert sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star2: 2289 | @bkinahan |http://www.freecodecamp.com/bkinahan
Darth Skywalker
@adityaparab
Aug 20 2016 10:33
Oh! That's a stupid question @BKinahan because the specific question goes on the lines of something like "what's the solution?".
Adam Jubert
@adamjubert
Aug 20 2016 10:34
This is why I love FCC's format. Sometimes I just need a little hint that wouldn't be available otherwise.
Moose
@mooooose
Aug 20 2016 10:34
function queue(arr, item) {
  // Your code here

  return item;  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(queue(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
Anand Kumar
@anandjha1806
Aug 20 2016 10:34
is feecodecamp certificate is valid? Means can I put it into my cv
Brendan Kinahan
@BKinahan
Aug 20 2016 10:34
@adityaparab what? no. You have to be more specific about what you don't understand than just stating the instructions of the problem. THAT'S more inviting of a solution than asking, for example, what method is used to add an item to the start of an array.
Albert Brennan
@bluegreybolt
Aug 20 2016 10:35
@anandjha1806 Yes it's valid but I don't know how many people will have heard of it
Your portfolio should be the main thing
Not the certificate
Brendan Kinahan
@BKinahan
Aug 20 2016 10:35
@adityaparab "what's the solution?" isn't a specific question :P
Darth Skywalker
@adityaparab
Aug 20 2016 10:36
@anandjha1806 : Yes, you can put it in your CV. Just like anything else! Like, for example, that one time when you were a kid and you pretended to be saying a dialog from the movie to a girl you were crushing on and you really meant it! Big achievement!
pahosler
@pahosler
Aug 20 2016 10:36
most of the solutions are in the wiki, wink wink... shhhhh