These are chat archives for FreeCodeCamp/HelpJavaScript

8th
Jan 2018
Nerando Johnson
@Nerajno
Jan 08 2018 00:40
@Gersho was learning promises ... looked like a good idea at the time
Unwana Essien
@afixoftrix
Jan 08 2018 10:36
Is this the place to ask for js help?
Blauelf
@Blauelf
Jan 08 2018 10:37
This is HelpJavaScript, so probably yes.
Specifying your problem (and providing the necessary context) might be the next step.
Unwana Essien
@afixoftrix
Jan 08 2018 10:39

@Blauelf Just making sure. Thank you for pointing that out.

var test = (el, val) => {
return val.push(el);
}
undefined
test( 3, [2, 1, 2]);
4

I am just wondering why 3 doesn't get pushed to the passed array. Instead I get the length of the array. This is on Chrome Console.

CamperBot
@camperbot
Jan 08 2018 10:39
afixoftrix sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4671 | @blauelf |http://www.freecodecamp.org/blauelf
Blauelf
@Blauelf
Jan 08 2018 10:41
@afixoftrix The return value of push is the new array length. So it does get pushed:
var arr = [2, 1, 2];
console.log(test(3, arr)); // 4
console.log(arr); // [2, 1, 2, 3]
Michael Grienauer
@mgrienauer
Jan 08 2018 13:14
im doing the symmetric difference challenge and am not really understanding why this code isnt working

function sym(args) {

  //create array from arguments
  args = Array.from(args);
  // create function to remove duplicate items found in both arrays
  var findSymDiff = function(arr1,arr2){
    var newArr = [];

    // check arr1 against newarr and arr2
    arr1.forEach(function(item){
      if (newArr.indexOf(item) < 0 && arr2.indexOf(item) < 0){
        newArr.push(item);
      }
    });

    // check arr2 against newarr and arr1
    arr2.forEach(function(item){
      if (newArr.indexOf(item) < 0 && arr1.indexOf(item) < 0){
        newArr.push(item);
      }
    });

    // return newArr
    return newArr;

  };
  // use reduce on args using findSymDiff function
  return args.reduce(findSymDiff);
}

sym([1, 2, 3], [5, 2, 1, 4]);
it's saying that I can't use forEach on arr1 and arr2, but should it be passed the args array of arrays?
Markus Kiili
@Masd925
Jan 08 2018 13:17
@mgrienauer sym has only one parameter args that catches only one passed argument. The arguments object has all the passed arguments.
Michael Grienauer
@mgrienauer
Jan 08 2018 13:18
shiiit lol i must have accidentally changed that
its working now, thanks @Masd925
CamperBot
@camperbot
Jan 08 2018 13:19
mgrienauer sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4639 | @masd925 |http://www.freecodecamp.org/masd925
Markus Kiili
@Masd925
Jan 08 2018 13:19
@mgrienauer :+1:
Christopher
@bradley1492
Jan 08 2018 13:38

Good afternoon,
I am trying to figure out this example at stack overflow. It's about checking value occurences in arrays. The other day @forkerino helped me out already, but still I had to give this a try:

var arr = [5, 5, 5, 2, 2, 2, 2, 2, 9, 4];
var counts = {};

for (var i = 0; i < arr.length; i++) {
  var num = arr[i];
  counts[num] = counts[num] ? counts[num] + 1 : 1;
}

console.log(counts[5], counts[2], counts[9], counts[4]);

I understand the execution context until the ternary operator.
What does counts[num] = counts[num] ? counts[num] + 1 : 1;explain?

Markus Kiili
@Masd925
Jan 08 2018 13:40
@bradley1492 That ? : is an conditional (ternary) operator.
Stephen James
@sjames1958gm
Jan 08 2018 13:40
@bradley1492 it is basically saying if there is value in counts[num] then add 1 to current value, else set the value to 1
Markus Kiili
@Masd925
Jan 08 2018 13:41
@sjames1958gm Only 500 more followers and you have got it :imp:
Christopher
@bradley1492
Jan 08 2018 13:41
@sjames1958gm okay, but isn't there always a value in counts[num] as I understand counts[num] is all the values from the arrays looped through
Stephen James
@sjames1958gm
Jan 08 2018 13:42
@bradley1492 Replace
counts[num] = counts[num] ? counts[num] + 1 : 1;
with
var x; // x is a temporary value
if (counts[num])  // not falsy (in this case not defined)
   x = counts[num] + 1;
else 
   x = 1
counts[num] = x;
Nazar
@IsaakNazar
Jan 08 2018 13:42
Hello guys
there's a problem with Twitch api.
when I click offline button there should be offline channels, and when click all button there should be
all channels, how to solve this problem
https://codepen.io/NazarIsaak/pen/WdXZad
Stephen James
@sjames1958gm
Jan 08 2018 13:42
@bradley1492 No counts is an empty object so it has no properties
@Masd925 Bwa ha ha
Christopher
@bradley1492
Jan 08 2018 13:45
@sjames1958gm Many thanks for the explanation. I think it doesn't get better explained than that.
I still struggle a bit, but I think I can manage to fully understand with a bit of playing around. :)
CamperBot
@camperbot
Jan 08 2018 13:45
bradley1492 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8828 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
Stephen James
@sjames1958gm
Jan 08 2018 13:48
@IsaakNazar Looks like to me that ("#container").prepend(htm).addClass("liveCh") is putting the liveCh class on the container and not the new html
@IsaakNazar Also you are missing # in the "else" of that ternary
Nazar
@IsaakNazar
Jan 08 2018 13:52
@sjames1958gm aah ok.
Stephen James
@sjames1958gm
Jan 08 2018 14:13
@IsaakNazar Just so you know, I used the element inspector from the developer tools to see what elements were created and where the classes were assigned
Nazar
@IsaakNazar
Jan 08 2018 14:15
@sjames1958gm and addClass is a wrong decision?
cant figure it out
ok I'll play around and get back :(
Stephen James
@sjames1958gm
Jan 08 2018 14:17
@IsaakNazar I am thinking that ("#container").prepend(htm) this returns the container element not the added html.
Use the offline/online logic to add the class to the htm string?
Nazar
@IsaakNazar
Jan 08 2018 14:21
@sjames1958gm ok, I'll think about it, thx Stephen
CamperBot
@camperbot
Jan 08 2018 14:21
isaaknazar sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8829 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
Stephen James
@sjames1958gm
Jan 08 2018 14:21
@IsaakNazar :+1: good luck!
Aditya
@ezioda004
Jan 08 2018 14:22
@sjames1958gm But shouldnt $("#container").prepend(htm).addClass("liveCh") work this way since the selector is $("#container")
Stephen James
@sjames1958gm
Jan 08 2018 14:22
@ezioda004 Yes, but I believe the goal was to have the class on the htm element and not the container.
Aditya
@ezioda004
Jan 08 2018 14:27
I may not have understood this properly but why not just add the class in this statement? var htm = '<div class="row"><div class="col-sm-2"><img src="' + data.logo + '"></div><div class="col-sm-4">'+data.display_name+'</div></div>';?
Nazar
@IsaakNazar
Jan 08 2018 14:39

when I cchange this code to

$(".liveCh").show();
    $(".offCh").hide();

this(change places)

    $(".offCh").hide();
$(".liveCh").show();

the result is different. in first case the online button hides everyting, on second case channels are not hiding

maybe problem is here?
$(document).ready(function() {
  loadTwitch();
  $("#on_btn").click(function(){
    $(".liveCh").show();
    $(".offCh").hide();
  });
  $("#off_btn").click(function(){
    $(".liveCh").hide();
    $(".offCh").show();
  });
  $("#all_btn").click(function(){
    $(".liveCh").show();
    $(".offCh").show();
  });
});
Stephen James
@sjames1958gm
Jan 08 2018 14:46
@ezioda004 Yes, that was also my suggestion
Aditya
@ezioda004
Jan 08 2018 14:46
@IsaakNazar This works
var htm = '<div class="row"><div class="col-sm-2"><img src="' + data.logo + '"></div><div class="col-sm-4">'+data.display_name+'</div></div>';
        $("#container").prepend(htm);
        status == 'online' ? 
          $("#container div").first().addClass("liveCh") : $("#container div").first().addClass("offCh");
      });
Nazar
@IsaakNazar
Jan 08 2018 14:49
@ezioda004 first() is like append? am I wrong?
Stephen James
@sjames1958gm
Jan 08 2018 14:50
@IsaakNazar - or this which keeps your prepend/append logic
        var className = status == 'online' ? "liveCh" : "offCh"
        var htm = '<div class="row ' + className + '"><div class="col-sm-2"><img src="' + data.logo + '"></div><div class="col-sm-4">'+data.display_name+'</div></div>';
        status == 'online' ? $("#container").prepend(htm) : $("#container").append(htm);
Aditya
@ezioda004
Jan 08 2018 14:55
@IsaakNazar No, first() only selects the first div, if you remove it the $("#container div") can select the previously prepended div too since it matches it.
Nazar
@IsaakNazar
Jan 08 2018 14:56
@ezioda004 @sjames1958gm holly cow :) I need a bit to understand this
ooh sh*t guys, what a wizard are you, damn, deeep Thanx guys. G @ezioda004 @sjames1958gm what a genius you are :)
CamperBot
@camperbot
Jan 08 2018 14:58
isaaknazar sends brownie points to @ezioda004 and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:cookie: 355 | @ezioda004 |http://www.freecodecamp.org/ezioda004
api offline
Stephen James
@sjames1958gm
Jan 08 2018 14:58
@IsaakNazar you're welcome
Aditya
@ezioda004
Jan 08 2018 15:00
@IsaakNazar :thumbsup: as @sjames1958gm said before you should checkout inspect element about how the classes are being added, that'll help you understand the code.
Nazar
@IsaakNazar
Jan 08 2018 15:03
@ezioda004 thank you so much, yeah you're right I get lost on my own code, thats very disappoints me
CamperBot
@camperbot
Jan 08 2018 15:03
isaaknazar sends brownie points to @ezioda004 :sparkles: :thumbsup: :sparkles:
api offline
texirv0203
@texirv0203
Jan 08 2018 16:12
hi,
  • I am new to angular2.
  • I am getting the below error, can you tell me how to fix it
    app/app.routing.ts(5,1): error TS1206: Decorators are not valid here.
  • providing my code below
import { ModuleWithProviders, NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { Router, Event, NavigationStart, NavigationEnd } from '@angular/router';

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule],
  providers: []
})
Kaz Baig
@kbaig
Jan 08 2018 16:13
@texirv0203 https://stackoverflow.com/questions/38357384/ts1206-decorators-are-not-valid-here-angular-2 decorators must be followed by the class that you're decorating
texirv0203
@texirv0203
Jan 08 2018 16:16
@kbaig can you tell me why we should do like that...so that in future it will be helpful for me :)
Kaz Baig
@kbaig
Jan 08 2018 16:17
@texirv0203 Decorators are meant for modifying objects, so you need an object to decorate otherwise it's not doing anything
I'm not an Angular person so I wouldn't know what class you need to add here but hopefully you can figure that part out
texirv0203
@texirv0203
Jan 08 2018 16:20
@kbaig hey in my code can you tell me which is object to decorate---> you need an object to decorate
Kaz Baig
@kbaig
Jan 08 2018 16:21
@texirv0203 As I said above, I'm not an Angular person so I wouldn't know
@texirv0203 https://v2.angular.io/docs/ts/latest/guide/ngmodule.html looks like you can just export an empty class, though idk if that's the right approach for your case
dinesh
@1532j0004kg
Jan 08 2018 16:33
hi
hi
Jason Luboff
@JLuboff
Jan 08 2018 16:36
Hello
dinesh
@1532j0004kg
Jan 08 2018 16:36
have u worked on firebase
?
Jason Luboff
@JLuboff
Jan 08 2018 16:36
No I haven't
dinesh
@1532j0004kg
Jan 08 2018 16:37
then what u use for db
Jason Luboff
@JLuboff
Jan 08 2018 16:37
MongoDB mainly.
dinesh
@1532j0004kg
Jan 08 2018 16:38
for backends,its enough to know basics of express(routing) and mongodb?
Jason Luboff
@JLuboff
Jan 08 2018 16:39
For the backend projects or backend in general? I'd say for the projects, yes. For backend in general, I'd say you'd want to know more than just the basics
dinesh
@1532j0004kg
Jan 08 2018 16:40
ok then for authentication?
Jason Luboff
@JLuboff
Jan 08 2018 16:41
I've used passport.js which allows you to choose a variety of strategies
dinesh
@1532j0004kg
Jan 08 2018 16:41
ok
would u create the personal login page?
Jason Luboff
@JLuboff
Jan 08 2018 16:42
You can. Or you can use OAuth with Github, Facebook, Twitter, etc
dinesh
@1532j0004kg
Jan 08 2018 16:42
where u learned the backend
?
This message was deleted
Jason Luboff
@JLuboff
Jan 08 2018 16:43
I purchased a course through uDemy on Nodejs/express and also took a free course offered by Mongo University to learn more about Mongodb
dinesh
@1532j0004kg
Jan 08 2018 16:44
ohh okay!
Jason Luboff
@JLuboff
Jan 08 2018 16:44
FCC beta also has some material, but I have not gone through it
dinesh
@1532j0004kg
Jan 08 2018 16:46
oh ok
Kelechi Chinaka
@ke1echi
Jan 08 2018 17:23
who knows when beta would go live @JLuboff
Isaiah Trembley
@IsaiahCT
Jan 08 2018 17:23
when is that happening
Kelechi Chinaka
@ke1echi
Jan 08 2018 17:23
dunno
Isaiah Trembley
@IsaiahCT
Jan 08 2018 17:23
ah, I am stoked for that
Kelechi Chinaka
@ke1echi
Jan 08 2018 17:23
thought they said christmas 2017
Isaiah Trembley
@IsaiahCT
Jan 08 2018 17:24
a bit late, but
Jason Luboff
@JLuboff
Jan 08 2018 17:27
@kelechy Last I had read, it was supposed to be as you said Christmas. Not sure at this point..
Kelechi Chinaka
@ke1echi
Jan 08 2018 17:27
maybe they meant christmas 2018? @JLuboff
Jason Luboff
@JLuboff
Jan 08 2018 17:28
If they do...than thats disappointing. Beta has been around for at least a year now I think.
Gersho
@Gersho
Jan 08 2018 17:28
check your inbox, maybe you received coal instead of a release
Kelechi Chinaka
@ke1echi
Jan 08 2018 17:29
i hope it comes outta beta soonest
hows your lil champ? @JLuboff
Jason Luboff
@JLuboff
Jan 08 2018 17:35
@kelechy He is doing good, growing! Thanks for asking
CamperBot
@camperbot
Jan 08 2018 17:35
jluboff sends brownie points to @kelechy :sparkles: :thumbsup: :sparkles:
:cookie: 323 | @kelechy |http://www.freecodecamp.org/kelechy
ehutchllew
@ehutchllew
Jan 08 2018 18:40
Does anyone here have experience with React Native?
texirv0203
@texirv0203
Jan 08 2018 18:58

hi,

  • I am trying to include the appdyanmics in my app.
  • so I used the below example
    https://github.com/derrekyoung/appd-sampleapp-angular2
  • when I include this line. I am getting the below error.
    Unhandled Promise rejection: error.json is not a function ; Zone: <root> ; Task: Promise.then ; Value: TypeError: error.json is not a function

  • can you tell me how to fix it.

  • providing my code below

import './rxjs-extensions';

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule,ReactiveFormsModule }   from '@angular/forms';
import { HttpModule }    from '@angular/http';
import { AppComponent }         from './app.component';

import {Base} from './components/base/base';
import {AdminUser} from './components/admin/user';
import {Admin} from './components/admin/admin';


import { routing }              from './app.routing';

import { AppRoutingModule }              from './app.routing';

import { sportsService }          from './services/sports.service';


import {
    Routes,
    RouterModule,
    Router,
    ActivatedRoute,

    CanActivateChild,
    CanDeactivate,
    ActivatedRouteSnapshot,
    RouterStateSnapshot
} from "@angular/router";
import { titleService } from './components/title/titleService';


@NgModule({
  imports: [
    BrowserModule,

    FormsModule,
    ReactiveFormsModule,
    HttpModule,
    routing,
    MultiselectDropdownModule,
    AccordionModule
  ],
  declarations: [
    AppRoutingModule,
    AppComponent,
    Base
  ],
  providers: [
  sportsService,],
  bootstrap: [ AppComponent ]
})
export class AppModule {
}
Brad
@bradtaniguchi
Jan 08 2018 22:03
@texirv0203 When you include what line?
And whats appdynamics?
Anthony Albertorio
@tesla809
Jan 08 2018 23:34
Hey al
hey all
question: I am working on FCC challenges
Trying to use ES6 to solve them. Is it possible to append some code to let the challenge accept it?
Brad
@bradtaniguchi
Jan 08 2018 23:39
@tesla809 I believe it does accept it by default, but the linter will show errors unless you put a special comment line in the code, let me see if I can find it exactly..
//jshint esversion: 6
Just put that on the first line of your code and the linter will accept es6