← C1: Computer Basics | ↑ Table of Contents ↑ | C2: The World Wide Web → |
The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do. — Ted Nelson
I think it's fair to say that personal computers have become the most empowering tool we've ever created. They're tools of communication, they're tools of creativity, and they can be shaped by their user. — Bill Gates
This text is designed to provide a balanced coverage of computer technology and its impacts. The Concept chapters (C1-C12) focus on understanding important concepts in computing, such as how computers work, the history of the Internet and Web, and how computers and artificial intelligence are impacting society. The Exploration chapters (X1-X10) provide hands-on experience using a computer to create interactive Web pages. By experiencing the process of designing, implementing and debugging programs in a Web setting, you will gain a deeper understanding of the power and potential pitfalls of software. This chapter introduces to some of the development tools you will use throughout the text.
The Exploration chapters encourage developing programming skills using a tutorial format. That is, the introduction of new concepts and techniques are interleaved with interactive examples and exercises that demonstrate and reinforce those concepts and techniques. The interactive examples follow a common format, as shown in EXAMPLE 1.1 below:
To the right of the example is an editable box that contains the example code. In this example, there is just the simple sentence "My name is Dave Reed." in the box. To the left is a blue box that contains a button labeled "See in Browser". When you click on the button, the content of the box is displayed in a separate Web browser window.
EXERCISE 1.1: Click on the "See in Browser" button in EXAMPLE 1.1. You should see "My name is Dave Reed." displayed in a separate window. Don't worry about the title at the top of the window (about:blank
). You will learn how to insert a more meaningful title in the Chapter X2.
EXERCISE 1.2: Modify the text in the box so that it contains your name instead of "Dave Reed". Click on the button to confirm that your name appears in the browser window.
The blue box at the left of the example also includes a link labeled "Download". This feature will be useful when you want to save the contents of the box to your computer. For example, you might be in the middle of completing an exercise in the box but need to pause to grab dinner or attend a class. If you close the chapter and later return, your changes will be lost, and the example will revert to its original contents. To save your work, click on the "Download" link. For example, clicking on the "Download" link in EXAMPLE 1.1 will download the contents of the box to your computer under the file name example1-1.html.
EXERCISE 1.3: Download the modified box contents to a file on your computer. By default, the file will be stored in your Downloads folder. Move that file to your Desktop for easier access.
EXERCISE 1.4: Reload this chapter in your browser. The box in EXAMPLE 1.1 should revert to its original content (with "Dave Reed"). If you open the file you saved to your computer using some text editor or word processor, you can copy the content of that file and paste it into the EXAMPLE 1.1 box. Do so and confirm that the saved edits are now restored in the example box.
if you just want to view the document that you downloaded without any further edits, you do not need to copy its contents back into the example box. Instead, you can open that file directly in the browser. If the document is saved with a .html
extension, simply clicking on the file icon will automatically open it in your default browser (e.g., Chrome). Alternatively, you can open the browser and select "Open File" under the "File" command at the top of the browser window. This will open a navigation window that will enable you to find and select the desired file that you wish to view.
EXERCISE 1.5: Click on the downloaded file icon (example1-1.html
on your Desktop). This should open the file in your default browser. Confirm that this works as described.
The interactive examples in this book are a simple and convenient way to explore new Web page features as they are introduced. If you want to create a complex Web page, however, a more advanced editing tool is needed. A text editor is a program in which you can type and edit text, then save that text in a file. Common examples are NotePad, which comes free with Microsoft Windows, and TextEdit, which comes free on Apple computers. Many software companies also offer free or low-cost text editors that provide special features, such as automatic indentation, color coding and helpful error messages. Phoenix is an example of a simple and free text editor that is available for both Windows and Apple computers. Below, we describe the steps involved in creating, editing and saving documents in the Phoenix text editor.
The Phoenix text editor has features that make creating and viewing Web pages simpler and so is ideal to accompany this text. It comes in both a desktop version (which must be installed on your computer) and an online version (which requires no installation). To access this online version of Phoenix, go to phcode.dev. The first time you visit this site, you will be prompted to create a Project (FIGURE 1).
FIGURE 1. The initial Phoenix online screen.
A Project is just a folder on your computer where your documents will be stored. Since you will be creating HTML documents (i.e., Web pages) throughout this text, click on the HTML5 icon to create a Project customized for Web pages. This will open a box in which you will select the name and location of your Project (FIGURE 2).
FIGURE 2. Prompt for creating a Project folder.
Click on the "Please select a folder..." button and select the location for your project. The location should be somewhere easily accessible, such as the Desktop or your Documents folder. Once you have selected the location, click on the "New Folder" button to create and name the Project folder. For example, if you are using this text in a class, you might name the Project after the class (e.g., CSC121
). After the Project folder is created and named, click the "Select" button to finalize its creation. At that point, you will receive a prompt to confirm that Phoenix has your permission to view files in that Project folder (FIGURE 3).
FIGURE 3. Prompt for permission to view files.
Click on the "View files" button to give the Phoenix editor permission. Then, click on the "Create Project" button to finalize the Project creation. You will receive yet another prompt to confirm that the Phoenix editor will have full access to files in the Project — click on the "save changes" button to confirm this (FIGURE 4).
FIGURE 4. Final steps in creating a Project.
Technically Speaking
You might be getting frustrated with all the confirmation prompts that Phoenix requires. Rest assured, these prompts are for your own safety. By default, an application running on the Web should not have access to files on your computer. You wouldn't want to visit a Web site and have that site view or delete the files on your computer! To override the default protections on Web applications, Phoenix needs to confirm that you are giving it access to your computer, but only in the specified Project folder.
At this point, you will see the development screen, which is divided into three panels (FIGURE 5). On the left, is a listing of Project files. The Project you just created should be listed there, with some files that are automatically created by Phoenix. You can ignore these. The middle panel is where you will create and edit files. The panel on the right is for viewing the files you create. Click on the "Trust & Execute Preview" button to enable file previewing.
FIGURE 5. Three panels of the online Phoenix editor.
EXERCISE 1.6: Follow the steps above to access the online Phoenix editor, set up a Project, and enable the live preview feature. Your Phoenix environment should appear similar to the screen shot in FIGURE 5.
Now that your project folder is fully set up and you have given Phoenix permission to access and edit files in that folder, you are ready to create a simple Web page. Click on the "File" command at the top of the middle panel and select the "New File" option. This will create a new file named "Untitled-1" in your project. You can change this by typing the desired name (e.g., info.html
) in the box in the left pane (FIGURE 6). If you already hit enter before changing the name, you can always right-click on the file name and select "Rename" to rename the file as desired. Note: if you do not have right-click enabled on your mouse, control-click on a Mac or shift-F10 on a Windows computer work as well.
FIGURE 6. Creating and naming a file in the Phoenix editor.
EXERCISE 1.7: Follow the steps above to create a new file in your Project named info.html
. Your Phoenix environment should appear similar to the screen shot in FIGURE 6.
Once a file is created, you can enter text into the file (via the middle pane) and use common editing operations (backspace, delete, return, and arrows). FIGURE 7 shows the file named info.html
with the text "This is a VERY crude Web page." typed in the file. You may note that there is a small circle to the left of the file name in the left panel, and also to the right of the file name at the top of the middle panel. This circle denotes that the file has been edited since it was last saved. When you save the file to your folder (by selecting "Save" under the "File" command), the circle will disappear. The pane on the right displays a preview of this page as it will appear in a Web browser. You may need to click on the lightning bolt icon at the top right of this pane to initiate the live preview. Each time you edit and save the file, the preview will update to display that document.
FIGURE 7. Editing and previewing a page in Phoenix.
At this point, you may not be overly impressed with the live preview pane. It just displays the same text that was entered into the file, although it does perform line-wrap as needed to fit the pane. In the next chapter, when you learn to add non-trivial content to a Web page, the value of this preview will become apparent.
EXERCISE 1.8: Enter several sentences that describe you in the info.html
document. These can be anything — your hometown, your family, your interests... View that text in the live preview.
As you learn to develop your own Web pages in subsequent chapters, one of the skills that will be useful is being able to locate and download images from the Web. The first step in this process is locating the image file. This may be trickier than it sounds, since many Web sites display images in a gallery but hide the actual files from the user. If you right-click on an accessible image, one of the options should be "Save Image as..." or something equivalent (depending on your browser). Note: if you do not have right-click set up on your mouse, control-click on a Mac or shift-F10 on a Windows computer work as well.
To download the image once you find it, right-click and select the "Save Image as..." (or equivalent) option. A window will appear in which you can select the location and name for the file. Note: when downloading images from the Web, you must be careful not to violate copyrights or otherwise infringe upon the rights of the owner. Unless explicitly stated otherwise, you should assume that any image on the Web is private property.
EXERCISE 1.9: Open a browser window to the home page for this book: freecsc.com. At the bottom of the page is a picture of the author. Download a copy of this image to the Desktop your computer. To confirm that it downloaded correctly, double click on the image file icon on your Desktop. This should open the image in your default image viewer (e.g., Preview on a Mac or Paint on Windows).
Today's digital cameras can take incredibly high-resolution images. For example, the Fujifilm GFX 100 II can take photographs consisting of more than 100 million pixels (or picture elements). Depending on the file format used, a single image taken by that camera can require up to 150 MB (megabytes) of storage. When displaying an image on a Web page, images of this size are overkill, as computer screens are incapable of displaying that high of a resolution. Plus, the time that it takes to download even a 15 MB image over the Web can be significant. A good rule of thumb is that images embedded in Web pages should never exceed 500 KB in size. Most images you find on the Web are much smaller.
Determinnig the size of a dowlnoaded image is easy: right click on the image file and select either "Get Info" (on a Mac) or "Properties" (on Windows). Information about the file, including its size, will be displayed in a small window. If you have an image that exceeds the 500 KB limit, there are many applications that you can use to reduce the size of the image file. Preview is a simple tool that is preinstalled on Macs, while Paint is a similar tool for Windows computers. In both programs, you can open an image file and adjust its dimensions (width and height) and/or resolution (pixels per square inch) to reduce the file size. In Preview, this is done by selecting "Change size" from the "Tools" menu; in Paint, you simply click on the "Resize" icon. You can also save or export the image using a different file format. For photographs, JPG tends to be the most compact file format, requiring only a fraction of the space that the equivalent GIF or PNG file would take.
EXERCISE 1.10: Confirm that the image file you downloaded is smaller than 500 KB in size.
.html
extension, double-clicking on its file icon will open that document in your default browser..jpg
, .png
or .gif
) as this identifies the format of the file.
PROJECT 1.A: While the Phoenix editor is optimized for creating and editing Web pages, it can be used to create documents of various types. For example, if you create a file with a .txt
extension, it is treated as a generic text file. Using Phoenix, create a text file named "YOURNAME.txt" where YOURNAME is your name. Enter the following information in the file:
Note: since this file is stored as a text file (with .txt
extension) instead of a Web page (with .html
extension), the live preview feature in Phoenix will not work.
PROJECT 1.B: Locate an image on the Web that somehow resonates with you. It may be a picture of you or a family member that has been previously uploaded to a Web site. It may be of a person you admire or a sports team that you follow. Or it may just be an image that you find beautiful or inspiring. Download that image to your computer and rename it YOURNAME.XXX, where YOURNAME is your name and XXX is the existing format of the image file (.jpg or .png or .gif).
If the image file exceeds 500 KB in size, use a program such as Preview or Paint to reduce its size so that it is below the 500 KB threshold. If the image is stored using a format other than JPG, simply saving/exporting that image as a JPG file might suffice. If not, reduce the dimensions of the image and/or its resolution to reduce the file size. Note even high-end computer screens are incapable of displaying more than 160 pixels per square inch, so this is a safe lower bound for reducing the image resolution.
← C1: Computer Basics | ↑ Table of Contents ↑ | C2: The World Wide Web → |