Here are solutions (partial, or worked out in full) to the questions posed along the text. In many cases, there are extra questions for you to do further work.
1.1. Classes as first class objects. If you remember that a class is basically a function that can be used with new, then it stands to reason that we should be able to pass classes as parameters to other functions. The makeSaluteClass() basically creates a class (that is, a special function) that uses a closure to remember the value of term. We'll be seeing more examples of these kind of things in the rest of the book.
1.2. Factorial errors. The key to avoiding repeated tests is to write a function that will:
- First check the value of the argument to see it it's valid, and if so
- Call an inner function to do the factorial itself, without worrying about erroneous arguments.
const carefulFact...