Java Reference
In-Depth Information
This uses an alert dialog to give some feedback about how many questions were answered
correctly.
Once you've made these changes, have a go at playing the quiz by opening the index.htm
file in your browser. It should look like the screenshot shown in Figure 4.3 .
Figure 4.3. Playing Quiz Ninja
While you play, you might notice that there's been no change to the functionality of the
quiz. This is the process of refactoring―the functionality of the application remains the
same, but the underlying code has become more flexible and easier to maintain, as well as
being more readable and descriptive due to the use of functions. We have abstracted much
of the internal game logic out into separate functions, which means that we can change the
mechanics of different aspects of the quiz by updating the relevant functions.
I hope this helps to demonstrate how functions can make your code more flexible, main-
tainable, reusable, and easier to read―as long as they are well-named.
Search WWH ::




Custom Search