In this section, we’ll go over a couple of key terms when using JS, and define what the HTML DOM is in relation to JavaScript and how that can help us think about creating and executing scripts.
Often when building a webpage, you won’t have to write your own JavaScript, but can use scripts already written by other people. There are many free and open-source JavaScript libraries that you can add code from to your webpage. For example:
To add a script from a library to your page, you add a script tag
In pairs, find a module in any of the JavaScript libraries above and add it to a new webpage in one of your GitHub repositories. Next, find a module not in one of the libraries above (use your awesome Googling skills) and add it to your webpage.
Sometimes you find a useful script, but need it to do something else or parse a dataset that it doesn’t already do. This is when your reading and writing skills come in, as you’ll need to edit the script to make it fit your purposes.
Take the script you added in the last activity and edit something about its functionality, styles, or the dataset it pulls from.
Break (15 minutes)
In pairs for the twenty-five minutes, take the time to write a script for the webpage you built yesterday that will change something in your CSS or HTML. The JS functions can do whatever you want, but it’s worth considering writing a script that may relate to your project. For example, Marijke might want to add a script that plays audio on clicking a piece of text. Nic might want to add a progress tracker of some sort. Brume might want to extract all of the titles of headings into a list. Gorka might want to make an image open up in a new tab on click. See the list below for an example of scripts you might want to considering editing or recreating:
We’ve spent an hour doing a lot of programming, so let’s check-in to see how we’re feeling about what we’ve handled so far. What questions do you have? How are you feeling about the process of programming? What frustrations have come up? What do you wish you knew more about?
Often you might find a feature on your favourite webpage that you want to incorporate on your own site. It’s useful to be able to “read’ JavaScript, HTML, and CSS in this instance, since it means you can use your web developer tools to see how the code on that site functions.
Below is a list of sites that include JavaScript. With your partner, go through each site and try to figure out what the JavaScript is doing on the site. What purpose does it serve? What functions does it have? How does it work? What specific scripts/modules are being used? What CSS and HTML is being changed?
All programmers, regardless of how long they’ve been coding, rely on resource lists to help them write and debug their code. Here are a few that you can refer to when you’re writing:
Continue to work on your two scripts from today’s session. If you need help, reach out to Kiran or Matt. (Optional) Keep working through programming exercises in W3 Tutorials.