3rd
Sep 2017
Stephen James
@sjames1958gm
Sep 03 2017 00:02
It is when a function calls itself. The recursive function will define a base case where it can return immediately
Otherwise it calls itself with a value that is from the input but closer to the base case.
``````function sum(n) {
if (n == 1) return 1;
return n + sum (n - 1);
}``````
that is a recursive function for summing numbers n through 1
if n is one (the base case simply return 1
else return the value that is n plus the sum of the numbers n - 1 through 1
When n reaches 1 on all the calls, the each function return will build up the sum back to the original call
Ginger
@GingerChew
Sep 03 2017 00:03
okay, that makes sense
thanks @sjames1958gm
CamperBot
@camperbot
Sep 03 2017 00:04
gingerchew sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8429 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Sep 03 2017 00:04
@GingerChew :+1:
John
@AnonymousLords
Sep 03 2017 00:31
rooms
CamperBot
@camperbot
Sep 03 2017 00:31

#### freeCodeCamp rooms:

:point_right: Here is a list of our official chat rooms
John
@AnonymousLords
Sep 03 2017 00:32
Guys i have just finished basic algorithm, i am continuing jQurray and started Json
``````
<script>

\$("#getMessage").on("click", function() {
\$.getJSON("/json/cats.json", function(json) {

var html = "";

json = json.filter(function(val) {
return (val.id !== 1);
});

json.forEach(function(val) {

html += "<div class = 'cat'>"

html += "<img src = '" + val.imageLink + "' " + "alt='" + val.altText + "'>"

html += "</div>"

});

\$(".message").html(html);

});
});
});``````
How is it able to get a certain cat pictures and filter the one out it wants?
I know their is teh filter, but is their a database for these pictures? and house is certian pictures === 1 but some dont?
FlashHero
@FlashHero
Sep 03 2017 00:49
Nodejs help, What is the difference between `connect.sid`and `req.cookies` in nodejs and which one contains the id assigned from `passport.serialize`
luccifer00
@luccifer00
Sep 03 2017 00:57
``````for (var i = 0; i < decimalValue.length; i++) {
while (decimalValue[i] <= num) {
romanized += romanNumeral[i];
num -= decimalValue[i];
}
}``````
someone can explain me how Works the `num-=decimalValue[i];` line?? i understand all except this line, i dont know how it Works....
John
@AnonymousLords
Sep 03 2017 01:02
`num = num - decimalValue[i];`
@luccifer00
luccifer00
@luccifer00
Sep 03 2017 01:05
`````` var decimalValue = [ 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 ];
var romanNumeral = [ 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I' ];

var romanized = '';

for (var index = 0; index < decimalValue.length; index++) {
while (decimalValue[index] <= num) {
romanized += romanNumeral[index];
num -= decimalValue[index];
}
}

return romanized;
}``````
but in thise code... @AnonymousLords if num is "8" how that con oparete??
it means Num(8) = Num(8)-decimalValue[i] means(9)
i dont understand how the function get the VIII
Sep 03 2017 01:35
@luccifer00 - it seems like it would be an excellent learning exercise to take this code over to the http://pythontutor.com/javascript.html page, plug it in and run it...
glitz20
@glitz20
Sep 03 2017 01:35
hey guys how can I globally set variables in express?
Sep 03 2017 01:39
@luccifer00 - just saw your question above - that line is reducing the value of the `num` by the numeric value at the `decimalValue[i]` position - the simplest one is if you have a num of, say `3500` - you would want to get three "M" characters, so you would have a descending value of your `num` from 3500 to 2500 to 1500 to 500, at which time you would jump to the next `decimalValue` array location.
Moisés Man
@moigithub
Sep 03 2017 01:40
luccifer00
@luccifer00
Sep 03 2017 01:42
yhes @khaduch you where right, the pytontutor is perfect for explain the exercice!! thanks a lot!
CamperBot
@camperbot
Sep 03 2017 01:42
luccifer00 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
Sep 03 2017 01:45
@luccifer00 - you're welcome! It's a helpful tool, for sure.
Daniel
@DanJP2016
Sep 03 2017 02:02
finished with the convert a number to roman numerals challenge. Trying to do it without a loop, and i'm wondering if someone can tell me if my solution can be made to run faster. https://codepen.io/bones211/pen/qXvEaO?editors=0011
Mai Thinh
@mthinh
Sep 03 2017 02:15
``````function startGame(){
botGiveTest();
isGiven = true;

if(isGiven){

\$('.box').click(function(){
isPlayed = false;
let ID,box= this;
ID=box.id
playerPlay(ID);

});
}//end of if
botGiveTest();
}//end of function start the game``````
hey guys, this is my function, i wanna call botGiveTest() again, only after playerPlay(ID) finished, how can i do, they start all together, that's not what I want .
Moisés Man
@moigithub
Sep 03 2017 02:24
``````function one(ID, callback){
// do something with ID
console.log(ID);
//after finish.. call the callback
callback('world');
}

function two(something){ console.log('hello '+ something) }

one(1, two)``````
it will log 1 .. then hello world
Mai Thinh
@mthinh
Sep 03 2017 02:27
@moigithub thank you
CamperBot
@camperbot
Sep 03 2017 02:27
mthinh sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3622 | @moigithub |http://www.freecodecamp.com/moigithub
Sep 03 2017 02:56
@DanJP2016 - that's a different approach to the Roman Numerals challenge! I don't know if there is any way that you could speed things up - each condition is unique, I wondered if you could have simplified the code with a lookup object, but that probably isn't doable? One thing that I think you are doing that is not necessary - when you are doing things like `romans.push(val = 'D');` - you don't really need the `val` in there, do you? It isn't really useful to be changing the value of `val` in that case.
Daniel
@DanJP2016
Sep 03 2017 03:03
@khaduch thanks for the feedback. val is the number being pulled from the temp array to be processed, it still needs to be converted to the roman numeral. I though about using a matrix or array to match the value to a key, but I felt the problem could be solved without a loop and wanted to try avoiding using one. It runs between 2ms and 4ms in chrome. is that a good speed?
CamperBot
@camperbot
Sep 03 2017 03:03
danjp2016 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
Sep 03 2017 03:08
@DanJP2016 - I took a different approach to my solution - I didn't really use a loop in my code, other than to generate the number of "M" values for the thousands. Your approach for the repeating values is neat. I didn't try to time mine to see if it is fast or slow. I guess I didn't think about that aspect of it at the time for a relatively simple problem. How did you arrive at the time values that you got?
Daniel
@DanJP2016
Sep 03 2017 03:10
i used console.time('key') / console.timeEnd('key') to get a rough estimate of how long it was taking to comlete
complete*
Sep 03 2017 03:12

@DanJP2016 - did you know that you can edit your post here in the chat for a few minutes after you make it? If you just hit the up arrow, it will open the comment and you can edit it. Just a little tip... You can also click on the three dots that appear when you hover over the time that you made your post, and there is an edit option there.

I'll have to see what happens with my solution for that?

Daniel
@DanJP2016
Sep 03 2017 03:13
@khaduch I did not know that lol. that will come in handy though thanks !
CamperBot
@camperbot
Sep 03 2017 03:13
danjp2016 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
Sep 03 2017 03:29
@DanJP2016 - I didn't know about `console.time` and `console.timeEnd`. I tried them with mine, and I got numbers all over the place. But it's a nice thing to know about - thanks!
CamperBot
@camperbot
Sep 03 2017 03:29
khaduch sends brownie points to @danjp2016 :sparkles: :thumbsup: :sparkles:
Gersho
@Gersho
Sep 03 2017 03:33
@DanJP2016 kinda like the way you did it, but couldn't you remplace some of the if/elseif with a switch ?
Daniel
@DanJP2016
Sep 03 2017 03:37
@Gersho i'm working on trying to remove some of that now. i don't know if a switch would shorten it any though, maybe a seperate function?
Gersho
@Gersho
Sep 03 2017 03:38
i'll show you mine to compare
Daniel
@DanJP2016
Sep 03 2017 03:38
ok
Gersho
@Gersho
Sep 03 2017 03:38
``````

function convertToRoman(num) {

var numArr = num.toString().split("");
var romArr=[];

if (numArr.length<4){

for (i=numArr.length; i<4; i++){
numArr.unshift("0");
}
}

switch (numArr[0]) {

case "1":
romArr.push("M");
break;

case "2":
romArr.push("MM");
break;

case "3":
romArr.push("MMM");
break;

}

switch (numArr[1]) {

case "1":
romArr.push("C");
break;

case "2":
romArr.push("CC");
break;

case "3":
romArr.push("CCC");
break;

case "4":
romArr.push("CD");
break;

case "5":
romArr.push("D");
break;

case "6":
romArr.push("DC");
break;
case "7":
romArr.push("DCC");
break;

case "8":
romArr.push("DCCC");
break;

case "9":
romArr.push("CM");
break;
}

switch (numArr[2]) {

case "1":
romArr.push("X");
break;

case "2":
romArr.push("XX");
break;

case "3":
romArr.push("XXX");
break;

case "4":
romArr.push("XL");
break;

case "5":
romArr.push("L");
break;

case "6":
romArr.push("LX");
break;

case "7":
romArr.push("LXX");
break;

case "8":
romArr.push("LXXX");
break;

case "9":
romArr.push("XC");
break;
}

switch (numArr[3]) {

case "1":
romArr.push("I");
break;

case "2":
romArr.push("II");
break;

case "3":
romArr.push("III");
break;

case "4":
romArr.push("IV");
break;

case "5":
romArr.push("V");
break;

case "6":
romArr.push("VI");
break;
case "7":
romArr.push("VII");
break;

case "8":
romArr.push("VIII");
break;

case "9":
romArr.push("IX");
break;
}

/*
1 = I
5 = V
10 = X
50 = L
100 = C
500 = D
1000 = M
*/

var romStr = romArr.join("");

return romStr;

}

convertToRoman(649);``````
in the end, it only calls once per digit, but i've never tried the time thing you mentioned earlier
Daniel
@DanJP2016
Sep 03 2017 03:41
looks like we had a similar idea for solving it.
Gersho
@Gersho
Sep 03 2017 03:41
i went to a math site and looked for their method to do it "normally" and turned it to code
Daniel
@DanJP2016
Sep 03 2017 03:43
my original idea was to convert the number into unicode and match it the correct roman numeral..that ended up a dead end, then I got the idea to just test the length of the string, and treat it like a queue. multiply the first number in the array by 10 or 100 or 1000 depending on the length of the array
for the first number that worked out, but I could not figure out how to keep the process going without needing to loop through something to get the roman numerals
kumquatfelafel
@kumquatfelafel
Sep 03 2017 03:44
@Gersho This is kinda long.
Gersho
@Gersho
Sep 03 2017 03:45
@kumquatfelafel in terms of lines maybe, but most of them aren't called upon
kumquatfelafel
@kumquatfelafel
Sep 03 2017 03:58
@Gersho Nonetheless, I'm not so sure it's ideal. There seems to be a lot of code repetition. For example, note that only two things are changing in your final three switch statements... numArr[1] becomes numArr[2] becomes numArr[3], and the string being pushed is different. But the push statement is otherwise the same... The breaks are otherwise the same... the cases are otherwise the same. Do you think there's a way you could significantly cut down on the amount of code you're writing here?
korzo
@korzo
Sep 03 2017 04:02
@Gersho Using lookup object you should save a lot of line. I have seen this method (convert number to string) solved in 30 lines.
Anyway, using subtraction in loop is easier solution
Gersho
@Gersho
Sep 03 2017 04:05
my aim wasn't line number, had tried with loops, but i hated how it looked like
piteto
@piteto
Sep 03 2017 04:06
Some people prefer switch statements
I just did that one with a for loop that has a while loop inside, lots and lots of loops
Gersho
@Gersho
Sep 03 2017 04:07
"easier" is an objective concept, but that's ok, it's always cool to see different versions of the same stuff
piteto
@piteto
Sep 03 2017 04:07
Must be a better way, but it worked, so moving on
Is anyone here familiar with \$.when by chance? I asked over in front end for someone to look at my code and didn't get a response
help front end*
Gersho
@Gersho
Sep 03 2017 04:10
i had a look at the doc, so it's like promise ?
piteto
@piteto
Sep 03 2017 04:13
It's jQuery's version of Promise.all
takes an array of deferred objects, like getJSON and processes them all at once
Gersho
@Gersho
Sep 03 2017 04:15
ooh...i was wondering the point of having promise since there is already callback in ajax calls, but you mean you can link all your ajax together and have a single callback when all of them resolved ?
Daniel
@DanJP2016
Sep 03 2017 04:15
promise.all rejects if any of the promises reject i think.
piteto
@piteto
Sep 03 2017 04:16
Yes, like this:
``````\$.when([
\$.getJSON(url1),
\$.getJSON(url2)
]).done(function(data) {
// both calls complete
});``````
Gersho
@Gersho
Sep 03 2017 04:16
@piteto thanks, i'll sleep smarter ! (and will have forgotten tomorrow)
CamperBot
@camperbot
Sep 03 2017 04:16
gersho sends brownie points to @piteto :sparkles: :thumbsup: :sparkles:
piteto
@piteto
Sep 03 2017 04:16
lol
Gersho
@Gersho
Sep 03 2017 04:16
oh you're new here ? welcome
piteto
@piteto
Sep 03 2017 04:16
Yeah, just trying to get through the front end first to do back end
kumquatfelafel
@kumquatfelafel
Sep 03 2017 04:17

@piteto the problem is, switch as deployed here would quickly become really hard to read, write and maintain, so bad practice. Consider if it went into not only 1000s, but 10000s... 100000s... etc. Following this logic, you'd need to write a separate switch statement for each new digit. This would be like saying

``````console.log(1);
console.log(2);
...
console.log(92487);
console.log(92488);``````

It's something you just won't do if you can avoid it.

Using object lookup as @korzo notes above, you can significantly cut down on the number of lines of code you have to write, and if you wanted to add another digit, e.g., you could just update the object (assuming the logic being followed is the same). So adding like 7 or so characters as opposed to writing another switch statement.

piteto
@piteto
Sep 03 2017 04:19
I'm personally not a fan of switch statements, mainly for readability like you say
whenever I have to take over someone's code and they're using switch statements, I convert it to a lookup
Gersho
@Gersho
Sep 03 2017 04:19
@kumquatfelafel adding new digit ? the code is meant to support standard roman letters, so only up to 3999, so it won't get longer (and adding more digits, would require reworking the code no matter what version you chose since it would mean including the special symbols)
piteto
@piteto
Sep 03 2017 04:19
But....there are switch fans out there haha
Gersho
@Gersho
Sep 03 2017 04:20
i see your point, but for a project of this scale i do not agree with it
but i do agree it would be detrimental for other uses
korzo
@korzo
Sep 03 2017 04:22
@piteto I don't think it's good idea to use \$.when in this case.
It will resolve when all are resolved. If some request hangs, you will wait until it timeouts.
Also you have to provide function for rejected promises. IMHO twitch api fails pretty often
Daniel
@DanJP2016
Sep 03 2017 04:22
i think the map call is causing the problem. it's trying to process elements that are not there or something weird like that.
piteto
@piteto
Sep 03 2017 04:24
@korzo Thanks for looking. I haven't added any failure cases yet or ajax timeout settings, just wanted to get it working and thought it seemed like a lot of extra work to add \$.when to the apiCalls array and then do \$.when again on that. Was wondering if there was a better way to use \$.when
CamperBot
@camperbot
Sep 03 2017 04:24
piteto sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
piteto
@piteto
Sep 03 2017 04:30
@korzo This handles the failures pretty well from a few minimal tests with invalid URLs and network throttling:
``````\$(document).ajaxError(console.error);
\$.ajaxSetup({timeout: 3000});``````
Gersho
@Gersho
Sep 03 2017 04:30
isn't this gonna explose at the face of the end user ?
piteto
@piteto
Sep 03 2017 04:30
Curious though - what's a better way to handle 16 API calls?
Instead of `console.error`, I'd capture the error and present it in the HTML
Gersho
@Gersho
Sep 03 2017 04:31
i'd say make less API call but i suppose it depends on your needs
Daniel
@DanJP2016
Sep 03 2017 04:31
you only need to make the second api call if the streamer is offline
piteto
@piteto
Sep 03 2017 04:31
hmmm, I should have checked if I can call all the users at once instead of each one individually
Gersho
@Gersho
Sep 03 2017 04:31
you can't
the url contains the username, so only 1 user per call
piteto
@piteto
Sep 03 2017 04:32
that would be a very good optimization @DanJP2016 thank you, I'll look into that
CamperBot
@camperbot
Sep 03 2017 04:32
piteto sends brownie points to @danjp2016 :sparkles: :thumbsup: :sparkles:
Daniel
@DanJP2016
Sep 03 2017 04:32
piteto
@piteto
Sep 03 2017 04:34
@Gersho thanks for confirming - no way to add multiple users in a query string... still stuck with lots of API calls :/
CamperBot
@camperbot
Sep 03 2017 04:34
piteto sends brownie points to @gersho :sparkles: :thumbsup: :sparkles:
korzo
@korzo
Sep 03 2017 04:34
@piteto I haven't worked on this yet, but I would chain callback calls.
Or if you want to go promise way, you can create getUser and getChannels function returning promise and create promise chain.
piteto
@piteto
Sep 03 2017 04:34
I'm new to jQuery, but doesn't getJSON return a promise?
Gersho
@Gersho
Sep 03 2017 04:34
it has a builtin callback
piteto
@piteto
Sep 03 2017 04:35
Yeah, getJSON is a deferred object from what I read
Daniel
@DanJP2016
Sep 03 2017 04:35
i believe it is just the standard xmlhttprequest setup
piteto
@piteto
Sep 03 2017 04:36
``````function getUser(user) {
return \$.getJSON(url + user);
}

getUser('freecodecamp').then(function(data) {
// promise resolved, do something with the data
})``````
korzo
@korzo
Sep 03 2017 04:38
@piteto it's shorthand for \$.ajax
Gersho
@Gersho
Sep 03 2017 04:38
you'd need an error handler too
``````p.then(function(value) {
// fulfillment
}, function(reason) {
// rejection
});``````
piteto
@piteto
Sep 03 2017 04:39
Yes @korzo I like getJSON because it's a simple one-liner
Gersho
@Gersho
Sep 03 2017 04:40
and even in one liner version, you can still set ajax options like
``````   \$.ajaxSetup({
cache: false
});``````
korzo
@korzo
Sep 03 2017 04:40
@piteto My point was that it has same behavior, so it returns defered object and you can use .then or .done
piteto
@piteto
Sep 03 2017 04:41
I thought that's what I was doing with \$.when though?
an array of promises
korzo
@korzo
Sep 03 2017 04:47
@piteto I'm not sure what happen when one promise reject using \$.when.
Because with Promise.all , if one promise reject, it will reject all.
And it's not desired in this situation
piteto
@piteto
Sep 03 2017 04:52
@korzo Yeah, I just tested it out, all of the remaining calls fail after one failure.
Well, a good learning experience I guess :)
korzo
@korzo
Sep 03 2017 04:52
@piteto That's what I thought.
piteto
@piteto
Sep 03 2017 04:54
Looks like a nightmare to work around from a quick search and I didn't realize that jQuery isn't Promises/A+ compliant...
korzo
@korzo
Sep 03 2017 04:54
@piteto that's why I said I would better chain promises or you can use \$.when on per user pair of ajax calls
piteto
@piteto
Sep 03 2017 04:54
Back to vanilla js - my jQuery days are over lol
Marc
@MWBauer
Sep 03 2017 04:56
Hey everyone. I was looking for more information on the certificates that we earn here.
HOw does that work?
Gersho
@Gersho
Sep 03 2017 04:57
what do you mean ?
Marc
@MWBauer
Sep 03 2017 04:58
I mean, do we have to do anything special, or do we just keep following the syllabus and it's given to us?
Gersho
@Gersho
Sep 03 2017 04:59
depends what you imply by "given", it's not like they're gonna send it to you
korzo
@korzo
Sep 03 2017 04:59
@MWBauer For certificate you have to finish all challenges/projects marked with  * in given section
Sep 03 2017 05:27
can anyone tell me anyone good books for javascript and jquery
Ravi Kishore Thella
@ravikishorethella
Sep 03 2017 05:36
@prakashyadav008 `ydkjs series` and `eloquent js`
Sep 03 2017 05:42
ydkjs first books is pretty basic
book*
@ravikishorethella
Ravi Kishore Thella
@ravikishorethella
Sep 03 2017 05:44
@prakashyadav008 read all the books. They are not basic, you will learn new stuff
Sep 03 2017 05:45
i cant buy all five or six books
right
does eloquent.js explain regular expression in detail
..?
eloquent js*
Razvan Jackson
@RazvanJackson
Sep 03 2017 05:48
Hello
Is it possible to do a auth system with node such as php?
Ravi Kishore Thella
@ravikishorethella
Sep 03 2017 05:57
Ayush Bahuguna
@relentless-coder
Sep 03 2017 05:59
Razvan Jackson
@RazvanJackson
Sep 03 2017 05:59
yes
@relentless-coder With MYsql
@relentless-coder Can we talk in private?
Ahmed raza
@Raza403
Sep 03 2017 06:45
Hi I need little help for twitch api project. I am unable to retrieve JSON as described in this link, can anyone help me doing it https://wind-bow.glitch.me/
glitz20
@glitz20
Sep 03 2017 07:00
hey anyone who can please let me know why I cannot go to product page?https://glitch.com/edit/#!/product-review?path=views/product.ejs:7:8
@relentless-coder any idea?
Ayush Bahuguna
@relentless-coder
Sep 03 2017 07:06
@sabin20 just a minute
@sabin20 it says the product is not defined
glitz20
@glitz20
Sep 03 2017 07:07
@relentless-coder so I have designed page for each product and when you click the link at the home page, it is supposed to go to that page
Ayush Bahuguna
@relentless-coder
Sep 03 2017 07:07

@sabin20

``````router.get("/product/:title", function(req, res, next){
Product.findOne({title: req.params.title}, function(err, product){
if(err) {return next(err);}
if(!product){return next (404);}
res.render("product");
});
});``````

in `res.render("product")` you need to pass along `product`

so something like `res.render("product", {product: product})`
glitz20
@glitz20
Sep 03 2017 07:09
gotcha thanks @relentless-coder
CamperBot
@camperbot
Sep 03 2017 07:09
sabin20 sends brownie points to @relentless-coder :sparkles: :thumbsup: :sparkles:
glitz20
@glitz20
Sep 03 2017 07:49
@relentless-coder how can I write one to many relation in express?
for eg how can I display product detail along with its comment?
Fernando
@lestairon
Sep 03 2017 08:03
:/
glitz20
@glitz20
Sep 03 2017 08:04
@EneCatalin do you have any idea?
Fernando
@lestairon
Sep 03 2017 08:05
Why is it not working?
glitz20
@glitz20
Sep 03 2017 08:05
@lestairon you missed a bracket
Fernando
@lestairon
Sep 03 2017 08:05
Where?
glitz20
@glitz20
Sep 03 2017 08:06
a-b))
Sweet Coding :)
@SweetCodingInc
Sep 03 2017 08:06
@lestairon on line 4. Just put an extra `)` before `;`
Ene Catalin
@EneCatalin
Sep 03 2017 08:06
@sabin20 sorry, new to node myself and I have exams for the next two weeks :|
Sweet Coding :)
@SweetCodingInc
Sep 03 2017 08:06
@sabin20 You need to embed product detail doc in your product doc
glitz20
@glitz20
Sep 03 2017 08:07
cool @EneCatalin
@SweetCodingInc can you help me do that?
it would be more clear through demonstration
Sweet Coding :)
@SweetCodingInc
Sep 03 2017 08:09
Example - assuming `ProductDetails` is the collection where you're storing details of all the products
``````router.get("/product/:title", function(req, res, next){
Product.findOne({title: req.params.title}, function(err, product){
if(err) {return next(err);}
if(!product){return next (404);}
ProductDetails.find({id: product.id}, function(err, details){
product.details = details
res.render("product", {product});
});
});
});``````
@sabin20
glitz20
@glitz20
Sep 03 2017 08:11
so I should be creating new collection which contains comments as well as product info?
Fernando
@lestairon
Sep 03 2017 08:12
@sabin20 @SweetCodingInc
Fernando
@lestairon
Sep 03 2017 08:18
HM
glitz20
@glitz20
Sep 03 2017 08:19
@lestairon =>(a-b)
you missed ( before a
Fernando
@lestairon
Sep 03 2017 08:19
`TypeError: arr.push(...).sort is not a function`
alpox
@alpox
Sep 03 2017 08:19
@lestairon take a look at what `.push` returns. You cannot chain it with sort.
@lestairon `.push`"The new length property of the object upon which the method was called." - MDN
glitz20
@glitz20
Sep 03 2017 08:22
@alpox are you familiar with express?
alpox
@alpox
Sep 03 2017 08:22
returns*
@sabin20 i am :)
glitz20
@glitz20
Sep 03 2017 08:22
@alpox sweet. So how can create one to many data in express?
so basically, I want to have my product detail and comment in the product page
alpox
@alpox
Sep 03 2017 08:23
@sabin20 i believe you mix things up. Express is not about relating data. Its about creating a REST interface to your data
@sabin20 i guess what you are talking about is mongodb
glitz20
@glitz20
Sep 03 2017 08:24
Yeah, I just assumed that
Yeah Mongo it is
alpox
@alpox
Sep 03 2017 08:25
@sabin20 and you use mongoose there for accessing it. So you can google for one to many relationship in mongoose
I believe that would tell you more than i could in here :)
glitz20
@glitz20
Sep 03 2017 08:26
can you please have a look at my project and I can tell what problem I am facing
alpox
@alpox
Sep 03 2017 08:27
@sabin20 your comment schema will need the object id of products
glitz20
@glitz20
Sep 03 2017 08:27
I did look at mongo document, but didnot find useful
as of now, I donot have product id, So I should be creating one?
alpox
@alpox
Sep 03 2017 08:29
Take a look at this :) this is what you need
glitz20
@glitz20
Sep 03 2017 08:30
cool @alpox thanks
CamperBot
@camperbot
Sep 03 2017 08:30
sabin20 sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1324 | @alpox |http://www.freecodecamp.com/alpox
alpox
@alpox
Sep 03 2017 08:31
@sabin20 np :)
Pethaf
@Pethaf
Sep 03 2017 08:31
Is P = NP?
alpox
@alpox
Sep 03 2017 08:37
@Pethaf noone can yet tell because there is no proof but the possibility
L
Sweet Coding :)
@SweetCodingInc
Sep 03 2017 08:43
@sabin20 Yeah.. Following mongo philosophy, you're better off creating one document that contains everything about the product.
but if you want to be able to manage it with better control, you should consider creating a separate collection that contains product details and another collection for comments.. And then embed documents from details and comments collection in to your product document
glitz20
@glitz20
Sep 03 2017 08:45
@SweetCodingInc exactly I wanted to do that
Daniel Romero
@Ranacode
Sep 03 2017 09:35
Hey guys I have one problem on Javascript,
I have this logic here, the thing is that my variable "profileData" is still empty out of the function but inside the profileData object have the data
``````    var profileData = { title: "", description: "", url: "" };

Profile.find({}, function(error, profile) {
if (error) throw new Error(error);

profileData.description = profile[0].description;
profileData.title = profile[0].title;
profileData.url = profile[0].imageURL;

// console.log(JSON.stringify(profile, undefined, 2));
// console.log("SEPARACION DE OBJETOS");
console.log(JSON.stringify(profileData, undefined, 2));

})
console.log(JSON.stringify(profileData, undefined, 2));

//CONSOLE OUTPUT:

{
"title": "",
"description": "",
"url": ""
}

{
"title": "LA EDUCACIÓN QUE AYUDA A TU MASCOTA",
"description": "Lorem ipsum dolor sit amet consectetur adipisicing elit. Aperiam animi quae cupiditate corrupti quo explicabo, nam perspiciatis deleniti laudantium id! Quidem sapiente velit tenetur vitae culpa eius, architecto sed vel!",
I don't know why exactly
Is not supposed to reassign my profileData variable ?
Abhinav Mishra
@abhinav-m
Sep 03 2017 09:39
no
you're printing inside the callback which is a function
the `console.log` outside the function prints first, as an empty object.
then the inner one gets printed.
Caleb David
@microworlds
Sep 03 2017 09:40
Welcome to the world of async programming
Abhinav Mishra
@abhinav-m
Sep 03 2017 09:40
which has the value
Daniel Romero
@Ranacode
Sep 03 2017 09:40
ou true, I forgot completely the async behavior
heroiczero
@heroiczero
Sep 03 2017 09:40
lol async = complete stuff before you complete stuff inside the async box
Daniel Romero
@Ranacode
Sep 03 2017 09:41
should I use .then to do things when the stuff is finished?
Abhinav Mishra
@abhinav-m
Sep 03 2017 09:42
does the callback return a promise object?
Daniel Romero
@Ranacode
Sep 03 2017 09:42
I'm gonna check on the mongoose docs
Ou yeah it works
Thank guys
thanks @heroiczero @abhinav-thinktank
CamperBot
@camperbot
Sep 03 2017 09:45
ranacode sends brownie points to @heroiczero and @abhinav-thinktank :sparkles: :thumbsup: :sparkles:
:star2: 1688 | @heroiczero |http://www.freecodecamp.com/heroiczero
Jefferson
@jeffersonnnn
Sep 03 2017 09:54

Hi guys, i have a question from the Seek and Destroy challenge. Here is my code

``````
function destroyer(arr) {
var newArray = array.prototype.slice.call(destroyer, 1);
}

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

Now, using the array.prototype.slice.call, i have sought to cut away the part of the `destroyer` argument that is outside the array. What i need to know is if upon using the array.prototype, my arguments return ```([1, 2, 3, 1, 2, 3], [ 2, 3])

Jefferson
@jeffersonnnn
Sep 03 2017 10:05
@Pethaf how does using the arguments object work. I have seen `...args` before, but how would it work?
Pethaf
@Pethaf
Sep 03 2017 10:06
I was in error.
It seem that the method you suggested is equivalent.
Markus Kiili
@Masd925
Sep 03 2017 10:10
@jeffersonnnn `var newArray = Array.prototype.slice.call(arguments, 1);`
Takes the array-like object `arguments` and makes an array from it from index 1.
Jefferson
@jeffersonnnn
Sep 03 2017 10:17
oh well. Happens to the best of us haha. So what then is wrong
so now, does this mean that what ever comes after the array has been made into an array?
Sep 03 2017 10:19
hey can anyone help me out
i am trying to apply the transition property but cant see the effect
``\$(".wiki-link").css({"text-decoration":"none","transition-property":"all","transition-duration":"1.3s","color":"rgb(40, 105, 255)"});``
thats the code for transition effect
``````.wiki-link:hover{
transform:scale(2.2);
color:purple;
}``````
Jefferson
@jeffersonnnn
Sep 03 2017 10:26
@Masd925 @Pethaf i can't seem to make it work on pythontutor
Markus Kiili
@Masd925
Sep 03 2017 10:27
@jeffersonnnn `Array.prototype.slice` is the array slice method. `.call()` there calls slice upon the array-like `arguments` object. By using call you can use array methods on array-like objects like arguments and Nodelist etc.
@jeffersonnnn Post the code again here.
Jefferson
@jeffersonnnn
Sep 03 2017 10:35
Alrighty then
``````
function destroyer(arr) {
var newArray = array.prototype.slice.call(destroyer, 1);
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);``````
@Masd925
Markus Kiili
@Masd925
Sep 03 2017 10:37
@jeffersonnnn `Array`, not `array`.
`(arguments,1)`, not `(destroyer,1)`
You are not using the new array `newArray` in any way there.
You could return it and test if it works by calling the function.
Fernando
@lestairon
Sep 03 2017 10:53
``````function rot13(str) { // LBH QVQ VG!

return str.split("").map((L) => L.charCodeAt()).replace(/[A-Z]/g, (X) => X.);
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");``````
Halp pls, i'm stucked lol
Jefferson
@jeffersonnnn
Sep 03 2017 10:54
@Masd925 well i have removed the `destroyer`. But you say there isn't much to do with the newArray huh.
Markus Kiili
@Masd925
Sep 03 2017 10:55
@jeffersonnnn I said that your code is creating the newArray but not using it yet.
You can use `arr` and `newArray` now to solve the problem.
@lestairon You should use replace on str.
Sweet Coding :)
@SweetCodingInc
Sep 03 2017 10:57

@jeffersonnnn

``var newArray = array.prototype.slice.call(destroyer, 1);``

should be

``var newArray = Array.prototype.slice.call(arguments, 1);``
luccifer00
@luccifer00
Sep 03 2017 10:58
``````
function pairElement(str) {
var test = [{A:["T"], T: ["A"], C:["G"], G:["C"]}];
var newArr=[];
var trol =[];
str = str.split("");
newArr = test.map(function(str){
for (var i in test){
var lett = str[i];
while (lett == test[0].lett){
return true;
}
}
});
return newArr;
}

pairElement("GCG");``````
sorry guys, i think i am close to, but i am losing the way to do it right... i am crazy with that way to do it?? it is the DNA pair Challenge...
Sweet Coding :)
@SweetCodingInc
Sep 03 2017 10:58
it should be `Array.prototype` not `array.prototype` AND you need to pass `arguments to`slice`not`destroyer`
Markus Kiili
@Masd925
Sep 03 2017 10:58
@luccifer00 The solution would be easier if you used just `var pairs = {A:'T', T: 'A', C: 'G', G: 'C'};`
luccifer00
@luccifer00
Sep 03 2017 11:00
@Masd925 i test it with that before, but in order to get the results in differents arrays, i thougth it will be easier..., any ways, with `var pairs = {A:'T', T: 'A', C: 'G', G: 'C'};`i also get stuck
Markus Kiili
@Masd925
Sep 03 2017 11:02
@luccifer00 You could use map and just map `val` -> `[val,pairs[val]]`
Fernando
@lestairon
Sep 03 2017 11:08
Ugh, being a newbie programmer is so overwhelming :worried:
Ahmed raza
@Raza403
Sep 03 2017 11:27
Hi I need to solve little bug in my code of twitch api, I get json back from api, I try to put description of video as described in "User stories" but that is not being appended I have commented out this in code, You can also see it in "Inspect element" https://codepen.io/raza403/pen/qXgpwj
I am facing problem appending html paragraph using javascript here
Stephen James
@sjames1958gm
Sep 03 2017 11:52
@Raza403 `for (var i=0;i<3;i++){` When you get the data back from the getJSON call (in the callback)
the variable i is set to 3 because the loop has completed so ids[i] is undefined.
console.log(ids[i]);
you will see undefined in the console.
You can replace var with let `for (let i=0;i<3;i++){`
And you wont have that problem
http://stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example
Ahmed raza
@Raza403
Sep 03 2017 11:56
@sjames1958gm thanks you so much, not only I solved the problem but also learned something new.
CamperBot
@camperbot
Sep 03 2017 11:56
raza403 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8431 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Sep 03 2017 11:57
@Raza403 :+1:
DiscoBoris
@DiscoBoris
Sep 03 2017 11:59
Hey guys... quick question! Is there a shorthand way of writing if statements with a condition that can take several values? i.e instead of `if (data.weather[0].id === "200" || data.weather[0].id === "201" || .....)` can I write something like `if (data.weather[0].id === "200" ,"201")`?
Stephen James
@sjames1958gm
Sep 03 2017 11:59
@DiscoBoris No
DiscoBoris
@DiscoBoris
Sep 03 2017 11:59
argh!
Stephen James
@sjames1958gm
Sep 03 2017 12:00
@DiscoBoris However you could put the values into an array and you indexOf
DiscoBoris
@DiscoBoris
Sep 03 2017 12:00
aaaaah, yes, of course!
thank you!
how do I give points?
Stephen James
@sjames1958gm
Sep 03 2017 12:00
@DiscoBoris :+!
:+1:
You reference me and say thanks
@DiscoBoris like this - thx
CamperBot
@camperbot
Sep 03 2017 12:01
sjames1958gm sends brownie points to @discoboris :sparkles: :thumbsup: :sparkles:
DiscoBoris
@DiscoBoris
Sep 03 2017 12:01
@sjames1958gm thanks
@sjames1958gm - thx
CamperBot
@camperbot
Sep 03 2017 12:02
discoboris sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8432 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
DiscoBoris
@DiscoBoris
Sep 03 2017 12:02
theeeere we go
Stephen James
@sjames1958gm
Sep 03 2017 12:02
@DiscoBoris :)
lfvpCO
@lfvpCO
Sep 03 2017 13:00
guys this a new room for JS basics. its public and I hope you enjoy it. the main purpose is to develope basics codes in JS and generate new projects ideas.https://gitter.im/JS-A-team/Lobby?utm_source=share-link&utm_medium=link&utm_campaign=share-link
Kelechi Chinaka
@ke1echi
Sep 03 2017 13:03
``````function sortItOut(array){
let odd = [], even = [];
for (let i = 0; i < array.length; i++) {
(array[i] % 2 === 0) ? even.push(array[i]) : odd.push(array[i])
}
return odd.sort((a,b) => a-b).concat(even.sort((a,b) => b-a))
}``````
passes all but fails random test, i know i am missing something in the description
https://www.codewars.com/kata/sorting-the-odd-way/train/javascript @sjames1958gm
Stephen James
@sjames1958gm
Sep 03 2017 13:05
If the array contains decimals, round them down while checking for odd/even.
You aren't handling this case.
Kelechi Chinaka
@ke1echi
Sep 03 2017 13:07
knew i missed something
Stephen James
@sjames1958gm
Sep 03 2017 13:15
@kelechy You can do it in one sort.
``````function sortItOut(array){
return array.sort((a, b) => {
let ap = Math.floor(a);
let bp = Math.floor(b);

return (ap % 2 === bp % 2
? (ap % 2 === 1 ? ap - bp : bp - ap)
: (ap % 2 === 1 ? -1 : 1))
})
}``````
Kelechi Chinaka
@ke1echi
Sep 03 2017 13:18
nice @sjames1958gm
Kelechi Chinaka
@ke1echi
Sep 03 2017 13:24
``````function sortItOut(array){
let odd = [], even = [];
for (let i = 0; i < array.length; i++) {
(Math.floor(array[i]) % 2 === 0) ? even.push(array[i]) : odd.push(array[i])
}
return odd.sort((a,b) => a-b).concat(even.sort((a,b) => b-a))
}``````
fixed the missing part @sjames1958gm
Razvan Jackson
@RazvanJackson
Sep 03 2017 13:48
Who's doing freelancing?
Pethaf
@Pethaf
Sep 03 2017 14:24
I tried, realized that for every single job there are 200 people out there willing to work for \$3/hour.
Then I gave up.
Ronique Ricketts
@RoniqueRicketts
Sep 03 2017 14:30
@Pethaf so what do u do now
Pethaf
@Pethaf
Sep 03 2017 14:31
Bum around.
Generally.
I am trying to get into a work-training program to learn programming.
Ronique Ricketts
@RoniqueRicketts
Sep 03 2017 14:33
Oh that would be good
Pethaf
@Pethaf
Sep 03 2017 14:33
I don't think I am going to learn a lot of programming in 12 weeks, but there are 12 weeks of guaranteed internship at the end.
And there you get references.
Ronique Ricketts
@RoniqueRicketts
Sep 03 2017 14:35
I want one of those
Pethaf
@Pethaf
Sep 03 2017 14:39
Well.
Aren't there 4 volounteer projects at the end of free code camp?
Oleh
@Lufter
Sep 03 2017 14:48
Hey guys, i don't really understand how can i write a code that would “inherit” and object from another object, overriding some of the parent’s functions. Could anyone please provide a simple example?
Pethaf
@Pethaf
Sep 03 2017 14:53
Are you asking for a practical illustration of the concept of inheritance or a code example?
Oleh
@Lufter
Sep 03 2017 14:53
code example
Markus Kiili
@Masd925
Sep 03 2017 14:57
``````function Animal() {
}

Animal.prototype.move = function() {
console.log("Animal moves");
};

Animal.prototype.MakeSound = function() {
console.log("Make animal sound");
};

function Horse() {

}

Horse.prototype = Object.create(Animal.prototype);

Horse.prototype.MakeSound = function(){
console.log("Prrrrr");
};

var myHorse = new Horse();

var myAnimal = new Animal();

myAnimal.move(); //      Animal moves
myAnimal.MakeSound(); // Make animal sound

myHorse.move(); //      Animal moves
myHorse.MakeSound(); // Prrrrr``````
So horses overwrite the makeSound property (method).
@Lufter
This is just one way.
Oleh
@Lufter
Sep 03 2017 14:59
@Masd925 thx
CamperBot
@camperbot
Sep 03 2017 14:59
lufter sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4468 | @masd925 |http://www.freecodecamp.com/masd925
Marc
@MWBauer
Sep 03 2017 15:47
Morning everyone
koder3
@koder3
Sep 03 2017 15:51
hi guys! how do i use babel stage 2 preset in an IDE like VS code
i dont understand the instructions provided on their page
Daniel Romero
@Ranacode
Sep 03 2017 15:52
Hi guys, I have a server question. I'm using express and nodejs on the serve side. The fact is, I have two forms in the same html page with the method "POST". How can I know which form was clicked in the server side to determine the flow of the data?
I want to try avoid differentes "actions" on the form attribute
Just do all the stuff in the same route
Marc
@MWBauer
Sep 03 2017 15:57
I'm currently trying to finish the largest number challenge.
``````function largestOfFour(arr) {
var biggest = [];
var big = 0;
for (i = 0; i < arr.length; i++) {
for (j = 0; j < arr[i].length; j++) {
if (arr[i][j] > big)
big = arr[i][j];
}
}
return arr[i][j];
biggest.push(big);
}``````
Currently it rejects telling me it cant get the property of 4
Daniel Romero
@Ranacode
Sep 03 2017 15:59
That's because when you return a value inside a function,
everything you write further will not be interpreted
try to push biggest.push(big) above the return
Marc
@MWBauer
Sep 03 2017 16:00
I don't think I need the return. I think it was just to show me where the code is and what it was doing.
piteto
@piteto
Sep 03 2017 16:00
@MWBauer `i` and `j` are undefined outside of your loop, return `big` instead of `arr[i][j]`
Marc
@MWBauer
Sep 03 2017 16:01
Remove the return command and now I get no answer in my box.
``````function largestOfFour(arr) {
var biggest = [];
var big = 0;
for (i = 0; i < arr.length; i++) {
for (j = 0; j < arr[i].length; j++) {
if (arr[i][j] > big)
big = arr[i][j];
}
}
biggest.push(big);
}``````
Daniel Romero
@Ranacode
Sep 03 2017 16:01
Don't remove the return lol
just change this:
``````
function largestOfFour(arr) {
var biggest = [];
var big = 0;
for (i = 0; i < arr.length; i++) {
for (j = 0; j < arr[i].length; j++) {
if (arr[i][j] > big)
big = arr[i][j];
}
}
biggest.push(big);
return big;
}``````
Marc
@MWBauer
Sep 03 2017 16:02
It technically answers correctly, the biggest is 1001
So, am I building an array with my loop?
Because that's what I'm trying to do.
piteto
@piteto
Sep 03 2017 16:04
move .push() inside your loop to build an array with your loop
Then return `biggest` rather than `big`
Marc
@MWBauer
Sep 03 2017 16:05
Ok. So I moved the push and returned biggest. I get every element as 1 array
piteto
@piteto
Sep 03 2017 16:06
push goes in your first loop, not the second one
Marc
@MWBauer
Sep 03 2017 16:07
So, something like....
``````for (I = 0; I<arr.length; I++) {
biggest.push(big);
for (j..``````
?
piteto
@piteto
Sep 03 2017 16:09
Yes, but at the end of the first loop, not the beginning, otherwise you'll get 0 as the first element of the `biggest` array
Marc
@MWBauer
Sep 03 2017 16:09
oy
piteto
@piteto
Sep 03 2017 16:10
when the second loop finishes, you have your biggest number from the array, so the push has to happen after the second loop finishes
Marc
@MWBauer
Sep 03 2017 16:10
for I, for j, push?
piteto
@piteto
Sep 03 2017 16:14
I'm not sure I understand the question. the .push() goes at the end of your first loop:
``````  for (i = 0; i < arr.length; i++) {
for (j = 0; j < arr[i].length; j++) {
if (arr[i][j] > big) big = arr[i][j];
}
biggest.push(big);
}``````
Still more work to do though - keep an eye on the value of `big` and make sure it gets reset when needed
Or, simplify everything and use Math.max()
Marc
@MWBauer
Sep 03 2017 16:16
Tell me in simple terms what you see happening with my code right now
Moisés Man
@moigithub
Sep 03 2017 16:16
....and review what each command/statement do separatelly
Marc
@MWBauer
Sep 03 2017 16:17
math.max(biggest)?
piteto
@piteto
Sep 03 2017 16:17
``````  for (i = 0; i < arr.length; i++) { // process each sub array one at a time
for (j = 0; j < arr[i].length; j++) { // process the values inside each sub array
if (arr[i][j] > big) big = arr[i][j]; // get the biggest value of each subarray
}
// the second loop has finished. big is equal to the biggest value of the subarray
}``````
Didn't mean to distract you with math.max, but the docs are here with code samples on how to get the largest value from an array: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max
Marc
@MWBauer
Sep 03 2017 16:18
yeah. just pulled that up.
I moved the push and now I have the largest of each array in an array. So now I just need to step thru again to find the largest, or does Math.max do that for me?
that's what it looks like.
piteto
@piteto
Sep 03 2017 16:20
Stick with your two for loops, they'll work fine for this solution. Math.max will make it more concise, but try that later. I shouldn't have mentioned it lol, your code is really close as is
Marc
@MWBauer
Sep 03 2017 16:21
Math.max would simplify the whole thing. But since they haven't taught us about math.max yet we can't use it due to lack of knowledge.
I could see where after we have learned the basics we can learn the intermediate which would allow us to come back and do the same challenges more easily
piteto
@piteto
Sep 03 2017 16:22
I didn't learn my javascript here, so I don't know what they teach/don't teach
just doing the required algorithms and projects to finish the front end part so I can work on back end
Moisés Man
@moigithub
Sep 03 2017 16:23
there are sooo many "commands" (u can check on mdn.io )
fcc dont teach u all, just the basics ones
Marc
@MWBauer
Sep 03 2017 16:23
``````Or with the new spread operator, getting the maximum of an array becomes a lot easier.
var arr = [1, 2, 3];
var max = Math.max(...arr);``````
piteto
@piteto
Sep 03 2017 16:24
A math.max solution would be:
``````function largestOfFour(arr) {
return arr.map(v => Math.max(...v));
}``````
Marc
@MWBauer
Sep 03 2017 16:24
according to this example, biggest would just plug in
piteto
@piteto
Sep 03 2017 16:24
get comfortable with for loops first though, higher order functions like map will come later I'm guessing
Marc
@MWBauer
Sep 03 2017 16:25
I would have var biggest then var showBiggest = Math.max(biggest);
Moisés Man
@moigithub
Sep 03 2017 16:26
... u need to think of... `what value` have that variable at that specific time
Marc
@MWBauer
Sep 03 2017 16:37
After the nested For the return statement gives me an array of 4 elements, the largest of each array.
So another for would step thru and find the largest and return it, correct>
Daniel Romero
@Ranacode
Sep 03 2017 16:38
``````router.post('options/0', (request, response) => {
//Doing stuff here
})``````
How can I set the route by number, (router.post('options/"thisnumber").. dinamically? I have various forms depends on the options that exist on the database. And the only change that I need is set this routes dinamically when the user do some post actions
``````<form action="/options/<%= index %>" method="POST">
// etc...``````
Ayush Bahuguna
@relentless-coder
Sep 03 2017 16:44
Moisés Man
@moigithub
Sep 03 2017 16:45
`router.post('/options/:num', (req,res)=>{`
`req.params.num`<-- will be 0 (or whatever num) @Ranacode
http://expressjs.com/en/4x/api.html#req.params
Daniel Romero
@Ranacode
Sep 03 2017 16:50
OMG that was easy man, thanks @moigithub
CamperBot
@camperbot
Sep 03 2017 16:50
ranacode sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3623 | @moigithub |http://www.freecodecamp.com/moigithub
Daniel Romero
@Ranacode
Sep 03 2017 16:50
It works 100%
Marc
@MWBauer
Sep 03 2017 17:02
Yall are mean and cruel. But thanks for your help.
I was going too far with the code
It didn't want the biggest element, it wanted an array of the biggest from each.
So, I have that, but the second array is switching the first and second elements.
and now it's taking the largest from the first array and making it also the largest for the second.
lol
WHAT?!
Ayush Bahuguna
@relentless-coder
Sep 03 2017 17:05
@MWBauer what is the situation? Can you quote your question?
Marc
@MWBauer
Sep 03 2017 17:06
Yeah. Hold on.
``````function largestOfFour(arr) {
var biggest = [];
var big = 0;
for (i = 0; i < arr.length; i++) {
for (j = 0; j < arr[i].length; j++) {
if (arr[i][j] > big)
big = arr[i][j];
} biggest.push(big);
} return biggest;
}``````
the second set of arrays when plugged in is acting weird.
Moisés Man
@moigithub
Sep 03 2017 17:06
"divide an conquer" thing
if u have this array = [1,2,3,4]
how can u get the largest of that SINGLE array ?
Marc
@MWBauer
Sep 03 2017 17:07
``````function largestOfFour(arr) {
var biggest = [];
var big = 0;
for (i = 0; i < arr.length; i++) {
for (j = 0; j < arr[i].length; j++) {
if (arr[i][j] > big)
big = arr[i][j];
} biggest.push(big);
} return biggest;
}
largestOfFour([[13, 27, 18, 26], [4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1]]);``````
The first set of arrays works fine. The third set works fine.
what's screwing up the second?
It just returned the array [27, 27, 39, 1001]
Ayush Bahuguna
@relentless-coder
Sep 03 2017 17:08
@MWBauer your `big` should be defined between the two loops

so something like

``````for(let i  = 0; i < arr.length; i++){
let big = 0;
for(let j = 0.....)
}``````

because your variable needs to set to 0 when you iterate a different array

otherwise in your second array you are comparing each value with the largest value in the first array
Markus Kiili
@Masd925
Sep 03 2017 17:11
@MWBauer Initializing to `-Infinity` would make it also work with negative numbers.
Ayush Bahuguna
@relentless-coder
Sep 03 2017 17:13
^
the hackerrank people leave no stone unturned to make your code fail their tests
Marc
@MWBauer
Sep 03 2017 17:15
HOld on. The first and third work fine. I get my arrays, they check out. Why is the second not working?
Ayush Bahuguna
@relentless-coder
Sep 03 2017 17:16
Marc
@MWBauer
Sep 03 2017 17:16
Yes. But why does it work all the other times?
Ayush Bahuguna
@relentless-coder
Sep 03 2017 17:17
it is just coincidence that the largest value in the first array is 27, in the second array no value is greater than 27, in the third 39 is greater than 27, and in last array 1001 is greater than 39

>
because your variable needs to set to 0 when you iterate a different array
otherwise in your second array you are comparing each value with the largest value in the first array

Marc
@MWBauer
Sep 03 2017 17:18
I did. I switched it to let and moved it and it works.
does let do something that var?
Ayush Bahuguna
@relentless-coder
Sep 03 2017 17:18
but did you read the explanation for moving the `big` variable?
Marc
@MWBauer
Sep 03 2017 17:18
or was it strictly about position?
Ayush Bahuguna
@relentless-coder
Sep 03 2017 17:18
Marc
@MWBauer
Sep 03 2017 17:18
yes
oik.
ok
thank you.
I WILL get this
my dude on the outside wants to teach me nodeJS
if I can't get this, that's not gonna' get very far either
Ayush Bahuguna
@relentless-coder
Sep 03 2017 17:19
you are just over reacting.
FlashHero
@FlashHero
Sep 03 2017 17:22
Nodejs help, What is the difference between `connect.sid`and `req.cookies` in nodejs and which one contains the id assigned from `passport.serialize`
Ayush Bahuguna
@relentless-coder
Sep 03 2017 17:47
@FlashHero what? those are two different things.
three different things
Jefferson
@jeffersonnnn
Sep 03 2017 18:23
Hi guys, i am still on the Seek and destroy challenge. Here is my code for turning argument objects into arguments that doesn't seem to work; can i get help, please?
``````

function destroyer(arr) {
var newArray = Array.prototype.slice.call(arguments, 1);
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);``````
Stephen James
@sjames1958gm
Sep 03 2017 18:57

@jeffersonnnn

``````function destroyer(arr) {
var newArray = Array.prototype.slice.call(arguments, 1);
return newArray;
}

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

Your code makes an array from the values after `arr` is that what you want

@jeffersonnnn Unless you return the value or console.log(newArray) how do you know it is working or not?
glitz20
@glitz20
Sep 03 2017 19:01
@sjames1958gm are you familiar with mongo?
Waterkid123012
@Waterkid123012
Sep 03 2017 19:01
yo can anyone help me with input and out put?
Stephen James
@sjames1958gm
Sep 03 2017 19:01
@sabin20 Only slightly, have taken a couple of courses is all
glitz20
@glitz20
Sep 03 2017 19:02
Stephen James
@sjames1958gm
Sep 03 2017 19:02
@Waterkid123012 That is pretty broad description, anything more specific
glitz20
@glitz20
Sep 03 2017 19:02
So here is the link to the project @sjames1958gm
Waterkid123012
@Waterkid123012
Sep 03 2017 19:02
int x = 600; out.println(x); x= 600
x = -80; out.println(x); x =-80
byte b = 5; out.println(b); b=5
short s = 32767; out.println(s); s=32767
double d = 9.9; out.println(d); d= 9.9
d = 5.2; out.println(d); d=5.2
float f = 9.87f; out.println(f); f=9.87
long big = 555845; out.println(big); big = 555845
x = s; out.println(x); x = 32767
x = b + 10; out.println(x); x = 15
int z = ‘A’+ 1; out.println(z); z = 66
char c = ‘A’ + 1; out.println(c); c = B i got one of these answers wrong, and i dont know which one
Stephen James
@sjames1958gm
Sep 03 2017 19:03
@Waterkid123012 That doesn't look like javascript
Waterkid123012
@Waterkid123012
Sep 03 2017 19:03
oh my bad. i try the other chat
glitz20
@glitz20
Sep 03 2017 19:03
basically I want to have comments in my product page along with its some detail @sjames1958gm
Stephen James
@sjames1958gm
Sep 03 2017 19:07
When you go to "/product/:title" this route? you want to pull the comments in as well?
glitz20
@glitz20
Sep 03 2017 19:08
Yeah
@sjames1958gm so I should embeed the comment somewhere bit I donot know how
Stephen James
@sjames1958gm
Sep 03 2017 19:10
@sabin20 Your comments schema doesn't have any reference to the product, like an id or something to say which product the comment is for.
glitz20
@glitz20
Sep 03 2017 19:10
yeah I know. @sjames1958gm so how should I proceed?
If you have time you can collab with me for this part
Stephen James
@sjames1958gm
Sep 03 2017 19:11
I would think in the produce findOne callback you would do a comments findAll for that product and then pass both to res.render.
I would add reference to the product in the comment schema, so you can fetch them
I assume you enter the comments from a product page, so that you can store the product reference with the comment?
glitz20
@glitz20
Sep 03 2017 19:14
so you want me to create comment Schema in the product.js page?
Stephen James
@sjames1958gm
Sep 03 2017 19:26
I would assume that the comments form would be on the products page? And when you submit the form you can pass along the product id.
If you want to display the comments on the product page, you would need to read the comments when you went to the products page.
Tiago Correia
@tiagocorreiaalmeida
Sep 03 2017 19:29
@sjames1958gm is it ok to pm you just for a quick question?
Stephen James
@sjames1958gm
Sep 03 2017 19:29
@tiagocorreiaalmeida ok
FlashHero
@FlashHero
Sep 03 2017 20:33
Nodejs help, What is the difference between `connect.sid`and `req.cookies` in nodejs and which one contains the session assigned from `passport.serialize`
Joseph
@Big-jo
Sep 03 2017 21:58
``````var inputBox = document.getElementsById("inputbox");

}

function Validate(args)
{
if(args=="")
{
// return true;
}
else
{
}

}
Validate(inputBox.value);``````
if i pass the argument args to my function alertMessage will it take the value of the inputBox and work with it?
Gersho
@Gersho
Sep 03 2017 22:03
it should
Joseph
@Big-jo
Sep 03 2017 22:06
The problem is the argument for alertMessage isnt being passed to it
Gersho
@Gersho
Sep 03 2017 22:07
i don't know .replaceWith , is that an equivalent to .htlm ?
Joseph
@Big-jo
Sep 03 2017 22:07
probably
think so
Gersho
@Gersho
Sep 03 2017 22:08
when you mean it isn't passed, you mean it displays "please Fill in Your ." but not the variable ?
Joseph
@Big-jo
Sep 03 2017 22:08
Yes
Gersho
@Gersho
Sep 03 2017 22:08
well i don't see any problem then
because
`````` if(args=="")
{
// return true;
}``````
(take a moment to let it sink, it's ok)
Joseph
@Big-jo
Sep 03 2017 22:10
Well it's empty in the snippet i'm showing you but not in my code
Gersho
@Gersho
Sep 03 2017 22:11
if it's not empty, alertMessage is not being called
Joseph
@Big-jo
Sep 03 2017 22:12
@Gersho oh,
@Gersho thanks
CamperBot
@camperbot
Sep 03 2017 22:12
big-jo sends brownie points to @gersho :sparkles: :thumbsup: :sparkles:
Gersho
@Gersho
Sep 03 2017 22:15

@Gersho oh,

that's why i said "(take a moment to let it sink, it's ok)" ^^

Joseph
@Big-jo
Sep 03 2017 22:15
lol
HAQish
@HAQish
Sep 03 2017 22:16
hey guys can I get help on this:
``````function helloWorld() {
console.log(Hello world!)
}``````
Gersho
@Gersho
Sep 03 2017 22:16
yesterday i struggled 30+mins on a react lesson because it had an array called strings (what an idea) and it used strings.map and i couldn't wrap my head around it xD
Tiago Correia
@tiagocorreiaalmeida
Sep 03 2017 22:16
sure @HAQish what's goign wrong?
you missing a ;
HAQish
@HAQish
Sep 03 2017 22:16
it's giving me a syntax error
Gersho
@Gersho
Sep 03 2017 22:16
@HAQish put quotation marks
Tiago Correia
@tiagocorreiaalmeida
Sep 03 2017 22:16
after console.log by the way
HAQish
@HAQish
Sep 03 2017 22:16
oh thanks!
Tiago Correia
@tiagocorreiaalmeida
Sep 03 2017 22:16
probably that, np
Joseph
@Big-jo
Sep 03 2017 22:17
@HAQish it's a statement ,all statements require a ; at the end
@Gersho lmao
Roxroy
@roxroy
Sep 03 2017 22:43
@HAQish , you need to log the string, so instead use `console.log('Hello world!')`. notice the single quote around the text
Stephen James
@sjames1958gm
Sep 03 2017 23:03
@HAQish Are you supposed to return the string and/or should it be World not world?
Caleb David
@microworlds
Sep 03 2017 23:27
Hello, please is there any node js and mongodb hosting service that is affordable for a medium size application. I want a database size of about 10gb (mongodb), but the pricing for that scares me. Are there no other alternatives but with cheaper cost? Thank you
FlashHero
@FlashHero
Sep 03 2017 23:30
anyone here who knows node
FlashHero
@FlashHero
Sep 03 2017 23:37
what above are you talking about @moigithub
Moisés Man
@moigithub
Sep 03 2017 23:37
Nodejs help, What is the difference between `connect.sid`and `req.cookies` in nodejs and which one contains the session assigned from `passport.serialize`
FlashHero
@FlashHero
Sep 03 2017 23:40
how is that not related `passport.serialize` assigns a cookie or session for the user authenticated user and in the cookies there's this thing called `connect.sid` which i don't know what its holding and some say that `req.cookies` has something to do with session too, I don't know what they're talking about that's why i came for help
@moigithub
odm275
@odm275
Sep 03 2017 23:52
@odm275
how can i enter http://google.com as an arguement for a get request
the
'//' part messes it up