These are chat archives for FreeCodeCamp/HelpJavaScript

1st
Sep 2017
aRtoo
@artoodeeto
Sep 01 2017 00:04
@sjames1958gm ohhhh. really is that closure??
@sjames1958gm i didnt know. i thought closures are like this
var test = function() {}... or this
(function () {} ()); IIFE
alpox
@alpox
Sep 01 2017 00:06
@artoodeeto
var test = function() {}
is (almost) the same as function test() {}
Stephen James
@sjames1958gm
Sep 01 2017 00:07
@artoodeeto An iffe uses closures but so does where you return a function like you do
alpox
@alpox
Sep 01 2017 00:07
And return function() {} is a closure because you pass this newly created function around (Return it)
Stephen James
@sjames1958gm
Sep 01 2017 00:08
@artoodeeto The variables that were in scope are captured (closed over) along with the function that is returned.
So that when you call the function the variable 'n' is still available to the function by closure
aRtoo
@artoodeeto
Sep 01 2017 00:09
@alpox bro but when i try to return a function and logging it will return me a word function. example function test () { return a+b;} this should return me the sum right? but when i do this console.log(test); it says function. its supposed to be the sum right because its returning the sum of a and b
@sjames1958gm i kinda understand it. if there's an inner function i know i can use the outer variables from my inner function. is that right?? thats all i know. but the function of closure and what it is usage is why im confused. theres also no structure to follow on closures.
alpox
@alpox
Sep 01 2017 00:12
@artoodeeto when you just log test, that will log the function itself. Its not called yet. It would only log the sum of a and b if you called the function with arguments. So if you write braces after the keyword test - test(1, 2) it will log the sum. Without the bracea its no call
Stephen James
@sjames1958gm
Sep 01 2017 00:13
@artoodeeto The fact that you can use those variables IS the essence of closure.
aRtoo
@artoodeeto
Sep 01 2017 00:17
@sjames1958gm so is that it?? if i crated a inner function and use some of the variables from the outside function is the closure?
@sjames1958gm thats easy then. ive been doing that unconsciously on some of my projects. i dont do global variables because its not good in coding
Stephen James
@sjames1958gm
Sep 01 2017 00:19
@artoodeeto When you create an IIFE with local variables inside the IIFE that uses closure
aRtoo
@artoodeeto
Sep 01 2017 00:22
@sjames1958gm ha? again bro?
Aaron Bell
@awb715
Sep 01 2017 00:23
can anyone help me send a post request from jquery through express?
Stephen James
@sjames1958gm
Sep 01 2017 00:24
@awb715 Sure, what do you have?
Aaron Bell
@awb715
Sep 01 2017 00:26
this is for a side project
function redirect(){

    console.log(data);
    $.ajax({
                        type: 'GET',
                        data: data,
                        contentType: 'application/json',
                        url: 'http://localhost:3000/Summary',                        
                        success: function(data) {
                            console.log('success');
                            console.log(JSON.stringify(data));
                        }
                    });

};
keep in mind the type is post
i changed it
<div class="question animated fadeIn">

<h2>How many roommates do you plan to have?</h2>
    <p>If you aren't sure, leave as 1</p>
    <form  action="javascript:redirect()" method="get">
        <input onkeyup="constructor('roommate',this.form.p.value)" type="number"  id="p" name="roommate" min=1 value=1 required>
         <input id="s" type="submit" value="Submit">
    </form>

</div>
Stephen James
@sjames1958gm
Sep 01 2017 00:28
@artoodeeto - so here the two functions have a closure containing the reference to the same val
let mylib = (function() {
   let val;

   return {
     setVal: function(v) { val = v; },
     getVal: function() { return val}
   };
})()
Jianhao Tan
@jaanhio
Sep 01 2017 00:28
hi all, may i know how can i export my API keys from an external folder?
Aaron Bell
@awb715
Sep 01 2017 00:28
this html is where the post gets called @sjames1958gm
Stephen James
@sjames1958gm
Sep 01 2017 00:29
@awb715 Are you seeing the POST at your express app?
Aaron Bell
@awb715
Sep 01 2017 00:29
app.get('/Summary', function (req, res) {
    res.render(req.body);

});
should it be changed to post? @sjames1958gm
because all i want to do is render the object with a handlebars template
Stephen James
@sjames1958gm
Sep 01 2017 00:30
@awb715 Yes - it has to be app.post
Put a console.log inside that app.post so you can see if it gets there.
Aaron Bell
@awb715
Sep 01 2017 00:31
app.js:112 Uncaught ReferenceError: module is not defined
at app.js:112
(anonymous) @ app.js:112
that error pops up on refersh
and 112 is the $.ajax line
aRtoo
@artoodeeto
Sep 01 2017 00:31
@sjames1958gm wait so the return is an object right and to access the an object is objectName,object key right? so i assume mylib[setval] = 2to give a v a value?
Stephen James
@sjames1958gm
Sep 01 2017 00:32
@artoodeeto well sort of it would be mylib.setVal(2) since those are functions
Aaron Bell
@awb715
Sep 01 2017 00:32
http://localhost:3000/Summary 500 (Internal Server Error)
is the error @sjames1958gm
doesnt get tehre
aRtoo
@artoodeeto
Sep 01 2017 00:32
@sjames1958gm i can only see one function. the mylib bro.
Stephen James
@sjames1958gm
Sep 01 2017 00:33
@artoodeeto there are three functions the return is an object with two functions
@awb715 Hmm. Are you including jquery?
aRtoo
@artoodeeto
Sep 01 2017 00:34
@sjames1958gm ohh. i see now. as long as the variable is being used from inner function that will be the closure??
Stephen James
@sjames1958gm
Sep 01 2017 00:34
@artoodeeto Yes.
@artoodeeto The two functions returned close over the variable val
Aaron Bell
@awb715
Sep 01 2017 00:35
well my code isnt in a document .ready or anything
but jquery is included in the html scripts
and the function is getting called from a dynamically render partial onto the html
Stephen James
@sjames1958gm
Sep 01 2017 00:35
@awb715 Your javascript is included at the end?
aRtoo
@artoodeeto
Sep 01 2017 00:36
@sjames1958gm aight thanks man. appreciate your help
CamperBot
@camperbot
Sep 01 2017 00:36
artoodeeto sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8420 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Sep 01 2017 00:36
@artoodeeto :+1:
Aaron Bell
@awb715
Sep 01 2017 00:36
at the end of the html?
@sjames1958gm
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>Sample Site</title>
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <link rel="stylesheet" type="text/css" href="css/ionicons.css" />
    <link rel="stylesheet" type="text/css" href="css/animate.css" />
    <link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script type='text/javascript' src='/js/app.js'></script>
    <link rel="apple-touch-icon" sizes="180x180" href="/favicon/apple-touch-icon.png">
    <link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png">
    <link rel="manifest" href="/favicon/manifest.json">
    <link rel="mask-icon" href="/favicon/safari-pinned-tab.svg" color="#5bbad5">
    <link rel="shortcut icon" href="/favicon/favicon.ico">
    <meta name="msapplication-config" content="/favicon/browserconfig.xml">
    <meta name="theme-color" content="#ffffff"> </head>

<body class="tool"> {{> nav}}
    <section class="animated fadeIn"> {{> choices}}
        <div class="form">
            <div onclick="Obj(null)" id="s">begin</div>
        </div>
    </section>
</body>

</html>
Stephen James
@sjames1958gm
Sep 01 2017 00:37
Or at least after jquery is included
trying to understand why it would say module is undefined
Aaron Bell
@awb715
Sep 01 2017 00:37
see the 2 scripts?
so the html is all partials
and and you iterate through all of them answer questions, so the last partial loaded to the html is where I want to call the get as i sent before
'post'
Stephen James
@sjames1958gm
Sep 01 2017 00:38
They recommend you put the javascript at the end of the body - so the page loads first, but not sure that is an issue here
Aaron Bell
@awb715
Sep 01 2017 00:38
well the other jquery works
Stephen James
@sjames1958gm
Sep 01 2017 00:39
@awb715 ok.
Aaron Bell
@awb715
Sep 01 2017 00:39
i guess it gets complicated because i render different templates
they get loaded to the form class div
and the last one is wher ei call the function that does the ajax on submit
Stephen James
@sjames1958gm
Sep 01 2017 00:41
@awb715 What is data in this line console.log(data);
I don't see any module to be referncing
Aaron Bell
@awb715
Sep 01 2017 00:41
it was unncessary actualy
i fixed the error
var data = {roommate:1}
so thats dats
and every question, a new property gets added
this is the object that needs to be submitted in the post
Stephen James
@sjames1958gm
Sep 01 2017 00:42
So now when you submit you see it in express?
Aaron Bell
@awb715
Sep 01 2017 00:43
right now heres the current error
jquery.min.js:4 POST http://localhost:3000/Summary 500 (Internal Server Error)
send @ jquery.min.js:4
ajax @ jquery.min.js:4
redirect @ app.js:83
(anonymous) @ VM740:1
function redirect(){

    console.log(data);
    $.ajax({
                        type: 'POST',
                        data: data,
                        contentType: 'application/json',
                        url: 'http://localhost:3000/Summary',                        
                        success: function(data) {
                            console.log('success');
                            console.log(JSON.stringify(data));
                        }
                    });

};
Stephen James
@sjames1958gm
Sep 01 2017 00:44
I would suggest a package called morgan that you can put in your express app that will trace messages coming in.
The 500 is likely coming from the server
Aaron Bell
@awb715
Sep 01 2017 00:46
in my server.js file
should i require the file that is calling the post
Addison
@addisonday
Sep 01 2017 00:47
I am not sure why my code is not executing past my console.log statement. Can someone please help me?
var str = "a test";
str = (str.charAt(str.length - 1));
console.log(str);
target = "t";
function strMatch(str, target){
if(str === target){
    return true;
} else {
    return false;
}
}
Stephen James
@sjames1958gm
Sep 01 2017 00:48
@awb715
Go to the npm page for morgan to see how to include and configure.
Also your have to include your code that calls app.post into your server.js
Addison
@addisonday
Sep 01 2017 00:48
I think I see my problem...
Stephen James
@sjames1958gm
Sep 01 2017 00:49
@addisonday Where are you calling strMatch?
Addison
@addisonday
Sep 01 2017 00:50
@sjames1958gm That's the name of my function.
Returns undefined now.
var str = "a test";
str = (str.charAt(str.length - 1));
console.log(str);
var target = "t";
function strMatch(str, target){
if(str === target){
    return true;
} else {
    return false;
}
}  //undefined
Stephen James
@sjames1958gm
Sep 01 2017 00:52
@addisonday The str / target inside the function are not the same as the str/target before the function
Where are you doing strMatch(...)
Addison
@addisonday
Sep 01 2017 00:52
@sjames1958gm Yeah just realized this is probably a local vs global scope situation!
Stephen James
@sjames1958gm
Sep 01 2017 00:53
@addisonday strMatch(str, target) this two parameters shadow (hide) the outer variables
Addison
@addisonday
Sep 01 2017 00:53
@sjames1958gm right
@sjames1958gm I see my other mistake tooo about not calling the function XD
Sucess!! Thank you @sjames1958gm .
function strMatch(str, target){
str = (str.charAt(str.length - 1));
target = "t";
if(str === target){
    return true;
} else {
    return false;
}
}

strMatch('a test', 't');  //true
CamperBot
@camperbot
Sep 01 2017 00:56
addisonday sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8421 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Sep 01 2017 00:56
@addisonday :+1:
Aaron Bell
@awb715
Sep 01 2017 00:57
@sjames1958gm not sure whats going on =/
the error now is cannot get
when its a post
Stephen James
@sjames1958gm
Sep 01 2017 00:59
Try copying this right into your server.js and see if you can get the console.log to show up
app.post('/Summary', function (req, res) {
    console.log("post")
    res.render(req.body);

});
Then just use res.send("test") or something simple to see if you can at least get a response back to the browser.
Refath
@Refath
Sep 01 2017 01:01
Hi guys. My code isn't working locally on my laptop, but is working on codepen
Any ideas?
Hello?
FlashHero
@FlashHero
Sep 01 2017 01:02
can i see the code
Refath
@Refath
Sep 01 2017 01:02
Sure
I'm using the Atom compiler to run my code locally
For example, when I click Change locally, jQuery doesn't hide the text field
Guys??
FlashHero
@FlashHero
Sep 01 2017 01:05
Do you have jquery installed in your editor
Refath
@Refath
Sep 01 2017 01:06
I don't understand,... I put the jQuery CDN in the html file, and then locally linked my own js file
Wait, so do I have to download jQuery, and move the mile into the website folder?
FlashHero
@FlashHero
Sep 01 2017 01:07
no Its fine
Aaron Bell
@awb715
Sep 01 2017 01:07
@sjames1958gm
function redirect(){

    console.log(data);
$.ajax({
                        type: 'POST',
                        data: JSON.stringify(data),
                        contentType: 'application/json',
                        url: 'http://localhost:3000/Summary',                        
                        success: function(data) {
                            console.log('success');
                            console.log(JSON.stringify(data));
                        }
                    });

};
the callback function works
but nothin in the browser
Refath
@Refath
Sep 01 2017 01:08
@FlashHero So, any ideas?
FlashHero
@FlashHero
Sep 01 2017 01:08
@Refath I don't understand your problem when you click change you put the new text then how do you hide the text
Stephen James
@sjames1958gm
Sep 01 2017 01:08
@awb715 You don't see the success function logs?
Refath
@Refath
Sep 01 2017 01:08
@FlashHero Try running the pen
When you click change, it toggles a show/hide command that's linked to the text field
But when I click "Change" locally, it doesn't hide the text field
Stephen James
@sjames1958gm
Sep 01 2017 01:09
@Refath you have a webserver running locally on your machine?
Aaron Bell
@awb715
Sep 01 2017 01:10
post
::1 - - [01/Sep/2017:01:09:01 +0000] "POST /Summary HTTP/1.1" 500 1165 "http://localhost:3000/Tool" "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Mobile Safari/537.36"
TypeError: Path must be a string. Received {}
    at assertPath (path.js:7:11)
    at extname (path.js:1431:5)
    at new View (/Users/AaronBell/Desktop/Request/node_modules/express/lib/view.js:57:14)
    at Function.render (/Users/AaronBell/Desktop/Request/node_modules/express/lib/application.js:570:12)
    at ServerResponse.render (/Users/AaronBell/Desktop/Request/node_modules/express/lib/response.js:971:7)
    at /Users/AaronBell/Desktop/Request/server.js:43:9
    at Layer.handle [as handle_request] (/Users/AaronBell/Desktop/Request/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/AaronBell/Desktop/Request/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/Users/AaronBell/Desktop/Request/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Users/AaronBell/Desktop/Request/node_modules/express/lib/router/layer.js:95:5)
the post worked
Stephen James
@sjames1958gm
Sep 01 2017 01:11
@awb715 Your res.render should be passed a string for the template and an object for the values to inject into the template
Refath
@Refath
Sep 01 2017 01:11
@sjames1958gm, yes, but I'm not using that
Aaron Bell
@awb715
Sep 01 2017 01:11
i just want to see the json first
Refath
@Refath
Sep 01 2017 01:11
Screen Shot 2017-08-31 at 9.11.32 PM.png
Stephen James
@sjames1958gm
Sep 01 2017 01:12
@awb715 You cannot use res.render - use res.json (I think
@Refath You have to be wary of using file:// URLs there are restrictions on what the browser can do with file:// URLs
Refath
@Refath
Sep 01 2017 01:13
@sjames1958gm I see; If I upload these fils to GitHub as a website, will the problem persist, then?
Aaron Bell
@awb715
Sep 01 2017 01:13
app.post('/Summary', function (req, res) {

  console.log(req.body);
    res.json(req.body);

});
@sjames1958gm like that?
FlashHero
@FlashHero
Sep 01 2017 01:13
@Refath I think you need to run it in localhost
Refath
@Refath
Sep 01 2017 01:13
@FlashHero OK, Let me try running it
Stephen James
@sjames1958gm
Sep 01 2017 01:14
@awb715 If the req.body is an object, I think so, you might need to check the express docs
Aaron Bell
@awb715
Sep 01 2017 01:15
must be an issue with the ajax content type
im not seeing any evidence of that being passed
FlashHero
@FlashHero
Sep 01 2017 01:16
@awb715 you have body-parser installed ?
Aaron Bell
@awb715
Sep 01 2017 01:17
app.use(bodyParser.urlencoded({
    extended: true
}));
is that right?
@FlashHero
FlashHero
@FlashHero
Sep 01 2017 01:19
you might want to add
app.use(bodyParser.json());
Refath
@Refath
Sep 01 2017 01:19
OK, This is embarrassing but how do I set up localhost? I did it a few times in the past, but I've forgotten
@FlashHero Any ideas?
FlashHero
@FlashHero
Sep 01 2017 01:21
You know node
Aaron Bell
@awb715
Sep 01 2017 01:21
SyntaxError: Unexpected token r
    at parse (/Users/AaronBell/Desktop/Request/node_modules/body-parser/lib/types/json.js:83:15)
    at /Users/AaronBell/Desktop/Request/node_modules/body-parser/lib/read.js:116:18
    at invokeCallback (/Users/AaronBell/Desktop/Request/node_modules/raw-body/index.js:262:16)
    at done (/Users/AaronBell/Desktop/Request/node_modules/raw-body/index.js:251:7)
    at IncomingMessage.onEnd (/Users/AaronBell/Desktop/Request/node_modules/raw-body/index.js:307:7)
    at emitNone (events.js:86:13)
    at IncomingMessage.emit (events.js:188:7)
    at endReadableNT (_stream_readable.js:975:12)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)
Refath
@Refath
Sep 01 2017 01:21
nope, but I have it installed
Aaron Bell
@awb715
Sep 01 2017 01:22
error popped up from body parser
Refath
@Refath
Sep 01 2017 01:22
Screen Shot 2017-08-31 at 9.22.28 PM.png
FlashHero
@FlashHero
Sep 01 2017 01:23
@awb715 Unexpected token r this means you have that letter r somewhere its causing errors
Refath
@Refath
Sep 01 2017 01:25
@FlashHero I tried running node -v, but apparently that's wrong syntax. How should I get localhost?
FlashHero
@FlashHero
Sep 01 2017 01:25
@Refath I don't know If there's other way to start up a localhost server but I think you'll have to learn node because that's the only way i know how to start a server
You might want to check out some videos on youtube its very easy
Refath
@Refath
Sep 01 2017 01:32
What's wrong?
FlashHero
@FlashHero
Sep 01 2017 01:32
what
Refath
@Refath
Sep 01 2017 01:32
Screen Shot 2017-08-31 at 9.31.42 PM.png
It says command not found
FlashHero
@FlashHero
Sep 01 2017 01:33
you have to say npm init
Refath
@Refath
Sep 01 2017 01:35
ok
I did so, and this came:
Screen Shot 2017-08-31 at 9.36.01 PM.png
FlashHero
@FlashHero
Sep 01 2017 01:38
that's called package.json file that's where your dependencies and module you install go, you have to go through that and you'll have a package.json file
@Refath I don't think you should do this node stuff because you still have to do a lot of stuff to server up your files and stuff like that, so unless your learning node I wouldn't prefer doing this
Refath
@Refath
Sep 01 2017 01:45
@FlashHero I agree; I thought this would be easier than expected, but it's not. I don't think this is worth it. Nevertheless, my question remains: If I upload these files onto GitHub as a website, will these problems persist?
PS, Thanks for the help!
FlashHero
@FlashHero
Sep 01 2017 01:46
if someone runs it in a localhost server then it might but I really don't know what's wrong with the code
Refath
@Refath
Sep 01 2017 01:47
Alright; thanks anyway. BTW, How do I make a website in Github
NVM, I'll check it out
FlashHero
@FlashHero
Sep 01 2017 01:48
You don't make a website, you have to upload your code to github or you can do it using git
Refath
@Refath
Sep 01 2017 01:50
Aaaand, yup; The problem persists
FlashHero
@FlashHero
Sep 01 2017 01:51
GitHub is not for making websites, its a website where people keep their code, you can upload your code to GitHub or you can do it using git which is the command line
Refath
@Refath
Sep 01 2017 01:52
@FlashHero I know, but you can also create project pages;
FlashHero
@FlashHero
Sep 01 2017 01:52
@Refath You mean repositories
Refath
@Refath
Sep 01 2017 01:53
@FlashHero OK; But even in the console I don't see the problem. What works in codepen should work in the browser, no?
FlashHero
@FlashHero
Sep 01 2017 01:55
it doesn't matter
what was the problem in your code anyway
Refath
@Refath
Sep 01 2017 01:56
If I click Change, it should trigger a jQuery event that hides the text field
FlashHero
@FlashHero
Sep 01 2017 01:57
no what was the solution
Refath
@Refath
Sep 01 2017 01:58
There was no problem, or... solution. It might just be that the browser is misinterpreting the code
Try clicking change; see that animation?
Doesn't happen in the browser
FlashHero
@FlashHero
Sep 01 2017 01:58
oh ok
Refath
@Refath
Sep 01 2017 01:59
Exactly, this is what I've been trying to say
FlashHero
@FlashHero
Sep 01 2017 01:59
well, going to sleep now man
Refath
@Refath
Sep 01 2017 01:59
/good night
thanks for the help anyways
FlashHero
@FlashHero
Sep 01 2017 02:00
np
Stephen James
@sjames1958gm
Sep 01 2017 02:01
@Refath Your click handlers at the first are not inside of document.ready and you load nina.js at the top of the file before they are ready.
In code pen it organizes your js to then end of the html file so they are there.
Try moving the script tag that loads nina.js to the end
Or put one document.ready around the whole file and remove the individual ones.
Aron Ciruela
@auricless
Sep 01 2017 02:09
for random qoute machine, what API do you use guys?
Tai Jones
@taiJones00
Sep 01 2017 02:10
There's multiple you can use
Look up random quote API
piteto
@piteto
Sep 01 2017 02:10
I did mine today with this one: https://quotesondesign.com/api-v4-0 @auricless
Aron Ciruela
@auricless
Sep 01 2017 02:13
i tried to use it but it has an https error?
how do you fix it sir?
firas omrane
@firou1925
Sep 01 2017 02:18
@auricless what is the error exactly?
Aron Ciruela
@auricless
Sep 01 2017 02:18

XMLHttpRequest cannot load https://codepen.io/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&_=1504230069692. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://s.codepen.io' is therefore not allowed access. The response had HTTP status code 404.

This one after trying to paste the example code to my codepen

it is frustrating.
firas omrane
@firou1925
Sep 01 2017 02:23
@auricless witch API you are using
Aron Ciruela
@auricless
Sep 01 2017 02:24
firas omrane
@firou1925
Sep 01 2017 02:25
@auricless share the pen
Ashley Owens
@yelhsa
Sep 01 2017 02:26
I don't understand why the +1 is needed in this section could someone help me?
image.png
Coy Sanders
@coymeetsworld
Sep 01 2017 02:27
@yelhsa Math.random returns a number w/ range [0,1), meaning it could be 0 but never 1
so like from 0-0.9999999
Math.floor truncates the expression (i.e chops off the decimal)
so in an example say myMin was 4, and myMax was 9.
Ashley Owens
@yelhsa
Sep 01 2017 02:29
ok... I'm following you so far
Coy Sanders
@coymeetsworld
Sep 01 2017 02:30
Math.random's absolute lowest number would be 0, so
Math.floor(0*(9-4+1))+myMin would be just myMin
Ashley Owens
@yelhsa
Sep 01 2017 02:30
ok I think i get it.
Tai Jones
@taiJones00
Sep 01 2017 02:30
Does anyone remember the Ronan numeral algorithm
Ashley Owens
@yelhsa
Sep 01 2017 02:31
because the floor cuts off the decimal if the range is 5 it will always return a max of 4
because a 4.999999 will always become a 4 so you make the range 6 so that 5.999999 will give you the 5 you want?
Coy Sanders
@coymeetsworld
Sep 01 2017 02:32
yes
Ashley Owens
@yelhsa
Sep 01 2017 02:32
thanks! @coymeetsworld
CamperBot
@camperbot
Sep 01 2017 02:32
yelhsa sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star2: 2995 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Coy Sanders
@coymeetsworld
Sep 01 2017 02:32
yw
Ashley Owens
@yelhsa
Sep 01 2017 02:33
i misunderstood the floor, I thought I was rounding not cutting off
Coy Sanders
@coymeetsworld
Sep 01 2017 02:34
no floor removes the decimal (i.e. truncates). the opposite of that is Math.ceil which always rounds up
and there is a Math.round function that will round the number for you
Ashley Owens
@yelhsa
Sep 01 2017 02:35
ok. ok got it. I really appreciate the help me
man*
Coy Sanders
@coymeetsworld
Sep 01 2017 02:36
no problem
firas omrane
@firou1925
Sep 01 2017 02:37
@auricless so I think you have the CORS problem
Bryan Reese
@breese8009
Sep 01 2017 02:37
anyone know express, mongo/mongoose well?
firas omrane
@firou1925
Sep 01 2017 02:37
Ogundele Olumide
@Lumexralph
Sep 01 2017 02:38
@breese8009 what question do you have?
Aron Ciruela
@auricless
Sep 01 2017 02:40
on my way sir, thanks.
Bryan Reese
@breese8009
Sep 01 2017 02:41

@Lumexralph So im trying to get my create function to work in my contollers folder... how ever for some reason its not saving to mongo, and not posting to html...
heres the create function

function create(req, res) {
  // create an album based on request body and send it back as JSON
console.log("whats up");
db.Album.create(req.body, (err, createdAlbumsObject) => {  
    if (err) {
        res.send(err);
    }
    console.log(req.body);
    res.send(createdAlbumsObject);
});
}

this is the route in my server.js file

app.post('/api/albums', controllers.albums.create);
firas omrane
@firou1925
Sep 01 2017 02:42
@auricless I am still here
read 3rd party API
Bryan Reese
@breese8009
Sep 01 2017 02:42
the console.log(req.body) is giving me basically an empty object in the console
this is extremely hard to explain on here lol
Ogundele Olumide
@Lumexralph
Sep 01 2017 02:43
@breese8009 is your db up ?
Bryan Reese
@breese8009
Sep 01 2017 02:44
@Lumexralph yesir
Ogundele Olumide
@Lumexralph
Sep 01 2017 02:47
@breese8009 i haven't used mongoose but I guess create will add req.body to Album collection in the db, right?
Bryan Reese
@breese8009
Sep 01 2017 02:47
@Lumexralph yessir
Ogundele Olumide
@Lumexralph
Sep 01 2017 02:47
@breese8009 will it also save it in the db?
Bryan Reese
@breese8009
Sep 01 2017 02:48
.create() in mongoose saves to db yes
no need for .save()
Ogundele Olumide
@Lumexralph
Sep 01 2017 02:48
@breese8009 if req.body is an empty object, have you checked your req object ?
@breese8009 okay
Bryan Reese
@breese8009
Sep 01 2017 02:49
i believe i have, but lemme console.log it gain
again
an ill show u wat i get
Ogundele Olumide
@Lumexralph
Sep 01 2017 02:50
@breese8009 have you successfully added documents to MongoDB prior to now?
Bryan Reese
@breese8009
Sep 01 2017 02:50
@Lumexralph in prev project yes
but not on this project
this is only my second db project
Ogundele Olumide
@Lumexralph
Sep 01 2017 02:51
@breese8009 i mean the current project
Bryan Reese
@breese8009
Sep 01 2017 02:51
nope
thats what im trying to do atm
what if i gave u the repo link with code i have
would that help at all?
Ogundele Olumide
@Lumexralph
Sep 01 2017 02:52
@breese8009 okay, let's see if that'll help
Bryan Reese
@breese8009
Sep 01 2017 02:52
@Lumexralph ok coo gimmie 1 min while i commit
firas omrane
@firou1925
Sep 01 2017 02:53
@auricless if you dont get it just follow this exemple
$.getJSON("https://api.github.com/users/jeresig?callback=?",function(json){
console.log(json);
});
add s to https and ?callback=?
Aron Ciruela
@auricless
Sep 01 2017 02:54
yes i dont quite get the article
firas omrane
@firou1925
Sep 01 2017 02:56
@auricless and now
??
Aron Ciruela
@auricless
Sep 01 2017 03:03
I just came back, I'll check it again.
firas omrane
@firou1925
Sep 01 2017 03:05
@auricless another thing is that the url is not complete
Aron Ciruela
@auricless
Sep 01 2017 03:06
ohhh thanks @firas, it worked, i just add the s in http. lols
CamperBot
@camperbot
Sep 01 2017 03:06
auricless sends brownie points to @firas :sparkles: :thumbsup: :sparkles:
:warning: @firas's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
firas omrane
@firou1925
Sep 01 2017 03:11
@auricless I am @firou1925
hhhh
Aron Ciruela
@auricless
Sep 01 2017 03:13
lols. hahaha @firou1925 , thank you so much. I got excited. sorry
CamperBot
@camperbot
Sep 01 2017 03:13
auricless sends brownie points to @firou1925 :sparkles: :thumbsup: :sparkles:
:cookie: 306 | @firou1925 |http://www.freecodecamp.com/firou1925
Ogundele Olumide
@Lumexralph
Sep 01 2017 03:21
@breese8009 are you using a schema or just simply an object?
@breese8009 what's Album meant to be in the db? collection?
Aron Ciruela
@auricless
Sep 01 2017 03:26
try using body-parser npm?
Refath
@Refath
Sep 01 2017 03:56
@sjames1958gm This is so great
Thank you so much
jmariomejiap
@jmariomejiap
Sep 01 2017 05:32

hey guys. can someone give a hand. Im trying to run a function that will verify if the elements of an array are present in an another array. I have been looking at the code for a while now, and cant seem to figure out why my code is being interrupted after the for-loop is done

function verify (who) {
    for (var x = 0; x <= winningOptions.length; x++) {
        var currentSet = winningOptions[x];
        var winner = currentSet.filter(function(letter) {
            if (who.includes(letter)) {
                return letter;
            }
        });

        if (winner.length === 3) {
            alert(who + " winner!!!!");
            return;
        }
        console.log("this is part works");
    }
    console.log("this is NOT being log out");
    return;
};

thanks in advace

Markus Kiili
@Masd925
Sep 01 2017 05:41
@jmariomejiap You most likely always return inside the loop, so the code after the loop never executes.
prakash chandra yadav
@prakashyadav008
Sep 01 2017 05:46
can anyone help me with the wikipedia api
jmariomejiap
@jmariomejiap
Sep 01 2017 06:31
@Masd925 Im on the tic tac toe challenge.
Im going to post a little bit more code. But lets say that the first or second time this function gets call, who ( array with player moves) will only contain 1 and later 2 elements.
Im puzzled because the for-loop should continue with execution after looping through winning options.
var winningOptions = [ ['a','b','c'],    ['d','e','f'],    ['g','h','i'],    ['a','d','g'],    ['b','e','h'],    ['c','f','i'],    ['a','e','i'],    ['c','e','g'] ];

function verify (who) {
    for (var x = 0; x <= winningOptions.length; x++) {
        var currentSet = winningOptions[x];
        var winner = currentSet.filter(function(letter) {
            if (who.includes(letter)) {
                return letter;
            }
        });        
        if (winner.length === 3) {
            alert(who + " winner!!!!");
            //return;
        }
        console.log("this is part works");
    }
    console.log("this is NOT being log out");
};
Markus Kiili
@Masd925
Sep 01 2017 06:40
@jmariomejiap Simplest is if you just return from the verify when you know the return value.
jmariomejiap
@jmariomejiap
Sep 01 2017 06:41
@Masd925 good idea. im going to give a shoot
thanks
@Masd925 thanks
CamperBot
@camperbot
Sep 01 2017 06:42
jmariomejiap sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4458 | @masd925 |http://www.freecodecamp.com/masd925
Yvonne
@yvonne6344
Sep 01 2017 06:44
Q:How many return statements can a function have in javascript?
Markus Kiili
@Masd925
Sep 01 2017 06:45
@yvonne6344 It can have any number of returns (can be zero too).
JS functions return undefined by default.
Letty
@SimpleProgrammerL
Sep 01 2017 06:52
What's wrong?

function findLongestWord(str) {

var myarr =str.split(" ");
for (var i = 0; i < myarr.length - 1; i++) {
for (var j = 0; j < myarr.length - 1 - i; j++) {
if (myarr[j].length > myarr[j + 1].length) {
var tmp = myarr[j].length;
myarr[j].length = myarr[j + 1].length;
myarr[j + 1].length = tmp;
}
}
}
return myarr[j].length ;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
Markus Kiili
@Masd925
Sep 01 2017 06:54
@SimpleProgrammerL One loop through the array of words is enough.
Yvonne
@yvonne6344
Sep 01 2017 06:54
one function use one return at the same time? or one function can use multiple returns?
Markus Kiili
@Masd925
Sep 01 2017 06:54
@SimpleProgrammerL You might need a variable that holds the longest words length found so far.
@yvonne6344 Functions code can have any number of return statements, but only one can be executed, because executing a return statement ends the executing of the function.
Yvonne
@yvonne6344
Sep 01 2017 06:56
@Masd925 wow!got it!! thanks. :smile:
CamperBot
@camperbot
Sep 01 2017 06:56
yvonne6344 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4459 | @masd925 |http://www.freecodecamp.com/masd925
Letty
@SimpleProgrammerL
Sep 01 2017 07:00
typeerror:cannot assign to read only property 'length' of brown.??
Markus Kiili
@Masd925
Sep 01 2017 07:01
@SimpleProgrammerL Are you trying to change string length?
Letty
@SimpleProgrammerL
Sep 01 2017 07:02
No I didn't understand the problem
Markus Kiili
@Masd925
Sep 01 2017 07:03
@SimpleProgrammerL You need to post the code for more help.
Letty
@SimpleProgrammerL
Sep 01 2017 07:04
That's the code
John Freeborn
@jfx1026
Sep 01 2017 07:05

Hi everyone!

I'm working on a project where I need to get to a specific line inside a three tiered array. I have two big sections, each with paragraphs and inside each paragraphs are a number of lines. I want to target line number 340 (could be any number) inside the first big section - so the program would need to count through the paragraphs, line by line and then find that line number. The paragraphs don't have the same number of lines in each.

My question, do I just brute force count through OR is there a smarter way?

Markus Kiili
@Masd925
Sep 01 2017 07:06
@SimpleProgrammerL You are assigning to string length. myarr[j].length = myarr[j + 1].length;. Strings are immutable and so length cannot be changed.
@jfx1026 Post some code so the array structure gets clear.
John Freeborn
@jfx1026
Sep 01 2017 07:10
@Masd925 - http://johnfreeborn.com/test/jh-ipsum/index2017.html - look in the console to see my array
Markus Kiili
@Masd925
Sep 01 2017 07:13
@jfx1026 So you have an array of arrays and you wan't to target the n:th element inside subarrays?
John Freeborn
@jfx1026
Sep 01 2017 07:13
yes - I'm working on pulling sentences from that object, but I want a random starting point
Markus Kiili
@Masd925
Sep 01 2017 07:20
@jfx1026 You should use subarray lengths to skip them if needed:
var arr = [[1,2,3],[],[5,6],[7,8,9,2]];

function get(arr,n) {
  for (var i=0;i<arr.length;i++) {
    if (arr[i].length>n) return arr[i][n];
    n-=arr[i].length;
  }
}

get(arr,2);   // 3
get(arr,3);   // 5
get(arr,7);   // 9
John Freeborn
@jfx1026
Sep 01 2017 07:21
ok @Masd925 use the paragraph lengths to skip ahead, counting along the way?
Markus Kiili
@Masd925
Sep 01 2017 07:22
@jfx1026 Yes, loop through the subarrays and subtract the subarray length from n until you find the subarray that has the element.
John Freeborn
@jfx1026
Sep 01 2017 07:23
that makes sense - I'll give it a go. Thanks @Masd925
CamperBot
@camperbot
Sep 01 2017 07:23
jfx1026 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4460 | @masd925 |http://www.freecodecamp.com/masd925
Summir
@summiry
Sep 01 2017 08:02
What's wrong?
function convert(celsius) {
  // 请把你的代码写在这条注释以下
  var Celsius;
  farhrenheit = Celsius * 9 / 5 + 32;

  // 请把你的代码写在这条注释以上
    return fahrenheit;
}

convert(-10);  // 你可以修改这一行来测试你的代码
Marianissimus
@Marianissimus
Sep 01 2017 08:07
var Celsius is what? @summiry
don't declare it again, use the celsius argument / remove the var Celsius declaration
Yvonne
@yvonne6344
Sep 01 2017 08:08
function convert(celsius) {
  var fahrenheit = celsius*9/5+32;
    return fahrenheit;
}
convert(-10);
Summir
@summiry
Sep 01 2017 08:10
Thank you!
Marianissimus
@Marianissimus
Sep 01 2017 08:12
@summiry or, directly this: function convert2(celsius) { return celsius*9/5+32; }
Summir
@summiry
Sep 01 2017 08:20
I've got it.Thanks. @Marianissimus
CamperBot
@camperbot
Sep 01 2017 08:20
summiry sends brownie points to @marianissimus :sparkles: :thumbsup: :sparkles:
:cookie: 444 | @marianissimus |http://www.freecodecamp.com/marianissimus
Jianhao Tan
@jaanhio
Sep 01 2017 09:23
Hi all, i have a question regarding hosting my react app on heroku.
so my app uses youtube data v3 api key and in order to keep the key private and still be able to commit to git, i save the key in a config.js file and gitignore it. works well.
then i tried to push it to heroku and got an error because the config.js couldnt be found. is there a good way to sort of separate these 2? like a branch for pushing to github and the other for production on heroku?
Tiago Correia
@tiagocorreiaalmeida
Sep 01 2017 09:40
@Masd925 do you use nodejs?
Markus Kiili
@Masd925
Sep 01 2017 09:41
@tiagocorreiaalmeida No, from backend languages, I only know java and little python.
So not yet ;)
Tiago Correia
@tiagocorreiaalmeida
Sep 01 2017 09:42
"Only" ehehhe thanks anyway mate
Sylvain
@orphen92
Sep 01 2017 10:06
Hi i'm looking for help with angular 4, ANyone knows it?
Johnny
@JohnnyBizzel
Sep 01 2017 10:31
@orphen92 err, I watched a tutorial. Does that count?
Stephen James
@sjames1958gm
Sep 01 2017 10:46
@jaanhio heroku lets you set environment variables for your running app, that is where I usually define my private values such as API keys
Then use process.env to get them out. Assuming you are using nodejs
Sonkeng Maldini
@sdmg15
Sep 01 2017 10:57
Hello, which markdown library should i use to highlight codes when we use backquotes ?
And at the same time with feature like bold and so on
Stephen James
@sjames1958gm
Sep 01 2017 11:01
@sdmg15 remarkable is supposed to be a good one
Sonkeng Maldini
@sdmg15
Sep 01 2017 11:02
Is it embedable with php ?
Blauelf
@Blauelf
Sep 01 2017 11:09
Looks like it could be used client-side, then server-side scripting language wouldn't matter.
Stephen James
@sjames1958gm
Sep 01 2017 11:13
@sdmg15 It is a javascript libraray so you include it client side
@sdmg15 If you are wanting to have markdown on the server side and then convert to HTML with php
https://github.com/michelf/php-markdown
WAINGOR
@WAINGOR
Sep 01 2017 12:09
Hi all, I have a question: might it be possible to manipulate html inside this mailchimp popup? https://www.choicesprogramme.org/opt-in
I am currently working on this page... greets

I tried

$(document).ready(function(){
    $('.field-wrapper').addClass("dark");
});

in the footer but its not working :(

heroiczero
@heroiczero
Sep 01 2017 12:10
@WAINGOR doesn't that just add the Class when the document is ready?
WAINGOR
@WAINGOR
Sep 01 2017 12:12
if it would have worked then yes... which would be manipulating/changing html, dont you agree
?
@heroiczero
Sonkeng Maldini
@sdmg15
Sep 01 2017 12:12
@sjames1958gm thanks man will check that
CamperBot
@camperbot
Sep 01 2017 12:12
sdmg15 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8422 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Markus Kiili
@Masd925
Sep 01 2017 12:13
@WAINGOR How is the pop-up made?
Blauelf
@Blauelf
Sep 01 2017 12:16
The pop-up contains an iframe.
Abhinav Mishra
@abhinav-m
Sep 01 2017 12:16
@sjames1958gm Hello stephen, thanks for that course you recommended on Node.js
CamperBot
@camperbot
Sep 01 2017 12:16
abhinav-thinktank sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8423 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Abhinav Mishra
@abhinav-m
Sep 01 2017 12:16
it's really nice and i like the pace at which it is set!
learning at a faster pace than usual due to it
WAINGOR
@WAINGOR
Sep 01 2017 12:20
@Blauelf allright, and what implications does this have?
Blauelf
@Blauelf
Sep 01 2017 12:22
It's a different document. Not sure how communication between inner and outer document works.
So you have your code running in the outer document? Or can you also add code to the inner document? (in dev tools, you usually can choose the document you want to see the console for)
WAINGOR
@WAINGOR
Sep 01 2017 12:26
My code runs in the outer document :)
@Blauelf
pfff have to do this for work and I'm a complete zombie after a horrible night's sleep
8*(
Spyrantis Theodoros
@thodorisanta
Sep 01 2017 12:45
okay, so i had this idea but i have absolutely no clue on how to do it. So i wanna make a code that will have a "text" like 3-4 lines and lets say that the site will have some mini terms and conditions and it wants to make sure that the user read the terms. And i want the user to confirm that he read the terms by hovering his pointer through all the letters of the text(obviously left to right and every line). Like kids do with their fingers when they read books. 1)What do you think about this idea? 2)How can i make something like that?
Keon Samuel
@keonsam
Sep 01 2017 12:48
zero idea
maybe react
onmouseover and add a count or something like that.
Blauelf
@Blauelf
Sep 01 2017 12:52
@WAINGOR If the popup is open, you can use $('.field-wrapper', frames[1].document) if you're using jQuery. Unfortunately, the frame does not have a name, so I had to pick the "1".
Stephen James
@sjames1958gm
Sep 01 2017 13:00
@abhinav-thinktank :+1:
@thodorisanta I have seen where sites require you to at least scroll to the end of the T&Cs before the accept button is enabled.
Blauelf
@Blauelf
Sep 01 2017 13:04
@thodorisanta The easiest way I could think of is to put every word in its own span element, and use a mouseenter event on each. This would make it on a word level, not on a letter level, and has a decent overhead, but that way it would somewhat work.
koder3
@koder3
Sep 01 2017 13:04
is it absolutely necessary to learn Node.js before learning React.js ?
i realised you need to use npm to include packages
heroiczero
@heroiczero
Sep 01 2017 13:05
@koder3 https://www.quora.com/Do-I-need-to-know-Node-js-to-learn-React i think that answers your question
Abhinav Mishra
@abhinav-m
Sep 01 2017 13:07
@koder3 to learn about react, you can simply use create-react-app and get familiar with it
after you're comfortable with react itself, you can learn about webpack and how it all works together with npm
koder3
@koder3
Sep 01 2017 13:08
ive seen some tutorials on React.js and before they start going into detail they mention in their ""What you need to know"" that you should be famoiliar with Node.js and npm
Node.js is back end i wanted to learn back end but only after i finish front end (react angular etc)
do i skip to learning node then come back to react
Stephen James
@sjames1958gm
Sep 01 2017 13:09
@koder3 Familiar enough to install and run npm commands, maybe a little debugging but not more than that
Blauelf
@Blauelf
Sep 01 2017 13:10
Haven't used React, but as I understand it, React is primarily client-side, while node.js is either a non-client tool or server-side. NPM is just a packet manager that gets bundled with Node.js (and the NPM maintainers always complain about node users having outdated versions of their tool), and together with Node it can be used to for build and deploy tasks.
koder3
@koder3
Sep 01 2017 13:10
so ill just learn to use npm and install packages then go on with learning React ?
heroiczero
@heroiczero
Sep 01 2017 13:11
yeah basically
Abhinav Mishra
@abhinav-m
Sep 01 2017 13:11
yup, pretty much
Blauelf
@Blauelf
Sep 01 2017 13:13
You probably won't be using Node.js much by itself, but tools using it like gulp or grunt, and/or transpilers like babel.
koder3
@koder3
Sep 01 2017 13:14
is there much of a difference between React V15.0 and React V0.13 because the tutorial i have uses React V0.13
Abhinav Mishra
@abhinav-m
Sep 01 2017 13:14
not sure about that..
Blauelf
@Blauelf
Sep 01 2017 13:15
15.0 vs 0.13? :D
heroiczero
@heroiczero
Sep 01 2017 13:15
well there probably are differences like major changes in https://facebook.github.io/react/blog/2016/03/07/react-v15-rc1.html
Blauelf
@Blauelf
Sep 01 2017 13:16
They went from 0.14 to 15.0. Looks like same marketing trick as Java did by dropping their 1.
koder3
@koder3
Sep 01 2017 13:18
alright thanks a lot guys @sjames1958gm @Blauelf @heroiczero @abhinav-thinktank
CamperBot
@camperbot
Sep 01 2017 13:18
koder3 sends brownie points to @sjames1958gm and @blauelf and @heroiczero and @abhinav-thinktank :sparkles: :thumbsup: :sparkles:
:star2: 1680 | @heroiczero |http://www.freecodecamp.com/heroiczero
:cookie: 538 | @abhinav-thinktank |http://www.freecodecamp.com/abhinav-thinktank
:star2: 4586 | @blauelf |http://www.freecodecamp.com/blauelf
:star2: 8424 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Emmanuel Akodia
@akodiaemma
Sep 01 2017 13:45
hello world,..my name is Emmanuel and i am friendly and awesome person. I draw cartoons for a living and make shitty websites
akodiaemma.github.io and expo2017.ug
Marianissimus
@Marianissimus
Sep 01 2017 13:46
@akodiaemma give link to shitty cartoons...
Marianissimus
@Marianissimus
Sep 01 2017 13:47
@akodiaemma those are sites, don't spam in here...
Emmanuel Akodia
@akodiaemma
Sep 01 2017 13:47
@Marianissimus i didnt know it was illegal
Blauelf
@Blauelf
Sep 01 2017 13:48
BrainFK?
That twitter birdie at the bottom seems a bit nervous.
Mark Kubik
@KUBIX90
Sep 01 2017 14:11

Hi All,

Struggling badly with the Random Quote Machine, I'm trying to do it with an API, but I can't even get it to respond.

//Wikiquote API request
$(document).ready(function(){

    //wikiquote API
    var API_URL = "https://en.wikiquote.org/w/api.php"*"";

    $("#getQuote").on("click", function(){

        $.getJSON(API_URL, function(){
            console.log();
        });
    });
});
I added the "*" to the url which seems to have got rid of the CORS error, but now getting the following error XML Parsing Error: mismatched tag. Expected: </link>. Location: xxx
Any ideas, I'm not finding any documentation etc particularly helpful, struggling to understand any of it currently
Spyrantis Theodoros
@thodorisanta
Sep 01 2017 14:17
lets say that i have a code in my js that says "in 3 seconds make that box appear"(that box was invisible till now with "display: none;") and i also have a button that makes that box invisible again.
the thing is! that if i press that button before those 3 seconds pass, then the box will appear anyway. What can i do?
Long Nguyen
@longnt80
Sep 01 2017 14:17
@KUBIX90 many here used https://quotesondesign.com/api-v4-0/
@thodorisanta how do you make the box appear in 3 seconds?
Spyrantis Theodoros
@thodorisanta
Sep 01 2017 14:20
@longnt80 setTimeOut
Long Nguyen
@longnt80
Sep 01 2017 14:20
@thodorisanta so clearTimeout when you press that button
Blauelf
@Blauelf
Sep 01 2017 14:21
This message was deleted
Spyrantis Theodoros
@thodorisanta
Sep 01 2017 14:22
@longnt80 since i have like 4 boxes, is there a way to clear all Timeouts with clearTimeout? cause as i see i can only clear one at a time
Blauelf
@Blauelf
Sep 01 2017 14:24
What about a loop then?
Spyrantis Theodoros
@thodorisanta
Sep 01 2017 14:24
@Blauelf loop?
Blauelf
@Blauelf
Sep 01 2017 14:25
Umm... you have multiple setTimeout and want to kill them all? Then save all those handles and call clearTimeout with them, one at a time.
Spyrantis Theodoros
@thodorisanta
Sep 01 2017 14:26
@Blauelf you mean put them all in an array and then kill them right?
Blauelf
@Blauelf
Sep 01 2017 14:27
clearTimeout takes a single handle at a time, it won't take them all at once.
Mark Kubik
@KUBIX90
Sep 01 2017 14:27
@longnt80 Thanks, I'll try using this one and see how i get on
CamperBot
@camperbot
Sep 01 2017 14:27
kubix90 sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 539 | @longnt80 |http://www.freecodecamp.com/longnt80
Long Nguyen
@longnt80
Sep 01 2017 14:27
@thodorisanta why not? since you only have 4
clearTimeout(timeout1);
clearTimeout(timeout2);
clearTimeout(timeout3);
clearTimeout(timeout4);
Spyrantis Theodoros
@thodorisanta
Sep 01 2017 14:33
@longnt80 hmm, what if i used fade in? how do i cancel it?
Long Nguyen
@longnt80
Sep 01 2017 14:35
@thodorisanta jquery?
Spyrantis Theodoros
@thodorisanta
Sep 01 2017 14:36
@longnt80 yes
Long Nguyen
@longnt80
Sep 01 2017 14:36
@thodorisanta try using stop()
Spyrantis Theodoros
@thodorisanta
Sep 01 2017 14:38
$(".player1").delay(4000).fadeIn(500);
how would i stop this?
@longnt80
Long Nguyen
@longnt80
Sep 01 2017 14:44
@thodorisanta I think you have to use setTImeout for that
from what I know, you can't cancel delay()
Marianissimus
@Marianissimus
Sep 01 2017 14:44
@thodorisanta from jQuery: s. Because it is limited—it doesn't, for example, offer a way to cancel the delay...
Spyrantis Theodoros
@thodorisanta
Sep 01 2017 14:46
@longnt80 @Marianissimus but i need this delay :P what do you suggest? is there something else that i can use instead of delay() that i can later stop?
Long Nguyen
@longnt80
Sep 01 2017 14:46
@thodorisanta setTimeout
Marianissimus
@Marianissimus
Sep 01 2017 14:47
a delay just delays smth. preferably a jQuery UI animation.
agree with @longnt80
Long Nguyen
@longnt80
Sep 01 2017 14:50
Spyrantis Theodoros
@thodorisanta
Sep 01 2017 14:59
@longnt80 thanks! but it still doesnt work. maybe its cause i have to stop this $(".you").show();
CamperBot
@camperbot
Sep 01 2017 14:59
thodorisanta sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 540 | @longnt80 |http://www.freecodecamp.com/longnt80
Spyrantis Theodoros
@thodorisanta
Sep 01 2017 14:59
but after this i use hide on it so idk..
Harut
@harut-g
Sep 01 2017 15:35
@longnt80 you should to show the div
Emmanuel Akodia
@akodiaemma
Sep 01 2017 15:40
hello world
Refath
@Refath
Sep 01 2017 15:41
@Refath
I'm messing with some js here, and I have:
$(document).ready(function(){
$(".speedtext").keyup(function(){
var newimg = $(this).val();
$(".parent").css("animation-duration", newimg);
$('.speedSave').click ( function(){
$(".speedChange").html(newimg);
});
});
});
However, when I click change, it doesn't trigger an event that changes the duration of the said css animation
Any ideas?
Tai Jones
@taiJones00
Sep 01 2017 15:45
What are your opinions on looking at the code solution and hints when you've been stuck for a long time
Christopher McCormack
@cmccormack
Sep 01 2017 15:49
@Refath do you have a pen or anything?
piteto
@piteto
Sep 01 2017 15:49
@Refath animation duration requires a unit like s for seconds
FTFY
$(document).ready(function() {
    $(".speedtext").keyup(function() {
        var newimg = $(this).val() + 's';
        $(".parent").css("animation-duration", newimg);
        $(".speedSave").click(function() {
            $(".speedChange").html(newimg);
        });
    });
});
Stephen James
@sjames1958gm
Sep 01 2017 15:51
@Refath Did you solve your codepen vs. local problem from yesterday?
@taiJones00 Being stuck without progress isn't teaching you anything but patience or frustration.
If you have really tried and are stuck, then take a look.
Refath
@Refath
Sep 01 2017 15:55
@sjames1958gm Yeah, thanks!
CamperBot
@camperbot
Sep 01 2017 15:55
refath sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8425 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Refath
@Refath
Sep 01 2017 15:55
I have the pen:
Stephen James
@sjames1958gm
Sep 01 2017 15:56
@Refath That is a cool design
Refath
@Refath
Sep 01 2017 15:57
Thanks, but the JS in the bottom is buggy
piteto
@piteto
Sep 01 2017 15:57
isn't document.ready deprecated? why are there 5?
Refath
@Refath
Sep 01 2017 15:58
I'm very inexperienced with jQury
I just kept repeating them
odm275
@odm275
Sep 01 2017 16:11
im doing the URL Shortener Microservice Incomplete 
do you need mongo?
Stephen James
@sjames1958gm
Sep 01 2017 16:11
@odm275 That project needs a database.
@Refath Wrap all your js in one document.ready -
odm275
@odm275
Sep 01 2017 16:12
@sjames1958gm what's the need for a database?
Stephen James
@sjames1958gm
Sep 01 2017 16:13
@odm275 You return a shortened URL that maps to the real URL -
You need to store the mapping from shortened URL to original URL
odm275
@odm275
Sep 01 2017 16:13
@sjames1958gm ahhh, that makes sense
@sjames1958gm thanks
CamperBot
@camperbot
Sep 01 2017 16:13
odm275 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8426 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
amatayamada
@amatayamada
Sep 01 2017 16:22
hello, I am on firefox and I'm trying to use debugger mode in a tricky situation
the situation is tricky because the webpage i'm trying to debug is a redirecting one
and i'm trying to debug the code to find out which part redirects me
setting a breakpoint on a code that shows in the debugger only for a split second is hard
what are the methods to deal with this situation?
LydaTech
@lydatech
Sep 01 2017 16:33
Click the "Tools" menu tab in your Firefox browser and select "Options." Select "Advanced" from the list of options at the top of the window. Check the box next to "Warn Me When Websites Try to Redirect or Reload the Page."
Blauelf
@Blauelf
Sep 01 2017 16:33

Some kinds of redirections can be turned off in about:preferences#advanced -> "Warn me when web sites try to Redirect or Reload the page"

Link won't work here :/

amatayamada
@amatayamada
Sep 01 2017 16:34
well, these are the http redirects
the one i'm talking about are caused by window.location, document.location or even jqueryWindow.attr("location", "/Info/AdBloc" + "k?Sour" + "ce=" + src);
there are certainly some efforts made to obscure what makes the redirect
and I thought a debugger would be helpful
but I can't make it even start on the redirecting page
i mean make it stop, like in a breakpoint ;-)
LydaTech
@lydatech
Sep 01 2017 16:36
@amatayamada whats the url of the page
amatayamada
@amatayamada
Sep 01 2017 16:36
I'm trying to write an ublock origin rule
lawrencelee93
@lawrencelee93
Sep 01 2017 16:37
hello everyone how is it going
i have a quick question
Blauelf
@Blauelf
Sep 01 2017 16:37
@amatayamada Is using NoScript an option? Was somewhat lucky with some pages, finding the script to block and suppressing a noscript element often did the trick.
lawrencelee93
@lawrencelee93
Sep 01 2017 16:37
I want to make it so that when i open my page, i start on the first image, and not a blank white page. Could someone help me a little on that?
amatayamada
@amatayamada
Sep 01 2017 16:38
@Blauelf nope, as the essence of the content on the page is js generated and the script is inline in the page along with the useful scripts
Blauelf
@Blauelf
Sep 01 2017 16:38
@lawrencelee93 Looks like your Javascript is in the CSS tab
amatayamada
@amatayamada
Sep 01 2017 16:39
until recently, ublock origin rule hotslogs.com##script:contains(.attr("location")
used to work
however, the author seems to have plugged in another method since it doesn't work anymore
amatayamada
@amatayamada
Sep 01 2017 16:39
the previous rule I wrote only blocked the single script with the offending line via ublock
and it worked brilliantly
now I'm trying to figure out what changed :)
I mean, obviously going through all the lines and trying to figure out which one does the trick could also work
but I thought learning how to use a debugger here could be more effective and educational
Cage Echarte
@CageEcharte
Sep 01 2017 16:53
Can someone help me? Im stuck on a project
amatayamada
@amatayamada
Sep 01 2017 16:54
@CageEcharte try just stating your problem here instead of asking to ask
Refath
@Refath
Sep 01 2017 16:56
Hi guys. My website https://refath.github.io/Niva/ is not loading correctly
I know I positioned the files wrong or something, but...?
Please help ASAP
I'm under a time limit
Cage Echarte
@CageEcharte
Sep 01 2017 16:59
@amatayamada Im building the simon game. And I want the colors to replay from the start after the player has clicked the colors correctly.
Blauelf
@Blauelf
Sep 01 2017 17:05

@amatayamada Just used the network tab, and at least it tells me the stack trace of what led to the redirect.

prop    https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js:4:744
attr    https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js:3:31501
S    https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js:3:116
attr    https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js:3:31269
N21d698d0    https://www.hotslogs.com/Sitewide/HeroDetails:260:19
<anonym>    https://www.hotslogs.com/Sitewide/HeroDetails:274:21

So you were right with which script did redirect you.

Cage Echarte
@CageEcharte
Sep 01 2017 17:11
Any ideas?
how do i add text to only pic[1]
Blauelf
@Blauelf
Sep 01 2017 17:24
What do you mean? Do you want to create a slider, showing different elements instead of changing background?
lawrencelee93
@lawrencelee93
Sep 01 2017 17:24
i want the picture as the background
with text in it
and when it rotates to the next picture, it is just the picture and no text
Blauelf
@Blauelf
Sep 01 2017 17:27
Then that's not just switching the background, but switching a whole element to display. Images don't have text, and backgrounds also don't.
Joshua
@jfc246
Sep 01 2017 17:45
does anyone know why there isn't any button from FCC to go to gitter?
amatayamada
@amatayamada
Sep 01 2017 17:53
@Blauelf I'm trying to replicate your result, are you using Chrome or Firefox?
my network tab doesn't seem to show me code lines
(Firefox)
or maybe I'm looking in the wrong place
ah, stack trace tab
on the right
that was quite hidden :)
amatayamada
@amatayamada
Sep 01 2017 18:03
what makes me curious is that your stack trace looks quite different from mine:
prop
https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js:4:744
attr
https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js:3:31501
S
https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js:3:116
attr
https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js:3:31269
b4821dece
https://www.hotslogs.com/Sitewide/HeroDetails:260:19
<anonymous>
https://www.hotslogs.com/Sitewide/HeroDetails:291:33
dispatch
https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js:3:9870
add/q.handle
https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js:3:7932
as in, not only is the suspect function name randomized, but the anonymous line call is whole 17 line numbers apart
291 vs 274
Now, if that javascript is generated individually per client server-side and served there's not much more I could do
but is there a possibility that he could alter the contents of this <script> tag in one of his earlier scripts and firefox now presents me the already altered version when using view source?
or does Firefox present raw HTML as received from server when using Ctrl+U? Probably the former
amatayamada
@amatayamada
Sep 01 2017 18:09
I guess I should use Wireshark to find out :D
he won't lie to me!
urgh, HTTPS
now that was always a pain to decode in Wireshark
screw you Let's Encrypt, convenient SSL cert generation providing website security! :D
ah, no need for that, it turns out Network tab in Firefox has even more useful features, such as Response tab
amatayamada
@amatayamada
Sep 01 2017 18:14
well I didn't learn how to use Firefox debugger today, but I certainly learned something useful
Network tab is awesome :D
thanks @Blauelf
CamperBot
@camperbot
Sep 01 2017 18:17
amatayamada sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4587 | @blauelf |http://www.freecodecamp.com/blauelf
Jean-Paul Sauve
@jp-sauve
Sep 01 2017 18:39
I'm having a bit of trouble with "Arguments Optional" in Intermediate Algorithm Scripting. When my function is called with 2 parentheses, I get "TypeError: addTogether(...) is not a function"
function addTogether() {
  var args = Array.prototype.slice.call(arguments);
  if (typeof args[1] === 'number' || (typeof args[0] === 'number' && typeof args[1] === 'number')) {
  if (args.length > 1) {
    return args[0]+args[1];
  }
  else return function(x) {
    return args[0]+x;
  };
  }
  return undefined;
}
oh wait...I think I see a mistake
Jean-Paul Sauve
@jp-sauve
Sep 01 2017 18:48
ok nevermind. I got it!

maybe someone would like to help with this one though? It's "Validate US phone numbers" in Advanced scripting.

function telephoneCheck(str) {
var rgx = new RegExp(/^1?\s?(\()?(?=\d{3})\d{3}(?!([\(][\d]).|^)\)?[ -]?\d{3}[ -]?\d{4}$/,'g');
var mymatch = str.match(rgx);
  console.log(mymatch);
  // Good luck!
  if (mymatch) {
  return true;
  }
  return false;
}

I'm so close, I can taste it. Only 3 cases don't pass!

Coy Sanders
@coymeetsworld
Sep 01 2017 19:05
@jp-sauve one tip also, you don't necessarily need to cram everything into one regex, you can use several.
dyon3334
@dyon3334
Sep 01 2017 19:06
array.entries() what does it ?
@coymeetsworld are you dutch ?
Moisés Man
@moigithub
Sep 01 2017 19:07
the thing inside /../ is already a regexp obj.. so u can just do
var rgx = /^1? etc etc et /g
Coy Sanders
@coymeetsworld
Sep 01 2017 19:07
no I'm not dutch
Datikzz
@Datikzz
Sep 01 2017 20:17

Hi, how i can change value of numbers that was written like this? '1 650.50'

i want to add to it some value, like 200, so it will be 1 850.50, also there is blank space that should be

Jason Luboff
@JLuboff
Sep 01 2017 20:18
I believe you'd have to remove the space first
Datikzz
@Datikzz
Sep 01 2017 20:19
ok, how to add space after calculations?
Jason Luboff
@JLuboff
Sep 01 2017 20:19
Do you always know the length of the number?
Datikzz
@Datikzz
Sep 01 2017 20:20
yes
Jason Luboff
@JLuboff
Sep 01 2017 20:24
You essentially need to use splice to add the space back in
Datikzz
@Datikzz
Sep 01 2017 20:25
nvm, just found out solution, it was so ez :3
Jason Luboff
@JLuboff
Sep 01 2017 20:25
Good :+1:
Datikzz
@Datikzz
Sep 01 2017 20:26
@JLuboff thanks anyway
CamperBot
@camperbot
Sep 01 2017 20:26
datikzz sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2183 | @jluboff |http://www.freecodecamp.com/jluboff
Guderian Raborg
@hypercuber
Sep 01 2017 20:45
How can I learn to use the libraries in three.js? I have been using TrackballControls.js but I want to learn tween.min.js, etc. Three.js have some examples but they dont explain it.
Diego Mayer
@Chrono79
Sep 01 2017 21:54
@jp-sauve test your regular expression (make sure you're using javascript as flavor in the left column) https://regex101.com/#javascript
I think your problem is with ()
1 (555 555-5555 this is passing with your regex
1 555) 555-5555 this one too
aRtoo
@artoodeeto
Sep 01 2017 22:45
yow fam. i have this regex ^1?[- .]?\(?\d{3}\)?[- .]\d{3}[- .]\d{4}
its returning me some of the true except this
5555555555 should return true.
(555)555-5555 should return true
1(555)555-5555 should return true
and its returning me this false values.
555)-555-5555 should return false.
(555-555-5555 should return false.
trying to add \s? between the square brackets but nothing happens. any idea fam?
legendinraze
@legendinraze
Sep 01 2017 22:58
how do I seperate my a class and put them next to eachother?
why cant cant I go HelpFrontEnd?
Caleb Brenner
@cwborion
Sep 01 2017 23:26

anyone able to tell me why when I open this page it takes a few seconds for the background images to start?

https://codepen.io/Calebwill91/pen/MvryOE?editors=1010

Moisés Man
@moigithub
Sep 01 2017 23:26
5555555555 should return true.
means [- .] should be optional (just like the first one u have) @artoodeeto
aRtoo
@artoodeeto
Sep 01 2017 23:27
@moigithub i did bro but still wrong. so i cheated it a little bit. heres the regex.
(^1?[- .]?\(?\d{3}\)?[- .]\d{3}[- .]\d{4}|^1?\(?\d{3}\)\d{3}[- .]\d{4}|5{10}) lol
@moigithub i added a condition or. this regex returns 5 tens. 5{10}\
@moigithub so this is just my problem now.
555)-555-5555 should return false. (555-555-5555 should return false.
Moisés Man
@moigithub
Sep 01 2017 23:29
u only had to add 2 ? i think....
for that last case .. an or will work
(555) OR 555
piteto
@piteto
Sep 01 2017 23:32
@cwborion setInterval will wait before running the function the first time. You could try something like this:
function startSlideShow() {
  action();
  setInterval(action, 3000);
}

window.onload= startSlideShow;
Caleb Brenner
@cwborion
Sep 01 2017 23:33
@piteto thanks I’ll give it a try!
CamperBot
@camperbot
Sep 01 2017 23:33
cwborion sends brownie points to @piteto :sparkles: :thumbsup: :sparkles:
:cookie: 40 | @piteto |http://www.freecodecamp.com/piteto
piteto
@piteto
Sep 01 2017 23:34
No problem
Are we 'graded' on our algorigthms? I was running through the js algorithms and then thought...maybe I should add code comments to explain my thought process?
Murrium
@Murrium123
Sep 01 2017 23:38
No I think it only focuses if it works on not... you dont have to explain it
FlashHero
@FlashHero
Sep 01 2017 23:55

nodejs help please

router.post('/signin',passport.authenticate('local', { successRedirect: '/success',
failureRedirect: '/signup' }),function(req,res){
    console.log('hello');
});

It redirects me to the success page but I wanted to assign a session but the function doesn't even run after it redirects me help please