14. Heterogeneous arrays need help please


#1

Heterogeneous arrays need help please

https://www.codecademy.com/pt/courses/javascript-beginner-en-9Sgpi/3/1?curriculum_id=506324b3a7dffd00020bf661#

the console display shows this: Make sure you have at least four elements in myArray, but the code is executed and I did the fourth object (Well I think so) in newArray but gives error the same way.
I do not know where the error is in the code


var needForSpeed = new Object();
needForSpeed.mostWanted = true;
var newArray = [18,true,"Chi0gy",needForSpeed]
console.log(newArray);


#2

@chi0gy

Hi,

Should be between brackets []


#3

HI instead of newArray change it to myArray here

var newArray = [18,true,"Chi0gy",needForSpeed]
console.log(newArray);

#4

Like this:
var needForSpeed = new Object();
needForSpeed['mostWanted'] = true;
var myArray = [18,true,"Chi0gy",needForSpeed]
console.log(newArray);


#5

Hi @miniapple8888 it's the same ...

@chi0gy yes try it like that

and here

console.log(newArray);

should be

console.log(myArray);

#6

@chi0gy

No,

Like this

var needForSpeed = new Object();
needForSpeed['mostWanted'] = true;
var myArray = [18,true,"Chi0gy", [needForSpeed]];
console.log(myArray);

#7

Now its works, i had forgotten myArray by new Array, thanks man and also @miniapple8888 iniapple8888


#8

Hi,

I am stuck :

var bool1 = true;
var myObj = {
type: "fancy";
disposition: "sunny";
};

myArray = [20, true, "Pasta", [myObj]]
console.log(myArray);

Can anyone help ?

Thx


#9
  1. The true in your array should be replaced by bool1 because boolean refers to the thing that is true/false not true or false itself.

  2. You don't need the [] around myObj in your array.

  3. Also, you need to put a var before myArray.

So it should be:
var bool1 = true;
var myObj = {
type: "fancy";
disposition: "sunny";
};

var myArray = [20, bool1, "Pasta", myObj]

Btw, next time you should start a new thread instead on replying to this one.


#10

Thank you. I will create a new thread next time