2.3 - Mathematics
Review
Web browsers run a language called JavaScript. It has syntax similar to C, C++, C#, Java.
We can output text, numbers, and values of variables to the console with console.log()
We can create variables with the let keyword.
Quiz
What will this print: console.log("2 + 2")
What will this print: console.log(12 / 5)
What if we want to round a mathematical answer? Or get a random number?
2.3 - Mathematics
Mr. Brash will demonstrate template strings in JavaScript.
A shortened version of the lesson is below.
A more detailed lesson is in the repository: 2.3 - Mathematics
Synopsis:
Computers were designed to do mathematics very quickly.
= is the assignment - it does not check if something is equal
+ and - for add and subtract
* and / for multiply and divide
== "is it equal?" (this is important)
Crucial note: a single equal sign '=' is not used for math! It means "become" or "assign"
!= "is it not equal?"
< > <= >=
** for exponent: 4**2 -> 16
BEDMAS still applies - it is important to utilize parentheses ( ) properly
JavaScript also has a Math object to perform more complex operations.
Math.PI
Math.sqrt(number)
Math.pow(base, exponent) // same as **
Math.random()
And so much more...