These are chat archives for FreeCodeCamp/HelpJavaScript

27th
Jul 2017
kumquatfelafel
@kumquatfelafel
Jul 27 2017 00:07
@gothamknight you can pass primitives to function as arguments, but you can't actually call functions on a primitive directly. wrapper objects offer a way to store the value and call functions on it that would otherwise be unavailable.
My example was a little threadbare, there's more to it than that, but... Think link provides decent and not too detailed explanation.
CallMeOrange
@EgnaroDev
Jul 27 2017 00:18
.
kumquatfelafel
@kumquatfelafel
Jul 27 2017 00:19
,
Nick Cleary
@Hijerboa
Jul 27 2017 00:31
function updateOnline(onStreamer) {
    $.getJSON(streamURL + onStreamer, function(status) {
        statusVar = status;
        game = statusVar.stream.game;
        link = statusVar._links.channel;
    });
    $.getJSON(usersURL + onStreamer, function(info) {
        usersVar = info;
        if (info.bio !== null) {
            bio = info.bio;
        }
        name = info.display_name;
        image = info.logo;
        console.log(info);
    });
    $(".body").append(
        '<div class="well well-lg"> <a class="hrefsomething" href="google.com" style="display:block"> <div class="row"> <div class="col-md-2"> <img src="https://res.cloudinary.com/hijerboa/image/upload/v1497894212/152964589-welcome-home-new-cat-632x475_rux8iu.jpg" class="thumbnail small-image" alt="profile pic"> </div>  <div class="col-md-3"><p>Hello</p></div> <div class="col-md-3"><p>' +
            game +
            '</p></div>  <div class="col-md-4"> <p>Hello this is so cool that I\'m using jQuery to modify some stuff such wow</p></div> </div> </a> </div>'
    );
    if (++onlineIndex < online.length) {
        updateOnline(online[onlineIndex]);
    }
}
Does anyone know how I would make the variable "game" and others like it available to .append() function? I defined the variables at the top of the file, so they should be global... :/
Conor Murphy
@cmurphy580
Jul 27 2017 00:42

@cmurphy580
image.png
I'm having this problem when i run my html file on a local server.

any ideas on how to fix i tried the tilde before the file path but didin't work
?

Gulsvi
@gulsvi
Jul 27 2017 00:56
@cmurphy580 What's your URL look like in your HTML?
Conor Murphy
@cmurphy580
Jul 27 2017 00:57
https://localhost:3000/Geolocation.html @SkyC0der
Gulsvi
@gulsvi
Jul 27 2017 00:57
@cmurphy580 In your .html file I mean - what's the path to your .css, and .js file?
Something is replacing c: or whatever drive letter your OS is on with a 0
Conor Murphy
@cmurphy580
Jul 27 2017 00:59
@SkyC0der /Users/CMurphy/Desktop/JavaScript30-Challenge/Geolocation/Geolocation.jshere's the path to the js file, css is the same just .css. What do you mean?
Gulsvi
@gulsvi
Jul 27 2017 01:00
@cmurphy580 Yeah, the red text means it can't be found, so the path is incorrect. If your index.html file is at:
/Users/CMurphy/Desktop/JavaScript30-Challenge/Geolocation/index.html
Then, just use Geolocation.js and Geolocation.css for your path
relative instead of absolute path
It will help when you deploy it to a server too, so no need to modify the paths after deployment
@Hijerboa You'll need to put your second getJSON in the callback function of your first getJSON, and put the .append() method in the callback of your second getJSON.
Conor Murphy
@cmurphy580
Jul 27 2017 01:02
@SkyC0der awesome! That work! thanks for the help
CamperBot
@camperbot
Jul 27 2017 01:02
cmurphy580 sends brownie points to @skyc0der :sparkles: :thumbsup: :sparkles:
:star2: 2227 | @skyc0der |http://www.freecodecamp.com/skyc0der
Gulsvi
@gulsvi
Jul 27 2017 01:03
Cool! Glad that worked!
Nick Cleary
@Hijerboa
Jul 27 2017 01:03
@SkyC0der works! Thanks mate!
CamperBot
@camperbot
Jul 27 2017 01:03
hijerboa sends brownie points to @skyc0der :sparkles: :thumbsup: :sparkles:
:star2: 2228 | @skyc0der |http://www.freecodecamp.com/skyc0der
Gulsvi
@gulsvi
Jul 27 2017 01:04
@Hijerboa Awesome, was worried maybe I wasn't clear enough, just got ready to paste this :)
function updateOnline(onStreamer) {
  $.getJSON(streamURL + onStreamer, function(status) {
    $.getJSON(usersURL + onStreamer, function(info) {
      statusVar = status;
      game = statusVar.stream.game;
      link = statusVar._links.channel;
      usersVar = info;
      if (info.bio !== null) bio = info.bio;
      name = info.display_name;
      image = info.logo;
      console.log(info);
      $(".body").append(
        '<div class="well well-lg"> <a class="hrefsomething" href="google.com" style="display:block"> <div class="row"> <div class="col-md-2"> <img src="https://res.cloudinary.com/hijerboa/image/upload/v1497894212/152964589-welcome-home-new-cat-632x475_rux8iu.jpg" class="thumbnail small-image" alt="profile pic"> </div>  <div class="col-md-3"><p>Hello</p></div> <div class="col-md-3"><p>' + game + '</p></div>  <div class="col-md-4"> <p>Hello this is so cool that I\'m using jQuery to modify some stuff such wow</p></div> </div> </a> </div>'
      );
      if (++onlineIndex < online.length) {
        updateOnline(online[onlineIndex]);
      }
    });
  });
}
Nick Cleary
@Hijerboa
Jul 27 2017 01:04
@SkyC0der nah you made sense.
:P
Gulsvi
@gulsvi
Jul 27 2017 01:04
lol
Seth
@sethdcd
Jul 27 2017 01:07
hello i am trying to setup a basic input box with html to input a username then have javascript print that to the screen this is what i'm using and it just doesn't seem to work.
function greetings() {
    var user_name = document.getElementById('username');
    document.getElementById('user').innerHTML = user_name;

}

greetings();
username is the id for the input tag and user id is for a span that i have nested in a p tag
Gulsvi
@gulsvi
Jul 27 2017 01:11
@sethdcd user_name is going to represent an object for your #username element. I believe you want to add .value to your document.getElementById('username')
Long Nguyen
@longnt80
Jul 27 2017 01:11
@sethdcd I tried your code and it's working
but are you trying to output the object of username to the span ?
Herdie27
@Herdie27
Jul 27 2017 01:11

Is it possible someone can help me? I'm not sure if its me or something beyond my control isn't working correctly. In the challenge I'm trying to add three to each item in the array.
var oldArray = [1,2,3,4,5];

// Only change code below this line.
var timesThree = oldArray.map(function(val){
return val + 3;
});

var newArray = oldArray;

Seth
@sethdcd
Jul 27 2017 01:12
@longnt80 no the value, i tried the .value at the end of the first row but it didn't seem to work either
Gulsvi
@gulsvi
Jul 27 2017 01:13
@sethdcd greetings() can't run until the user enters something. Looks like you're running it immediately, i.e. when the page loads (and <input> is blank)
__mifflin__
@cdrainxv
Jul 27 2017 01:13

@Herdie27: Look at the naming:

var timesThree = oldArray.map(function(val){
  return val + 3;
});

I believe they wanted you to map over the oldArray, add 3 to each element in it, then store the newly returned array in newArray not timesThree.

Seth
@sethdcd
Jul 27 2017 01:14
@SkyC0der oh! so how could i fix that?
Long Nguyen
@longnt80
Jul 27 2017 01:14
@sethdcd you need to trigger it when user click a button or hit Enter
Seth
@sethdcd
Jul 27 2017 01:14
@longnt80 ahhhhh
Gulsvi
@gulsvi
Jul 27 2017 01:14
@sethdcd If your <input> is in a <form> you can add an event listener for the submit event. Otherwise, you would have to run it on keyup and monitor for when the user presses the Enter key
Seth
@sethdcd
Jul 27 2017 01:16
@SkyC0der dang nice write up!
Herdie27
@Herdie27
Jul 27 2017 01:16
@cdrainxv I changed the name to plusThree but it the array still says
[1,2,3,4,5];
and doesn't add three to each value
Gulsvi
@gulsvi
Jul 27 2017 01:17
@sethdcd Lots of people have similar questions - hope it helps. I can translate the jQuery if needed lol
Seth
@sethdcd
Jul 27 2017 01:17
@SkyC0der thanks :D
CamperBot
@camperbot
Jul 27 2017 01:17
sethdcd sends brownie points to @skyc0der :sparkles: :thumbsup: :sparkles:
:star2: 2229 | @skyc0der |http://www.freecodecamp.com/skyc0der
Gulsvi
@gulsvi
Jul 27 2017 01:18
No problem!
Thanks @longnt80 for taking a look too
CamperBot
@camperbot
Jul 27 2017 01:19
skyc0der sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 464 | @longnt80 |http://www.freecodecamp.com/longnt80
Seth
@sethdcd
Jul 27 2017 01:20
@longnt80 yes! thanks for your help as well :)
CamperBot
@camperbot
Jul 27 2017 01:20
sethdcd sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
Long Nguyen
@longnt80
Jul 27 2017 01:20
@SkyC0der thanks, :D
CamperBot
@camperbot
Jul 27 2017 01:20
:cookie: 465 | @longnt80 |http://www.freecodecamp.com/longnt80
Ken Haduch
@khaduch
Jul 27 2017 01:22
@Herdie27 - what are you doing with your variable timesThree? it should have the answer that you need... that is what is returned from the .map() method. Like if you did var newArray = timesThree; or just used newArray to store the mapped array in, if that's what the variable is supposed to be.
Herdie27
@Herdie27
Jul 27 2017 01:26
Ohhh thanks! @khaduch I got really confused because of the example they gave me. Which was this...
CamperBot
@camperbot
Jul 27 2017 01:26
herdie27 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3140 | @khaduch |http://www.freecodecamp.com/khaduch
Herdie27
@Herdie27
Jul 27 2017 01:26
This message was deleted

Instead I ended up doing this because of you.
var oldArray = [1,2,3,4,5];

// Only change code below this line.

var newArray = oldArray.map (function(val){
return val + 3;
});

Oops this was the example they gave var oldArray = [1, 2, 3];
var timesFour = oldArray.map(function(val){
return val * 4;
});
console.log(timesFour); // returns [4, 8, 12]
console.log(oldArray); // returns [1, 2, 3]
qiubo1992
@qiubo1992
Jul 27 2017 01:59
1
Traek Wells
@TraekWells
Jul 27 2017 02:17
@JLuboff @kumquatfelafel sorry for the late replies. I got it work, thanks yall. I had to use the product of the first two in the array
CamperBot
@camperbot
Jul 27 2017 02:17
traekwells sends brownie points to @jluboff and @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 543 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:star2: 2113 | @jluboff |http://www.freecodecamp.com/jluboff
Ken Haduch
@khaduch
Jul 27 2017 02:29
@Herdie27 - great! Good luck as you continue
Manish Giri
@Manish-Giri
Jul 27 2017 02:51
@thekholm80 ty
CamperBot
@camperbot
Jul 27 2017 02:51
manish-giri sends brownie points to @thekholm80 :sparkles: :thumbsup: :sparkles:
:star2: 1375 | @thekholm80 |http://www.freecodecamp.com/thekholm80
Matthew Galang
@magalang
Jul 27 2017 02:54

Hello campers! I'm currently working on the Check for Palindromes - Basic Algorithm Scripting Challenge and I have been using the left-side console to run some methods before I compose my function for submission.

I have a console error:
TypeError: x.reverse is not a function

when I run:

function palindrome(str) {
  str.reverse();
}

palindrome("eye");

Am I doing something wrong? and Should I be using the console to test methods before I compose the function?

kumquatfelafel
@kumquatfelafel
Jul 27 2017 02:55
@magalang str is a string. Reverse is a function for arrays.
Matthew Galang
@magalang
Jul 27 2017 02:55
derp me. @kumquatfelafel thanks!
CamperBot
@camperbot
Jul 27 2017 02:55
magalang sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 544 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
kumquatfelafel
@kumquatfelafel
Jul 27 2017 02:57

np. There are other things you'll have to do beside this, but taking you at your word w/regards to

run some methods before I compose my function

user
@user-ap
Jul 27 2017 03:00
@kumquatfelafel thanks
CamperBot
@camperbot
Jul 27 2017 03:00
gothamknight sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 545 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Joel Korcsmaros
@lossness
Jul 27 2017 03:16
thx for reply @khaduch
CamperBot
@camperbot
Jul 27 2017 03:16
lossness sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3142 | @khaduch |http://www.freecodecamp.com/khaduch
Joseph
@revisualize
Jul 27 2017 03:20
Hello.
Ronique Ricketts
@RoniqueRicketts
Jul 27 2017 03:26
Sup
John
@AnonymousLords
Jul 27 2017 03:28
guys if i did
var myArray = [1, 2, 3];
myArray.reverse(1,3);
would it reverse pistions 1 and 3
or would it need to be (myArray[2], myArray[4]);
i gtg, ill reply to any replies later
Manish Giri
@Manish-Giri
Jul 27 2017 03:34
why don't you read .reverse() on MDN and try it out yourself
Stanley Su
@stanley-su
Jul 27 2017 03:34
@AnonymousLords Reverse doesn’t take in any arguments. Also you can test things like that yourself.
heroiczero
@heroiczero
Jul 27 2017 04:04
JoZhang0407
@JoZhang0407
Jul 27 2017 04:38

why there is always a mistake says miss semicolon it is Introducing JavaScript Object Notation JSON part
var myMusic = [
{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}

{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}
];

Abhinav Mishra
@abhinav-m
Jul 27 2017 04:40
guys is my "approach" to the react app correct?
Ravi Kishore Thella
@ravikishorethella
Jul 27 2017 04:42
@JoZhang0407 missing , after first object
@JoZhang0407
var myMusic = [
{ .....},
{ .....}
];
Joel Y.
@zapcannon99
Jul 27 2017 04:57
:point_up: Seconded
Joseph
@revisualize
Jul 27 2017 04:58
Thirded.
DreamingLuo
@DreamingLuo
Jul 27 2017 05:02
怎么一段时间没登 都是说英语的的了
kumquatfelafel
@kumquatfelafel
Jul 27 2017 05:05
Fifthed! :o
DreamingLuo
@DreamingLuo
Jul 27 2017 05:06
https://freecodecamp.cn/challenges/profile-lookup#?solution=%2F%2F%E5%88%9D%E5%A7%8B%E5%8C%96%E5%8F%98%E9%87%8F%0Avar%20contacts%20%3D%20%5B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Akira%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Laine%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220543236543%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Pizza%22%2C%20%22Coding%22%2C%20%22Brownie%20Points%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Harry%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Potter%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220994372684%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Hogwarts%22%2C%20%22Magic%22%2C%20%22Hagrid%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Sherlock%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Holmes%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220487345643%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Intriguing%20Cases%22%2C%20%22Violin%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Kristian%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Vos%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%22unknown%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Javascript%22%2C%20%22Gaming%22%2C%20%22Foxes%22%5D%0A%20%20%20%20%7D%0A%5D%3B%0A%0A%0Afunction%20lookUp(firstName%2C%20prop)%7B%0A%2F%2F%20%E8%AF%B7%E6%8A%8A%E4%BD%A0%E7%9A%84%E4%BB%A3%E7%A0%81%E5%86%99%E5%9C%A8%E8%BF%99%E6%9D%A1%E6%B3%A8%E9%87%8A%E4%BB%A5%E4%B8%8B%0A%20%20for(var%20i%3D0%3Bi%3Ccontacts.length%3Bi%2B%2B)%7B%0A%20%20%0A%20%20%20%20if(contacts%5Bi%5D.firstName%3D%3DfirstName)%7B%0A%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20if(contacts%5Bi%5D%5Bprop%5D!%3D%3Dnull)%7B%0A%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%0A%20%20%20%20%20%0A%20%20%20%20%20%20%20return%20contacts%5Bi%5D%5Bprop%5D%3B%0A%20%20%20%20%20%0A%20%20%20%20%20%0A%20%
help
kumquatfelafel
@kumquatfelafel
Jul 27 2017 05:08
@DreamingLuo post code in here. Like so :point_down:
```js
code goes here
```
Utkarsh Gupta
@UtkarshGupta-CS
Jul 27 2017 05:08
Hello everyone!
I wanted to ask that is there any method to append a element in reactjs like the jquery append method do?
alpox
@alpox
Jul 27 2017 05:14
@UtkarshGupta-CS Not the same. You never do direct DOM manipulations in react. You would keep state p
Of an object in the component and add an object to the state which then gets rendered by the render method
Utkarsh Gupta
@UtkarshGupta-CS
Jul 27 2017 05:17
Ok
kumquatfelafel
@kumquatfelafel
Jul 27 2017 05:37
alright, I'm off. g'night.
bitcoinabdi
@bitcoinabdi
Jul 27 2017 05:53
quick question campers?
am working on a react project and was wondering if i could use cloud9 as a localserver instead of downloading an npm hippster on my terminal...?
Baibhav Gautam
@baibhavx
Jul 27 2017 06:30
Hey guys I recently completed my front-end certification and I wanted to do a project on my own from scratch. I decided on making a clone of the terminal.
https://codepen.io/baibhavx/full/wqadwp/
This is work in progress, currently only two commands work : ls and echo. Is this a good project to put on my resume? Do you have any suggestions/advice?
Victor Popescu
@VicPopescu
Jul 27 2017 06:36
@baibhavx nice idea. make the font lighter, I guess :D
if I try to zoom in-out I get CONTROLCONTROLCONTROLCONTROLCONTROLCONTROLCONTROL :D
@baibhavx or, a select with font size would be very nice, to choose smaller or bigger font
Baibhav Gautam
@baibhavx
Jul 27 2017 06:38
@VicPopescu Thanks! I just started the project. Yup a long way to go
CamperBot
@camperbot
Jul 27 2017 06:38
baibhavx sends brownie points to @vicpopescu :sparkles: :thumbsup: :sparkles:
:cookie: 525 | @vicpopescu |http://www.freecodecamp.com/vicpopescu
Victor Popescu
@VicPopescu
Jul 27 2017 06:38
@baibhavx I see that, but it is a very nice idea :D
@baibhavx good luck, you will have some work to do
Baibhav Gautam
@baibhavx
Jul 27 2017 06:39
@VicPopescu Thanks :)
CamperBot
@camperbot
Jul 27 2017 06:39
baibhavx sends brownie points to @vicpopescu :sparkles: :thumbsup: :sparkles:
:warning: baibhavx already gave vicpopescu points
王想想
@wxxxxxxxx
Jul 27 2017 07:00
function myFunction() {
myFunction.Math.random();
return 0;
}
help
abraham anak agung
@padunk
Jul 27 2017 07:01
@abhinav-thinktank your approach is Ok. One thing is about sanitise: true i think it should be sanitize with z
@wxxxxxxxx there is a chinese room in gitter, but how can i help you?
wonder
@wonder2991
Jul 27 2017 07:02
@wxxxxxxxx what are you trying to do?
王想想
@wxxxxxxxx
Jul 27 2017 07:03
Generate random numbers
How should write it?
abraham anak agung
@padunk
Jul 27 2017 07:03
Why you return 0. do you know what is Math.random doing?
王想想
@wxxxxxxxx
Jul 27 2017 07:05
reset
Not what I wrote return 0;
Do not understand Math.random()
wonder
@wonder2991
Jul 27 2017 07:08
Math.floor(Math.random() * (max - min)) + min
generates a number between max and min
@wxxxxxxxx
abraham anak agung
@padunk
Jul 27 2017 07:08
@wxxxxxxxx try this forum https://gitter.im/FreeCodeCamp/chinese
Viktor Tiutiun
@vittorioVT
Jul 27 2017 07:08
@wxxxxxxxx Math.random() returns a random number between 0 (inclusive), and 1
王想想
@wxxxxxxxx
Jul 27 2017 07:08
ok
Huỳnh Trần Khanh
@khanh2003
Jul 27 2017 07:33
lots of people are using Math.floor when they mean Math.trunc
Viktor Tiutiun
@vittorioVT
Jul 27 2017 07:35
@khanh2003 Math.floor -use more often, you can also use Math.ceil()
abraham anak agung
@padunk
Jul 27 2017 07:36
what is the different between trunc, floor, ceil and round?
Huỳnh Trần Khanh
@khanh2003
Jul 27 2017 07:36
@padunk see link
Darth Skywalker
@AdiSkywalker
Jul 27 2017 07:37
@khanh2003 Math.trunc internally calls either of Math.floor or Math.ceil
Math.trunc = Math.trunc || function(x) {
  if (isNaN(x)) {
    return NaN;
  }
  if (x > 0) {
    return Math.floor(x);
  }
  return Math.ceil(x);
}
abraham anak agung
@padunk
Jul 27 2017 07:37
cool, thanks @khanh2003
CamperBot
@camperbot
Jul 27 2017 07:37
padunk sends brownie points to @khanh2003 :sparkles: :thumbsup: :sparkles:
:cookie: 106 | @khanh2003 |http://www.freecodecamp.com/khanh2003
Huỳnh Trần Khanh
@khanh2003
Jul 27 2017 07:37
@AdiSkywalker that's a polyfill, not internal stuff.
i know where you copied that code from
Darth Skywalker
@AdiSkywalker
Jul 27 2017 07:38
It's from MDN
I'd assume the native implementation is a bit optimised like this
return val < 0 ? Math.ceil(val) : Math.floor(val);
wonder
@wonder2991
Jul 27 2017 07:42
@khanh2003 explain why i'm wrong?
Huỳnh Trần Khanh
@khanh2003
Jul 27 2017 07:42
@wonder2991 have you read the link?
wonder
@wonder2991
Jul 27 2017 07:45
the goal was to generate a random number. not Math.floor() vs Math.trunc() @khanh2003
Markus Kiili
@Masd925
Jul 27 2017 07:45
@AdiSkywalker ES5 doesn't have a trunc method, so val>>0 is a quite popular way to trunc a number.
Darth Skywalker
@AdiSkywalker
Jul 27 2017 07:46
@Masd925 :+1:
takl95
@takl95
Jul 27 2017 07:53
Morning everyon!
e
makalohri
@makalohri
Jul 27 2017 08:00
@knrt10 thank you man
CamperBot
@camperbot
Jul 27 2017 08:00
makalohri sends brownie points to @knrt10 :sparkles: :thumbsup: :sparkles:
:cookie: 470 | @knrt10 |http://www.freecodecamp.com/knrt10
Huỳnh Trần Khanh
@khanh2003
Jul 27 2017 08:01
@wonder2991 yeah you are right
Owais Ahmed
@owaisehmed
Jul 27 2017 08:03
Im confused in the question where we need to truncate the string
truncateString("A-tisket a-tasket A green and yellow basket", 11) should return "A-tisket...".
wonder
@wonder2991
Jul 27 2017 08:05
@owaisehmed post your code
Owais Ahmed
@owaisehmed
Jul 27 2017 08:05
On what basis do i need to add the dots and truncate the string
kumquatfelafel
@kumquatfelafel
Jul 27 2017 08:05

@wonder2991 Math.floor rounds down, and Math.random generates values from 0, inclusive, to 1, exclusive.

So if you want to generate a value between max and min (both inclusive) with floor, you need
to multiply Math.random by (max + 1 - min). Whether your example works or not depends on whether you need inclusive or exclusive at top end

Owais Ahmed
@owaisehmed
Jul 27 2017 08:06
function truncateString(str, num) {
  // Clear out that junk in your trunk
  if(str.length == num || str.length < num)
    return str;
  else if (num > 3)
    return str.slice(-str.length,8) + "...";
}

truncateString("Peter Piper picked a peck of pickled peppers", 11);
Please just explain to me without writing the logic or code. Thanks
I have to use another if statement for the last part but stuck on this one currently
Ghulam Shabir
@ghulamshabir
Jul 27 2017 08:06
@owaisehmed "A-tisket..." it's length is equal to num including the dots
Owais Ahmed
@owaisehmed
Jul 27 2017 08:07
what does that suppose to mean
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 08:08
hello everyone
im at the calculator exercise is there anyway to avoid write all this code
if(this.id === "-" && this.id === entrys[length-1]){

  }
Huỳnh Trần Khanh
@khanh2003
Jul 27 2017 08:08
@tiagocorreiaalmeida :wave: :coffee:
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 08:08
I wanna check if the value inputed if its + - or / or . and the last value taht was entry before that was one of them return a error
Ghulam Shabir
@ghulamshabir
Jul 27 2017 08:08
@owaisehmed means if str length is greater than num then truncate str to length equal to num including the dots
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 08:09
but that will be like the line I wrote but more 3 tiems xd
Huỳnh Trần Khanh
@khanh2003
Jul 27 2017 08:09
@tiagocorreiaalmeida where is your calculator code? (preferably a codepen link)
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 08:09
var entrys = [];
$( "button" ).click(function() {
  if(this.id === "-" && this.id === entrys[length-1]){

  }
});
im starting
im just thinking about the problem
of pressing 2 tiems + +
or - +
Huỳnh Trần Khanh
@khanh2003
Jul 27 2017 08:09
checking this.id is a horrible idea
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 08:10
then how should I do?
kumquatfelafel
@kumquatfelafel
Jul 27 2017 08:11
As @ghulamshabir says, with exception of, for example...
truncateString("A-tisket a-tasket A green and yellow basket", 3) should return "A-t..."
This demonstrates return behavior when truncated string keeps 3 or fewer characters.
Huỳnh Trần Khanh
@khanh2003
Jul 27 2017 08:12
<button action="subtract" class="operator">-</button>

$("button.operator").click(function() {
  if (this.action === "subtract") {
    // your code here
  }
})
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 08:13
and what would be the problem with the id's ? sorry new to those things
kumquatfelafel
@kumquatfelafel
Jul 27 2017 08:13
alright. off again
Huỳnh Trần Khanh
@khanh2003
Jul 27 2017 08:16
@tiagocorreiaalmeida id is not the place to store information about the button's action
so you have to store it somewhere else (like action, sign or kjsdafjlhj attributes, basically any attributes you want that is not a native html attribute)
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 08:17
jsut have to change it all np and thanks
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 08:23
console.log(this.action); will return undefined
?strange
<button type="button" action="AC" class="btn btn-danger">AC</button>
@khanh2003
if possible
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 08:56
anyone?
Markus Kiili
@Masd925
Jul 27 2017 08:59
@khanh2003 Attributes of the html element don't become properties of the element object in general. You have to use .getAttribute() or some other method for getting the attribute value.
Owais Ahmed
@owaisehmed
Jul 27 2017 09:02
function truncateString(str, num) {
  // Clear out that junk in your trunk
  if(str.length == num || str.length < num)
    return str;
  else if (num > 3)
    return str.slice(-str.length,num-3) + "...";
  else if (num < 3 || num == 3)
    return str.slice(-str.length,num) + "...";
}

truncateString("Peter Piper picked a peck of pickled peppers", 14);
wanna see some other solutions.
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 09:03
ok mate thanks @Masd925
CamperBot
@camperbot
Jul 27 2017 09:03
tiagocorreiaalmeida sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4349 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Jul 27 2017 09:03
@tiagocorreiaalmeida this.getAttribute("action") will log "subtract"
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 09:03
thanks
always learning
Markus Kiili
@Masd925
Jul 27 2017 09:04
You can also use corresponding jQuery methods if you like.
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 09:04
like what?sorryt new to those things
Markus Kiili
@Masd925
Jul 27 2017 09:07
@tiagocorreiaalmeida .attr() and .prop()
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 09:09
thanks :)
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 09:29
@Masd925 was checking if my idea would work
````
var entrys = ["x"];
var operators = ["/","+","-","x","."];
$( "button" ).click(function() {
  if(operators.includes(this.getAttribute("action")) === true
    && operators.includes(entrys[length-1] === true)
    ){
     console.log(true);
  }
});
im I missing anything?
I gave entrys the x value to test out
the idea its to chec kif the value im clicking its a operator and if its true then check aswell if the last value on my array its a operator aswell so if that's truye I know I can«t do nohint about that
Markus Kiili
@Masd925
Jul 27 2017 09:30
@tiagocorreiaalmeida operators.includes(entrys[length-1] <- what length
=== true is redundant.
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 09:36
entrys.length = 1
wait
its.
nm
dumb
bilaal-s
@bilaal-s
Jul 27 2017 09:43
Hello guys
so for this https://www.freecodecamp.org/challenges/arguments-optional algorithm, when running the second test case: addTogether(2)(3) i get an typerror any ideas?
heres my code

function addTogether() {
  let args = Array.from(arguments);
  let sum = 0;
  let savedArg = args[0];
  if (typeof args[0] !== "number" || typeof args[1] !== "number") {
    return undefined;
  }
  if (args.length > 1) {
    sum = args[0] + args[1];
    return sum;
  } else {
    console.log("branch enetered")
  }
}

addTogether(2)(3);
Markus Kiili
@Masd925
Jul 27 2017 09:48
@bilaal-s When one valid argument is passed into addTogether, you need to return a function.
JS functions return undefined by default, so you can focus on positive tests and let the engine return undefined.
bilaal-s
@bilaal-s
Jul 27 2017 09:50
@Masd925 thanks sorry i posted the wrong iteration of code
CamperBot
@camperbot
Jul 27 2017 09:50
bilaal-s sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4350 | @masd925 |http://www.freecodecamp.com/masd925
bilaal-s
@bilaal-s
Jul 27 2017 09:50

function addTogether() {
  let args = Array.from(arguments);
  let sum = 0;
  let savedArg = args[0];
  if (typeof args[0] !== "number" || typeof args[1] !== "number") {
    return undefined;
  }
  if (args.length > 1) {
    sum = args[0] + args[1];
    return sum;
  }
  if (args.length == 1) {
    console.log("branch entered");
    let secondFunction = function(secondArgument) {
      console.log("function created");
      sum = savedArg + secondArgument;
    };
    return secondFunction();
  }
}

addTogether(2, 3);
Markus Kiili
@Masd925
Jul 27 2017 09:52
@bilaal-s You need to combine typeof check with arguments.length check, because when one valid number is passed, typeof args[1] will be undefined
bilaal-s
@bilaal-s
Jul 27 2017 09:53
oh
fail xd
Markus Kiili
@Masd925
Jul 27 2017 09:54
It is better to make two cases that are one valid and two valid arguments.
bilaal-s
@bilaal-s
Jul 27 2017 09:54
true, much cleaner
Markus Kiili
@Masd925
Jul 27 2017 09:55
@bilaal-s What is the returned function returning?
bilaal-s
@bilaal-s
Jul 27 2017 09:56
@Masd925 my goodness. you are humiliating me xD
thanks man really appreciate it
Markus Kiili
@Masd925
Jul 27 2017 09:57
@bilaal-s :+1:
bilaal-s
@bilaal-s
Jul 27 2017 10:15
all done, some advice needed, do i do the advanced algorithms or move onto the projects?
Stephen James
@sjames1958gm
Jul 27 2017 10:52
@bilaal-s I would move on to projects, for more practical experience with the tech.
bilaal-s
@bilaal-s
Jul 27 2017 11:06
@sjames1958gm thank you ^_^
CamperBot
@camperbot
Jul 27 2017 11:06
bilaal-s sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8170 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 27 2017 11:10
@bilaal-s :+1:
James French
@JamesFrench30
Jul 27 2017 11:11
Hi guys can someone help me with a loop?
$(document).ready(function() {
  var twitchStreams = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"];

  for (i = 0; i < twitchStreams.length; i++) {
    var stream = twitchStreams[i];
    var twitchUrl = "https://wind-bow.gomix.me/twitch-api/streams/" + stream + "?callback=?";

    $.getJSON(twitchUrl, function(json) {
      // console.log(json["stream"]);
      var streamStatus = "";
      var html = "";

      if (json["stream"] == undefined) {
        streamStatus = "offline";
      } else {
        streamStatus = "online";
      }

      html += '<div class = "twitch"><p class ="description">' + stream + ' is ' + streamStatus + '</p></div>';

      $("div.twitchDetails").html(html);

    });
  }
});
I only seem to be returning the last twitch stream details to my webpage - suggests my loop isn't working properly
Stanley Su
@stanley-su
Jul 27 2017 11:13
@JamesFrench30 That’s because every time you make the api call, you’re replacing div.twitchDetails’s html.
James French
@JamesFrench30
Jul 27 2017 11:13
Ah yeh, obvious
Stanley Su
@stanley-su
Jul 27 2017 11:14
@JamesFrench30 also it’s better to cache your jquery selector instead of having jquery search the DOM every time
James French
@JamesFrench30
Jul 27 2017 11:14
I'll look up a way to append rather than replace
What do you mean by cache the jquery selector?
Stanley Su
@stanley-su
Jul 27 2017 11:14
@JamesFrench30 From memory, it’s just .append(/htmlhere/)
Markus Kiili
@Masd925
Jul 27 2017 11:15
@JamesFrench30 Also all the getJSON callbacks use the same variable stream (and the same value for it).
Stephen James
@sjames1958gm
Jul 27 2017 11:15
@JamesFrench30 And your stream variable is shared by all the callbacks and will be set to the last streamer
when the callbacks occur. http://stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example
See this link (using let in your for loop may help)
Stanley Su
@stanley-su
Jul 27 2017 11:15
@JamesFrench30 You save a reference to the element. Like so:
const twitchDetailsDiv = $(“div.twitchDetails”);
Stephen James
@sjames1958gm
Jul 27 2017 11:15
@JamesFrench30 cache just means store it in a variable.
Abhinav Mishra
@abhinav-m
Jul 27 2017 11:16
Hello, i have a question
Im building a react app
and as suggested , using sass.
James French
@JamesFrench30
Jul 27 2017 11:16
Ok thanks everyone, will digest this info and see if I can change a few things
Abhinav Mishra
@abhinav-m
Jul 27 2017 11:16
Now im following the sass github setup thing from react.
Ive added the sass watch commands to run when i use npm -start to start the server
however , there is a noticable delay 5-6 seconds after which my sass converts to css
is this normal?
i remember when i was running it in a different process it was almost instantaneous.
Ashraful Islam
@iashraful
Jul 27 2017 11:39
can I like totally like seriously use gitlab OR bitbucket instead of github for projects?
Ashraful Islam
@iashraful
Jul 27 2017 11:44
everyone is asleep?
:worried:
Huỳnh Trần Khanh
@khanh2003
Jul 27 2017 11:45

Attributes of the html element don't become properties of the element object in general.

@Masd925 yeah i forgot that :(

@iashraful

everyone is asleep?

no, not me

Ashraful Islam
@iashraful
Jul 27 2017 11:45
why?
Huỳnh Trần Khanh
@khanh2003
Jul 27 2017 11:46

can I like totally like seriously use gitlab OR bitbucket instead of github for projects?

use gitlab or bitbucket for private projects and github for public ones. @iashraful

Ashraful Islam
@iashraful
Jul 27 2017 11:47
eh
no, I just wanted to the reverse
Stephen James
@sjames1958gm
Jul 27 2017 11:48
@iashraful You can use anything you want - as long as the projects are publicly available
Ashraful Islam
@iashraful
Jul 27 2017 11:48
@sjames1958gm thanks :+1:
CamperBot
@camperbot
Jul 27 2017 11:48
iashraful sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8171 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 27 2017 11:48
@iashraful No problem.
Ashraful Islam
@iashraful
Jul 27 2017 11:49
the backend projects, should they be always live or just src code in gitlab would be enough?
Huỳnh Trần Khanh
@khanh2003
Jul 27 2017 11:49

@sjames1958gm

You can use anything you want - as long as the projects are publicly available

100% wrong. You have to use the most popular one to host public projects.

Ashraful Islam
@iashraful
Jul 27 2017 11:49
gitlab is all the rage, last I read people ranting in HN
bitbucket is unsung but I see it being used religiously by some enterprise people
Huỳnh Trần Khanh
@khanh2003
Jul 27 2017 11:52
@iashraful if you are an asdf person, host your own git server.
Ashraful Islam
@iashraful
Jul 27 2017 11:52
@khanh2003 eh, am not that excited
Blauelf
@Blauelf
Jul 27 2017 11:53
What's an "asdf person"? A left-handed one?
Ashraful Islam
@iashraful
Jul 27 2017 11:53
^ my question
a simple determined fellow ?
or replace simple with sophisticated
Stephen James
@sjames1958gm
Jul 27 2017 11:57
@khanh2003 Not sure if you are being sarcastic. From the FCC about page:
Do I have to use CodePen for the front end projects?
As long as your code is publicly viewable, and you have a live demo, you can use whatever you want.
Blauelf
@Blauelf
Jul 27 2017 11:58
How would you have a live demo for a back-end project? GitHub hosting is static pages only.
(not exactly relevant to me right now, as I still have to do the frontend projects, still interesting)
Jianhao Tan
@jaanhio
Jul 27 2017 12:01
hi all, i am working on the leaderboard project. may i know how do i make the link work? how should the syntax be such that the href = https://www.freecodecamp.com/{allTime.username}
<td><img src={allTime.img} className="image is-24x24 profile"></img> <a href="'https://www.freecodecamp.com/' + '{allTime.username}'" className="username">{allTime.username}</a> </td>
Stephen James
@sjames1958gm
Jul 27 2017 12:02
@Blauelf The backend projects are mostly APIs, so having the API servers available?
The examples use heroku - but for free you only get so many active applications.
Ashraful Islam
@iashraful
Jul 27 2017 12:02
@Blauelf it is better to use github for your front-end projects, as you'll get an early hands on experience from building tools(webpack/rollup) instead of having codepen doing all the magic
also, you get added benefit of rollback
Markus Kiili
@Masd925
Jul 27 2017 12:03
@Blauelf Use some web hosting service?
Ashraful Islam
@iashraful
Jul 27 2017 12:04
yes
pagodabox.io/heroku/cloudno.de => give tiny boxes for free to host node apps
openshift.com used to give blessings, but recently they shifted to v3 and now everyone who wants a free service must be waiting for all eternity looking at the waiting for provisioning status
Stephen James
@sjames1958gm
Jul 27 2017 12:05
@jaanhio Use template strings they are easier to use.
Blauelf
@Blauelf
Jul 27 2017 12:06
@Masd925 Last time I used a "free" web hosting service, around 2004, it was pretty much restricted, like no HTTPS. Has that changed?
Markus Kiili
@Masd925
Jul 27 2017 12:07
@Blauelf I think proper ones cost a little.
Ashraful Islam
@iashraful
Jul 27 2017 12:08
http://pagodabox.io/ <-- I use this one and heroku for quick prototypes
amazon lightsail is free for 1 month if you like to config your own
eh, unintended marketing, I go build myself the timestamp api
Jianhao Tan
@jaanhio
Jul 27 2017 12:11
@sjames1958gm hmmm how do i implement that?
this is the code
ender() {
    const allTimeTop = this.props.allTimeTop;
    const allTimeTopRender = allTimeTop.map((allTime) =>
      const userName = allTime.user;
      <tr>
        <td>{allTimeTop.indexOf(allTime) + 1}</td>
        <td><img src={allTime.img} className="image is-24x24 profile"></img> <a href="https://www.freecodecamp.com/${ userName }" className="username">{allTime.username}</a> </td>
        <td>{allTime.recent}</td>
        <td>{allTime.alltime}</td>
      </tr>
  );
      return(
        <tbody>
          {allTimeTopRender}
        </tbody>
      );
  }
Stephen James
@sjames1958gm
Jul 27 2017 12:12
@jaanhio
`<td><img src={allTime.img} className="image is-24x24 profile"></img>
 <a href="${'https://www.freecodecamp.com/' + allTime.username}" className="username">${allTime.username}</a> </td>`
@jaanhio Hmm are you using a templating engine?
Jianhao Tan
@jaanhio
Jul 27 2017 12:13
@sjames1958gm nope. why do you ask?
im using bulma for styling
Stephen James
@sjames1958gm
Jul 27 2017 12:13
@jaanhio Oh, React - my bad

@jaanhio

let URL = `https://www.freecodecamp.com/${ userName }`

Then use {URL} in the

Alex
@alexandrupintilei
Jul 27 2017 12:14
@sjames1958gm Hi.Whats wrong at my code?

function diffArray(arr1, arr2) {
  var newArr = [];
  // Same, same; but different.
  for(var i = 0; i < arr1.length; i++) {
    console.log(arr1[i]);
  }
    var indexValue = arr1.indexOf(arr2);
if(indexValue >= 0){
  console.log(indexValue);
} else {

}
  return newArr;
}

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
Stephen James
@sjames1958gm
Jul 27 2017 12:16
@alexandrupintilei arr1.indexOf(arr2); this will always be -1 as you are looking for an array reference in arr1
Jianhao Tan
@jaanhio
Jul 27 2017 12:17
@sjames1958gm let URL = `https://www.freecodecamp.com/${ userName }`
where should i be putting this in my code?
Stephen James
@sjames1958gm
Jul 27 2017 12:18
@jaanhio You can put this in your arrow function -
Which looks odd - you have to have {} and return when you have statements like const.
zhihuizi
@Tibberss
Jul 27 2017 12:18
0.0
Blauelf
@Blauelf
Jul 27 2017 12:19
@alexandrupintilei You're not pushing anything to newArr. Also, you'll need an if with a push within the loop, filtering it, (or two of those loops if you handle arr1 and arr2 separately). Alternatively, first concat the arrays and then filter the joint array.
Alex
@alexandrupintilei
Jul 27 2017 12:19
@Blauelf Ok.I will try
Jianhao Tan
@jaanhio
Jul 27 2017 12:21
@sjames1958gm sorry im still kinda lost :worried:
do you mean like this?
render() {
    const allTimeTop = this.props.allTimeTop;
    const allTimeTopRender = allTimeTop.map((allTime) =>
    let URL = 'https://www.freecodecamp.com/${allTime.username}';
      <tr>
        <td>{allTimeTop.indexOf(allTime) + 1}</td>
        <td><img src={allTime.img} className="image is-24x24 profile"></img> <a href="${'https://www.freecodecamp.com/' + allTime.username}" className="username">{allTime.username}</a> </td>
        <td>{allTime.recent}</td>
        <td>{allTime.alltime}</td>
      </tr>
  );
i am getting “unexpected token” error
Blauelf
@Blauelf
Jul 27 2017 12:22
I think the ${} syntax is for string templates only
Alex
@alexandrupintilei
Jul 27 2017 12:22
@Blauelf

function diffArray(arr1, arr2) {
  var newArr = [];
  // Same, same; but different.
  for(var i = 0; i < arr1.length; i++) {
    console.log(arr1[i]);
  }
    var arr3 = arr1.concat(arr2);
if(arr3 >= 0){
  console.log(arr3);
} else {

}
  return newArr;
}

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
`
Stephen James
@sjames1958gm
Jul 27 2017 12:22
@jaanhio Part of the problem is you are trying to use statements in your arrow function without {}
Only and expression is allowed.
Alex
@alexandrupintilei
Jul 27 2017 12:22
concat dosent work good
i saw,return arr3*
Stephen James
@sjames1958gm
Jul 27 2017 12:23
@jaanhio Try this (removed the let / const) and changed the href
render() {
    const allTimeTop = this.props.allTimeTop;
    const allTimeTopRender = allTimeTop.map((allTime) =>
      <tr>
        <td>{allTimeTop.indexOf(allTime) + 1}</td>
        <td><img src={allTime.img} className="image is-24x24 profile"></img> <a href="https://www.freecodecamp.com/{allTime.username}" className="username">{allTime.username}</a> </td>
        <td>{allTime.recent}</td>
        <td>{allTime.alltime}</td>
      </tr>
  );
Huỳnh Trần Khanh
@khanh2003
Jul 27 2017 12:25

@sjames1958gm

Not sure if you are being sarcastic.

I am not being sarcastic.

Blauelf
@Blauelf
Jul 27 2017 12:25
@alexandrupintilei Could be like
function diffArray(arr1, arr2) {
  var newArr = [];
  var jointArr = arr1.concat(arr2);
  for (var i = 0; i < jointArr.length; i++) {
    if (some boolean expression involving indexOf(jointArr[i])) {
      newArr.push(jointArr[i]);
    }
  }
  return newArr;
}
Stephen James
@sjames1958gm
Jul 27 2017 12:25
@khanh2003 ok
Jianhao Tan
@jaanhio
Jul 27 2017 12:27
@sjames1958gm hmmm when i hover over the link, it shows “https://www.freecodecamp.com/%7BallTime.username%7D”.
Blauelf
@Blauelf
Jul 27 2017 12:28
@jaanhio If you want to use templates, then use backticks, like `${allTime.username}` instead of "${allTime.username}"
Stephen James
@sjames1958gm
Jul 27 2017 12:28
@jaanhio Hmm, maybe this is better:
href={"https://www.freecodecamp.com/" + allTime.userName}
Blauelf
@Blauelf
Jul 27 2017 12:30
@sjames1958gm Me not knowing React, this looks better.
Datikzz
@Datikzz
Jul 27 2017 12:30
Hi guys, i need regex pattern that matches all words before first character : in whole text, not just first sentence?
Stephen James
@sjames1958gm
Jul 27 2017 12:30
@Blauelf not sure if template strings work in jsx, but they should ( I think)
Jianhao Tan
@jaanhio
Jul 27 2017 12:31
@sjames1958gm @Blauelf yes it worked! thank you both
CamperBot
@camperbot
Jul 27 2017 12:31
jaanhio sends brownie points to @sjames1958gm and @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4538 | @blauelf |http://www.freecodecamp.com/blauelf
:star2: 8172 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 27 2017 12:31
@jaanhio :+1: Fighting the syntax battles . . .
Jianhao Tan
@jaanhio
Jul 27 2017 12:31
also, looking at your top profile right now @sjames1958gm :smile:
Stephen James
@sjames1958gm
Jul 27 2017 12:32
@jaanhio :) :zap:
Blauelf
@Blauelf
Jul 27 2017 12:33

I'm just super-confused by that code, to me it looks like there might be parentheses or something like that missing, separating the HTML from the JavaScript.

This totally looks like JSPs in the Java (not JavaScript) world, where logic and presentation form an unholy union.

Ronique Ricketts
@RoniqueRicketts
Jul 27 2017 12:33
@sjames1958gm ya i agree your doing very well James, Your point motivate me to code in the daytime :)
Jianhao Tan
@jaanhio
Jul 27 2017 12:34
@Blauelf what is the difference between using ${allTime.username} and “${alltime.username}” ? are both considered template strings?
Stephen James
@sjames1958gm
Jul 27 2017 12:34
@Blauelf That is React components. There is a preprocessor that converts the jsx to js
@RoniqueRicketts Cool!
Blauelf
@Blauelf
Jul 27 2017 12:35
@jaanhio ES6 template strings use backticks `, while regular strings use single ' or double " quotes.
Jianhao Tan
@jaanhio
Jul 27 2017 12:35
@Blauelf i see. so just a difference in syntax?
Ronique Ricketts
@RoniqueRicketts
Jul 27 2017 12:36
@sjames1958gm been looking at your guys grow and I tried to code everyday and now I am on a 27 day streak. I started over freeecodecamp about a month ago
Markus Kiili
@Masd925
Jul 27 2017 12:37
@Blauelf Can't you avoid the unholy by having the logic on servlets and just generating html with JSP?
Blauelf
@Blauelf
Jul 27 2017 12:37
@jaanhio The special ${} magic works in templates only, not in regular strings. There's more, like template strings allow for line breaks in code, like
var multiLineGreeting = `Hello,
World`;
var regularMultiLine = "Hello,\nWorld";
@Masd925 Aren't JSPs compiled into servlets?
Markus Kiili
@Masd925
Jul 27 2017 12:40
@Blauelf They are yes.
Stephen James
@sjames1958gm
Jul 27 2017 12:41
@Blauelf React components are an alliance (unholy or otherwise) of presentation and logic.
Blauelf
@Blauelf
Jul 27 2017 12:42
I think I tried JSP/servlets about 15 years ago, but could not reproduce the setup described in the book. The... was it Tomcat? wasn't called by the Apache. Had more luck with a pre-configured Apache/PHP environment, but did not like PHP.
Even tried ASP (without .net at that time ;) )
Markus Kiili
@Masd925
Jul 27 2017 12:44
@Blauelf We did one JSP pizzeria service at school a couple of years ago.
Stephen James
@sjames1958gm
Jul 27 2017 12:45
It was Tomcat, the first to run on port 8080
Nick Gray
@nicholasnbg
Jul 27 2017 12:45
hey guys, just getting my twitch streamer done, looking for some comments on what needs fixing up next, https://htmlpreview.github.io/?https://github.com/nicholasnbg/twitchStreamer/blob/Tiles/index.html
Jianhao Tan
@jaanhio
Jul 27 2017 12:45
@Blauelf @sjames1958gm just curious, how long did you guys take to reach this level of proficiency? you guys are what most of us are aiming towads
Stephen James
@sjames1958gm
Jul 27 2017 12:47
@jaanhio I have a lot of experience in programming in general, but have been into this web stuff for probably a couple of years or so. I joined FCC early last year
Lukáš Lefler
@Strikers666
Jul 27 2017 12:47
what am I doing wrong?
Nick Gray
@nicholasnbg
Jul 27 2017 12:47
one niggling thing I can't figure out (not strictly js related) is when there is < 3 streams on a row, the column widths are slightly larger than when there are 3 streams on a row
Lukáš Lefler
@Strikers666
Jul 27 2017 12:47
image.png
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 12:48
you have bogey?
and its birdie
Stephen James
@sjames1958gm
Jul 27 2017 12:49
@nicholasnbg Maybe add storage of added streamers in local storage, because on refresh they go away.
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 12:49
sec
Nick Gray
@nicholasnbg
Jul 27 2017 12:49
you are missing the par bit in the birdie code @Strikers666
Stephen James
@sjames1958gm
Jul 27 2017 12:49
@Strikers666 strokes are never going to be <= -1 (check your Birdie code)
Nick Gray
@nicholasnbg
Jul 27 2017 12:49
I have no idea how to do that @sjames1958gm , I assumed that sort of functionality would come with learning backend stuff
Lukáš Lefler
@Strikers666
Jul 27 2017 12:50
@nicholasnbg Thats it, thx, maybe im too tired today :D
CamperBot
@camperbot
Jul 27 2017 12:50
:cookie: 332 | @nicholasnbg |http://www.freecodecamp.com/nicholasnbg
strikers666 sends brownie points to @nicholasnbg :sparkles: :thumbsup: :sparkles:
Blauelf
@Blauelf
Jul 27 2017 12:50
@jaanhio I first met HTML and Javascript in the late 90s (before CSS), but rarely used them. Have experience in other programming languages, though (BASIC, Turbo Pascal, Java, a bit of C and C++, Matlab, whatever was useful at the time). So at least in imperative programming, I can use my previous experiences. In functional programming, while I used function pointers before, JavaScript and a short visit to Haskell are my first real experiences there.
Stephen James
@sjames1958gm
Jul 27 2017 12:50
@nicholasnbg local storage is front end (browser local) - one of the React apps uses it.
It is not hard to use, check MDN local storage
Nick Gray
@nicholasnbg
Jul 27 2017 12:51
all good @Strikers666 lack of sleep is probably responsible for a lot of programming mistakes haha
Stephen James
@sjames1958gm
Jul 27 2017 12:51
@Blauelf Have you looked at ELM at all? I kind of liked it but had trouble getting around the syntax
Nick Gray
@nicholasnbg
Jul 27 2017 12:51
@sjames1958gm I'll take a look, looking forward to learning React soon
Jianhao Tan
@jaanhio
Jul 27 2017 12:51
@Blauelf @sjames1958gm i guess proficiency is not something that can be rushed?? sometimes i find myself facing so many things to learn, not knowing where to start
Nick Gray
@nicholasnbg
Jul 27 2017 12:51
thanks @sjames1958gm
CamperBot
@camperbot
Jul 27 2017 12:51
nicholasnbg sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8173 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Ronique Ricketts
@RoniqueRicketts
Jul 27 2017 12:52
@Blauelf damn!! I met HTML CSS and Javascript Last year. They wooped my brain but html and css got tired and stopped but Javascript like to beat my brain still.
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 12:52
can I write something like these
this.getAttribute("action").indexof(".")
Stephen James
@sjames1958gm
Jul 27 2017 12:53
@jaanhio There are many patterns that you will see over and over again, in time.
When your brain starts recognizing them, things that you have to "think" about now, will come naturally.
Blauelf
@Blauelf
Jul 27 2017 12:54
@tiagocorreiaalmeida You mean indexOf with capital O?
Stephen James
@sjames1958gm
Jul 27 2017 12:54
@tiagocorreiaalmeida Sure, if getAttribute returns something that has indexOf function
Missed that typo
Blauelf
@Blauelf
Jul 27 2017 12:55
I assume this.getAttribute("action") returns a string? (array seems less likely)
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 12:55
I have a little problem just thinking how Im gonna fix it sec will paste the code to see if you have any idea
var entrys = [];
var operators = ["/","+","-","x","."];
$( "button" ).click(function() {
  console.log(splited);
  if(operators.includes(this.getAttribute("action"))
    && operators.includes(entrys[entrys.length-1])){
     console.log("You can't use multiple operators together");
  }
 else{
    entrys.push(this.getAttribute("action"));
  }
});

var updatescreen = function(){

}
still there's alot of things to check before atually make it work
but my problem is I need to store all the values pressed 1 time like
55555
then +
then 2
I can only push the values if the attribute returns a aoperator right?
Blauelf
@Blauelf
Jul 27 2017 12:57
@RoniqueRicketts I have a bad feeling about HTML and CSS looking so innocent and pure, but when they are interpreted by browsers, it's a pain to get a consistent rendering across multiple platforms. Tends to make me feel nervous.
Ronique Ricketts
@RoniqueRicketts
Jul 27 2017 13:00
@Blauelf Haha, wait ya, i forgot about Internet Explorer when I mention html and css. I keep forgetting that IE breaks everything.
Stephen James
@sjames1958gm
Jul 27 2017 13:11
@tiagocorreiaalmeida You need to split your first check into
if (operators.includes(this.getAttribute("action"))
   if (operators.includes(this.getAttribute("action"))
      console.log error multiple operators
   else
      push the action 
else
     push non-operators
Blauelf
@Blauelf
Jul 27 2017 13:12
@RoniqueRicketts In the late 90s, even the most basic browser APIs were different in IE and Netscape (I think Mosaic did not have JavaScript?). There was a lot of browser-specific stuff in my code trying to even that out.
Ronique Ricketts
@RoniqueRicketts
Jul 27 2017 13:14
@Blauelf oh my [Peter griffin voice]. must have been harder to develop websites. btw do now work as a dev?
Jefferson
@jeffersonnnn
Jul 27 2017 13:24
Hi guys, i need help with the Return Largest Number in Arrays bonfire because all i keep seeing online are straight answers and i want to solve this bonfire by myself. i am looking for a means to scan multidimensional arrays looking for largest number using the math.max method. Thanks.
Darth Skywalker
@AdiSkywalker
Jul 27 2017 13:26
@jeffersonnnn You can use nested loops to iterate over multidimensional array (2d array in this case)
If you use Math.max then you don't need nested loop
@RoniqueRicketts Don't you dare imitate the fat man
Blauelf
@Blauelf
Jul 27 2017 13:28

@RoniqueRicketts I don't know if it really was harder, as there were less possibilities, and less restrictions (nobody thought about CORS, one could easily include images from local hard disk, and so on). As I was younger, I'd of course build black-yellow-purple pages with blinking green text within large framesets, that part did not require JavaScript. Also did very simple games (none of which reached the complexity of Tic-Tac-Toe).

Regarding my current work, I mostly try to find errors in a specific website, with front- and backend developed independently, and parts of the configuration done by very different people, some of which put quotation marks into strings that would later end up between quotation marks, which breaks the whole page. Everything is a mess, as there's no specification what the page is supposed to do (any side has their own opinions, and when marketing and legal add theirs, ...), and the changelog for the frontend (there is one!) also is not very verbose. But I don't have experience as a developer, and I don't know if I did well at that job, so not sure if I should aim for such a position.

Ronique Ricketts
@RoniqueRicketts
Jul 27 2017 13:29
@AdiSkywalker lol that's what I always do in reality haha
Darth Skywalker
@AdiSkywalker
Jul 27 2017 13:32
Ronique Ricketts
@RoniqueRicketts
Jul 27 2017 13:33
@Blauelf please don't ever limit yourself. I'd really like to someday be on a development team to build a few Web apps. I may build a 1 or 2 from my list of apps I want to build just for practice but I need to know backend first.
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 13:36
@sjames1958gm hey
can you give a look to this'
im missign 2 points
Ronique Ricketts
@RoniqueRicketts
Jul 27 2017 13:36
@AdiSkywalker that's the exact oh my I was implying
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 13:37
first after using a operator code stops the other its that im using a operator as first numer and I can't but will solve that one now
dont look the design that's the last thing im gonna do xd
Jefferson
@jeffersonnnn
Jul 27 2017 13:40
@AdiSkywalker tried that, here is where i am in my code

function largestOfFour(arr) {
  var newArray = [];
  for (i = 0; i < 5; i++) {
     var largestNumber = 0;
    for (j = 0; j < 5; j++) {

    }
  }
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Darth Skywalker
@AdiSkywalker
Jul 27 2017 13:41
@jeffersonnnn yeah, inside your inner for loop, check if arr[i][j] is greater than largestNumber
if so, make arr[i][j] as largestNumber
Jefferson
@jeffersonnnn
Jul 27 2017 13:42
@AdiSkywalker i know i should use the math.max method, but i can't wrap my thoughts around what it should look like
Darth Skywalker
@AdiSkywalker
Jul 27 2017 13:42
when the inner loop ends, push this largestNumber in newArray
Stephen James
@sjames1958gm
Jul 27 2017 13:42
@tiagocorreiaalmeida Try this for last check on value:
!Number.isNaN(parseInt(value))
Darth Skywalker
@AdiSkywalker
Jul 27 2017 13:43
@jeffersonnnn okay, if you wanna use Math.max you need to get rid of that inner for loop
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 13:43
just writed a few console logs in all if statement
so if that one fails
Jefferson
@jeffersonnnn
Jul 27 2017 13:43
@AdiSkywalker alrighty then, let me run go implement that.
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 13:43
will paste the code you gave me
thanks for looking into it
Darth Skywalker
@AdiSkywalker
Jul 27 2017 13:43
and say var largestNumber = Math.max.apply(null, arr[i])
@jeffersonnnn
Nick Janne
@njanne19
Jul 27 2017 13:43
Hey, I'm almost done with my roguelike project. All I have to do is add darkness. I'm not sure exactly how I should go about implementing it. Does anyone have a suggestion?
Blauelf
@Blauelf
Jul 27 2017 13:44
@jeffersonnnn Please use var to declare i and j to make them function scope instead of global. Also, use arr.length for the outer and arr[i].length for the inner loop instead of hard-coding 5.
Stephen James
@sjames1958gm
Jul 27 2017 13:44
Blauelf
@Blauelf
Jul 27 2017 13:45
Using map and Math.max even gets rid of all the loops and their counters :D
Moisés Man
@moigithub
Jul 27 2017 13:45
@jeffersonnnn array are 0 based index.. soo if u have 4 elements.. 0, 1, 2, 3 <-- last index will be 3
if u write <5 ur last value will be 4.. soo ur code will try to access unexistant elements
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 13:46
@sjames1958gm that's it I think give it a new look and tell me if you find any mistake
Jefferson
@jeffersonnnn
Jul 27 2017 13:47
@AdiSkywalker so i should remove the j for loop if i intend to use math.max? Got it, but i don't understand how math.max.apply works. Can you please direct me to a resource i can study? Thanks.
CamperBot
@camperbot
Jul 27 2017 13:47
jeffersonnnn sends brownie points to @adiskywalker :sparkles: :thumbsup: :sparkles:
:cookie: 244 | @adiskywalker |http://www.freecodecamp.com/adiskywalker
Stephen James
@sjames1958gm
Jul 27 2017 13:47
@tiagocorreiaalmeida What I did was add console.log for value and entrys to the start of that function
And then tried to determine which if / else if should be passed or not from there.
Jefferson
@jeffersonnnn
Jul 27 2017 13:47
@sjames1958gm thanks for the resource. @moigithub point taken, thanks.
CamperBot
@camperbot
Jul 27 2017 13:47
jeffersonnnn sends brownie points to @sjames1958gm and @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3534 | @moigithub |http://www.freecodecamp.com/moigithub
:star2: 8174 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 13:48
did almost the same hehe, seems to be working I think
Moisés Man
@moigithub
Jul 27 2017 13:49
mdn.io/math.max
http://devdocs.io/javascript/global_objects/function/apply
there are also youtube videos explaining apply /call/this @jeffersonnnn
Blauelf
@Blauelf
Jul 27 2017 13:53

@jeffersonnnn You could say that Math.max(a, b, c) is same as Math.max.apply(Math, [a, b, c]). First argument to apply is the object to be passed for the function's this, Math.max ignores it, so you could use anything, I like using null in this case. Second argument to apply is an array-like that contains the arguments to pass to the function.

So if you have an array or array-like you'd like to pass to a function which expects a list of arguments instead, you can use apply.

Datikzz
@Datikzz
Jul 27 2017 13:59
Hi, how i can check array's elements(strings) for pattern/regex?
Diego Mayer
@Chrono79
Jul 27 2017 14:00
@Datikzz using map and test?
Diego Mayer
@Chrono79
Jul 27 2017 14:06
@tiagocorreiaalmeida Forbid using more than one dot per number (right now, you can enter 1.1.1.1)
Moisés Man
@moigithub
Jul 27 2017 14:08
to access array elements any kind of loop should work (ur question is too generic)
for pattern check u could use test.. but depending what u wanna do with the result.. u could also use match @Datikzz
Datikzz
@Datikzz
Jul 27 2017 14:12
well, i have 2 arrays, want to find via pattern value in 1st array that i need so i can compare it with 2nd array's elements
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 14:13
@Chrono79 that's what im looking for right now to acomplish :D but thanks for pointing out
CamperBot
@camperbot
Jul 27 2017 14:13
tiagocorreiaalmeida sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4501 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Jul 27 2017 14:14
:+1:
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 14:15
also avoiding that the user uses a operator before writing any numbr aswell
Kelechi Chinaka
@ke1echi
Jul 27 2017 14:18
most times i wonder how nesting works
Marianissimus
@Marianissimus
Jul 27 2017 14:19
i wonder about callbacks...
don't we wonder, all?
Kelechi Chinaka
@ke1echi
Jul 27 2017 14:19
like i need to flatten an array using map() [4, 6, 5], [], [9, 7, 8]] => [4, 6, 5,9, 7, 8]
pls some share some light on it
Diego Mayer
@Chrono79
Jul 27 2017 14:20
better use reduce
Kelechi Chinaka
@ke1echi
Jul 27 2017 14:21
why no map..it can still get it done i think
Diego Mayer
@Chrono79
Jul 27 2017 14:22
there is a ] more or a [ less
Kelechi Chinaka
@ke1echi
Jul 27 2017 14:22
ok..but how does it work
Ogundele Olumide
@Lumexralph
Jul 27 2017 14:25
@kelechy map might not be a good idea reduce comes to mind
Hello Everyone :wave:
Diego Mayer
@Chrono79
Jul 27 2017 14:26
@kelechy
var arr = [[4, 6, 5], [], [9, 7, 8]];
var arr2 = [];
arr.map(e=>arr2.push(...e)); // you're using map as a loop here
console.log(arr2);
try using reduce now
Kelechi Chinaka
@ke1echi
Jul 27 2017 14:27
:wave: @Lumexralph
Diego Mayer
@Chrono79
Jul 27 2017 14:28
Note that that only flatten 1 level
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 14:29
hey @Chrono79 can you give a look to my pen?got something I can't understand why doesnt work
````
else if(entrys[entrys.length-1] === dot && value === dot){
    console.log("You can't use two times");
        console.log("entering here 3");
  }
what I wanna do here its check fi the last value was a dot and if it was check if the atual value is a due aswell if it is console.log can't use a dot followed by another
Stephen James
@sjames1958gm
Jul 27 2017 14:34
@tiagocorreiaalmeida dot is an array not a string
Kelechi Chinaka
@ke1echi
Jul 27 2017 14:35
oh i get it now, reduce takes an initial value [] just like we use for arithmetic @Chrono79
Diego Mayer
@Chrono79
Jul 27 2017 14:36
@tiagocorreiaalmeida dot is an array
entrys[entrys.length-1] === dot && value === dot <- this one isn't true
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 14:37
im done nm
dumb
tyhanks for your patient
Kelechi Chinaka
@ke1echi
Jul 27 2017 14:39
it all makes sense now
function flattenAndSort(array) {
  return array.reduce(function (a, b) {
    return a.concat(b)
  }, []).sort((a, b) => {return a - b })
}
@Chrono79
Diego Mayer
@Chrono79
Jul 27 2017 14:41
:+1:
Alexander Køpke
@alexanderkopke
Jul 27 2017 14:45
so simple yet so powerful
Kelechi Chinaka
@ke1echi
Jul 27 2017 14:46
you can say that again @alexanderkopke
Ogundele Olumide
@Lumexralph
Jul 27 2017 14:46
@kelechy how're you doing?
Kelechi Chinaka
@ke1echi
Jul 27 2017 14:48
great..heard bootcamp is monday @Lumexralph
Moisés Man
@moigithub
Jul 27 2017 14:48
[].concat.apply([],[[1],[2],[3]])
u can omit the loop
//[1,2,3]
Kelechi Chinaka
@ke1echi
Jul 27 2017 14:49
reduce() is great
hmm...cool syntax @moigithub
Tiago Correia
@tiagocorreiaalmeida
Jul 27 2017 14:53
random question anyone here works with photoshop?
Alexander Køpke
@alexanderkopke
Jul 27 2017 14:53
a
a7n007
@a7n007
Jul 27 2017 14:56
function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  var arr1=[];var arr2=[];
  // Only change code below this line
 arr1=(Object.getOwnPropertyNames(source));
  for(var i=0;i<collection.length;i++)
  {
  for(var j=0;j<arr1.length;j++)
  {  
    if(collection[i].hasOwnProperty(arr1[j]));
     {
      if(source.arr1[j]==collection[i].arr1[j])
       arr.push(collection[i]);
     }
  }
  }

  // Only change code above this line
  return arr;
}

whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
error says source.arr1 undefined can anyone help me
Blauelf
@Blauelf
Jul 27 2017 15:00
@a7n007 Maybe you meant source[arr1[j]] and collection[i][arr2[k]]?
@a7n007 BTW, don't use the property names of collection[i]. Just test whether collection[i][arr1[j]] exists and equals source[arr1[j]].
And push only if all properties exist and have the right value.
a7n007
@a7n007
Jul 27 2017 15:02
it is showing exactly this : Type error : source.arr1 undefined
Blauelf
@Blauelf
Jul 27 2017 15:03
Caused by source.arr1[j]. As source.arr1 does not exist, there's no way to access its property/element.
a7n007
@a7n007
Jul 27 2017 15:05
i didnt understand, i mean i declared arr1 and it contains properties of source
Blauelf
@Blauelf
Jul 27 2017 15:05
Why should source have a property named "arr1"?
Ashraful Islam
@iashraful
Jul 27 2017 15:06
whelp
timestamp api done
https://fcc-timestamp-api.glitch.me/ feel free to criticize
Blauelf
@Blauelf
Jul 27 2017 15:06
source.arr1[j] is same as source["arr1"][j], while you meant source[arr1[j]] (completely different thing. For example, [j] refers to arr1)
a7n007
@a7n007
Jul 27 2017 15:07
i didnt get it source.arr1[j]=source.last; since arr1[j]=last;
Jason Luboff
@JLuboff
Jul 27 2017 15:11
@iashraful Just FYI, if I do https://fcc-timestamp-api.glitch.me/api/July 27 2017 it returns
{
    "unix": 8521875907200000,
    "natural": "July 1, 272017"
}
Ashraful Islam
@iashraful
Jul 27 2017 15:11
@JLuboff the api didn't mention anything about supporting all formats
a7n007
@a7n007
Jul 27 2017 15:12
@Blauelf and BTW when we say source[arr1[j]] it means we are treating source as an array
Ashraful Islam
@iashraful
Jul 27 2017 15:12
@JLuboff but it is a good bug, as july 27 should not be 272017
I check
Blauelf
@Blauelf
Jul 27 2017 15:12
@a7n007 Like
if (collection[i].hasOwnProperty(arr1[j]) && collection[i][arr1[j]] === source[arr1[j]]) {
  /* property has right value */
} else {
  /* skip that item, property is wrong */
}
@a7n007source is an object, and we are using bracket notation for accessing properties.
Jason Luboff
@JLuboff
Jul 27 2017 15:13
@iashraful Fair enough, but if you can make it work, then all the better :D
Ashraful Islam
@iashraful
Jul 27 2017 15:13
@a7n007 you can use fancy filter and every to solve wherearttho, I solved it like this

function whatIsInAName(collection, source) {
  // What's in a name?

  return collection.filter(function(el) {
    return Object.keys(source).every(function(key) {
       return (el[key] && el[key] === source[key]);
    });
  });
}

whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
@Blauelf which source you are asking for?
I am confused
Blauelf
@Blauelf
Jul 27 2017 15:14
@iashraful Is it intended to give unix timestamp in Javascript format (milliseconds rather than seconds)?
Ashraful Islam
@iashraful
Jul 27 2017 15:14
@Blauelf wait, I check
Nazar Maksymchuk
@MANTENN
Jul 27 2017 15:15
https://codepen.io/mantenn/pen/eRxwVg - help with eventlisteners - not attaching only executing
Blauelf
@Blauelf
Jul 27 2017 15:15
@iashraful Gitter name autocomplete loves recency over name similarity. :/
@iashraful The reference implementation seems to use seconds (like unix standard) and not Javascript's milliseconds
Jason Luboff
@JLuboff
Jul 27 2017 15:20
@Blauelf You're correct, it should be using Unix time.
odm275
@odm275
Jul 27 2017 15:20
In the twitch app, how does one deal with the case where the user does not exist?
the api information differentiate between offline and does not exist
Blauelf
@Blauelf
Jul 27 2017 15:21
@JLuboff JavaScript's time also is unix time, just using milliseconds. Because they can (with 64 bit floating point compared to 32 bit integer standard unix timer. 2038, we come!)
a7n007
@a7n007
Jul 27 2017 15:22
@iashraful i didnt understand your code can you please explain it or comment it
Ashraful Islam
@iashraful
Jul 27 2017 15:23
@a7n007 it is just doing the loop things in shorter syntax
array.prototype.filter => will loop through all your array element and run the callback() to check if true or false is returned
for any element callback is false, that is usually removed
so you get a new array with all elements back but ones that failed the test you put in callback
the array.prototype.every will only return true if all elements in the array passes the test
the good thing about every is, as soon as a test is failed, it doesn't run anymore, and immediately stops returning false, which is fancy saving of resource
:D
Jason Luboff
@JLuboff
Jul 27 2017 15:26
@Blauelf Better set a reminder for myself for Jan 18, 2038 to fix all my timestamps :joy:
Ashraful Islam
@iashraful
Jul 27 2017 15:26
@JLuboff yes, apparently, when I worked in android it became a big deal and then it become no problem as everyone decided that, devices will be 64bit by default then
:D
Blauelf
@Blauelf
Jul 27 2017 15:29
I doubt that. Maybe for android devices, but many embedded devices are there for 10-20 years or even longer. They might run into the issue. I would assume that current cars (then vintage) might have problems in 2038. I'd hope this affects only the navigation and entertainment systems.
Ashraful Islam
@iashraful
Jul 27 2017 15:30
@Blauelf or we could be freaking out for nothing, just like the y2k bug
Blauelf
@Blauelf
Jul 27 2017 15:30
It's not just that you have to have a 64 bit counter in your system, also all the protocols need to be updated, in many cases creating breaking changes.
Ashraful Islam
@iashraful
Jul 27 2017 15:31
@JLuboff fixed, now it should be handling shiny format you tested with
for unix epoc thing, I am confused
@Blauelf this epoc converter https://www.epochconverter.com/ and the api returns same result
odm275
@odm275
Jul 27 2017 15:32
anyone know how to differenciate between the offline and channel does not exist case on twitch app?
Blauelf
@Blauelf
Jul 27 2017 15:32
@iashraful The y2k bug broke some debit cards in Germany. In 1999, some bank decided to mask the problem by internally storing year-10, and doing shifting when communicating. This hack was forgotten when 2010 came.
Ashraful Islam
@iashraful
Jul 27 2017 15:33
@Blauelf 2038 is a long time from now, we will see massive upgrades, I still doubt anything(program) made today will be maintained till then
I don't see windows 98 anymore
dyon3334
@dyon3334
Jul 27 2017 15:34
im done with javascriot on cedecamp can someone send me good videos to check to bring it to the enxt level ?
Ashraful Islam
@iashraful
Jul 27 2017 15:34
I rarely see windows xp or vista in some ancient computers
@dyon3334 explain to me what is a closure
:D
a7n007
@a7n007
Jul 27 2017 15:34
@Blauelf still the code is not working
Jason Luboff
@JLuboff
Jul 27 2017 15:34
Windows XP is every where still
Ashraful Islam
@iashraful
Jul 27 2017 15:34
^ nope
Jason Luboff
@JLuboff
Jul 27 2017 15:34
Most ATM's still run XP embedded..
Ashraful Islam
@iashraful
Jul 27 2017 15:34
but IE is still haunting us :worried:
I go start writing front end stuff in fancy libs, and next thing I know, manager calls in to report that, one of the big customers use microsoft enterprise thingy and all their office people use IE
Blauelf
@Blauelf
Jul 27 2017 15:35
@JLuboff Recently found a screen on a train stating "Copyright by Microsoft 1985-1993". That one was not running XP I guess.
Jason Luboff
@JLuboff
Jul 27 2017 15:36
:joy:
Joel Y.
@zapcannon99
Jul 27 2017 15:36
@iashraful If he doesn't get to you, https://www.w3schools.com/js/js_function_closures.asp
Andrew Robida
@arobida
Jul 27 2017 15:36
function truncateString(str, num) {
  // Clear out that junk in your trunk
  str=str.concat('...').slice(0, num);
  return str.concat('...');
}

truncateString("Absolutely Longer", 2);
any body understand?
why is this not working my results end up being 1 letter off
Ashraful Islam
@iashraful
Jul 27 2017 15:36
@zapcannon99 dang, I know closures, was asked at interview :smile: was just asking as he said he is all done with js
Jason Luboff
@JLuboff
Jul 27 2017 15:37
@arobida You have three different cases you should be accounting for
Ashraful Islam
@iashraful
Jul 27 2017 15:38
@arobida IIRC slice end index is not inclusive
dyon3334
@dyon3334
Jul 27 2017 15:38
@iashraful a closure is a module that you made in your script a module that you acces only when you needed ithis is great if you want to have your code private
Joel Y.
@zapcannon99
Jul 27 2017 15:38
Oops, my bad @iashraful
Ashraful Islam
@iashraful
Jul 27 2017 15:38
@dyon3334 apparently what you said is very new to me
Joel Y.
@zapcannon99
Jul 27 2017 15:38
What happens when I don't read the whole thread.
Ashraful Islam
@iashraful
Jul 27 2017 15:38
:worried:
Blauelf
@Blauelf
Jul 27 2017 15:38
@arobida First slice (with num or num-3, depending on num), then concat. And truncate only if truncation is necessary!
abraham anak agung
@padunk
Jul 27 2017 15:38
@odm275 if you try https://wind-bow.glitch.me/twitch-api/users/asdfasdfadf, it will throw an error, that user does not exist
dyon3334
@dyon3334
Jul 27 2017 15:40
@iashraful its just a object where you have stored all your functions so you amde only the necessary code public
Andrew Robida
@arobida
Jul 27 2017 15:41
@Blauelf that is why is concated twice so I would not have to use num-3
Blauelf
@Blauelf
Jul 27 2017 15:41
@JLuboff The machine promoting newly launched Windows 7 back then was powered by Windows XP with IE6 installed (I think even then IE8 or 9 was probably most recent version).
odm275
@odm275
Jul 27 2017 15:42
@padunk thank you! Just what i needed
CamperBot
@camperbot
Jul 27 2017 15:42
odm275 sends brownie points to @padunk :sparkles: :thumbsup: :sparkles:
:cookie: 380 | @padunk |http://www.freecodecamp.com/padunk
abraham anak agung
@padunk
Jul 27 2017 15:42
anybody want give me a hint on TicTacToe? what is the good algo for this? I got the ai first move so far.
Blauelf
@Blauelf
Jul 27 2017 15:43
@arobida 1. you always add ellipses and truncate, which is wrong. 2. That would give you between 3 and 6 dots at the end. You need exactly three, and the final length depends on num (for num<=3, the ellipses don't count against num, for num>3, they do)
Andrew Robida
@arobida
Jul 27 2017 15:43
@Blauelf
function truncateString(str, num) {
  // Clear out that junk in your trunk
  str=str.slice(0, num-3);
  return str.concat('...');
}

truncateString("Absolutely Longer", 2);

gives you this function truncateString(str, num) {
  // Clear out that junk in your trunk
  str=str.slice(0, num-3);
  return str.concat('...');
}

truncateString("Absolutely Longer", 2);
Blauelf
@Blauelf
Jul 27 2017 15:44
@arobida A few ifs and elses might help.
Andrew Robida
@arobida
Jul 27 2017 15:45
@Blauelf nvmd what I just put but thank you I guess no shortcuts even though it did work fcc shut it down the first go round
CamperBot
@camperbot
Jul 27 2017 15:45
arobida sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4539 | @blauelf |http://www.freecodecamp.com/blauelf
Ashraful Islam
@iashraful
Jul 27 2017 15:46
@dyon3334 try out the codewars exercises, they are pretty interesting and you get to learn neat tricks :D
once you reach kata level 5 or 4 you will be thinking in real js
Blauelf
@Blauelf
Jul 27 2017 15:47
@iashraful On codewars, you also learn completely useless stuff like code golf :P
Ashraful Islam
@iashraful
Jul 27 2017 15:49
@Blauelf nah, it is really fancy, I just watch people's mad regexp skills and my brain explodes
there are some neat algorithms now and then if you know whose solution to look at :D
Blauelf
@Blauelf
Jul 27 2017 15:49
JavaScript does not even have recursive regular expressions. And no lookback, only lookahead.
Ashraful Islam
@iashraful
Jul 27 2017 15:51
:D regexp is the arcane knowledge of magic and wizardry
Blauelf
@Blauelf
Jul 27 2017 15:52
Like that test whether the number of "x" in a string is a power of 2. With recursion, no problem. Without, your regular expression gets longer for every number you want to support.
Ashraful Islam
@iashraful
Jul 27 2017 15:54
I did not find such usage so far
most regexp is used more or less for validation
Blauelf
@Blauelf
Jul 27 2017 15:56
After 1kyuu, is there a 1dan?
Ashraful Islam
@iashraful
Jul 27 2017 15:57
?
Blauelf
@Blauelf
Jul 27 2017 15:58
On codewars, there's 級 kyuu (student's ranks). I wonder whether there's also 段 dan (master's rank).
Ashraful Islam
@iashraful
Jul 27 2017 15:58
no idea
John
@AnonymousLords
Jul 27 2017 15:59
:point_up: July 27, 2017 12:04 AM so i couldn't just pick two pistons to reverse?
Thanks @heroiczero @stanley-su
CamperBot
@camperbot
Jul 27 2017 16:00
anonymouslords sends brownie points to @heroiczero and @stanley-su :sparkles: :thumbsup: :sparkles:
:cookie: 93 | @stanley-su |http://www.freecodecamp.com/stanley-su
:star2: 1538 | @heroiczero |http://www.freecodecamp.com/heroiczero
kumquatfelafel
@kumquatfelafel
Jul 27 2017 16:03
@Blauelf I've seen a few users with 1 dan
Jason Luboff
@JLuboff
Jul 27 2017 16:08
@kumquatfelafel Jeez...and they've only been a member since the beginning of the year
Ashraful Islam
@iashraful
Jul 27 2017 16:08
must be relative to tony stark
:D
Datikzz
@Datikzz
Jul 27 2017 16:09
guys, how to find everything after character :, and : is excluded ?
here is my regex /\:(.*)/g
Blauelf
@Blauelf
Jul 27 2017 16:14
Who is tony stark? Related to Eddard Stark?
Ashraful Islam
@iashraful
Jul 27 2017 16:16
could be
AmelZekovic
@AmelZekovic
Jul 27 2017 16:16
Hi all, i need some help with some homework and i am stuck
Blauelf
@Blauelf
Jul 27 2017 16:16
@Datikzz Try /(?::).*/ (?: marks non-capturing group. Unlike a lookback/lookahead, it does consume characters.)
Christopher McCormack
@cmccormack
Jul 27 2017 16:16
@Datikzz you could just do slice(1) on the result of the regex
AmelZekovic
@AmelZekovic
Jul 27 2017 16:16
it should display the index of chosen car instead the text Click
Ashraful Islam
@iashraful
Jul 27 2017 16:18
@AmelZekovic looks like working
I clicked button and it says 0
AmelZekovic
@AmelZekovic
Jul 27 2017 16:19
@iashraful it is working but instead of Click it should display the index and not go to other page
it should change the content of div with id result from Click to index
Ashraful Islam
@iashraful
Jul 27 2017 16:19
@AmelZekovic so basically if I change it, it'll just display index, there should be no clicky me!! text?
AmelZekovic
@AmelZekovic
Jul 27 2017 16:20
@iashraful yes
and the combo box would still be visible so you could change to other car and get different index
Ashraful Islam
@iashraful
Jul 27 2017 16:20
add the change event listener and update index
^
Blauelf
@Blauelf
Jul 27 2017 16:20
@AmelZekovic Then don't attach it to that field's click listener, but to the dropdown's change listener.
Datikzz
@Datikzz
Jul 27 2017 16:21
@Blauelf meh, doesnt work http://regexr.com/3gekv
Ashraful Islam
@iashraful
Jul 27 2017 16:22
@AmelZekovic here I updated it, check
should show index if you change dropdown item
Blauelf
@Blauelf
Jul 27 2017 16:22
@Datikzz Have you tried it in JS?
Datikzz
@Datikzz
Jul 27 2017 16:23
yeah
AmelZekovic
@AmelZekovic
Jul 27 2017 16:23
@iashraful thank you very much, i am gonna study this :D
CamperBot
@camperbot
Jul 27 2017 16:23
amelzekovic sends brownie points to @iashraful :sparkles: :thumbsup: :sparkles:
:cookie: 584 | @iashraful |http://www.freecodecamp.com/iashraful
Ashraful Islam
@iashraful
Jul 27 2017 16:24
@AmelZekovic everything that existed as onEventName is an event
there was a bug, I misspelled evt to event
tho, it is strange how that worked because event was unknown in that fn
AmelZekovic
@AmelZekovic
Jul 27 2017 16:28
@iashraful Javascript works in mysterious ways :D
Abhinav Mishra
@abhinav-m
Jul 27 2017 16:31
@Blauelf
Im struggling to understand this function involving template literals
function template(strings, ...keys) {
  return (function(...values) {
    var dict = values[values.length - 1] || {};
    var result = [strings[0]];
    keys.forEach(function(key, i) {
      var value = Number.isInteger(key) ? values[key] : dict[key];
      result.push(value, strings[i + 1]);
    });
    return result.join('');
  });
}

var t1Closure = template`${0}${1}${0}!`;
t1Closure('Y', 'A');  // "YAY!"
var t2Closure = template`${0} ${'foo'}!`;
t2Closure('Hello', {foo: 'World'});  // "Hello World!"
what i don't understand is this part
the strings[0] contains ! according to my understanding
that means successive values should be pushed after it, then why is it outputting YAY!
shouldn't it be !YAY
Blauelf
@Blauelf
Jul 27 2017 16:33
The ! is in the last element of strings. Why should it be at the start?
dyon3334
@dyon3334
Jul 27 2017 16:34
imlooking for something in between codecamp and codewars who can help me ? with videos ebooks links etc
Abhinav Mishra
@abhinav-m
Jul 27 2017 16:34
@Blauelf The first argument of a tag function contains an array of string values.
Datikzz
@Datikzz
Jul 27 2017 16:34
add egghead to your list
Abhinav Mishra
@abhinav-m
Jul 27 2017 16:34
umm.. the previous example had only the string part passed ino the string
Blauelf
@Blauelf
Jul 27 2017 16:35
@abhinav-thinktank In your case, with "YAY!" this should be ["", "", "", "!"]
Abhinav Mishra
@abhinav-m
Jul 27 2017 16:35
@Blauelf OOOOOOH
so the dollar operator acts as a placeholder for the split

function myTag(strings, personExp, ageExp) {

  var str0 = strings[0]; // "that "
  var str1 = strings[1]; // " is a "

  // There is technically a string after
  // the final expression (in our example),
  // but it is empty (""), so disregard.
  // var str2 = strings[2];

  var ageStr;
  if (ageExp > 99){
    ageStr = 'centenarian';
  } else {
    ageStr = 'youngster';
  }

  return str0 + personExp + str1 + ageStr;

}

var output = myTag`that ${ person } is a ${ age }`;
in this one the strins were that and is a
Blauelf
@Blauelf
Jul 27 2017 16:36
@abhinav-thinktank ${} mark the keys, and the strings are the stuff around the keys.
Abhinav Mishra
@abhinav-m
Jul 27 2017 16:36
strings*
@Blauelf thanks!
CamperBot
@camperbot
Jul 27 2017 16:37
abhinav-thinktank sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4540 | @blauelf |http://www.freecodecamp.com/blauelf
Abhinav Mishra
@abhinav-m
Jul 27 2017 16:37
:D
Christopher McCormack
@cmccormack
Jul 27 2017 16:37
@Blauelf @abhinav-thinktank thanks I haven't used template literals in this way so I've learned a bit too :D
CamperBot
@camperbot
Jul 27 2017 16:37
cmccormack sends brownie points to @blauelf and @abhinav-thinktank :sparkles: :thumbsup: :sparkles:
:cookie: 431 | @abhinav-thinktank |http://www.freecodecamp.com/abhinav-thinktank
:star2: 4541 | @blauelf |http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Jul 27 2017 16:37
So anything less or equal 99 years old is a youngster?
Abhinav Mishra
@abhinav-m
Jul 27 2017 16:38
hehe, an example from MDN
Christopher McCormack
@cmccormack
Jul 27 2017 16:40
@Blauelf to a centenarian an 80yo may seem young :D
Abhinav Mishra
@abhinav-m
Jul 27 2017 16:40
aah, also i seem to have missed this part
There is technically a string after // the final expression (in our example), // but it is empty (""), so disregard. // var str2 = strings[2];
Christopher McCormack
@cmccormack
Jul 27 2017 16:42
that makes sense, often splitting will create empty strings on the head/tail
Abhinav Mishra
@abhinav-m
Jul 27 2017 16:42
does it?
in a normal string as well?
Blauelf
@Blauelf
Jul 27 2017 16:42
Try " ".split(" ")
Christopher McCormack
@cmccormack
Jul 27 2017 16:43
> 'test'.split('test')
[ '', '' ]
oops pretty much same example lol
Blauelf
@Blauelf
Jul 27 2017 16:43
Or even 'test'.split('t') => ["", "es", ""]
Abhinav Mishra
@abhinav-m
Jul 27 2017 16:43
oooh, just ran it in the console.
how come i never noticed this while solving the fcc challenges..
Blauelf
@Blauelf
Jul 27 2017 16:44
Omitting the empty strings might mess up with indices.
GeorgeII
@GeorgeII
Jul 27 2017 16:49
Hello! Can someone help me? I need to know why my js code doesn't work. On button press should return current value plus 1 https://codepen.io/GeorgeIV/pen/BdyQWq?editors=1010
I think this pointer in jquery functions works wrong
Jason Luboff
@JLuboff
Jul 27 2017 16:52
@GeorgeII Why are you using setTime?
GeorgeII
@GeorgeII
Jul 27 2017 16:53
?
Cause I need to increase or decrease a value
Darth Skywalker
@AdiSkywalker
Jul 27 2017 16:54
@GeorgeII this.val is wrong
it should be $(this).val()
Jason Luboff
@JLuboff
Jul 27 2017 16:54
Why not just increment the value?
Darth Skywalker
@AdiSkywalker
Jul 27 2017 16:54
either $(this).val() or this.value
GeorgeII
@GeorgeII
Jul 27 2017 16:56
@AdiSkywalker ty. But why it always returns 1? It should return 1, 2 ...
CamperBot
@camperbot
Jul 27 2017 16:56
georgeii sends brownie points to @adiskywalker :sparkles: :thumbsup: :sparkles:
:cookie: 246 | @adiskywalker |http://www.freecodecamp.com/adiskywalker
Darth Skywalker
@AdiSkywalker
Jul 27 2017 16:56
@GeorgeII Sorry. You need to target your right-input and left-input text boxes instead of $(this)
I misread your code
hold on
Christopher McCormack
@cmccormack
Jul 27 2017 16:57
value isn't global
GeorgeII
@GeorgeII
Jul 27 2017 16:57
@JLuboff I don't need to always increment it
Darth Skywalker
@AdiSkywalker
Jul 27 2017 16:57
It should be like this @GeorgeII
$(function() {
  $("#upper-button-left").click(function() {
    var theClass = $(this).attr('class');
    $("#left-input").val(setTime($("#left-input").val(), theClass));
  });

  $("#lower-button-left").click(function() {
    var theClass = $(this).attr('class');
    $("#left-input").val(setTime($("#left-input").val(), theClass));
  });

  $("#upper-button-right").click(function() {
    var theClass = $(this).attr('class');
    $("#right-input").val(setTime($("#right-input").val(), theClass));
  });

  $("#lower-button-right").click(function() {
    var theClass = $(this).attr('class');
    $("#right-input").val(setTime($("#right-input").val(), theClass));
  });
})
GeorgeII
@GeorgeII
Jul 27 2017 16:57
sometimes it should be decremented
Jason Luboff
@JLuboff
Jul 27 2017 16:58
...in which case you would decrement
GeorgeII
@GeorgeII
Jul 27 2017 16:58
in case of pressing lower arrow
Darth Skywalker
@AdiSkywalker
Jul 27 2017 16:58
Because you're added click handlers to $("#lower-button-right") and the likes. So click upon respective up/down buttons would set this to that button
and you need value from text boxes which are not this
GeorgeII
@GeorgeII
Jul 27 2017 16:59
@AdiSkywalker ok ty again
CamperBot
@camperbot
Jul 27 2017 16:59
georgeii sends brownie points to @adiskywalker :sparkles: :thumbsup: :sparkles:
:warning: georgeii already gave adiskywalker points
GeorgeII
@GeorgeII
Jul 27 2017 17:00
I think I have to add new var for $("#right-input").val()
Darth Skywalker
@AdiSkywalker
Jul 27 2017 17:00
@GeorgeII I'd recommend you cache it. (as a matter of good practice)
GeorgeII
@GeorgeII
Jul 27 2017 17:01
?
explain please
CamperBot
@camperbot
Jul 27 2017 17:01

freeCodeCamp Wiki:

:point_right: The freeCodeCamp wiki can be found on our forum.
Please follow the link and search there.
Darth Skywalker
@AdiSkywalker
Jul 27 2017 17:01
@GeorgeII
$(function() {
  var $leftInput = $("#left-input");
  var $rightInput = $("#right-input");
  $("#upper-button-left").click(function() {
    var theClass = $(this).attr('class');
    $leftInput.val(setTime($leftInput.val(), theClass));
  });

  $("#lower-button-left").click(function() {
    var theClass = $(this).attr('class');
    $leftInput.val(setTime($leftInput.val(), theClass));
  });

  $("#upper-button-right").click(function() {
    var theClass = $(this).attr('class');
    $rightInput.val(setTime($rightInput.val(), theClass));
  });

  $("#lower-button-right").click(function() {
    var theClass = $(this).attr('class');
    $rightInput.val(setTime($rightInput.val(), theClass));
  });
})
Caching means you select an element and store it's reference in a variable somewhere common place so you're not querying the DOM all the time
GeorgeII
@GeorgeII
Jul 27 2017 17:03
@AdiSkywalker that makes sense. ty
CamperBot
@camperbot
Jul 27 2017 17:03
:warning: georgeii already gave adiskywalker points
georgeii sends brownie points to @adiskywalker :sparkles: :thumbsup: :sparkles:
GeorgeII
@GeorgeII
Jul 27 2017 17:04
using of $ in caching vars is also a good practice?
Kshitijaa Jaglan
@KshitijaaJaglan
Jul 27 2017 17:08
why is it displaying the message TypeError- str.slice is not a function

function truncateString(str, num) {
  var strslice="";
  if(num>=str.length-3){
    strslice=str; 
  }
  else if(str.length<=3){
    strslice=str;
  }
  else{
  strslice = str.slice(0,num-3)+"...";
  }

  return strslice;
}
truncateString("A-tisket a-tasket A green and yellow basket".length, 11);
GeorgeII
@GeorgeII
Jul 27 2017 17:10
And the last question: I read that regexp usage in html code is deprecated. So how should I replace this code var isUpperButton = buttonClass.match(/upper/gi);?
Joel Y.
@zapcannon99
Jul 27 2017 17:11
@KshitijaaJaglan You passed truncateString a number, not a string
Last line
Andrew Robida
@arobida
Jul 27 2017 17:11
@Blauelf thanx man here is my ugly ass solution
function truncateString(str, num) {
  // take slice the string by the num
  if(str.length<=num) {
    return str;
  } if(num>=3) {
    str=str.slice(0, num-3);
    return str.concat('...');
  } else {
    str=str.slice(0, num);
    return str.concat('...');
  }
  // if num is equal to the total str.length do not add ...
  // if num is not equal to total str.length add ...
}

truncateString("A-", 1);
Its ugly but this shit works
CamperBot
@camperbot
Jul 27 2017 17:11
arobida sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4542 | @blauelf |http://www.freecodecamp.com/blauelf
Kshitijaa Jaglan
@KshitijaaJaglan
Jul 27 2017 17:13
thanks @zapcannon99 it worked
CamperBot
@camperbot
Jul 27 2017 17:13
kshitijaajaglan sends brownie points to @zapcannon99 :sparkles: :thumbsup: :sparkles:
:cookie: 323 | @zapcannon99 |http://www.freecodecamp.com/zapcannon99
Joel Y.
@zapcannon99
Jul 27 2017 17:13
welcome
kumquatfelafel
@kumquatfelafel
Jul 27 2017 17:14
@arobida note that return str.concat('...'); is present in both of your lower conditions. You can move this return statement to after the else block and only have one of them.
John
@AnonymousLords
Jul 27 2017 17:15
starting basic algorithm scripting :D
Joel Y.
@zapcannon99
Jul 27 2017 17:15
It will be fun
John
@AnonymousLords
Jul 27 2017 17:15
their hard ;-;
most likely
Is the first challenge hard?
Joel Y.
@zapcannon99
Jul 27 2017 17:16
you'll be fine
Joel Y.
@zapcannon99
Jul 27 2017 17:16
I have a number of years programming, so, I don't think so
John
@AnonymousLords
Jul 27 2017 17:16
im doing it later, just finished up object orinated this morning
Jason Luboff
@JLuboff
Jul 27 2017 17:16
@AnonymousLords They give you all the tools necessary to accomplish it under the helpful links
Joel Y.
@zapcannon99
Jul 27 2017 17:17
:point_up: Very true.
John
@AnonymousLords
Jul 27 2017 17:17
Okay thanks @JLuboff @zapcannon99 @AnonymousLords
CamperBot
@camperbot
Jul 27 2017 17:17
anonymouslords sends brownie points to @jluboff and @zapcannon99 :sparkles: :thumbsup: :sparkles:
:star2: 2114 | @jluboff |http://www.freecodecamp.com/jluboff
:cookie: 324 | @zapcannon99 |http://www.freecodecamp.com/zapcannon99
John
@AnonymousLords
Jul 27 2017 17:17
ill do it tonight.
kumquatfelafel
@kumquatfelafel
Jul 27 2017 17:17

@arobida I'd also point out that your condition, num>=3 isn't quite correct. Check instructions.

if the given maximum string length num is less than or equal to 3, then the addition of the three dots does not add to the string length

If something is not less than or equal to three, then does that mean it is greater than or equal to three?

Kshitijaa Jaglan
@KshitijaaJaglan
Jul 27 2017 17:19
One more help @zapcannon99 why isn't this returning A...

function truncateString(str, num) {
  var strslice="";
  if(num>=str.length-3){
    strslice=str; 
  }
  else if(num<=3){
    strslice=str.slice(0,num)+"...";
  }
  else{
  strslice = str.slice(0,num-3)+"...";
  }

  return strslice;
}

truncateString("A-", 1);
It is returning A-
Andrew Robida
@arobida
Jul 27 2017 17:20
@kumquatfelafel I see that and it worked? I passed it
@kumquatfelafel also not sure what you mean by the one str.concat() return statement
kumquatfelafel
@kumquatfelafel
Jul 27 2017 17:21
@arobida You passed because, in spite of the what was said in instructions, it doesn't actually have a test for when num = 3. Which surprises me.
@KshitijaaJaglan With slice, the end index is excluded.
Joel Y.
@zapcannon99
Jul 27 2017 17:23
@KshitijaaJaglan The first condition you set is making it so that strslice is = A-, if that's not what you want, you'll need to reevaluate your conditions
Kshitijaa Jaglan
@KshitijaaJaglan
Jul 27 2017 17:24
ohk. Changing the order did it.
Joel Y.
@zapcannon99
Jul 27 2017 17:24
str.length - 3 => 2-3 = -1, so 1 >= -1 => strslice = str="A-"
Kshitijaa Jaglan
@KshitijaaJaglan
Jul 27 2017 17:25
ty @kumquatfelafel and @zapcannon99
CamperBot
@camperbot
Jul 27 2017 17:25
kshitijaajaglan sends brownie points to @kumquatfelafel and @zapcannon99 :sparkles: :thumbsup: :sparkles:
:warning: kshitijaajaglan already gave zapcannon99 points
:cookie: 546 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
kumquatfelafel
@kumquatfelafel
Jul 27 2017 17:25
@KshitijaaJaglan sorry misread. @zapcannon99 correct.
Andrew Robida
@arobida
Jul 27 2017 17:25
@kumquatfelafel I do not think you were reading my code correctly it is correct and I tried one return statement with that and it did not work had I stored that result in a var yes it could work
kumquatfelafel
@kumquatfelafel
Jul 27 2017 17:26

also not sure what you mean by the one str.concat() return statement

@arobida consider: instead of ...

if ( blah ) {
   b = 7;
   return b;
} else {
   b = 9;
   return b;
}

we can do

if (blah) {
  b = 7;
} else {
  b = 9;
}
return b;

Since these return statements are identical.

Datikzz
@Datikzz
Jul 27 2017 17:27

a b: c and blah blah.

how with regex extract value starting from c?

AmelZekovic
@AmelZekovic
Jul 27 2017 17:28
@iashraful hey, are you still online?
Andrew Robida
@arobida
Jul 27 2017 17:29
@kumquatfelafel okay so if the first condition is true it will return the proper result even with no return statemnet
GeorgeII
@GeorgeII
Jul 27 2017 17:30
maybe this one will help?
@Datikzz ok I misunderstood you
Alex
@alexandrupintilei
Jul 27 2017 17:31
function diffArray(arr1, arr2) {
   var newArr = []; 

for (var i = 0; i < arr1.length; i++){
    console.log(arr1[i]);
}
  var arr3 = arr1.concat(arr2);
      console.log(arr3);           // check if code works

  if(arr3.indexOf(4) > 0){
     var newArr = arr3.filter(function(arr4){
        newArr.push(4);
});
 }
     console.log(newArr);                     
}
diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
Compare two arrays and return a new array with any items only found in one of the two given arrays, but not both. In other words, return the symmetric difference of the two arrays.
Help!
GeorgeII
@GeorgeII
Jul 27 2017 17:32
@Datikzz you can also use indexOf() and substring() functions
Joel Y.
@zapcannon99
Jul 27 2017 17:35
@alexandrupintilei I am confused with the way you approached it. Why are you combining the arrays?
@alexandrupintilei How about you just iterate through one of the array and check if the number exists in the other array and if not, then throw it into newArr?
You seem to have all the pieces.
Alex
@alexandrupintilei
Jul 27 2017 17:43

@zapcannon99
function diffArray(arr1, arr2) {
var newArr = [];

for (var i = 0; i < arr1.length; i++){
console.log(arr1[i]);
var newArr = arr1.concat(arr2);
console.log(newArr); //Check if code is work
if(newArr[i].indexOf(7) === 4){
newArr.push(4);
}
}
console.log(newArr);
}
diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);

@zapcannon99
function diffArray(arr1, arr2) {
   var newArr = []; 

for (var i = 0; i < arr1.length; i++){
    console.log(arr1[i]);
    var newArr = arr1.concat(arr2);
      console.log(newArr);    //Check if code is work
  if(newArr[i].indexOf(7) === 4){
    newArr.push(4);
  }
}
     console.log(newArr);                     
}
diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);
whats wrong?
Joel Y.
@zapcannon99
Jul 27 2017 17:45
I don't think you are using indexOf 7 right
indexOf(7)* i mean
I guess I just don't understand what you are trying to do after var newArr=arr1.concat(arr2);
Markus Kiili
@Masd925
Jul 27 2017 17:48
@zapcannon99 One way to solve it is to concat the arrays and remove those values that are not single.
But doesn't look like that is happening here.
Marcus Parsons
@marcusparsons
Jul 27 2017 17:50
@Datikzz, if you want to find all matches for a particular character, you can run this function I created:
var str = "a b: c da3yy";
function getFrom (char, str) {
    return str.match(new RegExp("(?=" + char + ").+", "i"));
}
//And then call the it
var result = getFrom("c", str);
//And output it:
console.log(result[0]);
//Output:  "c da3yy"
kumquatfelafel
@kumquatfelafel
Jul 27 2017 17:50

@arobida I promise you that I'm reading your code correctly. :p It works properly for all cases except for num = 3, which in your algorithm returns as "...", but is supposed to return as, e.g., "A-t..." (assuming "A-tisket" yadayadayada string). That is, your condition for boundary is incorrect. It should not behave such a way when num >= 3, but when num > 3. Remember, > is essentially equivalent to "is a number not less than and not equal to". As noted in instructions, when num <= 3, the ... doesn't count in string length.

It's not really your fault here. They should have a test case for when num is 3, since code is far more likely to have a mistake at a boundary.

Joel Y.
@zapcannon99
Jul 27 2017 17:50
@Masd925 I understand that. And I agree, it's not really getting anywhere.
Ghulam Shabir
@ghulamshabir
Jul 27 2017 17:50
 @alexandrupintilei you should not concat the two arrays inside the loop, you should concatenate them before loop/filter. if you have solved Seek and Destroy using filter then think of concated array like arr of that challenge and arr1 and arr2 like two numbers
surferpilgrim
@surferpilgrim
Jul 27 2017 17:52

say I have two arrays

var arr=[1,2,3,4]
var arr2=[5,10,15,20,60]

and I want the 2nd array to be divided by each value of the first array

[5/4,5/3,5/2,5/1]
[10/4,10/3,10/2,10/1]
[15/4,15/3,15/2,15/1]
[20/4,20/3,20/2,20/1]
[60/4,60/3,60/2,60/1]

after this calculation I'd return an array for all the values that have remainders

var remainArr=[5,10,15,20]

how do i do this

Marcus Parsons
@marcusparsons
Jul 27 2017 17:53
@surferpilgrim, embedded for loop with the upper level being arr2 and the inside loop being arr and run a modulus on the two values and if that modulus returns something other than 0, push to an array. Badabing badaboom
Joel Y.
@zapcannon99
Jul 27 2017 17:54
@alexandrupintilei
Since I need to leave soon, I'll list things I think you should consider
  • Like @ghulamshabir said, concat before the loop
  • if you are going to do what @Masd925 said, you'll need to ensure that you actually find a second number
  • There is no reason to push if you are doing what @Masd925 said
Alex
@alexandrupintilei
Jul 27 2017 17:57
@zapcannon99 thx
CamperBot
@camperbot
Jul 27 2017 17:57
alexandrupintilei sends brownie points to @zapcannon99 :sparkles: :thumbsup: :sparkles:
:cookie: 325 | @zapcannon99 |http://www.freecodecamp.com/zapcannon99
Joel Y.
@zapcannon99
Jul 27 2017 17:58
@alexandrupintilei Don't forget the other two :)
surferpilgrim
@surferpilgrim
Jul 27 2017 17:58
@marcusparsons thanks Ima try that
CamperBot
@camperbot
Jul 27 2017 17:58
surferpilgrim sends brownie points to @marcusparsons :sparkles: :thumbsup: :sparkles:
:cookie: 435 | @marcusparsons |http://www.freecodecamp.com/marcusparsons
Marcus Parsons
@marcusparsons
Jul 27 2017 17:59
@surferpilgrim, not a problem!
Manuel Moya
@moyamanuel
Jul 27 2017 18:00
function destroyer(arr) {
  // Remove all the values
  var numArr = arguments[0].slice(0);
  var destroyArr = [];

  for (var i=1;i < arguments.length;i++) {
    destroyArr.push(arguments[i]);
  }

  var filteredNumArr = numArr.filter(function(num) {
    for (var t=0; t < destroyArr.length;t++) {
      return num !== destroyArr[t];
    }
  });
  return filteredNumArr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Does anyone know why it's not executing the last for loop correctly?
Christopher McCormack
@cmccormack
Jul 27 2017 18:02
@moyamanuel you have a return statement so it will only ever iterate once
Stephen James
@sjames1958gm
Jul 27 2017 18:02
@moyamanuel You are returning in the first pass in your for loop
@moyamanuel Consider indexOf as an alternative to that loop
Manuel Moya
@moyamanuel
Jul 27 2017 18:03
Ah right, the return statement stops execution once it gets a value. Thank you @cmccormack and @sjames1958gm
Stephen James
@sjames1958gm
Jul 27 2017 18:05
@moyamanuel :+1:
stops whichever function it is in.
kumquatfelafel
@kumquatfelafel
Jul 27 2017 18:24
@moyamanuel you could also say return numArr.filter(blahblahblah since you're not actually using filteredNumArr for anything inside the function.
Noremak
@Noremak
Jul 27 2017 18:58
What would be an alternative to the if/else in the follow?
function goalp(x) {
    var goal = 2000;
    var rem = goal - x;
    console.log(rem + " hours until " + goal);
    var percent = x / goal;
    console.log(percent*100 + "% complete");
    if (percent < .1) {
        return "---------";
    } else if (percent >= .1 && percent <.2) {
        return "*---------";
    }
    else if (percent >= .2) {
        return "**--------";
    } else  {
        return null;
}
};
Stephen James
@sjames1958gm
Jul 27 2017 19:02
@Noremak Compute integers from 0-9 rather than fractions. Then you could
Use something like "*".repeat(n) when n > 0
@Noremak Assuming you are doing some sort of progress indicator?
Noremak
@Noremak
Jul 27 2017 19:03
Yeah, just for kicks.
Stephen James
@sjames1958gm
Jul 27 2017 19:04
var n = Math.floor(percent * 10);
return ((n > 0) ? "*".repeat(n) : "") + ((n < 10) ? "-".repeat(10 - n) : "");
Noremak
@Noremak
Jul 27 2017 19:06
Oh cool, thanks! Lots to learn ha
Jamal Ali-Mohammed
@jdaio
Jul 27 2017 19:17
Ugh even the Basic Algorithm Scripting challenges are hard, and I wasn't having any issues with it prior haha. I've had to Google for help more often than not :/
Noremak
@Noremak
Jul 27 2017 19:21
@jdaio Hey Jamal, learning always feels awkward and challenging (at least in my experience). Having to google for help is natural, there is no way for you to just "know" these languages.
Jamal Ali-Mohammed
@jdaio
Jul 27 2017 19:22
Yeah I look up stuff to code for PHP all the time. fCC just made me feel like I didn't need to do it with JavaScript haha
Kelechi Chinaka
@ke1echi
Jul 27 2017 19:32
what string method is used to check for unicode values
CallMeOrange
@EgnaroDev
Jul 27 2017 19:32
.indexOf()?
Kelechi Chinaka
@ke1echi
Jul 27 2017 19:33
no
unicode values
Stephen James
@sjames1958gm
Jul 27 2017 19:34
@kelechy You mean charCodeAt?
Kelechi Chinaka
@ke1echi
Jul 27 2017 19:36
not it
ahh dont know it escape my head
uniTotal("a") == 97 @sjames1958gm
Stephen James
@sjames1958gm
Jul 27 2017 19:37
@kelechy "a".charCodeAt(0) === 97
Kelechi Chinaka
@ke1echi
Jul 27 2017 19:38
bang!
i thought it was one of the static string method
String.fromCharCode() String.fromCodePoint()
ty @sjames1958gm
CamperBot
@camperbot
Jul 27 2017 19:40
kelechy sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8175 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Guderian Raborg
@hypercuber
Jul 27 2017 19:42
Why is the array freq empty:
let arr = [1, 2, 2, 3, 1, 3, 1, 3];

function checkEqualFrequency(arr) {
  let newArr = new Set(arr);
  let freq = [];
  for (let i = 0; i < newArr.length; i++) {
    freq.push(arr.filter(n => n === arr[i]).length);
  }
  return freq;
}
Kelechi Chinaka
@ke1echi
Jul 27 2017 19:43
function uniTotal(string) {
  var unicode = [];
  string.split('').map((element) => {
    unicode.push(element.charCodeAt())
  });
  return unicode.reduce((a, b) => { return a + b }, 0);
}
needed to find unicode total..the names are so similar :smile: @sjames1958gm
Stephen James
@sjames1958gm
Jul 27 2017 19:45
@kelechy You should only do one loop:
string.split('').reduce((a, e) => a + e.charCodeAt(), 0);
Guderian Raborg
@hypercuber
Jul 27 2017 19:45
Oh, newArr is not an array. I need:
let newArr = [...new Set(arr)];
Kelechi Chinaka
@ke1echi
Jul 27 2017 19:47
hmm.nice syntax :+1: @sjames1958gm
one liner kings :smile: @sjames1958gm
Stephen James
@sjames1958gm
Jul 27 2017 19:48
@kelechy :wink:
function sumStrings(a,b) { 
  if (!a) a = 0;
  else if (!b) b = 0;
   var val = parseInt(a)+parseInt(b);
   return val.toString();
}
sumStrings('','456');
Expected: '712577413488402631964821329', instead got: '7.125774134884027e+26'
What should I do :/
@sjames1958gm You showed me the code other day to convert scientific notation to big number, where did you learn it?
Christopher McCormack
@cmccormack
Jul 27 2017 20:00
@EgnaroDev just a suggestion, don't use an else if for b, just use another if
CallMeOrange
@EgnaroDev
Jul 27 2017 20:01
Alright
Michael Kuang
@kuangmichael07
Jul 27 2017 20:16
hey guys I got a question about using ES6 to destruct the 'Event' as an input to a function:
so for example I got:
<input name='a' value={this.state.a} onChange={evt=> this.newFunc(evt)} />
And
newFunc({target: {value}}){//Do Something with {value}}
this work perfectly, but how can I destruct evt, so I can use both {value} and {name} in the newFunc?
Christopher McCormack
@cmccormack
Jul 27 2017 20:19
@kuangmichael07 isn't name an attribute of target?
Michael Kuang
@kuangmichael07
Jul 27 2017 20:19
@cmccormack yes, it is
@cmccormack so are you suggesting using target.name?
@cmccormack cuz value is also an attribute of target, but I don't think target.value would work
Christopher McCormack
@cmccormack
Jul 27 2017 20:23
I believe in your newFunc value is actually the event.target
but I'd have to check my destructuring syntax :D
Jason Luboff
@JLuboff
Jul 27 2017 20:29
@cmccormack Yo
Christopher McCormack
@cmccormack
Jul 27 2017 20:29
@kuangmichael07 here's an example: https://codepen.io/cmccormack/pen/XammMN basically remove your curly braces around value
@JLuboff yo
Jason Luboff
@JLuboff
Jul 27 2017 20:30
Whats crackin'?
Christopher McCormack
@cmccormack
Jul 27 2017 20:31
not much troubleshooting something for work while working on my dungeon project :)
you crackin down on those :fishing_pole_and_fish:
Jason Luboff
@JLuboff
Jul 27 2017 20:31
I still have to come up with an email to send it out in
And I guess either hash or slice the passwords prior to sending them to the DB
Christopher McCormack
@cmccormack
Jul 27 2017 20:34
oh good point, maybe just send the e-mail as the password as well
keep the password front-end only
Jean-Paul Sauve
@jp-sauve
Jul 27 2017 20:34
I'm having trouble with https://www.freecodecamp.org/challenges/validate-us-telephone-numbers
I get most of the validations, but because there's no negative look-behind, I'm not sure how to fit in the other cases. Here's what I've got.

function telephoneCheck(str) {
  var rgx = new RegExp(/^1?\s?\(?(?=\d{3})\d{3}(?!([\(][\d]).|^)\)?[ -]*\d{3}[ -]?\d{4}$/,'g');
  var mymatch = str.match(rgx);
  console.log(mymatch);
  if (mymatch) {
  return true;
  }
  return false;
}
Jason Luboff
@JLuboff
Jul 27 2017 20:35
@cmccormack Thing is..I want at least part of the password. Otherwise, they'll just argue that someone else put in the email, but if we have part/all of the password...they can't argue it as easily
Christopher McCormack
@cmccormack
Jul 27 2017 20:38
maybe just send password[0], password[password.length-1]?
Jason Luboff
@JLuboff
Jul 27 2017 20:39
Ya that or just slice the first or lsat 4 characters
Christopher McCormack
@cmccormack
Jul 27 2017 20:40
just be careful, could be dangerous. Maybe instead do a password hash that they can then test against internally with a tool
You probably don't want to store any of their password, I would recommend against it