Lesson 1 of 8

Rendering arrays on the page

Goal

Turn data into elements on the page

01

Explanation

Real interfaces aren't written by hand one element at a time: they're built from data. An array is a list of values, and the map method turns each value in it into something else.

So ['a','b'].map(x => '<li>' + x + '</li>') gives you an array of tags, and join('') combines them into a single string that you put in innerHTML.

Always keep this rule in mind: the data comes first, and the interface follows from it. Change the array and the page changes with it.

02

Your task

Show each item of fruits in its own <li> element inside the list.

Checks

4 checks
  1. The list has four li elements
  2. The first item is "Apple"
  3. The last item is "Fig"
  4. The items are in the same order as the array
03

Hints

0/3
Track lessons0 of 8 done

Work with data, functions and operations that take time, and build up to an interface that creates its elements from data.

Intermediate level, 8 lessons, 2 hours in total.

index.html
Preview
index.html100%
–/4

Press “Run and check” to grade your code.

4 checks listed under “Your task”.

Track lessons0 of 8 done

Work with data, functions and operations that take time, and build up to an interface that creates its elements from data.

Intermediate level, 8 lessons, 2 hours in total.