Operators: String Operations, Mathematical Operations, Boolean Expressions
Operators perform computations or manipulations on variables and values.
Types of Operators
1. String Operations (+, .toUpperCase(), .concat()): Used to manipulate text values.
let str = 'hello'
console.log(str.toLowerCase())
console.log(str.toUpperCase())
console.log(str+' world!')
In the platformer game, string operators are used to store data for next levels, and for checks in each level (in the console) to see if the machine is running through certain parts of the code.
2. Mathematical Operations (+, -, *, /, %): Used to perform arithmetic calculations.
let a = 5
let b = 7
console.log(a+b)
console.log(a*b)
console.log(a-b)
console.log(a/b)
In the game, we use mathematical operators to count for the number of coins, and to keep track of the time. We also use it for the jump and gravity features of Mario.
3. Boolean Expressions (>, <, ===, !==): Compare values and return true or false.
let a = 5
let b = 7
if(a>b) {
console.log("a is greater than b")
}
These boolean expressions in the game are commonly used with conditionals, and are used to check against static values to end the game.