Professional Documents
Culture Documents
(COMPUTER SCIENCE)
KATHMANDU, NEPAL
2023
Table of Contents
1. Acknowledgement I
2. Objectives II
3.1 Javascript
4. Work Done
5. Conclusion ……
2. Objective
HTML forms the backbone of web pages. It structures content using elements like
headings, paragraphs, images, and links. It provides the basic layout and semantics of
web documents.
CSS complements HTML by controlling the presentation and appearance of web pages. It
allows designers and developers to customize colors, layouts, fonts, and other visual
aspects of a website.
3. JavaScript:
JavaScript enables interactive elements on web pages. It allows for dynamic content
updates, event handling, and interaction with users. It's instrumental in creating engaging
user experiences.
Adding JS to a webpage
Adding JavaScript to a webpage can be done in several ways. Here's a basic example of
how you can incorporate JavaScript into an HTML document:
You can include JavaScript directly within the HTML document using the <script> tag in
the <head> or <body> section.
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Example</title>
<script>
// Inline JavaScript
function greet() {
alert('Hello, World!');
</script>
</head>
<body>
<h1>JavaScript Example</h1>
</body>
</html>
In this example, the JavaScript function greet() is defined within the <script> tag in the
<head> section and is triggered by the onclick event of the button.
Method 2: External JavaScript File
Alternatively, you can create a separate JavaScript file and link it to your HTML document
using the <script> tag's src attribute.
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Example</title>
<script src="script.js"></script>
</head>
<body>
<h1>JavaScript Example</h1>
</body>
</html>
javascript
function greet() {
alert('Hello, World!');
Here, the JavaScript code is saved in a file named script.js, and it's linked to the HTML file
using the <script> tag's src attribute.
JavaScript offers various ways to interact with users and handle their inputs. Here are
some simple user interaction functions commonly used:
Alert: Displays a message in a dialog box.