We're going to add a series of commands and see what happens.
Start by typing
document into the console.
Look familiar? This is our HTML document, interpreted as a node structure by the Document Object Model.
Okay, let's try a couple more lines:
document.body document.body.style document.body.style.color = "purple";
But wait, what is that
var thing, and what are those functions??
var, unlike Processing or other languages you have probably seen things like
For now, let's write some variables and then keep going.
x = 10; x++; // (Hmm... type x again) x += 10; x = x + 10; x = "ten"; x = "10"; x++; // (er... type x again) x = false; typeof x;
Okay, that was weird...
But actually, very useful in someways and of course easy to write!
Tricky, but useful...
= sign is used to assign data to variables, like
var img = "mycat.jpg"; or
var i = 0;. You can also use
+ to add variables,
- for subtraction,
* for multiplication,
/ for division,
++ to increment by one,
-- to decrease a value by one,
+= to add a value to the current value, or
-= to subtract that value. You can also use
% will give you the remainder from a division, ie
5%4 = 1, which is useful for cyclical logic, and can also be used as
%=. These operations are done primarily on numbers, but you can do addition with strings, and add strings to numbers.
Try a few operations in the console:
n = x + 1 n += 1 "Hello" + "World" "7" + 7
== is used to compare two variables or values, along with
!= (not equal).
"hello" == true var i = 10; i < 11; 6 != "six"
=== is used to determine that two values are the same type
7 === 7 "7" === 7