These are chat archives for FreeCodeCamp/HelpJavaScript

12th
Jul 2017
Christopher McCormack
@cmccormack
Jul 12 2017 00:01
@Rushh which test
Luis
@zdrifted
Jul 12 2017 00:03
It's not showing me the test. I'm thinking I need to make both numbers positive and append the negative sign afterwards if num1 was a negative number
Or maybe it's an issue with how I'm using .ceil or .floor
Christopher McCormack
@cmccormack
Jul 12 2017 00:05
what if num2 < 0?
Luis
@zdrifted
Jul 12 2017 00:06
It should still return the sign of num1 since that is how the modulo/remainder operator works in JavaScript
Christopher McCormack
@cmccormack
Jul 12 2017 00:06
ah ok
I really want to suggest you do this a much easier way, but I also see you've done a bunch of work and would like you to succeed with what you have :D
but I would suggest you create a boat load of tests with answers you are sure are correct then test it against your code
Luis
@zdrifted
Jul 12 2017 00:09
I don't mind lol. Which way would be easier?
I definitely feel like I'm overthinking this
LeSean Johnson
@leseanbiz
Jul 12 2017 00:11
@cmccormack ha! to hell with readability, right?
Christopher McCormack
@cmccormack
Jul 12 2017 00:12
@leseanbiz haha I can't read it and I wrote it! that's why it's not a good practice to string that much together on one line
@Rushh well, dividing is a lot like subtracting by the divisor a quotient-number of times until all that is left is the remainder < dividend.
And with that terrible explanation, I'm out of here to go help someone move :D good night all
Luis
@zdrifted
Jul 12 2017 00:17
Thanks @cmccormack I'll look into that after I finish my approach lol
CamperBot
@camperbot
Jul 12 2017 00:17
rushh sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1024 | @cmccormack |http://www.freecodecamp.com/cmccormack
Luis
@zdrifted
Jul 12 2017 00:22
Solved it! Wow that one was tough
Janelle deMent
@janelledement
Jul 12 2017 00:26
Get_Geo-location_Data___freeCodeCamp.png
Might anyone tell me what I'm doing wrong with my code? I'm on get geo-location data challenge.
Greg Duncan
@GregatGit
Jul 12 2017 00:28
@janelledement shouldnt the script be below - just before the closing of the body tag?
@janelledement i would use targetting closer <h4>You are here: <span id="data"><span></h4>
@janelledement <h4>You are here: lat - <span id="lat"><span> long - <span id="long"></span</h4>
Janelle deMent
@janelledement
Jul 12 2017 00:34
@GregatGit Good point! I'll try that....do you know if I'm using navigator.geolocation properly?
Greg Duncan
@GregatGit
Jul 12 2017 00:34
@janelledement are you doing this in code pen?
Elizabeth Paul
@Kowalatam
Jul 12 2017 00:34
@janelledement check spelling.. getCurrentPosition, not getCurretPosition
Janelle deMent
@janelledement
Jul 12 2017 00:35
@GregatGit No, it's a code challenge
Greg Duncan
@GregatGit
Jul 12 2017 00:35
@janelledement ok
Janelle deMent
@janelledement
Jul 12 2017 00:35
@Kowalatam Thanks, I didn't see that
CamperBot
@camperbot
Jul 12 2017 00:35
janelledement sends brownie points to @kowalatam :sparkles: :thumbsup: :sparkles:
:cookie: 269 | @kowalatam |http://www.freecodecamp.com/kowalatam
Janelle deMent
@janelledement
Jul 12 2017 00:36
@GregatGit Thanks Greg
CamperBot
@camperbot
Jul 12 2017 00:36
janelledement sends brownie points to @gregatgit :sparkles: :thumbsup: :sparkles:
:cookie: 874 | @gregatgit |http://www.freecodecamp.com/gregatgit
Elizabeth Paul
@Kowalatam
Jul 12 2017 00:37
@janelledement .. uwc :smile:
Pagnito
@Pagnito
Jul 12 2017 00:41
can someone tell me whats the diffirent between object.key = prop; vs object.defineProperty()?
CallMeOrange
@EgnaroDev
Jul 12 2017 00:44
They are small and big word!
Jeremy
@JeremyAntonoff
Jul 12 2017 00:47
can someone help withsimon
Netrunner21
@Netrunner21
Jul 12 2017 00:51
Hey man
@JToddFL I can help
I'm finishing up Simon now.
Jeremy
@JeremyAntonoff
Jul 12 2017 00:51
@Netrunner21 awesome
Joseph
@revisualize
Jul 12 2017 01:01
Hi.
aRtoo
@artoodeeto
Jul 12 2017 01:38
hello guys how can you create a border like on a text?? like change its color. make it thick. and googled it and it shows me text stroke but on the the example its a horizontal lines. any idea?
Yuserah Din
@YuserahN
Jul 12 2017 01:45
Hey, who here has completed the local weather app?
NicholasGalarza
@NicholasGalarza
Jul 12 2017 01:46
@YuserahN Me
Yuserah Din
@YuserahN
Jul 12 2017 01:46
Did you use an API from Dark Sky or openweather?
NicholasGalarza
@NicholasGalarza
Jul 12 2017 01:46
DarkSky
Yuserah Din
@YuserahN
Jul 12 2017 01:46
And your used HTML5 geolocation?
*you
NicholasGalarza
@NicholasGalarza
Jul 12 2017 01:47
Yes, HTML5
geolocation
Yuserah Din
@YuserahN
Jul 12 2017 01:49
Cool.
NicholasGalarza
@NicholasGalarza
Jul 12 2017 01:50
@YuserahN Hopefully it helps!
Yuserah Din
@YuserahN
Jul 12 2017 01:52
@NicholasGalarza Yeah thanks. I'm slightly confused about API's so it'll help to have a working example to get a basic idea from.
CamperBot
@camperbot
Jul 12 2017 01:52
yuserahn sends brownie points to @nicholasgalarza :sparkles: :thumbsup: :sparkles:
:cookie: 292 | @nicholasgalarza |http://www.freecodecamp.com/nicholasgalarza
NicholasGalarza
@NicholasGalarza
Jul 12 2017 01:55
@YuserahN The main thing to get over with the intermediate projects is dealing with CORS lol. It will come up alot! Happy coding!
Yuserah Din
@YuserahN
Jul 12 2017 02:00
Thnx. You too.
Nick Janne
@njanne19
Jul 12 2017 02:02
Can someone tell me why my game isn't automatically running? It seems like I've done everything right, and I can't find the bug.
https://codepen.io/njanne19/pen/BZGWaZ?editors=1011
Eunice Park
@eunicode
Jul 12 2017 02:04

Hi, I'm bamboozled why my code works (I got help in this chat earlier). It's for the Seek and Destroy challenge: https://www.freecodecamp.com/challenges/seek-and-destroy

function destroyer(arr) {
  // Remove all the values

  var args = Array.prototype.slice.call(arguments);

  var newArray = arr.filter(function(val) {

    if (args.indexOf(val) === -1) {
      return true;
    }

    return false;

    }
  );

  return newArray;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);

I'm confused about callback functions and parameters.
So I'm applying filter() to array arr, which is [1,2,3,1,2,3]
My filter function applies indexOf() to array args, which is [[1,2,3,1,2,3,], 2, 3] and the search element is val, which I think is 1,2,3,1,2,3.
But this doesn't make sense, bc I think I should be checking array arr for 2 and 3.

aRtoo
@artoodeeto
Jul 12 2017 02:11
hi guys. i have a wrapper that has attribute of opacity: 0.5 how can i use opacity without affecting the text?? heres the codepen. https://codepen.io/artoo/pen/bRmrzz/
CreateTheHype
@CreateTheHype
Jul 12 2017 02:12
how would i build a project estimate tool on my website?
Nathaniel Suchy
@nsuchy
Jul 12 2017 02:14
@artoodeeto You can apply a opacitiy attribute to the text (put the text inside a DIV or Class and style it thru CSS)
For example:
body {
  Opacity: 0.5;
}
#text {
Opacity: 0;
}
<div id=“text”>your text here<</div>
aRtoo
@artoodeeto
Jul 12 2017 02:15
@nsuchy hmm. ill try. thans
Nathaniel Suchy
@nsuchy
Jul 12 2017 02:16
No problem
aRtoo
@artoodeeto
Jul 12 2017 02:18
@nsuchy doenst work bro. ill find another way thanks
CamperBot
@camperbot
Jul 12 2017 02:18
artoodeeto sends brownie points to @nsuchy :sparkles: :thumbsup: :sparkles:
:cookie: 272 | @nsuchy |http://www.freecodecamp.com/nsuchy
Nick Janne
@njanne19
Jul 12 2017 02:19
Still confused as to why my react component update never runs
Angel J Piscola
@Redmega
Jul 12 2017 02:25
@njanne19 Youre using babel on codepen, why not use es6 classes? much easier to read than a mishmash of jquery and React.createClass
Nick Janne
@njanne19
Jul 12 2017 02:28
@Redmega when I tried using a class that starts with class X extends React.Component I got an error early on so I ditched it
I can try it again and see what happens
Angel J Piscola
@Redmega
Jul 12 2017 02:30
@njanne19 If you have trouble getting the classes to work, check out my codepen: https://codepen.io/Redmega/pen/NbJZbp
I used React to do my twitch api
Nick Janne
@njanne19
Jul 12 2017 02:32
@Redmega I tried doing the same thing just transitioning the component into an ES6 version and I get this error
Angel J Piscola
@Redmega
Jul 12 2017 02:33
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
Nick Janne
@njanne19
Jul 12 2017 02:33
I think React does not like the fact that a stateful component is inside a function
Angel J Piscola
@Redmega
Jul 12 2017 02:33
Yeah I dont think you can scope classes like that
But this is not the React way.
The mix of jquery and react is making the code very confusing to read
I would say stick to one or the other
<Game> can keep track of the game state and render <Cell>'s. It can keep track of which cells are alive and dead and tell the cell what it is based on a prop
That's how I would do it
Nick Janne
@njanne19
Jul 12 2017 02:36
@Redmega Ahh, so I moved the component outside of the createGameBoard function and it still works. But I don't understand why it doesn't work when I pass it new props
The way I have it set up is that the component is called when the function drawGameBoard() is called
Angel J Piscola
@Redmega
Jul 12 2017 02:36
Did you save it?
Ok
It looks to me like you're trying to control the state from outside of the component
rodrigomlp
@rodrigomlp
Jul 12 2017 02:38
guys, is prototype the same as class?
Angel J Piscola
@Redmega
Jul 12 2017 02:38
No @rodrigomlp
Nick Janne
@njanne19
Jul 12 2017 02:38
drawGameBoard calls the ReactCell component passing the board property as the current game board (the one that has all the current data). Then, I make changes to the gameBoard variable by going through one generation, and I know that the one generation function is called and gameBoard is in fact assigned a new variable because of console logging
Angel J Piscola
@Redmega
Jul 12 2017 02:38
@njanne19 You should move that logic inside of the React class
rodrigomlp
@rodrigomlp
Jul 12 2017 02:38
in which ways is a prototype different from a class @Redmega ?
Nick Janne
@njanne19
Jul 12 2017 02:39
Is there a specific lifecycle component that says when a certain global variable is changed that it should update
because the ReactCell component runs off of values that it's passed in as props
@njanne19 Get away from global variables. Anything that is a global variable can live in the component state
Nick Janne
@njanne19
Jul 12 2017 02:42
Well but the global variable is the crux of my entire application
It needs to be called by certain functions
Angel J Piscola
@Redmega
Jul 12 2017 02:46
Those can be in the class as well
create a parent of your ReactCell class (fyi, you should rename that. It's not cromulent, doesnt really tell what the class does). I would create <Game> component which renders buttons to control the board and a <Board> which has the board state
Nick Janne
@njanne19
Jul 12 2017 02:51
@Redmega That is easier said than done. That would require me to change every assignment I make to gameBoard[], generation, and more to a this.setState call
Angel J Piscola
@Redmega
Jul 12 2017 02:57
Well good luck then :) Thats a mess of a codebase mate. The mix of jquery and react will give you a headache debugging
Nick Janne
@njanne19
Jul 12 2017 02:58
Fml :smile:
@Redmega so just to be clear I'd have to make a parent class that does all the functionality of the functions I had, and then call the child class (ReactCell [yes, I'll rename it]) into the render method of the parent class
aRtoo
@artoodeeto
Jul 12 2017 03:02
hi... so i have a text. and on the jquery i have it on a event. the event when i click the text it should change the unit which is does. so my question is how can i change my cursor so that when it hover itll be a pointer?? i googled on how to change my cursor using jquery it confuses me. https://codepen.io/artoo/full/bRmrzz/ code is here. help. thanks
Nick Janne
@njanne19
Jul 12 2017 03:02
@artoodeeto Just do it in CSS:
CLASS NAME HERE {
    cursor: pointer
}
aRtoo
@artoodeeto
Jul 12 2017 03:03
@njanne19 thanks bro. let me try
CamperBot
@camperbot
Jul 12 2017 03:03
artoodeeto sends brownie points to @njanne19 :sparkles: :thumbsup: :sparkles:
:cookie: 330 | @njanne19 |http://www.freecodecamp.com/njanne19
aRtoo
@artoodeeto
Jul 12 2017 03:07
@njanne19 bro its not working on the actual text. on the number
Nick Janne
@njanne19
Jul 12 2017 03:08
Let me take a look at your pen one sec
@artoodeeto
.unit, #temperature {
  cursor: pointer;
}
You're essentially assigning the class unit and the id temperature the pointer curose
cursor
that should work now
Nathaniel Suchy
@nsuchy
Jul 12 2017 03:13

function mutation(arr) {
  // Define variables
  var str1 = "";
  var str2 = "";
  var arr1 = [];
  var arr2 = [];
  var count = 0;

  /*
  Step 1:
  Turn the array into a string with the join method, using the string toLowerCase() method make the strings easier to check, once this is complete turn it back into an array using the same seperator as used in join.
  */
  arr = arr.join(' ').toLowerCase().split(' ');

  /*
  Step 2:
  Change each element of the array into a new array of the characters
  */
  str1 = arr[0];
  str2 = arr[1];
  arr1 = str1.split('');
  arr2 = str2.split('');

  /*
  Step 3:
  Compare each each letter in str2 to str1, if all letters in str2 are in str1 return true otherwise return false.
  */
  for (i = 0; i < arr2.length; i++){
    if(str2[i].indexOf(str1) < 0){
      /*
        The letter was not in both strings so the count does not increase.
      */
    } else {
      /*
        The letter was in the string so increment the count by 1.
      */
      count++;
    }
  }

  if (count === arr2.length){
    /*
      If the count is equal the the length of arr2, all letters from str2 were in str1.
    */
    return true;
  }
  else {
    return false;
  }
}

mutation(["hello", "Hey"]);
I’m working on the above code and it doesn’t seem to work properly. Any ideas on fixing?
aRtoo
@artoodeeto
Jul 12 2017 03:13
@njanne19 bro still not working when i hover on the texr
Manish Giri
@Manish-Giri
Jul 12 2017 03:20
@nsuchy I can tell you another way, you can try it out if you want
Nathaniel Suchy
@nsuchy
Jul 12 2017 03:21
Sure mind DMing me?
aRtoo
@artoodeeto
Jul 12 2017 03:23
bross im using grid system. but why is it my weather app doesnt respond to the size? https://codepen.io/artoo/full/bRmrzz/
Nick Janne
@njanne19
Jul 12 2017 03:26
@artoodeeto when you're hovering over the temperature? It's working for me
aRtoo
@artoodeeto
Jul 12 2017 03:34
@njanne19 its working now bro
Nick Janne
@njanne19
Jul 12 2017 03:35
Sounds god
good
CallMeOrange
@EgnaroDev
Jul 12 2017 03:39
@artoodeeto Looks like you have improved
aRtoo
@artoodeeto
Jul 12 2017 03:50
@MCTwoDigitZero hahahahaha. yea. after all the question. i almost quit again bro.
Angel J Piscola
@Redmega
Jul 12 2017 03:57
@njanne19 Yeah basically. That and the buttons with the on clicks. Look up how to do onClicks in React as theres some "Gotchas" but its fairly straightforward
You can see an example of an on click in my twitch codepen
caneno
@caneno
Jul 12 2017 04:16
whats up guys I finish this challenge but I was wondering if you guys can help with the code, I think it can me factored but I don't know how.
function confirmEnding(str, target) {
  var newStr = target.length;
    if (str.substr(newStr * -1) === target) {
      return true;
    }else {
        return false;
    }

}

confirmEnding("Bastian", "n");
kumquatfelafel
@kumquatfelafel
Jul 12 2017 04:22

@caneno Not 100% sure what you're asking, but you can actually just return the condition inside the if statement here, assuming what you've done is correct for given thing.

So like... instead of

if (a)
  return true;
else
  return false;

just ...

return a

where "a" is the condition in question

caneno
@caneno
Jul 12 2017 04:24
thanks @kumquatfelafel
CamperBot
@camperbot
Jul 12 2017 04:24
caneno sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 457 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Manish Giri
@Manish-Giri
Jul 12 2017 04:24
@caneno

function confirmEnding(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
    return str.substr(-target.length) === target;
}

confirmEnding("Bastian", "n");
caneno
@caneno
Jul 12 2017 04:25
@Manish-Giri thats what I was looking for thanks
CamperBot
@camperbot
Jul 12 2017 04:25
caneno sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6239 | @manish-giri |http://www.freecodecamp.com/manish-giri
Ogundele Olumide
@Lumexralph
Jul 12 2017 04:25
@Manish-Giri stole it from my head
Manish Giri
@Manish-Giri
Jul 12 2017 04:25
lel
lggggmmmm :smiling_imp: :smiling_imp:
good morning
@Lumexralph
Ogundele Olumide
@Lumexralph
Jul 12 2017 04:25
I'm angry..... I leave the :smiling_imp: legend gang
Manish Giri
@Manish-Giri
Jul 12 2017 04:26
lol
Ogundele Olumide
@Lumexralph
Jul 12 2017 04:26
:joy:
Manish Giri
@Manish-Giri
Jul 12 2017 04:26
why would you
we're the :smiling_imp: 's creed
Ogundele Olumide
@Lumexralph
Jul 12 2017 04:26
@Manish-Giri Good Morning Bro and the Legendary sggggggggggggggggggggggggggggm :smiling_imp:
Manish Giri
@Manish-Giri
Jul 12 2017 04:26
lol pls
Ogundele Olumide
@Lumexralph
Jul 12 2017 04:27
you're excused :smirk:
how're you?
Manish Giri
@Manish-Giri
Jul 12 2017 04:28
trying to clean my apartment tonight
:weary:
you?
Ogundele Olumide
@Lumexralph
Jul 12 2017 04:29
woke with a cold, kind of running nose.....but good, excited about stuffs to be learnt today and done
@Manish-Giri laundry is my major enemy
Manish Giri
@Manish-Giri
Jul 12 2017 04:30
@Lumexralph oh yea i have to do laundry too
life sucks
Ogundele Olumide
@Lumexralph
Jul 12 2017 04:33
yeah, it can be
Alexander Køpke
@alexanderkopke
Jul 12 2017 05:04
no, life is great, we suck! :laughing:
Ogundele Olumide
@Lumexralph
Jul 12 2017 05:05
@alexanderkopke yeah.. i'll go with that too
Ragnorak
@Rrak
Jul 12 2017 05:10
We suck yay
Alexander Køpke
@alexanderkopke
Jul 12 2017 05:21
but then again I'm optimistic that the reason we hate laundry is because we don't want to do it but we still like clean clothes. Conundrum.
Alexander Køpke
@alexanderkopke
Jul 12 2017 05:36
@MCTwoDigitZero Nice work! :+1:
CallMeOrange
@EgnaroDev
Jul 12 2017 05:36
@alexanderkopke Thanks
CamperBot
@camperbot
Jul 12 2017 05:36
mctwodigitzero sends brownie points to @alexanderkopke :sparkles: :thumbsup: :sparkles:
:star2: 1611 | @alexanderkopke |http://www.freecodecamp.com/alexanderkopke
CallMeOrange
@EgnaroDev
Jul 12 2017 05:36
That is second weather app :p
Alexander Køpke
@alexanderkopke
Jul 12 2017 05:38
How you get the icon to move like that?
CallMeOrange
@EgnaroDev
Jul 12 2017 05:38
Skycons library, animation?
I just do Skycons.play()...
This is only animation I know that move like that
Alexander Køpke
@alexanderkopke
Jul 12 2017 05:39
looks really cool
CallMeOrange
@EgnaroDev
Jul 12 2017 05:39
Yea
First one ^
Alexander Køpke
@alexanderkopke
Jul 12 2017 05:40
looks nice too
CallMeOrange
@EgnaroDev
Jul 12 2017 05:40
Thanks
Im going to make another one
With 5-day forecast
Im going to make designs that looks like second one
Alexander Køpke
@alexanderkopke
Jul 12 2017 05:42
Now you make me want to make more weather apps :)
CallMeOrange
@EgnaroDev
Jul 12 2017 05:42
:)
iso
@iso1048
Jul 12 2017 05:42
is anyone available to help with the twitch api project?
Ragnorak
@Rrak
Jul 12 2017 05:43
@gothamknight And what is your project on!!
CallMeOrange
@EgnaroDev
Jul 12 2017 05:44
But I have to figure out how to use a loop for 5 day forecast
iso
@iso1048
Jul 12 2017 05:44
@Ragnorok-Gs im confused as to how I am supposed to get data about streamers when they are offline becuase in the documentation, it says that the following is the response if a streamer is offline: { "stream":null }
CallMeOrange
@EgnaroDev
Jul 12 2017 05:44
Say I have 8 days/8 objects from API and has to loop 5 of them
Ugh
Alexander Køpke
@alexanderkopke
Jul 12 2017 05:45
@MCTwoDigitZero doesn't it send an array with the objects inside?
CallMeOrange
@EgnaroDev
Jul 12 2017 05:45
Yeah
8 arrays I meant
Ragnorak
@Rrak
Jul 12 2017 05:46
@gothamknight It must be there in there API doc
CallMeOrange
@EgnaroDev
Jul 12 2017 05:47
@alexanderkopke There are like 8 objects that contain informations each day, temperature for example
But I have to figure out which days they are :/
Alright then, Im going to work on it
Cya
iso
@iso1048
Jul 12 2017 05:49
@Ragnorok-Gs i cannot seem to find it
Ragnorak
@Rrak
Jul 12 2017 05:53
@gothamknight
If you are relating to channel then check this snippet
$.getJSON('https://api.twitch.tv/kraken/streams/' + YOUR_CHANNEL_NAME, function(channel) {

    if (channel["stream"] == null) { 
        //THEY ARE OFFLINE DO WHATEVER HERE

    } else {

        //THEY ARE ONLINE DO WHATEVER HERE

    }



});
iso
@iso1048
Jul 12 2017 05:57
@Ragnorok-Gs the endpoint is different since the one you showed does not allow access to the json. https://wind-bow.glitch.me/twitch-api/streams/OgamingSC2 - this url works, but the user is currently offline, so I am not able to access his logo/image and other information.
Pieter Stokkink
@forkerino
Jul 12 2017 06:07
@gothamknight you have to use a different endpoint for the users that are offline (nest API calls).
iso
@iso1048
Jul 12 2017 06:32
@forkerino what endpoint is it?
Pieter Stokkink
@forkerino
Jul 12 2017 06:34
@gothamknight I think the /channels/ endpoint
If you go here you'll see three options of which you already used one. https://wind-bow.glitch.me/
So you can check yourself which suits best for the other info you need
iso
@iso1048
Jul 12 2017 06:35
@forkerino thanks man
CamperBot
@camperbot
Jul 12 2017 06:35
gothamknight sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2821 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Jul 12 2017 06:36
:+1:
abraham anak agung
@padunk
Jul 12 2017 06:41
Hi, can anybody help me? this is about arrow function. what is the different between => () and => {}
Pieter Stokkink
@forkerino
Jul 12 2017 06:45
@padunk with () you can return an object (you actually have to surround it by parentheses, otherwise it will be interpreted as a code block). {} denotes a code block and can contain several lines.
Valdovas1
@Valdovas1
Jul 12 2017 06:45
Hey guys !
function destroyer(arr) {
  // Remove all the values
var filtered = arr.filter(function(item){
  return (item < arguments[1] && arguments[2]);
}

 );}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Any ideas why this does not bring back anything ?
Pieter Stokkink
@forkerino
Jul 12 2017 06:47
@Valdovas1 you don't return anything from the outer function.
Valdovas1
@Valdovas1
Jul 12 2017 06:47
@forkerino Okey okey okey
Pieter Stokkink
@forkerino
Jul 12 2017 06:47
The filter will need some work, but if you return filtered, you can debug it a bit better.
Valdovas1
@Valdovas1
Jul 12 2017 06:48

@forkerino ```

function destroyer(arr) {
// Remove all the values
var filtered = arr.filter(function(item){
return (item < arguments[1] && arguments[2]);
}

);
return filtered;

}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
```

abraham anak agung
@padunk
Jul 12 2017 06:48
@forkerino ooo, ok. Thanks!
CamperBot
@camperbot
Jul 12 2017 06:48
padunk sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2822 | @forkerino |http://www.freecodecamp.com/forkerino
Valdovas1
@Valdovas1
Jul 12 2017 06:48


function destroyer(arr) {
  // Remove all the values
var filtered = arr.filter(function(item){
  return (item < arguments[1] && arguments[2]);
}

 );
  return filtered;

}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
@forkerino I got a green light on []
@forkerino By little work, what do you mean ? Is there a formula that is bad ?
Thayyeb salim
@Thayyebsalim
Jul 12 2017 06:51
I think that you have to use args and seperate the args
Pieter Stokkink
@forkerino
Jul 12 2017 06:51
@Valdovas1 inside the filter callback function, arguments is not the same as outside. Each function has its own arguments object.
Thayyeb salim
@Thayyebsalim
Jul 12 2017 06:51
@Valdovas1
Pieter Stokkink
@forkerino
Jul 12 2017 06:51
also, there can be more than two
so better put all of them in an array
Valdovas1
@Valdovas1
Jul 12 2017 06:52
@forkerino So, you are saying that i should write each argument a function that would be two extra ones ?
Pieter Stokkink
@forkerino
Jul 12 2017 06:52
@Valdovas1 definitely not
Valdovas1
@Valdovas1
Jul 12 2017 06:53
if i put whole array into an array then i would not need arguments
Pieter Stokkink
@forkerino
Jul 12 2017 06:53
@Valdovas1 create an array of the original arguments outside the filter. Use that inside the filter to check if the current element is or isn't in the array
Frostbites
@Frostbites
Jul 12 2017 06:54
Hey folks
How is everyone doing?
Valdovas1
@Valdovas1
Jul 12 2017 06:54
@forkerino Coudl you provide me an example as i do not quite understand this one?
Frostbites
@Frostbites
Jul 12 2017 06:54
Is anyone kind enough to explain how arguments works in JavaScript?
Valdovas1
@Valdovas1
Jul 12 2017 06:55
yes, there is a line of symbols whatever so you count them as each is an argument. If on the other hand there is an array into then it counts as one no matter how long
Pieter Stokkink
@forkerino
Jul 12 2017 06:56
@Valdovas1 yes, but you don't know how many arguments will be given
@Frostbites the arguments object is something that each function has (except ES6 arrow functions). It contains all the arguments passed into the function, named or not.
Frostbites
@Frostbites
Jul 12 2017 06:57
How do I create a condition for arguments in a filter?
Valdovas1
@Valdovas1
Jul 12 2017 06:59
function destroyer(arr) {
  // Remove all the values
var filtered = arr.filter(function(item){

  return item < (arguments[1] && arguments[2]);
}

 );
  return filtered;

}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
With this i solve 2/5 of challenge
@forkerino What do you suggest needs improvement? Could you tell it for like 5 year old ?
Frostbites
@Frostbites
Jul 12 2017 07:00
@Valdovas1 I am stuck on the same challenge
Pieter Stokkink
@forkerino
Jul 12 2017 07:00
@Valdovas1 pure luck.
inside the filter arguments[1] will be the index of the current element and arguments[2] will be the array
those are the default parameters to .filter callback
it won't be the arguments 2 and 3 of the destroyer function
Frostbites
@Frostbites
Jul 12 2017 07:02

function destroyer(arr) {


  var args = arr.slice.call(arguments);

  for (var i = 1; i < args[i].length; i++) {
    args[0].pop(args[i]);

  }return args;

}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
This somewhat worls
works but the incorrect way
Pieter Stokkink
@forkerino
Jul 12 2017 07:02
@Valdovas1 so outside the fiilter put arguments into an array, as explained in the docs on mdn. Use that array inside your filter.
gotta go now, my train is here.
Valdovas1
@Valdovas1
Jul 12 2017 07:09
function destroyer(arr) {
  // Remove all the values
  var numbers = [[1, 2, 3, 1, 2, 3], 2, 3];
var filtered = numbers.filter(function(item){

  return item < (arguments[1] && arguments[2]);
}

 );
  return filtered;

}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
any ideas why this does not let me pass ?
Frostbites
@Frostbites
Jul 12 2017 07:14
return item < (arguments[1] && arguments[2]); @Valdovas1 has to do with this I thnk
Valdovas1
@Valdovas1
Jul 12 2017 07:15
@Frostbites Do you think that could be a loop ?
the question will for loop work in this situation
?
Frostbites
@Frostbites
Jul 12 2017 07:16
I think that it can be done without the loop as well
because I am trying to work on it since yesterday with a for loop and today I used a for and an if loop
just messes things up
You have coded your solution for two items in the array only, which should not be the solution
Valdovas1
@Valdovas1
Jul 12 2017 07:18
@Frostbites aha, I get it. yet if for loop is not usable then how would one write arguments ?
@Frostbites I asked in stack overflow
Frostbites
@Frostbites
Jul 12 2017 07:19
Please share any insight you get
because I am getting confused
Valdovas1
@Valdovas1
Jul 12 2017 07:20
@Frostbites Got the answer that this line is bad
return item < (arguments[1] && arguments[2]);
Don't seem to understand why
Frostbites
@Frostbites
Jul 12 2017 07:21
because you're comparing two values to a random item in the array I think
Sweet Coding :)
@SweetCodingInc
Jul 12 2017 07:22
@Valdovas1 You need to break down this problem in smaller problems and solve it one by one
Valdovas1
@Valdovas1
Jul 12 2017 07:22
@SweetCodingInc Okey, was not helpful as i believe i broke it down enough ?\
Sweet Coding :)
@SweetCodingInc
Jul 12 2017 07:22
First thing, the number of arguments to your destroyer function is variable.
first argument (arr) is fixed, but the number that are passed after it may vary
Frostbites
@Frostbites
Jul 12 2017 07:23

@SweetCodingInc @Valdovas1 so far, I have come up with this and it's wrong

```


function destroyer(arr) {


  var args = arr.slice.call(arguments);

  var newArr = args.filter(function(number) {
        return number != args[arguments];

                               });




}



destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Sweet Coding :)
@SweetCodingInc
Jul 12 2017 07:23
so first thing is you need to separate out first array, and create another array of all the arguments passed after first argument.
@Frostbites You got it right on right tract at least
However this line return number != args[arguments]; is wrong
specifically [arguments] part
since your args is an array now, it expects a number to be passed into []
but arguments is an object and not a number
args[arguments] would evaluate to undefined
Valdovas1
@Valdovas1
Jul 12 2017 07:26
function destroyer(arr) {
  // Remove all the values
  var numbers = [[1, 2, 3, 1, 2, 3], 2, 3];
var filtered = numbers.filter(function(item){

  return item < numbers[arguments];
}

 );
  return filtered;

}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
what about his one ?
this*
Frostbites
@Frostbites
Jul 12 2017 07:26
can I do something like i = 1 and then somehow loop it so that it becomes arguments[i] and then carries on?
Sweet Coding :)
@SweetCodingInc
Jul 12 2017 07:26
@Valdovas1 same thing. You just changed variable names.. But you're doing the same mistake as @Frostbites
@Frostbites Yes. That is exactly what you need to do
Frostbites
@Frostbites
Jul 12 2017 07:27
I tried it with a for loop
but it didn't work
let me try that again
Valdovas1
@Valdovas1
Jul 12 2017 07:27
@SweetCodingInc @Frostbites so for loop is the answer after all
Frostbites
@Frostbites
Jul 12 2017 07:28

function destroyer(arr) {


  var args = arr.slice.call(arguments);

  var newArr = args.filter(function(number) {
    for (var i = 1; i != args[i]; i++)
        return number != args[arguments[i]];

                               });




}



destroyer([1, 2, 3, 1, 2, 3], 2, 3);
why is it not working
probably because there's a problem in the loo
loop*
but I don't know what problem that is
Sweet Coding :)
@SweetCodingInc
Jul 12 2017 07:30
@Frostbites args[i] not args[arguments[i]]
Valdovas1
@Valdovas1
Jul 12 2017 07:30
can you tell me why do you use slice ?
Sweet Coding :)
@SweetCodingInc
Jul 12 2017 07:31
Also this line is wrong var args = arr.slice.call(arguments);
it should be
var args = Array.prototype.slice.call(arguments);
Frostbites
@Frostbites
Jul 12 2017 07:31
@Valdovas1 to break up the given array into different elements

function destroyer(arr) {


  var args = arr.slice.call(arguments);

  var newArr = args.filter(function(number) {
    for (var i = 1; i != args[i]; i++) {
        return number != args[i];

                               }});




}



destroyer([1, 2, 3, 1, 2, 3], 2, 3);
@SweetCodingInc I think the only difference is that I didn't use the word prototype and replaced array with arr instead :)
Valdovas1
@Valdovas1
Jul 12 2017 07:32

function destroyer(arr) {
  // Remove all the values
  var numbers = [[1, 2, 3, 1, 2, 3], 2, 3];
var filtered = numbers.filter(function(item){
  for (var i = 1; i < arr.length; i++)
  return item < numbers[i];
}

 );
  return filtered;

}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Am i closer ?
Frostbites
@Frostbites
Jul 12 2017 07:33
@Valdovas1 Something tells me ou are
you*
Sweet Coding :)
@SweetCodingInc
Jul 12 2017 07:33
@Frostbites : There is a huge difference. Although it will give you the same output. However, it explains your lack understanding of using those methods the way you're using it
Frostbites
@Frostbites
Jul 12 2017 07:34
you're absolutely right there buddy, I am lost @SweetCodingInc
Valdovas1
@Valdovas1
Jul 12 2017 07:34
@Frostbites :D
Sweet Coding :)
@SweetCodingInc
Jul 12 2017 07:35

@Valdovas1 Almost there...

First remove that var numbers line

second run filter on arr (not numbers)
Frostbites
@Frostbites
Jul 12 2017 07:35

function destroyer(arr) {


  var args = Array.prototype.slice.call(arguments);

  var newArr = args.filter(function(number) {
    for (var i = 1; i != args[i]; i++) {
        return number;

                               }});


  return args;



}



destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Sweet Coding :)
@SweetCodingInc
Jul 12 2017 07:35
third i < arguments.length not i < arr.length
and you're done
@Frostbites i<args.length
Valdovas1
@Valdovas1
Jul 12 2017 07:37
@SweetCodingInc

function destroyer(arr) {
  // Remove all the values
var filtered = arr.filter(function(item){
  for (var i = 1; i < arguments.length; i++)
  return item < arguments[i];
}

 );
  return filtered;

}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Frostbites
@Frostbites
Jul 12 2017 07:37

function destroyer(arr) {


  var args = Array.prototype.slice.call(arguments);

  var newArr = args.filter(function(number) {
    for (var i = 1; i < args.length; i++) {
        return number != args[i];

                               }});


  return args;



}



destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Valdovas1
@Valdovas1
Jul 12 2017 07:37
does not pass the challenge
Sweet Coding :)
@SweetCodingInc
Jul 12 2017 07:37
@Valdovas1 becuase of this line return item < arguments[i];
Hint you can use .indexOf or .includes function
Valdovas1
@Valdovas1
Jul 12 2017 07:38
wha is bad with this one ?
@SweetCodingInc return arguments[i].indexOf() > -1;
?
Frostbites
@Frostbites
Jul 12 2017 07:41

function destroyer(arr) {


  var args = Array.prototype.slice.call(arguments);

  var newArr = args.filter(function(number) {
    for (var i = 1; i < args.length; i++) {
        if (args[0].includes(args[i] === false)) {
          args[i].pop();
          return args;

        }

                               }});


  return args;



}



destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Haha
Sweet Coding :)
@SweetCodingInc
Jul 12 2017 07:41
first do arr = Array.prototype.slice.call(arguments);
Frostbites
@Frostbites
Jul 12 2017 07:42
but arr is already defined @SweetCodingInc
I am gonna cheat now (6)
Valdovas1
@Valdovas1
Jul 12 2017 07:43
dont :)
dont cheat
Sweet Coding :)
@SweetCodingInc
Jul 12 2017 07:43
function destroyer(arr) {
  var args = Array.prototype.slice.call(arguments);
  var newArr = arr.filter(function(number) {
    return args.indexOf(number) === -1;
  });

  return newArr;
}



destroyer([1, 2, 3, 1, 2, 3], 3);
note: .indexOf returns -1 if number is not present in args
Valdovas1
@Valdovas1
Jul 12 2017 07:44
Damn i was doing it good
Frostbites
@Frostbites
Jul 12 2017 07:45
hahaha
I knew it had to be done without a darn loop
but I used a loop myself so -1 for me
Valdovas1
@Valdovas1
Jul 12 2017 07:45
indeed
Frostbites
@Frostbites
Jul 12 2017 07:47
so the question is, how does the computer know that args is related to arr (which is defined as the function parameter) when we don't even mention it?
Sweet Coding :)
@SweetCodingInc
Jul 12 2017 07:47
To break it down, First separate out first array and rest of the arguments in another array
function destroyer(arr) {
  var restOfTheArguments = [];
  for(var i=1; i< arguments.length;i++){
    restOfTheArguments.push(arguments[i]);
  }
  console.log(arr); //[ 1, 2, 3, 1, 2, 3 ]
  console.log(restOfTheArguments); //[ 2, 3 ]
}



destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Frostbites
@Frostbites
Jul 12 2017 07:48
@SweetCodingInc Ahan, then?
Sweet Coding :)
@SweetCodingInc
Jul 12 2017 07:48

@Frostbites

so the question is, how does the computer know that args is related to arr (which is defined as the function parameter) when we don't even mention it?

args or arguments ?

@Frostbites Then you filter over arr and see if each element of arr is present in restOfTheArguments
Frostbites
@Frostbites
Jul 12 2017 07:49
  var args = Array.prototype.slice.call(arguments);
  var newArr = arr.filter(function(number) {
    return args.indexOf(number) === -1;
  });

  return newArr;
look at the first line, it doesn't mention arr anywhere.
Valdovas1
@Valdovas1
Jul 12 2017 07:49
ithink arr is short for array
so javascript gets it automattically
@SweetCodingInc
Frostbites
@Frostbites
Jul 12 2017 07:50
@Valdovas1 @SweetCodingInc Really? Is JavaScript that weak as a language ?
Valdovas1
@Valdovas1
Jul 12 2017 07:50
I would like to know wy do you use this line at all ?
var args = Array.prototype.slice.call(arguments);
alpox
@alpox
Jul 12 2017 07:50
@Valdovas1 javascript doesnt interpret variable names
Valdovas1
@Valdovas1
Jul 12 2017 07:51
var args = Array.prototype.slice.call(arguments);
Frostbites
@Frostbites
Jul 12 2017 07:51
@Valdovas1 Thanks, that is my question too
CamperBot
@camperbot
Jul 12 2017 07:51
frostbites sends brownie points to @valdovas1 :sparkles: :thumbsup: :sparkles:
:cookie: 251 | @valdovas1 |http://www.freecodecamp.com/valdovas1
alpox
@alpox
Jul 12 2017 07:51
@Valdovas1 this line is for making a real array out of the argumenta object
Frostbites
@Frostbites
Jul 12 2017 07:51
and you're welcome for the unintended brownie points :D
Valdovas1
@Valdovas1
Jul 12 2017 07:51
Coudl you explain little more on this ? @alpox
:D
Frostbites
@Frostbites
Jul 12 2017 07:51
@alpox can you elaborate it in the simplest of words you can imagine?
haha
Valdovas1
@Valdovas1
Jul 12 2017 07:52
like for 5 year old
Sweet Coding :)
@SweetCodingInc
Jul 12 2017 07:53
Here is a total programming fanatic approach.
function destroyer(arr) {
  var restOfTheArguments = [];
  var u = 0;
  for(var i=1; i< arguments.length;i++){
    restOfTheArguments[u++] = arguments[i];
  }
  console.log(arr); //[ 1, 2, 3, 1, 2, 3 ]
  console.log(restOfTheArguments); //[ 2, 3 ]

  //now we are going to check if  each element of arr is present in restOfTheArguments
  var filteredElements = [];
  var k=0;

  for(var i=0; i<arr.length;i++){
    var number = arr[i];
    var numberFoundInRestOfTheArguments = false;

    for(var j=0;j<restOfTheArguments.length;j++){
      var argNumber = restOfTheArguments[j];

      if(argNumber === number){
        numberFoundInRestOfTheArguments = true;
      }

    }
    if(numberFoundInRestOfTheArguments === false){
      filteredElements[k++] = number;
    }
  }

  return filteredElements;

}
alpox
@alpox
Jul 12 2017 07:54
The variable arguments holds all the values which are passed to a function in an array-like object. Notice, array-LIKE you can index the arguments object for its values but the object doesnt define any normal array methods like filter etc
Sweet Coding :)
@SweetCodingInc
Jul 12 2017 07:54
Which with further mastery of javascript can be reduced to
function destroyer(arr) {
  return arr.filter(a => ![...arguments].includes(a))
}

destroyer([1, 2, 3, 1, 2, 3], 2);
alpox
@alpox
Jul 12 2017 07:55
Therefore you use this line to make a real array out of the arguments object.
What you actually do is that you use the slice method of a real array and use it on the arguments object which kind of copies the arguments object into an array
Frostbites
@Frostbites
Jul 12 2017 07:57
@SweetCodingInc WOW
abraham anak agung
@padunk
Jul 12 2017 07:57
@SweetCodingInc what is this doing? [...arguments]
Sweet Coding :)
@SweetCodingInc
Jul 12 2017 07:57
@padunk Its called es6 spread operator
it will cast arguments (which is an object) into an instance of Array
alpox
@alpox
Jul 12 2017 07:57
@padunk same as the slice call. It just makes a real array out of the arguments object using es6 spread
Sweet Coding :)
@SweetCodingInc
Jul 12 2017 07:58
so that you can use Array.prototype methods like .includes on it
Frostbites
@Frostbites
Jul 12 2017 07:59
Amazing
abraham anak agung
@padunk
Jul 12 2017 08:00
O...i see, never understand much about this spread operator. Kind of confusing :) Thanks @SweetCodingInc @alpox
Frostbites
@Frostbites
Jul 12 2017 08:00
Any links to further understand the spread operator?
Frostbites
@Frostbites
Jul 12 2017 08:03
@jlouiss thanks
CamperBot
@camperbot
Jul 12 2017 08:03
frostbites sends brownie points to @jlouiss :sparkles: :thumbsup: :sparkles:
:cookie: 381 | @jlouiss |http://www.freecodecamp.com/jlouiss
Alexander Køpke
@alexanderkopke
Jul 12 2017 08:06
spread is like what you put on bread. On the knife it doesn't seem like that much but then you spread it out on the bread and you can see all the content
Valdovas1
@Valdovas1
Jul 12 2017 08:07
@alpox @SweetCodingInc Thank you for patience and explanations.
CamperBot
@camperbot
Jul 12 2017 08:07
valdovas1 sends brownie points to @alpox and @sweetcodinginc :sparkles: :thumbsup: :sparkles:
:cookie: 118 | @sweetcodinginc |http://www.freecodecamp.com/sweetcodinginc
:star2: 1254 | @alpox |http://www.freecodecamp.com/alpox
Valdovas1
@Valdovas1
Jul 12 2017 08:07
but i stil dont get it. So i will read more on includes and call so next time i would know
Bomee
@Bomulacious
Jul 12 2017 08:12
1) I've added str.match(/[A-Z]/i) as a condition to ensure the if statement operates only for alphabets, is this a right away to do it? 2) for the 3rd condition where there is an arrow --> I want the condition to be "if it's not an alphabet", how do I do this? https://www.freecodecamp.com/challenges/caesars-cipher
Sweet Coding :)
@SweetCodingInc
Jul 12 2017 08:13
go there and run some shit
and learn by experimentation ;)
Sweet Coding :)
@SweetCodingInc
Jul 12 2017 08:18
@Bomulacious str.match(/[A-Z]/i) will give you null if it's not an alphabet
otherwise it will give you an array with matched character at index 0
wonder
@wonder2991
Jul 12 2017 08:24

@Bomulacious use g flag in your regex to match all alphabets

/[^a-z]/gi

will match non-alphabets

Bomee
@Bomulacious
Jul 12 2017 08:39
@wonder2991 @SweetCodingInc thanks! But, the space is still converted to a dash which is 13 space after in the unicode. Why is the non-alphabet space converted through the first condition?
CamperBot
@camperbot
Jul 12 2017 08:39
bomulacious sends brownie points to @wonder2991 and @sweetcodinginc :sparkles: :thumbsup: :sparkles:
:cookie: 119 | @sweetcodinginc |http://www.freecodecamp.com/sweetcodinginc
:cookie: 401 | @wonder2991 |http://www.freecodecamp.com/wonder2991
wonder
@wonder2991
Jul 12 2017 08:45
can i see your code? @Bomulacious
Bomee
@Bomulacious
Jul 12 2017 08:46

function rot13(str) { // LBH QVQ VG!
var decoded = [];

for (var i=0; i < str.length; i++){
if (str.match(/[A-Z]/gi) && str.charCodeAt(i)+13 <= 90)
decoded.push(String.fromCharCode(str.charCodeAt(i) + 13));

else if (str.match(/[A-Z]/gi) && str.charCodeAt(i)+13 > 90) 
decoded.push(String.fromCharCode(64+str.charCodeAt(i)+13-90));

else if (str.match(/[^A-Z]/gi))
decoded.push(str);

}

return decoded.join('');
}

rot13("SERR PBQR PNZC"); ---> this becomes FREE-CODE-CAMP with dashes...

wonder
@wonder2991
Jul 12 2017 08:56
that last else if in not right
regex match returns an array
Sweet Coding :)
@SweetCodingInc
Jul 12 2017 09:29
@Bomulacious What is your expected output?
if you don't want it separated by -, you could simply do return decoded.join('').split('-').join(' ');
Bomee
@Bomulacious
Jul 12 2017 09:36
@SweetCodingInc expected outcomes are as below...
rot13("SERR PBQR PNZC") should decode to "FREE CODE CAMP"
rot13("SERR CVMMN!") should decode to "FREE PIZZA!"
rot13("SERR YBIR?") should decode to "FREE LOVE?"
rot13("GUR DHVPX OEBJA QBT WHZCRQ BIRE GUR YNML SBK.") should decode to "THE QUICK BROWN DOG JUMPED OVER THE LAZY FOX."
Sweet Coding :)
@SweetCodingInc
Jul 12 2017 09:45
@Bomulacious Your last condition will never execute
wonder
@wonder2991
Jul 12 2017 09:45
function rot13(str) { // LBH QVQ VG!
  var decoded = [];
  for (var i=0; i < str.length; i++){
    if ((/[^A-Z]/gi).test(str[i]))
    decoded.push(str[i]);
    else if (str.charCodeAt(i)+13 <= 90)
    decoded.push(String.fromCharCode(str.charCodeAt(i) + 13));
    else if (str.charCodeAt(i)+13 > 90) 
    decoded.push(String.fromCharCode(64+str.charCodeAt(i)+13-90));
  }
  return decoded.join('');
}
rot13("SERR PBQR PNZC");
this works, but keep in mind that the if statement requires a condition which can be either true or false. @Bomulacious
Sweet Coding :)
@SweetCodingInc
Jul 12 2017 09:45
where you're pushing non alphabetic characters
I'd do it like this
function rot13(encodedStr) {
  return encodedStr.replace(/[a-z]/gi,function(c){
    if ("a"<=c && c<="z")
      return String.fromCharCode(97+(c.charCodeAt(0)-97+13)%26);
    if ("A"<=c && c<="Z")
      return String.fromCharCode(65+(c.charCodeAt(0)-65+13)%26);
    return c;
  });
}
imp: %26 part
Innocent Tauzeni
@Telthem89
Jul 12 2017 09:46
hello team guys
Stephen James
@sjames1958gm
Jul 12 2017 10:11
@Bomulacious Your match is matching the whole string not just the current character
@Telthem89 :wave:
function rot13(str) { // LBH QVQ VG!
  return str.replace(/([A-M])|([N-Z])/g, function(m, p1, p2) {
    return String.fromCharCode(m.charCodeAt(0) + (p1 ? 13 : -13)); 
  });
}
Andres Diaz-Pinto
@diazandr3s
Jul 12 2017 10:15
@Telthem89 Hey! How you doing'
tundeiness
@tundeiness
Jul 12 2017 10:15
hi guys. So I need a heads up on this: instead of my social media button tweeting the link of my random quote page, i'd like it to do something else like tweet the quote displayed on the page at that moment to my twitter handle. I have been scouring through twitter for developers and I can't find any clue yet. Can someone show me how to make my tweet button get the actual content displayed per time everytime I request a new quote?
makalohri
@makalohri
Jul 12 2017 10:21
@knrt10 thank you man
CamperBot
@camperbot
Jul 12 2017 10:21
makalohri sends brownie points to @knrt10 :sparkles: :thumbsup: :sparkles:
:cookie: 455 | @knrt10 |http://www.freecodecamp.com/knrt10
Frostbites
@Frostbites
Jul 12 2017 10:51
Hey guys
Ken Haduch
@khaduch
Jul 12 2017 10:51
@Frostbites - hey there, what's up?
Tai Jones
@taiJones00
Jul 12 2017 10:52

function palindrome(str) {

// turn str to array and lowercase
var arrayed = str.toLowerCase().split("");

// FILTER the string into a new array /A-Za-z0-9/g
var filtered = arrayed.filter(function(i){
return (i == /[A-Za-z0-9]/g);
});

// copy the filtered array and reverse it. both to strings
var reversed = filtered.reverse().join("");
var twofiltered = filtered.join("");

// compare filtered and reversed and return boolean
// return (filtered == reversed);
return (twofiltered == reversed);
}

palindrome("five|_/|four");

What's wrong with this
Frostbites
@Frostbites
Jul 12 2017 10:54
@khaduch
I am good

function getIndexToIns(arr, num) {
  // Find my place in this sorted array.

  var args = Array.prototype.slice.call(arguments);

  for (var i = 0; i < args[0].length; i++) {
    if (num < args[1] && args[i] > i + 1) {

    }
  }

  return ;
}

getIndexToIns([40, 60], 50);
I am stuck on this
Stephen James
@sjames1958gm
Jul 12 2017 10:58
@Frostbites You don't need arguments, the two values to process are arr and num
Dan Couper
@DanCouper
Jul 12 2017 10:58
You don't need to use arguments, the arguments are literally there (arr, num)
Ah snap
Stephen James
@sjames1958gm
Jul 12 2017 10:59
Think about these two lines the first is using args[0].length, but then you use i on args
Generally the for loop test and the use of the index variable are on the same array
  for (var i = 0; i < args[0].length; i++) {
    if (num < args[1] && args[i] > i + 1) {
Ken Haduch
@khaduch
Jul 12 2017 10:59
@taiJones00 - your filtering function is returning nothing for a string, so you are always comparing empty strings, so only true cases are passing. To be more precise, only test cases that are expecting true for a result are passing, because that is the only value you are returning.
Stephen James
@sjames1958gm
Jul 12 2017 10:59
@taiJones00 You are comparing i to a regular expression
use regex.test(string) to test if i matches
/[A-Za-z0-9]/.test(i);
Sweet Coding :)
@SweetCodingInc
Jul 12 2017 11:11
function getIndexToIns(arr, num) {
  arr.sort((a,b)=>b<a);
  for(var i=0;i<arr.length;i++){
    if(arr[i] >= num){
      break;
    }
  }
  return i;
}

getIndexToIns([40, 60], 50);
function getIndexToIns(arr, num) {
  return arr.sort( (a, b) => b<a)
            .filter(a =>  a < num)
            .length;
}

getIndexToIns([40, 60], 50);
function getIndexToIns(arr, num) {
  // Find my place in this sorted array.
  return arr.reduce(function(p,c){
    return p + (num>c);
  },0);
}

getIndexToIns([40, 60], 50);
Jianhao Tan
@jaanhio
Jul 12 2017 12:21
hi all, may i know how can i use jquery to retrieve the following values (“Want to sell”, “Lens”, “Tokina Mount”) found in the html below? it doesn’t seem to be nested within any element
<b><font size="1">Equipment Type</font>:</b> Lens<br>
<blockquote class="postcontent restore ">
                            <b><font size="1">Advertisement Category</font>:</b> Want To Sell (WTS)<br>
<br>
<b><font size="1">Equipment Type</font>:</b> Lens<br>
<b><font size="1">Equipment Brand</font>:</b> Tokina (CanonMount)<br>
<b><font size="1">Equipment Model</font>:</b> AT-X Pro 11-20 F2.8<br>
<b><font size="1">Price (S$)</font>:</b> <font color="Red"><b>550</b></font> <br>
<b><font size="1">Description</font>:</b><br>
 No mold or fungus, it is ALWAYS kept in a drybox. Glass is mint. No drops, dinks, visible scratches and comes with UV filter. I do take care of my gear.<br>
<br>
It is in excellent condition and a great lens for aps-c users.<br>
<br>
Comes with originals.<br>
Box, hood, manual<br>
<br>
Dm for more images or info.<br>
<br>
<b><font size="1">Real Name</font>:</b> Marshal<br>
<b><font size="1">Contact Number</font>:</b> 8198<br>
<br>
<b><font size="1">Condition of Item</font>:</b> 10<br>
<b><font size="1">Warranty Status</font>:</b> Nil
                        </blockquote>
Stephen James
@sjames1958gm
Jul 12 2017 12:28
@jaanhio Did you try $(".restore").text();
Jianhao Tan
@jaanhio
Jul 12 2017 12:29
@sjames1958gm hi Stephen, yes i did. i got the whole chunk within that blockquote element.
i want to be able to retrieve the specific equipment type/equipment brand etc
could it be implemented this way to deter webscraping?
Stephen James
@sjames1958gm
Jul 12 2017 12:31
@jaanhio Ah, that is what I guessed after I looked more closely.
It could just be poorly formatted HTML.
Other than searching the text returned, not sure there is a good way.
Jianhao Tan
@jaanhio
Jul 12 2017 12:35
@sjames1958gm ah man. are you saying i have to specifically target the words i am looking for? (e.g Tokina, AT-X Pro etc)
Stephen James
@sjames1958gm
Jul 12 2017 12:36
@jaanhio Yes, unless you can modify the structure of the HTML to put those inside of elements that can be targetted.
Jianhao Tan
@jaanhio
Jul 12 2017 12:37
because the key terms i am looking for could vary slightly in different pages as its input by different users (e.g Tokina, Canon, Nikon etc)
Cato Myhre
@Zalmez
Jul 12 2017 12:39
Am I completely off course? I should be able to use the stringInt inbetween right?
function randInt(min, max){
    var randomInt = Math.floor((Math.random() * max) + min);

    return randomInt;
}
$("#quoteBtn").click(function(){
                //changes the color and assign it to a variable
                var bkColor = randomColor();
                //using the variable, change the background color of the quote block and the body background color
                //$("#quoteBlock").css("background-color", bkColor, "important");
                var randomInt = randInt(0, 100);
                var stringInt = randomInt.toString();
    $("body").css("background-color", bkColor, "important");

                $.getJSON("http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter["+ stringInt + "]=1&callback=", function(a) {
          $("body").append(a[0].content + "<p>— " + a[0].title + "</p>")
        });
});
Tjasa Kravcar
@TDandelion
Jul 12 2017 12:42
hey community!
I got stuck in basic algorithms section (return largest of four), I think I have to change one little thing to make it work - need help
Marianissimus
@Marianissimus
Jul 12 2017 12:44
@Zalmez with the commas like that you're just calling a string: "+ stringInt + ". I assume you want "+ " + stringInt
Cato Myhre
@Zalmez
Jul 12 2017 12:47
well @Marianissimus I want to use the value because it get's a new quote with the value.
the api suggest it like this:
$.getJSON("http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&callback=", function(a) {
  $("body").append(a[0].content + "<p>— " + a[0].title + "</p>")
});
changing the "post_per_Page" to a int it changes the quote
Marianissimus
@Marianissimus
Jul 12 2017 12:48
@Zalmez yes, you're not using the " properly. add them in pairs around the strings or html content - "string" + "<h1>" + variable + "string" - and don't add them around the variable
also use the + operator
ok, maybe i'm wrong, but i think this is your problem: ["+ stringInt + "]
Cato Myhre
@Zalmez
Jul 12 2017 12:52
the first " closes off the first part. count the " and you can see it's used correctly. unless I'm really off XD
Saif Ur Rahman
@saifsmailbox98
Jul 12 2017 12:55
@Zalmez Do you want to get multiple quotes or just a random quote?
Cato Myhre
@Zalmez
Jul 12 2017 12:55
just a random
Saif Ur Rahman
@saifsmailbox98
Jul 12 2017 12:56
@Zalmez Then everytime you getJSON with this url http://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&callback=, you get a new random quote
try visiting this link multiple times from your browser
Cato Myhre
@Zalmez
Jul 12 2017 12:57
@saifsmailbox98 I get the same one
Tjasa Kravcar
@TDandelion
Jul 12 2017 12:59
function largestOfFour(arr) {
  var max = 0;
  var array=[];

  for(var i = 0; i < arr.length; i++){
     for(var j = 0; j < arr[i].length; j++){
       if(arr[i][j] > max){
       max = arr[i][j];      
      }        
     }
        console.log(max);
        array.push(max);
  }

  console.log(array);
  return array;
 }
Cato Myhre
@Zalmez
Jul 12 2017 12:59
well I g2g. o/
I'll try later
Tjasa Kravcar
@TDandelion
Jul 12 2017 13:00
hey, so I have a problem with these basic algorithms, it is some minor thing, because two tests are successfull, and one is not
Saif Ur Rahman
@saifsmailbox98
Jul 12 2017 13:01
dasa.gif
@Zalmez
Tjasa Kravcar
@TDandelion
Jul 12 2017 13:02
any ideas how to get it right?
Saif Ur Rahman
@saifsmailbox98
Jul 12 2017 13:02
@TDandelion which challenge is that?
Tjasa Kravcar
@TDandelion
Jul 12 2017 13:03
@saifsmailbox98 Return Largest Numbers in Arrays
Saif Ur Rahman
@saifsmailbox98
Jul 12 2017 13:04
@TDandelion try initializing max with a value of arr[0][0] instead of 0
Tjasa Kravcar
@TDandelion
Jul 12 2017 13:04
it is returning right for two of three tests
Saif Ur Rahman
@saifsmailbox98
Jul 12 2017 13:05
@TDandelion put this inside of the first for loop max=arr[i][0]; as the first statement.
Tjasa Kravcar
@TDandelion
Jul 12 2017 13:06
@saifsmailbox98 thanks!! it works now :)
CamperBot
@camperbot
Jul 12 2017 13:06
tdandelion sends brownie points to @saifsmailbox98 :sparkles: :thumbsup: :sparkles:
:cookie: 759 | @saifsmailbox98 |http://www.freecodecamp.com/saifsmailbox98
Saif Ur Rahman
@saifsmailbox98
Jul 12 2017 13:06
@TDandelion :+1:
Tjasa Kravcar
@TDandelion
Jul 12 2017 13:07
i knew it was some minor thing :)
Saif Ur Rahman
@saifsmailbox98
Jul 12 2017 13:07
:smile:
Tjasa Kravcar
@TDandelion
Jul 12 2017 13:07
as it always is..
Will Waymel
@willwaymel
Jul 12 2017 13:09
anyone know the correct chat room for node.js and npm questions?
Saif Ur Rahman
@saifsmailbox98
Jul 12 2017 13:10
@willwaymel backend
Will Waymel
@willwaymel
Jul 12 2017 13:11
@saifsmailbox98 perfect, thanks
CamperBot
@camperbot
Jul 12 2017 13:11
willwaymel sends brownie points to @saifsmailbox98 :sparkles: :thumbsup: :sparkles:
:cookie: 760 | @saifsmailbox98 |http://www.freecodecamp.com/saifsmailbox98
Nick Janne
@njanne19
Jul 12 2017 13:12
Does anyone see why my activate on click method is not being called? https://codepen.io/njanne19/pen/LLMJdE?editors=0111
Victor Popescu
@VicPopescu
Jul 12 2017 13:15
@njanne19 Uncaught TypeError: Cannot read property 'props' of undefined
Nick Janne
@njanne19
Jul 12 2017 13:18
@VicPopescu I tried calling the activate component in the same div with a button instead and it worked. Is there a potential that simply divs are not clickable?
Victor Popescu
@VicPopescu
Jul 12 2017 13:20
@njanne19 divs are clickable
Stephen James
@sjames1958gm
Jul 12 2017 13:20
@njanne19 You are using this inside the map function which is different than the component this
@njanne19 {this.props.board.map((cell, i) => { use and arrow function.
Nick Janne
@njanne19
Jul 12 2017 13:21
@sjames1958gm Ahh I see. I also like your new profile pic. Is there a solution around this?
@sjames1958gm Thank you!
CamperBot
@camperbot
Jul 12 2017 13:21
njanne19 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8048 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
kumquatfelafel
@kumquatfelafel
Jul 12 2017 13:21
Criticism? (Feel free to be brutal)
function smallestCommons(arr) {
  if (arr[0] < 0 || arr[1] < 0)
    return NaN;
  var min = Math.min(arr[0],arr[1]);
  var max = Math.max(arr[0],arr[1]);
  var maxLCM = 1;
  for (var i = min; i <= max; i++) 
    maxLCM *= i; //This calculates the maximum possible LCM
  for (var j = 1; j < maxLCM/max; j++){
    var lcmFound = true;
    var lcm = max * j;
    for (var k = min; k < max; k++) 
      if (lcm % k !== 0)
        lcmFound = false;
    if (lcmFound)
      return lcm;
  }
  return maxLCM;
}
Nick Janne
@njanne19
Jul 12 2017 13:21
This is like the third time I've remade this stupid project but every time I learn more about react functionality
Saif Ur Rahman
@saifsmailbox98
Jul 12 2017 13:22
@kumquatfelafel :wave:
kumquatfelafel
@kumquatfelafel
Jul 12 2017 13:22
@saifsmailbox98 :wave:
Saif Ur Rahman
@saifsmailbox98
Jul 12 2017 13:24
@kumquatfelafel thats a lot of code.
Nick Janne
@njanne19
Jul 12 2017 13:36
play() {
    this.setState({running: 1});
    this.runGame();
  }
  pause() {
    this.setState({running: 0});
    console.log("Paused")
  }
  runGame() {
    if (this.state.running == 1) {
      console.log("running");
    }
  }
So I understand why my play button requires two clicks to do run game. This is because that state updates at every render not just whenever its called. Is there a way I can get around this so I can runGame immediately when play is called
Stephen James
@sjames1958gm
Jul 12 2017 13:49
@njanne19 Where else does runGame() get called?
Nick Janne
@njanne19
Jul 12 2017 13:50
@sjames1958gm No where else yet because I'm working on this bit by bit, but i'll eventually use run game with recursion to call itself until this.state.running ==0 (off)
Stephen James
@sjames1958gm
Jul 12 2017 13:50
@njanne19 Except you will need to run the game on a timer, or the screen will never update
Nick Janne
@njanne19
Jul 12 2017 13:50
But since state gets updated on the new render, I use a button to click play, but I have to click it twice in order to have everything re render and the state to update
@sjames1958gm I'm aware of that I just haven't gotten to it yet
Stephen James
@sjames1958gm
Jul 12 2017 13:51
@njanne19 then why not assume that runGame will only be called when running is 1?
The timer will be stopped when pause and started on play
Nick Janne
@njanne19
Jul 12 2017 13:54
@sjames1958gm Isn't that what I'm doing by planning on using recursion in the future for run game to call itself? The problem I'm having currently is that play sets the state of running, but the state is not finalized until the next render, so I have to hit play twice. Maybe I'm not totally understanding what you're saying
Diego Mayer
@Chrono79
Jul 12 2017 13:56
@kumquatfelafel are you sure you need the first loop? Nvm, I see what you did there
Stephen James
@sjames1958gm
Jul 12 2017 13:56
@njanne19 You have to make your game running asynchronous. Using a timer.
assuming the timer callback is runGame() then when you set running to 1 then the next call to runGame should get that.
Or you can start the timer in play() and stop the timer in pause() so that runGame is only called when the game is running
Diego Mayer
@Chrono79
Jul 12 2017 14:00
@kumquatfelafel your solution uses brute force (like mine), but you could save some loops to make it faster
Nick Janne
@njanne19
Jul 12 2017 14:01
@sjames1958gm I see what you're saying. Would it be best to define a timer as a method and then use setInterval?
Stephen James
@sjames1958gm
Jul 12 2017 14:02
@njanne19 The timer callback could be runGame and yes, setInterval is what I wouild use.
oluwole ilesanmi
@oluwoleilesanmi
Jul 12 2017 14:02
@sjames1958gm bro my code runs but doesnt pass test

var firstSuppliedNum = 1;
var secondSuppliedNum = 1;

function sumFibs(num) {
var sum= firstSuppliedNum + secondSuppliedNum;

if(sum > num){
return 0;

}
else if (sum % 2 > 0){
firstSuppliedNum = secondSuppliedNum;
secondSuppliedNum = sum;
return sum +sumFibs(num);

}
else if (sum % 2 == 0){
firstSuppliedNum = secondSuppliedNum;
secondSuppliedNum = sum;
if(firstSuppliedNum == 1)
return sum + sumFibs(num);
else
return sumFibs(num);

}
}
sumFibs(75025);

Stephen James
@sjames1958gm
Jul 12 2017 14:03
@oluwoleilesanmi FCC tests don't work with globals very well.
The globals will not get reset between tests.
@oluwoleilesanmi If you want recursion you may need to declare another function for that call from sumFibs
oluwole ilesanmi
@oluwoleilesanmi
Jul 12 2017 14:04
@sjames1958gm thanks bro, now i have rewrite this code .... wheeew
CamperBot
@camperbot
Jul 12 2017 14:04
oluwoleilesanmi sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8049 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
oluwole ilesanmi
@oluwoleilesanmi
Jul 12 2017 14:06
@sjames1958gm ok
Abhinav Mishra
@abhinav-m
Jul 12 2017 14:21
@sjames1958gm Hello :wave:
@sjames1958gm Mind lending your thoughts on this https://codepen.io/abhinavthinktank/full/dRwwNb/
Made tic tac toe with minimax, used animations for the first time
Stephen James
@sjames1958gm
Jul 12 2017 14:23
@abhinav-thinktank Looks pretty good - the animations, for me, are a bit slow. When you select O it takes a while to come up.
Abhinav Mishra
@abhinav-m
Jul 12 2017 14:25
@sjames1958gm Allright. Also, i noticed that my board moves a bit when one of the displays is shown
@sjames1958gm thanks for the quick review!
CamperBot
@camperbot
Jul 12 2017 14:25
abhinav-thinktank sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8050 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Diego Mayer
@Chrono79
Jul 12 2017 14:27
@abhinav-thinktank Look at the developer tools console, it complains about Uncaught TypeError: Cannot set property '1' of undefined
Abhinav Mishra
@abhinav-m
Jul 12 2017 14:27
@Chrono79 Oh damn i thought i fixed that
@Chrono79 :\
@Chrono79 I'll need to take a look again, ty for pointing that out
CamperBot
@camperbot
Jul 12 2017 14:28
abhinav-thinktank sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4482 | @chrono79 |http://www.freecodecamp.com/chrono79
Abhinav Mishra
@abhinav-m
Jul 12 2017 14:28
@Chrono79 Anything else?
Diego Mayer
@Chrono79
Jul 12 2017 14:29
I'm seeing some weird behaviour after some matches
Abhinav Mishra
@abhinav-m
Jul 12 2017 14:29
@Chrono79 oh, do you have a screenshot
Diego Mayer
@Chrono79
Jul 12 2017 14:30
I reloaded it and I'm trying to see if it happens again
Abhinav Mishra
@abhinav-m
Jul 12 2017 14:30
@Chrono79 ok
@Chrono79 Let me know if it does!
Diego Mayer
@Chrono79
Jul 12 2017 14:31
@abhinav-thinktank It can be related to the animations duration
Abhinav Mishra
@abhinav-m
Jul 12 2017 14:32
@Chrono79 Allright, what exactly is happening
Diego Mayer
@Chrono79
Jul 12 2017 14:33
I played it faster and then sometimes the X or O from the start are still present when I'm playing and the blinking Tic Tac Toe title is still there when I lose
Abhinav Mishra
@abhinav-m
Jul 12 2017 14:33
@Chrono79 Oh ok let me do that , thanks for reviewing!
CamperBot
@camperbot
Jul 12 2017 14:33
abhinav-thinktank sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: abhinav-thinktank already gave chrono79 points
Diego Mayer
@Chrono79
Jul 12 2017 14:34
No problem :+1:
Abhinav Mishra
@abhinav-m
Jul 12 2017 14:35
@Chrono79 Hmm I think the animation duration is an issue with the tic tac toe title, i can't replicate the X or O from the start one, The AI automatically places an X when you select 0 is that what you were talking about
Diego Mayer
@Chrono79
Jul 12 2017 14:36
No, I meant the two buttons when you select X or O for yourself
Sometimes they won't go away when the board appears, or they do go away, but a while later
Abhinav Mishra
@abhinav-m
Jul 12 2017 14:37
@Chrono79 oooooh ill try to replicate that
studentzero
@studentzero
Jul 12 2017 14:37
'''
CamperBot
@camperbot
Jul 12 2017 14:37
:bulb: to format code use backticks! ``` more info
Diego Mayer
@Chrono79
Jul 12 2017 14:37
I would use O instead of 0 in the board
depending the font, O is rounder
studentzero
@studentzero
Jul 12 2017 14:38

```function findLongestWord(str) {
var words = str.split(' ');
var maxLength = 0;

for (var i = 0; i < words.lenght; i++); {
if (words[i].length > maxLength) {
maxLength = words[i].length;
}
}
return maxLength;
}

findLongestWord("The quick brown fox jumped over the lazy dog");

Diego Mayer
@Chrono79
Jul 12 2017 14:39
@studentzero length, in the loop condition
Abhinav Mishra
@abhinav-m
Jul 12 2017 14:39
@Chrono79 ok , i'll see to that, and i can't figure out why my animations are coming so slowly. The TIC TAC TOE one gets messed up alot
studentzero
@studentzero
Jul 12 2017 14:39
function findLongestWord(str) {
  var words = str.split(' ');
  var maxLength = 0;

  for (var i = 0; i < words.lenght; i++); {
    if (words[i].length > maxLength) {
      maxLength = words[i].length;
    }
  }
  return maxLength;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
I don't get why it's not working. Keep getting "0"
Abhinav Mishra
@abhinav-m
Jul 12 2017 14:39
@studentzero spelling of length
@studentzero words.length
studentzero
@studentzero
Jul 12 2017 14:40
Argh stupid mistakes. Need coffee. Thanx @Chrono79
CamperBot
@camperbot
Jul 12 2017 14:40
studentzero sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4483 | @chrono79 |http://www.freecodecamp.com/chrono79
studentzero
@studentzero
Jul 12 2017 14:40
thanx @abhinav-thinktank
CamperBot
@camperbot
Jul 12 2017 14:40
studentzero sends brownie points to @abhinav-thinktank :sparkles: :thumbsup: :sparkles:
:cookie: 393 | @abhinav-thinktank |http://www.freecodecamp.com/abhinav-thinktank
Abhinav Mishra
@abhinav-m
Jul 12 2017 14:40
@studentzero no problem :)
happens to the best of us
BlakeRB
@BlakeRB
Jul 12 2017 14:40
hey all, I am having some trouble pulling some information from an object and getting it to display in my html position for project

function Quotes(quote){
this.quote = quote;
}
Quotes.prototype.displayQuotes = function(){
console.log(this.quote);
};

var q1 = new Quotes('"We have enough people who tell it like it is—now we could use a few who tell it like it can be."' + ' '+ 'By ' + ' '+ 'Robert Orben');

var q2 = new Quotes('"Don’t ask what the world needs. Ask what makes you come alive, and go do it. Because what the world needs is people who have come alive."' + ' '+ 'By '+ ' ' +' Howard Thurman');

var q3 = new Quotes('"Motivation is when your dreams put on work clothes."' + ' '+ 'By ' + ' ' +' Benjamin Franklin');

var q4 = new Quotes('\"If you can\'t do great things, do small things in a great way.' + ' '+ 'By ' + ' ' +
'Napoleon Hill');

var q5 = new Quotes('"Be nice to people on your way up because you\'ll meet them on your way down." ' + ' ' + 'By ' + ' '+
'Wilson Mizner');

var quotes = [q1, q2, q3, q4, q5];

/// adding new quote
function nextQuote(){

var q = Math.floor(Math.random() * quotes.length);
quotes[q].displayQuotes();

}

var setupEventListeners = function(){

document.querySelector('.button').addEventListener('click', nextQuote);
};

$(document).ready(function() {
nextQuote();

studentzero
@studentzero
Jul 12 2017 14:41
I don't really get why I need ```
Diego Mayer
@Chrono79
Jul 12 2017 14:41
@abhinav-thinktank another minor style adjustment I'd do is changing the cross of the mouse pointer to the hand
studentzero
@studentzero
Jul 12 2017 14:41
i < words.length
Diego Mayer
@Chrono79
Jul 12 2017 14:42
@studentzero that's the loop's end condition, or better put, the run while that is true
You want to check all words
studentzero
@studentzero
Jul 12 2017 14:43
Ow I see now! It's all so simple after it clicks in place in my head. Many thanx @Chrono79
CamperBot
@camperbot
Jul 12 2017 14:43
studentzero sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: studentzero already gave chrono79 points
Moisés Man
@moigithub
Jul 12 2017 14:46
@BlakeRB u calling console.log to show ur quotes on displayQuotes method
Nick Janne
@njanne19
Jul 12 2017 14:46
  componentDidMount() {
    this.clearGameBoard();
    this.initialSetup();
    this.timer();
  }
  timer() {
    setInterval(function() {
      console.log("Interval");
      this.runGame();
    }, speed);
  }
Is there something wrong with my timer method?
BlakeRB
@BlakeRB
Jul 12 2017 14:47
@moigithub instead of console.log should i be storing the value and then calling the value later?
Abhinav Mishra
@abhinav-m
Jul 12 2017 14:47
@Chrono79 Ok thanks!
CamperBot
@camperbot
Jul 12 2017 14:47
abhinav-thinktank sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: abhinav-thinktank already gave chrono79 points
Moisés Man
@moigithub
Jul 12 2017 14:48
@BlakeRB if u wanna put on ur html DOM.. probably u need to add a placeholder to ur html..
ie. <div id="results"></div>
(since u already using jquery) do something like
$("#results").html(nextQuote())
and modify ur nextQuote function to RETURN a quote
BlakeRB
@BlakeRB
Jul 12 2017 15:01
@moigithub i understand the change but I am confused as to where it would go, do i nolonger need the console.log -- also when returning a quote am i geting rid of the diisplay?

@moigithub function nextQuote(q, result){

var q = Math.floor(Math.random() * quotes.length);

var result = [q];
return result[];

}

??
because now i am geting the random result but not the quote in the information,
Stephen James
@sjames1958gm
Jul 12 2017 15:06

@njanne19 Add bind to this for the function

setInterval(function() {
      console.log("Interval");
      this.runGame();
    }.bind(this), speed);

Or the this inside of that function won't be correct

Moisés Man
@moigithub
Jul 12 2017 15:06

this was ur original code posted above.. added a return

function nextQuote(){
    var q = Math.floor(Math.random() * quotes.length);
    return quotes[q].displayQuotes();
}

@BlakeRB
soo when u call ur function..those values get "returned" to the line whch started the call
ie: var q = nextQuote();
q will contain a quote

Nick Janne
@njanne19
Jul 12 2017 15:06
@sjames1958gm I worked it out, and then changed my interval function to use a fat arrow, thanks for the help I'll work on the neighbors logic later
CamperBot
@camperbot
Jul 12 2017 15:06
njanne19 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8051 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 12 2017 15:07
@njanne19 :+1: Makin' good progress
Nick Janne
@njanne19
Jul 12 2017 15:07
I've probably redone this project 5 times now but I think this time I'll finally get it
then I'll still have another project for react after this lma
Stephen James
@sjames1958gm
Jul 12 2017 15:10
@njanne19 I found this one to be fun.
https://codepen.io/silgarth/full/vKAzOm/
Sonja
@sonjaSch
Jul 12 2017 15:11
hi there i'm working on the calculator project and i struggle with the keyboard input
Boris Yordanov
@borisyordanov
Jul 12 2017 15:11
@sonjaSch what's the problem exactly?
Sonja
@sonjaSch
Jul 12 2017 15:12
@borisyordanov i really dont now how to handle both the click event and the keyboard input
@borisyordanov I'ts far from beeing finished... but i'd like to fix this
Jan Shah
@JanShah
Jul 12 2017 15:13
@sonjaSch are you making it so that a user can type numbers as well as click the buttons on screen?
Boris Yordanov
@borisyordanov
Jul 12 2017 15:14
@sonjaSch those are two separate events. This is the event for keypresses - https://developer.mozilla.org/en-US/docs/Web/Events/keydown . Also to find out what key was pressed you can use the keyCode prop - https://www.w3schools.com/jsref/event_key_keycode.asp
studentzero
@studentzero
Jul 12 2017 15:14
Working on the capitalize first letter assignment. Got so far. Wondering is it's possible to capitalize in the for loop or that I'm completely going the wrong way.

function titleCase(str) {
  var lowerWords = str.toLowerCase();
  var words = lowerWords.split(' ');
  var count = words.length;

  for (var i = 0; i <= count; i++) {

  }
  return words;
}

titleCase("I'm a little Tea pot");
Sonja
@sonjaSch
Jul 12 2017 15:14
@CentropyIT well i try :sweat_smile:
Boris Yordanov
@borisyordanov
Jul 12 2017 15:15
@studentzero yes, you need to iterate trough your word array and capitalize the first letter of each word in the array
BlakeRB
@BlakeRB
Jul 12 2017 15:15
@moigithub if the quotes variable is defined outside of the function i can not return in inside of the function, so should i declaire it as a variable inside of the function?
Nick Janne
@njanne19
Jul 12 2017 15:16
@studentzero You can use it in the for loop, I wouldn't even bother using the lowerWords variable and instead use the charAt string method to isolate the first letter in every word
Jan Shah
@JanShah
Jul 12 2017 15:17
@sonjaSch have you got either going? like keyboard input or mouse presses?
studentzero
@studentzero
Jul 12 2017 15:18
So like words[i].charAt(0).toCapitalize
@njanne19
Nick Janne
@njanne19
Jul 12 2017 15:20
@studentzero That's exactly right, except the method for capitalization is called .toUpperCase()
Sonja
@sonjaSch
Jul 12 2017 15:21
@CentropyIT mousepress works with the jquery click function, and i can display the numbers from the keyboard too, but i struggle with arithmetic operations
Moisés Man
@moigithub
Jul 12 2017 15:21
@BlakeRB according to ur code.. ur quotes variable is defined outside.. so its global
any functions can have access to it
studentzero
@studentzero
Jul 12 2017 15:21
I've got it like so. But it gives "words[i] is undifined"
function titleCase(str) {
  var lowerWords = str.toLowerCase();
  var words = lowerWords.split(' ');
  var count = words.length;

  for (var i = 0; i <= count; i++) {
    words[i].charAt(0).toUpperCase();
  }
  return words;
}

titleCase("I'm a little Tea pot");
Jason Luboff
@JLuboff
Jul 12 2017 15:22
@studentzero your loop goes to far. Use i < count;
studentzero
@studentzero
Jul 12 2017 15:22
Ow yeah I forget about the start at zero thing. But it still doesn't capitalize.
Jason Luboff
@JLuboff
Jul 12 2017 15:23
@studentzero Correct. Strings are immutable. You need to rebuild the entire string
Jan Shah
@JanShah
Jul 12 2017 15:24
@sonjaSch I used eval on a joined string of the user validated inputs
probably not the best solution... but wth, it works
BlakeRB
@BlakeRB
Jul 12 2017 15:25
@moigithub yes it has no bugs but it is not displaying any functions or allowing me to use my event listiener, which is odd
Sonja
@sonjaSch
Jul 12 2017 15:25
@CentropyIT i read bout eval but i'm not really familiar with it...
Jan Shah
@JanShah
Jul 12 2017 15:26
@sonjaSch for my purposes, eval takes the string, say '10+10' and returns the sum of it
eval('10+10') returns 20
Sonja
@sonjaSch
Jul 12 2017 15:27
@CentropyIT hm ok and so u used regex to check the input?
Moisés Man
@moigithub
Jul 12 2017 15:28
are u working on codepen ? @BlakeRB
share link easier to test/check
BlakeRB
@BlakeRB
Jul 12 2017 15:28
@moigithub yes
Jan Shah
@JanShah
Jul 12 2017 15:28
I used .includes to create a valid array and check against that before pushing it to the string
@sonjaSch
Jan Shah
@JanShah
Jul 12 2017 15:29
['+', '-', '/','*'].includes(data)
@sonjaSch
Sonja
@sonjaSch
Jul 12 2017 15:30
@CentropyIT oh this look good didnt know
Jan Shah
@JanShah
Jul 12 2017 15:30
and ['=', 'Enter'].includes(data) to do the final run
data is the user input
Innocent Tauzeni
@Telthem89
Jul 12 2017 15:32
hello team
studentzero
@studentzero
Jul 12 2017 15:32
I can capitalize a letter outside the for loop. But not in it?

function titleCase(str) {
  var lowerWords = str.toLowerCase();
  var first = lowerWords.charAt(0).toUpperCase();
  var words = lowerWords.split(' ');
  var count = words.length;

  for (var i = 0; i < count; i++) {
    words[i].charAt(0).toUpperCase();
  }
  return words;
}

titleCase("I'm a little Tea pot");
Jason Luboff
@JLuboff
Jul 12 2017 15:33
@studentzero Inside your loop you aren't assigning it to anything
Innocent Tauzeni
@Telthem89
Jul 12 2017 15:33
i love codecamp
kumquatfelafel
@kumquatfelafel
Jul 12 2017 15:33
@saifsmailbox98 @Chrono79 thanks. Yup, is brute force :p
I was thinking the first loop is probably unnecessary. Will have to think about how to cut down a little bit there. Looking at, I'm noticing can also break the inner loop when lcmFound = false (no point checking entire range at that point).
CamperBot
@camperbot
Jul 12 2017 15:33
kumquatfelafel sends brownie points to @saifsmailbox98 and @chrono79 :sparkles: :thumbsup: :sparkles:
:cookie: 761 | @saifsmailbox98 |http://www.freecodecamp.com/saifsmailbox98
:star2: 4484 | @chrono79 |http://www.freecodecamp.com/chrono79
Innocent Tauzeni
@Telthem89
Jul 12 2017 15:33
love algorithm
Diego Mayer
@Chrono79
Jul 12 2017 15:34
@kumquatfelafel one way to cut it down is realizing that the lcm is a multiple of the max number of the range and max-1
Not much improvement, but better than nothing ;)
BlakeRB
@BlakeRB
Jul 12 2017 15:35
@moigithub thank you for the help, have you seen the link i sent to codepen?
CamperBot
@camperbot
Jul 12 2017 15:35
blakerb sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3495 | @moigithub |http://www.freecodecamp.com/moigithub
kumquatfelafel
@kumquatfelafel
Jul 12 2017 15:37
@Chrono79 assuming min !== max (which I didn't even bother with anyway), yer right :) Less checks for that
BlakeRB
@BlakeRB
Jul 12 2017 15:37
@moigithub in the Quotes.prototype, should i not be console.loging this but instead displaying the value? with a for loop?
Jahid Bin Kibria
@jahidbinkibria
Jul 12 2017 15:38
i have made random quote machine(FCC) it works on localhost but does't work on codepen
awwsoclose
@awwsoclose
Jul 12 2017 15:39
Hi everyone, I'm currently on the palindrome challenge. Some of the palindromes pass the test, but 4 of them aren't. here's my code
function palindrome(str){
var newStr = str.replace(/[^0-9a-z]/gi,''); 
  var splitStr = newStr.split("");
  var reverseArray = splitStr.reverse();
  var joinStr = reverseArray.join("");
  var str2 = joinStr.toLowerCase();
  for (i=0; i< str2.length; i++){
    for(j=0; j< str.length; j++){
      if(str2[i] === (str[j])){
        return true;
      } else{
        return false;
      }
    }
  }
}
Jahid Bin Kibria
@jahidbinkibria
Jul 12 2017 15:40
Jan Shah
@JanShah
Jul 12 2017 15:41
@awwsoclose are you sure you need 2 loops there?
str[i] is surely the same position as str2[i]?
kumquatfelafel
@kumquatfelafel
Jul 12 2017 15:41
@awwsoclose also, as soon as you return, it will end function and stop checking the values.
(is there an instance it won't return after checking first value)?
Jan Shah
@JanShah
Jul 12 2017 15:43
@kumquatfelafel one of the solutions there is to only return false in the loop if two values don't match, it breaks the loop but that's a good thing in this case as it needn't iterate over the whole array
kumquatfelafel
@kumquatfelafel
Jul 12 2017 15:43
@CentropyIT Agreed. The issue arises when returning true before checking entire. :)
awwsoclose
@awwsoclose
Jul 12 2017 15:43
i'm stuck on a code to check to see if the letters match
Jan Shah
@JanShah
Jul 12 2017 15:44
@kumquatfelafel yeah, looking at it again I can see it
Moisés Man
@moigithub
Jul 12 2017 15:44
@BlakeRB displayquote prototype should also return
and on ur click listener u should change the dom
$('#quotes').html(nextQuote());
u need to create a new funciton to attach to ur click listener
kumquatfelafel
@kumquatfelafel
Jul 12 2017 15:44
@CentropyIT though yeah, the nested for is also definitely an issue here
Jan Shah
@JanShah
Jul 12 2017 15:46
@awwsoclose I think it's both the combination of 2 for loops (you only need one for both arrays) and return a true value in the loop, which can break the loop at 0
Margaret
@Margaret2
Jul 12 2017 15:46
@awwsoclose you need to also remove _ (underscore)
awwsoclose
@awwsoclose
Jul 12 2017 15:47
i hate this lol
kumquatfelafel
@kumquatfelafel
Jul 12 2017 15:47
@Margaret2 Their regex achieves this effect.
Jan Shah
@JanShah
Jul 12 2017 15:47
@awwsoclose you are close!
kumquatfelafel
@kumquatfelafel
Jul 12 2017 15:47
_ != 0-9 or a-z
@Margaret2 ^ in there means not.
Margaret
@Margaret2
Jul 12 2017 15:47
oh lol
awwsoclose
@awwsoclose
Jul 12 2017 15:48
okay so i should not use if/else right
Margaret
@Margaret2
Jul 12 2017 15:50
@awwsoclose really you don't need a loop at all, just lowercase the string, reverse it, check if the reversed string === the original string (lowercased)
don't overthink
BlakeRB
@BlakeRB
Jul 12 2017 15:51
@moigithub i am a bit confused with that bit of infomation sorry
kumquatfelafel
@kumquatfelafel
Jul 12 2017 15:52
@awwsoclose There is a way you can use a for loop and an if statement with return (since return halts the function) to kind of "imply" an else statement. Though as @Margaret2 points out you're making things a bit more difficult for yourself. Though I don't necessarily think that's a bad thing. Good to think about how you might compare individual characters of string ;)
BlakeRB
@BlakeRB
Jul 12 2017 15:52
@moigithub what should my display be returning? the var quotes? or the vaule generated by the next quote function?
kumquatfelafel
@kumquatfelafel
Jul 12 2017 16:00

@awwsoclose Another thing is you have to take another look at where you have toLowerCase. Remember, toLowerCase will not modify original string (strings are immutable)... it will return a new string.

You can also chain certain functions to cut down on variables/lines of code. For example, since toLowerCase returns a string, you can call another string function on the returned value... e.g. suppose you wanted to call toUpperCase afterwards to highlight the futility of certain actions :p ... you could do it like this

var str = "Hello World";
str = str.toLowerCase().toUpperCase(); // str now holds HELLO WORLD
awwsoclose
@awwsoclose
Jul 12 2017 16:04
when i set it up like that, someone said that i wasn't holding my values
awwsoclose
@awwsoclose
Jul 12 2017 16:13
could i do this:
var newStr = str.replace(/[^0-9a-z]/gi,'').split("").join("")
Saif Ur Rahman
@saifsmailbox98
Jul 12 2017 16:13
@awwsoclose why split and join both?
awwsoclose
@awwsoclose
Jul 12 2017 16:13
i have no idea lol
kumquatfelafel
@kumquatfelafel
Jul 12 2017 16:14
@awwsoclose Well... you can, but I think you may be forgetting a step (which makes this as futile as toLowerCase().toUpperCase(), as @saifsmailbox98 notes). Check your original code. ;)
Saif Ur Rahman
@saifsmailbox98
Jul 12 2017 16:14
@awwsoclose split("") converts the string to array, and join("") converts an array to a string.
BlakeRB
@BlakeRB
Jul 12 2017 16:14
@moigithub i got the guote to generate in the field, thank you, now i just need to work on geting the function back on the event listener
CamperBot
@camperbot
Jul 12 2017 16:14
blakerb sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:warning: blakerb already gave moigithub points
Saif Ur Rahman
@saifsmailbox98
Jul 12 2017 16:16
@awwsoclose yeah you need to have the whole string in only one of the caps, you that it's easy to compare with the reversed version.
awwsoclose
@awwsoclose
Jul 12 2017 16:17
and replace just takes out all of the non-letters right?
Saif Ur Rahman
@saifsmailbox98
Jul 12 2017 16:17
@awwsoclose
  • lowercase the original string(or uppercase)
  • remove non-alphanumeric characters from the original string
  • split the original string to an array
  • reverse the array
  • join the array to create back a string
  • compare the string with the original string
kumquatfelafel
@kumquatfelafel
Jul 12 2017 16:18
@awwsoclose :point_up: Your particular replace is removing non-alphanumeric
But it could replace other stuff given different arguments.
Saif Ur Rahman
@saifsmailbox98
Jul 12 2017 16:19
@awwsoclose the regex you are using /place_for_regex/ is enough to remove those non ALPHA-NUMERICS
awwsoclose
@awwsoclose
Jul 12 2017 16:21
is vary only for arrays?
oh my dear lord
i just did it
i'm just about to cry
kumquatfelafel
@kumquatfelafel
Jul 12 2017 16:21
@awwsoclose Though yeah, pay attention to @saifsmailbox98 list of order of functions, and note that in certain cases, chaining may be appropriate, but in others it might actually be detrimental if you're not careful

is vary only for arrays?

vary?

awwsoclose
@awwsoclose
Jul 12 2017 16:22
var*
function palindrome(str){
  str = str.toLowerCase();
  str = str.replace(/[^0-9a-z]/gi,''); 
  var splitStr = str.split("");
  var reverseArray = splitStr.reverse();
  str2 = reverseArray.join("");
  for (i=0; i< str2.length; i++){
      if(str2 === str){
        result = true;
      } else{
        result = false;
      }
      return result;
    }
}
you guys are so amazing
Saif Ur Rahman
@saifsmailbox98
Jul 12 2017 16:23
@awwsoclose var is used to create/defined new variable.
Jason Luboff
@JLuboff
Jul 12 2017 16:23
@awwsoclose There is not need for your for loop, just do a comparison of str2 to str
kumquatfelafel
@kumquatfelafel
Jul 12 2017 16:23
:point_up:
awwsoclose
@awwsoclose
Jul 12 2017 16:24
i'm still basking in my gloriusness \m/
took me a freaking week, but i finally freaking passed it
Saif Ur Rahman
@saifsmailbox98
Jul 12 2017 16:25
:metal: you rock @awwsoclose
awwsoclose
@awwsoclose
Jul 12 2017 16:25
oh god "find the longest word" !.~
!.!*
Pieter Stokkink
@forkerino
Jul 12 2017 16:27
A week!?
That's persistence
awwsoclose
@awwsoclose
Jul 12 2017 16:28
well, i mean, i wasn't working on it 24/7
Jason Luboff
@JLuboff
Jul 12 2017 16:29
@forkerino :wave:
kumquatfelafel
@kumquatfelafel
Jul 12 2017 16:29

@awwsoclose so here's examples where you can chain. ;)

str = str.toLowerCase().replace(blah);
var paliPossibly = str.split('').reverse().join('');

Also, str1 === str2 actually returns value of true or false. So in these kinds of cases where return of true or false entirely dependent upon result of condition, can return something like str1 === str2 instead.

Pieter Stokkink
@forkerino
Jul 12 2017 16:30
It doesn't really matter how long it takes. I'm just impressed. I would've given up a lot sooner. @awwsoclose
@JLuboff @kumquatfelafel :wave:
awwsoclose
@awwsoclose
Jul 12 2017 16:30
my dad used to call me a stubborn biotch lmao
Jason Luboff
@JLuboff
Jul 12 2017 16:30
@forkerino How's it going?
Pieter Stokkink
@forkerino
Jul 12 2017 16:31
Good. I got a killer new laptop
You?
Jason Luboff
@JLuboff
Jul 12 2017 16:33
@forkerino Eh. It's been a stressful week and a half thus far.
How killer we talking?
kumquatfelafel
@kumquatfelafel
Jul 12 2017 16:34

well, i mean, i wasn't working on it 24/7

@awwsoclose Lies! I can see those dark circles around your eyes.

...

On a completely unrelated note, ignore those sneakers sticking out from underneath the curtains. There is definitely no one there! :o :p

Pieter Stokkink
@forkerino
Jul 12 2017 16:35
16 g ram, 512 ssd, latest i7 @JLuboff
awwsoclose
@awwsoclose
Jul 12 2017 16:35
i was hoping you couldn't see >.>
kumquatfelafel
@kumquatfelafel
Jul 12 2017 16:35
haha
Jason Luboff
@JLuboff
Jul 12 2017 16:35
@forkerino Sweet
Terry Hayes
@TCHayes
Jul 12 2017 16:35
Hi everyone, I'm working on the "Set" data structure problems, and having some difficulty with the union problem (http://beta.freecodecamp.com/en/challenges/coding-interview-data-structure-questions/perform-a-union-on-two-sets). Because the collections are variables written like var collection = []; vs this.collection = [];, I'm not sure how to access each set's collection when writing the union method. I'm sure it's there's an obvious answer, but I'm not seeing it!
kumquatfelafel
@kumquatfelafel
Jul 12 2017 16:35
@JLuboff any signs of possible improvement/ramifications in future?
Pieter Stokkink
@forkerino
Jul 12 2017 16:35
It's :racehorse: fast
Jason Luboff
@JLuboff
Jul 12 2017 16:37
@kumquatfelafel Did I talk about my grandma before? If so, and thats what you're asking about...still no word on exactly what will be done..
@forkerino I bet. My work computer is similar spec.Although last gen (I think) i7
kumquatfelafel
@kumquatfelafel
Jul 12 2017 16:38
@JLuboff oh. Thought this was :fish: related.
Terry Hayes
@TCHayes
Jul 12 2017 16:38
If it was this.collection, I could use set2.collection and this.collection to access their respective collections, but I'm not sure how to access them with the given implementation.
Jason Luboff
@JLuboff
Jul 12 2017 16:38
@kumquatfelafel oooh..ya..that. We got a bunch of people who got sent the same phish email but no one that we're aware of actually fell for it this time
Pieter Stokkink
@forkerino
Jul 12 2017 16:38
@JLuboff it's about 2kg, so nice and light as well
kumquatfelafel
@kumquatfelafel
Jul 12 2017 16:39
@JLuboff But hope things work out for you on that front as well (whatever's happening)
Jason Luboff
@JLuboff
Jul 12 2017 16:40
@kumquatfelafel Thanks. Ya I've been a little distracted lately, my grandma's been in the hospital for the last week and a half with heart issues. Its been rough
CamperBot
@camperbot
Jul 12 2017 16:40
jluboff sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 458 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Jason Luboff
@JLuboff
Jul 12 2017 16:40
@forkerino Awesome. Work supplied or personal?
Pieter Stokkink
@forkerino
Jul 12 2017 16:41
@JLuboff work supplied. Hope everything works out for your grandmother.
Jason Luboff
@JLuboff
Jul 12 2017 16:42
@forkerino Even better. Thanks. She's a fighter.. keeps saying she'll be here to meet my son. Fingers crossed.
CamperBot
@camperbot
Jul 12 2017 16:42
jluboff sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2823 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Jul 12 2017 16:43
@JLuboff Let's hope so. My grandmother got to meet our daughter. She was very proud.
Jason Luboff
@JLuboff
Jul 12 2017 16:45
There's nothing more that I want right now then that, but I just have to trust that the doctors will be able to do something. But..enough talking about that.
Do they let you install anything you want on your laptop or does an admin have to do so?
awwsoclose
@awwsoclose
Jul 12 2017 16:45
is this possible
function findLongestWord(str) {
var wordArray = str.split("");
wordArray[0].length();
}
Jason Luboff
@JLuboff
Jul 12 2017 16:46
@awwsoclose You would be getting the length of a single letter there, but its not assigned to anything
Pieter Stokkink
@forkerino
Jul 12 2017 16:46
@JLuboff I can do what I want. We're too small to have an admin. :joy:
Jason Luboff
@JLuboff
Jul 12 2017 16:47
@forkerino Lol better for you but may not be best for all users to have that power
Mark
@vinarius
Jul 12 2017 16:48
@awwsoclose you would pass in an array, not a string to that function, then loop through the length of the array and return the element with the largest length
then throw in some if statements if there are multiple elements with the same, longest length
Pieter Stokkink
@forkerino
Jul 12 2017 16:49
Of course, but there's a culture of trust (they do ask you to encrypt everything related to work, obviously) and they won't hire a noob @JLuboff
awwsoclose
@awwsoclose
Jul 12 2017 16:49
as you can tell, i'm the type of person that needs crayons and construction paper to explain stuff to me
Mark
@vinarius
Jul 12 2017 16:49
haha me too!
kumquatfelafel
@kumquatfelafel
Jul 12 2017 16:49
@awwsoclose Well... you have a decent "starting point", but split will split for character sequence that match, or in case of empty string (which is what you provided as argument, i.e. in parentheses) will split every single character into separate element/cell in array. Rather than each character, we want each word to be an element of array. Are there any characters commonly found in between words? Also, length is a property but not a function so you don't want to use ()... just .length is fine
awwsoclose
@awwsoclose
Jul 12 2017 16:50
so i need to change my starting point?
Jason Luboff
@JLuboff
Jul 12 2017 16:50
@forkerino Thats good that they require you to encrypt everything.
Mark
@vinarius
Jul 12 2017 16:53
function findLongestWord(arr) {
let longestWord = "";
for(let i = 0; i < arr.length; i++){
if(arr[i].length > longestWord){
longestWord = arr[i];
}
}
}
Jason Luboff
@JLuboff
Jul 12 2017 16:53
@vinarius You can't compare a number to a string
Kelechi Chinaka
@ke1echi
Jul 12 2017 16:54
:wave: guys
Stephen James
@sjames1958gm
Jul 12 2017 16:54
@kelechy :wave:
Did you get a handle on arguments?
Kelechi Chinaka
@ke1echi
Jul 12 2017 16:55
i know an arguments is array-like but how do i get the last element on the arguments list
Mark
@vinarius
Jul 12 2017 16:55
I'm sorry, I should probably not just give away answers like that..
Stephen James
@sjames1958gm
Jul 12 2017 16:55
@kelechy arguments has the same concept of the array that arguments.length - 1 is the last element.
Kelechi Chinaka
@ke1echi
Jul 12 2017 16:56
thanks so much for the concern, just got home now and had to rush to the pc, i must finish that kata @sjames1958gm
CamperBot
@camperbot
Jul 12 2017 16:56
kelechy sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8052 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Mark
@vinarius
Jul 12 2017 16:56
I just get excited
Stephen James
@sjames1958gm
Jul 12 2017 16:56
@kelechy arguments is an object where the keys are numbers from 0 to arguments.length - 1
Mark
@vinarius
Jul 12 2017 16:57
Has anyone worked on any of the advanced algorithms for front end?
Stephen James
@sjames1958gm
Jul 12 2017 16:58
@vinarius yes
Mark
@vinarius
Jul 12 2017 16:59
They've been fun so far
Stephen James
@sjames1958gm
Jul 12 2017 17:00
@vinarius Tic Tac Toe was fun, creating an AI that was strong, but beatable
Jason Luboff
@JLuboff
Jul 12 2017 17:00
TTT was fun. I hated simon and pomodoro
Mark
@vinarius
Jul 12 2017 17:00
I used canvas for my clock
Kelechi Chinaka
@ke1echi
Jul 12 2017 17:01
wow its begining to make sense now @sjames1958gm "array-like"
Mark
@vinarius
Jul 12 2017 17:01
i think simon was my favorite tho
Jason Luboff
@JLuboff
Jul 12 2017 17:01
I used canvas for my TTT and clock
kumquatfelafel
@kumquatfelafel
Jul 12 2017 17:01
I feel like simon needs extra stuff... say... fish randomly floating by.
Mark
@vinarius
Jul 12 2017 17:02
I'm probably going to redo my portfolio home page at some point in canvas and do some cool background animation for the wow factor
Kelechi Chinaka
@ke1echi
Jul 12 2017 17:02
function last(list){
  return arguments[arguments.length - 1]
}
so i did this an got the last argument @sjames1958gm
awwsoclose
@awwsoclose
Jul 12 2017 17:02
alright i guess it's a good thing that that solution isn't working for me
Stephen James
@sjames1958gm
Jul 12 2017 17:02
@kelechy Check
Mark
@vinarius
Jul 12 2017 17:02
@awwsoclose the gist is missing one line of code, you can definitely figure it out
Kelechi Chinaka
@ke1echi
Jul 12 2017 17:02
yea it gets the last @sjames1958gm
kumquatfelafel
@kumquatfelafel
Jul 12 2017 17:09
@vinarius It's a bit more than one line, actually, on basis of how freecodecamp is testing function.
@awwsoclose You may (probably will) see part of what was provided in that solution (so if you come up with something similar somewhere along the line, don't automatically assume you're doing something wrong). That being said this function doesn't quite do exactly what FCC is telling you to do in the function. See if can figure things out. ;)
Kelechi Chinaka
@ke1echi
Jul 12 2017 17:15
function last(list){
 if (Array.isArray(list) == true) {
   return list[list.length - 1]
 }
 if (typeof(list) == 'string') {
   return list.split('')[list.length - 1];
 }
   return arguments[arguments.length - 1] 
}
passes all test but fails 2 random test, what am i doing wrong @sjames1958gm
Stephen James
@sjames1958gm
Jul 12 2017 17:16
@kelechy can you link the kata?
kumquatfelafel
@kumquatfelafel
Jul 12 2017 17:17
@kelechy Not really relevant to whatever problem it is you're having with whatever you're trying to do (haven't been paying attention :p ), but you don't need == true, you can just say
if (Array.isArray(list))
Nick Janne
@njanne19
Jul 12 2017 17:21
@sjames1958gm https://codepen.io/njanne19/pen/LLMJdE?editors=1111 :) thank you for everything
CamperBot
@camperbot
Jul 12 2017 17:21
njanne19 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8053 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 12 2017 17:21
@njanne19 :+1: Glad to help.
Nick Janne
@njanne19
Jul 12 2017 17:21
I'm just gonna copy over the code again later and make it look better but it finally works and that's all that matters
kumquatfelafel
@kumquatfelafel
Jul 12 2017 17:23
@kelechy Something weird seems to be going on with list, according to console.
Kelechi Chinaka
@ke1echi
Jul 12 2017 17:24
how do u mean @kumquatfelafel
Stephen James
@sjames1958gm
Jul 12 2017 17:25
@kelechy The instructions don't tell you, but if arguments.length > 1 then use arguments
because list might be a string or array when there are multiple arguments.
Kelechi Chinaka
@ke1echi
Jul 12 2017 17:28
string or array are they not arguments? @sjames1958gm
kumquatfelafel
@kumquatfelafel
Jul 12 2017 17:28

@kelechy Try adding the following test and see what happens. Sorry, I was being far too needlessly obscure before :laughing:

Test.assertEquals(last('z','b'), "b");

Stephen James
@sjames1958gm
Jul 12 2017 17:29
@kelechy The point is that
last("a", "b", "c")
should return "c" not "a"
Kelechi Chinaka
@ke1echi
Jul 12 2017 17:33
python tutor return c @sjames1958gm for last("a", "b", "c")
Stephen James
@sjames1958gm
Jul 12 2017 17:33
@kelechy With your code?
@kelechy The code above would return "a" because "a" is a string
kumquatfelafel
@kumquatfelafel
Jul 12 2017 17:34
:point_up:
Have you changed code in some way since posting?
Kelechi Chinaka
@ke1echi
Jul 12 2017 17:36
no p..its failed test is a random one, and i cant see it @kumquatfelafel
Alexander Køpke
@alexanderkopke
Jul 12 2017 17:38
python returns C lol
kumquatfelafel
@kumquatfelafel
Jul 12 2017 17:38
@alexanderkopke :laughing:
:p
@kelechy https://repl.it/JYzI/1 Run code in link and see what happens.
Kelechi Chinaka
@ke1echi
Jul 12 2017 17:42
pls what been returned ? :smile: my network is really slow @kumquatfelafel
kumquatfelafel
@kumquatfelafel
Jul 12 2017 17:42
@kelechy last('a', 'b', 'c') returns 'a'. (again, assuming your code is still the same as what you posted above)
Kelechi Chinaka
@ke1echi
Jul 12 2017 17:43
@sjames1958gm you still around ?
Stephen James
@sjames1958gm
Jul 12 2017 17:44
Yes
Nick Janne
@njanne19
Jul 12 2017 17:44
@sjames1958gm last question, how come when I have a clear board and I try to hit "play", it adds 2 to the generation and does not do anything else https://codepen.io/njanne19/pen/LLMJdE
Obviously it shouldn't be running if there's nothing on the board
Kelechi Chinaka
@ke1echi
Jul 12 2017 17:45
is it that one of the tests is wrong or what @sjames1958gm
Stephen James
@sjames1958gm
Jul 12 2017 17:46
@kelechy Has your code changed?
Kelechi Chinaka
@ke1echi
Jul 12 2017 17:46
a is not the last @kumquatfelafel
Stephen James
@sjames1958gm
Jul 12 2017 17:46
@kelechy this code will return "a" from last("a", "b", "c")
function last(list){
 if (Array.isArray(list) == true) {
   return list[list.length - 1]
 }
 if (typeof(list) == 'string') {
   return list.split('')[list.length - 1];
 }
   return arguments[arguments.length - 1] 
}
kumquatfelafel
@kumquatfelafel
Jul 12 2017 17:46
@kelechy https://repl.it/JYzI/2 I've modified code a bit so you can see a little clearer what is happening.
Stephen James
@sjames1958gm
Jul 12 2017 17:49
@njanne19 Why the setTimeout in runGame you already have setInterval running.
kumquatfelafel
@kumquatfelafel
Jul 12 2017 17:51
oh right... browser troubles?? Forgot, sorry. Here's what looks like... I've thrown in some comments to show what pops up in console.
function last(list){
 console.log(list);  // "a" shows up in console. Only "a"... nothing else.
 console.log(typeof(list)); // says "string" in console
 if (Array.isArray(list) == true) {
   return list[list.length - 1]
 }
 if (typeof(list) == 'string') {
   return list.split('')[list.length - 1];
 }
 return arguments[arguments.length - 1] 
}

console.log("The last is " + last('a','b','c')); // "The last is a" in console
Kelechi Chinaka
@ke1echi
Jul 12 2017 17:52
i did changed the logic a bit
Nick Janne
@njanne19
Jul 12 2017 17:52
@sjames1958gm just noticed that
Kelechi Chinaka
@ke1echi
Jul 12 2017 17:53
function last(list){
if (arguments.length >  1) {
  return arguments[arguments.length - 1]
} 

 if (Array.isArray(list)) {
   return list[list.length - 1]
 }
 if (typeof(list) == 'string') {
   return list.split('')[list.length - 1];
 }

}
Stephen James
@sjames1958gm
Jul 12 2017 17:53
@kelechy Closer
Kelechi Chinaka
@ke1echi
Jul 12 2017 17:53
passed all test except 1
only argument - Expected: 5, instead got: undefined
Stephen James
@sjames1958gm
Jul 12 2017 17:53
@kelechy the split is not needed, but if list is neither string nor array ?
@kelechy The instructions are sketchy :)
Kelechi Chinaka
@ke1echi
Jul 12 2017 17:55
yea, not really clear @sjames1958gm
thanks for making understand the arguments object better
CamperBot
@camperbot
Jul 12 2017 17:55
kelechy sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: kelechy already gave sjames1958gm points
Alexander Køpke
@alexanderkopke
Jul 12 2017 17:56
how do you play this game of life. I click but new dots appear all the time.
kumquatfelafel
@kumquatfelafel
Jul 12 2017 17:57
@sjames1958gm agreed.
Kelechi Chinaka
@ke1echi
Jul 12 2017 17:58
so where is the undefined coming from :smile: , thats the only failed test
kumquatfelafel
@kumquatfelafel
Jul 12 2017 17:59
@kelechy If you were to say last(12345); for example, it would expect 12345. 12345 is not array, is not string, and arguments length not greater than 1. When no explicit return statement, returns undefined by default.
zathura4240
@zathura4240
Jul 12 2017 18:02
heyy guys any new questions
?
Lydia-Ludmila
@Lydia-Ludmila
Jul 12 2017 18:03
Hi Everyone, I am new here.. I would need some help…. :(
kumquatfelafel
@kumquatfelafel
Jul 12 2017 18:03
hiya. Ask away :)
Lydia-Ludmila
@Lydia-Ludmila
Jul 12 2017 18:05
I hav to build a function, the containsString function should return a value of true, if search string is part of main string, and false if it’s not. For example, containsString (“independent”, “depend”) should return true, because depend is part of independent. But, contains-String(“independent”, “indy”) should return false, because that string is not part of independent…. So I wrote that function (I am new learning Javascript :worried: )

var mainString = "independent";
var searchString = "dependent";

function containsString (mainString, searchString){
if (mainString.indexOf(searchString)){
return true;
}
else {
return false;
}
};

and yeah.. it doesn’t work….
kumquatfelafel
@kumquatfelafel
Jul 12 2017 18:06
@zathura4240 questions for you or questions from you... if the former, I suppose I have always wondered... Why is granite? :o
I just don't know. :p
Lydia-Ludmila
@Lydia-Ludmila
Jul 12 2017 18:06
Hope someone can help me on this… thank you!!
Kelechi Chinaka
@ke1echi
Jul 12 2017 18:06
very confusing kata @sjames1958gm
Saif Ur Rahman
@saifsmailbox98
Jul 12 2017 18:06
@Lydia-Ludmila if(mainString.indexOf(searchString)>=0)
Stephen James
@sjames1958gm
Jul 12 2017 18:07
You learned what arguments is :)
Saif Ur Rahman
@saifsmailbox98
Jul 12 2017 18:07
@Lydia-Ludmila also, there is no need to end the function with ;
Stephen James
@sjames1958gm
Jul 12 2017 18:08
@Lydia-Ludmila You are not calling your function.
kumquatfelafel
@kumquatfelafel
Jul 12 2017 18:08

@Lydia-Ludmila on another note...

For future: if you write it in a code block, it makes it easier to read and allows you to do some formatting. To write it in a code block...
for one line: ``` code goes here ```
or for multiple lines vvv
```
code goes here
```
You can also edit your post if you make a mistake by clicking the … that appears when you hover your mouse over your comment.

Saif Ur Rahman
@saifsmailbox98
Jul 12 2017 18:08

@Lydia-Ludmila

function containsString (mainString, searchString){
if (mainString.indexOf(searchString)>=0){           //fixed
return true;
}
else {
return false;
}
}

containsString("independent", "dependent");     //function call

or simply return mainString.indexOf(searchString)>=0

Kelechi Chinaka
@ke1e