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.
- 1Target the elements. Use
document.querySelector()to target the rest of the buttons. Some are done for you. - 2Finish the functions. Fill in
changeFont(),changeSize(),invert(), andflash(). Notice which functions take arguments and which donβt. - 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. - 4Add some timing. Use
setTimeout()to change the title after 3 seconds, andsetInterval()to runflash()every second. - 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
colorargument. - Stop the specimen from shrinking below 10px using an if statement.
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.
Settings
View
Font size
14
Code
Preview
Delay
Zoom
Share
Reset
Preview
Currently previewing:
Dimensions0 × 0
Delay
Preview paused
Click to resume
Click to resume
The preview is disabled for this demo.
Use the console below.
Use the console below.
Console
›