-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray-dot-length-property.js
38 lines (29 loc) · 1.21 KB
/
array-dot-length-property.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
Objective
Practice using the .length property in JavaScript to:
- Retrieve the length of an array.
- Use .length dynamically in logic and loops.
- Handle arrays that change size during execution.
Instructions
You will complete the following tasks using the .length property.
Ensure that your code is syntactically correct and outputs the expected results.
Task 1: Basic Length Retrieval
Given the array:
const fruits = ["apple", "banana", "cherry"];
Log the length of the array using the .length property.
Task 2: Dynamic Length Check
Start with the following array:
const tasks = ["Homework", "Laundry"];
Log "No tasks remaining!" if the array is empty (i.e., its length is 0),
otherwise log the number of tasks using the message: "You have [X] tasks remaining."
(replace [X] with the actual number).
Task 3: Looping with .length
Given the array:
const animals = ["dog", "cat", "elephant"];
Use a loop to log each animal.
Ensure the loop dynamically adjusts to the size of the array using the .length property.
Task 4: Adding and Tracking Length
Create an empty array called shoppingCart.
Add three items to the array dynamically (e.g., "milk", "bread", "eggs").
Log the updated length of the array after each addition.
*/