0% found this document useful (0 votes)
57 views

Session-7 Introduction To Javascript: 1. Prompt For Amount, Interest Rate and No. of Years and Calculate Simple Interest

1. This document discusses JavaScript concepts including: - Calculating simple interest given various inputs - Checking if a string is a palindrome - Calculating the area of a circle given the radius - Copying object properties - Creating arrays of employee objects and filtering/grouping them based on properties 2. Examples are provided to demonstrate: - Filtering employees with salaries over 5000 - Grouping employees by age - Finding employees with salaries under 1000 and ages over 20 to give them a salary increment 3. The document contains JavaScript code examples for each concept discussed.

Uploaded by

Divya Chhabra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

Session-7 Introduction To Javascript: 1. Prompt For Amount, Interest Rate and No. of Years and Calculate Simple Interest

1. This document discusses JavaScript concepts including: - Calculating simple interest given various inputs - Checking if a string is a palindrome - Calculating the area of a circle given the radius - Copying object properties - Creating arrays of employee objects and filtering/grouping them based on properties 2. Examples are provided to demonstrate: - Filtering employees with salaries over 5000 - Grouping employees by age - Finding employees with salaries under 1000 and ages over 20 to give them a salary increment 3. The document contains JavaScript code examples for each concept discussed.

Uploaded by

Divya Chhabra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

SESSION-7

INTRODUCTION TO JAVASCRIPT

1. Prompt for amount, interest rate and no. of years and calculate simple
interest.

var t = 2;
var pri = 1500;
var roi = 6.5;
var si = (t*pri*roi)/100;
console.log("simple interest is: "+si);
2. is palindrome string

var x = isPalindrome('RITIK');

function isPalindrome(word){
var i,wLength = word.length-1,wLengthToCompare = wLength/2;

for (i = 0; i <= wLengthToCompare ; i++) {


if (word.charAt(i) != word.charAt(wLength-i)) {
console.log(word+" is not a palindrome");
}
}
console.log(word+" is a palindrome");
}
3. Area of circle

var r = areaOfCircle(5.12);

function areaOfCircle(r){
var pi = 3.14;
var area = pi*r*r;
console.log("Area of circle with radius "+r+" is: "+area);}

4. Copy information of one object to another and log it to console.

let obj = {
a: 1,
b: 2,
};
let copy = obj;
console.log("Earlier value of a defined:");
console.log(obj.a);
obj.a = 5;
console.log("Value of a in copy after updating it:");
console.log(copy.a);
5. Create a list of objects of Employee with info as follow :

○ Name, age, salary ,DOB

var employee = []
employee[0]={name: 'Riya', age: 22, salary: 15000, date:
'19/12/1997' },
employee[1]={ name: 'Divya', age: 23, salary: 15200, date:
'06/01/1998' },
employee[2]={ name: 'Riyya', age: 22, salary: 15100, date:
'19/12/1995' },
employee[3]={ name: 'Jasleen', age: 20, salary: 1500, date:
'23/02/1994' },
employee[4]={ name: 'Ritik', age: 21, salary: 3200, date:
'19/11/1995' }
console.log(employee);

○ filter all employees with salary greater than 5000

var employee = []
employee[0]={name: 'Riya', age: 22, salary: 15000, date:'19/12/1997' },
employee[1]={ name: 'Divya', age: 23, salary: 15200, date:
'06/01/1998' },
employee[2]={ name: 'Riyya', age: 22, salary: 15100, date: '19/12/1995' },
employee[3]={ name: 'Jasleen', age: 20, salary: 1500, date: '23/02/1994' },
employee[4]={ name: 'Ritik', age: 21, salary: 3200, date: '19/11/1995' }
console.log("Employees with salary greater Rs.5000");
for(var i=0; i<5; i++){
if(employee[i].salary>5000){
console.log(employee[i].name);}}
○ group employee on the basis of their age

var employee = []
employee[0]={name: 'Riya', age: 22, salary: 15000, date:
'19/12/1997' },
employee[1]={ name: 'Divya', age: 23, salary: 15200, date:
'06/01/1998' },
employee[2]={ name: 'Riyya', age: 22, salary: 15100, date:
'19/12/1995' },
employee[3]={ name: 'Jasleen', age: 23, salary: 500, date:
'23/02/1994' },
employee[4]={ name: 'Ritik', age: 21, salary: 200, date:
'19/11/1995' }

var age22=[];
var age23=[];
var ageother=[];
var i;
for (i=0; i<5; i++)
{
if(employee[i].age == 22)
{
age22.push(employee[i].name);
console.log("People with age 22");
for(var j=0; j<i; j++)
{
console.log(age22[j]);
}
}

else if(employee[i].age == 23)


{
age23.push(employee[i].name);
console.log("People with age 23");
for(var k=0; k<i; k++)
{
console.log(age23[k]);
}
}
else if(employee[i].age != 22 & employee[i].age != 23 )
{
ageother.push(employee[i].name);
for(var l=0; l<i; l++)
{
console.log(ageother[l]);
}
}
}

○ fetch employees with salary less than 1000 and age greater than 20.
Then give them an increment 5 times their salary.

var employee = []
employee[0]={name: 'Riya', age: 22, salary: 15000, date:'19/12/1997' },
employee[1]={ name: 'Divya', age: 23, salary: 15200, date:'06/01/1998' },
employee[2]={ name: 'Riyya', age: 22, salary: 15100, date: '19/12/1995' },
employee[3]={ name: 'Jasleen', age: 24, salary: 500, date:'23/02/1994' },
employee[4]={ name: 'Ritik', age: 21, salary: 200, date:'19/11/1995' }
console.log("Employee with salary less than 1000 and age greater than 20: ");
var i;
for(i=0; i<5; i++){
if(employee[i].salary<1000 & employee[i].age>20){
console.log(employee[i]);
employee[i].salary = 5*employee[i].salary;
console.log("updated salary: ");
console.log(employee[i].salary);}}

You might also like