20BCS4241 Mai Lab Worksheet 1.2 Punit

You might also like

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

Experiment No. 1.

2
Student Name: PUNIT RANOT UID: 20BCS4241
Branch: CSE-CC Section: 20BCC2-B
Semester: 5th Date of Performance: 24-08-2022
Subject Name: MAI Lab Sub code: 20CSA331

Aim/Overview of the practical:


Program to define variable, control structure in java script.

Task to be done:

1. Execute a sample program to define the variables in java

script. 2.Make a program using control structure in java script.

Requirements:

1) Laptop/pc.
2) JavaScript compiler (I’ve used Online).

Steps For Practical:

1) Execute a sample program to define the variable in JavaScript.

a) Variable store the date value that can be changed later.


b) JavaScript is a loosely typed language. It means it does not require a data type to
be declared.
c) We can assign any literal values to a variable, e.g., string, integer, float, Boolean,
etc.
Program code:

var a=5; // intiger value


b='six'; // string value
c='1.7'; // float value
d= 11>9; // boolean value
console.log(a);
console.log(b);
console.log(c);
console.log(d);

Output:
2) Make program using control structure in javascript.
a) Control structures are the statements which are used for loop and conditional
selections.
b) Control statements are ‘if else’, ‘for loop’, ‘while’, ‘do while’, ‘switch case’,
‘break’, …etc.
If else:
Program to find greatest between two number-
var a=30;
var b=25;

if (a>b)
console.log("a is greater than b")
else
console.log("b is greater than a")
Output:
For loop:
Program to find the sum of first 10 whole numbers-
var num;
var sum=0;
for(num=0;num<10;num++)
{
console.log(num);
sum=sum+num;
}
console.log("Sum of first 10 whole numbers =",sum);

Output:
While:
Program to find factorial of given number-
var num=15;
var i=1;
var fact;
while(i<num)
{
fact=num%i;
if(fact==0)
{
console.log(i);
}
i++;
}

Output:
Do While:
Program to multiply first 10 natural numbers
var num=1;
var multiply=1;
do
{
console.log(num);
multiply=multiply*num;
num++;
}while(num<11)
Console.log(multiply);

Learning outcomes (What I have learnt):

1. Declaring variables
2. Assigning values to the variables
3. Selection statement (if else)
4. Looping statement (for loop)
Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):
Sr. No. Parameters Marks Obtained Maximum Marks
1.

2.

3.

You might also like