CS50 Week 8: HTML, CSS, JavaScript

Jun 13, 2024

CS50 Week 8: The Internet and Intro to Web Development

Bingo and Motivation

  • CS50 bingo card from a Yale student includes common phrases by Professor Malan.
  • Potential for prizes (cookies) as motivation for participation.

Overview of Week 8

  • Focus on the internet: how it works and building software on top of it.
  • Recap of previously learned languages (Scratch, C, Python, SQL).
  • Introduce HTML, CSS, JavaScript.

The Internet: History and Basics

History of the Internet

  • Late '60s, '70s: ARPANET project by the US Department of Defense.
  • Concept of internetworking computers using packets of information.
  • Evolution to modern interconnected systems.

How Data Travels

  • Routers: Computers that route data geographically from point A to point B.
  • Data packets may travel through multiple routers, around downed or overwhelmed servers.
  • Dynamic nature of routing for efficiency.

Protocols: TCP/IP

  • Internet Protocol (IP): Standardizes addresses.
    • IP address (e.g., 123.456.789.000) analogous to addresses in the physical world.
    • IPv4 and the shift to IPv6 due to the limited number of IPv4 addresses.
  • Transmission Control Protocol (TCP): Guarantees data delivery and allows multiple services (email, web, etc.) via ports.
    • Sequence numbers for tracking packets.
    • Port numbers for identifying services.

DNS and Domain Names

  • Domain Name System (DNS): Translates domain names to IP addresses.
  • DNS Servers: Function as a distributed dictionary for domain names and their corresponding IP addresses.
  • Hierarchical and recursive nature; involvement of root servers.

Dynamic Host Configuration Protocol (DHCP)

  • DHCP: Automatically configures devices on a network with IP addresses, DNS servers, and routers.
  • Facilitates dynamic addition of devices to a network.

Building on the Internet: HTTP and Web Pages

HTTP Basics

  • Hypertext Transfer Protocol (HTTP): Protocol for web interactions.
  • HTTPS: Secure version with encryption.
  • URL Structure: Components include protocol, domain, path, etc.

HTTP Methods

  • GET: Request data from a server.
  • POST: Send data to a server.

HTML Introduction

  • HTML: Markup language for structuring web pages (not a programming language).
  • Basic Tags: <html>, <head>, <title>, <body>, etc.
  • Paragraphs and Headings: Use of <p>, <h1> to <h6> for content formatting.
  • Lists: <ul> for unordered (bulleted), <ol> for ordered (numbered) lists.

Basic Elements and Attributes

  • Tables: <table>, <tr>, <td> for tabular data.
  • Images: <img src=""> for embedding images.
  • Forms: <form>, <input>, <button> for user interactions like searches.
  • Hyperlinks: <a href=""> for linking to other pages.

Client-Side Validation with JavaScript

JavaScript Basics

  • JavaScript: A proper programming language; its libraries work in the context of the web.
  • Functions: Define with function keyword.
  • Variables: Declare with let similarly to Python.
  • DOM Manipulation: Use querySelector to interact with HTML elements.
  • Event Listeners: Handle user interactions like form submissions or button clicks.

Practical Examples

  • Background Color Changer: Modify CSS via JavaScript to change background colors.
  • Geolocation: Use JavaScript to determine the user's location (latitude and longitude).
  • Autocomplete Feature: Dynamically generate suggestions for user input using JavaScript.

Cascading Style Sheets (CSS)

CSS Basics

  • Selectors: Apply styles based on tag, class, ID, or attributes.
  • Properties: Define visual aesthetics using key-value pairs.
  • Classes and IDs: Reuse sets of properties across multiple tags using .classname or #idname.

Practical CSS Usage

  • Inline Styles: Apply directly within HTML tags using style attributes.
  • Style Tags: Define CSS in the head of the document.
  • External Stylesheets: Link to .css files to separate style from content.

CSS Frameworks

  • Introduction to Bootstrap: A popular CSS framework for creating responsive and visually attractive web pages.
  • Utilizing Bootstrap Classes: Simplify web design by leveraging pre-defined classes and properties.

Summary

  • Integration: Combining HTML, CSS, and JavaScript to create interactive and attractive web pages.
  • Best Practices: Ensuring proper validation and security both client-side and server-side.
  • Further Exploration: Leveraging tools, frameworks, and libraries to enhance web development skills.