bbb Home
Introduction to JavaScript Contents        

WHAT IS JAVASCRIPT?

JAVASCRIPT CAPABILITIES

WHERE TO ADD SCRIPT

javascript: alert('hi');document.write('Pretty exciting, huh?')  

<html>
   <body>
      Hi
      <script language = "javascript">
         alert('hi')
         document.write('<i>Hi again</i>')
      </script>
   </body>
</html>  
<head>
   <script>
      alert("hi")
      document.write("hi")
   </script>
</head>  

<script language = "javascript" src = "myjavascript.js"></script>  


SOME DETAILS

// Only this line is commented out
/* All of this code is commented out,
even though it is on different lines
*/  

EXAMPLE

Font: 8pt   12pt   20pt   24pt   Width: Min. 50%   75%   100%   

PRACTICE

Experiment with the example above:

  1. Change the line alert("In head") to Alert("In head") and run the code. Does it work?
  2. Change the line alert("In head") to alert('In head') and run the code. Does it work?
  3. Add some text immediately after the <body> tag and run the code. Change the line alert("In head") to document.write("In head"). Run the code. Where is the expression "In head" relative to the text that you typed after the <body> tag?
  4. Use document.write to write out a hyperlink on the page.
  5. Add a comment to your <script> code.

SELF-QUIZ