These are chat archives for FreeCodeCamp/HelpJavaScript

23rd
Aug 2017
Stephen James
@sjames1958gm
Aug 23 2017 00:00
Learn the fundamentals of any of these languages and you should be able to translate that to other languages.
At work I have been working with Alexa voice commands, sending to a javascript backend which opens a TCP connection
to our C++ platform which launches a java application into a android emulator. So at any time I have looking at
javascript, c++ and java code all at the same time
Gersho
@Gersho
Aug 23 2017 00:04
and how much javascript would you consider sufficient to be considered good fundamentals ?
Slitherings
@Slitherings
Aug 23 2017 00:06
@sjames1958gm i know this isn't a question related towards Code at all, but in all honesty with all the coding knowledge you have do u think you could easily become a hacker if you wanted to? or does the coding background not really provide you with the experience that you need to actually hack softwares or find exploits for stuff?
Keon Samuel
@keonsam
Aug 23 2017 00:06
understanding function and objects.
Slitherings
@Slitherings
Aug 23 2017 00:06
im quite confused between the coding world and the hacking world.
when your younger you think they are all the same thing
Keon Samuel
@keonsam
Aug 23 2017 00:07
hacking world are the cool guys.
Gersho
@Gersho
Aug 23 2017 00:07
@Slitherings i think you misunderstand hacking
Slitherings
@Slitherings
Aug 23 2017 00:07
@keonsam in all honesty dont u think it would be awesome to be ajacker
Gersho
@Gersho
Aug 23 2017 00:07
most of the time it's getting someone to give you the info you want
Slitherings
@Slitherings
Aug 23 2017 00:07
@Gersho oh im a 100% sure i am haha i want someone like you guys to explain it to me
Gersho
@Gersho
Aug 23 2017 00:08
no i mean, most of the time you don't even need a computer
Slitherings
@Slitherings
Aug 23 2017 00:08
@Gersho i was kinda talking about like how i hear stuff about people stealing money from peoples banks account without knowing anything about the person or any connections at all.
kinda like a keylogger
Gersho
@Gersho
Aug 23 2017 00:10
oh that kind, well i'm sure you know people with 14 toolbars and 'optimisation tools' on their computer ?
Margaret
@Margaret2
Aug 23 2017 00:11
it seems to me that some people are just more interested in practicing how to do mischievous things with their code. i think there are like "ethical hacking" courses you can take to learn a few basics :D
alpox
@alpox
Aug 23 2017 00:11
@Slitherings that requires a lot of system and networking knowledge, sometimes even embedded systems knowledge. I myself wouldnt be any good hacker even though i can code :)
Gersho
@Gersho
Aug 23 2017 00:11
a reinforced front door won't help you if you open the door yourself
Slitherings
@Slitherings
Aug 23 2017 00:11
hahaha
alpox i think you could do it bro
alpox
@alpox
Aug 23 2017 00:12
I think i couldnt, lad :D
And im really sleeping :D
Slitherings
@Slitherings
Aug 23 2017 00:12
i'd wanna become a white hat
but i dont think im smart enough haha
Keon Samuel
@keonsam
Aug 23 2017 00:13
@alpox your best programming language?
Slitherings
@Slitherings
Aug 23 2017 00:13
@keonsam haha i saw that
alpox
@alpox
Aug 23 2017 00:13
@keonsam probably javascript :/ it used to be C#
Slitherings
@Slitherings
Aug 23 2017 00:14
@alpox go 2 sleep!!
:(
alpox
@alpox
Aug 23 2017 00:14
And stop keeping me from sleep yall :D ill be a zombie tomorrow ^^
:wave:
Grigor Minasyan
@gogminsam
Aug 23 2017 00:14
hey guys i just finished writing my sum all primes code, I'd like to get feedback, is the code is efficient? Is this a good implementation of Sieve of Eratosthenes?
function sumPrimes(n) {
  var prime = [], notprime = [];
  //adds numbers to notprime[] which are not prime
  for (j=2;j<n;j++) {for (k=2;k*j<=n;k++) {if(notprime.indexOf(j*k)==-1) {notprime.push(j*k);}}}
  //adds numbers to prime[] which are not in notprime
  for (i=2;i<=n;i++) {if (notprime.indexOf(i)==-1) {prime.push(i);}}
  return prime.reduce(function(a,b) {return a+b;});
}

sumPrimes(1000);
Slitherings
@Slitherings
Aug 23 2017 00:16
hahaa can i link a funny video?
Grigor Minasyan
@gogminsam
Aug 23 2017 00:17
:smile: :smile: :smile: :smile:
Slitherings
@Slitherings
Aug 23 2017 00:18
"you must collaborate" "who will i collaborate with i'm the only developer????"
Stephen James
@sjames1958gm
Aug 23 2017 00:25
@Slitherings Finding exploits is a different knowledge set that what I have. I guess if I studied it I would not have too much trouble getting into it.
Slitherings
@Slitherings
Aug 23 2017 00:26
man i hate going to work when im programming....
Stephen James
@sjames1958gm
Aug 23 2017 00:26
@gogminsam I don't know about efficient, but writing all your code on one line is not accepted style.
Slitherings
@Slitherings
Aug 23 2017 00:26
^
i was gonna say that but im a scrub and didnt wanna step out of line
Stephen James
@sjames1958gm
Aug 23 2017 00:27
@Slitherings All the more impetus to make work a programming job :)
Slitherings
@Slitherings
Aug 23 2017 00:27
@sjames1958gm should i try to become a freelancer instead of working at this crap job
im making only 460 every two weeks
Inferfire
@Inferfire
Aug 23 2017 00:27
I'm back... with a question...
Grigor Minasyan
@gogminsam
Aug 23 2017 00:28
@sjames1958gm I know I just wanted to make it short after finishing it
Inferfire
@Inferfire
Aug 23 2017 00:28

I’ve created an interesting sort of array. I suppose it’s a bunch of arrays within an array.
It looks like this:

    var wallLocations = [[0, 0, 48, 600],
                         [0, 528, 3186, 72],
                         [3144, -100, 42, 700],
                         [93, 384, 225, 30],
                         [891, 159, 342, 69],
                         [1215, 375, 342, 69],
                         [1470, 66, 342, 69],
                         [1800, 342, 342, 69],
                         [2106, 69, 342, 69],
                         [1215, 375, 342, 69],
                         [2301, 465, 63, 63],
                         [2736, 465, 63, 63]];

Now whenever I go to most sites they say to splice the array. But I really don’t understand how I would do that.
My goal is to replace [93, 384, 225, 30] with [0, 525, 372, 72], but I don’t quite understand how that works. If someone could explain that to me, it’d be much appreciated.

Stephen James
@sjames1958gm
Aug 23 2017 00:28
@Slitherings If you can make it as a freelancer, that is great. I have too many obligations at this time to make the plunge
@Inferfire A nested array would be a common term for that
Slitherings
@Slitherings
Aug 23 2017 00:29
@sjames1958gm would it be hard to make 400 in 2 weeks as a freelancer doing web development?
Gersho
@Gersho
Aug 23 2017 00:29
@Inferfire wallLocation[3] = [0, 525, 372, 72]; ?
Inferfire
@Inferfire
Aug 23 2017 00:30
@Gersho Whoa... I'm stupid
Stephen James
@sjames1958gm
Aug 23 2017 00:30
@Slitherings Maybe at first, but as you build your skill and clients . . .
Start close to home with people you know. Charge a nominal fee for work.
The tendency is to charge nothing at first, but then people might think if you charge nothing your work might be worth nothing.
Gersho
@Gersho
Aug 23 2017 00:31
@sjames1958gm of course it's worth nothing, you're simply playing on the computer
Slitherings
@Slitherings
Aug 23 2017 00:31
yeaa
Stephen James
@sjames1958gm
Aug 23 2017 00:32
@Gersho Tell that to Sports figures that are just playing on a field and make 6 - 7 figures :)
Gersho
@Gersho
Aug 23 2017 00:32
it's different, they're famous
rules aren't the same for famous and handsome people
Slitherings
@Slitherings
Aug 23 2017 00:33

Iterate over Arrays with map

var oldArray = [1,2,3,4,5];

// Only change code below this line.
var timesFour = oldArray.map(function(val){
   return val + 3;                          
});
var newArray = oldArray;

(Check)You should not change the original array.
(X)You should add three to each value in the array.
(Check)You should be making use of the map method.
(Check)You should only modify the array with map.

Kinda confused on this one :worried:
Gersho
@Gersho
Aug 23 2017 00:34
what are you expecting from timesFour ?
do you return it at some point ?
same question with newArray
Stephen James
@sjames1958gm
Aug 23 2017 00:35
@Slitherings Shouldn't newArray be the result of map? You are setting timesFour to the result of map
Slitherings
@Slitherings
Aug 23 2017 00:35
oh
T_T im retarded
Gersho
@Gersho
Aug 23 2017 00:36
we all are don't worry ;)
Stephen James
@sjames1958gm
Aug 23 2017 00:36
@Slitherings You are learning.
Attention to detail when reading instructions maybe the most important lesson you can learn early on.
Be willing to read/read/read
Gersho
@Gersho
Aug 23 2017 00:37
and be very litteral about it
code is a bit like that sarcastic fairy that grants wish in a literal way
Slitherings
@Slitherings
Aug 23 2017 00:37
hahah
yea i can understand that
you say one thing thats a little off and the whole wish gets fucked over
Gersho
@Gersho
Aug 23 2017 00:38
when someone asks "what did the computer do ?" i answer "exactly what you asked it to"
Stephen James
@sjames1958gm
Aug 23 2017 00:41
@Slitherings lol
Slitherings
@Slitherings
Aug 23 2017 00:42
work in a hour in 30 mins
:(
like its geting to the point where as soon as i get 3k dollars im leaving
i have 1k right now 2k left 2 go
2k goes to school the other 1k goes to another computer
Gersho
@Gersho
Aug 23 2017 00:43
what currency are we talking about ? 1k for a comp seems a lot
Slitherings
@Slitherings
Aug 23 2017 01:02
well
im gonna drop about 700-800 on it
US currency the dollar haha
Slitherings
@Slitherings
Aug 23 2017 01:26
well guys im gonna have to get ready for work soon hopefulyl if any of you guys are on when i get off work later tonight at 5 am ish ill c u guys again soon
Peace! and keep coding! :D
Gersho
@Gersho
Aug 23 2017 01:27
later ! :)
Stuhl
@Stuhl
Aug 23 2017 02:31
hey guys, is someone here doing code reviews ?
Claudio Restifo
@Marmiz
Aug 23 2017 02:38
@Stuhl what do you mean by that?
You want some critic on a piece of code you've written?
Stuhl
@Stuhl
Aug 23 2017 02:39
@Marmiz yeah
But I have to redirect to the stack exchange page where I have one question up about the code
If no one minds I will put the link here
there is also explanation about the problem etc. Feel free to leave a comment
Claudio Restifo
@Marmiz
Aug 23 2017 02:42
code
@Stuhl the standard "good code" measurement
Stuhl
@Stuhl
Aug 23 2017 02:44
@Marmiz I've seen that pic before, but it doesn't really help to get my code cleaner u know, cuz to get the WTF's I need some critic back from you guys lol
Tricia
@patricia07
Aug 23 2017 02:48

@patricia07
hey
is something wrong with my code?
// Only change code below this line

var processed = 2;

function processArg(num) {
return (num + 2) / 5;

processed = process (7);

}

Ronique Ricketts
@RoniqueRicketts
Aug 23 2017 02:53
@patricia07 what is your desired result?
Stuhl
@Stuhl
Aug 23 2017 02:53
@patricia07 You didnt called the function correct, process(7) should be processArg(7)
Atleast that's what I think it is lol
Tricia
@patricia07
Aug 23 2017 02:55
so process = processArg (7)?
Stuhl
@Stuhl
Aug 23 2017 02:55
yeah
Tricia
@patricia07
Aug 23 2017 02:55
it still doesn't work
Stuhl
@Stuhl
Aug 23 2017 02:55
Try that
call it outside of the function then
Tricia
@patricia07
Aug 23 2017 02:55
i did
Stuhl
@Stuhl
Aug 23 2017 02:55
I feel like it will do recursive calls otherwise
Tricia
@patricia07
Aug 23 2017 02:55

var processed = 2;

function processArg(num) {
return (num + 2) / 5;

}

processed = processedArg (7)

Stuhl
@Stuhl
Aug 23 2017 02:55
Tell me it worked
Tricia
@patricia07
Aug 23 2017 02:55
like that?
Stuhl
@Stuhl
Aug 23 2017 02:56
yeah
Tricia
@patricia07
Aug 23 2017 02:56
it doesn't work
Stuhl
@Stuhl
Aug 23 2017 02:56
noo
xD
processedArg should be processArg
You wrote it wrong, again
Tricia
@patricia07
Aug 23 2017 02:57
ohhhh
that's why
sorry xD
Stuhl
@Stuhl
Aug 23 2017 02:57
np happens to the best
Had a similar problem and couldn't find the bug for like 1 hour straight
Tricia
@patricia07
Aug 23 2017 02:58

var processed = 2;

function processArg(num) {
return (num + 2) / 5;

}

processed = processArg (7)

Stuhl
@Stuhl
Aug 23 2017 02:58
that was funny lol
yeah should work
Tricia
@patricia07
Aug 23 2017 02:58
why it still doesn't work
Stuhl
@Stuhl
Aug 23 2017 02:58
xD
processArg (7)
dont make a space between
the paranthesis and the name
You troll me right
CamperBot
@camperbot
Aug 23 2017 02:59
:trollface: troll problems? notify admins here
Stuhl
@Stuhl
Aug 23 2017 02:59
lol
Tricia
@patricia07
Aug 23 2017 02:59
processed should have a value of 2

// Only change code below this line

var processed = 2;

function processArg(num) {
return (num + 2) / 5;
}
processed = processArg(7);

John
@AnonymousLords
Aug 23 2017 02:59
Guys what does this mean
var myFish = ['angel', 'clown', 'mandarin', 'sturgeon'];
var removed = myFish.splice(-2, 1);

// myFish is ["angel", "clown", "sturgeon"] 
// removed is ["mandarin"]
Stuhl
@Stuhl
Aug 23 2017 02:59
function processArg(num) {
return (num + 2) / 5;

}

processed = processArg(7)
Thats the correct way
John
@AnonymousLords
Aug 23 2017 02:59
What does teh 1 mean? :point_up: August 22, 2017 10:59 PM
Stuhl
@Stuhl
Aug 23 2017 03:00
@AnonymousLords it means that only 1 element gets removed
Tricia
@patricia07
Aug 23 2017 03:00
still not working xD @Stuhl
John
@AnonymousLords
Aug 23 2017 03:00
Now what would -2, 2 do? @Stuhl
WOuld it remove that and clown?
Stuhl
@Stuhl
Aug 23 2017 03:00
@patricia07 jeez wait a sec, gonna write it in playcode
http://playcode.io/blabla?tabs=console&script.js&output
Look there
Claudio Restifo
@Marmiz
Aug 23 2017 03:02

@Stuhl there's a lot of code there that needs a careful read to be properly commented.
The first thing I have noticed, and it's not an error per se nor a bad code, is that you've wrote all your queue logic in the same place.
I would have just gone to the constructor route, adding prototype to is, so that it's splitted into smaller chunk (generally easy to debug).

[shameless copied by a Queue in C and ported in JS]

function Queue() {
    this._oldestIndex = 1;
    this._newestIndex = 1;
}

Queue.prototype.size = function() {
    return this._newestIndex - this._oldestIndex;
};

let q = new Queue();
q.size();  // 0

But it's more a matter of preference and readability at this point

Stuhl
@Stuhl
Aug 23 2017 03:03
@AnonymousLords the -2 refers to the index your in the arr and the 2 refers to the delete count
look it up here on mdn:
https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Array/splice
sorry man I'm not a magician, cannot guess what happens when u put minus index values, normally you would always have positive values for the index
John
@AnonymousLords
Aug 23 2017 03:03
SO it would go from -2 and up right?
myFish.splice(-2, 2); = [ 'mandarin', 'sturgeon' ]
Tricia
@patricia07
Aug 23 2017 03:04
it still doesn't work @Stuhl but thank you anyways
CamperBot
@camperbot
Aug 23 2017 03:04
patricia07 sends brownie points to @stuhl :sparkles: :thumbsup: :sparkles:
:cookie: 171 | @stuhl |http://www.freecodecamp.com/stuhl
John
@AnonymousLords
Aug 23 2017 03:04
its going from the end to start with negative
Stuhl
@Stuhl
Aug 23 2017 03:07

@Marmiz Makes sense, will look into that solution thanks mate
I just thought that a namespace would do the trick because alot of libraries are using them like that, for example crafty.js or enchant.js

Though did you noticed something about the structure of the array code ? Because I feel like it's very cluttered and unecessary code, could be more concise in general
Also the access of the array is a nightmare in my opinion

CamperBot
@camperbot
Aug 23 2017 03:07
stuhl sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1027 | @marmiz |http://www.freecodecamp.com/marmiz
Stuhl
@Stuhl
Aug 23 2017 03:07
@patricia07 Damn can you send the link for the challenge ? Gonna help you out
@AnonymousLords I understand, didn't knew that lol
But why would you do that in that case ? positives are also valid because your array isn't that big, and you have to mess around with counting from backwards
Claudio Restifo
@Marmiz
Aug 23 2017 03:10
@Stuhl I have never implemented a Quque in JS, but even in C/Cpp you generally don't use native array :)
If you notice in my dumb example there's no reference to an array... I would simply allocate some space in the memory
function Queue() {
    this._oldestIndex = 1;
    this._newestIndex = 1;
    this._storage = {}; // allocate some space in an object
}
John
@AnonymousLords
Aug 23 2017 03:10
@Stuhl Im doing the Slasher Flick challenge ( https://www.freecodecamp.org/challenges/slasher-flick)
Claudio Restifo
@Marmiz
Aug 23 2017 03:12
@patricia07 if your desired output is 2,
your arithmetic operation is (7 +2) / 5 which is 1.8
Not sure what you want to achieve :)
John
@AnonymousLords
Aug 23 2017 03:12
I not to that level yet, but whata re you guys trying to achieve?
var myFish = ['angel', 'clown', 'mandarin', 'sturgeon'];
var removed = myFish.splice(-2, 1);

// myFish is ["angel", "clown", "sturgeon"] 
// removed is ["mandarin"]
It goes 2 elements into the array and only remove's one element
If it was 2 instead of 1, it woudld go from that elemnt and up 1
Gersho
@Gersho
Aug 23 2017 03:15
well you asked it that
John
@AnonymousLords
Aug 23 2017 03:15
If 1 was myFish.length, it would splace from the 2nd element in (from the end not from start) up until the end of the array.
Claudio Restifo
@Marmiz
Aug 23 2017 03:16

@Stuhl anyway I took inspiration of a Queue written in C, that uses a Struct.

I honestly don't know how to make it in JS.
I probably use an object as I showed you

Gersho
@Gersho
Aug 23 2017 03:16
array.splice(start, deleteCount)
Stuhl
@Stuhl
Aug 23 2017 03:16
@AnonymousLords This works now:

function slasher(arr, howMany) {
  if (howMany === 0) {
    return arr;
  } else {
    return arr.splice(howMany, 2); // Will cut away 2 elements, starting at arr[0] --> 1
  }
}

slasher([1, 2, 3], 0);
Gersho
@Gersho
Aug 23 2017 03:16
what are you trying to do btw ?
John
@AnonymousLords
Aug 23 2017 03:16
Oh i just already did it

function slasher(arr, howMany) {

  if (howMany > arr.length) {
    return arr = [];
  }
  if (howMany <= 0) {
    return arr;
  }

  arr = arr.slice(howMany, arr.length);

  return arr;
}

slasher([1, 2, 3], 0);
Gersho
@Gersho
Aug 23 2017 03:16
oh that one
That took me 5 minutes
That was the easiest basic algorithm i have done.
Stuhl
@Stuhl
Aug 23 2017 03:17
what are you doing with that if (howMany > arr.length) ?
John
@AnonymousLords
Aug 23 2017 03:17

Return the remaining elements of an array after chopping off n elements from the head.

The head means the beginning of the array, or the zeroth index.

Remember to use Read-Search-Ask if you get stuck. Write your own code.

Here are some helpful links:

Array.prototype.slice()
Array.prototype.splice()

Gersho
@Gersho
Aug 23 2017 03:17
stuff gets funny with intermediate challenges
slasher([1, 2, 3], 9) should return [].
:+1: slasher([1, 2, 3], 0) should return [1, 2, 3].
Gersho
@Gersho
Aug 23 2017 03:19
mine is 2 lines
Stuhl
@Stuhl
Aug 23 2017 03:19
@Marmiz Hmm I didn't consider to use an Object instead of array, could try to do that but will be painful to loop through because the for .. in .. loop doesn't go on queue, it sometimes jumpes around
And in my case it's important to keep queue
Gersho
@Gersho
Aug 23 2017 03:19
you don't need the if
John
@AnonymousLords
Aug 23 2017 03:19
Okay
wait one sec
Gersho
@Gersho
Aug 23 2017 03:20
function slasher(arr, howMany) {
  // it doesn't always pay to be first
    arr.splice(0,howMany);
    return arr;
}
Stuhl
@Stuhl
Aug 23 2017 03:20
@Gersho That doesn't work for one case, it will still cut away one
That's why the if statement
Gersho
@Gersho
Aug 23 2017 03:21
you mean if howMany = 0 ? why would that happen ? in that case why would you need the function for ?
Stuhl
@Stuhl
Aug 23 2017 03:22
I dunno why that happens, haven't read through the docs on MDN but it happens so there has to be a if statement
Probably a quirk in splice, could behave differently with slice though
John
@AnonymousLords
Aug 23 2017 03:22
Its supposed to get a blank array if number is bigger the number of elements
Gersho
@Gersho
Aug 23 2017 03:23

just checked my challenge, it has

slasher([1, 2, 3], 0) should return [1, 2, 3].
slasher([1, 2, 3], 9) should return [].

so it covers both cases, and works

Stuhl
@Stuhl
Aug 23 2017 03:23
@Marmiz Have to ask, did u understand the code completly ? cuz I sometimes don't do myself and I wrote it xDD
Gersho
@Gersho
Aug 23 2017 03:24
oh wait
you're using slice
i'm using splice
Claudio Restifo
@Marmiz
Aug 23 2017 03:24

@Stuhl the logic of a Queue is that in general you don't need to loop (unless to clean memory), all you need is to keep reference of the action and its index inside the queue and then point to it.

The closest thing in JS is an object.
To expand on the Queue example:

function Queue() {
    this._oldestIndex = 1;
    this._newestIndex = 1;
    this._storage = {};
}

Queue.prototype.enqueue = function(data) {
    this._storage[this._newestIndex] = data;
    this._newestIndex++;
};

let q = new Queue();
let action = { command: 'attack'};
let action1 = { command: 'defend'};
let action2 = { commande : 'cast spell'};
q.enqueue(action);
q.enqueue(action1);
q.enqueue(action2);

console.log(q._storage[2]) // { command: 'defend' }
John
@AnonymousLords
Aug 23 2017 03:24
Would it work if the number is bigger?
Would it return blank?
Gersho
@Gersho
Aug 23 2017 03:24
@AnonymousLords slasher([1, 2, 3], 9) should return [].
so yes
Stuhl
@Stuhl
Aug 23 2017 03:25
@Gersho Did you really evaluated the code ? It doesn't work on my side
John
@AnonymousLords
Aug 23 2017 03:25
Oh
Gersho
@Gersho
Aug 23 2017 03:25
@Stuhl reran it, yes it does
but it's splice not slice
so maybe the stuff you were refering too (0removing 1 item) is valid on slice but not on splice ?
Stuhl
@Stuhl
Aug 23 2017 03:26
@Gersho I also used splice, it didn't worked
weird
John
@AnonymousLords
Aug 23 2017 03:27
Im using https://repl.it/
Gersho
@Gersho
Aug 23 2017 03:29
@Stuhl did you get it to work ?
John
@AnonymousLords
Aug 23 2017 03:29
Ill try
Stuhl
@Stuhl
Aug 23 2017 03:30
@Marmiz But I have to call the functions according, lets say, to the agility level of a entity, and to do that I only know to get it into a array, sort from biggest value to lowest and then loop through until each corresponding entity has called it's function
Though I see your point, will do some testing tomorrow, I'm tired as hell
John
@AnonymousLords
Aug 23 2017 03:31
nvm
Gersho
@Gersho
Aug 23 2017 03:31
^ ^
Stuhl
@Stuhl
Aug 23 2017 03:31
@Gersho Ohh I fucked up, I see it I did (howMany, 2) instead of (0, howMany)
funny it still worked lol
Gersho
@Gersho
Aug 23 2017 03:32
so it's ok now ?
John
@AnonymousLords
Aug 23 2017 03:32
It works for me
thanks @Gersho @Stuhl I didn;t know splice worked like that
CamperBot
@camperbot
Aug 23 2017 03:32
anonymouslords sends brownie points to @gersho and @stuhl :sparkles: :thumbsup: :sparkles:
:cookie: 172 | @stuhl |http://www.freecodecamp.com/stuhl
:cookie: 343 | @gersho |http://www.freecodecamp.com/gersho
Gersho
@Gersho
Aug 23 2017 03:33
yummy cookies <3
Stuhl
@Stuhl
Aug 23 2017 03:33
@Gersho Thats weird
Gersho
@Gersho
Aug 23 2017 03:33
show the code ?
John
@AnonymousLords
Aug 23 2017 03:34
How to code on repl?
Stuhl
@Stuhl
Aug 23 2017 03:34

Returning the value like

return arr.splice(0, howMany);

doesn't work but

arr.splice(0, howMany);
return arr;

does work

I don't understand my life anymore, maybe i just need to sleep xD
John
@AnonymousLords
Aug 23 2017 03:34
Lol why doesnt it work?
Gersho
@Gersho
Aug 23 2017 03:35
because they aren't the same thing
Stuhl
@Stuhl
Aug 23 2017 03:35
Yeah, it returns the spliced arr
Gersho
@Gersho
Aug 23 2017 03:35
the first one is saying var foo = arr.splice(0, howMany)
Stuhl
@Stuhl
Aug 23 2017 03:35
instead of the actual arr lol
Gersho
@Gersho
Aug 23 2017 03:36
then returning foo
but splice modifies an existing array, it doesn't return anything
John
@AnonymousLords
Aug 23 2017 03:36
Does anyone here use repl.it>?
Stuhl
@Stuhl
Aug 23 2017 03:36
well thats weird but good to know
Im gonna sleep now
Gersho
@Gersho
Aug 23 2017 03:37
i don't sorry, for pure JS i use the freeCodeCamp challenge pages, and then codepen + atom/browser @AnonymousLords
Stuhl
@Stuhl
Aug 23 2017 03:37
happy coding everyone
Gersho
@Gersho
Aug 23 2017 03:37
good night
John
@AnonymousLords
Aug 23 2017 03:37
gn
@Stuhl
Ken Haduch
@khaduch
Aug 23 2017 03:37
@AnonymousLords - i've used it... what's going on?
John
@AnonymousLords
Aug 23 2017 03:38
How to delete a repl?
Gersho
@Gersho
Aug 23 2017 03:38
ctrl+A, delete, save ?
John
@AnonymousLords
Aug 23 2017 03:38
I created one as a test but how doi dlete it?
Gersho
@Gersho
Aug 23 2017 03:39
leave it empty ? don't worry about their database they probably have cleanup tools
Ken Haduch
@khaduch
Aug 23 2017 03:39
@AnonymousLords - go to your "Sessions" page - way over on the right there is a three-dot menu. One of the items is "delete".
if you have an account, that is. Maybe if you are "anonymous" then you don't have that option?
John
@AnonymousLords
Aug 23 2017 03:40
Thanks @khaduch
CamperBot
@camperbot
Aug 23 2017 03:40
anonymouslords sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3231 | @khaduch |http://www.freecodecamp.com/khaduch
John
@AnonymousLords
Aug 23 2017 03:40
Its in my repls
Ken Haduch
@khaduch
Aug 23 2017 03:40
@AnonymousLords - okay, great!
John
@AnonymousLords
Aug 23 2017 03:40
:D
Gersho
@Gersho
Aug 23 2017 03:41
so you use this site to keep a copy of your fCC challenges ?
John
@AnonymousLords
Aug 23 2017 03:42
Yes and to help figure teh chllang,e since it tells you a lot more then fcc does about errors
Its a good way to add to your portfolio
Along with codepen
Gersho
@Gersho
Aug 23 2017 03:44
i'm waiting to finish front end to redo my portfolio (only JS calculator left !)
John
@AnonymousLords
Aug 23 2017 03:44
cool :D How long have you been doing this for?
marcus dylan johnson
@mdjohns
Aug 23 2017 03:44
Hey all. Just finished the truncate a string challenge (https://www.freecodecamp.com/challenges/truncate-a-string). My answer passed the tests, but feels sloppy. Any tweaks you would make?
function truncateString(str, num) {
    if(num <= 3){
      return str.slice(0, num) + "...";
    }
    else if (str.length <= num){
      return str;
    } else if (str.length > num){
        return str.slice(0, num- 3)+ "...";
    }

}
truncateString("A-", 1);
Gersho
@Gersho
Aug 23 2017 03:45
started in march but had a ~3month gap of not being on it
John
@AnonymousLords
Aug 23 2017 03:45
How hard is indeterminate adn advanced algorithm scripting?
Wow i started in janurey, but stopped for a,long time. I have returned in july and been doing it every day
Gersho
@Gersho
Aug 23 2017 03:46
a few in intermediate felt a bit brutal, since that's when they stop holding your end (like they stop saying you "splice might be nice here"
John
@AnonymousLords
Aug 23 2017 03:46
Okay
IS it complicated>?
Gersho
@Gersho
Aug 23 2017 03:46
@djohnson501 i'm not sure you need the else, but apart from that it looks fine
@AnonymousLords depends, i asked around and not everyone struggle on the same ones, some took me 5 mins, steamroller took me a week
John
@AnonymousLords
Aug 23 2017 03:49
Okay
hillsie
@Hillsie
Aug 23 2017 03:52
@Slitherings re: your youtube clip ….bhahhahahhha
John
@AnonymousLords
Aug 23 2017 03:52
I gtg @Gersho , thanks for all of your help~!
CamperBot
@camperbot
Aug 23 2017 03:52
anonymouslords sends brownie points to @gersho :sparkles: :thumbsup: :sparkles:
:warning: anonymouslords already gave gersho points
hillsie
@Hillsie
Aug 23 2017 03:53
@Slitherings thanks
Ken Haduch
@khaduch
Aug 23 2017 04:01
@djohnson501 - I took a slightly different approach on "Truncate a string" - I set up a variable ellipsis and initialized it to an empty string. If the string was longer than the num value, I set it to .... Then I computed what the actual num value should be - for that one case, I subtract 3 from it. Then I only have one splice and just append ellipsis (the variable, which might be an empty string) to it. I think that's a little cleaner? It sort of does the dirty work in one place, and only one call to str.slice with the calculated parameters, one appending of the string variable to the end of it.
marcus dylan johnson
@mdjohns
Aug 23 2017 04:12
@khaduch that definitely sounds cleaner. Could you walk me through that solution? I think I’ve got it started.
function truncateString(str, num) {
var ellipsis = "";
if(str.length < num){
    ellipsis = "...";
}
return str.slice(0, num) + ellipsis;
};
truncateString("A-", 1);
Just not sure where the calculation of what num should go
Ken Haduch
@khaduch
Aug 23 2017 04:25
@djohnson501 - I have if(str.length > num) { ellipsis = '...' } because that is when you are going to truncate - If the input string is longer than the final truncated string. The else for that is just to set num = str.length; because that means that we aren't really slicing, just take the entire string.
For num - if ( num > 3 && str.length > 4 ) { num -= 3; } that reduces the length of what we slice out.
The final action is return str.slice(0, num) + ellipsis;
Gersho
@Gersho
Aug 23 2017 04:28
i don't have anything to say, but since you seem to be looking at how other people did it, here's mine

function truncateString(str, num) {
if (num>=str.length){
  return str;
}
if (num<=3){
  str = str.slice(0,num)+"...";
  return str;
}
 str = str.slice(0,num-3)+"...";
return str; 
}
Ken Haduch
@khaduch
Aug 23 2017 04:36
@Gersho - good point - I could simplify mine with just return str; instead of the manipulation with num for that case. I got locked into thinking about it a certain way where I only wanted to have one return statement... :) thanks for that!
CamperBot
@camperbot
Aug 23 2017 04:36
khaduch sends brownie points to @gersho :sparkles: :thumbsup: :sparkles:
:cookie: 345 | @gersho |http://www.freecodecamp.com/gersho
Gersho
@Gersho
Aug 23 2017 04:36
yay free cookies
Ken Haduch
@khaduch
Aug 23 2017 04:46

@djohnson501 - since I'm going to head offline, here's my slightly modified solution, just for reference.

function truncateString(str, num) {
  // Clear out that junk in your trunk
  var inStrLength = str.length;
  if ( inStrLength > num ) {
    if ( num > 3 && inStrLength > 4 ) {
      num -= 3; // input string is longer than 4 chars, reduce extracted length
    }
    return str.slice(0, num) + '...'; // take the slice and append '...'
  }
  else return str; // take the entire string
}

Now there is no need to fiddle with the ellipsis, just makes it even simpler!

WAINGOR
@WAINGOR
Aug 23 2017 05:58
hi all, how do we call this operator again -> "..." ? For instance:
var X = [1,[2],3];
var Y = [].concat(...X);
Markus Kiili
@Masd925
Aug 23 2017 06:01
@WAINGOR What are you trying to do?
Pethaf
@Pethaf
Aug 23 2017 06:01
@WAINGOR The unpacking operator?
Or the variadic argument operator?
WAINGOR
@WAINGOR
Aug 23 2017 06:01
@Masd925 find out what that operator is called
Markus Kiili
@Masd925
Aug 23 2017 06:02
@WAINGOR Spread operator.
Pethaf
@Pethaf
Aug 23 2017 06:02
Is there an equivalent to the spread operator in java?
WAINGOR
@WAINGOR
Aug 23 2017 06:02
thanks @Masd925
CamperBot
@camperbot
Aug 23 2017 06:02
waingor sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4429 | @masd925 |http://www.freecodecamp.com/masd925
Pethaf
@Pethaf
Aug 23 2017 06:02
Becuase it looks an awfull lot like the variadic template argument operator from C++.
Dan Couper
@DanCouper
Aug 23 2017 06:06
It's very similar, Java has varargs: https://studiofreya.com/java/how-to-use-java-varargs/
Amit Patel
@AmitP88
Aug 23 2017 06:28
hey guys, I need some help getting react-canvas to work. can anyone help me please?
Chris Cullen
@123xylem
Aug 23 2017 06:49
       <div class="row">
       <script>  
                 $(".homeImg").click(function()){
                     $(".homeImg").hide();
                 }
</script>
                          <div class="col">
                       <img class="homeImg" src ="https://image.ibb.co/csbaU5/portrait.png">

                 </div>
Why doesnt my Jquery work?
I have it linked in my header
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <link rel="stylesheet" href="/stylesheets/main.css">

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
Abhinav Mishra
@abhinav-m
Aug 23 2017 07:02
I want to understand import export statements in js
im a bit confused about this..
when i use node.js it implments the commonJS specification and uses require
so import / export is specific to a browser's environment right now?
do i need babel to use these statements?
when i use react, im guessing webpack does this for me since i read in the documentation that it compiles import /export statements out of the box
Claudio Restifo
@Marmiz
Aug 23 2017 07:08
@123xylem have you tried removing the extra ) you have after the function declaration?
Chris Cullen
@123xylem
Aug 23 2017 07:09
@Marmiz yup :(
Claudio Restifo
@Marmiz
Aug 23 2017 07:09
@123xylem are you in codepen?
Also in general it's not nice to write scrip in between html. Better place them all at the end
Chris Cullen
@123xylem
Aug 23 2017 07:10
@Marmiz ah it works when i move it to bottom!
Claudio Restifo
@Marmiz
Aug 23 2017 07:12

@abhinav-thinktank they are part of the "newer" version of JS (ECMA 16 I guess) so you still need to use babel or webpack to use them correctly.
Some browser are starting implementing them.

Otherwise you can always use the old fashioned require

Abhinav Mishra
@abhinav-m
Aug 23 2017 07:12
is require used natively?
i mean do i need some library to run it ..
Claudio Restifo
@Marmiz
Aug 23 2017 07:18
@abhinav-thinktank require() is a native function supported in node.js, If you want to run it straight in the browser you probably still need require.js
Abhinav Mishra
@abhinav-m
Aug 23 2017 07:18
@Marmiz ok..
@Marmiz thank you, i'll try to run some stuff using it
CamperBot
@camperbot
Aug 23 2017 07:19
abhinav-thinktank sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1028 | @marmiz |http://www.freecodecamp.com/marmiz
Claudio Restifo
@Marmiz
Aug 23 2017 07:24
@AmitP88 still in trouble?
Never used react-canvas but 4 eyes are maybe better than 2 :)
Javier Pons
@JavierPons
Aug 23 2017 07:31
Hi everyone!
I have problem with a code
with classes in javascript ES6

'' class Media {
constructor(media, CD, movie){
this._Media = media;
this._CD = CD;
this._Movie = movie;
}

get title(){
return this._title;
}
get isCheckedOut(){
return this._isCheckedOut;
}
get ratings(){
return this._ratings;
}

toggleCheckOutStatus(){
this._isCheckOutStatus = !this._isCheckOutStatus;
}

getAverageRating(){
let ratingsSum = this._ratings.reduce((currentSum, rating) =>
currentSum + rating, 0);
let lengthOfArray = this._ratings.length;
return ratingsSum/lengthOfArray;
}
addRating(rating){
this._ratings.push(rating);
}
}

class Book extends Media{
constructor(title, author, pages){
super(title);
this._author = author;
this._pages = pages;
this._title = title;
}
get author(){
return this._author;
}
get pages(){
return this._pages;
}

}

class Movie extends Media{
constructor(title, director, runTime){
super(title);
this._director = director;
this._runTime = runTime;
}

get director(){
return this._director;
}
get runTime(){
this._runTime;
}
}

const historyOfEverything = new Book('A Short History of Nearly Everything', 'Bill Bryson', 544);
console.log(historyOfEverything._title);
historyOfEverything.toggleCheckOutStatus()
console.log(historyOfEverything._isCheckedOut); ''

I add this._title = title; to the class child Book.... Isn't it that it should work without adding it?
koder3
@koder3
Aug 23 2017 07:45
<div class = "getTheNumber">
34.44
<button class = "btn"></button>
</div>
how do i access the number that is 34.44
using javascript
Markus Kiili
@Masd925
Aug 23 2017 07:51
@koder3 Target the element and use .textContent
Javier Pons
@JavierPons
Aug 23 2017 07:52
@Masd925 osaatko vastata kysymykseni?
koder3
@koder3
Aug 23 2017 07:53
@Masd925 thanks!
CamperBot
@camperbot
Aug 23 2017 07:53
koder3 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4432 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Aug 23 2017 07:53
@JavierPons En oikeastaan tunne ES6 juttuja.
Javier Pons
@JavierPons
Aug 23 2017 07:53
@Masd925 kiitos kuitenkin
Amit Patel
@AmitP88
Aug 23 2017 08:09
@Marmiz nah, I figured it out. react-canvas-component is a separate package from react-canvas. Go figure lol. Thanks for your offer though. I really appreciate it :)
CamperBot
@camperbot
Aug 23 2017 08:09
amitp88 sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1029 | @marmiz |http://www.freecodecamp.com/marmiz
Claudio Restifo
@Marmiz
Aug 23 2017 08:22
@AmitP88 anytime :+1:
Matej Bošnjak
@mbosnjak01
Aug 23 2017 08:58
Hi. Quick question. Would anyone know how to check if JSON object key has one or more http / https strings in javascript?
Stephen James
@sjames1958gm
Aug 23 2017 08:59
@mbosnjak01 You mean the value of a property in json is a URL?
Matej Bošnjak
@mbosnjak01
Aug 23 2017 08:59
@sjames1958gm yes, one or more
more -> array of links
Stephen James
@sjames1958gm
Aug 23 2017 09:00
@mbosnjak01 Well, you can use Regex and/or Array.isArray + Regex
heroiczero
@heroiczero
Aug 23 2017 09:01
@mbosnjak01 you could probably use regexp with https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys if keys and for... in if you are using the property or you can use the new object.values
Markus Kiili
@Masd925
Aug 23 2017 09:01
@mbosnjak01 You could also use .some() on Object.keys(obj)
Stephen James
@sjames1958gm
Aug 23 2017 09:03
Talking in abstracts is difficult do you have an example? (not sure why a URL would be a property key
Matej Bošnjak
@mbosnjak01
Aug 23 2017 09:03
@sjames1958gm check swapi.co
Stephen James
@sjames1958gm
Aug 23 2017 09:03
@mbosnjak01 Those are property values not keys that are URLs
Matej Bošnjak
@mbosnjak01
Aug 23 2017 09:04
http://i.imgur.com/XmCmHCU.jpg an example of how user looks like inside an object
heroiczero
@heroiczero
Aug 23 2017 09:05
Matej Bošnjak
@mbosnjak01
Aug 23 2017 09:06
@heroiczero no idea how I missed that. thanks :)
CamperBot
@camperbot
Aug 23 2017 09:06
mbosnjak01 sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1640 | @heroiczero |http://www.freecodecamp.com/heroiczero
Stephen James
@sjames1958gm
Aug 23 2017 09:07
Something like this assuming key is a variable holding a property key
if ((Array.isArray(json[key]) && json[key][0].match(/^http.*/)) || json[key].match(/^http.*/))
Abhinav Mishra
@abhinav-m
Aug 23 2017 09:12
var monthMod = function() {
    var names = ['Jan', 'Feb', 'March', 'April', 'May', 'Jun', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec']
    return function(number) {
        return names[number];
    }
}();
In this code, the function expression is being executed immediately right?
using the () at the end
Markus Kiili
@Masd925
Aug 23 2017 09:13
@abhinav-thinktank Yes.
heroiczero
@heroiczero
Aug 23 2017 09:13
@abhinav-thinktank but you don't have a number variable
Abhinav Mishra
@abhinav-m
Aug 23 2017 09:13
@Masd925 ok , so now i can use thismonthMod(3)
heroiczero
@heroiczero
Aug 23 2017 09:14
@abhinav-thinktank no you don't have a parameter
Abhinav Mishra
@abhinav-m
Aug 23 2017 09:14
@heroiczero since it is being executed immediately, my function can be passed a parameter
Markus Kiili
@Masd925
Aug 23 2017 09:14
@abhinav-thinktank Yes you can.
Abhinav Mishra
@abhinav-m
Aug 23 2017 09:14
@Masd925 ty!
CamperBot
@camperbot
Aug 23 2017 09:14
abhinav-thinktank sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4433 | @masd925 |http://www.freecodecamp.com/masd925
Stephen James
@sjames1958gm
Aug 23 2017 09:14
@abhinav-thinktank Yes you can use monthMod
Abhinav Mishra
@abhinav-m
Aug 23 2017 09:14
@sjames1958gm ok, ty. was a bit confused how it was working
CamperBot
@camperbot
Aug 23 2017 09:14
abhinav-thinktank sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8368 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Abhinav Mishra
@abhinav-m
Aug 23 2017 09:15
so basically monthMod refers to the inner function , which has access to names because it's forming a closure
Markus Kiili
@Masd925
Aug 23 2017 09:15
@abhinav-thinktank Yes.
Abhinav Mishra
@abhinav-m
Aug 23 2017 09:15
@Masd925 ok, thanks !
CamperBot
@camperbot
Aug 23 2017 09:15
abhinav-thinktank sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: abhinav-thinktank already gave masd925 points
Stephen James
@sjames1958gm
Aug 23 2017 09:15
@abhinav-thinktank This is useful to keep names array out of the global scope.
You could do this but names would be in global (or at least larger scope)
    var names = ['Jan', 'Feb', 'March', 'April', 'May', 'Jun', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec']
    var monthMod = function(number) {
        return names[number];
    }
Abhinav Mishra
@abhinav-m
Aug 23 2017 09:16
aah yes, doing the sample stuff from eloquent js
@sjames1958gm ty!
CamperBot
@camperbot
Aug 23 2017 09:16
abhinav-thinktank sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: abhinav-thinktank already gave sjames1958gm points
Abhinav Mishra
@abhinav-m
Aug 23 2017 09:16
What i aimed to do was to build my own modules without using the node environment
but i can't do this can i?
teevik
@teevik
Aug 23 2017 09:24
Don't think so
No idea
Victor Popescu
@VicPopescu
Aug 23 2017 10:26
@abhinav-thinktank if you want to build your own modules you can have a look at the revealing module pattern
but if you want something like require(module) as in node, but on the client side, then you have to use requireJS or browserify or something similar to build dependencies
James Dimitrakopoulos
@JamesDimi
Aug 23 2017 10:35
i need to create a list, is this code easily readable/understadable?
Markus Kiili
@Masd925
Aug 23 2017 10:39
@JamesDimi Returning list from the forEach callback doesn't do anything except goes to the next loop.
So return list; inside the callback does the same as return;
CamperBot
@camperbot
Aug 23 2017 10:46
jamesdimi sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4434 | @masd925 |http://www.freecodecamp.com/masd925
James Dimitrakopoulos
@JamesDimi
Aug 23 2017 10:50
@Masd925 thanks
CamperBot
@camperbot
Aug 23 2017 10:50
jamesdimi sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: jamesdimi already gave masd925 points
Abhinav Mishra
@abhinav-m
Aug 23 2017 11:04
@VicPopescu thank you, any good source i can read about that pattern
CamperBot
@camperbot
Aug 23 2017 11:04
abhinav-thinktank sends brownie points to @vicpopescu :sparkles: :thumbsup: :sparkles:
:cookie: 531 | @vicpopescu |http://www.freecodecamp.com/vicpopescu
Victor Popescu
@VicPopescu
Aug 23 2017 11:06
alpox
@alpox
Aug 23 2017 11:06
@abhinav-thinktank https://webpack.github.io is the most used tool for that
Abhinav Mishra
@abhinav-m
Aug 23 2017 11:06
@alpox hmm, i've looked at webpack, wondering how it works underneath the hood.
alpox
@alpox
Aug 23 2017 11:07
@abhinav-thinktank Quite complex. Webpack is a beast :D
Abhinav Mishra
@abhinav-m
Aug 23 2017 11:07
@alpox ty
CamperBot
@camperbot
Aug 23 2017 11:07
abhinav-thinktank sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1314 | @alpox |http://www.freecodecamp.com/alpox
Abhinav Mishra
@abhinav-m
Aug 23 2017 11:07
yeah it is.
I manually configured my react environment a few times and realized it :D
alpox
@alpox
Aug 23 2017 11:07
:D yea the webpack configuration is pretty bullshit
But it works well
Abhinav Mishra
@abhinav-m
Aug 23 2017 11:08
yeah.. create-react-app is good to start on
@VicPopescu aah, this link is really nice, ty
CamperBot
@camperbot
Aug 23 2017 11:08
abhinav-thinktank sends brownie points to @vicpopescu :sparkles: :thumbsup: :sparkles:
:warning: abhinav-thinktank already gave vicpopescu points
alpox
@alpox
Aug 23 2017 11:09
https://webpack.js.org/ probably the better link
(Webpack 2.0)
Victor Popescu
@VicPopescu
Aug 23 2017 11:09
@abhinav-thinktank np
bilaal-s
@bilaal-s
Aug 23 2017 11:10
hello guys, play around with this and criticise as appropriate ^_^ https://codepen.io/bilaal-s/pen/QMjVKK?editors=1010
Stephen James
@sjames1958gm
Aug 23 2017 11:17
@bilaal-s Seems like a lot of duplicated code. There is even code like this:
What is the purpose of checking minusRun if both cases to the same thing?
    } else if (plusRun === true && minusRun !== true) {
      number1 += number2;
      plusRun = false;
    } else if (plusRun === true && minusRun === true) {
      number1 += number2;
      plusRun = false;
    }
bilaal-s
@bilaal-s
Aug 23 2017 11:35
@sjames1958gm woops xD
Stephen James
@sjames1958gm
Aug 23 2017 11:37
@bilaal-s I think this challenge would lend itself to some offline flow charting.
bilaal-s
@bilaal-s
Aug 23 2017 11:38
@sjames1958gm on it!
Stephen James
@sjames1958gm
Aug 23 2017 11:38
@bilaal-s :+1:
bilaal-s
@bilaal-s
Aug 23 2017 11:48
can "+" be converted to + , without too much sophistication?
i doubt it but perhaps therese a function i dont know of
Keone Martin
@Athaman
Aug 23 2017 11:49
context?
bilaal-s
@bilaal-s
Aug 23 2017 11:49
@Athaman building a string for a calculation, "3+4+5", then splitting that string up into numbers and operators, saving to a variable and letting js return that variable
@Athaman i think adding a charcode on operator button click would be better than using +, then i can use then charcode at?
Keone Martin
@Athaman
Aug 23 2017 11:51
to my knowledge you can't save an operator as a variable (or return one) so the best i can think of would be to separate it out with a logic pathway.
like
if( operator === '+'){
  // do plussing things here
}
(where operator is the variable name...)
bilaal-s
@bilaal-s
Aug 23 2017 11:54
imagine the input from various button clicks would be "3+4+5-3", if i turned this somehow into: return sum = 3+4+5-3; wouldnt that work?
Keone Martin
@Athaman
Aug 23 2017 11:54
yeah, it's an interesting idea, it would be nice.
oh wait... maybe
Pethaf
@Pethaf
Aug 23 2017 11:55
@bilaal-s If you want to support things like having variables you need to build a parser.
Pethaf
@Pethaf
Aug 23 2017 11:56
Oh, eval("var x=4+5")
gives a variable called x with a value of 9 in the local scope.
Keone Martin
@Athaman
Aug 23 2017 11:56
apparently there are lots of ways :D it's just not something i've come across
bilaal-s
@bilaal-s
Aug 23 2017 11:57
interesting
@Pethaf @Athaman thanks
CamperBot
@camperbot
Aug 23 2017 11:57
bilaal-s sends brownie points to @pethaf and @athaman :sparkles: :thumbsup: :sparkles:
:cookie: 623 | @athaman |http://www.freecodecamp.com/athaman
:cookie: 388 | @pethaf |http://www.freecodecamp.com/pethaf
Keone Martin
@Athaman
Aug 23 2017 11:59
a note on the above though i would strongly recommend wrapping any inputs using eval in a try{} catch() {} block... since eval('1+2+3a') will throw an error
shaistha
@shaistha24
Aug 23 2017 13:06

hi
pls someone look at my code

var quotes= ["In forming a bridge between body and mind, dreams may be used as a springboard from which man can leap to new realms of experience lying outside his normal state of consciousness.","It has been said that democracy is the worst form of government except all the others that have been tried","By desiring little, a poor man makes himself rich.","Things work out best for those who make the best of how things work out.","If you are not willing to risk the usual you will have to settle for the ordinary.", "Trust because you are willing to accept the risk, not because it’s safe or certain.","Take up one idea. Make that one idea your life - think of it, dream of it, live on that idea. Let the brain, muscles, nerves, every part of your body, be full of that idea, and just leave every other idea alone. This is the way to success.","All our dreams can come true if we have the courage to pursue them.","Success is walking from failure to failure with no loss of enthusiasm.","Opportunities don’t happen, you create them.","Try not to become a person of success, but rather try to become a person of value.","Great minds discuss ideas; average minds discuss events; small minds discuss people.","I have not failed. I’ve just found 10,000 ways that won’t work.","If you don’t value your time, neither will others. Stop giving away your time and talents- start charging for it.","A successful man is one who can lay a firm foundation with the bricks others have thrown at him.","No one can make you feel inferior without your consent.","The whole secret of a successful life is to find out what is one’s destiny to do, and then do it.","If you’re going through hell keep going.","The ones who are crazy enough to think they can change the world, are the ones that do.","What seems to us as bitter trials are often blessings in disguise.","The distance between insanity and genius is measured only by success.","When you stop chasing the wrong things you give the right things a chance to catch you.","Don’t be afraid to give up the good to go for the great. ","Happiness is a butterfly, which when pursued, is always beyond your grasp, but which, if you will sit down quietly, may alight upon you.","If you can’t explain it simply, you don’t understand it well enough.", "Life is not about finding yourself. Life is about creating yourself. ", "Innovation distinguishes between a leader and a follower.","There are two types of people who will tell you that you cannot make a difference in this world: those who are afraid to try and those who are afraid you will succeed.","Success is walking from failure to failure with no loss of enthusiasm." ,"If you don’t value your time, neither will others. Stop giving away your time and talents- start charging for it.","What seems to us as bitter trials are often blessings in disguise."];


<script>
            $(document).ready(function() {
  var randomQuote = quotes[0];
$('blockquote.quotes').html(randomQuote);

                $('#quote').on('click', quote);

                $('#twitter').on('click', twitter);

                var temp;

                function quote() {
                    var randomNumber = Math.floor(Math.random() * quotes.length);
                    randomQuote = quotes[randomNumber];

                    $('blockquote.quotes').html(randomQuote);
                    temp = randomNumber;        
                }

                function twitter() {
                    tweetThis = 'http://twitter.com/home/?status=' + randomQuote;
                    // window.location.href = tweetThis;
                    window.open(tweetThis, '_blank', 'width = 500, height = 400');
                }
})

</script>

this is the code i have written in the code pen in the JS section...yes i have added jQuery to it

every time i press run...it show Unexpected token var..after $(document).ready(function() {

Gersho
@Gersho
Aug 23 2017 13:16
if it's in the JS section of codepen you don't need the <script> element
and by the color of the text i'd say you have some " " problems in your array but too lazy to check
shaistha
@shaistha24
Aug 23 2017 13:22
@Gersho no its not this color there...i have pasted it here ...but dont know
@Gersho thanks it was bcoz of <script> only
CamperBot
@camperbot
Aug 23 2017 13:24
shaistha24 sends brownie points to @gersho :sparkles: :thumbsup: :sparkles:
:cookie: 347 | @gersho |http://www.freecodecamp.com/gersho
Abhinav Mishra
@abhinav-m
Aug 23 2017 14:04
Im a bit confused by this example
function require ( name ) {
var code = new Function (" exports " , readFile ( name ));
var exports = {};
code ( exports ) ;
return exports ;
}
this is a minimal implementation of require
var names = [" Sunday " , " Monday " , " Tuesday ", " Wednesday ",
" Thursday " , " Friday ", " Saturday "];
exports . name = function ( number ) {
return names [ number ];
};
exports . number = function ( name ) {
return names . indexOf ( name ) ;
};
supposing the file read by readFile(name) has the above code
im confused how the exports has the properties name and number assigned to them.
Stephen James
@sjames1958gm
Aug 23 2017 14:05
What is readFile?
Abhinav Mishra
@abhinav-m
Aug 23 2017 14:06
is this because they are on a 'higher' scope than the function being executed
its an example, readFile is supposed to return a string containing the code pasted below
```
var names = [" Sunday " , " Monday " , " Tuesday ", " Wednesday ",
" Thursday " , " Friday ", " Saturday "];
exports . name = function ( number ) {
return names [ number ];
};
exports . number = function ( name ) {
return names . indexOf ( name ) ;
};
```
this one i mean
i can see the function constructor is creating a function and taking the exports object as it's argument.
however since this code is not returning anything explicitly, is it just modifying the exports object in the outer scope
Stephen James
@sjames1958gm
Aug 23 2017 14:09

@abhinav-thinktank When code is called, it has one parameter exports
So code looks like

function code(exports) {
  var names = [" Sunday " , " Monday " , " Tuesday ", " Wednesday ",
  " Thursday " , " Friday ", " Saturday "];
  exports . name = function ( number ) {
    return names [ number ];
  };
  exports . number = function ( name ) {
    return names . indexOf ( name ) ;
  };
}

so you are calling

code(exports);

so the exports object is updated by the function

Abhinav Mishra
@abhinav-m
Aug 23 2017 14:09
ok.
so i dont need to return the object explicitly right ? since it is also wrapped by the require function
i mean something like
Stephen James
@sjames1958gm
Aug 23 2017 14:10
The object is updated because you pass a reference, so no return is needed
Abhinav Mishra
@abhinav-m
Aug 23 2017 14:10
ok, @sjames1958gm ty.
CamperBot
@camperbot
Aug 23 2017 14:10
abhinav-thinktank sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8369 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 23 2017 14:11
@abhinav-thinktank :+1:
Alaa H. Youssef
@alaahamdyy26
Aug 23 2017 14:58
hii guys
i need help with this problem pls

function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
var result = [];
var srcKeys = Object.keys(source);

for (var x = 0; x < collection.length; x++) {
    for (var y = 0; y < srcKeys.length; y++) {

        if (collection[x].hasOwnProperty(srcKeys[y]) && collection[x][srcKeys[y]] === source[srcKeys[y]]) {

          arr.push(collection[x]);

        }


              }
            }
        return arr;

}

whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 });
it works for some test cases and others not
and i'm not sure what is wrong :@
Stephen James
@sjames1958gm
Aug 23 2017 15:00
@alaahamdyy26 You cannot push collection[x] until you have checked all the srcKeys
in this case you only check "a" before you push
Alaa H. Youssef
@alaahamdyy26
Aug 23 2017 15:01
@sjames1958gm ufff right!!!
will try to solve again
Keone Martin
@Athaman
Aug 23 2017 15:01
:+1:
Alaa H. Youssef
@alaahamdyy26
Aug 23 2017 15:01
thanks
Stephen James
@sjames1958gm
Aug 23 2017 15:01
@alaahamdyy26 :+1:
Alaa H. Youssef
@alaahamdyy26
Aug 23 2017 15:11
ok I really cant get it :/
i'm looping on both arguments but i dont know how to set that rule!!
Keone Martin
@Athaman
Aug 23 2017 15:12
what have you got now?
Alaa H. Youssef
@alaahamdyy26
Aug 23 2017 15:13
same

function whatIsInAName(collection, source) {
// What's in a name?
var arr = [];
var result = [];
var srcKeys = Object.keys(source);

for (var x = 0; x < collection.length; x++) {
    for (var y = 0; y < srcKeys.length; y++) {


          if (source[srcKeys[y]]== collection[x][srcKeys[y]]) {
             if (collection[x].hasOwnProperty(srcKeys[y]) ){

          arr.push(collection[x]);

        }
                                                      }

    }         

            }
        return arr;

}

whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 });
Keone Martin
@Athaman
Aug 23 2017 15:13
it's been a long time since i've done any of these things.
Moisés Man
@moigithub
Aug 23 2017 15:13
u "pushing" too soon
Alaa H. Youssef
@alaahamdyy26
Aug 23 2017 15:14
yes, i got the problem but i dont know how to solve it
Stephen James
@sjames1958gm
Aug 23 2017 15:14
@alaahamdyy26 You can set a variable true before the inner loop and false inside the loop if mismatch.
push only after the loop if variable is still true
Keone Martin
@Athaman
Aug 23 2017 15:14
i think you probably want to have the push be outside of the second for loop right?
Moisés Man
@moigithub
Aug 23 2017 15:14
u could use a "flag" or a counter
or use .every array method
Marc
@MWBauer
Aug 23 2017 15:15
I have a questiong about str.length used in a for loop.
Stephen James
@sjames1958gm
Aug 23 2017 15:15
var good = true
For each srcKey if mismatch good = false
if (good) push
@MWBauer ask away
Marc
@MWBauer
Aug 23 2017 15:15
HIya' Stephen James.
I was working on the longest word problem. I was thinking about using a For loop to step thru the array and have it run the str.length on each index of the array.
Is that possible?
for (var i = 0; i <= splitArray.length; i++) {
var strLength = .length;
Keone Martin
@Athaman
Aug 23 2017 15:18
you'd need splitArray[i].length; on the right hand side of the equal
Marc
@MWBauer
Aug 23 2017 15:18
If it is possible, would I use ....ooohhhh...thank you
that's where I was going.
Keone Martin
@Athaman
Aug 23 2017 15:18
that will save each words length as strLength as you go through... then you can store the largest one and if it's bigger than that you can replace it :)
Marc
@MWBauer
Aug 23 2017 15:19
I would need to run a comparison of each iteration, right?
If iteration 1 is larger than 2, keep 1. if iteration 1 is larger than iteration 3 keep.
Keone Martin
@Athaman
Aug 23 2017 15:20
yup
Marc
@MWBauer
Aug 23 2017 15:20
Ok. being the newb I'm thinking another For loop.
is there a simpler way?
Keone Martin
@Athaman
Aug 23 2017 15:21
you won't need another loop, it can be a direct comparison
can you show me the full code of what you're thinking? it'll give me a better idea of how you're going about the over all problem
Marc
@MWBauer
Aug 23 2017 15:22
function findLongestWord(str) {
var splitArray = str.split(" ");
//variable splitArray takes the str and splits it at each space and creates an array of words
var splitStr = "";
for (var i = 0; i <= splitArray.length; i++) {
var strLength = splitArray[i].length;
currently this is what I have.
Keone Martin
@Athaman
Aug 23 2017 15:22
function findLongestWord(str) {
  var splitArray = str.split(" ");
  //variable splitArray takes the str and splits it at each space and creates an array of words
  var splitStr = "";
  for (var i = 0; i <= splitArray.length; i++) {
    var strLength = splitArray[i].length;
Marc
@MWBauer
Aug 23 2017 15:23
How does your's come up in color?
what am I doing wrong?
Keone Martin
@Athaman
Aug 23 2017 15:23
if you put 3 back ticks at the top and the bottom it formats it
Marc
@MWBauer
Aug 23 2017 15:23
oy
th
thx
Keone Martin
@Athaman
Aug 23 2017 15:23
(backtick is under the tilde on the us keyboard, left of 1)
Marc
@MWBauer
Aug 23 2017 15:23
yeah
Keone Martin
@Athaman
Aug 23 2017 15:24
ok, you're looking pretty good in general. your var splitStr = "";
Marc
@MWBauer
Aug 23 2017 15:24
I'm trying to remember how to run just a (a<b) comparison
Keone Martin
@Athaman
Aug 23 2017 15:24
what are you planning to do with that?
if ( a < b) {
  //do things
}
Marc
@MWBauer
Aug 23 2017 15:25
(shrug) I'm at a loss. That was a couple of days ago.
Keone Martin
@Athaman
Aug 23 2017 15:25
:) fair enough
Marc
@MWBauer
Aug 23 2017 15:25
I didn't put a note on it so ....?
I will remove it
Keone Martin
@Athaman
Aug 23 2017 15:25
yeah, i would suggest replacing it with something that you can use to keep track of the current longest string
Marc
@MWBauer
Aug 23 2017 15:28
Something that will hold the longest string once it's found? give me a small clue how that would start.
Keone Martin
@Athaman
Aug 23 2017 15:28
and then was you go through your for loop that you have set up, you can then compare its length to the strLength value, if the strLength is longer then replace your word
Marc
@MWBauer
Aug 23 2017 15:28
if splitStr > splitArray[I]
?
Joseph
@revisualize
Aug 23 2017 15:29
hey.
Keone Martin
@Athaman
Aug 23 2017 15:29
well if it starts off as an empty string, then the first strLength will be longer than "".length ... so you'd overwrite "" with splitArray[0]... then check if splitArray[1] is greater than that value
yeah, basically... but rename splitStr to something like 'longestWord' or whatever you feel like, but something more relevant to what the variable is doing ;)
Jason Luboff
@JLuboff
Aug 23 2017 15:30
@revisualize Morning\
Joseph
@revisualize
Aug 23 2017 15:31
@JLuboff How's work for you today?
Jason Luboff
@JLuboff
Aug 23 2017 15:32
@revisualize Eh, just starting really. Watching some MS virtual academy videos and working on my stock chart app. Been a relatively slow week so far. You?
Joseph
@revisualize
Aug 23 2017 15:33
@JLuboff I'm on a bus. 32hrs of PTO
:D
Jason Luboff
@JLuboff
Aug 23 2017 15:33
@revisualize Nice, where are you off to?
Joseph
@revisualize
Aug 23 2017 15:34
@JLuboff No where exciting. :(
Jason Luboff
@JLuboff
Aug 23 2017 15:34
Its only not exciting if you don't make it exciting!
Joseph
@revisualize
Aug 23 2017 15:35
@JLuboff I haven't seen/spoken to my dad in 21 years. I don't even know where he lives. But, I know where my uncle lives. So. I'm on a trip.
Jason Luboff
@JLuboff
Aug 23 2017 15:36
@revisualize Ah. I wish you the best of luck, I can see why you'd say its not exciting, but thats a big step to take
Joseph
@revisualize
Aug 23 2017 15:37
@JLuboff Yeah. It's down in the same area my sister is getting married in. So, I took an extra couple of days ahead of the wedding.
Jason Luboff
@JLuboff
Aug 23 2017 15:37
Well hey, the wedding should be exciting though!
Joseph
@revisualize
Aug 23 2017 15:38
Yeah. But, not really this first part.
hehe.
I'm in for a trip.
Jason Luboff
@JLuboff
Aug 23 2017 15:38
That you are
Joseph
@revisualize
Aug 23 2017 15:39
I'm going to look at trying to create some projects and complete some Pluralsight on this trip too.
At least then I can make it worth it.
Jason Luboff
@JLuboff
Aug 23 2017 15:40
Thats a good idea
Joseph
@revisualize
Aug 23 2017 15:49
okay. I'm going to get off of my laptop to save the juice.
:v:
Jason Luboff
@JLuboff
Aug 23 2017 15:49
See ya
Ahmed raza
@Raza403
Aug 23 2017 15:57
Hi I need little help, My code of random quote generator is working on my local xampp server but not working on codepen, Here is the link https://codepen.io/raza403/pen/NvXLqL
Jason Luboff
@JLuboff
Aug 23 2017 16:00
@Raza403 Its working fine for me?
Ahmed raza
@Raza403
Aug 23 2017 16:00
Working now I just did not added jquery in js tab
Thanks for looking at it
Jason Luboff
@JLuboff
Aug 23 2017 16:01
blob
Ah. That'll do it
Ahmed raza
@Raza403
Aug 23 2017 16:01
I don't have much experience of using code pen..
I made it using scss can you have a look at css file and suggest me if I did something wrong , If you have some experience. It's my first time using SASS.
Jason Luboff
@JLuboff
Aug 23 2017 16:03
I don't have any experience with SASS, sorry
Ahmed raza
@Raza403
Aug 23 2017 16:04
Ok No problem.... and thanks
alpox
@alpox
Aug 23 2017 16:14
@Raza403 Well my two cents: Please don't put the whole bootstrap css in the css part of codepen :D You can use Settings->CSS for that
Just put there the cdn link to the bootstrap css
John
@AnonymousLords
Aug 23 2017 16:53
factorialize(269) gives you 4.2690680090047027e+304 :O
:P
Mark Kubik
@KUBIX90
Aug 23 2017 16:57
function rot13(str) {

    var array = [];

  for(var i = 0; i < str.length; i++ ){

      if (str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 77){
            array.push(str.charCodeAt(i)+13);} else if
         (str.charCodeAt(i) >= 78 && str.charCodeAt(i) <= 90){
            array.push(str.charCodeAt(i)-13);} else
            {array.push(str.charCodeAt(i));}
    }

    return array;

}

// Change the inputs below to test
rot13("AJFJF NDF KJN");
Christopher McCormack
@cmccormack
Aug 23 2017 16:57
@KUBIX90 don't push the char code to the array, just the letter
or push the char code and convert back at the end
Mark Kubik
@KUBIX90
Aug 23 2017 16:58
I have the array of coded numbers, but i cannot seem to convert them back to letters
I can get "fromCharCode " method to work
Christopher McCormack
@cmccormack
Aug 23 2017 16:59
@KUBIX90
> String.fromCharCode(70)
'F'
Mark Kubik
@KUBIX90
Aug 23 2017 16:59
@cmccormack Yeah my plan was to convert i back at the end but struggling with this part
Christopher McCormack
@cmccormack
Aug 23 2017 16:59
@KUBIX90 are you using it as a String method?
Mark Kubik
@KUBIX90
Aug 23 2017 17:00
String.fromCharCode(array) is what I used
Christopher McCormack
@cmccormack
Aug 23 2017 17:00
@KUBIX90 use the method when you push onto the array
or use map at the end
Mark Kubik
@KUBIX90
Aug 23 2017 17:03
@cmccormack Thanks I'll give this a go
CamperBot
@camperbot
Aug 23 2017 17:03
kubix90 sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1162 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Aug 23 2017 17:03
np gl
Stephen James
@sjames1958gm
Aug 23 2017 17:06
@KUBIX90 You 7 calls to the same function with the same values.
var code = str.charCodeAt(i);
then simply use code in the comparisons.
Then you can adjust code +/- 13 or not at all and push after the if (only one push)
} else if putting this at the end of the line is not an accepted style.
Jen
@jenniredfield
Aug 23 2017 17:24
Hi guys im stuck on wikipedia viewer challenge
because this request doesnt work?
cross domain blocking
did anyone figure a way round?
Gulsvi
@gulsvi
Aug 23 2017 17:28
@jenniredfield Add &origin=* anywhere in your URL after action=query. https://stackoverflow.com/a/38921370
AysunShack
@AysunShack
Aug 23 2017 17:33
can someone please explain something quick for the palindrom algorithm?
function palindrome(str) {
str = str.toLowerCase().replace(/[\W_]/g, '');
for(var i = 0, len = str.length - 1; i < len/2; i++) {
if(str[i] !== str[len-i]) {
return false;
}
}
return true;
}
Stephen James
@sjames1958gm
Aug 23 2017 17:33
@AysunShack What?
AysunShack
@AysunShack
Aug 23 2017 17:34
how does "len = str.length -1" reiterates backwards
when i = 3
why len should be str.length - 3 ?
I mean it should be like that, but I don't see how this works
Stephen James
@sjames1958gm
Aug 23 2017 17:34
when i is three len will be str.length - 4
AysunShack
@AysunShack
Aug 23 2017 17:34
how?
Stephen James
@sjames1958gm
Aug 23 2017 17:35
if the string length is 5 then the last letter is str[4] or str[str.length - 1]
Here len - i is going down at the same rate as i is going up
AysunShack
@AysunShack
Aug 23 2017 17:35
yea
and you compare first letter with last
then second letter with last again
there is no str.length - 2
Stephen James
@sjames1958gm
Aug 23 2017 17:36
@AysunShack str[len-i] len minus i not just len
len - i when i is 1 is str.length - 2
AysunShack
@AysunShack
Aug 23 2017 17:36
ah damn
got it
thank you @sjames1958gm
CamperBot
@camperbot
Aug 23 2017 17:36
aysunshack sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8370 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 23 2017 17:36
You could have done len-- in the for loop and just use len in the if
for(var i = 0, len = str.length - 1; i < len/2; i++, len--) {
if(str[i] !== str[len]) {
I would have done it the len-- way as the other way can be confusing as you saw
AysunShack
@AysunShack
Aug 23 2017 17:37
yea definitely, I almost got the challenge by myself, couldn't figure out why the solution was like this
I didn't know you can put two variables in a for and itterate them differently
thanks!
Stephen James
@sjames1958gm
Aug 23 2017 17:43
@AysunShack :) Now you know! :)
Jen
@jenniredfield
Aug 23 2017 17:51
thanks @sjames1958gm
CamperBot
@camperbot
Aug 23 2017 17:51
jenniredfield sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8371 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Jen
@jenniredfield
Aug 23 2017 17:51
thanks @SkyC0der
CamperBot
@camperbot
Aug 23 2017 17:51
jenniredfield sends brownie points to @skyc0der :sparkles: :thumbsup: :sparkles:
:star2: 2545 | @skyc0der |http://www.freecodecamp.com/skyc0der
Stephen James
@sjames1958gm
Aug 23 2017 17:51
@jenniredfield :+1:
Jason Luboff
@JLuboff
Aug 23 2017 17:57
Think I've completed my Stock Chart App: https://stockapp-jluboff.glitch.me/
Mark Kubik
@KUBIX90
Aug 23 2017 18:00
function rot13(str) {

    var array = [];

  for(var i = 0; i < str.length; i++ ){

    var code = str.charCodeAt(i);

      if (code >= 65 && code <= 77){array.push(String.fromCharCode(code +13));}
      if(code >= 78 && code <= 90){array.push(String.fromCharCode(code -13));}
      else {array.push(String.fromCharCode(code));}
    }

    return array.join("");

}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
@sjames1958gm Is that what you meant? I can't seem to get the +- 13 as one command. The function is also returning as FREEE COBDE CAMPC for some reason.
Stephen James
@sjames1958gm
Aug 23 2017 18:03
Yes the +/- was meant to refer to the if / else if (sorry for that confusion).
@KUBIX90 You need an else if or you will do the last else every time even when the first if is true
I would even reduce the number of fromCharCodes to 1 by extracting that out to the end
var code = code = str.charCodeAt(i);
if (test for 65 to 77) {
  code += 13
} else if (test for 78 to 90) {
  code -= 13
}
array.push(String.fromCharCode(code))
Mark Kubik
@KUBIX90
Aug 23 2017 18:10
@sjames1958gm HWat did you mean when you said that else ifwas not an accepted style, did you just mean you can't put it in the way I initially did? IS the below a more accepted style
function rot13(str) {

    var array = [];

  for(var i = 0; i < str.length; i++ ){

    var code = str.charCodeAt(i);

      if (code >= 65 && code <= 77){array.push(String.fromCharCode(code +13));}
      else if(code >= 78 && code <= 90){array.push(String.fromCharCode(code -13));}
      else {array.push(String.fromCharCode(code));}
    }

    return array.join("");

}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Stephen James
@sjames1958gm
Aug 23 2017 18:10
@KUBIX90 more accepted style, it is allowed by the language.
Mark Kubik
@KUBIX90
Aug 23 2017 18:14
@sjames1958gm I see, thanks for your help. In your code example, are you using ECMAscript 6 or 2015? Haven't come across "test for" and "to" is all.
marcus dylan johnson
@mdjohns
Aug 23 2017 18:14
Working on the Chunky Monkey challenge(https://www.freecodecamp.com/challenges/chunky-monkey) today. For some reason having a hard time wrapping my head around getting .slice() and .push() working inside this loop. I put it in pseudo code to try to work through it.
function chunkArrayInGroups(arr, size){
    var chunkyArr = [];
    for(var i = 0; i < arr.length; i++){
        slice every group of 2 from arr and push to 
        chunkyArr;
    }
}

chunkArrayInGroups(["a","b","c","d"], 2);
Stephen James
@sjames1958gm
Aug 23 2017 18:15
@KUBIX90 That is pseudo code - just so I didn't write out all those conditions - not javascript at all
Mark Kubik
@KUBIX90
Aug 23 2017 18:15
@sjames1958gm Ah fine, fair enough. Appreciate the help.
Stephen James
@sjames1958gm
Aug 23 2017 18:15
@djohnson501 separate the slice and push into two operations
@djohnson501 get the slice into a variable
then push the variable to the array.
@djohnson501 Consider that your loop will run arr.length times but are there that many chunks?
marcus dylan johnson
@mdjohns
Aug 23 2017 18:22
@sjames1958gm Ah, that makes sense. Didn’t think about storing the slice in a variable.
Stephen James
@sjames1958gm
Aug 23 2017 18:22
@djohnson501 If it makes it easier for you to visualize.
marcus dylan johnson
@mdjohns
Aug 23 2017 18:25
@sjames1958gm and that fixes my loop problem. So now I’ve got the loop running the correct number of times, and .push() is working correctly. I’ve got to figure out how to get slice to move through the array.
function chunkArrayInGroups(arr, size){
    var chunkyArr = [];
    for(var i = 0; i < num; i++){
        var slicer = arr.slice();
        chunkyArr.push(slicer);
    }
    return chunkyArr;
}
console.log(chunkArrayInGroups(["a","b","c","d"], 2));
Stephen James
@sjames1958gm
Aug 23 2017 18:26
@djohnson501 hmm, where does num come from?
Check the docs on slice what the parameters mean, and write down what the correct slice parameters are for the chunks
without the loop, just
slice(0, size) is the first slice
slice(?, ? ) is the second slice
then find a pattern that can be converted into a loop
marcus dylan johnson
@mdjohns
Aug 23 2017 18:29
@sjames1958gm num should be size. I don’t know why I keep typing that haha.
Stephen James
@sjames1958gm
Aug 23 2017 18:33
@djohnson501 the number of loops needs to depend on both size and arr.length, yes?
JROD81
@JROD81
Aug 23 2017 19:05
@djohnson501 : Hey Im new to the gitter thing.... how do you display your code like your doing?
Christopher McCormack
@cmccormack
Aug 23 2017 19:07
@JROD81
```
code
```
@JROD81 backticks should be on their own line
LiciniusRex
@hashtagyolo1
Aug 23 2017 19:08
They're on the tilde key in the top left for me on UK keyboard layout
JROD81
@JROD81
Aug 23 2017 19:13
Im in the "Return Largest Numbers in Array'' and I seem to get the right numbers back but instead of only one Im getting the amount of times its looping thru. I know my answer is simple but I feel like Im over thinking it.
function largestOfFour(arr) {
  var newArr = [];
  for(var i = 0; i < arr.length; i++){ 
     var arrCopy = arr[i];
        for(var j = 0; j < arrCopy.length; j++){
            var arrCopy2 = arrCopy;
             newArr.push(Math.max.apply(null, arrCopy2));
        }
    }
    return newArr;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Moisés Man
@moigithub
Aug 23 2017 19:15
if use Math.max.apply u only need 1 loop
Diego Mayer
@Chrono79
Aug 23 2017 19:19
@JROD81 var arrCopy = arr[i]; that's not a copy, that's another reference to the same array
If you change arrCopy, you'd be changing arr[i] too
Not a problem here, I'm just pointing it out for future reference ;)
JROD81
@JROD81
Aug 23 2017 19:26
@Chrono79 Thank you for the advice.
CamperBot
@camperbot
Aug 23 2017 19:26
jrod81 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4527 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Aug 23 2017 19:28
If you want a copy of a simple array (that has numbers, strings or booleans) you can use .slice()
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
:+1:
JROD81
@JROD81
Aug 23 2017 19:33
@moigithub Hey appreciate the advice...worked nicely! Ive been on this one for 5 days.
nubian16
@nubian16
Aug 23 2017 19:50
Could anyone tell me why the last $.post is not returning any information in the Console log? Much appreciated in advance
//defining the IDs inside body

var y = document.getElementById("Latitude");
var z = document.getElementById("Longitude");
var results1 = document.getElementById("City");
var results2 = document.getElementById("Weather");
console.log(results1.innerHTML);
console.log(results2.innerHTML);
//-------------------------------------------------

function getLocation() {
  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(positionValue);
  } else {
    x.innerHTML = "Geolocation is not supported by this browser.";
  }
}
//-------------------------------------------------

// Aquiring the LONGITUDE AND LATTITUDE THEN REVERSE GEOCODING

function positionValue(location) {
  y = location.coords.latitude;
  z = location.coords.longitude;

  // REVERSE GEOCODING for city name
  var cityUrl =
    "https://maps.googleapis.com/maps/api/geocode/json?latlng=" +
    y +
    "," +
    z +
    "&key=AIzaSyBzEmbFtdyy7QliLJM75nDQ1kjPqFgH0z4";

  $.post(cityUrl, function returnCity(data) {
    results1.innerHTML = data.results[1].address_components[1].short_name;
    console.log(results1.innerHTML);
  });

  //Obtaining weather information

  var weatherUrl =
    "api.openweathermap.org/data/2.5/weather?lat=" +
    y +
    "&lon=" +
    z +
    "&APPID=ace612d4c847454abd65f2f4a9b4bb27";

  $.post(weatherUrl, function returnWeather(place) {
    results2.innerHTML = place.weather[1];
    console.log(place.weather[1]);
  });


}

//-------------------------------------------------
CamperBot
@camperbot
Aug 23 2017 19:50
:bulb: to format code use backticks! ``` more info
Darshan
@Dave1089
Aug 23 2017 19:50
Can anyone explain whats going on in this arrow function?
keys.forEach(key => key.addEventListener('transitionend', removeTransition));
Gulsvi
@gulsvi
Aug 23 2017 19:55

@Dave1089

keys.forEach(function (key) {
  return key.addEventListener('transitionend', removeTransition);
});

for each element represented by the keys variable, add an event listener for the transitionend event. When that event fires, call the removeTransition() function.

Diego Mayer
@Chrono79
Aug 23 2017 19:55
@nubian16 both $.post calls are asynchronous, nobody can guaratee you'll get y and z of the first one before you do the second like that
Darshan
@Dave1089
Aug 23 2017 19:56
@SkyC0der it was simple..thanks :)
CamperBot
@camperbot
Aug 23 2017 19:56
dave1089 sends brownie points to @skyc0der :sparkles: :thumbsup: :sparkles:
:star2: 2546 | @skyc0der |http://www.freecodecamp.com/skyc0der
Diego Mayer
@Chrono79
Aug 23 2017 19:58
@nubian16 try looking at developer tools, maybe it's a matter of adding https:// at the front of weatherUrl
Also, you should see if the api uses get or post
nubian16
@nubian16
Aug 23 2017 20:00
@Chrono79 if place the link directly on the website it will load...... WAIT>>>!!!
@Chrono79 you are awsome without exception such an easy fix
@Chrono79 Thank you!
CamperBot
@camperbot
Aug 23 2017 20:01
nubian16 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4528 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Aug 23 2017 20:01
no problem
James Dimitrakopoulos
@JamesDimi
Aug 23 2017 20:35
can someone help understand something in js please?
Ronique Ricketts
@RoniqueRicketts
Aug 23 2017 20:35
@JamesDimi what is the problem
Kelechi Chinaka
@ke1echi
Aug 23 2017 20:37
i have a question about scope and closure
i cant understand the "passing along arguements" section

"If f takes more than one parameter, it gets only the first one. We could add a bunch of arguments to the inner function (arg1, arg2, and so on) and pass them all to f, but it is not clear how many would be enough. This solution would also deprive f of the information in arguments.length. Since we’d always pass the same number of arguments, it wouldn’t know how many arguments were originally given.

For these kinds of situations, JavaScript functions have an apply method. You pass it an array (or array-like object) of arguments, and it will call the function with those arguments."

this part got me a headache
Kelechi Chinaka
@ke1echi
Aug 23 2017 20:39
function createFunctions(n) {
  var callbacks = [];
  for (var i = 0; i < n; i++) {
    callbacks.push(function() {
      return i;
    });
  }
  return callbacks;
}
function createFunctions(n) {
  var callbacks = [];
  for (let i = 0; i < n; i++) {
    callbacks.push(function() {
      return i;
    });
  }
  return callbacks;
}
whats the diff between this snippet..what does the let keyword solve
James Dimitrakopoulos
@JamesDimi
Aug 23 2017 20:41
when you define a "var" variable the "i" can be used outside of the for but inside of the function createFunctions
if you use "let" i is only visible inside the for, and if you try to print "i" after the for, youll get undefined
Kelechi Chinaka
@ke1echi
Aug 23 2017 20:44
am aware of that
Pethaf
@Pethaf
Aug 23 2017 20:46
@JamesDimi It's called "Hoisting".
James Dimitrakopoulos
@JamesDimi
Aug 23 2017 20:47
@Pethaf hi my friend :D You mean hoisting is what is explained in the queston i asked?
Pethaf
@Pethaf
Aug 23 2017 20:48
No, why variables declared with var are accesible when a for loop has terminated.
Variables declared with var are "hoisted" to the top.
Variables declared with let aren't.
But to return to your original question.
Stuhl
@Stuhl
Aug 23 2017 20:48
thats not entirely correct, let is block scoped, var is function scoped
Cuz the for loop is a block of code, the let variable is only available in there
hoisting is not always done for var
Pethaf
@Pethaf
Aug 23 2017 20:49
Are you talking about this section? function transparentWrapping(f) { return function() { return f.apply(null, arguments); }; }
Marlon
@borgatajunky
Aug 23 2017 20:50

Function accum (s){
Var split = s.split("");

 For(let i = 0; i < split.length; i++){
     Split[i] += split[i];
 }
 Return split;

}

How can I adjust above code to add one every iteration.
Example A -Bb - Ccc- Dddd etc

Diego Mayer
@Chrono79
Aug 23 2017 20:50

@kelechy

function createFunctions(n) {
  var callbacks = [];
  for (var i = 0; i < n; i++) {
    (function(){
      var j = i;
      callbacks.push(function() {
        return j;
      });
    })();
  }
  return callbacks;
}

You can use IIFE instead of let

James Dimitrakopoulos
@JamesDimi
Aug 23 2017 20:51
@Pethaf i dont undersand what he means when he says " We could add a bunch of arguments to the inner function (arg1, arg2, and so on) and pass them all to f, but it is not clear how many would be enough. This solution would also deprive f of the information in arguments.length. Since we’d always pass the same number of arguments, it wouldn’t know how many arguments were originally given."
Pethaf
@Pethaf
Aug 23 2017 20:52
@JamesDimi is it in this example? function transparentWrapping(f) { return function() { return f.apply(null, arguments); }; } ?
James Dimitrakopoulos
@JamesDimi
Aug 23 2017 20:52
yeah
Pethaf
@Pethaf
Aug 23 2017 20:52
Do you understand what the arguments parameter refers to?
Diego Mayer
@Chrono79
Aug 23 2017 20:53
@borgatajunky what are you trying to do exactly? mind capitalization there
James Dimitrakopoulos
@JamesDimi
Aug 23 2017 20:53
@Pethaf hmmm no
So it is an array like object containing all the arguments passed to a function.
Kelechi Chinaka
@ke1echi
Aug 23 2017 20:56
passes all test with let, solves the scope and closure issue... IIFE also cool idea @Chrono79
James Dimitrakopoulos
@JamesDimi
Aug 23 2017 20:57
okay
Pethaf
@Pethaf
Aug 23 2017 20:59
You can try doing something like tmp = function() {console.log(arguments); }
And then calling tmp with different arguments.
James Dimitrakopoulos
@JamesDimi
Aug 23 2017 21:00
@Pethaf okay thanks man, ill try it
CamperBot
@camperbot
Aug 23 2017 21:00
jamesdimi sends brownie points to @pethaf :sparkles: :thumbsup: :sparkles:
:cookie: 391 | @pethaf |http://www.freecodecamp.com/pethaf
Pethaf
@Pethaf
Aug 23 2017 21:02
What the author has defined is a function with an inner function.
The outer function takes a function, and then returns a function that will run the function that was supplied to the outer function.
Pethaf
@Pethaf
Aug 23 2017 21:12
Hmm wonder if one can do const tmp = () => console.log(arguments);
Diego Mayer
@Chrono79
Aug 23 2017 21:13
@Pethaf no, you can't
Pethaf
@Pethaf
Aug 23 2017 21:15
I just found out that you can't.
Conor Murphy
@cmurphy580
Aug 23 2017 21:28
how do i get my javascript to work for safari browsers?
Conor Murphy
@cmurphy580
Aug 23 2017 21:33
@Chrono79 looks like it will thanks for the help
CamperBot
@camperbot
Aug 23 2017 21:33
cmurphy580 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4529 | @chrono79 |http://www.freecodecamp.com/chrono79
Netrunner21
@Netrunner21
Aug 23 2017 22:14
@Pethaf I've been doing this freecodecamp thing for a while now and I just learned about hoisting a few days ago. Losts of things going on under the hood.
luccifer00
@luccifer00
Aug 23 2017 22:19
hi! i habe a silly problema with the twitchTV, i am setting the buttons of the Online, Offline filter... but should be wrong, but i dont know why....
$('#green').click(function(){
 var x=  document.querySelectorAll('.off-line');
 var y= document.querySelectorAll('.pet');
     for (var j=0; j<x.length;j++){
 y[j].style = "display: none";
      } //end for loop
the problem is not all the elements with the class off-line are not displayed... the loops stops when he founds an on-line user...
here is the codepen if someone can take a look
Slitherings
@Slitherings
Aug 23 2017 22:32
Whats up guys
Fernando
@lestairon
Aug 23 2017 22:33

function titleCase(str) {
  var newStr = str.toLowerCase().split(" ");
  for (i = 0; i < newStr.length; i++) {
    newStr[i].replace(/^/g, newStr.charAt(0).toUpperCase());
  }
  return newStr;
}

titleCase("I'm a little tea pot");
I don't know what am I doing wrong :l
Christopher McCormack
@cmccormack
Aug 23 2017 22:34
@lestairon replace only returns a string but doesn't modify a string in place, strings are immutable. You'll need to assign the results of replace to the array index
Slitherings
@Slitherings
Aug 23 2017 22:36

Filter Arrays with filter

var oldArray = [1,2,3,4,5,6,7,8,9,10];

// Only change code below this line.
var newArray = oldArray.filter(function(val){
  return val <= 5;
});
oldArray = newArray;

Challenge: You should not change the original array.
For some reason its telling me i shouldn't change the original array but i haven't touched the top part of the code at all.

Margaret
@Margaret2
Aug 23 2017 22:37
@Slitherings the line oldArray = newArray; redefines oldArray, so you are changing it
Slitherings
@Slitherings
Aug 23 2017 22:37
but without that
it wont display the less than 5 vals it just displays the whole array.
Margaret
@Margaret2
Aug 23 2017 22:38
it works fine for me, try resetting and doing it over
Slitherings
@Slitherings
Aug 23 2017 22:39
man..
this sucks
Christopher McCormack
@cmccormack
Aug 23 2017 22:44
@Slitherings did that work? what did you have prior to adding oldArray = newArray;?
Slitherings
@Slitherings
Aug 23 2017 22:45
it just comes up in the console
You should not change the original array.
wait
oops
[1,2,3,4,5,6,7,8,9,10];
that just pops up in the console
Christopher McCormack
@cmccormack
Aug 23 2017 22:49
@Slitherings show your code
Slitherings
@Slitherings
Aug 23 2017 22:49

var oldArray = [1,2,3,4,5,6,7,8,9,10];

// Only change code below this line.
var newArray = oldArray.filter(function(val){
  return val <= 5;
});
newArray = oldArray;
Christopher McCormack
@cmccormack
Aug 23 2017 22:49
get rid of that last line
why are you doing that?
Slitherings
@Slitherings
Aug 23 2017 22:50
hahah
the last challenge before that
there was a line like that and i thought it was important
Christopher McCormack
@cmccormack
Aug 23 2017 22:50
important if you want to blow away the work you did in the previous filter :)
you're basically doing all that filtering work, then changing the reference for newArray back to oldArray
Slitherings
@Slitherings
Aug 23 2017 22:51
oooohh
@cmccormack thanks man haah
CamperBot
@camperbot
Aug 23 2017 22:51
slitherings sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1166 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Aug 23 2017 22:51
@Slitherings np
Slitherings
@Slitherings
Aug 23 2017 22:51
sometimes the code starts geting repetitve at one point
im learning how to mess with arrays and stuff, but im kind of wondering what are some real life things i would actually use this array code for?
like do companies and stuff use arrays? haha
Christopher McCormack
@cmccormack
Aug 23 2017 22:58
@Slitherings yeah arrays are a pretty standard way to store and access data. Most JSON files are either arrays or contain a property with an array that stores lots of objects, and you can iterate over that array or access by indexes
Slitherings
@Slitherings
Aug 23 2017 23:09
@cmccormack so the way they store information is through arrays or numbers? haha its confusing for me because im like a really simple person and not very smart when it comes to academics.
Christopher McCormack
@cmccormack
Aug 23 2017 23:13
Take a look at this JSON file - https://mackville.net/quotes/csquotes.json. All of the quotes and their authors are stored in an object ( notice the curly braces { }), while each of the objects is stored in one large array, each seperated by a comma. You can then use array methods like filter, reduce, map, and forEach to iterate over this array and do some work. You can also point to specific entries in arrays using their position (index), starting with 0 and ending with array.length-1.
Slitherings
@Slitherings
Aug 23 2017 23:14
oo okay
Christopher McCormack
@cmccormack
Aug 23 2017 23:14
The more you work with them the easier they will be to understand
cmccormack @cmccormack has to run, sorry
Stephen James
@sjames1958gm
Aug 23 2017 23:30
@Slitherings Any sort of list will likely be stored in an array.
@Slitherings If you think about it a deck of cards is an array. The drawers in your dresser are an array. Etc.
Slitherings
@Slitherings
Aug 23 2017 23:44
why not just make a list of strings?? haha