These are chat archives for FreeCodeCamp/HelpJavaScript

14th
May 2018
anthonygallina1
@anthonygallina1
May 14 2018 05:56
Whats the topic?
Francois Beyers
@Blusoup
May 14 2018 08:51
Hello everyone. I was hoping someone could help me out. I need to set a cookie if the customer clicked on the megaMenu. This needs to be false by default and the set to true on the next page if the customer clicked on a menu button. Any help would be appreciated
Ghost
@ghost~5a930610d73408ce4f8ec750
May 14 2018 11:07
function move() {
  var elem = document.getElementById("myBar");   
  var width = 0;
  var id = setInterval(frame, 10);
  function frame() {
    if (width == 100) {
      clearInterval(id);
    } else {
      width++; 
      elem.style.width = width + '%'; 
    }
  }
}
</script>
can anyone tell my what does elem.style.width = width + '%'; line does here?
I am trying to make a progress bar
Claudio Restifo
@Marmiz
May 14 2018 11:17
Updating the style to the element so that the width property will look like width: x% where x is the actual width :)
Ghost
@ghost~5a930610d73408ce4f8ec750
May 14 2018 11:18
thanks @Marmiz
CamperBot
@camperbot
May 14 2018 11:18
aditya8349_twitter sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1225 | @marmiz |http://www.freecodecamp.org/marmiz
ArchivalBoat50
@ArchivalBoat50
May 14 2018 14:13
var num;
arr = ([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

for (var i = 0; i<arr.length; i++) {
  for (var j = 0; j<arr[i].length; j++){
    if (num < arr[i][j]) {
      num = arr[i][j];
    }

  }
}

console.log(num);
I'm trying to return the largest numbers from each of those sub-arrays. But I don't know how I can store the largest number in a variable. Anyone have an idea?
Kudzu
@czhower
May 14 2018 14:16
Trying to work with JavaScriptCore which is part of webkit - I cant find any gitter rooms, forums, or mailing lists for JSCore or webkit.. anyone?\
Even webkit org has no support links on home page or menus, you have to dig and in the end its mailing lists and IRC :(
Nate Mallison
@NJM8
May 14 2018 14:20
@ArchivalBoat50 Your function works but because you do not set num to anything to begin with, so it is undefined, so your if statement equates to (undefined < arr[i][j]) which is false, so the num never gets set to anything
set num to 0 to start, or if it's the first iteration set it to the first number you find
@czhower Maybe some iosProgramming chat places?
Kudzu
@czhower
May 14 2018 14:23
its not on iOS.Webkit runs on Windows etc too.
Just amazing that in 2018 they are still using mailman mail lists and IRC only.
ArchivalBoat50
@ArchivalBoat50
May 14 2018 14:26

@NJM8

var num;
arr = ([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

for (var i = 0; i<arr.length; i++) {
  for (var j = 0; j<arr[i].length; j++){
    num = [i][0];
    if (num < arr[i][j]) {
      num = arr[i][j];
    }

  }
}

console.log(num);

I've done something like this, but now it's returning the last number of the sub-array. How do I get it to iterate through the sub-array and a store the largest value from that sub-array?

Nate Mallison
@NJM8
May 14 2018 14:27
@czhower Maybe you could send someone a letter? :smile:
@ArchivalBoat50 with that you are always setting num to the last value in the array then checking if it is larger then itself. Make it num = arr[i][j] then put it in an if statement that will only let it run if i and j are zero
Kudzu
@czhower
May 14 2018 14:29
@NJM8 Maybe they have a Telex address I can send to.
Nate Mallison
@NJM8
May 14 2018 14:32
It's amazing what the hipsters can get done when they really set their minds to it. hahaha
Kudzu
@czhower
May 14 2018 14:33
Id bet JSCore has a receptor for the pigeon.....
Nate Mallison
@NJM8
May 14 2018 14:33
NSWhenPigeonHasLanded
too short
NSWhenPigeonHasLandedWithinTenMetersOfCustomerNotifier
ArchivalBoat50
@ArchivalBoat50
May 14 2018 14:37

@NJM8 I did just that.

var num;
arr = ([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

for (var i = 0; i<arr.length; i++) {
  for (var j = 0; j<arr[i].length; j++){
    num = [i][j];
    if (num = arr[0][0]) {
      num = arr[i][j];
    }

  }
}

console.log(num);

I don't know why it is returning a 1 though. Also how do I store a variable from the sub-array doing this method, because it looks like the code thats going to return the largest number from the entire array of sub-arrays.

Kudzu
@czhower
May 14 2018 14:38
Looking like it will be easier to chagne over to node. Its far better supported and doesnt use 1980s methods of support channels.
Nate Mallison
@NJM8
May 14 2018 14:38
@ArchivalBoat50
for (var i = 0; i<arr.length; i++) {
  for (var j = 0; j<arr[i].length; j++){
    num = [i][j]; // I run every single loop, so I always set num to the current value
    if (num = arr[0][0]) {
      num = arr[i][j];
    }

  }
}
Kudzu
@czhower
May 14 2018 14:38
I have JSCore working, but its complaining about the class keyword despite it supporting ES6.
Nate Mallison
@NJM8
May 14 2018 14:39
@czhower what are you building?
Blauelf
@Blauelf
May 14 2018 14:39
@NJM8 Did you forget arr in front of [i][j]?
Oh, that was @ArchivalBoat50 's code.
Nate Mallison
@NJM8
May 14 2018 14:40
@ArchivalBoat50 remove that line I commented on and add your check to see if the current num is larger, sorry I didn't fully read your new code
Kudzu
@czhower
May 14 2018 14:41
@NJM8 Version 17 of a commercial product :)
Nate Mallison
@NJM8
May 14 2018 14:41
var num;
arr = ([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

for (var i = 0; i<arr.length; i++) {
  for (var j = 0; j<arr[i].length; j++){
    if (i === 0 && j === 0) {
      num = arr[i][j];
    }
    if (num < arr[i][j]) {
      num = arr[i][j];
    }

  }
}

console.log(num);
Kudzu
@czhower
May 14 2018 14:42
Need to run some of our TS based code though on Windows to avoid having to duplicate a lot of code.
Nate Mallison
@NJM8
May 14 2018 14:43
and I'm guessing windows doesn't like TS, can you use babel or something to compile down to ES5?
transpile
Kudzu
@czhower
May 14 2018 14:44
TS compiles to JS, thats not the issue. ES5 removes too many features we are using already.
Its not just running, with node we can run them as console apps etc.. but with JSCore we had direct integratino and call backs into the hosting code. Node can do same, but now we are looking at several days minimum to move over to it and get the integrations redone around how NODE does it.
ArchivalBoat50
@ArchivalBoat50
May 14 2018 14:45
@NJM8
It returned the largest number of the entire array
Nate Mallison
@NJM8
May 14 2018 14:45
@ArchivalBoat50 Is that not what you want?
that's what your first algorithm kinda lead to, largest num in all sub-arrays
@czhower Your beyond what I know but Node is large and well supported, so....
Kudzu
@czhower
May 14 2018 14:47
I knew the Apple curse would be reliabel and bite me in the end.
ArchivalBoat50
@ArchivalBoat50
May 14 2018 14:49
@NJM8 I'm trying to return the largest number from each sub-array. So it should return (4,27,39,1001). However I don't know how I can the largest number of each sub-array.
Kudzu
@czhower
May 14 2018 14:49
I think for deve time speed will just use node and console interface for now and do the integrations later. We only need to call this code at design time, never at run time so scalabiltiy isnt an issue. Basically we need it to suport some dev tools during development only. ie reuse existing parsers etc and also retrieve info about the TS/JS code and write native proxies in other langs that communicate with them in the browser.
Nate Mallison
@NJM8
May 14 2018 14:50
@czhower Apple was down last quarter, only $46 billion in revenue so take it easy on them
Kudzu
@czhower
May 14 2018 14:50
I have a lot history of hate with Apple.
Every Apple product I have ever owned has been a designed disaster without reason to be so. And we ran a multicountry service center for 7 years and working on Apple products was a nightmware - they engineer them to make them hard to work on in an effort to limit service to their own service centers.
Nate Mallison
@NJM8
May 14 2018 14:52
@ArchivalBoat50 So move num to the inside of the first loop, always set it to the first value found, compare it to each value in the sub-array, then push the num on to a results array
@czhower Yes I've always hated that Steve Jobs was so great at design and making a fantasic product but then didn't let the users do what they want to with it. But sadly there isn't much need to change, they are the most valuable company in the world.
Michael S
@Ohshi60
May 14 2018 14:53
@czhower Still my mac is my favourite coding-pc!
Nate Mallison
@NJM8
May 14 2018 14:57
@ArchivalBoat50 like so:
var results = [];
var arr = [[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]; 

for (var i = 0; i<arr.length; i++) { 
  var num; 
  for (var j = 0; j<arr[i].length; j++) { 
    if (j === 0) { 
      num = arr[i][j]; 
    } 
    if (num < arr[i][j]) { 
      num = arr[i][j]; 
    } 
  } 
  results.push(num);
} 

console.log(results);
Blauelf
@Blauelf
May 14 2018 14:58
I actually was a bit surprised when I learnt how limited Apple devices are in interaction with non-Apple. Every Bluetooth-enabled device with a file system supports sending files over Bluetooth. But not iPhone. These devices work great only if you stay in the limits Apple set. Which reminds me of Microsoft, especially Outlook. Ever got an empty E-Mail with an attachment "winmail.dat"?
Nate Mallison
@NJM8
May 14 2018 14:58
I hope to be able to learn to use Linux for web dev, that way when my macbook dies I can get the system 76 oryx pro. looks awesome
Kudzu
@czhower
May 14 2018 14:58
ugh..... any one know how to load mult JS files in node without merging or using a module loader? I would have thought I could just pass mult .js files on the command line but that doesnt work.
Wait, I bet node actually has a modern chat room :)
Nate Mallison
@NJM8
May 14 2018 15:01
@czhower Maybe path.join then read the file contents to one file?
Can you not use require?
Kudzu
@czhower
May 14 2018 15:03
cant use require, that uses the ES module system which we do not use and do not want for a variety of reasons not worth going into here.
we could join and do for production runs, but during dev we have separate files for maint and having to join them during dev just adds a step in the middle and really complicates debugging, not only the .map files but also updating source.
Nate Mallison
@NJM8
May 14 2018 15:07
hm, well you could create a file to run all the js from and copy all your files to that one before running
probably not the best solution
Kudzu
@czhower
May 14 2018 15:08
that breaks debugging and complicates fixing code, thats why I want to avoid it.
Nate Mallison
@NJM8
May 14 2018 15:09
hmmm, if you can't use node require you might want to look into if base node supplies everything need, even to do file system work you have to require('fs')
Kudzu
@czhower
May 14 2018 15:11
We have our own module loader which does things require doesnt. Id hate to have to work that into require somehow just because node cant seem to load multiple files.
Nate Mallison
@NJM8
May 14 2018 15:15
can you use import?
Jason Luboff
@JLuboff
May 14 2018 15:16
It's not recomended to use import at this time due to I believe not being fully standardized yet
Nate Mallison
@NJM8
May 14 2018 15:18
@czhower You could just use require to load your own module loader then use that from there no?
Or if it's all just JS extend require by adding your functions to it
Kudzu
@czhower
May 14 2018 15:19
No, we dont use require. it doesnt do everything we need, so we have our own system. It works fine everywhere so far but node apparently we have to recode ti just for node since it cant just load more than one file from command line like JSCore and others can.
Michael S
@Ohshi60
May 14 2018 15:24
Extending the original require with the functionality you need might be an option, know how to go about it in JS though
Nate Mallison
@NJM8
May 14 2018 15:25
wait, @czhower Are you just wanting access to file names passed through your command line?
because node can definitely accept more than one arg in command line
console.log(process.argv[2]);
console.log(process.argv[3]);
console.log(process.argv[4]);
Kudzu
@czhower
May 14 2018 15:26
no, I want node to do something liket his:
node main1.js main2.js
Nate Mallison
@NJM8
May 14 2018 15:26
Screen Shot 2018-05-14 at 11.26.35 AM.png
Kudzu
@czhower
May 14 2018 15:27
really simple, but apparently it cant do that.
Michael S
@Ohshi60
May 14 2018 15:27
youre supposed to use module.exports and require for that
node server1.js server2.jsdoesnt make sense
Kudzu
@czhower
May 14 2018 15:33
Please read. I explained at least 2x that we dont use the module system and dont want to. This is a pretty styupid limitation of node.
jscore you can just specifyi mult files, browser you can load or use script.. node you have to merge... which really sucks during debugging.
now we have to debug a huge massive file.
Michael S
@Ohshi60
May 14 2018 15:34
Hey dont insult me. I read it plenty - im just saying that simple thing you want to do is only hard because of your self-imposed limitations
And running multiple files on node doesnt make sense, since its supposed to run a server or app or main or whatever js file
Nate Mallison
@NJM8
May 14 2018 15:36
@czhower You can pass in multiple file names and run them after requiring them, I'm not sure what you are looking for in debugging but node does know what files the error came from
Screen Shot 2018-05-14 at 11.37.28 AM.png
a.js:
console.log(process.argv[2]);
console.log(process.argv[3]);
console.log(process.argv[4]);

const b = require(`./${process.argv[4]}`);
b();
b.js:
module.exports = function(){
  console.log(x);
}
thats all I got, there is some interesting stuff I saw about child processes, not sure if that fits your use case or not
Kudzu
@czhower
May 14 2018 15:39
require uses modules and/or external code. A no go here too.
Kudzu
@czhower
May 14 2018 16:21
Heck, apparently eval might even do the trick even easier. Yes, I know about eval, but this is not for production code. Its about getting some covnersion utilities functioning using existing code that cannot be adapted to modules without serious debuggnig side effects or effort given its size.
Chris
@ConnectCodes
May 14 2018 16:47
:wave:
Jason Luboff
@JLuboff
May 14 2018 16:58
:wave:
Chris
@ConnectCodes
May 14 2018 16:59
How is it going?
Jason Luboff
@JLuboff
May 14 2018 17:00
Not too bad..yourself?
Chris
@ConnectCodes
May 14 2018 17:16
Not bad, working on calculator project and drinking that hot coffee
Jason Luboff
@JLuboff
May 14 2018 17:18
Nice
Kaz Baig
@kbaig
May 14 2018 17:49
:wave: gang
Nazar
@IsaakNazar
May 14 2018 17:51
hey everybody, guys, what best books about DOM manipulation do you recommend ?
Jason Luboff
@JLuboff
May 14 2018 17:51
@kbaig Yo yo
Jason Luboff
@JLuboff
May 14 2018 18:29

Hmm. Trying to turn an array into a list.

<ul>
                      ${body.actions.map(action => `<li>${action}</li>`)}
                      </ul>

Where body.actions is an array with one or more items. With a single item, the returned result is fine. But if more than one, than I get some extra spacing and a comma added..

Item 1
,
•    Item 2
,
•    Item 3

Any one know why? This is a bit of HTML for an email message.

Moisés Man
@moigithub
May 14 2018 18:34
probably jquery doesnt like array ? .. or convert toString() .. which add the commas
try join(" ") @JLuboff
Jason Luboff
@JLuboff
May 14 2018 18:35
@moigithub I should specify, this is for nodeMailer, so backend no jquery
Where would I stick the join, inside the li? <li> ${action.join('')}</li>?
Moisés Man
@moigithub
May 14 2018 18:36
ahh.. though was jquery cuz $.. soo its some templating syntax instead :)
Jason Luboff
@JLuboff
May 14 2018 18:36
That join is no bueno. It's just a template string
Moisés Man
@moigithub
May 14 2018 18:37
chain join after closing map().join('')
Jason Luboff
@JLuboff
May 14 2018 18:37
Ah.. duh.
I think that did it. Let me see
@moigithub Thanks. I wasn't thinking about the fact that map is returning an array..hence the commas
CamperBot
@camperbot
May 14 2018 18:38
jluboff sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3748 | @moigithub |http://www.freecodecamp.org/moigithub