These are chat archives for FreeCodeCamp/HelpJavaScript

13th
May 2018
Ken Haduch
@khaduch
May 13 2018 04:02 UTC

@Will5592 - if it's an array, then the contents of the array can be modified, even if the variable is declared with const - quoting from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const

The const declaration creates a read-only reference to a value. It does not mean the value it holds is immutable, just that the variable identifier cannot be reassigned. For instance, in the case where the content is an object, this means the object's contents (e.g., its parameters) can be altered.

@Will5592 - I think that codeine is probably a mis-type of CodePen (or an autocorrect...)
Razvan Jackson
@RazvanJackson
May 13 2018 18:11 UTC
Hey guys! Someone here who knows C++?
Nate Mallison
@NJM8
May 13 2018 18:34 UTC
@lukadadiani_twitter you can play videos with vanilla JS.
ArchivalBoat50
@ArchivalBoat50
May 13 2018 22:41 UTC
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 subarray = arr[2];
  for (var j = 0; j<arr[i].length; j++){
    var num = arr[0[0]];
    }
  }

console.log(num);
I'm trying to get a number from this array but I don't understand why my console.log(num); is giving out an undefined. Anyone know whats going on?
Michael S
@Ohshi60
May 13 2018 22:42 UTC
you defined num inside the scope of your function and try to access it outside
try to define num outside the for-loop
@ArchivalBoat50 if that makes sense
anthonygallina1
@anthonygallina1
May 13 2018 23:09 UTC
@lukadadiani_twitter Hi this free course wil tell you how to build one es6 If it will be helpful https://www.javascript30.com/
ArchivalBoat50
@ArchivalBoat50
May 13 2018 23:20 UTC

@Ohshi60
I did this:

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

var num = arr[0[0]];
console.log(num);

num still returned undefined

Michael S
@Ohshi60
May 13 2018 23:20 UTC
aye youre confused :D
ArchivalBoat50
@ArchivalBoat50
May 13 2018 23:22 UTC
?
Michael S
@Ohshi60
May 13 2018 23:22 UTC
var num
for (var i = 0; i<arr.length; i++) {
  var subarray = arr[2]; // You dont use this value
  for (var j = 0; j<arr[i].length; j++){
      var num = arr[0[0]];      
    }
  }
console.log(num);
try this
doing the operation inside the for-loop is fine but then your console.log tries to print a value that only exists inside the for-loop so thats why it doesnt know it
now we create the value outside of the scope of the function, then access that value inside of the for-loop and modify it. Finally we log the number
ArchivalBoat50
@ArchivalBoat50
May 13 2018 23:27 UTC
@Ohshi60 That makes sense but for some reason it's still giving an undefined
Michael S
@Ohshi60
May 13 2018 23:28 UTC
@ArchivalBoat50 yes just noticed, shouldnt have been a problem second time, trying to run the code on my computer gives me the same. Give me a sec :)
Stephen James
@sjames1958gm
May 13 2018 23:29 UTC
@ArchivalBoat50 arr[0[0]]; this is invalid it is trying to take the index of a number 0
arr[0][0] this would be the first value in the first subarray
ArchivalBoat50
@ArchivalBoat50
May 13 2018 23:30 UTC
@sjames1958gm Oh it goes that way
@sjames1958gm @Ohshi60 Everything seems to make sense now thanks
CamperBot
@camperbot
May 13 2018 23:30 UTC
archivalboat50 sends brownie points to @sjames1958gm and @ohshi60 :sparkles: :thumbsup: :sparkles:
:cookie: 182 | @ohshi60 |http://www.freecodecamp.org/ohshi60
:star2: 9241 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
Stephen James
@sjames1958gm
May 13 2018 23:31 UTC
@ArchivalBoat50 :+1:
Michael S
@Ohshi60
May 13 2018 23:31 UTC
@sjames1958gm what editor you use, i have trouble spotting those kind of things in atom :(
or should i just accept my code blindness :D
Stephen James
@sjames1958gm
May 13 2018 23:34 UTC
@Ohshi60 I use vscode