These are chat archives for FreeCodeCamp/HelpJavaScript

4th
May 2018
Nate Mallison
@NJM8
May 04 2018 00:19
@revisualize good, then you know your stuff. haha
help
I don't understand this subject
Mike Haslam
@Ongomobile
May 04 2018 01:47
@wangzhen1994 here is a better link you copied the whole query https://freecodecamp.cn/challenges/word-blanks#
Mike Haslam
@Ongomobile
May 04 2018 02:02
@wangzhen1994 they are asking you to do string concatenation so what that means is you build a string and insert the parameters (myNoun, myAdjective, myVerb, myAdverb) from the function into your string the are saying use the + operator look at example sentence then insert the parameters into your string Sorry I do not speak Chinese
Mike Haslam
@Ongomobile
May 04 2018 02:10

Hi I am trying to wrap my head around passing state down from parent component to a stateless component note the cemented out code is how I did it (with help) in a single component

here is codepen https://codepen.io/Ongomobile/pen/bMReJg?editors=0111#0

Claudio Restifo
@Marmiz
May 04 2018 02:14
@Ongomobile you just have to pass all the methods to the stateless component. So far you are only passing the state :)
Mike Haslam
@Ongomobile
May 04 2018 02:16
@Marmiz Thanks so do I pass the methods when I instantiate to component not sure
CamperBot
@camperbot
May 04 2018 02:16
ongomobile sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1215 | @marmiz |http://www.freecodecamp.org/marmiz
Mike Haslam
@Ongomobile
May 04 2018 02:16
the component I meant
would it be <Counter onClick={this.increment, this.decrement}
皮卡丘
@Liang-L
May 04 2018 02:26
if you want to print the words,(I am a "double quoted" string inside "double quotes"),how do it with you by the javascript
Claudio Restifo
@Marmiz
May 04 2018 02:26

@Ongomobile simply pass them as props:


<Child
   onSomething={this.doSomething}
   onSomethingElse={this.doSomethingElse}
   aValue={this.aValue}
/>


const child = ({doSomething}) => ( <button onClick={() => doSomething()} />)

(I used sightly different syntax, but the principle is the same)

@Liang-L you escape them with \
皮卡丘
@Liang-L
May 04 2018 02:28
image.png
this is my problem
Claudio Restifo
@Marmiz
May 04 2018 02:29
@Liang-L check how you wrote quoted
Mike Haslam
@Ongomobile
May 04 2018 02:29
@Marmiz Thanks I will give it a try
CamperBot
@camperbot
May 04 2018 02:29
ongomobile sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
api offline
Claudio Restifo
@Marmiz
May 04 2018 02:29
unfortunately the test looks for the exact string, so also grammar error can lead to errors @Liang-L
皮卡丘
@Liang-L
May 04 2018 02:29
ok
I am too careless, thank you @Marmiz
CamperBot
@camperbot
May 04 2018 02:31
liang-l sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1216 | @marmiz |http://www.freecodecamp.org/marmiz
Mike Haslam
@Ongomobile
May 04 2018 02:39
@Marmiz I have 2 buttons with onClick events but they use a different methods do I need change those what do you think is the syntax onClick={this.increment}
abraham anak agung
@padunk
May 04 2018 02:54
@Ongomobile you can pass it with different name, onIncrement = {this.increment} onDecrement = {this.decrement}
In your child component you can access it like onClick = {props.onIncrement}
Mike Haslam
@Ongomobile
May 04 2018 02:58
@padunk Thanks so syntax would be <Counter onIncrement={this.increment} /> and in component it would be <button onIncrement={props.increment} </button>
CamperBot
@camperbot
May 04 2018 02:58
ongomobile sends brownie points to @padunk :sparkles: :thumbsup: :sparkles:
:cookie: 486 | @padunk |http://www.freecodecamp.org/padunk
Mike Haslam
@Ongomobile
May 04 2018 03:05
@padunk @Marmiz Thanks for help I got it ! Now my next challenge its to make more than 1 counter work independently !
CamperBot
@camperbot
May 04 2018 03:05
ongomobile sends brownie points to @padunk and @marmiz :sparkles: :thumbsup: :sparkles:
api offline
api offline
abraham anak agung
@padunk
May 04 2018 03:09
@Ongomobile you pass onIncrement as a props to child component. So you access it like i write before. Button must have onClick event. <button onClick ={props.onIncrement}
aRtoo
@artoodeeto
May 04 2018 03:22
hey fam need help. i need is to replace dash (-) to a letter. lets say. they have to guess a meow word. so the visual HTML will have four dashes. - - - - and if the user input o the dashed will transform to - - o -.
Claudio Restifo
@Marmiz
May 04 2018 04:20
@artoodeeto what happens if the word is abba and the user input a ?
You want to insert all the as or only one?
aRtoo
@artoodeeto
May 04 2018 04:20
@Marmiz yea bro.
@Marmiz so if they input a itll be a - - a
@Marmiz can i pm you and send you my code?
Claudio Restifo
@Marmiz
May 04 2018 04:22
@artoodeeto you can simply loop into the word, get the index of the matching letters and update the dashes, that hopefully will have the same indexes
aRtoo
@artoodeeto
May 04 2018 04:23
@Marmiz thank you bro
CamperBot
@camperbot
May 04 2018 04:23
artoodeeto sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1217 | @marmiz |http://www.freecodecamp.org/marmiz
Claudio Restifo
@Marmiz
May 04 2018 04:32
@artoodeeto
const getIndexes = (word, letter) => 
  word.split('').reduce((acc, curr, i) => curr === letter ? acc.push(i) && acc : acc,[]);
easy and nice to read :)
:coffee: break over. Gl with your function
Mike Haslam
@Ongomobile
May 04 2018 05:42
@Marmiz I learned something else too you can use public class fields and arrow functions to avoid the binding of this and the constructor thanks to babel transpling Thanks for the namjai my friend
CamperBot
@camperbot
May 04 2018 05:42
ongomobile sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1218 | @marmiz |http://www.freecodecamp.org/marmiz
NikolaNbgd
@NikolaNbgd
May 04 2018 14:39
Hi Folks, does anyone have experience with pug iteration?
Manuel Grondona
@manuel-grondona
May 04 2018 14:43

hey, don't know if someone can help me, I'm figuring out an excercise and I'm stuck (again) at this point. They ask me to pass these tests:

    calculator.sum(2);
    calculator.sum(3);
    expect(calculator.value()).toEqual(5);

Also they declare the following statements at the beginning of each test:

var calculator;
calculator = createCalculator;

what i've got so far are the following statements:

var calcObj = function() {
  this.value = function() {

    return 0;

  }

};

function createCalculator() {
  return new calcObj();
}

the return 0 has to be there somehow because the calculator should reset to 0 for every test.
I'm sorry if I'm not clear enough, please let me know and I'll try to provide further details.
Thanks in advance!

*where it says "also they declare the following statements at the beginning of each test" should say "at the beginning of each GROUP of tests (like the one I provide). Those 3 statements are considered ONE group of tests.
Ryan Williams
@Ryanwfile
May 04 2018 14:45
@ndburrus Thank you
CamperBot
@camperbot
May 04 2018 14:45
ryanwfile sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:star2: 2212 | @ndburrus |http://www.freecodecamp.org/ndburrus
Ken Haduch
@khaduch
May 04 2018 14:59
@manuel-grondona - try moving the declaration of var calculator inside the function body. Sometimes a global variable causes problems in the test environment.
Manuel Grondona
@manuel-grondona
May 04 2018 15:01
@khaduch Thank you Ken! However, as per what I understand from the excercise, I should not touch that code.
CamperBot
@camperbot
May 04 2018 15:01
:star2: 3903 | @khaduch |http://www.freecodecamp.org/khaduch
manuel-grondona sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
Ken Haduch
@khaduch
May 04 2018 15:03
Maybe just add a calculator = 0 at the start of your function code, then?
Manuel Grondona
@manuel-grondona
May 04 2018 15:05
For now the calculator = 0 part does not represent a problem. I have the problem testing the calculator.sum(2)statements, can't figure out exactly how to create a method in the object that takes these numbers, and then build the method in the value property to sum those separate numbers.
Aditya
@ezioda004
May 04 2018 15:05
@manuel-grondona From what I can tell, they expect the instance (calculator) to have a method called sum which adds the passed argument to some already defined property and then finally calculator.value() should return that property(key)'s value.
Manuel Grondona
@manuel-grondona
May 04 2018 15:06
@ezioda004 I believe you got it right Aditya (hello again by the way :+1: )
Ken Haduch
@khaduch
May 04 2018 15:07
@manuel-grondona - is this a freecodecamp exercise? Is there a link? (I was on my phone before so I couldn't see everything too clearly...)
Aditya
@ezioda004
May 04 2018 15:08

So you need to do something like this

var calcObj = function() {
  //define a new property here
  this.value = function() {
    //return the value of above defined property here
  }
//create a new method, sum here which adds the value passed to the property created at top.
};

Also, hello :)

Ken Haduch
@khaduch
May 04 2018 15:12
@NikolaNbgd - hello - I have used pug a little bit, just started to play with it. What are you trying to do?
Manuel Grondona
@manuel-grondona
May 04 2018 15:15
@ezioda004 Thanks! Gonna try it that way!
CamperBot
@camperbot
May 04 2018 15:15
manuel-grondona sends brownie points to @ezioda004 :sparkles: :thumbsup: :sparkles:
:cookie: 548 | @ezioda004 |http://www.freecodecamp.org/ezioda004
Manuel Grondona
@manuel-grondona
May 04 2018 15:16
@khaduch No Ken! it's a personal thing, from another course I'm taking.
NikolaNbgd
@NikolaNbgd
May 04 2018 15:17
@khaduch I need to iterate through array in json object and display one value from it. do you know how?
Ken Haduch
@khaduch
May 04 2018 15:18
@manuel-grondona - oh, well that's great! Good to expand your knowledge in other lessons. Looks like @ezioda004 is coming up with some good information.
Norvin Burrus
@ndburrus
May 04 2018 15:19
@Ryanwfile you're welcome! enjoy :peach:
Ken Haduch
@khaduch
May 04 2018 15:19
@NikolaNbgd - are you working in a CodePen?
Pug is for HTML generation, though, at least I thought that. How are you using it with a JSON object? (Or maybe I'm confused. let me see what I was using in my sandbox codepen...)
Aditya
@ezioda004
May 04 2018 15:20
@khaduch Credits to FCC and you. I've had a lot of help/feedback from you especially, thanks for that!
CamperBot
@camperbot
May 04 2018 15:20
ezioda004 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3905 | @khaduch |http://www.freecodecamp.org/khaduch
Manuel Grondona
@manuel-grondona
May 04 2018 15:20
@khaduch :+1:
Ken Haduch
@khaduch
May 04 2018 15:23
@NikolaNbgd - yes, I'm using PUG in my HTML generation for the (initial trial) of my calculator keyboard setup. I'd be interested to see what you are doing / how you are trying to do what you're doing to see if I could help in some way?
@ezioda004 - you're welcome, good to help out, and thanks for the comment!'
CamperBot
@camperbot
May 04 2018 15:24
khaduch sends brownie points to @ezioda004 :sparkles: :thumbsup: :sparkles:
:cookie: 549 | @ezioda004 |http://www.freecodecamp.org/ezioda004
Ken Haduch
@khaduch
May 04 2018 15:25
and @manuel-grondona - this looks a lot (to me) like the "Arguments Optional" exercise in the freecodecamp lessons.
Manuel Grondona
@manuel-grondona
May 04 2018 15:27
@khaduch haven't reached that excercise yet, I started with JavaScript and got a little confused, so I started reading some books, taking other online classes in Udemy, and finally, signed up for a BootCamp here in Argentina which I'm starting on Monday, however, they sent me a BootCamp prep to complete and that's where these excercises come from.
Ken Haduch
@khaduch
May 04 2018 15:29
@manuel-grondona - ah - is there a way that you could post the entire exercise? (Although I have to step away from the keyboard for a while... got to play with the grandkids...)
Manuel Grondona
@manuel-grondona
May 04 2018 15:31
@khaduch of course, though it's explained in spanish :/
I can send it to your e-mail if you want, don't want to spam the chat room, it's kinda long
@khaduch (whish my father in law would play a little more with my son, he's a handfull haha)
NikolaNbgd
@NikolaNbgd
May 04 2018 15:33
@khaduch I have an object, a big one and in that object I have an array, 'case', in that array, I have a few cases, I want to display that cases in td tag
ehutchllew
@ehutchllew
May 04 2018 15:38
@NikolaNbgd use an array map over the cases array
in the callback generaate <td> tags with whatever information you need and append that to the dom, or render it with whatever framework you're using.
NikolaNbgd
@NikolaNbgd
May 04 2018 15:41

I wrote this

                            each case in portfolio
                                td #{case.original_currency}

but it gives me this error

104|                             td #{portfolio.last_name}
   105|                             each case in portfolio
 > 106|                                 td #{case.original_currency}
----------------------------------------------^
   107|     include ../components/steps.pug
   108|    
Syntax Error: Unexpected token
@ehutchllew my bad, I wrote this
                            each case in portfolio.case
                                td #{case.original_currency}
ehutchllew
@ehutchllew
May 04 2018 15:44
@NikolaNbgd What syntax are you using? I'm not familiar with #{}
NikolaNbgd
@NikolaNbgd
May 04 2018 15:45
@ehutchllew that is regular pug syntax
ehutchllew
@ehutchllew
May 04 2018 15:45
oh okay, yeah i would generaly do this via javascript, not html/pug
not saying doing it your way is wrong, i just don't know how to do it.
so portfolio is an array of objects?
NikolaNbgd
@NikolaNbgd
May 04 2018 15:46
@ehutchllew yeah, but all backend is in node/express, and I have to do that on this way :(
portfolio is object
of arrays or just single names and values
and if I want to e.g. display name of my user
I write
td #{portfolio.first_name}
but when I have to fill my table with case fields and case in an array
ehutchllew
@ehutchllew
May 04 2018 15:48
okay so the error is saying the . in case is unexpected?
NikolaNbgd
@NikolaNbgd
May 04 2018 15:49
without '.'
just Syntax Error: Unexpected token
ehutchllew
@ehutchllew
May 04 2018 15:49
is there any way you can share what the portfolio object looks like?
NikolaNbgd
@NikolaNbgd
May 04 2018 15:52
hmmm
I certainly can share my screen with you
or
to find some why to share the object
ehutchllew
@ehutchllew
May 04 2018 15:58
post a screenshot
if you can't copy pasta
Norvin Burrus
@ndburrus
May 04 2018 16:11
@NJM8 ...does "exercise code" mean "Questions & Answers"?
if so, this may be helpful: :strawberry:
Mark
@vinarius
May 04 2018 19:04
Anyone interested in helping with a closure bug? I am working through the voting app project.
Ken Haduch
@khaduch
May 04 2018 19:09
@vinarius - want to post a link or some code and we can give it a shot?
Mark
@vinarius
May 04 2018 19:10
Absolutely. Any help is appreciated. vinarius/Free-Code-Camp#1
NikolaNbgd
@NikolaNbgd
May 04 2018 19:15

@ndburrus @ehutchllew this object is something like this

[
 "content": "dummy data",
  "content 2":  [
    "dummy": "dummy1",
  "dummy3": "dummy4",
]
 "case" : [
  {
"case_id" : "string", 
"product" : "string", 
"account_number" : "string", 
"disbursement_date" : "date", 
"maturity_date" : "date", 
"original_currency" : "GBP", 
"overdue" : {
"ammount" : "double", 
}, 
"deliquency" : {
"days" : "int32", 
"bucket" : "int32"
}, 
"outstanding_balance" : "double",
  {
  "activity_type" : "promise_to_pay", 
  "promised_amount" : "double", 
  "promise_date" : "date", 
  "next_contact_date" : "date", 
  "channel" : "chat", 
  "idv_pass" : "bool",
  "idv_pass_date" : "date",
  "kpis" : "string", 
  "created_at" : "date", 
  "updated_at" : "date"
  }
}
]
]

my goal is case object, btw object is really dummy, I just create a structure