CPNT 262 Day 3 - Strings, string methods and the browser environment

Houskeeping

Trophy of the day


1. Spoiler Demo: Tip Calculator

Materials


2. Strings and string methods

Materials


3. Dates and common DOM objects/methods

Materials

Key Takeaways

  • The querySelector() method accepts any valid CSS selector, such as:

    • .intro
    • h1
    • #sign-in-form
    • a[href="https://example.org"]
  • querySelector() will return the first matching element only. Use querySelectorAll() to return a list of all matching elements.

  • All HTML elements have the querySelector() method, so you can query for elements directly inside other elements:

    // finds the first paragraph in the document
    const paragraph = document.querySelector('p');

    // finds the first span element in the above paragraph
    const paraSpan = paragraph.querySelector('span');
  • Both textContent and innerHTML are object properties that you can read and assign like any other variable.

  • Use textContent unless the value contains HTML, then use innerHTML.

Activity


4. Open Lab

  • Trophy of the Day
  • Free Code Camp Exercises
  • Assignments
  • Prep for tomorrow

Prep

MDN Readings

Free Code Camp Exercises