What you need to know for tomorrow's assessment.
0
, 1
, 3.0
, -100
+
, -
, *
, /
, %
, **
What they do and how to use them in expressions.
()
to deal with order of operations
E.g. (a + b) / 2
If I tell you Math.abs
is a function that computes the absolute value of its argument I expect you to be able to use it like Math.abs(x)
if you need the absolute value of x
.
If I tell you Math.PI
is a good approximation of π then you should be able to use it in an expression like:
Math.PI * 2 * r
Or I might tell you a simple name like X
will hold a value you need to use in an expression. You should be able to use the variable without worrying about what its exact value is.
Sometimes you can clarify or simplify code with intermediate variables.
const maxRadius = (width, height) => {
return Math.min(width, height) / 2;
};
could be written:
const maxRadius = (width, height) => {
const maxDiameter = Math.min(width, height);
return maxDiameter / 2;
};
(It’s debatable if this particular example is made more clear by introducing the extra variable.)
Even if you get stuck on the function syntax, try to write something that looks like a correct expression using meaningful names.
You’ll at least get credit for your understanding of numeric expressions.