Open original
Info
Demo 4.18

Exercise: type specimen

Files in this demo

β”œβ”€ index.html
β”œβ”€ style.css
└─ script.js

Build an interactive type specimen using everything we learned today! Most of the code is already set up for you. Look for the TODO comments in script.js and fill them in.

  1. 1Target the elements. Use document.querySelector() to target the rest of the buttons. Some are done for you.
  2. 2Finish the functions. Fill in changeFont(), changeSize(), invert(), and flash(). Notice which functions take arguments and which don’t.
  3. 3Hook up the buttons. Use addEventListener() to run a function when each button is clicked. Pick your own word and sentence for the text buttons.
  4. 4Add some timing. Use setTimeout() to change the title after 3 seconds, and setInterval() to run flash() every second.
  5. 5Make it yours. Style the page however you want and add more buttons!

Use the console to check your work. If something isn’t working, look for red error messages.

Bonus challenges:

  • Import a custom font from Google Fonts and add a button for it.
  • Add a button that changes the specimen’s color using a new function with a color argument.
  • Stop the specimen from shrinking below 10px using an if statement.
You finished this book!Start another book
Keyboard Shortcuts
⌘ Z / ⌘ ⇧ ZCtrl Z / Ctrl ⇧ Z Undo / redo
Tab / ⇧ TabTab / ⇧ Tab Indent / unindent selection
⌘ ] / ⌘ [Ctrl ] / Ctrl [ Indent / unindent lines
⌘ ACtrl A Select all
⌘ DCtrl D Select next occurrence of selection
⌥ ClickAlt Click Add another cursor
⌘ /Ctrl / Comment / uncomment lines
Ctrl SpaceCtrl Space Autocomplete
Ctrl EnterCtrl Enter Reset layout
⌘ ⌥ [ / ⌘ ⌥ ]Ctrl ⇧ [ / Ctrl ⇧ ] Fold / unfold block
Code
The editor didn't load — try refreshing the page. Navigation, shortcuts and the info panel still work in the meantime.
Preview
Dimensions0 × 0
Delay
Console
›