These are chat archives for FreeCodeCamp/HelpJavaScript

21st
Aug 2017
Joseph Henshaw
@Big-jo
Aug 21 2017 01:00
I have a google map on my page and i used jquery hide method on in and when i use the the fadeIn method on it the map appears but just blank.
bitcoinabdi
@bitcoinabdi
Aug 21 2017 02:00
good evening guyz
quick question how do I transform a JS code into React code?
any help is highly appreciated
@sjames1958gm Go Chelsea !!
Ogundele Olumide
@Lumexralph
Aug 21 2017 02:17
@bitcoinabdi @sjames1958gm :smirk:
Caleb
@tech4him1
Aug 21 2017 02:18
I'm trying to figure out if an ES6 problem I am running into is a bug or a "feature", should I ask here, or does someone know of a better place?
It's not directly related to FreeCodeCamp.
Ogundele Olumide
@Lumexralph
Aug 21 2017 02:20
@tech4him1 you can still ask
Caleb
@tech4him1
Aug 21 2017 02:21
@Lumexralph I think I just figured it out, thanks anyway.
CamperBot
@camperbot
Aug 21 2017 02:21
tech4him1 sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 2049 | @lumexralph |http://www.freecodecamp.com/lumexralph
Ogundele Olumide
@Lumexralph
Aug 21 2017 02:21
@tech4him1 :+1:
张海峰
@zhanghaifeng213
Aug 21 2017 02:26
请问261题怎么做的啊?
Marc
@MWBauer
Aug 21 2017 02:26
what does str = " " do?
Caleb
@tech4him1
Aug 21 2017 02:27
Just in case it helps anyone else: My problem was trying to useArray(4).fill(Array(4)). fill actually copies the objects, though, so if I changed [0][0], that also changed [1][0], [2][0], and[3][0]`.
Long Nguyen
@longnt80
Aug 21 2017 02:43
Ken Haduch
@khaduch
Aug 21 2017 02:52
@MWBauer - it would set a variable named str to have a value of a string consisting of a single space character. It could be initializing it to a starting value, or to set it during the execution of some code. I would say that it is more typical to initialize it as str = ""; which would be an empty string. But you initialize as dictated by the problem you are trying to solve. :point_up: August 20, 2017 10:26 PM
Bradley Sands
@sandsbe
Aug 21 2017 04:11
anyone familiar with using the bootstrap progress bar??
I can change the aria-valuenow with jQuery .attr('aria-valuenow', newValVar). However, that doesn't actually change the bar display.
Some of the suggestions say I need to use .css along with .attr but that seems duplicative.
Bradley Sands
@sandsbe
Aug 21 2017 04:17
Here's an example that uses the .css. https://bootsnipp.com/snippets/PjyVm
This seems dumb. Why have the values associated with the bar?
Eva May
@qiqiqi7472
Aug 21 2017 06:29
image.png
请问怎么错了,找不出来哪错
Blauelf
@Blauelf
Aug 21 2017 06:56

@qiqiqi7472 Change the variable declarations, don't add new ones. There should be three variable declarations, plus three assignments.

So basically, remove the three variable declarations with the wrong cases, as you've already added those with the right ones.

Also, there's FreeCodeCamp/chinese.

Oh, you've already asked there, too.
Eva May
@qiqiqi7472
Aug 21 2017 07:15
thanks
Jefferson
@jeffersonnnn
Aug 21 2017 08:07

hi guys, i need n00b advice. Seeking for the cleanest way to turn arguments object into an array, i saw this: arguments = Array.prototype.slice.call(arguments); Sliding it into pythontutor.com for live coding, the code editor replied that the syntax possesses null characters. Any help?

TL;DR i need help with => arguments = Array.prototype.slice.call(arguments); for the purpose or argum

^purpose of converting arguments obeject to arrays
Claudio Restifo
@Marmiz
Aug 21 2017 08:10

@jeffersonnnn

var args = Array.prototype.slice.call(arguments);

// ES2015
var args = Array.from(arguments);

Both are valid options :)

Blauelf
@Blauelf
Aug 21 2017 08:10
@sandsbe width CSS property describes the visual appearance, while aria-valuenow describes a meaning, as it could be reported by screenreaders or similar assistive technology. So those are logically connected, but the connection could be non-trivial. For example, maybe you want it to report a progress linearly to screenreaders, but show a bar that's scaled logarithmically. Or you want to set the width in percent, while you should use numbers for the value (which might still be displayed as percent if it makes sense, for example on scrollbars).
Blauelf
@Blauelf
Aug 21 2017 08:17
@jeffersonnnn Works for me in my browser's console. But maybe you shouldn't assign to arguments. Try another name.
Jefferson
@jeffersonnnn
Aug 21 2017 08:33
@Marmiz @Blauelf thanks for the input guys. Can anyone give me an example of it at work? If it is not right form to show a camper this, then its no problem. Also what/how does it return?
CamperBot
@camperbot
Aug 21 2017 08:33
jeffersonnnn sends brownie points to @marmiz and @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 1026 | @marmiz |http://www.freecodecamp.com/marmiz
:star2: 4575 | @blauelf |http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Aug 21 2017 08:37
@jeffersonnnn Stupid example, logging all the arguments one per line.
function logMyArguments() {
    var args = Array.prototype.slice.call(arguments);
    args.forEach(console.log);
}
logMyArguments(["banana", Infinity], {answer: 42}, "FTW", NaN); // logs four times, output might depend on your console.log
Claudio Restifo
@Marmiz
Aug 21 2017 08:56

@jeffersonnnn , since @Blauelf already gave you a great example using the "standard" syntax, I'll provide you with one using a more modern one ( arrow and spread operator)... if you are not confortable with it, simply ignore :) the output is the same

const myArguments = ( ...args ) => {
  var a = Array.from(args); // I can create a new array with the values
  console.log(a)
  console.log([...args]) // or get them with the spread operator
}

myArguments(1, 42, {name: 'test'}, null, [])
// output in console: [ 1, 42, { name: 'test' }, null, [] ]

Hope you don't get confused.
This is just to tell you that both solution are fine

Blauelf
@Blauelf
Aug 21 2017 08:57
@Marmiz args created with rest argument already is an array, unlike arguments
Claudio Restifo
@Marmiz
Aug 21 2017 09:03
@Blauelf yep, my example is pretty useless tbh, it's already an array :)
Huỳnh Trần Khanh
@khanh2003
Aug 21 2017 09:23
[...object]: turn an Array-like object to an Array
[...array]: clone an Array
Blauelf
@Blauelf
Aug 21 2017 09:29
@khanh2003 Not array-like, but iterable.
var arrayLike = { 0: "answer", 1: 42, length: 2 };
console.log([...arrayLike]);
// TypeError: arrayLike is not iterable
Huỳnh Trần Khanh
@khanh2003
Aug 21 2017 09:29
@Blauelf yeah you are right.
Uncaught TypeError: arrayLike[Symbol.iterator] is not a function
Abhinav Mishra
@abhinav-m
Aug 21 2017 09:46
Im making a post request using XMLHttpRequest

function makeRequest(verb, ep) {
    return new Promise((resolve, reject) => {
        var xhr = new XMLHttpRequest();
        const url = 'https://jsonplaceholder.typicode.com/' + ep;
        xhr.open(verb, url);
        xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xhr.onload = () => resolve(xhr.responseText)
        xhr.onerror = () => reject(xhr.responseStatus)

        xhr.send('title=foo&body=bar&userId=1')


    })
}
is there a better way to use title=foo&body=bar&userId=1
using vanilla js
like if i create an object it maps to that format
koder3
@koder3
Aug 21 2017 09:49
is it always good to convert data into JSON before trying to get data from it?
korzo
@korzo
Aug 21 2017 09:54
@koder3 If data source is JSON, then it's the only way to get data from it
Abhinav Mishra
@abhinav-m
Aug 21 2017 09:57
trying to use formData like this , but it is giving me an incorrect response
 var formData = new FormData();
        formData.append('title', 'foo')
        formData.append('body', 'bar')
        formData.append('userId', 'foo')
        xhr.send(formData)
koder3
@koder3
Aug 21 2017 10:05
@korzo thanks. is there any way i can check what format the data source is in ?
CamperBot
@camperbot
Aug 21 2017 10:05
koder3 sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 396 | @korzo |http://www.freecodecamp.com/korzo
korzo
@korzo
Aug 21 2017 10:09
@koder3 Data format is usually mentioned in service documentation.
If you access data source using HTTP, you can check response headers for response format
koder3
@koder3
Aug 21 2017 10:22
@korzo alright. thanks
CamperBot
@camperbot
Aug 21 2017 10:22
koder3 sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:warning: koder3 already gave korzo points
Stephen James
@sjames1958gm
Aug 21 2017 11:15
@abhinav-thinktank How is it incorrect?
WAINGOR
@WAINGOR
Aug 21 2017 11:30
completely off-topic but Im hoping somebody here has experience in dealing with creating custom woocommerce websites
WAINGOR
@WAINGOR
Aug 21 2017 11:38
8*(
rawatdeepesh
@rawatdeepesh
Aug 21 2017 11:55
hello anyone here who could help me with Facebook's Marketing API, thanks
Stephen James
@sjames1958gm
Aug 21 2017 11:57
@rawatdeepesh Try asking a more specific question
rawatdeepesh
@rawatdeepesh
Aug 21 2017 12:01
I am trying to create an ad using the endpoint /adaccount/ads using 'POST' in FB.api() with name,adset_id, access_token of the app with the required permissions, status and creative(which is itself an object : {creative_id:(value returned from previous request) but I get an error
Error:No creative spec found for given adgroup.
Stephen James
@sjames1958gm
Aug 21 2017 12:15
creative:["{\"creative_id\" : \"adcreativeresponse.id /*or a static creative_id*/\"}"],
This look suspicious in that you are not referencing the variable as it is in a string.
Why are you putting the object inside quotes inside the array?
[{creative_id: adcreativeresponse.id}]
rawatdeepesh
@rawatdeepesh
Aug 21 2017 12:16
I passed it other way as well but it did n't help out either
Stephen James
@sjames1958gm
Aug 21 2017 12:19
Did you try without the [] ?
The API docs don't seem to have js examples
rawatdeepesh
@rawatdeepesh
Aug 21 2017 12:21
I actually also tried the same query using the query builder in https://developers.facebook.com/tools/explorer and it gave me the way I posted
creative:["{'creative_id' : 891390182371}"] used this way too
Stephen James
@sjames1958gm
Aug 21 2017 12:29
Have you tried template strings?
`{'creative_id': ${adcreativeresponse.id}}`
Abhinav Mishra
@abhinav-m
Aug 21 2017 12:38
@sjames1958gm xhr.send('title=foo&body=bar&userId=1')
when i used it like this it was working
im guessing the server doesn't accept the other request header type
Ronique Ricketts
@RoniqueRicketts
Aug 21 2017 12:39
Ok
@sjames1958gm
limbu
@limbu
Aug 21 2017 12:46
hi guys i have a js problem
if i wanted to add a disable attribute on an input field whilst the page is loading and be enabled once the page has fully loaded how would i do that?
Abhinav Mishra
@abhinav-m
Aug 21 2017 12:49
you could create classes and swap
korzo
@korzo
Aug 21 2017 12:49
@limbu add disabled in html and after document is ready, remove this attribute with javascript
limbu
@limbu
Aug 21 2017 12:49
ooooh thats nice korzo
and so simple i like it
korzo
@korzo
Aug 21 2017 12:50
@limbu
$(function(){
    $('.inputDisabled').prop("disabled", false);
});
limbu
@limbu
Aug 21 2017 12:52
@korzo i'm going to try that now
@korzo i'll let you know if i come across any problems
Tiago Correia
@tiagocorreiaalmeida
Aug 21 2017 13:03
can someone check my pen and console log and point what im missing? https://codepen.io/tiagocorreia/full/brYpog/
Jefferson
@jeffersonnnn
Aug 21 2017 13:06
hi guys, can anyone tell me how to push items return from a function into an array?
Tiago Correia
@tiagocorreiaalmeida
Aug 21 2017 13:07
sure @jeffersonnnn what do you have?
or what's the idea
Stephen James
@sjames1958gm
Aug 21 2017 13:09
@jeffersonnnn You can call a function as part of the push function call
arr.push(fn());
@abhinav-thinktank Yes it appears that jsonplaceholder doesn't understand that encoding.
Abhinav Mishra
@abhinav-m
Aug 21 2017 13:10
@sjames1958gm ok thanks!
CamperBot
@camperbot
Aug 21 2017 13:10
abhinav-thinktank sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8353 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Tiago Correia
@tiagocorreiaalmeida
Aug 21 2017 13:10
@sjames1958gm hey how are you?
Jefferson
@jeffersonnnn
Aug 21 2017 13:13
N00b question, yeah, but help needed ^
Stephen James
@sjames1958gm
Aug 21 2017 13:13
@tiagocorreiaalmeida good - monday morning here
Tiago Correia
@tiagocorreiaalmeida
Aug 21 2017 13:14
holidays?
Stephen James
@sjames1958gm
Aug 21 2017 13:14
No
@jeffersonnnn this is a simple case: arr.push(fn());
Can you provide more specifics?
Tiago Correia
@tiagocorreiaalmeida
Aug 21 2017 13:18
@sjames1958gm is there anyway to be sure that a element is present on the dom when called?cause I have a tag that if I had a new class to it, it will work but if I dont anything other than that wit hthe tag I get "is not a function" same issue of yesterday ,just came back
Ken Haduch
@khaduch
Aug 21 2017 13:18
@tiagocorreiaalmeida - looks like the way you are using audio isn't correct. audio is probably a jquery handle, and the .addEventListener() is a raw javascript method? At least that's the first error I'm seeing in the console.
Tiago Correia
@tiagocorreiaalmeida
Aug 21 2017 13:19
yeah that can be the issue and how about create a array with the url and do audio = new audio(url)
and then play it
woudl solve it?
Stephen James
@sjames1958gm
Aug 21 2017 13:24
@tiagocorreiaalmeida You are mixing jquery and native Try add [0] to end of your audio =
var audio = $("."+entrys[0]+"audio")[0];
That way audio is a native element
Tiago Correia
@tiagocorreiaalmeida
Aug 21 2017 13:27
Yes I was reading about it was going to create a array of objects and wou.ld play them directly on the js and not using html, it works big thanks @sjames1958gm
CamperBot
@camperbot
Aug 21 2017 13:27
:star2: 8354 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
tiagocorreiaalmeida sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
Jefferson
@jeffersonnnn
Aug 21 2017 14:15
@sjames1958gm @tiagocorreiaalmeida more to a question i asked: after converting the arguments object as provided to arrays, i am looking to push the result of the conversion into an array i had created before hand. Searching up on old googs just provided answers not relevant to my question. Help, maybe?

function destroyer(arr) {
  var argsToArray = [];
  var destroyer = arr.prototype.slice.call(destroyer);
  return destroyer;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Stephen James
@sjames1958gm
Aug 21 2017 14:18
@jeffersonnnn
Why not assign the result of slice directly to argsToArray?
var argsToArray = arr.prototype.slice.call(destroyer);
to remove the arr part of arguments
var argsToArray = arr.prototype.slice.call(destroyer, 1);
Jefferson
@jeffersonnnn
Aug 21 2017 14:35
@sjames1958gm trying to assign then result of slice directly to argsToArray is exactly what i am trying to do sigh.
Stephen James
@sjames1958gm
Aug 21 2017 14:37
@jeffersonnnn If the result of the function is an array - you don't have precreate an array in the variable.
Bradley Sands
@sandsbe
Aug 21 2017 14:38
ty @Blauelf
Jefferson
@jeffersonnnn
Aug 21 2017 14:50
@sjames1958gm point taken. Since i am outputting a variable, there is no need to have a array ready to catch the "return"
Bradley Sands
@sandsbe
Aug 21 2017 15:02
var timeout;

  function simonBox () {
    $('#'+simonGame.cpu[0]).toggleClass("clicked");
  }

  function simonDelay () {
    timeout = setTimeout(simonBox, 1000);
  }

  function cpuAlgo () {
    simonDelay();
  }

  $('#start').click(function(){
    cpuAlgo();
  })
Where does a for loop go in a setTimeout function chain?
Stephen James
@sjames1958gm
Aug 21 2017 15:04
@jeffersonnnn exactly
Thomas Faller
@thomasfaller
Aug 21 2017 15:04
Hey guys, not sure if anyone is into React but I’m trying to get a feel of how to “lift state up”
Id’ like to pass my child state to my parent component?
I created a basic CodePen to work on that but I’m not sure how to do :/
Stephen James
@sjames1958gm
Aug 21 2017 15:05
@thomasfaller lol - I was just ready a blog about lifting state up :)
@thomasfaller You need to provide as props a function that the child component can call that updates the state
in the parent component. Then the parent passes that state back to the child as props when it renders.
Thomas Faller
@thomasfaller
Aug 21 2017 15:07
… Ok that makes sense
Thomas Faller
@thomasfaller
Aug 21 2017 15:07
I’ll be happy to read that post when it’s publihed :)
:bookmark:
:D
Thanks @sjames1958gm
CamperBot
@camperbot
Aug 21 2017 15:08
thomasfaller sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8355 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 21 2017 15:08
@thomasfaller :+1:
Bradley Sands
@sandsbe
Aug 21 2017 15:10
Best setTimeout post I've ever found (and I've searched for quite a few): http://brackets.clementng.me/post/24150213014/example-of-a-javascript-closure-settimeout-inside
Stephen James
@sjames1958gm
Aug 21 2017 15:12
@sandsbe Are you wanting to sequence settimeouts?
@sandsbe - here is a function I wrote that allows you to call a function for each element in an array
delayed by delay value, then calls done when complete.

function forEachDelayed(delay, cb, done) {
  let i = 0;
  t = 0;

  let fn = () => { 
    setTimeout(() => {
      cb(this[i], i, this);
      i++;
      if (i < this.length) {
        t = delay;
        fn();
      } else {
        if (done) done();
      }
    }, t); 
  };

  fn();
}

Array.prototype.forEachDelayed = forEachDelayed;

[1, 2, 3, 4].forEachDelayed(1000,
                            (e) => { console.log(e); },
                            () => (console.log("done")))
Bradley Sands
@sandsbe
Aug 21 2017 15:14
I believe so. Trying to get my setTimeout inside my for loop so that I can fire the different .css for the Simon game
Wow. @sjames1958gm that is elegant.
Stephen James
@sjames1958gm
Aug 21 2017 15:15
@sandsbe Another camper was having trouble sequencing sounds / colors and I was playing around and wrote this.
The initial delay is zero for this - only because that is what he wanted
Bradley Sands
@sandsbe
Aug 21 2017 15:16
Ya, that makes sense. You would only want the delay for the game after the first fire.
Jason Luboff
@JLuboff
Aug 21 2017 15:18
@sjames1958gm Fancy. Cleaner then my solution when I had done it :D
Bradley Sands
@sandsbe
Aug 21 2017 15:18
Could you expand on your notation a bit? What is let? Isn't it in the same idea/class as const? The fCC curriculum and other learning sources seems to start "us" with var, etc., but Airbnb and Google JS styleguides direct other ways.
Stephen James
@sjames1958gm
Aug 21 2017 15:19
@sandsbe let is the ES6 var I have taken to using it pretty exclusively - there are scoping rule differences with let
if you do
for (let i = 0;;){
}
then i is only defined inside the for loop (and you don't share the same i between loops, important for async usage)
@sandsbe The () => is an arrow function and I use that because I need access to the function this variable for the array.
And arrow functions don't redefine the this variable
Bradley Sands
@sandsbe
Aug 21 2017 15:22
Ahh. Arrow functions actually have a different purposes besides brevity...
Very interesting.
@sjames1958gm thanks
CamperBot
@camperbot
Aug 21 2017 15:24
sandsbe sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8356 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Bradley Sands
@sandsbe
Aug 21 2017 15:30
Ight, another one: setTimeout(function(x){<some stuff>}(i))
the (i) that's tagged onto the end. Does that get the (x) to read the (i)?
Thomas Faller
@thomasfaller
Aug 21 2017 15:32
Hey @sjames1958gm sorry to bother, still on that listing state up issue. I’m trying to set a button that updates the parent state. I’m not too far from doing it but still….
https://codepen.io/thomasfaller/pen/MvVdOa
Would you mind looking into this and check what might be wrong?
Also this.state.number is updating itself 800 times by the time the app refreshes which is weird :/
Stephen James
@sjames1958gm
Aug 21 2017 15:34
@sandsbe Yes that i becomes x in the function
@thomasfaller looking
@thomasfaller boss meeting
Bradley Sands
@sandsbe
Aug 21 2017 15:43
For those playing along at home, now trying this route
function start(counter){
  if(counter < 10){
    setTimeout(function(){
      counter++;
      console.log(counter);
      start(counter);
    }, 1000);
  }
}
start(0);
similar to @sjames1958gm 's as it uses recursion (i think...)
Guderian Raborg
@hypercuber
Aug 21 2017 15:56
@sandsbe would it be better to use setInterval in this case?
idk
Bradley Sands
@sandsbe
Aug 21 2017 15:56
I was kicking that around. setInterval made sense for the Pomodoro project.
function start(counter){
    if(counter < simonGame.cpu.length){
      setTimeout(function(){
        $('#'+simonGame.cpu[counter]).toggleClass("clicked");
        console.log(counter);
        setTimeout(function(){
          $('#'+simonGame.cpu[counter]).toggleClass("clicked");
          console.log(counter);
          counter++;
          start(counter);
        }, 100)
      }, 500);
    }
  }

  $('#start').click(function(){
    start(0);
  })
Stephen James
@sjames1958gm
Aug 21 2017 16:02
@thomasfaller You are calling updateState not passing as a prop addOne={this.updateState}/> I removed the () here.
Also, this.updateState = this.updateState.bind(this); put this in constructor to bind this correctly.
Abhinav Mishra
@abhinav-m
Aug 21 2017 17:11
@thomasfaller forked your pen https://codepen.io/abhinavthinktank/pen/ZJoEpJ
oh, what @sjames1958gm said is the reason
John
@AnonymousLords
Aug 21 2017 17:26
https://gitter.im/FreeCodeCamp/HelpFrontEnd I need help with a lil math
Abhinav Mishra
@abhinav-m
Aug 21 2017 17:26
go on
Thomas Faller
@thomasfaller
Aug 21 2017 17:39
Thanks @abhinav-thinktank and @sjames1958gm
CamperBot
@camperbot
Aug 21 2017 17:39
thomasfaller sends brownie points to @abhinav-thinktank and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:cookie: 521 | @abhinav-thinktank |http://www.freecodecamp.com/abhinav-thinktank
:star2: 8357 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 21 2017 17:40
@thomasfaller :+1:
luccifer00
@luccifer00
Aug 21 2017 18:25
<div class='container-fluid'>
  <div class='row container-fluid'>
      <div id= 'title' class='col-xs-8 well col-center'> twitch tv test </div> 
      <div id= 'bloq' class='col-xs-8 well col-center'> 
          <div id='img' class="col-sm-2"> <img id=icon src="#" height="42" width="42"> </div>
          <div id="name" class="col-sm-8">.col-sm-8</div>
          <div id='status' class="col-sm-2">
             <div id ="online" class="col-sm-12">online</div>
             <div id="offline" class="col-sm-12">offline</div>
          </div>  <!-- close status div -->     
    </div> <!-- close bloq div -->
    </div> <!-- close row div -->
</div> <!-- close container fluid -->
hi! i am on twitchTV challenge (here is my codepen)
i have some JS and Bootstrap questions...
Can i créate with JS all the stuff inside the <div class='row container-fluid'>...</div> maybe with parentChild()??
I also have questions about container-fluid.... when i move in codepen my editor the size of the elements inside the row change completly his positions... i am writting bad the container-fluid? should i write on every <div>?
thank you in advance! :clap:
Jason Luboff
@JLuboff
Aug 21 2017 18:26
I believe with bootstrap, container-fluid should only be used on the initial <div> and not within a row or column (unless we create another container within)
And yes you can create that stuff with JS, if you use jQuery, you can use .html
Christopher McCormack
@cmccormack
Aug 21 2017 18:37
@JLuboff :wave:
Jason Luboff
@JLuboff
Aug 21 2017 18:37
Howdy
Christopher McCormack
@cmccormack
Aug 21 2017 18:37
Heya
Jason Luboff
@JLuboff
Aug 21 2017 18:38
Hows it going
Tiago Correia
@tiagocorreiaalmeida
Aug 21 2017 18:38
hello everyone
Christopher McCormack
@cmccormack
Aug 21 2017 18:38
@tiagocorreiaalmeida heya
@JLuboff going well, in all day meeting and bored out of my mind
Jason Luboff
@JLuboff
Aug 21 2017 18:39
Ugh...meetings..
Don
@dons94
Aug 21 2017 18:40
hi guys
I know this is usually only for JavaScript
Christopher McCormack
@cmccormack
Aug 21 2017 18:40
Got a lot of coding done on a side project though so that's fun :)
Don
@dons94
Aug 21 2017 18:40
But I've really run into a tough situation on MS Excel
pls help
Christopher McCormack
@cmccormack
Aug 21 2017 18:40
@dons94 sure
Jason Luboff
@JLuboff
Aug 21 2017 18:41
@cmccormack I'm still working on my stock chart app. Was breaking it earlier, but back to fixing it now
Don
@dons94
Aug 21 2017 18:41
ok so basically
Christopher McCormack
@cmccormack
Aug 21 2017 18:42
@JLuboff haha isn't that always the case - 80% done all is well, need to add one feature - 50% done.
Don
@dons94
Aug 21 2017 18:42
how do i create an automated table on excel that takes the cell values from another cell whenever it is iterated
blob
blob
blob
woops sorry for the spam
Jason Luboff
@JLuboff
Aug 21 2017 18:43
@cmccormack Pretty much. I was trying to add an event listener to a dynamically created item...wasn't working with vanilla JS so I went back to jquery..
Don
@dons94
Aug 21 2017 18:44
i want to the cell values from F3 to J3 to automatically update into the table i have below
Christopher McCormack
@cmccormack
Aug 21 2017 18:44
@dons94 you can do several things but I'm not exactly certain what you're asking - you can use vlookup/hlookup to see if something exists and do something accordingly
@dons94 probably need to use some VBS to do that
Don
@dons94
Aug 21 2017 18:45
I've made it so that the Bet cell has a dropdown list of 1, 5, and 10, and whenever I choose either one of these 3 numbers, Reel 1, Reel 2, Reel 3 will automatically generate random values
Im not allowed to use VBA
Christopher McCormack
@cmccormack
Aug 21 2017 18:46
@JLuboff haha it probably didn't exist when you needed it
Don
@dons94
Aug 21 2017 18:46
which really perplexes me cos I could easily do it with VBA
Jason Luboff
@JLuboff
Aug 21 2017 18:46
@cmccormack Correct, so I already had a solution for it using jquery as opposed to looking up how to do it with vanilla
Don
@dons94
Aug 21 2017 18:46
and I want it to automatically update the table below whenever I put one of the three values into Bet
Christopher McCormack
@cmccormack
Aug 21 2017 18:47
@JLuboff probably some type of search you an do so it has to traverse the dom to find it after it's added
Jason Luboff
@JLuboff
Aug 21 2017 18:47
Ya...meh..forget about it!
Don
@dons94
Aug 21 2017 18:48
Pls help if anyone knows, been wracking my brains about this issue for days, ( note: not allowed to rely on vba and macros)
Christopher McCormack
@cmccormack
Aug 21 2017 18:50
@dons94 with the way you're implementing I don't see a way to do it without VBA
Don
@dons94
Aug 21 2017 18:51
Do you have any suggestions as to how to randomly generate a cell range that is based on another cell value?
and after doing so, automatically updates a table to show the records?
if you do, or anyone does, I'd really be very grateful
Tiago Correia
@tiagocorreiaalmeida
Aug 21 2017 18:55
@cmccormack can you give a look into this? https://codepen.io/tiagocorreia/full/brYpog/ , only to this part
   function sound(){
     if(index < entrys.length){
       $("."+entrys[index]+"").css("Opacity","1");
       audio = $("."+entrys[index]+"audio")[0];
       audio.play();
       index++;
        console.log(entrys[index]);
     }else{
       console.log(index);
        $(".row-button div").css("Opacity","0.80");
        $(".row-button div").css("pointer-events","auto");
       audio.removeEventListener('ended', sound, false);
     }
   }
after I ended up playing all my sounds I set the pointer events to auto so the user is avaible to click
after the first sequence it stops
Christopher McCormack
@cmccormack
Aug 21 2017 18:56
@dons94 if you can randomly generate the reel items, and the bet for all pulls is the same (1 or 2 or 3) then you should just be able to populate all reel items with a randbetween or whatever random function and then check if all three cells are the same, and if they are determine your winnings based on the string and the bet
I guess bet could be randomly generated as well but I still am not sure your exact requirements
Don
@dons94
Aug 21 2017 18:58
@cmccormack my current issue is that i can't find a way to automate transferring the cell values from the top table into the table below
without using vba or macros
the requirement is to auto populate the table below to keep them as records based on everytime I place a bet
Christopher McCormack
@cmccormack
Aug 21 2017 19:02
@tiagocorreiaalmeida why are you starting with index 1?
Don
@dons94
Aug 21 2017 19:02
the reels 1,2, and 3 have been set with an IF OR function to only generate the randoms only when the bet is $1,$5, or $10. which I've already solved, my current issue is that I need the information from every new bet to auto populate the table below whenever I place a bet. @cmccormack
Tiago Correia
@tiagocorreiaalmeida
Aug 21 2017 19:05
this was a idea that another person on here gave me since I was having troubles controlling the setIntervall and stuff and creating loops aswell so the idea here is I run the first sound then it calls the function and after that it just keeps playing unthil the end of the array, was an idea, what you would change?
Christopher McCormack
@cmccormack
Aug 21 2017 19:07
I would completely separate the computer playing the sounds from the user inputs. use a setinterval to go through all the sounds, then when done, set something up to allow the user to input their colors
@dons94 sorry not sure you can do that, maybe check the requirements and see if that's really what you need to do
Don
@dons94
Aug 21 2017 19:07
@cmccormack alright, thank you for all your help so far tho, I really appreciate it
CamperBot
@camperbot
Aug 21 2017 19:07
dons94 sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1160 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Aug 21 2017 19:07
I gotta run for a few, breaking for lunch
@dons94 np good luck
Tiago Correia
@tiagocorreiaalmeida
Aug 21 2017 19:08
I have it separated my only problem here is enable the pointer events once the function has ended do you have any idea?
Christopher McCormack
@cmccormack
Aug 21 2017 19:08
@tiagocorreiaalmeida I can look at it more in a bit, but maybe do some more logging so you can what's going on
Tiago Correia
@tiagocorreiaalmeida
Aug 21 2017 19:09
@cmccormack that's what I will do, if I havent solved when you can back would be great, good lunch mate
come*
Bradley Sands
@sandsbe
Aug 21 2017 19:12
Is there a prettier way to do this?
  $('.box').mousedown(function(){
    $('#'+this.id).toggleClass("clicked");
  })

  $('.box').click(function(){
      playerPlay(this.id);
      });

  $('.box').mouseup(function(){
    $('#'+this.id).toggleClass("clicked");
  })
Tiago Correia
@tiagocorreiaalmeida
Aug 21 2017 19:15
    console.log(index);
        $(".row-button div").css("Opacity","0.80");
        $(".row-button div").css("pointer-events","auto");
       audio.removeEventListener('ended', sound, false);
the problem seems to be here this isnt running after a certain time
strange thing
after having more than 1 color*
Gulsvi
@gulsvi
Aug 21 2017 19:19
@sandsbe You could use the :active selector in CSS to take care of the mousedown/mouseup functionality
Ogundele Olumide
@Lumexralph
Aug 21 2017 19:21
@JLuboff @cmccormack Bro! :wave:
Jason Luboff
@JLuboff
Aug 21 2017 19:21
@Lumexralph Hey, how goes it?
Bradley Sands
@sandsbe
Aug 21 2017 19:22
@SkyC0der will do. thanks.
CamperBot
@camperbot
Aug 21 2017 19:22
sandsbe sends brownie points to @skyc0der :sparkles: :thumbsup: :sparkles:
:star2: 2519 | @skyc0der |http://www.freecodecamp.com/skyc0der
luccifer00
@luccifer00
Aug 21 2017 19:30
@JLuboff thanks for the answer , i just read it now.... meanwhile i was testing other ways... and i think i am close with .cloneNode and .insertAdjacentHTML i have this result... i am on the right way?? https://codepen.io/luccifer00/pen/RZQYdM?editors=0011
CamperBot
@camperbot
Aug 21 2017 19:30
luccifer00 sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2161 | @jluboff |http://www.freecodecamp.com/jluboff
Tiago Correia
@tiagocorreiaalmeida
Aug 21 2017 19:42
function sequence () {
$(".row-button div").css("pointer-events","none");
  entrys.push(colors[(Math.floor(Math.random()*4))]); 
   index = 1;
   var audio = $("."+entrys[0]+"audio")[0];
   function sound(){
     if(index < entrys.length){
       $("."+entrys[index]+"").css("Opacity","1");
       audio = $("."+entrys[index]+"audio")[0];
       audio.play();
       index++;
     }else{
       console.log("else");
        $(".row-button div").css("Opacity","0.80");
        $(".row-button div").css("pointer-events","auto");
       audio.removeEventListener('ended', sound, false);
     }
   }
     $("."+entrys[0]+"").css("Opacity","1");
     audio.addEventListener('ended',sound);
     audio.play();
  }
guys I got this function for some reason the if statement will run the else everytime it gets to the point that index is biger but only if all the colors in the array are the same? cause If I have 2 diferentes colors followed it doesnt runs the else statmenet?any idea?
Mohammed Boudad
@matrixersp
Aug 21 2017 19:55
What do you guys think about this solution? How can I optimize it more?
function smallestCommons(arr) {
  var arr2 = [];
  var bool = true;

  if(arr[0] == arr[1]) {
    return arr[0];
  } else if(arr[0] < arr[1]) {
    for(var i = arr[0]; i <= arr[1]; i++) {
      arr2.push(i);
    }
  } else {
    for(var j = arr[1]; j <= arr[0]; j++) {
      arr2.push(j);
    }
  }
  var arr3 = arr2.slice();

  while(bool) {
    if(arr3[arr3.length - 1]  >= arr3[arr3.length - 2]) {
      arr3[arr3.length - 2]  += arr2[arr2.length - 2];
    } else {
      arr3[arr3.length - 1]  += arr2[arr2.length - 1];
    }

    if(arr3[arr3.length - 1]  === arr3[arr3.length - 2] && arr3.length == 2) {
      return arr3[arr3.length - 1];
    }
    if(arr3[arr3.length - 1]  === arr3[arr3.length - 2]) {
      var count = 0;
      while(arr3[arr3.length - 1] % arr2[count] === 0 && count < arr3.length - 2) {
        count++;
        if(count === arr3.length - 2) {
          return arr3[arr3.length - 1];
        }
      }
    }
  }
}
smallestCommons([1,5]);
korzo
@korzo
Aug 21 2017 19:57
@Tekkie7 You can save some lines, when you sort arr at start
Tiago Correia
@tiagocorreiaalmeida
Aug 21 2017 20:00
@cmccormack are you around mate?
Mohammed Boudad
@matrixersp
Aug 21 2017 20:02
@korzo Yes that would save me some lines, but I don't think it'll optimize the algorithm
korzo
@korzo
Aug 21 2017 20:02
@Tekkie7 also it's very complicated. You can solve it using one while loop + for loop ( or array.every)
@Tekkie7 And if you are good with math, you can use Greatest Common Divisor + Least Common Multiple
Mohammed Boudad
@matrixersp
Aug 21 2017 20:04
Okay thanks @korzo
CamperBot
@camperbot
Aug 21 2017 20:04
tekkie7 sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 397 | @korzo |http://www.freecodecamp.com/korzo
Ogundele Olumide
@Lumexralph
Aug 21 2017 21:26
@JLuboff going well bro, how're you?
Jason Luboff
@JLuboff
Aug 21 2017 21:28
@Lumexralph Doing alright.
luccifer00
@luccifer00
Aug 21 2017 21:38
$(document).ready(function(){

  //create an object with diferent twitch users
  var user = ["frecodecamp", "esl_cs2","github_", "omgitsfirefoxx","kindafunnygames", "manvsgame", "trihex", "Nightblue3", "kittyplays", "teamsp00ky", "bobroos", "maximilian", "mang0","deadmau5", "amazhs"];
   var test = document.getElementById('row');
    var div = document.createElement('div');
  var bloque = document.getElementById('bloq');
  var clonbloq= bloque.cloneNode(true);
 for (var i=0; i<user.length; i++){
  var ele= test.appendChild(clonbloq);
   div.insertAdjacentHTML('afterend', ele);   
 test.appendChild(ele);
Hi there!, what i am missing on this loop?? my goal is to créate one row behind the other in the loop... but i just can créate one... and i need 15 (15 is = user.length) any idea?
Gulsvi
@gulsvi
Aug 21 2017 22:07
@luccifer00 use .innerHTML
var user = ["frecodecamp", "esl_cs2","github_", "omgitsfirefoxx"];
user.forEach(function(streamer) {
  document.getElementById('results').innerHTML +=
    `<div id='${streamer}row' class='row'>
       <div class='col-sm-8 well col-sm-offset-2'>
         <!-- your HTML for each user's row --> 
       </div>
     </div>`  
});
Bradley Sands
@sandsbe
Aug 21 2017 22:20
<div class="checkbox">
    <label>
    <input type="checkbox" value="false" id='strict'>
    Strict Mode
  </label>
  </div>
I put in that value of "false". How should I be checking on this checkbox?
luccifer00
@luccifer00
Aug 21 2017 22:24
@SkyC0der it is posible to use other method as .insertAdjacentHTML ?
Stephen James
@sjames1958gm
Aug 21 2017 22:33
@sandsbe checked is the property that sets the value of the check
Gulsvi
@gulsvi
Aug 21 2017 22:35
@luccifer00 Yes, you can do that too, but it gets complicated quickly as you are noticing. Remember also, that IDs need to be unique. When you clone an element, the IDs clone too - then you have duplicate IDs
Conor Murphy
@cmurphy580
Aug 21 2017 23:54
Hey i'm having some issues with my mobile version of my portfolio. My click features in javascript, using jQuery too, are not working and i tried ontouch that doesn't seem to work either. any ideas>
?
my bad used touchstart