-
As a developer, you will have a lot of tools that you can use to calculate values in JavaScript. This can be helpful in building products for stores, games, or other applications.
-
Here are the operators:
-
Addition (+): Adds two or more numbers together.
-
Subtraction (-): Subtracts one number from another.
-
Multiplication (*): Multiplies two or more numbers.
-
Division (/): Divides one number by another.
-
Modulus (%): Returns the remainder after division.
-
JavaScript follows the standard mathematical rules of precedence (PEMDAS), where multiplication and division are evaluated before addition and subtraction. You can use parentheses to control the order of operations if needed.
- Assignment Operator: Remember, the equal sign, =, is the assignment operator and not a traditional equal sign. This is how you can assign and reassign values in JavaScript!
- Math Object: JavaScript comes with the Math object that provides handy tools for running certain calculations. Here is the MDN article on the Math Object.
- NaN stands for "Not-a-Number." It is a special value used to represent the result of an operation that cannot produce a meaningful numeric result. When you perform certain arithmetic operations in JavaScript, the result may be undefined or not a valid number. In such cases, the result is represented as NaN.
- Connect your js file to your HTML file
- Open your code in the browser and open your console
- In the
js
file, carefully review the code listed. - Answer the questions about the code and run it in the browser.
- In the
js
file, complete the activities on using different operators.
- In the
js
file, follow the prompts to calculate the amount of meals you will need to last you for the next decade.
- In the
js
file, follow the prompts to calculate average scores of each student's subjects.
- In the
js
file, follow the prompts to calculate farenheit based on celsius temperatures.
- You will regularly need to reassign the values of variables based on what you need to be tracking as a user interacts with your program.
- In the
js
file, follow the prompts to reassign the values of a variable.
- The Math Object is a powerful tool for helping you with certain math calculations.
- In the
js
file, follow the prompts to round a number.
- In the
js
file, follow the prompts to generate a random number for a dice game, and then alert the user of the value.
- In the
js
file, follow the prompts to fix the code of its NaN values. - Look up the isNaN() operator in MDN.