OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Why am i not able to run my program and my tool not accepting other forms of code? [closed]

  • Thread starter Thread starter user25613389
  • Start date Start date
U

user25613389

Guest
Write a function that takes an object as a parameter and prints all its property names and values. Create a function called 'printObjectProperties' that takes an object as a parameter. Inside the function, use a loop to iterate through the object properties and print each property name and its value in the following format: "Property: <property name>, Value: <value>" Using the following object as test input for the function:

Code:
let person = {
        firstName: 'John',
        lastName: 'Doe',
        age: 30,
        address: {
            street: '123 Main St',
            city: 'Anytown',
            zipCode: '12345'
        },
        hobbies: ['reading', 'swimming', 'coding'],
        isStudent: false,
        
    };

this problem is very tough pl solve it accordingly without using Jason stringy got the following code already but my tool is not accepting this code..so pl give an alternative solution to the image question. Thank You

Code:
function printObjectProperties(obj) {
    for (let key in obj) {
        if (obj.hasOwnProperty(key)) {
            console.log(`Property: ${key}, Value: ${JSON.stringify(obj[key])}`);
        }
    }
}

// Test the function with the provided object
let person = {
    firstName: 'John',
    lastName: 'Doe',
    age: 30,
    address: {
        street: '123 Main St',
        city: 'Anytown',
        zipCode: '12345'
    },
    hobbies: ['reading', 'swimming', 'coding'],
    isStudent: false
};

printObjectProperties(person);

<blockquote>
<p>Write a function that takes an object as a parameter and prints all its property names and values. Create a function called 'printObjectProperties' that takes an object as a parameter. Inside the function, use a loop to iterate through the object properties and print each property name and its value in the following format: "Property: <property name>, Value: <value>" Using the following object as test input for the function:</p>
<pre><code>let person = {
firstName: 'John',
lastName: 'Doe',
age: 30,
address: {
street: '123 Main St',
city: 'Anytown',
zipCode: '12345'
},
hobbies: ['reading', 'swimming', 'coding'],
isStudent: false,

};
</code></pre>
</blockquote>
<p>this problem is very tough pl solve it accordingly without using Jason stringy got the following code already but my tool is not accepting this code..so pl give an alternative solution to the image question. Thank You</p>
<pre><code>function printObjectProperties(obj) {
for (let key in obj) {
if (obj.hasOwnProperty(key)) {
console.log(`Property: ${key}, Value: ${JSON.stringify(obj[key])}`);
}
}
}

// Test the function with the provided object
let person = {
firstName: 'John',
lastName: 'Doe',
age: 30,
address: {
street: '123 Main St',
city: 'Anytown',
zipCode: '12345'
},
hobbies: ['reading', 'swimming', 'coding'],
isStudent: false
};

printObjectProperties(person);
</code></pre>
 

Latest posts

Top