Prev | Current Page 775 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

split(???|???);
q.push({ author:StringTools.trim(p[0]), quotation:StringTools.trim(p[1]) });
}
return q;
}
private static function pickRandom(qs : Array < Quotation > )
{
var index = Std.int(Math.random() * qs.length);
return qs[index];
}
}
417
Chapter 14: More Interactive Content with JavaScript
The file contains a quotation per line. Each line is composed by the author name, a pipe character ( |),
and the quotation text. You can test the script by compiling it to a quotation.n file and invoking it,
pointing your browser to your development web server or executing the file on the command line.
The client page can be a complex home or as simple as the one in the following code. The importance is
the presence of the placeholder element with id= ??? quotation ??? and of course of the JavaScript file.
< html >
< head >
< title > Quotation Example < /title >
< /head >
< body >
< div id=???quotation??? > < /div >
< script type=???text/javascript??? src=???main.js??? > < /script >
< /body >
< /html >
Now it is time for the client - side script.


Pages:
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787