Training Guide: Programming in HTML5 with JavaScript and CSS3 Ebook

(Nora) #1

100 CHAPTER 3 Getting started with JavaScript


FIGURE 3-11 he QUnit-Metro summary screen showing the passing testT

As you add more features to your application, you add another test that defines or helps
shape each feature, and then write the code to make the test pass.

Using the script tag


In the previous sections, links to JavaScript files were added to HTML documents by dragging
the JavaScript file from the Solution Explorer window and dropping it on the HTML docu-
ment. Upon dropping, a <script> element is added that references the JavaScript file.
The <script> element can define a JavaScript code block or load an external JavaScript file,
but not both.
The following is an example of using the <script> element to define a JavaScript code
block within the HTML document:
<script type="text/javascript">
<!--
function Add(x, y) {
return x + y;
}
alert(Add(3, 2));
//-->
</script>

The type attribute specifies the MIME type, which was required in earlier versions of HTML
but is optional in HTML5.
Free download pdf