Begin to Code with JavaScript 1st Edition Miles download
Begin to Code with JavaScript 1st Edition Miles download
pdf download
https://textbookfull.com/product/begin-to-code-with-
javascript-1st-edition-miles/
https://textbookfull.com/product/begin-to-code-with-python-rob-
miles/
https://textbookfull.com/product/source-code-analytics-with-
roslyn-and-javascript-data-visualization-mukherjee/
https://textbookfull.com/product/reactive-programming-with-
rxjs-5-untangle-your-asynchronous-javascript-code-1st-edition-
sergi-mansilla/
https://textbookfull.com/product/refactoring-javascript-turning-
bad-code-into-good-code-first-edition-burchard/
MASTERING JAVASCRIPT DESIGN PATTERNS create scalable
and reliable applications with advanced Javascript
design patterns using reliable code 3rd Edition Tomas
Corral Cosas
https://textbookfull.com/product/mastering-javascript-design-
patterns-create-scalable-and-reliable-applications-with-advanced-
javascript-design-patterns-using-reliable-code-3rd-edition-tomas-
corral-cosas/
https://textbookfull.com/product/models-to-code-with-no-
mysterious-gaps-1st-edition-leon-starr/
https://textbookfull.com/product/beginning-functional-javascript-
functional-programming-with-javascript-using-ecmascript-6-1st-
edition-anto-aravinth/
https://textbookfull.com/product/simplifying-javascript-writing-
modern-javascript-with-es5-es6-and-beyond-1st-edition-joe-morgan/
https://textbookfull.com/product/beginning-functional-javascript-
functional-programming-with-javascript-using-ecmascript-6-1st-
edition-anto-aravinth-2/
Begin to Code with JavaScript
Rob Miles
BEGIN TO CODE WITH JAVASCRIPT
No patent liability is assumed with respect to the use of the information contained
herein. Although every precaution has been taken in the preparation of this book,
the publisher and author assume no responsibility for errors or omissions. Nor is
any liability assumed for damages resulting from the use of the information
contained herein.
ISBN-13: 978-0-13-687072-2
ISBN-10: 0-13-687072-4
ScoutAutomatedPrintCode
TRADEMARKS
Every effort has been made to make this book as complete and as accurate as
possible, but no warranty or fitness is implied. The information provided is on an
“as is” basis. The author, the publisher, and Microsoft Corporation shall have
neither liability nor responsibility to any person or entity with respect to any loss
or damages arising from the information contained in this book or from the use
of the programs accompanying it.
SPECIAL SALES
For information about buying this title in bulk quantities, or for special sales
opportunities (which may include electronic versions; custom cover designs; and
content particular to your business, training goals, marketing focus, or branding
interests), please contact our corporate sales department at
corpsales@pearsoned.com or (800) 382-3419.
Editor-in-Chief
Brett Bartow
Executive Editor
Loretta Yates
Development Editor
Rick Kughen
Sponsoring Editor
Charvi Arora
Managing Editor
Sandra Schroeder
Tracey Croom
Copy Editor
Rick Kughen
Indexer
James Minken
Proofreader
Scout Festa
Technical Editor
John E. Ray
Editorial Assistant
Cindy Teeters
Cover Designer
Compositor
Danielle Foster
Graphics
Danielle Foster
To Imogen
About the author
Chapter 9 Objects
Introduction
1 Running JavaScript
What is JavaScript?
JavaScript origins
Tools
Getting Git
What is HTML?
Display symbols
Create headings
Using a button
Egg timer
Text alignment
Cascading styles
Variables in programs
JavaScript identifiers
Performing calculations
Making applications
Adding comments
Global variables
Boolean thinking
Boolean expressions
Logical operators
The if construction
App development
7 Creating functions
Arrays of arguments
8 Storing data
Collections of data
Creating an array
9 Objects
Prototype HTML
Prototype JavaScript
Storing contact details
Finding contacts
Displaying contacts
Saving a contact
Finding a contact
Catching exceptions
Class design
Object-oriented design
Data storage
11 Creating applications
Data analysis
Node.js
12 Creating games
Canvas coordinates
Computer art
Animate images
Control gameplay
Window events
Control object position with a keyboard
Game sprites
Add sound
Adding scores
Programming is the most creative thing you can learn how to do. Why? If
you learn to paint, you can create pictures. If you learn to play the violin,
you can make music, but if you learn to program, you can create entirely
new experiences (and you can make pictures and music, too, if you want).
Once you’ve started on the programming path, there’s no limit to where
you can go. There are always new devices, technologies, and
marketplaces where you can use your programming skills.
But first, a word of warning: I would not say that learning to write
programs is easy. This is for two reasons:
If I tell you that it’s easy, and you still can’t do it, you might feel bad about
this (and rather cross with me).
If I tell you it’s easy and you manage to do it, you might think that it isn’t
worth doing.
Learning to program is not easy. It’s a kind of difficult that you might not
have seen before. Programming is all about detail and sequencing. You
must learn how the computer does things and how to express what you
want it to do.
Imagine that you were lucky enough to be able to afford your own
personal chef. At the start, you would have to explain things like, “If it is
sunny outside, I like orange juice and a grapefruit for breakfast, but if it is
raining, I’d like a bowl of porridge and a big mug of coffee.” Occasionally,
your chef would make mistakes. Perhaps you would get a black coffee
rather than the latte that you wanted. However, over time, you would add
more detail to your instructions until your chef knew exactly what to do.
A computer is like a chef who doesn’t even know how to cook. Rather
than saying “make me a coffee,” you would have to say, “Take the brown
powder from the coffee bag and add it to hot water.” Then you would
have to explain how to make hot water and how you must be careful with
the kettle and so on. This is hard work.
It turns out that the key to success as a programmer is much the same as
for many other endeavors. To become a world-renowned violin player,
you will have to practice a lot. The same is true for programming. You
must spend a lot of time working on your programs to acquire code-
writing skills. However, the good news is that just as a violin player really
enjoys making the instrument sing, making a computer do exactly what
you want turns out to be a very rewarding experience. It gets even more
enjoyable when you see other people using programs that you’ve written
and finding them useful and fun to use.
I’ve organized this book in three parts. Each part builds on the previous
one with the aim of turning you into a successful programmer. We start
off discovering the environment in which JavaScript programs run. Then
we learn the fundamentals of programming and we finish by making
some properly useful (and fun) programs.
Part 2 describes the features of the JavaScript that you use to create
programs that work on data. You will pick up some fundamental
programming skills that apply to a wide range of other languages and
that get you thinking about what it is that programs actually do. You’ll
find out how to break large programs into smaller elements and how you
can create custom data types that reflect the specific problem being
solved.
Now that you can make JavaScript programs, it’s time to have some fun
with them. You’ll discover how to create good-looking applications, learn
how to make programs that are secure and reliable, and finish off with a
bit of game development.
In each chapter, I will tell you a bit more about programming. I’ll show
you how to do something, and then I’ll invite you to make something of
your own by using what you’ve learned. You’ll never be more than a page
or so away from doing something or making something unique and
personal. After that, it’s up to you to make something amazing!
You can read the book straight through if you like, but you’ll learn much
more if you slow down and work with the practical parts along the way.
Like learning to ride a bicycle, you’ll learn by doing. You must put in the
time and practice to learn how to do it. But this book will give you the
knowledge and confidence to try your hand at programming, and it will
also be around to help you if your programming doesn’t turn out as you
expected. Here are some elements in the book that will help you learn by
doing:
Yes, the best way to learn things is by doing, so you’ll find “Make
Something Happen” elements throughout the text. These elements offer
ways for you to practice your programming skills. Each starts with an
example and then introduces some steps you can try on your own.
Everything you create will run on Windows, macOS, or Linux.
CODE ANALYSIS
If you don’t already know that programs can fail, you’ll learn this hard
lesson soon after you begin writing your first program. To help you deal
with this in advance, I’ve included “What Could Go Wrong” elements,
which anticipate problems you might have and provide solutions to those
problems. For example, when I introduce something new, I’ll sometimes
spend some time considering how it can fail and what you need to worry
about when you use the new feature.
PROGRAMMER’S POINTS
I’ve spent a lot of time teaching programming, but I’ve also written many
programs and sold a few to paying customers. I’ve learned some things
the hard way that I really wish I’d known at the start. The aim of
“Programmer’s Points” is to give you this information up front so that you
can start taking a professional view of software development as you learn
how to do it.
You’ll need a computer and some software to work with the programs in
this book. I’m afraid I can’t provide you with a computer, but in the first
chapter, you’ll find out how you can get started with nothing more than a
computer and a web browser. Later, you’ll discover how to use the Visual
Studio Code editor to create JavaScript programs.
Using a PC or laptop
You can use Windows, macOS, or Linux to create and run the programs in
the text. Your PC doesn’t have to be particularly powerful, but these are
the minimum specifications I’d recommend:
Using a Raspberry Pi
If you want to get started in the most inexpensive way possible, you can
use a Raspberry Pi running the Raspbian operating system. This has a
Chromium-compatible browser and is also capable of running Visual
Studio Code.
Downloads
In every chapter in this book, I’ll demonstrate and explain programs that
teach you how to begin to program—and you can then use that code to
create programs of your own. I’ve made a few video walkthroughs for
some crucial tasks. The book text will contain screenshots that you can
use, but these can go out of date. Follow the links to the walkthroughs to
get the latest steps to follow. You can download the book’s sample code
and video walkthroughs from the following page:
MicrosoftPressStore.com/BeginCodeJavaScript/downloads
www.begintocodewithjavascript.com
Video walkthroughs
https://bit.ly/3wEn6zX
Acknowledgments
Thanks to Mary for the cups of tea and Immy for the distraction.
We’ve made every effort to ensure the accuracy of this book and its
companion content. You can access updates to this book—in the form of a
list of submitted errata and their related corrections—at
MicrosoftPressStore.com/BeginCodeJavaScript/errata
http://www.MicrosoftPressStore.com/Support
Please note that product support for Microsoft software and hardware is
not offered through the previous addresses. For help with Microsoft
Random documents with unrelated
content Scribd suggests to you:
these often close their petals on the Fig. 277.—Expanded
approach of night, thus protecting their Spikelet of the Oat
pollen during the period in which their G. glumes; P.e, outer
fertilisers sleep. Others, fertilised by pale; P.i, inner pale; A,
nocturnal insects, always spread their awn; F.S, a sterile flower.
The stamens and the
petals during the night, and generally feathery stigmas of the
protect their pollen from waste by fertile flower are also
sleeping throughout the day. As a rule, shown
too, these night-bloomers have large and
pale-coloured petals that are more easily seen by night; they also
evolve a powerful scent to aid the insects in searching them out.
It will be seen that the economic relationship existing between
flowers and insects is a mutual one, the latter visiting the former in
order to obtain food, while the former derive in return the advantage
of a direct transfer of pollen from flower to flower.
It is a well-known fact that the self-fertilisation of a flower often
results in the development of very weak seedlings as compared with
those that are produced by crossing; and it often happens that the
pollen of a flower is incapable of producing the least effect when
deposited on the stigma of the same bloom. In some cases the
contact of the pollen of a flower with its own stigma will even act as a
poison, causing the whole to shrivel and die; and truly wonderful are
the varied means by which flowers contrive to secure a cross-
fertilisation. It is here that the work of the wind and insects proves so
valuable to flowers; but, in addition to this, a very large number of
flowers are absolutely incapable of self-fertilisation, for the anthers
and the stigma are not mature at the same time, or they exist in
separate flowers, either on the same plant or on distinct plants of the
same species. It is most interesting and instructive to study the many
contrivances by which flowers compel certain insects to convey the
pollen exactly in the way that best serves their purpose, sometimes
even entrapping them after they have been allured, and not allowing
them to escape until they are thoroughly dusted with the pollen which
they are required to convey; but it is hardly our province to enter
more fully into this matter in these pages.
An examination of the grasses will show at once that they are
adapted for fertilisation by the wind. The flowers produce no nectar;
and, consistently, develop no bright petals and evolve no odours to
attract insects. On the other hand, their anthers produce abundance
of lightly-adhering pollen, and are mounted on long filaments which
hold them well exposed to the wind; and the stigmas are well
adapted for catching the scattered grains, being long and protruding,
and often covered with sticky hairy or feathery appendages.
Although the flowers of grasses are generally wanting in attractive
colours, the clusters of blossoms are often very graceful and pretty,
especially when the large anthers, covered with bright-yellow pollen,
dangle in the breeze.
We will now briefly describe the principal British grasses that grow
chiefly or exclusively in the immediate neighbourhood of the sea.
The Sea Hard Grass (Lepturus filiformis) is a perennial species, usually
about six inches in height, very common on some sandy coasts, and
found in flower during the hottest months of the summer. The flowers
are arranged in simple spikes, on slender erect stems; and the
glumes, which are united at their bases, enclose a single bloom.
In similar situations we may find the Sea Lyme Grass (Elymus
arenarius), a tall species, often reaching a height of four feet, with
glaucous rigid leaves. The flowers are arranged in a simple spike, but
the spikelets are clustered two or three together. This species flowers
in August.
Of the well-known Barley Grasses there is one species (Hordeum
maritimum) that has its habitat along the coast. Like the others of its
genus, the spikelets are arranged in threes, each bearing a single
flower, and the pales have long slender processes (awns) which
constitute the so-called beard. It also resembles the common Meadow
Barley Grass in having the middle flower of each three perfect, while
the two laterals are abortive, but may be distinguished by its rough
and bristly glumes, and the semi-oval form of the pales of the lateral
flowers. It is a somewhat stunted species, sometimes only five or six
inches in height, and may be found in flower about Midsummer.
The Brome Grasses have also a representative of a sea-loving nature,
which is to be found in fields near the cliffs. It is the Field Brome
Grass (Bromus arvensis), an annual grass that grows to a height of
two or three feet. Brome grasses generally are known by their loose
panicles of flowers, lanceolate and compressed spikelets, and awned
florets enclosed in unequal glumes; and B. arvensis may be
distinguished by its hairy leaves and stem-sheath, and the drooping
panicle with the lower peduncle branched.
Among the Meadow Grasses we have three
or four coast species. In these the florets are
in panicles and are not awned. The outer
glumes are keeled and traversed by several
veins; and the lower pales are also keeled,
with five or more nerves. The Sea Meadow
Grass (Poa maritima) grows in salt marshes
near the sea, its erect rigid panicles reaching
a height of about eight or ten inches. It has a
creeping root, and its leaves are curved
inward at the margins. The Procumbent
Meadow Grass (P. procumbens) and a variety
of the Reflexed Meadow Grass (P. distans)
are also plentiful in salt marshes. The former
may be known by the short rigid branches of
its panicle and the five ribs of the lower
pales; and the latter is much like P. maritima, Fig. 278.—The Sea Lyme
but grows taller, and its spikelets are Grass
crowded. The Wheat Meadow Grass (P.
loliacea) grows on sandy shores. Its spikelets are arranged singly and
alternately along the central axis, and the upper glume reaches to the
base of the fourth floret. This species flowers in June, but the other
three of the same genus bloom from July to September.
The reader is probably acquainted with the Fescue Grass, with its
awned flowers arranged in one-sided panicles. There are no less than
seven species, one of which—the Single-husked Fescue (Festuca
uniglumis)—grows on sandy shores, flowering in June and July, and
reaching a height of from nine to twelve inches. The panicles are
upright and unbranched, and the species may be readily known by
the flowers, which are compressed, with long awns, and with the
lower glumes wanting.
Knappia agrostidea is a dwarf species, rarely exceeding four inches in
height, that is found on certain sandy shores, but is very local. Its
flowers are arranged in a simple spike, the spikelets being solitary and
unilateral, with only a single flower, and the pales are shaggy. The
plant has several stems which bear short, rough leaves.
The Mat Grass or Sea Reed (Ammophila arundinacea) is common on
many sandy coasts, where it grows to a height of three or four feet,
and flowers in July. The white flowers are clustered in dense
cylindrical, pointed spikes; and the leaves are of a glaucous green
colour, rigid, and curved inward at the edges.
Dog’s-tooth Grass (Cynodon dactylon). This species has a creeping
root, and the leaves are downy on the under side. The flowers are
arranged in a compound spreading spike, of three to five parts, and
the spikelets are of a purplish colour, ovate in form, and arranged in
pairs. The glumes are equal in size. It is found on sandy shores,
grows to a height of about six inches, and flowers in July.
A species of Canary Grass (Phalaris arundinacea) is also to be seen on
sandy coasts. Unlike the other species of the same genus, its flowers
form an erect spreading panicle, and the glumes are not keeled. It is
also taller than the common canary grass of waste places, often
reaching a height of three feet, and is commonly known as the Reed
Canary Grass.
Fig. 279.—Knappia Fig. 280.—The Dog’s-Fig. 281.—The Reed
agrostidea tooth Grass Canary Grass
Some of the so-called rushes belong to the same order as the sedges,
and a few of these are more or less restricted to the neighbourhood
of the sea. The Salt-marsh Club Rush (Scirpus maritimus), as its name
implies, is to be found in marshes near the sea. It is very variable in
height, ranging from one to three feet, and displays its dense terminal
cluster of spikelets in July and August. In this genus all the flowers
are perfect, the glumes imbricated and bristled; and the present
species may be distinguished by the glumes being divided into two
sharply pointed lobes. A variety of S. lacustris may also be found on
the sea shore, but it is somewhat rare. It has a leafless glaucous
stem, and flowers arranged in compound spikes. The glumes are
rough, and contain a compressed fruit.
A very small species of the Spike Rush (Eleocharis parvula), growing
only one or two inches high, is sometimes found on the muddy shores
of Ireland. It has perfect flowers, in a single terminal spikelet. The
leaves are very narrow, growing from the base of the plant; and the
round stem is enclosed in a single leafless sheath.
The true rushes belong to the order Juncaceæ. These have fibrous
roots and narrow leaves, and bear clusters of brown flowers. The
perianth consists of six parts, and the stamens are usually six in
number. The ovary is generally three-celled, developing into a three-
valved capsule. The Lesser Sea Rush (Juncus maritimus) is common
in salt marshes, growing to a height of two or three feet, and
flowering in July. It has a rigid leafless stem, bearing lateral clusters
of flowers. The segments of the perianth are very narrow and sharp,
and the seeds are enclosed in a loose testa. Closely allied to this
species is the Great Sea Rush (J. acutus), which grows three or four
feet high on sandy shores. In general characteristics it resembles J.
maritimus, but the segments of the perianth are oval and have thin
transparent margins; and it is a much rarer species.
Fig. 283.—The Sea Fig. 284.—The Curved Fig. 285.—The Great
Sedge Sedge Sea Rush
Fig. 286.—The
Broad-leaved Grass Fig. 287.—The Sea-side Fig. 288.—The Common
Whack Arrow Grass Asparagus
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com