Numeric review

What you need to know for tomorrow's assessment.

How to write literal numbers

0, 1, 3.0, -100

The six arithmetic operators

+, -, *, /, %, **

What they do and how to use them in expressions.

Grouping

() to deal with order of operations

E.g. (a + b) / 2

How to use functions given to you

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.

How to use constants given to you

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.

Variables might be useful

Sometimes you can clarify or simplify code with intermediate variables.

For example

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.)

Try to write an expression

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.