These are chat archives for FreeCodeCamp/HelpJavaScript

3rd
Jul 2017
kumquatfelafel
@kumquatfelafel
Jul 03 2017 00:03

@Shadilix w/regards to -num in slice, you don't really want to have a negative "end" in this case.

What that negative does is basically says "I want up until this far away from the end"... a fixed-length (not changing) from the end. What you want is a string that ends at some fixed length from the beginning, so you want to use a positive value for the end index.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice

Mike
@MikeJSchorah
Jul 03 2017 00:17
Is it better to not learn Mongoose?
kumquatfelafel
@kumquatfelafel
Jul 03 2017 00:21

The idea behind truncation is... we're setting a maximum acceptable length (sort of like how Twitter only allows tweets to be 100 characters or whatever)

If I tried to post a 400000 word rant here in chat about how spiders are out to get me, it probably wouldn't allow this since they've implemented ways to prevent people from doing this kind of thing. It's a similar idea here, except in this case, we're taking a long (presumably) string and shortening it to a certain length with ... on the end.

Mike
@MikeJSchorah
Jul 03 2017 00:23
@kumquatfelafel That's why it's better to not learn Mongoose?!
kumquatfelafel
@kumquatfelafel
Jul 03 2017 00:24
@MikeJSchorah No no... That's why it's always good to bring a mongoose. :o
@MikeJSchorah I can't really give you a satisfactory answer, I'm afraid. :p
Joseph
@revisualize
Jul 03 2017 00:37
@MikeJSchorah Dont think of a framework or library as a thing to learn.
@MikeJSchorah It should be a tool to get a job done.
Can I import jQuery on every one of my projects? .. Yes. Should I? ... No!
Why would I import jQuery to a project where it is only going to save me from writing 20 lines of code?
@MikeJSchorah Should you learn Mongoose.js? ... What is the problem it will solve for you?
Mike
@MikeJSchorah
Jul 03 2017 00:47
@revisualize Thank you. Exactly what I was looking for. I was going to do the jQuery comparison as well. I still have not learned jQuery, because I haven't mastered JavaScript yet. Just went through a tutorial on Mongoose and immediately thought of the JavaScript vs. jQuery comparison.
CamperBot
@camperbot
Jul 03 2017 00:47
mikejschorah sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4295 | @revisualize |http://www.freecodecamp.com/revisualize
Mike
@MikeJSchorah
Jul 03 2017 00:48
@revisualize What happened to accessing the JS chat on the Front End Certification program? Now they just have a "Hint" button. Lmao
Joseph
@revisualize
Jul 03 2017 00:48
IDK.
kumquatfelafel
@kumquatfelafel
Jul 03 2017 00:59
@MikeJSchorah There were complaints, apparently.
Mike
@MikeJSchorah
Jul 03 2017 01:01
@kumquatfelafel Haha. What kind of complaints?
Hey, I like @revisualize. Hahaha
luccifer00
@luccifer00
Jul 03 2017 01:13
Thanks @
Frank McCroy
@fmccroy
Jul 03 2017 01:14
Asking us for hints and help was too much trouble? Or someone couldn’t figure out how to ask?
luccifer00
@luccifer00
Jul 03 2017 01:14
@alpox thanks, your advice work perfectly after too many work! :smile:
CamperBot
@camperbot
Jul 03 2017 01:14
luccifer00 sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1204 | @alpox |http://www.freecodecamp.com/alpox
luccifer00
@luccifer00
Jul 03 2017 01:16
@fmccroy i was on the mobile, so sometimes i hace same mistakes like that, but i have a questuion prepared!! Lol
luccifer00
@luccifer00
Jul 03 2017 01:27
after too many houres i found a workeable API for my random quites. I would like to know, if i can make an if conditional inside my json console log! I would like to filter the quotes by length ( filter if one quote hace more than 50 characters) the matter is, the api hasnt that property, so i suppouse i have to do it while my function is going on... also i would like to delete the '<p> and </p>' when i make tweet... this is becouse the api content cames with it.... here is my Code Pen . If sombody could take a look, will be great! Thanks in advance! 🙌
John
@AnonymousLords
Jul 03 2017 01:29
Guys what does the"escape" mean in a quote? Does it mean that it wont be counted as the end ot start of a string. Like explain all teh different types on this list - https://www.freecodecamp.com/challenges/escape-sequences-in-strings
Frank McCroy
@fmccroy
Jul 03 2017 01:33
@John-freeCodeCamp The items on the list are all called escape sequences, which are used because a string cannot normally print what they represent. For example printing a string "
I’m a little teapot’ might think the string ended. But if you put in \’ it will print the single quote without any problems. Each of those escape sequences will print or do something special when you output it in a string.
John
@AnonymousLords
Jul 03 2017 01:35
Cant i use that for two quoes inside of one major quote?
Like ```
var myStr = '<a href="http://www.example.com" target="_blank">Link</a>';
thx @fmccroy
CamperBot
@camperbot
Jul 03 2017 01:36
john-freecodecamp sends brownie points to @fmccroy :sparkles: :thumbsup: :sparkles:
:cookie: 368 | @fmccroy |http://www.freecodecamp.com/fmccroy
Frank McCroy
@fmccroy
Jul 03 2017 01:38
Depending on what you are doing, when using either double quotes or singles, you may come upon a time when you need to have that kind of quote as part of your string. That is when you would need the escape sequence version: \’ or \”. The other sequences just do special stuff like skip lines
kumquatfelafel
@kumquatfelafel
Jul 03 2017 01:38
@John-freeCodeCamp You can use ' outside if you want to use " inside without having to escape. However, then you have to escape for '. Alternatively, if you use " outside, you no longer have to escape for ' inside, but you do have to escape for "
John
@AnonymousLords
Jul 03 2017 01:38
Guys this is making no sense, what is it telling eme to do?
me*
Frank McCroy
@fmccroy
Jul 03 2017 01:40
@John-freeCodeCamp Print a string that displays the three lines given, using the escape sequences shown.
kumquatfelafel
@kumquatfelafel
Jul 03 2017 01:40
@John-freeCodeCamp replace
FirstLinenewlinebackslashSecondLinebackslashcarriage-returnThirdLine
the newline, backslash, and carriage returns with their specified escape sequences listed in the table.
Frank McCroy
@fmccroy
Jul 03 2017 01:40
The trick being that your string is all on one line
kumquatfelafel
@kumquatfelafel
Jul 03 2017 01:42
@John-freeCodeCamp For example, if instead they had HellotabtabtabWorld, I'd look at that table in description on left, see that tab is \t, and do "Hello\t\t\tWorld".
Joseph
@revisualize
Jul 03 2017 01:42
hi
John
@AnonymousLords
Jul 03 2017 01:43
QThis is my code
Joseph
@revisualize
Jul 03 2017 01:43
@John-freeCodeCamp You have to assign 'FirstLine newline backslash SecondLine backslash carriage-return ThirdLine' to the variable myStr.
But, You have to replace the escape words with the proper escape sequences. (And per the instructions: remove all spaces.)
How do you escape a newline?
How do you escape a backslash?
How do you escape a carriage-return?
John
@AnonymousLords
Jul 03 2017 01:43
var myStr = "\'FirstLine\n'\'SecondLine\r'\'ThirdLine";
x on myStr should have encoded text with the proper escape sequences and no spacing.
Joseph
@revisualize
Jul 03 2017 01:44
@John-freeCodeCamp Why are you escaping the '?
John
@AnonymousLords
Jul 03 2017 01:44
so its the whole thing is one big
``
Joseph
@revisualize
Jul 03 2017 01:44
@John-freeCodeCamp No.
kumquatfelafel
@kumquatfelafel
Jul 03 2017 01:44

@John-freeCodeCamp They don't ask for any single quote marks, so you don't have to use them.

', in and of itself is not necessary for escape sequence. Using ' will not escape. Backslash, \, is necessary.
vvvvvv

Joseph
@revisualize
Jul 03 2017 01:45
@John-freeCodeCamp You have to assign 'FirstLine newline backslash SecondLine backslash carriage-return ThirdLine' to the variable myStr.
But, You have to replace the escape words with the proper escape sequences. (And per the instructions: remove all spaces.)
How do you escape a newline? With: \n
How do you escape a backslash? With: \\
How do you escape a carriage-return? With \r
So, you have break the problem down.
FirstLine newline backslash SecondLine backslash carriage-return ThirdLine
FirstLine \n backslash SecondLine backslash carriage-return ThirdLine
FirstLine \n \\ SecondLine backslash carriage-return ThirdLine
John
@AnonymousLords
Jul 03 2017 01:45
okay ill try
Joseph
@revisualize
Jul 03 2017 01:46

This lesson is not trying to teach you how to get some green check marks to pass onto the next lesson. It is trying to teach you a really valuable skill. If you have a string in JavaScript that is instantiated with double quotes (") (Example: var myStr = "Hello World";) you can also instantiate a string with single quotes (') (Example: var myStr = 'Hello World';)

How do you add a " to that string? Let's say you instantiated the string with double quotes and you want to put in a quote that someone said. You have to use an escape character.
Example: var myQuote = "Happy Feet said, \"I really like the rhythm.\"";
Or what happens if you want to add a tab to your string? You can't really add 3 spaces and expect it to show up as a tab. You have to use the escape character for a tab (\t).

OR let's say your trying to output a bunch of text and paragraphs within your JavaScript string. You can't really just make a bunch of variables.
var myParagraph1 = "a bunch of characters";
var myParagraph2 = "a bunch more characters";
I mean you could... but, why not just:
var myStr = "A bunch of characters/sentences.\nThe second paragraph of characters and sentences.";

John
@AnonymousLords
Jul 03 2017 01:47
thanks @revisualize @kumquatfelafel @kumquatfelafel
CamperBot
@camperbot
Jul 03 2017 01:47
john-freecodecamp sends brownie points to @revisualize and @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 429 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:star2: 4296 | @revisualize |http://www.freecodecamp.com/revisualize
John
@AnonymousLords
Jul 03 2017 01:48
@fmccroy thx
CamperBot
@camperbot
Jul 03 2017 01:48
john-freecodecamp sends brownie points to @fmccroy :sparkles: :thumbsup: :sparkles:
:warning: john-freecodecamp already gave fmccroy points
fdemaa
@fdemaa
Jul 03 2017 01:49
can i do this :
String.fromCharCode(str.charCodeAt([i]) - 13);
kumquatfelafel
@kumquatfelafel
Jul 03 2017 01:49
@fdemaa cipher?
fdemaa
@fdemaa
Jul 03 2017 01:49
hi ! @kumquatfelafel
yes
Joseph
@revisualize
Jul 03 2017 01:49
@fdemaa no
kumquatfelafel
@kumquatfelafel
Jul 03 2017 01:50
^^^
@fdemaa what is [i]?
vvv
Joseph
@revisualize
Jul 03 2017 01:50
@fdemaa What is [i]
heh
kumquatfelafel
@kumquatfelafel
Jul 03 2017 01:50
:p
Joseph
@revisualize
Jul 03 2017 01:54
@kumquatfelafel I guess it is telling when two people ask the same question.
And one of those peoples has a broken wrist/forearm.
kumquatfelafel
@kumquatfelafel
Jul 03 2017 01:56
so how bad is it typing?
Is it like "one-hand" bad?
Joseph
@revisualize
Jul 03 2017 02:01
one handed
kumquatfelafel
@kumquatfelafel
Jul 03 2017 02:07

Come to think of it, I'm... not entirely sure why I asked that. I've seen broken armos before.
But yeah, that really sucks.

I guess no more riding bikes for a while as well.

For how long is cast on approx.?
John
@AnonymousLords
Jul 03 2017 02:09
Guys i think i made a small error
why is this wrong?
var myStr = "This is the first sentence.";
myStr += "This is the second sentence.";
Its saying it doesnt match up with
"myStr should have a value of This is the first sentence. This is the second sentence." Its has a X
How does my code not match up to that?
kumquatfelafel
@kumquatfelafel
Jul 03 2017 02:10
Yours: This is the first sentence.This is the second sentence.
Their: This is the first sentence. This is the second sentence.
@John-freeCodeCamp it is indeed something very small, but see if you can spot the difference above.
John
@AnonymousLords
Jul 03 2017 02:10
danke again @kumquatfelafel
CamperBot
@camperbot
Jul 03 2017 02:10
john-freecodecamp sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:warning: john-freecodecamp already gave kumquatfelafel points
John
@AnonymousLords
Jul 03 2017 02:11
Thanks
Joseph
@revisualize
Jul 03 2017 02:24
@kumquatfelafel 8 weeks in cast for me.
Guderian Raborg
@hypercuber
Jul 03 2017 02:25
Can someone help me make a nav bar that is fixed and there is no space above or sides? https://codepen.io/hypercuber/pen/Ogvqwq
Stephen James
@sjames1958gm
Jul 03 2017 02:28
@revisualize How bad is the typing? in the cast?
Ok. I need one more brownie to keep my streak alive, I hate to beg for it, but it is late and the beer was good.
Ok, I know I sound like a teenage girl on snapchat:(
SaiChand Duppala
@saichandd
Jul 03 2017 02:33
:laughing: @sjames1958gm thx. Here have one
CamperBot
@camperbot
Jul 03 2017 02:33
imradioactive sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7980 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 03 2017 02:33
@imRadioactive thanks. :sleeping:
CamperBot
@camperbot
Jul 03 2017 02:33
sjames1958gm sends brownie points to @imradioactive :sparkles: :thumbsup: :sparkles:
:cookie: 299 | @imradioactive |http://www.freecodecamp.com/imradioactive
Joseph
@revisualize
Jul 03 2017 02:39
@sjames1958gm I just type with my right hand.
@sjames1958gm thanks
CamperBot
@camperbot
Jul 03 2017 02:40
revisualize sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7981 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Joseph
@revisualize
Jul 03 2017 02:41
@sjames1958gm I'm worried that my streak is going to die soon.
I have surgery tomorrow and I will be out for some 3 days.
Daniel Lim
@ddanielnp
Jul 03 2017 02:59
i want to compare 2 arrays ['apple', 'boy', 'coco'] and ['apple', 'dog', 'tree']
how should i use javascript to do this
should i split both arrays and compare it?
shivam gupta
@shivamg11000
Jul 03 2017 03:20
@ddanielnp
```
for(let i=0;i<array1.length;i++){
for(let j=0;j<array.length;j++){}
}
@ddanielnp
for (var i=0;i<array1.lenght;i++){
  for( var j=0;j<array2.length;j++){
     if(array1[i]!=array2[j])
       return false;
  }
}
return true;
Joseph
@revisualize
Jul 03 2017 03:22
Why?
for (var i = 0; i < arrOne.length; i++) {
    if (arrOne[i] !== arrTwo[i]) {
         return false;
    }
}
return true;
Daniel Lim
@ddanielnp
Jul 03 2017 03:23
i will need to compare array1 with array2 constantly, array1 will have strings input one by one, with array2 remains
Joseph
@revisualize
Jul 03 2017 03:25
@ddanielnp What?
Daniel Lim
@ddanielnp
Jul 03 2017 03:25
['apple'] compare with ['apple', 'baby', 'boy'] should be true and next, ['apple', 'baby'] compared with ['apple', 'baby', 'boy'] should be true and next, ['apple', 'baby', 'hello'] compared with ['apple', 'baby', 'boy'] should return false
Joseph
@revisualize
Jul 03 2017 03:26
@ddanielnp Show two tests
Daniel Lim
@ddanielnp
Jul 03 2017 03:27
array1 will be pushed a string each turn
Joseph
@revisualize
Jul 03 2017 03:27
@ddanielnp can you show two tests?????
Daniel Lim
@ddanielnp
Jul 03 2017 03:27
im sorry i dont know what u mean
Joseph
@revisualize
Jul 03 2017 03:28
@ddanielnp give me a test case.
Daniel Lim
@ddanielnp
Jul 03 2017 03:28
im writing a function checkIfCorrect
fdemaa
@fdemaa
Jul 03 2017 03:28
Can anyone help me with my algorithm ? Do i have to restart or i can fix over these?
function rot13(str) { 



var array = [];

for(var i = 0; i<str.length; i++){
    var substracUnicodes = (str.charCodeAt([i])-13);
    var addingUnicodes = (str.charCodeAt([i])+13);
    if( substracUnicodes >=65 && substracUnicodes<=77){
       array.push(String.fromCharCode(substracUnicodes));
    } else  {
      array.push(String.fromCharCode(addingUnicodes));
    }
}

var result= array.join("").replace(/-/g , " "); 

return result;
}

rot13("GUR DHVPX OEBJA QBT WHZCRQ BIRE GUR YNML SBK.");
Joseph
@revisualize
Jul 03 2017 03:28
@fdemaa [i] ... what?
@ddanielnp Look.. I need two test cases... and I can help you.
Jeremy
@JeremyAntonoff
Jul 03 2017 03:29
can anyone help me solve an async issue
Claudio Restifo
@Marmiz
Jul 03 2017 03:30
@JToddFL Node?
Jeremy
@JeremyAntonoff
Jul 03 2017 03:30
@Marmiz no just the twitch api
Claudio Restifo
@Marmiz
Jul 03 2017 03:31
@JToddFL go ahead :)
I was ready for a Node "callback hell"
Joseph
@revisualize
Jul 03 2017 03:32
@ddanielnp Are you still here?
Daniel Lim
@ddanielnp
Jul 03 2017 03:32
@revisualize yes
Joseph
@revisualize
Jul 03 2017 03:32
Okay.
Jeremy
@JeremyAntonoff
Jul 03 2017 03:32
@Marmiz if i do the callbacks in the console one at a time it appends the list to the page but if i call them in the JS file they dont. its clearly an async issue
not sure what to do
Joseph
@revisualize
Jul 03 2017 03:33
@ddanielnp Do you happen to have a couple of tests for your issue?
Jeremy
@JeremyAntonoff
Jul 03 2017 03:33
@Marmiz i need to do getFeed() and then all()
Joseph
@revisualize
Jul 03 2017 03:33
@ddanielnp Are you trying to PM me?
@ddanielnp I don't read PMs
Daniel Lim
@ddanielnp
Jul 03 2017 03:34
ok
@revisualize
i will want to compare 2 arrays
one array will have a fixed array with strings
one array will be growing
arr1 = ['apple']
arr2 = ['apple', 'boy', 'hello']
Joseph
@revisualize
Jul 03 2017 03:35
@ddanielnp ok. that is false
Daniel Lim
@ddanielnp
Jul 03 2017 03:35
i will want it to check as true
Joseph
@revisualize
Jul 03 2017 03:36
@ddanielnp is.. compareTwoArr(['apple'] , ['apple', 'boy', 'hello']); .. true or false?
Daniel Lim
@ddanielnp
Jul 03 2017 03:36
arr1 = ['apple', 'girl']
arr2 = ['apple', 'boy', 'hello'] should be false
the first should be true
arr1 = ['apple']
arr2 = ['apple', 'boy', 'hello']
comparing should return true
Joseph
@revisualize
Jul 03 2017 03:37
How is the first one true?
Daniel Lim
@ddanielnp
Jul 03 2017 03:37
i want it to contain
something like includes
Joseph
@revisualize
Jul 03 2017 03:38
hmm.. ok
for (var i = 0; i < arrOne.length; i++) {
    if (arrOne[i] !== arrTwo[i]) {
         return false;
    }
}
return true;
Claudio Restifo
@Marmiz
Jul 03 2017 03:39

@JToddFL It's not an Async issue. You declared a function

getFeed()

That calls the Ajax request.
but getFeed() never get fired.
Either bind it to an event, or for now I have just invoked it as an immediate invoked function as:

(function getFeed() {
    for (var i =0; i <streams.length; i++) {
        getStreams(streams[i])
    }
})()

And BOOM! mappedStreams is now populated

Joseph
@revisualize
Jul 03 2017 03:39
@ddanielnp I wrote that earlier. Does that not work?
Daniel Lim
@ddanielnp
Jul 03 2017 03:39
i will try it @revisualize thanks
CamperBot
@camperbot
Jul 03 2017 03:39
ddanielnp sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4297 | @revisualize |http://www.freecodecamp.com/revisualize
Claudio Restifo
@Marmiz
Jul 03 2017 03:40
@JToddFL also consider that in codepen you don't need to import script tags via script in HTML, but open up the settings and add any extra resource from there :)
Jeremy
@JeremyAntonoff
Jul 03 2017 03:41
@Marmiz i took that out of my code for now to do it manually in the console
@Marmiz it still doesnt work if it gets fired or not
Joseph
@revisualize
Jul 03 2017 03:45
@ddanielnp ???
Jeremy
@JeremyAntonoff
Jul 03 2017 03:45
fire getFeed() and then load the page and go into console and fire all()
it will load
if i do both in the JS file it wont
its deff an async issue
M-C-Haker
@M-C-Haker
Jul 03 2017 03:46
i really don't want to look at any full solutions online, i've gotten everything up to this point, but i seem to be really struggling with this one and don't know where to go. This is the only one so far that i don't seem to even know where to begin. i know i need to use replace but how am I supposed to single out the first digit in EVERY array? chartAt?

`function titleCase(str) {
var lower = str.toLowerCase.split(" ");
var upperCase = [];
for (i = 0; i < lower.length; i++){

}
}

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

what i have so far... like i said completely lost
Joseph
@revisualize
Jul 03 2017 03:47
@M-C-Haker String concatenation
Jeremy
@JeremyAntonoff
Jul 03 2017 03:47
I think I have to do a promise and i have absolutely no idea what im doing
M-C-Haker
@M-C-Haker
Jul 03 2017 03:48
@revisualize no really following,..
Jeremy
@JeremyAntonoff
Jul 03 2017 03:48
@revisualie do you think thats what i need in my case
Joseph
@revisualize
Jul 03 2017 03:49
@M-C-Haker what is string concatenation?
M-C-Haker
@M-C-Haker
Jul 03 2017 03:49
adding arrays together
Joseph
@revisualize
Jul 03 2017 03:49
@JToddFL Actually, I have no idea. It was one of my open tabs
@M-C-Haker String Concatenation...
M-C-Haker
@M-C-Haker
Jul 03 2017 03:50
i get that, but how does that help me specify the first digit in every array that needs to be capitalized
Joseph
@revisualize
Jul 03 2017 03:50
@M-C-Haker How is String Concatenation adding Arrays together?
@M-C-Haker String Concatenation 100% helps your issue
@M-C-Haker How do you select the first character in a string?
var str = "penguin";
M-C-Haker
@M-C-Haker
Jul 03 2017 03:53
can you give me an example? arry = 1,2,3,4 concat 5,6, 7, 8 would yield 1,2,3,4,5,6,7,8 not really sure that's what i'm looking for just yet. i know i will have to join them somehow, maybe concat , but at this point i'm just trying to make the first digit of every array uppercase
Joseph
@revisualize
Jul 03 2017 03:53
@M-C-Haker I don't care about arrays.
M-C-Haker
@M-C-Haker
Jul 03 2017 03:54
@revisualize var x = str.split("") x[y]?
Joseph
@revisualize
Jul 03 2017 03:54
@M-C-Haker String Concatenation .... NOT Array Concatenation.
@M-C-Haker no.
@M-C-Haker
var str = "penguin";
How do you select the first character of this String??
You don't .split()
M-C-Haker
@M-C-Haker
Jul 03 2017 03:56
@revisualize chartat?
Joseph
@revisualize
Jul 03 2017 03:57
ok?
show me?
M-C-Haker
@M-C-Haker
Jul 03 2017 03:57
str.chartAt(0);
Jeremy
@JeremyAntonoff
Jul 03 2017 03:58
@revisualize can you help me
Joseph
@revisualize
Jul 03 2017 03:58
@M-C-Haker Ok. how do you make something uppercase?
@JToddFL I don't understand your problem.
M-C-Haker
@M-C-Haker
Jul 03 2017 03:58
.toUpperCase
Joseph
@revisualize
Jul 03 2017 03:59
@M-C-Haker Show me.
M-C-Haker
@M-C-Haker
Jul 03 2017 03:59
str.chartAt(0).toUpperCase;
Joseph
@revisualize
Jul 03 2017 03:59
ok
Jeremy
@JeremyAntonoff
Jul 03 2017 03:59
Joseph
@revisualize
Jul 03 2017 03:59
@M-C-Haker how do you select every character but the first?
Jeremy
@JeremyAntonoff
Jul 03 2017 04:00
@revisualize they wont append to the page because of an async issue
M-C-Haker
@M-C-Haker
Jul 03 2017 04:00
@revisualize that i'm going to have to look for...
Tricia
@patricia07
Jul 03 2017 04:00

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

is anything wrong with my code?

Joseph
@revisualize
Jul 03 2017 04:00
@JToddFL You don't seem to understand. ... I don't understand your problem.. It goes far beyond linking me your codepen.
@patricia07 With just that little bit of code.. no.
Jeremy
@JeremyAntonoff
Jul 03 2017 04:02
@revisualize the names of the streams are suppose to append at the bottom under all() but wont because i guess mappedStreams hasnt populated yet with all the info from AJAX
Tricia
@patricia07
Jul 03 2017 04:02
@revisualize it doesn't work
Joseph
@revisualize
Jul 03 2017 04:02
@JToddFL I don't know AJAX
@patricia07 Need more info.
Ronald T. Casili
@nvlled
Jul 03 2017 04:02
@patricia07 Do you intend to push the whole array? Or just add dog and 3 to myArray directly?
Aaron Bell
@awb715
Jul 03 2017 04:03
would anyone want to help figureout this api in node?
Claudio Restifo
@Marmiz
Jul 03 2017 04:03
@JToddFL All you have to do is call all() after the Ajax event.
eg:
success: function() {
[do your thing]
 all()
}
Jeremy
@JeremyAntonoff
Jul 03 2017 04:04
i cant all all() until my array is populated
M-C-Haker
@M-C-Haker
Jul 03 2017 04:04
@revisualize are you looking for .substring?
Claudio Restifo
@Marmiz
Jul 03 2017 04:04
@JToddFL Is populated
M-C-Haker
@M-C-Haker
Jul 03 2017 04:04
.substr*
Claudio Restifo
@Marmiz
Jul 03 2017 04:04
I just did it
Jeremy
@JeremyAntonoff
Jul 03 2017 04:04
it doesnt print out 4 names
which is what i need
i only have 4 streams
Joseph
@revisualize
Jul 03 2017 04:05
@M-C-Haker I'm not looking for anything.. you are.
@M-C-Haker so, how do you select every character not the first character?
Claudio Restifo
@Marmiz
Jul 03 2017 04:06
the order:
1 - fire `getFeed()`
2 - getFeed() call an ajax for each entry ( NOTE: inefficient)
3 - call all()
M-C-Haker
@M-C-Haker
Jul 03 2017 04:07
I know, i know....ok yes str.chartAt(0).toUppCase.subStr(2,7).toLowerCase;?
Tricia
@patricia07
Jul 03 2017 04:07
image.png
image.png
M-C-Haker
@M-C-Haker
Jul 03 2017 04:08
@revisualize str.chartAt(0).toUppCase.subStr(2,7).toLowerCase;?
Joseph
@revisualize
Jul 03 2017 04:08
@patricia07 why are you .push() ???
@M-C-Haker no.
Tricia
@patricia07
Jul 03 2017 04:09
@revisualize i used pop and it's still a no
Joseph
@revisualize
Jul 03 2017 04:09
@M-C-Haker Youre trying to answer two different questions when only one was asked
@patricia07 challenge name?
Ronald T. Casili
@nvlled
Jul 03 2017 04:09
@patricia07 Don't use push, just pop
M-C-Haker
@M-C-Haker
Jul 03 2017 04:10
@revisualize alright. substr(2, 7)
Jeremy
@JeremyAntonoff
Jul 03 2017 04:10
@Marmiz that doesnt work
Tricia
@patricia07
Jul 03 2017 04:10
@nvlled i used pop
still doesn't work
Ronald T. Casili
@nvlled
Jul 03 2017 04:10
myArray.pop()
Joseph
@revisualize
Jul 03 2017 04:11
Worked for me.
image.png
@M-C-Haker no.
Tricia
@patricia07
Jul 03 2017 04:11
image.png
Manish Giri
@Manish-Giri
Jul 03 2017 04:12
@patricia07 .pop() doesn't take any args
just .pop()
Joseph
@revisualize
Jul 03 2017 04:12
@patricia07 You deleted the variable.
@M-C-Haker str.substr(1)
@M-C-Haker
var str = 'abcdefghij';

console.log('(1, 2): '   + str.substr(1, 2));   // '(1, 2): bc'
console.log('(-3, 2): '  + str.substr(-3, 2));  // '(-3, 2): hi'
console.log('(-3): '     + str.substr(-3));     // '(-3): hij'
console.log('(1): '      + str.substr(1));      // '(1): bcdefghij'
Claudio Restifo
@Marmiz
Jul 03 2017 04:14
@JToddFL works for me but print duplicate since, by the way you have structured your functions there is no way of avoiding multiple call to the same function.
If you want to stick on this route you need a callback
Ronald T. Casili
@nvlled
Jul 03 2017 04:14
@patricia07 Use ourArray as an example of what you should do
M-C-Haker
@M-C-Haker
Jul 03 2017 04:15
@revisualize ok wow, this is the first time i've use this haven't seen it before very good to know
Tricia
@patricia07
Jul 03 2017 04:15
i did. Thanks a lot!
Joseph
@revisualize
Jul 03 2017 04:16
@M-C-Haker
var str = "penguin";
str.charAt(0).toUpperCase()
str.substr(1)
@M-C-Haker then you need to do String Concatenation.
Jeremy
@JeremyAntonoff
Jul 03 2017 04:16
@Marmiz what is a callback
M-C-Haker
@M-C-Haker
Jul 03 2017 04:19
@revisualize i'm doing the algorithym part i think they're looking for some kind of loop to select the first letter of every word
Ronald T. Casili
@nvlled
Jul 03 2017 04:19
@JToddFL
a callback is a piece of code, a function, that you pass as an argument to another function
function doSomething(callback) {
  console.log("doing something");
  callback(); 
}

doSomething(function() {
  console.log("done!");
});
M-C-Haker
@M-C-Haker
Jul 03 2017 04:19
algorithm
@M-C-Haker so the code is recycle-able'
Jeremy
@JeremyAntonoff
Jul 03 2017 04:20
@nvlled whoa so confused lol
Ronald T. Casili
@nvlled
Jul 03 2017 04:21
@JToddFL Yeah, it will be confusing if you're not familiar yet with functional programming
Jeremy
@JeremyAntonoff
Jul 03 2017 04:21
@nvlled im very familiar with it thats jsut confusing to me
Joseph
@revisualize
Jul 03 2017 04:22
@M-C-Haker You have that part written.
Jeremy
@JeremyAntonoff
Jul 03 2017 04:22
why do you use an anonymous function
Ronald T. Casili
@nvlled
Jul 03 2017 04:23
@JToddFL It's optional, but it's more succint that way
Joseph
@revisualize
Jul 03 2017 04:23
@M-C-Haker Did you write this?
function titleCase(str) {
  var lower = str.toLowerCase.split(" ");
  var upperCase = [];
  for (i = 0; i < lower.length; i++){

  }
}

titleCase("I'm a little tea pot");
M-C-Haker
@M-C-Haker
Jul 03 2017 04:23
i did yeah, i see what we are doing here now.. allow me a min to try and incorportate that into the loop
Ronald T. Casili
@nvlled
Jul 03 2017 04:24
@JToddFL This accomplishes the same thing
function myCallback() {
  console.log("done!");
}
doSomething(myCallback);
Jeremy
@JeremyAntonoff
Jul 03 2017 04:24
o ok gotcha i get it now
@nvlled thank you
CamperBot
@camperbot
Jul 03 2017 04:24
jtoddfl sends brownie points to @nvlled :sparkles: :thumbsup: :sparkles:
:cookie: 241 | @nvlled |http://www.freecodecamp.com/nvlled
Claudio Restifo
@Marmiz
Jul 03 2017 04:27

@JToddFL just to show you your "logic" and how it could work:

var streams = ["freecodecamp", "GamesDoneQuick", "summit1g", "jimthewhooo"];
var streamList = $("#streamList");
var mappedStreams = [];



function getStreams(stream) {
    $.ajax({
        url: "https://wind-bow.glitch.me/twitch-api/streams/" + stream,
        dataType: "jsonp",
        success: function(item) {
                if (item.stream) {
                    mappedStreams.push( {
                        name: stream,
                        status: item.stream.stream_type,
                        game: item.stream.game,
                        logo: item.stream.channel.logo
                        }) ;
                } else {
                    mappedStreams.push( {
                        name: stream,
                        status: "Offline"
                        } );
                    }
        }
    });    
}

// getFeed needs to be called, in this case I just Immediately invoked it
(function getFeed() {
    for (var i =0; i <streams.length; i++) {
        getStreams(streams[i])
    }
// since you have no callbacks to your ajax events, I am just delaying the all function till we are sure that the array is populated
  setTimeout(()=> {
    all()
  },1000)
})()

function all() {
    for (var i =0; i<mappedStreams.length; i++) {
        $('#streamList').append("<li>"+mappedStreams[i].name+"</li>")
    }
}

Instead of a Timeout you need a function to tell you that all the Ajax requests have been completed.. AKA a callback

M-C-Haker
@M-C-Haker
Jul 03 2017 04:28
@revisualize i turned the argument/parament into an array with var lower = .... .split(" "), how would i use string contencation
Jeremy
@JeremyAntonoff
Jul 03 2017 04:28
@Marmiz interesting so i can set a timeout to do that
i restructured my code is this better
Joseph
@revisualize
Jul 03 2017 04:29
@M-C-Haker What?
Jeremy
@JeremyAntonoff
Jul 03 2017 04:29
var streams = ["freecodecamp", "GamesDoneQuick", "summit1g", "jimthewhooo"];
var streamList = $("#streamList");
var mappedStreams = [];



function getStreams(stream) {
    $.ajax({
        url: "https://wind-bow.glitch.me/twitch-api/streams/" + stream,
        dataType: "jsonp",
        async: false,
        success: function(item) {
            mapStream(item,stream)

        }
    });    
}

function getFeed() {
    for (var i =0; i <streams.length; i++) {
        getStreams(streams[i])
    }

}

function mapStream(item, stream) {

    console.log(item);
    var str;
    if (item.stream) {
                    str = {
                        name: stream,
                        status: item.stream.stream_type,
                        game: item.stream.game,
                        logo: item.stream.channel.logo
                        } ;
                } else {
                    str = {
                        name: stream,
                        status: "Offline"
                        };
                    }
        all(str);

}

function all(str) {
        $("ul").append("<li>" +str.name + "</li>")

}

getFeed()
that way it does it one at a time
Joseph
@revisualize
Jul 03 2017 04:29
Get help on our basic JavaScript and Algorithms Challenges. If you are posting code that is large use Gist - https://gist.github.com/ paste the link here.
M-C-Haker
@M-C-Haker
Jul 03 2017 04:29
@revisualize doesn't the str.split("") return an array?
Joseph
@revisualize
Jul 03 2017 04:30
@M-C-Haker yes
M-C-Haker
@M-C-Haker
Jul 03 2017 04:30
i guess i'm just lost on where string contencation comes into it
Joseph
@revisualize
Jul 03 2017 04:30
@M-C-Haker Each Array element is a String.
M-C-Haker
@M-C-Haker
Jul 03 2017 04:30
in way over my head on this one, but i don't want to take the easy way out
Claudio Restifo
@Marmiz
Jul 03 2017 04:30
@JToddFL yes but is.... dumb.
What if internet is slow and istead of 1sec to finish all the AJAX it takes 4?
Or if instead of 4 elements you have 4k?
Joseph
@revisualize
Jul 03 2017 04:31
@M-C-Haker "H" + "ello"
Jeremy
@JeremyAntonoff
Jul 03 2017 04:31
@Marmiz but if i still need to populate everything what other choice do i have
like if every ajax call i need to put into a list
dont i have to wait anyway
Joseph
@revisualize
Jul 03 2017 04:33
@M-C-Haker You take the Uppercase letter and concatenate the lowercase letters on the end to make an uppercase word
Claudio Restifo
@Marmiz
Jul 03 2017 04:34

@JToddFL yes but with a promise/callback you can start append items as soon as each individual item has done:

ajax(...).then(append) //note: example... it doesn't work like this

So your content gets appended while it has finished, instead of waiting for all the element to finish and then append

Joseph
@revisualize
Jul 03 2017 04:34
var str = "penguin";
str = str.charAt(0).toUpperCase() + str.subsrt(1);
Jeremy
@JeremyAntonoff
Jul 03 2017 04:35
@marmiz so if i want to get more proficient at api and ajax should i research promises mostly?
Joseph
@revisualize
Jul 03 2017 04:35
@M-C-Haker Did you do the JS lessons about String Concatenation?
Pagnito
@Pagnito
Jul 03 2017 04:35
does anyone know how to activate the packages on atom?
Claudio Restifo
@Marmiz
Jul 03 2017 04:36
@JToddFL But in reality for your Twitch you don't have to worry too much, you will have a list of what, 10 streams at most?
Just make sure to handle the append function at the right time/place
Pagnito
@Pagnito
Jul 03 2017 04:36
Screen Shot 2017-07-03 at 12.35.56 AM.png
M-C-Haker
@M-C-Haker
Jul 03 2017 04:36
@revisualize yes i understand how to do it using +
Pagnito
@Pagnito
Jul 03 2017 04:36
i have the package open-files-extended but it doesnt actually work
Claudio Restifo
@Marmiz
Jul 03 2017 04:36
@Pagnito preferences>packages>installed
Joseph
@revisualize
Jul 03 2017 04:36
@M-C-Haker that is string concatenation
Jeremy
@JeremyAntonoff
Jul 03 2017 04:37
@Marmiz did you see my upper comment
Claudio Restifo
@Marmiz
Jul 03 2017 04:37
@JToddFL nope
Pagnito
@Pagnito
Jul 03 2017 04:37
Screen Shot 2017-07-03 at 12.37.22 AM.png
its already installed
Jeremy
@JeremyAntonoff
Jul 03 2017 04:38
@marmiz to get better and more proficent like you are talking about should i look more into promises or callbacks
M-C-Haker
@M-C-Haker
Jul 03 2017 04:40

@revisualize right, so you can see where i'm at `
function titleCase(str) {
var lower = str.toLowerCase();
var upperCase = [];
for (i = 0; i < lower.length; i++){
lower = str.charAt(0).toUpperCase();
lower = str.substr(1);
upperCase = lower[i].toUpperCase();
}
return upperCase + lower;
}

titleCase("I'm a little tea pot");
` i understand it's wrong just trying to understand where -- i believe with my upperCase sections

Pagnito
@Pagnito
Jul 03 2017 04:40
@Marmiz is ther somethin else im supposed to do once i go to installed section
Joseph
@revisualize
Jul 03 2017 04:41
@M-C-Haker you really need to use www.pythontutor.com/javascript.html
M-C-Haker
@M-C-Haker
Jul 03 2017 04:42
@revisualize this is an amazing resource thank you
CamperBot
@camperbot
Jul 03 2017 04:42
m-c-haker sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4298 | @revisualize |http://www.freecodecamp.com/revisualize
Claudio Restifo
@Marmiz
Jul 03 2017 04:42

@JToddFL in general, yes. Especially if you want to dive into Node (callback hell is a thing)
But for now just focus on the logic.

Can you tell me why your all function was not working?(as expected)
And is not a callback thing ^^

just a tip: instead of ajax success I'd use .done method as I told you.

$(ajax({
 [...]
}).done(() =>{
 // do something since the ajax has finished
})
Pagnito
@Pagnito
Jul 03 2017 04:43
oh it seems the extended one doesnt work
i downloaded open-files and it works
Claudio Restifo
@Marmiz
Jul 03 2017 04:44
@Pagnito some pkg require atom to restart but they usually prompt.
Look into its docs
Pagnito
@Pagnito
Jul 03 2017 04:46
yea, i already tried restarting before, as soon as i downloaded the original open-files tho it worked instantly
hmm, weird tho my icon-files package doesnt seem to apply to the open-folders
i mean open-files
CallMeOrange
@EgnaroDev
Jul 03 2017 04:51
Is it possible to remove two item from a parameter using filter method?
shivam gupta
@shivamg11000
Jul 03 2017 04:51
@MCTwoDigitZero yes but from array
then you can use spread operator
CallMeOrange
@EgnaroDev
Jul 03 2017 04:52
Yeah an array
function test(arr) {
  return arr;
}
test([1, 'abc'])
How would I remove both?
That is an example
Claudio Restifo
@Marmiz
Jul 03 2017 04:53
@MCTwoDigitZero you want to remove them based on some condition I suppose
not just remove 2 random
shivam gupta
@shivamg11000
Jul 03 2017 04:53
var ar = [ 1,2,3,4,5,6]
ar = ar.filter(function(val){
     return val>3;
})
ar becomes [4,5,6]
CallMeOrange
@EgnaroDev
Jul 03 2017 04:53
function test(arr) {
  var remove = arr.filter(function(fff) {
   return fff !== 1;
});
}
test([1, 'abc'])
Not that way
So that code remove 1
shivam gupta
@shivamg11000
Jul 03 2017 04:54
you have to return false for that val which you dont want to be in the array
CallMeOrange
@EgnaroDev
Jul 03 2017 04:55
return fff !== 1, 'abc'; wont this work?
shivam gupta
@shivamg11000
Jul 03 2017 04:55
@MCTwoDigitZero
@MCTwoDigitZero yes it would woek
work*
CallMeOrange
@EgnaroDev
Jul 03 2017 04:55
really?
function test(arr) {
  var remove = arr.filter(function(fff) {
   return fff !== 1, 'abc';
});
return remove;
}
test([1, 'abc'])
It doesn't, thats why Im asking how to remove both like that way
shivam gupta
@shivamg11000
Jul 03 2017 04:56
what you want to remove from [1, 'abc']
@MCTwoDigitZero
CallMeOrange
@EgnaroDev
Jul 03 2017 04:56
Both
shivam gupta
@shivamg11000
Jul 03 2017 04:56
why?
kumquatfelafel
@kumquatfelafel
Jul 03 2017 04:56
@MCTwoDigitZero In this case, to remove both you could literally just do return !fff, but that would remove everything truthy. I'm not entirely sure what your end goal is here.
shivam gupta
@shivamg11000
Jul 03 2017 04:56
just for fun
use return false;
@MCTwoDigitZero
CallMeOrange
@EgnaroDev
Jul 03 2017 04:57
Yeah....
sigh wait a sec
Let me rewrite a code
shivam gupta
@shivamg11000
Jul 03 2017 04:57
function test(arr) {
  var remove = arr.filter(function(fff) {
   return false;
});
return remove;
}
test([1, 'abc'])
@MCTwoDigitZero
CallMeOrange
@EgnaroDev
Jul 03 2017 04:57
function test(arr) {
  var remove = arr.filter(function(fff) {
   return fff !== 1, 'abc';
});
return remove;
}
test([1, 'abc', 5])
Just asking how to remove 1 and 'abc'
So leave 5 alone
shivam gupta
@shivamg11000
Jul 03 2017 04:58
there would be true not false ,srry
CallMeOrange
@EgnaroDev
Jul 03 2017 04:58
Maybe I can try if statement
shivam gupta
@shivamg11000
Jul 03 2017 04:58
and it would not be removed from arr , instead it would copy all to remove
remeber true for that value which is to be returned and false for that which is not to be returned
kumquatfelafel
@kumquatfelafel
Jul 03 2017 04:59
@shivamg11000 true, though you can always overwrite it .
wonder
@wonder2991
Jul 03 2017 04:59
you can use or in the filter i think
CallMeOrange
@EgnaroDev
Jul 03 2017 04:59
use or in?
wonder
@wonder2991
Jul 03 2017 05:00
give me a sec
CallMeOrange
@EgnaroDev
Jul 03 2017 05:00
Im just doing this so I could remove falsy values somehow...
shivam gupta
@shivamg11000
Jul 03 2017 05:00
@MCTwoDigitZero ^
read that
kumquatfelafel
@kumquatfelafel
Jul 03 2017 05:00
@MCTwoDigitZero It would be easier to give test a parameter that can hold a boolean-returning function which can be used in filter.
CallMeOrange
@EgnaroDev
Jul 03 2017 05:01
if statement inside filter function?
shivam gupta
@shivamg11000
Jul 03 2017 05:01
true for that value which is to be returned and false for that which is not to be returned
you can use if
Claudio Restifo
@Marmiz
Jul 03 2017 05:01

@MCTwoDigitZero what kind of condition is this?

 return fff !== 1, 'abc';

you'd want to watch for true/false

function test(arr) {
  var remove = arr.filter(function(fff) {
   if(fff === 1 || fff === 'abc') return false
   else return true
});
return remove;
}
test([1, 'abc', 5])
CallMeOrange
@EgnaroDev
Jul 03 2017 05:01
I see
I think that will work
@Marmiz thanks
CamperBot
@camperbot
Jul 03 2017 05:02
mctwodigitzero sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:cookie: 979 | @marmiz |http://www.freecodecamp.com/marmiz
Claudio Restifo
@Marmiz
Jul 03 2017 05:03
@MCTwoDigitZero but again, what is your end condition? If it's the foulsy bouncer you have to watch for Boolean values so I don't see how a === 1 || ==='abc' will help
kumquatfelafel
@kumquatfelafel
Jul 03 2017 05:03
^ This is a very limited function.
CallMeOrange
@EgnaroDev
Jul 03 2017 05:04
hm..
Claudio Restifo
@Marmiz
Jul 03 2017 05:04
WOOOOOOOH the spoiler!!
wonder
@wonder2991
Jul 03 2017 05:05
hmm
kumquatfelafel
@kumquatfelafel
Jul 03 2017 05:05
@Marmiz ikr :o
@wonder2991 (for what it's worth though, there's actually an even simpler solution)
CallMeOrange
@EgnaroDev
Jul 03 2017 05:07
:p scrolled up
wonder
@wonder2991
Jul 03 2017 05:07
let him work it out
CallMeOrange
@EgnaroDev
Jul 03 2017 05:07
function test(arr) {
   var filtered = arr.filter(funciton(remove)) {
     if (remove === 1) {
       return false;
     }
   });
   return filtered;
}

  test([1, 'abc'])'
What am I missing?
kumquatfelafel
@kumquatfelafel
Jul 03 2017 05:08
funciton?
:p
CallMeOrange
@EgnaroDev
Jul 03 2017 05:08
oo
Tricia
@patricia07
Jul 03 2017 05:08

function ourFunctionWithArgs(a, b) {
console.log(a + b);

}

functionWithArgs();

kumquatfelafel
@kumquatfelafel
Jul 03 2017 05:08
To be fair, it should be called funciton. Way cooler ;)
CallMeOrange
@EgnaroDev
Jul 03 2017 05:08
Yeah..
Tricia
@patricia07
Jul 03 2017 05:08
can u help me with this one?
CallMeOrange
@EgnaroDev
Jul 03 2017 05:08
and removed last )
(funciton(remove))
function test(arr) {
   var filtered = arr.filter(function(remove) {
     if (remove === 1) return false;

   });
   return filtered;
}

  test([1, 5])
Why did it return empty array?
function test(arr) {
   var filtered = arr.filter(function(remove) {
     if (remove === 1) return false;
     else return true;
   });
   return filtered;
}

  test([1, 5])
guess I needed else
Claudio Restifo
@Marmiz
Jul 03 2017 05:11
@patricia07 you have declared a function that expects two arguments, but you called it with none... actually you called a different function
function ourFunctionWithArgs(a, b) { // it expects two arguments
  console.log(a + b);

}

functionWithArgs(); // what even is functionWithArgs ??
kumquatfelafel
@kumquatfelafel
Jul 03 2017 05:12
@MCTwoDigitZero If you don't include a return, at the end of a function it will return undefined by default.
Tricia
@patricia07
Jul 03 2017 05:13
@Marmiz
wonder
@wonder2991
Jul 03 2017 05:13
function test(arr) {
   return arr.filter(function(remove) {
     return remove !==1;
   });
}
test([1, 'abc']);
why complicate it?
Tricia
@patricia07
Jul 03 2017 05:13
image.png
image.png
Claudio Restifo
@Marmiz
Jul 03 2017 05:14
@patricia07 look how you declared YOUR function
the example is called ourFunctionWithArgs you have to make a new one called functionWithArgs
kumquatfelafel
@kumquatfelafel
Jul 03 2017 05:15
Instructions : create a function called functionWithArgs
CallMeOrange
@EgnaroDev
Jul 03 2017 05:15
@wonder2991 hm, thats good, returning it without assigning it to a variable
Claudio Restifo
@Marmiz
Jul 03 2017 05:16
@MCTwoDigitZero have you looked into filter docs after we showed you some examples?
CallMeOrange
@EgnaroDev
Jul 03 2017 05:17
I have already look into filter docs
Was wondering if you could remove two items in an array using filter
Saif Ur Rahman
@saifsmailbox98
Jul 03 2017 05:17
@MCTwoDigitZero Whatever function you pass to the filter() method, that function should return true on element that you want to filter out (save).
Tricia
@patricia07
Jul 03 2017 05:18

@Marmiz function functionWithArgs(a, b) {
console.log(1 + 2);

}

functionWithArgs(1, 2); // outputs 3

function functionWithArgs(c, d) {
console.log(7 + 9);
}

functionWithArgs(7, 9); // outputs 16

??
Saif Ur Rahman
@saifsmailbox98
Jul 03 2017 05:18
console.log(7 + 9); -- > console.log(c + d);
@patricia07
CallMeOrange
@EgnaroDev
Jul 03 2017 05:19
function bouncer(arr) {
  return arr.filter(function(remove) {
     if (remove === false || remove === null || remove === 0 || remove === "" || remove === undefined) return false;
     else return true;
  });
}

bouncer([1, "ate", "", false, 9, NaN, 0, null, undefined]);
Saif Ur Rahman
@saifsmailbox98
Jul 03 2017 05:19
don't change the code for the example function ourFunctionWithArgs
@patricia07
Tricia
@patricia07
Jul 03 2017 05:19
why is it c+d instead of 7+9?
CallMeOrange
@EgnaroDev
Jul 03 2017 05:20
So c and d contains some numbers so you dont need to do that
Saif Ur Rahman
@saifsmailbox98
Jul 03 2017 05:20
@patricia07 thats why you are creating function, so that any value can be passed to c and d, and not just 7 and 9
@patricia07
Tricia
@patricia07
Jul 03 2017 05:20
ohhh i see thanks
CallMeOrange
@EgnaroDev
Jul 03 2017 05:21

function functionWithArgs(c, d) {

}
functionWithArgs(7, 9);

@saifsmailbox98 See that code? I just need to ask a question
Saif Ur Rahman
@saifsmailbox98
Jul 03 2017 05:21
@MCTwoDigitZero All those falsyyyyy values will get coerced to false, when needed. You can directly put it inside of if(Condition)
kumquatfelafel
@kumquatfelafel
Jul 03 2017 05:21
As noted. If you used 7 and 9, it would always be 7 and 9. By using variables in your function, it could be anything. c and d are called parameters, and you can think of them as being sort of like placeholders.
CallMeOrange
@EgnaroDev
Jul 03 2017 05:22
@saifsmailbox98 coerced?
Saif Ur Rahman
@saifsmailbox98
Jul 03 2017 05:22
@MCTwoDigitZero converted.
CallMeOrange
@EgnaroDev
Jul 03 2017 05:22
oh
Claudio Restifo
@Marmiz
Jul 03 2017 05:22

@patricia07 when declaring function you can tell them how many values they expect to receive (and probably do something with those values)
for example I am creating a add function that add numbers, then I can call it with any number I want:

function add(x, y) {
return x + y //return the sum of the two values passed
}

add(1,2) //return 3
add(1,4) //return 5
add(10,10) //return 20

make sense?

CallMeOrange
@EgnaroDev
Jul 03 2017 05:22
@saifsmailbox98 So do I need to change something in my code?
Is something wrong with if statements?
kumquatfelafel
@kumquatfelafel
Jul 03 2017 05:23
@MCTwoDigitZero you might also sometimes see the term "cast" (though i'm not sure this is so prevalent in javascript?)
Saif Ur Rahman
@saifsmailbox98
Jul 03 2017 05:23
if(null){

}
if(undefined){

}
if(0){


}
if(NaN){


}

if(""){

}

all the equivalent to
CallMeOrange
@EgnaroDev
Jul 03 2017 05:23
false?
Saif Ur Rahman
@saifsmailbox98
Jul 03 2017 05:23

if(false){

}

CallMeOrange
@EgnaroDev
Jul 03 2017 05:23
ah..
Saif Ur Rahman
@saifsmailbox98
Jul 03 2017 05:23
yeah false too
CallMeOrange
@EgnaroDev
Jul 03 2017 05:23
so either is fine?
I can use false instead but why wasn't NaN removed?
Saif Ur Rahman
@saifsmailbox98
Jul 03 2017 05:24
@MCTwoDigitZero The condition of if expects a boolean, that is either true or false, but these are some other values that get coerced to boolean false, any other values will get coerced to `true.
CallMeOrange
@EgnaroDev
Jul 03 2017 05:24
coerced again
Saif Ur Rahman
@saifsmailbox98
Jul 03 2017 05:25
converted
CallMeOrange
@EgnaroDev
Jul 03 2017 05:25
lol
Saif Ur Rahman
@saifsmailbox98
Jul 03 2017 05:25
if(I need a boolean HERE :( )
CallMeOrange
@EgnaroDev
Jul 03 2017 05:25
Yeah..
Saif Ur Rahman
@saifsmailbox98
Jul 03 2017 05:25
:joy_cat: js : don't worry I'll handle it.
CallMeOrange
@EgnaroDev
Jul 03 2017 05:25
if (false) return false;
     else return true;
just false or add something to it?
Saif Ur Rahman
@saifsmailbox98
Jul 03 2017 05:25
remove
CallMeOrange
@EgnaroDev
Jul 03 2017 05:26
I see
remove === false
Saif Ur Rahman
@saifsmailbox98
Jul 03 2017 05:26
if( ! remove)
CallMeOrange
@EgnaroDev
Jul 03 2017 05:26
Well thats work too
Saif Ur Rahman
@saifsmailbox98
Jul 03 2017 05:26
@MCTwoDigitZero if remove is false you want to executed some code?
then put if( ! remove)
CallMeOrange
@EgnaroDev
Jul 03 2017 05:26
I see
Is there another way besides that?
like if (remove === false)
Saif Ur Rahman
@saifsmailbox98
Jul 03 2017 05:27
@MCTwoDigitZero There are, but why go there.
CallMeOrange
@EgnaroDev
Jul 03 2017 05:28
I dont know... !remove seems.
Yeah I checked that docs out
So if statements need to be executed with a boolean
Saif Ur Rahman
@saifsmailbox98
Jul 03 2017 05:28
@MCTwoDigitZero The value passed as the first parameter is converted to a boolean value, if necessary. If the value is omitted or is 0, -0, null, false, NaN, undefined, or the empty string (""), the object has an initial value of fals
@MCTwoDigitZero yes.
CallMeOrange
@EgnaroDev
Jul 03 2017 05:29
I see
ok one more question :p
say... (remove === false || remove === null || remove === 0 || remove === "") works but why not NaN?
kumquatfelafel
@kumquatfelafel
Jul 03 2017 05:30
NaN !== NaN
CallMeOrange
@EgnaroDev
Jul 03 2017 05:30
NaN means not available number right?
wonder
@wonder2991
Jul 03 2017 05:30
not a num
CallMeOrange
@EgnaroDev
Jul 03 2017 05:30
In computing, NaN, standing for not a number
Saif Ur Rahman
@saifsmailbox98
Jul 03 2017 05:31

@MCTwoDigitZero
NaN is a property of the global object.

The initial value of NaN is Not-A-Number — the same as the value of Number.NaN. In modern browsers, NaN is a non-configurable, non-writable property. Even when this is not the case, avoid overriding it.

It is rather rare to use NaN in a program. It is the returned value when Math functions fail (Math.sqrt(-1)) or when a function trying to parse a number fails (parseInt("blabla")).

-mdn
CallMeOrange
@EgnaroDev
Jul 03 2017 05:31
I see.... thanks @-mdn
Saif Ur Rahman
@saifsmailbox98
Jul 03 2017 05:32

@MCTwoDigitZero also you can't compare NaN like this

var a  = NaN;
a===NaN; //false

There is a function for that.

isNaN(a); // true
CallMeOrange
@EgnaroDev
Jul 03 2017 05:33
Yeah since NaN === NaN return true
Saif Ur Rahman
@saifsmailbox98
Jul 03 2017 05:33
@MCTwoDigitZero no, thats false.
CallMeOrange
@EgnaroDev
Jul 03 2017 05:33
What about null?
Oh my bad
Saif Ur Rahman
@saifsmailbox98
Jul 03 2017 05:33
@MCTwoDigitZero null === null :+1:
CallMeOrange
@EgnaroDev
Jul 03 2017 05:33
I see even errors said to use isNaN function
null === null return false not true?
Saif Ur Rahman
@saifsmailbox98
Jul 03 2017 05:34
@MCTwoDigitZero smart environment.
CallMeOrange
@EgnaroDev
Jul 03 2017 05:34
:p
Saif Ur Rahman
@saifsmailbox98
Jul 03 2017 05:34
@MCTwoDigitZero https://repl.it/JLLD
gotta run :wave:
CallMeOrange
@EgnaroDev
Jul 03 2017 05:35
Cya
You didnt have to post repl.it... :/
Bharath Kumar Reddy
@reddy-bharathkumar
Jul 03 2017 05:45
hello all, how can I convert string "3+4" to mathematical form?
Pieter Stokkink
@forkerino
Jul 03 2017 05:49
@reddy-bharathkumar there is a method eval but only - I repeat only - use it if you are 100% sure that the string you have contains a mathematical expression. eval can be used to inject a script into the page and is a security issue. Otherwise, you'll have to parse the string and it can get quite complicated if you have stuff like parentheses and such.
kumquatfelafel
@kumquatfelafel
Jul 03 2017 05:55
@MCTwoDigitZero If you want some nice weirdness on repl.it, some of these comparisons may interest you. :p
https://repl.it/JKl0/8
CallMeOrange
@EgnaroDev
Jul 03 2017 05:55
@kumquatfelafel wow... indeed that is useful, thanks
CamperBot
@camperbot
Jul 03 2017 05:55
mctwodigitzero sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 430 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
kumquatfelafel
@kumquatfelafel
Jul 03 2017 05:56
@MCTwoDigitZero Some of them are very misleading and should not be used.
CallMeOrange
@EgnaroDev
Jul 03 2017 05:56
I see
kumquatfelafel
@kumquatfelafel
Jul 03 2017 05:57
^ is a bit funky. :p
KZinDaHouse
@KZinDaHouse
Jul 03 2017 06:06

// Setup
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];

// Only change code below this line.

var myData = myArray[2][1];

myData equals to 8 right?
why am i still getting error like this: 'You should be using bracket notation to read the correct value from myArray.'
is this a bug?
M-C-Haker
@M-C-Haker
Jul 03 2017 06:09

`function largestOfFour(arr) {
var first = Math.max(...arr[0]);
var second = Math.max (...arr[1]);
var third = Math.max (...arr[2]);
var fourth = Math.max (...arr[3]);
var largest = first.concat(second, third, fourth);

return largest;

}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);`

i feel like that should work thoughts on that?
wonder
@wonder2991
Jul 03 2017 06:09
@KZinDaHouse try refreshing. it works here
KZinDaHouse
@KZinDaHouse
Jul 03 2017 06:09
i tried several times
ok, this time worked! :)
thanks
@wonder2991 thanks
CamperBot
@camperbot
Jul 03 2017 06:10
kzindahouse sends brownie points to @wonder2991 :sparkles: :thumbsup: :sparkles:
:cookie: 378 | @wonder2991 |http://www.freecodecamp.com/wonder2991
Pieter Stokkink
@forkerino
Jul 03 2017 06:12
@M-C-Haker .concat doesn't work on numbers.
@M-C-Haker you could do return [first, second, ...
wonder
@wonder2991
Jul 03 2017 06:13
yep
Pieter Stokkink
@forkerino
Jul 03 2017 06:13
@M-C-Haker but it is easier to use .map
seeing as you repeat a lot of code
M-C-Haker
@M-C-Haker
Jul 03 2017 06:14
@forkerino right was my main concern as well alright i'll give it another go
Pieter Stokkink
@forkerino
Jul 03 2017 06:15
:+1:
kumquatfelafel
@kumquatfelafel
Jul 03 2017 06:17
@MCTwoDigitZero just... to clarify, i was saying that ^ is a bit funky :laughing:
CallMeOrange
@EgnaroDev
Jul 03 2017 06:17
oh lol

I thought you meant my message

I see

I had no idea so I just left :p
kumquatfelafel
@kumquatfelafel
Jul 03 2017 06:18
yeah. Occurred to me about 20 or so minutes later that that could have been interpreted differently in a chat room. :p
M-C-Haker
@M-C-Haker
Jul 03 2017 06:18
@forkerino or should i plan on sorting? i'm not sure how map would be able to get me the largest values without repeating code again
kumquatfelafel
@kumquatfelafel
Jul 03 2017 06:19
@M-C-Haker sort is a bit slow
M-C-Haker
@M-C-Haker
Jul 03 2017 06:21
@kumquatfelafel ok well i want to learn best practices so can you describe how i would set up a map to get the highest values out of multiple arrays (w/o doing it for me lol)? seems to me you'd have to use a loop of some kind but from what i saw last time i tried you can't use a function in a for loop
Pieter Stokkink
@forkerino
Jul 03 2017 06:21
@M-C-Haker I suggest you put the Math.max inside the .map
M-C-Haker
@M-C-Haker
Jul 03 2017 06:22
@forkerino ok i like where this is going. i was wondering if that was still a function but guess not thanks
CamperBot
@camperbot
Jul 03 2017 06:22
m-c-haker sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2811 | @forkerino |http://www.freecodecamp.com/forkerino
Sweet Coding :)
@SweetCodingInc
Jul 03 2017 06:24
@M-C-Haker : First do it using traditional loops. Without using either or .map or Math.max
It is important to understand the methodology. Not just climbing up the number of challenges completed ladder
M-C-Haker
@M-C-Haker
Jul 03 2017 06:25
@SweetCodingInc for understanding purposes
Sweet Coding :)
@SweetCodingInc
Jul 03 2017 06:25
Exactly
That challenge is just a one liner when you use .map and Math.max. But that doesn't guarantee you will understand how to find largest (or smallest) number in the array
Neither will it help you understand the loops
M-C-Haker
@M-C-Haker
Jul 03 2017 06:27
@SweetCodingInc i agree and i guess i will do so. i was honestly just following the read search ask methodology and looking at sorting and found the math.max was suggested -- so kind of FCC's bad there i guess
kumquatfelafel
@kumquatfelafel
Jul 03 2017 06:28
Best possible case (already sorted), sort does as many comparisons as Math.max would. If it's poorly sorted though, you also have to worry about changing the order of the elements (can also mean more comparisons), which allows you that convenient "I'll just take the first element" solution, sure, but it's not particularly necessary..
Sweet Coding :)
@SweetCodingInc
Jul 03 2017 06:29
@M-C-Haker Well.. I tend to agree with that. However, you have to make a decision on whether to take the path that will complete the challenges or to take a path that will improve your skill and understanding. :)
The advice I'd like to give you is focus on completing each of the challenge without using any sort of built in mechanism.
If you do, you will sure run into a glass ceiling when you reach intermediate algorithm part. Many people get stuck there for they can't seem to put 2 and 2 together when it comes to using your own logic.
Start working that muscle out now when it's easy. Later it becomes frustrating. :)
M-C-Haker
@M-C-Haker
Jul 03 2017 06:31
@SweetCodingInc i agree i see zero benefit to completing the challenges. i believe the only way i'll get a job in development is by demonstrating my understanding of programming... not thru fcc's certification -- though it has been tremendously helpful in getting me there
Sweet Coding :)
@SweetCodingInc
Jul 03 2017 06:32
@M-C-Haker Correct. :) Just like any Bachelor's or Master's degree
M-C-Haker
@M-C-Haker
Jul 03 2017 06:32
@SweetCodingInc i mean completing them just to get through them, not actually mastering the content
Sweet Coding :)
@SweetCodingInc
Jul 03 2017 06:32
certificate doesn't prove anything. It just opens up the doorways.

@SweetCodingInc i mean completing them just to get through them, not actually mastering the content

No worries. I understand the subtleties and nuances :)

M-C-Haker
@M-C-Haker
Jul 03 2017 06:33
@SweetCodingInc eh, there are some schools that'll get you a job just by name and after my bachelors i certainly never had to demonstrate my knowledge on the subject as I expect i will when i go in for a developer interview!
wonder
@wonder2991
Jul 03 2017 06:34
at this point of the challenge you should have learned loop
Sweet Coding :)
@SweetCodingInc
Jul 03 2017 06:34
Yeah. That happens many times. However, getting a job and thriving there are two entirely different things :)
One doesn't necessarily lead to other.
M-C-Haker
@M-C-Haker
Jul 03 2017 06:35
100% agree. I appreciate the guidance. I'm doing this because I want to learn and i'm certainly not looking to cheat myself out of the knowledge
Sweet Coding :)
@SweetCodingInc
Jul 03 2017 06:35
All the best :) :+1:
@M-C-Haker
M-C-Haker
@M-C-Haker
Jul 03 2017 06:36
@SweetCodingInc thanks :+1:
CamperBot
@camperbot
Jul 03 2017 06:36
m-c-haker sends brownie points to @sweetcodinginc :sparkles: :thumbsup: :sparkles:
:cookie: 54 | @sweetcodinginc |http://www.freecodecamp.com/sweetcodinginc
Bomee
@Bomulacious
Jul 03 2017 06:38
hi, can someone teach me how to connect atom to terminal? I downloaded atom and can't figure how to get it work so that any code I input returns something.
_
Joseph
@revisualize
Jul 03 2017 06:39
HelpJavaScript
Claudio Restifo
@Marmiz
Jul 03 2017 06:41

@Bomulacious atom is a text editor. If you want to open a file or atom from terminal you simply need to type

atom path/to/file

and you'll see atom opening that file (or directory)

That said there are packages that lets you integrate a terminal window inside Atom so you can run command from the editor

Bomee
@Bomulacious
Jul 03 2017 06:42
oh, I believe that's what I'd like to have essentially: being able to run command from the editor
@Marmiz oh, I believe that's what I'd like to have essentially: being able to run command from the editor
@Marmiz how do I get that package?
Claudio Restifo
@Marmiz
Jul 03 2017 06:44
@Bomulacious look for atom-terminal or terminal-plus
depends on your needs
kumquatfelafel
@kumquatfelafel
Jul 03 2017 06:44
alright, I'm off. Night
Owais Ahmed
@owaisehmed
Jul 03 2017 07:03
var count = 0;

function cc(card) {
  // Only change code below this line
  if(card == 2 || card == 3 || card == 4 || card == 5 || card == 6){
    count++;
    return (""+count+" Bet");
  }
  else if(card == 7 || card == 8 || card == 9){
    return (""+count+" Hold");
  }
  else if(card == 10 || card == 'J' || card == 'Q' || card == 'K' || card == 'A'){
    count--;
    return (""+count+" Hold");
  }


  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
not getting it
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.
It's a straight forward question. No idea where am i going wong
M-C-Haker
@M-C-Haker
Jul 03 2017 07:07
@SweetCodingInc to be honest man i'm having a hard time seeing how i'm going to solve with without .reduce or . sort
KZinDaHouse
@KZinDaHouse
Jul 03 2017 07:07

function golfScore(par, strokes) {
// Only change code below this line
if (strokes == 1){
return "Hole-in-one!";
} else if (strokes <= par-2){
return "Eagle";
} else if (strokes == par-1){
return "Birdie";
} else if (strokes == par){
return "Par";
} else if (strokes == par+1){
return "Bogey";
} else if (strokes == par+2){
return "Double Bogey";
} else {
return "Go Home";
}
// Only change code above this line
}

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

i did not pass the 'Go Home' test
i tried in another environment and it worked
iso
@iso1048
Jul 03 2017 07:09
$("#input").on('keyup', function (e) {
    if (e.keyCode == 13) {
            //code
    }
});
in the example above, what is e (the argument being passed in to the function) and where does it come?
thanks
Claudio Restifo
@Marmiz
Jul 03 2017 07:10
@owaisehmed How can you return if betting or not if you have yet to finish counting the card?
The idea is to update the count firsts... then after updating, check the count values and then return accordingly
KZinDaHouse
@KZinDaHouse
Jul 03 2017 07:10
nvm, i was missing '!'
Claudio Restifo
@Marmiz
Jul 03 2017 07:10
@gothamknight e is the browser event
try a console.log(e) and you'll see all the data that the browser pass with the event
wonder
@wonder2991
Jul 03 2017 07:18
@owaisehmed return after counting
Mai Thinh
@mthinh
Jul 03 2017 07:20
function diffArray(arr1, arr2) {
  var newArr = [];
  // Same, same; but different.
  newArr = arr1.concat(arr2);
  newArr =  newArr.filter(function(val,index,array){
    return array.indexOf(val) === index;
  });

  return newArr;
}

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
I got the result [1,2,3,5,4] after concat arr1 and arr2 ,
how I got 4 pls
wonder
@wonder2991
Jul 03 2017 07:23
your filter function is not right
makalohri
@makalohri
Jul 03 2017 07:24
@knrt10 thank you
CamperBot
@camperbot
Jul 03 2017 07:24
makalohri sends brownie points to @knrt10 :sparkles: :thumbsup: :sparkles:
:cookie: 446 | @knrt10 |http://www.freecodecamp.com/knrt10
connor-5
@connor-5
Jul 03 2017 07:24
@mthinh and you shouldn't concatenate the arrays
wonder
@wonder2991
Jul 03 2017 07:26
just take 1 argument val then you can compare with arr1 and see if val is found in arr1
iso
@iso1048
Jul 03 2017 07:26
@Marmiz thanks
CamperBot
@camperbot
Jul 03 2017 07:26
gothamknight sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:cookie: 980 | @marmiz |http://www.freecodecamp.com/marmiz
Joseph
@revisualize
Jul 03 2017 07:29
@connor-5 I did.
wonder
@wonder2991
Jul 03 2017 07:30
yeah. concat can work for just two arrays
connor-5
@connor-5
Jul 03 2017 07:32
I suppose so, but it still doesn't work with the way the filter function's set up (I don't think it can)
Mai Thinh
@mthinh
Jul 03 2017 07:41
function diffArray(arr1, arr2) {
  var newArr1 = [], newArr2=[];
  // Same, same; but different.
  newArr1=arr2.filter(function(val){
    return arr1.indexOf(val)===-1;
  });
  newArr2=arr1.filter(function(val){
    return arr2.indexOf(val)===-1;
  });
  return newArr1.concat(newArr2);


}

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
It works in this way
wonder
@wonder2991
Jul 03 2017 07:48
:thumbsup:
june808
@june808
Jul 03 2017 08:18
myStr should contain escaped characters and separate them in the order of the backslash TAB return operator
How do I write that?
var myStr="\ebu\tebv\rd\ns";
a27-suryansh
@a27-suryansh
Jul 03 2017 08:25
Hi can someone help me with JS i need help with Twitch Viewer
Thayyeb salim
@Thayyebsalim
Jul 03 2017 08:28
can someone help me with replacing the fist letter of every char in a str
Yulia
@GJMarvel
Jul 03 2017 08:51
hi everyone! i'm working on "Smallest Common Multiple" now. could you please explain me why we're expecting smallestCommons([1, 5]) should return 60? in my opinion it should be 5.am i wrong?
h1tag
@h1tag
Jul 03 2017 08:54
@june808 what's the challenge name?
@a27-suryansh what's the problem?
@h1tag
var result="";
$(document).ready(function() {

  var channels=["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"];
  var online=[];
  var offline=[];
for(var i=0; i<channels.length; i++) {
  $.getJSON("https://wind-bow.gomix.me/twitch-api/streams/" +channels[i]+"?callback=?", function(loadData){
   $(".result").html(result);
result+=JSON.stringify(loadData);

});        
}
    // why does this does not works// $(".result").html(result); //
});
Please check the comment @h1tag
h1tag
@h1tag
Jul 03 2017 08:56
@a27-suryansh we talked about this yesterday
a27-suryansh
@a27-suryansh
Jul 03 2017 08:56

I moved this

$(".result").html(result);

bit above and it gave the output why?

@h1tag
h1tag
@h1tag
Jul 03 2017 08:57
it's because $(".result").html(result); outside the getjson callback get executed before the result comeback from the api
a27-suryansh
@a27-suryansh
Jul 03 2017 08:57
Ok @h1tag
Thanks i got this @h1tag
kumquatfelafel
@kumquatfelafel
Jul 03 2017 08:58
@GJMarvel It's the least common multiple of the range of values from 1 to 5, not just 1 and 5. 60 is coming from 3 * 4 * 5 here.
CamperBot
@camperbot
Jul 03 2017 08:58
a27-suryansh sends brownie points to @h1tag :sparkles: :thumbsup: :sparkles:
:cookie: 885 | @h1tag |http://www.freecodecamp.com/h1tag
h1tag
@h1tag
Jul 03 2017 08:58
so everything u want to do with the data/result from the api after the result comes back should be inside the getjson callback
@a27-suryansh
a27-suryansh
@a27-suryansh
Jul 03 2017 08:59
Ok @h1tag
Thayyeb salim
@Thayyebsalim
Jul 03 2017 09:01
can someone help me to capitaize the first letter of every word in a setence
but how does it work?
wonder
@wonder2991
Jul 03 2017 09:03
@Thayyebsalim what's the challenge name?
wonder
@wonder2991
Jul 03 2017 09:05
how much have you figured out?
let's see your code
Thayyeb salim
@Thayyebsalim
Jul 03 2017 09:07
function titleCase(str) {
    var newTitle = str.split(' ');
    var updatedTitle = [];
    for (var st in newTitle) {
    }
    return updatedTitle.join(' ');

}

titleCase("I'm a little tea pot");
I'm confused about the logic section
how do i implement the charAt
wonder
@wonder2991
Jul 03 2017 09:11
first you need to convert the string to lower case before splitting
Thayyeb salim
@Thayyebsalim
Jul 03 2017 09:13
i understood that part but how do you select the first character of rach word
*each
wonder
@wonder2991
Jul 03 2017 09:13
that should return an array e.g ["i'm", "a", "little", "tea", "pot"];
Thayyeb salim
@Thayyebsalim
Jul 03 2017 09:13
yes
wonder
@wonder2991
Jul 03 2017 09:15
you need to access each array element then use charAt to capitalize the 1st char
Thayyeb salim
@Thayyebsalim
Jul 03 2017 09:15
is it done with a loop iteration
im confused about how to do that
wonder
@wonder2991
Jul 03 2017 09:16
yeah. you can use a for loop
Thayyeb salim
@Thayyebsalim
Jul 03 2017 09:17
the problem with me is that i have no idea how to select the first ones with charAt and a loop
Stuhl
@Stuhl
Jul 03 2017 09:18
U split them up and access each word wizh yourArr[i]
wonder
@wonder2991
Jul 03 2017 09:18
say str is your array, str[0] will be the first word
Thayyeb salim
@Thayyebsalim
Jul 03 2017 09:19
yes
wonder
@wonder2991
Jul 03 2017 09:20
use a for loop to iterate through the elements
Thayyeb salim
@Thayyebsalim
Jul 03 2017 09:20
ah i see
but how would o replace the first letter replaceAt(0,charAt(0).toUpperCase());?
wonder
@wonder2991
Jul 03 2017 09:24
 for(var i=0;i<str.length;i++){
          str[i].charAt(0).toUpperCase()
Thayyeb salim
@Thayyebsalim
Jul 03 2017 09:24
thanks @wonder2991
CamperBot
@camperbot
Jul 03 2017 09:24
:cookie: 379 | @wonder2991 |http://www.freecodecamp.com/wonder2991
thayyebsalim sends brownie points to @wonder2991 :sparkles: :thumbsup: :sparkles:
wonder
@wonder2991
Jul 03 2017 09:25
you will also need to concatenate the remaining characters
Thayyeb salim
@Thayyebsalim
Jul 03 2017 09:25
i wish i could give you a double brownie
can i pm you
wonder
@wonder2991
Jul 03 2017 09:25
sure
manuchehr94
@manuchehr94
Jul 03 2017 09:38
function dropElements(arr, func) {
  // Drop them elements.
  var newArr = [];
  for (var i = 0; i < arr.length; i++) {
    if (func(arr[i])) {
      return arr.slice(arr[i]);
    }
  }
  // console.log(arr);
}
console.log(dropElements([1, 2, 3, 4], function(n) {return n >= 3;}));
Why it's not slicing element "3"?
heroiczero
@heroiczero
Jul 03 2017 09:45
@manuchehr94 return arr.slice(arr[i]); will make your function to end the loop prematurely
manuchehr94
@manuchehr94
Jul 03 2017 09:47

@heroiczero

function dropElements(arr, func) {
  // Drop them elements.
  var newArr = [];
  for (var i = 0; i < arr.length; i++) {
    if (func(arr[i])) {
      return arr.slice(arr[i-1]);
    }

  }
  return []; 
  // console.log(arr);
}
console.log(dropElements([0, 1, 0, 1], function(n) {
  return n === 1;
}));

I tried like this but it's not passing one test.

Viktor Tiutiun
@vittorioVT
Jul 03 2017 09:49
@manuchehr94 slice() method creates a new array. It does not remove any elements from the source array
manuchehr94
@manuchehr94
Jul 03 2017 09:50
@vittorioVT and so?
Viktor Tiutiun
@vittorioVT
Jul 03 2017 09:54

@manuchehr94 for (var i = 0; i < arr.length; i++) {
if (func(i) === true) {
if (i === 1){
arr = arr.slice(i);
}
else {
arr = arr.slice(i - 1);
}
return arr;
}
}

return [];

heroiczero
@heroiczero
Jul 03 2017 09:57
@manuchehr94 personally, I would use shift rather than slice.
manuchehr94
@manuchehr94
Jul 03 2017 09:57
@heroiczero why?
heroiczero
@heroiczero
Jul 03 2017 09:58
@manuchehr94 because you are dropping the element if the function is true
manuchehr94
@manuchehr94
Jul 03 2017 09:59
@heroiczero hm...thanks
CamperBot
@camperbot
Jul 03 2017 09:59
manuchehr94 sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1450 | @heroiczero |http://www.freecodecamp.com/heroiczero
Rinor Bivolaku
@RinorNotorious
Jul 03 2017 10:22

Hello guys, can you help me find out why isn't this working? By isn't working, I mean why isn't it printing in HTML?
-
<body>
<div class = "random vertical-align">
<h1>Random Quote Generator</h1>
<div id = "quoteDisplay">
</div>
<button id = "quotes">New Quote</button>
<a target = "_blank">Tweet It Out, Man </a>
</div>

<script>
    var array = ["A", "B", "C", "D", "E"];

        var arrayLength = array.length; //number of entries in 

        var randomValue = Math.floor(Math.random() * arrayLength);
        var newQuote = array[randomValue];


        $('#quotes').click(function(){
            $("#quoteDisplay").html(newQuote);
        }); 

</script>
</body>

Pethaf
@Pethaf
Jul 03 2017 10:25
Have you checked that the $("#quotes").click( ) is actually ran when you load the page?
Dan Couper
@DanCouper
Jul 03 2017 10:26
You don't have jQuery available?
the error will say $ is not a function if so
because the function called $ that jQuery gives you won't exist
It all works fine if I have jQuery available, so I'm assuming it's that
Note it will pick a random letter then continue printing that same letter out, it won't pick a different random one unless you reload the page
Rinor Bivolaku
@RinorNotorious
Jul 03 2017 10:30
I forgot to put <script src="js/jquery.min.js"></script> at the top of the page and yes it's the problem that you say it is, printing the same letter
so what do I do to pick a random letter every time
?
Dan Couper
@DanCouper
Jul 03 2017 10:31
var randomValue = Math.floor(Math.random() * arrayLength); so this will give you say, 4, so randomValue is 4 in that case, it's always 4
you need to run the random stuff when it's clicked, at the minute you're just printing a value that's already been created
that fact it was originally created randomly isn't relevant, once it's created it is that value. Whereas if you run it all when a user clicks, then it will run the whole randomisation function again
Rinor Bivolaku
@RinorNotorious
Jul 03 2017 10:33
So what you mean is, put all the variables that I use, inside one function and to call that function later at the .html method?
Kevin
@kevinwr
Jul 03 2017 10:35

Hey, all.

Can anyone tell me what's wrong with my following code, please?

function getWeatherData() {
    //Create URL string for getJSON request
    var strURL = "https://api.darksky.net/forecast/660cb07514ae3e2fe39c452bb166ef31/" + latitude.toString() + "," + longitude.toString();


    function success(data) {
       $("#currentTemp").html(JSON.stringify(data));
    }

    $.getJSON(strURL, success); 


}

By the way, I tested to make sure strURL is indeed a string with the typeOf operator. then I also got the URL to output into a DIV, copied that URL into my browser, and was able to produce the JSON data. So this tells me something is wrong with my getJSON call or something.

Dan Couper
@DanCouper
Jul 03 2017 10:35
or just put everything in the callback, yes
Pethaf
@Pethaf
Jul 03 2017 10:36
@kevinwr So what is your success function?
Kevin
@kevinwr
Jul 03 2017 10:36
success
Pethaf
@Pethaf
Jul 03 2017 10:36
Do you have a function actually called success?
Kevin
@kevinwr
Jul 03 2017 10:36
yes
Dan Couper
@DanCouper
Jul 03 2017 10:36
it's there????
Kevin
@kevinwr
Jul 03 2017 10:36
yes
do you not see it?
Pethaf
@Pethaf
Jul 03 2017 10:36
Yes, I didn't read properly.
My misstake.
Dan Couper
@DanCouper
Jul 03 2017 10:36
:) lol
Kevin
@kevinwr
Jul 03 2017 10:37
oh ok lol
or URL, rather
Dan Couper
@DanCouper
Jul 03 2017 10:39
when you try it in codepen or whatever, what's the error in the console (note use the browser, not the codepen console)
Kevin
@kevinwr
Jul 03 2017 10:40
I'm using brackets editor
Alexander Køpke
@alexanderkopke
Jul 03 2017 10:41
you're using brackets in codepen? How?!
Kevin
@kevinwr
Jul 03 2017 10:41
no
not in codepen
on my computer lol
Alexander Køpke
@alexanderkopke
Jul 03 2017 10:41
oh!
silly me lol
Kevin
@kevinwr
Jul 03 2017 10:42
I'm not seeing anything that's standing out in the "report panel" brackets has
Maybe let me post my code into codepen, and I'll hand you the link
Alexander Køpke
@alexanderkopke
Jul 03 2017 10:43
are you using the mini server that comes with brackets?
Dan Couper
@DanCouper
Jul 03 2017 10:43

@RinorNotorious eg

$('#quotes').click(function() {
  var array = ["A", "B", "C", "D", "E"];
  var randomValue = Math.floor(Math.random() * array.length);
  $("#quoteDisplay").html(randomValue);
});

or something like

function randomValue(array) {
    return array[Math.floor(Math.random() * array.length)];
}

$('#quotes').click(function(){
  $("#quoteDisplay").html(randomValue(["A", "B", "C", "D", "E"]));
});
@alexanderkopke no. not using any server
except my local storage
and links to scripts and CSS I need
Alexander Køpke
@alexanderkopke
Jul 03 2017 10:52
@kevinwr add ?callback=? to the end of th url: latitude.toString() + "," + longitude.toString()+"?callback=?";
Rinor Bivolaku
@RinorNotorious
Jul 03 2017 10:53
@DanCouper Thank you, I did it like this:
-
<script>
var array = ["A", "B", "C", "D", "E"];
    function getQuote(){    
         arrayLength = array.length; //number of entries in array
         randomValue = Math.floor(Math.random() * arrayLength);
         newQuote = array[randomValue];    
        $('#quoteDisplay').html(newQuote);
    };    

        $(document).ready(function() {
            $('#quotes').click(function(){
                getQuote();
            }); 
        });

</script>
CamperBot
@camperbot
Jul 03 2017 10:53
rinornotorious sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:cookie: 822 | @dancouper |http://www.freecodecamp.com/dancouper
Rinor Bivolaku
@RinorNotorious
Jul 03 2017 10:53
But now, I need to tweet out the random letter
Kevin
@kevinwr
Jul 03 2017 10:54
@alexanderkopke OMG that worked. What does that code do?!
I didn't see anywhere in the documentation to add that
Alexander Køpke
@alexanderkopke
Jul 03 2017 10:59
@kevinwr I wish I knew exactly why. It has to do with security. Basically it means it accepts the input from the url whereas before it didn't.
Pethaf
@Pethaf
Jul 03 2017 10:59
@alexanderkopke JSONP, right?
Alexander Køpke
@alexanderkopke
Jul 03 2017 10:59
yeah
Pethaf
@Pethaf
Jul 03 2017 10:59
Allowing a remote source to call a local function.
Alexander Køpke
@alexanderkopke
Jul 03 2017 11:01
with $.ajax one would set it with dataType="JSONP" or something. But I don't understand why, I just do it when needed and leave the techy info to the experts :laughing:
Pethaf
@Pethaf
Jul 03 2017 11:02
JSONP stands for json with padding.
Is is basically an abuse of the fact that remote sites are allowed to call local functions.
Alexander Køpke
@alexanderkopke
Jul 03 2017 11:02
but it would be nice if apis included it in their docs because I have seen it needed often
ok
Kevin
@kevinwr
Jul 03 2017 11:04
hmmmm ooooook
makes no sense hahaha
Alexander Køpke
@alexanderkopke
Jul 03 2017 11:04
are or aren't allowed? @Pethaf
Pethaf
@Pethaf
Jul 03 2017 11:05
Are allowed.
Alexander Køpke
@alexanderkopke
Jul 03 2017 11:05
remote sites are allowed to call local functions.. that is interesting
Pethaf
@Pethaf
Jul 03 2017 11:05
You pass the name of the local function as a parameter in the query string.
Alexander Køpke
@alexanderkopke
Jul 03 2017 11:06
and so the padding is the json or whatever passed to that function?
Pethaf
@Pethaf
Jul 03 2017 11:06
I could probably dig out the relevant part from Head First HTML5 at opportuntity.
Alexander Køpke
@alexanderkopke
Jul 03 2017 11:07
@Pethaf thank you
why camperbot never works for me :(
Jasper
@Jasperaine
Jul 03 2017 11:09
Hello, Please could somebody help me with my Wikipedia app. Cant see why this error is appearing - https://codepen.io/Jasperaine/pen/vZyORW - Thank you!
Kevin
@kevinwr
Jul 03 2017 11:09
and now I'm trying to pass quarry parameters and doesn't look like the parameters are working
mother fudger lol
Kevin
@kevinwr
Jul 03 2017 11:16
it produces a JSON object, but just not what I thought it would be. I expected the object to be smaller since I'm supposed to be filtering out things to make the return shorter
looks like the same length to me
Alexander Køpke
@alexanderkopke
Jul 03 2017 11:17
ah ok so the reason for the ? in callback=? is that the function that is called is the anonymous tht gets called in the getJSON method. Imma test something
abraham anak agung
@padunk
Jul 03 2017 11:18
@Jasperaine first you need to call your id with $('#id-name') and you forget + sign after data[2][i]
Kevin
@kevinwr
Jul 03 2017 11:19
I'm kinda' frustrated because I've been "learning" a lot lately about AJAX, JSON, and re"learning" some things about javascript, but yet I can't seem to remember what I'm reading.
for instance, like what parameters "getCurrentPosition" takes, etc.
Alexander Køpke
@alexanderkopke
Jul 03 2017 11:22
@kevinwr that is normal. There is so much information that no one can remember. Coders use google everyday because the code you write has to be exact or it won't work. So if you can remember fine but if you can't just google it. It's fine too :)
Kevin
@kevinwr
Jul 03 2017 11:23
Yeah...I understand that. Still frustrating because I feel like nobody would ever want to hire me (when I get to that point), because it would take me forever to do anything since I'd be looking up crap all day
lol
Daniel Lim
@ddanielnp
Jul 03 2017 11:23

<div id="u1" class="topbun"></div>

<div id="u2" class="cheese"></div>

<div id="u3" class="meat"></div>

<div id="u4" class="lettuce"></div>

<div id="u5" class="onion"></div>

<div id="u6" class="cucumber"></div>

<div id="u7" class="botbun"></div>
is there anyway where i can change only the 5 class='ingredients' into class='hamItems'? less topbun and botbun, using DOM and javascript

bilaal-s
@bilaal-s
Jul 03 2017 11:23
@kevinwr it gets better with time, trust me
Kevin
@kevinwr
Jul 03 2017 11:24
@bilaal-s I sure hope so, Bilaal-s
because right now I feel like I'm an idiot
bilaal-s
@bilaal-s
Jul 03 2017 11:25
@kevinwr Keep going, thats the most important thing, eventually, you will get to where you want. Your skill will improve, and youll look back and laugh at the old days
To all, can anyone figure out why my code isn't working? I cant... I have been through 19 revisions over 5 days. https://repl.it/JFZW/19
Kevin
@kevinwr
Jul 03 2017 11:26
I guess we shall see. Definitely going to keep pressing, though
Kshitijaa Jaglan
@KshitijaaJaglan
Jul 03 2017 11:32

Can someone help me out with this code...

function reverseString(str) {
  return str;
}

reverseString ("sup");
str = reverseString.split('');
str.reverse();
str.join('');

It gives the error

TypeError: reverseString.split is not a function
Alexander Køpke
@alexanderkopke
Jul 03 2017 11:33
@kevinwr what helps me is looking back at times when I struggled with other things that I now know how to do. Struggling is part of it. The reason it sucks is because the struggle is eternal when it comes to coding. So it never feels like you get to rest on a plateau because there is always another things you "must" learn. That is part of why this industry is different and more difficult than other industries. But the thing is, if you keep going you will get there! I've been doing this for two years now. Still feel like crap but looking back I'm definitely better than a year ago. I'm a slow learner though. My take is. I'm giving it 3-4 years. If I'm not a professional coder by then I'll give it another 3-4 years and then I'll see where I'm at. My friends and family say I have to have a degree etc and I tell them, no I don't, not if I'm good enough. Imma do dis!! :smiling_imp: :fire: :sparkles: :smile:
abraham anak agung
@padunk
Jul 03 2017 11:33
@KshitijaaJaglan put your code inside a function
Kshitijaa Jaglan
@KshitijaaJaglan
Jul 03 2017 11:35
@padunk It didn't work.
Kevin
@kevinwr
Jul 03 2017 11:36
@KshitijaaJaglan you need to put your code inside the function. then just need to split str, reverse it, and then join it.
Alan Alickovic
@alan2207
Jul 03 2017 11:36
@KshitijaaJaglan put your code inside the function
Kshitijaa Jaglan
@KshitijaaJaglan
Jul 03 2017 11:37
but the problem is that it asked that the input and the output should both be strings
Daniel Lim
@ddanielnp
Jul 03 2017 11:37
@KshitijaaJaglan put all the str =... inside the function
and then return str
Kshitijaa Jaglan
@KshitijaaJaglan
Jul 03 2017 11:38
I tried this.
function reverseString ("hello"){
str = reverseString.split('');
str.reverse();
str.join('');}
Alan Alickovic
@alan2207
Jul 03 2017 11:38
@KshitijaaJaglan you need to return it
Kevin
@kevinwr
Jul 03 2017 11:38
@alexanderkopke thanks for the input and advice. All I can do is keep pressing and keep trying my best. It's all I can do.
CamperBot
@camperbot
Jul 03 2017 11:38
kevinwr sends brownie points to @alexanderkopke :sparkles: :thumbsup: :sparkles:
:star2: 1593 | @alexanderkopke |http://www.freecodecamp.com/alexanderkopke
Kshitijaa Jaglan
@KshitijaaJaglan
Jul 03 2017 11:39

@alan2207 the whole code is


function reverseString(str) {
  return str;
}

function reverseString ("hello"){
str = reverseString.split('');
str.reverse();
str.join('');}

They have already mentioned return.

Kevin
@kevinwr
Jul 03 2017 11:40
Try something like this @KshitijaaJaglan
function reverseString(str) {

str.split("");
str.reverse();
str.join("");
}

reversestring("Reverse this string");
sabahatullah
@sabahatullah
Jul 03 2017 11:40
Hey guys can some one help me. I am trying to add jQuery to this website https://www.windeln.de/
but it gives me error. could you tell me whats wrong with the following code
var jQuery = document.createElement("script");
jQuery.type = "text/javascript";
jQuery.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js";
$("footer").append(jQuery);
Kevin
@kevinwr
Jul 03 2017 11:41
@KshitijaaJaglan Sorry, the bottom call is supposed to be reverseString("Reverse this string");
wonder
@wonder2991
Jul 03 2017 11:42
and no return
Ken Haduch
@khaduch
Jul 03 2017 11:42
@sabahatullah - I don't know if you can do what you're trying to do, but you cannot add jQuery to the site using jQuery code - your last line $("footer").append(jQuery); is jquery code, but if jQuery isn't loaded, then you cannot use it?
Kevin
@kevinwr
Jul 03 2017 11:43
@KshitijaaJaglan yeah, then you'll want to return str.
Daniel Lim
@ddanielnp
Jul 03 2017 11:43
function reverseString(str) {

str = str.split("")
str = str.reverse()
str = str.join("")
return str
}

reverseString("hello")
Kshitijaa Jaglan
@KshitijaaJaglan
Jul 03 2017 11:44

@kevinwr The complete code is this

function reverseString(str) {
  return str;
}

reverseString("hello");
str = reverseString.split('');
str.reverse();
str.join('');

and they have already defined reverseString in the function.

Daniel Lim
@ddanielnp
Jul 03 2017 11:44
@KshitijaaJaglan
function reverseString(str) {

str = str.split("")
str = str.reverse()
str = str.join("")
return str
}

reverseString("hello")
or try this
function reverseString(str) {

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

return str
}

reverseString("hello")
EpicTriffid
@EpicTriffid
Jul 03 2017 11:46
Hi all, so im still a little confused and APIs, and why they do/don't work sometimes. Any ideas why this one doesnt work to get the user's city?
$(document).ready(function() {
$("#but").on('click', function() {
$("#location").fadeOut(function() {
$.getJSON('https://geoip-db.com/jsonp')
.done(function(loc) {
$("#location").html(loc[0].city);
});
}).fadeIn();
});
});
bilaal-s
@bilaal-s
Jul 03 2017 11:46
Any ideas as to where im going wrong? this is the smallest common multiple algorithm
function smallestCommons(arr) {
  arr.sort((a, b) => a - b);
  let number1 = arr[0];
  let number2 = arr[1];
  let number1arr = [];
  let number2arr = [];
  let lcm;
  let toMultiply1 = 1;
  let toMultiply2 = 1;
  let lcmFound = false;
  let rangeArr = [];
  let lcmIndex = 0;
  let isDivisibleByAll;
  let lcmDivisible;


  function addMultiples() {
    for (let j = 1; j <= 100; j++) {
      number1arr.push(arr[0] * toMultiply1);
      toMultiply1++;
    }
    number2arr.push(arr[1] * toMultiply2);
    toMultiply2++;
  }

  addMultiples();

  function findLcm(index) {
    for (let i = index; i < number2arr.length; i++) {
      if (number1arr.indexOf(number2arr[i]) > -1) {
        lcm = number2arr[i];
        lcmFound = true;
        lcmIndex = number2arr.indexOf(number2arr[i]);
        break;
      }
    }
  }

  while (lcmFound === false) {
    addMultiples();
    findLcm(0);
  }

  for (let k = arr[0]; k <= arr[1]; k++) {
    rangeArr.push(k);
  }

  function checkIfDivisible() {
    for (let l = 0; l < rangeArr.length; l++) {
      if (lcm % rangeArr[l] !== 0) {
        console.log(lcm + " is divisible not by: " + rangeArr[l]);
        isDivisibleByAll = false;
        lcmFound = false;
        break;
      }      
    }
    console.log("Divisible by all!");
    lcmFound = true;
    lcmDivisible = lcm;
    isDivisibleByAll = true;
  }

  while (isDivisibleByAll === false) {
    while (lcmFound === false) {
      addMultiples();
      findLcm(0);
    }
    checkIfDivisible();
  }

  console.log(lcmDivisible);
  return lcmDivisible;
}


smallestCommons([23, 18]);
sabahatullah
@sabahatullah
Jul 03 2017 11:47
@khaduch thanks for pointing out my mistake. It works with Javascript :)
CamperBot
@camperbot
Jul 03 2017 11:47
sabahatullah sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3066 | @khaduch |http://www.freecodecamp.com/khaduch
Kshitijaa Jaglan
@KshitijaaJaglan
Jul 03 2017 11:47
thanks @ddanielnp @kevinwr . It worked. The second last code by @ddanielnp
CamperBot
@camperbot
Jul 03 2017 11:47
kshitijaajaglan sends brownie points to @ddanielnp and @kevinwr :sparkles: :thumbsup: :sparkles:
:warning: @kevinwr's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
:cookie: 151 | @ddanielnp |http://www.freecodecamp.com/ddanielnp
Daniel Lim
@ddanielnp
Jul 03 2017 11:47
@KshitijaaJaglan thats how functions work
Kshitijaa Jaglan
@KshitijaaJaglan
Jul 03 2017 11:48
oh thanks
abraham anak agung
@padunk
Jul 03 2017 11:55
@bilaal-s hey, im not good at read your code but your code is complicated, you hv 3 functions inside a function but return nothing in each of it
bilaal-s
@bilaal-s
Jul 03 2017 11:55
@padunk dont worry :) ill try solve it
Greg Duncan
@GregatGit
Jul 03 2017 11:56
@bilaal-s the problem is not as difficult as you made it - I would start again looking for simpler ways
bilaal-s
@bilaal-s
Jul 03 2017 11:57
@GregatGit ok!
Chris_Bo
@krzysztofbogusz91
Jul 03 2017 11:59
hi, well i have a problem with this code, I'm trying to get same result as from jQuery function below(it works fine) but just with JavaScript and I run out of ideas how to get it working. I would appreciate some help.
window.onload = function(){

   var xhr = new XMLHttpsRequest();

    xhr.onradystagechange= function(){
        if(xhr.readyState===4 && xhr.status===200){
            console.log(JSON.parse(xhr.response));
        }

    };
   xhr.open('GET', 'https://ipapi.co/json', true);
    xhr.send('');
   /*

    $.get('https://ipapi.co/json', function(data){

        console.log(data);

    })
    */
};
manuchehr94
@manuchehr94
Jul 03 2017 12:01
  for (var i = 0; i < arr.length; i++) {
    if (func(arr[i])) { //func is a function
      return arr[i];
    }
  }
Hey, guys. How can I rewrite this code? I'm trying to avoid for loop whenever it's possible. I know that forEach returns nothing but if there any elegant solution?
Dan Couper
@DanCouper
Jul 03 2017 12:02
the onradystagechange incantation is a misspelling

arr.filter(func)
manuchehr94
@manuchehr94
Jul 03 2017 12:06
@DanCouper but filter returns an array
Dan Couper
@DanCouper
Jul 03 2017 12:07
arr.forEach(v => {
  if (func(v)) return v;
});

or maybe

for (const el of arr) if (func(el)) return el;

or in more forgiving syntax

for (const el of arr) {
  if (func(el)) {
    return el;
  }
}
Chris_Bo
@krzysztofbogusz91
Jul 03 2017 12:09
@DanCouper true, but still there is an error XMLHttpsRequest is not defined
at window.onload (javascript.js:3)
Dan Couper
@DanCouper
Jul 03 2017 12:09
XMLHttpRequest
EpicTriffid
@EpicTriffid
Jul 03 2017 12:11
@EpicTriffid
Hi all, so im still a little confused and APIs, and why they do/don't work sometimes. Any ideas why this one doesnt work to get the user's city?
$(document).ready(function() {
$("#but").on('click', function() {
$("#location").fadeOut(function() {
$.getJSON('https://geoip-db.com/jsonp')
.done(function(loc) {
$("#location").html(loc[0].city);
});
}).fadeIn();
});
});
Chris_Bo
@krzysztofbogusz91
Jul 03 2017 12:13
@DanCouper oh yeah, thanks!
CamperBot
@camperbot
Jul 03 2017 12:13
:cookie: 823 | @dancouper |http://www.freecodecamp.com/dancouper
krzysztofbogusz050591 sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
Dan Couper
@DanCouper
Jul 03 2017 12:13
;)
@EpicTriffid you cannot use the getJSON function in this instance, you should use the $.ajax function with the correct parameters - if I transcribe the example from https://geoip-db.com, it works
Chris_Bo
@krzysztofbogusz91
Jul 03 2017 12:17
@DanCouper so there is no error now but it won't print JSON and I'm not sure why?
Ken Haduch
@khaduch
Jul 03 2017 12:22
@bilaal-s - I was going to make a similar comment to @GregatGit - for me the key to this is that the multiples that you generate have to be multiples of the larger of the two numbers, that's the only way you'll get a value that works. Try to incorporate that idea into your solution. It can indeed be solved in a less complicated way.
EpicTriffid
@EpicTriffid
Jul 03 2017 12:26
@DanCouper Thankyou! Why does JSON not work in this instance?
Stephen James
@sjames1958gm
Jul 03 2017 12:29
@krzysztofbogusz050591 Is there such an thing as XMLHttpsRequest? Only XMLHttpRequest in my browser
Chris_Bo
@krzysztofbogusz91
Jul 03 2017 12:30
@sjames1958gm no there is not it was a mistake (i was testing a dumb idea and then forgot to corect before pasting it here)
Stephen James
@sjames1958gm
Jul 03 2017 12:31
@krzysztofbogusz050591 Ah, didn't see anyone had answered you, so thought maybe that was the issue
Dan Couper
@DanCouper
Jul 03 2017 12:32

@EpicTriffid it is because of CORS:

For security reasons, browsers restrict cross-origin HTTP requests initiated from within scripts. For example, XMLHttpRequest and Fetch follow the same-origin policy. So, a web application using XMLHttpRequest or Fetch could only make HTTP requests to its own domain. To improve web applications, developers asked browser vendors to allow cross-domain requests.

In this case, the API owner has not allowed cross origin requests. JSONP allows you to cheat - it tricks the browser by writing a script into the head of your document, which in turn calls the script. The browser then thinks that the script it requesting is local, from somewhere you control.

Chris_Bo
@krzysztofbogusz91
Jul 03 2017 12:33
well now there is no error(after correting misspellings), but console log is not working
Dan Couper
@DanCouper
Jul 03 2017 12:34
Could you show the updated code, with the console.log included?
Chris_Bo
@krzysztofbogusz91
Jul 03 2017 12:34
sure,
window.onload = function(){

   var xhr = new XMLHttpRequest();

    xhr.onreadystagechange = function(){
        if(xhr.readyState===4 && xhr.status===200){
            console.log(JSON.parse(xhr.response));
        }

    };
   xhr.open('GET', 'https://ipapi.co/json', true);
    xhr.send('');
   /*

    $.get('https://ipapi.co/json', function(data){

        console.log(data);

    })
    */
};
ISU
@isu17
Jul 03 2017 12:40
How to properly hide my js info ? Even with private variables where the user cant change them, they can be seen if called right. I am talking about an api key that I dont want to be seen
shivam gupta
@shivamg11000
Jul 03 2017 12:41
@isu17 you can use encrypt
encrypt the key
Stephen James
@sjames1958gm
Jul 03 2017 12:41
@krzysztofbogusz050591 mispelling - onreadystatechange (you have stage)
Chris_Bo
@krzysztofbogusz91
Jul 03 2017 12:43
@sjames1958gm it worked, thank you.... I'm totally bind today!
CamperBot
@camperbot
Jul 03 2017 12:43
krzysztofbogusz050591 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7982 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 03 2017 12:44
@krzysztofbogusz050591 I ran it several times before I saw it
Jasper
@Jasperaine
Jul 03 2017 12:44
@padunk Thank you! got it searching now! do you also know how i would change the search results. They are currently returning with the least relevant at the top.
CamperBot
@camperbot
Jul 03 2017 12:44
jasperaine sends brownie points to @padunk :sparkles: :thumbsup: :sparkles:
:cookie: 371 | @padunk |http://www.freecodecamp.com/padunk
Stephen James
@sjames1958gm
Jul 03 2017 12:44
@isu17 You cannot hide your API key. Likely you would have to only use API keys from your back end and deliver the data to your front end.
Dan Couper
@DanCouper
Jul 03 2017 12:45
@isu17 It is not possible, not for frontend JS code, pernickety hackers will unscramble your secrets no matter how much you obfuscate them
Paul
@faux-pas
Jul 03 2017 12:45

Hey all. I'm going through the YDKJS book series and I'm hitting my head against the wall on closures.

<script src="https://gist.github.com/faux-pas/bfd5e46c347bb4a6eb429bc641123d39.js"></script>
(I hope i've done that right)

Why does a for loop stop working as I'd expect and print 6 five times? The code inside the loop executes each time,

fuck
ISU
@isu17
Jul 03 2017 12:45
Well.. I thought I was in the wrong and didn't know the magic way to do it...
Paul
@faux-pas
Jul 03 2017 12:46
I thought that would embed the code snippet
ISU
@isu17
Jul 03 2017 12:46
so how should I proceed with my weather app if I am "hosting" it on code pen ?
It should be no problem if the key is visible right ?
Dan Couper
@DanCouper
Jul 03 2017 12:46
just paste the url direct @faux-pas, it should work
Eric
@Zaknefeinn
Jul 03 2017 12:47
Paul, use ` before and after the snippet.
Paul
@faux-pas
Jul 03 2017 12:47
Ah my bad, thankyou @DanCouper
CamperBot
@camperbot
Jul 03 2017 12:47
faux-pas sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:cookie: 824 | @dancouper |http://www.freecodecamp.com/dancouper
Dan Couper
@DanCouper
Jul 03 2017 12:47
:) :thumbsup:
Eric
@Zaknefeinn
Jul 03 2017 12:48
Your changing the vap
Dan Couper
@DanCouper
Jul 03 2017 12:48
@isu17 you don't really have a choice as it relates to the weather app: unless you pull in the data on some backend you have yourself built, you will have to include an API key
Diego Mayer
@Chrono79
Jul 03 2017 12:48
@faux-pas when the function inside timeout runs i value is 6, the loop ended before that
try using let instead of var
Paul
@faux-pas
Jul 03 2017 12:49
@Chrono79 How can the loop end if it's inside the for loop? I mean, how is the loop able to increment without first executing the code inside of it?
Diego Mayer
@Chrono79
Jul 03 2017 12:50
@faux-pas the code is executed, it says, do a console.log after x seconds, i value keeps changing with each loop
ISU
@isu17
Jul 03 2017 12:51
@DanCouper if I do that, do you think it will be overkill? :D
Paul
@faux-pas
Jul 03 2017 12:53
@Chrono79 So it waits say 1000ms and during that time the for loop finishes its iterations?
Diego Mayer
@Chrono79
Jul 03 2017 12:53
@faux-pas yes
UnkyKong
@UnkyKong
Jul 03 2017 12:53
https://codepen.io/Unky/pen/WOzozg?editors=0100 how do I my .pic div to be the same height as my .result div
Dan Couper
@DanCouper
Jul 03 2017 12:53
@isu17 :) it would be an excellent exercise - if you really do wish to try it, then glitch would be a good platform, to allow you to write a full Node application, front-end and back-end (note it will be quite painful, but it is not too hard, there is but a very small amount of functionality).
Diego Mayer
@Chrono79
Jul 03 2017 12:54
@faux-pas it works with let instead of var
https://repl.it/JLbO/0
Dan Couper
@DanCouper
Jul 03 2017 12:55
jesus christ i read this "Hexing the Technical Interview" blogpost someone posted in the main chatroom and it's infected me and all my writing has gone really archaic "there is but a small amount of functionality" :\
Paul
@faux-pas
Jul 03 2017 12:57
@Chrono79 Now I don't understand again. Your previous explanation was that the code executed each time but the pause meant that by the time that code was executed the value of i reached 6. Why does it work with let? My understanding of let is that it just binds the variable to that block scope. Shouldn't the pause still mean the value ends up reaching 6 before console.log is run?
Moisés Man
@moigithub
Jul 03 2017 12:57
Paul
@faux-pas
Jul 03 2017 12:57
Also sorry for not getting it
JeroPRC
@JeroPRC
Jul 03 2017 13:07

I've been stuck for days in the "Factorialize a Number"challenge. Is using a for loop like this too far away of a possible solution?:

for (i = 1; i <= num; i++) {
times = times * (times + i)
}

Ahmed Ramy
@Shadilix
Jul 03 2017 13:07
can someone help me with an approach to Chunky Monkey challenge ?
Diego Mayer
@Chrono79
Jul 03 2017 13:11
@JeroPRC that won't work, what's the initial value of times?
Let's say it's 1, the first time 1 * 2 is 2, the next time, you make it 2 * 4, the next one, 4 * 7
Diego Mayer
@Chrono79
Jul 03 2017 13:18
@JeroPRC it's not too far away, but you need to fix it, so you actually do a factorial: 1*2*3*4*...*n
bilaal-s
@bilaal-s
Jul 03 2017 13:20
@Chrono79 Hello diego, could ask you to look at this code for me? ive commented it for you so its easier to follow: https://repl.it/JFZW/21
JeroPRC
@JeroPRC
Jul 03 2017 13:20
@Chrono79 So, in that case what is the for loop actually doing? Is it generating numbers from 1 to num? Because what I'm trying to do is to generate those numbers and then multiply them, but I don't actually know if I'm generating them in the first place.
bilaal-s
@bilaal-s
Jul 03 2017 13:20
@Chrono79 it correctly adds multiples and finds lcm. everything after that doesn't seem to work, i think its checkDivisble function or my while statement after that
Diego Mayer
@Chrono79
Jul 03 2017 13:21
@JeroPRC i holds those numbers, you have to fix times = times * (times + i) <- this
JeroPRC
@JeroPRC
Jul 03 2017 13:22
@Chrono79 Ok, I'll get to it, thanks a lot :)
CamperBot
@camperbot
Jul 03 2017 13:22
jeroprc sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4453 | @chrono79 |http://www.freecodecamp.com/chrono79
Gus
@Guscoder
Jul 03 2017 13:22
Hi, any advice on this--the Profile Lookup. Can't seem to get it to fully work right.
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


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