<input type="text" id="eq0">
</div>
</div>
<input type="button" value="Submit" id="submit">
</form>
<div id="score"></div>
</div>
Basically, the worksheet is an HTML form containin g one or more pairs o f <label>
and <input> elements, each pair representing an equation . For the homework yo u
will only work with a single equation but in general there will be more of them. The
question part of the equation is represented by a label, while the part accepting the
answer is implemented a s a text box. At first gla nce, so me of the elements in the
above document look superfluous but they are in fact there to make your life easier.
The innermost <div> ele ment, for example, allows you to trea t the label-input pair as
a sep arate entity, which is especially useful for positioning the equations.
Let the finished application initially display an equation, which sho uld be contained in
the <label> element. Each time the u ser clicks the submit button, a so lution entered
into the text box should be checked and the total score updated accordingly. You use
the <div> element with the ID sc ore to display the score. Finally, a n ew equ ation
should be generated and displayed.
Before we go home, here’s a list of today’s keywords:
In this meeting: core JavaScript, client-side JavaScript, Window object, global ob-
ject, global variables an d functions, <script>, sr c, synchronous execution, asyn-
chronous execution, event, event-hand le r property, onclick, onload, DHTML,
web application, API, DOM API, Docum ent object, getElementById(),Element
object, innerHTML, timers, setTimeout(), setInterval(), callbac k, class,
className, <form>, input con trols, <input> , type, text, butto n, val ue, for,
htmlFor, <label>
244 Meeting 12. Using JavaScript to Control the Browser