These are chat archives for FreeCodeCamp/Help

3rd
Jan 2019
thedev-ninja
@thedev-ninja
Jan 03 01:55
can you share code?
@tundeiness
also hello everyone and happy new year
Richmond Wong
@richmondwong
Jan 03 04:12
Hi there - does FCC save answers to coding challenges? Everytime I revisit challenges I’ve previously completed, all my code is lost!
Sometimes I go back to old challenges to see how certain concepts are implemented
b3twiise
@b3twiise
Jan 03 04:47
I have a similar situation. But usually going to my profile then I can see my progress + my submissions. Havent checked much so far though. Might be one thing to look at.
I would also manually refresh the page from time to time to make sure
Richmond Wong
@richmondwong
Jan 03 04:51
Ohhh ok. I Googled and I found a discussion thread where Quincy (founder of FreeCodeCamp) said that only algorithim challenges (bonfires) and projects are saved?
@b3twiise For you the code you wrote for “regular” challenges is saved?
b3twiise
@b3twiise
Jan 03 05:14
@richmondwong tried to replicate what I just described with no success. While I was so sure I did it before.
Richmond Wong
@richmondwong
Jan 03 05:15
@b3twiise Ohhhh dohhh :(
@b3twiise Yeah its wierd how it doesn’t save :(
b3twiise
@b3twiise
Jan 03 05:16
@richmondwong yeah, did not work. I think it used to work. But maybe giving the success of the platform, they decided to save in sever costs and stuff by not saving those. Just guessing
Richmond Wong
@richmondwong
Jan 03 05:21
Yeah that’s what I was thinking too
Think Quincy mentioned that in the discussion thread I read as well
DevelopingUK
@DevelopingUK
Jan 03 10:13

I’m having a play around with functions and scope… Why is my local variable being console.log to chrome dev tools, I expect “global” to show up once but it shows up twice if I call it outside of the function?

‘function hiThere (a, b) {
console.log(a * b)
var myGlobal = "global";
console.log(myGlobal)
}

hiThere(507, 17);

console.log(myGlobal);'

psyperl
@psyperl
Jan 03 10:19
function hiThere (a, b) {
 console.log(a * b)
 var myGlobal = "global";
 console.log(myGlobal) // [1.0] will print global if hiThere is called
}

hiThere(507, 17); // [1.1] hi there is called. it will print 'global' read [1.0]
console.log(myGlobal); // [1.2] this will print 'global' also
so yeah .. 'global' will be printed twice.
DevelopingUK
@DevelopingUK
Jan 03 10:19
Thank you so much, so I am in fact calling it 3 times but the last one isn’t being called?
psyperl
@psyperl
Jan 03 10:21
you are calling it twice only. that is in [1.1] and [1.2] ... although [1.1] is actually calling [1.0]
DevelopingUK
@DevelopingUK
Jan 03 10:22
Okay, I get it now, thank you so much I really appreciate the help!
psyperl
@psyperl
Jan 03 10:22
:thumbsup:
DevelopingUK
@DevelopingUK
Jan 03 10:51
Do you know why if i call outside of the scope the console on chrome still shows the result of the variable but in quotation with the string colour red?

``` function hiThere (a, b) {
console.log(a * b)
var myGlobal = "global";
console.log(myGlobal)
}

hiThere(507, 17);
myGlobal; ```

Is it saying, this is what you wanted and we will show you it but in red to remind you this is bad practice?
abraham anak agung
@padunk
Jan 03 11:01

@DevelopingUK use ``` in separate line

 function hiThere (a, b) {
console.log(a * b)
var myGlobal = "global";
console.log(myGlobal)
}

hiThere(507, 17);
myGlobal;

you can't call a variable.

DevelopingUK
@DevelopingUK
Jan 03 11:02
Thanks
It’s still outputting to the console, I just wondered why? My purpose is to break things to learn what’s right/wrong but I’m still seeing the result of the variable.
psyperl
@psyperl
Jan 03 11:04
i might made a bit mistake about the printing before...
firstly
function hiThere() {
  var myGlobal = "global"
}

hiThere()
console.log(myGlobal); // this will never  print "global" because myGlobal is out of scope
abraham anak agung
@padunk
Jan 03 11:05
@DevelopingUK what console you use? you can't call variable like that, it will output undefined
DevelopingUK
@DevelopingUK
Jan 03 11:05
Chrome dev tools, right click > console.
abraham anak agung
@padunk
Jan 03 11:06
I tried it, it will output ref error.
VM210:1 Uncaught ReferenceError: myGlobal is not defined
    at <anonymous>:1:1
DevelopingUK
@DevelopingUK
Jan 03 11:06
Screenshot 2019-01-03 at 11.51.15.png
That’s what I’m seeing.
psyperl
@psyperl
Jan 03 11:08
it shows in red because you typed it in console
basically you are asking the console what vallue is in myGlobal
DevelopingUK
@DevelopingUK
Jan 03 11:09
Okay, that makes a lot of sense @psyperl thanks again!
I just ran it inside VScode terminal and I get myGlobal is not a function error as you suggested, makes more sense now, thanks again!
May Kittens Devour Your Soul
@diomed
Jan 03 11:16
hoopla to you! @psyperl
psyperl
@psyperl
Jan 03 11:16
@diomed hoopla
for me Javascript is much easier to code without var. one can ask me question about tricky var situation and i can possibly still trip on it
DevelopingUK
@DevelopingUK
Jan 03 11:21
Do you prefer let or something else? @psyperl
psyperl
@psyperl
Jan 03 11:21
yes I only use let and const @DevelopingUK
they are much easier to predict
DevelopingUK
@DevelopingUK
Jan 03 11:22
I might be wrong but let is similar to var but cannot be called outside a the scope of the function it is in and const just means the variable will never change throughout the program?
psyperl
@psyperl
Jan 03 11:23
correct
DevelopingUK
@DevelopingUK
Jan 03 11:24
@psyperl - would you suggest moving away from using var altogether for someone new to javascript?
psyperl
@psyperl
Jan 03 11:24
strongly suggest :D
except the part that some tutorial is still trying to explain what var is.. but in general .. i think one can code without and code better
DevelopingUK
@DevelopingUK
Jan 03 11:27
Okay, I’m taking note, if at some point I get into trouble I’ll just say “ @psyperl said it’s better” :D
psyperl
@psyperl
Jan 03 11:28
I would be happy if someone gives me a counter perspective about it ( var ) .. but i am pretty sure most of us has left the var behind :D
korzo
@korzo
Jan 03 11:33
@psyperl You can't repeatedly run code with let/const in console
psyperl
@psyperl
Jan 03 11:34
@korzo what do you mean by repeatedly run code in console? maybe give me an example? i'll try to reply with let/const variant
hensn5250
@hensn5250
Jan 03 11:34
const is not good for the console
if testing your code since it is fixed
psyperl
@psyperl
Jan 03 11:36
well yes .. it's meant to make things fixed @hensn5250 :D
DevelopingUK
@DevelopingUK
Jan 03 11:36
I am writing code inside VScode and running it using node file.js from the terminal, I just read that I need to get familiar with the chrome dev tools to debug :D
hensn5250
@hensn5250
Jan 03 11:37
@psyperl right, he was saying repeatedly run code.... const will likely lead to error message in the console if running tests
psyperl
@psyperl
Jan 03 11:39
@hensn5250 if one need something to be redeclared or it's value to be overwritten, then one shouldn't use const .. const are there to guard against such case
korzo
@korzo
Jan 03 11:41
@psyperl It's the same with let. It's really annoying, when you want to quickly test/fix some snippet
hensn5250
@hensn5250
Jan 03 11:41
@DevelopingUK chrome has a great debugger. Using the debugger is much better than using console.log since you can set breakpoints and watch the changes in values of your variables... might be overkill for small apps though
@psyperl i agree
why is let annoying?
let is just a better version of var
korzo
@korzo
Jan 03 11:45
@hensn5250 We were talking about running code in console.
DevelopingUK
@DevelopingUK
Jan 03 11:45
@hensn5250 Thanks! Is it similar to the debugger inside VScode?
hensn5250
@hensn5250
Jan 03 11:46
@DevelopingUK don't know, never used VS Code's debugger.
@psyperl do you use any JS frameworks?
DevelopingUK
@DevelopingUK
Jan 03 11:49
@hensn5250 thanks
hensn5250
@hensn5250
Jan 03 11:49
no problem, FYI, FireFox Dev Edition also has a great debugger
psyperl
@psyperl
Jan 03 11:50
@hensn5250 only if it's decided for me, but no i generally do not use third parties
DevelopingUK
@DevelopingUK
Jan 03 11:50
I will download FF now and check it out!
hensn5250
@hensn5250
Jan 03 11:50
If I recall correctly, VS Code has a plugin for using both Chrome and FF debugger in the IDE
@psyperl If you had to use one which would you recommend. I also stay far from 3rd part stuff but would like to learn a good framework but there are so many.
The obvious choice at the moment is Angular or React
DevelopingUK
@DevelopingUK
Jan 03 11:53
I am trying to get to an advanced level of javascript before I touch a framework so I can switch between frameworks if I need to.
I like react and also might try learn vue.
psyperl
@psyperl
Jan 03 11:54
@hensn5250 I don't think i am the correct person to ask that.. coz my knowledge of those ( Angular/React/Vue) are very limited. :D
DevelopingUK
@DevelopingUK
Jan 03 11:54
@psyperl what do you usually build with? Vanilla.js?
psyperl
@psyperl
Jan 03 11:55
@DevelopingUK yes
hensn5250
@hensn5250
Jan 03 11:55
@psyperl oh ok, .. same here
DevelopingUK
@DevelopingUK
Jan 03 11:55
I learnt ruby on rails before (up to deploying an app struggled with running tests) but I’d like a similar MVC framework once I’ve learned javascript.
Either that or learn to use API’s.
hensn5250
@hensn5250
Jan 03 11:56
how are you learning JavaScript?
DevelopingUK
@DevelopingUK
Jan 03 11:57
I learnt an aspect of it from a video like, for example, functions
then I just keep writing them and breaking them whilst trying new things until I understand what it is and how to use it.
I’m on if-else statements/functions now and I’ll keep going until I break things enough to know what I’m doing…
hensn5250
@hensn5250
Jan 03 11:59
@DevelopingUK JavaBrains has a awesome playlist for learning JS
DevelopingUK
@DevelopingUK
Jan 03 11:59
var askNumber = prompt("What is your favourite number?");

function myTry (a) {
    if (a = 5) {
        return "This is my number too!";
    } else {
        return "terrible number";
    }
};

myTry(a);
I’m getting a is not defined here, so working my way through it.
psyperl
@psyperl
Jan 03 11:59
a = 5 is an assignment
DevelopingUK
@DevelopingUK
Jan 03 11:59
Opened JavaBrains and will look at it today, thanks!
hensn5250
@hensn5250
Jan 03 12:00
Its more theory heavy than FCC, its a good supplement to FCC's practice based learning.
DevelopingUK
@DevelopingUK
Jan 03 12:00
yeah, I want to get user feedback, so I ask a user what their favourite number is and depending on their answer it returns the strings in if-else.
psyperl
@psyperl
Jan 03 12:00
myTry(a); a is never defined previously
DevelopingUK
@DevelopingUK
Jan 03 12:01
so put a variable inside defining it as askNumber?
or the argument is askNumber?
or am i way off here? :D
psyperl
@psyperl
Jan 03 12:02
the arg probably is askNumber yes
hensn5250
@hensn5250
Jan 03 12:03
@DevelopingUK what is your code suppose to be doing?
psyperl
@psyperl
Jan 03 12:03
assuming that prompt function is meant to return the number from user
DevelopingUK
@DevelopingUK
Jan 03 12:03
yeah it worked
it returned the string.
I’m practicing if-else statements with user input, I find it easier to learn JS concepts if it requires user input which also helps me with the flow @hensn5250
hensn5250
@hensn5250
Jan 03 12:05
@DevelopingUK oh ok, just read your explanation a few lines above
DevelopingUK
@DevelopingUK
Jan 03 12:05
I prompt the user for a number if it’s = 5 then it returns the first string if not it returns the second string, it’s now working after fixing the argument.
@hensn5250 no worries :)
but I need to add something to the else statement as it will return the first statement.
psyperl
@psyperl
Jan 03 12:06
please check the difference between = and == operator
= is an assignment, while == or === are comparison op
DevelopingUK
@DevelopingUK
Jan 03 12:06
@psyperl awesome, thanks! I’ll look now.
So, I’m not assigning it with = I am comparing it with == …
so i can do =< 5 which would be less than or equal to 5
psyperl
@psyperl
Jan 03 12:09
correct
so possibly <= instead of =< ? :D
DevelopingUK
@DevelopingUK
Jan 03 12:12
Yeah that’s a lot better on the eyes too :D
DevelopingUK
@DevelopingUK
Jan 03 12:23
@psyperl thanks to your advice, this is what I ended up with and it works as I want it to...
var askNumber = prompt("What is your favourite number?");

function myTry (askNumber) {
    if (askNumber == 5) {
        return "This is my number too!";
    } else if (askNumber != 5) {
        return "terrible number";
    }
};

myTry(askNumber);
psyperl
@psyperl
Jan 03 12:25
awesome @DevelopingUK :thumbsup:
just a teaser .. that some might write that like this :D
const myTry = askNumber => askNumber == 5 ? "this is my number too!" : "terrible number"
myTry(prompt("What is your favourite number?"))
DevelopingUK
@DevelopingUK
Jan 03 12:36
Is that more advanced javascript?
is that what I should aim for?
I think I’m writing like a noob haha :D
psyperl
@psyperl
Jan 03 12:37
that is the ES6 version.. and no yours is not like a noob .. just more formal i believe
psyperl
@psyperl
Jan 03 12:56
now i wonder when ES7 will be the current version.. or has it been already
DevelopingUK
@DevelopingUK
Jan 03 13:07
@psyperl thanks!
Anand Potukuchi
@anandpotukchi
Jan 03 17:27
how do i find the docs in between two dates
what is the method
psyperl
@psyperl
Jan 03 17:29
you want the time interval between 2 dates?
Anand Potukuchi
@anandpotukchi
Jan 03 17:30
@psyperl say tow fields
sorry two vaues in fields
psyperl
@psyperl
Jan 03 17:31
ok so you have 2 date fields?
Anand Potukuchi
@anandpotukchi
Jan 03 17:31
yeah
psyperl
@psyperl
Jan 03 17:31
and you want to find the interval between those 2 dates?
like date1 - date2 ?
Anand Potukuchi
@anandpotukchi
Jan 03 17:32
no
i wanrto show the documents in b/w thse two
psyperl
@psyperl
Jan 03 17:33
like docs.date <= date1 && docs.date >= date2 ?
Jason Luboff
@JLuboff
Jan 03 17:34
@anandpotukchi documents...as in documents from a database...?
Anand Potukuchi
@anandpotukchi
Jan 03 17:34
yes
sorry i wasn't elaborate
Jason Luboff
@JLuboff
Jan 03 17:34
You need to say that from the beginning
What type of database
Anand Potukuchi
@anandpotukchi
Jan 03 17:34
im doing the exercise tracker
mongoDB
can you chck my code
Jason Luboff
@JLuboff
Jan 03 17:35
Ok.. so you would want db.collection.find({date: {$gte: firstDate, $lte: secondDate}})
Obiviousily you need to change out some items there but you get the basic idea
Aditya
@ezioda004
Jan 03 17:41
That gte and lte is so not intuitive
Jason Luboff
@JLuboff
Jan 03 17:42
How so?
Anand Potukuchi
@anandpotukchi
Jan 03 17:45
@ezioda004 alternate?
can someone point me to the docs
Aditya
@ezioda004
Jan 03 17:47
@JLuboff I mean the abbreviation :D Atleast at the beginning
Anand Potukuchi
@anandpotukchi
Jan 03 17:48
Is there a way
With mongoose
@ezioda004
Aditya
@ezioda004
Jan 03 17:48
Its the same thing in mongoose too
Jason Luboff
@JLuboff
Jan 03 17:52
@ezioda004 Oooh gotcha.. ya.. its a bit clearer in SQL :) (either Col1 >= firstDate And Col1 <= secondDate or Col1 Between firstDate And secondDate
Karma Drukpa
@coderkarma
Jan 03 18:00
question
I want to change the color of each letter of h1 , let's say my <h1> Karma Drukpa </h1> is this.
What would be good way of changing colors of each letter of that h1 tag.
_
Aditya
@ezioda004
Jan 03 18:11
@JLuboff Oh yeah, totally
@coderkarma You can generate like a span around each letter dynamically with JS and then color them with JS too
Karma Drukpa
@coderkarma
Jan 03 18:12
[...document.querySelector('h1').innerText].map(char => <span> classs="${char}"> ${char} </span>)
@ezioda004
I have this and random color function, I am trying to make h1 each letter filled with random colors
Aditya
@ezioda004
Jan 03 18:14
That seems fine
Karma Drukpa
@coderkarma
Jan 03 18:19
@ezioda004 Do i need to append or do anything because this is not working, it is just making class for each letter of h1 tag
even though i gave css for each letter like .K { color : blue}
Jason Luboff
@JLuboff
Jan 03 18:20
You misspelled class
Aditya
@ezioda004
Jan 03 18:21
Yes, you'd need to add it back to the h1
document.querySelector("h1").innerHTML = [...document.querySelector('h1').innerText]
  .map(char => `<span> class="${char}"> ${char} </span>`);
Karma Drukpa
@coderkarma
Jan 03 18:27
this is giving me all the classes and displaying in h1 tag
Y4T9Code
@Y4T9Code
Jan 03 19:37
hi
psyperl
@psyperl
Jan 03 21:01
hmm i am failing the 6th test on drum machine, somehow the test can't detect the event key listener triggerring the sound
psyperl
@psyperl
Jan 03 21:09
ok seems like they send the capital Q instead of q ( not sure )