Hp2240 / u1_lab_jurassic_objects

Practice using JavaScript objects by exploring the world of Jurassic Park.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Jurassic Objects Lab

Jurassic Objects

Lab Overview

In this lab, we'll practice using JavaScript objects by exploring the world of Jurassic Park!

Getting Started

  • Fork and Clone this repository
  • cd into the directory
  • code . to open in VSCode
  • Create a new file with touch called script.js. You'll do all your work in this file. Remember, you can test your work by typing node script.js in the terminal.

Lab Instructions

Movie Object (quick warmup)

Create your own JavaScript object representing your favorite movie. I'm going to use Jurassic Park, obviously.

Example:

const myMovie = {
  title: 'Jurassic Park',
  director: 'Stephen Spielberg',
  actors: ['Sam Neill', 'Laura Dern', 'Jeff Goldblum', 'Samuel L. Jackson'],
  releaseYear: 1993,
  duration: 128
}
  1. After you have created your movie object, console log the title of your movie using dot notation
  2. Console log the director's name
  3. Console log the release year
  4. Use bracket notation in combination with dot notation to access one of the actors and console log their name
  5. Maybe your favorite movie came with an extended director's cut - write a statement that increases your movie object's duration by 25 minutes

What else can we do with objects in JavaScript, you may ask?

Hammond

Today we visit Jurassic Park to explore the wild world of objects!

Copy and paste each of these JavaScript snippets into your JavaScript file. You'll be working off of these as we go.

Grant

Part 1

In this first part, we're in Montana to check in with Dr. Grant on his Velociraptor dig.

// copy and paste into your script.js

const montana = {
  scientist: 'Dr. Alan Grant',
  depth: '10 meters',
  dino: 'Velociraptor'
}
  1. Create a variable called guestOfHonor and assign its value to the name of the scientist in montana.

  2. Access the value of the dino key found in the montana object and store it in a variable called cleverGirl.

Nedry

Part 2

Next, we head to Costa Rica, where Dennis Nedry and Dodgson (nobody cares) have already got a plan brewing to steal all of the dinosaur embryos...

// copy and paste into your script.js

const costaRica = {
  programmer: 'Dennis Nedry',
  contact: 'Lewis Dodgson',
  payment: 750000,
  specimens: [
    'Tyrannosaurus Rex',
    'Triceratops',
    'Brachiosaurus',
    'Velociraptor',
    'Dilophasaurus',
    'Gallimimus'
  ],
  menthol: false
}
  1. Store the array of specimens Nedry is supposed to steal in a variable called barbasol.

  2. Make a variable called favoriteDino and assign its value to your favorite dinosaur within specimens.

  3. Add 750000 to Nedry's payment to reflect the total he'll receive if he succeeds.

Part 3

Welcome to Jurassic Park! Things are starting off great! Spared no expense!

// copy and paste into your script.js

const jurassicPark = {
  expenseSpared: 0,
  staff: {
    founder: 'John Hammond',
    programmer: 'Dennis Nedry',
    engineer: 'John Arnold',
    security: 'Robert Muldoon',
    scientist: 'Dr. Henry Wu'
  },
  guests: ['Dr. Alan Grant', 'Dr. Ellie Sattler', 'Dr. Ian Malcolm', 'Donald Gennaro'],
  systems: [
    {
      area: 'Perimeter Fence',
      volts: 10000,
      online: true
    },
    {
      area: 'T-Rex Paddock',
      volts: 10000,
      online: true
    },
    {
      area: 'Velociraptor Pen',
      volts: 10000,
      online: true
    }
  ]
}
  1. Access the founder of Jurassic Park and store his name in an appropriately named variable.

  2. The grandkids have arrived! Add "Tim" and "Lex" to the array of guests. You could assign the values to a specific index number of the array or you could look into .push().

  3. Time for the tour! Everyone into the vehicles! Let's loop through and console log the entire updated list of guests.

  4. Let's add the vehicles to the list of systems. Add the following object to the array of systems:

{
  area: 'Tour Vehicles',
  lockingMechanisms: false,
  online: true
}
  1. Uh oh, fences are failing all over the park. Nedry said a few systems would go offline, didn't he? Switch the online keys to false for the "Perimeter Fence", "T-Rex Paddock", and "Tour Vehicles" systems. Luckily the "Velociraptor Pen" is still online...

ah ah ah

  1. Check the vending machines! Nedry is nowhere to be found! Remove "Dennis Nedry" from the staff object. You could assign his role to an empty string or look into delete.

  2. Well, when you gotta go, you gotta go. Remove "Donald Gennaro" from the list of guests. You could assign his specific index in the array an empty value, or you could look into .splice().

  3. Looks like the "Velociraptor Pen" has gone offline too! Clever girl... Update it's online value to false and remove "Robert Muldoon" from the staff object.

  4. Hold on to your butts. Sadly, remove "John Arnold" from the staff object. He wasn't able to get the systems back online.

Butts

  1. Dr. Sattler has found the main power console. Loop through our entire systems array and switch each online key to true. Mr.Hammond, I think we're back in business!

All done! Great work!

Goldblum

Resources

About

Practice using JavaScript objects by exploring the world of Jurassic Park.