| Index | Code Tester |
How to Add Javascript
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 */
1. Explain the different approaches for adding javascript to a web page.
2. Identify the statements that will run:
3. How do you create a comment in script code? How do you create an HTML comment?
4. Copy and paste the following code in the Address Bar in the browser. Run the code. Then change the coded so that the message "greater than 3" is displayed in the alert. What did you do?
javascript: var a; a = 3; if (a <= 3) alert(a); else alert("greater than 3")
5. Create a page with a <script> block that is embedded in the <body> tag. The script should display an alert with the message "alert1", then write "This is my first use of java script", and then display another alert with the message "alert2".
6. Modify the page in #5 so that the code in your script block is ALSO in a script block in the <head> section. However, change the messages in the alerts and what is written to the screen. Then open your page and observe the sequence of the alerts.
7. Create a javascript file (using the .js extension) that uses document.write to create a table with one column and three rows. The three rows should contain "Home", "Exercises", and "Links". Then create an .htm file and link it to the script file so that the table is created when the page loads.