These are chat archives for FreeCodeCamp/HelpJavaScript

9th
Aug 2017
Guderian Raborg
@hypercuber
Aug 09 2017 00:11
@cmccormack thanks
CamperBot
@camperbot
Aug 09 2017 00:11
hypercuber sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:warning: hypercuber already gave cmccormack points
dyon3334
@dyon3334
Aug 09 2017 00:38
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
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
@dyon3334 check ur brackets...
{ <-- start of block
} <-- end of block
kumquatfelafel
@kumquatfelafel
Aug 09 2017 00:55

: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
@kumquatfelafel thanks !!
CamperBot
@camperbot
Aug 09 2017 00:59
dyon3334 sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 585 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Joseph
@Big-jo
Aug 09 2017 01:07
I tried to parse a JSON formatted object and then i got [object Object]
kumquatfelafel
@kumquatfelafel
Aug 09 2017 01:08
@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
@kumquatfelafel oh lol
@Big-jo try stringify to have a look at it
Joseph
@Big-jo
Aug 09 2017 01:09
image.png
Stephen James
@sjames1958gm
Aug 09 2017 01:09
@Big-jo you parsed a JSON string and got an object, that is what should happen
kumquatfelafel
@kumquatfelafel
Aug 09 2017 01:09

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
@Big-jo You tried to parse the toString of an object which is not correct.
Joseph
@Big-jo
Aug 09 2017 01:10

@sjames1958gm

image.png

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

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
hello people
kumquatfelafel
@kumquatfelafel
Aug 09 2017 01:12
hey
Adnan Karšić
@adokce
Aug 09 2017 01:12
are there any senior devs here
kumquatfelafel
@kumquatfelafel
Aug 09 2017 01:13
@moigithub p.s. thanks :p
CamperBot
@camperbot
Aug 09 2017 01:13
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
i need advice
from someone a little bit more experienced
Joseph
@Big-jo
Aug 09 2017 01:13
ask your question and w'll try to help
Stephen James
@sjames1958gm
Aug 09 2017 01:14
@Big-jo console.log(Received) and see what it is
Joseph
@Big-jo
Aug 09 2017 01:14
okay
Uncaught ReferenceError: Recieved is not defined
at <anonymous>:1:13
Stephen James
@sjames1958gm
Aug 09 2017 01:16
@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
@Big-jo
Aug 09 2017 01:17
oh no p
Adnan Karšić
@adokce
Aug 09 2017 01:18
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
@Big-jo
Aug 09 2017 01:19
@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
(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
@Big-jo Show your set up of the AJAX request
Joseph
@Big-jo
Aug 09 2017 01:23
@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
hello can someone help me please with my code?
Stephen James
@sjames1958gm
Aug 09 2017 01:26
@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
@Kristi92 post code
Joseph
@Big-jo
Aug 09 2017 01:28
@sjames1958gm thanks, It makes sense now
CamperBot
@camperbot
Aug 09 2017 01:28
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
@Kristi92 (or codepen or code snippet or something)... can't help without more information on what need help with.
Joseph
@Big-jo
Aug 09 2017 01:38
{
   "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
@Big-jo something like this: .results["0"].geometry.location
.results["0"].geometry.location.lat
.results["0"].geometry.location.lng
Joseph
@Big-jo
Aug 09 2017 01:47
@longnt80 thanks
CamperBot
@camperbot
Aug 09 2017 01:47
big-jo sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 485 | @longnt80 |http://www.freecodecamp.com/longnt80
Joseph
@Big-jo
Aug 09 2017 01:54
@longnt80 not working
kumquatfelafel
@kumquatfelafel
Aug 09 2017 01:54
@Big-jo try console.logging each step of the way to see what you get.
Joseph
@Big-jo
Aug 09 2017 01:55
:thumbsup:
Long Nguyen
@longnt80
Aug 09 2017 01:56
@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
this too. So blah.results[0].yadayada
except... y'know... not blah, and not yadayada
Long Nguyen
@longnt80
Aug 09 2017 01:58
@Big-jo or you can give us a codepen link
Cody Seibert
@codyseibert
Aug 09 2017 02:20
@adokce just do MEAN or MERN
Jefferson
@jeffersonnnn
Aug 09 2017 02:25
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
@jeffersonnnn can you give the code?
Jefferson
@jeffersonnnn
Aug 09 2017 02:39
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
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
good evening folks!
i need help with how to render a team project that has react
Jefferson
@jeffersonnnn
Aug 09 2017 02:51
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
@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
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
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
@bitcoinabdi how did it go?
Joseph
@revisualize
Aug 09 2017 04:12
Hello.
abraham anak agung
@padunk
Aug 09 2017 04:14
Good Afternoon
bitcoinabdi
@bitcoinabdi
Aug 09 2017 04:22
@GregatGit still having issues
Greg Duncan
@GregatGit
Aug 09 2017 04:23
@bitcoinabdi Where are you stuck?
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:24

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
@GregatGit i am supposed to render my project and should look like this http://imgur.com/e65PCU8
heroiczero
@heroiczero
Aug 09 2017 04:26
@faahim is the reverse the same as the original?
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:26
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
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:26
yes, I think so. See for yourself @heroiczero :(
eyeforofeye is same even when you spell backword
iso
@iso1048
Aug 09 2017 04:27
@faahim check again if you are supposed to remove numbers
Greg Duncan
@GregatGit
Aug 09 2017 04:29
@bitcoinabdi so the project works and you want to use github pages to host it?
heroiczero
@heroiczero
Aug 09 2017 04:29
@faahim says "all non-alphanumeric characters"
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:29

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
@faahim yep. keep numbers
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:29
Thanks @gothamknight and @heroiczero
CamperBot
@camperbot
Aug 09 2017 04:29
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
:)
bitcoinabdi
@bitcoinabdi
Aug 09 2017 04:30
yes
Joseph
@revisualize
Aug 09 2017 04:30

@faahim This:

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

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

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

Method chaining?

Never heard about it!

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

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
@bitcoinabdi you'll have it up in no time
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:34
is Method chaining suitable for learning in the beginning?
Joseph
@revisualize
Aug 09 2017 04:34
@faahim Yes.
Greg Duncan
@GregatGit
Aug 09 2017 04:34

@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
@codyseibert Guass.
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:35
I was looking up regex101. But this one seems better. Thanks! @revisualize :)
CamperBot
@camperbot
Aug 09 2017 04:35
faahim sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:warning: faahim already gave revisualize points
bitcoinabdi
@bitcoinabdi
Aug 09 2017 04:36
@GregatGit OMG !
Joseph
@revisualize
Aug 09 2017 04:36
@codyseibert You can actually solve that lesson with just math.
Cody Seibert
@codyseibert
Aug 09 2017 04:36
@revisualize I was looking for a non mathmatical solution
Joseph
@revisualize
Aug 09 2017 04:36
@codyseibert oh
bitcoinabdi
@bitcoinabdi
Aug 09 2017 04:36
thank you very much realy embarrased
Cody Seibert
@codyseibert
Aug 09 2017 04:36
I know you can do some formula for n * n - 1 / 2 or something
Joseph
@revisualize
Aug 09 2017 04:37
@codyseibert kind of.
Greg Duncan
@GregatGit
Aug 09 2017 04:37
@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
@codyseibert But, yea.
Cody Seibert
@codyseibert
Aug 09 2017 04:37
max(max+1)/2 - min(min+1)/2 ?
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:38

yee! Done!

Number was the issue! :)

Joseph
@revisualize
Aug 09 2017 04:38
@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

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
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
max*(max+1)/2 - (min-1)*(min)/2 ?
Joseph
@revisualize
Aug 09 2017 04:39
@codyseibert Yes.
@faahim yes
Cody Seibert
@codyseibert
Aug 09 2017 04:40
@revisualize but let's say we are not allowed to solve it using that formula
Joseph
@revisualize
Aug 09 2017 04:40
@codyseibert Ok.
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:42
@revisualize
Amazing!
namethatisnottaken
@namethatisnottaken
Aug 09 2017 04:43
any help anyone ?
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:43

@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
@namethatisnottaken combinedArray.sort();
in case what you're sorting is numbers, this won't work
namethatisnottaken
@namethatisnottaken
Aug 09 2017 04:44
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
@namethatisnottaken is there a link to the challenge?
namethatisnottaken
@namethatisnottaken
Aug 09 2017 04:46
Joseph
@revisualize
Aug 09 2017 04:46
@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
Got it! Gotta create a repo today! :)
Manish Giri
@Manish-Giri
Aug 09 2017 04:48
@namethatisnottaken one sec
Joseph
@revisualize
Aug 09 2017 04:49
@faahim There is a reason I even have my codewars challenges on my github.
namethatisnottaken
@namethatisnottaken
Aug 09 2017 04:49
ok thanks @Manish-Giri
CamperBot
@camperbot
Aug 09 2017 04:49
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
@revisualize the same reason I guess?
Joseph
@revisualize
Aug 09 2017 04:50
@faahim Yup.
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:50
haha
Joseph
@revisualize
Aug 09 2017 04:50
@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
@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
@faahim I don't read unsolicited private messages.
@faahim If you have a question ask here.
Greg Duncan
@GregatGit
Aug 09 2017 04:53
@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

@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
@codyseibert :)
Cody Seibert
@codyseibert
Aug 09 2017 04:54
@revisualize would you be interested in working on multiple choice quiz questions for FCC?
Joseph
@revisualize
Aug 09 2017 04:55
No.
Afiur Rahman Fahim
@faahim
Aug 09 2017 04:55

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
@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
@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
Great! Thanks @revisualize
CamperBot
@camperbot
Aug 09 2017 04:58
faahim sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:warning: faahim already gave revisualize points
Joseph
@revisualize
Aug 09 2017 05:01
@faahim Any other questions?
namethatisnottaken
@namethatisnottaken
Aug 09 2017 05:01
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
Manish Giri
@Manish-Giri
Aug 09 2017 05:06
@namethatisnottaken I just tested
namethatisnottaken
@namethatisnottaken
Aug 09 2017 05:07
hi thanks @Manish-Giri @revisualize
CamperBot
@camperbot
Aug 09 2017 05:07
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
@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
looks great mate, why i could not think of that earlier :sob:
Manish Giri
@Manish-Giri
Aug 09 2017 05:11
it's okay :smile:
you'll get there with practice
and remember, "keep it simple"!
namethatisnottaken
@namethatisnottaken
Aug 09 2017 05:12
haha yes thanks :+1:
juni
@junipberry
Aug 09 2017 05:13
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
@junipberry sure thing
juni
@junipberry
Aug 09 2017 05:14
great, ty~~
so far, I have broken it down into steps
Manish Giri
@Manish-Giri
Aug 09 2017 05:14
there's an in built function actually, for that
Object.keys()
juni
@junipberry
Aug 09 2017 05:14
yes!
but Im not supposed to use it lol
Manish Giri
@Manish-Giri
Aug 09 2017 05:14
ah cool
thought so
post your steps/code
juni
@junipberry
Aug 09 2017 05:15
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
sure
juni
@junipberry
Aug 09 2017 05:15
so one way was to use the Object.entries then filter out
Manish Giri
@Manish-Giri
Aug 09 2017 05:16
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
ah okay
Manish Giri
@Manish-Giri
Aug 09 2017 05:18
any other way you thought of?
juni
@junipberry
Aug 09 2017 05:18
I cannot just filter afterwards?
Manish Giri
@Manish-Giri
Aug 09 2017 05:18
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
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
actually
I was wrong about filter
I meant .map()
juni
@junipberry
Aug 09 2017 05:21
ah
Manish Giri
@Manish-Giri
Aug 09 2017 05:21
so when you map over Object.entries
juni
@junipberry
Aug 09 2017 05:21
got it
Manish Giri
@Manish-Giri
Aug 09 2017 05:21
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
sounds good
I was also thinking of the .hasOwnProp to look for i
[i]
Manish Giri
@Manish-Giri
Aug 09 2017 05:23
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
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
let keys = [];
for (var prop in object) {
 if(!keys.includes(prop) {
  keys.push(prop)
 }
}
juni
@junipberry
Aug 09 2017 05:27
oh interesting
Manish Giri
@Manish-Giri
Aug 09 2017 05:28
if(!keys.includes(prop) {
actually you don't need this
just keys.push(prop)
juni
@junipberry
Aug 09 2017 05:32
I’m a bit unclear w the prop in part in the second line
Manish Giri
@Manish-Giri
Aug 09 2017 05:34
it iterates over all the key-value pairs in your object, one by one
Markus Kiili
@Masd925
Aug 09 2017 05:35
@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
like you iterate over an array with
for(var i = 0; i < array.length; i++)
@junipberry
Markus Kiili
@Masd925
Aug 09 2017 05:36
@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
ohh got it, ty @Manish-Giri ty @Masd925
CamperBot
@camperbot
Aug 09 2017 05:36
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

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
@zengjunyu The filter callback function has its own arguments object.
曾君宇
@zengjunyu
Aug 09 2017 05:49
thanks
Markus Kiili
@Masd925
Aug 09 2017 05:50
@zengjunyu Otherwise the code is fine.
juni
@junipberry
Aug 09 2017 06:05
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
@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
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
@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
ty for that clarification @Masd925
CamperBot
@camperbot
Aug 09 2017 07:20
junipberry sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4394 | @masd925 |http://www.freecodecamp.com/masd925
juni
@junipberry
Aug 09 2017 07:21
@Masd925 , all the ways I’ve tried submitting the code are restricted methods
Markus Kiili
@Masd925
Aug 09 2017 07:22
@junipberry So does that code pass, or is push restricted too?
juni
@junipberry
Aug 09 2017 07:22
seems like I cannot use any Object oriented methods for this exercise
Markus Kiili
@Masd925
Aug 09 2017 07:23
@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
000000
juni
@junipberry
Aug 09 2017 07:39
it doesn’t go into detail about what it restricted.
Markus Kiili
@Masd925
Aug 09 2017 07:40
@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
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
@sky1095 No solutions here, only help.
sky1095
@sky1095
Aug 09 2017 07:47
really fed up with this
kumquatfelafel
@kumquatfelafel
Aug 09 2017 07:47
what have you tried so far?
sky1095
@sky1095
Aug 09 2017 07:47
@Masd925 Help me out
Markus Kiili
@Masd925
Aug 09 2017 07:50
@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
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
@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
There's only so many ways to access the properties of the object without knowing said properties.
juni
@junipberry
Aug 09 2017 08:06
I see your point.. yea I don’t think I can use a loop then
sky1095
@sky1095
Aug 09 2017 08:09
@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
gm everyone
Tiago Correia
@tiagocorreiaalmeida
Aug 09 2017 08:22
@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
just found out I think thanks anyway
EpicTriffid
@EpicTriffid
Aug 09 2017 09:17
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

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
@Blauelf So have I done it the wrong way round by detecting the absence of vowels first?
Blauelf
@Blauelf
Aug 09 2017 09:34
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
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
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

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
@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
@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
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

@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
@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
@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
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
I'd use forEach instead of map if I weren't interested in the return values.
Markus Kiili
@Masd925
Aug 09 2017 09:51
@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
TKS
Blauelf
@Blauelf
Aug 09 2017 09:53
@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
IIRC the specs say that order isn't guaranteed...
Markus Kiili
@Masd925
Aug 09 2017 09:57
@pahosler Yes, we were talking about exactly that.
Blauelf
@Blauelf
Aug 09 2017 09:59
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
hey
can anyone help me out fcc challange
EpicTriffid
@EpicTriffid
Aug 09 2017 10:02
@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
can you be more specific @prakashyadav008
Markus Kiili
@Masd925
Aug 09 2017 10:05
@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
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
@prakashyadav008 Don't use a global variable like that. It can mess up fcc tests.
prakash chandra yadav
@prakashyadav008
Aug 09 2017 10:06
ya thts the doubt
about global variables @Masd925
CamperBot
@camperbot
Aug 09 2017 10:06
:star2: 4394 | @masd925 |http://www.freecodecamp.com/masd925
prakash chandra yadav
@prakashyadav008
Aug 09 2017 10:07
using local function variables it returns correct but using global variable returns error
Markus Kiili
@Masd925
Aug 09 2017 10:07
@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
on the console it does return different arrays
if i use console.log
thanks @Masd925
CamperBot
@camperbot
Aug 09 2017 10:10
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
@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

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
mutating solutions ..like what..?
@Masd925
Markus Kiili
@Masd925
Aug 09 2017 10:15
@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
@Masd925 Sorry Markus, did you see my question above?
Markus Kiili
@Masd925
Aug 09 2017 10:16
@EpicTriffid Ask @Blauelf , the local regexp master.
EpicTriffid
@EpicTriffid
Aug 09 2017 10:18
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
@EpicTriffid Sorry, I mixed you up with @WAINGOR
EpicTriffid
@EpicTriffid
Aug 09 2017 10:19
Dats ok!
WAINGOR
@WAINGOR
Aug 09 2017 10:19
@Masd925 U hurt my feelings 8*( I thought we had bonded
Markus Kiili
@Masd925
Aug 09 2017 10:21
@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
@Masd925 XD XD <3
EpicTriffid
@EpicTriffid
Aug 09 2017 10:23
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
thats a local variable @Masd925
Markus Kiili
@Masd925
Aug 09 2017 10:23
@prakashyadav008 What is?
Your code had a global variable:
var array = [];
EpicTriffid
@EpicTriffid
Aug 09 2017 10:25
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
@EpicTriffid Strings are immutable, so the original string is not affected. Slice just makes a new string.
EpicTriffid
@EpicTriffid
Aug 09 2017 10:27
So do I need to assign that second one to a new variable?
Markus Kiili
@Masd925
Aug 09 2017 10:27
str = str.slice(2) would change the string held in str.
prakash chandra yadav
@prakashyadav008
Aug 09 2017 10:27
i mean ur code example @Masd925
Markus Kiili
@Masd925
Aug 09 2017 10:29
@prakashyadav008 Yes, the variable is local, as it should.
Blauelf
@Blauelf
Aug 09 2017 10:39

@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
@WAINGOR What do you want to match? Something like /\S+/g?
bilaal-s
@bilaal-s
Aug 09 2017 10:48
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
$(".button").unbind("click").on("click", function() { seems to have fixed the issue
Stephen James
@sjames1958gm
Aug 09 2017 11:14
@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
@sjames1958gm is unbinding the event best practice? or should i restructure the code?
@sjames1958gm thanks bytheway
CamperBot
@camperbot
Aug 09 2017 11:34
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
@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
<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
@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
@Masd925 so, the for loop does not wait for settimeout function to finish running. ?
Ene Catalin
@EneCatalin
Aug 09 2017 11:48
@Venkateshwaran maybe check this out
I am not familiar with the let myself
Markus Kiili
@Masd925
Aug 09 2017 11:49
@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
@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
@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
@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
@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
@Venkateshwaran :+1:
Venkateshwaran
@Venkateshwaran
Aug 09 2017 12:01
@sjames1958gm @Masd925 and In let case each for loop becomes a different block ?
Markus Kiili
@Masd925
Aug 09 2017 12:01
@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
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
@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
@Venkateshwaran That I don't know.
Venkateshwaran
@Venkateshwaran
Aug 09 2017 12:10
@sjames1958gm thanks :)
CamperBot
@camperbot
Aug 09 2017 12:10
venkateshwaran sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8281 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Blauelf
@Blauelf
Aug 09 2017 12:11
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
@Masd925 thanks to you too.
CamperBot
@camperbot
Aug 09 2017 12:11
venkateshwaran sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4396 | @masd925 |http://www.freecodecamp.com/masd925
Venkateshwaran
@Venkateshwaran
Aug 09 2017 12:12
@Blauelf you mean in var case I used closure, and that is more heavy?
Stephen James
@sjames1958gm
Aug 09 2017 12:13
@Blauelf Wouldn't both be closure, just with differently organized contexts?
Markus Kiili
@Masd925
Aug 09 2017 12:14
@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
@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
@Masd925 @sjames1958gm @Blauelf so using var appropriately would be better than using let ?
Markus Kiili
@Masd925
Aug 09 2017 12:17
@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
@Masd925 Ah, I see. My misunderstanding
@Masd925 thx
CamperBot
@camperbot
Aug 09 2017 12:18
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
@sjames1958gm Well, I didn't say it very clearly. Thanks too.
CamperBot
@camperbot
Aug 09 2017 12:19
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
Brownies for EVERYONE ! ;)
Markus Kiili
@Masd925
Aug 09 2017 12:20
help brownie dilution
:(
Abhishek Kumar Pandey
@abhishekpandeykr
Aug 09 2017 12:26
how to use Object.assign{} inside a class
Bartosz
@CataciD
Aug 09 2017 12:27
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
js class i want to merge two objects inside a class, sorry that was Object.assign()
Stephen James
@sjames1958gm
Aug 09 2017 12:29
@abhishekpandeykr Why would inside a class have any impact on using Object.assign?
Abhishek Kumar Pandey
@abhishekpandeykr
Aug 09 2017 12:30
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
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
@CataciD ES6 has class syntax (sugar).
Bartosz
@CataciD
Aug 09 2017 12:32
but no matter, could you be more specific?
as in extention of modules?
Stephen James
@sjames1958gm
Aug 09 2017 12:33
@abhishekpandeykr What is the error that it is throwing.
Bartosz
@CataciD
Aug 09 2017 12:33
also markus, that class syntax is pretty ridiculous from what i can tell
Stephen James
@sjames1958gm
Aug 09 2017 12:33
@abhishekpandeykr The first object does not have to be blank
Bartosz
@CataciD
Aug 09 2017 12:34
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
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
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
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
lol
Markus Kiili
@Masd925
Aug 09 2017 12:35
@CataciD I agree that JS classes just mostly confuse things.
Stephen James
@sjames1958gm
Aug 09 2017 12:35
@kelechy if (number is prime) return number :)
Elizabeth Paul
@Kowalatam
Aug 09 2017 12:35
lol
Abhishek Kumar Pandey
@abhishekpandeykr
Aug 09 2017 12:35
lol
Bartosz
@CataciD
Aug 09 2017 12:35
@kelechy probably need to check if its dividable only by its self and 1
Kelechi Chinaka
@ke1echi
Aug 09 2017 12:35
since prime numbers are numbers that can be divided by 1 and itself
namethatisnottaken
@namethatisnottaken
Aug 09 2017 12:35
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
if ((i % 1 ) && (i % i)) {
      prime.push(i)
    }
this is what i have
Bartosz
@CataciD
Aug 09 2017 12:36
@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
that would just give him the answer tho
Kelechi Chinaka
@ke1echi
Aug 09 2017 12:37
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
thats the point
an algorithm is not coding
Kelechi Chinaka
@ke1echi
Aug 09 2017 12:37
ok @CataciD
namethatisnottaken
@namethatisnottaken
Aug 09 2017 12:37
@kelechy prime only have 2 factors 1 and itself if i am not mistaken
Bartosz
@CataciD
Aug 09 2017 12:37
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
@kelechy Do you know what makes a number prime?
Bartosz
@CataciD
Aug 09 2017 12:38
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
yes @sjames1958gm it must be divisible by only 1 and itself
Stephen James
@sjames1958gm
Aug 09 2017 12:39
@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
do you wan't it @kelechy ?
Kelechi Chinaka
@ke1echi
Aug 09 2017 12:39
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
i found an algorithm thats basically bingo
you specify the range of numbers
Stephen James
@sjames1958gm
Aug 09 2017 12:39
@kelechy You can use the sieve method or just test every value from 2 to sqrt(i)
Bartosz
@CataciD
Aug 09 2017 12:39
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
@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
from what i've read
so you start at 2
Stephen James
@sjames1958gm
Aug 09 2017 12:40
@namethatisnottaken The first function looks like it will pass i not int to the swap function
Bartosz
@CataciD
Aug 09 2017 12:40
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
@namethatisnottaken I doubt that there is much execution difference
Bartosz
@CataciD
Aug 09 2017 12:40
if a number is divisible (%number)
then remove it
Kelechi Chinaka
@ke1echi
Aug 09 2017 12:41
yea 1 is not prime @CataciD
Bartosz
@CataciD
Aug 09 2017 12:41
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
oh my God yes, i did not get it @_@
Bartosz
@CataciD
Aug 09 2017 12:41
go on to 3
namethatisnottaken
@namethatisnottaken
Aug 09 2017 12:41
lol
Bartosz
@CataciD
Aug 09 2017 12:41
3 eliminates 6,9
namethatisnottaken
@namethatisnottaken
Aug 09 2017 12:41
thanks @sjames1958gm
CamperBot
@camperbot
Aug 09 2017 12:41
namethatisnottaken sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
Bartosz
@CataciD
Aug 09 2017 12:41
but 6 already eliminated
CamperBot
@camperbot
Aug 09 2017 12:41
:star2: 8283 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Bartosz
@CataciD
Aug 09 2017 12:41
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
@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
that was sure confusing.. can you send me the link so i can read through? @CataciD
Bartosz
@CataciD
Aug 09 2017 12:44
@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
i think i am going to make a kata outta this @sjames1958gm :smile:
thanks @CataciD
CamperBot
@camperbot
Aug 09 2017 12:45
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

@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
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
@kelechy :+1:
namethatisnottaken
@namethatisnottaken
Aug 09 2017 12:49
@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
@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
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
sure.. why not ? @Chrono79
Roxroy
@roxroy
Aug 09 2017 14:09
@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
@Chrono79 You have to at least respond with 200 OK to satisfy http
Diego Mayer
@Chrono79
Aug 09 2017 14:13
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
maybe.. depends on the payment gateway u using... require some configuration (i dunno never used)
Tao
@zombiebirds
Aug 09 2017 14:39
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
@zombiebirds 0>undefined //false
initialize max
also u need to return a number value.. not an array
WAINGOR
@WAINGOR
Aug 09 2017 14:58

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
@WAINGOR you're using strict comparison, !undefined isn't "jack"
console.log(!undefined);
//true
Brad
@bradtaniguchi
Aug 09 2017 15:03
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
@moigithub thanks!
CamperBot
@camperbot
Aug 09 2017 15:04
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
undefined and 'jack' are different values
they never gonna be equal @WAINGOR
WAINGOR
@WAINGOR
Aug 09 2017 15:09
Thanks @Chrono79 !!
CamperBot
@camperbot
Aug 09 2017 15:09
waingor sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4512 | @chrono79 |http://www.freecodecamp.com/chrono79
WAINGOR
@WAINGOR
Aug 09 2017 15:10
@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
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
@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
oops my syntax isn't even valid, thats what I get for winging it
WAINGOR
@WAINGOR
Aug 09 2017 15:31
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
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
@WAINGOR Yes
WAINGOR
@WAINGOR
Aug 09 2017 15:32
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
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
@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
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
@kelechy Link to the challenge?
Addison
@addisonday
Aug 09 2017 16:24
"less than or equal to" @kelechy
Kelechi Chinaka
@ke1echi
Aug 09 2017 16:25
does not work even if i did str.length <= 3
Stephen James
@sjames1958gm
Aug 09 2017 16:27
@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
147 lines of code for my javascript calculator so far
lol
Addison
@addisonday
Aug 09 2017 16:29
Thank you @JLuboff btw. That's a good thing to keep in mind!
CamperBot
@camperbot
Aug 09 2017 16:29
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
@bilaal-s yeah lots of different cases to keep track of in that one
Kelechi Chinaka
@ke1echi
Aug 09 2017 16:29
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
I'd say that's a fair assessment :D
Kelechi Chinaka
@ke1echi
Aug 09 2017 16:33
:smile:
are you done with it @JLuboff
Jason Luboff
@JLuboff
Aug 09 2017 16:36
@kelechy Haven't started lol
Kelechi Chinaka
@ke1echi
Aug 09 2017 16:41
ok...hows your backend project going? @JLuboff
Jason Luboff
@JLuboff
Aug 09 2017 16:41
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
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
o cool @JLuboff
Christopher McCormack
@cmccormack
Aug 09 2017 16:49
@RoniqueRicketts do you want this maybe?
document.querySelector("#destiny").style.display = 'none'
Abid Rahim
@abidRahim
Aug 09 2017 16:49

@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
use three backticks to format code
Ronique Ricketts
@RoniqueRicketts
Aug 09 2017 16:49
@cmccormack i know that works but why can't I set an attribute
Christopher McCormack
@cmccormack
Aug 09 2017 16:50
@abidRahim arguments.length will be 2
@abidRahim what are you trying to iterate over?
Abid Rahim
@abidRahim
Aug 09 2017 16:51
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
@RoniqueRicketts
document.querySelector("#destiny").setAttribute("hidden", "");
Ronique Ricketts
@RoniqueRicketts
Aug 09 2017 16:51
@cmccormack thanks man your a lifesaver
CamperBot
@camperbot
Aug 09 2017 16:51
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
Christopher McCormack
@cmccormack
Aug 09 2017 16:52
@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
okay
what do i return after comparing
within filter's anonymous function
Stephen James
@sjames1958gm
Aug 09 2017 16:55
@abidRahim return true if you want to keep the value false if you want to drop
Christopher McCormack
@cmccormack
Aug 09 2017 16:55
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
yes i am
i'll try your suggestion and get back
Stephen James
@sjames1958gm
Aug 09 2017 16:55
@abidRahim the arguments inside the filter function are for that function not destroyer
Abid Rahim
@abidRahim
Aug 09 2017 16:56
oh right
Christopher McCormack
@cmccormack
Aug 09 2017 16:56
you can simplify a bit using:
return (val !== arguments[i])
Abid Rahim
@abidRahim
Aug 09 2017 16:57
i actually tried that
Stephen James
@sjames1958gm
Aug 09 2017 16:57
@abidRahim a simple assignment var args = arguments, will make it available as args
Abid Rahim
@abidRahim
Aug 09 2017 16:57
brb
Stephen James
@sjames1958gm
Aug 09 2017 16:57
@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
@sjames1958gm ah good point
Addison
@addisonday
Aug 09 2017 17:24
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
@addisonday Try i < contacts.length not contacts[i]`
Addison
@addisonday
Aug 09 2017 17:25
@JLuboff Same result
Jason Luboff
@JLuboff
Aug 09 2017 17:28
@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
@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
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
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
@RoniqueRicketts The console is incredibly useful
Ronique Ricketts
@RoniqueRicketts
Aug 09 2017 17:30
@addisonday yeah it is man. I love it
juni
@junipberry
Aug 09 2017 17:38
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
@junipberry Use a loop to push the object elements into an array?
juni
@junipberry
Aug 09 2017 17:43
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
Can you give an example of one of the objects?
juni
@junipberry
Aug 09 2017 17:47
date: “Wednesday”,
weather: “sunny”,
month: “August”
}
Ene Catalin
@EneCatalin
Aug 09 2017 17:47
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
sorry there should be a { in the beginning
Jason Luboff
@JLuboff
Aug 09 2017 17:50

@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
It's behaving weird
juni
@junipberry
Aug 09 2017 17:51
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
@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
let arr = Object.entries(obj)
es7 ?
Jason Luboff
@JLuboff
Aug 09 2017 17:57
@moigithub She doesn't want to use any Object methods
Moisés Man
@moigithub
Aug 09 2017 17:57
ahh ok :D
Kelechi Chinaka
@ke1echi
Aug 09 2017 18:00
already using es7? pls slow down :smile: @moigithub
juni
@junipberry
Aug 09 2017 18:03
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
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
@junipberry What is this for?
juni
@junipberry
Aug 09 2017 18:04
I’m just practicing on a prep site
Jason Luboff
@JLuboff
Aug 09 2017 18:04
Can you link to it or is it private?
juni
@junipberry
Aug 09 2017 18:04
its private, bc the questions are only accessible w a login
Jason Luboff
@JLuboff
Aug 09 2017 18:05
:+1:
juni
@junipberry
Aug 09 2017 18:05
:/
Addison
@addisonday
Aug 09 2017 18:05
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
Hello Buys
guys*
Jason Luboff
@JLuboff
Aug 09 2017 18:06
@addisonday contact.hasOwnProperty(prop)
Addison
@addisonday
Aug 09 2017 18:07
Why not use bracket notation? We don't know what the user can input for prop correct?
juni
@junipberry
Aug 09 2017 18:08
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
@JLuboff The function is returning nothing
Jason Luboff
@JLuboff
Aug 09 2017 18:09
@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
@Delwalt :wave:
Moisés Man
@moigithub
Aug 09 2017 18:10
@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
@addisonday You should be using contacts[i] not contacts inside the loop
Addison
@addisonday
Aug 09 2017 18:11
@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
@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
@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
@addisonday I did mean inside the loop not in the for loop test
Addison
@addisonday
Aug 09 2017 18:13
@sjames1958gm I see what you mean now
juni
@junipberry
Aug 09 2017 18:19

@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
Looks good to me? I'm guessing it's not passing though?
juni
@junipberry
Aug 09 2017 18:20
no..
Jason Luboff
@JLuboff
Aug 09 2017 18:21
Can you show the full instructions of the challenge?
juni
@junipberry
Aug 09 2017 18:22
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
@junipberry Oh, so you just need the keys
juni
@junipberry
Aug 09 2017 18:23
yes~
Jason Luboff
@JLuboff
Aug 09 2017 18:24
So just do myArr.push(key);
I thought you need the key and value
juni
@junipberry
Aug 09 2017 18:25
ahh
I thought I was only pushing the [keys] from the obj..
ty @JLuboff !
CamperBot
@camperbot
Aug 09 2017 18:27
junipberry sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:warning: junipberry already gave jluboff points
Jason Luboff
@JLuboff
Aug 09 2017 18:27
:+1:
Thayyeb salim
@Thayyebsalim
Aug 09 2017 18:28
@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
@Thayyebsalim Can you be more specific of the issue?
Adam Bohannon
@abohannon
Aug 09 2017 18:33
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
@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
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
Yeah that's it
but I have no idea how to bypass it :worried:
Jason Luboff
@JLuboff
Aug 09 2017 18:48
@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
@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
@addisonday Validate in what regard?
Addison
@addisonday
Aug 09 2017 18:54
@JLuboff in the case that it doesn't exist
Jason Luboff
@JLuboff
Aug 09 2017 18:56
@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

@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
@addisonday you're supposed to check it against first name as well.
Addison
@addisonday
Aug 09 2017 19:07
@kumquatfelafel I am not sure how to do that. All the ways I have tried failed...
kumquatfelafel
@kumquatfelafel
Aug 09 2017 19:07
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
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
@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
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
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
@addisonday , You will need to check that the contacts[i].firstName matches the firstName from the parameter.
kumquatfelafel
@kumquatfelafel
Aug 09 2017 19:12
@addisonday basically, your code is 100% correct, provided you now implement the first name check properly
Roxroy
@roxroy
Aug 09 2017 19:19
@kumquatfelafel , right, will update accordingly..
kumquatfelafel
@kumquatfelafel
Aug 09 2017 19:19
aye :)

http:\\/\\/

???

Addison
@addisonday
Aug 09 2017 19:25
@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
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
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

@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
@tiagocorreiaalmeida what do you mean with prefor?
Tiago Correia
@tiagocorreiaalmeida
Aug 09 2017 19:40
@Chrono79 perform*
Addison
@addisonday
Aug 09 2017 19:41
@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
you have to load jqueryui too, it's not in the regular jquery
Tiago Correia
@tiagocorreiaalmeida
Aug 09 2017 19:46
@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
@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
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
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

@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
@kelechy the parentheses shouldn't be necessary at all
kumquatfelafel
@kumquatfelafel
Aug 09 2017 19:59
@kelechy could you link the challenge? :point_down:
Margaret
@Margaret2
Aug 09 2017 19:59
@kelechy yeah, it also depends on what the instructions said
Ronique Ricketts
@RoniqueRicketts
Aug 09 2017 20:02
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
@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
lol @kumquatfelafel
Kelechi Chinaka
@ke1echi
Aug 09 2017 20:09
oh...i think i need a rest now :smile: @kumquatfelafel thanks
CamperBot
@camperbot
Aug 09 2017 20:09
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
@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
@RoniqueRicketts try document.querySelectorAll("div > .grids");
Tiago Correia
@tiagocorreiaalmeida
Aug 09 2017 20:11
.show used that @Chrono79 but thanks for the info
CamperBot
@camperbot
Aug 09 2017 20:11
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
@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
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
@cmccormack thanks I will try that
CamperBot
@camperbot
Aug 09 2017 20:13
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
@RoniqueRicketts grids.forEach(grid=>grid.addEventListener...
Ronique Ricketts
@RoniqueRicketts
Aug 09 2017 20:16
@cmccormack your a genius. thanks omg my project is coming along :D
CamperBot
@camperbot
Aug 09 2017 20:16
roniquericketts sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:warning: roniquericketts already gave cmccormack points
Christopher McCormack
@cmccormack
Aug 09 2017 20:16
@RoniqueRicketts :thumbsup:
Ronique Ricketts
@RoniqueRicketts
Aug 09 2017 20:17
@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
@roxroy thx :)
CamperBot
@camperbot
Aug 09 2017 20:20
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
@RoniqueRicketts yeah man it's looking good!
Ronique Ricketts
@RoniqueRicketts
Aug 09 2017 20:24
@cmccormack Yeah I am working on getting it fixed up.
WAINGOR
@WAINGOR
Aug 09 2017 20:25

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
@WAINGOR Kill the terminal window or the node process
WAINGOR
@WAINGOR
Aug 09 2017 20:28
how
:)
Jason Luboff
@JLuboff
Aug 09 2017 20:28
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
do you want it to shut off automatically? could run setTimeOut on a clearInterval
Abid Rahim
@abidRahim
Aug 09 2017 20:35
@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
@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
okay
Diego Mayer
@Chrono79
Aug 09 2017 20:42
@WAINGOR cut the red wire as everybody knows ;)
kumquatfelafel
@kumquatfelafel
Aug 09 2017 20:48

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

:boom:

Tiago Correia
@tiagocorreiaalmeida
Aug 09 2017 20:53
@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
@tiagocorreiaalmeida you missed = in your html when defining the classes
Tiago Correia
@tiagocorreiaalmeida
Aug 09 2017 20:57
oh god
thanks
can I use append and fadein at the same time?
Abid Rahim
@abidRahim
Aug 09 2017 20:58

@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

@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
@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
@tiagocorreiaalmeida should work
scarejar
@scarejar
Aug 09 2017 21:05
//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
@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
@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
got a problem where SERVER is defined but says it's not defined for some reason
Jason Luboff
@JLuboff
Aug 09 2017 21:07
@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
lmao
kumquatfelafel
@kumquatfelafel
Aug 09 2017 21:08
@JLuboff sounds legit
Christopher McCormack
@cmccormack
Aug 09 2017 21:08
@JLuboff ah that's so sweet
kumquatfelafel
@kumquatfelafel
Aug 09 2017 21:08
It's the uncleboard you really have to keep an eye on.
Jason Luboff
@JLuboff
Aug 09 2017 21:09
:joy:
Christopher McCormack
@cmccormack
Aug 09 2017 21:09
or another motherboard, don't tell hardware what to love!
kumquatfelafel
@kumquatfelafel
Aug 09 2017 21:09
lol
Oleh
@Lufter
Aug 09 2017 21:10
@tiagocorreiaalmeida
W3S - jQ selectors
Christopher McCormack
@cmccormack
Aug 09 2017 21:11
@tiagocorreiaalmeida you may want to check what .text() returns, if it's an element then should work
Oleh
@Lufter
Aug 09 2017 21:13

@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

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
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
@artoodeeto shouldn't you use new before RegExp?
And what about the capitalization?
scarejar
@scarejar