These are chat archives for FreeCodeCamp/HelpJavaScript

31st
Jul 2017
ThePineal
@ThePineal
Jul 31 2017 00:17
can anyone explain to me why when im trying to close the image tag it reads as a string instead of actually closing the tag?
$(document).ready(function(){
  $("#newQuoteBtn").on("click",function(){
    randomNum();
    $(".quote").html(<i class="fa fa-quote-left" aria-hidden="true"></i> + quotes[quoteNum].quote);
    $(".author").html("- "+quotes[quoteNum].author);
  });
Margaret
@Margaret2
Jul 31 2017 00:25
@ThePineal isn't the whole thing inside .html() supposed to be a string? so like .html('<i class=" ..... </i>')
ThePineal
@ThePineal
Jul 31 2017 00:30
is that how its supposed to work? im not sure, i was trying to add the image before the html
Margaret
@Margaret2
Jul 31 2017 00:32
@ThePineal i was just referring to this http://api.jquery.com/html/
Stephen James
@sjames1958gm
Jul 31 2017 00:32
@ThePineal Use single quotes around your <i to </i>
Bryan Reese
@breese8009
Jul 31 2017 00:34

im tryna get this function

function increaseShift(arr){
  let a=[];
for(let i=0; i<arr.length; i++){
  if(arr[i]===32){
  a.push(arr.slice(i,arr.length));
  } 
}
  return a;
}
increaseShift([97, 108, 101, 97, 32, 105, 97, 99, 116, 97, 32, 101, 115, 116]);

to return this...

// [[97, 108, 101, 97],[105, 97, 99, 116, 97],[101, 115, 116]]
currently gettin this...
[ [ 32, 105, 97, 99, 116, 97, 32, 101, 115, 116 ],
  [ 32, 101, 115, 116 ] ]
Stephen James
@sjames1958gm
Jul 31 2017 00:36
@breese8009 I would push onto another array at each loop, then when you hit 32 push that array onto a, and reset the array to []
Bryan Reese
@breese8009
Jul 31 2017 00:37
@sjames1958gm im sorta following what ur sayin, can u show me a small example?
Stephen James
@sjames1958gm
Jul 31 2017 00:37
Or if you want to use slice, then keep track of the last 32 (start with 0) then slice between the each 32
var a = []
var b = []
for (let i = 0; i < arr.length; i++) {
   if (arr[i] == 32) {
      a.push(b);
      b = [];
   } else {
      b.push(arr[i]);
   }
}
After the loop if b is not empty you will need to push
Bryan Reese
@breese8009
Jul 31 2017 00:39
@sjames1958gm let me try, I think i get it
brb
slertka
@slertka
Jul 31 2017 00:46
need help with the 'wherefore art thou challenge' when there are two value pairs
ThePineal
@ThePineal
Jul 31 2017 00:46
@sjames1958gm thanks steve
CamperBot
@camperbot
Jul 31 2017 00:46
thepineal sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8203 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
slertka
@slertka
Jul 31 2017 00:47
function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line

  var sourceKey = Object.keys(source).toString(); // returns last
  // return collection[2][sourceKey]; // returns Capulet;

  for (var i=0; i<collection.length; i++) {
    if (collection[i][sourceKey] == source[sourceKey]) {
      arr.push(collection[i]);
    }
  }

  return arr;


}
here's what i have so far
Stephen James
@sjames1958gm
Jul 31 2017 00:47
@slertka You need to have a second loop over the sourceKey array, don't turn into a string
slertka
@slertka
Jul 31 2017 00:47
@sjames1958gm ok i will try i think i'm just don't know how to loop with objects. let me try
Corentin Whyte
@CorySW
Jul 31 2017 00:48
it already works more or less it's just the array to make it apparent that the person won that's missing and I really am struggling with this I tried "$('.game').toArray" and it doesn't work what should I do?
  $(".AskO").on("click", function() {
   $(".game").on("click", function() {
      $(this).html("O");
      toggle *=-1;
      while(toggle === 1){
         $(".game").on("click", function() {
      $(this).html("X");
      });
         break;
      }
       while(toggle === -1){
         $(".game").on("click", function() {
      $(this).html("O");
      });
          break;
      }
   });

});

$(".AskX").on("click", function() {
   $(".game").on("click", function() {
      $(this).html("X");
      toggle *=-1;
     while(toggle === 1){
         $(".game").on("click", function() {
      $(this).html("O");
      }); 
        break;
   };
      while(toggle === -1){
         $(".game").on("click", function() {
      $(this).html("X");
      });
          break;
      };
});
});
Stephen James
@sjames1958gm
Jul 31 2017 00:50
@slertka Object.keys is an array that you can loop on
slertka
@slertka
Jul 31 2017 00:50
hmm ok would i first loop on the collections array then inside that loop the source keys to find a match?
Corentin Whyte
@CorySW
Jul 31 2017 00:51
its okay I found how to do it
ThePineal
@ThePineal
Jul 31 2017 01:01
var bgColors = [{
  bgColor: 2BBBAD,
  hoverColor: 00695c
},
                {
                  bgColor:9932CC,
                  hoverColor:9400D3
                },
                {
                  bgColor:7FDBFF,
                  hoverColor:0074D9
                },
                {
                  bgColor:2ECC40,
                  hoverColor:01FF70
                },
                {
                  bgColor:FF851B,
                  hoverColor:FFDC00
                },
                {
                  bgColor:,
                  hoverColor:
                }
                }];
somehwere in there is an illegal token, whats taht mean?
Margaret
@Margaret2
Jul 31 2017 01:02
@ThePineal can't combine letters and numbers in JS like you can in CSS, the colors should all be strings
ThePineal
@ThePineal
Jul 31 2017 01:03
can they have the hashcode within the string?
Margaret
@Margaret2
Jul 31 2017 01:03
yeah
ThePineal
@ThePineal
Jul 31 2017 01:04
@Margaret2 thanks
CamperBot
@camperbot
Jul 31 2017 01:04
thepineal sends brownie points to @margaret2 :sparkles: :thumbsup: :sparkles:
:star2: 2862 | @margaret2 |http://www.freecodecamp.com/margaret2
Margaret
@Margaret2
Jul 31 2017 01:04
:smile:
ThePineal
@ThePineal
Jul 31 2017 01:08
can you manipulate the css of multiple elements with js?
using something like $("h2, h5").css
nvm, it is
ThePineal
@ThePineal
Jul 31 2017 01:25
trying to figure out why my background for hovering over an icon is staying that color even when its not hovered
it works correctly before using the button to change the color, but not after
and i used the same options from the css in the js to change the colors
$("body, .btn-primary,.btn-primary:focus, .btn-primary.focus, .btn-primary:active, .btn-primary.active, .btn-primary:visited, .btn-primary:active:hover, .btn-primary.active:hover").css("background-color", bgColors[colorNum].bgColor),
    $(".btn-primary:hover").css("background-color", bgColors[colorNum].hoverColor),
angus
@dangus21
Jul 31 2017 01:37
anyone here experienced with react?
Stephen James
@sjames1958gm
Jul 31 2017 01:59
@dangus21 somewhat
Zac Cassini
@zcassini
Jul 31 2017 02:05
@breese8009 you get your function figured out?
Greg Duncan
@GregatGit
Jul 31 2017 02:09
@dangus21 I have some react xp
Bryan Reese
@breese8009
Jul 31 2017 02:16
@zcassini nope
its annoying me too lol
Yong Lee
@yonglee79
Jul 31 2017 02:17
hello world
Zac Cassini
@zcassini
Jul 31 2017 02:17
@breese8009 what are we trying to do
Bryan Reese
@breese8009
Jul 31 2017 02:19
turn this [97, 108, 101, 97, 32, 105, 97, 99, 116, 97, 32, 101, 115, 116] into this
[[97, 108, 101, 97],[105, 97, 99, 116, 97],[101, 115, 116]] so creating an array of arrays and each array inside is all numbers before 32 ... if that makes sense
Yong Lee
@yonglee79
Jul 31 2017 02:19
wow chat interface looks different
Bryan Reese
@breese8009
Jul 31 2017 02:19
once i figure that out ill have that advanced cease cipher challenge solved
Zac Cassini
@zcassini
Jul 31 2017 02:19
@breese8009 gotcha we splitting hte array on 32
Bryan Reese
@breese8009
Jul 31 2017 02:20
@zcassini correct
its weird, cause i done this before
Zac Cassini
@zcassini
Jul 31 2017 02:20
@breese8009 so think yabout your chunky monkey code,
Bryan Reese
@breese8009
Jul 31 2017 02:20
i dont really have much code as of right now, whatever was posted before ive erased
Zac Cassini
@zcassini
Jul 31 2017 02:22
@breese8009 i would make a recursive function, that keeps chucking the numberes into the last element/array of the accumulator. if it his a 32 it whould start a new array
Bryan Reese
@breese8009
Jul 31 2017 02:26
@zcassini if i cant do it with a for loop, then im not ready to do it with recursive dude lol
i wouldn't know how to go about what u just said
thanks tho
Zac Cassini
@zcassini
Jul 31 2017 02:34
@breese8009 came up with this, i would refactorit maybe
const chunkinator = (xs, acc =[[]]) => {
  if (!xs.length) {
    return acc
  } else {
    if (xs[0] == 32) {
      acc.push([])
      return chunkinator(xs.slice(1), acc)
    } else {
      let last = acc[acc.length - 1].push(xs[0])
      newAcc = acc.slice(0, acc.length -1).push(last)
      return chunkinator(xs.slice(1), acc)
    }
  }
}

chunkinator([97, 108, 101, 97, 32, 105, 97, 99, 116, 97, 32, 101, 115, 116])
=> [ [ 97, 108, 101, 97 ],
  [ 105, 97, 99, 116, 97 ],
  [ 101, 115, 116 ] ]
Zac Cassini
@zcassini
Jul 31 2017 02:40
@breese8009 a lil destructuring...
const chunkinator = ([x, ...xs], acc =[[]]) => {
  if (!x) {
    return acc
  } else {
    if (x == 32) {
      acc.push([])
      return chunkinator(xs, acc)
    } else {
      let last = acc[acc.length - 1].push(x)
      newAcc = acc.slice(0, acc.length - 1).push(last)
      return chunkinator(xs, acc)
    }
  }
}
insouciantone
@insouciantone
Jul 31 2017 02:41
@abhinav-thinktank Yes, it fixed it. I'm not sure what doesn't make sense about that? It works exactly as intended as far as I can tell. It randomly selects a piece of the array and places it into the quote box.
Zac Cassini
@zcassini
Jul 31 2017 02:45
@breese8009 move it into a switch
const chunkinator = ([x, ...xs], acc =[[]]) => {
  switch (true) {
    case !x:
      return acc
    case x === 32:
      acc.push([])
      return chunkinator(xs, acc)
    default:
      const last = acc[acc.length -1].push(x)
      acc.slice(0, acc.lenth -1).push(last)
      return chunkinator(xs, acc)
  }
}
Stephen James
@sjames1958gm
Jul 31 2017 02:46
@breese8009 Here is a way using slice like you started
function chunker(arr)
   let a = [];
   let l = 0;
   arr.forEach((e, i) => {
      if (e == 32) {
         a.push(arr.slice(l, i ));
         l = i + 1;
      }
});
if  (l < arr.length - 1) a.push(arr.slice(l);
return arr;
}
Zac Cassini
@zcassini
Jul 31 2017 02:57
@breese8009 add in the missing javascript array methods
Array.prototype.pushIt = function (x) { this.push(x); return this }
Array.prototype.last = function () { return this[this.length - 1] }
Array.prototype.allButLast = function () { return this.slice(0, this.length - 1) }


const chunkinator = ([x, ...xs], acc = [[]]) => {
  switch (true) {
    case !x:       return acc
    case x === 32: return chunkinator(xs, acc.pushIt([]))
    default:       return chunkinator(xs, acc.allButLast().pushIt(acc.last().pushIt(x)))
  }
}
Abhishek Kumar Tiwari
@abhkt2611
Jul 31 2017 02:58
arr1
.concat(arr2)
.filter(
item => !arr1.includes(item) || !arr2.includes(item) can any one tell me what is the meaning of => in above lines?
Zac Cassini
@zcassini
Jul 31 2017 02:59
it is an arrow fuction
insouciantone
@insouciantone
Jul 31 2017 03:14
Im having problems with the HTML5 Geolocation api being really unstable. I don't understand why it works sometimes but not other times. Can someone help me out please?
Ragnorak
@Rrak
Jul 31 2017 03:16
@insouciantone can you send your code or project's link
Claudio Restifo
@Marmiz
Jul 31 2017 03:18

@insouciantone the user can block the usage of geolocation:

The geolocation API allows the user to provide their location to web applications if they so desire. For privacy reasons, the user is asked for permission to report location information.

Therefore it's common to put a case that the app may need it in order to work:

if ("geolocation" in navigator) {
  /* geolocation is available */
} else {
  /* geolocation IS NOT available */
}
insouciantone
@insouciantone
Jul 31 2017 03:19
@Rrak It's not an issue with my code. it's across any application that uses the api. Even on the FCC website "Get Geolocation Data" challenge. Sometimes it shows the lat and lon values and sometimes it doesn't. When I go to https://html5demos.com/geo it says failed.
For reference i'm trying this over both chromium and firefox on linux mint 18.1
CallMeOrange
@EgnaroDev
Jul 31 2017 03:22
@insouciantone https://html5demos.com/geo works but if you say it failed then you didn't allow location access
insouciantone
@insouciantone
Jul 31 2017 03:23
@EgnaroDev I explicitly did. It asks me if I would like to allow it and I do.
CallMeOrange
@EgnaroDev
Jul 31 2017 03:23
Hm..
insouciantone
@insouciantone
Jul 31 2017 03:24
Sometimes it works and other times it doesn't. I'm not sure why it's so unstable.
I get the same results even if I attempt to do it over a mobile data hotspot.
Christopher McCormack
@cmccormack
Jul 31 2017 03:39
@insouciantone in Chrome Dev Tools you can click on More tools in the Customize drop-down and select Sensors - this will allow you to fake your location if your local geolocation isn't working too well. I had an issue where Chrome wasn't picking it up for me for a while so I had to use a test location to troubleshoot APIs
Zac Cassini
@zcassini
Jul 31 2017 03:43
@breese8009 looking at @sjames1958gm version game me an idea to make mine simpler
Array.prototype.pushIt = function (x) { this.push(x); return this }

const chunkinator = ([x, ...xs], chunk = [], acc = []) => {
  switch (true) {
    case !x:       return acc.pushIt(chunk)
    case x === 32: return chunkinator(xs, [], acc.pushIt(chunk))
    default:       return chunkinator(xs, chunk.pushIt(x), acc)
  }
}

chunkinator([97, 108, 101, 97, 32, 105, 97, 99, 116, 97, 32, 101, 115, 116])
insouciantone
@insouciantone
Jul 31 2017 03:53
@cmccormack Cool. This'll work fine. I don't actually care that my location data isn't being shared properly but not being able to test my application was driving me crazy.
@cmccormack Thanks!
CamperBot
@camperbot
Jul 31 2017 03:53
insouciantone sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1081 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Jul 31 2017 03:53
np
Nick Gray
@nicholasnbg
Jul 31 2017 04:05
@insouciantone I have the same problem, made life difficult working on that project
insouciantone
@insouciantone
Jul 31 2017 04:22
@nicholasnbg Yeah it's a real pain in the ass. Oh well, at least spoofing it works fine.
Tarun Khandelwal
@Delwalt
Jul 31 2017 04:24

Hi Guys I need help with my JS code. I am new to JS so pardon my silly mistakes.

What I am trying to do is create a function which can be called many times with the different parameter but some how I could not get it right need your help with code.

function add_field_a(inputId,inputType) {

                                                                var inputValue = document.getElementById(inputId).value;
                                                                if (!inputValue == '') {
                                                                    var inputCount = $(".xtra_inputs").children().length;
                                                                    var inputMarkup = '<div class="input-group"  id="input-grp' +  inputId + '" style="margin-bottom:5px;"><input type="text" class="form-control" placeholder="Please enter number" name="'inputType + inputCount '"  value="' + inputType + '"><div class="input-group-addon"><i class="fa fa-remove label-icon" onclick="remove_me(' + inputCount + ');" title="remove"></i></div></div>';
                                                                    if (inputCount < 4) {
                                                                        $('#xtra_inputs').append(inputMarkup);
                                                                        $(inputId).val('');
                                                                        if (inputCount == 3) {
                                                                            $('.addInput').hide();
                                                                        }
                                                                    } else {
                                                                        return false;
                                                                    }
                                                                }

                                                            }
Nick Gray
@nicholasnbg
Jul 31 2017 04:25
I think this line is wrong:
if (!inputValue == '')
should be
if(inputValue !== '')
Tarun Khandelwal
@Delwalt
Jul 31 2017 04:27

@nicholasnbg thanks Nick I will correct that. But what I checked I am getting error at

var inputMarkup =

in this complete line.

CamperBot
@camperbot
Jul 31 2017 04:27
delwalt sends brownie points to @nicholasnbg :sparkles: :thumbsup: :sparkles:
:cookie: 334 | @nicholasnbg |http://www.freecodecamp.com/nicholasnbg
Nick Gray
@nicholasnbg
Jul 31 2017 04:28
you are missing a '+' before inputType in the nave value about halfway through
and a + after input count in the same bit
Tarun Khandelwal
@Delwalt
Jul 31 2017 04:31
@nicholasnbg Thanks Nick I knew I was making some silly mistake. Thank you very much you saved lots of time.
CamperBot
@camperbot
Jul 31 2017 04:31
delwalt sends brownie points to @nicholasnbg :sparkles: :thumbsup: :sparkles:
:warning: delwalt already gave nicholasnbg points
Nick Gray
@nicholasnbg
Jul 31 2017 04:31
no problem mate good luck with the rest of it :)
Tarun Khandelwal
@Delwalt
Jul 31 2017 05:00
Hi anyone here
I need help calling a function parameter inside $('')
if I directly write it will become string.
without the commas its not working
Christopher McCormack
@cmccormack
Jul 31 2017 05:08
can you show an example?
create a method for doubly linked list called reverse which reverses the list in place.
var Node = function(data, prev) {
  this.data = data;
  this.prev = prev;
  this.next = null;
};
var DoublyLinkedList = function() {
  this.head = null;
  this.tail = null;
};
Can someone help me with this interview challenge? Thank you.
Christopher McCormack
@cmccormack
Jul 31 2017 05:19
@Jeffchiucp looks like you just have to add a few methods like add and reverse - I would assume reverse needs to iterate the chain and swap the prev and next
Jeff Chiu
@Jeffchiucp
Jul 31 2017 05:23
@cmccormack great. I will add the methods
Tiago Correia
@tiagocorreiaalmeida
Jul 31 2017 08:02
Good morning everyone
kumquatfelafel
@kumquatfelafel
Jul 31 2017 08:15
hi
Blauelf
@Blauelf
Jul 31 2017 08:17
Good morning
Darth Skywalker
@AdiSkywalker
Jul 31 2017 08:17
@Blauelf :wave:
mingumckevin
@mingumckevin
Jul 31 2017 08:20
Good evening Everyone.
Blauelf
@Blauelf
Jul 31 2017 08:26
@mingumckevin Evening? Down Under or Kiwi?
mingumckevin
@mingumckevin
Jul 31 2017 08:26
Kiwi , North Island.
@Blauelf
Blauelf
@Blauelf
Jul 31 2017 08:29
Wow, that's pretty much as far as it could get.
Darth Skywalker
@AdiSkywalker
Jul 31 2017 08:29
I am past evening 1.30 am :P
but of previous day.. (or same day, whichever you prefer)
mingumckevin
@mingumckevin
Jul 31 2017 08:30
Rip sleep.
Blauelf
@Blauelf
Jul 31 2017 08:34
Here in Europe, not so far from Greenwich and its zero longitude, I cannot even imagine what living somewhat near the International Date Line implies. But there's probably plenty of Pacific around.
Tiago Correia
@tiagocorreiaalmeida
Jul 31 2017 08:40
im doing the pomodoro clock exercise is it a good idea to ue a while to make a countdown or ue a foreach basedo n the amount of seconds?I always start confusef when a new exercise comes to me
GeorgeII
@GeorgeII
Jul 31 2017 08:49
@tiagocorreiaalmeida it's interesting, how are you going to make a countdown by while loop?
as for me, I used setInterval function
kumquatfelafel
@kumquatfelafel
Jul 31 2017 08:53
What would be regex for matching one or more of any character, but only more if it's the same character again?
/.{1,}/g for example greedily takes whole thing (understand why, but want something along these lines except, you know... not this.) :p
Blauelf
@Blauelf
Jul 31 2017 08:53

With async and await, a while loop might work, but I don't like those.

I'd use setInterval as well.

GeorgeII
@GeorgeII
Jul 31 2017 08:55
@Blauelf is it normally if setInterval functions lag?
Blauelf
@Blauelf
Jul 31 2017 08:55
@kumquatfelafel Do a group and use a backreference, like /(.)\1/ (matches any double character but newline)
kumquatfelafel
@kumquatfelafel
Jul 31 2017 08:55
@Blauelf ahhh... thanks
CamperBot
@camperbot
Jul 31 2017 08:55
kumquatfelafel sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4548 | @blauelf |http://www.freecodecamp.com/blauelf
GeorgeII
@GeorgeII
Jul 31 2017 08:56
I use 4 setIntervals and sometimes they lag
Blauelf
@Blauelf
Jul 31 2017 08:58
@GeorgeII setTimeout and setInterval enqueue a function call if they see that it is due. This means you have two lags: setTimeout or setInterval don't check the timers continuously, and there is a time between enqueueing the function call and its execution.
Markus Kiili
@Masd925
Jul 31 2017 08:59
@GeorgeII En event happens after provided amount of time, and the callback is placed on the task queue and executed in its turn. So those times are effectively minimum times after which the callback is executed.
kumquatfelafel
@kumquatfelafel
Jul 31 2017 08:59
@Blauelf is there a way to make that backreference greedy?
Blauelf
@Blauelf
Jul 31 2017 09:00
The second is due to JavaScript allowing only a single thread, and that one picks functions from a queue, processes them, goes on to the next. That queue is also where your events go, they are not processed immediately.
@kumquatfelafel Like /(.)\1+/? (now: two or more of the same)
kumquatfelafel
@kumquatfelafel
Jul 31 2017 09:01
gotcha. thanks!
Works perfectly.
Abhinav Mishra
@abhinav-m
Jul 31 2017 09:02
can someone mind reviewing this for me, i dont care about the ui right now, my app structure is awful i feel. what would be a good way to approach react apps?
someone mind*
GeorgeII
@GeorgeII
Jul 31 2017 09:03
@Blauelf @Masd925 got it ty
CamperBot
@camperbot
Jul 31 2017 09:03
georgeii sends brownie points to @blauelf and @masd925 :sparkles: :thumbsup: :sparkles:
Kelechi Chinaka
@ke1echi
Jul 31 2017 09:03
where can i improve my regex skills @Blauelf @kumquatfelafel
CamperBot
@camperbot
Jul 31 2017 09:03
:star2: 4549 | @blauelf |http://www.freecodecamp.com/blauelf
:star2: 4356 | @masd925 |http://www.freecodecamp.com/masd925
Blauelf
@Blauelf
Jul 31 2017 09:04
@kelechy There are a few sites on the wiki
I like regexr.com for a regex playground, but others are probably as good.
Abhinav Mishra
@abhinav-m
Jul 31 2017 09:06
@AdiSkywalker Hey you mind reviewing this now, i just added the highlight functionality, also how do you recommend i learn to "structure" my react app
Kelechi Chinaka
@ke1echi
Jul 31 2017 09:06
o cool..the power of regex is huge
Blauelf
@Blauelf
Jul 31 2017 09:11
With great power comes great responsibility. While Regular Expressions sometimes are much faster than doing something on your own, they can sometimes slow you down really hard. In some cases, you can refactor the regular expressions, in others try to avoid them.
Kelechi Chinaka
@ke1echi
Jul 31 2017 09:14
so are you saying regex is bad?
Stephen James
@sjames1958gm
Jul 31 2017 09:15
@abhinav-thinktank I think DataSection component doesn't add any value in that it is only a div and another component.
Other than that the structure is not bad.
Abhinav Mishra
@abhinav-m
Jul 31 2017 09:15
@sjames1958gm allright, what about the <Buttons>
@sjames1958gm i could have used normal buttons inside the Header section
not sure if creating a component added any value
Stephen James
@sjames1958gm
Jul 31 2017 09:16
@abhinav-thinktank Yeah, I was thinking that Buttons didn't seem to add much either beyond <button>
Abhinav Mishra
@abhinav-m
Jul 31 2017 09:17
what would be a good strategy to approach any react app
kumquatfelafel
@kumquatfelafel
Jul 31 2017 09:17
@kelechy more like a double-edged sword I think.
Abhinav Mishra
@abhinav-m
Jul 31 2017 09:17
i was seeing someone build a calculator in react he said I always start by thinking what is my state and when will it change and build downwards from that
Blauelf
@Blauelf
Jul 31 2017 09:17
@kelechy Not bad. Very powerful, but sometimes very compute-intense, depending on your use.
Stephen James
@sjames1958gm
Jul 31 2017 09:22
@abhinav-thinktank That is not a bad strategy. Redux was designed to somewhat separate state from structure.
Laying out your design, and then identifying components should be part of the process. And be willing to toss out stuff that ultimately is not useful as a component - such as Button.
Derek B. McIntire
@derekbmcintire
Jul 31 2017 09:27

Hey everyone... I am working on my FCC Tic Tac Toe game App. Up to this point I haven't done any coding outside of CodePen, and so I am trying to work on this on my computer when I'm offline. I have separated my code into html, css and javascript files, linked them in the head of my html file, but when I open in in FireFox, the javascript doesn't do anything. I can see that the html and css work fine, and the same code works perfectly in CodePen. I have checked and re-checked my syntax and it seems to be right, but I must be missing something to make this work. Here is my code that's in my html file linking to everything.

<head>
<link rel="stylesheet" type="text/css" href="tictactoe.css"></link>
<script type="text/javascript" src="js/script.js"></script>
</head>

Also, I have tried putting the script file in the same folder as index.html and not using js/ and it makes no difference
Markus Kiili
@Masd925
Jul 31 2017 09:28
@derekbmcintire You can look at the page source code on the browser and see if the script is really imported.
Abhinav Mishra
@abhinav-m
Jul 31 2017 09:28
@sjames1958gm allright , for the next project ill try structuring the app first on paper, and then proceding with building it.thanks!
CamperBot
@camperbot
Jul 31 2017 09:28
abhinav-thinktank sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8204 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Derek B. McIntire
@derekbmcintire
Jul 31 2017 09:29
I did that and couldn't find any javascript code there @abhinav-thinktank
so I'm not sure why it's not importing?
Abhinav Mishra
@abhinav-m
Jul 31 2017 09:29
@derekbmcintire ?...
kumquatfelafel
@kumquatfelafel
Jul 31 2017 09:29
@abhinav-thinktank mis@, I'm assuming.
Abhinav Mishra
@abhinav-m
Jul 31 2017 09:29
oh i guess you meant to ask someone else..
@kumquatfelafel i always want felafels after reading your username
damn you.
Derek B. McIntire
@derekbmcintire
Jul 31 2017 09:30
@abhinav-thinktank sorry, meant to tag @Masd925
Abhinav Mishra
@abhinav-m
Jul 31 2017 09:30
is fine :D
kumquatfelafel
@kumquatfelafel
Jul 31 2017 09:30
@abhinav-thinktank if it makes you feel any better, there's no such thing. :p
Abhinav Mishra
@abhinav-m
Jul 31 2017 09:32
@kumquatfelafel well.. it sounds the same and theres a dish similar to it :D
here which i love
kumquatfelafel
@kumquatfelafel
Jul 31 2017 09:32
fair nuff.
Markus Kiili
@Masd925
Jul 31 2017 09:33
@derekbmcintire Try to check if the script is run. For example by console.logging something.
kumquatfelafel
@kumquatfelafel
Jul 31 2017 09:33
and besides, felafels are like falafels but 4 better.
Markus Kiili
@Masd925
Jul 31 2017 09:34
@derekbmcintire If it is run, it might be executed before the dom is ready. Then you should place it at the end of body or use window load event or jQuery document ready, to make it sure that the script runs after the page is ready.
Abhinav Mishra
@abhinav-m
Jul 31 2017 09:35
@kumquatfelafel what exactly are those
kumquatfelafel
@kumquatfelafel
Jul 31 2017 09:35
what are what???
Derek B. McIntire
@derekbmcintire
Jul 31 2017 09:36
@Masd925 hmmm it is saying there is a syntax error - SyntaxError: missing ( before formal parameters
Markus Kiili
@Masd925
Jul 31 2017 09:37
@derekbmcintire ok. Post the code if you can't fix it on your own.
EpicTriffid
@EpicTriffid
Jul 31 2017 09:37

var sum = 0;

function sumAll(arr) {
for (var i = 0; i < arr.length; i++) {
return sum += arr[i];
}
}

sumAll([10,5,1]);

Hi all. Very simple question but why isn't this code generating 16?
kumquatfelafel
@kumquatfelafel
Jul 31 2017 09:38
@EpicTriffid return halts function immediately, "returning" specified value
Blauelf
@Blauelf
Jul 31 2017 09:38
I'd take a Falafel Dürüm :D
Darth Skywalker
@AdiSkywalker
Jul 31 2017 09:38

@abhinav-thinktank

Hey you mind reviewing this now, i just added the highlight functionality, also how do you recommend i learn to "structure" my react app

Well.. There is no straightforward heuristic about that.. Howerver, Angular folks have explained the points one needs to consider while identifying data flow patterns in the application. Take a look

https://www.youtube.com/watch?v=bVI5gGTEQ_U

EpicTriffid
@EpicTriffid
Jul 31 2017 09:38
@kumquatfelafel FFS, yes, you're right
Darth Skywalker
@AdiSkywalker
Jul 31 2017 09:38
It's not about react but the principles still hold true
EpicTriffid
@EpicTriffid
Jul 31 2017 09:38
@kumquatfelafel Thanks
CamperBot
@camperbot
Jul 31 2017 09:38
epictriffid sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 560 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
kumquatfelafel
@kumquatfelafel
Jul 31 2017 09:38
@EpicTriffid np
Derek B. McIntire
@derekbmcintire
Jul 31 2017 09:38
here is a pen, I just copied and pasted the JS code https://codepen.io/derekbmcintire/pen/rzeNZx?editors=0011 @Masd925
Blauelf
@Blauelf
Jul 31 2017 09:39
@EpicTriffid Don't use global variables. Return after your loop.
EpicTriffid
@EpicTriffid
Jul 31 2017 09:39
@Blauelf Why not global variables?
Blauelf
@Blauelf
Jul 31 2017 09:39
What happens if your function is called twice?
kumquatfelafel
@kumquatfelafel
Jul 31 2017 09:39
:point_up: this too. When multiple calls are made, sum is not reset
Kelechi Chinaka
@ke1echi
Jul 31 2017 09:40
your loop runs only once @EpicTriffid
EpicTriffid
@EpicTriffid
Jul 31 2017 09:41
I've been doing the previous prjects so long (twitch, wiki etc) that my arithmatic JS has gone out of the window
Blauelf
@Blauelf
Jul 31 2017 09:41
@EpicTriffid You probably built a function to be able to reuse the code. If you want to reuse the code, you probably want it to always start at 0. That's why you would want to give your function a local sum variable.
kumquatfelafel
@kumquatfelafel
Jul 31 2017 09:41
In any case, even though you could technically fix by adding sum = 0 at beginning there isn't really any need for it to be global here.
Tiago Correia
@tiagocorreiaalmeida
Jul 31 2017 09:42
@GeorgeII thanks just saw it now
CamperBot
@camperbot
Jul 31 2017 09:42
tiagocorreiaalmeida sends brownie points to @georgeii :sparkles: :thumbsup: :sparkles:
:cookie: 8 | @georgeii |http://www.freecodecamp.com/georgeii
EpicTriffid
@EpicTriffid
Jul 31 2017 09:43
@Blauelf Right, that makes sense. Im currently working on on "summing all numbers in a range" and was trying to break it down to its most basic format before i build back up to using something like reduce
@Blauelf Which i can actually get to work, when the values are given in a seperate array, rather than as part of the function
Abhinav Mishra
@abhinav-m
Jul 31 2017 09:44
and besides, felafels are like falafels but 4 better. @kumquatfelafel
@AdiSkywalker allright, ill go through that once, ty!
CamperBot
@camperbot
Jul 31 2017 09:44
abhinav-thinktank sends brownie points to @adiskywalker :sparkles: :thumbsup: :sparkles:
:cookie: 292 | @adiskywalker |http://www.freecodecamp.com/adiskywalker
Blauelf
@Blauelf
Jul 31 2017 09:45
I still want falafel dürüm. But does not seem to come to me. Miracles have become unreliable :/
Stephen James
@sjames1958gm
Jul 31 2017 09:45
@derekbmcintire You should move your script tags to the end of <body>
then wrap that map at the end in
document.onload = function() {
// put .map here
};
Darth Skywalker
@AdiSkywalker
Jul 31 2017 09:45
@sjames1958gm That's not a right syntax :laughing:
it should be
function main(){
}

window.onload = main;
onload doesn't take a callback..
It should be a function.
Blauelf
@Blauelf
Jul 31 2017 09:47
Why not document.addEventListener("load", main)? Would allow for multiple event listeners to attach.
Darth Skywalker
@AdiSkywalker
Jul 31 2017 09:47
@Blauelf What if load event triggers before this line executes?
kumquatfelafel
@kumquatfelafel
Jul 31 2017 09:48

I mean, this is all well and good, but shouldn't it be

public static void main (String[] args){
}

:o

:p
Blauelf
@Blauelf
Jul 31 2017 09:48
@AdiSkywalker Interesting question. Is that different in case of onload?
Stephen James
@sjames1958gm
Jul 31 2017 09:49
@kumquatfelafel No
int main(int argc, char** argv)
kumquatfelafel
@kumquatfelafel
Jul 31 2017 09:49
lol
Derek B. McIntire
@derekbmcintire
Jul 31 2017 09:49
I've been trying window.onload = function() {
} @AdiSkywalker and it wasn't working... will try yours. I now have the script tag in a footer in index.html
Darth Skywalker
@AdiSkywalker
Jul 31 2017 09:50
@Blauelf You can do that with window.addEventListener but not document.addEventListener
Reason -: Docs..
Derek B. McIntire
@derekbmcintire
Jul 31 2017 09:50
sorry, also not sure how to properly write code in this chat
Darth Skywalker
@AdiSkywalker
Jul 31 2017 09:50
"load" event is targeted for window and not document
So... Using that becomes unreliable
@Blauelf
Kelechi Chinaka
@ke1echi
Jul 31 2017 09:51
this regex is head banging @Blauelf @kumquatfelafel
Derek B. McIntire
@derekbmcintire
Jul 31 2017 09:51
I am still getting "SyntaxError: missing ( before formal parameters" in the console
Darth Skywalker
@AdiSkywalker
Jul 31 2017 09:52
@derekbmcintire Can you share your code? (preferably codepen)
Blauelf
@Blauelf
Jul 31 2017 09:53
@AdiSkywalker load event exists for both, but window.onload seems to wait for external resources.
Derek B. McIntire
@derekbmcintire
Jul 31 2017 09:53
shared above... here it is again: https://codepen.io/derekbmcintire/pen/rzeNZx?editors=0011 @AdiSkywalker
Blauelf
@Blauelf
Jul 31 2017 09:53
@kelechy Which regex?
Derek B. McIntire
@derekbmcintire
Jul 31 2017 09:53
images don't work because they are only local on my computer
kumquatfelafel
@kumquatfelafel
Jul 31 2017 09:54
@kelechy which regex?
kumquatfelafel @kumquatfelafel perches from a chandelier, in suspense
Markus Kiili
@Masd925
Jul 31 2017 09:56
@Blauelf I think document load event has some compatibility problems in comparison to window load.
Darth Skywalker
@AdiSkywalker
Jul 31 2017 09:56
@derekbmcintire it says the images are not found... x.jpg and y.jpg
Kelechi Chinaka
@ke1echi
Jul 31 2017 09:56
how does regex count..maybe lower case char
kumquatfelafel
@kumquatfelafel
Jul 31 2017 09:57
you mean like [a-z]?
Kelechi Chinaka
@ke1echi
Jul 31 2017 09:57
yea
kumquatfelafel
@kumquatfelafel
Jul 31 2017 09:57
when you say count... in what context?
Kelechi Chinaka
@ke1echi
Jul 31 2017 09:58
may i need to count all lowercase char in a str
kumquatfelafel
@kumquatfelafel
Jul 31 2017 09:58
Do you, e.g, want to match a certain number of a given character?
Derek B. McIntire
@derekbmcintire
Jul 31 2017 09:59
@AdiSkywalker yes, they are only local on my computer. The app works fine in codepen (different codepen), but I am trying to make it work locally on my computer offline and having trouble getting the javascript to import. html and css display fine, but javascript isn't there.
Darth Skywalker
@AdiSkywalker
Jul 31 2017 09:59
@derekbmcintire : I changed you xImg and oImg to point to the same image urls you're using in your css and it seems to work
xImg = "http://www.iconsdb.com/icons/preview/black/x-mark-xxl.png",
oImg ="https://alphabetletters.org/alphabet-letter-downloads/bold-letters/alphabet-letter-o.jpg",
Blauelf
@Blauelf
Jul 31 2017 09:59
@kelechy What do you mean with "count"? Regular expressions return a match, and possibly groups, but not numbers. Or do you want to match if there is a specific number of a specific character within a string?
Stephen James
@sjames1958gm
Jul 31 2017 09:59
@kelechy replace all non-lowercase with "" and then .length of the result is one way
Derek B. McIntire
@derekbmcintire
Jul 31 2017 10:00
@AdiSkywalker I just made this codepen so someone could see my javascript code and make sure the syntax was okay, which I'm not getting any major erros and seems like it should work. So my problem is figuring out how to link it to my index.html correctly.
Darth Skywalker
@AdiSkywalker
Jul 31 2017 10:00
This video explains the process of codepen to local.. But if you don't wanna be bothered by that, there is always export button at the bottom right of codepen
EpicTriffid
@EpicTriffid
Jul 31 2017 10:01
right, next problem, why wont this return 1?
Derek B. McIntire
@derekbmcintire
Jul 31 2017 10:01
ahh thanks, I will check this out.
EpicTriffid
@EpicTriffid
Jul 31 2017 10:01

function sumAll(arr) {
var start = Math.min(arr);
return start;
}

sumAll([1, 4]);

Markus Kiili
@Masd925
Jul 31 2017 10:02
@EpicTriffid Math.min doesn't work on arrays just like that.
Darth Skywalker
@AdiSkywalker
Jul 31 2017 10:02
@EpicTriffid var start = Math.min.apply(null, arr);
Kelechi Chinaka
@ke1echi
Jul 31 2017 10:02
:smile: i need to learn this beast @sjames1958gm @Blauelf @kumquatfelafel
Darth Skywalker
@AdiSkywalker
Jul 31 2017 10:02
or var start = Math.min(arr[0],arr[1]);
kumquatfelafel
@kumquatfelafel
Jul 31 2017 10:02
:point_up: There's something called a spread operator which you could potentially use
Darth Skywalker
@AdiSkywalker
Jul 31 2017 10:02
since you can be certain that the array has only 2 elements
Derek B. McIntire
@derekbmcintire
Jul 31 2017 10:06
@AdiSkywalker wow, I didn't even know about the export option. That makes it easier, I will have to make an attempt to set up an offline app from scratch with something simpler. thanks.
CamperBot
@camperbot
Jul 31 2017 10:06
derekbmcintire sends brownie points to @adiskywalker :sparkles: :thumbsup: :sparkles:
:cookie: 293 | @adiskywalker |http://www.freecodecamp.com/adiskywalker
Darth Skywalker
@AdiSkywalker
Jul 31 2017 10:06
@derekbmcintire :+1:
EpicTriffid
@EpicTriffid
Jul 31 2017 10:24
@Masd925 @AdiSkywalker Thankyou guys. Very helpful
CamperBot
@camperbot
Jul 31 2017 10:24
epictriffid sends brownie points to @masd925 and @adiskywalker :sparkles: :thumbsup: :sparkles:
:cookie: 294 | @adiskywalker |http://www.freecodecamp.com/adiskywalker
:star2: 4357 | @masd925 |http://www.freecodecamp.com/masd925
EpicTriffid
@EpicTriffid
Jul 31 2017 10:45
Can anyone help me with figuring out the reduce function? I really do not understand how it works in place of a for loop
How would i convert this:

function sumAll(arr) {
var start = Math.min(arr[0], arr[1]);
var end = Math.max(arr[0], arr[1]);
var sum = 0;
for (var i = start; i <= end; i++) {
sum += i;
}
return sum;
}

sumAll([1, 4]);

into a reduce function?
Im stumped
Markus Kiili
@Masd925
Jul 31 2017 10:47
@EpicTriffid Not the best place to use reduce. You would need to make an array that has all the numbers from min to max and then use reduce with a callback function with return acc+curr.
Blauelf
@Blauelf
Jul 31 2017 10:48
@EpicTriffid You would have to create an array first, containing all the numbers to sum up. In this case, that's a lot overhead without any benefit, but for the sake of learning...
  var numbers = [];
  for (var i = start; i <= end; i++) {
    numbers.push(i);
  }
  return numbers.reduce(function(acc, curr) { return acc + curr; }, 0); // 0 for initial value of sum
EpicTriffid
@EpicTriffid
Jul 31 2017 10:48
@Masd925 But the FCC exercise referenced it to use
kumquatfelafel
@kumquatfelafel
Jul 31 2017 10:48
@EpicTriffid Reduce accumulates based upon operations performed upon values of the array. You would have to actually get an array with all the values in given range on which to call reduce. You're already going through all the values so you might as well just sum it in original loop
EpicTriffid
@EpicTriffid
Jul 31 2017 10:49
I managed to get reduce to work when i made my own arrays, so was so confused when they were telling me to use it
Markus Kiili
@Masd925
Jul 31 2017 10:49
@EpicTriffid Yeah. One place to learn how to use reduce. Instead of using such a loop to construct the array, you could just count the sum instead.
EpicTriffid
@EpicTriffid
Jul 31 2017 10:50
@Blauelf @kumquatfelafel @Masd925 So in this exercise I did it the right way?
kumquatfelafel
@kumquatfelafel
Jul 31 2017 10:51
makes more sense than using reduce.
Markus Kiili
@Masd925
Jul 31 2017 10:51
@EpicTriffid Yes.
EpicTriffid
@EpicTriffid
Jul 31 2017 10:51
Thank god
kumquatfelafel
@kumquatfelafel
Jul 31 2017 10:51
:p
Markus Kiili
@Masd925
Jul 31 2017 10:51
@EpicTriffid Another way is to use math but it doesn't teach programming too much.
EpicTriffid
@EpicTriffid
Jul 31 2017 10:52
@Masd925 Math I can't do!
Blauelf
@Blauelf
Jul 31 2017 10:52

@EpicTriffid Sort of... I prefer the O(1)\mathcal{O}(1) solution

  return (arr[0] + arr[1]) * (1 + Math.abs(arr[0] - arr[1])) / 2;

No loop required :P

EpicTriffid
@EpicTriffid
Jul 31 2017 10:53
Kinda worries me actually. When it comes to the project side of the exercises, like the twitch and the wiki, I have little trouble working out what to do, but when it comes to this logical side, with maths, I get completely stumped
Blauelf
@Blauelf
Jul 31 2017 10:53
(arr[0] + arr[1]) / 2 is the average value, 1 + Math.abs(arr[0] - arr[1]) is the number of values.
No magic involved, just re-formulating the problem.
EpicTriffid
@EpicTriffid
Jul 31 2017 10:54
@Blauelf Mind blown
kumquatfelafel
@kumquatfelafel
Jul 31 2017 10:54
Or if you want a no-"Math" alternative...
return (arr[0] + arr[1]) * (1 + ((arr[0] - arr[1]) < 0? -(arr[0] - arr[1]): arr[0] - arr[1]))/2;
EpicTriffid
@EpicTriffid
Jul 31 2017 10:55
@kumquatfelafel faints
kumquatfelafel
@kumquatfelafel
Jul 31 2017 10:55
@EpicTriffid generally speaking, having code this unreadable would be a bad thing. :p
I'm not even sure if I have the right number of parentheses in the right places
EpicTriffid
@EpicTriffid
Jul 31 2017 10:56
@kumquatfelafel In the professional world, is this logical side of js more important, or the side that deals with design?
kumquatfelafel
@kumquatfelafel
Jul 31 2017 11:06
I'm probably not the one to ask :laughing:
Though I imagine it depends on what kind of work you're looking for.
Markus Kiili
@Masd925
Jul 31 2017 11:10
@EpicTriffid Depends on the job. However, it is good to have a hunch of all things related to software development.
zealsham
@zealsham
Jul 31 2017 11:40
how do you implement role based authentication and does anybody knows areasonalble resource to learn how to use babel
Darth Skywalker
@AdiSkywalker
Jul 31 2017 12:02

@zealsham

For Authentication - Passport
For Authorization (i.e role based auth) ACL

You need to use them both in combination
a7n007
@a7n007
Jul 31 2017 12:39
function spinalCase(str) {

  str=str.replace(/ /g,'-');
  str=str.replace(/_/g,'-');
  str=str.splice(str.indexOf(/[A-Z]/g),0,"-");
  str=str.toLowerCase();
  return str;
}

spinalCase('This Is Spinal Tap');
can anyone help me fix the above code
shows str.splice is not a function
Marianissimus
@Marianissimus
Jul 31 2017 12:50
@a7n007 splice works only for arrays, so you either convert that string into an array, or you find another method
a7n007
@a7n007
Jul 31 2017 12:53
oh
so what can i do
Marianissimus
@Marianissimus
Jul 31 2017 12:54
now ask yourself, why did you want to splice it in the first place?
don't you just need to replace spaces with - and capitals with lowercase?
a7n007
@a7n007
Jul 31 2017 12:56
@Marianissimus i want to insert ' - ' before capitals
Marianissimus
@Marianissimus
Jul 31 2017 12:58
you can do it entirely with regex and replace
Michiel
@MichielHuijse
Jul 31 2017 13:00
@a7n007 first of all you can eliminate the 'str =' to clean it up a bit ;)
sorry that is incorrect, you need the '='
a7n007
@a7n007
Jul 31 2017 13:06
@MichielHuijse i didnt understand
Michiel
@MichielHuijse
Jul 31 2017 13:08
@a7n007 you need to find a manner to put a space before a Capital letter.
this: str=str.splice(str.indexOf(/[A-Z]/g),0,"-"); is the line that you need to modify, after that it is a question of finding the right order of operations.
a7n007
@a7n007
Jul 31 2017 13:22
@MichielHuijse but to use splice i need to split on what condition will i split the string
Michiel
@MichielHuijse
Jul 31 2017 13:46
@a7n007 you dont need splice or split. Just insert a space before a capital letter in the string.
a7n007
@a7n007
Jul 31 2017 14:02
got it thanks
Michael Baxter
@baxt01
Jul 31 2017 14:02
instead of using splice why not try looking at str.replace(' ', '-');
a7n007
@a7n007
Jul 31 2017 14:03
yeah i just did this : str = str.replace(/([a-z])([A-Z])/g, '$1 $2')
Michael Baxter
@baxt01
Jul 31 2017 14:03
cool :)
a7n007
@a7n007
Jul 31 2017 14:03
and it worked
Guderian Raborg
@hypercuber
Jul 31 2017 14:15
Can someone help me create more circles as you increase the width or height or canvas?
https://codepen.io/hypercuber/pen/vJLMQq
a7n007
@a7n007
Jul 31 2017 14:18
@hypercuber in your for (var i = 0; i < cirArr.length+window.innerWidth+window.innerHeight; i++)
Guderian Raborg
@hypercuber
Jul 31 2017 14:21
Didn't work for me... Thanks anyways.
a7n007
@a7n007
Jul 31 2017 14:26
@hypercuber why didnt it work
sorry missed out a %10 out there
@hypercuber in your for (var i = 0; i < cirArr.length+window.innerWidth%10+window.innerHeight%10; i++)
Guderian Raborg
@hypercuber
Jul 31 2017 14:29
Script to busy. I think I need to change the two for loops or whatnot. Thanks for the feedback.
Guderian Raborg
@hypercuber
Jul 31 2017 14:49
I have another question. Why does the elements in array say undefined?
Stephen James
@sjames1958gm
Jul 31 2017 14:57
@hypercuber The function that you call in push doesn't return anything
@hypercuber Since it appears to be a constructor - call it with new
Guderian Raborg
@hypercuber
Jul 31 2017 14:59
@sjames1958gm I forgot to say "new Sq()" rather than "Sq()"
@sjames1958gm Thanks
CamperBot
@camperbot
Jul 31 2017 14:59
hypercuber sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8205 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 31 2017 14:59
@hypercuber yw
Guderian Raborg
@hypercuber
Jul 31 2017 14:59
@sjames1958gm yw?
Stephen James
@sjames1958gm
Jul 31 2017 15:00
you're welcome
Guderian Raborg
@hypercuber
Jul 31 2017 15:00
Oh
:P
Stephen James
@sjames1958gm
Jul 31 2017 15:00
:+1:
Guderian Raborg
@hypercuber
Jul 31 2017 15:04
Is using canvas.width, window.innerWidth, and innerWidth all the same here right?
zealsham
@zealsham
Jul 31 2017 15:07
  var mongoose = require("mongoose");


mongoose.connect("mongodb://localhost/accelerar");

// the mongoose connection 
var db = mongoose.connection ;


//handle any error that arises when trying to connect with the database
db.on('error', console.error.bind(console, 'connection error:could not connect'));
how come no datbase is created when i run "show dbs " in nmongo shell
@AdiSkywalker any resource on how to achieve that, tutorial video or anything
Abhinav Mishra
@abhinav-m
Jul 31 2017 15:12
doesn't learnyoumongo teach you how to create a db?
i can't recall it..
Ronique Ricketts
@RoniqueRicketts
Jul 31 2017 15:15
@abhinav-thinktank it's on their website.
Abhinav Mishra
@abhinav-m
Jul 31 2017 15:15
@RoniqueRicketts good
Christopher McCormack
@cmccormack
Jul 31 2017 15:38
:wave: hello
sabahatullah
@sabahatullah
Jul 31 2017 15:38
can we load/ fetch an element that output content on Ajax request?
Jason Luboff
@JLuboff
Jul 31 2017 15:38
@cmccormack Yo
Christopher McCormack
@cmccormack
Jul 31 2017 15:39
@JLuboff hey!
Jason Luboff
@JLuboff
Jul 31 2017 15:39
Whats up
Christopher McCormack
@cmccormack
Jul 31 2017 15:40
I think I just about finished my dungeon project, at least the mechanics and gameplay - I"m going to upload - will you beta test?
Jason Luboff
@JLuboff
Jul 31 2017 15:40
Sure thing
Seid Akhmed Agitaev
@agitaev
Jul 31 2017 15:42
hey martians, how to convert values of an array to Boolean?
Jason Luboff
@JLuboff
Jul 31 2017 15:43
What are the values to begin with?
Christopher McCormack
@cmccormack
Jul 31 2017 15:44
https://mackville.net/react/dungeon/ - it's still a bit laggy on input, something I'll have to dig deeper into React to resolve. Some mobs can be tough but there should be enough items and health to be able to get to the next floor and beat the boss. Only two levels currently, easy to add more though.
Seid Akhmed Agitaev
@agitaev
Jul 31 2017 15:45
@JLuboff, i need to find the falsy values in an array, and there's a hint to convert them to boolean values firstly
Jason Luboff
@JLuboff
Jul 31 2017 15:45
Are you working on Falsey Bouncer?
Seid Akhmed Agitaev
@agitaev
Jul 31 2017 15:45
@JLuboff yup
Jason Luboff
@JLuboff
Jul 31 2017 15:46
@dactice Ok, so you need to filter your array. Look at the links they provide, especially the Boolean object link
Seid Akhmed Agitaev
@agitaev
Jul 31 2017 15:46
is there any way to check NaN values except isNaN function?
Ronique Ricketts
@RoniqueRicketts
Jul 31 2017 15:46
Guys this might sound dumb but idk how to make find prime numbers.
Jason Luboff
@JLuboff
Jul 31 2017 15:46
@cmccormack I'm attacking a zombie, but then it says I started a new journey even though I still have health?
Blauelf
@Blauelf
Jul 31 2017 15:46
@dactice NaN equals nothing, not even itself. You can use that.
Christopher McCormack
@cmccormack
Jul 31 2017 15:47
@JLuboff the scroll should read from the top as latest
Jason Luboff
@JLuboff
Jul 31 2017 15:47
@cmccormack Oh nevermind...it scrolls opposite lol
Seid Akhmed Agitaev
@agitaev
Jul 31 2017 15:47
@JLuboff i'm working on betaFCC, there is no link
Christopher McCormack
@cmccormack
Jul 31 2017 15:47
@JLuboff I'll tweak a bit of that afterwards
Seid Akhmed Agitaev
@agitaev
Jul 31 2017 15:47
@Blauelf thank you, let me give it a try
CamperBot
@camperbot
Jul 31 2017 15:47
dactice sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4550 | @blauelf |http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Jul 31 2017 15:47
@dactice And if you're on falsy bouncer, understanding truthy/falsy makes the solution really short. No need to check for individual falsy values.
Seid Akhmed Agitaev
@agitaev
Jul 31 2017 15:48
@JLuboff but thanks anyway, i'll find links
CamperBot
@camperbot
Jul 31 2017 15:48
dactice sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2118 | @jluboff |http://www.freecodecamp.com/jluboff
Christopher McCormack
@cmccormack
Jul 31 2017 15:49
@RoniqueRicketts you can iterate over all the odd numbers starting from 3 (2 is an implied prime) and if that number is only divisible by itself and 1, then it's a prime and can be added to your list of primes. The check to ensure it's a prime can be as simple as dividing the number by each found prime number and verifying the remainder is not 0
Jason Luboff
@JLuboff
Jul 31 2017 15:50
@cmccormack Ah man...the boss killed me
Christopher McCormack
@cmccormack
Jul 31 2017 15:51
he's tough :D
Jason Luboff
@JLuboff
Jul 31 2017 15:51
Works well. Don't see any real issues. Only thing I would recomend adding is a Key for the symbols.
Christopher McCormack
@cmccormack
Jul 31 2017 15:51
Do you think if I replaced the icons on the board with the icons in the status bar that would be key enough?
Trying to keep it as intuitive as possible
so Atk and Def icons at top are same as the pickups
Jason Luboff
@JLuboff
Jul 31 2017 15:52
Ya that would work
Christopher McCormack
@cmccormack
Jul 31 2017 15:52
ok great idea
Any other improvements?
Jason Luboff
@JLuboff
Jul 31 2017 15:53
What about showing the health of the enemy so you can determine if you should keep attacking or not?
Guderian Raborg
@hypercuber
Jul 31 2017 15:53
@RoniqueRicketts You can do an array of primes and check if each number is a prime or product of primes.
Thayyeb salim
@Thayyebsalim
Jul 31 2017 15:53
Can I get some critiques for my Local Weather API
Thanks in advance
https://codepen.io/Thayyeb_Itachi/pen/vZvoGY
Guderian Raborg
@hypercuber
Jul 31 2017 15:54
Is there a less laggy way to make squares without overlap? https://codepen.io/hypercuber/pen/vJLMQq?editors=0010
Christopher McCormack
@cmccormack
Jul 31 2017 15:54
@JLuboff haha I thought about that but also kind of liked how risky it was to try, wanted the player to discover they can't just bash stuff and win
Jason Luboff
@JLuboff
Jul 31 2017 15:54
@cmccormack ...but thats all I want to do!
Christopher McCormack
@cmccormack
Jul 31 2017 15:54
Maybe a compromise, like a enemy health state, not just the numbers?
@JLuboff haha
Jason Luboff
@JLuboff
Jul 31 2017 15:54
That could work
Ronique Ricketts
@RoniqueRicketts
Jul 31 2017 15:54
@cmccormack @hypercuber will try these Thanks
sabahatullah
@sabahatullah
Jul 31 2017 15:55
anyone help please

On this page https://www.bupa.co.uk/care-services/care-homes/mugdock-house-glasgow
when I add
$('body').load('https://www.bupa.co.uk/care-services/care-homes/funding .mod-funding-calculator')

it brings in the required element but in broken state. can someone help me why is that? its crucial for my learning

I add via browser console*
Christopher McCormack
@cmccormack
Jul 31 2017 15:56
@Thayyebsalim I like it! It's quirky and provides good information
Thayyeb salim
@Thayyebsalim
Jul 31 2017 15:57
Thank you @cmccormack
CamperBot
@camperbot
Jul 31 2017 15:57
thayyebsalim sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1084 | @cmccormack |http://www.freecodecamp.com/cmccormack
Pieter Stokkink
@forkerino
Jul 31 2017 15:57
:wave:
Abhinav Mishra
@abhinav-m
Jul 31 2017 15:58
@Thayyebsalim the middle div is empty for me
Christopher McCormack
@cmccormack
Jul 31 2017 15:58
@hypercuber what do you mean laggy? Have you ran your algorithm in a loop to see if it's actually slow?
Abhinav Mishra
@abhinav-m
Jul 31 2017 15:58
@Thayyebsalim some error in the console too
Christopher McCormack
@cmccormack
Jul 31 2017 15:59
@forkerino hiya! @JLuboff was beta testing my React dungeon - you want to try it too? https://mackville.net/react/dungeon/ looking for some feedback
Jason Luboff
@JLuboff
Jul 31 2017 15:59
@forkerino Yo
Abhinav Mishra
@abhinav-m
Jul 31 2017 15:59
@cmccormack damn thats pretty cool
@cmccormack :D
Christopher McCormack
@cmccormack
Jul 31 2017 16:00
@abhinav-thinktank thank you :) been working on it far too long
CamperBot
@camperbot
Jul 31 2017 16:00
cmccormack sends brownie points to @abhinav-thinktank :sparkles: :thumbsup: :sparkles:
:cookie: 445 | @abhinav-thinktank |http://www.freecodecamp.com/abhinav-thinktank
Abhinav Mishra
@abhinav-m
Jul 31 2017 16:00
@cmccormack how long exactly
im guessing this will take up most of my time
Pieter Stokkink
@forkerino
Jul 31 2017 16:00
@cmccormack does it work on mobile? If not, pm it and I'll look later....
Christopher McCormack
@cmccormack
Jul 31 2017 16:00
@forkerino will do thanks. Probably wont work too well on mobile but I did add buttons to move the player just in case
CamperBot
@camperbot
Jul 31 2017 16:00
cmccormack sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2902 | @forkerino |http://www.freecodecamp.com/forkerino
sabahatullah
@sabahatullah
Jul 31 2017 16:01

@sabahatullah
anyone help please

On this page https://www.bupa.co.uk/care-services/care-homes/mugdock-house-glasgow
when I add
$('body').load('https://www.bupa.co.uk/care-services/care-homes/funding .mod-funding-calculator')
via browser console
it brings in the required element but in broken state. can someone help me why is that? its crucial for my learning

Abhinav Mishra
@abhinav-m
Jul 31 2017 16:01
@cmccormack i love the messages that popup
Christopher McCormack
@cmccormack
Jul 31 2017 16:02
@abhinav-thinktank looks like I started it back in early June, but I didn't dedicate as much time to this one each day as I had my other projects
Pieter Stokkink
@forkerino
Jul 31 2017 16:02
@Thayyebsalim one temp has "is", the other doesn't.
Christopher McCormack
@cmccormack
Jul 31 2017 16:02
There was always a hurdle I didn't feel like tackling for a few days
Abhinav Mishra
@abhinav-m
Jul 31 2017 16:02
@cmccormack man.. im never gonna be able to complete my projects on time
Christopher McCormack
@cmccormack
Jul 31 2017 16:03
@abhinav-thinktank there isn't a real deadline is there? haha
Abhinav Mishra
@abhinav-m
Jul 31 2017 16:03
i had set one for myself :|
but react is taking more time than expected
the frontend section wasn't really a problem
hope i can make something half decent as this
lol
Christopher McCormack
@cmccormack
Jul 31 2017 16:05
@abhinav-thinktank if I had to do it again I would probably have done it in canvas. I thought it would be fun to try and do it within html elements but that can be tricky trying to get everything to look good
Pieter Stokkink
@forkerino
Jul 31 2017 16:05
@cmccormack yeah, gameplay on mobile is crap, will look at it later on my laptop.
Jason Luboff
@JLuboff
Jul 31 2017 16:06
Damn thats harsh... hahaha
Thayyeb salim
@Thayyebsalim
Jul 31 2017 16:06
@forkerino thanks for pointing that out
CamperBot
@camperbot
Jul 31 2017 16:06
thayyebsalim sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2903 | @forkerino |http://www.freecodecamp.com/forkerino
Abhinav Mishra
@abhinav-m
Jul 31 2017 16:06
@cmccormack i will do it in react :D and somehow (hopefully) make it decent looking
Christopher McCormack
@cmccormack
Jul 31 2017 16:06
@abhinav-thinktank you can use react and canvas together no problem
Pieter Stokkink
@forkerino
Jul 31 2017 16:07
Lol, not meant in a mean way
Abhinav Mishra
@abhinav-m
Jul 31 2017 16:07
arghh, @cmccormack those are two things im not familiar with yet
Christopher McCormack
@cmccormack
Jul 31 2017 16:07
@forkerino haha he's right though @JLuboff when I just tested it it kept zooming in and out while trying to quickly move
Pieter Stokkink
@forkerino
Jul 31 2017 16:07
Codepen just resizes randomly when trying to press the btns
With my fingers
Christopher McCormack
@cmccormack
Jul 31 2017 16:08
it's not codepen
it's probably the browser
Pieter Stokkink
@forkerino
Jul 31 2017 16:08
Ah, yeah
Christopher McCormack
@cmccormack
Jul 31 2017 16:08
@abhinav-thinktank canvas isn't too bad, make a quick project to play with it, kind of fun
Pieter Stokkink
@forkerino
Jul 31 2017 16:09
Mixed up with the other thing i was testing
Abhinav Mishra
@abhinav-m
Jul 31 2017 16:10
@cmccormack yeah, i actually have it on my to - play - with list
Christopher McCormack
@cmccormack
Jul 31 2017 16:10
@abhinav-thinktank I used this playlist, it was pretty good. https://www.youtube.com/watch?v=EO6OkltgudE&list=PLpPnRKq7eNW3We9VdCfx9fprhqXHwTPXL
Abhinav Mishra
@abhinav-m
Jul 31 2017 16:10
@cmccormack nice. thanks!
CamperBot
@camperbot
Jul 31 2017 16:10
abhinav-thinktank sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1085 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Jul 31 2017 16:10
@forkerino haha sorry if I interrupted your testing!
Pieter Stokkink
@forkerino
Jul 31 2017 16:11
No problem!
Christopher McCormack
@cmccormack
Jul 31 2017 16:11
@abhinav-thinktank unfortunately all the React videos I watched didn't really explain the key concepts of React very well, the Facebook documentation was a lot better for that
Abhinav Mishra
@abhinav-m
Jul 31 2017 16:12
@cmccormack i know , RIGHT
@cmccormack the egghead ones were more like do this and this happens BAM!
then i read the facebook documentation to actually understand stuff
Jason Luboff
@JLuboff
Jul 31 2017 16:39
Manipulating dynamically added DOM content after the page has already loaded is a pain in the ass..
Kelechi Chinaka
@ke1echi
Jul 31 2017 16:49
so if i need to learn react i should use the docs instead of videos @cmccormack @forkerino
Christopher McCormack
@cmccormack
Jul 31 2017 16:51
@kelechy I would probably recommend reading the docs first for most things, then watching videos to see how it is all implemented. Everyone learns differently, but there are a lot of videos where they only cover little bits but don't explain why everything works or why something is better than something else
Kelechi Chinaka
@ke1echi
Jul 31 2017 16:53
ok
Tomasz
@Tgralak
Jul 31 2017 17:38

function mutation(arr) {
  var firstElement = arr[0].toLowerCase();
  var secondElement = arr[1].toLowerCase();
  for (var i = 0; i < secondElement.length; i++) {
    if (firstElement.indexOf(secondElement[i]) === -1) {
      return false;
    }
    else {
      return true;
    }
  }
}

mutation(["hello", "hey"]);
can anyone help me with this challenge? "hello" and "hey" keeps returning true instead of false, every other check is ok
Jason Luboff
@JLuboff
Jul 31 2017 17:39
I don't know why I deleted my post. But ya, you need to only return true outside your loop
Tomasz
@Tgralak
Jul 31 2017 17:39
@JLuboff why its like that?
@JLuboff it still doesn't work
@JLuboff ok sorry, it works now, but i dont know why
Jason Luboff
@JLuboff
Jul 31 2017 17:40
Becuase return stops all code execution.
So the first test, would be h === h which is true, so it stops right there
Sicne we want to check every letter of the second string inside the first, we need to only return true if all of those letters match
Tomasz
@Tgralak
Jul 31 2017 17:41
ok, thank You, it sounds simple :)
@JLuboff thanks
CamperBot
@camperbot
Jul 31 2017 17:41
tgralak sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2119 | @jluboff |http://www.freecodecamp.com/jluboff
Jason Luboff
@JLuboff
Jul 31 2017 17:42
:+1:
Jahid Bin Kibria
@jahidbinkibria
Jul 31 2017 17:45
why it doesn't work
fetch('https://ipinfo.io', {
method:"GET"
})
.then(result => console.log(result))
but it does
$.getJSON('https://ipinfo.io', function(data){
console.log(data)
})
scarejar
@scarejar
Jul 31 2017 17:45
anyone use libraries for modules ?
debating on rollup or browserify..
zealsham
@zealsham
Jul 31 2017 17:50

why is my express router middle ware not working for some routes
in my app.js i required the following files

   var routes = require("./routes/index");
var users = require("./routes/users");
var king = require("./routes/kings")

and also inititalized them as middlewares

  app.use('/',routes);
app.use('/users',users);
app.use('/about',king)

in king.js i have

 var express = require('express');

var router = express.Router()

router.get('/about', function (req,res){
    res.send("hello every one")
})

module.exports = router

in my index.js i have

var express = require('express');

var router =  express.Router();

router.get('/',function(req,res){
    res.send('index');
})

module.exports = router;

and finally in my users.js i have

var express = require('express');

var router =  express.Router();

router.get('/loft',function(req,res){
    res.render('mrequest');
})

module.exports = router;
Jason Luboff
@JLuboff
Jul 31 2017 17:52
@zealsham You might have better luck in the HelpBackEnd room Just fyi. But
Dan Couper
@DanCouper
Jul 31 2017 17:56
@scarejar Rollup is the simplest, for a lot of stuff it Just Works. We've found some issues with it, mainly relating to sticking very close to the spec - it is unforgiving of weirdly named modules for example (eg NPM modules called my-module.js, literally the .js in the name). Any of Webpack/Rollup/Browserify will work fine, rollup is possibly the simplest, Browserify is older and a bit slow, but is better known, Webpack is current de facto standard but config for it tends to become a massive pain in the ass.
Jason Luboff
@JLuboff
Jul 31 2017 17:57
@DanCouper I've found that one of the node modules I'm using (yelp-fusion), the module folder name is call-me-maybe
Dan Couper
@DanCouper
Jul 31 2017 17:57
:joy:
Jason Luboff
@JLuboff
Jul 31 2017 17:58
It took me a minute to figure out what was going on haha
scarejar
@scarejar
Jul 31 2017 18:08
guess I'll go with Rollup
@DanCouper thanks!
CamperBot
@camperbot
Jul 31 2017 18:08
scarejar sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:cookie: 848 | @dancouper |http://www.freecodecamp.com/dancouper
Stephen James
@sjames1958gm
Jul 31 2017 18:15
@jahidbinkibria fetch doesn't assume json
Stephen James
@sjames1958gm
Jul 31 2017 18:22

@jahidbinkibria

fetch('https://ipinfo.io', {
  method:"GET", 
  headers: new Headers({
    'Accept': 'application/json'
  })
})
.then(result => result.json())
.then(data => console.log(data))

Or use https://ipinfo.io/json

Jason Luboff
@JLuboff
Jul 31 2017 18:27
@sjames1958gm With jQuery (or vanilla js).. how can I change the text of a dynamically created span element? I was able to add a click event to a class but once inside that, I'm trying to use .html() but it's not working. It can't find the element.
$(document).on('click', '.going', (e) => {
    e.preventDefault();
    $.ajax({
      type: 'POST',
      url: e.target.href,
      success: data => {
     console.log($(e.target.id + 'Count').html()); //This returns undefined
      $(e.target.id + 'Count').html(data.count);
      }
    })
  })
But e.target.id does return the ID
Stephen James
@sjames1958gm
Jul 31 2017 18:29
@JLuboff Don't you need "#"
Jason Luboff
@JLuboff
Jul 31 2017 18:29
....maybe...
Christopher McCormack
@cmccormack
Jul 31 2017 18:29
@JLuboff try e.currentTarget
Stephen James
@sjames1958gm
Jul 31 2017 18:29
@JLuboff "#" + e.target.id + 'Count'
Jason Luboff
@JLuboff
Jul 31 2017 18:30
@sjames1958gm Hmm..nope doesn't like that. @cmccormack Let me try that
Stephen James
@sjames1958gm
Jul 31 2017 18:31
This is an id e.target.id + 'Count'?
Christopher McCormack
@cmccormack
Jul 31 2017 18:31
he's right though you need the # selector
Stephen James
@sjames1958gm
Jul 31 2017 18:31
This is going to select the element that was clicked on e.currentTarget
Jason Luboff
@JLuboff
Jul 31 2017 18:31
Yes it is. And I agree that I was missing the # but still doesn't target it
Or atleast it doesn't like it
Christopher McCormack
@cmccormack
Jul 31 2017 18:32
and I may have currentTarget backwards, I forget which one selects the element you click and which one is the the handler
Stephen James
@sjames1958gm
Jul 31 2017 18:32
@cmccormack Yeah, I am not sure which is which you may be correct.
Jason Luboff
@JLuboff
Jul 31 2017 18:32
e.currentTarget returns the link that was clicked
Christopher McCormack
@cmccormack
Jul 31 2017 18:33

currentTarget

Identifies the current target for the event, as the event traverses the DOM. It always refers to the element to which the event handler has been attached, as opposed to event.target which identifies the element on which the event occurred.
so target is probably what you want
Darth Skywalker
@AdiSkywalker
Jul 31 2017 18:33
@JLuboff forget depending on event and being confused about target vs currentTarget stick to "this"
Jason Luboff
@JLuboff
Jul 31 2017 18:34
e.target returns the same thing as currentTarget
Darth Skywalker
@AdiSkywalker
Jul 31 2017 18:34
"#"+this.id+"Count"
Jason Luboff
@JLuboff
Jul 31 2017 18:34
@AdiSkywalker I believe I had tried this before and wasn't running into any luck but let me try again
Christopher McCormack
@cmccormack
Jul 31 2017 18:34
not sure this will work correctly if using ES6 arrow function will it?
Jason Luboff
@JLuboff
Jul 31 2017 18:34
Ya this.id doesn't work
Darth Skywalker
@AdiSkywalker
Jul 31 2017 18:35
Nope! You need to use function in this case
Stephen James
@sjames1958gm
Jul 31 2017 18:35
@JLuboff Go to your inspector and see if what you think the ID is and what it really is match.
Darth Skywalker
@AdiSkywalker
Jul 31 2017 18:35
its always good practice to have event listeners as functions (as opposed to arrow function) for your get instance of target element in "this"
Christopher McCormack
@cmccormack
Jul 31 2017 18:36
@JLuboff does your id exist in the DOM when this ajax call is run?
Jason Luboff
@JLuboff
Jul 31 2017 18:36
@sjames1958gm They do match...one potential issue is the ID has spaces....
Darth Skywalker
@AdiSkywalker
Jul 31 2017 18:36
$(document).on('click', '.going', function(e) {
Christopher McCormack
@cmccormack
Jul 31 2017 18:36
it's sad I keep finding reasons I can't use arrow functions, they seem to only be good for simple chaining but not much more
Jason Luboff
@JLuboff
Jul 31 2017 18:37
@cmccormack I have a couple of ajax calls. The first will load the data, and the second is the one above
Eunice Park
@eunicode
Jul 31 2017 18:37
I have a dumb, newbie question here. I created an array of image URLS and a random number variable. I then used the DOM (idk if that's the right way to phrase it) to add a random background image. However, my background remains blank. https://codepen.io/eunipa/pen/GvprjX?editors=1010
Stephen James
@sjames1958gm
Jul 31 2017 18:37
@cmccormack general use in .map, .filter, .reduce .
Darth Skywalker
@AdiSkywalker
Jul 31 2017 18:37
@cmccormack the Inner Ajax request is where arrow function proves it's importances perfectly
Avoid arrow functions where "this" is important
Stephen James
@sjames1958gm
Jul 31 2017 18:38
@eunipa Your variable (array reference is inside quotes and not resolved)
Darth Skywalker
@AdiSkywalker
Jul 31 2017 18:38
for example defining a prototype method
Christopher McCormack
@cmccormack
Jul 31 2017 18:39
@AdiSkywalker I agree but then it's all mixed anyhow, why not just use normal anon functions. I only use arrow functions now mainly when using map/filter/reduce type work
Stephen James
@sjames1958gm
Jul 31 2017 18:39
@eunipa Try template strings - they are good for this
document.body.style.backgroundImage = `url('${bgImg[randomNumber]}')`;
Eunice Park
@eunicode
Jul 31 2017 18:39
@sjames1958gm Thanks! I was just about to ask if this an instance where I would need to use template literals!
CamperBot
@camperbot
Jul 31 2017 18:39
eunipa sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8206 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Jason Luboff
@JLuboff
Jul 31 2017 18:39
!!!!! I got it!!!!
Stephen James
@sjames1958gm
Jul 31 2017 18:39
@eunipa :)
Jason Luboff
@JLuboff
Jul 31 2017 18:39
Woooo
It was becuase of the damn spaces in the ID plus missing the # selection
@sjames1958gm @cmccormack @AdiSkywalker Thanks!
CamperBot
@camperbot
Jul 31 2017 18:40
jluboff sends brownie points to @sjames1958gm and @cmccormack and @adiskywalker :sparkles: :thumbsup: :sparkles:
:cookie: 301 | @adiskywalker |http://www.freecodecamp.com/adiskywalker
:star2: 1088 | @cmccormack |http://www.freecodecamp.com/cmccormack
:star2: 8207 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Darth Skywalker
@AdiSkywalker
Jul 31 2017 18:40
@cmccormack I believe that's the main usecase for arrow functions..
also you'd find arrow functions useful in a nested chain of promises
@JLuboff :+1:
Eunice Park
@eunicode
Jul 31 2017 18:50
@sjames1958gm Seriously, thank you so much. I think I'm a little closer to understanding this. Sorry to bother, but how come bgImg[randomNumber] isn't a string? Or how come the variable (the array bgImg) isn't resolved? Is it bc an array inside quotes becomes a string? So a template literal would turn the output of bgImg[randomNumber] into a string while keeping the variable resolved?
Stephen James
@sjames1958gm
Jul 31 2017 19:10
@eunipa Because you had "" bgImg[randomNumber] wasn't even looked at as a variable but treated just as string contents
@eunipa The template string syntax ${expression} converts expression into a string and inserts it into the string.
Here bgImg[randomNumber] resolved to a string so good to go.
Bradley Sands
@sandsbe
Jul 31 2017 19:18
Trying to use .hidden to get my appended data to hide when I select a button. The items DO hide, but my columns don't re-adjust.
i.e. doc flow still impacted
Stephen James
@sjames1958gm
Jul 31 2017 19:20
@sandsbe Try display:none to remove from render tree
Bradley Sands
@sandsbe
Jul 31 2017 19:20
add it to the CSS?
Christopher McCormack
@cmccormack
Jul 31 2017 19:22
@sandsbe yes, or a style attribute in the element
@sandsbe are you using jQuery? If so you can also use .hide() and .show() on the elements, which is pretty convenient
I may have appended the data to make it not use those features properly
Christopher McCormack
@cmccormack
Jul 31 2017 19:25
@sandsbe you're creating only three columns. You should consider instead adding each user's data as a new row, then you can hide the row
Bradley Sands
@sandsbe
Jul 31 2017 19:26
Yup. The three columns was much easier when I did this a bit ago. I guess columns is the best way to do it.
Although, in theory, shouldn't the hide() still work?
Christopher McCormack
@cmccormack
Jul 31 2017 19:27
you're only hiding spans but you still have your breaks in there
Bradley Sands
@sandsbe
Jul 31 2017 19:28
@cmccormack. Yes I do. Great point.
Tiago Correia
@tiagocorreiaalmeida
Jul 31 2017 19:28
hello everyone
Christopher McCormack
@cmccormack
Jul 31 2017 19:28
I'd highly recommend getting that <p> wrapper out of there too - you're using bootstrap - you don't want another element that adds its own padding and margins inside your bootstrap grid or things will be harder to control
@tiagocorreiaalmeida hello
Tiago Correia
@tiagocorreiaalmeida
Jul 31 2017 19:29
im trying to read about what parameters I can use in the SetInterval function but can't find any good info about how it maybe its cause im searrching the wrong thing
hey how are you?
ty @cmccormack
CamperBot
@camperbot
Jul 31 2017 19:29
sandsbe sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1089 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Jul 31 2017 19:29
@tiagocorreiaalmeida did you try https://mdn.io/setInterval
@sandsbe avoid <br> tags as much as possible, there is almost always a better way to do it
Tiago Correia
@tiagocorreiaalmeida
Jul 31 2017 19:30
no I didnt... thanks @cmccormack
CamperBot
@camperbot
Jul 31 2017 19:30
tiagocorreiaalmeida sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1090 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Jul 31 2017 19:31
@tiagocorreiaalmeida when in doubt - https://mdn.io/[search-query]
it's pretty good at bringing you to exactly what you need
Tiago Correia
@tiagocorreiaalmeida
Jul 31 2017 19:32
yup somethings I dont think... going to use this on the pomodoro clock exercise lets see what I can do, thanks
Christopher McCormack
@cmccormack
Jul 31 2017 19:32

@tiagocorreiaalmeida np. Make sure you pay attention to this part to clear your timer:

Return value

The returned timeoutID is a numeric, non-zero value which identifies the timer created by the call to setInterval(); this value can be passed to WindowOrWorkerGlobalScope.clearInterval() to cancel the timeout.

Tiago Correia
@tiagocorreiaalmeida
Jul 31 2017 19:34
thanks once again
Eunice Park
@eunicode
Jul 31 2017 19:34
@sjames1958gm bless you~~ May you get all the brownies/cookies in the world :raised_hands:
Stephen James
@sjames1958gm
Jul 31 2017 19:35
@eunipa Lol thanks
CamperBot
@camperbot
Jul 31 2017 19:35
sjames1958gm sends brownie points to @eunipa :sparkles: :thumbsup: :sparkles:
:warning: @eunipa's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
Alex
@alexandrupintilei
Jul 31 2017 19:35
function diffArray(arr1, arr2) {
   var newArr = [];
  for(i=0; i < arr2.length; i++){
    if(arr2[i] != arr1[i]){
      return arr2.indexOf(4);
      newArr.push(arr2);
    }
  }
     console.log(newArr);                      
}
diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
What should i do now to push 4 into newArr?
Christopher McCormack
@cmccormack
Jul 31 2017 19:38
@alexandrupintilei first, don't explicitly try to add 4. Second- arr2[i] != arr1[i] will only work if everything is in the same position, but what if the second array had 0 at the beginning? Use indexOf instead and iterate over only one array
Kelechi Chinaka
@ke1echi
Jul 31 2017 19:40
do u use react? @sjames1958gm
Alex
@alexandrupintilei
Jul 31 2017 19:40
@cmccormack thx
CamperBot
@camperbot
Jul 31 2017 19:40
alexandrupintilei sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1091 | @cmccormack |http://www.freecodecamp.com/cmccormack
Joseph
@Big-jo
Jul 31 2017 19:41
Hi everyone , is there a way to customize the alert box
Stephen James
@sjames1958gm
Jul 31 2017 19:41
@kelechy I don't professionally, but I have worked on personal learning projects.
Kelechi Chinaka
@ke1echi
Jul 31 2017 19:41
the docs likes nice..how long have u been using react @cmccormack
Stephen James
@sjames1958gm
Jul 31 2017 19:41
@Big-jo I don't believe so.
Christopher McCormack
@cmccormack
Jul 31 2017 19:41
@kelechy just a few months
@Big-jo there are different types of modals you can use, alert is just one type
Bradley Sands
@sandsbe
Jul 31 2017 19:42
Anyone have any general tips on the calculator exercise?
Kelechi Chinaka
@ke1echi
Jul 31 2017 19:42
hows the experience been @cmccormack
Stephen James
@sjames1958gm
Jul 31 2017 19:42
@alexandrupintilei This code will push the values from arr2 that are not in arr1
if (arr1.indexOf(arr2[i]) === -1) newArr.push(arr2[i]);
Pieter Stokkink
@forkerino
Jul 31 2017 19:43
@cmccormack not sure if already reported but I found a bug in your dungeon crawler: when I attack an enemy and just keep the arrow pressed, I either don't lose any hp or very little.
Christopher McCormack
@cmccormack
Jul 31 2017 19:43
@kelechy great - once you get the hang of it it's really nice, and I kind of want to move all my code into React. It gives you a structure to work with
Pieter Stokkink
@forkerino
Jul 31 2017 19:43
@cmccormack the game is fun, though! well done!
Joseph
@Big-jo
Jul 31 2017 19:43
@cmccormack i just want a box to pop up when the webpage loads and in the box i want the user to fill in some things
Christopher McCormack
@cmccormack
Jul 31 2017 19:44
@forkerino Thanks, and great catch! I need to just avoid mousedown maybe
CamperBot
@camperbot
Jul 31 2017 19:44
cmccormack sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2905 | @forkerino |http://www.freecodecamp.com/forkerino
Tiago Correia
@tiagocorreiaalmeida
Jul 31 2017 19:44
use prompt or use css/html followed with jquery
Christopher McCormack
@cmccormack
Jul 31 2017 19:44
Kelechi Chinaka
@ke1echi
Jul 31 2017 19:45
ok..am trying to go the react way @cmccormack
Alex
@alexandrupintilei
Jul 31 2017 19:45
@sjames1958gm thx
CamperBot
@camperbot
Jul 31 2017 19:45
alexandrupintilei sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8208 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Joseph
@Big-jo
Jul 31 2017 19:46
@cmccormack thanks
CamperBot
@camperbot
Jul 31 2017 19:46
big-jo sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1092 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Jul 31 2017 19:46
np
Pieter Stokkink
@forkerino
Jul 31 2017 19:46
@cmccormack I'm talking about the arrow keys on my keyboard. Not sure if it has to do with mousedown.
Christopher McCormack
@cmccormack
Jul 31 2017 19:46
@forkerino sorry keydown :D
yeah it's just super laggy as it's trying to render for every tick of keydown I bet, maybe I'll change it to keyup
Pieter Stokkink
@forkerino
Jul 31 2017 19:47
@cmccormack hmm. can't reproduce it now.
weird
Christopher McCormack
@cmccormack
Jul 31 2017 19:47
I have optimizations to do that's for sure
@forkerino I think it can hang if you hold it down and maybe die, seemed to happen in my dev version
Pieter Stokkink
@forkerino
Jul 31 2017 19:49
@cmccormack or is it maybe when the defenses are way up that those hits by the enemies are just too weak?
not sure all of a sudden
Christopher McCormack
@cmccormack
Jul 31 2017 19:50
that can happen where they hit for 0, still a bit of balancing to do, maybe set a minimum of 1 damage or something
but you should be able to kill them quickly as well
Pieter Stokkink
@forkerino
Jul 31 2017 19:51
@cmccormack maybe that's it. I just found it weird that I could basically drive through the maze at some point and not lose any HP. A minimum of 1 or 2 would be good.
Christopher McCormack
@cmccormack
Jul 31 2017 19:51
ok I'll try to add that
thanks again @forkerino !
CamperBot
@camperbot
Jul 31 2017 19:51
cmccormack sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:warning: cmccormack already gave forkerino points
Pieter Stokkink
@forkerino
Jul 31 2017 19:51
:+1:
Jason Luboff
@JLuboff
Jul 31 2017 19:52
:shipit:
Pieter Stokkink
@forkerino
Jul 31 2017 19:52
:octocat:
Jason Luboff
@JLuboff
Jul 31 2017 19:52
:octopus:
Pieter Stokkink
@forkerino
Jul 31 2017 19:53
:whale:
Jason Luboff
@JLuboff
Jul 31 2017 19:53
:poodle:
kumquatfelafel
@kumquatfelafel
Jul 31 2017 19:53
:poop:
Pieter Stokkink
@forkerino
Jul 31 2017 19:53
:joy:
Jason Luboff
@JLuboff
Jul 31 2017 19:53
@kumquatfelafel Damn it! I was saving that one!
Pieter Stokkink
@forkerino
Jul 31 2017 19:54
Never save your shit
kumquatfelafel
@kumquatfelafel
Jul 31 2017 19:54
lol
Pieter Stokkink
@forkerino
Jul 31 2017 19:54
It's weird
Jason Luboff
@JLuboff
Jul 31 2017 19:54
@forkerino What about holding it? I don't like public bathrooms :worried:
Pieter Stokkink
@forkerino
Jul 31 2017 19:54
TMI
Jason Luboff
@JLuboff
Jul 31 2017 19:54
hahahahaha
Pieter Stokkink
@forkerino
Jul 31 2017 19:56
you can do the semi squat, holding on to the door handle and not touching the toilet
don't combine with Indian food
Jason Luboff
@JLuboff
Jul 31 2017 19:56
:joy:
Have you ever been in a public restroom in the US? People can see through man! Its not like in Europe where its full doors
Pieter Stokkink
@forkerino
Jul 31 2017 19:56
I must've been
kumquatfelafel
@kumquatfelafel
Jul 31 2017 19:57
It has to be more of a "one foot on the ground, other against the door, one hand against the wall behind you so you don't fall in".
Pieter Stokkink
@forkerino
Jul 31 2017 19:57
hahaha
Christopher McCormack
@cmccormack
Jul 31 2017 19:57
New build with some suggestions implemented: https://mackville.net/react/dungeon/
added status icons on the statustext for a bit more flavor
Gurpreet SIngh
@Gurpreet3131
Jul 31 2017 19:58
Can anyone help me out with handlebars?
Christopher McCormack
@cmccormack
Jul 31 2017 19:58
I remember when I went to Europe they charged you to use public restrooms but they sure were clean
Jason Luboff
@JLuboff
Jul 31 2017 19:58
@Gurpreet3131 I might be able to
Gurpreet SIngh
@Gurpreet3131
Jul 31 2017 19:59
{{#if user}}
              <li role="presentation"><a href="/">Index</a></li>
              <li role="presentation"><a href="/users/logout">Logout</a></li>

            {{else}}
              <li role="presentation"><a href="/users/login">Login</a></li>
              <li role="presentation"><a href="/users/register">Register</a></li>

            {{want to show this if role field in userinfo database is admin}}
            <li role="presentation"><a href="/users/insert">Insert</a></li>
            {{/end}}
I want the third list option to be displayed only if the role field is admin
How can I make it work like that
Christopher McCormack
@cmccormack
Jul 31 2017 20:00
can you use a ternary?
Jason Luboff
@JLuboff
Jul 31 2017 20:00
@Gurpreet3131 either feed it another object with that info or if its inside of user then {{#if user.admin}} or whatever
Gurpreet SIngh
@Gurpreet3131
Jul 31 2017 20:02
how to equate it? @JLuboff
@JLuboff like {{#if user.admin == 'admin'}} ??
Jason Luboff
@JLuboff
Jul 31 2017 20:03
@Gurpreet3131 Honestly, I would probably do the check on the backend. Once you get the info from the database, check there. Then just have an admin object.
Pieter Stokkink
@forkerino
Jul 31 2017 20:04
@cmccormack we want moar levels!
Gurpreet SIngh
@Gurpreet3131
Jul 31 2017 20:04
@JLuboff can you help me out on how to do that. Kind of new to the handlebars
Christopher McCormack
@cmccormack
Jul 31 2017 20:04
@forkerino We listened and we heard you! adding more levels! I think I'll need to up the difficulty modifier just a tad though, level 2 is a bit too easy.
Jason Luboff
@JLuboff
Jul 31 2017 20:05
@Gurpreet3131 Just to be clear...are you using this with node/express in the backend?
Pieter Stokkink
@forkerino
Jul 31 2017 20:05
@cmccormack yeah, it gets easier with time instead of harder.
Christopher McCormack
@cmccormack
Jul 31 2017 20:05
@forkerino originally I assumed people would see the next floor and just go there, then realize they may not have enough items to beat the boss
balancing is hard though
Pieter Stokkink
@forkerino
Jul 31 2017 20:06
@cmccormack that's what I did initially, until I got smart
Christopher McCormack
@cmccormack
Jul 31 2017 20:06
woohoo! then 80% of players will still find it challenging!
Gurpreet SIngh
@Gurpreet3131
Jul 31 2017 20:07
@JLuboff yes i am using node express in the backend
Jason Luboff
@JLuboff
Jul 31 2017 20:07
@Gurpreet3131 Ok so do something like
db.collection('db').find({}).toArray((err, doc) => {
let user = doc.user;
let admin = doc.admin === true;
res.render('index.hbs', { user, admin});
}
)
So now you'll have the admin variable being passed to your template.
Joseph
@Big-jo
Jul 31 2017 20:09
@cmccormack so thanks for that but, what i want is a window that opens when the page is loaded and i want to build some forms in it to be filled
CamperBot
@camperbot
Jul 31 2017 20:09
big-jo sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:warning: big-jo already gave cmccormack points
Christopher McCormack
@cmccormack
Jul 31 2017 20:10
@Big-jo you have to tell us that so we know what you're looking for. What you want is a modal
@Big-jo take a look at my recipe app - when you add a new recipe, is that the type of input you're looking for? https://mackville.net/react/recipes/index.html
Gurpreet SIngh
@Gurpreet3131
Jul 31 2017 20:12
@JLuboff kindly check your private message
Joseph
@Big-jo
Jul 31 2017 20:14
@cmccormack I want a window to open with forms(i will build the forms myself) and then after the forms have been filled , i want to use the data to access google map API and o some other stuff with the data
monkeyfingerz
@monkeyfingerz
Jul 31 2017 20:14

function checkCashRegister(price, cash, cid) {
  var change;
  var penny = 0;
  var nickle = 0;
  var dime = 0;
  var quarter = 0;
  var one = 0;
  var five = 0;
  var ten = 0;
  var oneHundred= 0;

  for(var i =0; i<cash.length; i++){
  switch (cid[i][0]){
     case "PENNY": penny = cid[i][1];
     break;
     case "NICKLE": nickle = cid[i][1];
     break;
     case "DIME": dime = cid[i][1];
     break;
     case "QUARTER": quarter = cid[i][1];
     break;
     case "ONE" : one= cid[i][1];
     break;
     case "FIVE": five = cid[i][1];
     break;
    case "TEN" : ten = cid[i][1];
     break;
    case "ONE HUNDRED": oneHundred = cid[i][1];
  }
  }
  return one;
}


checkCashRegister(19.50, 20.00, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.10], ["QUARTER", 4.25], ["ONE", 90.00], ["FIVE", 55.00], ["TEN", 20.00], ["TWENTY", 60.00], ["ONE HUNDRED", 100.00]]);
why is it not returning 90.00?
Christopher McCormack
@cmccormack
Jul 31 2017 20:15
@monkeyfingerz why are you iterating over cash.length?
monkeyfingerz
@monkeyfingerz
Jul 31 2017 20:15
@cmccormack thanks
CamperBot
@camperbot
Jul 31 2017 20:15
monkeyfingerz sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1093 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Jul 31 2017 20:16
@monkeyfingerz you'll probably want a while loop for this one, as you can have multiples of the same denomination
monkeyfingerz
@monkeyfingerz
Jul 31 2017 20:17
@cmccormack i'll have multiple "PENNY" 's for instance?
Joseph
@Big-jo
Jul 31 2017 20:17
@Big-jo i want it to overlay the current screen , just like an alert box
Christopher McCormack
@cmccormack
Jul 31 2017 20:18
@monkeyfingerz correct
@Big-jo did you look at the example of modal I provided or the bootstrap docs on modals at all?
Joseph
@Big-jo
Jul 31 2017 20:18
@cmccormack I will
monkeyfingerz
@monkeyfingerz
Jul 31 2017 20:18
@cmccormack couldn't i just write a penny+=cid[i][1] ?
Christopher McCormack
@cmccormack
Jul 31 2017 20:19
@Big-jo :point_up: July 31, 2017 1:10 PM
@monkeyfingerz no clue how you're iterating, but when will your case ever be a string?
Joseph
@Big-jo
Jul 31 2017 20:19
@cmccormack i am looking at it now
Christopher McCormack
@cmccormack
Jul 31 2017 20:21
@monkeyfingerz maybe considering subtracting the largest denomination that you can over and over until you have no more or it's no longer the largest denomination that will divide into the new total
Joseph
@Big-jo
Jul 31 2017 20:24
how do i add jquery in a javascript file, or if i put it in the head tag in the html file i can still use it in the javascript file?
Jason Luboff
@JLuboff
Jul 31 2017 20:26
@Big-jo You don't add it in the JS file, just include it in your HTML file
Christopher McCormack
@cmccormack
Jul 31 2017 20:27
@Big-jo if you add it in the head, you can just use it in the javascript file using $ syntax
Joseph
@Big-jo
Jul 31 2017 20:28
@JLuboff @cmccormack thanks
CamperBot
@camperbot
Jul 31 2017 20:28
big-jo sends brownie points to @jluboff and @cmccormack :sparkles: :thumbsup: :sparkles:
:warning: big-jo already gave cmccormack points
:star2: 2120 | @jluboff |http://www.freecodecamp.com/jluboff
Joseph
@Big-jo
Jul 31 2017 20:56
Should i use a jquery cdn or a jquery bootstarp cdn?
Bradley Sands
@sandsbe
Jul 31 2017 21:03
Does anyone attend any fCC meetups? Have you found them helpful? I'm considering hosting one in my city.
Ronique Ricketts
@RoniqueRicketts
Jul 31 2017 21:10
@sandsbe can you come to Jamaica and host one. Id appreciate it :)
Also a good web Hackerthon would be nice. We attend the event IN VR. What say you guys?
Bradley Sands
@sandsbe
Jul 31 2017 21:16
Bah. I think you're assuming expertise associated with hosting.
I attended one, the guy basically was there to help people as they moved along in the fCC program. I'd say half of the attendees hadn't even signed up!
scarejar
@scarejar
Jul 31 2017 21:19
I enabled experimental browser features on chrome://flags that allows for naitive es6 modules and I'm not sure if I'm importing my modules correctly . It gives me "Uncaught SyntaxError: Unexpected token import"
//createPerson.js
export default createPerson{
     constructor(){
         //logic 
     }
}

//main.js
import createPerson from "createPerson"

//console
"Uncaught SnytaxError: Unexpected token import"
or if it's just the browser not implementing modules yet
Tomasz
@Tgralak
Jul 31 2017 21:24

Hello, does anyone know, why my code is not working with all the cases?


function getIndexToIns(arr, num) {
  arr.push(num);
  arr.sort();
  // Find my place in this sorted array.
  console.log(arr);
  return arr.indexOf(num);
}

getIndexToIns([2, 5, 10], 15);

for example in this case it returns "1" instead of "3"

Joseph
@revisualize
Jul 31 2017 21:26
Hello.
@Tgralak .sort() is unicode sort
Tomasz
@Tgralak
Jul 31 2017 21:28
@revisualize oohhh, thank You!
CamperBot
@camperbot
Jul 31 2017 21:28
tgralak sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4395 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Jul 31 2017 21:28
@Tgralak [80,9,700,40,1,5,200].sort() makes the array: [1, 200, 40, 5, 700, 80, 9]
Dan Couper
@DanCouper
Jul 31 2017 21:29
@scarejar is it Chrome Canary you're using? I think it's only Canary at the minute, rather than Chrome proper
scarejar
@scarejar
Jul 31 2017 21:30
I'm using latest version of Chromium v60
Tomasz
@Tgralak
Jul 31 2017 21:30
@revisualize thanks, just made the challenge :)
CamperBot
@camperbot
Jul 31 2017 21:30
tgralak sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:warning: tgralak already gave revisualize points
Dan Couper
@DanCouper
Jul 31 2017 21:31
Has to be Canary I think, it's slated for v61 in other Chrome builds
scarejar
@scarejar
Jul 31 2017 21:34
lol
Jefferson
@jeffersonnnn
Jul 31 2017 21:34
i just want to say thanks guys, for the support and the love shown to newbs like us. More power to your elbows.
scarejar
@scarejar
Jul 31 2017 21:35
3 versions of chrome now installed, lolol
honestly thought chromium was the alpha testing chrome branch
Dan Couper
@DanCouper
Jul 31 2017 21:45
😔 Canary is the one you want, just Chrome from the future, with shiny new features that are not quite properly tested
Joseph
@Big-jo
Jul 31 2017 21:47
is it possible to pass data from forms to a javascript object?
Dan Couper
@DanCouper
Jul 31 2017 21:48
Chromium is basically the Open Source version of Chrome (Chrome is based on Chromium), it's based on latest stable Chrome so Canary has newer features normally
Tiago Correia
@tiagocorreiaalmeida
Jul 31 2017 21:49
@revisualize can you give me a little help?
scarejar
@scarejar
Jul 31 2017 21:49
I see...
Tiago Correia
@tiagocorreiaalmeida
Jul 31 2017 21:49
im doing a countdown using setinterval if I stop the countdown and I want him to stay exatly where he stopped so he can restart from there I have to store the value right?
scarejar
@scarejar
Jul 31 2017 21:51
interestingly still not working on Canary...
is it because I'm using the <script> to load the initial file in html?
Joseph
@revisualize
Jul 31 2017 21:52
@tiagocorreiaalmeida With?
@tiagocorreiaalmeida I can't help with that.
Tiago Correia
@tiagocorreiaalmeida
Jul 31 2017 21:53
oh ok thanks and np :)
scarejar
@scarejar
Jul 31 2017 21:55
on ff " SyntaxError: import declarations may only appear at top level of a module " , interestingly.
Dan Couper
@DanCouper
Jul 31 2017 21:55
@scarejar possibly, I just need to find an example - I've only tried this once and it didn't really work well past very basic stuff so I was just going to ignore it until the functionality was finalized. I'm sure I had an article saved going through the current caveats tho, I'll have a search for
aha
scarejar
@scarejar
Jul 31 2017 21:58
OHH
Dan Couper
@DanCouper
Jul 31 2017 21:58
So I started off copying the examples there, gradually adding more stuff; I had tried what you're doing straightaway but hit errors and stuff failing silently
scarejar
@scarejar
Jul 31 2017 21:59
was actually "zombie skimming" that article ... missed the headline : ""Bare" import specifiers aren't currently supported "
Ogundele Olumide
@Lumexralph
Jul 31 2017 22:05
Hello Everybody :wave:
scarejar
@scarejar
Jul 31 2017 22:05
dern it... wonder when they're going to fully implement naitive modules already
wootupm8
Ogundele Olumide
@Lumexralph
Jul 31 2017 22:05
@DanCouper can I challenge you a lil?
Christopher McCormack
@cmccormack
Jul 31 2017 22:05
@Lumexralph hiya!
Dan Couper
@DanCouper
Jul 31 2017 22:06
:+1:
Ogundele Olumide
@Lumexralph
Jul 31 2017 22:06
@cmccormack Hi! can I challenge you too?
@DanCouper @cmccormack how're you guys doing?
Christopher McCormack
@cmccormack
Jul 31 2017 22:06
@Lumexralph uh only if it's to help someone :D otherwise I'm trying to fix bugs in my stupid dungeon project
Stephen James
@sjames1958gm
Jul 31 2017 22:07
@Lumexralph :wave:
Ogundele Olumide
@Lumexralph
Jul 31 2017 22:07
@cmccormack :joy:
Dan Couper
@DanCouper
Jul 31 2017 22:08
p good I think, have a baby so have been awake for about a week and a half solid so far
Ogundele Olumide
@Lumexralph
Jul 31 2017 22:08
@sjames1958gm Hey man, if your to create an algorithm that checks an array if it's geometric or arithmetic sequence, how will you approach.... I have my solution maybe a refactor
@sjames1958gm @DanCouper @cmccormack this is my solution to that challenge what do you guys think
const aritGeo = (arr) => {
  "use strict";

  //if input is not an array
  if(!Array.isArray(arr)) return "Array required";

  //check if array is empty
  if (arr.length === 0) return 0;

  else {
    //sort array in ascending order
    arr.sort((a, b) => a - b);

    //include helper functions to 
    //arithmetic or geometric progression

    const arithmeticProgression = (arr) => {
      let difference = arr[1] - arr[0];

      return arr.reduce((acc, nextVal) => {
        if (nextVal - acc === difference) {
          return nextVal;
        }
        return 0;
      }) === arr[arr.length - 1];

    };

    const geometricProgression = (arr) => {

      let ratio = arr[1] / arr[0];
      return arr.reduce((acc, nextVal) => {
        if (nextVal / acc === ratio) {
          return nextVal;
        }
        return 0;
      }) === arr[arr.length - 1];
    };

    if (arithmeticProgression(arr)) return "Arithmetic";
    if (geometricProgression(arr)) return "Geometric";

    //if none of the above run
    return -1;
  }


};
Stephen James
@sjames1958gm
Jul 31 2017 22:18
@Lumexralph From a efficiency - early termination - I might use every
let diff = arr[1] - arr[0];
let curr = arr[0] - diff;
return arr.every(val) {
    if ((val - curr) === diff)  {
        curr = val;
       return true;
    }
   return false;
});
Ogundele Olumide
@Lumexralph
Jul 31 2017 22:20
@sjames1958gm referring to arithmeticProgression, right?
Stephen James
@sjames1958gm
Jul 31 2017 22:20
MIght be more difficult with geometric
@Lumexralph Yes
@Lumexralph Doesn't your geometric need an initial value for acc?
Ogundele Olumide
@Lumexralph
Jul 31 2017 22:22
@sjames1958gm thanks that actually make sense, to stop from going through the whole array
CamperBot
@camperbot
Jul 31 2017 22:22
lumexralph sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8209 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Ogundele Olumide
@Lumexralph
Jul 31 2017 22:23

@Lumexralph Doesn't your geometric need an initial value for acc?

not necessary, whichever applies

Wisdom Peters
@blackcytographer
Jul 31 2017 22:24
pls i need an idea on how to write a problem such that no letter repeats itself
Ogundele Olumide
@Lumexralph
Jul 31 2017 22:25
@blackcytographer i am thinking using Set or object to hold the data
Wisdom Peters
@blackcytographer
Jul 31 2017 22:30
@Lumexralph can u gv examples pls
njordomir
@njordomir
Jul 31 2017 22:43
I'm working on "Smallest Common Multiple," and I have the feeling I'm missing something obvious. For some reason I can't even get the second and third console logs to print. Could someone give me a hint?
Challenge: https://www.freecodecamp.org/challenges/smallest-common-multiple
function smallestCommons(arr) {
for (i=1;i>0;i++) {
  console.log(i);
  for (j=arr[0];j>=arr[1];j++) {
    console.log("j" + j);
    console.log(!Number.isInteger(i/j));
    if (!Number.isInteger(i/j)) {  
    } else {
      return i;
    }
  }
}
}
smallestCommons([1,5]);
Also, I'm aware that the first loop is infinite, but it shouldn't matter when it hits the return. I'll fix it with a while loop or something later.
Joel Y.
@zapcannon99
Jul 31 2017 22:47
if the second and third console logs aren't printing, then your condition in the for loop is failing
so, what's j >= arr[1] ?
or what's arr[0] >= arr[1]
@njordomir
njordomir
@njordomir
Jul 31 2017 22:51
Oh! I think you got me. @zapcannon99 The args aren't necessarily in order. It's supposed to be running through the integers between arr[0] and arr[1] no make sure i is divisible by all of them evenly. Perhaps, if arr[0] is greater than arr[1] it's failing immedietly, but I see the first console.log iterating into the thousands. I'll rethink the second for loop.
Joel Y.
@zapcannon99
Jul 31 2017 22:55

Makes sense then why it's failing.

Also, I know you don't have to, but make sure to add var before i and j in the loops. Weird things may happen if you do that in an actual project.

Tomasz
@Tgralak
Jul 31 2017 22:56
function rot13(str) { // LBH QVQ VG!
  var arr = str.split("");
  var arrToStr;

  var newArr = arr.map(function(x) {
    return x.charCodeAt();
  });

  for (i=0;i<newArr.length;i++) {
    if (newArr[i] > 65 && newArr[i] <= 78) {
      newArr[i] += 13;
    }
    else if (newArr[i] > 78 && newArr[i] <= 91) {
      newArr[i] -= 13;    
    }
    arrToStr = newArr.toString();
  }
  var res = newArr.map(String.fromCharCode); {
    return res;
  }
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Hello again. Does anyone know why my result is like "F\u000..."?
Jason Luboff
@JLuboff
Jul 31 2017 22:58
@Tgralak You are not using map correctly or fromCharCode
You would want something like:
var res = newArr.map(function(el){return String.fromCharCode(el)});
And also, 91 is not a letter. In your else if, it should be newArr[i] < 91
njordomir
@njordomir
Jul 31 2017 22:59
@zapcannon99 Apparently I'm a dummy who confused assignment and conditionals :P
Joel Y.
@zapcannon99
Jul 31 2017 22:59
it happens.
Jason Luboff
@JLuboff
Jul 31 2017 23:00
@Tgralak In fact... your range for both are wrong. It should be between 65 and 77, and then 78 and 90
Tomasz
@Tgralak
Jul 31 2017 23:01
@JLuboff thank You very much for Your time
CamperBot
@camperbot
Jul 31 2017 23:01
tgralak sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2121 | @jluboff |http://www.freecodecamp.com/jluboff
Stephen James
@sjames1958gm
Jul 31 2017 23:05
@Tgralak Your result will be an array not a string
Tomasz
@Tgralak
Jul 31 2017 23:07
@JLuboff @sjames1958gm finally did it, so much satisfaction!
I bet it could be done 10x easier way, but it doesnt matter lol
Stephen James
@sjames1958gm
Jul 31 2017 23:10
@Tgralak reduce is a way to convert your array
[65, 66, 67].reduce((a, c) => a + String.fromCharCode(c), "");
Tomasz
@Tgralak
Jul 31 2017 23:12
I just used the .join method after String.fromCharCode :smile: and it works
Stephen James
@sjames1958gm
Jul 31 2017 23:18
@Tgralak ok
aRtoo
@artoodeeto
Jul 31 2017 23:56
hi guys. need help have you experienced live searched?? i tried it twitch but its throwing me all the characters. giving me an error. heres my codepen. https://codepen.io/artoo/full/YxPOWP/