In this activity, you will generate a comma-separated list of nouns and display it on a web page.
For example, this array:
const nouns = [`one`, `two`, `three`];
Should be display on the page as a sentence in the following format:
One, Two and Three.
- Declare an empty string variable named
output
or similar. - Create a
for
loop so thati
iterates through each index of the array:- initialized at
i = 0
; - increments by one with each iteration;
- stops after
i
equalsArray.length - 1
.
- initialized at
- Inside the
for
loop, use theoutput
variable and the addition assignment operator (+=
) (or another method of your choice) to create a comma-separated of nouns so that (for example):- the first character of each noun is capitalized;
- each noun is separated by a comma;
- the last noun is separated by the word
and
.
- Finally, after the
for
loop finishes, useElement.innerHTML
to assign youroutput
string to a paragraph element.