Professional Documents
Culture Documents
20BCS4241 Mai Lab Worksheet 1.2 Punit
20BCS4241 Mai Lab Worksheet 1.2 Punit
20BCS4241 Mai Lab Worksheet 1.2 Punit
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
Task to be done:
Requirements:
1) Laptop/pc.
2) JavaScript compiler (I’ve used Online).
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);
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.