Westworld Lab
Title: OOP Westworld Lab Type: Lab Duration: 1 hr Creator: Thom Page Modified by: Kristyn Bryan, Taylor Darneille Topics: Object methods, Constructors
OOP Westworld Lab
WESTWORLD

From Wikipedia:
[Westworld] takes place in fictional Westworld, a technologically advanced, Western-themed amusement park populated completely by synthetic androids dubbed "hosts".
Make your own Westworld hosts
You are going to make some androids for the Westworld park!
Create a host
Make an object called host that has the following properties:
name
occupation
Give your host object a method called saySpecs.
The saySpecs method should output a message from the host listing the host's specifications -- the host's name and occupation:
Create some basic hosts
Now let's make a class so that we can easily make many hosts.
Make a class called BasicHost that takes parameters for name and occupation.
Make it so the BasicHost function will spit out a host object.
Output:
Make another instance with the BasicHost called host2.
Augment your basic hosts
Give your class a saySpecs method that will log all of the specs of the instance.
Create a few more basic host objects with your constructor.
Invoke the saySpecs function on those hosts.
Populate the world with hosts
How many hosts can we make???? We are going to populate an array with host objects using a for loop.
We will need a pool of names to draw from. Make an array called names, and add in a few names. Here's one if you want to use it:
taken from http://listofrandomnames.com/
Make an array called occupations and add in a few occupations. Here's one if you want to use it:
Make an empty array called hostArray. This is where we will store our host objects.
Write a for loop that will will run 100 times. Inside the for loop, push a new BasicHost into the array:
After the loop, console.log the hostArray.
We have 100 hosts, but they have no values for their attributes:

FIGURE IT OUT
Make it so that when a new BasicHost is pushed into the array, that host will be assigned a random name and random occupation from the names and occupations arrays.
If it works, you should have an array of objects of a variety of different hosts.
hostArray:

Make a host speak.
hostArray[55].saySpecs()
Bonus
Make your hosts more interesting by giving them random numerical values from 1-20 for personality traits (how ever many you would like):
Empathy
Loyalty
Aggression
Curiosity
Bulk Apperception
Etc.
Last updated
Was this helpful?