Nimesh Print Finale

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

TRINITY INTERNATIONCAL SS & COLLEGE

Dillibazar Height, Kathmandu, Nepal

LAB WORK # 1: Javascript

(COMPUTER SCIENCE)

SUBMITTED BY: SUBMITTED TO:


NAME: NIMESH BHATTARAI

GRADE: XII MC2

DATE : 2080-07-17 PRAVEEN KOIRALA

Faculty of Computer Science


Table of Contents

S. No. Page No.

1. Objectives 1

3. Theoretical Background (2-3)

3.1 Programming Concept

3.1.1 Javascript

4. Work Done

4.1 Work Done on Javascript 4


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.
3. Theoretical Background

Javascript
Javascript is one of the most popular scripting programming language. It is a case
sensitive language developed by Netscape. Javascript consists of three basic types of
data types:

• Numbers
• String
• Boolean

Javascript variables can be defined in following ways:

• Var
• Let
• Const

Input and Output of data in Javascript


We can use prompt() function to ask and input data from the user.

We can also use functions like alert(), document.write(), console.log() etc.

Arithmetic Operations
The arithmetic operators in javascript are:

+ : It is used for addition of numbers and concatenate strings.

- : It is used for subtraction numbers.

* : It is used for number multiplications.

/ : It is used for number division.


% : It is used for numbers remainder divisions.
++ : It is used for incrementing the value by 1.

-- : It is used for decrementing the value by 1. Logical


Operators

The logical operators used in Javascript are as follow:

|| : It is the logical OR.

&& : It is the logical AND.

! : It is the logical NOT.

Conditional Statements
The conditional statements in Javascript are:

• if statement: It is used to check if a statement is true or not.


Syntax:if (condition) {};

• else : It is used to specify a block of code to be executed, if the same


condition is false. Syntax: if (condition) {} else {}(if condition is
false)

• else if: It is used to specify a new condition to test, if the first


condition is false. Syntax: if (condition1) { } else if (condition2)

• Switch : It is used to specify many alternative blocks of code to be


executed. Syntax: switch(expression) { case x: statement;
break; case y: statement; break; default:

You might also like