These are chat archives for FreeCodeCamp/HelpJavaScript

5th
Jan 2018
aRtoo
@artoodeeto
Jan 05 2018 08:48
hello fam

is there a way we can detect if the function stops running
because i need to disable a button after being pressed then enable it after the function ends.
heres my code

var timerFn; //GLOBAL assign to timer function

    //start button function
    $("#btnPly").on('click', function() {

        $("#btnPly").attr('disabled' , 'disabled'); //disables after press

        timerFn = timer(sesVal, 60); // timer function takes 2 argumetns
        console.log('adasf'); //checking if attr disable is working
    });

    /* timer function*/
    function timer(minutes,seconds) {

        // console.log(typeof minutes); //checking type of data. (needs to be a number)

        $('#min').text(minutes);  //passes and displays the minutes to HTML  
        $('#secs').text(seconds); //passes and displays the seconds to HTML 

        var counter = setInterval(setIntervalFunction,10); //Interval for the timer, assigned to counter variable (counter will be use to clearInterval)

        //function for callback function for setInterval    
        function setIntervalFunction() {

            $('#secs').text(seconds-=1); //reduced seconds by 1;

            if(minutes > 0 && seconds === 0){ //condition if seconds and minutes are 0;

                $('#min').text(minutes-=1); ///reduced minutes by 1;

                seconds = 60; // revalues seconds
            } 

            else if(minutes === 0 && seconds === 0) { //condition to check if minutes is 0, then passes a new value of minutes in timer function.

                clearInterval(counter); //clears the counter setInterval or stop

                if (brkVal > 0) { //if brkVal gets zero
                    timer(brkVal, 60); //passes the a new argument to the timer function. takes the first argument as a minutes of brkVal
                    brkVal  = 0; //revalues brk to zero 

                    $("#btnPly").removeAttr('disabled'); // shouldnt be here. need to enable attr after the timer is finished
                }
            }

        }

        return counter; //timer function will return the setInterval to timer and timer to timerFn

    }

i put the removeAttr inside the if brkVal > 0 which i know is wrong just for testing.

Long Nguyen
@longnt80
Jan 05 2018 11:22
@artoodeeto use a flag
var functionIsRunning = true
after function is done, has it run: functionIsRunning = false
pocahontas123
@pocahontas123
Jan 05 2018 13:15

HELLO, i have a simple question regarding "https://gitcdn.link/repo/freeCodeCamp/testable-projects-fcc/master/build/bundle.js" with the tribute project. THANKS
Maybe question is: Is it normal that i only have 1 test running out (1/10 with green color) and not like 10/10 ? It say in it: Tribute Page tests

Technology Stack

And at the top right: 1test 0 failure. So it mean it is ok for me?
(i'm going to check the chat now and then :) )

Virgo
@QTFYING
Jan 05 2018 15:28
'
Daniel Romero
@Ranacode
Jan 05 2018 16:07
Hey guys I have a weird issue on my code
I can't get the style values from an html element
If I console.log the style.display property, give me a blank string and I already prove on the console that the element exists on the variables
const signupForm = document.querySelector(".signup-container");
const loginForm = document.querySelector(".login-container");

console.log(signupForm.style.display)
console.log(loginForm.style.display)
And I already have some displays for them on my .css file
Pieter Stokkink
@forkerino
Jan 05 2018 16:22
@Ranacode does the code run before the css is loaded?
Jason Luboff
@JLuboff
Jan 05 2018 16:40
@forkerino :wave:
Will White
@willnwhite
Jan 05 2018 16:42
@pocahontas123 All I can say to you is that when I run the Tribute Page tests in the CodePen (without doing any coding) I get "Tests 1/10". When I click on that I get Technology Stack passed, other tests failed. That sounds the same as you.
Pieter Stokkink
@forkerino
Jan 05 2018 17:00
@JLuboff Yo
Jason Luboff
@JLuboff
Jan 05 2018 17:01
@forkerino How's it going?
Daniel Romero
@Ranacode
Jan 05 2018 17:03
@forkerino Thanks by the way, I already fixed and the code runned after the css was loaded
CamperBot
@camperbot
Jan 05 2018 17:03
ranacode sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2957 | @forkerino |http://www.freecodecamp.org/forkerino
Daniel Romero
@Ranacode
Jan 05 2018 17:04
I just change the code lines to obtain the display property for this
Pieter Stokkink
@forkerino
Jan 05 2018 17:04
@JLuboff all is well, went to one of those indoor playgrounds with my daughter this afternoon, she went completely wild and enjoyed a lot.
Daniel Romero
@Ranacode
Jan 05 2018 17:04
getComputedStyle(loginForm).getPropertyValue("display")
Pieter Stokkink
@forkerino
Jan 05 2018 17:06
@Ranacode ah, ok, getting the css props of an element is something I rarely do. Maybe you had problems because querySelector returned a collection of HTML elements?
Jason Luboff
@JLuboff
Jan 05 2018 17:06
@forkerino Awesome! What sort of activities are part of the indoor playground (slides, etc?)
Daniel Romero
@Ranacode
Jan 05 2018 17:07
Yes, I think so, the HTML collection always is a pain if you forgot it :P
Pieter Stokkink
@forkerino
Jan 05 2018 17:07
@Ranacode indeed
@JLuboff they had everything! Slides, huge lego blocks, a room pretty much filled with balls, stuff to climb on, trampolines, the works.
Jason Luboff
@JLuboff
Jan 05 2018 17:09
@forkerino Oh that sounds like tons of fun! Is it free to get into?
Pieter Stokkink
@forkerino
Jan 05 2018 17:10
@JLuboff nah, had to pay 7 euros for the two of us, but it was totally worth it.
Jason Luboff
@JLuboff
Jan 05 2018 17:10
Thats not bad at all
Pieter Stokkink
@forkerino
Jan 05 2018 17:12
It's still school holiday, so it was a bit crowded, but lots of fun (and it tires them a lot, so we'll probably be able to put her to bed early and have some time to ourselves ;) )
Jason Luboff
@JLuboff
Jan 05 2018 17:12
;)
@forkerino How's work been?
Pieter Stokkink
@forkerino
Jan 05 2018 17:19
@JLuboff It's still lots of fun. I'm diving into Django/Python/TDD at the moment and this really helps me to become more all-round in our current stack.
@JLuboff How's the little one? And how are you adjusting to the new way of life?
Daniel Romero
@Ranacode
Jan 05 2018 17:20
Hey guys I have a challenging question, How can I check if a cookie exist on the browser without reading it with javascript (document.cookie) ?
Jason Luboff
@JLuboff
Jan 05 2018 17:20
@forkerino Learning new things is always a positive. He is doing well. Doing my best to adjust to sleep and what not haha. Definitely less time at home to do hobbies, but thats alright
Daniel Romero
@Ranacode
Jan 05 2018 17:22
That question it's because I have jsonwebtoken implemented on the server side and I storage it on a cookie that I send to the client but I want to display a modal that have the signup/login forms if the cookie don't exist
Pieter Stokkink
@forkerino
Jan 05 2018 17:23
@Ranacode so why would you not want to read it?
Daniel Romero
@Ranacode
Jan 05 2018 17:24
I readed that reading cookies via javascript it's vulnerable to some xss attacks
httpOnly: true, avoid this
Pieter Stokkink
@forkerino
Jan 05 2018 17:59
Sorry got called away, I have no idea about the security issues with regards to webtokens stored in cookies. It just seems to me that you can't really check if something is there without reading it.
@JLuboff Hobbies? What are those? :P
Jason Luboff
@JLuboff
Jan 05 2018 18:00
@forkerino Ya ya ya... I know haha. A father can dream :P
Ghost
@ghost~56ef2a8b85d51f252ab9dec9
Jan 05 2018 18:53
Hi everyone! I have a back-end related question.
I want to update my database daily. For example, I want that every morning at 9AM, my database has to be updated.
I'm currently using mLab (mongoDB) to store data and Heroku to host my apps. Does someone know how to do it ?
Jason Luboff
@JLuboff
Jan 05 2018 18:57
@thomlom I think you would need a chron job and then you'd probably have to have an always running app on heroku. (I've never done either though)
Ghost
@ghost~56ef2a8b85d51f252ab9dec9
Jan 05 2018 19:01
@JLuboff Thanks for your response. What do you mean by cron job?
CamperBot
@camperbot
Jan 05 2018 19:01
thomlom sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2288 | @jluboff |http://www.freecodecamp.org/jluboff
legendinraze
@legendinraze
Jan 05 2018 19:20
why does total equal 40?

var myArr  = [2, 3, 4, 5, 6];
var myTotal = 0;

for (var i = 0; i < myArr.length; i++) {
 total += myArr[i];
}
It's supposed to equal 20
Markus Kiili
@Masd925
Jan 05 2018 19:33
@legendinraze That code makes an error actually.
Use myTotal inside the loop instead of total.
Stephen James
@sjames1958gm
Jan 05 2018 19:35
@thomlom A cron job is a periodic task that is available on most *nix system that is enabled by the cron process and controlled by crontab files.
Ghost
@ghost~56ef2a8b85d51f252ab9dec9
Jan 05 2018 19:46
@sjames1958gm Do you know if we create cronjobs on Heroku?
Stephen James
@sjames1958gm
Jan 05 2018 19:46
@thomlom I don't know, I would not think so.
legendinraze
@legendinraze
Jan 05 2018 19:50
@Masd925 it still comes out as 40
Jason Luboff
@JLuboff
Jan 05 2018 19:54
@thomlom There are several npm packages, such as https://www.npmjs.com/package/cron (again, I haven't used any)
But that package for example, has been downloaded almost 1 million times in the last month...so it must do something right ;)
Brad
@bradtaniguchi
Jan 05 2018 19:57
@JLuboff Maybe the package runs a cron to download itself, thus 1million dowloads :trollface:
Jason Luboff
@JLuboff
Jan 05 2018 19:59
@bradtaniguchi That would be the ultimate :trollface:
aRtoo
@artoodeeto
Jan 05 2018 23:22
hello guys. made a loading bar but it wont fill the whole bar. checkout my pen. thanks
https://codepen.io/artoo/pen/BJmywa?editors=1111
Jason Luboff
@JLuboff
Jan 05 2018 23:28
@artoodeeto Works fine in firefox
aRtoo
@artoodeeto
Jan 05 2018 23:35
@JLuboff damn. google has issue. i just added plus 1
I would like to get feedback please
if anyone is kind enough
Jason Luboff
@JLuboff
Jan 05 2018 23:37
@onomesotu Looks good and works properly, good job!
Aditya
@ezioda004
Jan 05 2018 23:40
@onomesotu I like it, its elegant. IMO if you can add maybe a transition/delay when next search happens and add hovering effect over the title of returned search results, it'll look better otherwise its very good.
aRtoo
@artoodeeto
Jan 05 2018 23:46
@onomesotu like bro. minimalist design. good job man.