* (asterisk) character, 52, 101
(backslash) character, 120, 141
` (backtick) character, 119, 141, 143
+ (plus) operator, 111, 119, 120
; (semicolon) character, 76
{ } (curly braces), 161, 173, 288, 296, 319
[ ] (square brackets), 189, 288, 296, 319
acceleration values, 458
activeGame
object, 442
addEventListener
method, 429
adding machine program, 122, 124–126
addition service, 398, 399–400
alertInputText
ID, 46
alternative text, 39
Andreessen, Marc, 28
anonymous functions
awaits
contained in, 468
simplifying promises using, 383
appendChild
method, 200
applets, 5
applications
fashion shop, 335–363, 368–379
ride selector, 161–172, 178–196
temperature conversion, 130–131
See also programs
arc
drawing method, 417
arguments
arrays of, 221
maximum number of, 238
ordering of, 18
bounds of, 271
counting from zero in, 249
filter
method, 377
investigating and creating, 246–248
reduce
method, 378
storing data in, 246–248, 281–283
arrow functions, 374–375, 376, 402, 405, 463
artificial intelligence (AI), 456–457
artwork
drawing on canvas, 410–413, 419–425
assign
function, 356
assignment operation, 46
asterisk (*) character, 52, 101
asynchronous operations, 380, 420
attract mode for games, 468
attributes
image tag, 38
properties vs., 60
Audacity program, 453
audio
await
keyword, 424–425, 426, 467–468
Azure account, 401
backslash () character, 120, 141
backtick (`) character, 119, 141, 143
bad nesting, 37
Berners-Lee, Tim, 28
binary representation, 104
binding event handlers, 421
block-copy
commands, 342
blocks of statements
for
loop and, 193
blur
event, 435
Boolean values, 146–149, 173, 174
bounds of the array, 271
break
keyword, 171
breakpoints, setting, 262
browsers. See web browsers
bugs
responding to reports of, 181
See also errors
buildElementsFromSchema
method, 358
C# and C++ programming languages, 4, 346
calculations
calling functions, 208, 209, 210–211
camel case, 108
drawing on, 410–413, 419–425, 468
changeArrayElement
function, 267
children
property, 189
constructor
method for, 339–340, 342
inheritance mechanism for, 343–344, 345–347
method members added to, 348–349
object-oriented design and, 341–342
static members of, 352–355, 357
className
property, 180
code
avoiding repeated, 343
building web pages from, 196–201
finding and fixing bugs in, 181–183
importance of well-designed, 183–184
code analysis, xvi
code errors and testing, 109–110
evaluating expressions, 100–102
findContacts
function, 284
floating-point values, 114–115
getNumberFromElement
function, 230–231
if
constructions, 160
JSON, 299
keyboard events, 430–431, 432–433
performing calculations, 112
ticking clock program, 75
whole vs. real numbers, 113
collections
arrays as, 221
collision detection, 455
colors
creating, 418
keyword, 24
comments
adding to programs, 131–133, 141
comparison function, 371–372, 373, 374, 402
computers
art generated by, 414–419, 440
data processing by, 96–97, 140
minimum requirements for, xvii
concat
method, 272
confirm
function, 334
console.log
statement, 192
Console window, 9
constructive laziness, 195
constructor
method
class creation and, 339–340, 342
displaying contacts in, 285
finding contacts in, 283–285, 287, 309–315
JSON for encoding data in, 295–298
property accessors in, 300–304
Super Search feature for, 310–315
user ideas for improving, 310, 316
container
element, 306
control variables, 191
controller function, 422
class definition, 438, 440–441
collision detection, 455
end detection, 464
physics and friction, 457–458, 459
sprites in, 436–438, 443–452, 456–460
start screen added to, 461–462, 463
createElement
method, 199, 255, 380
createListElement
function, 369–370
createListPage
function, 369
createServer
method, 389–390, 395, 404
CSS (Cascading Style Sheets), 82, 85–86, 89, 91
See also style sheets
data
information vs., 103
sorting, 371–373, 376–377, 402
text vs. numeric, 112
adding to HTML elements, 184–185
data processing
data schemas. See schemas
default
selector, 170
defining functions, 208, 209–210, 213
delimiters, 119
designing
systems before building, 305, 341–342
user interface for customers, 162, 252–254
double dice version of, 236
error handling added to, 227–232
random number calculations in, 222–226
disabled
attribute, 385
displayContact
function, 292
displayElementValue
function, 280, 285
displaying
images, 57
displayMessage
function, 462
<div>
element, 84–85, 88, 90, 253
doAddToTotal
function, 136
doBuildPage
function, 305, 306, 307
doBuildSalesInputItems
function, 253–254, 256
doCalc
function, 244–245, 251, 262
doClockTick
function, 74, 76–77
Document Object Model (DOM), 45, 252
documents
deleting elements from, 201–202
HTML formatting of, 41
doGame
function, 441
doMouseOver
function, 66
doSaveAdd
function, 362
doStartFashionShop
function, 360
doStartTimer
function, 52
doStartTinyContacts
function, 298
double quote (") character, 119, 141, 143
doUpdateItem
function, 370
downloads for book, xviii
drawing
on canvas, 410–413, 419–425, 468
functions used in, 52
sound added to, 55
Eich, Brendan, 5
Elements window, 8
emojis, meanings of, 33
encapsulation, 234
end
method, 392
end tags, 32
equality operator, 151, 152, 153, 174
error handling
adding to applications, 227–232
JavaScript promises and, 384
errors
floating-point values and, 114–115
importance of managing, 335
spelling, 110
escape sequences, 120, 141, 143
event handlers, 421
events
attributes of, 87
definition of, 421
exceptions
catching, 327
explanation of, 299, 324, 364–365
JSON use of, 299, 324, 325–326
Express system, 401
expressions
evaluated by JavaScript, 100–102, 111
operators and operands in, 100, 110, 141
processing data with, 100
fashion shop application, 335–363, 368–379
code exploration, 362
data storage solutions, 355–356
menu options, 361
sorting data, 371–372, 376–377
starting the program, 360
store stock data, 339–340, 368–370
suggestions for expanding, 363
faults
responding to reports of, 181
See also errors
fetch
function, 381–382, 403, 404
asynchronous operation for, 380
calling web services and, 399–400
disabling FETCH button after, 384–385
fetchPromise
object, 381
files
finding, 21
saving, 20
fillRect
function, 418
fillText
method, 454
finally
function, 385, 387, 403
findContactPos
function, 283, 284, 285, 286, 287
findContacts
function, 284
finding
files in Visual Studio Code, 21
findStartsWithDataPos
function, 313, 314
firewalls, 391
floating-point numbers, 114–116
equality and, 153
real numbers and, 114
floor
function, 117, 118, 129, 141
fonts
monospaced vs. proportional, 36
findContacts
function and, 284
for-of
loop, 195–196, 204, 221, 259
anonymous, 374
designing with, 228
giving information to, 213
methods distinguished from, 61, 341, 365
multiple parameters in, 218
game engines, 465
gameEnd
method, 464
gameReset
function, 442
gameRun
method, 463
gameRunning
property, 463, 464, 468
games
artificial intelligence in, 456–457
attract mode for, 468
building your own, 465
code analysis for, 438, 440–441
collision detection for, 455
end detection for, 464
fixing problems in, 456
image loading promise for, 421–425
including instructions with, 461
making playable, 465
sprites in, 436–438, 443–452, 456–460
start screen for, 461–462, 463
gameStart
method, 441, 442, 463
gameUpdate
function, 428, 433–435, 442–443, 463
“get” requests, 29
getAttribute
method, 185, 186–187
getDescription
method, 349, 350–352
getElementByID
method, 45–46, 47, 55
getElementValue
function, 281
getHighest
function, 250
getHours
method, 72
getLargestStockRef
method, 353, 354
getLowest
function, 250
getNumberFromElement
function, 226, 229, 230–231, 260, 263
getRandomColor
function, 418
getTotal
function, 250
Gimp program, 419
installing, 14
repositories in, 17
private work on, 24
repositories on, 17
headers
response, 404
heading tags, 35
hierarchy of classes, 345, 347–348
High and Low game, 139
highlighting elements, 269
hover
selector, 87
href
attribute, 41
HTML (Hypertext Markup Language), 12, 27–50
document formatting, 41
heading creation, 35
JavaScript and, 45–48, 58, 199–201
origins and development of, 28
paragraph layout, 34
schema for building, 305–308, 358–359
validator site, 38
web servers and, 396
<html>
tag, 41
HTTP and HTTPS protocols, 28, 29
Node.js platform and, 389–390, 404
server requests vs. responses, 406
stateless description of, 407
ice cream sales program, 242–269
arrays used in, 246–248, 265–268
collections of data in, 242–246
detecting invalid values in, 251–252
finding highest/lowest sales in, 249–251
fixed-width layouts for, 268–269
highlighting elements in, 269
identity operator, 152, 173, 174
if
construction, 158–161, 173, 174
blocks of statements in, 160–161
else
keyword added to, 159–160, 174
Math.random
function used in, 172
images
alternative text for, 39
program for displaying, 57
indexer or subscript, 246
information vs. data, 103
inheritance, 343–344, 345–347, 364
<input>
tag, 44–45, 244, 278, 318
input paragraphs, 254–257, 258
input validation, 175
installing
Git program, 14
Visual Studio Code program, 15–16
Internet of Things (IoT), 97
Internet vs. World Wide Web, 59
isNaN
function, 230
Java programming language, 5, 346
JavaScript
data processing in, 99, 100, 104
evaluating expressions with, 100–102
exceptions thrown by, 324, 364–365
functions and statements in, 43
origins and intention of, 5
programming languages and, 4–5, 6, 23
tools for working with, 13
web browsers and, 6
JPEG file format, 419
JSON (JavaScript Object Notation), 295–299
class hierarchy and, 355
code analysis of using, 299
encoding object data with, 295–298, 317
example of working with, 296–297
exceptions thrown by, 299, 324, 325–326
fetched data and, 382
validator web page, 327
code analysis, 430–431, 432–433
object position control, 431, 432–433
keydown
event, 429–430, 433, 463
keywords, 24
lambda functions, 375
layouts
paragraph, 34
styles vs., 81
length
property, 271
let
keyword, 193, 205, 235–236, 238
letDemo
function, 236
lineTo
method, 412
<link>
element, 81
lists
ordered, 164
unordered, 188
loadDataStore
function, 331–332
investigating the use of, 293–295
localhost address, 391
LocalStorage
object, 293
loops
makeElement
function, 307–308, 315
makeInputPar
function, 254, 255, 256
management
error, 335
local storage, 293
style, 86
manifest
configuration file, 401
Math
class, 354
Math.random
function, 172
measureText
method, 462
menuInput
style, 229
menuInputError
style, 229
menuLabel
style, 269
message
variable, 46
functions distinguished from, 61, 341, 365
overriding in subclasses, 350–352
Microsoft Paint program, 419
Microsoft Press resources, xix
mobile devices, xviii
modules, 389
monospaced font, 36
mouse rollover
rollover
style and, 87
moveTo
method, 412
multiplication table program, 196–203
deleting elements from, 201–202
displaying scores in, 270
ideas to investigate for, 202–203
myCanvas
variable, 411
myContext
variable, 412
names
sorting array of, 373
NaN
value, 11, 125, 141, 142, 148, 230, 231
Nerves of Steel game, 138
Netscape Communications Corporation, 5
networks
JSON data received from, 383
text received from, 384
Node.js program, 387–401, 403–404
installing and testing, 387–388
node package manager, 401, 404
purpose and limitations, 389
server deployment, 401
node package manager (npm), 401, 404
notation
null
value, 299
Number
function, 124, 125, 141, 142, 213
numbers
random, 116–118, 137–139, 222–226
numeric operators, 111
object-oriented design
inheritance mechanism in, 343–344
JSON for encoding data in, 295–298
polymorphism and, 350
position control for, 431
properties of, 50–51, 300, 316–317
references to, 49, 60, 290–291, 299, 317
schema for building, 308
storing data in, 288, 292–293, 295
<ol>
element, 164
onclick
attribute, 43, 225, 236
onerror
event, 421
oninput
function, 313–314, 315
onload
event, 74, 77, 253, 421, 441
onmouseout
event, 67
openPage
function, 361
numeric, 111
ordered lists, 164
overlapping elements, 37
<p>
tag, 34
paragraphs
laying out text in, 34
parameters
functions with multiple, 218
as values, 217
parse
method
JSON strings and, 297, 299, 317, 325–326
paths
defining and drawing, 412
Petzold, Charles, 104
Phasor game engine, 465
physics of games, 457–458, 459
plus (+) operator, 111, 119, 120
PNG file format, 419
polymorphism, 350
Preview image editor, 419
print
function, 12
problem solving, 311
compiled, 23
determining the “best,” 5
programs
audio added to, 55
bugs vs. faults in, 67
comments added to, 131–133, 141
good specifications for, 134
interpreting, 102
user interface for, 162, 163–165
See also applications
Promise.all
method, 422–423, 426
controller function for, 422
explanation of, 381–382, 386, 403, 405
finally
function in, 385
handling errors in, 384
importance of understanding, 427
JSON delivery process, 382
managing multiple, 422–423, 426
simplifying with anonymous functions, 383
text delivery process, 384
waiting for results of, 424–425, 426
properties
attributes vs., 60
explanation of, 300
property identifiers, 303
propertyName
variable, 304
proportional fonts, 36
prototypes
pseudocode, 249
random
function, 116, 117, 118
random numbers, 116–118, 137–139, 222–226, 469
Raspberry Pi computers, xviii
real numbers
floating-point numbers and, 114–116
whole numbers vs., 112–113, 141, 142
recursion, 212
references
array of, 372
game, 440
object, 49, 60, 290–291, 299, 317
property accessors and, 319
stored in JSON strings, 299
relational operators, 152
removeItem
function, 295
repeating code, 343
requestAnimationFrame
method, 427, 429
requests, HTTP, 406
require
function, 389, 401, 403
resetFind
function, 314
resource information, xix
responses
contents of, 404
JavaScript commands and, 10–12
requests vs., 406
result
variable, 125
return
keyword, 222
rgb
function, 418
ride selector program, 161–172
switch
construction in, 168–170, 171
user interface for, 162, 163–165
rollover
style, 87
saving files, 20
scaffolding, 401
data storage created from, 309
designing for applications, 304–305
HTML built from, 305–308, 358–359
objects built from, 308
scores
displaying in programs, 270
searching. See finding
selectors
color highlighting using, 86–87
style sheets using, 80
semicolon (;) character, 76
sendResponse
function, 395
servers
code analysis of using, 390–392
deploying Node.js, 401
process of building, 396
See also web servers
service function, 404
setAttribute
method, 187
setInterval
function, 74, 77, 88, 427
setTimeout
function, 52, 54, 57, 58
setup
element, for
loop, 191
single quote (') character, 119, 141, 143
slide shows, 57
software. See programs
solving problems, 311
sorting data, 371–373, 376–377, 402
sound
source code, 13
source code highlighting, 24
source code management (SCM) software, 14
Source Control dialog, 18
specifications, 134
spelling errors, 110
sprites, 436–438, 443–452, 456–460
friction added to, 458
superclass for, 438
square brackets [ ], 189, 288, 296, 319
src
attribute, 39, 55, 57, 420
start and end tags, 32
start screen for games, 461–462, 463
startsWith
method, 312, 314, 317
statements
alert, 43
assignment, 105
for
loop, 191
static class members, 352–355, 357, 364
status code, 404
stockItemCompare
function, 372–373
storage
arrays used for, 246–248, 281–283
class hierarchy and, 355
schema produced for, 309
storeContact
function, 283, 292
storeData
function, 308
stories, user, 336
stringify
method, 296, 297, 317, 325, 329–330
stringOrderCompare
function, 373
strings of text. See text
<strong>
tag, 32
<style>
tag, 80
style sheets
exploring the use of, 83
See also CSS
conflicting, 89
explanation of, 64
layouts vs., 81
managing, 86
menu label, 269
overriding, 86
text alignment, 71
subclasses
class hierarchy and, 345
extending classes and, 346
inheritance mechanism and, 343–344
overriding methods in, 350–352, 364
template for, 438
problem solving for, 311
solutions for creating, 312–314
superclasses
class hierarchy and, 345
game sprites and, 438
inheritance mechanism and, 343–344
missing breaks in, 171
path for controlling, 394
symbols, HTML display of, 32–33, 58
synchronized actions, 380
TCP/IP protocol, 29
temperature conversion program, 130–131
template, subclass, 438
test
element, for
loop, 191
testing
Node.js, 388
text
alternative, 39
arrays of, 265
combining numbers and, 120–121
converting into numbers, 122–123
delimiters for, 119
emphasizing in HTML, 30
escape sequences for, 120
getting from networks, 384
heading creation, 35
indicating with quotes, 10
paragraph layout, 34
as property accessors, 300–304
text
method, 384
textContent
property, 49, 50–51
Theme Park Ride Selector. See ride selector program
then
method, 381, 382, 384, 386, 403, 405–406
this
keyword, 340, 341, 364, 365, 376, 440, 442–443
threads, 426
throw
statement, 329
code analysis, 75
timeString
variable, 73
Tiny Contacts application. See contacts app
toFixed
method, 130
try-catch
construction, 326, 327, 328, 363, 386–387
Twitter information, xix
two-dimensional arrays, 272
type
attribute, 44
type
property, 356
<ul>
element, 164
undefined
value, 106, 107, 141, 142
unordered lists, 188
update
element, for
loop, 191
update
method, 434, 438, 451, 453, 460, 464
URLs (uniform resource locators)
parse
method and, 395–396, 397
query strings added to, 397–398, 406
user interface
designing for customers, 162, 252–254
examples of building, 163–165, 252–264, 357–359
improving for contacts app, 309–316
input paragraph creation, 254–257
users
receiving ideas from, 310, 316
written stories for, 336
value
attribute, 44
values
NaN, 11, 125, 141, 142, 148, 230, 231
parameters as, 217
query, 397
var
keyword, 48, 72, 75–76, 205, 235, 238
variables
control, 191
creating, 48, 72, 75–76, 193, 236, 239
global, 134–136, 142, 143, 235, 417
video walkthroughs, xviii
Visual Studio Code program, 13, 25
App Service Extension, 401
cloning repositories with, 18–19
color styles added in, 65
finding files in, 21
font selector in, 69
keywords in, 24
Node.js test in, 388
Visual Studio suite, 25
web browsers
badly formatted HTML in, 37–38
JavaScript used in, 6
local storage managed by, 293, 318
web pages, 28
ideas for creating, 57
web servers
creating with Node.js, 389–400
deploying Node.js, 401
JavaScript and, 23
websites, 28
whole numbers, 112–113, 141, 142
World Wide Web (WWW)
HTML and, 28
Internet vs., 59
World Wide Web Consortium (W3C), 28
write
method, 392
35.172.121.218