What is wrong with my code? It has a boolean, strings and numbers.
The solution is made with a one-dimensional array, I made a multi dimensional array.
I wish thats what they told us when they added an example! Theres nothing that leads the user to writing a one-dimensional array.I wish thats what they told us when they added an example! Theres nothing that leads the user to writing a one-dimensional array.
The instructions is asking you: Complete the statement by assigning an array of at least 5 elements in length to the yourArray variable. Your array should contain at least one string, one number, and one boolean.
It’s not asked to add nested arrays or objects within the array, you just need to add required number of elements within a single array.
If you add one example and then add another example, you’re not gonna go and say “hmm the first example is better!” because you wont know that. You’ll be going for the latest example. At least make them accept both? fCC staff said that my array is wrong but its literally a copy of their example.
I would suggest you slow down and read the challenge text and requirements a few times.
It explains the array data structure and gives a simple example. Then it expands on that by informing you of the length property, and then gives a more complex array example.
Then it gives you the requirements, and they clearly state what the array you are asked to create should contain. It does not ask for arrays, or arrays of objects, you only added that because of the complexArray example.
The key takeaway is that an array only contain its own elements. Nested arrays or objects and their elements/properties does not count against the outer array content.
The below arr array does not contain a number, it contains an array. The fact that the nested array contains a number doesn’t matter.
const arr = [[1]]
If I ask for an array with a number inside it, it means if I were to run typeof arr[0] it would return "number"
The example is an example of a multi-dimensional array.
You have written an array that contains arrays. You need an array that has three elements as requested, the other two (or more) can be what you want even arrays or objects:
Your array should contain at least one string, one number, and one boolean.
An array contains an element when the element is one of the items inside the array, not when it is inside an array or object inside the array