Download Complete Programming for Absolute Beginners: Using the JavaScript Programming Language 1st Edition Jonathan Bartlett PDF for All Chapters
Download Complete Programming for Absolute Beginners: Using the JavaScript Programming Language 1st Edition Jonathan Bartlett PDF for All Chapters
https://ebookmass.com
https://ebookmass.com/product/programming-for-
absolute-beginners-using-the-javascript-
programming-language-1st-edition-jonathan-
bartlett/
https://ebookmass.com/product/the-awk-programming-language-2nd-
edition-aho/
testbankdeal.com
C Programming Absolute Beginner’s Guide (3rd Edition)
Perry
https://ebookmass.com/product/c-programming-absolute-beginners-
guide-3rd-edition-perry/
testbankdeal.com
https://ebookmass.com/product/go-programming-language-for-dummies-1st-
edition-wei-meng-lee/
testbankdeal.com
https://ebookmass.com/product/c-programming-for-beginners-by-sett-
john-hafeez-abdulmutolib/
testbankdeal.com
https://ebookmass.com/product/c-programming-language-c-programming-
lang-_p2-2nd-edition-ebook-pdf/
testbankdeal.com
Programming for
Absolute Beginners
Using the JavaScript
Programming Language
Jonathan Bartlett
Programming for Absolute Beginners: Using the JavaScript Programming Language
Jonathan Bartlett
Tulsa, OK, USA
—Linus Torvalds
Table of Contents
About the Author����������������������������������������������������������������������������������������������������� xi
Acknowledgments���������������������������������������������������������������������������������������������������xv
Chapter 1: Introduction�������������������������������������������������������������������������������������������� 1
1.1 What You Will Learn����������������������������������������������������������������������������������������������������������������� 1
1.2 How to Use This Book������������������������������������������������������������������������������������������������������������� 3
1.3 For Younger Programmers������������������������������������������������������������������������������������������������������ 4
v
Table of Contents
vii
Table of Contents
Chapter 11: Grouping Values Together with Objects and Arrays�������������������������� 145
11.1 A Basic Introduction to Objects����������������������������������������������������������������������������������������� 146
11.2 Simplifying Object Creation����������������������������������������������������������������������������������������������� 149
11.3 Storing Sequences of Values Using Arrays����������������������������������������������������������������������� 150
11.4 Using Arrays in Programs�������������������������������������������������������������������������������������������������� 151
11.5 Mixing Objects and Arrays������������������������������������������������������������������������������������������������ 154
11.6 Object Methods����������������������������������������������������������������������������������������������������������������� 156
11.6.1 Review���������������������������������������������������������������������������������������������������������������������� 159
11.6.2 Apply What You Have Learned���������������������������������������������������������������������������������� 160
viii
Table of Contents
ix
Visit https://ebookmass.com
now to explore a rich
collection of eBooks and enjoy
exciting offers!
Table of Contents
Index��������������������������������������������������������������������������������������������������������������������� 323
x
About the Author
Jonathan Bartlett is a software developer, researcher, and
writer. His first book, Programming from the Ground Up, has
been required reading in computer science programs from
DeVry to Princeton. He has been the sole or lead author for
eight books on topics ranging from computer programming
to calculus. He is a senior software developer for McElroy
Manufacturing, spearheading projects in web, mobile, and
embedded software. He is now the author of several Apress
books including Electronics for Beginners and more.
xi
About the Technical Reviewer
Germán González-Morris is a polyglot software architect/engineer with more than 20
years in the field, with knowledge in Java(EE), Spring, Haskell, C, Python, and JavaScript,
among others. He works with web-distributed applications. Germán loves math
puzzles (including reading Knuth) and swimming. He has tech-reviewed several books,
including an application container book (Weblogic), as well as titles covering various
programming languages (Haskell, Typescript, WebAssembly, Math for coders, and
regexp). You can find more details at his blog site (https://devwebcl.blogspot.com/)
or Twitter account (@devwebcl).
xiii
Acknowledgments
I want to take a moment and thank everyone who helped me write this book. First, I want
to thank those who read and appreciated my first programming book, Programming
from the Ground Up. The encouragement I received from that book has given me the
encouragement to continue writing and educating throughout the years.
Next, I want to thank my homeschool summer co-op class for being guinea pigs
for this material. Your questions, your successes, and your difficulties all informed the
writing of this book. You were both my motivation to write in the first place and the first
proving ground for the material.
I would also like to thank my family, my friends, and my church, all of whom are
essential parts of my life. Thanks especially to my wife who puts up with me when I am
too focused on my writing to notice what the kids have been up to or to put a stop to
whatever trouble they have found themselves in!
xv
CHAPTER 1
Introduction
The modern world is filled with computers. Computers run our phones, our cars, and
even our refrigerators. Computers manage our businesses, our calendars, and our social
lives. With the world relying on computers for so many functions, it is important to know
how these devices work. Even if you never need to program a computer yourself, chances
are that, at some point in your life, you will be involved with software development.
You may be an accountant who needs to tell a computer programmer how you want
your purchasing system set up. You may be an engineer who needs to describe your
engineering process so that a programmer can automate it. In all such tasks as these, it
is important to know something about how computers are programmed, even if you are
not personally writing the software.
1
© Jonathan Bartlett 2023
J. Bartlett, Programming for Absolute Beginners, https://doi.org/10.1007/978-1-4842-8751-4_1
Chapter 1 Introduction
hired people for my development team who already knew the programming language
that my team uses. If someone learns one programming language and practices until
they are good at it, then the effort to learn a new language is fairly minimal.
You may wonder why, if the languages are so similar, there are so many
programming languages to choose from. The fact is, when engineering anything, trade-
offs have to be made. Sometimes in order to make one type of task easier, another type
of task has to be made harder. In my kitchen I have both a mixer and a blender. Both of
them operate on the same basic principles—you put food into the main container area,
an electric motor turns, and some attachment combines the food together. While these
tasks are very similar and operate on the same principles, there are many types of food
in the world and many ways that they need to be mixed, such that the mixer works better
for some tasks and the blender for others. Similarly, with programming languages, some
of them are better suited to different tasks. Also, the choice of programming language
is dependent on the programmer. Just as different types of cars suit the preferences and
tendencies of different types of drivers, so do different programming languages suit the
preferences and tendencies of different types of programmers. Because of these reasons,
there are numerous programming languages available for nearly any task you might
want to perform.
The programming language covered in this book is called JavaScript. I like to teach
JavaScript as a first language for several reasons. First of all, JavaScript was developed
to be a first language. One of the goals of the language was to make it easy for new
programmers to get started quickly. Even though JavaScript was designed to make
programming easier for new programmers, it is not any less powerful as a language.
Second, JavaScript has become the de facto programming language for website
interfaces. If you use a website that does anything besides link to other web pages,
JavaScript is probably involved. Therefore, learning JavaScript will have immediate
practical benefits in learning how the Web operates. Third, the tools for programming
JavaScript are available on every computer. You don’t need to download any special tools
to program JavaScript. If you have a computer with a web browser, you can program
JavaScript! Finally, JavaScript is very similar to other popular programming languages
such as C#, Java, and Swift. Therefore, knowing JavaScript will not only be immediately
beneficial for programming websites, it is also a language that makes it easy to transition
to other popular systems.
This book is for the first-time programmer. No prior programming experience is
assumed. This book does assume that you have a basic understanding of how to use your
computer and browse the Internet. That is all that you need!
2
Chapter 1 Introduction
You will learn not only the basics of computer programming but also a more general
knowledge of how computers and data work. You will learn where computers came
from, how they work, how computers work with data, how data is transmitted, and how
web pages work. This book will not go in-depth in all of these subjects, but it will give
you a basic working framework that will help you better understand ideas that you may
encounter elsewhere.
When discussing smaller pieces of code within a paragraph, code that is under
discussion will look like this.
Now, there are many different types of computers, each with different operating
systems and software loaded on them, with each of those having different versions.
There are also numerous different web browsers, each with different features available
and slightly different ways of working. This book attempts to walk you through setting
everything up on each operating system. If there is anything in this book that depends
on the specific operating system or browser that you are using, Appendix B has the steps
for several different systems, including Windows and Mac operating systems. This book
will refer you to the appropriate section of the Appendix when needed. Though this
book works with any modern web browser (basically anything released after 2008), I
recommend that you use Google Chrome. As of the time of this writing, Google Chrome
is the easiest browser to work with as a programmer. That being said, you should be just
fine with any web browser, including Brave, Firefox, Safari, Chrome, Opera, or Edge.
3
Chapter 1 Introduction
This book contains several practice questions and practice activities. The goal of
these questions and activities is to provide you with a hands-on way of understanding
the material. By doing the questions and activities, the text will become much more
meaningful and understandable. More importantly, they might show you the places
where you did not fully understand the text. Many people have a tendency to skip over
things if they don’t understand them well. Practice questions and activities give you a
chance to slow down and make sure you know which parts you understood and which
parts you need to read again and spend time thinking about. Practice questions build
on each other, so by doing them all in the order given, you can see exactly where you are
having problems.
At the end of every chapter is a review section which covers the most important
concepts of each chapter. After that is a section to help you practice applying your
knowledge to problems. These questions require you to further engage your brain and
really think about what you learned in that chapter and what it means.
Appendix A contains an extended glossary of terms used in this book, plus others
you are likely to encounter when reading about programming. This chapter will help you
find your bearings as you read and talk with other people about programming. I would
suggest that, concurrent with your readings, you also take the time to look through the
glossary for words that you may have heard but did not understand at the time.
Also, if you run into problems when writing code, Section B.6 has several suggestions
for getting you back on the right track.
4
CHAPTER 2
A Short History
of Computers
The history of computers is weird and wonderful. What started as an abstract
philosophical quest ended up setting the course for society for over a century and
continues to be one of the most profound parts of modern life. The goal of this chapter is
to trace an outline of where computing started, where it has been, and where it is now.
7
© Jonathan Bartlett 2023
J. Bartlett, Programming for Absolute Beginners, https://doi.org/10.1007/978-1-4842-8751-4_2
Visit https://ebookmass.com
now to explore a rich
collection of eBooks and enjoy
exciting offers!
Chapter 2 A Short History of Computers
to being near streams but could now go anywhere, since the power could be generated
from fire and stored water. Eventually this even allowed the creation of trains, since the
power could move with the vehicle.
The other invention of the industrial revolution was interchangeable parts.
This allowed a standardization and maintenance of equipment that was previously
unattainable. Instead of having each part be a unique piece, the parts became
standardized which allowed for the machines to become more specialized. It is one
of the more curious paradoxes of technology that as the pieces of technology become
less unique, the more advanced and unique the systems created from those parts can
become. Standardization allows for users of technology to stop having to think about all
of the low-level decisions and focus on the larger, more meaningful decisions. This also
allows for better communication about systems, because the parts can be more readily
described. If I can give you a schematic that lists premade parts, it is much easier to
design and communicate that design than if I also had to describe how each individual
part was supposed to be made.
So the introduction of available powered machinery and standardized parts in the
industrial revolution led to an explosion of specialized machines. We then had machines
to perform any number of tasks that a person could want to do. The next step was the
introduction of machines which were directed not by people directly controlling the
machine but by coded instructions. The earliest of these machines was the Jacquard
Loom, which used punched cards to signify a pattern woven into a fabric. The cards had
punched holes to signify to the machine the raising or lowering of the particular thread
causing it to be visible or hidden in the pattern. Thus, the loom could be programmed
to make a pattern by specifying at each point whether each thread should be raised or
lowered.
Later inventions applied this concept to mathematics. Calculating machines had
been around for a long time, with Blaise Pascal’s mechanical calculator having been
invented in the mid-1600s. However, this required the power of physical manipulation
to actually accomplish the addition. Most mathematical tasks are not single-step like
addition but require a process of several steps, sometimes repeating steps, before finding
an answer. Charles Babbage invented a more advanced machine to perform navigational
calculations. In this machine, the user entered the input, and then the machine used
that input to run a series of steps which eventually yielded results. Babbage eventually
designed a machine that could take a list of arbitrary instructions much like a modern
computer, but he was never able to build that design.
8
Chapter 2 A Short History of Computers
Once humans had the ability to power a machine, create a machine that operated
on external instructions, and use those instructions to perform mathematical functions,
they had all of the pieces in place to create a computer. However, the revolution that
brought about computing took place not from an invention, but from a problem in
philosophy.
9
Random documents with unrelated
content Scribd suggests to you:
inspiration; a quintet by Ernst von Dohnányi. Sgambati has written a
quintet without distinction. Mr. Dunhill tells us in his book[83] on
chamber music that there is an excellent quintet by a young British
composer, James Friskin. Moreover the sextet for piano and strings
by Joseph Holbrooke, in which a double bass is added to the
quartet, deserves mention. And among American composers Arthur
Foote and George Chadwick should be mentioned, the one for his
quintet in A minor, opus 38, the other for his quintet in E-flat major,
without opus number.
Only a few piano quartets have been written since those of Brahms
and Dvořák which are significant of any development or even of a
freshness of life. Those of Fauré have already been mentioned as
being perfect in style, but on the whole they seem less original and
less interesting than the quintet by the same composer. Saint-Saëns’
quartet, opus 41, is remarkable for the brilliant treatment of the
pianoforte, and the fine sense of instrumental style which it reveals,
but is on the whole uninteresting and is certainly insignificant
compared with the quartets of Fauré or those of d’Indy and
Chausson. D’Indy’s quartet, opus 7, in A minor is no longer a new
work, nor does it show in any striking way those qualities in French
music which have more recently come to splendid blooming. But it is
carefully wrought and the three movements are moderately
interesting. The second is perhaps the best music, the third is
certainly the most spirited. There is more of the manner though
perhaps less of the spirit of César Franck in Chausson’s quartet in A
major, opus 30.
III
As to sonatas, those for violin and piano are treated elsewhere.
There are too many to be discussed in this chapter. There are fewer
for the cello and the best of these may here be mentioned. Skill in
playing the violoncello was slower to develop than that in playing the
violin. This was probably because the viola da gamba with its six
strings was easier to play and was more in favor as a solo
instrument. The baryton was a kind of viola da gamba with
sympathetic strings stretched under the fingerboard, and even as
late as the maturity of Haydn this instrument was in general favor.
But the tone of the viola da gamba was lighter than that of the
violoncello, and so by the beginning of the eighteenth century the
cello was preferred to the gamba for the bass parts of works like
Corelli’s in concerted style. Little by little it rose into prominence from
this humble position. Meanwhile the immortal suites for the
violoncello alone by Bach had been written. Bach was probably
advised in the handling of the instrument by Abel, who was a famous
gamba player; so that it seems likely that these suites were
conceived for the gamba as much as for the cello.[84] The last of
them, however, was written especially for the viola pomposa, an
instrument which Bach invented himself. This was a small cello with
an extra string tuned to E, a fifth above the A of the cello.
Among composers who wrote expressly for the cello were Giorgio
Antoniotti, who lived in Milan about 1740, and Lanzetti, who was
'cellist to the king of Sardinia between 1730 and 1750. Later the
Italians A. Canavasso and Carlo Ferrari (b. 1730) became famous as
players, and Boccherini also was a brilliant cellist.
Beethoven wrote five sonatas for cello and piano. The first two, opus
5, were written in 1796, while Beethoven was staying in Berlin,
evidently with the intention of dedicating them to Frederick William II,
and for his own appearance in public with Duport. They are
noticeably finer, or more expressive works, than the early sonatas for
violin, opus 12; perhaps because the cello does not suggest a style
which, empty of meaning, is yet beautiful and effective by reason of
sheer brilliance. The violin sonatas, all of them except the last, are
largely virtuoso music. The cello sonatas are more serious and on
the whole more sober. This may be laid to thoroughly practical
reasons. The cello has not the variety of technical possibilities that
the violin has, nor even in such rapid passages as can be played
upon it can it give a brilliant or carrying tone. By reason of its low
register it can be all too easily overpowered by the piano. Only the
high notes on the A string can make themselves heard above a solid
or resonant accompaniment. Hence if the composer desires to write
a brilliant, showy sonata for pianoforte and cello, he can do so only
by sacrificing all but the topmost registers of the cello. Even at that
the piano is more than likely to put the cello wholly in the shade.
The next sonata, opus 69, in A major, was not written until twelve
years later. A different Beethoven speaks in it. The first theme,
announced at once by the cello alone, gives the key to the spirit of
the work. It is gentle (dolce) in character, but full of a quiet and
moving strength. After giving the first phrase of it alone the cello
holds a long low E, over which the piano lightly completes it. There is
a cadenza for piano, and then, after the piano has given the whole
theme once again, there is a short cadenza for cello, leading to a
short transition at the end of which one finds the singing second
theme. This is first given out by the piano over smooth scales by the
cello, and then the cello takes it up and the piano plays the scales.
Nothing could be more exquisite than the combination of these two
instruments in this altogether lovely sonata, which without effort
permits each in turn or together to reveal its most musical qualities.
Sometimes the cello is low and impressive, strong and independent,
while the piano is lively and sparkling, as in the closing parts of the
first section of the first movement. Again the cello has vigorous
rolling figures that bring out the fullest sonority the instrument is
capable of, while the piano adds the theme against such a vibrant
background, with no fear of drowning the cello, as in the first portions
of the development section.
Finally there are two sonatas, opus 102, which are in every way
representative of the Beethoven of the last pianoforte sonatas and
even the last quartets. The first of these—in C major—Beethoven
himself entitled a ‘free sonata,’ and the form is indeed free, recalling
the form of the A major pianoforte sonata, opus 101, upon which
Beethoven was working at the same time. In spirit, too, it is very like
the A major sonata, but lacks the more obvious melodic charm. The
sonata begins with an andante, in that singing yet mystical style
which characterizes so much of Beethoven’s last work, and the
andante does not end but seems to lose itself, to become absorbed
in a mist of trills, out of which there springs a vigorous allegro vivace,
in the dotted march rhythm which one finds in the later pianoforte
sonatas. After this, a short rhapsodical adagio brings us back to a bit
of the opening andante, which once more trills itself away, seems to
be snuffed out, as it were, by a sudden little phrase which, all
unexpected, announces the beginning of the final rondo.
There remains only to mention the sonata by Max Reger, opus 78,
two sonatas by Emanuel Moór, one by Guy Ropartz in G minor, two
by Camille Saint-Saëns, opus 32 and opus 123, as among those
which make a partial success of the extremely difficult combination.
If excellent music for cello and piano is so rare, music for the viola
and piano is almost entirely wanting. The two instruments do not go
well together. Practically the only example of the combination in the
works of the great masters is furnished by Schumann’s
Märchenbilder, which are but indifferent music. York Bowen, an
English composer, has considered it worthy of the sonata, and has
written two for it, one in C minor and one in F major. Mr. Benjamin
Dale has also written some agreeable pieces, including a suite and a
fantasy.
IV
There are relatively few works also in which the piano has been
combined with wind instruments. The wind instruments which have
been most employed in chamber music are the flute, oboe, clarinet,
and bassoon. Occasionally there is a short bit for horn, or for English
horn, and rarely something for trumpet or saxophone. No special
combination of these instruments either by themselves or with the
piano has obtained signal favor, and we may therefore confine
ourselves to mentioning with brief notice the various works of the
great masters in turn. We will include likewise here their chamber
works for wind instruments without pianoforte.
Of Haydn’s works we will only mention the two trios for flute and
violin and the octet for two oboes, two clarinets, two horns and two
bassoons. Most of Mozart’s works for wind instruments bear the
mark of some occasion. There are a great many Serenades and
Divertimenti, which can hardly be called representative of his best
and can hardly be distinguished from each other. Among the
interesting works are the concerto for flute and harp (K 299), the trio
for clarinet, viola and piano (K 498), the quintet for pianoforte, oboe,
clarinet, horn and bassoon (K 452), and the quintet for clarinet and
strings (K 581). The trio was composed in Vienna in August, 1786,
and is conspicuous for a fine handling of the viola. The clarinet is not
used at all in the lower registers, lest it interfere with the viola.
Mozart considered the quintet for piano and wind instruments at the
time he wrote it the best thing he had written. It was composed in
March, 1784, for a public concert and was received with great
applause. Jahn wrote of it that from beginning to end it was a true
triumph in the art of recognizing and adapting the peculiar
euphonious quality of each instrument. Doubtless it served as a
model for Beethoven’s composition in the same form.
The octet, opus 103, the sextet, opus 81, the sextet, opus 71, and
the quintet, opus 16, are all in the key of E-flat major, a key which is
favorable to all wood-wind instruments. The octet was written, as we
have said, in 1792. Beethoven rearranged it as a string quintet and
in that form it was published in 1796 as opus 4. In its original form
the chief rôle is taken by the oboe, especially in the slow second
movement, which has the touch of a pastoral idyl. The last
movement in rondo form offers the clarinets an opportunity in the first
episode. A Rondino for the same combination of instruments written
about the same time seems to forecast parts of Fidelio. The sextet
for two horns and string quartet is little more than a duet for the
horns with a string accompaniment.
We may pass over the trio for two oboes and English horn, published
as opus 87, and the flute duet written for his friend Degenhart on the
night of August 23, 1792. The sextet, opus 71, which Beethoven said
was written in a night, is none the less written with great care. The
prelude introduction and the cheerful style suggest some happy sort
of serenade music. The melody (bassoon) in the adagio is of great
beauty. There are, among its movements, a minuet and a lively
rondo in march rhythm.
The quintet, opus 16, in which the piano is joined with four
instruments may well have been suggested by Mozart’s quintet in
the same form; though Beethoven was a great pianist and had
already in an earlier trio and a sonata experimented in combining the
pianoforte with wind instruments. The wind instruments are here
treated as an independent group and the part for the piano is
brilliant. There is a richness of ideas throughout which raises the
work above the earlier compositions for wind.
The septet in E-flat, opus 20, for clarinet, horn, bassoon, violin, viola,
cello and double-bass, is undoubtedly the finest of Beethoven’s
works for combinations of wind instruments. It was written just before
1800 and was so full of joy and humor that those who had heard
Beethoven’s other works with a hostile ear were quite won over for
the time being by this. Technically it may be considered the result of
all his previous experiments. It is rather in the manner of a suite.
There is a slow prelude, an allegro con brio, an adagio cantabile, a
tempo di menuetto, which he later arranged for pianoforte and
incorporated in the little sonata, opus 49, No. 1, a theme and
variations, a scherzo, and a final presto, which is preceded by an
introductory andante of great beauty and of more seriousness than is
characteristic of the work as a whole. The success of the work is due
first to the freshness of the ideas, then to the skill with which they are
arranged for the difficult combination of instruments. For Beethoven
has made something of charm out of the very shortcomings of the
wind instruments. The short phrases, the straightforward character of
all the themes and motives, and the general simplicity all show these
necessarily restricted instruments at their very best.
Spohr, too, showed a special favor towards the clarinet and he, like
Weber, wrote two concertos for it. Three of Spohr’s works which
were broadly famous in their day and much beloved are the nonet for
strings, flute, oboe, clarinet, horn, and bassoon, opus 31; the octet
for violin, two violas, cello, double-bass, clarinet, and two horns,
opus 32; and the quintet for flute, clarinet, horn, bassoon, and piano.
The two former are delicately scored, but the latter is marred by the
piano. Some idea of the fervor with which Spohr’s music was loved
may be gained from the fact that Chopin, the most selective and
fastidiously critical of all composers, conceived Spohr’s nonet to be
one of the greatest works of music. Doubtless the perfection of style
delighted him, a virtue for which he was willing to forgive many a
weakness. At present Spohr’s music is in danger of being totally
neglected.