Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Last active April 12, 2024 07:48
Show Gist options
  • Save harrisonmalone/ce59a6132000d4f26d0c1fd92109fdc7 to your computer and use it in GitHub Desktop.
Save harrisonmalone/ce59a6132000d4f26d0c1fd92109fdc7 to your computer and use it in GitHub Desktop.

Destructuring Challenge

  1. Print blue and 1996 to the screen using object destructuring
const car = {
    colour: 'blue', 
    brand: 'ford',
    gears: 4,
    year: '1996',
    manual: true 
}
  1. Make the code below run (with object destructuring), you need to reassign the languages key to a new name
const school = {
    name: 'Coder Academy',
    students: 36,
    address: '120 Spencer Street',
    languages: [
        'Ruby',
        'JavaScript'
    ]
}
console.log(programmingLanguages)
  1. Print Melbourne and 36 to the screen using object destructuring
const schools = {
    name: 'Coder Academy',
    languages: [
        'Ruby',
        'JavaScript'
    ],
    cities: [
        {
            name: 'Melbourne',
            address: '120 Spencer Street',
            students: 36
        },
        {
            name: 'Sydney',
            address: '1 Martin Place',
            students: 30
        }
    ]    
}
  1. Make the code below run (with object destructuring), we want to print Monica Seles' US Open wins to the screen
const sport = {
    name: 'Tennis',
    number_of_players: [
        {
            type: 'singles',
            players: 2
        },
        {
            type: 'doubles',
            players: 4
        }
    ],
    key_players: [
        {
            type: 'female',
            players: [
                {
                    name: 'Steffi Graf',
                    total_majors: 22,
                    slam_breakdown: {
                        aus_open: [1988, 1989, 1990, 1994],
                        roland_garros: [1987, 1988, 1993, 1995, 1996, 1999],
                        wimbledon: [1988, 1989, 1991, 1992, 1993, 1995, 1996],
                        us_open: [1988, 1989, 1993, 1995, 1996]
                    }
                },
                {
                    name: 'Monica Seles',
                    total_majors: 9,
                    slam_breakdown: {
                        aus_open: [1991, 1992, 1993, 1996],
                        roland_garros: [1990, 1991, 1992],
                        wimbledon: [],
                        us_open: [1991, 1992]
                    }
                }
            ]
        }
    ]
}
console.log(monicaUsOpenWins)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment