Solution to JavaScript Exercise2