MathematicalExpression
A blog understanding about Diffrent Mathematical Expression
What are Mathematical Expressions and Types of Mathematical Expression?
-
Mathematical expression is an expression that evaluates to a numerical value. It consists of numbers, variables, operators, and functions.
-
Diffrent types of Mathematical Expression
- Arithmetic Expressions – Use basic mathematical operations like addition, subtraction, multiplication, and division.
- Algebraic Expressions – Contain variables that represent unknown values.
- Function-based Expressions – Utilize built-in mathematical functions such as square root, exponentiation, and trigonometric functions.
- Complex Expressions – Combine multiple operations and functions, following the standard order of operations (PEMDAS).
1)
To use basic math equation you always gotta define a and b in order to
- Sum of
a
andb
- Difference of
a
andb
- Product of
a
andb
- Quotient of
a
divided byb
// Define variables
let a = 12;
let b = 4;
// Perform operations
let sum = a + b; // Sum
let difference = a - b; // Difference
let product = a * b; // Product
let quotient = a / b; // Quotient
// Log results to console
console.log("Sum:", sum);
console.log("Difference:", difference);
console.log("Product:", product);
console.log("Quotient:", quotient);
2) Modulus Operator
- Create a variable num1 and assign it a number.
- Create a variable num2 and assign it another number.
- Use num1 % num2 to get the remainder when num1 is divided by num2.
- Print the remainder using console.log().
//eg
// Define variables
let a = 17;
let b = 5;
// Compute remainder
let result = a % b; // 17 divided by 5 gives a remainder of 2
// Log the result to the console
console.log("Remainder of", a, "divided by", b, "is:", result);
3) Increment an Decrement
- What is Increment and Decrement
- Increment= is where you increase a number using ++
- Decrement = is when you decrease a number using –
- How do you Increment or decremnt by spefifc value
- Glad you asked += for increment by spefic value
- Decrement -= to decrement by spefifc value
1) Define the variable or the number you are working with eg (1 or 10) doesn’t matter 2) use this ++ to increment by 1 or – to decrement by 1 3) Use this += to increment by spefifc value and use this -= to decrement by spefifc value 4) thenuse console.log to track those values Sample Eg
let num = 10; // Starting number
// Increment by 1
num++;
console.log(num); // Output: 11
// Decrement by 1
num--;
console.log(num); // Output: 10 (back to original)
// Increase by a specific value (e.g., 4)
num += 4;
console.log(num); // Output: 14
// Decrease by a specific value (e.g., 4)
num -= 4;
console.log(num); // Output: 10 (back to original)
How can we apply to game?
Have you played adventure games where you have the monster attacking you and killing or destroying your health well that how it works an Eg down here
let mainCharacterEnergy = 50;
let npcEnergy = 40;
// Main character finds an energy boost
let energyBoost = 4;
mainCharacterEnergy += energyBoost; // Increase energy by 4
console.log("Main Character Energy: " + mainCharacterEnergy); // Output: Main Character Energy: 54
// NPC loses energy due to an obstacle
npcEnergy -= energyBoost; // Decrease energy by 4
console.log("NPC Energy: " + npcEnergy); // Output: NPC Energy: 36
// Main character uses a skill, reducing energy by 1
mainCharacterEnergy--;
console.log("Main Character Energy after skill: " + mainCharacterEnergy); // Output: Main Character Energy: 53
// NPC regains some energy
npcEnergy++;
console.log("NPC Energy after recovery: " + npcEnergy); // Output: NPC Energy: 37
Conclusion?
The Mathematical Expresison are crucial as they help us Calculate health, damage, and energy changes. Control movement, physics, and scoring systems and help us create if statement to make sure to track if they are killed and detroyed so remeebr to Code, Code, Code bye