100% found this document useful (1 vote)
28 views

JavaScript A Beginner's Guide Fifth Edition John Pollock - The ebook in PDF and DOCX formats is ready for download now

The document provides information about various eBooks available for download at ebookmeta.com, including titles like 'JavaScript: A Beginner's Guide, Fifth Edition' by John Pollock and others. It includes links to download these eBooks in different formats such as PDF, EPUB, and MOBI. Additionally, it contains copyright information and terms of use for the eBooks offered.

Uploaded by

marcomqusar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
28 views

JavaScript A Beginner's Guide Fifth Edition John Pollock - The ebook in PDF and DOCX formats is ready for download now

The document provides information about various eBooks available for download at ebookmeta.com, including titles like 'JavaScript: A Beginner's Guide, Fifth Edition' by John Pollock and others. It includes links to download these eBooks in different formats such as PDF, EPUB, and MOBI. Additionally, it contains copyright information and terms of use for the eBooks offered.

Uploaded by

marcomqusar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

Read Anytime Anywhere Easy Ebook Downloads at ebookmeta.

com

JavaScript A Beginner's Guide Fifth Edition John


Pollock

https://ebookmeta.com/product/javascript-a-beginners-guide-
fifth-edition-john-pollock/

OR CLICK HERE

DOWLOAD EBOOK

Visit and Get More Ebook Downloads Instantly at https://ebookmeta.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

JavaScript: A Beginner's Guide, Fifth Edition Pollock

https://ebookmeta.com/product/javascript-a-beginners-guide-fifth-
edition-pollock/

ebookmeta.com

JavaScript Absolute Beginner s Guide 2nd Edition Kirupa


Chinnathambi

https://ebookmeta.com/product/javascript-absolute-beginner-s-
guide-2nd-edition-kirupa-chinnathambi/

ebookmeta.com

Beginner s Guide to Kotlin Programming John Hunt

https://ebookmeta.com/product/beginner-s-guide-to-kotlin-programming-
john-hunt/

ebookmeta.com

Environmental Data Analysis with MatLab or Python:


Principles, Applications, and Prospects 3rd Edition
William Menke
https://ebookmeta.com/product/environmental-data-analysis-with-matlab-
or-python-principles-applications-and-prospects-3rd-edition-william-
menke/
ebookmeta.com
Bad Witch Burning 1st Edition Jessica Lewis

https://ebookmeta.com/product/bad-witch-burning-1st-edition-jessica-
lewis-2/

ebookmeta.com

Textbook of Dermatologic Ultrasound Ximena Wortsman


(Editor)

https://ebookmeta.com/product/textbook-of-dermatologic-ultrasound-
ximena-wortsman-editor/

ebookmeta.com

Cloud Native Security Cookbook: Recipes for a Secure Cloud


1st Edition Josh Armitage

https://ebookmeta.com/product/cloud-native-security-cookbook-recipes-
for-a-secure-cloud-1st-edition-josh-armitage/

ebookmeta.com

Theologizing in Black On Africana Theological Ethics and


Anthropology 9th Edition Joseph

https://ebookmeta.com/product/theologizing-in-black-on-africana-
theological-ethics-and-anthropology-9th-edition-joseph/

ebookmeta.com

First Amendment Law Freedom of Expression and Freedom of


Religion 5th Edition Arthur D Hellman William D Araiza
Thomas E Baker Ashutosh A Bhagwat
https://ebookmeta.com/product/first-amendment-law-freedom-of-
expression-and-freedom-of-religion-5th-edition-arthur-d-hellman-
william-d-araiza-thomas-e-baker-ashutosh-a-bhagwat/
ebookmeta.com
Only the Lonely Death Gate Grim Reapers 1 1st Edition
Amanda M. Lee

https://ebookmeta.com/product/only-the-lonely-death-gate-grim-
reapers-1-1st-edition-amanda-m-lee/

ebookmeta.com
Copyright © 2020 by McGraw-Hill Education (Publisher). All rights
reserved. Except as permitted under the United States Copyright Act
of 1976, no part of this publication may be reproduced or distributed
in any form or by any means, or stored in a database or retrieval
system, without the prior written permission of the publisher, with
the exception that the program listings may be entered, stored, and
executed in a computer system, but they may not be reproduced for
publication.

ISBN: 978-1-26-045769-8
MHID: 1-26-045769-9

The material in this eBook also appears in the print version of this
title: ISBN: 978-1-26-045768-1, MHID: 1-26-045768-0.

eBook conversion by codeMantra


Version 1.0

All trademarks are trademarks of their respective owners. Rather


than put a trademark symbol after every occurrence of a
trademarked name, we use names in an editorial fashion only, and
to the benefit of the trademark owner, with no intention of
infringement of the trademark. Where such designations appear in
this book, they have been printed with initial caps.

McGraw-Hill Education eBooks are available at special quantity


discounts to use as premiums and sales promotions or for use in
corporate training programs. To contact a representative, please visit
the Contact Us page at www.mhprofessional.com.

Oracle and Java are registered trademarks of Oracle Corporation


and/or its affiliates. All other trademarks are the property of their
respective owners, and McGraw-Hill Education makes no claim of
ownership by the mention of products that contain these marks.
Screen displays of copyrighted Oracle software programs have been
reproduced herein with the permission of Oracle Corporation and/or
its affiliates.

Information has been obtained by Publisher from sources believed to


be reliable. However, because of the possibility of human or
mechanical error by our sources, Publisher, or others, Publisher does
not guarantee to the accuracy, adequacy, or completeness of any
information included in this work and is not responsible for any
errors or omissions or the results obtained from the use of such
information.

TERMS OF USE

This is a copyrighted work and McGraw-Hill Education and its


licensors reserve all rights in and to the work. Use of this work is
subject to these terms. Except as permitted under the Copyright Act
of 1976 and the right to store and retrieve one copy of the work,
you may not decompile, disassemble, reverse engineer, reproduce,
modify, create derivative works based upon, transmit, distribute,
disseminate, sell, publish or sublicense the work or any part of it
without McGraw-Hill Education’s prior consent. You may use the
work for your own noncommercial and personal use; any other use
of the work is strictly prohibited. Your right to use the work may be
terminated if you fail to comply with these terms.

THE WORK IS PROVIDED “AS IS.” McGRAW-HILL EDUCATION AND


ITS LICENSORS MAKE NO GUARANTEES OR WARRANTIES AS TO
THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS
TO BE OBTAINED FROM USING THE WORK, INCLUDING ANY
INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK VIA
HYPERLINK OR OTHERWISE, AND EXPRESSLY DISCLAIM ANY
WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR
A PARTICULAR PURPOSE. McGraw-Hill Education and its licensors do
not warrant or guarantee that the functions contained in the work
will meet your requirements or that its operation will be
uninterrupted or error free. Neither McGraw-Hill Education nor its
licensors shall be liable to you or anyone else for any inaccuracy,
error or omission, regardless of cause, in the work or for any
damages resulting therefrom. McGraw-Hill Education has no
responsibility for the content of any information accessed through
the work. Under no circumstances shall McGraw-Hill Education
and/or its licensors be liable for any indirect, incidental, special,
punitive, consequential or similar damages that result from the use
of or inability to use the work, even if any of them has been advised
of the possibility of such damages. This limitation of liability shall
apply to any claim or cause whatsoever whether such claim or cause
arises in contract, tort or otherwise.
To my wife, Heather, and children, Eva, Elizabeth,
Elaine, and Evan, Bruce and Joy Anderson, and Dr. J.
D. and Linda Andrews

In memory of John and Betty Hopkins, James D. and


Livian Anderson, John William and Edith Hopkins,
Burley T. and Aline Price, “Doc” Flores, and Clifton
Idom
About the Author
John Pollock is employed as a software developer during the day
and works on Web sites and other projects during the evening. You
can find him on Twitter (@ScripttheWeb) or LinkedIn
(https://www.linkedin.com/in/john-pollock-82a2b074). John holds a
Bachelor of Arts in English from Sam Houston State University and
currently lives in New Waverly, Texas with his wife, Heather, and
children, Eva, Elizabeth, Elaine, and Evan.

About the Technical Editor


Christie Sorenson is a senior software engineer at ZingChart. She
has worked on JavaScript-based systems since 1997 and has been
fascinated with the evolution of the language. She has collaborated
and been the technical editor on several JavaScript and HTML books.
She holds a Bachelor of Science in Computer Science from University
of California, San Diego, and now lives in San Francisco with her
husband, Luke, and daughters, Ali and Keira.
Contents
ACKNOWLEDGMENTS
INTRODUCTION

1 Introduction to JavaScript
What You Need to Know
Basic HTML and CSS Knowledge
Basic Text Editor and Web Browser Knowledge
Which Version?
Client-Side and Server-Side Programming
Beginning with JavaScript
Prototype-Based
Interpreted Language
Numerous Environments
Putting It All Together
Online Resources
Try This 1-1: Use JavaScript to Write Text
Chapter 1 Self Test

2 Placing JavaScript in an HTML File


Using the HTML Script Tags
Identifying the Scripting Language
Calling External Scripts
Specifying when the Script Should Load
Using <noscript></noscript> Tags
Creating Your First Script
Writing a “Hello World” Script
Creating an HTML Document for the Script
Inserting the Script into the HTML Document
Try This 2-1: Insert a Script into an HTML Document
Using External JavaScript Files
Creating a JavaScript File
Creating the HTML Files
Viewing the Pages in Your Browser
Try This 2-2: Call an External Script from an HTML Document
Using JavaScript Comments
Inserting Comments on One Line
Adding Multiple-Line Comments
Chapter 2 Self Test

3 Using Variables
Understanding Variables
Why Variables Are Useful
Variables as Placeholders for Unknown Values
Variables as Time-Savers
Variables as Code Clarifiers
Defining Variables for Your Scripts
Declaring Variables
Assigning Values to Variables
Naming Variables
Understanding Data Types
Number
String
Boolean
Null
Undefined
Symbol
Object
Try This 3-1: Declare Variables
Using Variables in Scripts
Making a Call to a Variable
Adding Variables to Text Strings
Writing a Page of JavaScript
Creating the Framework
Defining the Variables
Adding the Commands
Modifying the Page
Try This 3-2: Create an HTML Page with JavaScript
Chapter 3 Self Test

4 Using Functions
What a Function Is
Why Functions Are Useful
Structuring Functions
Declaring Functions
Defining the Code for Functions
Naming Functions
Adding Arguments to Functions
Adding Return Statements to Functions
Calling Functions in Your Scripts
Script Tags: Head Section or Body Section
Calling a Function from Another Function
Calling Functions with Arguments
Calling Functions with Return Statements
Other Ways to Define Functions
Try This 4-1: Create an HTML Page with Functions
Scope/Context Basics
Global Context
Function Context
Block Context
Try This 4-2: Write Your Own Functions
Chapter 4 Self Test

5 JavaScript Operators
Understanding the Operator Types
Understanding Arithmetic Operators
The Addition Operator (+)
The Subtraction Operator (–)
The Multiplication Operator (*)
The Division Operator (/)
The Modulus Operator (%)
The Increment Operator (++)
The Decrement Operator (– –)
The Unary Plus Operator (+)
The Unary Negation Operator (–)
The Exponentiation Operator
Understanding Assignment Operators
The Assignment Operator (=)
The Add-and-Assign Operator (+=)
The Subtract-and-Assign Operator (–=)
The Multiply-and-Assign Operator (*=)
The Divide-and-Assign Operator (/=)
The Modulus-and-Assign Operator (%=)
The Exponent-and-Assign Operator (**=)
Try This 5-1: Adjust a Variable Value
Understanding Comparison Operators
The Is-Equal-To Operator (==)
The Is-Not-Equal-To Operator (!=)
The Strict Is-Equal-To Operator (===)
The Strict Is-Not-Equal-To Operator (!==)
The Is-Greater-Than Operator (>)
The Is-Less-Than Operator (<)
The Is-Greater-Than-or-Equal-To Operator (>=)
The Is-Less-Than-or-Equal-To Operator (<=)
Understanding Logical Operators
The AND Operator (&&)
The OR Operator (||)
The NOT Operator (!)
The Bitwise Operators
Special Operators
Understanding Order of Operations
Try This 5-2: True or False?
Chapter 5 Self Test

6 Conditional Statements and Loops


Defining Conditional Statements
What Is a Conditional Statement?
Why Conditional Statements Are Useful
Using Conditional Statements
Using if/else Statements
Using the switch Statement
Using the Conditional Operator
User Input from a Prompt
Try This 6-1: Work with User Input
Defining Loops
What Is a Loop?
Why Loops Are Useful
Using Loops
for
while
do while
for in, for each in, and for of
Using break and continue
Try This 6-2: Work with for Loops and while Loops
Chapter 6 Self Test

7 JavaScript Arrays
What Is an Array?
Why Arrays Are Useful
Defining and Accessing Arrays
Naming an Array
Defining an Array
Accessing an Array’s Elements
Using the length Property and Loops
Changing Array Values and Changing the Length
Try This 7-1: Use Loops with Arrays
Array Properties and Methods
Properties
Methods
Nesting Arrays
Defining Nested Arrays
Loops and Nested Arrays
Try This 7-2: Nested Arrays Practice
Chapter 7 Self Test

8 Objects
Defining Objects
Creating Objects
Naming
Single Objects
Try This 8-1: Create a Computer Object
Object Structures
Constructor Functions
Using Prototypes
The class Keyword
Helpful Statements for Objects
The for-in Loop
The with Statement
Try This 8-2: Practice with the Combination
Constructor/Prototype Pattern
Understanding Predefined JavaScript Objects
The Navigator Object
The History Object
Chapter 8 Self Test
9 The Document Object
Defining the Document Object
Using the Document Object Model
Using the Properties of the Document Object
Collections
The cookie Property
The dir Property
The lastModified Property
The referrer Property
The title Property
The URL Property
The URLUnencoded Property
Using the Methods of the Document Object
The get Methods for Elements
The open() and close() Methods
The write() and writeln() Methods
Using DOM Nodes
DOM Node Properties
DOM Node Methods
Try This 9-1: Add a DOM Node to the Document
Creating Dynamic Scripts
Styles in JavaScript
Simple Event Handling
Coding a Dynamic Script
Try This 9-2: Try Out Property Changes
Chapter 9 Self Test

10 Event Handlers
What Is an Event Handler?
Why Event Handlers Are Useful
Understanding Event Handler Locations and Uses
Using an Event Handler in an HTML Element
Using an Event Handler in the Script Code
Learning the Events
The Click Event
Focus and Blur Events
The Load and Unload Events
The Reset and Submit Events
The Mouse Events
The Keyboard Events
Try This 10-1: Focus and Blur
Other Ways to Register Events
The addEventListener() Method
The attachEvent() Method
The Event Object
DOM and Internet Explorer: DOM Level 0 Registration
Using event with Modern Event Registration
Properties and Methods
Event Information
Try This 10-2: Using addEventListener()
Creating Scripts Using Event Handlers
Show Hidden Content
Change Content
Custom Events
Chapter 10 Self Test

11 Introduction to Node.js
Introducing Node.js
Installing Node.js
Check for a Current Installation
Install Node.js
Write a “Hello World” Script
Using Node Modules
Using Native Node Modules
Asynchronous Execution
Non-Native Modules
Try This 11-1: Use a Custom Module
Installing a Database
Database Options
Install PostgreSQL
Create a Database Using pgAdmin
Try This 11-2: Test Some SQL Queries
Creating a Web Server
Chapter 11 Self Test

12 Math, Number, and Date Objects


Using the Math Object
What Is the Math Object?
How the Math Object Is Useful
Properties
Methods
Try This 12-1: Display a Random Link on a Page
Understanding the Number Object
Properties
Methods
Using the Date Object
Properties and Methods
Methods That Get Values
Methods That Set Values
Other Methods
How About Some Date Scripts?
Try This 12-2: Create a JavaScript Clock
Continuing Project
Getting to the Needed Data
Running Some Calculations on the Results
Chapter 12 Self Test

13 Handling Strings
Introduction to the String Object
The String Object
The String Literal
What’s the Difference?
Using the Properties and Methods of the String Object
The length Property
Methods of the String Object
Try This 13-1: Use indexOf() to Test an Address
Using Cookies
Setting a Cookie
Reading a Cookie
Try This 13-2: Remember a Name
Using Regular Expressions
Creating Regular Expressions
Testing Strings Against Regular Expressions
Adding Flags
Creating Powerful Patterns
Grouping Expressions
The replace(), match(), matchAll(), and search() Methods
More Information
Continuing Project
Chapter 13 Self Test

14 Browser-Based JavaScript
Window: The Global Object
Using the Properties of the Window Object
The closed Property
The frames Property
The innerWidth and innerHeight Properties
The length Property
The location Property
The name Property
The opener Property
The parent, self, and top Properties
The status and defaultStatus Properties
Try This 14-1: Use the location and innerWidth Properties
Using the Methods of the Window Object
The alert(), prompt(), and confirm() Methods
The print() Method
The setInterval() and clearInterval() Methods
The setTimeout() and clearTimeout() Methods
Try This 14-2: Use the setTimeout() and confirm() Methods
The Main Window and New Windows
The Tale of Pop-up Windows
Opening New Windows
Closing New Windows
Moving, Resizing, and Scrolling New Windows
The resizeBy() and resizeTo() Methods
The scrollBy() and ScrollTo() Methods
Working with Images
Rollovers
JavaScript and Frames
Purpose of Frames
Accessing Frames
Breaking Out of Frames
Using iFrames
Chapter 14 Self Test

15 JavaScript Forms and Data


Accessing Forms
Using the forms Array
Using an ID
Using the Properties and Methods of the Form Object
Properties
Methods
Ensuring the Accessibility of Forms
Using Proper Element and Label Order
Using <label></label> Tags
Using <fieldset></fieldset> Tags
Not Assuming Client-Side Scripting
Validation
Simple Validation
Techniques
Check Boxes and Radio Buttons
Try This 15-1: Request a Number
HTML5 and Forms
New Elements
New Input Types
New Attributes
HTML5 Form Validation
Try This 15-2: Validate a Phone Number with HTML5 or
JavaScript
AJAX and JSON
AJAX
JSON
Chapter 15 Self Test

16 Further Browser-Based JavaScript


Using jQuery
Obtaining jQuery
Getting Started: document.ready()
Using Selectors
Altering Classes
Methods for Effects
Further Reading
Try This 16-1: Use jQuery to Create Effects
Debugging Scripts
Types of Errors
Using the Console
Using a Lint Tool
Browser Developer Tools
JavaScript and Accessibility
Separate Content from Presentation
Enhancing Content
Try This 16-2: Make This Code Accessible
JavaScript Security
Page Protection
JavaScript and APIs from HTML
The <canvas> Element
Drag and Drop
Try This 16-3: Drag and Drop
Node.js App Completion
Update the Node.js Code
Update the Front-end Code
Need Help?
Chapter 16 Self Test

A Answers to Self Tests


Chapter 1: Introduction to JavaScript
Chapter 2: Placing JavaScript in an HTML File
Chapter 3: Using Variables
Chapter 4: Using Functions
Chapter 5: JavaScript Operators
Chapter 6: Conditional Statements and Loops
Chapter 7: JavaScript Arrays
Chapter 8: Objects
Chapter 9: The Document Object
Chapter 10: Event Handlers
Chapter 11: Introduction to Node.js
Chapter 12: Math, Number, and Date Objects
Chapter 13: Handling Strings
Chapter 14: Browser-Based JavaScript
Chapter 15: JavaScript Forms and Data
Chapter 16: Further Browser-Based JavaScript

Index
Acknowledgments

I would like to begin by thanking my wonderful wife, Heather


Pollock, for all of her love, support, and encouragement in all I do. I
love you! I would also like to thank my three daughters, Eva,
Elizabeth, and Elaine, as well as my son, Evan. I love all of you!
I would like to thank my parents, Bruce and Joy Anderson, for
their love and guidance, and for always supporting my endeavors.
I would like to thank Dr. J. D. and Linda Andrews for their love,
guidance, and support.
In addition, I would like to thank Richard Pollock (brother) and
family, Misty Castleman (sister) and family, Warren Anderson
(brother) and family, Jon Andrews (brother) and family, Lisa and
Julian Owens (aunt/uncle) and family, and every aunt, uncle, cousin,
or other relation in my family. All of you have been a great influence
in my life.
I would like to thank all of my editors at McGraw-Hill for their
outstanding help and support throughout the writing of this book.
Thanks to Lisa McClain, Emily Walters, Claire Yee, Snehil Sharma,
Sarika Gupta, Bart Reed, and to all the editors who worked on this
and previous editions of the book.
Thanks to my technical editor, Christie Sorenson, for editing and
checking over all the technical aspects of the book and for helping
me provide clear explanations of the topics that are covered.
I would like to thank God for the ability He has given me to help
and teach people by my writing. “In all your ways acknowledge Him,
and He shall direct your paths.” (Proverbs 3:6)
Introduction

W elcome to JavaScript: A Beginner’s Guide, Fifth Edition! Years


ago, I was surfing the Web and noticed that people were publishing
pages about themselves and calling them homepages. After viewing
a number of these, I decided to create a homepage myself. I had no
idea where to begin, but through trial and error I figured out how to
code HTML and publish my documents on a Web server. Over time, I
saw some interesting effects used on other homepages (like alert
messages that popped up out of nowhere or images that would
magically change when I moved my mouse over them). I was
curious and just had to know what was being done to create those
effects. Were these page creators using HTML tags I did not know
about?
Eventually, one site revealed what was being used to create those
effects: JavaScript. I went in search of information on it and came
across a few tutorials and scripts on the Web. Since I had
programmed in other languages (such as a relatively obscure
language called Ada), I was able to catch on to JavaScript fairly
quickly by looking at these tutorials and scripts.
I learned enough that I decided to create a Web site that would
teach HTML and JavaScript to beginners. As soon as I began the
project, I received questions from visitors that were way over my
head—forcing me to dig deeper and learn more about JavaScript. As
a result, I became completely familiar with this scripting language
and what it can do. Not only can you add fun effects to a Web page,
you can create scripts that will perform useful tasks, like validate
form input, add navigational elements to documents, and react to
user events.
The goal of this book is to help you to learn the basics of the
JavaScript language with as little hair pulling and monitor smashing
as possible. You do not need any prior programming experience to
learn JavaScript from this book. All you need is knowledge of HTML
and/or XHTML, Cascading Style Sheets (CSS), and how to use your
favorite text editor and Web browser (see Chapter 1 for more
information).

What This Book Covers


The 16 chapters of this book cover specific topics on the JavaScript
language. The first two chapters cover the most basic aspects of the
language: what it is, what you need to know to begin using
JavaScript, and how to place JavaScript into an HTML file. The
middle of the book (Chapters 3–14) covers beginning JavaScript
topics from variables all the way to using JavaScript with forms. The
final two chapters (Chapters 15–16) introduce some advanced
techniques, and point you toward resources if you want to learn
more about JavaScript once you have completed the book.
This book includes a number of special features in each chapter to
assist you in learning JavaScript. These features include

• Key Skills & Concepts Each chapter begins with a set of key
skills and concepts that you will understand by the end of the
chapter.
• Ask the Expert The Ask the Expert sections present commonly
asked questions about topics covered in the preceding text, with
responses from the author.
• Try This These sections get you to practice what you have
learned using a hands-on approach. Each Try This will have you
code a script through step-by-step directions on what you need to
do to in order to accomplish the goal. You can find solutions to
each project on the McGraw-Hill Professional Web site at
www.mhprofessional.com/computingdownload.
• Notes, Tips, and Cautions These elements call your attention
to noteworthy statements that you will find helpful as you move
through the chapters.
• Code Code listings display example source code used in scripts
or programs.
• Callouts Callouts display helpful hints and notes about the
example code, pointing to the relevant lines in the code.
• Self Test Each chapter ends with a Self Test, a series of 15
questions to see if you have mastered the topics covered in the
chapter. The answers to each Self Test can be found in the
appendix.

That is it! You are now familiar with the organization and special
features of this book to start your journey through JavaScript. If you
find that you are stuck and need help, feel free to contact me with
your questions. To contact me, you can reach me on LinkedIn
(https://www.linkedin.com/in/john-pollock-82a2b074) or you can
find me on Twitter (@ScripttheWeb).
Now it is time to learn JavaScript. Get ready, get set, and have
fun!
Chapter 1
Introduction to JavaScript

Key Skills & Concepts


• Using Text Editors, WYSIWYG Editors, and Web Browsers
• Defining JavaScript
• Differences Between Client-Side and Server-Side Programming

W elcome to JavaScript: A Beginner’s Guide, Fifth Edition! You’re


obviously interested in learning JavaScript, but perhaps you’re not sure
what you need to know to use it. This chapter answers some basic
questions about what JavaScript is, provides a brief history of the
language, and discusses the various environments that can use JavaScript
for programming.
JavaScript is ubiquitous on the World Wide Web. You can use JavaScript
both to make your Web pages more interactive, so that they react to a
viewer’s actions, and to give your Web pages some special effects (visual
or otherwise). JavaScript can now even be used to perform input/output
operations or build Web servers by using Node.js!
JavaScript often gets included with Hypertext Markup Language (HTML)
and Cascading Style Sheets (CSS) as the three recommended languages
for beginning Web developers (whether you build Web sites for business or
pleasure). Of course, you can build a Web page by using only HTML and
CSS, but JavaScript allows you to add additional features that a static page
of HTML can’t provide without some sort of scripting or programming help.

What You Need to Know


Before you begin learning about JavaScript, you should have (or obtain) a
basic knowledge of the following:

• HTML and Cascading Style Sheets (CSS)


• Text editors and Web browsers
• The different versions of JavaScript
• Differences in client-side and server-side programming

If you have this basic knowledge, you’ll do just fine as you work through
this book. Knowing another programming/scripting language or having
previous experience with JavaScript isn’t required. This book is a beginner’s
guide to JavaScript.
If you think you don’t have enough experience in one of the
aforementioned areas, a closer look at each one may help you decide what
to do.

Basic HTML and CSS Knowledge


While you don’t need to be an HTML guru, you do need to know where to
place certain elements (like the head and body elements) and how to add
your own attributes. This book will reference scripts in the head section
(between the <head> and </head> tags) and the body section (between
the <body> and </body> tags).
Sometimes, you will also need to add an attribute to a tag for a script to
function properly. For example, you may need to name a form element
using the id attribute, as shown in the following code:

<input type="text" id="thename">

If you know the basics of using tags and attributes, the HTML portion
shouldn’t pose any problems in learning JavaScript.
If you don’t have a basic knowledge of HTML, you can learn it fairly
quickly through a number of media. For example, you can buy a book or
look for some helpful information on the Web. A good book is HTML: A
Beginner’s Guide, Fifth Edition by Wendy Willard (McGraw-Hill, 2013). To
find information about HTML on the Web, check out
developer.mozilla.org/en-
US/docs/Learn/HTML/Introduction_to_HTML/Getting_started.
Occasionally, you will need to use CSS to add or change presentation
features on a Web page. We will mainly use CSS for the purposes of
dynamically changing CSS properties via JavaScript in this book. A good
place to learn CSS is developer.mozilla.org/en-
US/docs/Learn/CSS/Introduction_to_CSS/How_CSS_works.

Basic Text Editor and Web Browser Knowledge


Before jumping in and coding with JavaScript, you must be able to use a
text editor or HTML editor, and a Web browser. You’ll use these tools to
code your scripts.

Text Editors
A number of text editors and HTML editors support JavaScript. If you know
HTML, you’ve probably already used an HTML editor to create your HTML
files, so you might not have to change.
However, some HTML editors have problems related to adding
JavaScript code (such as changing where the code is placed or altering the
code itself when you save the file). This is more often the case when using
WYSIWYG (What You See Is What You Get) editors. It is best to use a code
editor such as Sublime or Visual Studio Code (recommended) or a plain
text editor. Some examples of text editors are Notepad, TextPad, and
Simple Text.

Web Browsers
Again, if you’ve been coding in HTML, you probably won’t need to change
your browser. However, some browsers have trouble with the newer
versions of JavaScript. The choice of Web browser is ultimately up to you,
as long as it’s compatible with JavaScript. I recommend the latest version
of one of following browsers to test your JavaScript code:

• Google Chrome
• Mozilla Firefox
• Microsoft Edge

New versions of these browsers continue to be produced. The newest


versions will continue to support more features.
To give you an idea of what some browsers look like, Figure 1-1 shows a
Web page when viewed in Chrome, and Figure 1-2 shows a Web page
when viewed in Mozilla Firefox.

Figure 1-1 A Web page viewed in Google Chrome


Figure 1-2 A Web page viewed in Mozilla Firefox

If you have an older browser and you can’t upgrade, a number of


features (mostly discussed later in the book) may not work in that browser.
Even so, the book can still help you learn the JavaScript language itself
(especially when you’re using Node.js instead of a browser), so you don’t
need to give up if you have an older browser.

NOTE
Even if you have one of the latest browsers, your web site viewers
may not, so it is always appropriate to understand what features
may not be supported in older browsers. This book will cover how to
handle a number of these issues.

Which Version?
The version of JavaScript being used by a browser is typically associated
with what version of ECMAScript it supports. You can see what ECMAScript
versions are supported by each browser at kangax.github.io/compat-
table/es6/.
ECMAScript is the international standard name and specification used for
the JavaScript language, so it’s not a new language but a standard that is
set for JavaScript, JScript, and other implementations of the language. For
more on ECMAScript, see www.ecma-
international.org/publications/standards/Ecma-262.htm.
At the time of this writing, the browsers recommended earlier in this
chapter should support at least ECMAScript 7. Node.js uses the V8
JavaScript engine, and the latest version of Node.js should also support at
least ECMAScript 7.

Remember, It’s Not Java


JavaScript and Java are two different languages. Java is a programming
language that must be compiled (running a program through software that
converts the higher-level code to machine language) before a program can
be executed. More information on the Java language can be found at
docs.oracle.com/javase/tutorial/.

Similarities to Other Languages


JavaScript does have similarities to other programming and scripting
languages. If you have experience with Java, C++, or C, you’ll notice some
similarities in the syntax, which may help you to learn more quickly.
Because it’s a scripting language, JavaScript also has similarities to
languages like PHP—which can also be run through an interpreter rather
than being compiled.
If you have programming or scripting experience in any language, it will
make learning JavaScript easier—but it isn’t required.

Client-Side and Server-Side Programming


The addition of Node.js allows JavaScript to be run on the server side in
addition to its traditional space on the client side. Learning a little about
these different environments will help you to understand the type of
programming that will need to be done when working on the client side
versus working on the server side.
A client-side language is run directly through the client being used by
the viewer. In the case of client-side JavaScript, the client is typically a Web
browser. Therefore, client-side JavaScript is run directly in the Web browser
and doesn’t need to handle any requests on a Web server. The limitation is
that client-side JavaScript cannot directly save information (though it can
send information to a server-side program to do so).

NOTE
Using the XMLHttpRequest object and the Fetch API allows
JavaScript to send and request data from the server. These will be
covered briefly in Chapter 14.

A client-side language is useful for tasks that deal with the content of a
document or that allow information to be validated before it is sent to a
server-side program or script. For instance, JavaScript can change the
content of one or more elements on a Web page when the user clicks a
link or presses a button (many other user actions can also be activated).
JavaScript can also be used to check the information entered into a form
before the form is sent to a server-side program to be processed. This
information check can prevent strain on the Web server by not allowing
submissions with inaccurate or incomplete information. Rather than the
program running on the server until the information is correct, that data
can be sent to the server just once with correct information. This also
benefits the user, since client-side validation can provide feedback much
more quickly to allow the user to make any corrections.

NOTE
While client-side JavaScript is able to help validate information sent
to the server, it cannot replace server-side validation since users
may have JavaScript disabled or unavailable in the device being
used (which allows them to bypass the client-side validation). For
security reasons, you should always use server-side validation,
regardless of whether or not you incorporate client-side validation.

For client-side JavaScript, the Document Object Model (DOM) is


provided so that you can access the different elements in a document. This
is typically accessible within a browser for HTML documents.
A server-side language runs on a server. For example, a server-side
language can be used to receive information from the user of a Web
browser and then take an action using that information. The server-side
program can send information back to the Web browser, save it to a
database, or do any number of other things that the Web browser cannot
do on its own.
However, a server-side language is likely to be limited in its ability to
deal with special features of the client that can be accessed with a client-
side language (like the width of the browser window or the contents of a
form before it’s submitted to the server).
Traditionally, server-side programming was done in languages other than
JavaScript, such as PHP, Perl, Python, Ruby, Java, and a number of others.
When Node.js came along, it allowed the opportunity to use JavaScript on
the server side in addition to the client side.
Depending on the needs of you or your company, you may or may not
use Node.js, but this book will cover it in order to provide a more complete
introduction to the JavaScript language and the different environments in
which JavaScript can be used.

Ask the Expert


Q: You mentioned that I could use a text editor or HTML
editor of my choice, but I’m not quite sure what that
means. What is a text editor and where can I find one?

A: A text editor is a program that you can use to save and edit written
text. Text editors range from simple to complex, and a number of
choices are available: Notepad, WordPad, and Simple Text, to name
a few. You can also purchase and download some from the Web,
like NoteTab or TextPad.
An HTML editor is either a more complex text editor or an editor
that allows you to add code by clicking buttons or by other means—
often called a What You See Is What You Get (WYSIWYG) editor.
For the purposes of JavaScript coding, you may decide to use a
more code-oriented program that can offer features such as code
highlighting, completion, debugging tools, and more, such as Visual
Studio or Sublime. I recommend one of these tools since they offer
more features to assist with programming.
Q: What exactly do I need to know about using a text editor?

A: Basically, you only need to know how to type plain text into the
editor, save the file with an .html, .css, or .js extension, and be able
to open it again and edit it if necessary. Special features aren’t
needed because HTML, CSS, and JavaScript files are made up of
plain text, but the features of coding tools like Visual Studio and
Sublime can be extremely helpful as you write HTML, CSS, and
JavaScript code.

Q: What do I need to know about using a browser?

A: All you absolutely need to know is how to open a local HTML file on
your computer (or on the Web) and how to reload a page. If you
don’t know how to open an HTML file from your own computer,
open your browser and go to the address bar. Type in file:///C:/
and press ENTER. If you are using a drive letter other than C, type
that letter instead of C in the example. The browser will display files
and folders from the drive and allow you to navigate to the file you
want to open. Click an HTML file to open it. The following illustration
shows how this might look after navigating into a few folders from
the C drive using Google Chrome:
Q: Where do I get those browsers you mentioned?
A: Here are links for the browsers:
• Google Chrome www.google.com/chrome/
• Mozilla Firefox www.mozilla.com/firefox
• Microsoft Edge https://www.microsoft.com/en-
us/windows/microsoft-edge

Beginning with JavaScript


JavaScript came about as a joint effort between Netscape Communications
Corporation and Sun Microsystems, Inc. The news release of the new
language was issued on December 4, 1995, back when Netscape Navigator
2.0 was still in its beta version. JavaScript version 1.0 became available
with the new browser. (Before its release as JavaScript, it was called
LiveScript.)
JavaScript is a prototype-based interpreted language that can be used in
numerous environments. To expand on this definition, let’s look at its
important parts one by one.

Prototype-Based
Prototype-based means that JavaScript is an object-oriented programming
language that can use items called objects. However, the objects are not
class-based, so no distinction is made between a class and an instance;
instead, objects inherit from other objects via the prototype property.
JavaScript has made changes in ES6 to allow you to use the class keyword,
but the language is not technically class-based. You’ll learn how to work
with JavaScript objects in Chapter 10. You don’t need to understand them
in detail until you know a few other features of the language.

Interpreted Language
An interpreted language doesn’t require a program to be compiled before it
is run. All the interpretation is done on-the-fly by the client. The client,
such as a Web browser or the Node.js environment, is what is being used
to interpret the language.
With a compiled programming language, before you can run a program
you have written, you must compile it using a special compiler to be sure
there are no syntax errors. With a scripting language, the code is
interpreted as it is loaded in the client. Thus, you can test the results of
your code more quickly. However, errors won’t be caught before the script
is run and could cause problems with the client if it can’t handle the errors
well. In the case of JavaScript, the error handling is up to the client being
used by the viewer.

Numerous Environments
JavaScript can be run in numerous environments. Most commonly, the
environment is a Web browser since JavaScript has basically become the
default scripting language used when adding dynamic interactivity to a
Web page.
While JavaScript is often thought of in relation to Web browsers, a
number of other environments use it for programming, such as Adobe
Acrobat and Flash (based on ECMAScript). In addition to this, Node.js
allows JavaScript to be used as a server-side language or to perform
input/output operations on an operating system. This book will cover
JavaScript in Node.js and in the Web browser at a beginner level to help
you get started with programming in both environments.

Putting It All Together


To begin, you might wonder how JavaScript is run in a browser. Where
should you write your JavaScript code, and what tells the browser it is
different from anything else on a Web page? The answers are general for
now, but the next chapter provides more details.
JavaScript runs in the browser by being added into an existing HTML
document (either directly or by referring to an external script file). You can
add special tags and commands to the HTML code that will tell the browser
that it needs to run a script. When the browser sees these special tags, it
interprets the JavaScript commands and will do what you have directed it
to do with your code. Thus, by simply editing an HTML document, you can
begin using JavaScript on your Web pages and see the results.
For example, the following code adds some JavaScript to an HTML file
that writes some text onto the Web page. Notice the addition of <script>
and </script> tags. The code within them is JavaScript.

The next chapter looks at how to add JavaScript in an HTML file by


using the <script> and </script> HTML tags. This will be your first step on
the road to becoming a JavaScript coder!

Online Resources
To find additional information online to help you with JavaScript, here are
some useful resources:

• Projects/code for this book: github.com/JohnPollock/JSABG-ED-5


• An excellent tutorial site that includes cut-and-paste scripts:
www.javascriptkit.com
• A place where you can address questions about JavaScript to fellow
coders: stackoverflow.com/questions/tagged/javascript

Try This 1-1 Use JavaScript to Write Text

pr1_1.html

This project shows you JavaScript in action by loading an HTML document


in your browser. The script writes a line of text in the browser using
JavaScript.

Step by Step
1. Copy and paste the code shown here into your text editor:

2. Save the file as pr1_1.html and open it in your Web browser. You
should see a single line of text that was written with JavaScript. (To
open a file in your Web browser, go to the File menu and look for an
option that says something like Open, or Open File, and select it. You
should be able to browse for the file you want to open as you would
with other programs.)

Try This Summary


In this project, you copied and pasted a section of code into a text editor
and saved the file. When you opened the saved file in your Web browser, a
line of text was displayed in the browser. This text was written in the
browser window using JavaScript. You will see more about how this type of
script works in Chapter 2.
Chapter 1 Self Test
1. You must know which of the following to be able to use JavaScript in
a Web browser?
A. Perl
B. C++
C. HTML
D. SGML
2. Which of the following is something you should have to use
JavaScript in a Web page?
A. A Web browser
B. A C++ compiler
C. A 500GB hard drive
D. A DVD-RW drive
3. The choice of a Web browser is up to you, as long it’s compatible with
__________.
A. Flash
B. VBScript
C. JavaScript
D. Windows XP
4. JavaScript and Java are the same language.
A. True
B. False
5. __________ is the international standard name and specification used
for the JavaScript language.
A. JScript
B. LiveScript
C. ECMAScript
D. ActionScript
6. JavaScript has similarities to other programming and scripting
languages.
A. True
B. False
7. Before its release as JavaScript, JavaScript was called __________.
A. Java
B. JavaCup
C. LiveScript
D. EasyScript
8. JavaScript is __________.
A. prototype-based
B. class-based
C. object deficient
D. not a language that uses objects
9. A fancy code editor is necessary to edit JavaScript files.
A. True
B. False
10. In what ways can a fancy code editor help a JavaScript programmer?
A. It may offer features such as movies and video games.
B. It may offer features such as code highlighting, completion,
debugging tools, and more.
C. It may offer features such as electronics repairs and warranties.
D. It can’t help at all.
11. A(n) __________ language doesn’t require a program to be compiled
before it is run.
A. programming
B. server-side
C. interpreted
D. computer
Another Random Scribd Document
with Unrelated Content
KIITOLLISUUTTA.

Lauantaina joulukuun 31 p:nä.

Sinun toverisi Stardi ei koskaan moiti opettajaansa, siitä olen


vakuutettu. — "Opettaja oli tänään huonolla tuulella, opettaja oli
kärsimätön"; sinä sanot sen tavalla, joka osoittaa suuttumusta.
Mutta ajattelepa hiukkasen, kuinka monta kertaa sinä olet
kärsimätön ja kenelle! Isällesi ja äidillesi; ja se on rikos. Sinun
opettajallasi on kyllä syytä silloin tällöin olla kärsimätön. Ajattele
kuinka monta vuotta hän jo on työskennellyt ja uuvuttanut itseänsä
teidän tähtenne, ja vaikka muutamat teistä ovatkin hyviä ja
herttaisia, on teissä paljon sellaisiakin, jotka vain hänen hyvyyttään
väärinkäyttävät. Ja kaikki te hänelle tuotatte enemmän katkeria
hetkiä kuin iloa.

Ja jospa tietäisit, kuinka monesti opettaja tulee kouluun, vaikka


onkin sairas. Hänen kärsimättömyytensä on usein vain seuraus siitä,
että hän on pahoinvoipa, ja kipeästi häneen koskee, kun hän
huomaa, etteivät oppilaat ole siitä tietävinänsäkään, vaan käyttävät
tilaisuutta vaivatakseen häntä.
Poikaseni, kunnioita ja rakasta opettajaasi! Rakasta häntä siksi,
että isäsikin häntä rakastaa ja kunnioittaa; siksi että hän pyhittää
elämänsä monen pojan hyväksi; siksi että hän valaisee ja laajentaa
sisäistä ihmistäsi ja kasvattaa sieluasi; siksi että monen vuoden
perästä, kun sekä minä että hän jo olemme poissa, hänen kuvansa
nousee sielussasi aina minun kuvani keralla. Ja silloin muistuu
mieleesi sellaisia surun ja väsymyksen piirteitä hänen kasvoissaan,
joita nyt et huomaakaan, ja sinä häpeet ja kadut, ettet ole häntä
kyllin rakastanut, kyllin kunnioittaen häntä kohdellut. Rakasta
opettajaasi, sillä hän on jäsen tuosta suuresta, 50.000 henkilöä
käsittävästä perheestä, joka on levinnyt ympäri koko maamme ja
työskentelee alkeisopettajina miljoonien lasten henkisinä isinä. Hän
on noita huonosti palkattuja ja vähässä arvossa pidettyjä työmiehiä,
jotka maallemme kokevat kasvattaa nykyistä sukupolvea
kunnollisempaa kansaa. Minä en voi iloita rakkaudestasi, ellet ulota
sitä kaikkiin hyväntekijöihisi, joista opettajasi on vanhempiesi jälkeen
ensimmäisen sijan saava. Rakasta häntä aivan kuin rakastaisit minun
veljeäni, rakasta häntä silloin kun hän sinua hyväilee ja silloin kun
hän sinua nuhtelee, silloin kun hän sinusta tekee oikein ja silloin kun
et saata hänen toimiansa ymmärtää; rakasta häntä silloin kun hän
on iloinen ja puhelias, mutta vielä enemmän silloin kun näet hänet
surullisena! Ja lausu aina sana "opettaja" suurimmalla
kunnioituksella, sillä isän ja äidin nimen jälkeen ei ole sanaa, jolla
olisi suloisempi sointu!

Isäsi.
APUOPETTAJA.

Keskiviikkona tammikuun 4 p:nä.

Isä oli oikeassa. Opettaja oli huonolla tuulella siksi, että hän oli
sairas. Hänen sijaansa me saimme jo kolme päivää sitten
apuopettajan, joka on pieni ja parraton ja melkein nuorukaiselta
näyttävä. Tänä aamuna sattui koulussamme ruma tapahtuma. Jo
ensimmäisenä ja toisena päivänä pojat melusivat aikalailla, siksi että
tämä apuopettaja on hyvin kärsivällinen ja ainoastaan sanoi: "Olkaa
hiljaa, olkaa hiljaa, minä pyydän!" Mutta tänä aamuna vallattomuus
meni yli rajojensa. Syntyi sellainen rähinä, ettei hänen sanojansa
enää kuulunut. Hän nuhteli ja pyysi, mutta turhaan. Pari kertaa
esiintyi johtaja ovella meitä ankarasti katsellen. Tuskin hän oli
päässyt pois, ennenkuin taas syntyi sellainen hälinä kuin
markkinatorilla.

Garrone ja Derossi kääntyivät ja koettivat merkkejä antamalla


hillitä toisia, sellainen käytös kun oli häpeä. Ei kukaan heistä
välittänyt. Ei kukaan muu pysynyt alallaan kuin Stardi, joka
kyynärpäät pulpetilla ja nyrkit ohimoilla istui luultavasti mietiskellen
ihanaa kirjastoansa, ja Garoffi haukannenineen ja postimerkkeineen;
hän järjesteli niiden nimiä, jotka olivat ottaneet arpoja ja maksaneet
kaksi sentesimoa voittaakseen erään taskussa kannettavan
mustetolpon. Toiset lörpöttelivät ja nauroivat, kiinnittivät kyniä
pulpettiin ja soittivat niillä, ampuivat toisiaan pureskelluilla
paperikuulilla, käyttäen linkoina venyviä sukkanauhojaan.

Opettaja tarttui milloin mihinkin, ravisteli heitä ja pani seinää


vastaan seisomaan. Ei siitä mitään apua ollut. Hän ei lopulta enää
tiennyt muuta sanoa kuin: "Miksi käyttäydytte tällä tavalla?
Tahdotteko välttämättömästi, että saan nuhteita?"

Sitten hän löi nyrkkinsä pöytään ja huusi vimmastuneella,


itkunsekaisella äänellä: "Hiljaa, hiljaa, hiljaa!" Se oli surullista kuulla.
Mutta melu vain kasvoi. Franti viskasi hänen päällensä paperinuolen,
muutamat naukuivat, jotkut löivät toisiaan päähän kirjalla. Kaikki oli
niin mullin mallin, ettei sitä kielin voi kertoa. Samassa astui
vahtimestari sisään ja sanoi: "Johtaja kutsuu teitä, herra opettaja."
Opettaja meni kiireesti ulos tehden tuskastuneen liikkeen. Nytpä
hälinä oikein nousi. Mutta yht'äkkiä Garrone syöksähti paikaltaan,
kasvot muuttuneina, nyrkkiä puiden, ja huusi raivostuneella äänellä:
"Heretkää jo! Te olette petomaisia. Te rääkkäätte opettajaa siksi,
että hän on hyvä. Jos hän teitä löisi ja hutkisi, kyllä te silloin
luikertelisitte kuin koirat. Te olette raukkoja. Sitä, joka häntä vielä
vihoittaa, odotan minä tuolla ulkona ja lyön niin, että hampaat
kurkussa kolisevat, vaikka hänen isänsä olisi näkemässä. Sen minä
lupaan."

Kaikki olivat ääneti. Miten kaunis Garrone oli tällä hetkellä


säihkyvine silmineen! Hän oli kuin nuori jalopeura. Hän tähysteli
kaikkein rohkeimpia toista toisensa perästä, ja kaikki olivat allapäin.
Kun opettaja hetkisen kuluttua palasi, silmät punaisina, ei kuulunut
enää hiiskaustakaan. Hän oli hyvin hämmästynyt. Mutta kun hän
sitten näki Garronen värisevänä ja tulistuneena, sanoi hän
sydämellisesti, aivan kuin veljelleen: "Minä kiitän sinua, Garrone."
STARDIN KIRJASTO.

Torstaina tammikuun 5 p:nä.

Minä olen nyt käynyt Stardin luona, joka asuu vastapäätä koulua,
ja kateeksi kävi nähdessäni hänen kirjansa. Hän ei ole ensinkään
varakas eikä voi ostaa itselleen monta kirjaa, mutta hän säilyttää
huolellisesti kaikki koulukirjansa ja muut vanhemmiltaan saamansa
kirjat. Joka soldon, jonka hän saa, hän panee säästöön ja vie
kirjakauppiaalle. Hän on siten jo saanut pienen kirjaston. Kun isä
huomasi tämän hänen mielitekonsa, osti hän hänelle kauniin
kirjahyllyn viheriäisine uutimineen ja sidotti melkein kaikki hänen
kirjansa erivärisiin kansiin, jotka poika itse valitsi.

Nyt hän vain vetää erästä rihmaa, uutimet aukenevat, ja sitten


näkee kolme riviä kirjoja, kaikenvärisiä, kiiltävillä kultakirjaimilla
kaunistettuja satukirjoja, matkakertomuksia, runoja. Kuvitettujakin
kirjoja hänellä on.

Ja hän ymmärtää niin hyvin sovitella värit yhteen. Hän panee


valkoiset punaisten, keltaiset mustien ja siniset valkoisten rinnalle,
niin että ne jo kaukaa näkee, ja kokonaisvaikutus on komea.
Hänestä on todellinen ilo ryhmitellä niitä aina uuteen järjestykseen.
Hän on hankkinut itselleen luettelon ja on aivan kuin luotu
kirjastonhoitajaksi. Hän seisoo aina kirjojensa ääressä, pyyhkii niitä,
selailee niitä sekä tarkastelee niiden siteitä. Kannattaa nähdä millä
huolella hän aukoilee niitä pyöreillä, lyhyillä käsillään ja puhaltelee
lehtiä. Kaikki näyttävät vielä aivan uusilta. Ja minä olen jo aikaa
omani repinyt. Jokaisen kirjan saanti on hänestä juhlatilaisuus. Hän
sivelee sitä, asettaa hyllylle ja ottaa jälleen alas, tarkastelee ja
vartioitsee kuin aarretta. Ei hän tunnin aikaan näyttänyt minulle
mitään muuta. Väliin hänen silmiänsä pakottaa pelkästä lukemisesta.

Kerran hänen isänsä, joka myöskin on tanakka, voimakas ja


isopäinen kuin poikakin, tuli sisään, löi häntä kahdesti niskaan ja
sanoi karkealla äänellään: "No, mitä sanot tästä visapäästä? Se on
kova pää, mutta jotakin tulee, sen vakuutan." Ja isän hyväillessä
Stardi ummisti silmänsä kuin iso metsäkoira. Minä en ymmärrä syytä,
mutta minä en uskaltanut laskea leikkiä hänen kanssaan, ja minusta
tuntuu ihan uskomattomalta, että hän on vain vuotta vanhempi
minua. Kun hän ovessa sanoi minulle: "Näkemiin", ei paljoa
puuttunut, etten täysikasvuisen tavalla vastannut: "Voikaa hyvin!"

Sitten sanoin isälle kotona: "Stardi ei ole nerokas, hänellä ei ole


minkäänmoisia seurustelutapoja, hänen vartalonsa on miltei
naurettava, ja kuitenkin hän tekee minuun syvän vaikutuksen." Ja
isäni vastasi: "Syy on siinä, että hänellä on luonteen lujuutta." Ja
minä sanoin: "Tunnin kuluessa, jonka nyt olen oleskellut hänen
seurassaan, hän ei ole vaihtanut kanssani viittäkymmentä sanaa, ei
näyttänyt leikkikaluja, ei kertaakaan nauranut, ja kuitenkin olen
viihtynyt mainiosti hänen seurassaan." — Ja isäni vastasi: "Se johtuu
siitä, että sinä kunnioitat häntä."
SEPÄN POIKA.

Perjantaina tammikuun 6 p:nä.

Mutta myöskin Precossia minä kunnioitan, ja oikeastaan on liian


vähän sanottu, että häntä vain kunnioitan. Precossi, tuo sepän poika,
on pieni näivettynyt raukka, joka aina pelokkaasti katsoo syvillä,
mutta suloisilla silmillään ja tuntuu kaikille sanovan: Suokaa
anteeksi! Hän on aina kivulloinen ja lukee kuitenkin paljon. Isä tulee
usein päihtyneenä kotiin, lyö häntä aivan syyttä ja viskoo hänen
kirjansa ja vihkonsa sekaisin. Usein hän tulee kouluun mustelmia
poskissa, kasvot turvoksissa, silmät itkusta punaisina. Mutta ei hän
milloinkaan myönnä isänsä häntä lyöneen.

"Isäsi on taas lyönyt sinua", huutavat toverit. Mutta hän huutaa


takaisin: "Ei se ole totta, ei se ole totta" vain pelastaakseen isänsä
kunnian. "Tätä lehteä sinä et ole polttanut", sanoi opettaja eräänä
päivänä osoittaessaan hänen puoleksi palanutta työtänsä. "Olen",
vastasi hän värisevällä äänellä, "se pääsi minulta luiskahtamaan
tuleen". Ja kuitenkin me kaikki tiesimme, että hänen humalainen
isänsä oli potkaissut pöydän kumoon pojan kirjoittaessa.
Hän asuu eräässä meidän talomme vinttikamarissa. Ovenvartija
kertoo äidilleni kaikki. Ja sisareni Silvia kuuli hänen kerran itkevän,
kun isä tyrkkäsi hänet päistikkaa rappusista alas; hän oli pyytänyt
muutamia soldoja ostaakseen kieliopin. Hänen isänsä juo, on
työtönnä, ja perhe kärsii nälkää. Usein Precossi tulee syömättä
kouluun ja pureskelee salaa leivänpalaa, jonka Garrone hänelle
antaa. Mutta hän ei koskaan sano: "Minun on nälkä, isä ei anna
ruokaa."

Aina kun hänen isänsä kulkee koulun ohi hoippuvin askelin, kasvot
pöhöttyneinä, hiukset kuin tuulenpesä ja lakki kallellaan, hän jääpi
poikaansa odottamaan. Ja poika parka värisee kuin haavanlehti
hänet kadulla nähdessään. Mutta sitten hän kuitenkin juoksee
hymyillen häntä vastaan, vaikk'ei isä ole hänestä tietävinäänkään.

Precossi parka! Hän ompelee hajalliset vihkonsa kokoon, lainaa


kirjoja lukeakseen läksynsä, kiinnittää paidanriekaleitaan
nuppineuloilla yhteen. Kerrassaan surkeata on nähdä hänen
voimistelevan isoissa kaltoissa kengissään, retkuvissa housuissaan ja
liian pitkässä takissaan, jonka hihat ovat aina kyynärpäihin käärityt.
Hän on ahkera ja oppivainen. Hän olisi ensimmäisiä luokalla, jos hän
voisi kotona rauhallisesti työskennellä. Tänä aamuna hän tuli
kouluun kynsien jäljet poskissa, ja kaikki huusivat: "Nyt et voi enää
valheeksi väittää. Isäsi on sen tehnyt. Sanopa johtajalle, että hän
toimittaa isäsi linnaan!"

Mutta hän nousi seisomaan aivan tulipunaisena ja huusi


vapisevalla äänellä: "Se ei ole totta, isäni ei lyö minua koskaan."
Mutta sitten tunnilla vierähtivät kyynelkarpalot hänen pulpetilleen, ja
kun joku häntä katseli, koetti hän hymyillä salatakseen
mielenhaikeuttaan. Precossi rukka!
VIKTOR EMANUELIN MUISTO.

Tiistaina tammikuun 17 p:nä.

Tänään kello kaksi, kun olimme kokoontuneet kouluun, kutsui


opettaja Derossin, joka asettui luokan eteen ja kauniilla, sointuvalla
äänellään rupesi meille kertomaan:

"Tänään neljä vuotta sitten, juuri tänä tuntina, saapuivat Rooman


Pantheonin edustalle ruumisvaunut, jotka kuljettivat Viktor
Emanuelin ruumista. Viktor Emanuel II, Italian ensimmäinen
kuningas, kuoli 29-vuotisen hallituskauden jälkeen, joka muodostui
mainehikkaaksi ja siunausta tuottavaksi hänen urhoollisuutensa,
oikeudentuntonsa ja rohkeutensa vuoksi.

"Hänen ajaltaan on suuri, yhteinen italialainen isänmaa.


Seitsemästä valtakunnasta, joihin se oli hajonnut, syntyi yksi ainoa
itsenäinen, vapaa valtio.

"Seppeleiden peittämät ruumisvaunut kulkivat kukkien sadellessa


hiljalleen eteenpäin lukemattomien ihmisjoukkojen ohi, jotka olivat
rientäneet Italian kaikista osista ja nyt seisoivat hiljaa, henkeä
pidättäen, surun valtaamina. Saattojoukon etunenässä kulki
kenraaleja, koko joukko ministereitä ja ruhtinaita, joita seurasi jono
sotavanhuksia, koko metsä lippuja, kolmensadan kaupungin
edustajat, parhaita, mainehikkaimpia miehiä, mitä kansassa oli.
Vihdoin se pysähtyi sen ylevän temppelin edustalle, missä hauta
odotti suurta vainajaa.

"Kaksitoista haarniskoitua sotilasta kantoi arkun vaunuista. Silloin


Italian kansa lausui viimeiset jäähyväiset kuninkaalleen, joka sitä oli
niin lämpimästi rakastanut, viimeiset jäähyväiset sotilaalleen,
isälleen, historiansa siunatuimmille, onnellisimmille vuosille. Se oli
suuri, juhlallinen hetki, Tuhannesta kurkusta kaikui yht'aikaa:
'Hyvästi, jalo, hyvä, oikeuttarakastava kuningas! Sinä olet elävä
kansasi sydämessä niin kauan kuin aurinko Italiaa valaisee.' Liput
kohosivat taivasta kohti, ja Viktor Emanuel laskettiin
mainehikkaaseen hautakammioonsa."
KÖYHÄT.

Perjantaina tammikuun 20 p:nä.

On suurta uhrautua isänmaansa puolesta, mutta silti ei pidä


halveksia pienempiä hyveitä, poikani. Kun tänä aamuna tulit koulusta
ja astelit minun edelläni, näin vastaasi tulevan erään köyhän vaimon,
joka kantoi näivettynyttä, surkeannäköistä lasta ja pyysi sinulta
almua. Sinä kyllä katsoit häneen, mutta et kuitenkaan antanut
mitään, vaikka taskussasi oli soldoja.

Älä totuta itseäsi kulkemaan välinpitämättömänä köyhän ohi, joka


ojentaa kättään, varsinkaan jos tämä köyhä on äiti, joka pyytää
soldon lapselleen! Ajattele, että tämä lapsi mahdollisesti kärsii
nälkää, ajattele mitä äiti silloin tuntee! Koeta kuvitella, miltä tuntuisi
omasta äidistäsi, jos hänen jonakin päivänä täytyisi sanoa: "Henrik,
tänään en voi antaa sinulle edes leipää." Kun annan jollekulle
köyhälle soldon ja hän sanoo: "Jumala siunatkoon teitä", et voi
käsittää, minkä suloisen tunteen se minussa herättää. Minusta
tuntuu sillä, kuin saisin paljon enemmän kuin olen antanut. Ota
sinäkin silloin tällöin soldo pienestä kukkarostasi ja anna se jollekulle
turvattomalle vanhukselle, leivättömälle äidille tai orpolapselle.
Köyhät pitävät lasten lahjoista, sillä ne eivät nöyryytä heitä, koska
lapset, jotka eivät mitään omista, vaan saavat kaiken muilta, ovat
heidän kaltaisiansa. Katsopa vain kuinka köyhät aina ympäröivät
kouluja. Aikaihmisen almu on lähimmäisrakkaudesta lähtenyt, multa
lapsen anti on kuin hyväily. On kuin hän soldon ohessa myös antaisi
kukan.

Ajattelepa, että kun sinulla on joka lajia yllin kyllin, heiltä puuttuu
kaikki, että sinun ollessasi onnellinen he kerjäävät almua vain siksi,
etteivät kokonaan menehtyisi! Ajattele kuinka surkeata, että keskellä
näitä komeita palatseja ja valaistuja katuja, joilla loistavat vaunut
kulkevat ja samettiin puetut lapset astuvat, on vaimoja ja lapsia,
joilla ei ole leipää! Keskellä meluavia kaupunkeja on poikasia, aivan
yhtä kyvykkäitä kuin sinä, joilla ei ole enempää syötävää kuin
erämaan pedoilla. Voi lapseni, älä koskaan enää mene almua
rukoilevan äidin ohi antamalta hänelle jotain!

Äitisi.
FRANTI EROTETAAN KOULUSTA.

Lauantaina tammikuun 21 p:nä.

Franti on inhoittava poika. Kun joku isä tulee kouluun poikaansa


nuhtelemaan, iloitsee Franti. Hänen on pakko pelätä Garronea,
mutta muurarimestaria hän lyö, siksi että tämä poloinen on pieni.
Hän kiusaa Crossia hänen hervottoman kätensä takia ja härnäilee
Precossia, jota kaikki kunnioittavat; Robettiakin, joka pelasti lapsen
ja nyt liikkuu puujaloilla, hän pilkkaa. Hän pistelee kaikkia, jotka ovat
häntä heikommat, ja kun hän pui nyrkkiään, on hän oikein raivoisa ja
vaarallinen.

Hänen matalassa otsassaan ja ilkeissä silmissään, jotka hän


melkein piilottaa lakkinsa alle, on jotain inhoa herättävää. Hän ei
välitä mistään, nauraa opettajaa päin silmiä, varastaa kun vain
tilaisuuden saapi, valehtelee hävyttömällä naamalla, tuo
nuppineuloja kouluun pistääkseen toverejaan, repii napit sekä
omasta että toveriensa takeista pelatakseen nappikuoppaa. Hänen
kirjansa, vihkonsa ja karttansa ovat rutistetut, tahratut ja repaleina.
Viivoittimessa on hampaan jälkiä, kynät ovat pureskeltuja, kynnet
samaten, hänen vaatteensa ovat täynnä tahroja ja tappeluissa
saatuja ratkeamia ja repeämiä.
Kerrotaan, että hänen äitinsä on tullut huolista sairaaksi ja että
hänen isänsä on kolme kertaa ajanut hänet kotoa pois. Usein tulee
äiti kouluun poikansa käytöstä tiedustelemaan ja menee aina itkien
pois. Franti vihaa koulua, vihaa tovereitaan, vihaa opettajaa.
Opettaja ei aina ole huomaavinansakaan hänen konnamaisuuksiaan,
mutta siitä hän vain yltyy.

Opettaja koetti voittaa häntä hyvyydellä, mutta sitten Franti vain


pilkkasi häntä. Nuhteita saadessaan hän oli itkevinään, peitti
kasvonsa käsillään ja — nauroi. Hänet erotettiin kolmeksi päiväksi
koulusta, mutta hän palasi entistä ilkeämpänä.

Derossi sanoi hänelle tuonoin: "Mutta herkeä jo, etkö näe, että
opettaja kärsii" — ja Franti uhkaa iskeä naulan hänen ruumiiseensa.

Tänä aamuna hänet vihdoin ajettiin koulusta kuin koira. Juuri kun
opettaja ojensi Garronelle kirjoitusvihkoa, viskasi Franti lattialle
pienen dynamiittinallin, joka räjähti kuin pyssynpamaus.

Koko luokka hypähti seisoalleen, ja opettaja ryntäsi paikaltaan


huutaen: "Franti, tiehesi heti!" Hän vastasi: "En minä sitä tehnyt." Ja
nauroi. Opettaja sanoi vielä kerran: "Ulos täältä!" "Enkä mene",
vastasi hän.

Silloin opettaja kiivastui, tarttui hänen käsivarteensa, ravisti häntä


ja laahasi pulpetista ulos. Hän puolustautui, kiristi hammasta ja teki
vastakynttä. Opettaja enemmän kantoi kuin talutti hänet johtajan luo
ja palasi sitten yksin luokkaan asettuen paikalleen. Hänen päänsä
vaipui kättä vasten, ja kasvojen ilme oli niin alakuloinen ja väsynyt,
että meihin oikein syvästi koski häntä katsellessa.
"Kolmikymmenvuotisena opettaja-aikanani ei ole vielä sellaista
tapahtunut", sanoi hän katkerasti päätään pudistaen. Ei kukaan
uskaltanut hiiskahtaa. Hänen kätensä vapisivat liikutuksesta, ja ryppy
hänen otsassaan oli niin syvä, että muistutti arpea. Opettaja parka!
Kaikki kärsivät hänen kanssaan.

Derossi nousi ja sanoi: "Opettaja, älkää olko noin murheellinen!


Me rakastamme teitä." Hän tointui hiukkasen ja sanoi:
"Palatkaamme taas tehtäväämme!"
SARDINIALAINEN RUMMUNLYÖJÄ.

(Opettajan kertomus.)

Tiistaina tammikuun 24 p:nä.

Custozan taistelun ensimmäisenä päivänä, heinäkuun 24:ntenä


1848, joutui noin 60 miestä meidän jalkaväkeämme suureen
vaaraan. Kun he juuri olivat miehittämässä yksinäistä taloa, joka oli
pienellä töyryllä, karkasi pari komppaniaa vihollisia heidän
kimppuunsa lähettäen sellaisen luotituiskun joka puolelta, että
meikäläiset tuskin ennättivät taloon suojaan.

Ovet lujasti suljettuaan meikäläiset riensivät maakerroksen ja


kellarin ikkunoihin ja aloittivat kiivaan tulen hyökkääjiä vastaan, jotka
vastasivat samaan tapaan, lähestyen askel askelelta. Nämä
kuusikymmentä italialaista olivat vanhan valkopartaisen, ankaran
näköisen kapteenin komennossa. Heidän joukossaan oli myöskin
sardinialainen rummunlyöjä, neljätoistavuotias poika, joka tuskin
näytti kaksitoistavuotiaalta, pieni, oliivinvärinen, mustasilmäinen.

Kapteeni johti puolustusta eräästä alakerroksen ikkunasta. Hänen


komentonsa kajahtivat kuin pistolinlaukaukset, eikä hänen
rautakasvoissaan havainnut vähintäkään liikutuksen merkkiä.

Rummunlyöjä oli hieman kalpea, mutta seisoi tanakkana pystyssä.


Sitten hän kiipesi eräälle pöydälle ja nojaten seinää vasten kurotti
kaulaansa nähdäksensä ikkunasta. Hän erotti savun läpi vihollisten
valkeat univormut, jotka kentällä hitaasti lähenivät.

Talo oli jyrkällä rinteellä, mutta sinnepäin oli vain yksi ikkuna, sekin
vinttikamariin kuuluva. Siksi eivät viholliset uhanneetkaan tältä
puolelta. Koko rinne oli vapaa. Tuli kohtasi vain huoneen etupuolta ja
sivuja.

Mutta se oli kauhea tuli. Luoteja sinkoili kuin rakeita, muurit


murenivat, tiilet pirstautuivat ja ovet, ikkunapielet ja huonekalut
särkyivät. Puun pirstaleita, kalkkipilviä ja keittiökalujen kappaleita
lensi ilmaan. Kaikkialla pamahteli, rätisi ja ryskyi. Siellä täällä kaatui
aina joku sotilas ikkunan luota ja vietiin syrjään. Toiset hoipertelivat
huoneesta huoneeseen painaen käsiään haavoihinsa. Keittiössä
makasi jo eräs kuolleena, ammottava reikä otsassa. Vihollisten
puoliympyrä vetäytyi yhä lähemmäksi.

Kapteeni, joka tähän asti oli seisonut järkähtämättä, teki samassa


levottoman liikkeen ja poistui pitkin askelin huoneesta. Vahti seurasi
häntä. Kolmen minuutin kuluttua tämä palasi kiireesti takaisin ja
huusi pientä rummunlyöjää käskien häntä mukaansa. Poika seurasi.
Hän juoksi portaita ylös ja astui vahdin kanssa autioon
vinttikamariin, missä tapasi kapteenin kirjoittamassa ikkunaa vasten
nojautuneena. Lattialla oli köysi.

Kapteeni pani kirjeen kokoon ja käänsi poikaan harmaat, kylmät


silmäteränsä, jotka saivat kaikki sotilaat värisemään, ja sanoi
tuimasti: "Rummunlyöjä!"
Tämä nosti heti kätensä ohimolle.

Kapteeni sanoi: "Onko sinulla sydän oikealla paikalla?"

Pojan silmät iskivät tulta. "On, herra kapteeni", vastasi hän.

"Katso tuonne", sanoi kapteeni työntäen hänet ikkunan luo,


"tuonne tasangolle, Villafrancan lähelle, missä nuo pistimet nyt juuri
välähtelevät! Siellä meikäläiset seisovat joutilaina. Ota tämä kirje,
laskeudu tästä pienestä ikkunasta köyttä myöten, lennä kuin nuoli
rinnettä alas, aukealla tapaat meikäläiset ja anna tämä kirje
ensimmäiselle upseerille, jonka näet. Jätä tänne vyösi ja reppusi!"

Pieni rummunlyöjä laski vyönsä ja reppunsa lattialle ja kätki


kirjeen povitaskuunsa. Vahti viskasi köyden pään ikkunasta ja piti
lujasti molemmin käsin kiinni sen toisesta päästä. Kapteeni auttoi
poikaa, joka selkä tasangolle päin laskeusi köyttä myöten. "Paina
mieleesi" — sanoi hän — "että tämän joukon pelastus riippuu sinun
rohkeudestasi ja voimastasi! Sen kohtalo on sinun käsissäsi."

"Luottakaa minuun, herra kapteeni", vastasi poika ja kapusi alas.

"Juokse kumarassa rinnettä alas!" varoitti kapteeni vielä pitäen


köyden päästä vahdin kanssa.

"Olkaa huoleti!"

"Jumala auttakoon sinua!"

Muutamassa silmänräpäyksessä oli poika jo maassa. Vahti veti


köyden ylös ja katosi. Kapteeni jäi ikkunaan seisomaan ja seurasi
levottomana poikaa, joka täyttä laukkaa juoksi rinnettä alas. Hän
toivoi hänen jo päässeen onnellisesti, kun äkkiä kuusi pientä
tomupilveä, jotka kohosivat maasta aivan poikasen läheisyydessä,
ilmoitti, että viholliset olivat huomanneet hänet ja ampuneet ylängön
harjalta. Pienet tomupilvet olivat hiekkaa, jonka kuulat olivat
tupruttaneet ilmaan. Mutta rummuttaja vain juoksi kuin mieletön.
Yht'äkkiä hän kaatui. "Kuoliaaksi ammuttu", huusi kapteeni nyrkkiään
puiden. Mutta tuskin oli sana päässyt hänen suustaan, ennenkuin
hän jo taas näki pojan nousevan. "Pieni kompastus vain", sanoi hän
itsekseen ja hengitti jälleen helpommin. Ja todellakin, rummuttaja
alkoi taas voimiensa takaa juosta, mutta hän ontui. "Jalka on
nyrjähtänyt", ajatteli kapteeni. Muutamia tomupilviä nousi vielä siellä
täällä, mutta yhä etempänä pojasta. Hän oli pelastunut. Kapteeni
päästi riemuhuudon. Mutta hän jäi kuitenkin vielä ikkunan ääreen
silmillään seuraamaan poikaa pelosta vavisten, sillä kaikki riippui nyt
muutamasta tuokiosta. Ellei poika avunpyyntökirjeineen saapunut
ajoissa perille, oli näiden sotilaiden joko siihen paikkaan kaatuminen
tai antautuminen. Poika juoksi jonkin aikaa sangen nopeasti, mutta
sitten hän hiljensi vauhtia ja näkyi ontuvan pahasti. Taas hän jatkoi
juoksuaan, mutta se kävi yhä vaivalloisemmaksi; ehtimiseen hän
kompastui ja pysähtyi. "Kuula on hipaissut häntä", ajatteli kapteeni,
seurasi tarkkaan ja vavisten hänen liikkeitänsä ja lausui rohkaisevia
sanoja, ikäänkuin poika olisi voinut kuulla häntä. Palavin silmin hän
lakkaamatta mittasi pojan ja noiden välähtelevien aseiden väliä,
jotka näkyivät keskellä auringon kultaamia vehnäpeltoja. Ja sillä
aikaa hän kuuli alakerroksesta kuulien vinkumista ja jyskettä,
upseerien ja vahdin raivoisia, käskeviä huutoja, haavoittuneiden
äänekkäitä valituksia, särkyvien huonekalujen ja muurien ryskinää.

"Rohkeutta!" huusi hän seuraten silmillään kaukaista rummuttajaa.


"Eteenpäin! Juokse! Kas nyt hän pysähtyy, voi surkeutta! Mutta kas,
nyt hän taas juoksee."
Eräs upseeri riensi hengästyneenä kertomaan, että viholliset jo
liehuttivat valkeata liinaa viitaten antautumaan.

"Ei saa vastata siihen", huusi kapteeni kääntämättä silmiään


pojasta, joka jo oli tasangolla, mutta ei enää juossut, vaan hiljaa
laahusti eteenpäin.

"No mene nyt! Juokse nyt vielä vähäisen!" sanoi kapteeni


hampaitaan kiristellen ja nyrkkiään puiden. "Kuole, lurjus, mutta
juokse! — Voi tuota kurjaa laiskuria! Nyt hän kai istuu."

Ja tosiaankin, poika, jonka pää tähän asti vielä oli pistänyt esiin
vehnäpellosta, oli kadonnut aivan kuin hän olisi kaatunut. Mutta
hetken kuluttua hänen päänsä näkyi uudestaan, kunnes hän vihdoin
katosi kapteenin näkyvistä pensaston taakse.

Nyt kapteeni laskeusi kärsimättömänä alas. Kuulat vinkuivat,


huoneet olivat täynnä haavoittuneita, joista muutamat hoipertelivat
kuin juopuneet etsien tukea huonekaluista. Seinät ja lattia olivat
veriset. Ruumiita makasi poikkiteloin ovien edessä. Kuula oli
murskannut erään luutnantin oikean käsivarren. Kaikki oli savu- ja
tomupilvien peitossa. "Rohkeutta!" huusi kapteeni. "Pysykää
järkähtämättöminä! Apua tulee kohta. Vähän kestävyyttä vielä!"

Viholliset olivat yhä lähenneet. Savun läpi saattoi jo erottaa heidän


kasvonsa, ja ammunnan keskeltä kuuluivat heidän raivoisat
huutonsa. He vaativat antaumista uhaten muuten surmata kaikki.
Muutamat pelästyneet sotilaat vetäytyivät jo ikkunasta pois.
Kersantit ajoivat heidät takaisin.

Mutta puolustus laimeni yhä Alakuloisuus kuvastui kaikkien


kasvoilla. Vastarinta oli mahdotonta. Hetkeksi taukosi ampuminen, ja
jylisevä ääni karjaisi: "Antautukaa!" — "Emme!" ärjäisi kapteeni
eräästä ikkunasta. Ja tuli alkoi uudestaan entistä kiivaammin ja
raivoisammin molemmilta puolin. Sotilaita kaatui, moni ikkuna oli jo
ilman puolustajaa. Ratkaiseva hetki läheni. Kapteeni huusi
vimmastuneena: "He eivät tulekaan, eivät tule!" ja riehui miekka
kädessä kuin mieletön valmiina kuolemaan. Mutta samassa tuli vahti
vinttikamarista ja kirkaisi ääneen: "He tulevat!" "He tulevat!" toisti
kapteeni riemusta huudahtaen.

Tämän kuullessaan kaikki, sekä terveet että sairaat, vahdit ja


upseerit syöksyivät ikkunoihin, ja vastustus kävi taaskin ankaraksi.
Hetkisen kuluttua huomattiin jonkinmoista epävarmuutta ja alkavaa
epäjärjestystä vihollisten riveissä. Salaman nopeudella kapteeni
kokosi joukon maakerrokseen ja järjesti siellä pistinhyökkäyksen
vihollista vastaan.

Sitten hän taas oli ylhäällä. Tuskin hän oli sinne päässyt, kun jo
kuului kovaa töminää, johon yhtyi raikkaita hurraa-huutoja, ja tuolla
jo italialaisten ratsumiesten kaksihuippuiset lakit näkyivät savupilvien
läpi. Heitä oli koko eskadroona, joka kiiti täyttä laukkaa, ja miekat,
jotka välähtelivät ilmassa, iskivät suhinalla vihollisten päihin,
hartioihin ja selkiin. Nyt ryntäsi myöskin tuo pieni joukko pistimet
ojennettuina ovesta ulos. Viholliset horjuivat, joutuivat
epäjärjestykseen ja pötkivät pakoon.

Koko tanner ja tuo pieni talo oli vihollisista vapaa, ja kohta sen
jälkeen asetettiin kukkulalle kaksi pataljoonaa italialaista jalkaväkeä
ja kaksi tykkiä.

Kapteeni palasi jäljellejääneiden sotilaittensa kanssa rykmenttiinsä,


taisteli vielä sielläkin, mutta sai viimeisessä hyökkäyksessä haavan
vasempaan käteensä. Päivä päättyi meikäläisten voitolla.

You might also like