This is adapted from example 7-15 from The Book of JavaScript, by Dave Thau.

Number 1:
Number 2: