These are chat archives for FreeCodeCamp/HelpFrontEnd

27th
Dec 2017
Johnny
@jtan3
Dec 27 2017 00:06
@DavidBelmares https://regexr.com/ you can use this to test out your regex
David Belmares
@DavidBelmares
Dec 27 2017 00:08
@jtan3 thanks
CamperBot
@camperbot
Dec 27 2017 00:08
davidbelmares sends brownie points to @jtan3 :sparkles: :thumbsup: :sparkles:
:cookie: 466 | @jtan3 |http://www.freecodecamp.org/jtan3
David Belmares
@DavidBelmares
Dec 27 2017 00:19
Ugh, my regex is the way I want it but my code still doesn't pass
Kevin Kindorf
@kkindorf
Dec 27 2017 00:23
@DavidBelmares are you working on a fcc challenge?
David Belmares
@DavidBelmares
Dec 27 2017 00:23
yes
Kevin Kindorf
@kkindorf
Dec 27 2017 00:23
which one?
David Belmares
@DavidBelmares
Dec 27 2017 00:23
The palindrome challenge
Kevin Kindorf
@kkindorf
Dec 27 2017 00:29
@DavidBelmares your missing capital letters
your not checking for that
David Belmares
@DavidBelmares
Dec 27 2017 00:29
I got rid of uppercases in the previous line
Kevin Kindorf
@kkindorf
Dec 27 2017 00:29
you could use \W or this /\W/ or /[^A-Za-z0-9_]/
\W catches all alpha numeric characters
David Belmares
@DavidBelmares
Dec 27 2017 00:31
can i do /\^W?
Kevin Kindorf
@kkindorf
Dec 27 2017 00:32
you can use \W or this [^A-Za-z0-9_] they both do the same
David Belmares
@DavidBelmares
Dec 27 2017 00:33
must be something else with my code, no matter how the regex is, it won't pass
image.png
Kevin Kindorf
@kkindorf
Dec 27 2017 00:33
have you looked at the test strings that they're testing your function against?
David Belmares
@DavidBelmares
Dec 27 2017 00:34
yes
Kevin Kindorf
@kkindorf
Dec 27 2017 00:34
what does reverseStr look like when you console log it
David Belmares
@DavidBelmares
Dec 27 2017 00:35
well I can't really console log anything because it doesn't show in the output :(
Kevin Kindorf
@kkindorf
Dec 27 2017 00:35
your using split but I don't think your turning reverseStr into a string yet
David Belmares
@DavidBelmares
Dec 27 2017 00:35
yeah it wasn't working when i turned it back into a string
Kevin Kindorf
@kkindorf
Dec 27 2017 00:36
your also not checking if the string they're testing your palindrome with does not match
you need an if else statement in there
David Belmares
@DavidBelmares
Dec 27 2017 00:36
I used a single line return statement instead of an if statement
yep still no output when I make it into a string
and console log it
Kevin Kindorf
@kkindorf
Dec 27 2017 00:37
can you paste your code again
David Belmares
@DavidBelmares
Dec 27 2017 00:37
image.png
Kevin Kindorf
@kkindorf
Dec 27 2017 00:38
you can use back ticks like this
three back ticks on top of first line three back ticks below last line of your code
I can't copy and paste an image :-)
David Belmares
@DavidBelmares
Dec 27 2017 00:39
oh
function palindrome(str) {

  var strWithoutSpecial = str;
  var strWSandLower = strWithoutSpecial.toLowerCase();
  var toReplace = /[^A-Za-z0-9_]/g;
  strWSandLower = strWSandLower.replace(toReplace, "");  
  strWSandLower = strWSandLower.split("");


  var reverseStr = strWSandLower.reverse("");
  reverseStr = reverseStr.join("");
  console.log(reverseStr);

  return reverseStr == strWSandLower;

}



palindrome("eye");
Kevin Kindorf
@kkindorf
Dec 27 2017 00:39
thanks
Kevin Kindorf
@kkindorf
Dec 27 2017 00:46
@DavidBelmares try running this in the console
function palindrome(str) {

  var strWithoutSpecial = str;
  var strWSandLower = strWithoutSpecial.toLowerCase();
  var toReplace = /[^A-Za-z0-9_]/g;
  strWSandLower = strWSandLower.replace(toReplace, "");  
  strWSandLower = strWSandLower.split("");


  var reverseStr = strWSandLower.reverse("");
  reverseStr = reverseStr.join("");
  console.log(reverseStr);
  console.log(strWSandLower);
//   return reverseStr == strWSandLower;

}

undefined
palindrome("eye")
strings and arrays are not the same thing
so I dont you'll ever get true
David Belmares
@DavidBelmares
Dec 27 2017 00:48
nothing was output
Kevin Kindorf
@kkindorf
Dec 27 2017 00:48
use your browser's console
your developer tools
David Belmares
@DavidBelmares
Dec 27 2017 00:48
oh
i'm stupid
Kevin Kindorf
@kkindorf
Dec 27 2017 00:49
all your tests pass when its false but your function is always returning false because your testing a string against an array
David Belmares
@DavidBelmares
Dec 27 2017 00:49
oh i see now
Kevin Kindorf
@kkindorf
Dec 27 2017 00:49
I think you just need a join function on the strWSandLower
then uncomment your return statement
Kevin Kindorf
@kkindorf
Dec 27 2017 00:56
there's another thing wrong with your code
David Belmares
@DavidBelmares
Dec 27 2017 00:56
what is it
Kevin Kindorf
@kkindorf
Dec 27 2017 01:08
your comparing the same string
so now it's always true
David Belmares
@DavidBelmares
Dec 27 2017 01:09
hmm
Kevin Kindorf
@kkindorf
Dec 27 2017 01:10
I would go back and review your code a little more closely your extremely close but I think your variables are getting a little mixed up
David Belmares
@DavidBelmares
Dec 27 2017 01:10
yes
Kevin Kindorf
@kkindorf
Dec 27 2017 01:13
it may be easier to repeat the same steps up to using your regex for both strings but only reverse the new string and not the original string that's passed to the function
David Belmares
@DavidBelmares
Dec 27 2017 01:14
yeah i'm going to rewrite the entire thing now
Kevin Kindorf
@kkindorf
Dec 27 2017 01:15
I think you've misplaced one of your strings when your declaring your variables so your using two different variables but they both have the same string
@DavidBelmares let me know how it goes!
David Belmares
@DavidBelmares
Dec 27 2017 01:15
I will, thanks for all your help so far
Tom
@moT01
Dec 27 2017 01:18
use his @name and say thanks @DavidBelmares
CamperBot
@camperbot
Dec 27 2017 01:18
mot01 sends brownie points to @name and @davidbelmares :sparkles: :thumbsup: :sparkles:
:cookie: 234 | @davidbelmares |http://www.freecodecamp.org/davidbelmares
api offline
Tom
@moT01
Dec 27 2017 01:18
gives cookies
David Belmares
@DavidBelmares
Dec 27 2017 01:18
@kkindorf thanks
CamperBot
@camperbot
Dec 27 2017 01:18
davidbelmares sends brownie points to @kkindorf :sparkles: :thumbsup: :sparkles:
:cookie: 342 | @kkindorf |http://www.freecodecamp.org/kkindorf
David Belmares
@DavidBelmares
Dec 27 2017 01:18
yee
Tom
@moT01
Dec 27 2017 01:19
if you didnt already know
David Belmares
@DavidBelmares
Dec 27 2017 01:19
or brownie points
yeah i forgot
David Belmares
@DavidBelmares
Dec 27 2017 01:27
@kkindorf yay I coded my own working solution, thanks again for your help
CamperBot
@camperbot
Dec 27 2017 01:27
davidbelmares sends brownie points to @kkindorf :sparkles: :thumbsup: :sparkles:
api offline
David Belmares
@DavidBelmares
Dec 27 2017 01:27
image.png

```function palindrome(str) {

var originalString = str; originalString = originalString.toLowerCase();
var reversedStr = str.split(""); reversedStr = reversedStr.reverse(); reversedStr = reversedStr.join(""); reversedStr = reversedStr.toLowerCase();

originalString = originalString.replace(/[^a-z0-9]/g, "");
reversedStr = reversedStr.replace(/[^a-z0-9]/g, "");

return originalString == reversedStr;
}

palindrome("eyeE$@");

```function palindrome(str) {

var originalString = str; originalString = originalString.toLowerCase();
var reversedStr = str.split(""); reversedStr = reversedStr.reverse(); reversedStr = reversedStr.join(""); reversedStr = reversedStr.toLowerCase();

originalString = originalString.replace(/[^a-z0-9]/g, "");
reversedStr = reversedStr.replace(/[^a-z0-9]/g, "");

return originalString == reversedStr;
}

palindrome("eyeE$@");```

oh well
Ken Haduch
@khaduch
Dec 27 2017 01:46
@DavidBelmares - put the backticks on separate lines at the beginning and end. YOu can go and edit the post for a few minutes, but you might have missed the time window for that.
David Belmares
@DavidBelmares
Dec 27 2017 01:47
i tried that the first time but it sent the message instead of making a new line
Kris Baillargeon
@krisb1220
Dec 27 2017 02:00
function palindrome(str) {

  var originalString = str; originalString = originalString.toLowerCase();
  var reversedStr = str.split(""); reversedStr = reversedStr.reverse(); reversedStr = reversedStr.join(""); reversedStr = reversedStr.toLowerCase();

  originalString = originalString.replace(/[^a-z0-9]/g, "");
  reversedStr = reversedStr.replace(/[^a-z0-9]/g, "");

  return originalString == reversedStr;
}



palindrome("eyeE$@");
@DavidBelmares instead of doing all that extra stuff, try to return a "true" or "false" depending on the condition
David Belmares
@DavidBelmares
Dec 27 2017 02:03
I probably could but that would be harder to read
Kris Baillargeon
@krisb1220
Dec 27 2017 02:05
@DavidBelmares use a ternary
4 == 2 ? expressionTrue : expressionFalse ;
Christopher Brown
@ChrisBrownie55
Dec 27 2017 02:11
@DavidBelmares you should be removing the extraneous characters before splitting and reversing. And just as well, originalString = str; originalString = originalString.toLowerCase() is redundant, just do originalString = str.toLowerCase(), same goes for reversedStr, and besides that you don't need the originalString variable, just rename the variable that the function takes to originalString.
Also a major erroring you're making @DavidBelmares is that you're doing reversedStr = str.split(""), because if you look above it you made originalStr lowercase whereas reversedStr will not be lowercase
David Belmares
@DavidBelmares
Dec 27 2017 02:43
I see where you're coming from as for the redundant code, but about the lowercase problem, I did make both lowercase
Christopher Brown
@ChrisBrownie55
Dec 27 2017 02:47
@DavidBelmares Oh, yeah my bad, it was just off to the side of the screen, had to scroll all the way so I missed it.
David Belmares
@DavidBelmares
Dec 27 2017 02:47
oh haha
Kevin Kindorf
@kkindorf
Dec 27 2017 02:59
@DavidBelmares nice well done. On to the next!
Joseph A. Sangine
@HTML-joe
Dec 27 2017 03:10
anyone know why the text size is unaffected after i change the CSS in this codepen?
it is under the class a in the css
the text aligns to the center but for some odd reason the size wont increase
iso
@iso1048
Dec 27 2017 03:11
@HTML-joe font-size not text-size
Shakil Ahmed
@iAmShakil
Dec 27 2017 04:28
Hello. How can I start contributing to open source projects for fcc without taking the code challenges
more specifically, how can I skip the entry level tutorials?
Ken Haduch
@khaduch
Dec 27 2017 04:50
@iAmShakil - if you go to the Map on the navbar, you can see all of the lessons / challenges and which ones are required and which are optional. You can just start at any point if you need to skip the early lessons and can do the required ones, then go for it!
linkin-park
@linkin-park
Dec 27 2017 04:52
hi is anyone interested in a project - full stack, please let me know.
we are looking for someone who is passionate about js/node/react/(sql and nosql)/dedicated
has done some good projects on the past/current
DM me
code pair
linkin-park
@linkin-park
Dec 27 2017 04:58
minimum criteria : need to know javascript ,
level: intermediate to advanced.
cyoung045
@cyoung045
Dec 27 2017 05:55
can someone help me figure out how to center an image in a bootstrap "jumbotron" image? No matter what I do the image keeps veering right. I have added a class of "img-responsive" to the image itself, but it's still too large for the screen.
abraham anak agung
@padunk
Dec 27 2017 05:56
@cyoung045 you hv codepen link? or share your code here
abraham anak agung
@padunk
Dec 27 2017 05:59
@cyoung045 you use BS 4. img-responsive is for BS3
cyoung045
@cyoung045
Dec 27 2017 05:59
Is there a similar code for BS4?
abraham anak agung
@padunk
Dec 27 2017 05:59
use img-fluid
cyoung045
@cyoung045
Dec 27 2017 06:00
ok, hang on
wow, that works
thanks
abraham anak agung
@padunk
Dec 27 2017 06:00
@cyoung045 if you don't know BS4 yet, use BS3. they have different naming
cyoung045
@cyoung045
Dec 27 2017 06:01
ha, will do.
any ideas how to insert a caption into that image?
abraham anak agung
@padunk
Dec 27 2017 06:03
you can use <figcaption> element or just use simple text tag either p, h1, h2
cyoung045
@cyoung045
Dec 27 2017 06:06
ok
Peter
@zzt1413
Dec 27 2017 06:46
function ss(){
this.draw=function(){
...
}
this.move=function(){
this.draw();
...
}
direct this.move() is ok
but when i run
setinterval(this.move,20);
it told me this.draw() is not a function why
}
Nick Karnik
@theoutlander
Dec 27 2017 06:50
@zzt1413 can you post complete source and error
Markus Kiili
@Masd925
Dec 27 2017 06:51
@zzt1413 You pass this.move into setInterval. It is not a method anymore, just a function. Therefore this points to the window, when it is executed.
Nick Karnik
@theoutlander
Dec 27 2017 06:52
oh this,draw … i was confused … @Masd925 is right
Peter
@zzt1413
Dec 27 2017 06:52
so i
Markus Kiili
@Masd925
Dec 27 2017 06:53
@zzt1413 Something like setInterval(this.move.bind(this),20); could work.
Peter
@zzt1413
Dec 27 2017 06:54
thanks i go to try
Nick Karnik
@theoutlander
Dec 27 2017 06:54
if you’re doing this within a class, you can also use fat arrow functions so it references the class instance
Peter
@zzt1413
Dec 27 2017 06:57
ok work it out
primuscovenant
@primuscovenant
Dec 27 2017 12:09
@heroiczero thx
CamperBot
@camperbot
Dec 27 2017 12:09
primuscovenant sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 2118 | @heroiczero |http://www.freecodecamp.org/heroiczero
Deepak Manjunath
@Deepak2322
Dec 27 2017 14:13
<button class="search-btn tab-btn" data-content="search-view" on-click="toggle">btn1</button>
<button class="customize-btn tab-btn" data-content="customize-view" on-click="toggle">btn2</button>

<div class="auto-complete-view" id="search-view"></div>
<div class="customize-view" id="customize-view"></div>

<script>
var tabBtn = this.shadowRoot.querySelectorAll('.tab-btn');
var customizeView = this.shadowRoot.getElementById('customize-view');
var searchView = this.shadowRoot.getElementById('search-view');
var closeBtn = this.shadowRoot.getElementById('closeBtn');
tabBtn.forEach(btn => {
btn.addEventListener('click', function(e){
    if(e.target.dataset.content === 'search-view') {
    this.classList.toggle('active');
    searchView.style.display = "block";
    customizeView.style.display = "none";
    } else if (e.target.dataset.content === 'customize-view') {
    this.classList.toggle('active');
    customizeView.style.display = "block";
    searchView.style.display = "none";
    } else {
    this.classList.removeClass('active');
    }
});

closeBtn.addEventListener('click', function(e) {
    tabBtn.classList.remove('active');
})
})
</script>
i am toggling active class, but i am not sure how do i remove active class when i click on other button and also when i click on close button it throws an error in console “Cannot read property ‘remove’ of undefined”
Tom
@moT01
Dec 27 2017 14:49
@Deepak2322 perhaps remove that class from all the buttons on a click
Nick Karnik
@theoutlander
Dec 27 2017 14:49
@Deepak2322 use element.classList.remove(‘classname’)
Look at versions you want to support here https://caniuse.com/#search=classlist
and then if you need to support legacy, you can use alternate syntax ….
Deepak Manjunath
@Deepak2322
Dec 27 2017 14:53
@moT01 i also have to toggle
Tom
@moT01
Dec 27 2017 14:54
k
so remove that class on all the buttons - then do the toggle like you have it
or i was thinking making a lastClicked variable - and set it in the click function to the element
Nick Karnik
@theoutlander
Dec 27 2017 14:55
@Deepak2322 you can use element.classList.toggle(‘classname’)
Tom
@moT01
Dec 27 2017 14:56
but what element would it be for
Nick Karnik
@theoutlander
Dec 27 2017 14:57
element you’re trying to toggle …. not sure why that question?
Tom
@moT01
Dec 27 2017 14:57
cause he wants to remove the class from an element other than the one he clicked
Nick Karnik
@theoutlander
Dec 27 2017 14:58
as long he has a reference to that element, he can use those methods
Tom
@moT01
Dec 27 2017 14:59
so wheres the reference to the element
Nick Karnik
@theoutlander
Dec 27 2017 15:00
oh … i misread the question … it is more about how to get a reference to the element that was clicked!
Let me check
@Deepak2322 can you post a working codepen ?
Deepak Manjunath
@Deepak2322
Dec 27 2017 15:04
yes
Nick Karnik
@theoutlander
Dec 27 2017 15:04
I started here but there are too many errors
specifically not sure what this.shadowRoot is
Deepak Manjunath
@Deepak2322
Dec 27 2017 15:05
working on webcomponents
Deepak Manjunath
@Deepak2322
Dec 27 2017 15:22
i am sorry there are too many things wired up using css , posting pen would take a lot of time, i basically want remove the active class on the previous button which has some border if its active.
Tom
@moT01
Dec 27 2017 15:22
you should be able to make a pen that just illustrates the problem
Deepak Manjunath
@Deepak2322
Dec 27 2017 15:22
ok
Nick Karnik
@theoutlander
Dec 27 2017 15:27
:+1:
border is not removed on click of other button @theoutlander @moT01
i came up with something like that
Deepak Manjunath
@Deepak2322
Dec 27 2017 15:33
@moT01 i also have to remove active class on toggle
dinesh
@1532j0004kg
Dec 27 2017 15:34
hi.
Tom
@moT01
Dec 27 2017 15:34
so take out the if statement
Nick Karnik
@theoutlander
Dec 27 2017 15:34
so when you click one button, the other is reset ?
Tom
@moT01
Dec 27 2017 15:34
and change the add to toggle
Nick Karnik
@theoutlander
Dec 27 2017 15:34
or are they independent?
so i just want to toggle state of the same button
Tom
@moT01
Dec 27 2017 15:35
the other is reset - or the class is removed
wait - what are you trying to accomplish? maybe i am misunderstanding
Nick Karnik
@theoutlander
Dec 27 2017 15:36
simply adding this.classList.toggle('active’) in your callback will toggle the same button
if you want to toggle both, you need to track them in an arr
Tom
@moT01
Dec 27 2017 15:37
i resaved - is that more like it?
Nick Karnik
@theoutlander
Dec 27 2017 15:40
play with it … i’m confused about the use case
Deepak Manjunath
@Deepak2322
Dec 27 2017 15:40
should i add an id to the button ?
to get reference
Chris Rutherford
@cjrutherford
Dec 27 2017 15:41
has anyone had issues doing boolean comparison with date objects? Anyone have a good tutorial?
Deepak Manjunath
@Deepak2322
Dec 27 2017 15:44
thanks @moT01 @theoutlander
CamperBot
@camperbot
Dec 27 2017 15:44
deepak2322 sends brownie points to @mot01 and @theoutlander :sparkles: :thumbsup: :sparkles:
api offline
:cookie: 943 | @mot01 |http://www.freecodecamp.org/mot01
Shubham Sharma
@shubham1604
Dec 27 2017 16:08
Hey guys
I am using a tweet button
and I need to dnamically cahnge contents of my tweet
how do i do that?
The conventional method of getelementbyid doesnt work with the tweet button due to some reason (I know the reason)
dynamically change*
Xarri Jorge
@xarrijorge
Dec 27 2017 16:11
hello folks, For some reason, all my api calls are having CORS errors. I just can't wrap my head around it. Help greatly needed
Shubham Sharma
@shubham1604
Dec 27 2017 16:12
@kodinglife ou cant make cross domain calls for securit reasons
You*
VaseJS
@VaseJS
Dec 27 2017 16:13
@kodinglife that happens. I had the same issue. let me grab my resource that fixed it. brb
VaseJS
@VaseJS
Dec 27 2017 16:22

@kodinglife "Chrome my block continued non-https request to your browser so your code may work one day and not a week later.

By adding https://cors-anywhere.herokuapp.com, it solve the issue.
Everyone should try it.
"

@kodinglife you add the entire line to the url. but you can also go to the site for more info. it fixed my issues
Ken Haduch
@khaduch
Dec 27 2017 16:37
@cjrutherford - what are you trying to do with Date objects? Sometimes working with date/time info is tricky...
Chris Rutherford
@cjrutherford
Dec 27 2017 17:01
I'm seeing that @khaduch got it working though. I was trying to filter objects from my array by date.....
Ken Haduch
@khaduch
Dec 27 2017 17:05
@cjrutherford - I would convert the date to the millisecond value and use that to do filtering, I think...
Chris Rutherford
@cjrutherford
Dec 27 2017 17:06
yeah.... I did this:
.map(x => x.filter(r => {
        let dbTime = new Date(r.createdAt);
        let lastThirty = Date.now() - 30*24*60*60*1000;
        console.log(`Created At ${r.createdAt}, dbtime: ${dbTime.getTime()}`);
        console.log(`Last Thirty ${lastThirty}`);
        console.log(`Now: ${Date.now()}`);
        console.log(dbTime.getTime() > lastThirty);
        return dbTime.getTime() >= lastThirty;
dinesh
@1532j0004kg
Dec 27 2017 17:19
guys can u please check whether this code right or wrong for posting and retreiving data ?
thsi is showing error thats y i am asking!
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>maxi</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

  </head>
  <body>
    <input id="search1" placeholder="enter playername">
    <input id="search2" placeholder="enter playerscore">
    <button class="btn-primary">click</button>
         <div class="well"></div>
  </body>
  <script>
               $(document).ready(function(){
                    $("button").click(function(){
                     $.ajax({
                           type : "POST",
                           url : "http://localhost:4000/api/ninjas",
                           data :{
                            "name" : $("#search1").val(),
                            "rank" : $("#search2").val()
                            },
                           success : function(data){
                                     console.log(data);
                           },
                           error : function(err){
                             console.log('error' ,err);
                           }
                         });
                    });
               });
  </script>
</html>
still i gave the input using input tag , the server is not accepting those data's y?
is there any error in posting data ?
dinesh
@1532j0004kg
Dec 27 2017 17:24
onething when i posting data using postman its working properly !
Nick Karnik
@theoutlander
Dec 27 2017 17:34
what is the error
on the client side console
dinesh
@1532j0004kg
Dec 27 2017 17:35
yes, i cant able to post data .
Nick Karnik
@theoutlander
Dec 27 2017 17:36
no response from server?
you need to give me more than that to help u
otherwise, everything looks okay
i would check the values been sent to the server
dinesh
@1532j0004kg
Dec 27 2017 17:36
ok i will give more info!
i think my ajax post posting in client side is wrong.
because when i posting the data using postman its working !!!
this is the real problem
@theoutlander did u get my problem?
Nick Karnik
@theoutlander
Dec 27 2017 17:41
I don’t use jquery so not sure … look at their docs
look at the debugger
See what is being sent
dinesh
@1532j0004kg
Dec 27 2017 17:42
ok
Nick Karnik
@theoutlander
Dec 27 2017 17:42
if you post codepen’s then you might get better help
dinesh
@1532j0004kg
Dec 27 2017 17:42
actually nothing is sent!
Nick Karnik
@theoutlander
Dec 27 2017 17:42
there you go ;)
dinesh
@1532j0004kg
Dec 27 2017 17:42
but i am using by local host.
hope , somebody can help me!
Nick Karnik
@theoutlander
Dec 27 2017 17:53
you could always setup a mock server
access another api
lots of options
dinesh
@1532j0004kg
Dec 27 2017 17:54
whats this actually?
Nick Karnik
@theoutlander
Dec 27 2017 17:58
you can mock your server side
don’t use it if you don’t know what it is
learn your basics …. i would do it without query as well
dinesh
@1532j0004kg
Dec 27 2017 17:58
ok
TheRedstoneTaco
@TheRedstoneTaco
Dec 27 2017 18:21
wait a moment
can you use an arrow functon within an arrow function
fat arrow function, I mean
and Jesus is Lord
Nick Karnik
@theoutlander
Dec 27 2017 18:31
Yes
It’s the same concept as function within function.
Smefinka
@Smefinka
Dec 27 2017 18:59
Hi ) I need help )) I have this function ) how i can get sum
function sum(f,s, operator){
return f operator s
}
summ(1,2,'+')
Stephen James
@sjames1958gm
Dec 27 2017 19:03
@Smefinka you could create a string and use eval()
eval(f + operator + s);
Smefinka
@Smefinka
Dec 27 2017 19:03
@sjames1958gm okay )) now try this variant ) thanks! )
CamperBot
@camperbot
Dec 27 2017 19:03
smefinka sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8804 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
Stephen James
@sjames1958gm
Dec 27 2017 19:04
@Smefinka :+1:
Smefinka
@Smefinka
Dec 27 2017 19:05
@sjames1958gm yes, it is work )) wohoo :clap:
Stephen James
@sjames1958gm
Dec 27 2017 19:05
:)
David Belmares
@DavidBelmares
Dec 27 2017 19:14

function findLongestWord(str) {
  var strLetters = str.split(""); // stores each individual character of the input
  var strWords = []; // stores each word of input string in separate indexes
  var strCurrentWord = []; // temporary storage for the letters of each word before it's joined to make currentWord
  var currentWord = ""; // temporary storage for each word before it's added to strWords

  for (i=0; i < strLetters.length; i++){ // loops through letters of input string
    if (strLetters[i] != " ") { // if the current character of the input string...
      strCurrentWord.push(strLetters[i]); // ...is not a whitespace then push it to the temporary letters array
    } else { // ...is a whitespace then we know we're at the end of the current word.
      strCurrentWord.pop(); // pop the whitespace (last value) out of the array
      currentWord = strCurrentWord.join(""); // combine the letters of the temporary array into the temporary string var
      strWords.push(currentWord); // add the value of the temporary string var to the final array of words of the string
      console.log(strCurrentWord); // for debugging
      currentWord = ""; // clear temporary variable
      strCurrentWord = []; // same as above line

    }
    i++; //this extra increment skips over the whitespace to prevent infinite looping

  }
  var lengthOfLongestWord; // self explanatory
  for (i = 0; i < strWords.length; i++) { // loops through array containing extracted words from input string

    if (strWords[i].length > lengthOfLongestWord){ // if the length of the current word is greater than the previous longest word
      lengthOfLongestWord = strWords[i].length; // update that record to reflect it
    }
  }
  return lengthOfLongestWord; // return length of longest word
}

findLongestWord("The quick brown fox jumped over the lazy dog");
I'm having trouble with this code not working... I've looked over the logic, even explained it to myself with all those comments but I still can't see what's wrong. Thanks to anyone who helps
It's supposed to find the longest word in an input string
and yes it is an FCC challenge
AbrisM
@AbrisM
Dec 27 2017 19:18
Hmm, I believe we did something similiar to this but with numbers using Arrays. However what ended up happening is that the IDE either crashed or it slowed down to a crawl :)
You might not want to include your comments inside of brackets. Try adding them in a line above your code @DavidBelmares
I see in the first else statement there's some comments inside of the opening bracket :)
David Belmares
@DavidBelmares
Dec 27 2017 19:20
Yes, but doesn't the browser ignore comments?
AbrisM
@AbrisM
Dec 27 2017 19:21
It does, but sometimes It will not work if the comments are inside of brackets. I've done this a couple times myself :)
Try moving them above the code
David Belmares
@DavidBelmares
Dec 27 2017 19:23
function findLongestWord(str) {
  var strLetters = str.split(""); // stores each individual character of the input
  var strWords = []; // stores each word of input string in separate indexes
  var strCurrentWord = []; // temporary storage for the letters of each word before it's joined to make currentWord
  var currentWord = ""; // temporary storage for each word before it's added to strWords

  // loops through letters of input string
  for (i=0; i < strLetters.length; i++){ 
    // if the current character of the input string...
    if (strLetters[i] != " ") { 
      strCurrentWord.push(strLetters[i]); // ...is not a whitespace then push it to the temporary letters array
      // ...is a whitespace then we know we're at the end of the current word.
    } else { 
      strCurrentWord.pop(); // pop the whitespace (last value) out of the array
      currentWord = strCurrentWord.join(""); // combine the letters of the temporary array into the temporary string var
      strWords.push(currentWord); // add the value of the temporary string var to the final array of words of the string
      console.log(strCurrentWord); // for debugging
      currentWord = ""; // clear temporary variable
      strCurrentWord = []; // same as above line

    }
    i++; //this extra increment skips over the whitespace to prevent infinite looping

  }
  var lengthOfLongestWord; // self explanatory
  // loops through array containing extracted words from input string
  for (i = 0; i < strWords.length; i++) { 
    // if the length of the current word is greater than the previous longest word
    if (strWords[i].length > lengthOfLongestWord){ 
      lengthOfLongestWord = strWords[i].length; // update that record to reflect it
    }
  }
  return lengthOfLongestWord; // return length of longest word
}

findLongestWord("The quick brown fox jumped over the lazy dog");
Nope
AbrisM
@AbrisM
Dec 27 2017 19:24
You are using JS, yes?
David Belmares
@DavidBelmares
Dec 27 2017 19:24
yes
AbrisM
@AbrisM
Dec 27 2017 19:24
Okay
abosalah2
@abosalah2
Dec 27 2017 19:25
hello guys, I am having an issue with JavaScrip looping code
AbrisM
@AbrisM
Dec 27 2017 19:26
@abosalah2 is it for a while or do statement?
abosalah2
@abosalah2
Dec 27 2017 19:26
my loop get infinite, can anyone take a look on my code
yes it is while
AbrisM
@AbrisM
Dec 27 2017 19:26
my machine is somewhat slow today, doing a scan :)
If I don't respond the machine might have locked up
abosalah2
@abosalah2
Dec 27 2017 19:27
my code working fine but as soon as I put it inside the loop things get messy
shall I post it here?
AbrisM
@AbrisM
Dec 27 2017 19:32
Yes
abosalah2
@abosalah2
Dec 27 2017 19:33
 while (comScore < 5 && playScore < 5){

      const keys = document.querySelector('#keys');
      keys.addEventListener('click', function(e) {
        const rock = e.target.className
        if(e.target.className == 'rock' && pick == "scissors" || e.target.className == 'scissors' && pick == "paper" || e.target.className == 'paper' &&pick == "rock") {
        document.getElementById("choice").innerHTML = "Alright you won!";
        playScore++
        document.getElementById("scorePlayer").innerHTML = playScore;
      } else if(e.target.className == 'rock' && pick == "paper" || e.target.className == 'paper' && pick == "scissors" || e.target.className == 'scissors' &&pick == "rock") {
        document.getElementById("choice").innerHTML = "You have lost! Computer choice was: " + pick;
        comScore++
        document.getElementById("scoreCom").innerHTML = comScore;
      } else if(e.target.className == pick) {
        document.getElementById("choice").innerHTML = "You are tie!";
    }
  })
}
AbrisM
@AbrisM
Dec 27 2017 19:34
@DavidBelmares Do you have the html part as well? :)
David Belmares
@DavidBelmares
Dec 27 2017 19:34
no, it's a javascript algorithm challenge
Ken Haduch
@khaduch
Dec 27 2017 19:59
@DavidBelmares - an easier way to approach this, since you are looking for the longest word, would be to split the string using spaces, and get the words as separate elements in the array, and then use .length of each word to get the length. Then just find the longest one? Your approach could work but you are working too hard, I think...
@DavidBelmares - I would hazard a guess that where you are popping the last letter out of the array, thinking that it was a space, it looks like you didn't .push that letter into the array for your word - if you're just ending up being off by a digit in the length, that could be it? And if you're ending up being off by more, your i++ at the end is causing it to skip every other letter.
Ken Haduch
@khaduch
Dec 27 2017 20:05
@DavidBelmares - if you want to try a nice tool, take your code and plug it into http://pythontutor.com/javascript.html and step through it. It could be very interesting for you to observe the code execution.
@DavidBelmares - one last thing - initializing the var lengthOfLongestWord; will also help tremendously. You are trying to compare something to it, and if it is undefined, you will not get a good comparison.
Jigal Sanders
@sandersjj
Dec 27 2017 20:29
Hello, I am working on the last of a series of assignments. This time it's the twich api assignment. However everytime I get the famous CORS error. I am using this linkhttps://wind-bow.glitch.me/twitch-api/channels/freecodecamp and the native fetch api. How Can I get around the CORS error?
Henry
@GitHub-Henry
Dec 27 2017 20:33
Chris
@bestintown23
Dec 27 2017 20:49
how can i fix my site to not be choppy or jumpy when i scroll? https://codepen.io/bestintown23/pen/gogmVB
try in internet explorer
Chris Rutherford
@cjrutherford
Dec 27 2017 20:51
anyone familiar with flexbox? I'm trying to hack together a table out of flexbox, because standard tables weren't cutting it.
Jigal Sanders
@sandersjj
Dec 27 2017 20:52
@GitHub-Henry that gives me empty responses as you can see https://codepen.io/dubbeltje/full/OzpJZb/
Tom
@moT01
Dec 27 2017 20:53
@bestintown23 its smooth for me - perhaps your computer cant keep up
@cjrutherford what is it you want to make
David Belmares
@DavidBelmares
Dec 27 2017 20:53
@khaduch thanks, initializing the variable did something but it still won't work. I also tried removing the .pop and extra i++ separately, to no avail. when I removed both, all but one checkbox turned green. So i'm onto something
CamperBot
@camperbot
Dec 27 2017 20:53
davidbelmares sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3628 | @khaduch |http://www.freecodecamp.org/khaduch
iso
@iso1048
Dec 27 2017 20:54
@cjrutherford try this little tutorial: http://flexboxfroggy.com/
or you could also look into the css grid: http://cssgridgarden.com/
Ken Haduch
@khaduch
Dec 27 2017 20:54
@DavidBelmares - great, it looks like you have something that is close... which case isn't working?
Chris Rutherford
@cjrutherford
Dec 27 2017 20:55
I'm actually trying to duplicate a standard table in flexbox, mainly because my app is in angular and the table would be split across several components. and Thanks @gothamknight I'll def check those out, and if you're in the city, I'd be glad to buy you a beer for your trouble. I'm in WaHi
CamperBot
@camperbot
Dec 27 2017 20:55
cjrutherford sends brownie points to @gothamknight :sparkles: :thumbsup: :sparkles:
:cookie: 471 | @gothamknight |http://www.freecodecamp.org/gothamknight
David Belmares
@DavidBelmares
Dec 27 2017 20:55
image.png
Chris
@bestintown23
Dec 27 2017 20:55
@moT01 try it in internet explorer
Henry
@GitHub-Henry
Dec 27 2017 20:56
@sandersjj what happens when you put your url in the browser, do you still get a CORS error?
Tom
@moT01
Dec 27 2017 20:56
why dont you try it in chrome or firefox @bestintown23
sorry i dont have that
Ken Haduch
@khaduch
Dec 27 2017 20:57
@DavidBelmares - I see, it's the last test. Looks like it should be finding the last word for that one, so I'm going to guess that you are not handling the last word properly - probably not pushing it on the list of words.
David Belmares
@DavidBelmares
Dec 27 2017 20:58
yeah
let's see here
iso
@iso1048
Dec 27 2017 20:58
@cjrutherford no worries. Haha, I dont live in the US. Thanks for the offer though
CamperBot
@camperbot
Dec 27 2017 20:58
gothamknight sends brownie points to @cjrutherford :sparkles: :thumbsup: :sparkles:
:cookie: 326 | @cjrutherford |http://www.freecodecamp.org/cjrutherford
Jigal Sanders
@sandersjj
Dec 27 2017 20:58
@GitHub-Henry nope
Chris
@bestintown23
Dec 27 2017 20:59
@moT01 i know it works in those browsers. i was just trying to find out why it was not working in internet explorer
Henry
@GitHub-Henry
Dec 27 2017 21:00
@sandersjj you are one step closer, past the CORS error
Jigal Sanders
@sandersjj
Dec 27 2017 21:00
?
Tom
@moT01
Dec 27 2017 21:01
@bestintown23 sounds like something you are using isnt supported ie
what version of ie do you have
Ken Haduch
@khaduch
Dec 27 2017 21:02
@DavidBelmares - you are relying on finding another character to put the word into the array of words, like a space character, which probably isn't going to be there. You have to handle that last word in a different way.
Jigal Sanders
@sandersjj
Dec 27 2017 21:03
@GitHub-Henry I foundout now that when I use $.getJSON of jQuery I don't get the CORS headers issue
Tom
@moT01
Dec 27 2017 21:05
@cjrutherford im not sure flex would be necessary if you're just trying to duplicate a table - do you have a pen by chance ? maybe i could take a look.
Henry
@GitHub-Henry
Dec 27 2017 21:05
@sandersjj :+1: good job
Chris
@bestintown23
Dec 27 2017 21:06
@moT01 11
Tom
@moT01
Dec 27 2017 21:08
try not using <figure>
Jigal Sanders
@sandersjj
Dec 27 2017 21:08
@GitHub-Henry thanksfor your help
Henry
@GitHub-Henry
Dec 27 2017 21:08
@sandersjj np, good luck on your project
David Belmares
@DavidBelmares
Dec 27 2017 21:30
@khaduch I'm getting close to the solution, a debugging run in Developer Tools shows that the last word isn't being added to the array of words
David Belmares
@DavidBelmares
Dec 27 2017 21:41
function findLongestWord(str) {
  var strLetters = str.split(""); // stores each individual character of the input
  var strWords = []; // stores each word of input string in separate indexes
  var strCurrentWord = []; // temporary storage for the letters of each word before it's joined to make currentWord
  var currentWord = ""; // temporary storage for each word before it's added to strWords
  var i = 0;
  // loops through letters of input string
  for (i=0; i < strLetters.length; i++){ 
    // if the current character of the input string...
    if (strLetters[i] != " ") { 
      strCurrentWord.push(strLetters[i]); // ...is not a whitespace then push it to the temporary letters array
      // ...is a whitespace then we know we're at the end of the current word.
    } else if (strLetters[i] == " ") { 

      currentWord = strCurrentWord.join(""); // combine the letters of the temporary array into the temporary string var
      strWords.push(currentWord); // add the value of the temporary string var to the final array of words of the string
      console.log(currentWord + "XDD"); // for debugging
      currentWord = ""; // clear temporary variable
      strCurrentWord = []; // same as above line

    }

  }


  var lengthOfLongestWord = 1; // self explanatory
  // loops through array containing extracted words from input string
  for (i = 0; i < strWords.length; i++) { 
    // if the length of the current word is greater than the previous longest word
    if (strWords[i].length > lengthOfLongestWord){ 
      lengthOfLongestWord = strWords[i].length; // update that record to reflect it
    }
  }
  return lengthOfLongestWord; // return length of longest word
}

findLongestWord("What if we try a super-long word such as otorhinolaryngology");
my current code for reference. I'm still looking for a solution myself
Chris Rutherford
@cjrutherford
Dec 27 2017 21:41
@moT01 well I was using a table, but ran into an issue with showing and hiding certain elements
that's an angular issue thou
though
David Belmares
@DavidBelmares
Dec 27 2017 21:52
idk at this point
Ken Haduch
@khaduch
Dec 27 2017 22:07

@DavidBelmares - well, there are a couple ways to fix it... one (a really sleazy way, so don't do this) would be to append a space onto the string so that you have an extra character to work with. Do not do that... The other way is to change the loop that is working with strLetters.length to make it test for i <= strLetters.length But then you have to be careful. because you don't want to access the array with the value of i that is off the end of the array. So you would have to change the code inside the loop to be like this:

  for (i=0; i <= strLetters.length; i++){ 
    // if the current character of the input string...
    if (i < strLetters.length && strLetters[i] != " ") { 
      strCurrentWord.push(strLetters[i]); // ...is not a whitespace then push it to the temporary letters array
      // ...is a whitespace then we know we're at the end of the current word.
    } else  { 

      currentWord = strCurrentWord.join(""); // combine the letters of the temporary array into the temporary string var
      strWords.push(currentWord); // add the value of the temporary string var to the final array of words of the string
      console.log(currentWord + "XDD"); // for debugging
      currentWord = ""; // clear temporary variable
      strCurrentWord = []; // same as above line
    }
  }

That allows your inner code to run one last time, but test the value of i before you try to use it.

@DavidBelmares - I don't know if you saw my comments above (a couple hours ago) in their entirety, but you can really save yourself a lot of work if you just initially split the string into words directly by using str.split(" "); - it will directly dive you the array of words to do the individual checks. But your way should eventually work, just making a lot of extra steps that you are going through.
David Belmares
@DavidBelmares
Dec 27 2017 22:09
Oh that's what the parameter in .split() does?
Oh my gosh!! Thanks so much @khaduch I was over complicating it big time
CamperBot
@camperbot
Dec 27 2017 22:11
davidbelmares sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3629 | @khaduch |http://www.freecodecamp.org/khaduch
David Belmares
@DavidBelmares
Dec 27 2017 22:12
function findLongestWord(str) {
  var strWords = str.split(" "); // stores each individual character of the input

  var lengthOfLongestWord = 1; // self explanatory
  // loops through array containing extracted words from input string
  for (i = 0; i < strWords.length; i++) { 
    // if the length of the current word is greater than the previous longest word
    if (strWords[i].length > lengthOfLongestWord){ 
      lengthOfLongestWord = strWords[i].length; // update that record to reflect it
    }
  }
  return lengthOfLongestWord; // return length of longest word
}

findLongestWord("What if we try a super-long word such as otorhinolaryngology");
Much cleaner code now
Ken Haduch
@khaduch
Dec 27 2017 22:12
@DavidBelmares - yes, check the docs - you can do a lot with it! But your technique is doable, it's essentially doing what you need to do, character-by-character... good luck! :)
Guys I need help. The personal porfolio is killing me! MY hello world function is not working. Can you tell me why I cannot put text on the first page?
Daniel
@DanJP2016
Dec 27 2017 22:51
@BuBBRBbr1 it looks like the negative margin on the background image you have set is pushing the text above the rest of the page. you can try playing around with the margins to get it repositioned where you want it or play the way you have the background image setup to try to fix it
David Belmares
@DavidBelmares
Dec 27 2017 23:02
@texas2010 You should probably ban the guy 2 messages up, I don't think advertising a YT channel here is compliant with the rules especially one not related to front end web dev
Ruben Abraham
@BuBBRBbr1
Dec 27 2017 23:04
Thanks a lot!
Lance
@texas2010
Dec 27 2017 23:07
@DavidBelmares thanks. they are not allow to promote their social media.
CamperBot
@camperbot
Dec 27 2017 23:07
texas2010 sends brownie points to @davidbelmares :sparkles: :thumbsup: :sparkles:
:cookie: 236 | @davidbelmares |http://www.freecodecamp.org/davidbelmares
Chris Rutherford
@cjrutherford
Dec 27 2017 23:08
@gothamknight I just went through the grid tutorial and I love this!
iso
@iso1048
Dec 27 2017 23:24
@cjrutherford yeah they are great
Daniel
@DanJP2016
Dec 27 2017 23:57
I think I am done with the calculator project. https://codepen.io/bones211/pen/LeWVzQ