These are chat archives for FreeCodeCamp/HelpJavaScript

9th
Aug 2017
Guderian Raborg
@hypercuber
Aug 09 2017 00:11 UTC
@cmccormack thanks
CamperBot
@camperbot
Aug 09 2017 00:11 UTC
hypercuber sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:warning: hypercuber already gave cmccormack points
dyon3334
@dyon3334
Aug 09 2017 00:38 UTC
can anyone tell me why this not work
function findLongestWord(str) {
  var index = 0;
  var test;
  var arr = str.split(" ");
  for(i=0;i<arr.length;i++){
    test = arr[i].length;}
    if (index<test){
    index = arr[i].length;
    }
   return index;
    }

findLongestWord("The quick brown fox jumped over the lazy dog");
Gersho
@Gersho
Aug 09 2017 00:39 UTC
it's asking for the longest word, the answer you are giving is the longest word's length
Moisés Man
@moigithub
Aug 09 2017 00:47 UTC
@dyon3334 check ur brackets...
{ <-- start of block
} <-- end of block
kumquatfelafel
@kumquatfelafel
Aug 09 2017 00:55 UTC

:point_up:

This is what your code actually looks like with proper indentation (and that closing bracket on a separate line). :point_down:

function findLongestWord(str) {
  var index = 0;
  var test;
  var arr = str.split(" ");
  for(i=0;i<arr.length;i++){
    test = arr[i].length;
  }
  if (index<test){
    index = arr[i].length;
  }
  return index;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
dyon3334
@dyon3334
Aug 09 2017 00:59 UTC
@kumquatfelafel thanks !!
CamperBot
@camperbot
Aug 09 2017 00:59 UTC
dyon3334 sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 585 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Joseph Henshaw
@Big-jo
Aug 09 2017 01:07 UTC
I tried to parse a JSON formatted object and then i got [object Object]
kumquatfelafel
@kumquatfelafel
Aug 09 2017 01:08 UTC
@Gersho The challenge is actually asking for the length, not the word itself, in spite of function name being a bit ... well... ambiguous at best.
Gersho
@Gersho
Aug 09 2017 01:08 UTC
@kumquatfelafel oh lol
@Big-jo try stringify to have a look at it
Joseph Henshaw
@Big-jo
Aug 09 2017 01:09 UTC
image.png
Stephen James
@sjames1958gm
Aug 09 2017 01:09 UTC
@Big-jo you parsed a JSON string and got an object, that is what should happen
kumquatfelafel
@kumquatfelafel
Aug 09 2017 01:09 UTC

yeah. First time I did that challenge, assumed from function name that wanted the word. :p

Easy fix, but very reasonable assumption based on function name

Stephen James
@sjames1958gm
Aug 09 2017 01:10 UTC
@Big-jo You tried to parse the toString of an object which is not correct.
Joseph Henshaw
@Big-jo
Aug 09 2017 01:10 UTC

@sjames1958gm

image.png

Gersho
@Gersho
Aug 09 2017 01:10 UTC
having a look at your code would be more usefull
especially line 46
Stephen James
@sjames1958gm
Aug 09 2017 01:11 UTC
@Gersho :+1:
Joseph Henshaw
@Big-jo
Aug 09 2017 01:12 UTC

request.onload = function () {
    /* body... */
    var Recieved = request.response;
var GoogleApi = JSON.parse(Recieved);
}
my variable names are crappy though
Adnan Karšić
@adokce
Aug 09 2017 01:12 UTC
hello people
kumquatfelafel
@kumquatfelafel
Aug 09 2017 01:12 UTC
hey
Adnan Karšić
@adokce
Aug 09 2017 01:12 UTC
are there any senior devs here
kumquatfelafel
@kumquatfelafel
Aug 09 2017 01:13 UTC
@moigithub p.s. thanks :p
CamperBot
@camperbot
Aug 09 2017 01:13 UTC
kumquatfelafel sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3571 | @moigithub |http://www.freecodecamp.com/moigithub
Adnan Karšić
@adokce
Aug 09 2017 01:13 UTC
i need advice
from someone a little bit more experienced
Joseph Henshaw
@Big-jo
Aug 09 2017 01:13 UTC
ask your question and w'll try to help
Stephen James
@sjames1958gm
Aug 09 2017 01:14 UTC
@Big-jo console.log(Received) and see what it is
Joseph Henshaw
@Big-jo
Aug 09 2017 01:14 UTC
okay
Uncaught ReferenceError: Recieved is not defined
at <anonymous>:1:13
Stephen James
@sjames1958gm
Aug 09 2017 01:16 UTC
@Big-jo If you do that after the request.response line that can't be
@Big-jo Oh, I meant add that console.log to the code (not in the console) my bad for not being clear
Joseph Henshaw
@Big-jo
Aug 09 2017 01:17 UTC
oh no p
Adnan Karšić
@adokce
Aug 09 2017 01:18 UTC
i'm university student and i'm starting a project with 2 colleagues of mine. we are building a web app for recruitment (sort of like recruitment agency). it will probably have some tests, user database. it would need an options for regular people to login and post their CVs, take tests and stuff like that but also for companies to hire these people.
my question is: since we are not that experienced with real world projects, which technologies shoud we use and learn to do this?
Joseph Henshaw
@Big-jo
Aug 09 2017 01:19 UTC
@sjames1958gm Uncaught SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at XMLHttpRequest.request.onload
Adnan Karšić
@adokce
Aug 09 2017 01:19 UTC
(mean? mern? something with postgresql? we don't want to waste too much time thinking which tools to use)
Stephen James
@sjames1958gm
Aug 09 2017 01:22 UTC
@Big-jo Show your set up of the AJAX request
Joseph Henshaw
@Big-jo
Aug 09 2017 01:23 UTC
@sjames1958gm lol It's scattered around my JS file
but hold on
var requestURL = 'https://maps.googleapis.com/maps/api/geocode/json?address=" + Concat + "&key=AIzaSyBCyqeNvQ2ykQl524BcIWr_XAJwApEyWZU'

var request = new  XMLHttpRequest();
var GoogleApi;

function StoreObj() {
    var UsrObjects = {
    Name : FirstName.value,
    email: EmailAddress.value,
    destination_Country : DestinationCountry.value,
    destination_State : DestinationState.value,

};

    localStorage.setItem('StoredUsrObj', JSON.stringify(UsrObjects));

    //The dissappering act for the div 'PostContainer'
    $('.PostContainer').fadeOut("slow", function() {
            // Callback is empty
    });


request.open('GET',requestURL);

request.responseType = 'json';

request.send();

}

request.onload = function () {
    /* body... */
    var Recieved = request.response;
GoogleApi = JSON.parse(Recieved);

}
Kristi Nushi
@Kristi92
Aug 09 2017 01:25 UTC
hello can someone help me please with my code?
Stephen James
@sjames1958gm
Aug 09 2017 01:26 UTC
@Big-jo Since you said the responseType is JSON, I believe that the json is already parsed
So Received is an object and JSON.parse expects a string so Recieved.toString is [object object]
kumquatfelafel
@kumquatfelafel
Aug 09 2017 01:28 UTC
@Kristi92 post code
Joseph Henshaw
@Big-jo
Aug 09 2017 01:28 UTC
@sjames1958gm thanks, It makes sense now
CamperBot
@camperbot
Aug 09 2017 01:28 UTC
big-jo sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8277 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
kumquatfelafel
@kumquatfelafel
Aug 09 2017 01:38 UTC
@Kristi92 (or codepen or code snippet or something)... can't help without more information on what need help with.
Joseph Henshaw
@Big-jo
Aug 09 2017 01:38 UTC
{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "1600",
               "short_name" : "1600",
               "types" : [ "street_number" ]
            },
            {
               "long_name" : "Amphitheatre Pkwy",
               "short_name" : "Amphitheatre Pkwy",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Mountain View",
               "short_name" : "Mountain View",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Santa Clara County",
               "short_name" : "Santa Clara County",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "California",
               "short_name" : "CA",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "94043",
               "short_name" : "94043",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA",
         "geometry" : {
            "location" : {
               "lat" : 37.4224764,
               "lng" : -122.0842499
            },
            "location_type" : "ROOFTOP",
            "viewport" : {
               "northeast" : {
                  "lat" : 37.4238253802915,
                  "lng" : -122.0829009197085
               },
               "southwest" : {
                  "lat" : 37.4211274197085,
                  "lng" : -122.0855988802915
               }
            }
         },
         "place_id" : "ChIJ2eUgeAK6j4ARbn5u_wAGqWA",
         "types" : [ "street_address" ]
      }
   ],
   "status" : "OK"
}
I saw this and was just confused on how to get out the location under geometry, can anyone help out?
Long Nguyen
@longnt80
Aug 09 2017 01:44 UTC
@Big-jo something like this: .results["0"].geometry.location
.results["0"].geometry.location.lat
.results["0"].geometry.location.lng
Joseph Henshaw
@Big-jo
Aug 09 2017 01:47 UTC
@longnt80 thanks
CamperBot
@camperbot
Aug 09 2017 01:47 UTC
big-jo sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 485 | @longnt80 |http://www.freecodecamp.com/longnt80
Joseph Henshaw
@Big-jo
Aug 09 2017 01:54 UTC
@longnt80 not working
kumquatfelafel
@kumquatfelafel
Aug 09 2017 01:54 UTC
@Big-jo try console.logging each step of the way to see what you get.
Joseph Henshaw
@Big-jo
Aug 09 2017 01:55 UTC
:thumbsup:
Long Nguyen
@longnt80
Aug 09 2017 01:56 UTC
@Big-jo you need to plug that to the name of the big object
since you just have an object with no name
kumquatfelafel
@kumquatfelafel
Aug 09 2017 01:57 UTC
this too. So blah.results[0].yadayada
except... y'know... not blah, and not yadayada
Long Nguyen
@longnt80
Aug 09 2017 01:58 UTC
@Big-jo or you can give us a codepen link
Cody Seibert
@codyseibert
Aug 09 2017 02:20 UTC
@adokce just do MEAN or MERN
Jefferson
@jeffersonnnn
Aug 09 2017 02:25 UTC
Help with understanding why console.log keeps printing i not referenced. My understanding was that the default state of mutation splits the elements within the bracket into arr[0] and arr[2].
Long Nguyen
@longnt80
Aug 09 2017 02:34 UTC
@jeffersonnnn can you give the code?
Jefferson
@jeffersonnnn
Aug 09 2017 02:39 UTC
yes i can. Thank you.

function mutation(arr) {

  for (i = 0; i < arr[1].length; i++) {
    if(arr[i].toLowerCase() === 'scatter the floor');
  }
}

mutation(["hello", "hey"]);
kumquatfelafel
@kumquatfelafel
Aug 09 2017 02:40 UTC
Why are you comparing to "scatter the floor"?
also, arr has two elements, "hello" and "hey". arr[1] ("hey") has a length of 3. So what happens in final iteration of for loop?
bitcoinabdi
@bitcoinabdi
Aug 09 2017 02:44 UTC
good evening folks!
i need help with how to render a team project that has react
Jefferson
@jeffersonnnn
Aug 09 2017 02:51 UTC
I got the code snippet from SO; I take full responsibility for "scatter the floor" though. They compared "if(arr[i].toLowerCase() ===" to "whatever" in the snippet.
@kumquatfelafel @longnt80 it is up there.
Jefferson
@jeffersonnnn
Aug 09 2017 02:58 UTC
@kumquatfelafel, the grand idea is to create a variable that will execute when matching letters or words are found.
kumquatfelafel
@kumquatfelafel
Aug 09 2017 03:04 UTC
Suppose that arr is ["hi", "blah"].
  • What is arr[1]?
  • What is arr[1].length?
  • What value would i have on, e.g., the final iteration of for loop?
  • For this value of i, what would arr[i] be?
  • In such a case, what would happen when you call toLowerCase?
@jeffersonnnn I would also say var i = 0 instead. Without that, i is treated as a global variable, which at best provides no benefit and at worst could result in your program breaking somewhere.
Jefferson
@jeffersonnnn
Aug 09 2017 03:19 UTC
definitely seen the use of the second half of your recommendations. i have gone ahead to implement too. The first half i am still parsing.
Greg Duncan
@GregatGit
Aug 09 2017 03:54 UTC
@bitcoinabdi how did it go?
Joseph
@revisualize
Aug 09 2017 04:12 UTC
Hello.
abraham anak agung
@padunk
Aug 09 2017 04:14 UTC
Good Afternoon
bitcoinabdi
@bitcoinabdi
Aug 09 2017 04:22 UTC
@GregatGit still having issues
Greg Duncan
@GregatGit
Aug 09 2017 04:23 UTC
@bitcoinabdi Where are you stuck?
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:24 UTC

Hi everyone!

I am trying to solve the palindrome problem from the basic algorithm section.

Here is my code:


function palindrome(str) {
  // Good luck!

  var converted = str.replace(/\d*[\W_]+/gi, '');
  var toLow = converted.toLowerCase();

  var splitted = toLow.split("");
  var reversed = splitted.reverse();
  var concatted = reversed.join('');

  if (concatted === toLow) {
    return true;
  } else {
    return false;
  }


//   return toLow;
}



palindrome("1 eye for of 1 eye.");

Now, this is working just fine on my eye, but it can't pass the test because as the editor saying:

palindrome("1 eye for of 1 eye.") should return false.

But, is it really? I think IT IS a palindrome and hence it should return true

Can anyone tell me where I am wrong?

bitcoinabdi
@bitcoinabdi
Aug 09 2017 04:25 UTC
@GregatGit i am supposed to render my project and should look like this http://imgur.com/e65PCU8
heroiczero
@heroiczero
Aug 09 2017 04:26 UTC
@faahim is the reverse the same as the original?
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:26 UTC
1 eye for of 1 eye becomes eeyeforofeye when you remove all the numbers, spaces and symbol. And then its a palindrome, isn't it? :/
bitcoinabdi
@bitcoinabdi
Aug 09 2017 04:26 UTC
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:26 UTC
yes, I think so. See for yourself @heroiczero :(
eyeforofeye is same even when you spell backword
iso
@iso1048
Aug 09 2017 04:27 UTC
@faahim check again if you are supposed to remove numbers
Greg Duncan
@GregatGit
Aug 09 2017 04:29 UTC
@bitcoinabdi so the project works and you want to use github pages to host it?
heroiczero
@heroiczero
Aug 09 2017 04:29 UTC
@faahim says "all non-alphanumeric characters"
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:29 UTC

Good point @gothamknight

It says: Note
You'll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything lower case in order to check for palindromes.

Maybe I need to keep the number.

Let me try

iso
@iso1048
Aug 09 2017 04:29 UTC
@faahim yep. keep numbers
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:29 UTC
Thanks @gothamknight and @heroiczero
CamperBot
@camperbot
Aug 09 2017 04:29 UTC
faahim sends brownie points to @gothamknight and @heroiczero :sparkles: :thumbsup: :sparkles:
:cookie: 363 | @gothamknight |http://www.freecodecamp.com/gothamknight
:star2: 1590 | @heroiczero |http://www.freecodecamp.com/heroiczero
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:29 UTC
:)
bitcoinabdi
@bitcoinabdi
Aug 09 2017 04:30 UTC
yes
Joseph
@revisualize
Aug 09 2017 04:30 UTC

@faahim This:

  if (concatted === toLow) {
    return true;
  } else {
    return false;
  }

Should just be...
return concatted === toLow;

bitcoinabdi
@bitcoinabdi
Aug 09 2017 04:30 UTC
@GregatGit yes please
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:31 UTC
oh! right! It's boolean! I don't need to fo all those if else!
Greg Duncan
@GregatGit
Aug 09 2017 04:31 UTC
@bitcoinabdi very easy to do
CamperBot
@camperbot
Aug 09 2017 04:31 UTC
faahim sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4419 | @revisualize |http://www.freecodecamp.com/revisualize
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:32 UTC
Thanks @revisualize
CamperBot
@camperbot
Aug 09 2017 04:32 UTC
faahim sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:warning: faahim already gave revisualize points
Joseph
@revisualize
Aug 09 2017 04:32 UTC
@faahim You should also learn about method chaining.
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:32 UTC

Method chaining?

Never heard about it!

I've just started learning JS
Joseph
@revisualize
Aug 09 2017 04:33 UTC
@faahim Good.
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:33 UTC
I'll surely look up
Joseph
@revisualize
Aug 09 2017 04:33 UTC
@faahim Good time to look up method chaining.
bitcoinabdi
@bitcoinabdi
Aug 09 2017 04:33 UTC
@GregatGit how so
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:33 UTC
But for now, I'm struggling with regex
Greg Duncan
@GregatGit
Aug 09 2017 04:33 UTC
@bitcoinabdi in the README.md just search for 'GitHub Pages'
Joseph
@revisualize
Aug 09 2017 04:33 UTC
@faahim Go learn Regex: https://regexone.com/
Cody Seibert
@codyseibert
Aug 09 2017 04:33 UTC

anyone have an alternative solution for this challenge: https://www.freecodecamp.org/challenges/sum-all-numbers-in-a-range ?

I was trying to do this as FP as possible:

function sumAll(arr) {
  return (([min, max]) =>
    Array.from(Array(max - min + 1).keys())
      .map(i => i + min)
      .reduce((sum, n) => sum + n) 
  )([
    ...arr.sort((a, b) => a - b)
  ])
}

sumAll([1, 4]);
Greg Duncan
@GregatGit
Aug 09 2017 04:34 UTC
@bitcoinabdi you'll have it up in no time
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:34 UTC
is Method chaining suitable for learning in the beginning?
Joseph
@revisualize
Aug 09 2017 04:34 UTC
@faahim Yes.
Greg Duncan
@GregatGit
Aug 09 2017 04:34 UTC

@bitcoinabdi
GitHub Pages

Note: this feature is available with react-scripts@0.2.0 and higher.
Step 1: Add homepage to package.json

The step below is important!
If you skip it, your app will not deploy correctly.

Open your package.json and add a homepage field:

"homepage": "https://myusername.github.io/my-app",
Create React App uses the homepage field to determine the root URL in the built HTML file.

Step 2: Install gh-pages and add deploy to scripts in package.json

Now, whenever you run npm run build, you will see a cheat sheet with instructions on how to deploy to GitHub Pages.

To publish it at https://myusername.github.io/my-app, run:

npm install --save gh-pages
Alternatively you may use yarn:

yarn add gh-pages
Add the following scripts in your package.json:

"scripts": {

  • "predeploy": "npm run build",
  • "deploy": "gh-pages -d build",
    "start": "react-scripts start",
    "build": "react-scripts build",
    The predeploy script will run automatically before deploy is run.

Step 3: Deploy the site by running npm run deploy

Then run:

npm run deploy
Step 4: Ensure your project’s settings use gh-pages

Finally, make sure GitHub Pages option in your GitHub project settings is set to use the gh-pages branch:

gh-pages branch setting

Joseph
@revisualize
Aug 09 2017 04:34 UTC
@codyseibert Guass.
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:35 UTC
I was looking up regex101. But this one seems better. Thanks! @revisualize :)
CamperBot
@camperbot
Aug 09 2017 04:35 UTC
faahim sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:warning: faahim already gave revisualize points
bitcoinabdi
@bitcoinabdi
Aug 09 2017 04:36 UTC
@GregatGit OMG !
Joseph
@revisualize
Aug 09 2017 04:36 UTC
@codyseibert You can actually solve that lesson with just math.
Cody Seibert
@codyseibert
Aug 09 2017 04:36 UTC
@revisualize I was looking for a non mathmatical solution
Joseph
@revisualize
Aug 09 2017 04:36 UTC
@codyseibert oh
bitcoinabdi
@bitcoinabdi
Aug 09 2017 04:36 UTC
thank you very much realy embarrased
Cody Seibert
@codyseibert
Aug 09 2017 04:36 UTC
I know you can do some formula for n * n - 1 / 2 or something
Joseph
@revisualize
Aug 09 2017 04:37 UTC
@codyseibert kind of.
Greg Duncan
@GregatGit
Aug 09 2017 04:37 UTC
@bitcoinabdi its easy once you know its there - once you have set it up once - if you make changes - npm run deploy updates the gh-pages branch
Joseph
@revisualize
Aug 09 2017 04:37 UTC
@codyseibert But, yea.
Cody Seibert
@codyseibert
Aug 09 2017 04:37 UTC
max(max+1)/2 - min(min+1)/2 ?
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:38 UTC

yee! Done!

Number was the issue! :)

Joseph
@revisualize
Aug 09 2017 04:38 UTC
@codyseibert (Math.max(...arr)*(Math.max(...arr)+1) / 2) - (Math.min(...arr)*(Math.min(...arr)-1) / 2)
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:39 UTC

So, @revisualize
Is there any place where I can enter my regex to see what it means?

Sure I can look up, but it's better if there's a site for that

namethatisnottaken
@namethatisnottaken
Aug 09 2017 04:39 UTC
function updateInventory(arr1, arr2) {
    // All inventory must be accounted for or you're fired!  
  //create new find Index function return index or -1
  function findElInArray(array, seekEl, zeroOrFirst){
    var result = -1;
    for(var i = 0; i< array.length;i++){
      if(array[i][zeroOrFirst]==seekEl){
        result = i;
      }
    }
    return result;
  }  
  //clone arr1 and 2
  var arr1Clone= arr1.slice();
  var arr2Clone= arr2.slice();
  //fill and sort combinedArray  
  var combinedArray = [];
  for(var j=0;j<arr1.length;j++){
    arr1[j].shift();
    if(findElInArray(combinedArray, arr1[j][0],0==-1)){
       combinedArray.push(arr1[j]);
       }      
  }
  for(var k=0;k<arr2.length;k++){
    arr2[k].shift();  
    if(findElInArray(combinedArray, arr2[k][0],0)==-1){
      combinedArray.push(arr2[k]);
    }
  }    
  combinedArray.sort();


    return arr1Clone;
}
Hi, i was trying to clone the arr1 and arr2 on code below but failed, tried to use const but it is not supported by the platform, any idea how to really copy arr1 and 2 ?
Cody Seibert
@codyseibert
Aug 09 2017 04:39 UTC
max*(max+1)/2 - (min-1)*(min)/2 ?
Joseph
@revisualize
Aug 09 2017 04:39 UTC
@codyseibert Yes.
@faahim yes
Cody Seibert
@codyseibert
Aug 09 2017 04:40 UTC
@revisualize but let's say we are not allowed to solve it using that formula
Joseph
@revisualize
Aug 09 2017 04:40 UTC
@codyseibert Ok.
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:42 UTC
@revisualize
Amazing!
namethatisnottaken
@namethatisnottaken
Aug 09 2017 04:43 UTC
any help anyone ?
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:43 UTC

@revisualize I'm stalking a little bit on you! :P

I see you kept all your fcc code on your GitHub. Doesn't FCC stores your code at your profile?
I mean, Is that something I should do too?

Manish Giri
@Manish-Giri
Aug 09 2017 04:44 UTC
@namethatisnottaken combinedArray.sort();
in case what you're sorting is numbers, this won't work
namethatisnottaken
@namethatisnottaken
Aug 09 2017 04:44 UTC
no, i was trying to sort it alphabetically actually
but i need the number later on so i was trying to retain its value
Manish Giri
@Manish-Giri
Aug 09 2017 04:45 UTC
@namethatisnottaken is there a link to the challenge?
Joseph
@revisualize
Aug 09 2017 04:46 UTC
@faahim Where do you think a potential employer is going to look for my code when I apply for a job?
@faahim Github or my freeCodeCamp profile?
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:48 UTC
Got it! Gotta create a repo today! :)
Manish Giri
@Manish-Giri
Aug 09 2017 04:48 UTC
@namethatisnottaken one sec
Joseph
@revisualize
Aug 09 2017 04:49 UTC
@faahim There is a reason I even have my codewars challenges on my github.
namethatisnottaken
@namethatisnottaken
Aug 09 2017 04:49 UTC
ok thanks @Manish-Giri
CamperBot
@camperbot
Aug 09 2017 04:49 UTC
namethatisnottaken sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6387 | @manish-giri |http://www.freecodecamp.com/manish-giri
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:49 UTC
@revisualize the same reason I guess?
Joseph
@revisualize
Aug 09 2017 04:50 UTC
@faahim Yup.
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:50 UTC
haha
Joseph
@revisualize
Aug 09 2017 04:50 UTC
@faahim Once place and a good sample of my work.
Can I upload everything I do. No.
@faahim But, I'm selective.
bitcoinabdi
@bitcoinabdi
Aug 09 2017 04:51 UTC
@GregatGit so when the step one instruction --> where do i make the changes at . is it on git hub,the repo or github website?
Joseph
@revisualize
Aug 09 2017 04:52 UTC
@faahim I don't read unsolicited private messages.
@faahim If you have a question ask here.
Greg Duncan
@GregatGit
Aug 09 2017 04:53 UTC
@bitcoinabdi you should do in the command line and make sure you are in the branch that all the code is in - i think you called it reactify or something like that
Cody Seibert
@codyseibert
Aug 09 2017 04:53 UTC

@revisualize I saw your solution on github

const sumAll = ([x, y]) => (x + y) * (Math.abs(x - y) + 1) / 2;

:+1:

Joseph
@revisualize
Aug 09 2017 04:53 UTC
@codyseibert :)
Cody Seibert
@codyseibert
Aug 09 2017 04:54 UTC
@revisualize would you be interested in working on multiple choice quiz questions for FCC?
Joseph
@revisualize
Aug 09 2017 04:55 UTC
No.
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:55 UTC

Oh Okay, That's fine. @revisualize

I was just asking about how far you've gotten in your learning journey.

I'm just starting, I'd ask you what book would you recommend or what resource you've found useful (beside fcc)

Greg Duncan
@GregatGit
Aug 09 2017 04:55 UTC
@bitcoinabdi in your ide (vs code or sublime) make sure you are in the right branch when you do it "homepage": "https://myusername.github.io/my-app",
Joseph
@revisualize
Aug 09 2017 04:56 UTC
@faahim How far am I in my learning journey. ... My learning journey is never done. Learning is not a destination it's a journey.
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:58 UTC
Great! Thanks @revisualize
CamperBot
@camperbot
Aug 09 2017 04:58 UTC
faahim sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:warning: faahim already gave revisualize points
Joseph
@revisualize
Aug 09 2017 05:01 UTC
@faahim Any other questions?
namethatisnottaken
@namethatisnottaken
Aug 09 2017 05:01 UTC
hi Joseph
can you help me to clone arr 1 and arr 2 in this code ?
function updateInventory(arr1, arr2) {
    // All inventory must be accounted for or you're fired!  
  //create new find Index function return index or -1
  function findElInArray(array, seekEl, zeroOrFirst){
    var result = -1;
    for(var i = 0; i< array.length;i++){
      if(array[i][zeroOrFirst]==seekEl){
        result = i;
      }
    }
    return result;
  }    
  //fill and sort combinedArray  
  var combinedArray = [];
  for(var j=0;j<arr1.length;j++){
    arr1[j].shift();
    if(findElInArray(combinedArray, arr1[j][0],0==-1)){
       combinedArray.push(arr1[j]);
    }      
  }  
  for(var k=0;k<arr2.length;k++){
    arr2[k].shift();  
    if(findElInArray(combinedArray, arr2[k][0],0)==-1){
      combinedArray.push(arr2[k]);
    }
  }    
  combinedArray.sort();  

    return arr;
}
basically i need to shift one clone of arr 1 but need to get the values back later;
Joseph
@revisualize
Aug 09 2017 05:03 UTC
Manish Giri
@Manish-Giri
Aug 09 2017 05:06 UTC
@namethatisnottaken I just tested
namethatisnottaken
@namethatisnottaken
Aug 09 2017 05:07 UTC
hi thanks @Manish-Giri @revisualize
CamperBot
@camperbot
Aug 09 2017 05:07 UTC
namethatisnottaken sends brownie points to @manish-giri and @revisualize :sparkles: :thumbsup: :sparkles:
:warning: namethatisnottaken already gave manish-giri points
:star2: 4420 | @revisualize |http://www.freecodecamp.com/revisualize
Manish Giri
@Manish-Giri
Aug 09 2017 05:08 UTC
@namethatisnottaken what I'm doing is -
  1. loop through second array
  2. check if current item exists in array 1, if it does - update count
  3. if doesn't exist - add current item to first array
  4. sort first array
namethatisnottaken
@namethatisnottaken
Aug 09 2017 05:11 UTC
looks great mate, why i could not think of that earlier :sob:
Manish Giri
@Manish-Giri
Aug 09 2017 05:11 UTC
it's okay :smile:
you'll get there with practice
and remember, "keep it simple"!
namethatisnottaken
@namethatisnottaken
Aug 09 2017 05:12 UTC
haha yes thanks :+1:
juni
@junipberry
Aug 09 2017 05:13 UTC
hey @Manish-Giri , could you help me out with a problem. I’m supposed to write a function to return an array of all the keys of an Object.
Manish Giri
@Manish-Giri
Aug 09 2017 05:13 UTC
@junipberry sure thing
juni
@junipberry
Aug 09 2017 05:14 UTC
great, ty~~
so far, I have broken it down into steps
Manish Giri
@Manish-Giri
Aug 09 2017 05:14 UTC
there's an in built function actually, for that
Object.keys()
juni
@junipberry
Aug 09 2017 05:14 UTC
yes!
but Im not supposed to use it lol
Manish Giri
@Manish-Giri
Aug 09 2017 05:14 UTC
ah cool
thought so
post your steps/code
juni
@junipberry
Aug 09 2017 05:15 UTC
I have a few possibilities here. Would like to talk over which way would be better to go about it
Manish Giri
@Manish-Giri
Aug 09 2017 05:15 UTC
sure
juni
@junipberry
Aug 09 2017 05:15 UTC
so one way was to use the Object.entries then filter out
Manish Giri
@Manish-Giri
Aug 09 2017 05:16 UTC
right
but that would give you a 2D array
[['key', 'value'], [],...]
of that form
that would work, but you'd need to handle 2D arrays
juni
@junipberry
Aug 09 2017 05:17 UTC
ah okay
Manish Giri
@Manish-Giri
Aug 09 2017 05:18 UTC
any other way you thought of?
juni
@junipberry
Aug 09 2017 05:18 UTC
I cannot just filter afterwards?
Manish Giri
@Manish-Giri
Aug 09 2017 05:18 UTC
yeah you can
you can chain .filter() to Object.entries()
and then return the first item from each sub array
that would give you the array of keys
juni
@junipberry
Aug 09 2017 05:19 UTC
right. Then I can just use a loop to do that, yea?
to return first item of each sub array
afterwards
Manish Giri
@Manish-Giri
Aug 09 2017 05:20 UTC
actually
I was wrong about filter
I meant .map()
juni
@junipberry
Aug 09 2017 05:21 UTC
ah
Manish Giri
@Manish-Giri
Aug 09 2017 05:21 UTC
so when you map over Object.entries
juni
@junipberry
Aug 09 2017 05:21 UTC
got it
Manish Giri
@Manish-Giri
Aug 09 2017 05:21 UTC
let obj = {'a': 1, 'b':2};
if this is your object
[['a', 1], ['b', 2]]
this will be Object.entries(obj)
then when you map over it
just return the element at index 0
that will get you the keys
juni
@junipberry
Aug 09 2017 05:23 UTC
sounds good
I was also thinking of the .hasOwnProp to look for i
[i]
Manish Giri
@Manish-Giri
Aug 09 2017 05:23 UTC
yup
that would be a nice check
since you can eliminate duplicates that way
(if you need to)
there's also another way
with a for loop
juni
@junipberry
Aug 09 2017 05:24 UTC
I won’t need to in this case, but I somehow liked the feel of doing this.
ahh right
Manish Giri
@Manish-Giri
Aug 09 2017 05:25 UTC
let keys = [];
for (var prop in object) {
 if(!keys.includes(prop) {
  keys.push(prop)
 }
}
juni
@junipberry
Aug 09 2017 05:27 UTC
oh interesting
Manish Giri
@Manish-Giri
Aug 09 2017 05:28 UTC
if(!keys.includes(prop) {
actually you don't need this
just keys.push(prop)
juni
@junipberry
Aug 09 2017 05:32 UTC
I’m a bit unclear w the prop in part in the second line
Manish Giri
@Manish-Giri
Aug 09 2017 05:34 UTC
it iterates over all the key-value pairs in your object, one by one
Markus Kiili
@Masd925
Aug 09 2017 05:35 UTC
@junipberry for...in loop iterates the keys of enumerable (~not built-in) properties of the object and prototype chain. There are no inherited enumerable properties on plain objects so that for...in loop just iterates the property keys of that object.
Manish Giri
@Manish-Giri
Aug 09 2017 05:35 UTC
like you iterate over an array with
for(var i = 0; i < array.length; i++)
@junipberry
Markus Kiili
@Masd925
Aug 09 2017 05:36 UTC
@junipberry Iterating Object.keys(obj) would not look up the prototype chain, so would be a bit more logical, but both work.
juni
@junipberry
Aug 09 2017 05:36 UTC
ohh got it, ty @Manish-Giri ty @Masd925
CamperBot
@camperbot
Aug 09 2017 05:36 UTC
junipberry sends brownie points to @manish-giri and @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4393 | @masd925 |http://www.freecodecamp.com/masd925
:star2: 6389 | @manish-giri |http://www.freecodecamp.com/manish-giri
曾君宇
@zengjunyu
Aug 09 2017 05:47 UTC

function destroyer(arr) {
// 请把你的代码写在这里
return arr.filter(function(val) {
for(var i=1; i<arguments.length; i++) {
if(val === arguments[i])
return false;
}

return true;

});
}

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

这么写为啥不对
Markus Kiili
@Masd925
Aug 09 2017 05:48 UTC
@zengjunyu The filter callback function has its own arguments object.
曾君宇
@zengjunyu
Aug 09 2017 05:49 UTC
thanks
Markus Kiili
@Masd925
Aug 09 2017 05:50 UTC
@zengjunyu Otherwise the code is fine.
juni
@junipberry
Aug 09 2017 06:05 UTC
Could I also do this:
function getKeys(obj){
var myArr = [];
for (var i in obj){
if (obj.hasOwnProperty(i)){
myArr.push(obj[i]);
}
}
}
Markus Kiili
@Masd925
Aug 09 2017 06:06 UTC
@junipberry i loops the property keys of the object, and there cannot be duplicates, so no need for that check.
juni
@junipberry
Aug 09 2017 06:08 UTC
this is what I got from above, but its not really working:
function getAllKeys(obj) {
  let keys = [];
for (var prop in obj) {
  keys.push(prop);
}
}
do I need to specify the prop in obj to be ([i],n)
Markus Kiili
@Masd925
Aug 09 2017 06:15 UTC
@junipberry You need to return keys from the function.
@junipberry Inside the loop block, prop will be each property key (a string) in its turn.
@junipberry Properties are key-value pairs, so you can access keys inside the loop with prop, and values with obj[prop] if you need them.
So you just need to add the return there for it to work:
function getKeys(obj){
  var myArr = [];
  for (var prop in obj){
    myArr.push(prop);
  }
  return myArr;
}
juni
@junipberry
Aug 09 2017 07:20 UTC
ty for that clarification @Masd925
CamperBot
@camperbot
Aug 09 2017 07:20 UTC
junipberry sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4394 | @masd925 |http://www.freecodecamp.com/masd925
juni
@junipberry
Aug 09 2017 07:21 UTC
@Masd925 , all the ways I’ve tried submitting the code are restricted methods
Markus Kiili
@Masd925
Aug 09 2017 07:22 UTC
@junipberry So does that code pass, or is push restricted too?
juni
@junipberry
Aug 09 2017 07:22 UTC
seems like I cannot use any Object oriented methods for this exercise
Markus Kiili
@Masd925
Aug 09 2017 07:23 UTC
@junipberry Instead of push you could use myArr[myArr.length] = prop;
That also adds a new element to an array.
xfangbao
@xfangbao
Aug 09 2017 07:26 UTC
000000
juni
@junipberry
Aug 09 2017 07:39 UTC
it doesn’t go into detail about what it restricted.
Markus Kiili
@Masd925
Aug 09 2017 07:40 UTC
@junipberry Try that code I just posted. If for...in loop is restricted too, you need to wait for the full moon and find a sage.
sky1095
@sky1095
Aug 09 2017 07:44 UTC
any one who can give me solution to this?
ES6: Write Higher Order Arrow Functions
Use arrow function syntax to compute the square of only the positive integers (fractions are not integers) in the array realNumberArray and store the new array in the variable squaredIntegers.
Markus Kiili
@Masd925
Aug 09 2017 07:47 UTC
@sky1095 No solutions here, only help.
sky1095
@sky1095
Aug 09 2017 07:47 UTC
really fed up with this
kumquatfelafel
@kumquatfelafel
Aug 09 2017 07:47 UTC
what have you tried so far?
sky1095
@sky1095
Aug 09 2017 07:47 UTC
@Masd925 Help me out
Markus Kiili
@Masd925
Aug 09 2017 07:50 UTC
@sky1095 You need to loop or iterate the array of real numbers and then check if the looped number is a positive integer. For integrity check you can use Number.isInteger(). Then calculate the square and push the result into a result array. You can also use methods like filter and map if you like.
juni
@junipberry
Aug 09 2017 07:51 UTC
I think the for.. in loop might be restricted bc it calls it within obj. Maybe I need to stick to a simple loop after I convert the strings in the object in an array?
*into an array
what do you think @Masd925
Markus Kiili
@Masd925
Aug 09 2017 07:54 UTC
@junipberry If an arbitrary object is passed into the function, how are you looping the keys? You need to use a for...in loop or iterate Object.keys(obj) (or use some similar ES6 method). If you wan't to loop objects property keys, you need to use the object.
kumquatfelafel
@kumquatfelafel
Aug 09 2017 07:54 UTC
There's only so many ways to access the properties of the object without knowing said properties.
juni
@junipberry
Aug 09 2017 08:06 UTC
I see your point.. yea I don’t think I can use a loop then
sky1095
@sky1095
Aug 09 2017 08:09 UTC
@Masd925 cant use loops
let arr = realNumberArray.filter(Number.isInterger(realNumberArray)) => arr.push();
var squaredIntegers = realNumberArray.map(arr);
@kumquatfelafel
also, should be isInteger (in case that's not just a typo on here)
Tiago Correia
@tiagocorreiaalmeida
Aug 09 2017 08:17 UTC
gm everyone
Tiago Correia
@tiagocorreiaalmeida
Aug 09 2017 08:22 UTC
@kumquatfelafel can you give me a little help?
im doing the tic tac toe exercise, im trying to make it single | multiplayer, I created a turn variable if turn === 0 I know its X turn else its O turn

    if (multiplayer) {
        // i === row
        // j === column
      if(turn==="0"){
        markToPlace = "X";
      }else{
        markToPlace = "0";
      }
       $('.col').click(function() {
        var i = $(this).data('i');
        var j = $(this).data('j');
        if (entrys[i][j] === '') {
            $(this).html(markToPlace);
            entrys[i][j] = markToPlace;
            var gameState = gameOver(entrys);
            if (gameState) {
                alert('game over ' + gameState + ' won');
                return;
            }
        }
       });
    }
how can I the end of the if "pass" the playing option to the other user
Tiago Correia
@tiagocorreiaalmeida
Aug 09 2017 08:28 UTC
just found out I think thanks anyway
EpicTriffid
@EpicTriffid
Aug 09 2017 09:17 UTC
I'm confused about how I might change my code so that it checks for consonant clusters at the beginning of words rather than just one consonant. Any ideas?

function translatePigLatin(str) {
  var vowels = ["a","e","i","o","u"];
  var arr = str.split("");
  if (vowels.indexOf(arr[0]) == -1) {
    arr = arr.join("").slice(1) + arr.slice(0,1) + ("ay");
    return arr;
  }
  else {
    arr.push("way");
    return arr.join("");
  }  
}

translatePigLatin("algorithm");
Is it possible in a for loop to have the end parameter be when it encounters something, instead of x.length?
Blauelf
@Blauelf
Aug 09 2017 09:26 UTC

That's entirely possible, like

  if (vowels.indexOf(str[0]) !== -1) {
    return str + "way";
  }
  for (var i = 1; i < str.length; i++) {
    if (vowels.indexOf(str[i]) !== -1) {
      break;
    }
  }
  return str.slice(i) + str.slice(0, i) + "ay";

or

  if (vowels.indexOf(str[0]) !== -1) {
    return str + "way";
  }
  for (var i = 1; i < str.length && vowels.indexOf(str[i]) === -1; i++) {
    // nothing to do
  }
  return str.slice(i) + str.slice(0, i) + "ay";
Notice that I combined both i < str.length and vowels.indexOf(str[i]) === -1, so that in case you have a string without a vowel, the loop still terminates when reaching string end.
EpicTriffid
@EpicTriffid
Aug 09 2017 09:33 UTC
@Blauelf So have I done it the wrong way round by detecting the absence of vowels first?
Blauelf
@Blauelf
Aug 09 2017 09:34 UTC
I just turned it around to avoid having an else (because I returned earlier, everything after is equal to being in an else).
EpicTriffid
@EpicTriffid
Aug 09 2017 09:38 UTC
If you have a string, with doing str[0] still select the first letter?
Because I've always thought if you used square brackets, the thing had to be an array
Blauelf
@Blauelf
Aug 09 2017 09:38 UTC
Strings are array-like, have a length and numeric properties like an array, but are not arrays. Plus, they are immutable, so you cannot assign to their properties.
Square brackets are for accessing object properties. Arrays are objects and have properties like "0", "1", "2", and so on, and "length".
LovingVi
@LovingVi
Aug 09 2017 09:40 UTC

function largestOfFour(arr) {
for(var i = 0;i < arr.length;i++){
for(var n = 0;n < arr[i].length ;n++){
var max =arr[0][0];
arr[i][n] > max ? (max = arr[i][n]) : max;
arr = max;
}
}
return arr;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

This code throw "Cannot read property 'length' of undefined",
EpicTriffid
@EpicTriffid
Aug 09 2017 09:41 UTC
@Blauelf That's very helpful. I always have a thing of splitting up strings to cycle through them for various tasks, but now I know I can at least remove that
Blauelf
@Blauelf
Aug 09 2017 09:41 UTC
@LovingVi Initialise max before your inner loop, and use arr[i][0]. Store max to some new variable/array after your inner loop.
EpicTriffid
@EpicTriffid
Aug 09 2017 09:41 UTC
Does an element have to be an array to run a for loop through it?
Or does a for loop just go through an object?
Blauelf
@Blauelf
Aug 09 2017 09:45 UTC

@EpicTriffid What do you mean? The standard for looping an array uses its length property explicitly. You can even apply array functions to other array-likes, like

function removeVowels(str) {
  return Array.prototype.filter.call(str, function(ch) { return "AIUEOaiueo".indexOf(ch) === -1; }).join("");
}

(I'd use return str.replace(/[aiueo]/gi, ''); instead, that's just an example)

Markus Kiili
@Masd925
Aug 09 2017 09:46 UTC
@EpicTriffid For loop suits well looping through an object that has numeric properties like "0" and "1" and a .length property (array-like objects). If the object has property keys like "cat", then for loop doesn't help straight away.
Blauelf
@Blauelf
Aug 09 2017 09:49 UTC
@EpicTriffid There's also the for..in loop, which loops the enumerable properties of an object (theoretically in insertion order, but with exceptions in some browsers).
pahosler
@pahosler
Aug 09 2017 09:49 UTC
you can also..
const RECIPIES = {
  spaghetti: {
    ingredients: ["1 lb pasta", "2 jars Ragu"],
    directions: [
      "Add pasta to 4qts boiling water",
      "stir occasionally and let boil for approx 10 mins",
      "Remove from heat and drain water from pasta",
      "Heat Ragu according to directions on jar"
    ]
  },
  pizza: {
    ingredients: ["1 frozen Digorno Pizza"],
    directions: ["Follow heating instructions on box", "Slice into 8 pieces"]
  },
  "tomato soup": {
    ingredients: ["1 can Progresso Tomato Basil Soup"],
    directions: [
      "Use can opener to open can",
      "Empty into a microwave safe bowl",
      "Heat on high approximately 3 mins"
    ]
  },
  "wish sandwich": {
    ingredients: ["2 slices of bread", "1 Wish"],
    directions: ["While holding bread use wish to wish for meat", "Eat bread"]
  },
  "rubber biscuit": {
    ingredients: ["1 rubber biscuit"],
    directions: [
      "Throw biscuit against wall",
      "If biscuit doesn't bounce back into your mouth, you go hungry!"
    ]
  }
};

Object.keys(RECIPIES).map((e,i) => console.log(e.toUpperCase()))
Blauelf
@Blauelf
Aug 09 2017 09:50 UTC
I'd use forEach instead of map if I weren't interested in the return values.
Markus Kiili
@Masd925
Aug 09 2017 09:51 UTC
@Blauelf I wouldn't say theoretically in insertion order, when the order is not specified by the language standard.
But yes, most browsers at the moment seem to iterate for...inin insertion order.
LovingVi
@LovingVi
Aug 09 2017 09:52 UTC
TKS
Blauelf
@Blauelf
Aug 09 2017 09:53 UTC
@Masd925 There seem to be exceptions like numeric first (sorted numerically), or deleted and re-inserted properties appearing according to their first/last insertion (I think IE did that different to all others)
pahosler
@pahosler
Aug 09 2017 09:55 UTC
IIRC the specs say that order isn't guaranteed...
Markus Kiili
@Masd925
Aug 09 2017 09:57 UTC
@pahosler Yes, we were talking about exactly that.
Blauelf
@Blauelf
Aug 09 2017 09:59 UTC
Some things, even though not part of the specs, are widely expected. Like Array.prototype.sort being stable (not swapping the order of elements considered equal), even though that one is explicitly not guaranteed (yes, I did not say "not explicitly guaranteed"). It was considered a bug in Firefox.
prakash chandra yadav
@prakashyadav008
Aug 09 2017 10:02 UTC
hey
can anyone help me out fcc challange
EpicTriffid
@EpicTriffid
Aug 09 2017 10:02 UTC
@Masd925 @Blauelf So my understanding of loops is that is use For loops for Arrays, and For..In loops for strings. Is that not right?
I understand things by putting them in very specific boxes in my head and giving them a very simple description so that's what I did for for loops
pahosler
@pahosler
Aug 09 2017 10:05 UTC
can you be more specific @prakashyadav008
Markus Kiili
@Masd925
Aug 09 2017 10:05 UTC
@Blauelf Sure, but there are other ways to use if the order matters. Why use something that might cause bugs or compatibility problems?
prakash chandra yadav
@prakashyadav008
Aug 09 2017 10:05 UTC
i am solving the chunky-monkey challenge and i hav a doubt
@pahosler

 var array = [];
function chunkArrayInGroups(arr, size) {
  // Break it up.

  for(var i =0;i<arr.length;i=i+size){
    array.push(arr.slice(i,i+size));
  }
  console.log(array);
  return array;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
Markus Kiili
@Masd925
Aug 09 2017 10:06 UTC
@prakashyadav008 Don't use a global variable like that. It can mess up fcc tests.
prakash chandra yadav
@prakashyadav008
Aug 09 2017 10:06 UTC
ya thts the doubt
about global variables @Masd925
CamperBot
@camperbot
Aug 09 2017 10:06 UTC
:star2: 4394 | @masd925 |http://www.freecodecamp.com/masd925
prakash chandra yadav
@prakashyadav008
Aug 09 2017 10:07 UTC
using local function variables it returns correct but using global variable returns error
Markus Kiili
@Masd925
Aug 09 2017 10:07 UTC
@prakashyadav008 FCC tests call your function several times and that array doesn't reset between the calls.
prakash chandra yadav
@prakashyadav008
Aug 09 2017 10:08 UTC
on the console it does return different arrays
if i use console.log
thanks @Masd925
CamperBot
@camperbot
Aug 09 2017 10:10 UTC
prakashyadav008 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4395 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Aug 09 2017 10:13 UTC
@prakashyadav008 And in my opinion, that is the clearest solution for Chunky.
Some mutating solutions are even simpler, but they lead you to philosophical turmoil.
WAINGOR
@WAINGOR
Aug 09 2017 10:14 UTC

Hi all I have a question: if I run this

var regexWhitespace1 = /^[^\n ]*$/g;
var adV = "\n                            jeroen\n                                ";
var runAd = adV.match(regexWhitespace1);
console.log("test results in " + runAd);

it doesnt do anything except log null.. I want to match everything except for newlines and whitespace... I got this code from https://stackoverflow.com/questions/23235200/how-to-matches-anything-except-space-and-new-line

prakash chandra yadav
@prakashyadav008
Aug 09 2017 10:14 UTC
mutating solutions ..like what..?
@Masd925
Markus Kiili
@Masd925
Aug 09 2017 10:15 UTC
@prakashyadav008 Something that changes the passed array. Like this one:
function chunkArrayInGroups(arr, size) {
  var result = [];
  while (arr.length>0) result.push(arr.splice(0,size));
  return result;
}
Doesn't even need an index.
EpicTriffid
@EpicTriffid
Aug 09 2017 10:15 UTC
@Masd925 Sorry Markus, did you see my question above?
Markus Kiili
@Masd925
Aug 09 2017 10:16 UTC
@EpicTriffid Ask @Blauelf , the local regexp master.
EpicTriffid
@EpicTriffid
Aug 09 2017 10:18 UTC
Thankyou :)
@Blauelf So my understanding of loops is that is use For loops for Arrays, and For..In loops for strings. Is that not right?
I understand things by putting them in very specific boxes in my head and giving them a very simple description so that's what I did for for loops
Markus Kiili
@Masd925
Aug 09 2017 10:19 UTC
@EpicTriffid Sorry, I mixed you up with @WAINGOR
EpicTriffid
@EpicTriffid
Aug 09 2017 10:19 UTC
Dats ok!
WAINGOR
@WAINGOR
Aug 09 2017 10:19 UTC
@Masd925 U hurt my feelings 8*( I thought we had bonded
Markus Kiili
@Masd925
Aug 09 2017 10:21 UTC
@EpicTriffid For loop can iterate well over incremented indices, so you can loop array elements and also array-like object like strings. for...in loop is for iterating over object property keys (enumerable properties of the object and the prototype chain).
@WAINGOR We have, I don't bond with regexp voluntarily :rat:
WAINGOR
@WAINGOR
Aug 09 2017 10:22 UTC
@Masd925 XD XD <3
EpicTriffid
@EpicTriffid
Aug 09 2017 10:23 UTC
Perfect. So, to simplify, For loops for objects involving numbers in any order, for...in loops for objects that have properties you need to be accessing?
prakash chandra yadav
@prakashyadav008
Aug 09 2017 10:23 UTC
thats a local variable @Masd925
Markus Kiili
@Masd925
Aug 09 2017 10:23 UTC
@prakashyadav008 What is?
Your code had a global variable:
var array = [];
EpicTriffid
@EpicTriffid
Aug 09 2017 10:25 UTC
Im trying to take two letters from the beginning of a word and shove them on the end.
return str.slice(1) + str.slice(0,1)
that takes the first letter
I would imagine that:
return str.slice(2) + str.slice(0,2)
would take the first two
But it aint working
Markus Kiili
@Masd925
Aug 09 2017 10:27 UTC
@EpicTriffid Strings are immutable, so the original string is not affected. Slice just makes a new string.
EpicTriffid
@EpicTriffid
Aug 09 2017 10:27 UTC
So do I need to assign that second one to a new variable?
Markus Kiili
@Masd925
Aug 09 2017 10:27 UTC
str = str.slice(2) would change the string held in str.
prakash chandra yadav
@prakashyadav008
Aug 09 2017 10:27 UTC
i mean ur code example @Masd925
Markus Kiili
@Masd925
Aug 09 2017 10:29 UTC
@prakashyadav008 Yes, the variable is local, as it should.
Blauelf
@Blauelf
Aug 09 2017 10:39 UTC

@EpicTriffid Better not use for..in on arrays or array-likes. First, there's no guaranteed order. Then, for..in walks through all enumerable properties, inherited or not. If I used a polyfill to add some method to Array.prototype, and used a simple assignment instead of Object.defineProperty, it would automatically be enumerable and would show up in the for..in over any array.

In a for loop using the length property, you control the order. You are never affected by enumerable non-numeric properties, because your index is numeric.

@EpicTriffid And in my previous code, the return str.slice(i) + str.slice(0, i) + "ay"; should work for any i. So why do you say "it aint working"? What is the code you execute, what do you expect, what happens instead?
Blauelf
@Blauelf
Aug 09 2017 10:46 UTC
@WAINGOR What do you want to match? Something like /\S+/g?
bilaal-s
@bilaal-s
Aug 09 2017 10:48 UTC
Hello guys, sorry to be a bother, at work trying to get this calculator project going. I have my click event firing twice in a row if i: type a number, press add, type another number, press add (result appears) and then type (here the number pressed is added twice). i put a console log showing that the click event fired twice, don't know why T_T https://codepen.io/bilaal-s/pen/QMjVKK?editors=1010
if anyone wants to attempt to help, please rerun the calculator after adding two number and typing a third, otherwise the number will become too big and it will be tricky to track in console
how can a event fire twice without a loop or anything? granted there are two events in the code, but the other has a condition on it which is not hit, and this is confirmed in the console output as it only logs secondary click event fired
bilaal-s
@bilaal-s
Aug 09 2017 11:09 UTC
$(".button").unbind("click").on("click", function() { seems to have fixed the issue
Stephen James
@sjames1958gm
Aug 09 2017 11:14 UTC
@bilaal-s You have to be careful when you have click handlers assigned within other callbacks, because you can get more than on handler attached
and you will get this double behavior.
bilaal-s
@bilaal-s
Aug 09 2017 11:34 UTC
@sjames1958gm is unbinding the event best practice? or should i restructure the code?
@sjames1958gm thanks bytheway
CamperBot
@camperbot
Aug 09 2017 11:34 UTC
bilaal-s sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8280 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 09 2017 11:37 UTC
@bilaal-s Probably a style choice
  1. Bind everything once, and have some sort of state that says whether to act on the event.
  2. bind/unbind based on other clicks
    I don't know if unbind is an expensive operation.
    My personal choice is 1. but I won't say that is best or better.
Venkateshwaran
@Venkateshwaran
Aug 09 2017 11:41 UTC
<script>

for (let i = 0; i < 10; i++) {
  console.log(i);
  setTimeout(function(){
    console.log("the number is "+ i);
  }, 1000)
}
</script>
When I ran this.. I am getting the output
 0
 1
 2
 3
 4
 5
 6
 7
 8
 9
 the number is 0
 the number is 1
 the number is 2
 the number is 3
 the number is 4
 the number is 5
 the number is 6
 the number is 7
 the number is 8
 the number is 9
Same thing.. If I used var i=0 in the for loop , I am getting
0
 1
 2
 3
 4
 5
 6
 7
 8
 9
 the number is 10
can someone explain what is happening?
Markus Kiili
@Masd925
Aug 09 2017 11:43 UTC
@Venkateshwaran When you use var, you create a global variable that all those callbacks use. So the number is 10 is printed 10 times.
So that script runs and i ends up with value 10 and later those timeout events fire and callbacks are run.
Venkateshwaran
@Venkateshwaran
Aug 09 2017 11:48 UTC
@Masd925 so, the for loop does not wait for settimeout function to finish running. ?
Ene Catalin
@EneCatalin
Aug 09 2017 11:48 UTC
@Venkateshwaran maybe check this out
I am not familiar with the let myself
Markus Kiili
@Masd925
Aug 09 2017 11:49 UTC
@Venkateshwaran setTimeout just binds a function to the event. So it tells the browser to run the callback function after certain time has passed. That script runs almost immediately, and doesn't wait for callbacks to run.
Venkateshwaran
@Venkateshwaran
Aug 09 2017 11:51 UTC
@Masd925 when I am using let, where is the value of is stored?
how is it printing 0, 1, 2, 3...
?
I am sorry if this is very basic question and I am complicating it.
Markus Kiili
@Masd925
Aug 09 2017 11:55 UTC
@Venkateshwaran Those callback functions have access to the block scope created by let. So the variable stays alive on the closure of the callback. I am not too familiar with ES6, so eat my stew at arms length.
With var, all those callbacks would have access to the same variable on the global scope.
Stephen James
@sjames1958gm
Aug 09 2017 11:56 UTC
@Venkateshwaran When you use let each loop through the for creates a separate context which stores i
When you use var i there is only a single context that stores i
These contexts are then used when the callback is run
Venkateshwaran
@Venkateshwaran
Aug 09 2017 11:59 UTC
@sjames1958gm @Masd925 OK. So in var case , the i value has reached 10. and it is available at global scope. So by the time setTimeout is called it picks the last value of i which is 10, Right? correct me if I am wrong
Stephen James
@sjames1958gm
Aug 09 2017 12:00 UTC
@Venkateshwaran :+1:
Venkateshwaran
@Venkateshwaran
Aug 09 2017 12:01 UTC
@sjames1958gm @Masd925 and In let case each for loop becomes a different block ?
Markus Kiili
@Masd925
Aug 09 2017 12:01 UTC
@Venkateshwaran Yes with var, when any of those callback function is executed, i is found on the global scope.
@Venkateshwaran With let, it is found on the block scope created by a loop step.
Stephen James
@sjames1958gm
Aug 09 2017 12:03 UTC
To be very specific it is not a variable at global scope that is being accessed, it is a variable in the closed scope.
here in this function i is not in the global scope but is in the greater (non-block) scope of the timeout function
So you would see the same behavior
function x() {
  for (var i = 0; i < 10; i++) {
    console.log(i);
    setTimeout(function(){
      console.log("the number is "+ i);
    }, 1000)
  }
}
Venkateshwaran
@Venkateshwaran
Aug 09 2017 12:06 UTC
@Masd925 @sjames1958gm ok. I get it now. does that mean let takes more space, because it makes 10 block scopes?
Stephen James
@sjames1958gm
Aug 09 2017 12:07 UTC
@Venkateshwaran That I don't know.
Venkateshwaran
@Venkateshwaran
Aug 09 2017 12:10 UTC
@sjames1958gm thanks :)
CamperBot
@camperbot
Aug 09 2017 12:10 UTC
venkateshwaran sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8281 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Blauelf
@Blauelf
Aug 09 2017 12:11 UTC
As each function expression holds a reference to its own version of i, that's more space than one. But before that, you would have used a closure, which is probably even more overhead.
Venkateshwaran
@Venkateshwaran
Aug 09 2017 12:11 UTC
@Masd925 thanks to you too.
CamperBot
@camperbot
Aug 09 2017 12:11 UTC
venkateshwaran sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4396 | @masd925 |http://www.freecodecamp.com/masd925
Venkateshwaran
@Venkateshwaran
Aug 09 2017 12:12 UTC
@Blauelf you mean in var case I used closure, and that is more heavy?
Stephen James
@sjames1958gm
Aug 09 2017 12:13 UTC
@Blauelf Wouldn't both be closure, just with differently organized contexts?
Markus Kiili
@Masd925
Aug 09 2017 12:14 UTC
@sjames1958gm Before let, an implementation of the let case would have used closure and caused more overhead.
Stephen James
@sjames1958gm
Aug 09 2017 12:16 UTC
@Masd925 They are both using closure. The let doesn't change that the function is closing over a context.
The let creates an addition block scope that likely increases the overhead of the closures.
Venkateshwaran
@Venkateshwaran
Aug 09 2017 12:16 UTC
@Masd925 @sjames1958gm @Blauelf so using var appropriately would be better than using let ?
Markus Kiili
@Masd925
Aug 09 2017 12:17 UTC
@sjames1958gm Yes, all smell like closure. I just tried to explain what @Blauelf said.
@sjames1958gm Old implementation would most likely use some wrapper function or such.
Stephen James
@sjames1958gm
Aug 09 2017 12:18 UTC
@Masd925 Ah, I see. My misunderstanding
@Masd925 thx
CamperBot
@camperbot
Aug 09 2017 12:18 UTC
sjames1958gm sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4397 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Aug 09 2017 12:19 UTC
@sjames1958gm Well, I didn't say it very clearly. Thanks too.
CamperBot
@camperbot
Aug 09 2017 12:19 UTC
masd925 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8282 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 09 2017 12:19 UTC
Brownies for EVERYONE ! ;)
Markus Kiili
@Masd925
Aug 09 2017 12:20 UTC
help brownie dilution
:(
Abhishek Kumar Pandey
@abhishekpandeykr
Aug 09 2017 12:26 UTC
how to use Object.assign{} inside a class
Bartosz
@CataciD
Aug 09 2017 12:27 UTC
wait what
firstly what do you mean by class
and what is this monstrous consctruction with the brackets
Abhishek Kumar Pandey
@abhishekpandeykr
Aug 09 2017 12:28 UTC
js class i want to merge two objects inside a class, sorry that was Object.assign()
Stephen James
@sjames1958gm
Aug 09 2017 12:29 UTC
@abhishekpandeykr Why would inside a class have any impact on using Object.assign?
Abhishek Kumar Pandey
@abhishekpandeykr
Aug 09 2017 12:30 UTC
because i was not able to use, it was throwing error
is it mandatory , to use first object as blank
Bartosz
@CataciD
Aug 09 2017 12:31 UTC
what do you mean you want to merge two objects?
also in js a class is kind of um
not a class?
from what i know not in the sense of other languages
its just awkwardly been put here with no apparent reason than to appease the java devs
and it failed at that also
Markus Kiili
@Masd925
Aug 09 2017 12:32 UTC
@CataciD ES6 has class syntax (sugar).
Bartosz
@CataciD
Aug 09 2017 12:32 UTC
but no matter, could you be more specific?
as in extention of modules?
Stephen James
@sjames1958gm
Aug 09 2017 12:33 UTC
@abhishekpandeykr What is the error that it is throwing.
Bartosz
@CataciD
Aug 09 2017 12:33 UTC
also markus, that class syntax is pretty ridiculous from what i can tell
Stephen James
@sjames1958gm
Aug 09 2017 12:33 UTC
@abhishekpandeykr The first object does not have to be blank
Bartosz
@CataciD
Aug 09 2017 12:34 UTC
tho take my words with a grain of salt i might be talking shit
it just seems like a replacement word for a bigger 'OOOOBJECT"
Abhishek Kumar Pandey
@abhishekpandeykr
Aug 09 2017 12:34 UTC
done @sjames1958gm , you last statement was very powerful which makes me to make that correct
i was doing something silly
Bartosz
@CataciD
Aug 09 2017 12:34 UTC
as usualy
we're always doing something silly when we get where we went wrong now dont we?
Kelechi Chinaka
@ke1echi
Aug 09 2017 12:34 UTC
i am trying to code a function that returns only prime number, whats the condition going to look like?
Abhishek Kumar Pandey
@abhishekpandeykr
Aug 09 2017 12:34 UTC
lol
Markus Kiili
@Masd925
Aug 09 2017 12:35 UTC
@CataciD I agree that JS classes just mostly confuse things.
Stephen James
@sjames1958gm
Aug 09 2017 12:35 UTC
@kelechy if (number is prime) return number :)
Elizabeth Paul
@Kowalatam
Aug 09 2017 12:35 UTC
lol
Abhishek Kumar Pandey
@abhishekpandeykr
Aug 09 2017 12:35 UTC
lol
Bartosz
@CataciD
Aug 09 2017 12:35 UTC
@kelechy probably need to check if its dividable only by its self and 1
Kelechi Chinaka
@ke1echi
Aug 09 2017 12:35 UTC
since prime numbers are numbers that can be divided by 1 and itself
namethatisnottaken
@namethatisnottaken
Aug 09 2017 12:35 UTC
function generate(int) {
    if (int === 1) {
      // Make sure to join the characters as we create  the permutation arrays
      permutations.push(arr.join(''));
    } else {
      for (var i = 0; i != int; ++i) {
        generate(int - 1);
        swap(int % 2 ? 0 : i, int - 1); // why this cannot be altered using traditional if else ?
      }
    }
  }
hi can anyone help explain the difference between this function and below function ?
function generate(int) {
    if (int === 1) {
      // Make sure to join the characters as we create  the permutation arrays
      permutations.push(arr.join(''));
    } else {
      for (var i = 0; i != int; ++i) {
        generate(int - 1);
        if(int % 2 === 0){
          swap (0,int-1);
        }
        else{
          swap (int, int-1);
        }
      }
    }
  }
Kelechi Chinaka
@ke1echi
Aug 09 2017 12:36 UTC
if ((i % 1 ) && (i % i)) {
      prime.push(i)
    }
this is what i have
Bartosz
@CataciD
Aug 09 2017 12:36 UTC
@kelechy id advice you to google prime number algorithm
i found one that worked for me, there might be something better but im not actually sure
Elizabeth Paul
@Kowalatam
Aug 09 2017 12:37 UTC
that would just give him the answer tho
Kelechi Chinaka
@ke1echi
Aug 09 2017 12:37 UTC
function primes(start, end) {
  var prime = []
  for (var i = start; i <= end; i++) {
    if ((i % 1 ) && (i % i)) {
      prime.push(i);
    }
  }
  return prime;
}
it returns empty array
Bartosz
@CataciD
Aug 09 2017 12:37 UTC
thats the point
an algorithm is not coding
Kelechi Chinaka
@ke1echi
Aug 09 2017 12:37 UTC
ok @CataciD
namethatisnottaken
@namethatisnottaken
Aug 09 2017 12:37 UTC
@kelechy prime only have 2 factors 1 and itself if i am not mistaken
Bartosz
@CataciD
Aug 09 2017 12:37 UTC
there's no point in trying to figure out mathematical thesis if you havent seen them ever
Stephen James
@sjames1958gm
Aug 09 2017 12:37 UTC
@kelechy Do you know what makes a number prime?
Bartosz
@CataciD
Aug 09 2017 12:38 UTC
i can tell you my approach/algorithm without detail if you want
might've been a long way around and there might be something better suited or more efficient
but i was lazy
and im no math student
Kelechi Chinaka
@ke1echi
Aug 09 2017 12:38 UTC
yes @sjames1958gm it must be divisible by only 1 and itself
Stephen James
@sjames1958gm
Aug 09 2017 12:39 UTC
@namethatisnottaken int % 2 ? 0 : i this does the if / else check of the second function.
it will return 0 or i so you get two different calls to swap based on the value if int
Bartosz
@CataciD
Aug 09 2017 12:39 UTC
do you wan't it @kelechy ?
Kelechi Chinaka
@ke1echi
Aug 09 2017 12:39 UTC
i taught my kids at school the math, just trying apply the logic to code @sjames1958gm :smile:
sure @CataciD
Bartosz
@CataciD
Aug 09 2017 12:39 UTC
i found an algorithm thats basically bingo
you specify the range of numbers
Stephen James
@sjames1958gm
Aug 09 2017 12:39 UTC
@kelechy You can use the sieve method or just test every value from 2 to sqrt(i)
Bartosz
@CataciD
Aug 09 2017 12:39 UTC
and then have a grid filled with them
so for 1-10 you have a grid of numbers from 1 to 10
condition is 0 and 1 is not prime
namethatisnottaken
@namethatisnottaken
Aug 09 2017 12:40 UTC
@sjames1958gm hi James, yes i think there is not much different between the first function and the later right ? only perhaps the execution time ?
Bartosz
@CataciD
Aug 09 2017 12:40 UTC
from what i've read
so you start at 2
Stephen James
@sjames1958gm
Aug 09 2017 12:40 UTC
@namethatisnottaken The first function looks like it will pass i not int to the swap function
Bartosz
@CataciD
Aug 09 2017 12:40 UTC
first you take a number and then run through all the numbers
checking if any of them is divisible by it
Stephen James
@sjames1958gm
Aug 09 2017 12:40 UTC
@namethatisnottaken I doubt that there is much execution difference
Bartosz
@CataciD
Aug 09 2017 12:40 UTC
if a number is divisible (%number)
then remove it
Kelechi Chinaka
@ke1echi
Aug 09 2017 12:41 UTC
yea 1 is not prime @CataciD
Bartosz
@CataciD
Aug 09 2017 12:41 UTC
so the grid shortens
so in that case you have 2,3,4,5,6,7,8,9,10
on first step 2
removes 4,6,8,10
if end of table get next number
namethatisnottaken
@namethatisnottaken
Aug 09 2017 12:41 UTC
oh my God yes, i did not get it @_@
Bartosz
@CataciD
Aug 09 2017 12:41 UTC
go on to 3
namethatisnottaken
@namethatisnottaken
Aug 09 2017 12:41 UTC
lol
Bartosz
@CataciD
Aug 09 2017 12:41 UTC
3 eliminates 6,9
namethatisnottaken
@namethatisnottaken
Aug 09 2017 12:41 UTC
thanks @sjames1958gm
CamperBot
@camperbot
Aug 09 2017 12:41 UTC
namethatisnottaken sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
Bartosz
@CataciD
Aug 09 2017 12:41 UTC
but 6 already eliminated
CamperBot
@camperbot
Aug 09 2017 12:41 UTC
:star2: 8283 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Bartosz
@CataciD
Aug 09 2017 12:41 UTC
4 is eliminated
5
eliminates nothing cause 10 is gone
then 7
you're left with 2,3,5,7
voila
you got the prime numbers in range of 1-10
so if i wanted to check if a number is prime i could generate them up to that number
or just generate primes constantly until i find one that divides it
sounds a bit confusing i think
but it worked xP
Markus Kiili
@Masd925
Aug 09 2017 12:43 UTC
@kelechy Another fairly simple way is to test the looped candidate number for divisibility against the primes generated so far.
Kelechi Chinaka
@ke1echi
Aug 09 2017 12:44 UTC
that was sure confusing.. can you send me the link so i can read through? @CataciD
Bartosz
@CataciD
Aug 09 2017 12:44 UTC
@kelechy yeah that's the second part i mentioned
the idea is to generate numbers while dividing by previous ones
is something is divisible by anything it's not a prime
here ya go
eratosthenes
a cool dude
Kelechi Chinaka
@ke1echi
Aug 09 2017 12:45 UTC
i think i am going to make a kata outta this @sjames1958gm :smile:
thanks @CataciD
CamperBot
@camperbot
Aug 09 2017 12:45 UTC
kelechy sends brownie points to @catacid :sparkles: :thumbsup: :sparkles:
:cookie: 417 | @catacid |http://www.freecodecamp.com/catacid
Stephen James
@sjames1958gm
Aug 09 2017 12:46 UTC

@namethatisnottaken There is a difference: This is the first code changed to if / else

if (int % 2) {
    swap(0, int-1); // so when int % 2 is not zero
} else {
    swap(i, int-1); // here i is used not int
}

looks like the if / else are swapped and the else is using i not int

namethatisnottaken
@namethatisnottaken
Aug 09 2017 12:47 UTC
yes i missed that haha been trying to find the difference for hours only to miss that :sob:
Stephen James
@sjames1958gm
Aug 09 2017 12:47 UTC
@kelechy :+1:
namethatisnottaken
@namethatisnottaken
Aug 09 2017 12:49 UTC
@kelechy An integer is prime if it is not divisible by any prime less than or equal to its square root
Blauelf
@Blauelf
Aug 09 2017 13:12 UTC
@sjames1958gm You're right, a block scope referenced from a function expression within is also a closure. I always associate "closure" with "function scope", because previously there were no block scopes.
Diego Mayer
@Chrono79
Aug 09 2017 13:51 UTC
Can I fire a PHP file execution with Ajax and don't wait for an answer? The PHP script should wait 5 minutes and do something that doesn't require the user interaction
Moisés Man
@moigithub
Aug 09 2017 14:08 UTC
sure.. why not ? @Chrono79
Roxroy
@roxroy
Aug 09 2017 14:09 UTC
@Chrono79, create a php route that is callable from your frontend. Add code to the route to run the backend code you want to be executed.
Stephen James
@sjames1958gm
Aug 09 2017 14:10 UTC
@Chrono79 You have to at least respond with 200 OK to satisfy http
Diego Mayer
@Chrono79
Aug 09 2017 14:13 UTC
I'll copy the whole explanation of what I'm trying to accomplish here too
I'm working on a custom made shopping cart, the validation of the credit card is done by an external provider, I sent the amount and credit card brand beforehand and after some steps I send a form with some data to them via a form using post method, the customer goes to the external site and when finished there, he should come back to my site using post again and my code starts from there to process if the operation was successful or not.
Sometimes the response from the external provider never comes back so my code never run, and I want to check the operation automatically when that happens making a call to the external provider
Moisés Man
@moigithub
Aug 09 2017 14:26 UTC
maybe.. depends on the payment gateway u using... require some configuration (i dunno never used)
Tao
@zombiebirds
Aug 09 2017 14:39 UTC
function largestOfFour(arr) {
// 请把你的代码写在这里
var newarr = [];
var max ;
for(i=0 ; i<arr.length;i++){ for(j=0;j<arr[i].length;j++){ max = arr[i][0]; if(arr[i][j]>max){
max = arr[i][j];
}
}
newarr.push(max);
}
return newarr;
What's wrong?
Moisés Man
@moigithub
Aug 09 2017 14:56 UTC
@zombiebirds 0>undefined //false
initialize max
also u need to return a number value.. not an array
WAINGOR
@WAINGOR
Aug 09 2017 14:58 UTC

Hi all I have a question: why does this:

console.log (!undefined === "jack") ;
VM2539:1 false
undefined
console.log(!undefined === "jack");
VM2581:1 false
undefined

both return false?!

forget abt the lines with VM in them
Excuse me
this was not the right code

This is the right code:

console.log(!undefined === "jack");
//false
undefined
console.log(undefined === "jack");
// false

How can this be?

Diego Mayer
@Chrono79
Aug 09 2017 15:01 UTC
@WAINGOR you're using strict comparison, !undefined isn't "jack"
console.log(!undefined);
//true
Brad
@bradtaniguchi
Aug 09 2017 15:03 UTC
Its the wrong check, !undefined is being checked. You should check
console.log(undefined !== 'jack'); // should be true
Tao
@zombiebirds
Aug 09 2017 15:04 UTC
@moigithub thanks!
CamperBot
@camperbot
Aug 09 2017 15:04 UTC
zombiebirds sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3573 | @moigithub |http://www.freecodecamp.com/moigithub
Moisés Man
@moigithub
Aug 09 2017 15:09 UTC
undefined and 'jack' are different values
they never gonna be equal @WAINGOR
WAINGOR
@WAINGOR
Aug 09 2017 15:09 UTC
Thanks @Chrono79 !!
CamperBot
@camperbot
Aug 09 2017 15:09 UTC
waingor sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4512 | @chrono79 |http://www.freecodecamp.com/chrono79
WAINGOR
@WAINGOR
Aug 09 2017 15:10 UTC
@moigithub I understood that :) that wasnt my fallacy... It was presuming that !undefined === "jack" meant: return true if undefined equals jack .... but I found out that that should be written as !(undefined === "Jack")
Moisés Man
@moigithub
Aug 09 2017 15:12 UTC
since undefined and "jack" are different values..
ie 1==2 that will always be false
! (NOT operator)
!false === true
Stephen James
@sjames1958gm
Aug 09 2017 15:21 UTC
@WAINGOR https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence
The operator precendence shows ! at a higher precendence that === so the !undefined gets evaluated before the === "jack"
Brad
@bradtaniguchi
Aug 09 2017 15:23 UTC
oops my syntax isn't even valid, thats what I get for winging it
WAINGOR
@WAINGOR
Aug 09 2017 15:31 UTC
Thanks @sjames1958gm ... and this is correct right:
I was presuming that !undefined === "jack" meant: return true if undefined equals jack .... but I found out that that should be written as !(undefined === "Jack")
CamperBot
@camperbot
Aug 09 2017 15:31 UTC
waingor sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8284 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 09 2017 15:31 UTC
@WAINGOR Yes
WAINGOR
@WAINGOR
Aug 09 2017 15:32 UTC
Lol this was a wallbanger for me (to clearify: its a word I invented 3 seconds ago to describe a problem which has you banging your head against the wall for hours)
Addison
@addisonday
Aug 09 2017 16:20 UTC
I DONT want the answer but can someone help me figure out why I am getting a "Syntax Error: Unexpected token '{'"? I am not sure where my mistake is.

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


function lookUpProfile(firstName, prop){
// Only change code below this line
for (i = 0; i < contacts[i].length; i++){
  if (firstName && prop === true){
    return firstName.prop;
  } else (prop === false){
    return "No such property";
  } else (firstName === false){
    return "No such contact";
  }
}
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
Jason Luboff
@JLuboff
Aug 09 2017 16:21 UTC
@addisonday You're using else instead of else if. else does not have a condition
Also, you'll only want to return "No such contact" outside of your loop
Kelechi Chinaka
@ke1echi
Aug 09 2017 16:22 UTC
function trim(str, size) {
  if (str.length > size){
    return str.slice(0, (size - 3)) + '...';
  }
  if (str.length < 3) {
    //this is the prob line
    return str.slice(0, size) + '...'
  }
  else{
    return str;
  }
}
someone help me with an extra eye here, passes all except one test

```If the string is smaller than or equal to 3 characters then the length of the dots is not added to the string length.

e.g. trim("He", 1) should return "H..."```

Jason Luboff
@JLuboff
Aug 09 2017 16:24 UTC
@kelechy Link to the challenge?
Addison
@addisonday
Aug 09 2017 16:24 UTC
"less than or equal to" @kelechy
Kelechi Chinaka
@ke1echi
Aug 09 2017 16:25 UTC
does not work even if i did str.length <= 3
Stephen James
@sjames1958gm
Aug 09 2017 16:27 UTC
@kelechy Think about your order of operations, will the first if make it so you never reach this test?
bilaal-s
@bilaal-s
Aug 09 2017 16:27 UTC
147 lines of code for my javascript calculator so far
lol
Addison
@addisonday
Aug 09 2017 16:29 UTC
Thank you @JLuboff btw. That's a good thing to keep in mind!
CamperBot
@camperbot
Aug 09 2017 16:29 UTC
addisonday sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2138 | @jluboff |http://www.freecodecamp.com/jluboff
Christopher McCormack
@cmccormack
Aug 09 2017 16:29 UTC
@bilaal-s yeah lots of different cases to keep track of in that one
Kelechi Chinaka
@ke1echi
Aug 09 2017 16:29 UTC
oop... :hand: i hail thee @sjames1958gm :smile:
am I the only person that feels this particular room is more important than the oval office? :smile:
Christopher McCormack
@cmccormack
Aug 09 2017 16:32 UTC
I'd say that's a fair assessment :D
Kelechi Chinaka
@ke1echi
Aug 09 2017 16:33 UTC
:smile:
are you done with it @JLuboff
Jason Luboff
@JLuboff
Aug 09 2017 16:36 UTC
@kelechy Haven't started lol
Kelechi Chinaka
@ke1echi
Aug 09 2017 16:41 UTC
ok...hows your backend project going? @JLuboff
Jason Luboff
@JLuboff
Aug 09 2017 16:41 UTC
Finished Nightlife App. Slowly starting Stock Chart App. But been focusing on studying for a certification test for work
Ronique Ricketts
@RoniqueRicketts
Aug 09 2017 16:42 UTC
hey guys I am having an unexpected result in my project when I choose my Destiny it wont make my selection disappear. Someone tell me what I did wrong.https://codepen.io/Ronique/pen/EXMRNB?editors=1111
Kelechi Chinaka
@ke1echi
Aug 09 2017 16:42 UTC
o cool @JLuboff
Christopher McCormack
@cmccormack
Aug 09 2017 16:49 UTC
@RoniqueRicketts do you want this maybe?
document.querySelector("#destiny").style.display = 'none'
Abid Rahim
@abidRahim
Aug 09 2017 16:49 UTC

@Masd925 please help

`
function destroyer(arr) {

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

for (var i=1; i<arguments.length; i++)
{
if (val === arguments[i])
return false;
}

return true;

});

}
`

can't think beyond this :/
Thayyeb salim
@Thayyebsalim
Aug 09 2017 16:49 UTC
use three backticks to format code
Ronique Ricketts
@RoniqueRicketts
Aug 09 2017 16:49 UTC
@cmccormack i know that works but why can't I set an attribute
Christopher McCormack
@cmccormack
Aug 09 2017 16:50 UTC
@abidRahim arguments.length will be 2
@abidRahim what are you trying to iterate over?
Abid Rahim
@abidRahim
Aug 09 2017 16:51 UTC
the arguments.. and if they match with 'val' from the destroyer parameter arr, then it should filter out
@cmccormack
Christopher McCormack
@cmccormack
Aug 09 2017 16:51 UTC
@RoniqueRicketts
document.querySelector("#destiny").setAttribute("hidden", "");
Ronique Ricketts
@RoniqueRicketts
Aug 09 2017 16:51 UTC
@cmccormack thanks man your a lifesaver
CamperBot
@camperbot
Aug 09 2017 16:51 UTC
roniquericketts sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1109 | @cmccormack |http://www.freecodecamp.com/cmccormack
Abid Rahim
@abidRahim
Aug 09 2017 16:52 UTC
Christopher McCormack
@cmccormack
Aug 09 2017 16:52 UTC
@abidRahim if I remember that exercise correctly, arguments will contain two arrays, your destroy as arguments[0] and seek as arguments[1]. your loop iterates over just those two items
oh sorry looks like seek are different arguments
@abidRahim use indexOf to check within arguments[0] instead
Abid Rahim
@abidRahim
Aug 09 2017 16:53 UTC
okay
what do i return after comparing
within filter's anonymous function
Stephen James
@sjames1958gm
Aug 09 2017 16:55 UTC
@abidRahim return true if you want to keep the value false if you want to drop
Christopher McCormack
@cmccormack
Aug 09 2017 16:55 UTC
hmm sorry @abidRahim I really didn't read your code closely, if you want to use filter, you should be able to, but are you returning your result?
Abid Rahim
@abidRahim
Aug 09 2017 16:55 UTC
yes i am
i'll try your suggestion and get back
Stephen James
@sjames1958gm
Aug 09 2017 16:55 UTC
@abidRahim the arguments inside the filter function are for that function not destroyer
Abid Rahim
@abidRahim
Aug 09 2017 16:56 UTC
oh right
Christopher McCormack
@cmccormack
Aug 09 2017 16:56 UTC
you can simplify a bit using:
return (val !== arguments[i])
Abid Rahim
@abidRahim
Aug 09 2017 16:57 UTC
i actually tried that
Stephen James
@sjames1958gm
Aug 09 2017 16:57 UTC
@abidRahim a simple assignment var args = arguments, will make it available as args
Abid Rahim
@abidRahim
Aug 09 2017 16:57 UTC
brb
Stephen James
@sjames1958gm
Aug 09 2017 16:57 UTC
@cmccormack That won't work because you have to return true only if it doesn't match any of arguments 1-n
Christopher McCormack
@cmccormack
Aug 09 2017 16:58 UTC
@sjames1958gm ah good point
Addison
@addisonday
Aug 09 2017 17:24 UTC
Okay, I am not getting syntax errors anymore but my function is returning no values. Can someone help point me in the right direction?

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


function lookUpProfile(firstName, prop){
// Only change code below this line
for (i = 0; i < contacts[i].length; i++){
  if (firstName && prop === true){
    return contacts[firstName][prop];
  } else if (prop === false){
    return "No such property";
  } else if (firstName === false){
    return "No such contact";
  }
}
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
Jason Luboff
@JLuboff
Aug 09 2017 17:25 UTC
@addisonday Try i < contacts.length not contacts[i]`
Addison
@addisonday
Aug 09 2017 17:25 UTC
@JLuboff Same result
Jason Luboff
@JLuboff
Aug 09 2017 17:28 UTC
@addisonday Ok, couple of other items. firstName && prop === true this is not valid syntax, you must make each comparison sperate ie. firstName === true && prop === true But thats not going to work either, you want to actually check if contacts has those properties using something like .hasOwnProperty
@kelechy My one line solution
const trim = (arr, size) => arr.length < 3 ? `${arr.slice(0, size)}...` : arr.length > size ? `${arr.slice(0, size-3)}...` : arr
Addison
@addisonday
Aug 09 2017 17:29 UTC
@JLuboff Thank you for making me aware of that syntax mistake! I'll give the other suggestion a try.
CamperBot
@camperbot
Aug 09 2017 17:29 UTC
addisonday sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2140 | @jluboff |http://www.freecodecamp.com/jluboff
Ronique Ricketts
@RoniqueRicketts
Aug 09 2017 17:30 UTC
I just started using the browser console and I really like this thing. It makes finding errors so much easier. Console is the best thing since slice bread!!!
Addison
@addisonday
Aug 09 2017 17:30 UTC
@RoniqueRicketts The console is incredibly useful
Ronique Ricketts
@RoniqueRicketts
Aug 09 2017 17:30 UTC
@addisonday yeah it is man. I love it
juni
@junipberry
Aug 09 2017 17:38 UTC
Hello guys, could I get some help turning an object into an array without using any of the object functions
/methods
Jason Luboff
@JLuboff
Aug 09 2017 17:40 UTC
@junipberry Use a loop to push the object elements into an array?
juni
@junipberry
Aug 09 2017 17:43 UTC
but before I push into an array, do I get object elements to split into strings, to transform into an array?
Jason Luboff
@JLuboff
Aug 09 2017 17:44 UTC
Can you give an example of one of the objects?
juni
@junipberry
Aug 09 2017 17:47 UTC
date: “Wednesday”,
weather: “sunny”,
month: “August”
}
Ene Catalin
@EneCatalin
Aug 09 2017 17:47 UTC
guys if I want to make a countdown timer is it easier to use the Date or to just run a -- at 1 second intervals ? Asking for the pomodoro project
juni
@junipberry
Aug 09 2017 17:48 UTC
sorry there should be a { in the beginning
Jason Luboff
@JLuboff
Aug 09 2017 17:50 UTC

@junipberry And what format do you want the array to be?

[["date", "Wednesday"], ["weather"....]]

or

["date", "Wednesday", "weather"...]

or

["Wednesday", "sunny"...]
Thayyeb salim
@Thayyebsalim
Aug 09 2017 17:51 UTC
It's behaving weird
juni
@junipberry
Aug 09 2017 17:51 UTC
I believe the first one, bc I will push out [0] of each element. I need an array of all keys
Jason Luboff
@JLuboff
Aug 09 2017 17:55 UTC
@junipberry Something like this would work:
let obj = {
    date: "Wednesday",
    weather: "sunny",
    month: "August"
};

let arr = [];
for(let key in obj) {
    arr.push([key, obj[key]]);
}

console.log(arr); // Result: [ [ 'date', 'Wednesday' ], [ 'weather', 'sunny' ], [ 'month', 'August' ] ]
Moisés Man
@moigithub
Aug 09 2017 17:56 UTC
let arr = Object.entries(obj)
es7 ?
Jason Luboff
@JLuboff
Aug 09 2017 17:57 UTC
@moigithub She doesn't want to use any Object methods
Moisés Man
@moigithub
Aug 09 2017 17:57 UTC
ahh ok :D
Kelechi Chinaka
@ke1echi
Aug 09 2017 18:00 UTC
already using es7? pls slow down :smile: @moigithub
juni
@junipberry
Aug 09 2017 18:03 UTC
ty @JLuboff , I’ve actually been struggling with the for..in loop on this for awhile. Its not passing the test..comes up as undefined.
CamperBot
@camperbot
Aug 09 2017 18:03 UTC
junipberry sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2141 | @jluboff |http://www.freecodecamp.com/jluboff
Jason Luboff
@JLuboff
Aug 09 2017 18:03 UTC
@junipberry What is this for?
juni
@junipberry
Aug 09 2017 18:04 UTC
I’m just practicing on a prep site
Jason Luboff
@JLuboff
Aug 09 2017 18:04 UTC
Can you link to it or is it private?
juni
@junipberry
Aug 09 2017 18:04 UTC
its private, bc the questions are only accessible w a login
Jason Luboff
@JLuboff
Aug 09 2017 18:05 UTC
:+1:
juni
@junipberry
Aug 09 2017 18:05 UTC
:/
Addison
@addisonday
Aug 09 2017 18:05 UTC
Not sure what I am missing here... Am I going about this the right way?

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


function lookUpProfile(firstName, prop){
// Only change code below this line
for (i = 0; i < contacts.length; i++){
  if (contacts.hasOwnProperty([prop])){
    return contacts.firstName[prop];
  } else if (prop === false){
    return "No such property";
  }
}
if (firstName === false){
  return "No such contact";
}
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
Tarun Khandelwal
@Delwalt
Aug 09 2017 18:05 UTC
Hello Buys
guys*
Jason Luboff
@JLuboff
Aug 09 2017 18:06 UTC
@addisonday contact.hasOwnProperty(prop)
Addison
@addisonday
Aug 09 2017 18:07 UTC
Why not use bracket notation? We don't know what the user can input for prop correct?
juni
@junipberry
Aug 09 2017 18:08 UTC
If I want to do the for..in loop within a function, do I label the console.log(arr) as result. Then call for the function variable of that result?
Addison
@addisonday
Aug 09 2017 18:08 UTC
@JLuboff The function is returning nothing
Jason Luboff
@JLuboff
Aug 09 2017 18:09 UTC
@addisonday You're telling hasOwnProperty what property to look for. In this case, prop is our parameter which acts as a variable, so it's assigned by the function call (in this case, it defined as "likes"). By adding brackets, you're telling it look for ["likes"] instead of "likes"
@junipberry I just used console.log as an example, and becuase I didn't have a function I couldn't use return. If this is inside a function, you can instead use return
and you can return whatever variable name you like. You don't have to use arr
Stephen James
@sjames1958gm
Aug 09 2017 18:10 UTC
@Delwalt :wave:
Moisés Man
@moigithub
Aug 09 2017 18:10 UTC
@kelechy Object.entries seems its not es7 but part of es8 (ecmascript 2017)
http://exploringjs.com/es2016-es2017/index.html#toc_ch_object-entries-object-values
Stephen James
@sjames1958gm
Aug 09 2017 18:11 UTC
@addisonday You should be using contacts[i] not contacts inside the loop
Addison
@addisonday
Aug 09 2017 18:11 UTC
@JLuboff I still am getting nothing returned
@sjames1958gm I had that originally and was told to change it :/
Stephen James
@sjames1958gm
Aug 09 2017 18:12 UTC
@addisonday contacts[i][prop] is the value to return if the property exists.
firstName and prop are strings and won't === false
Jason Luboff
@JLuboff
Aug 09 2017 18:12 UTC
@addisonday I had only told you to change to i < contacts.length, which is what we want. @sjames1958gm is refering to actually inside the for loop
Stephen James
@sjames1958gm
Aug 09 2017 18:12 UTC
@addisonday I did mean inside the loop not in the for loop test
Addison
@addisonday
Aug 09 2017 18:13 UTC
@sjames1958gm I see what you mean now
juni
@junipberry
Aug 09 2017 18:19 UTC

@JLuboff
could you take a look at this:
```function getKeys(obj){
let myArr = [];

for(let key in obj){
myArr.push([key,obj[key]]);
}
return myArr;
}
```

function getKeys(obj){
let myArr = [];
for(let key in obj){
myArr.push([key,obj[key]]);
}
return myArr;
}
Jason Luboff
@JLuboff
Aug 09 2017 18:20 UTC
Looks good to me? I'm guessing it's not passing though?
juni
@junipberry
Aug 09 2017 18:20 UTC
no..
Jason Luboff
@JLuboff
Aug 09 2017 18:21 UTC
Can you show the full instructions of the challenge?
juni
@junipberry
Aug 09 2017 18:22 UTC
Write a function called "getKeys" which returns an array of all the input object's keys.
Example input: 
{
  name : 'Sam',
  age : 25,
  hasPets : true
}

Function's return value (output) :
['name', 'age', 'hasPets’]
Do not use "Object.keys" to solve this prompt.

Note that your function should be able to handle any object passed in it.

E.g. it should also handle an input like:
{
  a : 'a',
  number : 11,
  hungry : true,
  grammyWins : 1
}

Function's return value (output):
['a', 'number', 'hungry', 'grammyWins’]
Jason Luboff
@JLuboff
Aug 09 2017 18:23 UTC
@junipberry Oh, so you just need the keys
juni
@junipberry
Aug 09 2017 18:23 UTC
yes~
Jason Luboff
@JLuboff
Aug 09 2017 18:24 UTC
So just do myArr.push(key);
I thought you need the key and value
juni
@junipberry
Aug 09 2017 18:25 UTC
ahh
I thought I was only pushing the [keys] from the obj..
ty @JLuboff !
CamperBot
@camperbot
Aug 09 2017 18:27 UTC
junipberry sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:warning: junipberry already gave jluboff points
Jason Luboff
@JLuboff
Aug 09 2017 18:27 UTC
:+1:
Thayyeb salim
@Thayyebsalim
Aug 09 2017 18:28 UTC
@JLuboff Can you take a peek at my code
The second ajax call is messing up
just check the console
Jason Luboff
@JLuboff
Aug 09 2017 18:32 UTC
@Thayyebsalim Can you be more specific of the issue?
Adam Bohannon
@abohannon
Aug 09 2017 18:33 UTC
Hey all, quick question about event handlers and 'this'. When used inside an event handler, does 'this' always refer to the current event being triggered? Here's some code I was working with earlier:
const checkboxes = document.querySelectorAll('.inbox input[type="checkbox"]');

let lastChecked;

  function handleCheck(e) {

        lastChecked = this;

      }

checkboxes.forEach(checkbox => checkbox.addEventListener('click', handleCheck));
in this case, this equals my e.target. I'm not too comfortable using 'this' yet, so just curious.
Thayyeb salim
@Thayyebsalim
Aug 09 2017 18:38 UTC
@JLuboff the loops works perfect for the first json call, in the second json call it just keeps the value of the last elt in the array
image.png
Jason Luboff
@JLuboff
Aug 09 2017 18:40 UTC
Ah
It looks like channels is fine, but streams is always the last user in the array. My guess is its due to the async nature of .getJSON. but I'm not positive
Thayyeb salim
@Thayyebsalim
Aug 09 2017 18:43 UTC
Yeah that's it
but I have no idea how to bypass it :worried:
Jason Luboff
@JLuboff
Aug 09 2017 18:48 UTC
@Thayyebsalim Try this
detailUrl = "https://wind-bow.glitch.me/twitch-api/channels/" + user;

    $("#streamers").append("<div class='user' id="+user+"></div>");
    $.getJSON(detailUrl,function(detail){
      streamUrl = "https://wind-bow.glitch.me/twitch-api/streams/" + user;

      $.getJSON(streamUrl, function(current){
I believe the issue is that the first JSON call gets ran, and takes time. In the meantime, the forEach keeps running, thus changing the streamUrl user by the time the second JSON call occurs
Addison
@addisonday
Aug 09 2017 18:53 UTC
@JLuboff How do you validate the user input for firstName? Not sure how I am overlooking this
Jason Luboff
@JLuboff
Aug 09 2017 18:54 UTC
@addisonday Validate in what regard?
Addison
@addisonday
Aug 09 2017 18:54 UTC
@JLuboff in the case that it doesn't exist
Jason Luboff
@JLuboff
Aug 09 2017 18:56 UTC
@addisonday All you need is return "No such contact" outside your loop, you loop is already assessing (inside or at least it should be ;)) that the user exists or doesn't
Atleast, if I remember correctly. Its been a while since I've looked at that challenge
Addison
@addisonday
Aug 09 2017 18:59 UTC

@JLuboff Here is what I have now.


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


function lookUpProfile(firstName, prop){
// Only change code below this line
for (i = 0; i < contacts.length; i++){
  if (contacts[i].hasOwnProperty(prop)){
    return contacts[i][prop];
  } else {
    return "No such property";
  } 
}  
  return "No such contact";
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");

Two of the 5 tests pass

F "Kristian", "lastName" should return "Vos"
F "Sherlock", "likes" should return ["Intriguing Cases", "Violin"]
P "Harry","likes" should return an array
F "Bob", "number" should return "No such contact"
P "Akira", "address" should return "No such property"
kumquatfelafel
@kumquatfelafel
Aug 09 2017 19:05 UTC
@addisonday you're supposed to check it against first name as well.
Addison
@addisonday
Aug 09 2017 19:07 UTC
@kumquatfelafel I am not sure how to do that. All the ways I have tried failed...
kumquatfelafel
@kumquatfelafel
Aug 09 2017 19:07 UTC
for (var i = 0; i < 5; i++) {
   return i; // how many times will this line of code execute?
}
WAINGOR
@WAINGOR
Aug 09 2017 19:08 UTC
Hi all, I am currently sending e-mails through a nodeJS module and I am trying to spice up things a little by adding html tags and inline styling into my mail templates. I presume I have to escape // in my url (background image of the div element. Still Node tells me that "<" is an unexpected token...
    html: '<p style="color:green;"><b>Dear Sir.</b>I this is a message from your automatic mailingservice</p><div style = "position: relative; background-image: url('http:\\/\\/willpenman.com/teaching/armin0_img.png'); background-repeat: no-repeat; background-position: center top;  background-size: cover; min-height: 310px;"> </div>'
kumquatfelafel
@kumquatfelafel
Aug 09 2017 19:08 UTC
@addisonday First, you check if the first names are the same. Then, only if they are... you check the property.
WAINGOR
@WAINGOR
Aug 09 2017 19:09 UTC
Excuse me this should be better:
var  mail = {    html: '<p style="color:green;"><b>Dear Sir.</b>I this is a message from your automatic mailingservice</p><div style = "position: relative; background-image: url('http:\\/\\/willpenman.com/teaching/armin0_img.png'); background-repeat: no-repeat; background-position: center top;  background-size: cover; min-height: 310px;"> </div>'
};
kumquatfelafel
@kumquatfelafel
Aug 09 2017 19:09 UTC
you have right idea with no such contact being outside of for loop, but currently, because of how your code is written that line can never be executed.
Roxroy
@roxroy
Aug 09 2017 19:12 UTC
@addisonday , You will need to check that the contacts[i].firstName matches the firstName from the parameter.
kumquatfelafel
@kumquatfelafel
Aug 09 2017 19:12 UTC
@addisonday basically, your code is 100% correct, provided you now implement the first name check properly
Roxroy
@roxroy
Aug 09 2017 19:19 UTC
@kumquatfelafel , right, will update accordingly..
kumquatfelafel
@kumquatfelafel
Aug 09 2017 19:19 UTC
aye :)

http:\\/\\/

???

Addison
@addisonday
Aug 09 2017 19:25 UTC
@kumquatfelafel @roxroy Thank you guys both for the help. Am I creating a separate if statement for this check?
CamperBot
@camperbot
Aug 09 2017 19:25 UTC
addisonday sends brownie points to @kumquatfelafel and @roxroy :sparkles: :thumbsup: :sparkles:
:cookie: 586 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:star2: 1096 | @roxroy |http://www.freecodecamp.com/roxroy
Tiago Correia
@tiagocorreiaalmeida
Aug 09 2017 19:33 UTC
hello everyone
How can I prefor a modal show with jquery? and no im not using bootstrap :d
kumquatfelafel
@kumquatfelafel
Aug 09 2017 19:34 UTC

@addisonday Check property if and only if first names are the same. Otherwise, do not check for property. No such property basically means "contact with this name exists, but said contact doesn't have the given property". So if the first name I'm looking for is Larry, but the contact I'm looking at is Sal... if Sal doesn't have the given property, then this in and of itself is not justification for returning no such property. I should only be returning no such property if there is a contact with the first name of Larry, who doesn't have said property.

Remember, return statement, if executed, will halt the loop and the function immediately returning the specified value. Currently, your "No such contact" (which should occur when none of the contacts has the given first name) return statement is never executed because one of your other two return statements is executed no matter what in the first iteration of your for loop. (this statement based upon code above, but may not be true for whatever you have now)

kumquatfelafel @kumquatfelafel is away
Diego Mayer
@Chrono79
Aug 09 2017 19:38 UTC
@tiagocorreiaalmeida what do you mean with prefor?
Tiago Correia
@tiagocorreiaalmeida
Aug 09 2017 19:40 UTC
@Chrono79 perform*
Addison
@addisonday
Aug 09 2017 19:41 UTC
@kumquatfelafel
Solved! :) This took awhile but I learned a ton!

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


function lookUpProfile(firstName, prop){
// Only change code below this line
for (i = 0; i < contacts.length; i++){
  if (contacts[i].firstName === firstName){ 
    if (contacts[i].hasOwnProperty(prop)){
    return contacts[i][prop];
 } else {
    return "No such property";
        }  
  }
}
  return "No such contact";
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
Diego Mayer
@Chrono79
Aug 09 2017 19:41 UTC
you have to load jqueryui too, it's not in the regular jquery
Tiago Correia
@tiagocorreiaalmeida
Aug 09 2017 19:46 UTC
@Chrono79 isnt there any simple jquery way of making it based on the code I have and without using anything else?like a .show or something?im just wasting ause show is not working
Thayyeb salim
@Thayyebsalim
Aug 09 2017 19:49 UTC
@JLuboff Thanks dude that worked.
I have been messing around and searching for it for some time now
thanks alot
CamperBot
@camperbot
Aug 09 2017 19:49 UTC
thayyebsalim sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2142 | @jluboff |http://www.freecodecamp.com/jluboff
Kelechi Chinaka
@ke1echi
Aug 09 2017 19:54 UTC
missing some logic part
function toaster(b){
  return (b == 'white bread') ? '1 min' : (b == 'frozen white bread') ? '1.5 mins' :
  (b == 'brown bread') ? '2 mins' : (b == 'frozen brown bread') ? '3 mins' :
  "Please do not put that in the toaster!";
}
random test : Expected: '1 min', instead got: 'Please do not put that in the toaster!'
kumquatfelafel
@kumquatfelafel
Aug 09 2017 19:58 UTC

@addisonday that's good. :)

I think nested if statements like you have is best option here. Without it your for loop would probably look something like...

for(blahblah) {
  if (contacts[i].firstName !== firstName)
    continue;
  else if(contacts[i].hasOwnProperty(prop)
    return contacts[i][prop];
  else
    return "No such property";
}

this... which, coding-wise, is kinda weird

Margaret
@Margaret2
Aug 09 2017 19:58 UTC
@kelechy the parentheses shouldn't be necessary at all
kumquatfelafel
@kumquatfelafel
Aug 09 2017 19:59 UTC
@kelechy could you link the challenge? :point_down:
Margaret
@Margaret2
Aug 09 2017 19:59 UTC
@kelechy yeah, it also depends on what the instructions said
Ronique Ricketts
@RoniqueRicketts
Aug 09 2017 20:02 UTC
can someone tell me why I can't use this document.querySelectorAll()
https://codepen.io/Ronique/pen/EXMRNB?editors=1111
kumquatfelafel
@kumquatfelafel
Aug 09 2017 20:03 UTC
@kelechy
Okay. So string comparison should be case insensitive. e.g. WHitE BreAD should also return 1 min
Margaret
@Margaret2
Aug 09 2017 20:05 UTC
lol @kumquatfelafel
Kelechi Chinaka
@ke1echi
Aug 09 2017 20:09 UTC
oh...i think i need a rest now :smile: @kumquatfelafel thanks
CamperBot
@camperbot
Aug 09 2017 20:09 UTC
kelechy sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 587 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Diego Mayer
@Chrono79
Aug 09 2017 20:09 UTC
@tiagocorreiaalmeida afaik jquery core doesn't support modals, you have to use a third party library (here is another one: http://jquerymodal.com/)
Christopher McCormack
@cmccormack
Aug 09 2017 20:11 UTC
@RoniqueRicketts try document.querySelectorAll("div > .grids");
Tiago Correia
@tiagocorreiaalmeida
Aug 09 2017 20:11 UTC
.show used that @Chrono79 but thanks for the info
CamperBot
@camperbot
Aug 09 2017 20:11 UTC
tiagocorreiaalmeida sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4513 | @chrono79 |http://www.freecodecamp.com/chrono79
Christopher McCormack
@cmccormack
Aug 09 2017 20:12 UTC
@RoniqueRicketts actually it does look like it's working but you have to loop over the results for your listeners
scarejar
@scarejar
Aug 09 2017 20:12 UTC
so there's shared code between the client and server (using nodejs) and is this "good" design wise ?
class Player extends Gfx{
    constructor(){

if(SERVER === false){ //to make sure the server doesn't run the super constructor because it contains things that are just not needed in the server
        super(); 
    }

    }
}
Ronique Ricketts
@RoniqueRicketts
Aug 09 2017 20:13 UTC
@cmccormack thanks I will try that
CamperBot
@camperbot
Aug 09 2017 20:13 UTC
roniquericketts sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1114 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Aug 09 2017 20:14 UTC
@RoniqueRicketts grids.forEach(grid=>grid.addEventListener...
Ronique Ricketts
@RoniqueRicketts
Aug 09 2017 20:16 UTC
@cmccormack your a genius. thanks omg my project is coming along :D
CamperBot
@camperbot
Aug 09 2017 20:16 UTC
roniquericketts sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:warning: roniquericketts already gave cmccormack points
Christopher McCormack
@cmccormack
Aug 09 2017 20:16 UTC
@RoniqueRicketts :thumbsup:
Ronique Ricketts
@RoniqueRicketts
Aug 09 2017 20:17 UTC
@cmccormack I am grateful for the help man. I really appreciate it. I feel like I am actually coding :)
Oleh
@Lufter
Aug 09 2017 20:20 UTC
@roxroy thx :)
CamperBot
@camperbot
Aug 09 2017 20:20 UTC
lufter sends brownie points to @roxroy :sparkles: :thumbsup: :sparkles:
:star2: 1097 | @roxroy |http://www.freecodecamp.com/roxroy
Christopher McCormack
@cmccormack
Aug 09 2017 20:21 UTC
@RoniqueRicketts yeah man it's looking good!
Ronique Ricketts
@RoniqueRicketts
Aug 09 2017 20:24 UTC
@cmccormack Yeah I am working on getting it fixed up.
WAINGOR
@WAINGOR
Aug 09 2017 20:25 UTC

Hi all, I have a question. I have a crawler that I will let run on my mac terminal. It's written in NodeJS. I will have it scan 1 specific page every 5 seconds. Because I want I will do it using:

setInterval(function(){ alert("Hello"); }, 3000);

I want it to keep running the entire day but I just have 1 question: once it's running, how will I make it stop!! lol

Jason Luboff
@JLuboff
Aug 09 2017 20:27 UTC
@WAINGOR Kill the terminal window or the node process
WAINGOR
@WAINGOR
Aug 09 2017 20:28 UTC
how
:)
Jason Luboff
@JLuboff
Aug 09 2017 20:28 UTC
Press the red button on the terminal window..? Or for Windows it's ctrl+c to kill the node process not sure if its the same for OS X or if it's cmd+c
scarejar
@scarejar
Aug 09 2017 20:30 UTC
do you want it to shut off automatically? could run setTimeOut on a clearInterval
Abid Rahim
@abidRahim
Aug 09 2017 20:35 UTC
@cmccormack @sjames1958gm
function destroyer(arr) {


var args = Array.from(arguments);

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

for (var i=1; i<args.length; i++)
  return (val !== args[i]);

});
 return here;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
the o/p i'm getting is [1,3,1,3]
Christopher McCormack
@cmccormack
Aug 09 2017 20:38 UTC
@abidRahim you're returning too soon, only return within your loop if there is a match (destroy)
Abid Rahim
@abidRahim
Aug 09 2017 20:38 UTC
okay
Diego Mayer
@Chrono79
Aug 09 2017 20:42 UTC
@WAINGOR cut the red wire as everybody knows ;)
kumquatfelafel
@kumquatfelafel
Aug 09 2017 20:48 UTC

Pft... everybody knows it's the blue wire. I'll prove it!

:boom:

Tiago Correia
@tiagocorreiaalmeida
Aug 09 2017 20:53 UTC
@kumquatfelafel can you look into my pen https://codepen.io/tiagocorreia/full/VzKxeb/
$('.col-1 a').click(function(){
console.log("hi");
multiplayer = false;
$(".col-1").fadeOut();
$(".col-2").fadeOut();
});
$('.col-2 a').click(function(){
console.log("hi2");
multiplayer = true;
$(".col-1").fadeOut();
$(".col-2").fadeOut();
}); why those lines dont work?
the console log doesnt show
the tag imlooking for its the a tag that's around the icon
Diego Mayer
@Chrono79
Aug 09 2017 20:56 UTC
@tiagocorreiaalmeida you missed = in your html when defining the classes
Tiago Correia
@tiagocorreiaalmeida
Aug 09 2017 20:57 UTC
oh god
thanks
can I use append and fadein at the same time?
Abid Rahim
@abidRahim
Aug 09 2017 20:58 UTC

@cmccormack This worked

function destroyer(arr) {


var args = Array.from(arguments);

var here = arr.filter( function(val) {
      return !args.includes(val);

});
 return here;
}

But i'm still breaking my head with the previous code

Oleh
@Lufter
Aug 09 2017 21:00 UTC

@tiagocorreiaalmeida

And make it like this instead, to hide overlay area and pop-up.
Because right now you only hide half of popup

  $('.col-1 a').click(function(){
    console.log("hi");
    multiplayer = false;
    $("#popup1").fadeOut();
  });
   $('.col-2 a').click(function(){
     console.log("hi2");
     multiplayer = true;
     $("#popup1").fadeOut();
  });
Tiago Correia
@tiagocorreiaalmeida
Aug 09 2017 21:01 UTC
@Lufter im gonna change the modal content before hidding it eheh
   $('.content h3').text("Choose your Mark").fadeIn();
is this a possible thing or?
Oleh
@Lufter
Aug 09 2017 21:04 UTC
@tiagocorreiaalmeida should work
scarejar
@scarejar
Aug 09 2017 21:05 UTC
//shared js code between server and client

class Player extends Gfx{
     constructor(){
             if(SERVER === false){ //this is the line that says SERVER is not defined when it is defined in app.js
                  super();
}

           }

}

if(module.exports){
      module.exports = {player};
}

//app.js on node

const SERVER = true;

let PlayerClass = require("player.js").player;

let testPlayer = new PlayerClass();
// giving error that SERVER is not defined
Oleh
@Lufter
Aug 09 2017 21:05 UTC
@tiagocorreiaalmeida as i know it will work in case if you will use tags only*
for ex.
$('div span').text('Hello World');
Christopher McCormack
@cmccormack
Aug 09 2017 21:05 UTC
@abidRahim best thing you can do is walk line by line through your code and determine what it's supposed to do and what it is doing
scarejar
@scarejar
Aug 09 2017 21:06 UTC
got a problem where SERVER is defined but says it's not defined for some reason
Jason Luboff
@JLuboff
Aug 09 2017 21:07 UTC
@cmccormack So studying for one of my cert's and this was a potential answer in one of my practice exams:
blob
scarejar
@scarejar
Aug 09 2017 21:07 UTC
lmao
kumquatfelafel
@kumquatfelafel
Aug 09 2017 21:08 UTC
@JLuboff sounds legit
Christopher McCormack
@cmccormack
Aug 09 2017 21:08 UTC
@JLuboff ah that's so sweet
kumquatfelafel
@kumquatfelafel
Aug 09 2017 21:08 UTC
It's the uncleboard you really have to keep an eye on.
Jason Luboff
@JLuboff
Aug 09 2017 21:09 UTC
:joy:
Christopher McCormack
@cmccormack
Aug 09 2017 21:09 UTC
or another motherboard, don't tell hardware what to love!
kumquatfelafel
@kumquatfelafel
Aug 09 2017 21:09 UTC
lol
Oleh
@Lufter
Aug 09 2017 21:10 UTC
@tiagocorreiaalmeida
W3S - jQ selectors
Christopher McCormack
@cmccormack
Aug 09 2017 21:11 UTC
@tiagocorreiaalmeida you may want to check what .text() returns, if it's an element then should work
Oleh
@Lufter
Aug 09 2017 21:13 UTC

@tiagocorreiaalmeida
You may use has to get the required result

    $(".content:has(h3)").text("Hello World");

Basically 'All elements with class ".content" that have a <h3> element' will display text "Hello World"

aRtoo
@artoodeeto
Aug 09 2017 21:14 UTC

hi guys. i think i found a but. im on the algo search and replace. and this is my code


function myReplace(str, before, after) {

  var myRegex = RegExp('(\\w*'+before+'\\w*)','gi');


  return str.replace(myRegex,after);
}
myReplace("He is Sleeping on the couch", "Sleeping", "sitting");

its returning right but i have an error. like what???

scarejar
@scarejar
Aug 09 2017 21:14 UTC
getting this error in node..

        this.uid = obj.uid || "none";
        ^

ReferenceError: this is not defined
this should be relative to "new"
since it's a constructor but I don't get why "this" is not defined
Diego Mayer
@Chrono79
Aug 09 2017 21:15 UTC
@artoodeeto shouldn't you use new before RegExp?
And what about the capitalization?
scarejar
@scarejar
Aug 09 2017 21:15 UTC
is it because I'm not calling the super? I'm only calling the super depending on if it is the server or not that is running the code
aRtoo
@artoodeeto
Aug 09 2017 21:18 UTC
@Chrono79 what sir??
@Chrono79 i think thats the syntax for constructor
Diego Mayer
@Chrono79
Aug 09 2017 21:19 UTC
@scarejar could it be related to you using arrow notation?

@artoodeeto

var re = new RegExp("\\w+");
var re = /\w+/;

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp

Adam Bohannon
@abohannon
Aug 09 2017 21:20 UTC
Can anyone help me understand why this template literal expression is neceesary? Why couldn't I just use the 'percent' variable?
function handleProgress() {
  const percent = video.currentTime / video.duration * 100;
  progressBar.style.flexBasis = `${percent}%`;
}
Diego Mayer
@Chrono79
Aug 09 2017 21:21 UTC
have you tried using it and it didn't work?
kumquatfelafel
@kumquatfelafel
Aug 09 2017 21:21 UTC
do you mean like percent + '%'?
Adam Bohannon
@abohannon
Aug 09 2017 21:21 UTC
yea it didn't work
scarejar
@scarejar
Aug 09 2017 21:21 UTC
@Chrono79 tried without and it gives same result strangely..
teevik
@teevik
Aug 09 2017 21:23 UTC
It's css, flex-basis: 50 wouldn't work, but flex-basis: 50% would
Adam Bohannon
@abohannon
Aug 09 2017 21:24 UTC
ah i see how it's working now
kumquatfelafel
@kumquatfelafel
Aug 09 2017 21:24 UTC
@abohannon not entirely sure which question answer is response to :p
Diego Mayer
@Chrono79
Aug 09 2017 21:24 UTC
@teevik but isn't percent + '%' equivalent to ${percent}%? That's what seems weird
Adam Bohannon
@abohannon
Aug 09 2017 21:24 UTC
thank you all for the nudge @kumquatfelafel @Chrono79
CamperBot
@camperbot
Aug 09 2017 21:24 UTC
abohannon sends brownie points to @kumquatfelafel and @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4514 | @chrono79 |http://www.freecodecamp.com/chrono79
:cookie: 588 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
kumquatfelafel
@kumquatfelafel
Aug 09 2017 21:24 UTC
nvm
Adam Bohannon
@abohannon
Aug 09 2017 21:24 UTC
you guys are right. percent + '%' does work
kumquatfelafel
@kumquatfelafel
Aug 09 2017 21:24 UTC
np
Adam Bohannon
@abohannon
Aug 09 2017 21:24 UTC
i had typed it wrong
Diego Mayer
@Chrono79
Aug 09 2017 21:24 UTC
:+1:
Adam Bohannon
@abohannon
Aug 09 2017 21:25 UTC
cheers, sorry abt that
kumquatfelafel @kumquatfelafel is offline.
Bradley Sands
@sandsbe
Aug 09 2017 21:27 UTC
Random Q I'd been searching online about but my phrasing has been failing at finding an answer. Also, not into Node yet. What would it be called (i.e., what should I search), if I wanted my script in Node to call a particular API at the same time each day? Front-end JS would just do the call when you open the browser or press a button that activates the call. Can I "time" it on the backend?
Jason Luboff
@JLuboff
Aug 09 2017 21:28 UTC
@sandsbe You could just have a setInterval on the frontend to make the call every 24 hours
Diego Mayer
@Chrono79
Aug 09 2017 21:28 UTC
@sandsbe try googling cron and node
Tiago Correia
@tiagocorreiaalmeida
Aug 09 2017 21:29 UTC
@cmccormack can you give just 1 last look into something?
Christopher McCormack
@cmccormack
Aug 09 2017 21:29 UTC
sure
Jason Luboff
@JLuboff
Aug 09 2017 21:29 UTC
@sandsbe What @Chrono79 mentioned is probably a better route. I see there is this package which maybe what you want: https://github.com/kelektiv/node-cron
Tiago Correia
@tiagocorreiaalmeida
Aug 09 2017 21:29 UTC
https://codepen.io/tiagocorreia/full/VzKxeb/ after I choose 1 or 2 players I let the user choose X or O, to test only choose the 1 player option when I click on the X after nothing happens and I got this code to turn
run*
  $('.choicex').click(function(){
     console.log("Here");
     if(multiplayer){
       userMark = 'X';
       secondPlayer = "O";
     }else{
       userMark = 'X';
       computerMark = "O";
     }
     $("#popup1").fadeOut();
   });
Abid Rahim
@abidRahim
Aug 09 2017 21:31 UTC
@cmccormack ty
CamperBot
@camperbot
Aug 09 2017 21:31 UTC
abidrahim sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1115 | @cmccormack |http://www.freecodecamp.com/cmccormack
Bradley Sands
@sandsbe
Aug 09 2017 21:32 UTC
Worked wonders. Key words (besides cron and node) were Scheduling Tasks.
thanks @JLuboff @Chrono79
CamperBot
@camperbot
Aug 09 2017 21:32 UTC
sandsbe sends brownie points to @jluboff and @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 2143 | @jluboff |http://www.freecodecamp.com/jluboff
:star2: 4515 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Aug 09 2017 21:32 UTC
:+1:
Stephen James
@sjames1958gm
Aug 09 2017 21:33 UTC
@tiagocorreiaalmeida Those elements don't exist when you assign handlers
Diego Mayer
@Chrono79
Aug 09 2017 21:34 UTC
@tiagocorreiaalmeida ^ that, you have to bind the onclick event when you add the html to the dom
Christopher McCormack
@cmccormack
Aug 09 2017 21:34 UTC
right - you may want to add the elements to the dom first but hidden
Tiago Correia
@tiagocorreiaalmeida
Aug 09 2017 21:34 UTC
so append will not work here?
maybe its time to use hide and show
Christopher McCormack
@cmccormack
Aug 09 2017 21:34 UTC
or you can do a search for the element when you click instead of selecting the element directly
Tiago Correia
@tiagocorreiaalmeida
Aug 09 2017 21:35 UTC
how could I do that? confusing to me
Christopher McCormack
@cmccormack
Aug 09 2017 21:37 UTC
I would recommend creating your HTML first and just show/hide as you suggested
Tiago Correia
@tiagocorreiaalmeida
Aug 09 2017 21:38 UTC
ok mate thanks
@cmccormack solved just 1 thing is there anyway to hide that fractio nof second where it fadesout and in cause it looks kinda strange try it out if ppossible :D
Christopher McCormack
@cmccormack
Aug 09 2017 21:43 UTC
@tiagocorreiaalmeida you can add an opaque div behind it if you want
Tiago Correia
@tiagocorreiaalmeida
Aug 09 2017 21:43 UTC
and the overflow hidden solves the other part or? cause I tried and doenst seems to :package:
:p
Christopher McCormack
@cmccormack
Aug 09 2017 21:44 UTC
Keep playing with it you'll get it :D
Tiago Correia
@tiagocorreiaalmeida
Aug 09 2017 21:44 UTC
eheheh ok thanks once again and yeah sometimes its just better to write random things unthil you get it
JLuboff @JLuboff needs a :sleeping:
Joseph
@revisualize
Aug 09 2017 22:15 UTC
@JLuboff me too.
Jason Luboff
@JLuboff
Aug 09 2017 22:16 UTC
@revisualize ...less than 2 hours to go..right?
luccifer00
@luccifer00
Aug 09 2017 22:19 UTC
someone knows about google revers for get location?? i cant get it... i have this
var gooloc ="https://maps.googleapis.com/maps/api/geocode/json?latlng="+ lat + "," + long +"&key=AIzaSyBUzuWvyNu66-dU5DW8DfMqNQ87JgFPCUs";
        var province;
        var state;
        var city;

         $.getJSON(gooloc, function(loc){
          $("#locate").html(loc.results.long_name.country);
  city=loc.address_components.administrative_area_level_1;
 state=loc.adress_components.country;
          province=loc.address_components.administrative_area_level_2;

        }); // closing getjson gooloc

       $("#locate").html(loc);
juni
@junipberry
Aug 09 2017 22:22 UTC
is the syntax wrong here:
for (let i=0; i<myLgth; i++){ myObj[array[i,[0]]]= array[i,[1]]; }
Christopher McCormack
@cmccormack
Aug 09 2017 22:23 UTC
@junipberry looks wrong
@luccifer00 did you try logging loc to console in your getJSON to see if it's getting a response? Did you check your browser console for errors?
juni
@junipberry
Aug 09 2017 22:26 UTC
yea, that doesn’t help
Fanny
@FannyVieira
Aug 09 2017 22:26 UTC
Can anyone tell me if there is a significant difference in using the create-react-app or in configuring the webpack manually?
Christopher McCormack
@cmccormack
Aug 09 2017 22:26 UTC
@junipberry why do you have myObj[array[i,[0]]]= array[i,[1]];? An assignment statment in your object lookup
Fanny
@FannyVieira
Aug 09 2017 22:27 UTC
Is it a good practice to use create-react-app in the new version?
Christopher McCormack
@cmccormack
Aug 09 2017 22:27 UTC
@FannyVieira create-react-app makes it much easier, that's for sure
luccifer00
@luccifer00
Aug 09 2017 22:27 UTC
oh... i just write loc, but it tried with city, province and contry... and nothing happens... i am not sure if i set the api path correctly.... results.long_name.country @cmccormack
scarejar
@scarejar
Aug 09 2017 22:28 UTC
anyone experienced with nodejs ?
Christopher McCormack
@cmccormack
Aug 09 2017 22:28 UTC
@luccifer00 output just loc to your console and look at the properties - if they match what you have it should work.
Fanny
@FannyVieira
Aug 09 2017 22:28 UTC
It's just that I'm afraid of losing some knowledge of what happens, but thank you very much.
juni
@junipberry
Aug 09 2017 22:28 UTC
function listToObject(array) {
  let myObj = {};
  let myLgth = array.length;

  for (let i=0; i<myLgth; i++){
    myObj[array[i,[0]]]= array[i,[1]];
  }
  return myObj;
}
bc I want to turn an array of arrays into key-value pairs
@cmccormack
I want to loop my assignment of object
of index 0 as key and index 1 as value, respectively
Christopher McCormack
@cmccormack
Aug 09 2017 22:30 UTC
@junipberry what is this supposed to be doing? array[i,[0]]
can you update your code with what array might look like?
juni
@junipberry
Aug 09 2017 22:31 UTC
I was trying to target the other arrays within the array.. thus my question re: syntax
Moisés Man
@moigithub
Aug 09 2017 22:31 UTC
how the array looks like ?
Christopher McCormack
@cmccormack
Aug 09 2017 22:32 UTC
@junipberry maybe you want something like this:
> var arr = [[1,2,3], [4,5, [6,7]]]
> arr[1][2] // arr[1] grabs the second item in the array, then the following [2] grabs the third item from THAT array
[ 6, 7 ]
juni
@junipberry
Aug 09 2017 22:33 UTC
I want to set every index of 0 within the first array as an object key, and index1 within the first array as object value
Im targeting the i of array because I want to set a loop for every array within that array
Moisés Man
@moigithub
Aug 09 2017 22:36 UTC
soo array is like this ?
[
       ["key1", "value1"], 
       ["key2", "value2"],
       ["key3", "value3"]
]
Christopher McCormack
@cmccormack
Aug 09 2017 22:36 UTC
@junipberry you'll need to show us what your array parameter will look like
juni
@junipberry
Aug 09 2017 22:38 UTC
[[key:’value’],[key:’value’],[key:’value’]…etc]
an array within an array w no defined limit of elements
Christopher McCormack
@cmccormack
Aug 09 2017 22:40 UTC
@junipberry
myObj[array[i][0]] = array[i][1]]
juni
@junipberry
Aug 09 2017 22:40 UTC
oh, right
ty @cmccormack
CamperBot
@camperbot
Aug 09 2017 22:41 UTC
junipberry sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1116 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Aug 09 2017 22:41 UTC
np
@moigithub glad you understood what it was supposed to look like :)
Joseph
@revisualize
Aug 09 2017 22:42 UTC
@JLuboff Not for me.
@JLuboff I'm migrating a database from one SQL server to another SQL server.
Then... I'm updating the application version from 12.3 to 12.5.1
Jason Luboff
@JLuboff
Aug 09 2017 22:43 UTC
Oh jolly good fun
Joseph
@revisualize
Aug 09 2017 22:43 UTC
@JLuboff I have an outage scheduled from 430pm to 530pm ... I think it is going to be until 6pm.
@JLuboff And... I have a meetup.com event at 6pm that I want to attend.
Jason Luboff
@JLuboff
Aug 09 2017 22:45 UTC
Better make that data move quicker ;)
juni
@junipberry
Aug 09 2017 22:47 UTC

so then, just want to be sure, this part of the function:

for (let i=0; i<myLgth; i++){
    myObj[array[i][0]]= array[[i][1]];

is effectively looping the assignment of index [0] and index [1] to object key-value, respectively.

Jim Tryon
@jimtryon
Aug 09 2017 22:50 UTC
Should that be myLgth.length @junipberry?
Christopher McCormack
@cmccormack
Aug 09 2017 22:51 UTC
let myLgth = array.length; was defined in her code up above a bit
@junipberry yup
juni
@junipberry
Aug 09 2017 22:52 UTC

@jimtryon , its from this:

function listToObject(array) {
  let myObj = {};
  let myLgth = array.length;

  for (let i=0; i<myLgth; i++){
    myObj[array[i][0]]= array[[i][1]];
  }
  return myObj;
}

so it should be fine.

Jim Tryon
@jimtryon
Aug 09 2017 22:52 UTC
@junipberry Yeah, I thought you might have already declared the variable with the .length property
@junipberry makes sense now
@junipberry I usually do it inside of the loop
juni
@junipberry
Aug 09 2017 22:53 UTC
@cmccormack , still not clearing in the test..trying to figure out what is still wrong
Jim Tryon
@jimtryon
Aug 09 2017 22:53 UTC
@junipberry What are you trying to do in this code?
thanks @cmccormack saw that above
CamperBot
@camperbot
Aug 09 2017 22:53 UTC
jimtryon sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1117 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Aug 09 2017 22:54 UTC
@junipberry =array[i][1]
aRtoo
@artoodeeto
Aug 09 2017 22:54 UTC
bro you know why fast is not adding to the text?
console.log('freecode'.split('').splice(0,1,"fast"));
juni
@junipberry
Aug 09 2017 22:56 UTC
gosh, that was silly. got it. ty @cmccormack
CamperBot
@camperbot
Aug 09 2017 22:56 UTC
junipberry sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:warning: junipberry already gave cmccormack points
Christopher McCormack
@cmccormack
Aug 09 2017 22:56 UTC
@artoodeeto it is
@artoodeeto but splice returns the deleted item
splice itself is an inplace method
aRtoo
@artoodeeto
Aug 09 2017 22:59 UTC
@cmccormack ha?? why on the mdn its returning the added item

@cmccormack

var myFish = ['angel', 'clown', 'trumpet', 'sturgeon'];
var removed = myFish.splice(0, 2, 'parrot', 'anemone', 'blue');

// myFish is ["parrot", "anemone", "blue", "trumpet", "sturgeon"] 
// removed is ["angel", "clown"]

this is the sample

Christopher McCormack
@cmccormack
Aug 09 2017 23:00 UTC
it isn't
it's modifying myFish in place with the splice method, and the returned array is the removed items, stored in removed
intcreate
@intcreate
Aug 09 2017 23:01 UTC
Why is this returning undefined? It's suppose to return a number.
    var name = function () {
        fs.readdir(dir, (err, files) => {
            return files.length + 1;
        });       
    }
Jim Tryon
@jimtryon
Aug 09 2017 23:02 UTC
Is this node @intcreate?
intcreate
@intcreate
Aug 09 2017 23:02 UTC
yes
its reading a file
Jim Tryon
@jimtryon
Aug 09 2017 23:02 UTC
yeah, it looks similar to code I wrote yesterday
if you are doing async read, you want to use fs.readFile
intcreate
@intcreate
Aug 09 2017 23:03 UTC
I mean it's suppose to return the number of files in a folder.
Jim Tryon
@jimtryon
Aug 09 2017 23:03 UTC
What does it return?
intcreate
@intcreate
Aug 09 2017 23:04 UTC
undefined
when I do name();
Jim Tryon
@jimtryon
Aug 09 2017 23:05 UTC
you have the require statement?
also have you defined dir?
Jason Luboff
@JLuboff
Aug 09 2017 23:06 UTC
dir is a valid path?
What do you get if you do console.log(files)?
Jim Tryon
@jimtryon
Aug 09 2017 23:06 UTC
I’m going to guess that dir is undefined
Jason Luboff
@JLuboff
Aug 09 2017 23:06 UTC
That would be my guess is well..
intcreate
@intcreate
Aug 09 2017 23:07 UTC
dir is
./uploads
Jim Tryon
@jimtryon
Aug 09 2017 23:07 UTC
can you show me that line?
intcreate
@intcreate
Aug 09 2017 23:08 UTC
// Use the mv() method to place the file somewhere on your server
    var dir = './uploads';


    fs.readdir(dir, (err, files) => {
        return files.length + 1;
    });       



    sampleFile.mv('./uploads/' + name + '.jpg', function(err, res) {
        if (err) {
          return res.status(500).send(err);
        }
        res.redirect('/dashboard');
    });
im trying to return the readdir so I can use it in the sampleFile.mv
Jim Tryon
@jimtryon
Aug 09 2017 23:09 UTC
What happens if you console.log(files)?
actually, try console.log(files.length) in your function
intcreate
@intcreate
Aug 09 2017 23:10 UTC
[ '.jpg',
'2.jpg',
'3.jpg',
'undefined.jpg' ]
oh ok
Jason Luboff
@JLuboff
Aug 09 2017 23:11 UTC
Ok, so why do you have +1?
intcreate
@intcreate
Aug 09 2017 23:11 UTC
So when I upload a photo it changes the name
Moisés Man
@moigithub
Aug 09 2017 23:11 UTC
async
intcreate
@intcreate
Aug 09 2017 23:11 UTC
1.jpg, 2.jpg ...
Jim Tryon
@jimtryon
Aug 09 2017 23:11 UTC
you are concatenating the next number on to the filename?
intcreate
@intcreate
Aug 09 2017 23:12 UTC
yes
Jim Tryon
@jimtryon
Aug 09 2017 23:12 UTC
You should do that on the filename
not files.length + 1
intcreate
@intcreate
Aug 09 2017 23:12 UTC
What do you mean on the file name
Jim Tryon
@jimtryon
Aug 09 2017 23:13 UTC
I mean I would append a random value on the actual filename
intcreate
@intcreate
Aug 09 2017 23:13 UTC
sampleFile.mv('./uploads/' + RANDOMVALUE + '.jpg',