Page 134 - Computer Software Application TP - Volume 1
P. 134
COMPUTER SOFTWARE APPLICATION - CITS
TASK 2: External JavaScript
I Create JavaScript file
1 Open the text editor
2 Write the following codes
console.log(“Hello, world!”);
console.log(“This is external javascript”);
3 Save the program as ‘script.js’
II Link the External JavaScript File to HTML
1 Open the text editor
2 Write the following codes
<html>
<head>
<meta charset=”UTF-8”>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0”>
<title>JavaScript Example</title>
<!-- Link to external JavaScript file -->
<script src=”script.js”></script>
</head>
<body>
<!-- HTML content -->
</body>
</html>
3 Save the program as a .html file
4 Open the html file with a web browser
5 Go to the browsers console tab and verify the output.
1 What is inline JavaScript, and how does it differ from external JavaScript files?
2 What are some advantages and disadvantages of using inline JavaScript in web development?
3 What are the different ways to include inline JavaScript in HTML elements
4 How do you include an external JavaScript file in your HTML document, and what are the different ways to
specify the path to the file?
119
CITS : IT & ITES - Computer Software Application - Exercise 37