Created
September 20, 2025 17:10
-
-
Save davidystephenson/c668603dd928ceac51845de4c05cdcf4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Question 1: Declare an object named "person" with properties "name", "age", and "city" and set their respective values to "John", 30, and "New York". | |
| var person = { | |
| name: 'John', | |
| age: 30, | |
| city: 'New York' | |
| } | |
| console.log('person', person) | |
| // Question 2: Declare an object named "book" with properties "title", "author", and "year" and set their respective values to "The Great Gatsby", "F. Scott Fitzgerald", and 1925. Access the "author" property and store its value in a variable called "authorName". | |
| var book = { | |
| title: 'The Great Gatsby', | |
| author: 'F. Scott Fitzgerald', | |
| year: 1925 | |
| } | |
| var authorName = book.author | |
| console.log('authorName', authorName) | |
| // Question 3: Declare an object named "employee" with properties "name", "age", and "city". Delete the "city" property from the object. | |
| var employee = { | |
| name: 'John', | |
| age: 30, | |
| city: 'New York' | |
| } | |
| delete employee.city | |
| console.log('employee', employee) | |
| // Question 4: Create a "game" object having following information - | |
| // gamingPlatform as "Roblox", minimumAge as 10, programmingLanguage as "Lua". | |
| // Display object information. | |
| // Change the value of minimumAge as 12. | |
| // Display object information again. | |
| var game = { | |
| gamingPlatform: 'Roblox', | |
| minimumAge: 10, | |
| programmingLanguage: 'Lua' | |
| } | |
| console.log('game', game) | |
| game.minimumAge = 12 | |
| console.log('game 2:', game) | |
| // Question 5: Given an array "employees" of Javascript objects. Write a code to iterate through | |
| // each of these objects using forEach method and extract first name and last name of each employee. | |
| var employees = [ | |
| { first: 'John', last: 'Doe' }, | |
| { first: 'Francis', last: 'Fitzgerald' }, | |
| { first: 'Zelda', last: 'Fitzgerald' } | |
| ] | |
| employees.forEach(employee => { | |
| console.log('first', employee.first) | |
| console.log('last', employee.last) | |
| }) | |
| // Question 6: Declare an object named "toy" with an empty object as its initial value. | |
| // Add the properties "name" and "category" with values "Super Space Rocket" and "Action Figures & Playsets" respectively. | |
| var toy = {} | |
| toy.name = 'Super Space Rocket' | |
| toy.category = 'Action Figures & Playsets' | |
| console.log('toy', toy) | |
| // Question 7: Given an array of employees objects, define a function to find employee with the least salary. | |
| var employees = [ | |
| { first: 'Francis', last: 'Fitzgerald', salary: 100 }, | |
| { first: 'Zelda', last: 'Fitzgerald', salary: 1000000 }, | |
| { first: 'John', last: 'Doe', salary: 10 }, | |
| ] | |
| var result = employees[0] | |
| for (var employee of employees) { | |
| var lower = employee.salary < result.salary | |
| if (lower) { | |
| result = employee | |
| } | |
| } | |
| console.log('result', result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment