Skip to content

Commit 1be7dcf

Browse files
minor updates
1 parent 6260c78 commit 1be7dcf

1 file changed

Lines changed: 29 additions & 55 deletions

File tree

javascript.html

Lines changed: 29 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ <h1>Web Programming & Interactivity with JavaScript</h1>
4040

4141
<section id="overview">
4242
<h2>Overview</h2>
43-
<p>This workshop introduces <strong>JavaScript</strong> as the programming layer of the web. It is designed for <strong>researchers, librarians, and research staff</strong> who already have basic familiarity with HTML and CSS and want to add <em>interactivity</em> to research pages.</p>
44-
45-
43+
<p>This workshop introduces <strong>JavaScript</strong> as the programming layer of the web.
44+
You should already have basic familiarity with HTML and CSS prior to proceeding.</p>
4645
<ul>
4746
<li><strong>Duration:</strong> 2 hours</li>
4847
<li><strong>Prerequisites:</strong> Basic HTML & CSS</li>
@@ -64,15 +63,9 @@ <h2>Setup</h2>
6463
</li>
6564
</ul>
6665
<p>
67-
To load this index.js file within your webpage use:
68-
<pre><code id="code-container"></code></pre>
69-
<script>
70-
// The raw HTML code you want to display
71-
var rawHTML = '<script src="js/index.js">< /script>';
72-
73-
// Set the textContent property to display the code as text
74-
document.getElementById('code-container').textContent = rawHTML;
75-
</script>
66+
To load this index.js file within your webpage add the following line to the <i>&lt;head&gt;</i> element of your HTML file:
67+
<pre><code id="code-container">&lt;script src="js/index.js">&lt;/script></code></pre>
68+
7669
</p>
7770
</section>
7871

@@ -115,7 +108,7 @@ <h3>Variables</h3>
115108
<li>Not be a reserved keyword</li>
116109
</ul>
117110

118-
<p>JavaScript is case-sensitive. So variables named 'age' and 'Age' are different. Best to keep varaibles</p>
111+
<p>JavaScript is case-sensitive. So variables named 'age' and 'Age' are different. Best to keep variables in consistent case (e.g., camelCase).</p>
119112
<h4>Variable Types</h4>
120113
<h5>String</h5>
121114
<pre><code>
@@ -146,7 +139,7 @@ <h5>Object</h5>
146139
role: "Researcher"
147140
};
148141

149-
//to get the 'name' key two ways
142+
//to get the 'name' key (two ways)
150143
console.log(user.name, user['name'])
151144
</code></pre>
152145

@@ -183,7 +176,8 @@ <h3>Functions</h3>
183176
return "Welcome, " + name;
184177
}</code></pre>
185178

186-
<pre><code>// As an arrow function
179+
<pre><code>// As an arrow function
180+
// structure: const functionName = (parameters) => { function body };
187181
const greetUser = (name) => {
188182
return "Welcome, " + name;
189183
};</code></pre>
@@ -193,17 +187,15 @@ <h3>Functions</h3>
193187

194188
<h3>Conditionals</h3>
195189
<h4>if</h4>
196-
<pre><code>
197-
const temperature = 85;
190+
<pre><code>const temperature = 85;
198191

199192
if (temperature > 80) {
200193
console.log("It's hot outside");
201194
}
202195
</code></pre>
203196

204197
<h4>if / else</h4>
205-
<pre><code>
206-
const isLoggedIn = false;
198+
<pre><code>const isLoggedIn = false;
207199

208200
if (isLoggedIn) {
209201
console.log("Welcome back!");
@@ -213,8 +205,7 @@ <h4>if / else</h4>
213205
</code></pre>
214206

215207
<h4>if / else if / else</h4>
216-
<pre><code>
217-
const score = 72;
208+
<pre><code>const score = 72;
218209

219210
if (score >= 90) {
220211
console.log("Grade: A");
@@ -228,17 +219,15 @@ <h4>if / else if / else</h4>
228219
</code></pre>
229220

230221
<h4>Comparison operators in conditionals</h4>
231-
<pre><code>
232-
5 === 5 // true (strict equality)
222+
<pre><code>5 === 5 // true (strict equality)
233223
5 == "5" // true (type coercion – usually avoid)
234224
5 !== 3 // true
235225
10 > 3 // true
236226
5 <= 5 // true
237227
</code></pre>
238228

239229
<h4>Logical operators (&&, ||, !)</h4>
240-
<pre><code>
241-
const isAdmin = true;
230+
<pre><code>const isAdmin = true;
242231
const isLoggedIn = true;
243232

244233
if (isAdmin && isLoggedIn) {
@@ -254,7 +243,7 @@ <h4>Logical operators (&&, ||, !)</h4>
254243

255244
</code></pre>
256245

257-
<h4>switch statement</h4>
246+
<h4>Switch Statement</h4>
258247
Good when comparing one value against many options.
259248
<pre><code>
260249
const day = "Monday";
@@ -278,15 +267,13 @@ <h4>switch statement</h4>
278267

279268
<h3>Loops</h3>
280269
<h4>for loop (classic)</h4>
281-
<pre><code>
282-
for (let i = 0; i < 5; i++) {
270+
<pre><code>for (let i = 0; i < 5; i++) {
283271
console.log(i);
284272
}
285273
</code></pre>
286274

287275
<h4>Looping through an array with for</h4>
288-
<pre><code>
289-
const colors = ["red", "green", "blue"];
276+
<pre><code>const colors = ["red", "green", "blue"];
290277

291278
for (let i = 0; i < colors.length; i++) {
292279
console.log(colors[i]);
@@ -295,8 +282,7 @@ <h4>Looping through an array with for</h4>
295282

296283
<h4>for...of (modern & clean)</h4>
297284
Best for looping over values in arrays and strings.
298-
<pre><code>
299-
const fruits = ["apple", "banana", "orange"];
285+
<pre><code>const fruits = ["apple", "banana", "orange"];
300286

301287
for (const fruit of fruits) {
302288
console.log(fruit);
@@ -305,8 +291,7 @@ <h4>for...of (modern & clean)</h4>
305291

306292
<h4>for...in (objects)</h4>
307293

308-
<pre><code>
309-
const user = {
294+
<pre><code>const user = {
310295
name: "Kevin",
311296
role: "Researcher"
312297
};
@@ -318,8 +303,7 @@ <h4>for...in (objects)</h4>
318303

319304
<h4>while loop</h4>
320305
Runs while a condition is true.
321-
<pre><code>
322-
let count = 0;
306+
<pre><code>let count = 0;
323307

324308
while (count < 3) {
325309
console.log(count);
@@ -329,8 +313,7 @@ <h4>while loop</h4>
329313

330314
<h4>do...while</h4>
331315
Runs at least once, even if the condition is false.
332-
<pre><code>
333-
let num = 5;
316+
<pre><code>let num = 5;
334317
do {
335318
console.log(num);
336319
num++;
@@ -339,8 +322,7 @@ <h4>do...while</h4>
339322

340323
<h4>break and continue</h4>
341324

342-
<pre><code>
343-
for (let i = 1; i <= 5; i++) {
325+
<pre><code>for (let i = 1; i <= 5; i++) {
344326
if (i === 3) {
345327
continue; // skip 3
346328
}
@@ -354,8 +336,7 @@ <h4>break and continue</h4>
354336
</code></pre>
355337
<h4>Array methods (loops you’ll actually use a lot)</h4>
356338
<h5>Array methods (loops you’ll actually use a lot)</h5>
357-
<pre><code>
358-
const numbers = [1, 2, 3];
339+
<pre><code>const numbers = [1, 2, 3];
359340

360341
numbers.forEach(num => {
361342
console.log(num * 2);
@@ -389,26 +370,21 @@ <h5>reduce</h5>
389370
</section>
390371
<section id="exercise_1">
391372
<h2>Mini Exercise (5–7 min)</h2>
392-
<p>Write and test a function that converts fahrenheit to celsius</p>
373+
<p>Write and test a function called 'fToC' that converts fahrenheit to celsius</p>
393374

394-
<pre><code>
395-
396-
//Step 1: create fahrenheit to celsius function noting that F = (C * 9/5) + 32
375+
<pre><code>//Step 1: create fahrenheit to celsius function noting celsius = (fahrenheit - 32) * 5 / 9
397376

398377
// Step 2: test the function with different values to make sure it works as expected
399378
</code></pre>
400379

401-
402380
When you're done, save the file and test it in your web browser.
403381
</section>
404382
<section id="dom">
405383
<h2>The DOM: Connecting JavaScript to HTML</h2>
406384
<p>The <strong>Document Object Model (DOM)</strong> allows JavaScript to read and change HTML.</p>
407385
<p>To make sure the HTML elements are present before the JavaScript runs,
408-
be sure to wait for the 'DOMContentLoaded' event to fire.</p>
409-
<pre><code>
410-
// Select an element
411-
document.addEventListener('DOMContentLoaded', () => {
386+
be sure to wait for the 'DOMContentLoaded' event to fire, see below</p>
387+
<pre><code>document.addEventListener('DOMContentLoaded', () => {
412388
// Select an element
413389
const heading = document.querySelector("h1");
414390
console.log(heading)
@@ -418,13 +394,11 @@ <h2>The DOM: Connecting JavaScript to HTML</h2>
418394
});</code></pre>
419395

420396
<p>Think of the DOM as a bridge between your HTML structure and JavaScript logic.</p>
421-
422-
423397
</section>
424398

425399
<section id="events">
426400
<h2>Events & User Interaction</h2>
427-
<p>Events allow your page to respond to user actions such as clicks or typing.
401+
<p>Events allow your page to respond to user actions such as clicks or typing.>
428402
The following example shows how to show/hide an element:
429403
</p>
430404
<h3>HTML</h3>
@@ -479,7 +453,7 @@ <h2>Looping through DOM elements</h2>
479453
</section>
480454
<section id="tabs">
481455
<h2>Tabs</h2>
482-
<p>Often time the web interface isn't large enough to show all the content at once. A common solution is to use tabs to show and hide different sections of content.
456+
<p>Often times the web interface isn't large enough to show all the content at once. A common solution is to use tabs to show and hide different sections of content.
483457
The following example shows how to show/hide different content sections using JavaScript and CSS.</p>
484458
<h3>HTML</h3>
485459
<pre><code>

0 commit comments

Comments
 (0)