var marketer = {
name: "Jacob Drew",
sclass: "VII",
rollno: 10
};
console.log (marketer);
var marketer = {
name: "Jacob Drew",
sclass: "VII",
rollno: 10
};
delete marketer.rollno;
console.log("After deletion:");
console.log(marketer);
var student = {
name : "Jacob Drew",
sclass : "VII",
rollno : 10 };
console.log(Object.keys(marketer).length);
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
}
];
for (var i = 0; i < library.length; i++) {
var book = library[i];
var bookInfo = book.title + ' by ' + book.author;
if (book.readingStatus) {
console.log('You have finished reading ' + bookInfo);
} else {
console.log('You have not finished reading ' + bookInfo);
}
}
class Cylinder {
constructor(radius, height) {
this.radius = radius;
this.height = height;
}
getVolume() {
const volume = Math.PI * Math.pow(this.radius, 2) * this.height;
return volume.toFixed(4);
}
}
const radius = 3.5;
const height = 8.2;
const cylinder = new Cylinder(radius, height);
const volume = cylinder.getVolume();
console.log("Volume of the cylinder: " + volume);
function bubbleSort(arr) {
var len = arr.length;
for (var i = 0; i < len - 1; i++) {
for (var j = 0; j < len - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
var temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
return arr;
}
var data = [6, 4, 0, 3, -2, 1];
var sortedData = bubbleSort(data);
console.log("Sorted data: " + sortedData);
function getSubsets(str) {
var subsets = [];
for (var i = 0; i < str.length; i++) {
for (var j = i + 1; j <= str.length; j++) {
var subset = str.substring(i, j);
subsets.push(subset);
}
}
return subsets;
}
var input = "dog";
var result = getSubsets(input);
console.log(result);
function formatTimeUnit(unit) {
return unit < 10 ? "0" + unit : unit;
}
function displayTime() {
var currentTime = new Date();
var hours = formatTimeUnit(currentTime.getHours());
var minutes = formatTimeUnit(currentTime.getMinutes());
var seconds = formatTimeUnit(currentTime.getSeconds());
var timeString = hours + ":" + minutes + ":" + seconds;
console.log(timeString);
}
setInterval(displayTime, 1000);
function calculateArea(radius) {
return Math.PI * radius * radius;
}
function calculatePerimeter(radius) {
return 2 * Math.PI * radius;
}
var adius = parseFloat(console.log("Enter the radius of the circle:"));
var area = calculateArea(radius);
var perimeter = calculatePerimeter(adius);
console.log("Area: " + area.toFixed(2));
console.log("Perimeter: " + perimeter.toFixed(2));
var library = [
{
title: 'The Road Ahead',
author: 'Bill Gates',
libraryID: 1254
},
{
title: 'Walter Isaacson',
author: 'Steve Jobs',
libraryID: 4264
},
{
title: 'Mockingjay: The Final Book of The Hunger Games',
author: 'Suzanne Collins',
libraryID: 3245
}
];
library.sort(function(a, b) {
return a.libraryID - b.libraryID;
});
console.log(library);
function allProperties(obj) {
var properties = Object.getOwnPropertyNames(obj);
var methods = properties.filter(function (property) {
return typeof obj[property] === 'function';
});
return methods;
}
console.log(allProperties(Array));
function praseUrl() {
let url = 'https://www.example.com';
console.log(url)
}
praseUrl();
function getAllPropertyNames(obj) {
var propertyNames = [];
function getProperties(obj) {
if (obj === null || obj === undefined) {
return;
}
var currentPropertyNames = Object.getOwnPropertyNames(obj);
propertyNames = propertyNames.concat(currentPropertyNames);
var prototype = Object.getPrototypeOf(obj);
getProperties(prototype);
}
getProperties(obj);
return propertyNames;
}
var obj = {};
obj.name = 'John';
obj.age = 30;
function Person() {}
Person.prototype = obj;
var person = new Person();
var allPropertyNames = getAllPropertyNames(person);
console.log(allPropertyNames);
function objectToList(obj) {
return Object.entries(obj);
}
var sampleObject = {
name: 'John',
age: 30,
city: 'New York'
};
var keyValuePairs = objectToList(sampleObject);
console.log(keyValuePairs);
function reverseObject(obj) {
var reversedObj = {};
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
reversedObj[obj[key]] = key;
}
}
return reversedObj;
}
var sampleObject = {
name: 'Samuel',
age: 20,
city: 'Enugu'
};
var reversedObject = reverseObject(sampleObject);
console.log(reversedObject);
function hasProperty(obj, propertyName) {
return propertyName in obj;
}
var sampleObject = {
name: 'John',
age: 30,
city: 'New York'
};
var hasAgeProperty = hasProperty(sampleObject, 'age');
console.log('Object has "age" property:', hasAgeProperty);
var hasGenderProperty = hasProperty(sampleObject, 'gender');
console.log('Object has "gender" property:', hasGenderProperty);
function isDOMElement(value) {
return value instanceof Element || value instanceof HTMLDocument;
}
var element = document.getElementById('myElement');
var isElement = isDOMElement(element);
console.log('Is element:', isElement);
var notAnElement = 'This is a string';
var isNotElement = isDOMElement(notAnElement);
console.log('Is not element:', isNotElement);