These are chat archives for FreeCodeCamp/HelpJavaScript

26th
Aug 2017
Stephen James
@sjames1958gm
Aug 26 2017 00:17
@Lumexralph Bye
Nick Cleary
@Hijerboa
Aug 26 2017 00:36
Hey does anyone know how to modify the following code so it will replace all instances of the item in a given string? I'm trying to use the variables here to make the code cleaner, rather than individually typing out each replacement.
function convertHTML(str) {
  var toReplace = ["&", ">", "<", '\"', "\'"];
  var toReplaceWith = ["&amp;", "&gt;", "&lt;", "&​quot;", "&​apos;"];
  for(i=0; i<toReplace.length; i++){
    str = str.replace(toReplace[i], toReplaceWith[i]);
  }
  console.log(str);
  return str;
}
currently it only replaces the first instance of any given item in the toReplace array
Manish Giri
@Manish-Giri
Aug 26 2017 00:52
@Hijerboa
return str.split('').map(thing => {
 if(toReplace.includes(thing) {
  let pos = toReplace.indexOf(thing);
   return toReplaceWith[pos];
}
return thing;
}).join('');
something like this might work
Nick Cleary
@Hijerboa
Aug 26 2017 00:56
@Manish-Giri so what you're suggesting is that i split the string into individual characters and then replace those?
Manish Giri
@Manish-Giri
Aug 26 2017 00:56
yes
Nick Cleary
@Hijerboa
Aug 26 2017 01:00
@Manish-Giri I honestly never thought of that
@Manish-Giri thanks mate
CamperBot
@camperbot
Aug 26 2017 01:00
:star2: 6464 | @manish-giri |http://www.freecodecamp.com/manish-giri
hijerboa sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
Manish Giri
@Manish-Giri
Aug 26 2017 01:00
@Hijerboa :+1:
return str.split('').map(thing => toReplace.includes(thing) ? toReplaceWith[toReplace.indexOf(thing)]: thing).join('');
here is that code in 1 line
Nick Cleary
@Hijerboa
Aug 26 2017 01:06
@Manish-Giri that is... very condensed...
Manish Giri
@Manish-Giri
Aug 26 2017 01:06
yup
that's the point
Moisés Man
@moigithub
Aug 26 2017 01:07
@Hijerboa u can use regex.. with g flag
Nick Cleary
@Hijerboa
Aug 26 2017 01:07
@moigithub would that work with the variables I have in place currently?
because I was under t he impression it wouldn't
Moisés Man
@moigithub
Aug 26 2017 01:09
new RegExp(toReplace[i], 'g')
instead of toReplace[i]
should work i think
Manish Giri
@Manish-Giri
Aug 26 2017 01:12
will that replace all characters in the input string that are in toReplace array?
Moisés Man
@moigithub
Aug 26 2017 01:31
"hello".replace(/l/g,'X')
"heXXo"
global flag will find any occurrences
Manish Giri
@Manish-Giri
Aug 26 2017 02:00
I meant all characters
like "hell&o><"
Moisés Man
@moigithub
Aug 26 2017 02:04
"hell<<<o".replace(/</g,'X')
"hellXXXo"
Vikrant Singh
@VikrantSingh13
Aug 26 2017 02:22
How to fix "Bootstrap dropdown require Popper.js" https://codepen.io/vikrantsingh13/full/LjJxPb/
Vikrant Singh
@VikrantSingh13
Aug 26 2017 02:26
yeah pooper is effing us all up the joys of open source :3
@longnt80 nvm thanks fixed the problem with the right cdn
@longnt80 thanks
CamperBot
@camperbot
Aug 26 2017 02:27
vikrantsingh13 sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 530 | @longnt80 |http://www.freecodecamp.com/longnt80
Long Nguyen
@longnt80
Aug 26 2017 02:27
@VikrantSingh13 np
Addison
@addisonday
Aug 26 2017 02:32
Can anyone give me pointers on iterating through multidimensional arrays?
Long Nguyen
@longnt80
Aug 26 2017 02:37
@addisonday
maybe, nested loop and recursive
Addison
@addisonday
Aug 26 2017 02:41
I'm having a hard time grasping how to iterate through second array and only grab a value at a certain index
Tai Jones
@taiJones00
Aug 26 2017 02:43
Is a second array an array inside of an array?
Long Nguyen
@longnt80
Aug 26 2017 02:44
@addisonday nested loop
outside loop to iterate through the main array
inside loop to iterate through each internal array
Addison
@addisonday
Aug 26 2017 02:45
why do you say each internal array ? what if I have an infintely nested array?
Manish Giri
@Manish-Giri
Aug 26 2017 02:45
maybe this example will help
let arr = [[1,2,3], [4,5,6], [7,8,9]]

let firstFromEach = arr.map(a => a[0])

console.log(firstFromEach)
// [1, 4, 7]
@addisonday
Addison
@addisonday
Aug 26 2017 02:50
@Manish-Giri I want an example with an array like this
[2, [1,2,3], 3, [4,5,6], 5 , [7,8,9]]
Manish Giri
@Manish-Giri
Aug 26 2017 03:20
@addisonday okay
what data do you want back from that array?
Addison
@addisonday
Aug 26 2017 03:22
I want to print the 2, 3, 5, and the 1, 4, 7 @Manish-Giri
Manish Giri
@Manish-Giri
Aug 26 2017 03:23
okay
so all elements that are not arrays
Addison
@addisonday
Aug 26 2017 03:23
correct
Manish Giri
@Manish-Giri
Aug 26 2017 03:23
and first element of each sub array
Addison
@addisonday
Aug 26 2017 03:24
yes
Manish Giri
@Manish-Giri
Aug 26 2017 03:25
let arr = [2, [1,2,3], 3, [4,5,6], 5 , [7,8,9]]

let data = arr.map(a => {
  if(Array.isArray(a)) {
    return a[0];
  }
  else {
    return a;
  }
})

console.log(data)
// [2, 1, 3, 4, 5, 7]
Addison
@addisonday
Aug 26 2017 03:26
@Manish-Giri That helps a ton.
Manish Giri
@Manish-Giri
Aug 26 2017 03:26
:+1:
Addison
@addisonday
Aug 26 2017 03:26
@Manish-Giri Thank you
CamperBot
@camperbot
Aug 26 2017 03:26
addisonday sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6466 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Aug 26 2017 03:27
welcome
Marc
@MWBauer
Aug 26 2017 03:45
for (var i = 0; i <= splitArray.length; i++) { var strLength = splitArray[i].length;
lol
for (var i = 0; i <= splitArray.length; i++) { var strLength = splitArray[i].length;
well....that doesn't seem to be working well.
The question is, once you've run the loop, and all words in an array have been measured for their length, how do I compare them?
 for (var i = 0; i <= splitArray.length; i++) {
    var strLength = splitArray[i].length;
Manish Giri
@Manish-Giri
Aug 26 2017 04:04
@MWBauer var strLength = splitArray[i].length; is wrong
you need to first declare var strLength outside the loop
and even then, strLength will only contain the length of the last word..
Jefferson
@jeffersonnnn
Aug 26 2017 07:31
Hi guys, i have question. When an arguments object like ([1, 2, 3, 1, 2, 3], 2, 3); is turned into an array, what becomes of it. Is every character turn array a lá ([1] [2] [3] [1] [2] [3], [2] [3]); ?
Abdoullah Alee U
@abdoullfurya
Aug 26 2017 07:31

This is my code and

var count = 0;

function cc(card) {
  // Only change code below this line

  switch(card) {
      case 2,3,4,5,6:
      return "5 Bet";
    case 7, 8, 9:
      return "0 Hold";
    case 10, "J", "Q", "K", "A":
      return "-5 Hold";
    case 2,"j",9,2,7: 
    case 2, 2, 10:
      return "1 Bet";
    case 3, 2, "A", 10,"K":
    case 3, 7,"Q", 8, "A":
      return "-1 Hold";

  }

  return "count";
  // Only change code above this line
}

case 3, 2, "A", 10,"K": case 3, 7,"Q", 8, "A": is supposed to return "-1 Hold" but only 3, 2, A, 10, K returns "-1 Hold"

Pethaf
@Pethaf
Aug 26 2017 07:33
@abdoullfurya Pretty certain you have to use break to avoid fall through.
Abdoullah Alee U
@abdoullfurya
Aug 26 2017 07:42
@pethaf The break was omitted intentionally because i want both cases to return "-1 Hold" as i did here case 2,"j",9,2,7: case 2, 2, 10: return "1 Bet";
Mollyoyo
@Mollyoyo
Aug 26 2017 09:06
???
koder3
@koder3
Aug 26 2017 09:34
do i need to use cors in this jsfiddle https://jsfiddle.net/koder3/1msp901d/ to get through the 'Access-Control-Allow-Origin' ... if so how do i go about using it
Ene Catalin
@EneCatalin
Aug 26 2017 09:48
@koder3 that's a pretty nasty problem
why not just make it locally and upload to github ?
koder3
@koder3
Aug 26 2017 09:50
you mean i can make it on notepad or some editor on my pc then upload it to github?
Ene Catalin
@EneCatalin
Aug 26 2017 09:52
notepad ?
use atom
webstorm
brackets
Pieter Stokkink
@forkerino
Aug 26 2017 09:53
notepad :joy:
It works, but not great for coding
Ene Catalin
@EneCatalin
Aug 26 2017 09:53
best way to make a programmer kill himself is to force him to write code in notepad
koder3
@koder3
Aug 26 2017 09:54
ROFL i havent any experience with other editors
Ene Catalin
@EneCatalin
Aug 26 2017 09:54
notepad is not an editor
koder3
@koder3
Aug 26 2017 09:54
though ive heard of many
Ene Catalin
@EneCatalin
Aug 26 2017 09:54
you're better off writing code on paper
than in that beep
Pieter Stokkink
@forkerino
Aug 26 2017 09:54
Pick one Atom/Sublime/VS Code/Brackets/Webstorm
you select the language and you got syntax highlighting
Ene Catalin
@EneCatalin
Aug 26 2017 09:55
I'd say go for webstorm if a student
koder3
@koder3
Aug 26 2017 09:55
alright.
Ene Catalin
@EneCatalin
Aug 26 2017 09:55
or for vs Code if you have 50 free gb
Pieter Stokkink
@forkerino
Aug 26 2017 09:55
@EneCatalin why?
Ene Catalin
@EneCatalin
Aug 26 2017 09:55
students get it for free
and visual studio is hell to unistall
occupies 3 hdds
koder3
@koder3
Aug 26 2017 09:55
you mentioned using cors would be a nasty problem. can you elaborate? @EneCatalin
Pieter Stokkink
@forkerino
Aug 26 2017 09:56
@EneCatalin not VS, VS Code
Ene Catalin
@EneCatalin
Aug 26 2017 09:56
read an article on it, sounded nasty, so I just hope to not run into it anytime soon :P
Pieter Stokkink
@forkerino
Aug 26 2017 09:56
it is quite light
Ene Catalin
@EneCatalin
Aug 26 2017 09:56
oh
didn't know it had a light version
Pieter Stokkink
@forkerino
Aug 26 2017 09:56
It is built on Electron, like Atom, but less of a memory hog
Ene Catalin
@EneCatalin
Aug 26 2017 09:56
had to work in C++ once so I installed VS with a lot of stuff in it. I mean it was good but had so much stuff
best C\C++ editor by far though
probs best for C# too
koder3
@koder3
Aug 26 2017 09:59
when i used the wikipedia api i ran into this access control allow origin issue on jsfiddle and codepen.io. however when i use other api such as the weather one provided by freecodecamp i didnt find this issue.. any reasons?
Ene Catalin
@EneCatalin
Aug 26 2017 10:00
it's a security thing man
so you don't get your server fked
it's cause you get stuff (potential code I guess) from another source or something
koder3
@koder3
Aug 26 2017 10:01
hmm understandable
so no easy workaround i suppose?
Ene Catalin
@EneCatalin
Aug 26 2017 10:02
Access-Control-Allow-Origin: http://siteA.com
try it out, no idea if it will work
Pieter Stokkink
@forkerino
Aug 26 2017 10:03
@koder3 I think for wikipedia you can add &origin=* to the url
koder3
@koder3
Aug 26 2017 10:04
@forkerino oh it worked!! thanks
CamperBot
@camperbot
Aug 26 2017 10:04
koder3 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2927 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Aug 26 2017 10:04
:+1:
@koder3 not all API's have this option
koder3
@koder3
Aug 26 2017 10:05
but if i run into one that doesnt, do i HAVE to use cors or is there any easier workaround? @forkerino
Pieter Stokkink
@forkerino
Aug 26 2017 10:07
@koder3 you can use a proxy like cors-anywhere, but I don't find the solution satisfactory. Better is to just choose the right API, so that you don't run into the problem. :)
koder3
@koder3
Aug 26 2017 10:08
yeah this is the main issue ive been having whilst learning json apis... the url itself
will i face this issue using any IDE ?
Ene Catalin
@EneCatalin
Aug 26 2017 10:12
what do you mean ?
Razvan Jackson
@RazvanJackson
Aug 26 2017 10:12
Guys, what's the best way to show register errors? php or javascript?
In my opinion it's php bcs you have to check if the username exists, im waiting other's opinion
Ene Catalin
@EneCatalin
Aug 26 2017 10:12
depending on the IDE it may actually make suggestions
I use webstorm, it makes your life much easier, smart code completion, tells you when an function can be converted to an arrow function (and does that for you too)
@RazvanJackson php or javascript ? You mean language with best debugging ?
Razvan Jackson
@RazvanJackson
Aug 26 2017 10:13
@EneCatalin no i mean when i show the register errors for customers
Like username is already taken
Or
Name should include only lettersd
letters
koder3
@koder3
Aug 26 2017 10:14
@EneCatalin yeah i find webstorm quite nice. thanks!
CamperBot
@camperbot
Aug 26 2017 10:14
koder3 sends brownie points to @enecatalin :sparkles: :thumbsup: :sparkles:
:cookie: 443 | @enecatalin |http://www.freecodecamp.com/enecatalin
Razvan Jackson
@RazvanJackson
Aug 26 2017 10:14
What should i use Javascript or Php?
Ene Catalin
@EneCatalin
Aug 26 2017 10:14
@koder3 if you're a student you can get it for free
@RazvanJackson I don't know, if you use js go for node and just search the npm, see if you find what you need
pretty sure php also had something, composer I think
Razvan Jackson
@RazvanJackson
Aug 26 2017 10:15
idk node
Ene Catalin
@EneCatalin
Aug 26 2017 10:15
then use php
Razvan Jackson
@RazvanJackson
Aug 26 2017 10:15
K
Btw cati ani ai :))
Ene Catalin
@EneCatalin
Aug 26 2017 10:15
also node is JS
23
tu ?
Razvan Jackson
@RazvanJackson
Aug 26 2017 10:15
Multi inainte
17
Putem sa vb in privat, sa nu incurcam aici?
Ene Catalin
@EneCatalin
Aug 26 2017 10:16
you should look into node, at least for the npm
sure
Pethaf
@Pethaf
Aug 26 2017 10:44
Ohhh, look.
Ossifrage is back.
Ene Catalin
@EneCatalin
Aug 26 2017 10:45
ostrich was never gone
Diego Mayer
@Chrono79
Aug 26 2017 12:15
@EneCatalin composer is similar to npm
There are other package managers in PHP, like Yarn and Bower
mm1mm2
@mm1mm2
Aug 26 2017 12:25
Is anybody here?
i need help..
Pethaf
@Pethaf
Aug 26 2017 12:27
Maybe.
mm1mm2
@mm1mm2
Aug 26 2017 12:28
@_@
heroiczero
@heroiczero
Aug 26 2017 12:30
@mm1mm2 post your code and problem using ''' :point_down:
CamperBot
@camperbot
Aug 26 2017 12:30
:bulb: to format code use backticks! ``` more info
mm1mm2
@mm1mm2
Aug 26 2017 12:30

//初始化变量
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["Javascript", "Gaming", "Foxes"]
}
];

function lookUp(firstName, prop){
var res;
for(var i=0;i<contacts.length;i++){
if(contacts[i].firstName==firstName)
{
if(contacts[i].hasOwnProperty(prop))
{
res=contacts[i][prop];break;
}
else res='No such property';
}
else res='No such contact';
}
return res;
}
lookUp("Akira", "address");

Pethaf
@Pethaf
Aug 26 2017 12:31
Yes.
mm1mm2
@mm1mm2
Aug 26 2017 12:31
image.png
heroiczero
@heroiczero
Aug 26 2017 12:32
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUp(firstName, prop){
var res;
for(var i=0;i<contacts.length;i++){
  if(contacts[i].firstName==firstName)
  {
    if(contacts[i].hasOwnProperty(prop))
    {
    res=contacts[i][prop];break;
    }
   else res='No such property';
  }
  else res='No such contact';
}
  return res;
}
lookUp("Akira", "address");
@mm1mm2 first the function should be function lookUpProfile(firstName, prop)
mm1mm2
@mm1mm2
Aug 26 2017 12:35
wt?
heroiczero
@heroiczero
Aug 26 2017 12:40
@mm1mm2 yeah your "No such contact" is overwriting the "No such property" when you don't have the property and contacts[cantacts.length-1].firstName==firstName is false.
mm1mm2
@mm1mm2
Aug 26 2017 12:43
Thanks.
Aimee
@bestAimee
Aug 26 2017 12:56
image.png
Markus Kiili
@Masd925
Aug 26 2017 12:58
@mm1mm2 If you use a result variable, it is wise to initialize it to "No such contact" and overwrite it if you find the correct contact.
Abhinav Mishra
@abhinav-m
Aug 26 2017 13:01
Im currently doing the react game of life
i was able to successfully simulate the first generation
i have a question
i need to add the functionality of changing a live cell -> dead and vice versa on click of the cell
Stephen James
@sjames1958gm
Aug 26 2017 13:01
@bestAimee You reset result to 1 each loop so you only get last value from each inner array
Abhinav Mishra
@abhinav-m
Aug 26 2017 13:01
should i use event delegation for this ? or should i add the onClick to each div nested in my wrapper div
i was thinking of adding the onClick to the wrapper, and using the id by event.target.id
im not sure which way will be more efficient
Stephen James
@sjames1958gm
Aug 26 2017 13:03
@abhinav-thinktank Memory wise the wrapper would be more efficient, NxN event handlers vs. one
Abhinav Mishra
@abhinav-m
Aug 26 2017 13:03
hmm
but will it take more time?
Stephen James
@sjames1958gm
Aug 26 2017 13:03
@abhinav-thinktank Probably not
Abhinav Mishra
@abhinav-m
Aug 26 2017 13:03
cause i've also added an interval for simulating next generation
250ms
its a huge 2D matrix
smallest is 30 X 50
so 1500 cells
Stephen James
@sjames1958gm
Aug 26 2017 13:04
@abhinav-thinktank Why would the size of the array make a difference for event delegation?
@abhinav-thinktank It is still only one or two divs deep?
Abhinav Mishra
@abhinav-m
Aug 26 2017 13:05
aah yes only one div deep
Aimee
@bestAimee
Aug 26 2017 13:05
thank you @sjames1958gm
CamperBot
@camperbot
Aug 26 2017 13:05
bestaimee sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
Abhinav Mishra
@abhinav-m
Aug 26 2017 13:05
so it will bubble up to the wrapper instantly
CamperBot
@camperbot
Aug 26 2017 13:05
:star2: 8391 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Abhinav Mishra
@abhinav-m
Aug 26 2017 13:05
right?
Stephen James
@sjames1958gm
Aug 26 2017 13:05
I assume so
@bestAimee :+1:
Abhinav Mishra
@abhinav-m
Aug 26 2017 13:06
aah ok @sjames1958gm ty
CamperBot
@camperbot
Aug 26 2017 13:06
abhinav-thinktank sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8392 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Abhinav Mishra
@abhinav-m
Aug 26 2017 13:06
i guess i was confused with all the rows being adjacent..
nvm
@sjames1958gm ty!
CamperBot
@camperbot
Aug 26 2017 13:06
abhinav-thinktank sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: abhinav-thinktank already gave sjames1958gm points
Stephen James
@sjames1958gm
Aug 26 2017 13:06
@abhinav-thinktank :+1:
LiciniusRex
@hashtagyolo1
Aug 26 2017 13:17
Still struggling with this weather api. Can't seem to get the json data to output to a html element. I think I might have been staring at it for too long to be able to see what I'm doing wrong. Extra eyes to point out what simple mistake I'v made would be greatly appreciated
Stephen James
@sjames1958gm
Aug 26 2017 13:20
@hashtagyolo1 darksky doesn't support cross origin requests from the browser. that is the error you are getting.
You can try this API provided by FCC
https://fcc-weather-api.glitch.me/
cumibulat
@cumibulat
Aug 26 2017 13:23
hi guys
Stephen James
@sjames1958gm
Aug 26 2017 13:24
@cumibulat hey
cumibulat
@cumibulat
Aug 26 2017 13:24
@sjames1958gm how are you james.. have you finished the front end challenge
?
LiciniusRex
@hashtagyolo1
Aug 26 2017 13:25
That would explain it. Thanks @sjames1958gm
CamperBot
@camperbot
Aug 26 2017 13:25
hashtagyolo1 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8393 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 26 2017 13:26
@cumibulat yes
@hashtagyolo1 :+1:
cumibulat
@cumibulat
Aug 26 2017 13:30
how you solve the advanced algorithm challenge ? did it take a long time for you to solve all that challenges ?
LiciniusRex
@hashtagyolo1
Aug 26 2017 13:30
I have been struggling so bad. Can't believe it was just a problem with the api!
Stephen James
@sjames1958gm
Aug 26 2017 13:32
@cumibulat Some of the advanced ones were tough.
I usually consider how to solve the problem on paper before trying to code the solution.
cumibulat
@cumibulat
Aug 26 2017 13:35
i could use that idea.
Stephen James
@sjames1958gm
Aug 26 2017 13:36
@hashtagyolo1 Got to keep looking at the dev tools console for errors
Ene Catalin
@EneCatalin
Aug 26 2017 13:40
@hashtagyolo1 you better believe it brother, the first interesting api we get to play with
Pethaf
@Pethaf
Aug 26 2017 13:44
Ossifrage api?
LiciniusRex
@hashtagyolo1
Aug 26 2017 13:46
f12? I've not been using it. I guess I should start
alpox
@alpox
Aug 26 2017 13:47
@hashtagyolo1 thats the most important tool for frontend devs ;)
LiciniusRex
@hashtagyolo1
Aug 26 2017 13:48
Well that explains one of the many reason I've been struggling
finally got some simulations working
:D
need to work on some bug fixes now
some patterns arent working
and need to make it pretty
Mahesh
@mahis929
Aug 26 2017 15:00
hii
please someone help me with my javascript
Aimee
@bestAimee
Aug 26 2017 15:19
how can i delete the string's space and punctuation?
Aimee
@bestAimee
Aug 26 2017 15:22
can you give me an example?
korzo
@korzo
Aug 26 2017 15:24
@bestAimee 'Hello World'.replace(' ','')
Aimee
@bestAimee
Aug 26 2017 15:26
but other punctuation? such as "hello, how are you !"
korzo
@korzo
Aug 26 2017 15:30
@bestAimee You can use regex in replace
@bestAimee like "hello, how are you !".replace(/[^A-Za-z]/g, '')
Aimee
@bestAimee
Aug 26 2017 15:33
OK,i see @korzo
Marc
@MWBauer
Aug 26 2017 15:57
HOw can I tell replace to take regexp and capitalize it to return it?
Moisés Man
@moigithub
Aug 26 2017 15:59
replace can take as second parameter a function (instead of a string)
inside this function u can DO whatever u want to the match values.. like toUppercase it
check the documentation https://www.w3schools.com/jsreF/jsref_replace.asp (last example)
Marc
@MWBauer
Aug 26 2017 16:01
I was just reading that. Thanks.
Aimee
@bestAimee
Aug 26 2017 16:02
i have a problem is that check the string is palindrome the code :

function palindrome(str) {
// 请把你的代码写在这里
str = str.replace(/\W+|\s+/g,'');
str = str.toLowerCase();
var arr = str.split('');
var arr1 =[];
for(var i in arr){
arr1[i] = arr[i];
}
arr1 = arr1.reverse();
var str1 = arr1.join('');

if(str1 === str){
return true;
}else{
return false;
}

}

but the last palindrome("0_0 (: /-\ :) 0-0");should be return true;
Markus Kiili
@Masd925
Aug 26 2017 16:04
@bestAimee You can compare strings with === so no need for that loop. Just compare str with str.split("").reverse().join("")
Aimee
@bestAimee
Aug 26 2017 16:04
i can't do it;
Moisés Man
@moigithub
Aug 26 2017 16:04
\W is the same as /[^A-Za-z0-9_]/
Aimee
@bestAimee
Aug 26 2017 16:05
ok
so the palindrome("0_0 (: /-\ :grinning: 0-0");should be return true;i can't solute;
Moisés Man
@moigithub
Aug 26 2017 16:07

u need to replace/remove _
to make ur code work

str = str.replace(/\W|_/g,'');

Aimee
@bestAimee
Aug 26 2017 16:11
thank you very much
you are very nice
aRtoo
@artoodeeto
Aug 26 2017 16:18

alright guys. so im back. this is getting crazier. so on algorithm challenge entitled. arguments optional. the instruction says:

// Create a function that sums two arguments together. If only one argument is provided, then return a function that expects one argument and returns the sum.
// For example, addTogether(2, 3) should return 5, and addTogether(2) should return a function.
// Calling this returned function with a single argument will then return the sum:
// var sumTwoAnd = addTogether(2);
// sumTwoAnd(3) returns 5.
// If either argument isn't a valid number, return undefined

now how can i return the a sum with only one argument?
this is my code:

function addTogether(a,b) {

  var len = arguments.length;

  if(len === 1){
    return function(x){
      return x;
    };
  } 
  return a+b;
}
addTogether(2,3);
Moisés Man
@moigithub
Aug 26 2017 16:21
read about currying @artoodeeto
alpox
@alpox
Aug 26 2017 16:21
@artoodeeto returning a function is right already, but you have to do a calculation inside of the function
@artoodeeto inside of the inner function (The one you return), you can access variables from the outer scope (Outer function)
aRtoo
@artoodeeto
Aug 26 2017 16:27
@alpox so you mean. i just another parameter inside the return function to add x+y?
alpox
@alpox
Aug 26 2017 16:28
@artoodeeto no, no additional parameter. just use one of the parameters from the outer function
aRtoo
@artoodeeto
Aug 26 2017 16:39
@alpox so ill use b then return x+b?
alpox
@alpox
Aug 26 2017 16:53
@artoodeeto why b? what does b stand for?
aRtoo
@artoodeeto
Aug 26 2017 16:53
@alpox the 2nd argument
alpox
@alpox
Aug 26 2017 16:53
@artoodeeto yea but where do you find the second argument of the first function call in addTogether(2)(3)
You have to sum up 2 and 3
aRtoo
@artoodeeto
Aug 26 2017 16:54
@alpox thats where i get confused? its not enclosed in a one parenthesis.
alpox
@alpox
Aug 26 2017 16:55
@artoodeeto 2 goes into the function call to addTogether directly. 3 goes into the function you return
aRtoo
@artoodeeto
Aug 26 2017 16:55
so addTogether(2)(3) is the same as addTOgether(2) and addtogether(3)??
alpox
@alpox
Aug 26 2017 16:55
@artoodeeto no
aRtoo
@artoodeeto
Aug 26 2017 16:56
@alpox damn this is hard
alpox
@alpox
Aug 26 2017 16:57
@artoodeeto Its the same as:
var addTwo = addTogether(2);
addTwo(3);
Markus Kiili
@Masd925
Aug 26 2017 17:00
@artoodeeto addTogether(2) returns a function. (3) calls that returned function.
koder3
@koder3
Aug 26 2017 17:33
@koder3
image.png
i am getting the exact results i wanted on jsfiddle for the same code in the console
but why not in webstorm
my console is blank no matter what i console.log
koder3
@koder3
Aug 26 2017 17:39
how do i open console in webstorm
Jan Shah
@JanShah
Aug 26 2017 17:52
I think the ide console is different to the browser console, I'm not sure you'd see the same thing unless you add debuggers
@koder3
koder3
@koder3
Aug 26 2017 17:53
how do i open the ide console on webstorm?
@JanShah
Jan Shah
@JanShah
Aug 26 2017 17:54
webstorm is your integrated development environment. your screenshot shows tabs for console and debugger @koder3
koder3
@koder3
Aug 26 2017 17:55
the debugger is not opening now that i click on debug
how do i open that console i did in that screenshot
Jan Shah
@JanShah
Aug 26 2017 17:56
when you say open, what do you mean? as a new window?
try using vscode, it's awesome, free and I think it's easier than jetbrains apps
koder3
@koder3
Aug 26 2017 17:58
how do i open those tabs that i did in the screenshot i mean
Jan Shah
@JanShah
Aug 26 2017 17:59
click on the tab and it will open, I don't know if there's a way to detach it, sorry.
LiciniusRex
@hashtagyolo1
Aug 26 2017 18:13
is there a way of finding out all the possible responses an api can give?
alpox
@alpox
Aug 26 2017 18:15
@hashtagyolo1 usually through its documentation
@hashtagyolo1 called API reference. You should look online if you find one for your api
Jan Shah
@JanShah
Aug 26 2017 18:16
if there's no documentation it's probably not possible unless the api has a reference or urls(endpoints) in it
LiciniusRex
@hashtagyolo1
Aug 26 2017 18:18
thanks @alpox , not been able to find anything for the fcc weather api
CamperBot
@camperbot
Aug 26 2017 18:18
hashtagyolo1 sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1318 | @alpox |http://www.freecodecamp.com/alpox
alpox
@alpox
Aug 26 2017 18:20
@hashtagyolo1 there is no fcc weather api unless someone created something like that :D as far as i know, there is only a proxy to the darksky api
@hashtagyolo1 although you shouldnt need more than it says here https://fcc-weather-api.glitch.me
LiciniusRex
@hashtagyolo1
Aug 26 2017 18:28
@alpox, I was hoping to into more depth with it. But I guess there's no need for now. Hadn't realised it just hooked into DS
Gulsvi
@gulsvi
Aug 26 2017 19:19
@alpox @hashtagyolo1 That hooks into Open Weather map FYI https://openweathermap.org/current
alpox
@alpox
Aug 26 2017 19:33
@SkyC0der ah really? I thought darksky had the lead when it was about the free traffic possibilities :D seems that i missed part of the conversation then :D
JLuis Avalos
@avalos010
Aug 26 2017 19:41
Anyone recommend any good react + redux courses? I'm thinking of doing udacity's nano degree program
Chris Juchtmans
@kjuchtmans
Aug 26 2017 19:44
Evening coders! :wave:
Pethaf
@Pethaf
Aug 26 2017 19:45
@avalos010 Do they cover react at udacity?
Don't they have a separate redux degree that costs a boatload of money.
Chris Juchtmans
@kjuchtmans
Aug 26 2017 19:47

quick question to understand objectsbetter: is it correct that the global object in JS is in fact not an object, but a function?

would assume so, considering the syntax : new Object( )

Pethaf
@Pethaf
Aug 26 2017 19:50
@kjuchtmans Constructor function.
Chris Juchtmans
@kjuchtmans
Aug 26 2017 19:52
@Pethaf right
Vali
@valimikayilov
Aug 26 2017 19:53

can you help me with pig latin '''
function translatePigLatin(str) {
var vowel =["a", "e", "i", "o", "u"];
var result = str.split("");
for (var i = 0; i < str.length; i++) {
for (var j = 0; j < 5; j++) {
if (result[i] == vowel[j]) {
result = str.substr(i) + str.substr(0, i);
}
}
}
return result;
}

translatePigLatin("consonant");
'''

CamperBot
@camperbot
Aug 26 2017 19:53
:bulb: to format code use backticks! ``` more info
Vali
@valimikayilov
Aug 26 2017 19:54
can you help me with pig latin
function translatePigLatin(str) {
var vowel =["a", "e", "i", "o", "u"];
var result = str.split("");
for (var i = 0; i < str.length; i++) {
for (var j = 0; j < 5; j++) {
if (result[i] == vowel[j]) {
result = str.substr(i) + str.substr(0, i);
}
}
}
return result;
}
translatePigLatin("consonant");
korzo
@korzo
Aug 26 2017 19:58
@Geek-Killer I think you have it wrong
@Geek-Killer As long as I understand, you have to replace either with way or ay
JLuis Avalos
@avalos010
Aug 26 2017 20:00
@Pethaf yeah it's a 4 month course enrollment closes Monday so im trying to make my mind up. They offer mentorship and everything which is the reason I wanna do it and because they give us projects that are reviewed by someone
Pethaf
@Pethaf
Aug 26 2017 20:01
$500.
Thats a bit of money.
JLuis Avalos
@avalos010
Aug 26 2017 20:03
@Pethaf yeah I know I might do Stephen griders course on react I did the es6 course and it was really good
korzo
@korzo
Aug 26 2017 20:04
@Geek-Killer If first letter is from [aeiou], then add way at the end
Otherwise remove letters from start till [aeiou] and add them at the and with ay
Pethaf
@Pethaf
Aug 26 2017 20:08
@avalos010 To be honest, if I had the time and the money I would probably go udacity.
The feedback from a professional is probably worth a lot.
JLuis Avalos
@avalos010
Aug 26 2017 20:23
@Pethaf yeah I think Ima do it not only does it teach react js but It also teaches react native
Pethaf
@Pethaf
Aug 26 2017 20:28
But 12h/week for 4 months is a big commitment.
JLuis Avalos
@avalos010
Aug 26 2017 20:30
@Pethaf it's not that bad it's decent like 3 hours a day 1 before work 2 after
Pethaf
@Pethaf
Aug 26 2017 20:31
Ok. If you think you can manage it.
charles
@code9ja
Aug 26 2017 20:55
hi guys
I have been on challenge 196 for the past 2 weeks
Gulsvi
@gulsvi
Aug 26 2017 20:56
Hello @code9ja
196 is the number of points you have
about @code9ja
CamperBot
@camperbot
Aug 26 2017 20:56
:cookie: 196 | @code9ja |http://www.freecodecamp.com/code9ja
Gulsvi
@gulsvi
Aug 26 2017 20:56
^^ 196 :)
What's the challenge title?
charles
@code9ja
Aug 26 2017 20:57
Can someone please explain how I can make all the instruction turn green at the same time
@SkyC0der comparison-with-the-greater-than-operator
korzo
@korzo
Aug 26 2017 20:58
@code9ja Those are tests. They turn green as soon as your code is correct
Gulsvi
@gulsvi
Aug 26 2017 20:58
function testGreaterThan(val) {
  if (val) {  // Change this line
    return "Over 100";
  }

  if (val) {  // Change this line
    return "Over 10";
  }

  return "10 or Under";
}

// Change this value to test
testGreaterThan(10);
@code9ja We use the > for greater than
5 > 3
^^ five is greater than three
charles
@code9ja
Aug 26 2017 20:59
@korzo Well they turn green when I work on over 10 and the over 100's turn red
@SkyC0der I got that
Gulsvi
@gulsvi
Aug 26 2017 21:00
Can you show us your code?
charles
@code9ja
Aug 26 2017 21:00
but for some reason I can't ace my instruction
Gulsvi
@gulsvi
Aug 26 2017 21:00
how are you showing the val is greater than 10 and val is greater than 100 ?
charles
@code9ja
Aug 26 2017 21:00
ok one second

```function testGreaterThan(val) {
if (val > 10) { // Change this line
return "Over 10";
}

if (val) { // Change this line
return "Over 10";
}

return "10 or Under";
}

// Change this value to test
testGreaterThan(10);```

korzo
@korzo
Aug 26 2017 21:03
@code9ja 3. line should be return "Over 100";
charles
@code9ja
Aug 26 2017 21:03
really
Gulsvi
@gulsvi
Aug 26 2017 21:03
@code9ja I think you have a copy/paste error in your code
charles
@code9ja
Aug 26 2017 21:03
let me try
Gulsvi
@gulsvi
Aug 26 2017 21:03
Look at the code I put above and see how it is different
charles
@code9ja
Aug 26 2017 21:04
@SkyC0der ok give me a sec
@SkyC0der It looks like the default code
am I mistaking
Gulsvi
@gulsvi
Aug 26 2017 21:08
@code9ja Yes, it is the default code. Notice how it differs from yours
You don't have this part in your code, so the 100 part is failing:
  if (val) {  // Change this line
    return "Over 100";
  }
korzo
@korzo
Aug 26 2017 21:09
@code9ja Yes, but code you posted has error I posted before
Gulsvi
@gulsvi
Aug 26 2017 21:09
Your code has two cases for the over 10
charles
@code9ja
Aug 26 2017 21:10
I am trying to see my errors
Gulsvi
@gulsvi
Aug 26 2017 21:10
In your code, where do you return "Over 100"?

It seems you understand the concept, because this part of your code is correct:

if (val > 10) { // Change this line
return "Over 10";
}

Maybe you can start over by pressing the "Reset your code" button and try again.

charles
@code9ja
Aug 26 2017 21:12
when val is > 100
Gulsvi
@gulsvi
Aug 26 2017 21:13
look at your code again, and try to find this text: return "Over 100"
Chris Juchtmans
@kjuchtmans
Aug 26 2017 21:13

"Create a Person" lesson: why is below solution not accepted / recorded?

As I run all the tests, the returns are correct, yet most red crosses are not replaced by green checkmarks.
Except when I refresh the page without hitting "Run tests (ctrl-enter)" ...then all green checkmarks appear, but I don't get the success pop-up.

Code on Repl.it

A bug, or just my Chrome needing a reboot? thanks, k

charles
@code9ja
Aug 26 2017 21:13
ok brb
Gulsvi
@gulsvi
Aug 26 2017 21:14
@kjuchtmans I think there's an issue with how the test cases run - remove the last line you have:
Object.keys(bob).length;
If I do that, and then click Run Tests, it all passes.
Chris Juchtmans
@kjuchtmans
Aug 26 2017 21:15
@SkyC0der yeah, I commented that out but still not accepted
Gulsvi
@gulsvi
Aug 26 2017 21:15
Weird, it just worked for me
korzo
@korzo
Aug 26 2017 21:16
@kjuchtmans which test fails?
Fernando
@lestairon
Aug 26 2017 21:16

function mutation(arr) {
  arr.map((L) => L.toLowerCase());
}

mutation(["hello", "hello"]);
Why the arr.map is not working?
charles
@code9ja
Aug 26 2017 21:16
@SkyC0der @kjuchtmans Honestly guys at this point I am having challenges loving coding
Chris Juchtmans
@kjuchtmans
Aug 26 2017 21:16
@korzo "Create a Person"
Gulsvi
@gulsvi
Aug 26 2017 21:17
@lestairon .map() returns an array - you'll need to assign it to a variable
function mutation(arr) {
  arr = arr.map((L) => L.toLowerCase());
}
Chris Juchtmans
@kjuchtmans
Aug 26 2017 21:18

@code9ja true true. You know, I stumbled across a YT channel, JS concepts explained by this Swedish guy who is rather hilarious: Fun Fun Function.

Besides giving you some more elaborate background on object creation etc, it might also bring the joy back. Or as he says: Fun!

Gulsvi
@gulsvi
Aug 26 2017 21:18
@code9ja I think most developers feel that way sometimes :)
It's hard communicating with computers sometimes
charles
@code9ja
Aug 26 2017 21:19
I've reset my code
I will take a line at a time now
Gulsvi
@gulsvi
Aug 26 2017 21:21
@kjuchtmans Curious, if you click "Run Tests" a second time, does it all pass for you?
It failed once for me, then started passing
now it won't fail anymore
Chris Juchtmans
@kjuchtmans
Aug 26 2017 21:25
@SkyC0der nope. maybe if I clear chrome's cache. bizarrely enough this has never happened in all my algorythms, until now.
perhaps I'm doing too many of thrm and shouldn really be moving on :smile:
Gulsvi
@gulsvi
Aug 26 2017 21:28
lol, hope it works out for you. I only tried your code in Firefox
Fernando
@lestairon
Aug 26 2017 21:31
@SkyC0der Ty!
CamperBot
@camperbot
Aug 26 2017 21:31
lestairon sends brownie points to @skyc0der :sparkles: :thumbsup: :sparkles:
:star2: 2572 | @skyc0der |http://www.freecodecamp.com/skyc0der
Fernando
@lestairon
Aug 26 2017 21:54

function mutation(arr) {
  arr =arr.map((L) => L.toLowerCase());
  if (arr[0].indexOf(arr[1]) === arr[1].length) {
    return true;
  }
  return false;
}

mutation(["hello", "hello"]);
Wonder why is it not working...
Jan Shah
@JanShah
Aug 26 2017 21:58
'hello'.indexOf('hello') //returns 0
'hello'.length() //returns error
@lestairon
Fernando
@lestairon
Aug 26 2017 22:00
Should return 5, shouldn't?
'hello'.indexOf('hello') //returns 0
Jan Shah
@JanShah
Aug 26 2017 22:00
'hello'.indexOf('o') //returns 4
Fernando
@lestairon
Aug 26 2017 22:01
Oh
Jan Shah
@JanShah
Aug 26 2017 22:01
indexOf returns the index of the match
Fernando
@lestairon
Aug 26 2017 22:01
So, it doesn't work like "How many matches are"
Jan Shah
@JanShah
Aug 26 2017 22:02
no, that would be something different
Fernando
@lestairon
Aug 26 2017 22:02
Instead it returns the index of the match
Jan Shah
@JanShah
Aug 26 2017 22:02
maybe you should just check if one is equal to the other, they're both strings
'hello'==='hello' //returns true
Fernando
@lestairon
Aug 26 2017 22:04
But i need tho check if arr[0] letters are in arr[1]
Jan Shah
@JanShah
Aug 26 2017 22:05
so arr[1] might not be the same length but have the same characters?
@lestairon
Fernando
@lestairon
Aug 26 2017 22:05
Yes
Like team and mate
Or line and Alien
Jan Shah
@JanShah
Aug 26 2017 22:08
any matching letters, not sequential?
@lestairon you need to compare each letter, maybe a loop
Fernando
@lestairon
Aug 26 2017 22:10
And maybe split the strings
Jan Shah
@JanShah
Aug 26 2017 22:11
to compare each letter you would need to
at least one of them to compare with the content of the other
Margaret
@Margaret2
Aug 26 2017 22:11
@JanShah https://www.freecodecamp.com/challenges/mutations
look at the challenge instructions/tests
will help you give help ...
Jan Shah
@JanShah
Aug 26 2017 22:12
yes, I have just checked.