checkAnswer () có hai tham số: câu trả lời mà người chơi nộp và thời gian ra để hủy bỏ nếu câu trả lời là chính xác. Dòng đầu tiên của chức năng, nhiệm vụ, kiểm tra câu trả lời. Nếu nó là chính xác, hủy bỏ thời gian ra ngoài, mà dừng lại JavaScript gọi goToAnswerPage () chức năng, và chúc mừng các cầu thủ. Nếu các cuộc gọi chức năng checkAnswer () khi người chơi nộp mẫu đơn, dường như không quen thuộc, nhìn vào. | Line-by-Line Analysis of Figure 11-4 When the form is submitted the onSubmit in calls the checkEmail function and sends it the contents of the emailbox form element. If the visitor filled out the form correctly that is with a correctly formatted email address checkEmail returns true the form is submitted and the page reloads. If the form has been completed incorrectly the function returns false the form is not submitted and the page doesn t reload. The checkEmail function works by checking for six basic formatting rules all email addresses must follow 1. There must be an @ sign. 2. The @ sign can t be the first character. 3. There must be a period in the address. 4. There must be at least one character between the @ and the last period. 5. There must be at least one character between the last period and the email s end. 6. There can be no blank spaces in the address. To test all six rules we need a few pieces of information. Lines o through determine the location of the first @ sign the location of the last period and the location of the first space if any in the string. Lines through check to see whether the address violates any of the six rules. Because these lines are ANDed together see the section AND on page 44 if you ve forgotten about the operator they must all be true to trigger the first result clause of the if-then-else statement which tells the visitor he or she filled out the form correctly . If any of the tests turns up false that triggers the else part of the if-then-else statement telling the visitor he or she entered the email address incorrectly. Table 11-2 shows you each rule and the line that tests it. Table 11-2 Checking Email Addresses Line Rule Comment 1 If there s an @ sign the_at doesn t equal -1. 2 If the @ sign is not the first character the_at is greater than 0. 3 If there s a period the_dot doesn t equal -1. o 4 If there s something between the @ sign and the last period the_dot is greater than the_at 1. 5 If a period is the last .