These are chat archives for FreeCodeCamp/HelpJavaScript

1st
Oct 2017
RyanHuang06
@RyanHuang06
Oct 01 2017 00:02
hey, why isn't this code for mutations working?

function mutation(arr) {
var test = arr[1].toLowerCase();
var target = arr[0].toLowerCase();
var newTester = test.split();
var newTarget = target.split();
for(n=0;n<test.length;n++){
if (newTester[n]!==newTarget[n]){
return true;
}
return false;
}

}

mutation(["hello", "hello"]);

korzo
@korzo
Oct 01 2017 00:03
@RyanHuang06 because you compare letters on the same position
Moisés Man
@moigithub
Oct 01 2017 00:04
split needs a parameter @RyanHuang06
Gersho
@Gersho
Oct 01 2017 00:04
don't you need split("") ?
korzo
@korzo
Oct 01 2017 00:05

@RyanHuang06
Take a look at this example. Letters are not on the same position

Lastly, ["Alien", "line"], should return true because all of the letters in "line" are present in "Alien".

Moisés Man
@moigithub
Oct 01 2017 00:05
also there are no guarantee both strings will always have the same size
if target is smaller than test.. then that code will NOT check all chars
if larger.. u will access unexistant elements
RyanHuang06
@RyanHuang06
Oct 01 2017 00:07
ohhhhh
thx
thanks @korzo
CamperBot
@camperbot
Oct 01 2017 00:07
ryanhuang06 sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 562 | @korzo |http://www.freecodecamp.com/korzo
korzo
@korzo
Oct 01 2017 00:07
@moigithub That part is ok, because he iterate over second string
h1tag
@h1tag
Oct 01 2017 04:13
Hey, anybody got hints for this challenge or knows why my code isn't passing?
let repeatNum = "42 42 42";
let reRegex = /(\d+)\3/; // Change this line
let result = reRegex.test(repeatNum);
heroiczero
@heroiczero
Oct 01 2017 04:25
@h1tag let reRegex = /(\d+)\s\1/; you need a space and you have to repeat the first group
@h1tag so that would return true for "42 42" you need to do another \s\1 for another " 42"
h1tag
@h1tag
Oct 01 2017 04:32
@heroiczero using /(\d+)\s\1/\s\1/ it's working for all the cases except Your regex should not match "42 42 42 42"
heroiczero
@heroiczero
Oct 01 2017 04:33
@h1tag because it matches it "42 42 42" you probably need a
@h1tag beginning ^ and end anchor $
@h1tag if you don't have a beginning or end anchor it could match any 42 42 42 in a series of number and return true
@h1tag in "42 42 42 42", does it have "42 42 42"?
h1tag
@h1tag
Oct 01 2017 04:37
@heroiczero oh, right
but I thought that capture groups alone will be able to solve this
heroiczero
@heroiczero
Oct 01 2017 04:38
@h1tag you are capturing groups. (\d+) is group and \1 represents that group and you are repeating three times
h1tag
@h1tag
Oct 01 2017 04:41
@heroiczero I mean I thought that it will only match the ones that repeat 3 times without needing to use other identifiers
heroiczero
@heroiczero
Oct 01 2017 04:42
@h1tag you still need those spaces before the repeat
h1tag
@h1tag
Oct 01 2017 04:42
@heroiczero I'm talking about the starting and ending identifiers
heroiczero
@heroiczero
Oct 01 2017 04:43
@h1tag you mean the ^ and $
h1tag
@h1tag
Oct 01 2017 04:43
yes
@heroiczero but now I understand how capture groups work thanks to you :) . I didn't get how do they work from the challenge.
Thank you for taking the time
CamperBot
@camperbot
Oct 01 2017 04:45
h1tag sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1798 | @heroiczero |http://www.freecodecamp.com/heroiczero
heroiczero
@heroiczero
Oct 01 2017 04:46
@h1tag you need both because you want only three digits. if you have only the ^ without the end, you could have a "42 42 42 ..." where it can continue and it will be true. if you only have the end $, you could have "... 42 42 42" and it will be true. Therefore, you would need both, so you only have 3 numbers
h1tag
@h1tag
Oct 01 2017 04:48
@heroiczero so it's the word "only" that made the difference here "Use capture groups in reRegex to match numbers that are repeated only three times in a string,"
oh, I see it right now, ty
Quilty
@zebralight
Oct 01 2017 04:49
can someone help with an issue I'm having with deploying a nodejs app on heroku
h1tag
@h1tag
Oct 01 2017 04:55
@zebralight what's the issue, I might be able to help, haven't used heroku before though
h1tag
@h1tag
Oct 01 2017 05:26
Any idea why this re /^\s+|\s+$/g works for this challenge but this /^(\s+)|\1$/g doesn't?
Fabien SHAN
@X140hu4
Oct 01 2017 05:31
arent's you missing something on the second regexp?
h1tag
@h1tag
Oct 01 2017 05:33
@X140hu4 I'm not sure
heroiczero
@heroiczero
Oct 01 2017 05:34
@h1tag second one is grouping
h1tag
@h1tag
Oct 01 2017 05:35
@heroiczero yea, I know. You mean grouping doesn't work this way?
it should be like a one sentence?
Fabien SHAN
@X140hu4
Oct 01 2017 05:38
Why is there a 1 in the second regexp?
heroiczero
@heroiczero
Oct 01 2017 05:40
@X140hu4 \1 is the first group which is (\s+)
Fabien SHAN
@X140hu4
Oct 01 2017 05:41
Oh sorry
Fabien SHAN
@X140hu4
Oct 01 2017 05:48
Isn't it because it because of the OR?
This would work for example: (\s)+\1
parthprakash1
@parthprakash1
Oct 01 2017 06:16
Hi guys! Could anyone help me with this-
function numfunc() {
var cnum=rnum;
var rnum=Math.floor(Math.random()*20);
if (cnum===rnum){
numfunc()
}
console.log(rnum);
}
What I want to do is generate a random num but if its the same a s last one then I want to run it again
it refers to the function
piteto
@piteto
Oct 01 2017 06:26
@parthprakash1 it works good for me - how are you calling it?
function numfunc() {
  var cnum = rnum;
  var rnum = Math.floor(Math.random() * 20);
  if (cnum === rnum) {
    numfunc();
  }
  console.log(rnum);
}

numfunc();
parthprakash1
@parthprakash1
Oct 01 2017 06:26
on button click
image.png
piteto
@piteto
Oct 01 2017 06:27
hmmm, when I call numfunc() over and over, I get new numbers logged to the console
parthprakash1
@parthprakash1
Oct 01 2017 06:27
Yup thats what I want but it aint working with my button click
Umm okay it's working now
piteto
@piteto
Oct 01 2017 06:28
Maybe you can share your code?
parthprakash1
@parthprakash1
Oct 01 2017 06:28
Yup I'll share but it's working now
piteto
@piteto
Oct 01 2017 06:28
ahh, good :)
piteto
@piteto
Oct 01 2017 06:29
particles.js :)
parthprakash1
@parthprakash1
Oct 01 2017 06:29
Yup :laughing:
I spent all day yesterday and figured that q index was missing
:laughing:
piteto
@piteto
Oct 01 2017 06:30
lol, well it will probably be nice when you're done :)
parthprakash1
@parthprakash1
Oct 01 2017 06:30
Hope so!!
btw @piteto Thanks!
CamperBot
@camperbot
Oct 01 2017 06:30
parthprakash1 sends brownie points to @piteto :sparkles: :thumbsup: :sparkles:
:cookie: 175 | @piteto |http://www.freecodecamp.com/piteto
piteto
@piteto
Oct 01 2017 06:31
any time, good luck with the rest
parthprakash1
@parthprakash1
Oct 01 2017 06:31
Thank you!
parthprakash1
@parthprakash1
Oct 01 2017 07:31
@piteto You on/
*?
WAINGOR
@WAINGOR
Oct 01 2017 10:16

Hi guys, I have a question about reduce in the code below:

var X =  [["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]];
var Y = X.reduce((accu,el)=>accu+el[1],0);
undefined
Y
335.40999999999997

Where in HELL does JS get the decimal numbers from here?!?!?

Pieter Stokkink
@forkerino
Oct 01 2017 10:20
@WAINGOR type 0.1 + 0.2 in your console
WAINGOR
@WAINGOR
Oct 01 2017 10:20
same weirdness indeed
Pieter Stokkink
@forkerino
Oct 01 2017 10:20
not all floating point numbers can be properly represented in binary
so it is an approximation
WAINGOR
@WAINGOR
Oct 01 2017 10:21
but will this leave the outcome of any calculation unaffected?
it feels so wonky
Pieter Stokkink
@forkerino
Oct 01 2017 10:21
If you need precision you need to do some rounding, or multiply everything by 100 and do your calculations in pennies instead of dollars
WAINGOR
@WAINGOR
Oct 01 2017 10:22
lol for real? Funny thing is, that was my initial intent
but I swithced back
as I didnt think it was necessary
thanks @forkerino
CamperBot
@camperbot
Oct 01 2017 10:22
waingor sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2943 | @forkerino |http://www.freecodecamp.com/forkerino
Pethaf
@Pethaf
Oct 01 2017 10:44
@WAINGOR Now you have learned the first painfull lesson on how floating point mathemtics (don't) work in javascript.
Marc
@MWBauer
Oct 01 2017 14:32
It's times like this that I think that front end dev is not for me.
I've made it thru the basic algo section, and feel like I need to finish my portfolio.
I didn't do it the first time because I don't know what I want to put in, what I should put in, and of course dressing it up so that it doesn't look like a $2 hooker at a Hollywood Highschool prom.
Can I just steal someone elses's?
lol I would never.
Marc
@MWBauer
Oct 01 2017 14:50
Is Copyright a thing we need to worry about when making our portfolios?
Pethaf
@Pethaf
Oct 01 2017 14:52
Shouldn't you have original content to put on your portfolio if you are going to use it for your portfolio?
Marc
@MWBauer
Oct 01 2017 14:52
I was thiking about background pics
Ronique Ricketts
@RoniqueRicketts
Oct 01 2017 15:37
So I have to learn php for my job and I just learn the basics and now I feel like I am conflicting , I wanna work with node but my job requires PHP and code ignighter. Has anyone been in this situation before and how have you handled it?
Stephen James
@sjames1958gm
Oct 01 2017 15:51
@RoniqueRicketts I work in C++ but I really like node/js so I end up doing the former at work and the latter in my free time.
I have been able to inject node into our company on some special projects.
Tai Jones
@taiJones00
Oct 01 2017 15:58
Would you solve the telephone validate with a switch statement for each allowed format
Stephen James
@sjames1958gm
Oct 01 2017 16:04
You can solve it with a single regex, I ended up using 4
Tai Jones
@taiJones00
Oct 01 2017 16:05
How can a single regex handle like 6 scenarios
Stephen James
@sjames1958gm
Oct 01 2017 16:05
Mtaching alternatives where one of the alternatives are empty
@taiJones00 It is a pretty complex regex
Tai Jones
@taiJones00
Oct 01 2017 16:06
Great :worried:
Stephen James
@sjames1958gm
Oct 01 2017 16:07
That's why I did 4. Not as efficient
Tai Jones
@taiJones00
Oct 01 2017 16:08
Okay thank you @sjames1958gm
CamperBot
@camperbot
Oct 01 2017 16:08
taijones00 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8499 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Ronique Ricketts
@RoniqueRicketts
Oct 01 2017 16:09
@sjames1958gm nice, ill try that. I shall continue my weekend studies in Nodejs and then my part-time in PHP
Stephen James
@sjames1958gm
Oct 01 2017 16:14
@RoniqueRicketts Experience in other languages and platforms can't hurt.
Daniel Romero
@Ranacode
Oct 01 2017 16:26
Hey guys what's up
I want to build an image compressor on Javascript and the first step is read the image file asArraybuffer but I don't understand it at all
I know that represent binary data but how can I handle them on Javascript?
Kelechi Chinaka
@kelechy
Oct 01 2017 16:44
i think am missing something in the description but can point it out
function meanVsMedian(n) {
  let median = n[Math.floor(n.sort((a,b)=>a-b).length/2)], mean = n.reduce((a,b)=>a+b,0);
  return (mean > median) ? 'mean' : (mean < median) ? 'median' : 'same'
}
Tiago Correia
@tiagocorreiaalmeida
Oct 01 2017 17:01
@sjames1958gm quick question for the url shortner idea is have a database check if the url exists there if it it is send back a link that when opened opens the website requested if doenst exist regist in db the link an id and a inc value that we can use to make it short right?
Moisés Man
@moigithub
Oct 01 2017 17:09

The "mean" is the "average" you're used to, where you add up all the numbers and then divide by the number of numbers

http://www.purplemath.com/modules/meanmode.htm
@kelechy

Amit Patel
@AmitP88
Oct 01 2017 17:10
hey guys, I'm refactoring my code and I'm running into an error "Cannot read property 'cell_x' of undefined" at line 36. I've read and inspected my code a few times, but I still can't see what's causing the error. Please, any help would be highly appreciated
https://codepen.io/AmitP88/pen/pWyaNY?editors=0010
Stephen James
@sjames1958gm
Oct 01 2017 17:11
@tiagocorreiaalmeida You have an API that gets a URL as a parameter and registers it in the DB returning a shortened URL to your site,
Then when that URL is accessed you redirect the request to the stored URL
Tiago Correia
@tiagocorreiaalmeida
Oct 01 2017 17:13
yeah was thinking about that, I can use a simple number inc to create the shorten version, last question if we request 2 times a shorten url for a website should that duplicate a doc or return the existent? and thanks
Stephen James
@sjames1958gm
Oct 01 2017 17:13
@AmitP88 clickedCell is not assigned a value when you are trying to use it.
@tiagocorreiaalmeida Return the existing.
Amit Patel
@AmitP88
Oct 01 2017 17:14
@sjames1958gm I thought it was though - clickedCell is the object containing the cell_x, cell_y, and cell_image key value pairs
Stephen James
@sjames1958gm
Oct 01 2017 17:15
@AmitP88 How can it be - the object you are creating is assigned to that variable.
Amit Patel
@AmitP88
Oct 01 2017 17:16
@sjames1958gm I thought that it was possible to use a key : value pair defined in an object to create another key : value pair within the same object
Stephen James
@sjames1958gm
Oct 01 2017 17:18
The variable clickedCell is not set until the object is created - so no, this will not work.
      var clickedCell = {
        cell_x : Math.floor(x/cell.width),
        cell_y : Math.floor(y/cell.height),
        cell_image : grid[clickedCell.cell_x + gridSize * clickedCell.cell_y].image 
      };
Amit Patel
@AmitP88
Oct 01 2017 17:18
@sjames1958gm ah I see. ok, I'll revert to my old code (the commented out code) and retweak it that way
@sjames1958gm thanks for the help. You helped me learn something new today lol
CamperBot
@camperbot
Oct 01 2017 17:19
amitp88 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8500 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Oct 01 2017 17:19
@AmitP88 :+1: So today is a success :)
Amit Patel
@AmitP88
Oct 01 2017 17:20
@sjames1958gm yup :)
RyanHuang06
@RyanHuang06
Oct 01 2017 17:49
I am trying to decode a caesar cipher. Why isn't this working?

function rot13(str) { // LBH QVQ VG!
  for(i=0;i<str.length;i++){
  var k = str.charCodeAt(i);
    k -= 13;

  }
var dec = String.fromCharCode();
return dec;}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
diamant11
@diamant11
Oct 01 2017 17:53
Sup
Ronique Ricketts
@RoniqueRicketts
Oct 01 2017 17:53
@sjames1958gm that's cool, so I guess soon I can say I am a full stack dev in php and nodejs :) wow
diamant11
@diamant11
Oct 01 2017 17:54
Guys??
Ronique Ricketts
@RoniqueRicketts
Oct 01 2017 18:00
sup?
Daniel Mattox
@dmattox10
Oct 01 2017 18:04
I'm adding divs, but only one of the inner divs shows up as an element, div_card contains div_count, and div_art. div_art never shows up, no errors:
function createDeckUI() {
  document.getElementById('deck').innerHTML='';
  var div_card = document.createElement('div');
  var div_count = document.createElement('div');
  var div_art = document.createElement('div');
  var num = Math.floor(Math.random() * 5);
  var deckSuit = "suit";

  switch (num) {
    case 0:
    deckSuit = "suit";
    break;
    case 1:
    deckSuit = "suit d";
    break;
    case 2:
    deckSuit = "suit h";
    break;
    case 3:
    deckSuit = "suit s";
    break;
  };
  console.log(deckSuit);
  div_art.className = deckSuit;
  div_card.className = "card";
  div_card.id = "deckcount";
  div_count.innerHTML = "52";
  div_card.appendChild(div_count);
  div_card.appendChild(div_art);
  document.getElementById('deck').appendChild(div_card);
}
Missed those lines
Tom
@moT01
Oct 01 2017 18:11
what ones arent showing? just divart? - maybe try appending div_card before the others?
Daniel Mattox
@dmattox10
Oct 01 2017 18:12
Just div_art. div_card is the parent of div_count (which shows up and works) and div_art
Tom
@moT01
Oct 01 2017 18:15
i dont suppose you have the code somewhere i can see it, like codepen
Moisés Man
@moigithub
Oct 01 2017 18:16
how u checking ?? inspect element on browser ??
Daniel Mattox
@dmattox10
Oct 01 2017 18:16
if you clone it, open blackjack.html in the browser. Yes, chrome dev tools
Moisés Man
@moigithub
Oct 01 2017 18:16
empty divs dont show on browsers.. cuz no content
Daniel Mattox
@dmattox10
Oct 01 2017 18:17
Ok, but it's not empty, it has a class, do I have to include a character of some type?
Technically, that empty div, should have an image, drawn the same way I did for the players cards.
Moisés Man
@moigithub
Oct 01 2017 18:17
https://jsfiddle.net/4qnjz01v/
check on the result box.. it show nothing
but if u inspect element its there
for testing purposes...
div_art.innerHTML = "hello" ///<< put some content
RyanHuang06
@RyanHuang06
Oct 01 2017 18:20
Why isn't this code working? It says the join is not a function.
//function rot13(str) { //for(n=0;n<str.length;n++){ //var k = str.charCodeAt(n); //k=k-13; //var g = String.fromCharCode(k); //g.join(""); //return g;} //}
Daniel Mattox
@dmattox10
Oct 01 2017 18:21
That code does NOT change anything, or show up as an element.
I did this same cascading div addition, elsewhere, for the individual player cards, I can share that here if it helps.
Tom
@moT01
Oct 01 2017 18:24
i was going to suggest to try and isolate the problem on codepen or jsfiddle @dmattox10
@RyanHuang06 cause it's all commented out
Daniel Mattox
@dmattox10
Oct 01 2017 18:26
I'll try it out.
Tom
@moT01
Oct 01 2017 18:28
@dmattox10 is className right?
is that how to give a class with vanilla? - im wondering if that might be wrong, im not sure
Daniel Mattox
@dmattox10
Oct 01 2017 18:29
className is variable, to load different parts of a CSS sprite.
It's used successfully elsewhere in the code.
THIS code works, does much of the same thing:
function createPlayersUI() //BlackJack
{
    document.getElementById('players').innerHTML = '';
    for(var i = 0; i < players.length; i++)
    {
        var div_player = document.createElement('div');
        var div_playerid = document.createElement('div');
        var div_hand = document.createElement('div');
        var div_points = document.createElement('div');

        div_points.className = 'points';
        div_points.id = 'points_' + i;
        div_player.id = 'player_' + i;
        div_player.className = 'player';
        div_hand.id = 'hand_' + i;

        div_playerid.innerHTML = players[i].ID;
        div_player.appendChild(div_playerid);
        div_player.appendChild(div_hand);
        div_player.appendChild(div_points);
        document.getElementById('players').appendChild(div_player);
        ////console.table(players);
    }
}
Moisés Man
@moigithub
Oct 01 2017 18:39

for testing purposes...
div_art.innerHTML = "hello" ///<< put some content

@dmattox10 r u sure .. setting some innerhtml value dont shows up on ur html?
https://jsfiddle.net/4qnjz01v/3/ works perfectly fine

Amit Patel
@AmitP88
Oct 01 2017 18:41
hey @diamant11 :)
Daniel Mattox
@dmattox10
Oct 01 2017 18:41
Yeah, I know that code, creates div elements, but for some reason, the same code, in the same program, does literally nothing later on.
Tom
@moT01
Oct 01 2017 18:44
did you do that test? put something in art and it didn't show? @dmattox10
Daniel Mattox
@dmattox10
Oct 01 2017 18:44
Yes.
Nothing changed, on the page, or in dev tools
Moisés Man
@moigithub
Oct 01 2017 18:46
Daniel Mattox
@dmattox10
Oct 01 2017 18:47
Yes, that's count, count works, please read the code, ART doesn't work, doesn't show up, never appends to deck.
oh
I see
Moisés Man
@moigithub
Oct 01 2017 18:47
This message was deleted
Daniel Mattox
@dmattox10
Oct 01 2017 18:47
Not here....
Tiago Correia
@tiagocorreiaalmeida
Oct 01 2017 18:48
anyone here took the nodejs course from andrew mead?
Daniel Mattox
@dmattox10
Oct 01 2017 18:48
How can I get a screenshot to show you guys? ART is not on my page, element doesn't exist. What did you change?
I'm pulling my hair out.
Tom
@moT01
Oct 01 2017 18:50
dont do that
Tiago Correia
@tiagocorreiaalmeida
Oct 01 2017 18:50
@dmattox10
Moisés Man
@moigithub
Oct 01 2017 18:51
make a codepen with ur code.. (or similar tool.. jsbin, jsfiddle, plnkr, ...)
Tiago Correia
@tiagocorreiaalmeida
Oct 01 2017 18:51
press print on keyboard
ctrl+v
here
or a codepen
Moisés Man
@moigithub
Oct 01 2017 18:51
printscreen dont work on my side.. dunno why...
but i use gyazo to do screenshot captures
Tiago Correia
@tiagocorreiaalmeida
Oct 01 2017 18:52
or lightshot is a good thing aswell
@moigithub got some knowledge of backend process with nodejs and some nmodules?
Moisés Man
@moigithub
Oct 01 2017 18:53
me.. probably already forgot :P
been a while since got all certs
...need to practice more
learning about patterns atm
Tiago Correia
@tiagocorreiaalmeida
Oct 01 2017 18:54
probably this is a simple thing @moigithub im setting a connection to mlab for mongodb it requires me to insert user name and pw on the connection is there anyway to hide thos values?
nm
gonna add file to gitignore
and proble msolved
:D
Moisés Man
@moigithub
Oct 01 2017 18:57

@dmattox10 add debugger; on ur function
ie

function createDeckUI() {
   debugger;  ///////////<<<<<<<<<<<<

  document.getElementById('deck').innerHTML='';
  var div_card = document.createElement('div');
  var div_count = document.createElement('div');

that will make ur code stops.. then u can execute line by line

Daniel Mattox
@dmattox10
Oct 01 2017 19:00
How do I "step"? I don't see what to click?
Moisés Man
@moigithub
Oct 01 2017 19:01
there are some arrows on devtools... lemme make a ss
Daniel Mattox
@dmattox10
Oct 01 2017 19:02
I'm willing to paste "debugger;" every other line if I have to lol.
Daniel Mattox
@dmattox10
Oct 01 2017 19:04
Second button from the left, stepping!
Moisés Man
@moigithub
Oct 01 2017 19:07
while u debuggin.. u can switch to console tab.. (since all those variables/code is loaded on memory)
and do console.log(div_art) (or use console.dir) to check its content (or whatever js code u like )
Tiago Correia
@tiagocorreiaalmeida
Oct 01 2017 19:08
@moigithub
image.png
im 100% sure the data is correct any idea what might be missing?
Daniel Mattox
@dmattox10
Oct 01 2017 19:09
I've got some kind of odd behavior, whenever a new message pops up in this channel, I get the contents of the chat, dumped into the contents of my JS file open in chrome.
Tiago Correia
@tiagocorreiaalmeida
Oct 01 2017 19:11
got it working nm
Kelechi Chinaka
@kelechy
Oct 01 2017 19:11
:smile: oooohh!!, how did i miss that... thanks @moigithub
CamperBot
@camperbot
Oct 01 2017 19:11
kelechy sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3648 | @moigithub |http://www.freecodecamp.com/moigithub
Moisés Man
@moigithub
Oct 01 2017 19:12
@tiagocorreiaalmeida on top of ur screenshot it says.. MongoError : Authentication failed.
on heroku dont forget to setup ur environment variables
Tiago Correia
@tiagocorreiaalmeida
Oct 01 2017 19:13
yeah
forgot to clean the <>
:D
before the user and password
Moisés Man
@moigithub
Oct 01 2017 19:14
:)
Daniel Mattox
@dmattox10
Oct 01 2017 19:21
@moigithub THANK YOU
CamperBot
@camperbot
Oct 01 2017 19:21
dmattox10 sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3649 | @moigithub |http://www.freecodecamp.com/moigithub
Daniel Mattox
@dmattox10
Oct 01 2017 19:22
For some reason, deckcount interferes with art. Removing the deck count, art loads, and behaves.
Tiago Correia
@tiagocorreiaalmeida
Oct 01 2017 19:24
@moigithub I got the db set and everything on plan but when I run a page that would insert some data to db it doesnt follow that process plus I dont get any error on logs
any idea what i might be missign here?
Kelechi Chinaka
@kelechy
Oct 01 2017 19:26
what project are you working on @tiagocorreiaalmeida
Tiago Correia
@tiagocorreiaalmeida
Oct 01 2017 19:28
an udemy course previously mathlad addone on heroku didnt required cc not it does so I just created a mlab acc and now trying to insert data to there but I think my problem is really on the code that writes in a new document
but understanding this first before doing the url shortner
that's the point
Kelechi Chinaka
@kelechy
Oct 01 2017 19:29
o cool
Tiago Correia
@tiagocorreiaalmeida
Oct 01 2017 19:29
my mistake
somehow postman setted back the method to get
instead of post
just saw it now arg :D
@dmattox10 got it all fixed or still some isuses?
Daniel Mattox
@dmattox10
Oct 01 2017 19:36
Still issues. I got the card count, and the sprite, to show up where they belong, but when the card count gets updated, the card art does not.
Tiago Correia
@tiagocorreiaalmeida
Oct 01 2017 19:38
@dmattox10 can you create a codepen wit hit?
Daniel Mattox
@dmattox10
Oct 01 2017 19:39
yes, but I have no way of including the sprite then? It's up on github, if that would be easier for you.
Tiago Correia
@tiagocorreiaalmeida
Oct 01 2017 19:40
link?
I can give it a look there
or try to
Fixed card update. All thats left now, is to fix a div I accidentally deleted. Thanks for the interest @tiagocorreiaalmeida
CamperBot
@camperbot
Oct 01 2017 19:41
dmattox10 sends brownie points to @tiagocorreiaalmeida :sparkles: :thumbsup: :sparkles:
:cookie: 373 | @tiagocorreiaalmeida |http://www.freecodecamp.com/tiagocorreiaalmeida
Tiago Correia
@tiagocorreiaalmeida
Oct 01 2017 19:43
ui.js file right?
Daniel Mattox
@dmattox10
Oct 01 2017 19:47
Yes.
Tiago Correia
@tiagocorreiaalmeida
Oct 01 2017 19:47
gonna be hard to debugg this
do you get any error on console?
Daniel Mattox
@dmattox10
Oct 01 2017 19:47
lol, no need, like I said, i fixed it.
Tiago Correia
@tiagocorreiaalmeida
Oct 01 2017 19:47
aaa ok :D
Daniel Mattox
@dmattox10
Oct 01 2017 19:47
I thanked you above.
Tiago Correia
@tiagocorreiaalmeida
Oct 01 2017 19:47
im blind
korn song plays in the background
Ayush Bahuguna
@relentless-coder
Oct 01 2017 20:07

@relentless-coder
So, I have been trying to hack together a hacky js syntax highlighter, but it is acting bizarre

function highlightFilter(value) {
    if (value) {
      let keywords = 'in of if for while finally var new function do return void else break catch instanceof with throw case default try this switch continue typeof delete let yield const export super debugger as async await static import from as'

      let literal = 'true false null undefined NaN Infinity'
      let builtIn = 'eval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Error EvalError InternalError RangeError ReferenceError StopIteration SyntaxError TypeError URIError Number Math Date String RegExp Array Float32Array Float64Array Int16Array Int32Array Int8Array Uint16Array Uint32Array Uint8Array Uint8ClampedArray ArrayBuffer DataView JSON Intl arguments require module console window document Symbol Set Map WeakSet WeakMap Proxy Reflect Promise'

      keywords = keywords.split(' ');
      literal = literal.split(' ');
      builtIn = builtIn.split(' ');
      keywords.forEach((el) => {
        value = value.replace(new RegExp(el, 'g'), `<span class="js-keyword">${el}</span>`)
      })
      literal.forEach((el) => {
        value = value.replace(new RegExp(el, 'g'), `<span class="js-literal">${el}</span>`)
      })
      builtIn.forEach((el) => {
        value = value.replace(new RegExp(el, 'g'), `<span class="js-builtIn">${el}</span>`)
      })
      return value
    }
}

Sorry, for the wall of code

The idea is that I replace each javascript code with that particular word wrapped in a span with a specific class attached to it
but instead what this does is, i can't even explain, let me put up a screenshot
Alex
@alexandrupintilei
Oct 01 2017 20:47
Hello world!
Daniel Mattox
@dmattox10
Oct 01 2017 20:47
Hello!
legendinraze
@legendinraze
Oct 01 2017 21:05
why did thsi come out as 5?
var tools = ["drill","saw","screwdriver","pliers"]

// Add a hammer to the array in the next number index.
tools.push(["hammer"]);
this*
piteto
@piteto
Oct 01 2017 21:07
@legendinraze .push() adds an item to an array and returns the new length of the array. Your new array length is 5
legendinraze
@legendinraze
Oct 01 2017 21:07
ok but I wan't hammer to be in the sentance
want*
nevermind I got thanks @piteto
CamperBot
@camperbot
Oct 01 2017 21:08
legendinraze sends brownie points to @piteto :sparkles: :thumbsup: :sparkles:
:cookie: 176 | @piteto |http://www.freecodecamp.com/piteto
piteto
@piteto
Oct 01 2017 21:09
var tools = ["drill","saw","screwdriver","pliers"] 
// Add a hammer to the array in the next number index. 
tools.push(["hammer"]);
console.log(tools); // ["drill", "saw", "screwdriver", "pliers", ["hammer"]]
piteto
@piteto
Oct 01 2017 21:43
@relentless-coder It's hard to say without seeing how you're calling the function. It seems to return the correct value, though you could simplify it a bit without the multiple for each loops and regex replacements
function highlightFilter(value) {
  if (value) {
    let keywords = "in of if for while finally var new function do return void else break catch instanceof with throw case default try this switch continue typeof delete let yield const export super debugger as async await static import from as";
    let literal = "true false null undefined NaN Infinity";
    let builtIn = "eval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Error EvalError InternalError RangeError ReferenceError StopIteration SyntaxError TypeError URIError Number Math Date String RegExp Array Float32Array Float64Array Int16Array Int32Array Int8Array Uint16Array Uint32Array Uint8Array Uint8ClampedArray ArrayBuffer DataView JSON Intl arguments require module console window document Symbol Set Map WeakSet WeakMap Proxy Reflect Promise";

    [[keywords, "keyword"], [literal, "literal"], [builtIn, "builtIn"]].forEach(arr => {
      if (arr[0].includes(value)) value = `<span class="js-${arr[1]}">${value}</span>`;
    });
  }
  return value;
}
Tiago Correia
@tiagocorreiaalmeida
Oct 01 2017 21:45
@piteto are you used to mongoose?
Gyllenbern
@Gyllenbern
Oct 01 2017 21:57
@jonandrepedersen Thanks for inviting me jon =)!
CamperBot
@camperbot
Oct 01 2017 21:57
gyllenbern sends brownie points to @jonandrepedersen :sparkles: :thumbsup: :sparkles:
:cookie: 295 | @jonandrepedersen |http://www.freecodecamp.com/jonandrepedersen
Carlos Pulido
@carlosfrontend
Oct 01 2017 22:38
hi /@all
i´m in Exact Change challenge somebody can tell me why it not works i´m starting

function checkCashRegister(price, cash, cid) {

  var change_due = (cash -price).toFixed(2);

  var cash_in_drawer = 0;

  var formatChashInDrawer = 0;




  for(var i in cid){
    cash_in_drawer+= (cid[i][1]);
  }

  formatChashInDrawer = cash_in_drawer.toFixed(2);

  if(cash_in_drawer < change_due ){
    return "Insufficient Funds";
  }  

}

// Example cash-in-drawer array:
// [["PENNY", 1.01], 1 ct
// ["NICKEL", 2.05], 5 ct
// ["DIME", 3.10], 10 ct
// ["QUARTER", 4.25], 25 ct
// ["ONE", 90.00], 100 ct
// ["FIVE", 55.00], 500 ct
// ["TEN", 20.00], 1000 ct
// ["TWENTY", 60.00], 10000 ct
// ["ONE HUNDRED", 100.00]] 100000 ct Devuelva la cadena "Fondos Insuficientes" si el efectivo en el cajón es menor que el cambio debido. 

checkCashRegister(19.50, 20.00, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 1.00], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]);
Stephen James
@sjames1958gm
Oct 01 2017 22:46
@carlosfrontend Because there is more money in the drawer than the change needed, just that there is no money with which to make .50
Carlos Pulido
@carlosfrontend
Oct 01 2017 22:48
ok i understand now @sjames1958gm
i`m not saw it jejj
thanks @sjames1958gm
CamperBot
@camperbot
Oct 01 2017 22:49
carlosfrontend sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8502 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Carlos Pulido
@carlosfrontend
Oct 01 2017 22:53
i suposse that it is better


function checkCashRegister(price, cash, cid) {

  var change_due = (cash -price).toFixed(2);

  var cash_in_drawer = 0;

  var formatChashInDrawer = 0;




  for(var i in cid){
    cash_in_drawer+= (cid[i][1]);
  }

  formatChashInDrawer = cash_in_drawer.toFixed(2);



  if(cash_in_drawer < change_due || cash_in_drawer % change_due !== 0 ){

    return "Insufficient Funds";
  }

  if(cash_in_drawer == change_due){
    return "Closed";
  }


}

// Example cash-in-drawer array:
// [["PENNY", 1.01], 1 ct
// ["NICKEL", 2.05], 5 ct
// ["DIME", 3.10], 10 ct
// ["QUARTER", 4.25], 25 ct
// ["ONE", 90.00], 100 ct
// ["FIVE", 55.00], 500 ct
// ["TEN", 20.00], 1000 ct
// ["TWENTY", 60.00], 10000 ct
// ["ONE HUNDRED", 100.00]] 100000 ct Devuelva la cadena "Fondos Insuficientes" si el efectivo en el cajón es menor que el cambio debido. 

checkCashRegister(19.50, 20.00, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 1.00], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]);
what you think @sjames1958gm ?
Tiago Correia
@tiagocorreiaalmeida
Oct 01 2017 22:54
@sjames1958gm is it ok to create a promise from another? I needto wait for a variable to be set and can't think of anything else
        urlShort.findOne({}, {}, { sort: { 'key' : -1 } }).then((doc) =>{
                //checks if is there any url created at all if not return key = 1;
                if(doc){
                    tempKey = doc.key + 1;
                }
              },(err)=>{
                  response.status(400).send(err);
              });
need to wait for tempkey to be set