These are chat archives for FreeCodeCamp/HelpJavaScript

1st
Nov 2017
Morchid Chellali
@Morched23MJ
Nov 01 2017 00:01 UTC
In the Tic Tac Toe game, I have been trying to make the part for when the 'computer' plays its turn. If the center is empty it takes it, else it would search for an empty one to take it. But it doesn't seem to work. I'd appreciate any help, here is my pen: https://codepen.io/Morched23MJ/pen/VzRQZM
Diego Mayer
@Chrono79
Nov 01 2017 00:08 UTC
@Morched23MJ Sorry, I'm tired but, there are several things that doesn't work there, try making it work part by part, it's not easy to read a lot of code
Morchid Chellali
@Morched23MJ
Nov 01 2017 00:10 UTC
@Chreono79, I understand, thanks. I made a kind of messy code there.. :l
CamperBot
@camperbot
Nov 01 2017 00:10 UTC
api offline
morched23mj sends brownie points to @chreono79 :sparkles: :thumbsup: :sparkles:
Diego Mayer
@Chrono79
Nov 01 2017 00:10 UTC
In single player no matter what I choose the game starts with X
In multiplayer I've fallen in an infinite loop after 4 moves
Morchid Chellali
@Morched23MJ
Nov 01 2017 00:11 UTC
The multiplayer works fine, I tested it. :OO
Diego Mayer
@Chrono79
Nov 01 2017 00:11 UTC
I'll try to reproduce it
Morchid Chellali
@Morched23MJ
Nov 01 2017 00:13 UTC
The parts that are concerned with the problem, are functions PredictPlayerWin which also makes the AI plays and function predictTool that I use to try to predict which move of the player can make him win, and I use these functions when any column is clicked and there is only one player (!players).
Diego Mayer
@Chrono79
Nov 01 2017 00:14 UTC
@Morched23MJ in multiplayer choose O
when you first click it shows X
and sometimes it shows draw after 4 moves (can't point it out how)
happened twice
Morchid Chellali
@Morched23MJ
Nov 01 2017 00:15 UTC
Because who ever choses X is always the first to start.
chooses*
Diego Mayer
@Chrono79
Nov 01 2017 00:17 UTC
Like chess with the white pieces?
Morchid Chellali
@Morched23MJ
Nov 01 2017 00:18 UTC
I don't really know, but I read that who chooses X always starts first, and in the second play, O starts.
Roger Futrell
@rogfut
Nov 01 2017 03:00 UTC
Happy halloween all! Im stuck on this challenge. I was able to solve it without using reduce, but would like to solve it with. Could anyone give me a hint how I would reduce to solve the problem? https://www.freecodecamp.org/challenges/sorted-union
my approach without reduce was to flatten the array of arrays into a single array, then add it to a new array if the value didn't already exist
Diego Mayer
@Chrono79
Nov 01 2017 03:08 UTC
@rogfut reduce can be used to flatten the arrays into a single array, then you can filter the values that repeat
Roger Futrell
@rogfut
Nov 01 2017 03:16 UTC
@Chrono79 thanks Diego - i tried to use reduce to flatten but was missing something. To filter the values that repeat would that be using reduce as well?
CamperBot
@camperbot
Nov 01 2017 03:16 UTC
rogfut sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4595 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Nov 01 2017 03:16 UTC
@rogfut better use filter for that
with reduce you can use an initial value
Roger Futrell
@rogfut
Nov 01 2017 03:18 UTC
thanks!
Roger Futrell
@rogfut
Nov 01 2017 04:41 UTC
does anyone have a recommended resource on understanding callbacks?
callback is a kind of higher order function that is executed later instead of now
You may also read Book 5 of YDKJS which covers Async (explains the difference between now and later)
Roger Futrell
@rogfut
Nov 01 2017 04:46 UTC
@ashwins93 thank you, I will check those out
CamperBot
@camperbot
Nov 01 2017 04:46 UTC
rogfut sends brownie points to @ashwins93 :sparkles: :thumbsup: :sparkles:
:cookie: 405 | @ashwins93 |http://www.freecodecamp.com/ashwins93
tarun47900
@tarun47900
Nov 01 2017 05:13 UTC
Is there any advanced javascript section in codecamp
RakeshNerkar
@Rakesh18754
Nov 01 2017 06:02 UTC
@Masd925 Thanks a lot ...Markus.....Superb explanation!!!
CamperBot
@camperbot
Nov 01 2017 06:02 UTC
rakesh18754 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4556 | @masd925 |http://www.freecodecamp.com/masd925
How can i use Array equal to compare ?anyone have a advice?
RakeshNerkar
@Rakesh18754
Nov 01 2017 06:06 UTC
1+1+"3" outputs :  "23"
"3"+1+1 outputs :  "311"
why so?
"3"+1 //"31" string
Markus Kiili
@Masd925
Nov 01 2017 06:10 UTC
@Rakesh18754 If either addition operator operand is a string, both are coerced to strings and concatenated.
If not, both are coerced to numbers and added.
RakeshNerkar
@Rakesh18754
Nov 01 2017 06:19 UTC
@Masd925 so the engine read value from left to right and if the first two are integer it will add those....m i right?
Markus Kiili
@Masd925
Nov 01 2017 06:20 UTC
@Rakesh18754 Yes.
RakeshNerkar
@Rakesh18754
Nov 01 2017 06:20 UTC
@Masd925 cool...got it.....Thanks again...
CamperBot
@camperbot
Nov 01 2017 06:20 UTC
rakesh18754 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
api offline
Taro
@TaroWong
Nov 01 2017 08:41 UTC

Hi everyone. I have a question regarding this challenge.
https://www.freecodecamp.org/challenges/mutations

The challenge is to return true if the string in the first element of the array contains all of the letters of the string in the second element of the array.

I managed to find the solution by filtering out the common letters from both array.

function mutation(arr) {

  var first = arr[0].toLowerCase().split('');
  var second = arr[1].toLowerCase().split('');

  perfect = first.filter(function(letter){
    if(second.indexOf(letter) > -1){
      return letter;
    }
  });
  return perfect;
}
mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"]);

How should I proceed because the letters I filtered out have a difference letter sequence from the one FCC gave.

I am thinking of using a for loop
Taro
@TaroWong
Nov 01 2017 08:50 UTC
Okay I just checked the answer. Seems like I am overcomplicating myself
Markus Kiili
@Masd925
Nov 01 2017 10:01 UTC
@TaroWong You need to loop the second string characters and see if they are found on the first.
Stephen James
@sjames1958gm
Nov 01 2017 10:50 UTC
@TaroWong You could use filter on the second string and filter out those letters in the first string.
Return true/false if all the letters are filtered out.
husterlihuijuan
@husterlihuijuan
Nov 01 2017 12:19 UTC
Roman Numeral Converter
yofri
@yofriadi
Nov 01 2017 12:25 UTC
Hi guys, need help
how to filter this name into one?
[ { candidate_name: 'Rep. Dan Benishek',
    total_votes: 32,
    full_name: 'Watson Mueller' },
  { candidate_name: 'Rep. Dan Benishek',
    total_votes: 32,
    full_name: 'Reed Schneider' },
  { candidate_name: 'Rep. Dan Benishek',
    total_votes: 32,
    full_name: 'Frederique Schuppe' }]
i mean the candidate_name
Long Nguyen
@longnt80
Nov 01 2017 12:30 UTC
@Yofri what do you mean?
filter into another array that contains only those names?
yofri
@yofriadi
Nov 01 2017 12:30 UTC
@longnt80 i need to filter the candidate_name to only return unique names
you can ignore the other property
Long Nguyen
@longnt80
Nov 01 2017 12:31 UTC
ok let me see
@Yofri what's the return result? Array?
yofri
@yofriadi
Nov 01 2017 12:33 UTC
@longnt80 yes array is good
[ { name: 'name' },
  { name: 'name'},
  { name: 'another name'}]
i should use simpler code to ask
@longnt80 i just get the answer man :D
Long Nguyen
@longnt80
Nov 01 2017 12:38 UTC
@Yofri :+1:
yofri
@yofriadi
Nov 01 2017 12:38 UTC
const unique = [...new Set(arraysToFilter.map(item => item.candidate_name))];
Long Nguyen
@longnt80
Nov 01 2017 12:39 UTC
es6 is nice
@Yofri what these do: new Set
?
yofri
@yofriadi
Nov 01 2017 12:41 UTC
...new is spreading
Set is new type of data
@longnt80 i cant explain much since i dont understand it very clear
Long Nguyen
@longnt80
Nov 01 2017 12:42 UTC
it's okay, I got it
Alex
@alexandrupintilei
Nov 01 2017 12:42 UTC
What i need to make navbar links to be responsive(when i click on it,to directionate me to a specific page in site) ?
Sameer Jain
@SJ50
Nov 01 2017 12:57 UTC
for (var i = 0; i < 9; i++) { var arr = ["O",,"X","X",,,"X","O","O"]; if (Boolean(arr[i])) { continue; } console.log(arr); var arrX=[]; arrX=arr; arrX[i] = "X"; console.log(arr); }
I am just trying to change arrX but for some reason arr also getting changed
how do I stop this
how to prevent changing arr
Markus Kiili
@Masd925
Nov 01 2017 12:58 UTC
@SJ50 arrX=arr.slice();
Might be some other problems too with the loop logic there.
Marianissimus
@Marianissimus
Nov 01 2017 13:00 UTC
@SJ50 why so many ,,, in the array? just curious
Sameer Jain
@SJ50
Nov 01 2017 13:01 UTC
@Masd925 arrX=arr.slice(); worked
but why defining arrX= arr and changin arrX also changes arr?
Markus Kiili
@Masd925
Nov 01 2017 13:01 UTC
@SJ50 After arrX=arr both variables point to the same array in memory.
Sameer Jain
@SJ50
Nov 01 2017 13:02 UTC
@Marianissimus I am trying to write algorithm for tic tac toe game
Markus Kiili
@Masd925
Nov 01 2017 13:02 UTC
@Marianissimus Those commas create holes in the array.
Sameer Jain
@SJ50
Nov 01 2017 13:03 UTC
so if I say var a= 2; b=a; and changes b=5 also changes value of a
Markus Kiili
@Masd925
Nov 01 2017 13:03 UTC
@SJ50 No.
@SJ50 Variables hold either primitive values or references to objects (arrays are objects).
Sameer Jain
@SJ50
Nov 01 2017 13:05 UTC
so objects goes to memory and if two variable are identical objects by changing one object also changes second?
can you give me some material to read on this?
Markus Kiili
@Masd925
Nov 01 2017 13:06 UTC
@SJ50 Yes, if both variables hold a reference to the same object, mutating the object will of course be seen using either variable.
Sameer Jain
@SJ50
Nov 01 2017 13:09 UTC
var arrX=[]; arrX=arr; by doing this isn't arrX is separate object?
Markus Kiili
@Masd925
Nov 01 2017 13:11 UTC
@SJ50 No. var arrX=[]; makes an array in memory and stores a reference (~memory location) on variable arrX. After arr=arrX, that reference is copied to arr too. So you manipulate the same object with either variable.
Sameer Jain
@SJ50
Nov 01 2017 13:12 UTC
this is complicated for to absorbs it, anyway thank you
@SJ50 arrX=arr.slice();thank you
Markus Kiili
@Masd925
Nov 01 2017 13:13 UTC
@SJ50 slice() makes a copy of the original array.
Sameer Jain
@SJ50
Nov 01 2017 13:16 UTC
I can use this command as well arrX=Array.from(arr);
Margaret Greaney
@greaneym
Nov 01 2017 15:11 UTC
hello, I am making baby step progress on learning how to interact with pixi.js and react for the game challenge. I am stuck on figuring out how to set the ticker speed back on a reset. I am not sure how to reset the ticker speed. Does it happen in the pixi.js reset or in the onResetGame in react ? I've tried both ways. Also need help on stopping the RAF frame. I have almost a working setup locally and not yet on code pen but here is my code and I would appreciate any help. It is very messy at this point (warning).
I will come back later to see if anyone has the time to take a look and suggest anything. Thanks.
Morchid Chellali
@Morched23MJ
Nov 01 2017 16:27 UTC

In the Tic Tac Toe game, I have made the function below to predict the win, if the player is playing against the AI, so when there is only one spot to take by the player so he gets the win, the AI takes it. It works sometimes, sometimes it blocks, and the function returns undefined.

function predictTool(u, v, w) {
  if (((sH('c'+u) === sH('c'+v)) && (sH('c'+u) === '')) || ((sH('c'+w) === sH('c'+v)) && (sH('c'+w) === '')) || ((sH('c'+u) === sH('c'+w)) && (sH('c'+w) === ''))) return false;
  else if (sH('c'+u) === '') {
   console.log(u+'1');
    return u;
  }
  else if (sH('c'+v) === '') {
   console.log(v+'2');
    return v;
  }
  else if (sH('c'+w) === '') {
   console.log(w+'3');
    return w;
  }
}

here is the pen: https://codepen.io/Morched23MJ/pen/VzRQZM

Those console.logs are only there to know where the function actually goes. Same for the code in the pen, just to monitor how things go.
eswhy27
@eswhy27
Nov 01 2017 16:28 UTC

quick question I just completed the return early pattern for functions challenge https://www.freecodecamp.org/challenges/return-early-pattern-for-functions

I am just wondering why when writing my if stmt, my function does run correctly when I write

if( a || b < 0) it only works seperating the two conditions thus if (a<0 || b<0) is what works....why is this?

Morchid Chellali
@Morched23MJ
Nov 01 2017 16:28 UTC
Because it's the syntax required by the language? :l
korzo
@korzo
Nov 01 2017 16:29 UTC
@Morched23MJ as you return from inside the if, you don't need else if
Morchid Chellali
@Morched23MJ
Nov 01 2017 16:29 UTC
Yeah, you mean I could remove the elses? @korzo
korzo
@korzo
Nov 01 2017 16:30 UTC
@Morched23MJ yes
if(x) {
   return true;
}

if(y) {
   return true;
}
@Morched23MJ if it returns undefined it means, that none of conditions is true
Add console.log athe end of the function to see arguments, when it happens
Morchid Chellali
@Morched23MJ
Nov 01 2017 16:33 UTC
I see.. :l I forgot to tell you that you have to choose always X, I haven't made the part when the AI starts, for now, I'm just making how the AI plays. I guess you understood the logic behind my function? @korzo It checks if one the three win combo is empty so it returns it, and the AI takes it..
korzo
@korzo
Nov 01 2017 16:35 UTC
@eswhy27 if( a || b < 0) means : if a is not falsy(0) or b is less than zero
Morchid Chellali
@Morched23MJ
Nov 01 2017 16:36 UTC
You mean truthy, @korzo?
Could you point out why it returns underfined when it should have returned the correct value? :l
korzo
@korzo
Nov 01 2017 16:37 UTC
@Morched23MJ I meant NOT falsy :)
Morchid Chellali
@Morched23MJ
Nov 01 2017 16:38 UTC
Lol, I didn't notice
korzo
@korzo
Nov 01 2017 16:40 UTC
@Morched23MJ you can also add debugger; at the end of function and open Devtools.
Javascript will stop if reach this statement and you can inspect the situation
Morchid Chellali
@Morched23MJ
Nov 01 2017 16:41 UTC
Alright, thank you @korzo.
CamperBot
@camperbot
Nov 01 2017 16:41 UTC
morched23mj sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 713 | @korzo |http://www.freecodecamp.com/korzo
eswhy27
@eswhy27
Nov 01 2017 16:41 UTC
@korzo thanks for the explanation!
CamperBot
@camperbot
Nov 01 2017 16:41 UTC
eswhy27 sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 714 | @korzo |http://www.freecodecamp.com/korzo
korzo
@korzo
Nov 01 2017 16:42 UTC
@Morched23MJ it happens in this situation u = "1", v = "2", w = "3"
eswhy27
@eswhy27
Nov 01 2017 16:42 UTC
@korzo makes sense after doing some research on your explanation
korzo
@korzo
Nov 01 2017 16:46 UTC
@Morched23MJ it looks like it returns undefined in case of winning turn
@Morched23MJ You doesn't cover the situation, when non of u, v, w is empty
Morchid Chellali
@Morched23MJ
Nov 01 2017 16:48 UTC
I'll try to understand what's happening. Thanks! :smile:
korzo
@korzo
Nov 01 2017 16:49 UTC
@Morched23MJ more exactly it reaches the end of the function when all u, v, w are not empty
Ronique Ricketts
@RoniqueRicketts
Nov 01 2017 17:00 UTC
hey guys I am trying out nodejs backend challenges from fcc but I am getting an error when I try to install learnyounode
Jason Luboff
@JLuboff
Nov 01 2017 17:00 UTC
@RoniqueRicketts Thats becuase learnyounode is awful :D
Ashwin
@ashwins93
Nov 01 2017 17:00 UTC
@RoniqueRicketts what error are you getting?
Ronique Ricketts
@RoniqueRicketts
Nov 01 2017 17:00 UTC
@JLuboff so is it not working?
module.js:471
    throw err;
    ^

Error: Cannot find module 'process-nextick-args'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/ubuntu/.nvm/versions/node/v6.11.2/lib/node_modules/npm/node_modules/readable-stream/lib/_stream_readable.js:26:23)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
Jason Luboff
@JLuboff
Nov 01 2017 17:01 UTC
No, I'm sure it works but its just a garbage tutorial system
Ronique Ricketts
@RoniqueRicketts
Nov 01 2017 17:01 UTC
which tutorial do you suggest to learn nodejs
right here in the terminal or cloud9 environment
Ashwin
@ashwins93
Nov 01 2017 17:01 UTC
@RoniqueRicketts you get that error on cloud9?
Jason Luboff
@JLuboff
Nov 01 2017 17:01 UTC
Personally I purchased a few courses on udemy
Ronique Ricketts
@RoniqueRicketts
Nov 01 2017 17:02 UTC
@JLuboff your :ok_hand: wrong :ok_hand: bigly
I ain't spending a dime to learn nodejs
Ashwin
@ashwins93
Nov 01 2017 17:03 UTC
@RoniqueRicketts haha you don't have to there are plenty of free resources
Ronique Ricketts
@RoniqueRicketts
Nov 01 2017 17:03 UTC
I'm o get youtubing then.
@ashwins93 yes
Ashwin
@ashwins93
Nov 01 2017 17:03 UTC
try installing learnyounode without -g
Jason Luboff
@JLuboff
Nov 01 2017 17:03 UTC
Ya I'm sure there are plenty of free courses, thats just the route I took
Ronique Ricketts
@RoniqueRicketts
Nov 01 2017 17:03 UTC
@ashwins93 what is the best one you suggest
@ashwins93 same error without the -g flaf
Ashwin
@ashwins93
Nov 01 2017 17:04 UTC
@RoniqueRicketts I actually learned only from the learnyounode
which OS are you running?
Ronique Ricketts
@RoniqueRicketts
Nov 01 2017 17:04 UTC
@ashwins93 I am on windows. I am actually at work so I am stuck with windows.
Ashwin
@ashwins93
Nov 01 2017 17:05 UTC
ah okay then try to install npm install process-nextick-args before learnyounode
Ronique Ricketts
@RoniqueRicketts
Nov 01 2017 17:11 UTC
@ashwins93 that fails also
Ashwin
@ashwins93
Nov 01 2017 17:11 UTC
you couldn't install a node module
i think you are having permission issues
Ronique Ricketts
@RoniqueRicketts
Nov 01 2017 17:14 UTC
man screw this shit I am going to delete the project and try again
Ashwin
@ashwins93
Nov 01 2017 17:15 UTC
haha
Ronique Ricketts
@RoniqueRicketts
Nov 01 2017 17:18 UTC
@ashwins93 setting up
Ashwin
@ashwins93
Nov 01 2017 17:19 UTC
i know node can run on any OS, but most of these packages were made with linux in mind, if you can find a linux machine things would be smooth
Jason Luboff
@JLuboff
Nov 01 2017 17:20 UTC
I've had no problems with node on windows
and c9 is already running linux
Ashwin
@ashwins93
Nov 01 2017 17:22 UTC
@JLuboff yeah it actually runs fine
but sometimes the packages are effed up
i had some issues with the learnyoumongo on pc
Jason Luboff
@JLuboff
Nov 01 2017 17:24 UTC
I did the learnyou Modules through c9 so I dunno about those...just that they suck lol. I switched to local development after the API projects
Ashwin
@ashwins93
Nov 01 2017 17:24 UTC
i don't find c9 any more useful than the local environment
we could just develop locally and deploy on heroku, that seems much convenient than c9
Jason Luboff
@JLuboff
Nov 01 2017 17:46 UTC
@ashwins93 I agree, I only used c9 at first when I was doing the API projects then switched to local and have kept up with that. Then I deploy to Heroku or Glitch
Ronique Ricketts
@RoniqueRicketts
Nov 01 2017 18:01 UTC
@ashwins93 ok Ill try make a linux system
Jason Luboff
@JLuboff
Nov 01 2017 18:02 UTC
@RoniqueRicketts c9 is already linux, just fyi
Ronique Ricketts
@RoniqueRicketts
Nov 01 2017 18:02 UTC
@JLuboff oh silly me. but it wont work
Ronique Ricketts
@RoniqueRicketts
Nov 01 2017 18:33 UTC
I did it
Margaret Greaney
@greaneym
Nov 01 2017 18:34 UTC
I have a question about the react game challenge. After doing the tic tac toe and simon game, this one is the third I've ever worked on, so not familiar with game engines. It looks like game engines do not use buttons to control start, stop, etc.
But I am using react to do these things. Is that wrong?
Jason Luboff
@JLuboff
Nov 01 2017 18:34 UTC
@RoniqueRicketts :+1:
Ronique Ricketts
@RoniqueRicketts
Nov 01 2017 18:34 UTC
@JLuboff I am gonna learn
Margaret Greaney
@greaneym
Nov 01 2017 18:41 UTC
Returning later.
git00000
@git00000
Nov 01 2017 18:42 UTC
hey
I am confused by the meaning of this phrases
plase help
becareful when using the negated s horthands inside square brackets. « [\D\S] » is not the same as « [^\d\s] ». The latter will match any character that is not a digit or whitespace. So it will match „ x ”, but not “ 8 ”. The former, however, will match any character that is either not a digit, or is not whitespace. Because a digit is not whitespace, and whitespace is not a digit, « [\D\S] » will match any character, digit, whitespace or otherwise.
thanks in advance, I am not so good in english
Markus Kiili
@Masd925
Nov 01 2017 18:50 UTC
@JLuboff Yo.
Jason Luboff
@JLuboff
Nov 01 2017 18:50 UTC
@Masd925 Yo
Markus Kiili
@Masd925
Nov 01 2017 18:52 UTC
@JLuboff I'm going to apply for another job in spring (season, not the framework).
Jason Luboff
@JLuboff
Nov 01 2017 18:52 UTC
@Masd925 Nice, tired of PHP? :P
Markus Kiili
@Masd925
Nov 01 2017 18:53 UTC
hmm, actually it might have something to do with the framework.
No, I have managed to avoid that 3-letter word and this move is part of that big plan.
Jason Luboff
@JLuboff
Nov 01 2017 18:54 UTC
Good deal. Better paying job?
Markus Kiili
@Masd925
Nov 01 2017 18:56 UTC
@JLuboff It is like master-apprentice line in a big company. Front and/or backend line and data analytics line are possible.
I know two people in the firm and one got there with that same route.
Jason Luboff
@JLuboff
Nov 01 2017 18:57 UTC
Awesome
Markus Kiili
@Masd925
Nov 01 2017 18:57 UTC
Most likely better paying than this job.
Taro
@TaroWong
Nov 01 2017 18:58 UTC
Hi everyone
Has anyone completed the Caesars Cipher challenge?
Jason Luboff
@JLuboff
Nov 01 2017 18:59 UTC
Yes
git00000
@git00000
Nov 01 2017 19:00 UTC
@Masd925 hey
@git00000 how are you?
Markus Kiili
@Masd925
Nov 01 2017 19:01 UTC
@git00000 Hi. Fine.
Taro
@TaroWong
Nov 01 2017 19:01 UTC

I managed to get the regular expression correct but on my console it shows different results.

This is my regular expression

/([A-M])|([N-Z])/g

However, when I try to check it on the console. There are undefined objects?

  return str.replace(/([A-M])|([N-Z])/g, function(match, g1, g2){
    console.log(g1);
    console.log(g2);
  });
git00000
@git00000
Nov 01 2017 19:01 UTC
@Masd925 why this [^\d\s] != [\D\S]
Markus Kiili
@Masd925
Nov 01 2017 19:02 UTC
@git00000 Not sure about that one. Regexp is not my strong point.
git00000
@git00000
Nov 01 2017 19:02 UTC
tks
@TaroWong means charecter that are not in the range A-M or not in the range N-Z
@TaroWong I think it won't work, It look like contraditory to me
maybe use [A-Z]
Taro
@TaroWong
Nov 01 2017 19:05 UTC

@git00000

I tested it on https://regexr.com/ and it matches what I want :(

I am not using A-Z because I need to target 2 groups. A-M and N-Z
My full code is below. But it is not working as I am getting some undefined results.
function rot13(str) {
  return str.replace(/([A-M])|([N-Z])/g, function(match, g1, g2){
    g1 = g1.charCodeAt(0);
    g2 = g2.charCodeAt(0);
    return String.fromCharCode(g1+13, g2-13);
  });
}
rot13("SERR CVMMN!"); //"FREE PIZZA!"
Moisés Man
@moigithub
Nov 01 2017 19:06 UTC
if match the first group.. ie. "A".. then g2 will be undefined
if match the second group.. ie. "W".. then g1 will be undefined
git00000
@git00000
Nov 01 2017 19:06 UTC
@TaroWong oops
@TaroWong wanna say character in A-M or in N-Z
@TaroWong same as [A-Z]
Taro
@TaroWong
Nov 01 2017 19:08 UTC
@moigithub What do you mean? I thought global solved it
Oh
I got it
Because there is an "or" operator
Thanks. Time to get back to fix this expression
It's 3am here :O
git00000
@git00000
Nov 01 2017 19:10 UTC
I am learning regex at this moment :smile:
Taro
@TaroWong
Nov 01 2017 19:13 UTC
Which challenge are you at? :)
git00000
@git00000
Nov 01 2017 19:19 UTC
I am not doing chanllenge
@TaroWong thanks for the link you provide
CamperBot
@camperbot
Nov 01 2017 19:20 UTC
git00000 sends brownie points to @tarowong :sparkles: :thumbsup: :sparkles:
:cookie: 250 | @tarowong |http://www.freecodecamp.com/tarowong
git00000
@git00000
Nov 01 2017 19:20 UTC
@TaroWong I even didn't know it exists
Ronique Ricketts
@RoniqueRicketts
Nov 01 2017 19:21 UTC
idk what learnyounode is askin in the second challenge about baby steps
git00000
@git00000
Nov 01 2017 19:22 UTC
?
Taro
@TaroWong
Nov 01 2017 19:25 UTC
No problem :)
Is anyone good at Regular expressions?
Ashwin
@ashwins93
Nov 01 2017 19:26 UTC
@TaroWong ask your question directly, you would get help easier that way
just post your code
Taro
@TaroWong
Nov 01 2017 19:28 UTC

Below is my code

I am having trouble matching the "S" and the duplicate letters like "R" and "M"

I managed to come out with the algorithm, just need help with crafting the regular expression.

function rot13(str) {
  return str.replace(/([A-M])([N-Z])/g, function(match, g1, g2){
    g1 = g1.charCodeAt(0);
    g2 = g2.charCodeAt(0);
    console.log(g1);
    console.log(g2);
    return String.fromCharCode(g1+13, g2-13);
  });
}
rot13("SERR CVMMN!"); //"FREE PIZZA!"
imperial-isms
@imperial-isms
Nov 01 2017 19:32 UTC
@TaroWong Have you played with https://regexr.com/ ?
You can actually even put in the exact string you’re trying to manipulate your regex to recognize the necessary characters
Taro
@TaroWong
Nov 01 2017 19:34 UTC
Yup I just notice that
Yup I actually came out that solution on that site
@imperial-isms How should I proceed? I have not learnt something like this before
Was thinking of splitting it into 2 replace functions
Ashwin
@ashwins93
Nov 01 2017 19:35 UTC
@TaroWong the specialty about the rot13 cipher is that it uses the same algorithm to both encrypt and decrypt
Moisés Man
@moigithub
Nov 01 2017 19:36 UTC
adding a if condition.. to handle fromCharCode should work
depending if first or second group have values
if (g1  != undefined) return String.fromCharCode(g1+13)
return String.fromCharCode(g2-13);
Ashwin
@ashwins93
Nov 01 2017 19:36 UTC
you are just complicating it, this can be done easily even without regex
try using map
another hint would be to use modular arithmetic
Taro
@TaroWong
Nov 01 2017 19:37 UTC
Modular arithmetic seems complicated lol
Ashwin
@ashwins93
Nov 01 2017 19:37 UTC
lol only the name is scary
i m not able to think of any more hints without revealing the answer
Taro
@TaroWong
Nov 01 2017 19:38 UTC
Okay
I am going to give it a last try for regex if it fails I am going to use maps
which came across my mind when I am working out this
Ashwin
@ashwins93
Nov 01 2017 19:38 UTC
modular arithmetic is something like ( charCode +13 ) % 26
Taro
@TaroWong
Nov 01 2017 19:38 UTC
Thanks all :)
I guess I am heading to bed
It's 4am soon
Ashwin
@ashwins93
Nov 01 2017 19:45 UTC
You're working really hard at this
Bryan Reese
@breese8009
Nov 01 2017 19:58 UTC
sooo w react how can i delte something and then have it be gone with out having to refresh
???
Ashwin
@ashwins93
Nov 01 2017 20:02 UTC
@breese8009 you can render elements based on a condition
if you wanna remove the element, just make the condition false
it won't render
Bryan Reese
@breese8009
Nov 01 2017 20:03 UTC
@ashwins93 im not sure im following?
So basically if i click delete on an element, i want it to disappear real time
right now I have a page refresher set up
Where would i set this condition up?
Moisés Man
@moigithub
Nov 01 2017 20:05 UTC
if ur component holds data on state, and renders based on that state
changing the state (with setState) will make react auto-refresh ur page
Taro
@TaroWong
Nov 01 2017 20:06 UTC
@ashwins93 Thanks for introducing modular arithmetic. It does looks interesting reading the basic concept. Couldn't sleep :X
CamperBot
@camperbot
Nov 01 2017 20:06 UTC
tarowong sends brownie points to @ashwins93 :sparkles: :thumbsup: :sparkles:
:cookie: 407 | @ashwins93 |http://www.freecodecamp.com/ashwins93
Taro
@TaroWong
Nov 01 2017 20:06 UTC
Have a good day everyone
Ashwin
@ashwins93
Nov 01 2017 20:07 UTC
@breese8009
{
  if(shouldDisplay) {
    <div>Hello</div>
  }
}
and then have a delete button with a listener that would toggle the boolean
of course this is not exactly how you would do it
you might wanna take a look at some todo list examples ( almost all the react tutorials only teach todo lists)

if you are rendering elements based of an array like

for( var item in array ) {
  <CustomComponent name={item} />
}

then simply splicing an item from the array will make that particular component disappear

Spyrantis Theodoros
@thodorisanta
Nov 01 2017 20:17 UTC
if i have a <div class="whateva"></div> how can i add a text inside the div with plain JS
Ashwin
@ashwins93
Nov 01 2017 20:19 UTC
@thodorisanta document.querySelector(".whateva").textContent = "hello, world";
Moisés Man
@moigithub
Nov 01 2017 20:21 UTC
document.getElementsByClassName("whateva")[0].innerText = "hello"
Bryan Reese
@breese8009
Nov 01 2017 20:25 UTC
@ashwins93 ah ha, I see, thank you sire!
CamperBot
@camperbot
Nov 01 2017 20:25 UTC
breese8009 sends brownie points to @ashwins93 :sparkles: :thumbsup: :sparkles:
:cookie: 408 | @ashwins93 |http://www.freecodecamp.com/ashwins93
Bryan Reese
@breese8009
Nov 01 2017 20:26 UTC
sir*
i Will try that
Chris
@bestintown23
Nov 01 2017 20:48 UTC
Why are my menu options not showing when i click the menu button. (Must minimize screen between 768 to 1023 px to see what i am talking about.) i want my menu options to come up when i hit the button but its not working for me. https://codepen.io/bestintown23/pen/yPYbyo
Stephen James
@sjames1958gm
Nov 01 2017 20:54 UTC
@bestintown23 You have not include jquery in your dependencies
Chris
@bestintown23
Nov 01 2017 20:56 UTC
@sjames1958gm thanks so much i was able to get it updated, now my nav options are not showing when i hit the menu button.
CamperBot
@camperbot
Nov 01 2017 20:56 UTC
bestintown23 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8649 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Nov 01 2017 20:58 UTC
@bestintown23 ul li is still display none
Chris
@bestintown23
Nov 01 2017 21:11 UTC
@sjames1958gm if i remove it, then all my menu options show, how can i make it so that it only shows the options when i hit the menu button
Ronique Ricketts
@RoniqueRicketts
Nov 01 2017 21:31 UTC
wow I am at 3 out of 13 in learnyounode :)
Stephen James
@sjames1958gm
Nov 01 2017 22:48 UTC
@bestintown23 Put display: block in your showing class and move it below the one with the display:none
or make display:none a class and toggle that when you toggle showing
Tiago Correia
@tiagocorreiaalmeida
Nov 01 2017 23:14 UTC
@RoniqueRicketts I found it quite confusing
Morchid Chellali
@Morched23MJ
Nov 01 2017 23:20 UTC
I have worked on the AI that plays against the player on the Tic Tac Toe game. I didn't use Minimax.
Here is the result: https://codepen.io/Morched23MJ/full/VzRQZM/
Any feedback, suggestions would be appreciated.
Jason Luboff
@JLuboff
Nov 01 2017 23:31 UTC
@Morched23MJ Every other game, I click to go, but instead..the computer goes..
Morchid Chellali
@Morched23MJ
Nov 01 2017 23:32 UTC
@JLuboff, in the second time the game starts when you click anywhere, but this time computer plays first, then you can play.
Then the third time, you play first.
Jason Luboff
@JLuboff
Nov 01 2017 23:37 UTC
Thats confusing from a UI standpoint
You don't state that anywher
Morchid Chellali
@Morched23MJ
Nov 01 2017 23:38 UTC
True. I'll try to change that. Thanks @JLuboff
CamperBot
@camperbot
Nov 01 2017 23:38 UTC
morched23mj sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2243 | @jluboff |http://www.freecodecamp.com/jluboff