Skip to content

Commit d0c4a60

Browse files
committed
Merge pull request #66 from CactaurMan36/master
Added Arrays chapter
2 parents cd0b6fd + 1263801 commit d0c4a60

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

SUMMARY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
* [Else](conditional/else.md)
1919
* [Comparators](conditional/comparators.md)
2020
* [Concatenate](conditional/concatenate.md)
21+
* [Arrays](arrays/README.md)
22+
* [Indicies](indicies.md)
23+
* [Length](length.md)
2124
* [Loops](loops/README.md)
2225
* [For](loops/for.md)
2326
* [While](loops/while.md)

arrays/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Arrays
2+
3+
Arrays are a fundamental part of programming. An array is a list of data. We can store a lot of data in one variable, which makes our code more readable and easier to understand. It also makes it much easier to perform functions on related data.
4+
5+
The data in arrays are called **elements**.
6+
7+
Here is a simple array:
8+
```javascript
9+
// 1, 1, 2, 3, 5, and 8 are the elements in this array
10+
var numbers = [1, 1, 2, 3, 5, 8];
11+
```

arrays/indicies.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Indicies
2+
3+
So you have your array of data elements, but what if you want to access a specific element? That is where indicies come in. An **index** refers to a spot in the array. Indicies logically progress one by one, but it should be noted that the first index in an array is 0, as it is in most languages. Brackets [] are used to signify you are referring to an index of an array.
4+
5+
```javascript
6+
// This is an array of strings
7+
var fruits = ["apple", "banana", "pineapple", "strawberry"];
8+
9+
// We set the variable banana to the value of the second element of
10+
// the fruits array. Remember that indicies start at 0, so 1 is the
11+
// second element. Result: banana = "banana"
12+
var banana = fruits[1];
13+
```
14+
---
15+
16+
Define the variables using the indices of the array
17+
18+
```js
19+
var cars = ["Mazda", "Honda", "Chevy", "Ford"]
20+
var honda =
21+
var ford =
22+
var chevy =
23+
var mazda =
24+
```
25+
26+
```js
27+
var cars = ["Mazda", "Honda", "Chevy", "Ford"]
28+
var honda = cars[1];
29+
var ford = cars[3];
30+
var chevy = cars[2];
31+
var mazda = cars[0];
32+
```
33+
34+
```js
35+
assert(honda === "Honda");
36+
assert(ford === "Ford");
37+
assert(chevy === "Chevy");
38+
assert(mazda === "Mazda");
39+
```
40+
41+
---

arrays/length.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Length
2+
3+
Arrays have a property called length, and it's pretty much exactly as it sounds, it's the length of the array.
4+
5+
```javascript
6+
var array = [1 , 2, 3];
7+
8+
// Result: l = 3
9+
var l = array.length;
10+
```
11+
12+
---
13+
14+
Define the variable a to be the number value of the length of the array
15+
16+
```js
17+
var array = [1, 1, 2, 3, 5, 8];
18+
var l = array.length;
19+
var a =
20+
```
21+
22+
```js
23+
var array = [1, 1, 2, 3, 5, 8];
24+
var l = array.length;
25+
var a = 6;
26+
```
27+
28+
```js
29+
assert (a === 6)
30+
```
31+
---

0 commit comments

Comments
 (0)