-
Notifications
You must be signed in to change notification settings - Fork 7
/
activity-arrays.html
84 lines (67 loc) · 3.65 KB
/
activity-arrays.html
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html>
<head>
<title>AC Workshop - Activity: Arrays</title>
<link rel="stylesheet" type="text/css" href="styles.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.3.0/styles/default.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.3.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>
<body>
<div class="container">
<div class="container-inner">
<div class="left-sidebar">
<div class="home-anchor">
<h3><a href="index.html">Intro to Programming with JavaScript</a></h3>
</div>
<div class="navigation-links">
<div class="navigation-link-item"><a href="activity-logging.html">Activity: Logging</a></div>
<div class="navigation-link-item"><a href="lecture-variables.html">Lecture: Variables</a></div>
<div class="navigation-link-item"><a href="activity-variables.html">Activity: Variables</a></div>
<div class="navigation-link-item"><a href="lecture-arrays.html">Lecture: Arrays</a></div>
<div class="navigation-link-item"><strong><em><a href="activity-arrays.html">Activity: Arrays</a></em></strong></div>
<div class="navigation-link-item"><a href="lecture-conditionals.html">Lecture: Conditionals</a></div>
<div class="navigation-link-item"><a href="activity-conditionals.html">Activity: Conditionals</a></div>
<div class="navigation-link-item"><a href="assignment-webproposal.html">Assignment: Web App Proposal</a></div>
<div class="navigation-link-item"><a href="lecture-loops.html">Lecture: Loops</a></div>
<div class="navigation-link-item"><a href="activity-arraysadvanced.html">Activity: Arrays (Advanced)</a></div>
<div class="navigation-link-item"><a href="lecture-functions.html">Lecture: Functions</a></div>
<div class="navigation-link-item"><a href="activity-functions.html">Activity: Functions</a></div>
<div class="navigation-link-item"><a href="activity-fizzbuzz.html">Activity: Fizz Buzz</a></div>
<div class="navigation-link-item"><a href="teamchallenge.html">Team Challenge</a></div>
</div>
</div>
<div class="content">
<h1>Activity: Arrays</h1>
<p>
Let's start with an array of some films, books, or tv shows that you like:
</p>
<pre><code>let films = ["Starship Troopers", "Total Recall", "Robocop", "Basic Instinct"]
let books = ["East of Eden", "White Noise", "100 Years of Solitude"]</code></pre>
<p>
And then let's use the <code>.push()</code> method to add more names!
</p>
<pre><code>//Let's add some values to our array using `.push()`
console.log("I have " + films.length + " favorite films")
//Push some more and see the length change!</code></pre>
<h2>What's broken in this code?</h2>
<p>
This code is trying to change the value of the <b>first</b> element to -10 and the value of the <b>last</b> element to 10, but it's broken! Why?!
</p>
<pre><code>myArray = 66,27,108,44,92,1,100
myArray[1] = -10
myArray[array.length] = 10</code></pre>
<h2>Pair with a new neighbor for these challenges!</h2>
<ol>
<li>Create an array and assign it to a variable.</li>
<li>Log the first element of your array.</li>
<li>Log the second element of your array.</li>
<li>Log the last element of your array. <i>Hint: how can you find out how long your array is?</i> It should always print out the last element even if you add or remove elements from the array</li>
<li>Log the second to last element of your array.</li>
<li>Log the middle element of the array (rounded down if there are an even number of elements).</li>
</ol>
</div>
</div>
</div>
</body>
</html>