Home > Articles > Open Source > Ajax & JavaScript

  • Print
  • + Share This
This chapter is from the book


The workshop will test how much you have grasped of the topics discussed in this chapter.


  1. I want to repeat a piece of code an exact number of times. Which JavaScript statement should I use?

  1. The for statement is ideal to achieve that. You could achieve the same thing using a while loop, for example, but it is less convenient to use it.

  1. I want to be able to check the length of several strings of characters in my code. How can I do that?

  1. You could create a short function which takes a single argument—the string you want to check. You may want to use array techniques within the function. Those will be described in Chapter 5.

  1. I want to check if more than one thing is true. Can I use a switch statement to do that?

  1. You could use a switch statement, but not on its own. You could nest another function which uses a switch statement within a case statement. Often it will be at least as easy to use an if statement with a number of else if statements. Whichever technique you choose you need to be clear about the process of logic and which statements will be evaluated and which statements won't.


  1. List the looping statements that are present in JavaScript.

  2. Is it possible to include multiple statements in my own functions?

Quiz Answers

  1. The looping statements in JavaScript are the while statement, the do while statement, and the for statement.

  2. Yes. You can include multiple statements in a function by enclosing them in curly braces, like this:

function myFunction()


Modify the multiplication table generator so that it will respond appropriately if the user clicks Cancel or enters a non-numeric value.

  • + Share This
  • 🔖 Save To Your Account