These are chat archives for FreeCodeCamp/HelpJavaScript

2nd
Jan 2018
Long Nguyen
@longnt80
Jan 02 2018 02:14
Happy new Year!
Henry
@GitHub-Henry
Jan 02 2018 02:52
@longnt80 happy new year
Long Nguyen
@longnt80
Jan 02 2018 02:56
@GitHub-Henry anything new?
Henry
@GitHub-Henry
Jan 02 2018 03:02
@longnt80 decided to read YDKJS on book 5 of 6. how about you?
Long Nguyen
@longnt80
Jan 02 2018 03:03
@GitHub-Henry
I'm considering a new job move :D
yeah, I need to finish that book too
Henry
@GitHub-Henry
Jan 02 2018 03:06
@longnt80 what kind of job move?
Long Nguyen
@longnt80
Jan 02 2018 03:08
I meant same job but different company
Henry
@GitHub-Henry
Jan 02 2018 03:08
what would be different?
besides the company
what's the upside of the different company?
Long Nguyen
@longnt80
Jan 02 2018 03:27
it is a bigger company with better salary
@GitHub-Henry
I kinda like the current small company though
Henry
@GitHub-Henry
Jan 02 2018 03:35
@longnt80 did you already get a job offer with the larger company?
Long Nguyen
@longnt80
Jan 02 2018 03:35
yeah they did
Henry
@GitHub-Henry
Jan 02 2018 03:36
@GitHub-Henry nice situation to be in, wish you the best in choosing.
Long Nguyen
@longnt80
Jan 02 2018 03:36
it's always hard when you have to choose :D
Henry
@GitHub-Henry
Jan 02 2018 03:39
it's a nice decision to have to make
Blauelf
@Blauelf
Jan 02 2018 07:19
@tiagocorreiaalmeida You can use the loop in Array.from, like return Array.from({length:+n},()=>v);
Blauelf
@Blauelf
Jan 02 2018 07:35
There are more obscure ES5 ways for that, too (Array.map won't consider empty elements, so new Array(+n).map(()=>v) won't work)
Blauelf
@Blauelf
Jan 02 2018 08:22
Oh, someone used Array(n).fill(v). Did not realize fill works on sparse arrays, unlike map.
Tiago Correia
@tiagocorreiaalmeida
Jan 02 2018 09:36
@Blauelf yeah I feel like my solution wasnt one of the best ones :D
but recursion was the first time that came into my head
Bryan Reese
@breese8009
Jan 02 2018 09:48
anyone know whats up with this https://beta.freecodecamp.org/en/challenges/react-and-redux/manage-state-locally-first not accepting event.target.value
???
is this an open issue?
Tiago Correia
@tiagocorreiaalmeida
Jan 02 2018 09:55
image.png
the code I have doesnt run at all
class DisplayMessages extends React.Component {
  constructor(props) {
    super(props);
    this.handleChange = this.handleChange.bind(this);
    this.submitMessage = this.submitMessage.bind(this);
    this.state = {
      input: '',
      messages: []
    }
  }
  handleChange(e){
    let input = e.target.value;
    this.setstate(()=>({input}))
  }

  submitMessage(){
    this.setState((prevState,props)=>({
      messages: prevState.messages.concat(this.state.input),
        input:""
    }))
  }

  render() {
    return (
      <div>
        <h2>Type in a new Message:</h2>
         <input type="text" onChange={this.handleChange}           value={this.state.input} 
           <button onClick={this.submitMessage}>Save</button>
           <ul>
           {this.state.messages.map((message)=>(
            <li>{message}</li>
          ))}
        </ul>
        { /* change code above this line */ }
      </div>
    );
  }
I think the soluttion would be something similiar to this but I can't run it at all keeps trhowing "try again later"
Blauelf
@Blauelf
Jan 02 2018 10:21
@tiagocorreiaalmeida Is there a closing > missing on the input element?
I have no experience with JSX, but HTML tags should have ends.
alpox
@alpox
Jan 02 2018 10:29
@tiagocorreiaalmeida I also vote for closing the input tag
Tiago Correia
@tiagocorreiaalmeida
Jan 02 2018 10:31
yah there is a missing one but the platform it self its having some issues for what I see it doesnt run any line of code :\
Sweet Coding :)
@SweetCodingInc
Jan 02 2018 10:36

@tiagocorreiaalmeida This line

<input type="text" onChange={this.handleChange}           value={this.state.input}

should be

<input type="text" onChange={this.handleChange}           value={this.state.input}/>
You don't need that value={this.state.input} part
Forked your pen
Tiago Correia
@tiagocorreiaalmeida
Jan 02 2018 10:39
yup, the value part would be only needed if the value would come allready defined, the big issue here was the platform not working at all
but thanks
Sweet Coding :)
@SweetCodingInc
Jan 02 2018 10:46
@tiagocorreiaalmeida could be issue with the platform itself
apart from unclosed input tag, your code was fine
Btw, this is how small it becomes with AngularJs
<div ng-app="todo">
  <div ng-controller="ToDoController as td">
    <div>
      <input type="text" ng-model="td.input"/>
      <button ng-disabled="!td.input.length" ng-click="td.add()">Add</button>
    </div>
    <div ng-if="td.messages.length">
      <ul>
        <li ng-repeat="m in td.messages track by m">{{m}}</li>
      </ul>
    </div>
  </div>
</div>
const app = angular.module('todo', []);

app.controller('ToDoController', function() {
  this.messages = [];
  this.input = '';

  this.add = () => {
    this.messages.push(this.input);
    this.input = '';
  }
})
Ronique Ricketts
@RoniqueRicketts
Jan 02 2018 12:43
@all Happy New Year !! May all your bugs be fixed this year and may new and exciting ideas pop up in your brains daily.
pocahontas123
@pocahontas123
Jan 02 2018 14:23
Hi every body. Could some one help me regarding a FCC beta challenge ? (Cash register https://beta.freecodecamp.org/en/challenges/javascript-algorithms-and-data-structures-projects/cash-register).
Blauelf
@Blauelf
Jan 02 2018 14:42

Hehe. My solution to the equivalent problem in regular fCC could return $0.30 when having only quarters and dimes. My personal challenge :P

A solution that won't be able to handle that correctly can be done much easier.

Where are you with that challenge? What have you already done?
pocahontas123
@pocahontas123
Jan 02 2018 14:46
re
Hi, i cuted my exercice in two
Blauelf
@Blauelf
Jan 02 2018 14:46
"cuted" :D
Sweet Coding :)
@SweetCodingInc
Jan 02 2018 14:47
:laughing:
pocahontas123
@pocahontas123
Jan 02 2018 14:47
First, i work with the number before the ','
cutted :) I learned some thing
And with this number, i compare it to the 100, 20, 10, 5 and 1
like this (wait i'm writing)
Sweet Coding :)
@SweetCodingInc
Jan 02 2018 14:48
@pocahontas123 it's just cut
go went gone
cut cut cut
English is a funny language
pocahontas123
@pocahontas123
Jan 02 2018 14:49
myNumber >= 100 ? if yes, work on it and retry. If not, check myNumber >= 20...
(funny language, it's like though and thought. Only one letter)
But i'm doing this with multiply While()...
Sweet Coding :)
@SweetCodingInc
Jan 02 2018 14:50
phonetically, though should be pronounced as thug
pocahontas123
@pocahontas123
Jan 02 2018 14:50
And first of all, i don't think it's good practice. And then, with this i failed
With these primary explanation, can i share my code with you?
Sweet Coding :)
@SweetCodingInc
Jan 02 2018 14:51
@pocahontas123 yes
pocahontas123
@pocahontas123
Jan 02 2018 14:51
function checkCashRegister(price, cash, cid) {
    //find the change
    let change = cash - price; //0.50 centimes
    //find the number before ',' (convert it to String to find it, then int)
    let bDecimal = parseInt( change.toString().split(".")[0] ); //0
    //find the number after ',' (convert it to String to find it, then int)
    let aDecimal = parseInt( change.toString().split(".")[1] ); //50
    //Correspond to how many my cash register have regarding 100, 20, 10, 5 and 1 
    let unitArray = [ cid[8][1], cid[7][1], cid[6][1], cid[5][1], cid[4][1] ];
    //To know how many of each i have to give (only concern 100, 20, 10, 5, and 1) (change)
    let unitArrayChange = [ ["ONE HUNDRED", 0], ["TWENTY", 0], ["TEN", 0], ["FIVE", 0], ["ONE", 0] ];
    //Help me to loop to every solutions regarding the number before the ','
    let end = true;


    while( end ) {
        do {
            if( bDecimal >= 100 ) {
                //update the decimal change value
                bDecimal = bDecimal - 100;
                //update the cash in drawer
                unitArray[0] = unitArray[0] - 100;
                //update and save the change
                unitArrayChange[0][1] == unitArrayChange[0][1] + 1;

                //if bDecimal equal zero, we end it
                //if not, we will continue because the inside while doesn't end
                if( bDecimal == 0 ) {
                    end = false;
                }
            }
        }while( bDecimal >= 100 );

        do {
            if( bDecimal >= 20 ) {
                //update the decimal change value
                bDecimal = bDecimal - 20;
                //update the cash in drawer
                unitArray[1] = unitArray[1] - 20;
                //update and save the change
                unitArrayChange[1][1] == unitArrayChange[1][1] + 1;

                //if bDecimal equal zero, we end it
                //if not, we will continue because the inside while doesn't end
                if( bDecimal == 0 ) {
                    end = false;
                }
            }
        }while( bDecimal >= 20 );

        do {
            if( bDecimal >= 10 ) {
                //update the decimal change value
                bDecimal = bDecimal - 10;
                //update the cash in drawer
                unitArray[2] = unitArray[2] - 10;
                //update and save the change
                unitArrayChange[2][1] == unitArrayChange[2][1] + 1;

                //if bDecimal equal zero, we end it
                //if not, we will continue because the inside while doesn't end
                if( bDecimal == 0 ) {
                    end = false;
                }
            }
        }while( bDecimal >= 10 );

        do {
            if( bDecimal >= 5 ) {
                //update the decimal change value
                bDecimal = bDecimal - 5;
                //update the cash in drawer
                unitArray[3] = unitArray[3] - 5;
                //update and save the change
                unitArrayChange[3][1] == unitArrayChange[3][1] + 1;

                //if bDecimal equal zero, we end it
                //if not, we will continue because the inside while doesn't end
                if( bDecimal == 0 ) {
                    end = false;
                }
            }
        }while( bDecimal >= 5 );

        do {
            if( bDecimal >= 1 ) {
                //update the decimal change value
                bDecimal = bDecimal - 1;
                //update the cash in drawer
                unitArray[4] = unitArray[4] - 1;
                //update and save the change
                unitArrayChange[4][1] == unitArrayChange[4][1] + 1;

                //if bDecimal equal zero, we end it
                //if not, we will continue because the inside while doesn't end
                if( bDecimal == 0 ) {
                    end = false;
                }
            }
        }while( bDecimal >= 1 );

    }

    //Should give me how much of 100, 20, 10, 5 and 1 i should give for the change
    console.log( unitArrayChange );

    // return change;
};
I will let you look at what i did. Like i said, i don't think so many while is a good thing. But i don't know a better like way to do it. I have wrote the logic on a paper but i didn't find an otherway to put it in code
Sweet Coding :)
@SweetCodingInc
Jan 02 2018 14:53
Oh dear!
This looks crazy
Is this code working?
pocahontas123
@pocahontas123
Jan 02 2018 14:55
First of all, if you can share an equivalant way to work on the same logic as me. A way which can replace the while. I could work on.
Well, not really. I'm stuck in the while :/ It never end and i'm not sure why. I have a bit of trouble with how while work and their scope
Sweet Coding :)
@SweetCodingInc
Jan 02 2018 14:57
give me some test cases for this
will try it out
pocahontas123
@pocahontas123
Jan 02 2018 14:58
Ok
I think, the best for my code should be to delet every " if( bDecimal == 0 ) {
end = false;
}"
And put only 1 at the end
With this code:
function checkCashRegister(price, cash, cid) {
    //find the change
    let change = cash - price; //0.50 centimes
    //find the number before ',' (convert it to String to find it, then int)
    let bDecimal = parseInt( change.toString().split(".")[0] ); //0
    //find the number after ',' (convert it to String to find it, then int)
    let aDecimal = parseInt( change.toString().split(".")[1] ); //50
    //Correspond to how many my cash register have regarding 100, 20, 10, 5 and 1 
    let unitArray = [ cid[8][1], cid[7][1], cid[6][1], cid[5][1], cid[4][1] ];
    //To know how many of each i have to give (only concern 100, 20, 10, 5, and 1) (change)
    let unitArrayChange = [ ["ONE HUNDRED", 0], ["TWENTY", 0], ["TEN", 0], ["FIVE", 0], ["ONE", 0] ];
    //Help me to loop to every solutions regarding the number before the ','
    let end = true;


    while( end ) {
        do {
            if( bDecimal >= 100 ) {
                //update the decimal change value
                bDecimal = bDecimal - 100;
                //update the cash in drawer
                unitArray[0] = unitArray[0] - 100;
                //update and save the change
                unitArrayChange[0][1] == unitArrayChange[0][1] + 1;

            }
        }while( bDecimal >= 100 );

        do {
            if( bDecimal >= 20 ) {
                //update the decimal change value
                bDecimal = bDecimal - 20;
                //update the cash in drawer
                unitArray[1] = unitArray[1] - 20;
                //update and save the change
                unitArrayChange[1][1] == unitArrayChange[1][1] + 1;

            }
        }while( bDecimal >= 20 );

        do {
            if( bDecimal >= 10 ) {
                //update the decimal change value
                bDecimal = bDecimal - 10;
                //update the cash in drawer
                unitArray[2] = unitArray[2] - 10;
                //update and save the change
                unitArrayChange[2][1] == unitArrayChange[2][1] + 1;

            }
        }while( bDecimal >= 10 );

        do {
            if( bDecimal >= 5 ) {
                //update the decimal change value
                bDecimal = bDecimal - 5;
                //update the cash in drawer
                unitArray[3] = unitArray[3] - 5;
                //update and save the change
                unitArrayChange[3][1] == unitArrayChange[3][1] + 1;

            }
        }while( bDecimal >= 5 );

        do {
            if( bDecimal >= 1 ) {
                //update the decimal change value
                bDecimal = bDecimal - 1;
                //update the cash in drawer
                unitArray[4] = unitArray[4] - 1;
                //update and save the change
                unitArrayChange[4][1] == unitArrayChange[4][1] + 1;

            }
        }while( bDecimal >= 1 );

        //if bDecimal equal zero, we end it
        //if not, we will continue because the inside while doesn't end
        if( bDecimal == 0 ) {
            end = false;
        }
    }

    //Should give me how much of 100, 20, 10, 5 and 1 i should give for the change
    console.log( unitArrayChange );

    // return change;
};
Sweet Coding :)
@SweetCodingInc
Jan 02 2018 15:01
try bDecimal < 1 instead of bDecimal == 0
pocahontas123
@pocahontas123
Jan 02 2018 15:02
ok. One try out could be checkCashRegister(19.5, 150, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);
So, it do 150-19.5 == 130.5
My code should be working on 130 for now. The response should be (100, 1) (20, 1) (10, 1)
Sweet Coding :)
@SweetCodingInc
Jan 02 2018 15:06
got it
pocahontas123
@pocahontas123
Jan 02 2018 15:06
I think this work somehow
because at the end, i have with unitArray
[0, 40, 10, 55, 90]
And before this
[100, 60, 20, 55, 90]
So i have exactly 100 + 20 + 10 equal 130. I messed up the unitArrayChange[1][1] == unitArrayChange[1][1] + 1; for exemple
pocahontas123
@pocahontas123
Jan 02 2018 15:12
I think i'm an idiot
unitArrayChange[0][1] == unitArrayChange[0][1] + 1; is not true
unitArrayChange[0][1] = unitArrayChange[0][1] + 1; is
Sweet Coding :)
@SweetCodingInc
Jan 02 2018 15:12
@pocahontas123 yyeah
lol :D
I just got here to point that out :D
pocahontas123
@pocahontas123
Jan 02 2018 15:12
Gonna try
Sweet Coding :)
@SweetCodingInc
Jan 02 2018 15:12
it worked for me
not sure if the output is correct, but it's not returning 0 like before
pocahontas123
@pocahontas123
Jan 02 2018 15:13
Ok, this work At least it does what i asked for
But if i can finish it and make it work, some people are going to slap my hand. Will make a forum post i think later on to have some feed back
Sweet Coding :)
@SweetCodingInc
Jan 02 2018 15:14
I changed your code and made it work with just 1 while loop
function checkCashRegister(price, cash, cid) {
    //find the change
    let change = cash - price; //0.50 centimes
    //find the number before ',' (convert it to String to find it, then int)
    let bDecimal = parseInt( change.toString().split(".")[0] ); //0
    //find the number after ',' (convert it to String to find it, then int)
    let aDecimal = parseInt( change.toString().split(".")[1] ); //50
    //Correspond to how many my cash register have regarding 100, 20, 10, 5 and 1 
    let unitArray = [ cid[8][1], cid[7][1], cid[6][1], cid[5][1], cid[4][1] ];
    //To know how many of each i have to give (only concern 100, 20, 10, 5, and 1) (change)
    let unitArrayChange = [ ["ONE HUNDRED", 0], ["TWENTY", 0], ["TEN", 0], ["FIVE", 0], ["ONE", 0] ];
    //Help me to loop to every solutions regarding the number before the ','
    let end = true;

    let changeFactor, unitIndex;
    while( bDecimal >= 0 ) {
      if(bDecimal >= 100){
        changeFactor = 100;
        unitIndex = 0;
      } else if(bDecimal >= 20){
        changeFactor = 20;
        unitIndex = 1;
      } else if(bDecimal>= 10){
        changeFactor = 10;
        unitIndex = 2;
      } else if(bDecimal >= 5){
        changeFactor = 5;
        unitIndex = 3;
      } else if(bDecimal >= 1){
        changeFactor = 1;
        unitIndex = 4;
      } else {
        //break;
      }

      bDecimal = bDecimal - changeFactor;
      unitArray[unitIndex] = unitArray[unitIndex] - changeFactor;
      unitArrayChange[unitIndex][1] = unitArrayChange[unitIndex][1] + 1;
    }
    //Should give me how much of 100, 20, 10, 5 and 1 i should give for the change
    console.log( unitArrayChange );
    // return change;
};
pocahontas123
@pocahontas123
Jan 02 2018 15:16
Ok, so when it's for exemple "if(bDecimal >=100)" == true, it bypass every other else if and end up at the end.
Then, because the while is not true, it re do it
Sweet Coding :)
@SweetCodingInc
Jan 02 2018 15:16
yes
pocahontas123
@pocahontas123
Jan 02 2018 15:17
Ok thanks. I though about else if but... some where in my brain i couldn't make it work
Sweet Coding :)
@SweetCodingInc
Jan 02 2018 15:18
No worries.. Optimised syntax takes a while to get used to..
you'll get there
cool solution, btw
pocahontas123
@pocahontas123
Jan 02 2018 15:18
@SweetCodingInc Thanks you. I will continue with your code
CamperBot
@camperbot
Jan 02 2018 15:18
pocahontas123 sends brownie points to @sweetcodinginc :sparkles: :thumbsup: :sparkles:
:cookie: 179 | @sweetcodinginc |http://www.freecodecamp.org/sweetcodinginc
pocahontas123
@pocahontas123
Jan 02 2018 15:18
Happy new year
Sweet Coding :)
@SweetCodingInc
Jan 02 2018 15:18
you managed to avoid so many newbie pitfalls as it is.. Which is good..

with this notation

 let unitArray = [ cid[8][1], cid[7][1], cid[6][1], cid[5][1], cid[4][1] ];
//To know how many of each i have to give (only concern 100, 20, 10, 5, and 1) (change)
let unitArrayChange = [ ["ONE HUNDRED", 0], ["TWENTY", 0], ["TEN", 0], ["FIVE", 0], ["ONE", 0] ];

a typical newbie would end up writing if else for that as well

Happy new year
RecodeExistence
@RecodeExistence
Jan 02 2018 16:42
oh wow, 90 messages to catch up on . xD
@bradley1492 i don't know if you're still working on your regex, but i found an outstanding resource on youtube which is helping me with the concept a lot. let me know if you'd like it.
Gersho
@Gersho
Jan 02 2018 16:45
put the link, it could help someone else ;)
RecodeExistence
@RecodeExistence
Jan 02 2018 16:46
that's true xD
the link is : https://www.youtube.com/watch?v=7DG3kCDx53c , he has a series of videos on RegExp, and he's honestly explaining in a way i can understand what on earth they actually are, what they do, and how to put them into use.
Point to note - the videos won't hand you the answer to challenges, but help develop concrete knowledge on regexp ^^ (more important to me at least!)
Gersho
@Gersho
Jan 02 2018 16:49
of course, the point here is to learn
RecodeExistence
@RecodeExistence
Jan 02 2018 16:50
nod but i (admittedly from previous experience), know how easy it is to look for the answer to a challenge, than actually go learn how to understand a challenge lol. It was more of a disclaimer than anything.
Tiago Correia
@tiagocorreiaalmeida
Jan 02 2018 17:28
no brakes on the coding train :D
Ken Haduch
@khaduch
Jan 02 2018 17:30
@tiagocorreiaalmeida :D - that's a good one!
Tiago Correia
@tiagocorreiaalmeida
Jan 02 2018 17:33
funfunfunction and coding train are probably the best people on youtube to teach you how stuff works and keep you motivated/concentrated
Gersho
@Gersho
Jan 02 2018 17:34
Eli the Computer Guy has good vids too (they are easy to understand even if english isn't your native language, he's very articulate)
Jason Luboff
@JLuboff
Jan 02 2018 17:36
:wave:
dinesh
@1532j0004kg
Jan 02 2018 17:40
function sumAll(arr) {
  arr.reduce(function(x,y)
            {
    return x+y;
  });
}

sumAll([1, 4]);
guys this is not working~
?
Jason Luboff
@JLuboff
Jan 02 2018 17:40
You aren't returning anything
dinesh
@1532j0004kg
Jan 02 2018 17:40
return x+y ?
Jason Luboff
@JLuboff
Jan 02 2018 17:41
That is, sumAll is not returning anything
Plus, don't you need to sum everything between the range? So not just 1 +4 but 1+2+3+4?
dinesh
@1532j0004kg
Jan 02 2018 17:42
i wanna to add only 1&4 !
Jason Luboff
@JLuboff
Jan 02 2018 17:42
Ok..well still.. sumAll isn't returning anything
dinesh
@1532j0004kg
Jan 02 2018 17:43
wanna to give return 1;
?
Jason Luboff
@JLuboff
Jan 02 2018 17:43
What?
dinesh
@1532j0004kg
Jan 02 2018 17:44
what i want to give ?
Gersho
@Gersho
Jan 02 2018 17:44
what are you trying to achieve with that reduce ?
also :wave: @JLuboff are you daddy yet .
dinesh
@1532j0004kg
Jan 02 2018 17:45
wanna to add 1 & 4
Gersho
@Gersho
Jan 02 2018 17:45
in terms of data, where is the 1 stored ? and the 4 ?
Jason Luboff
@JLuboff
Jan 02 2018 17:46
@Gersho Ya! He was born November 23! Healthy and happy (I mean..he doesn't talk so I'm just making an assumation(I'm pretty sure I butchered the spelling here) about being happy :P)
dinesh
@1532j0004kg
Jan 02 2018 17:46
in arr!
only the 1&4 is stored
Gersho
@Gersho
Jan 02 2018 17:47
@1532j0004kg exactly, so why are you trying to do stuff with x and y ? you only need arr[0] (=1)and arr[1] (=2)
@JLuboff congratulation, oh i'm sure he's happy, i'd be happy too if my main mean of getting food was breastfeeding ;)
Jason Luboff
@JLuboff
Jan 02 2018 17:48
@Gersho Thanks! He definitely loves his milk haha
CamperBot
@camperbot
Jan 02 2018 17:48
jluboff sends brownie points to @gersho :sparkles: :thumbsup: :sparkles:
:cookie: 547 | @gersho |http://www.freecodecamp.org/gersho
dinesh
@1532j0004kg
Jan 02 2018 17:48
@Gersho put the answer
! is probably easy way to understand.
Gersho
@Gersho
Jan 02 2018 17:51
function sumAll(arr) {

    return arr[0]+arr[1];
  }
sumAll([1, 4]);
will do 1+4 in your exemple, but as far as i remember the challenge asks you for 1+2+3+4
dinesh
@1532j0004kg
Jan 02 2018 17:52
purpose of reduce function is to add the array value right?
then y its not worked when i giving those values

  [1, 4].reduce(function(x,y)
     {
    return x+y;
  });
its working! how
?
i did earlier like just replaced the [1,4 ] with the function parameter!\
Gersho
@Gersho
Jan 02 2018 17:56

if you really want to use the reduce you could try

function sumAll(arr) {

    return  arr.reduce(function(x,y)
     {
    return x+y;
  });


  }
sumAll([1, 4]);

bvut i don't really see the point of using reduce on an array with only 2 elements

dinesh
@1532j0004kg
Jan 02 2018 17:58
got it!!!
Gersho
@Gersho
Jan 02 2018 17:58
but like said earlier sumAll challenge doesn't ask you for that, it asks for 1+2+3+4
dinesh
@1532j0004kg
Jan 02 2018 17:59
ok , i want to find the intermediate things and i want to add those right?
Gersho
@Gersho
Jan 02 2018 18:01
to stay in line within your method you should find some way to turn [1, 4] into [1,2,3,4] , and use it with your code
function sumAll(arr) {
//something here  that makes [1,4] into [1,2,3,4]
// newArr = [1,2,3,4]
    return  newArr.reduce(function(x,y)
     {
    return x+y;
  });


  }
sumAll([1, 4]);
dinesh
@1532j0004kg
Jan 02 2018 18:02
ok thanks @Gersho
CamperBot
@camperbot
Jan 02 2018 18:02
1532j0004kg sends brownie points to @gersho :sparkles: :thumbsup: :sparkles:
:cookie: 548 | @gersho |http://www.freecodecamp.org/gersho
dinesh
@1532j0004kg
Jan 02 2018 18:03
whats ur current status of fcc projects?
@1532j0004kg
Gersho
@Gersho
Jan 02 2018 18:04
me ? almost done with frontend and tried a few things in data viz
dinesh
@1532j0004kg
Jan 02 2018 18:05
ok! cool
dinesh
@1532j0004kg
Jan 02 2018 18:13
is it the 7,8,9,10 projects are easy?
Jason Luboff
@JLuboff
Jan 02 2018 18:16
I can't believe FCC beta hasn't gone live yet. I thought they were aiming for end of 2017..
Gersho
@Gersho
Jan 02 2018 18:16
there was a date ? i didn't know
Jason Luboff
@JLuboff
Jan 02 2018 18:17
I think originally they were aiming for november..then it turned to December..then I think I had read Christmas day...and..now who knows
Gersho
@Gersho
Jan 02 2018 18:17
i still have much to do before i'm done with the current content so i'm in no rush xD
but more lessons wouldn't hurt yeah
Jason Luboff
@JLuboff
Jan 02 2018 18:19
I started the React stuff on beta but didn't get too far yet. Focusing on other things
Gersho
@Gersho
Jan 02 2018 18:31
i learned react on codeacademy but they don't have projects only lessons
Jason Luboff
@JLuboff
Jan 02 2018 18:33
Haven't gone to codecademy in a looooong time
Gersho
@Gersho
Jan 02 2018 18:33
i plan to start stuff on edx to have more theoric knowledge
because i don't know stuff like paradigm, inheritence types, functional programming, etc
Jason Luboff
@JLuboff
Jan 02 2018 18:37
Ya, my theoric knowledge isn't great lol
It's getting a bit stronger that I've been studying C# but still no where near what a programmer should be at
RecodeExistence
@RecodeExistence
Jan 02 2018 18:42
I got muted for 2 weeks on codecademy recently for asking why half of the content i learnt years ago on an old account is now behind a monthly subscription fee. i guess they don't like opinion.
Jason Luboff
@JLuboff
Jan 02 2018 18:56
I love turning an if/else statement into a single line
RecodeExistence
@RecodeExistence
Jan 02 2018 18:57
^ that's why i love ternary operators lol.
Jason Luboff
@JLuboff
Jan 02 2018 18:58
I didn't even need a ternary

I turned this:

 if (cbOther.Checked)
            {
                tbComments.Visible = true;
            } else
            {
                tbComments.Visible = false;
            }

into

tbComments.Visible = cbOther.Checked
RecodeExistence
@RecodeExistence
Jan 02 2018 19:10
 var tbComments.Visible = return cbOther.Checked ? true: false;
would that work? in my head it has the same logic, but i have a lot to learn
(other than the fact the return would be result of a function of course).
Gersho
@Gersho
Jan 02 2018 19:14
well it looks like it would work but evaluating a boolean to return the same boolean doesn't seem very efficient
it's like if you did
if (cb0ther.Checked) {
return true;
}else{
return false
}
edited
Brad
@bradtaniguchi
Jan 02 2018 19:17
Id say this would work, assign the value to tbComments.Visibible, and return the actual value as well.
return tbComments.Visible = cbOther.Checked ? true: false;
RecodeExistence
@RecodeExistence
Jan 02 2018 19:19
that was my original thought @bradtaniguchi , i just snagged on the reassignment at the end of @JLuboff 's code. (and his avoidance of ternary) xD
Brad
@bradtaniguchi
Jan 02 2018 19:20
The other thing you could do is get rid of the tenery aswell now that I think about it. I think this would work too.
return tbComments.Visible = !!cbOther.Checked;
RecodeExistence
@RecodeExistence
Jan 02 2018 19:20
Lemme check my logic here:
Jason Luboff
@JLuboff
Jan 02 2018 19:22
This is C# code, not JS. But yes a ternary would be fine but you wouldn't want the return as you're assigning not returning
RecodeExistence
@RecodeExistence
Jan 02 2018 19:22
nope. not following that. != is not equal , what is !! ?
Sorry @JLuboff I just made assumptions. I'm somewhere between beginner and intermediate JS, and this is the JS help channel. Lol, my apologies.
Jason Luboff
@JLuboff
Jan 02 2018 19:23
No its fine, I was just pointing that out is all. In this case, it would be the same
Brad
@bradtaniguchi
Jan 02 2018 19:24

!! is still kinda forign to me, but if you do this:

var value = !someTruthyValue

you get true or false of the OPPOSITE, of the someTruthyValue. So doing it twice means you get the original value, but not as a truthy one, but rather a pure true/false value

Its important if you expect exactly true, or false somewhere else in the code( which is why you return them directly rather than just the value of the cbOther.Checked). But all of this is redundant if cbOther.Checked will always be either true or false
RecodeExistence
@RecodeExistence
Jan 02 2018 19:25
@bradtaniguchi would that be equivalent to switching the sign? so for +FalseStatement // where false statement is now switched to true?
Jason Luboff
@JLuboff
Jan 02 2018 19:25
Ya, cbOther.Checked returns a boolean by nature
Brad
@bradtaniguchi
Jan 02 2018 19:25
^
if that is the case, then just return it directly with the assignment, no fancy checking of the value just to return true/false
RecodeExistence
@RecodeExistence
Jan 02 2018 19:26
@JLuboff no problem man. I'm definitely an advocate of making code much more concise. I'm far from making anything i'd call "real world use", but i'm always aiming to be even more concise and DNR.
Jason Luboff
@JLuboff
Jan 02 2018 19:29
@RecodeExistence Don't worry. I haven't really made any "real world use" applications either. I've completed FCC front and back end portions but..I wouldn't call my end product a shining example of knowledgable code lol. Right now I'm studying C# and working on converting one of my companies in house built apps from Visual Basic to C# for the sake of practicing and learning
RecodeExistence
@RecodeExistence
Jan 02 2018 19:30
I'm terrible with front end for a good reason - i'm not design oriented. I tried FCC a few years ago and stumped on the 'personal portfolio' for that reason. I can think how to make things work, not how to make them look unfortunately.
Jason Luboff
@JLuboff
Jan 02 2018 19:32
Maybe you'd like backend design more than
RecodeExistence
@RecodeExistence
Jan 02 2018 19:33
I wouldn't know where to start. My head is still in that coding place of "get what a user inputs and validate it", or "check that username and password against a known list and let them in if it's right" kind of place.
Having trouble stepping from there to "here's what actually makes things work".
To me, it's the difference between knowing that a painter uses brushes, lines, light, etc, and knowing how to actually make something meaningful lol.
Jason Luboff
@JLuboff
Jan 02 2018 19:37

Eh..I think you're overthinking it a bit. Using NodeJS, if you're already familar with JS, isn't that difficult. Yes you're setting up a web server but using a package likes Express makes it super simple. Then you just specify routes, etc.

const express = require('express');
var app = express();

app.route('/').get((req, res) => { res.send('Hello World!')});

app.listen(3000);

There I created a web server listening over port 3000 that will render a simple "Hello World!" page

Watch a couple videos on it, you may like it
RecodeExistence
@RecodeExistence
Jan 02 2018 19:38
I think what i mean is: i wouldn't even know the thought process that lead to creating that code. If that makes sense.
It's something i have trouble explaining, so maybe i need to think on it more.
Daniel Narilton
@spaganger
Jan 02 2018 19:40
https://codepen.io/Vigariuoluvi/pen/JMJeeZ?editors=1010 I'm trying to display the current number of people in space with Ajax but i'm getting an error. The same happened when I used this url:(http://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b6907d289e10d714a6e88b30761fae22). However, when i used this one: https://learnwebcode.github.io/json-example/animals-1.json, it works. can anybody help me
Jason Luboff
@JLuboff
Jan 02 2018 19:40
Its all a matter of starting somewhere
RecodeExistence
@RecodeExistence
Jan 02 2018 19:40
It's the little step from that somewhere, @JLuboff . I understand the tools i'm given now, just not how to use them to come up with things (or to reverse that, things to come up with, with them lmao!);
Tiago Correia
@tiagocorreiaalmeida
Jan 02 2018 20:17
hey @JLuboff
@RecodeExistence I can give you some websites that will help with the colors
other than that just take a look around the websites that exist pick some ideias and create something
Brad
@bradtaniguchi
Jan 02 2018 20:18
@tiagocorreiaalmeida https://coolors.co/
Tiago Correia
@tiagocorreiaalmeida
Jan 02 2018 20:18
Brad
@bradtaniguchi
Jan 02 2018 20:18
This is what I use
Tiago Correia
@tiagocorreiaalmeida
Jan 02 2018 20:19
to generate palettes I go for the same as you :D
somethings I pick a color or two from here and then generate unthil I get something I like
anyway there's alot of tools that will help us in the small projects but when things get really big the best thing to do is let someone who has knowledge on the topic handle it :D
Stephen James
@sjames1958gm
Jan 02 2018 21:06
@Vigariuoluvi You cannot request data from a http:// URL from a site that https://
FlashHero
@FlashHero
Jan 02 2018 21:11
I have a question, were we supposed to use api for getting random quotes or can we just use an array to store random quotes in the Build a Random Quote Machine challenge
Stephen James
@sjames1958gm
Jan 02 2018 21:12
@FlashHero You could use an API, but you did not have to.
FlashHero
@FlashHero
Jan 02 2018 21:13
@sjames1958gm oh ok on my last challenge so just making sure i did all the projects the way it was supposed to be thanks though
CamperBot
@camperbot
Jan 02 2018 21:13
flashhero sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8815 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
Jason Luboff
@JLuboff
Jan 02 2018 21:17
@tiagocorreiaalmeida Yo
Tiago Correia
@tiagocorreiaalmeida
Jan 02 2018 21:18
how's c# today?:D
Jason Luboff
@JLuboff
Jan 02 2018 21:19
@tiagocorreiaalmeida It's going.. lol
What're you working on?
Tiago Correia
@tiagocorreiaalmeida
Jan 02 2018 21:20
well besides trying to leave laziness behind im aswell tyring to build a blog api, and pratice react/redux so far
Jason Luboff
@JLuboff
Jan 02 2018 21:21
Nice
Tiago Correia
@tiagocorreiaalmeida
Jan 02 2018 21:23
how will your exam be? like hand writting or code something during a certain time?
Jason Luboff
@JLuboff
Jan 02 2018 21:24
@tiagocorreiaalmeida They usually consist of Multiple choice, True/False, correct the underlined word, and drag and drop questions
Daniel Narilton
@spaganger
Jan 02 2018 21:31
@sjames1958gm and how can I use that data on my weather app dynamically? should i download the json file every time the weather changes?
Stephen James
@sjames1958gm
Jan 02 2018 21:32
@Vigariuoluvi If you want up to the date weather you will have to query the website periodically
Jason Luboff
@JLuboff
Jan 02 2018 21:32
@Vigariuoluvi You could use setInterval (or would it be setTimeout..it's been a while) to have it check the API every so often to update as well as on refresh have it update
Daniel Narilton
@spaganger
Jan 02 2018 21:33
@sjames1958gm whenever i request from this url: https://learnwebcode.github.io/json-example/animals-1.json, it works
Stephen James
@sjames1958gm
Jan 02 2018 21:33
@Vigariuoluvi Yes. that URL is https:// (secure) the others you listed are http:// (insecure)
Daniel Narilton
@spaganger
Jan 02 2018 21:34
how can i query it periodically? Using setInterval?
Jason Luboff
@JLuboff
Jan 02 2018 21:34
@Vigariuoluvi You could use setInterval (or would it be setTimeout..it's been a while) to have it check the API every so often to update as well as on refresh have it update
Daniel Narilton
@spaganger
Jan 02 2018 21:37
@JLuboff thanks. but i don't know how to do that yet
CamperBot
@camperbot
Jan 02 2018 21:37
vigariuoluvi sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2286 | @jluboff |http://www.freecodecamp.org/jluboff
Jason Luboff
@JLuboff
Jan 02 2018 21:37
Call you function within the setInterval function
Tiago Correia
@tiagocorreiaalmeida
Jan 02 2018 21:37
@Vigariuoluvi we are here to help :D
open a new codepen and place settimeout there and try to see how it works then implement it
Daniel Narilton
@spaganger
Jan 02 2018 21:50
@tiagocorreiaalmeida Cool =) is there a way or a trick for requesting data from an http url
Tiago Correia
@tiagocorreiaalmeida
Jan 02 2018 21:51
what are you using at the moment?
Daniel Narilton
@spaganger
Jan 02 2018 21:51
just vanilla javascript
Daniel Narilton
@spaganger
Jan 02 2018 21:53
https://www.youtube.com/watch?v=ecT42O6I_WI he loaded data from an http url and i couldn't. so i figured this guy knew a trick or sth
Jason Luboff
@JLuboff
Jan 02 2018 21:55
He probably was also on an unsecure (http) connection
or using a cross origin proxy
Tiago Correia
@tiagocorreiaalmeida
Jan 02 2018 21:55
just follow his videos and you will be fine :D
Bryan Reese
@breese8009
Jan 02 2018 21:57
'updating the text in the JS source code' - whats this mean to u?
Tiago Correia
@tiagocorreiaalmeida
Jan 02 2018 21:57
fcc beta?
Daniel Narilton
@spaganger
Jan 02 2018 22:14
@tiagocorreiaalmeida I wrote this in order to get an HTTP GET request, but it doesn't work https://codepen.io/Vigariuoluvi/pen/YYQgWL?editors=0010 so websites like this one https://openweathermap.org/ cannot be used because they only contain http urls?
Jason Luboff
@JLuboff
Jan 02 2018 22:16
@breese8009 Going into the JS file and modifying some text?
Tiago Correia
@tiagocorreiaalmeida
Jan 02 2018 22:18
@Vigariuoluvi can you give me an example call url?
Bryan Reese
@breese8009
Jan 02 2018 22:18
that how i read it too
some reason i was thinking it was something different
Tiago Correia
@tiagocorreiaalmeida
Jan 02 2018 22:19
req.isAuthenticated decide to return false eveytime today :D
@JLuboff did you ever had the same issue?
Jason Luboff
@JLuboff
Jan 02 2018 22:20
@breese8009 I could be totally wrong but with that context that seems to be what it is..
@tiagocorreiaalmeida Nope..
Tiago Correia
@tiagocorreiaalmeida
Jan 02 2018 22:24
@Vigariuoluvi the issue was codepen
blocking http requests
let theUrl = "https://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b6907d289e10d714a6e88b30761fae22";
function httpGetAsync(theUrl, callback) {
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
            callback(xmlHttp.responseText);
    }
    xmlHttp.open("GET", theUrl, true); // true for asynchronous 
    xmlHttp.send(null);
}

let data = httpGetAsync(theUrl,function(weatherData){
      console.log(weatherData);                  
});
I think this is similiar to what you need
Daniel Narilton
@spaganger
Jan 02 2018 22:33
@tiagocorreiaalmeida i copiedpaste the code onto chrome and this msg popped up>VM38:9 GET https://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b6907d289e10d714a6e88b30761fae22 net::ERR_INSECURE_RESPONSE
Tiago Correia
@tiagocorreiaalmeida
Jan 02 2018 22:33
dont worry about that
codepen will love it
:D
Daniel Narilton
@spaganger
Jan 02 2018 22:33
but it's not on codepen
Tiago Correia
@tiagocorreiaalmeida
Jan 02 2018 22:34
plus there's an option
below to see the content
so where are you coding this?
Dan Lafferty
@DanLaff
Jan 02 2018 22:34
@Vigariuoluvi Your API calls to Open Weather Map should be using: https://api.openweathermap.org/...
samples.openweathermap.org appears to just be something they use for demonstration in their docs
Jason Luboff
@JLuboff
Jan 02 2018 22:35
which unless openweathermap has changed, won't work unless you pay for a subscription to use https
Daniel Narilton
@spaganger
Jan 02 2018 22:35
@DanLaff does the same hold true for this url: http://api.open-notify.org/astros.json ?
Dan Lafferty
@DanLaff
Jan 02 2018 22:36
@JLuboff They made that change back in August according to: http://openweathermap.org/news/post/ssl-free-and-startup-accounts
Jason Luboff
@JLuboff
Jan 02 2018 22:36
@DanLaff Good looking out. Thanks!
CamperBot
@camperbot
Jan 02 2018 22:36
jluboff sends brownie points to @danlaff :sparkles: :thumbsup: :sparkles:
api offline
Dan Lafferty
@DanLaff
Jan 02 2018 22:36
@Vigariuoluvi I don't know anything about open-notify.org, sorry - but I'm guessing codepen can't be used with any API URLs starting with http:// because codepen itself is served over HTTPS
No problem @JLuboff :)
Daniel Narilton
@spaganger
Jan 02 2018 23:01
thanks, guys
Ronique Ricketts
@RoniqueRicketts
Jan 02 2018 23:32
@JLuboff @sjames1958gm @tiagocorreiaalmeida happy new year nerd! :)
Jason Luboff
@JLuboff
Jan 02 2018 23:32
@RoniqueRicketts Thanks, happy new year to you as well
CamperBot
@camperbot
Jan 02 2018 23:32
jluboff sends brownie points to @roniquericketts :sparkles: :thumbsup: :sparkles:
:cookie: 413 | @roniquericketts |http://www.freecodecamp.org/roniquericketts
Ronique Ricketts
@RoniqueRicketts
Jan 02 2018 23:33
@JLuboff yw bruv. Man I haven'r coded from last year bruv. I feel unaccomplished.
Jason Luboff
@JLuboff
Jan 02 2018 23:34
Disappointing :P
Ronique Ricketts
@RoniqueRicketts
Jan 02 2018 23:35
IKR I didn't open teamviewer on my computer this morning so I could remote into my environment and code.
Tiago Correia
@tiagocorreiaalmeida
Jan 02 2018 23:39
@RoniqueRicketts happy new year :D
Ronique Ricketts
@RoniqueRicketts
Jan 02 2018 23:39
@tiagocorreiaalmeida thanks man
CamperBot
@camperbot
Jan 02 2018 23:39
roniquericketts sends brownie points to @tiagocorreiaalmeida :sparkles: :thumbsup: :sparkles:
:cookie: 483 | @tiagocorreiaalmeida |http://www.freecodecamp.org/tiagocorreiaalmeida