From c8ff530f549cf61b5829ebbf9dc838e5f69fa871 Mon Sep 17 00:00:00 2001 From: Shayne Smith Date: Tue, 21 Jan 2020 15:27:02 -0600 Subject: [PATCH] Homework Lesson 08 --- Lesson08-JS-V/homework/homework.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Lesson08-JS-V/homework/homework.js b/Lesson08-JS-V/homework/homework.js index e1447c7ef..06d2a29d9 100755 --- a/Lesson08-JS-V/homework/homework.js +++ b/Lesson08-JS-V/homework/homework.js @@ -7,11 +7,26 @@ function createUserClass() { // the constructor should have a method 'sayHi' on its prototype that returns the string 'Hello, my name is {{name}}' // {{name}} should be the name set on each instance // return the class + function User(options) { + this.username = options.username; + this.name = options.name; + this.email = options.email; + this.password = options.password; + } + + User.prototype.sayHi = function () { + return 'Hello, my name is ' + this.name; + }; + + return User; } function addPrototypeMethod(Constructor) { // add a method to the constructor's prototype // the method should be called 'sayHi' and should return the string 'Hello World!' + Constructor.prototype.sayHi = function () { + return 'Hello World!'; + }; } function addReverseString() { @@ -21,6 +36,14 @@ function addReverseString() { // you will need to use 'this' inside of reverse } +addReverseString.prototype.reverse = function () { + let reverseString = ''; + for (let i = 0; i < this.length; i++) { + reverseString = reverseString + reverseString[this.length - (i + 1)]; + } + return reverseString; +}; + // Do not modify code below this line. // -------------------------------- @@ -28,4 +51,4 @@ module.exports = { createUserClass, addPrototypeMethod, addReverseString, -}; +}; \ No newline at end of file