Professional Documents
Culture Documents
Level 1
> 3.14
> 24
24
LEVEL ONE
3.14
Operators
Common Operators used in JavaScript Syntax:
addition
>6 + 4
10
subtraction
>9 - 5
4
multiplication
>3 * 4
12
division
> 12 / 4
3
modulus
> 43 % 10
3
> (5 + 7) * 3
12
> (3 * 4) + 3 - 12 / 2
* 3
36
12
+ 3 - 12 / 2
12
+ 3 -
6
9
> (-5 * 6) - 7 * -2
-30
-30
> 4 + (8 % (3 + 1))
- 7 * -2
- -14
4 + (8 %
4 +
0
-16
LEVEL ONE
)
4
Comparators
Common Number Comparators used in JavaScript Syntax:
greater than
>6 > 4
less than
greater or equal
> 8 >= -2
>9 < 5
true
false
true
equals
not equals
less or equal
boolean value
> 3 == 4
false
two equal signs!
LEVEL ONE
> 10 <= 10
> 12 != 4
true
the not symbol
true
Strings
How JavaScript stores and processes at text
Strings need quotes!
LEVEL ONE
LEVEL ONE
Uh oh...what happened?
Concatenation adds no
spaces, so we need to
add our own.
LEVEL ONE
"Login Password:
LEVEL ONE
"C3P0R2D2""
Orlando(MCO)\London(LHR)"
String Comparisons
Checking for matching strings and alphabetical ordering
false
true
String Comparisons
The length of strings can be accessed with the .length property
> "antidisestablishmentarianism".length
28
LEVEL ONE
Level 2
Variable Valley
value to be
stored
assignment
operator
> trainWhistles
3
Naming Variables
Rules and regulations
var no spaces
var 3blindmice
no digits in front
var scored_is_fine
var get$
var $_$
var goodNameBro
var mortalKombat2
FATALITY!!
LEVEL TWO
> trainWhistles
3
> trainWhistles = 9
> trainWhistles
> trainWhistles
12
> trainWhistles
same operation,
different syntax
> trainWhistles += 3
12
> trainWhistles
15
LEVEL TWO
> trainWhistles
> trainWhistles += 3
15
> trainWhistles
same operation,
different syntax
> trainWhistles *= 2
30
> trainWhistles
60
Using Variables
Variable names also act as substitutes for the data they point to
> trainWhistles = 3
LEVEL TWO
Using Variables
Variable names also act as substitutes for the data they point to
> trainWhistles = 3
> pollack9000
9
LEVEL TWO
Using Variables
Variable names also act as substitutes for the data they point to
> trainWhistles = 3
LEVEL TWO
> trainWhistles = 3
> trainWhistles++
> trainWhistles--
> trainWhistles
> trainWhistles
4
LEVEL TWO
LEVEL TWO
> var longString = "I wouldn't want to retype this String every time."
> longString.length
49
LEVEL TWO
LEVEL TWO
28
Spaces are
characters too!
> sentence.length
43
LEVEL TWO
42
> sentence.charAt(31)
"b"
LEVEL TWO
" "
> sentence.charAt(42)
"!"
LEVEL TWO
LEVEL TWO
Files Falls
Level 3
FILES FALLS
10
LEVEL THREE
11
12
index.html
The <script> tag says YO, we
want some JavaScript code
executed!
<html>
<header>
<script src="trains.js"></script>
</header>
<body>
<h1>JAVASCRIPT EXPRESS!</h1>
...
</body>
</html>
Remember to
turn off your
script tag!
trains.js
LEVEL THREE
root/
index.html
trains.js
LEVEL THREE
<html>
<header>
<script src="trains.js"></script>
</header>
<body>
<h1>JAVASCRIPT EXPRESS!</h1>
...
</body>
</html>
root/
index.html
scripts/
trains.js
<html>
<header>
<script src="scripts/trains.js"></script>
</header>
<body>
<h1>JAVASCRIPT EXPRESS!</h1>
...
</body>
</html>
root/
pages/
index.html
scripts/
trains.js
<html>
<header>
<script src="../scripts/trains.js"></script>
</header>
<body>
<h1>JAVASCRIPT EXPRESS!</h1>
...
</body>
</html>
ERROR
LEVEL THREE
But guess what? If we enter multiple console statements to execute in one le...
var trainsOperational = 8
trainsOperational = trainsOperational + 4
"There are " + trainsOperational + " running trains."
...it is interpreted by the compiler pretty much like this utter nonsense:
var trainsOperational = 8trainsOperational = trainsOperational +
4"There are " trainsOperational + " running trains."
LEVEL THREE
Enter Semicolons!
We like semicolons; they do not suck.
Console Entry
File Entry
wootForSemicolons.js
Multiple executable
statements are all
separated by semicolons
var trainsOperational = 8;
trainsOperational = trainsOperational + 4;
"There are " + trainsOperational + " running trains.";
(blank)
LEVEL THREE
We need a way to g
printed out to the c
console.log method
to the console. Whi
false
#"
#"
#"
#"
#"
+
+
+
+
+
4
5
6
7
8
+
+
+
+
+
"
"
"
"
"
is
is
is
is
is
running.");
running.");
running.");
running.");
running.");
Train
Train
Train
Train
Train
Train
Train
Train
#1
#2
#3
#4
#5
#6
#7
#8
is
is
is
is
is
is
is
is
running.
running.
running.
running.
running.
running.
running.
running.
trains.js
console.log("Train #" + 1 + " is running.");
console.log("Train #" + 2 + " is running.");
console.log("Train #" + 3 + " is running.");
console.log("Train
console.log("Train
console.log("Train
console.log("Train
console.log("Train
#"
#"
#"
#"
#"
+
+
+
+
+
4
5
6
7
8
+
+
+
+
+
"
"
"
"
"
is
is
is
is
is
running.");
running.");
running.");
running.");
running.");