These are chat archives for FreeCodeCamp/HelpJavaScript

9th
May 2018
Ryan Williams
@Ryanwfile
May 09 2018 01:36 UTC
If I have a data type of a number such as .16666 how do I get it to only show 5 decimal places without converting it to a string with toFixed or toPrecision?
K-ream
@K-ream
May 09 2018 05:48 UTC
Is it possible to circulate random six digits?
Markus Kiili
@Masd925
May 09 2018 06:01 UTC
@K-ream What do you mean exactly?
Blauelf
@Blauelf
May 09 2018 06:10 UTC
@Ryanwfile "show" sounds like you do some conversion to string?
1Mher1
@1Mher1
May 09 2018 08:29 UTC
jQuery; who can help me to create canvas snake game food this is my code
I have 3 js file in codepan what function i can do to show all js?
Koohyar Movassagh
@Koohyar-m
May 09 2018 09:44 UTC
Morning :wave:
Stephen James
@sjames1958gm
May 09 2018 10:41 UTC
@ConnectCodes :wave:
Nate Mallison
@NJM8
May 09 2018 12:35 UTC
@Ryanwfile Number(myNum.tofixed(5))
just convert back to a number
Joshua Frias
@Juke-Magic
May 09 2018 13:17 UTC
guys will this work?
contacts[i].hasOwnProperty(firstName, prop); ???
Nate Mallison
@NJM8
May 09 2018 13:23 UTC
I think hasOwnProperty only takes one arguement
Ken Haduch
@khaduch
May 09 2018 13:34 UTC
@Juke-Magic - I posted this in the HelpFrontEnd room.
@Juke-Magic - hasOwnProperty docs for reference - the .hasOwnProperty() method accepts a single parameter. Or at least would ignore any other parameters and only process the first one. For the contact list, all contacts have the firstName property so you don't really have to check for that in this situation.
Jason Luboff
@JLuboff
May 09 2018 15:32 UTC
:fire:
Blauelf
@Blauelf
May 09 2018 15:39 UTC
Thanks, now playing in my head: Alicia Keys - Girl On Fire
Could be worse.
Jason Luboff
@JLuboff
May 09 2018 15:42 UTC
:joy:
Nazar
@IsaakNazar
May 09 2018 16:17 UTC
hey everybody, what am I doing wrong ?
const menu = document.querySelector('.hamburger-menu');

[].forEach.call(menu, function(m) {
  m.addEventListener('click', function() {
    console.log('toggle');
     m.classList.toggle('close-hamburger');
  });
});
dinesh
@1532j0004kg
May 09 2018 16:18 UTC
m ?
Nazar
@IsaakNazar
May 09 2018 16:18 UTC
my hamburger menu doesnt toggle
dinesh
@1532j0004kg
May 09 2018 16:18 UTC
menu?
menu or m
Nazar
@IsaakNazar
May 09 2018 16:19 UTC
I'm passing argument
dinesh
@1532j0004kg
May 09 2018 16:19 UTC
ohh ok
can u put the codepen link
Nazar
@IsaakNazar
May 09 2018 16:19 UTC
ok, one sec
dinesh
@1532j0004kg
May 09 2018 16:22 UTC
so here what is m
where u passing
Wait i will give u
the reference for navbar toggle
Nazar
@IsaakNazar
May 09 2018 16:28 UTC
@1532j0004kg nope, hover on hamburger menu, and you'll se what it has to do
Jason Luboff
@JLuboff
May 09 2018 16:29 UTC
@IsaakNazar Why the foreach? If you just add the event listener to menu it will toggle
Nazar
@IsaakNazar
May 09 2018 16:32 UTC
@JLuboff like this?
function toggling() {
  menu.classList.toggle(closeMenu);
}

menu.addEventListener('click', toggling);
@JLuboff oh thx got it :smile:
Jason Luboff
@JLuboff
May 09 2018 16:34 UTC

I did this

menu.addEventListener('click', function(){
  menu.classList.toggle('close-hamburger');
})

but ya if you had a function toggling that would work

Christopher McCormack
@cmccormack
May 09 2018 16:36 UTC
Yeah the javascript will do nothing if you call a forEach on an empty array
Jason Luboff
@JLuboff
May 09 2018 16:38 UTC
@cmccormack :wave:
Nazar
@IsaakNazar
May 09 2018 16:40 UTC
@cmccormack my bad :worried:
Christopher McCormack
@cmccormack
May 09 2018 16:41 UTC
@JLuboff yo
Jason Luboff
@JLuboff
May 09 2018 16:41 UTC
What up
Christopher McCormack
@cmccormack
May 09 2018 16:43 UTC
NM playing the semantics game on how to name different fields in our master template.
could go on forever...
@IsaakNazar that's a nice effect on your hamburger, I like it!
Jason Luboff
@JLuboff
May 09 2018 16:44 UTC
Oh fun..
Nazar
@IsaakNazar
May 09 2018 16:44 UTC
@cmccormack oh yeah, thanx :+1:
Christopher McCormack
@cmccormack
May 09 2018 16:45 UTC
not even a little
Jason Luboff
@JLuboff
May 09 2018 16:52 UTC
:P
Nazar
@IsaakNazar
May 09 2018 17:02 UTC
ok guys, one more question
how to toggle my class using transition ?
const menu = document.querySelector('.hamburger-menu');
const nav = document.querySelector('.nav_positionfixed');

function toggling() {
  menu.classList.toggle('close-hamburger');
  if (document.querySelector('.close-hamburger')) {
    nav.style.display = 'none';
    nav.style.transition = '.2s ease-in-out';
  } else {
    nav.style.display = 'block';
    nav.style.transition = '.2s ease-in-out';
  }
}
menu.addEventListener('click', toggling);
Christopher McCormack
@cmccormack
May 09 2018 17:09 UTC
@IsaakNazar why not just do all of that in your css?
add a class to your nav when you toggle
Nazar
@IsaakNazar
May 09 2018 17:12 UTC
@cmccormack coz I have no idea how to do that :worried:
still googling
Jason Luboff
@JLuboff
May 09 2018 17:13 UTC
One timed I googled...and never returned..
Gulsvi
@gulsvi
May 09 2018 17:14 UTC
That usually happens with Bing :p
Christopher McCormack
@cmccormack
May 09 2018 17:14 UTC
Some say he has become a part of Google
Jason Luboff
@JLuboff
May 09 2018 17:14 UTC
@gulsvi I actually exclusively use Bing (Microsoft rewards FTW)
Gulsvi
@gulsvi
May 09 2018 17:15 UTC
I should give that a try, to be honest. I checked out my xbox account and it had thousands of those points - no idea how I got them
Jason Luboff
@JLuboff
May 09 2018 17:15 UTC
So far I've gotten two years of Xbox live for free just by using Bing and doing the daily rewards
Gulsvi
@gulsvi
May 09 2018 17:16 UTC
Wow, huh... wonder if I can automate that
Jason Luboff
@JLuboff
May 09 2018 17:17 UTC
Maybe? I've never tried
Christopher McCormack
@cmccormack
May 09 2018 17:17 UTC

@IsaakNazar

function toggling() {
  menu.classList.toggle('close-hamburger');
  nav.classList.toggle('hamburger-closed');

?

then add some nav.hamburger-closed { css
Markus Kiili
@Masd925
May 09 2018 17:20 UTC
:wave:
Jason Luboff
@JLuboff
May 09 2018 17:21 UTC
@Masd925 :wave: How's the new job?
Markus Kiili
@Masd925
May 09 2018 17:21 UTC
@JLuboff Today was the last day at the old job. Two and half weeks of vacation/studying before the new one starts.
Christopher McCormack
@cmccormack
May 09 2018 17:22 UTC
@Masd925 hi
Markus Kiili
@Masd925
May 09 2018 17:22 UTC
Hi.
Christopher McCormack
@cmccormack
May 09 2018 17:22 UTC
Is anyone else having Gitter issues? Doesn't seem to be working without reloading a lot
Markus Kiili
@Masd925
May 09 2018 17:22 UTC
I'm having same problems too.
Jason Luboff
@JLuboff
May 09 2018 17:22 UTC
@cmccormack I'm using the app and its acting up, ya
1Mher1
@1Mher1
May 09 2018 17:22 UTC
someone who can help me to create real data& time in jQuery?
Jason Luboff
@JLuboff
May 09 2018 17:22 UTC
@Masd925 Ah! I thought you had already been on vacation
Christopher McCormack
@cmccormack
May 09 2018 17:23 UTC
that's actually why I don't use the App - couldn't figure out how to reload the page, which is the only thing fixing it
Jason Luboff
@JLuboff
May 09 2018 17:23 UTC
Normally you don't have to..but I can just click another room and back and its fine
@1Mher1 What do you mean?
Nazar
@IsaakNazar
May 09 2018 17:25 UTC
@cmccormack ok, I'll give it a shot
1Mher1
@1Mher1
May 09 2018 17:34 UTC

@JLuboff exactly I want to create same code in dynamically in jQuery var d = new Date();

var month = d.getMonth()+1;
var day = d.getDate();

var output = d.getFullYear() + '/' +
(month<10 ? '0' : '') + month + '/' +
(day<10 ? '0' : '') + day;
console.log(d)
console.log(day)

Gulsvi
@gulsvi
May 09 2018 17:44 UTC
@1Mher1 if you console.log the output it will show you the date you have created
You could also do it without the string construction:
var options = {
  year: "numeric",
  month: "2-digit",
  day: "2-digit"
};
var date = new Date().toLocaleDateString("en-gb", options);
console.log(date);
1Mher1
@1Mher1
May 09 2018 17:45 UTC
@gulsvi dynamiccaly I want this same code I want to create dynamically
Gulsvi
@gulsvi
May 09 2018 17:46 UTC
new Date() does dynamically get you the current date, I'm not sure I understand
1Mher1
@1Mher1
May 09 2018 17:46 UTC
I want to replace this code
var orer=this.stanal_orer()
var index =0
for(i=0;i<orer.length/7;i++){
var tr =$("<tr />")
for(j=0;j<7;j++){
var cls= j==5 || j==6 ? "weekend":""
var td =$("<td />")
if(orer[index]){
td.html(orer[index].amsativ)
index++
}
td.addClass(cls)
tr.append(td)
}
table.append(tr)
}
$(this.container).append(table)
Christopher McCormack
@cmccormack
May 09 2018 17:48 UTC
@IsaakNazar why would you want your nav to disappear when you close the hamburger?
Kudzu
@czhower
May 09 2018 17:51 UTC
use gitter to format your code please... three ` and the word code
1Mher1
@1Mher1
May 09 2018 17:58 UTC
var orer=this.stanal_orer()
var index =0
for(i=0;i<orer.length/7;i++){
var tr =$("<tr />")for(j=0;j<7;j++){
var cls= j==5 || j==6 ? "weekend":""var td =$("<td />")
if(orer[index]){td.html(orer[index].amsativ)
index++}
td.addClass(cls)tr.append(td)
}table.append(tr)
}$(this.container).append(table)
``` (shift+enter for new line)
your code here
```
I'm sorry, but I need more information to help answer your question - I am not sure what you mean by dynamically replacing that code :(
1Mher1
@1Mher1
May 09 2018 18:00 UTC
@gulsvi I can show in codepan but I have two js file
if have other codepan I can create than send to you
1Mher1
@1Mher1
May 09 2018 18:05 UTC
function Calendar(a,b,c){

    this.tari =a
    this.amis =b-1
    this.container =c

    this.create=function(){

        var table=$("<table class='table table-dark text-center'/>")
        table.append(`
            <tr>

            <th>Erkushabti</th>
            <th>Ereqshabti</th>
            <th>Choreqshabti</th>
            <th>Hingshabti</th>
            <th>Urbat</th>
            <th>Shabat</th>
             <th>kiraki</th>



            </tr>
            `)
        var orer=this.stanal_orer()
        var index =0
        for(i=0;i<orer.length/7;i++){
            var tr =$("<tr />")
            for(j=0;j<7;j++){
                var cls= j==5 || j==6 ? "weekend":""
                var td =$("<td />")
                if(orer[index]){
                td.html(orer[index].amsativ)
                index++
                }
                td.addClass(cls)    
                tr.append(td)
            }
            table.append(tr)
        }
        $(this.container).append(table)

    }
    this.stanal_orer=function(){
        var arr =[]
        var tmp=new Date(this.tari,this.amis,1)
        while(this.amis==tmp.getMonth()){

            var obj ={
                or:tmp.getDay(),
                amsativ:tmp.getDate()
            }
            arr.push(obj)
            tmp.setDate(tmp.getDate()+1)
        }

        return arr
    }


}
this is my calendar.js code
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .weekend{
            color:red;
        }
        .kanach{color:green;}
    </style>
    <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<!-- Popper JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
</head>
<body>
    <div id="a1"></div>
</body>
<script src="js/calendar.js"></script>
<script src="js/script.js"></script>
</html>
this is my index.html code
var c =new Calendar(2018,05,"#a1")
var x = new Date(2018,05,01)

// console.log(x)
c.create()
console.log(c.stanal_orer())
this is my script.js code
I want to create real actual data & time
please check and help me
1Mher1
@1Mher1
May 09 2018 18:30 UTC
???????????????????????????????????
Ronique Ricketts
@RoniqueRicketts
May 09 2018 19:43 UTC
Wazzup bruvs and sisters!
Christopher McCormack
@cmccormack
May 09 2018 19:44 UTC
@RoniqueRicketts how goes it
Ronique Ricketts
@RoniqueRicketts
May 09 2018 19:45 UTC
If I have 2 folders one with express backend and another with React CLI for fronend and we connect via proxy, what tool/tools could I use redirect my CLI from my express backend?
@cmccormack It going.. but its going without me
Christopher McCormack
@cmccormack
May 09 2018 19:49 UTC
what is React CLI?
Ronique Ricketts
@RoniqueRicketts
May 09 2018 19:49 UTC
I meant CRA
Create React App
Christopher McCormack
@cmccormack
May 09 2018 19:52 UTC
Are you loading your React app from your express backend when a user hits an endpoint?
or is the react app loaded completely separately?
Ronique Ricketts
@RoniqueRicketts
May 09 2018 19:52 UTC
@cmccormack they are in separate folders and are connected through a proxy.
Christopher McCormack
@cmccormack
May 09 2018 19:53 UTC
@RoniqueRicketts what do you mean by that exactly
Ronique Ricketts
@RoniqueRicketts
May 09 2018 19:55 UTC
https://github.com/RoniqueRicketts/my-school-app this is how my folders are structured.
Christopher McCormack
@cmccormack
May 09 2018 19:56 UTC
yeah I've seen it but I still don't know what you mean they are connected through a proxy
a React app shouldn't be connected to an express server, you're basically going to use the server from the React app using an ajax call of some sort
However, if you want the express server to serve the React App, you have to have an endpoint on the express server that does so, and you can do the rest of our front end routing using something like React Router
Ronique Ricketts
@RoniqueRicketts
May 09 2018 19:58 UTC
@cmccormack so in my package.json file I use the proxy key and set the value to a local host with the port number for my backend. but Idk how to get a redirect from the backend and make it redirecto n the frontend.
Christopher McCormack
@cmccormack
May 09 2018 20:00 UTC
What example are you going off for your setup?
Ronique Ricketts
@RoniqueRicketts
May 09 2018 20:05 UTC
I was under the understanding that I could setup my react app for frontend and then set up express backend and connect through a proxy and I could redirect base on backend response
@cmccormack none :(
Christopher McCormack
@cmccormack
May 09 2018 20:06 UTC
@RoniqueRicketts :point_up: May 9, 2018 12:56 PM read this again when you have time - basically treat your backend as a completely separate API, like the weather api or whatever. The only link you may need is to actually serve your index.html file from your express server
Tiago Correia
@tiagocorreiaalmeida
May 09 2018 21:21 UTC
anyone used google-auth on passport lately?
Jason Luboff
@JLuboff
May 09 2018 21:24 UTC
Nope
Ryan Williams
@Ryanwfile
May 09 2018 21:34 UTC
@NJM8 That's exactly what I was looking for, thank you so much
Keegan
@Keggatron
May 09 2018 22:53 UTC
hi guys, I'm working on the front end of an app and I'm unable to install anything using NPM
here's the error:
npm ERR! code EINVALIDPACKAGENAME npm ERR! Invalid package name "node_modules": node_modules is a blacklisted name
I've tried removing my node_modules folder then reinstalling but that doesn't work
Brad
@bradtaniguchi
May 09 2018 23:12 UTC
Why does it sound like you have "dependencies":{ "node_modules": x.x.x}in your package.json
@Keggatron