-
Create a function,
makeCounter, that takes a parameter,startingValueand returns a function. When called, the returned function should incrementstartingValueand then log the number.const countFromFive = makeCounter(5); countFromFive(); // 6 countFromFive(); // 7 countFromFive(); // 9 const countFromOneHundred = makeCounter(100); countFromOneHundred(); // 101 countFromOneHundred(); // 102 countFromOneHundred(); // 103
-
Create a function called ,
makeFriendList, that returns an object that mutates a private array. The object should have three methods -addFriend,removeFriend,displayFriends.
addFriendtakes a string argument and adds that arguments the private array of friends.addFriendshould return"<<friend>> successfully added.".removeFriendshould take a name and remove that name from the private friend array. If found, it should return"<<friend>> successfully removed.". If not found, it should return"<<friend>> not found.".- Lastly,
displayFriendsshould return the private friends array.
- Create a constructor function,
Teacher. Objects created with theTeacherfunction should have the following properties:
nameschoolgradesubjectstudents(studentsshould be initialized with the value of an empty array)
Teacher objects should have the following two methods added to their prototype:
addStudent, which takes a string student argument and adds it to theTeacherobject'sstudentsproperty. This method should return the total number of students in thestudentsarray.changeSchools, which takes a string school argument and reassigns the object'sschoolproperty to the passed argument. This method should return the name of the new school.const maya = new Teacher('Maya Bhattacharjee', 'The Marcy Lab School', 'post-secondary', 'L&D'); maya.name; // 'Maya Bhattacharjee' maya.school; // 'The Marcy Lab School' maya.grade; // 'post-secondary' maya.subject; // 'L&D' maya.students; // [] maya.addStudent('Paul'); // 1 maya.addStudent('Peter'); // 2 maya.students; // ['Paul', 'Peter'] maya.changeSchools('Uncommon Schools'); // 'Uncommon Schools' maya.school; // 'Uncommon Schools'
-
Create a
Quadrilateralconstructor function. It should be initialized with four arguments that represent the four sides of the quadrilateral. It should have one prototype method:getPerimeter, which returns the perimeter of the quadrilateral.const quad = new Quadrilateral(3, 5, 9, 4); quad.side1; // 3 quad.side2; // 5 quad.side3; // 9 quad.side4; // 4 quad.getPerimeter(); // 21
-
A rectangle is a special type of quadrilateral. Rectangles have four 90 degree angles and, thus, have two pairs of congruent sides. Create a
Rectangleconstructor with an is-a/inheritance relationship with yourQuadrilateralconstructor.Rectangles should be initialized with two arguments, as rectangles can be described by theirlengthandwidth. In addition to an inheritedgetPerimetermethod,Rectangles should have agetAreamethod, that returns the area of theRectangleobject.const rect = new Rectangle(30, 40); rect.side1; // 30 rect.side2; // 40 rect.side3; // 30 rect.side4; // 40 rect.getPerimeter(); // 140 rect.getArea(); // 1200