- Open the project in Visual Studio Code
- Start the Live Server
- Open the Console tab on Chrome's DevTools
-
Create an array
names
with at least 3 elements:'david'
,'gordon'
, and'sahil'
and log it to the console -
Log the value of the third element in
names
to the console -
Log the value of the
names
array'slength
property to the console -
Set the value of the
length
property to1
-
Once again, log the value of the
names
array'slength
property to the console. Did it change? -
Log the entire
names
array to the console again -
Add a few more elements to the array
-
Log the last element of the array to the console
-
Log the second last element of the array to the console
-
Change the
textContent
property of the secondp
tag on the page to"JavaScript was here!"
-
Convert the
names
array to a string, with each element separated by a '<br>'. Store it in a new variable callednamesString
e.g. ifnames
is['harry', 'ron', 'dean']
thennamesString
will be"harry<br>ron<br>dean"
-
Change the
innerHTML
property of the firstp
tag on the page tonamesString
. What happens when you usetextContent
instead ofinnerHTML
?
-
Create a new array
shoppingList
with a few string elements -
Using
forEach
, log every element of theshoppingList
array to the console -
For each element in the
shoppingList
array, create an<li>
node and append it to the<ul>
element on the page (usedocument.createElement
and.appendChild
) -
Create a new array
numbers
with a few numeric elements -
Using
map
on thenumbers
array, create a new array calledsquareNumbers
where each element is the square of the corresponding element in thenumbers
array