A+ Work




Overview
Project requires you to write web programs that use aspects of JavaScript that you have already learned (selection, loops, arrays, functions, and DOM methods) and in addition to use objects.

PART 2. Practice with objects -  Store the code for each exercise in objects.js

All of the following are Command-Line JavaScript exercises. None of the functions in these objects will contain i/o (no code using prompt, console.log or alert). You do not need to create a web page for this part of the project. Store the code for each exercise in objects.js.

2A) Write an object named car that has the following properties:
make
model
year
speed
description() – returns year + make + model
isSpeedOk(speedLimit) – returns true if speed is not over limit or under limit by more than 10 mph.

Example of console testing and results:
car.make = “Toyota”
car.model = “Prius”
car.year = 2002
car.speed = 44
car.description() => 2002 Toyota Prius
car.isSpeedOk(55) => false – test speeds that are valid and over the limit too.


2B) Write an object named triangle that has the following properties:
sides – this is an array that will contain the three sides of the triangle isTriangle() – this property and the next two are functions- aka methods perimeter() area() – this use the Math object in the calculation

Example of console testing and results:
triangle.sides[0] = 3
triangle.sides[1] = 4
triangle.sides[2] = 5
triangle.isTriangle() => true
triangle.isTriangle() => false
triangle.perimeter() => 12
triangle.area() => 6


2C) Write an object named person that has the following properties:
firstName
lastName
birthday – use the Date object to store the year, month, and day
fullName() – returns the person’s first and last name
age(todaysDate) – pass in a Date object with today’s date

Example of console testing and results:
person.firstName = “Harry”
person.firstName = “Houdini”
person.birthday = new Date(1874, 10, 31)
person.fullName() => Harry Houdini
person.age(Date.now()) => 142


2D) Modify the person object from question 2C by adding the following properties:
facebookPage – the URL for the person’s facebook page
isValidPage() – use RegExp to check the facebookPage URL formatting

Example of console testing and results:
person.facebookPage = “www.facebook.com/thegreathoudini
person.isValidPage() => true
person.facebookPage = “www.headbook.com/thegreathoudini
person.isValidPage() => false – test for everything about the URL to be correct


PART 3. Triangle Web Page - Store the code for each exercise in triangle.js.

3A) Create a web page named triangle.html with the following elements:
Three text-boxes labeled Side 1:, Side 2: and Side 3:
Three click-buttons labeled Legal “Triangle?”, “Area?”, and “Perimeter?”.

Use the Triangle object you created in question 2B with the web page. When any button is clicked, the user inputs are used to set the side property of the Triangle object. For each button:
When “Legal Triangle?” is clicked, the object’s isTriangle method is called. The returned value is displayed in a div on the web page.
When “Perimeter?” is clicked, the object’s perimeter method is called and the returned value is displayed in a div on the web page.
When “Area?” is clicked, the object’s area method is called, and the returned value is displayed in a div on the web page.