The code looks clean and well readable and with one exception I would say there is nothing wrong with it per se, however you are using several unusual approaches.
The task asks for
A text element to show result
I'm not sure what a "text element" means here, but it could be an <input type="text">
. However that would be wrong, since there are for input and not output. Your choice of a <b>
element is better, but HTML 5 provides the <output>
element, that would be even more suitable.
Your choice to collect your variables in objects (elements
, data
, events
) seems somewhat arbitrary. It's not wrong, and after getting used to it, it actually helped readability somewhat (except that now almost all lines begin with elements.
..., which seems a bit repetitive).
Just be aware that it's an unusual thing to do, because people usually expect objects like that to have sort of technical use, instead of just grouping variables.
The use of the comma operator to separate statements (or to be exact expressions) instead of semicolons (or just line breaks) is very unusual. Since the comma operator is very rarely used, it can be confusing for beginners and experts may try to find deeper meaning to it, even when there is none. Especially the first line of init()
irritated me for a moment, because there is no line break after the commas, so that it looks like some special is happening, which isn't.
The only point that I consider wrong: The use of &&
instead of a regular if
. This (and the use of the comma operator) looks like you are trying to emulate the kind of "optimizations" that code compressors do. Don't do this. It compromises readablily. If you want to serve compact code, then use a code compressor.