Chapter 15. JavaScript 4: Objects and Arrays Table of Contents



Download 0.78 Mb.
View original pdf
Page15/16
Date04.04.2022
Size0.78 Mb.
#58550
1   ...   8   9   10   11   12   13   14   15   16
chp15
15.2.12 Array activities

Activity 1: Creating and displaying elements of an array

Write an HTML file that creates an array called ages containing the following numbers 21, 14, 33, 66, 11. Write code so that the values of array elements 0, 1 and 3 are displayed. The screen should look similar to the following when the page is loaded You can find a discussion of this activity at the end of the unit.
Activity 2: Iterating through array contents

Create an array called primes containing the following numbers 1, 2, 3, 5, 7, 11. Write awhile loop that will iterate (loop) through each element of the array, displaying each number on a separate line. Your code should be written in a general way, so if more numbers were added to the array (say 13, 17 and 19) the loop code would not need to be changed. The browser output should be something like You can find a discussion of this activity at the end of the unit.

Download 0.78 Mb.

Share with your friends:
1   ...   8   9   10   11   12   13   14   15   16




The database is protected by copyright ©ininet.org 2024
send message

    Main page