You are on page 1of 8

TRINITY INTERNATIONAL SS & COLLEGE

Dillibazar Height, Kathmandu, Nepal

LAB WORK # [1] : Javascript

(COMPUTER SCIENCE)

SUBMITTED BY: SUBMITTED TO:

NAME: Bhupesh Budha

GRADE: XII (MC2)

DATE : 16th Mangshir 2080 PRAVEEN KOIRALA

Faculty of Computer Science

KATHMANDU, NEPAL
2023
Table of Contents

S. No. Page No.

1. Acknowledgement I

2. Objectives II

3. Theoretical Background (1-…….)

3.1 Javascript

4. Work Done

4.1 Work Done on JavaScript …….


1. WAP to find area and circumference of circle.
2. WAP to find the square root of a number.
3. WAP to pick the greatest number among three numbers.
4. WAP to find even or odd.
5. WAP to input your name and age using form and know whether he/she is eligible to
vote or not.
6. WAP to perform following operations using switch structure.
If you enter A+, it says you have obtained grade A+.
If you enter A, it says you have obtained grade A.
If you enter B+, it says you have obtained grade B+.
If you enter B, it says you have obtained grade B.
If you enter any other value/character, it says you have obtained other grade.
7. WAP to print factorial value of a number.
8. WAP to print multiplication table of a number. Use function.
9. WAP to reverse a string. [use loop from its length-1 to 0 and print it]
10. An array contains multiple strings. Print them in reverse order.[use array.reverse()
method].
11. WAP to insert a string “We are learning JS” via form object getElementById()
method. Use paragraph with id.
12. Input your name and grade using form. Validate this with a message ‘This field is
required’, using onclick() event.
13. Write any two paragraphs in your html page. Now write a program using JQuery to
hide that written paragraphs as you click on that.
14. Use JQuery to create an alert message for a button.

5. Conclusion ……
2. Objective

The main objectives of the lab work are as follows:

1. To understand different variable types in JavaScript.

2. To get input from user and display output.

3. To perform arithmetic and logical operation in JavaScript.

4. To understand and apply conditional statements in JavaScript.To understand

different variable types in JavaScript.

5. To get input from user and display output.

6. To perform arithmetic and logical operation in JavaScript.

7. To understand and apply conditional statements in JavaScript.


3. Theoretical Background
Web Technology
Web technology refers to the various tools, software, protocols, and standards that enable
the functioning of the World Wide Web. It encompasses a broad range of components that
work together to facilitate the creation, management, and interaction with web-based
applications and content. Here are some key elements of web technology:

1. HTML (Hypertext Markup Language):

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.

2. CSS (Cascading Style Sheets):

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.

Fig: Web Technology


JavaScript
JavaScript is a versatile programming language primarily used for creating interactive
effects within web browsers. Initially developed by Brendan Eich in 1995, it has evolved
into a fundamental tool for web development. Its flexibility allows developers to build
dynamic and engaging web pages, enabling functionalities like user interactions,
animations, and handling data.

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:

Method 1: Inline JavaScript

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>

<button onclick="greet()">Click me</button>

</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>

<button onclick="greet()">Click me</button>

</body>

</html>

javascript

// External JavaScript file (script.js)

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.

Simple user interaction function

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.

alert('This is an alert message!');

Prompt: Prompts the user to enter some value.

let userInput = prompt('Enter your name:');

Confirmation: Presents a dialog box with OK and Cancel buttons.

let userConfirmation = confirm('Are you sure you want to proceed?');


4. Work Done

You might also like