The goal of this workshop is to become more fluent with javascript syntax, vocabulary and to understand how to create and work with objects. Try to write at least the first five exercises yourself to gain confidence and muscle memory. Syntax comes with practice.
-
Create a variable named
personand assign it the value'Mr. Rogers'; -
Log out to the console the length of the person variable.
-
Add the text
" Neighborhood"to the person variable and log out the results to the screen. -
Create another variable named
ageand give it the value 57. -
Concatenate the two variables
personandagetogether in a third variable calledpersonAndAge. Put a space between the two variables. Log that value out to the screen. -
Write a function called
addthat takes in two arguments and returns the result of adding those two arguments together. -
Call the
addfunction you just created with the values6and7and assign that to variable calledthirteen. Logthirteento the screen. -
Call the
addfunction with the values"Star Wars"and"The Force Awakens". Store that information in memory and log it out to the screen. -
Create a function called
printArraythat takes in an array as a parameter. When called, the function should print out any values in the array. Pass in an array calledcerealsthat contains the valuesCap'n Crunch,CheeriosandWheaties. Passcerealsinto theprintArraymethod and observe the results. -
Create a function called
canRetirethat returns true if the argument value is greater than or equal to the retirement age, and false if it is not. Call the function with the value21, store it in a variable, and log it out.
The theme of the modeling exercise will revolve around hotels. The main domain will consist of hotels, hotel rooms, guests etc... If a property you feel integral to the operation of a hotel is not in the list below, feel free to play around with the code.
-
Create an object to represent a hotel. The hotel should have a name, maximum occupancy, star rating and location. The location should, at a minimum, contain the city and state of the hotel.
-
Hotels need rooms, add hotel room objects to the hotel. A hotel room needs to have a unique number and how many people it can fit. The hotel also wants to know if the room has wifi enabled, free cable tv, or a jacuzzi.
-
The hotel needs to communicate how many rooms are available. Alter the hotel model (if need be) to know which rooms are available, then add a method on the hotel that returns whether or not any rooms are available.
-
Hotels get filled with people. Add a method onto the hotel to book a room for guests. Only book rooms that are available. Make sure to keep the hotels state correct, don't double book rooms.
-
To make the previous method more correct, when booking a room, make sure the available room can accommodate the amount of people attempting to book a room.
-
Guests eventually leave. Model out the process of a guest leaving the hotel room. There are many ways to solve this problem depending on your previous choices (i.e does a guest leave a room? does a hotel checkout a guest? both?).
-
Hotels want to make money. Starting with 0, give a value to the amount of money the hotel is making. Then either give a price to each particular room, or a price to the rooms in general. When a room is booked, add more money to the hotels bank.