Learn JavaScript basics and interact with web pages using the DOM! We'll compare JavaScript to C# and build an interactive Book Library webpage. (Ages 8-18)
Session Date: Saturday, March 21, 2026 at 11:00 AM EST
| ๐ง Elementary (8-11) | ๐ง Middle School (12-14) | ๐ High School (15-18) | |
|---|---|---|---|
| ๐ค JS Basics | Understand variables and functions | Use arrays and objects | Compare C# and JS patterns |
| ๐ณ DOM | Select elements by ID | Use querySelector and loops | Create dynamic content |
| ๐ฎ Events | Handle click events | Work with forms and input | Build event-driven apps |
| ๐พ Storage | See data persist | Use localStorage basics | Build full CRUD with storage |
| ๐ By End | Click buttons to change page | Add/remove books dynamically | Complete library with persistence |
๐ฌ Setup: Students physically arrange themselves to form a DOM tree
๐ Scenario: Building a Web Page
THE DOM IS A FAMILY TREE! ๐ณ
One student is <html> (the grandparent)
โ
โโโโโโโโโโโดโโโโโโโโโโ
โ โ
<head> <body>
(one student) (one student)
โ โ
โ โโโโโโโโโผโโโโโโโโ
<title> <header> <main> <footer>
โ
โโโโโโโดโโโโโโ
<h1> <div>
โ
โโโโโโโดโโโโโโ
<p> <button>
INSTRUCTIONS:
1. Students hold signs with tag names
2. They link arms with their "parent" and "children"
3. Teacher calls out: "Find the <button>!"
4. Trace the path: html โ body โ main โ div โ button
๐ฌ Discussion:
"JavaScript uses the DOM to find and change elements. When we say
document.getElementById('myButton'), we're asking JavaScript to walk down this family tree and find that element!"
๐ One partner says C#, the other translates to JavaScript:
C# TO JAVASCRIPT TRANSLATION ๐
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ C# (What you know) โ JavaScript (New!) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ โ
โ string name = "Sam"; โ let name = "Sam"; โ
โ โ โ โ โ
โ [Declare type explicitly] โ [Let JS figure out type] โ
โ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ โ
โ int age = 12; โ let age = 12; โ
โ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ โ
โ void SayHello() { } โ function sayHello() { } โ
โ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ โ
โ Console.WriteLine(x); โ console.log(x); โ
โ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ โ
โ List<string> books = โ let books = []; โ
โ new List<string>(); โ โ
โ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ โ
โ books.Add("Harry Potter"); โ books.push("Harry Potter"); โ
โ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ฏ KEY INSIGHT: JavaScript is more relaxed about types!
C# says: "Tell me EXACTLY what type this is!"
JavaScript says: "I'll figure it out, don't worry!"
๐ก Key Insight:
"You already know programming! JavaScript just uses different words for the same ideas."
๐ฑ Pass a message through the chain:
EVENT FLOW - Like a Game of Telephone! ๐
โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ
โ USER โโโโโถโ BROWSER โโโโโถโ DOM โโโโโถโ YOUR โโโโโถโ PAGE โ
โ clicks โ โ detects โ โ creates โ โ CODE โ โ UPDATES โ
โ button โ โ click โ โ "event" โ โ runs โ โ โจ โ
โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ
ROLE PLAY:
1. ๐ Student 1 (User): "I clicked the Add Book button!"
2. ๐ฅ๏ธ Student 2 (Browser): "Click detected at button#addBook!"
3. ๐ Student 3 (DOM): "Creating click event with target: addBook"
4. ๐ป Student 4 (Code): "Running addBook function!"
5. โจ Student 5 (Page): "New book card appears on screen!"
This is EXACTLY what happens with:
button.addEventListener('click', addBook);
๐ฏ Takeaway:
"Events are how your webpage LISTENS for user actions. You're setting up a listener that waits patiently until something happens!"
HOW JAVASCRIPT SEES YOUR WEB PAGE ๐ณ
document
โ
โ
<html>
โ
โโโโโโโโโโโโโโโดโโโโโโโโโโโโโโ
โ โ
<head> <body>
โ โ
โโโโโโโโดโโโโโโโ โโโโโโโโโโโผโโโโโโโโโโ
โ โ โ โ โ
<title> <link> <header> <main> <footer>
"Book Library" CSS file โ โ
โ โโโโโโดโโโโโ
<h1> <form> <div>
id="bookList"
โ
โโโโโโโผโโโโโโ
โ โ โ
<div> <div> <div>
book1 book2 book3
๐ FINDING ELEMENTS:
document.getElementById('bookList')
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
Returns the <div id="bookList"> element!
document.querySelector('.book-card')
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
Returns the FIRST element with class "book-card"
document.querySelectorAll('.book-card')
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
Returns ALL elements with class "book-card" (as a list!)
HOW EVENTS WORK IN JAVASCRIPT ๐ฏ
STEP 1: SET UP A LISTENER ๐
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
const button = document.getElementById('addBtn');
button.addEventListener('click', handleClick);
โ โ โ โ
โ โ โ โโโ Function to run
โ โ โโโ What event to listen for
โ โโโ "Hey, listen for events!"
โโโ The element we're watching
STEP 2: USER INTERACTS ๐
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ฑ๏ธ User clicks the button
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ CLICK EVENT! ๐ฅ โ
โ โ
โ target: <button> โ
โ type: "click" โ
โ timestamp: 12345 โ
โโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
Your function runs! ๐
STEP 3: YOUR CODE RESPONDS ๐ป
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
function handleClick(event) {
console.log("Button was clicked!");
// Add a new book, show a message, etc.
}
COMMON EVENTS ๐
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
'click' โ User clicks something
'submit' โ Form is submitted
'input' โ Text is typed in a field
'keydown' โ Key is pressed
'mouseover' โ Mouse hovers over element
'load' โ Page finishes loading
Session17/
โโโ README.md โ ๐ This lesson plan
โโโ index.html โ ๐ The webpage structure
โโโ styles.css โ ๐จ Makes it look pretty
โโโ script.js โ ๐ป JavaScript code (the magic!)
โโโ .gitignore โ ๐ซ Files Git should ignore
- โ Completed Sessions 1-15 (C# fundamentals & API)
- โ Understanding of variables, functions, and loops
- โ Basic understanding of HTML from Session 16
- Go to GitHub and Fork the Session17 repository
- Clone to your computer:
git clone https://github.com/YOUR-USERNAME/Session17-JavaScript.git
๐ Open index.html and examine:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>๐ My Book Library</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>๐ My Book Library</h1>
</header>
<main>
<!-- ๐ Form to add new books -->
<form id="bookForm">
<input type="text" id="titleInput" placeholder="Book Title" required>
<input type="text" id="authorInput" placeholder="Author" required>
<button type="submit">โ Add Book</button>
</form>
<!-- ๐ Where our books will appear -->
<div id="bookList"></div>
</main>
<script src="script.js"></script>
</body>
</html>๐ Key parts:
HTML STRUCTURE BREAKDOWN ๐
<form id="bookForm">
โโโ Has an ID so JavaScript can find it!
<input id="titleInput">
โโโ We'll get the typed value from here
<div id="bookList">
โโโ Empty now, JavaScript will fill it with books!
<script src="script.js">
โโโ Loads our JavaScript file (put at bottom!)
๐ Open script.js and start coding:
// ๐ฏ STEP 1: Wait for the page to load
document.addEventListener('DOMContentLoaded', function() {
console.log('๐ Page loaded! JavaScript is ready!');
// All our code goes inside here
});๐ก Why wait for DOMContentLoaded?
PAGE LOADING TIMELINE โฑ๏ธ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 1. Browser starts downloading HTML โ
โ 2. Browser parses HTML, building the DOM tree โ
โ 3. Browser hits <script> tag โ
โ 4. JavaScript tries to run... โ
โ โ
โ โ WITHOUT DOMContentLoaded: โ
โ JavaScript might run before elements exist! โ
โ document.getElementById('bookList') = null ๐ฑ โ
โ โ
โ โ
WITH DOMContentLoaded: โ
โ JavaScript waits until DOM is fully built โ
โ document.getElementById('bookList') = <div> ๐ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Add to script.js:
document.addEventListener('DOMContentLoaded', function() {
// ๐ฏ STEP 2: Grab references to our HTML elements
const bookForm = document.getElementById('bookForm');
const titleInput = document.getElementById('titleInput');
const authorInput = document.getElementById('authorInput');
const bookList = document.getElementById('bookList');
console.log('๐ Form found:', bookForm);
console.log('๐ Book list found:', bookList);
});๐ Compare to C#:
SELECTING ELEMENTS: C# vs JavaScript
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ C# (Finding a control in WinForms/WPF) โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ TextBox titleBox = this.Controls.Find("titleInput"); โ
โ โ
โ JavaScript (Finding an element in DOM) โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ const titleInput = document.getElementById('titleInput'); โ
โ โ
โ Same concept! Different syntax! โจ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Add a books array:
document.addEventListener('DOMContentLoaded', function() {
// ... element references from Step 4 ...
// ๐ฏ STEP 3: Create an array to store our books
let books = [];
// ๐ Let's start with some sample books
books = [
{ id: 1, title: 'Harry Potter', author: 'J.K. Rowling' },
{ id: 2, title: 'The Hobbit', author: 'J.R.R. Tolkien' },
{ id: 3, title: 'Diary of a Wimpy Kid', author: 'Jeff Kinney' }
];
console.log('๐ Books:', books);
});๐ Compare to C#:
ARRAYS/LISTS: C# vs JavaScript
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ C# (Typed List with Class) โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ List<Book> books = new List<Book> โ
โ { โ
โ new Book { Id = 1, Title = "Harry Potter" }, โ
โ new Book { Id = 2, Title = "The Hobbit" } โ
โ }; โ
โ โ
โ JavaScript (Flexible Array with Objects) โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ let books = [ โ
โ { id: 1, title: 'Harry Potter' }, โ
โ { id: 2, title: 'The Hobbit' } โ
โ ]; โ
โ โ
โ ๐ KEY DIFFERENCES: โ
โ โข JS uses let instead of List<Type> โ
โ โข JS objects use { } without "new" โ
โ โข JS properties are lowercase by convention โ
โ โข JS uses single quotes ' ' (or double " ") โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Add a function to render books:
// ๐ฏ STEP 4: Function to display all books
function displayBooks() {
// Clear the current list
bookList.innerHTML = '';
// Loop through each book and create HTML
books.forEach(function(book) {
// Create a new div for this book
const bookCard = document.createElement('div');
bookCard.className = 'book-card';
bookCard.setAttribute('data-id', book.id);
// Set the content
bookCard.innerHTML = `
<h3>๐ ${book.title}</h3>
<p>โ๏ธ by ${book.author}</p>
<button class="delete-btn" onclick="deleteBook(${book.id})">
๐๏ธ Delete
</button>
`;
// Add it to the page
bookList.appendChild(bookCard);
});
console.log('๐ Displayed', books.length, 'books');
}
// Call it to show initial books
displayBooks();๐ What's happening:
CREATING ELEMENTS DYNAMICALLY ๐๏ธ
document.createElement('div')
โโโ Creates a new <div> element (not on page yet!)
bookCard.className = 'book-card'
โโโ Adds the CSS class for styling
bookCard.innerHTML = `...`
โโโ Sets the HTML content inside the div
(The ` ` backticks allow multi-line strings!)
bookList.appendChild(bookCard)
โโโ Actually adds the element to the page!
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Before appendChild: โ After appendChild: โ
โ โ โ
โ <div id="bookList"> โ <div id="bookList"> โ
โ </div> โ <div class="book-card"> โ
โ โ ๐ Harry Potter โ
โ (Empty!) โ </div> โ
โ โ </div> โ
โ โ โ
โ โ (Book appears! โจ) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Add event listener for the form:
// ๐ฏ STEP 5: Listen for form submissions
bookForm.addEventListener('submit', function(event) {
// ๐ Stop the form from refreshing the page!
event.preventDefault();
// Get the values from the input fields
const title = titleInput.value.trim();
const author = authorInput.value.trim();
// Validate - make sure fields aren't empty
if (title === '' || author === '') {
alert('โ ๏ธ Please fill in both fields!');
return;
}
// Create a new book object
const newBook = {
id: Date.now(), // Use timestamp as unique ID
title: title,
author: author
};
// Add to our array
books.push(newBook);
// Update the display
displayBooks();
// Clear the form
titleInput.value = '';
authorInput.value = '';
console.log('โ
Added new book:', newBook);
});๐ Why event.preventDefault()?
FORM BEHAVIOR ๐
DEFAULT BEHAVIOR (without preventDefault):
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 1. User clicks "Add Book" โ
โ 2. Form tries to submit to a server โ
โ 3. Page refreshes! ๐ฑ โ
โ 4. All your JavaScript variables are GONE! โ
โ 5. Books array is reset to empty! ๐ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
WITH preventDefault():
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 1. User clicks "Add Book" โ
โ 2. event.preventDefault() says "STOP! Don't refresh!" โ
โ 3. Our JavaScript code runs instead โจ โ
โ 4. We handle the data ourselves โ
โ 5. Page stays loaded, books are safe! ๐ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Add delete function (outside the DOMContentLoaded):
// ๐ฏ STEP 6: Function to delete a book
// (This needs to be global so onclick can find it)
function deleteBook(id) {
// Confirm before deleting
if (!confirm('Are you sure you want to delete this book?')) {
return;
}
// Filter out the book with this ID
books = books.filter(function(book) {
return book.id !== id;
});
// Update the display
displayBooks();
// Save to localStorage
saveBooks();
console.log('๐๏ธ Deleted book with ID:', id);
}๐ Compare to C#:
FILTERING/REMOVING: C# vs JavaScript
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ C# (LINQ) โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ books = books.Where(b => b.Id != id).ToList(); โ
โ โ
โ JavaScript (Array filter) โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ books = books.filter(book => book.id !== id); โ
โ โ
โ Same idea! Both create a NEW list without that item! ๐ฏ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Add functions to save and load:
// ๐ฏ STEP 7: Save books to localStorage
function saveBooks() {
// Convert array to JSON string and save
localStorage.setItem('myBooks', JSON.stringify(books));
console.log('๐พ Books saved to localStorage!');
}
// ๐ฏ STEP 8: Load books from localStorage
function loadBooks() {
const savedBooks = localStorage.getItem('myBooks');
if (savedBooks) {
// Parse JSON string back to array
books = JSON.parse(savedBooks);
console.log('๐ Loaded', books.length, 'books from storage!');
} else {
// No saved books, use defaults
books = [
{ id: 1, title: 'Harry Potter', author: 'J.K. Rowling' },
{ id: 2, title: 'The Hobbit', author: 'J.R.R. Tolkien' }
];
console.log('๐ Using default books');
}
}๐ What is localStorage?
LOCAL STORAGE - Your Browser's Memory ๐พ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ localStorage is like a tiny database in your browser! โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Browser Storage โ โ
โ โ โ โ
โ โ KEY โ VALUE โ โ
โ โ โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ "myBooks" โ "[{id:1,title:'Harry Potter'}]" โ โ
โ โ "userName" โ "Sam" โ โ
โ โ "darkMode" โ "true" โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ ๐ Data persists even after closing the browser! โ
โ ๐ Each website has its own storage (can't see others) โ
โ ๐ Limited to ~5-10MB per website โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
METHODS:
localStorage.setItem('key', 'value') โ Save data
localStorage.getItem('key') โ Read data
localStorage.removeItem('key') โ Delete data
localStorage.clear() โ Delete ALL data
๐ Complete script.js structure:
// ๐ Book Library - JavaScript Edition!
// Books array (will be loaded from storage)
let books = [];
// DOM Elements (set in DOMContentLoaded)
let bookForm, titleInput, authorInput, bookList;
// ๐พ Save books to localStorage
function saveBooks() {
localStorage.setItem('myBooks', JSON.stringify(books));
}
// ๐ Load books from localStorage
function loadBooks() {
const saved = localStorage.getItem('myBooks');
if (saved) {
books = JSON.parse(saved);
} else {
books = [
{ id: 1, title: 'Harry Potter', author: 'J.K. Rowling' },
{ id: 2, title: 'The Hobbit', author: 'J.R.R. Tolkien' }
];
}
}
// ๐ Display all books
function displayBooks() {
bookList.innerHTML = '';
books.forEach(function(book) {
const card = document.createElement('div');
card.className = 'book-card';
card.innerHTML = `
<h3>๐ ${book.title}</h3>
<p>โ๏ธ by ${book.author}</p>
<button class="delete-btn" onclick="deleteBook(${book.id})">๐๏ธ Delete</button>
`;
bookList.appendChild(card);
});
}
// ๐๏ธ Delete a book
function deleteBook(id) {
if (confirm('Delete this book?')) {
books = books.filter(book => book.id !== id);
displayBooks();
saveBooks();
}
}
// ๐ฌ When page loads
document.addEventListener('DOMContentLoaded', function() {
// Get DOM elements
bookForm = document.getElementById('bookForm');
titleInput = document.getElementById('titleInput');
authorInput = document.getElementById('authorInput');
bookList = document.getElementById('bookList');
// Load saved books
loadBooks();
displayBooks();
// Handle form submit
bookForm.addEventListener('submit', function(event) {
event.preventDefault();
const title = titleInput.value.trim();
const author = authorInput.value.trim();
if (title && author) {
books.push({
id: Date.now(),
title: title,
author: author
});
displayBooks();
saveBooks();
bookForm.reset();
}
});
console.log('๐ Book Library loaded!');
});git add .
git commit -m "Add interactive book library with JavaScript"
git push origin main๐ Circle Share - Answer one:
- "The biggest difference between C# and JavaScript is..."
- "DOM manipulation lets me..."
- "localStorage is useful because..."
- "Events in JavaScript are like..."
- ๐ Open index.html in browser (double-click or Live Server)
- ๐ Initial books display on page load
- โ Can add new books with form
-
โ ๏ธ Empty fields show alert - ๐๏ธ Can delete books with confirmation
- ๐พ Books persist after page refresh (localStorage works!)
- ๐ง No errors in browser console (F12 โ Console)
Add a search box that filters books as you type:
// Hint: Use the filter method and check if title includes search term
books.filter(book => book.title.toLowerCase().includes(searchTerm))Add an "Edit" button that lets you modify a book's title or author.
Replace localStorage with fetch() calls to your C# API from Sessions 11-15:
// Hint: Use fetch to call your API
fetch('http://localhost:5000/api/books')
.then(response => response.json())
.then(data => { books = data; displayBooks(); });Add CSS animations when books are added or deleted:
.book-card {
animation: fadeIn 0.3s ease-in;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(-20px); }
to { opacity: 1; transform: translateY(0); }
}| Term | ๐ Kid-Friendly Definition | ๐ป C# Comparison |
|---|---|---|
| ๐ณ DOM | The tree structure of your webpage that JavaScript can read and change | Like a UI form's Controls collection |
| ๐ let/const | Ways to declare variables in JavaScript | Like var or string in C# |
| ๐ง function | A reusable block of code | Same as C# methods! |
| ๐ Array | A list that holds multiple items | Like List<T> in C# |
| ๐ฆ Object | A container with properties | Like a C# class instance |
| ๐ฏ Event | Something that happens (click, type, etc.) | Like button click handlers |
| ๐ addEventListener | Tell JS to watch for an event | Like button.Click += handler |
| ๐พ localStorage | Browser storage that persists | Like saving to a file |
| ๐ JSON | Text format for data | Same JSON we used in APIs! |
| ๐ getElementById | Find one element by its ID | Like FindControl() |
| ๐ querySelector | Find elements with CSS selectors | Like LINQ queries for DOM |
๐จโ๐ฉโ๐ง Talk to a family member:
"Today I learned JavaScript! It's the language that makes websites interactive. When you click a button on a website and something happens without the page reloading - that's JavaScript! I built a book library where I can add and remove books, and it remembers them even after I close the browser."
๐ Real-world examples:
- ๐ Adding items to a shopping cart
- โค๏ธ Clicking "Like" on social media
- ๐ Google's search suggestions as you type
- ๐ฌ Chat messages appearing in real-time
๐ Activity: Open your browser's Developer Tools (F12) on any website and type in the Console:
document.body.style.backgroundColor = 'lightblue';Watch the page change! You just used JavaScript!
SESSION 17 COMPLETE! ๐
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
โ โ
You learned: โ
โ โข JavaScript syntax (compared to C#) โ
โ โข DOM selection and manipulation โ
โ โข Event handling โ
โ โข localStorage for persistence โ
โ โ
โ ๐ฎ Coming in Session 18: Fetch API & Async JavaScript โ
โ โข Connect your frontend to your C# API! โ
โ โข Learn about Promises and async/await โ
โ โข Build a full-stack application! โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
You're now a polyglot programmer - you know C# AND JavaScript! ๐