Add a new method to the Shape class's prototype, calcPerimeter(), which calculates its perimeter (the length of the shape's outer edge) and logs the result to the console.
Create a new instance of the Shape class called square. Give it a name of square and a sideLength of 5.
Call your calcPerimeter() method on the instance, to see whether it logs the calculation result to the browser DevTools' console as expected.
Create a new instance of Shape called triangle, with a name of triangle and a sideLength of 3.
Call triangle.calcPerimeter() to check that it works OK.
Task 1 Create constructor function for
Address
class with the following fields:street
houseNumber
city
country
zip
Add to
Person
classaddress
field that will containAddress
object (you can do it viaPerson.prototype.address = new Address()
).Add to
Person
class functionsayAddress()
that returns the all address fields concatenated with space between field values.Create object
pushkin
of classPerson
with following values:firstName
: AlexanderlastName
: Pushkingender
: MaleCall on this object function
sayAddress()
and make sure it returns no addressPopulate address fields of
pushkin
object with following values:street
: embankment river MoykahouseNumber
: 12city
: St Petersburgcountry
: Russiazip
: 191186Call on this object function
sayAddress()
and make sure it now returns the address of Alexander Pushkin.Add value returned by
sayAddress()
function to the bio function result.Task 2
Given constructor function:
Add a new method to the
Shape
class's prototype,calcPerimeter()
, which calculates its perimeter (the length of the shape's outer edge) and logs the result to the console. Create a new instance of theShape
class calledsquare
. Give it a name ofsquare
and asideLength
of5
. Call yourcalcPerimeter()
method on the instance, to see whether it logs the calculation result to the browser DevTools' console as expected. Create a new instance ofShape
calledtriangle
, with a name oftriangle
and asideLength
of3
. Calltriangle.calcPerimeter()
to check that it works OK.