These are chat archives for FreeCodeCamp/HelpJavaScript

4th
Nov 2017
Spyrantis Theodoros
@thodorisanta
Nov 04 2017 00:00
shouldnt this work?
document.getElementsByClassName('clickable').onclick = function(e){
   console.log("yay");
}
Mois├ęs Man
@moigithub
Nov 04 2017 00:18
Getelementsbyclassname return a nodelist ...similar to anbarray
Sooo u need to iterate throuhg all elements to attach click event
FlashHero
@FlashHero
Nov 04 2017 00:21
@thodorisanta this.id is how you would get the id of the element that was clicked
AbrisM
@AbrisM
Nov 04 2017 00:38
Hi all
Ghost
@ghost~59cdefc7d73408ce4f77dab0
Nov 04 2017 07:16
Could anybody help me with this-
Im trying to change backgroundColor of dispdiv on buttonclick of id search
Spyrantis Theodoros
@thodorisanta
Nov 04 2017 07:19
@FlashHero but how will i do the other part?
tarun47900
@tarun47900
Nov 04 2017 08:09
Cabt anybody tell me
Devin Miller
@edwin0258
Nov 04 2017 08:12
@parthprakash1 Made a fork , maybe this will help. https://codepen.io/edwin0258/pen/bYprwx?editors=1010
e.preventDefault() will prevent form from being refreshed on button click. Without that you won't be able to change the color I think. There were also a few errors in HTML.
Don't need # in getElementById. @parthprakash1
Dan Couper
@DanCouper
Nov 04 2017 08:29

@thodorisanta example, either

document.addEventListener('click', e => {
  if (e.target.classList.contains('clickable')) console.log('yay');
});

or

document.querySelectorAll('.clickable').forEach(el => {
  el.addEventListener('click', () => console.log('yay'));
});
Razvan Jackson
@RazvanJackson
Nov 04 2017 08:59
Who use vscode?
Rohit Yadav
@rohyadav
Nov 04 2017 09:11
is there anyone help me out
in javascript program
function generate(A,B,C,D,E,F){
  var isValidTime = /^(?:[01]\d|2[0-3]):(?:[0-5]\d)$/;
  var pattern = "0123012 0132013 0213021 0231023 0312031 000789".replace(/\d/g, i => arguments[+i]);
  var max = "";
  for(var i=pattern.length-6; i--; ){
    var time = pattern.substr(i,2) + ":" + pattern.substr(i+2,2);
    if(time > max && isValidTime.test(time)) 
      max = time;
  }
  return max || "NOT POSSIBLE";
}

[
  [0,0,0,7,8,9]
].forEach(arr => console.log(arr + ' -> ' + generate(...arr)));


/*
the output will be like
given 0,0,0,7,8,9 the function shoud return "00:08:09"
given 2,4,5,6,5,9 the function shoud return NotPossible
*/
anyone help me out
Ashwin
@ashwins93
Nov 04 2017 09:17
@RazvanJackson i do
Rohit Yadav
@rohyadav
Nov 04 2017 09:18
if i given value 1,8,3,2,6,4 the function should return "12:36:48"
anyone help me out
??
Rohit Yadav
@rohyadav
Nov 04 2017 09:25
@rohyadav
ok, please help me out
write a function

function solution(a,b,c,d,e,f)
that, given six integers a,b,c,d,e,f return the earliest valid time in "hh:mm:ss" string format, or "Not Possible" if it is not possible to display a vlid time using all six intergers

the output will be like
given 0,0,0,7,8,9 the function shoud return "00:08:09"
given 2,4,5,6,5,9 the function shoud return NotPossible

if i given value 1,8,3,2,6,4 the function should return "12:36:48"
yofri
@yofriadi
Nov 04 2017 09:27
hi guys, how to call function prototype in handlebars
// router.js
// i have object like this named rows and passing to .hbs file
{ first_name: 'first',
  last_name: 'last }
console.log(rows.getFullname());  // i can call function prototype like this
res.render('mypage', rows);  // with express, render it to .hbs

// .hbs
{{#each this}}
  {{first_name}}
  {{last_name}}
  // i want to call function prototype her
{{/each}}
Dan Couper
@DanCouper
Nov 04 2017 09:31
@rohyadav I don't understand what this is asking you to do. What relation do the integers have to time? I assumed you were supposed to rearrange them, but then 0,0,0,7,8,9 would be "07:08:09", not "00:08:09" as the example states. Maybe I'm missing something, but this doesn't seem to make any sense
@Yofri the templates are supposed to be logic-less (beyond very simple loop constructs). You're not supposed to put arbitrary code in them: they're designed so that you can't do that. As far as I can remember, you need to write a helper and use the helper: http://handlebarsjs.com/block_helpers.html
yofri
@yofriadi
Nov 04 2017 09:35
@DanCouper so i made </script> in bottom of my hbs file and create the logic there?
Petru Conduraru
@bluecondor
Nov 04 2017 09:38
Cand anybody explain to me please what logical operator does mean here?
"start": "npm run css-watch | npm run js-watch"
I know "||" is OR but only "|", I have no clue :(
Pethaf
@Pethaf
Nov 04 2017 09:42
@bluecondor bash syntax vs javascript syntax I would guess.
Dan Couper
@DanCouper
Nov 04 2017 09:42
@Yofri Umm, seperate, that won't work at all: because the hbs file is going to be a template the gets rendered to HTML, if you put it in the .hbs file Handlebars would need to try to render the template backend with something that wasn't there, then once it got to the frontend (where handlebars won't exist) parse the script and rerender the template.
Petru Conduraru
@bluecondor
Nov 04 2017 09:43
@Pethaf but what is the result of this command?
Pethaf
@Pethaf
Nov 04 2017 09:43
Oh, right.
Petru Conduraru
@bluecondor
Nov 04 2017 09:43
@Pethaf it will run both of them? or only one?
Dan Couper
@DanCouper
Nov 04 2017 09:43
It's the pipe operator
Dan Couper
@DanCouper
Nov 04 2017 09:44
it runs css watch then pipes the result of that to js watch
and I don't see how this will work
Pethaf
@Pethaf
Nov 04 2017 09:44
So it will feed the result of the first operation as an argument to the second operation.
Now I have to brush up on my bash skills.
Petru Conduraru
@bluecondor
Nov 04 2017 09:44
:)
Pethaf
@Pethaf
Nov 04 2017 09:44
What is the difference between > and |
Dan Couper
@DanCouper
Nov 04 2017 09:44
yeah, that doesn't make sense, they're both watching files, not passing arguments, so this should just break??
Petru Conduraru
@bluecondor
Nov 04 2017 09:44
@DanCouper @Pethaf thank you both
CamperBot
@camperbot
Nov 04 2017 09:44
bluecondor sends brownie points to @dancouper and @pethaf :sparkles: :thumbsup: :sparkles:
:cookie: 858 | @dancouper |http://www.freecodecamp.com/dancouper
:cookie: 446 | @pethaf |http://www.freecodecamp.com/pethaf
Ashwin
@ashwins93
Nov 04 2017 09:45
@Pethaf > is used to write to file streams
Pethaf
@Pethaf
Nov 04 2017 09:45
Ok.
Ashwin
@ashwins93
Nov 04 2017 09:45
you also have >> which appends to files
Pethaf
@Pethaf
Nov 04 2017 09:46
Like cat /prop/cpuinfo > cpulog.txt
yofri
@yofriadi
Nov 04 2017 09:46
@DanCouper hey man, i made the stackoverflow here https://stackoverflow.com/questions/47109394/calling-function-prototype-in-handlebars and the repo here https://github.com/Yofri/school-app/blob/master/views/student.hbs hope you can help me. im new to handlebars
Pethaf
@Pethaf
Nov 04 2017 09:47
@ashwins93 Thanks.
CamperBot
@camperbot
Nov 04 2017 09:47
pethaf sends brownie points to @ashwins93 :sparkles: :thumbsup: :sparkles:
:cookie: 412 | @ashwins93 |http://www.freecodecamp.com/ashwins93
Dan Couper
@DanCouper
Nov 04 2017 09:56
@Yofri <td>{{ first_name }} {{ last_name }}</td>, why do you need a function?
abraham anak agung
@padunk
Nov 04 2017 09:59
Anyone know React & Redux here?
yofri
@yofriadi
Nov 04 2017 09:59
@DanCouper hmm it is the requirement, im doing task here in my bootcamp
Spyrantis Theodoros
@thodorisanta
Nov 04 2017 10:09
@DanCouper can you explain me how exactly those work?
Long Nguyen
@longnt80
Nov 04 2017 10:30
@padunk I know a little, what do you want to ask?
Spyrantis Theodoros
@thodorisanta
Nov 04 2017 10:31
can you check my last function in JS.Shount the var x take the id of the element that is clicked?(line 127)
https://codepen.io/oshikurou/pen/ZaWzoa?editors=0011
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 11:02
@thodorisanta you mean that undefined coming back?
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 11:08
as far as I know the this keyword doesnt work with arrow functions plus I think when working it vanillajs there's a bit of more workaround to make that work but im not really used to it
Spyrantis Theodoros
@thodorisanta
Nov 04 2017 11:11
@tiagocorreiaalmeida i want it to return the id of the element that is clicked
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 11:12
with jquery I know how to do it, dom manipullation with js its one of the things I have few knowledge sadly, anyway join the frontend chat there's someone who might save you :D
but try as said by other e.target.id
abraham anak agung
@padunk
Nov 04 2017 11:13
@longnt80 nvm, my reducer is wrong. :smile: it won't update my component
Spyrantis Theodoros
@thodorisanta
Nov 04 2017 11:33
isnt this suppose to compare the last elements of 2 arrays? what did i do wrong
if(x[x.length - 1] === y[y.length - 1]){
        console.log("fuck yeah");
 }
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 11:35
@thodorisanta https://jsfiddle.net/a3mL1z5j/1/ nothing wrong
maybe the probblem is somewhere else
Pieter Stokkink
@forkerino
Nov 04 2017 11:39
@thodorisanta On your pen I see 'x is undefined' errors, because you didn't define x
if I comment out that console.log('id: ' + x) it works for me
Margaret Greaney
@greaneym
Nov 04 2017 11:53
@cmccormack , thanks for your feedback about implementing keydown. After reading more about best practices, the performance is best when one uses stateless components and use of events support by react. Then pass the handlers as function definitions. as properties. Your example is a custom handler for keydown as I understand. Is that right?
CamperBot
@camperbot
Nov 04 2017 11:53
greaneym sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1255 | @cmccormack |http://www.freecodecamp.com/cmccormack
Margaret Greaney
@greaneym
Nov 04 2017 11:54
If that is so, why did you use a custom event handler if react supports keydown, press, up events? thanks
@cmmccormack, in any case what you sent helps me and thanks.
CamperBot
@camperbot
Nov 04 2017 11:55
greaneym sends brownie points to @cmmccormack :sparkles: :thumbsup: :sparkles:
api offline
Margaret Greaney
@greaneym
Nov 04 2017 12:00
will check back later.
Dan Couper
@DanCouper
Nov 04 2017 12:00
@thodorisanta if you try to attach an event handler to a group of elements like you were trying to do it won't work because you're saying you want to attach an event handler to [what is basically] an array, which doesn't make sense. So either you loop over the group of elements and attach an event handler to each one (forEach), or you just attach one event handler to the document, then check what the class of the element that was clicked is - if it's the right class, do your thing.
Spyrantis Theodoros
@thodorisanta
Nov 04 2017 12:04
@DanCouper i did it with this
document.addEventListener('click', e => {
  if (e.target.classList.contains('clickable')){

  }
});
Margaret Greaney
@greaneym
Nov 04 2017 12:57
Doing background reading for the rogue like react game, I would like to use pixi.js and I found react-pixi and this code pen example for moving the cursor, https://codepen.io/SkuliOskarsson/pen/ZbJKVW
Can someone tell me how to search for how to create the mask on the moving cursor? Is that a clip path or some other css? thanks for any help.
Margaret Greaney
@greaneym
Nov 04 2017 13:54
I found some very helpful ideas reading the fcc forum on the rogue game but still can't figure out the masking for the pointer, cursor, so would appreciate any hints on how to approach that.
I understand the opacity property on css, so is it some combination of that with a mask? Stumped on this.
will check back later.
Ronique Ricketts
@RoniqueRicketts
Nov 04 2017 14:57
Hi guys. I am wondering does next() in express acts like then() in vanillajs? Will the middleware pass the final result to the next function when the upcoming middleware is called?
Ronique Ricketts
@RoniqueRicketts
Nov 04 2017 15:15
:eyes: where the nerds at? :worried:
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 15:20
the only think I know about using next is that if you dont call it the page will stop working :D
and the circle will keep spining on the top
as far as I know the then its called upon a promise the next doesnt takes any values and its just after doing some process it calls next to the middleware can proceed, just an example
Ronique Ricketts
@RoniqueRicketts
Nov 04 2017 15:22
@tiagocorreiaalmeida lol ok. smh I am a noob at this. I was reading the express documentation to get familiar with it before I run to the backend projects but based on how they describe things. I seems similar to then() that's why I asked if the value is passed
@tiagocorreiaalmeida so what if I wanted my fist middleware to process some info then pass it to another middleware how would that work out?
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 15:24
but somehow that seems possible passing values into next was looking ath the doc and found this
app.get('/user/:id', function (req, res, next) {
  // if the user ID is 0, skip to the next route
  if (req.params.id == 0) next('route');
  // otherwise pass the control to the next middleware function in this stack
  else next(); //
}, function (req, res, next) {
  // render a regular page
  res.render('regular');
});

// handler for the /user/:id path, which renders a special page
app.get('/user/:id', function (req, res, next) {
  res.render('special');
});
this middleware checks if is there an id passed as parameter to the url if so it calls the next and the normal get path will render if there's not id it calls next and renders another page, here's something I atually never used tough
beucase you dont need to go this way
you can simply check if there's an id if so call next if not res.redirect will sned the other to another page
anyway what's the final idea @RoniqueRicketts ?:D
im not the best at node and express and nothing close to that tough
Ronique Ricketts
@RoniqueRicketts
Nov 04 2017 15:32
@tiagocorreiaalmeida thanks. Well I am just here checking out express so I can do the backend challenges. While going through the guide. I saw that function but I guess I overlooked that code last night. I guess it was one of the things I was reading before I fell asleep :)
CamperBot
@camperbot
Nov 04 2017 15:32
roniquericketts sends brownie points to @tiagocorreiaalmeida :sparkles: :thumbsup: :sparkles:
:cookie: 424 | @tiagocorreiaalmeida |http://www.freecodecamp.com/tiagocorreiaalmeida
Spyrantis Theodoros
@thodorisanta
Nov 04 2017 15:32
is there a way to have a setInterval inside a forEach a handle every object inside the array that runs in forEach for the time that i set in interval? like run the first item of the array and after setInterval ends run the second.
Ronique Ricketts
@RoniqueRicketts
Nov 04 2017 15:33
@thodorisanta do you have any code that you've tried so far?
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 15:33
@RoniqueRicketts but give me a pratice example or what you were thinking to tell you how normally I do it
Spyrantis Theodoros
@thodorisanta
Nov 04 2017 15:37
@RoniqueRicketts @rahsheen lets say that i have an array of array = [1,2,3,4] and i have the folowing code. what will happen is that every "case" will run after 1 second. what i want to happen is that i want every "case" to run with diference of 1 second.
   simonMoves.forEach(function(moves) {
   var x = setInterval(function(){
      switch(moves) {
        case 1:
            //do something
            clearInterval(x);
           break;
        case 2:
           //do something
            clearInterval(x);
           break;
        case 3:
           //do something
            clearInterval(x);
           break;
        case 4:
           //do something
            clearInterval(x);
           break;
      }
   }, 1000);
   });
Ronique Ricketts
@RoniqueRicketts
Nov 04 2017 15:39
@tiagocorreiaalmeida I didn't have an actual scenario I just wanted to know if thats one of its functions. eg. 1. middleware check if name and email is sent. middleware 2. look up name and email in database and return the values of the user eg class scores. if its true and then middleware 3 is fired calculating some scores and sending it to the client.
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 15:40
I normal use middleware to check if an user is logged and I place the middleware in the path geth like app.get("/rout", middleware, ((req,res)=>{}); if im not mistaken and in the middlware
I have something like app.use((req,res,next)=>{});
sec
app.use((req,res,next)=>{
 if(something){
 next();
}else{
 res.redirect("/");
}

});
this way I could check if an user is logged if not send im back to the homepage
Ronique Ricketts
@RoniqueRicketts
Nov 04 2017 15:42
@thodorisanta in the switch statement wouldn't you use moved instead of array?
Spyrantis Theodoros
@thodorisanta
Nov 04 2017 15:42
@RoniqueRicketts yeah that was my bad
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 15:42
now about lookup values in the database you make a normal request to the db on the app.get and if there's data on the database response you behave one way if not you can just send the user back to the same page or as you prefer
about the fields behing filled im not sure if its better doing it on the frontend but you can do it in both, in frontendjs check if the fields are filled and do the same in the backend and only after checking if they are filled in the bakcend you do the database request
sec I think I have something like that
router.post("/new",authenticated,(req,res)=>{
    req.checkBody("title","Title is required").notEmpty();
    req.checkBody("options","Options are required").notEmpty();
    let errors = req.validationErrors();
    if(errors){
        res.render("add_poll.hbs",{errors});
    }else{
        let title = req.body.title;
        let optionsSplit = req.body.options.match(/([^,\s][^\,]*[^,\s]*)/g);
        let options= [];
        let author = req.user._id;
       for(let i=0; i <optionsSplit.length; i++){
          let trim = optionsSplit[i].trim();
            if(trim !== "")
            options.push({
                title:trim
            });
        }
        Poll.findOne({title}).then((data)=>{
            if(data){
                req.flash("error","A poll with the same title allready exists");
                res.render("add_poll.hbs");
            }else{
                let newPoll = new Poll({
                    title,
                    author,
                    createdAt:moment().format("Do MMMM YYYY"),
                    options
                });
                newPoll.save().then((data)=>{
                    res.redirect("/poll/"+data._id);
                }).catch((e)=>{
                    console.log(e);
                })
            }
            }).catch((e)=>{
            console.log(e);
        });
    }
});
var authenticated = (req,res,next)=>{
    if(req.isAuthenticated()){
        return next();
    }
    res.redirect("/");
};
@RoniqueRicketts hope this works as a good example tough and to check for the fields im usign a package tough but that doenst matter
Ronique Ricketts
@RoniqueRicketts
Nov 04 2017 15:46
@thodorisanta I tried this in a js repl and it logged the console results. idk if that's what your looking for
var simonMoves = [1, 2, 3, 4]
simonMoves.forEach(function(moves) {
   var x = setInterval(function(){
      switch(moves) {
        case 1:
            //do something
            console.log("hi",1)
            clearInterval(x);
           break;
        case 2:
          console.log("hi",2)
           //do something
            clearInterval(x);
           break;
        case 3:
          console.log("hi",3)
           //do something
            clearInterval(x);
           break;
        case 4:
          console.log("hi",4)
           //do something
            clearInterval(x);
           break;
      }
   }, 1000);
   });
Spyrantis Theodoros
@thodorisanta
Nov 04 2017 15:47
@RoniqueRicketts i want each "case" to run with difference of 1 second from each other
Ronique Ricketts
@RoniqueRicketts
Nov 04 2017 15:50
@tiagocorreiaalmeida nice thank. that makes sense. Lol. I am just 23days old in express anyways. What is best for authentications in express? Its my biggest concern atm
CamperBot
@camperbot
Nov 04 2017 15:50
roniquericketts sends brownie points to @tiagocorreiaalmeida :sparkles: :thumbsup: :sparkles:
api offline
Ronique Ricketts
@RoniqueRicketts
Nov 04 2017 15:51
@thodorisanta unless you want to pass an incrementing count instead of 1000ms
@thodorisanta eg
var simonMoves = [1, 2, 3, 4]
simonMoves.forEach(function(moves) {
   var x = setInterval(function(){
      switch(moves) {
        case 1:
            //do something
            console.log("hi",1)
            clearInterval(x);
           break;
        case 2:
          console.log("hi",2)
           //do something
            clearInterval(x);
           break;
        case 3:
          console.log("hi",3)
           //do something
            clearInterval(x);
           break;
        case 4:
          console.log("hi",4)
           //do something
            clearInterval(x);
           break;
      }
   }, `${moves}000`);
   });
each is fired 1s after the other is fired. Try this and watch each log
Spyrantis Theodoros
@thodorisanta
Nov 04 2017 15:56
@RoniqueRicketts thats smart but the thing is that was an example to prove my point. my actuall cases in my code are strings
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 15:56
@RoniqueRicketts I use passportjs its atually quiet easy after using it one or two times, I never used a local strategy(register users with email and pw) for now but I allready used loging with github/twitter/facebook
and those were simple
not at the first minute but after some hours/days looking at it tough :D
Ronique Ricketts
@RoniqueRicketts
Nov 04 2017 16:01
@thodorisanta then use the index instead of the first parameter for the forEach() remember you can pass 3 parameters to forEach()
Ronique Ricketts
@RoniqueRicketts
Nov 04 2017 16:15
@tiagocorreiaalmeida lol i'll try out passport.js soon then
Ronique Ricketts
@RoniqueRicketts
Nov 04 2017 16:50
@tiagocorreiaalmeida hey man are you still around?
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 16:58
@RoniqueRicketts yeah
AbrisM
@AbrisM
Nov 04 2017 17:35
Hi all
Someone is doing a switch case from above?
Margaret Greaney
@greaneym
Nov 04 2017 18:13
well, I found that the rogue-like fov, field of view is what I was seeking. I thought it was simpler than this, like using a clip path on a pointer and hover, but this is a lot more complicated.
AbrisM
@AbrisM
Nov 04 2017 19:09
Does anyone know that freecode offers a code on switches?
You find them in the basic javascript section
AbrisM
@AbrisM
Nov 04 2017 19:25
Thanks
Could someone explain what a conditional operator is?
The ? : represent what?
alpox
@alpox
Nov 04 2017 19:29
@AbrisM That is called a ternary operator it represents an implicit if/else statement and evaluates to a value based on the given condition
AbrisM
@AbrisM
Nov 04 2017 19:32
Ahhh
alpox
@alpox
Nov 04 2017 19:33
@AbrisM <condition> ? <value if true> : <value if false>
AbrisM
@AbrisM
Nov 04 2017 19:33
Alright but ? stands for and : is just seperating two conditions?
The first part is true, the second false
alpox
@alpox
Nov 04 2017 19:34
@AbrisM no, its like i just showed. The condition comes first, then the ? tells that the condition is over. If the condition evaluated to truthy, the value between ? and : gets used. If the condition was falsy, the value after : gets used
AbrisM
@AbrisM
Nov 04 2017 19:38
That explains it, thank you :D
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 19:55
@alpox saving lives 24/7 :D
alpox
@alpox
Nov 04 2017 19:55
@tiagocorreiaalmeida no man, i have to sleep sometime :D
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 19:57
23/7* my mistake
alpox
@alpox
Nov 04 2017 19:58
@tiagocorreiaalmeida id be so dead if i slept only one hour :D
Naaman Saif
@Naaman-Saif
Nov 04 2017 20:00
Can anybody help me with the challenge Wherefore art thou?
AbrisM
@AbrisM
Nov 04 2017 20:00
Does anyone know what extends application does in JFX?
Naaman Saif
@Naaman-Saif
Nov 04 2017 20:09
??
alpox
@alpox
Nov 04 2017 20:10
@Forlenza just ask your question :)
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 20:10
@Forlenza you just need to paste your code in here and soon as someone is free to look at it they will you dont need to ask ;)
Naaman Saif
@Naaman-Saif
Nov 04 2017 20:11
@alpox I did see above
I need help with Wherefore Art thou Challenge
Where do I start, what do I do? I have no clue atm xD
alpox
@alpox
Nov 04 2017 20:12
@Forlenza thats no question :D please describe your problem
Naaman Saif
@Naaman-Saif
Nov 04 2017 20:13
I just need to know what do I have to do, how do I start with it.I can't understand the problem
alpox
@alpox
Nov 04 2017 20:13
@Forlenza A good starting point is to read about the proposed methods (Object.keys etc.)
Naaman Saif
@Naaman-Saif
Nov 04 2017 20:13
I did, but still have no clue
AbrisM
@AbrisM
Nov 04 2017 20:14
Does anyone know what extends Application does in JFX?
Does it mean more graphics?
Naaman Saif
@Naaman-Saif
Nov 04 2017 20:14
I'll just re read again
alpox
@alpox
Nov 04 2017 20:15

@Forlenza You get an array and an object. The array also contains objects.
The object you got as second argument (source) defines properties ( as example last ) with a value.

You have to look through the array (collection) and look for an object which defines all properties which are defined also in source and also has the same values assigned to the properties like in source.

You have to return that object you found in collection.

To accomplish that you have to loop through the array and for each object in the array you have to compare its properties to the ones from source. If all properties of source are the same as in the object you look at, you found your object and can return it.
Naaman Saif
@Naaman-Saif
Nov 04 2017 20:21
Thank you I did it :D @alpox
CamperBot
@camperbot
Nov 04 2017 20:21
forlenza sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1433 | @alpox |http://www.freecodecamp.com/alpox
alpox
@alpox
Nov 04 2017 20:22
@Forlenza top :D
Np
Naaman Saif
@Naaman-Saif
Nov 04 2017 20:23
Now I'll spend another day just on one challenge lol xD
alpox
@alpox
Nov 04 2017 20:23
Next one? :D
Naaman Saif
@Naaman-Saif
Nov 04 2017 20:24
Yes :P Search and Replace
But I have to get it done fast :( I had started an year ago. And I'll need a job very soon :(
alpox
@alpox
Nov 04 2017 20:25
@Forlenza Does it have to be web?
Naaman Saif
@Naaman-Saif
Nov 04 2017 20:26
Yes
alpox
@alpox
Nov 04 2017 20:26
I'm just asking because i think its better to take your time to study
Naaman Saif
@Naaman-Saif
Nov 04 2017 20:26
Its the only thing I am passionate about xD
alpox
@alpox
Nov 04 2017 20:26
@Forlenza Hahah high five! :D
Oh well me not just web, but programming :D
@Forlenza So for search and replace, the hardest thing is to keep the case sensitivity. There are very different ways to achieve that.
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 20:29
jesus the apis to thestock app look messy
@JLuboff by anyway are you around?
Ronique Ricketts
@RoniqueRicketts
Nov 04 2017 21:02
@tiagocorreiaalmeida what you sent earlier the then("route") allows the program to jump to the next middleware not actually pass information to the next middleware.
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 21:05
can you just me again what part of code?
got confused
:D
I dont know if you do use udemy but if you do there's a really good course I would recommend im evne doing a recap of a part of if that uses sockets to do the new project :D
Ronique Ricketts
@RoniqueRicketts
Nov 04 2017 21:08

@tiagocorreiaalmeida as I said before I am just 2days old in express. :)

```
app.get('/user/:id', function (req, res, next) {
// if the user ID is 0, skip to the next route
if (req.params.id == 0) next('route');
// otherwise pass the control to the next middleware function in this stack
else next(); //
}, function (req, res, next) {
// render a regular page
res.render('regular');
});

// handler for the /user/:id path, which renders a special page
app.get('/user/:id', function (req, res, next) {
res.render('special');
});
```

Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 21:11
if it does next() it will keep going and below you will need to get the same path once again and do other stuff with it tough
app.get('/user/:id', function (req, res, next) {
  // if the user ID is 0, skip to the next route
  if (req.params.id === '0') next('route')
  // otherwise pass the control to the next middleware function in this stack
  else next()
}, function (req, res, next) {
  // render a regular page
  res.render('regular')
})

// handler for the /user/:id path, which renders a special page
app.get('/user/:id', function (req, res, next) {
  res.render('special')
})
in this case code order matters
anyway to render you need to set a express static folder
if you tell me what you wanna do I might be able to be more helpfull since im not the greatest at explaning sadly
Ronique Ricketts
@RoniqueRicketts
Nov 04 2017 21:29
@tiagocorreiaalmeida I thought once you hit that path and the req.parms.id === 0 it jumps to render the special page.
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 21:30
yeah it does
Ronique Ricketts
@RoniqueRicketts
Nov 04 2017 21:30
@tiagocorreiaalmeida well I am not using it in a real life app at the moment I just want to understand if next could pass info to the upcoming middleware. But you make it all clearer I am good with it now.
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 21:30
and the next(); just keeps the code going on and below ther'es another app.get and that one will get the same path but this time you do a render there
To skip the rest of the middleware functions from a router middleware stack, call next('route') to pass control to the next route. NOTE: next('route') will work only in middleware functions that were loaded by using the app.METHOD() or router.METHOD() functions.
To skip the rest of the middleware functions from a router middleware stack, call next('route') to pass control to the next route. NOTE: next('route') will work only in middleware functions that were loaded by using the app.METHOD() or router.METHOD() functions.
btw I never had to use something smiliar as the code above tough
atually a good way of starting using some of those things its start the first backend projects
for the first two you dont need a database
Ronique Ricketts
@RoniqueRicketts
Nov 04 2017 21:35
Yes sir I surely will start my own application but I want to get familiar with authentication first.
I'll try em out when I seem fit enough to code those backend projects
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 21:38
there's a good youtube tutorial I used myself about authentication
it uses mysql not sure if that's your point tough you can watch it and use mongodb on it
like I did
hope it helps you
Ronique Ricketts
@RoniqueRicketts
Nov 04 2017 21:39
@tiagocorreiaalmeida I want to use mysql I read a little about it on w3schools.com
Is helmetjs better than authentication
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 21:39
@RoniqueRicketts then this is the right tutorial for you ;)
it explains expressjs aswell and check for user authentication on route aswell, never used helmetjs and never readed anything about it sorry mate
Ronique Ricketts
@RoniqueRicketts
Nov 04 2017 21:43
ok I am going to watch the video. got a notification that a few of my cryptocoins sold so I have to check in on those :)
alpox
@alpox
Nov 04 2017 21:50
@RoniqueRicketts helmetjs does not at all replace authentication. Use it in addition to keep safe
Ronique Ricketts
@RoniqueRicketts
Nov 04 2017 21:53
so both passport and helmet could run side by side as middleware?
Naaman Saif
@Naaman-Saif
Nov 04 2017 22:15
Can somebody help me with the Pig Latin Challenge?
Isaiah Trembley
@IsaiahCT
Nov 04 2017 22:16
iay on'tday peaksay igpay atinlay
Naaman Saif
@Naaman-Saif
Nov 04 2017 22:16

function translatePigLatin(str) {
  var vowels = ['a','e','i','o','u'];
  var isVowel = 0;
  var consonants = [];
  str = str.split('');
  for(var i = 0;i<vowels.length;i++){
    if(str[0]== vowels[i]){
      str.push('way');
      isVowel= 1;
    }
  }
  if(isVowel == 0){
    for(var j = 0; str[j] === vowels[0]||str[j] === vowels[1]||str[j] === vowels[2]||str[j] === vowels[3]||str[j] === vowels[4]||str[j] === vowels[5];j++){
      consonants.push(str[j]);
    }
  }
  return consonants;
}

translatePigLatin("California");
It Converts Vowels but doesn't convert Consonants
I am sorry let me reassemble it :P

function translatePigLatin(str) {
  var vowels = ['a','e','i','o','u'];
  var isVowel = 0;
  var consonants = [];
  str = str.split('');
  for(var i = 0;i<vowels.length;i++){
    if(str[0]== vowels[i]){
      str.push('way');
      isVowel= 1;
    }
  }
  if(isVowel == 0){
    for(var j = 0; str[j] === vowels[0]||str[j] === vowels[1]||str[j] === vowels[2]||str[j] === vowels[3]||str[j] === vowels[4]||str[j] === vowels[5];j++){
      consonants.push(str[j]);
    }
    str.push(consonants);
    str.push('ay');
    isVowel = 1;
  }
  return str.join('');
}

translatePigLatin("California");
Have a look now
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 22:22
you dont need to make that loop on the toop if the idea is check if the str first value is a vwel there's a thing called indexof that works in arrays, plus Im confused about the second for loop xd
you can search for a value in an array
vowels.indexOf(str[0])
Naaman Saif
@Naaman-Saif
Nov 04 2017 22:25
Let me try
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 22:25
you can check if the result from the above is different from -1, -1 in this case means that it doesnt found the letter
I was about to write the code but tyr to do it yourself if not im here to help
Naaman Saif
@Naaman-Saif
Nov 04 2017 22:28
Okay I get it how to do that for vowels
Now How about Consonants?

function translatePigLatin(str) {
  var vowels = ['a','e','i','o','u'];
  var isVowel = 0;
  var consonants = [];
  str = str.split('');
  if(vowels.indexOf(str[0])== -1){

  }else{
    str.push('way');
  }
  return str.join('');

}
translatePigLatin(eight);
This is done for Vowels now how about consonants?
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 22:33
well for the second option you have to remove the first letter add it to the end and then add ay right?
sorry dont remember the challenge but for what readed seems it right?
Naaman Saif
@Naaman-Saif
Nov 04 2017 22:33
Well it isn't that simple unfortunately :P I would have done in that case
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 22:34
you have to keep going until you fing a vowel that's it?
like cde
would end ecday?
Naaman Saif
@Naaman-Saif
Nov 04 2017 22:34
Yes! Exactly :D
ecdway
*ecday
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 22:35
what's better than an while loop for this?
Naaman Saif
@Naaman-Saif
Nov 04 2017 22:35
Right sorry
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 22:35
you could do it if it was just 1 letter as said above
so if its many a while loop can do it
the only thing you need to do is check right in the top of the loop if the letter is a vowel if so you stop the while loop
if not keep removing first letter push it to the end
hope you get it, gl @Forlenza ;)
Naaman Saif
@Naaman-Saif
Nov 04 2017 22:36
Let me try
Naaman Saif
@Naaman-Saif
Nov 04 2017 22:45

function translatePigLatin(str) {
  var vowels = ['a','e','i','o','u'];
  str = str.split('');
  if(vowels.indexOf(str[0])== -1){
    while(vowels.indexOf(str[0]) == 0){
      str.push(str[0]);
      str.splice(0,1);
    }
    str.push('ay');
  }else{
    str.push('way');
  }
  return str.join('');

}

translatePigLatin("California");
It doesn't work for consonants still :(
iso
@iso1048
Nov 04 2017 22:47
Hi Could I have some feedback on my code for the exact change challenge please (I passed the challenge)
function checkCashRegister(price, cash, cid) {
  var cidArr = [],
      total_cid,
      change = cash-price,
      valuesArr = [0.01, 0.05, 0.10, 0.25, 1.00, 5.00, 10.00, 20.00, 100.00],
      finalArr=[];

  cid.forEach(cur => cidArr.push(cur[1]));
  total_cid = Math.round(cidArr.reduce((a,b) => a+b)*100)/100;

  if (total_cid == change){return 'Closed';}

  for (var i = valuesArr.length-1; i>-1; i--){
    var x = 0;

    while(change/valuesArr[i]>=1 && cid[i][1]>x){
      x+=valuesArr[i];
      change-=valuesArr[i];
      change = Math.round(change*1000)/1000;
    }//while
    if (x !=0){finalArr.push([cid[i][0],x]);}
  }//for 
 return  change == 0 ? finalArr : 'Insufficient Funds';
}
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 22:47
you mean while the result is equal to -1
and not 0
Naaman Saif
@Naaman-Saif
Nov 04 2017 22:50

function translatePigLatin(str) {
  var vowels = ['a','e','i','o','u'];
  var consonants = [];
  str = str.split('');
  if(vowels.indexOf(str[0])== -1){
    while(vowels.indexOf(str[0])!== -1){
      consonants.push(str[0]);
      str.splice(0,1);
    }
    str.push('ay');
  }else{
    str.push('way');
  }
  return consonants;

}

translatePigLatin("California");
I have tried checking if it pushes the letter in the array, Well it doesn't. I still have an empty array
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 22:58
why !== -1?
that means that the first letter is a vowel
in your case you need the oposite you need the loop to run if the first letter is not a vowel you are confusing things
Naaman Saif
@Naaman-Saif
Nov 04 2017 22:59
It gave :D
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 22:59
why you need an array for consoants?
you need to change the word you have
you need to change the str itself
Naaman Saif
@Naaman-Saif
Nov 04 2017 23:00
I had it for testing purpose I'll remove it now
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 23:00
aliforniaCay
btw this is your idea right?
Naaman Saif
@Naaman-Saif
Nov 04 2017 23:00
Done! :D Thank you @tiagocorreiaalmeida <#
CamperBot
@camperbot
Nov 04 2017 23:00
forlenza sends brownie points to @tiagocorreiaalmeida :sparkles: :thumbsup: :sparkles:
:cookie: 426 | @tiagocorreiaalmeida |http://www.freecodecamp.com/tiagocorreiaalmeida
Naaman Saif
@Naaman-Saif
Nov 04 2017 23:00
<3
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 23:00
xd
it was only a simple change in the loop
anytime and congrats one step further next time you will know indexof exists
I recommend check mdn to learn more
Naaman Saif
@Naaman-Saif
Nov 04 2017 23:01
I will xD
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 23:01
left side there's a few methods you can use on arrays
and there's aswell some for strings you just have to search for it
Naaman Saif
@Naaman-Saif
Nov 04 2017 23:01
I always forget things And end up stuck on one challenge for whole day
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 23:01
well the good is that the process of learning is based on that
there's a website called codewars that's about algorithms aswell sometimes I can look to the problem 1 hour and dont figure out a solution I stand up walk 2minutes and while walking the solution comes to my head :D anyway if you want to do somethign and dont know how to do it search for it its the better way
best*
Naaman Saif
@Naaman-Saif
Nov 04 2017 23:07
Okie Boss <3
Naaman Saif
@Naaman-Saif
Nov 04 2017 23:25
I don't get the DNA pairing program like What Do i have to do? I don't get the problem
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 23:29
Base pairs are a pair of AT and CG. Match the missing element to the provided character.
ATCGA
at first
AT
cause letter at missing the t
then letter T missing the A so TA
letter c missing the g so CG
letter G missing the C so CG
GC
and last letter A missing the T so AT
so the pairs are a c with g and a with T
so if the letters its a a you add t
if t you ad
add a*
confusing?
Naaman Saif
@Naaman-Saif
Nov 04 2017 23:30
Alot lol
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 23:31
just an example of code but its the last example I show further you have to figure out alone or you dont learn from it
imagine you have a lot that goes by each letter of the word
and then inside the loop you check what's the letter
 case "G":
        result.push(["G","C"]);
imagine its an G you add a c to it cause its from the gc pair
Naaman Saif
@Naaman-Saif
Nov 04 2017 23:32
If its a G you add C
And if its an A you add T
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 23:32
if its a c
you add a g
if its a t you had a
if its a you add a t ;)
gc works as vice versa aswell
Naaman Saif
@Naaman-Saif
Nov 04 2017 23:32
If its a C you add G
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 23:32
so now knowing this look the examples before coding and see if you get it
alpox
@alpox
Nov 04 2017 23:32
@Forlenza The pairs are A-T and G-C (A gets paired with T, T gets paired with A). You get a string with those letters. For each letter in the string you create an array with the letter and its paired letter.
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 23:33
here's the support you need @Forlenza time for me to take some rest :D
alpox
@alpox
Nov 04 2017 23:33
@tiagocorreiaalmeida Hey! I was going to go to bed! :D
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 23:33
haahha, where you from?maybe sime timezone
same
Naaman Saif
@Naaman-Saif
Nov 04 2017 23:33
@tiagocorreiaalmeida Hahaha go sleep xD
alpox
@alpox
Nov 04 2017 23:33
Switzerland :D
Tiago Correia
@tiagocorreiaalmeida
Nov 04 2017 23:34
never then ;) see you tomorrow
alpox
@alpox
Nov 04 2017 23:35
@tiagocorreiaalmeida Where are you from :D
Naaman Saif
@Naaman-Saif
Nov 04 2017 23:35
Its 4:35 AM here lol xD
alpox
@alpox
Nov 04 2017 23:36
@Forlenza Dude, get some rest :D
Naaman Saif
@Naaman-Saif
Nov 04 2017 23:43
@alpox
I just can't atm xD
alpox
@alpox
Nov 04 2017 23:44
@Forlenza tunnel vision on code? :D
Naaman Saif
@Naaman-Saif
Nov 04 2017 23:53
Whats that???
??