1. CS425 - Web and Mobile Software Engineering
Dr. Lilia Sfaxi
1 février 2017
JavaScript Objects
Exercises
Sample Object:
var student = {
name : "David Rayy",
sclass : "VI",
rollno : 12
};
I. Write a JavaScript program to list the properties of a JavaScript object.
II. Write a JavaScript program to delete the rollno property from the following object.
Also print the object before and after deleting the property.
III. Write a JavaScript program to get the length of a JavaScript object. (Use the
preceding student object as a sample object).
IV. Write a JavaScript program to display the reading status (i.e. display book name,
author name and reading status) of the following books.
var library = [
{
author: 'Bill Gates',
title: 'The Road Ahead',
readingStatus: true
},
{
author: 'Steve Jobs',
title: 'Walter Isaacson',
readingStatus: true
},
{
author: 'Suzanne Collins',
title: 'Mockingjay: The Final Book of The Hunger Games',
readingStatus: false
}];
JAVASCRIPT OBJECTS DR. LILIA SFAXI !1
MedTech
2. V. Write a JavaScript program to calculate the area and perimeter of a circle. Go to the
editor. Note : Create two methods to calculate the area and perimeter. The radius of the
circle will be supplied by the user.
VI. Write a JavaScript function to print all the methods in a JavaScript object.
var student = {
name : "David Rayy",
sclass : "VI",
display: function(){
console.log(this.name+" - sclass: « +this.sclass)
}
};
Expected Output: display
VII.Write a JavaScript function to get a copy of the object where the keys have become
the values and the values the keys.
Sample object:
var student = {
name : "David Rayy",
sclass : "VI",
rollno : 12
};
Expected result:
newObj = {
"David Rayy": "name",
"VI": "sclass",
12: « rollno"
};
JAVASCRIPT OBJECTS DR. LILIA SFAXI !2