Writing JavaScript in your HTML
see p. 14-16
Here is a simple JavaScript.
<HTML>
<HEAD>
<TITLE> Script 2.1 </TITLE>
</HEAD>
<BODY>
<H1> Does it work ???
<SCRIPT LANGUAGE="JavaScript">
<!-- HIDE
document.write("It works!")
// STOP HIDING-->
</SCRIPT>
<NOSCRIPT>
This page requires a JavaScript-capable browser
</NOSCRIPT>
</H1>
</BODY>
</HTML>
- Use your favorite editor - whatever you use to write your HTML is fine
- Put your JavaScript
- In the body of your HTML
- In the head of your HTML
- In its own .js file (p 164)
- Use <SCRIPT> </SCRIPT> tags
- Hide your JavaScript from old browsers
- (Hide your hiding from JavaScript!)
- Use <NOSCRIPT> </NOSCRIPT> tags to tell users whose browsers
are not JavaScript enabled (old browsers or new browsers with JavaScript
disabled) what they are missing!
- Comment your code
- Write block comments with /* ... */
- Write inline comments with //
Assignment:
- Write a JavaScript like this one that uses JavaScript to write your name.
- Add to your JavaScript so it tells something about you on a new line.
- Add to your JavaScript so it puts some of your text in a
different font.