These are chat archives for FreeCodeCamp/HelpJavaScript

19th
Aug 2017
Ken Haduch
@khaduch
Aug 19 2017 00:21
@artoodeeto - you are taking elements off the array until the function returns true, so the .shift() is doing that - removing the elements.
Kaeleb Rocha
@Kralleb
Aug 19 2017 00:25
anyone here know regex?
Ken Haduch
@khaduch
Aug 19 2017 00:26
@Kralleb - you'll find some help here for sure... ask away!
Kaeleb Rocha
@Kralleb
Aug 19 2017 00:28
var check = str.match(/1?[- ]?(\(\d{3}\)[- ]?)|\d{3}[- ]?/);
elephoneCheck("1 (555) 555-5555");
that's my regex and that's my search parameter
This is my result: ["1 (555) ","(555) "];
I can't imagine why i'm getting 2 (555)
I know it has something to do with the parenthesis, but it's confusing because theyre group capturing.. @khaduch
Ken Haduch
@khaduch
Aug 19 2017 00:29
@Kralleb - yeah, regex matching can be confusing... I think that the second (555) is coming from the | part of the expression.
Kaeleb Rocha
@Kralleb
Aug 19 2017 00:30
So i put optionally 1 followed by optionally "-" followed by space. Then i wanted to say if it has parenthesis then use this version else use that version
Right, but i thought alternation would only pick either or.
Should i do a character class instead?
Ken Haduch
@khaduch
Aug 19 2017 00:32
I'm trying to read it... I think that it's probably that the first part is the entire expression match, and the second part is the capture group that is the match of this part: (\(\d{3}\)[- ]?)
Kaeleb Rocha
@Kralleb
Aug 19 2017 00:33
So parenthesis doesn't group them, it captures them? @khaduch
Ken Haduch
@khaduch
Aug 19 2017 00:35
@Kralleb - when you have the back-quoted parentheses, it will literally match a parenthesis character. Un-quoted parentheses establish capture groups, which you can use in that way, or they just group expressions for the alternate matches, like the |. I'd have to look at it a little more just to confirm that I'm not making anything up - but that's my call on it. If you don't need the captured group to do anything in particular, it's just a side effect of using parentheses for your grouped expressions.
Kaeleb Rocha
@Kralleb
Aug 19 2017 00:40
right, That's why I wrapped the entire thing in parenthesis. I also need parenthesis to be in there to see if the telephone number works. My goal was to say "Capture (555) or 555"
Ken Haduch
@khaduch
Aug 19 2017 00:43
@Kralleb - I did my expression for that part like this: ((\(\d{3}\))|\d{3}) - either match (ddd) or ddd so I went a slightly different route.
@Kralleb - my final expression for the entire telephone number validation only gets one match for the entire expression - I have it plugged into http://regexr.com, a nice tool to see where things are happening with your regex.
Kaeleb Rocha
@Kralleb
Aug 19 2017 00:48
@khaduch Doesn't seem to work in the same way. Thanks @khaduch I'll just have to figure out what the heck is going on.
CamperBot
@camperbot
Aug 19 2017 00:48
kralleb sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3216 | @khaduch |http://www.freecodecamp.com/khaduch
Ken Haduch
@khaduch
Aug 19 2017 00:49
@Kralleb - something else that might make a difference - I have my regexp anchored to the start and end of the string, not sure if that would affect the matches that you are getting. I'm going to check that, too. And it doesn't seem to make a difference.
in regexr.com, it's actually getting three matches with your expression.
@Kralleb - https://regex101.com/#javascript does a better job of showing where the groups are and explaining things. Take a look at that
Kaeleb Rocha
@Kralleb
Aug 19 2017 00:53
@khaduch How do i get it to just match once?
Ken Haduch
@khaduch
Aug 19 2017 00:55
@Kralleb - lump your group of three digits into one parenthesized expression like I did in :point_up: August 18, 2017 8:43 PM that comment. I made it be either a parenthesized three-digit group, or a non-parenthesized three-digit group
Kaeleb Rocha
@Kralleb
Aug 19 2017 00:57
Oh okay. regex is breaking my brain haha again Thanks @khaduch
CamperBot
@camperbot
Aug 19 2017 00:57
kralleb sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:warning: kralleb already gave khaduch points
Ken Haduch
@khaduch
Aug 19 2017 00:59
@Kralleb - so, esssentially this: 1?[- ]?(\(\d{3}\)|\d{3}) but you still get the match of the entire 1 (555) and then the capture group, because you are still using the parentheses (unquoted) to establish alternatives, and it also forms a capture group. You just have to ignore the captured matching group since you are not interested in that side-effect.
it's confusing, it takes a while to wrap your head around it!
:dizzy_face:
alhajit21
@alhajit21
Aug 19 2017 01:22

need help understanding this closure problem https://codecard.io/a/challenge/7rMlnYpk2?sequence=7rVGdfJUu

var outer = function(){
var name = 'Tyler';
return function(){
return 'The original name was ' + name;
}
outer();
}
var inner = outer();
inner();
console.log(outer);

Ken Haduch
@khaduch
Aug 19 2017 01:30

@alhajit21 - I think that the only think that you are missing is to do this at the end:

var inner = outer();
console.log(inner());

You should see the output on the console that says: "The original name was Tyler"

I don't know if that helps you to understand, but that's the way they want you to write the code.
alhajit21
@alhajit21
Aug 19 2017 01:34
dam I was close thanks for the help @khaduch
CamperBot
@camperbot
Aug 19 2017 01:34
alhajit21 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3217 | @khaduch |http://www.freecodecamp.com/khaduch
Ken Haduch
@khaduch
Aug 19 2017 01:39
@alhajit21 :+1:
Dovydas Stirpeika
@Giveback007
Aug 19 2017 01:57
The random quote api I was using stoped working so I created my own :smile:
https://giveback007-random-quote-microservice.glitch.me/
I love free code camp, just a few months ago I couldn't even make an ajax call without wrecking my brain
Ginger
@GingerChew
Aug 19 2017 02:09
hey I think I'm getting this .forEach() function in java, can I get some help?
function uniteUnique(arr) {
  var args = Array.prototype.slice.call(arguments);
  var newArgs = args.forEach(function(index) {
    for (var i=i;i<args.length;i++){
      if (args[0][index] === args[i][index]) {
        return args[i][index];
      }
    }
  });
  return newArgs;
}
Dovydas Stirpeika
@Giveback007
Aug 19 2017 02:10
@GingerChew what are you trying to achieve?
for each is kind of like a loop and in this case it would be more of an outer loop
Ginger
@GingerChew
Aug 19 2017 02:11
I'm trying to get it to check each value in arguments[i] against the first argument given. But I think I'm defeating the purpose of that by putting a for loop in it? I'm not sure how to set up a forEach function
@Giveback007 what do you mean by outerloop?
Dovydas Stirpeika
@Giveback007
Aug 19 2017 02:11
idk if this would fix it, but you at least want to change args[index][i] instead of the other way
Ginger
@GingerChew
Aug 19 2017 02:12
Yeah it didn't, i think the funciton is messed up on a ground level issue
Dovydas Stirpeika
@Giveback007
Aug 19 2017 02:13
forEach will take an array or an object and for 'each' of the values in the array or object will execute the function
have you nested loops before?
var args = Array.prototype.slice.call(arguments);
also that's not how you use slice
Ginger
@GingerChew
Aug 19 2017 02:16
what do you mean?
if you do it the way I did, it puts all of the arguments into one array
into an array of arrays
Dovydas Stirpeika
@Giveback007
Aug 19 2017 02:16
ahh I see, I guess I've never seen that before
do you have this code somewhere for me to look at?
maybe on codepen?
Ginger
@GingerChew
Aug 19 2017 02:17
I can put it on repl real quick hold on
Dovydas Stirpeika
@Giveback007
Aug 19 2017 02:17
and an example input that would go in to the function
cause the ultimate goal is to return an array with all the arguments unique elements. So if there is a 1 present in more than 1 array, only the first 1 will be seen, others will be removed
Dovydas Stirpeika
@Giveback007
Aug 19 2017 02:19
I see
hold on let me see what the problem is
do you know how to use indexOf()?
@GingerChew
Ginger
@GingerChew
Aug 19 2017 02:22
on a shallow level sure
think that could be useful?
Dovydas Stirpeika
@Giveback007
Aug 19 2017 02:22
well if indexOf returns -1 it means that the value was not found
so you could use that (hint hint)
Ginger
@GingerChew
Aug 19 2017 02:23
ahhhhhhhhh
i gotchu
hmmmmm, i'll stew on that, thanks m8
@Giveback007 thanks
Dovydas Stirpeika
@Giveback007
Aug 19 2017 02:23
do you know how to use push()
Ginger
@GingerChew
Aug 19 2017 02:24
yeah, that early stuff I got, I'm on intermediate algorithms and theyre kicking my ass
Dovydas Stirpeika
@Giveback007
Aug 19 2017 02:25
also if MDN ever feels daunting you can check out w3schools reference
https://www.w3schools.com/jsref/
it helped me a lot when I was going trough the interm algos
(i still use it till this day, just don't tell anyone)
Ginger
@GingerChew
Aug 19 2017 02:27
Yeah, i gotta check there out too, thanks for the tip!
Dovydas Stirpeika
@Giveback007
Aug 19 2017 02:27
np
Ken Haduch
@khaduch
Aug 19 2017 02:54
@Giveback007 @GingerChew - I find the w3schools site to be pretty handy, too - they have a nice sandbox environment to see how things work and experiment with it a little on each concept. Some people have dissed that site, there might be things that are a little out of date, but in general it's good for the basics, and I use it a lot.
Ginger
@GingerChew
Aug 19 2017 03:00
@Giveback007 I figured out where I was messing up, didn't need to reference i as much as I was, it was returning undefined
Dovydas Stirpeika
@Giveback007
Aug 19 2017 03:21
@khaduch yeah I'm awfully surprised how hard people try to get beginners on MDN
it is unreadable for newbies, makes programming feel unreachable
I mean mdn is great, but not when you can hardly understand what a method is
Dovydas Stirpeika
@Giveback007
Aug 19 2017 03:44
@GingerChew goot job on solving the algo :smile:
This thing took DAYS
Tai Jones
@taiJones00
Aug 19 2017 04:06
so a white screen is getting returned
why?
Abhinav Mishra
@abhinav-m
Aug 19 2017 04:15
@sandsbe good job :)
Bradley Sands
@sandsbe
Aug 19 2017 04:19
My wife already broke it. I can't recreate her errors.
She's my live-in bug.
Tai Jones
@taiJones00
Aug 19 2017 04:20
can I have help
Abhinav Mishra
@abhinav-m
Aug 19 2017 04:24
@taiJones00 im not sure.. i think it might be because youre using a form and passing GET as the form action with a php link
Tai Jones
@taiJones00
Aug 19 2017 04:24
hm?
should I not use the action and get attributes
yep now it's not a white page so next is...
Abhinav Mishra
@abhinav-m
Aug 19 2017 04:28
@taiJones00 you could use a simple textarea for the input and a div for the searchbutton or a button
@taiJones00 look at this fork
Tai Jones
@taiJones00
Aug 19 2017 04:28
that would work better?
but oh no it looks worse. Couldn't this way still work
Abhinav Mishra
@abhinav-m
Aug 19 2017 04:29
you can make this fork look better
Tai Jones
@taiJones00
Aug 19 2017 04:29
It was submitting your form - I changed it to a div to stop that.
Use this to see the JSON - looks like something is wrong with your query
console.log("the JSON got got!" + JSON.stringify(json));
does this make sense ^
Abhinav Mishra
@abhinav-m
Aug 19 2017 04:30
yea
what?
it is logging the response
take a look at these
some cool ways to search
Tai Jones
@taiJones00
Aug 19 2017 04:31
oh sweet
and you think this will solve all these issues?
Abhinav Mishra
@abhinav-m
Aug 19 2017 04:31
the white screen issues, yes
you still need to parse the response properly.
Tai Jones
@taiJones00
Aug 19 2017 04:32
oh that one has been solved. Getting rid of action and method from the form attributes solved that problem thank you
wait what
Abhinav Mishra
@abhinav-m
Aug 19 2017 04:32
:+1:
As in extract what you need from the JSON object youre getting
and display it in your page
Tai Jones
@taiJones00
Aug 19 2017 04:33
okay I updated the page. no white page but why isn't any json being written to the page
Addison
@addisonday
Aug 19 2017 05:11
I do not want any more help than figuring out how to remove the single quotes returned in the result... Thank you in advance! Here is the code:
 "use strict";
      const doc = [
        'div',
        ['p', 'The first paragraph.'],
        ['p', 'The second paragraph.'],
        [
          'div',
          ['p', 'The third paragraph is nested.'],
          ['p', 'As is the fourth.']
        ]
      ];

      //const doc = ['p', 'this is a paragraph'];

      function transpile(arr){
       return '<' + arr[0]. + '>';
      };

      transpile(doc);  // '<div>'
Ogundele Olumide
@Lumexralph
Aug 19 2017 05:27
@addisonday don't worry yourself about the single quotes ' it's the way the console will represent a string except you do something like this
 //const doc = ['p', 'this is a paragraph'];

      function transpile(arr){
       return `<${arr[0]}>`;
      };

      console.log(transpile(doc));  // <div>
@addisonday But it's still a string just the display is different
Addison
@addisonday
Aug 19 2017 05:28
@Lumexralph What does the $ and { } mean?
Can you refer to me some reading?
and okay so it's the console putting the ' '
Joseph
@revisualize
Aug 19 2017 05:32
Hello.
Ogundele Olumide
@Lumexralph
Aug 19 2017 05:34
@addisonday it's template literals, just a way of embedding an expression into a string
@addisonday nope but that doesn't change the datatype
Addison
@addisonday
Aug 19 2017 05:34
@Lumexralph Okay, thank you!
CamperBot
@camperbot
Aug 19 2017 05:34
addisonday sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 2048 | @lumexralph |http://www.freecodecamp.com/lumexralph
Ogundele Olumide
@Lumexralph
Aug 19 2017 05:36
@addisonday you're welcome
Pieter Stokkink
@forkerino
Aug 19 2017 10:46
Announcement: CodeSchool has a free weekend. Which means that all their courses are freely available until tomorrow night. https://www.codeschool.com
Abhinav Mishra
@abhinav-m
Aug 19 2017 11:25
@forkerino do you recommend any particular course from there
theres so much to choose from not sure which one i can do in this timeperiod
heroiczero
@heroiczero
Aug 19 2017 11:35
Well they have react
Pieter Stokkink
@forkerino
Aug 19 2017 11:42
@abhinav-thinktank the courses don't go very deep, so pick something new in which you are interested to get you of the ground.
I'm doing the django courses because we use django at work and I didn't learn it before.
Abhinav Mishra
@abhinav-m
Aug 19 2017 11:44
aah.. ok
i was looking at the bootstrap one
@heroiczero ive done some react tutorials
@heroiczero egghead, facebook docs
@heroiczero is their react course good?
interested in this one as well
i guess ill do either this or their node one.
Ronique Ricketts
@RoniqueRicketts
Aug 19 2017 12:38
I feel so happy!!! Tomorrow is my Birthday and I have fulfilled my birthday gift to myself. I have learnt to code. I feel so happy and accomplished. Thanks much FCC and MDN :) By next year I should be able to code in react and Nodejs.
heroiczero
@heroiczero
Aug 19 2017 12:38
@RoniqueRicketts congratz on accomplishing your goals :) and Happy Birthday
:cake:
Ronique Ricketts
@RoniqueRicketts
Aug 19 2017 12:41
@heroiczero Oh thank you. It was a lot of work. I even Got a few certificates along the way and now I am on 1.5 Internship ( .5 because the guy is always busy and hasn't given me any real task as yet) I feel so proud of myself. I could hug my own self right now!!!
CamperBot
@camperbot
Aug 19 2017 12:41
roniquericketts sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1627 | @heroiczero |http://www.freecodecamp.com/heroiczero
Kelechi Chinaka
@ke1echi
Aug 19 2017 12:41
:birthday: @RoniqueRicketts
Aleksander Gębicki
@Takumar
Aug 19 2017 12:41
@RoniqueRicketts congratulations, you made big progress with your own work and happy birthday of course :-)
Ronique Ricketts
@RoniqueRicketts
Aug 19 2017 12:41
I should celebrate with cake and liquor for real.
@Takumar thanks man. It was hard but I stuck to it.
CamperBot
@camperbot
Aug 19 2017 12:42
roniquericketts sends brownie points to @takumar :sparkles: :thumbsup: :sparkles:
:star2: 3781 | @takumar |http://www.freecodecamp.com/takumar
Ken Haduch
@khaduch
Aug 19 2017 13:16
@RoniqueRicketts - great news for you! Congratulations on your progress, your internship, and happy birthday too!
Yuguantao
@Yuguantao
Aug 19 2017 13:27
hello everyone
nice to meet you
Ronique Ricketts
@RoniqueRicketts
Aug 19 2017 13:40
@khaduch thanks man. I am so excited for my own self. :)
CamperBot
@camperbot
Aug 19 2017 13:40
roniquericketts sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3218 | @khaduch |http://www.freecodecamp.com/khaduch
Ken Haduch
@khaduch
Aug 19 2017 13:41
@Yuguantao - hello and welcome to freeCodeCamp! Are you just starting the program?
Yuguantao
@Yuguantao
Aug 19 2017 13:41
yes
Ken Haduch
@khaduch
Aug 19 2017 13:42
@Yuguantao - welcome and good luck with your learning! Are you new to coding or have some previous exposure?
Yuguantao
@Yuguantao
Aug 19 2017 13:42
I have a question
Ken Haduch
@khaduch
Aug 19 2017 13:42
@Yuguantao - just ask and people here can try to help...
Yuguantao
@Yuguantao
Aug 19 2017 13:43
Check for Palindromes
what is this question meaning
Ken Haduch
@khaduch
Aug 19 2017 13:46
A palindrome is a word or sentence that has the same spelling if you look at it forward or backward, and in this case, you need to remove any non-alphabetic or non-numeric characters from the string. One of the classic ones is "Madam, I'm Adam", which, if you take out all of the spaces, apostrophes, and change it to all lower case, you have the letters "madamimadam", which will be the same if you reverse it. So you basically have to check that the character strings that they pass to the function that you have to write will either meet that condition or not, and return true or false accordingly.
Yuguantao
@Yuguantao
Aug 19 2017 13:47
Thank you
very much
Ken Haduch
@khaduch
Aug 19 2017 13:49
@Yuguantao - you're welcome.
Stephen James
@sjames1958gm
Aug 19 2017 13:52
@RoniqueRicketts :clap: :+1:
Yuguantao
@Yuguantao
Aug 19 2017 13:55
@RoniqueRicketts Congratulations
Happy Birthday to you
Margaret
@Margaret2
Aug 19 2017 14:12
aww that's awesome :blush: :cake: happy birthday @RoniqueRicketts
Huỳnh Trần Khanh
@khanh2003
Aug 19 2017 15:33
:coffee: :cake:
Ronique Ricketts
@RoniqueRicketts
Aug 19 2017 15:44
@sjames1958gm @Yuguantao @Margaret2 thank you :D
CamperBot
@camperbot
Aug 19 2017 15:44
roniquericketts sends brownie points to @sjames1958gm and @yuguantao and @margaret2 :sparkles: :thumbsup: :sparkles:
:star2: 2888 | @margaret2 |http://www.freecodecamp.com/margaret2
:warning: @yuguantao's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
:star2: 8340 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Ayush Bahuguna
@relentless-coder
Aug 19 2017 16:19
let animal = {
   traits: [],
   name: 'Animal',
   name(value){
     this.name = value
   },
    setTrait(value){
      this.traits.push(value)
  },
  getTrait(){
   console.log(this.traits)
}

}

let dog = Object.create(animal);
dog.name('fluffy');
dog.setTrait('active')

let cat = Object.create(animal);
cat.name('lazy')
cat.setTrait('lazy')


dog.getTrait() // ['active', 'lazy']
cat.getTrait() // ['active', 'lazy']
How do I keep the trait array exclusive to each object that is instantiated?
Pieter Stokkink
@forkerino
Aug 19 2017 16:26
@relentless-coder use new instead of Object.create
and make a constructor out of Animal
Ayush Bahuguna
@relentless-coder
Aug 19 2017 16:29
@forkerino That's what I am trying to avoid.
Pieter Stokkink
@forkerino
Aug 19 2017 16:31
ok. Maybe try Object.assign({}, animal)?
problem is you'll have multiple instances of the functions as well
so it's not a scalable solution
Ayush Bahuguna
@relentless-coder
Aug 19 2017 16:33
I wish javascript had classical inheritance, would have loved using new keyword :D
Abhinav Mishra
@abhinav-m
Aug 19 2017 16:34
you can use new keyword..
although its not exactly classical
Pieter Stokkink
@forkerino
Aug 19 2017 16:34
prototypal inheritance > classical inheritance :laughing:
Abhinav Mishra
@abhinav-m
Aug 19 2017 16:34
nnoooo
:(
Ayush Bahuguna
@relentless-coder
Aug 19 2017 16:35
Object.create looks way beautiful :D delegation looks pretty
LiciniusRex
@hashtagyolo1
Aug 19 2017 17:11
I'm still struggling with Seek and Destroy. Can't seem to work out in my head what I need for my last argument. ANy hints would be greatly appreciated
function destroyer(arg) {
  var array = arg.slice(); //shows primary array
  var tester = []; // after for loop contains arguments to test
  for (var i = 1 ; i < arguments.length ; i++){
    tester.push(arguments[i]);
  }
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
I think it's mostly because I'm really struggling to understand .filter
Stephen James
@sjames1958gm
Aug 19 2017 17:14
@hashtagyolo1
you pass filter a function that will get each array element in turn
if that function returns true for an element that element is put in the result, otherwise it is not.
[1, 2, 3, 4].filter(function(e) { return e % 2 == 0; });
This will result in [2,4] because they are even (remainder of div by 2 is zero)
korzo
@korzo
Aug 19 2017 17:15
@hashtagyolo1 Also you have to extract elements to filter from arguments object
Stephen James
@sjames1958gm
Aug 19 2017 17:16
@korzo That is what is in tester
@hashtagyolo1
tester = Array.prototype.slice(arguments, 1) is another way to get the remaining arguments into an array
korzo
@korzo
Aug 19 2017 17:18
@sjames1958gm Oh, right, I didn't look past for loop
LiciniusRex
@hashtagyolo1
Aug 19 2017 17:18
thanks @sjames1958gm
CamperBot
@camperbot
Aug 19 2017 17:18
hashtagyolo1 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8341 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
LiciniusRex
@hashtagyolo1
Aug 19 2017 17:18
I'll see where I can get from there
Stephen James
@sjames1958gm
Aug 19 2017 17:19
@hashtagyolo1 :+1:
Tai Jones
@taiJones00
Aug 19 2017 17:22
why is my console.log of search val giving me this weird value
 var searchVal = $("#search").val;
    console.log(searchVal);
Stephen James
@sjames1958gm
Aug 19 2017 17:25
@taiJones00 val is a function you have to call it ()
Tai Jones
@taiJones00
Aug 19 2017 17:26
like console.log(searchVal.val); ?
Kelechi Chinaka
@ke1echi
Aug 19 2017 17:30
$("#search").val()
Stephen James
@sjames1958gm
Aug 19 2017 17:31
@taiJones00 $("#search").val this is a function - so searchVal is a reference to the same function.
var searchVal = $("#search").val();
LiciniusRex
@hashtagyolo1
Aug 19 2017 17:36
So I've made it to what I feel must be damn close to the answer, but I can't work out what I'm doing next
function destroyer(arg) {
  var array = arg.slice(); //shows primary array
  var tester = []; // after for loop contains arguments to test
  for (var i = 1 ; i < arguments.length ; i++){
    tester.push(arguments[i]);
  }
  array.filter(function(val){
    console.log(val == tester[1]);
  });
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Stephen James
@sjames1958gm
Aug 19 2017 17:37
@hashtagyolo1 you need to return false if val is in the tester array and true otherwise.
Think of a function that searches an array for a value
LiciniusRex
@hashtagyolo1
Aug 19 2017 17:50
the problem I seem to be having is that when I test val against tester I either get all false or all true depending on what I sak
it's not testing each valer of tester, but rather the array as a whole i think]
LiciniusRex
@hashtagyolo1
Aug 19 2017 17:57
this is the closest I've got.
function destroyer(arg) {
  var array = arg.slice(); //shows primary array
  var tester = []; // after for loop contains arguments to test
  for (var i = 1 ; i < arguments.length ; i++){
    tester.push(arguments[i]);
  }
 console.log(array.filter(function(val){
    return val !== tester[0];
  }));

}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
I can't work out why it's not going through wach location of tester without my specifiying it
Stephen James
@sjames1958gm
Aug 19 2017 17:59
@hashtagyolo1 Consider tester.indexOf(val)
LiciniusRex
@hashtagyolo1
Aug 19 2017 18:02
Gives exactly the same answer. Loses the 2s and nothing else. For some reason it's only reading tester[0]
function destroyer(arg) {
  var array = arg.slice(); //shows primary array
  var tester = []; // after for loop contains arguments to test
  for (var i = 1 ; i < arguments.length ; i++){
    tester.push(arguments[i]);
  }
 console.log(array.filter(function(val){
    return tester.indexOf(val);
  }));

}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Stephen James
@sjames1958gm
Aug 19 2017 18:05
@hashtagyolo1 you need to compare indexOf(val) result to a value -
@hashtagyolo1 indexOf returns -1 if it doesn't find the value
christopher clarke
@chrisdclarke
Aug 19 2017 18:36
goodmorning fellow javascript enthusiasts... greetings from the pacific ocean..... Im having trouble getting any API's to work on codepen... ive added jquery and ajax in the settings but still cant get it.... im trying to add a quote to the box rectangle... but i have tried a few different ways and cant get anything to work..... PLEASE HELP ME IM DROWNING.....
$.getJSON("http://labs.bible.org/api/?passage=random", function(data) {
document.write(JSON.stringify(data))
}
document.getelementbyId("rectangle").innerHTML=data;
soulproprietor
@soulproprietor
Aug 19 2017 18:43
Hello! how can I write a RegEx that matches a whole word? for example I want the word count for the letter "a" to be 2 and not 3 in the following example. Thank you in advance!
function countWords(str) {
  // your code here
  var obj = {};

  if (str.length > 0) {
  var arr = str.split(" ");
  for (var i=0; i<arr.length;i++){
    var kk = arr[i];
  var regEx = new RegExp(kk, 'g');
  obj[arr[i]] = str.match(regEx).length;
  }

  }
return obj;
  }
countWords("ask a bunch get a bunch");
Kelechi Chinaka
@ke1echi
Aug 19 2017 18:49
the syntax is document.getElementById(id) @chrisdclarke
camelCased word @chrisdclarke
Stephen James
@sjames1958gm
Aug 19 2017 18:51
@soulproprietor you can add ^ and $ to the regex
christopher clarke
@chrisdclarke
Aug 19 2017 18:52
@kelechy Thanks....
CamperBot
@camperbot
Aug 19 2017 18:52
chrisdclarke sends brownie points to @kelechy :sparkles: :thumbsup: :sparkles:
:cookie: 301 | @kelechy |http://www.freecodecamp.com/kelechy
Kelechi Chinaka
@ke1echi
Aug 19 2017 18:55
:wave: @sjames1958gm
Stephen James
@sjames1958gm
Aug 19 2017 18:57
@kelechy :wave:
christopher clarke
@chrisdclarke
Aug 19 2017 18:58
https://codepen.io/Clarkie/pen/xLrzzw hey guys.. i still cant get any api's to work....???? any thoughts..?
Joseph
@revisualize
Aug 19 2017 19:09
@chrisdclarke Did you look in the Console?
@chrisdclarke You have a huge error in your Console:
jquery.min.js:4 Mixed Content: The page at 'https://codepen.io/Clarkie/pen/xLrzzw' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://labs.bible.org/api/?passage=random'. This request has been blocked; the content must be served over HTTPS.
Ellyria
@Ellyria
Aug 19 2017 19:10
You might want to use a proxy like this one, @chrisdclarke since you're using the http protocol from the CodePen server, which uses the https protocol.
Joseph
@revisualize
Aug 19 2017 19:11
Or just change to https://labs.bible.org/api/?passage=random
christopher clarke
@chrisdclarke
Aug 19 2017 19:12
oh.. ok.. thanks.. yeah i saw it in the console but i thought by addin ajax in the settings it would allow it... ok thanks alot guys...
Joseph
@revisualize
Aug 19 2017 19:12
Oops. you still get an error with that:
XMLHttpRequest cannot load https://labs.bible.org/api/?passage=random. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://s.codepen.io' is therefore not allowed access.
Ellyria
@Ellyria
Aug 19 2017 19:12
I had to use a proxy with mine.
Joseph
@revisualize
Aug 19 2017 19:13
@Ellyria Thanks.
CamperBot
@camperbot
Aug 19 2017 19:13
revisualize sends brownie points to @ellyria :sparkles: :thumbsup: :sparkles:
:cookie: 498 | @ellyria |http://www.freecodecamp.com/ellyria
christopher clarke
@chrisdclarke
Aug 19 2017 19:13
@revisualize @Ellyria thanks... ill try out the proxy.... how do you use it...?
CamperBot
@camperbot
Aug 19 2017 19:13
chrisdclarke sends brownie points to @revisualize and @ellyria :sparkles: :thumbsup: :sparkles:
:cookie: 499 | @ellyria |http://www.freecodecamp.com/ellyria
:star2: 4444 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Aug 19 2017 19:13
WOOT!
Ellyria
@Ellyria
Aug 19 2017 19:13
You just put its URL before your URL in the script.
Joseph
@revisualize
Aug 19 2017 19:14
4444 brownie points on my 333rd day streak!
Ellyria
@Ellyria
Aug 19 2017 19:14
So: https://CORS-Anywhere.HerokuApp.com/http://somewhere
christopher clarke
@chrisdclarke
Aug 19 2017 19:14
cool.. thanks...
Stephen James
@sjames1958gm
Aug 19 2017 19:15
@revisualize :+1:
Ellyria
@Ellyria
Aug 19 2017 19:15
It also works the other way around. Like if you wanted to run an API from your local machine, which uses the http protocol, then you could use the same address, but swap out the http and https.
Tai Jones
@taiJones00
Aug 19 2017 19:15
how do I not have the box get left behind when it translates up
Ellyria
@Ellyria
Aug 19 2017 19:15
Oh, I can't look at the Wikipedia one. I'm on that one.
Tai Jones
@taiJones00
Aug 19 2017 19:15
it's the relevant search box that's left behind on desktop
it's okay
christopher clarke
@chrisdclarke
Aug 19 2017 19:18
does data that comes back from an api come back in the variable data? or do you assign it a random variable?
Tai Jones
@taiJones00
Aug 19 2017 19:19
data that comes back from an api I usually have to assign to a variable to improve readability
var name = json.name;
    var country = json.sys.country;
    var icon = json.weather[0].icon;
I definitely store it in a variable.
kumquatfelafel
@kumquatfelafel
Aug 19 2017 19:21
It will be in data, assuming you called parameter of function argument in getJSON data. @chrisdclarke
Ellyria
@Ellyria
Aug 19 2017 19:22
Ah, that makes sense. I didn't use jQuery, so mine is a bit different.
kumquatfelafel
@kumquatfelafel
Aug 19 2017 19:22
If you call it something else, like json :point_up: August 19, 2017 12:19 PM then it will be that instead
Ellyria
@Ellyria
Aug 19 2017 19:24
It looks like you're missing the (document).ready statement, @chrisdclarke, or is that not needed in jQuery?
christopher clarke
@chrisdclarke
Aug 19 2017 19:26
well im not sure,,, im finding with codepen somethings are required that normally arent... i should put it in...
Ellyria
@Ellyria
Aug 19 2017 19:27
Thanks, @kumquatfelafel! It looks like it's needed.
CamperBot
@camperbot
Aug 19 2017 19:27
ellyria sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 619 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Ellyria
@Ellyria
Aug 19 2017 19:29
You also don't want anything but the contents of the body element in that far left pane in CodePen, @chrisdclarke. The stuff that goes into the head element should be added in the Stuff for <head> section in the Settings of the pen.
Ellyria @Ellyria does not like CodePen and considers it a necessary evil.
christopher clarke
@chrisdclarke
Aug 19 2017 19:31
ok thanks... the jquery page says "A page can't be manipulated safely until the document is "ready." jQuery detects this state of readiness for you. Code included inside $( document ).ready()".....
definately a necessary evil....
is there anything better i wonder?
Stephen James
@sjames1958gm
Aug 19 2017 19:32
@chrisdclarke codepen wraps your code in a document.onload function
Ellyria
@Ellyria
Aug 19 2017 19:33
I didn't realize that. That's cool.
Stephen James
@sjames1958gm
Aug 19 2017 19:33
Oh, maybe not - that might be jsfiddle
christopher clarke
@chrisdclarke
Aug 19 2017 19:33
so document ready isnt needed?
Ellyria
@Ellyria
Aug 19 2017 19:34
There's repl.it, but I'm not sure that's any better.
kumquatfelafel
@kumquatfelafel
Aug 19 2017 19:34
You can, potentially, avoid using codepen. I believe you can test your code without an internet connection even by writing html, script, css in IDE, e.g. and opening the html on localhost blah blah blah on chrome.
Or summat
Haven't really done something like that in a while

I believe you can test your code without an internet connection

Mind you, this wouldn't work with api calls, e.g.

Ellyria
@Ellyria
Aug 19 2017 19:36
Yep, I do it all the time. But if you want to share it, and you have to for these projects, it has to go online. Also, I'm pretty sure the project requires that it's on CodePen. I could be wrong on that, though.
kumquatfelafel
@kumquatfelafel
Aug 19 2017 19:36
FCC does I think, yeah.
Ellyria
@Ellyria
Aug 19 2017 19:36
Sure it does. I do all of my API coding on my local computer before I ever put it online.
christopher clarke
@chrisdclarke
Aug 19 2017 19:37
$.ajax('https://CORS-Anywhere.HerokuApp.com/http://labs.bible.org/api/?passage=random', { success:
function(response){
document.console(data);
}}); so with this code, in the console i get the error back "An iframe which has both allow-scripts and allow-same-origin for its sandbox attribute can remove its sandboxing.""""
kumquatfelafel
@kumquatfelafel
Aug 19 2017 19:38
@Ellyria Sorry, wasn't clear there. Meant in the sense of "someone else's api that you don't have"
(since in that case you'd need internet connection to actually make request, etc.)
Ellyria
@Ellyria
Aug 19 2017 19:38
Ah, true. In that case, they have to send you the code and then you put it in a file on your computer and run it. All very awkward and slow as compared to these CodePen type places.
kumquatfelafel
@kumquatfelafel
Aug 19 2017 19:39
agreed
Ellyria
@Ellyria
Aug 19 2017 19:39
I did have fun creating my very own API, though, and accessing that from my computer. It helped me to understand how it works.
That's okay. I totally misunderstood, though, so sorry for any confusion from my end!
kumquatfelafel
@kumquatfelafel
Aug 19 2017 19:39

Well... we're both very sorry. And we should be.

:p ;)

Ellyria
@Ellyria
Aug 19 2017 19:39
Yeah, what's with that iframe error?
Well, before you can debug, you need to clean up that left frame, @chrisdclarke.
christopher clarke
@chrisdclarke
Aug 19 2017 19:40
ok..
Ellyria
@Ellyria
Aug 19 2017 19:40
You never know if some of that is causing an issue.
Also, I've seen it where people have all sorts of odd errors and then it turns out it was the version of jQuery or Bootstrap or whatever else they were using. Are you using the correct version?
christopher clarke
@chrisdclarke
Aug 19 2017 19:41
yeah... your saying that the top calls arent needed because theyre done in the settings? is that correct?
ill check the versions.. good idea...
kumquatfelafel
@kumquatfelafel
Aug 19 2017 19:43
document.console(data);
This strikes me as a bit odd. What are you trying to do here?
christopher clarke
@chrisdclarke
Aug 19 2017 19:45
im trying to display the data from the api on the console just to test to see if its working...
Ellyria
@Ellyria
Aug 19 2017 19:45
All elements, except those which are inside the body element, do not belong in the left frame of CodePen. All the code inside the head element can be put into the settings.
The body tags also don't go there. Just the contents of the body, just like you did with the CSS where you just have the CSS rules and not the style element tags, and the JavaScript pane where you just have the JavaScript and not the script tags.
christopher clarke
@chrisdclarke
Aug 19 2017 19:47
@Ellyria ok i get you .. thanks... and the version 3.2.1 jquery seems to support ajax calls....
CamperBot
@camperbot
Aug 19 2017 19:47
chrisdclarke sends brownie points to @ellyria :sparkles: :thumbsup: :sparkles:
:warning: chrisdclarke already gave ellyria points
christopher clarke
@chrisdclarke
Aug 19 2017 19:47
@kumquatfelafel is data the correct variable?
Ellyria
@Ellyria
Aug 19 2017 19:48
Does anybody know if that's a good version to use? I passed the jQuery portion of freeCodeCamp a while back, but have happily forgotten most of it and haven't used it, so I'm not very good at knowing what you ought to be using.
kumquatfelafel
@kumquatfelafel
Aug 19 2017 19:48
@chrisdclarke data is not the correct variable.
function(correctVariable) {
   //do stuff with correctVariable
}
In your case, you have
function(response) {
  //so do stuff with response
}
christopher clarke
@chrisdclarke
Aug 19 2017 19:50
k thanks....
kumquatfelafel
@kumquatfelafel
Aug 19 2017 19:50
The parameter is what will hold the ... can't think of word... but that's what it will hold :o
:point_up: super helpful explanation :p
(sorry, was in airport/on plane for 15 hours yesterday) :laughing:
Ellyria
@Ellyria
Aug 19 2017 19:53
Good catch!
Does that innerHTML line need to be reenabled?
christopher clarke
@chrisdclarke
Aug 19 2017 19:54
lol actually thats what i needed to ktnow ... so do responses from an api always have the variable response, or is it assigned to whatever i put in the function...
kumquatfelafel
@kumquatfelafel
Aug 19 2017 19:55
(though yeah, also, I would use console.log()... unless there's some ajax thing I'm unaware of???)
@chrisdclarke whatever you name that variable (parameter), be it response or widdershinsVonHooklum, the name you give it will be the one used inside the function itself. It may be called "response" or something along those lines by convention, but not sure.
Ellyria
@Ellyria
Aug 19 2017 19:56
This page goes into how the response is referred to, but I'm not sure if it's handled differently in jQuery: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseText
Guderian Raborg
@hypercuber
Aug 19 2017 19:58
How do I make circles/ dots inside the big circle here?
Ellyria
@Ellyria
Aug 19 2017 20:01
I'm not sure, @hypercuber, but Khan Academy has an excellent section on Canvas.
christopher clarke
@chrisdclarke
Aug 19 2017 20:03
$.ajax('https://CORS-Anywhere.HerokuApp.com/http://labs.bible.org/api/?passage=random', { success:
function(response){
document.console.log(response);
}}); now i get a type error.. document.console is undefined
Ellyria
@Ellyria
Aug 19 2017 20:06
That's good. Undefined means a variable has been declared, but has not yet been assigned a value.
You need to assign a value to the response that you're getting from the server.
kumquatfelafel
@kumquatfelafel
Aug 19 2017 20:06
@chrisdclarke *console.log(response)
christopher clarke
@chrisdclarke
Aug 19 2017 20:07
no document....? k thanks again
kefah elhelou
@kefelhelou
Aug 19 2017 20:09
cannot save package.json file, what will the problem be?? access denied
christopher clarke
@chrisdclarke
Aug 19 2017 20:09
success thank you so much... Ellyria and kumquatfelafel.... finally working...
Ellyria
@Ellyria
Aug 19 2017 20:11
Yay!
How are you trying to save it, @kefelhelou?
kefah elhelou
@kefelhelou
Aug 19 2017 20:12
@Ellyria I am trying to add "start" : "src/server.js" in the script section
Guderian Raborg
@hypercuber
Aug 19 2017 20:13
@Ellyria Thanks. Will check it out. It is nice to have more resources.
CamperBot
@camperbot
Aug 19 2017 20:13
hypercuber sends brownie points to @ellyria :sparkles: :thumbsup: :sparkles:
:cookie: 500 | @ellyria |http://www.freecodecamp.com/ellyria
Ellyria
@Ellyria
Aug 19 2017 20:13
Is that a pair of values for an Object, @kefelhelou?
I'm only part-way through their Canvas class, @hypercuber, and it's really well done.
kefah elhelou
@kefelhelou
Aug 19 2017 20:14
so I can type node server.js in terminal without putting the folder
Ellyria
@Ellyria
Aug 19 2017 20:14
Ah, I don't know node.js.
kefah elhelou
@kefelhelou
Aug 19 2017 20:15
ok thanks :) for trying to help @Ellyria
CamperBot
@camperbot
Aug 19 2017 20:15
kefelhelou sends brownie points to @ellyria :sparkles: :thumbsup: :sparkles:
:cookie: 501 | @ellyria |http://www.freecodecamp.com/ellyria
Ellyria
@Ellyria
Aug 19 2017 20:16
Any time, and good luck!
Nick Cleary
@Hijerboa
Aug 19 2017 20:16
Does anyone have any idea why the fromCharCode() function in my algorithim doesn't appear to be working whenever a variable is used?
function fearNotLetter(str) {
  var toReturn;
  for(var i=0; i<str.length; i++){
    if(str.charCodeAt((i + 1)) !== (str.charCodeAt(i) + 1)){
      toReturn = String.fromCharCode(i);
      console.log(toReturn);
    }else {
      toReturn = undefined;
    }
  }
  return toReturn;
}
kumquatfelafel
@kumquatfelafel
Aug 19 2017 20:17
@Hijerboa could you link to this challenge? Don't remember what the goal is.
Nick Cleary
@Hijerboa
Aug 19 2017 20:17
kumquatfelafel
@kumquatfelafel
Aug 19 2017 20:22
@Hijerboa what is the value of i?
Nick Cleary
@Hijerboa
Aug 19 2017 20:22
its modified by the for loop
kumquatfelafel
@kumquatfelafel
Aug 19 2017 20:23
Let's throw another console.log in there, to take a look
Nick Cleary
@Hijerboa
Aug 19 2017 20:24
oh....
I feel dumb now
It's due to the fact that i is less than 65 which is when the unicode characters begin... am I correct?
thus... its necessary to use charCodeAt in order to find a character code in order to output...
thanks @kumquatfelafel
CamperBot
@camperbot
Aug 19 2017 20:27
hijerboa sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 620 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
kumquatfelafel
@kumquatfelafel
Aug 19 2017 20:27

Maybe?

http://www.asciitable.com

i holds your spot in loop, but it doesn't, e.g. give you char code of 'g', e.g.

Nick Cleary
@Hijerboa
Aug 19 2017 20:28
@kumquatfelafel yeah im pretty sure that's the issue... the value of i isn't high enough for it to understand
kumquatfelafel
@kumquatfelafel
Aug 19 2017 20:28
Though yeah, you don't want to change i to 65, let's say, to compensate.
Nick Cleary
@Hijerboa
Aug 19 2017 20:29
yeah.... I'm going to try something and report back
kumquatfelafel
@kumquatfelafel
Aug 19 2017 20:29
aye:)
@Hijerboa Just... if things come out wrong in your attempt, be aware that there may (or may not) be other problems with your code, so don't immediately assume your attempted fix was incorrect. Some console.log'ing may be in order ;)
Nick Cleary
@Hijerboa
Aug 19 2017 20:34
@kumquatfelafel haha im figuring that out now :P
does anybody know how i can put information in these individual tabs
Gersho
@Gersho
Aug 19 2017 23:01
well there's like...no code at all
Tai Jones
@taiJones00
Aug 19 2017 23:02
okay well I put text in between the li tags and it was just added as part of the tab
Gersho
@Gersho
Aug 19 2017 23:05
honestly i have no idea, you made an horizontal list, but i don't think the html considers it as different (pages) like you're hoping
i guess you could have a <div> under that and make it's content change via js based on what 'page' you asked for, but i think it would probably better to reword your html some other way
you should try to find a pen with similar design and look how they did it
Tai Jones
@taiJones00
Aug 19 2017 23:09
thank you @Gersho
CamperBot
@camperbot
Aug 19 2017 23:09
taijones00 sends brownie points to @gersho :sparkles: :thumbsup: :sparkles:
:cookie: 340 | @gersho |http://www.freecodecamp.com/gersho
Moisés Man
@moigithub
Aug 19 2017 23:10
"tab panes" missing