Create an array of three fruit names and show how many it holds.
Acceptance criteria
- 1.#out should show 3.
JavaScript Tutorial · JavaScript Arrays
These 10 tasks go with the JavaScript Arrays chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “A JavaScript array stores several values in a single variable.” Read the chapter.
1.Create an arrayexercise · easy · 10 min
Create an array of three fruit names and show how many it holds.
Passes when: #out should show 3.
2.Show an empty array lengthexercise · easy · 10 min · practice plan
Create an empty array and show its length.
Passes when: #out should show 0.
3.Store mixed typesexercise · easy · 10 min · practice plan
Create an array holding a string, a number and a boolean, then show the type of the middle element.
Passes when: #out should show number.
4.Count a nested rowexercise · medium · 10 min · practice plan
Create a grid of two rows with three values each and show the length of the first row.
Passes when: #out should show 3.
5.Grow a const arrayexercise · easy · 10 min · practice plan
Push a value onto an array declared with const and show the new length.
Passes when: #out should show 4.
6.Fix the missing commasbug fix · easy · 8 min
The array was written without separators, so it holds one value instead of three.
Passes when: #out should show 3.
7.Fix the wrong bracketsbug fix · easy · 8 min · practice plan
Curly braces make an object, not an array, so there is no length.
Passes when: #out should show 2.
8.Fix length called as a functionbug fix · easy · 8 min · practice plan
length is a property, not a method.
Passes when: #out should show 5.
9.Fix the flat gridbug fix · easy · 8 min · practice plan
The grid should hold rows, but every value was put in one list.
Passes when: #out should show row of 3.
10.Fix the array that was replacedbug fix · easy · 8 min · practice plan
Building a new array loses the earlier values instead of adding to them.
Passes when: #out should show a,b,c.
Between them these tasks cover Array literals, length and Nested arrays.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.