Heterogeneous arrays HELP


Heterogeneous arrays exercise

I keep getting the error code " Make sure you have at least four elements in myArray."


Replace this line with your code.

var myArray = [12, true, 'Duncan', me];
myArray = [me];
var me = {
name: 'Paige'


This declaration should follow the definition of me. It and the next one reference me before it is defined.


Hi mtf,

Could explain to me how it works? I am so confused.


You have an object with the variable name, me, but it is not defined until the third line. This means it does not exist yet when the first two lines are parsed so those lines will not contain a defined value or object for me.

When you log the array, the output will be,

[ undefined ]

Move the definition for your object to the top of the code so it comes first, followed by the other two lines. Now the output will be,

[ { name: 'Paige' } ]


When i write out my code how come my array has to before the console.log?


var bool1 = true;
myArray = [me];
var me = {
name: 'Paige'
var myArray = [12, bool1, 'Duncan', me];


For the same reason it has to written above where it is first referenced.

// define an object
// access an object

in that order. If we attempt to log an object that is not defined, it could throw an error.

 > console.log(me)
ReferenceError: me is not defined


ok got. Thanks mtf. :slight_smile:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.