diff --git a/package-lock.json b/package-lock.json index c2d7130..d746e6f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "js-homework-1", + "name": "javascript-ii", "version": "1.0.0", "lockfileVersion": 1, "requires": true, @@ -3695,15 +3695,6 @@ } } }, - "string_decoder": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", - "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", - "dev": true, - "requires": { - "safe-buffer": "5.1.1" - } - }, "string-length": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/string-length/-/string-length-1.0.1.tgz", @@ -3724,6 +3715,15 @@ "strip-ansi": "3.0.1" } }, + "string_decoder": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", + "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==", + "dev": true, + "requires": { + "safe-buffer": "5.1.1" + } + }, "stringstream": { "version": "0.0.5", "resolved": "https://registry.npmjs.org/stringstream/-/stringstream-0.0.5.tgz", @@ -4180,6 +4180,11 @@ "dev": true } } + }, + "yarn": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/yarn/-/yarn-1.5.1.tgz", + "integrity": "sha1-6GgDYOgyrIlSHrgNrTp7wnpAurQ=" } } } diff --git a/package.json b/package.json index f761ac7..b12d150 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "repository": { "type": "git", "url": "git+https://github.com/LambdaSchool/javascript-ii.git" - }, + }, "devDependencies": { "babel-jest": "^19.0.0", "eslint": "^3.17.1", @@ -25,6 +25,7 @@ "babel-preset-es2015": "^6.24.0", "eslint-config-airbnb": "^14.1.0", "eslint-plugin-jsx-a11y": "^3.0.2 || ^4.0.0", - "eslint-plugin-react": "6.9.0" + "eslint-plugin-react": "6.9.0", + "yarn": "^1.5.1" } } diff --git a/src/class.js b/src/class.js index 1ec26ec..0aac61e 100644 --- a/src/class.js +++ b/src/class.js @@ -8,7 +8,15 @@ // Return true if the potential password matches the `password` property. Otherwise return false. // code here - +class User { + constructor(options) { + this.email = options.email; + this.password = options.password; + } + comparePasswords(param) { + return param === this.password; + } +} // Part 2 // Create a class called `Animal` and a class called `Cat` using ES6 classes. // `Cat` should extend the `Animal` class. @@ -20,6 +28,26 @@ // property set on the Cat instance. // code here +class Animal { + constructor(options) { + this.age = options.age; + } + + growOlder() { + return ++this.age; + } +} + +class Cat extends Animal { + constructor(options) { + super(options); + this.name = options.name; + } + + meow() { + return `${this.name} meowed!`; + } +} /* eslint-disable no-undef */ diff --git a/src/prototype.js b/src/prototype.js index e2494a6..7975245 100644 --- a/src/prototype.js +++ b/src/prototype.js @@ -51,6 +51,60 @@ /* eslint-disable no-undef */ +function GameObject(attributes) { + this.createdAt = attributes.createdAt; + this.dimensions = attributes.dimensions; +} + +GameObject.prototype.destroy = function () { + return 'Game object was removed from the game.'; +}; + +function NPC(npcAttributes) { + GameObject.call(this, npcAttributes); + this.hp = npcAttributes.hp; + this.name = npcAttributes.name; +} + +NPC.prototype = Object.create(GameObject.prototype); + +NPC.prototype.takeDamage = function () { + return `${this.name} took damage.`; +}; + +function Humanoid(humAttributes) { + NPC.call(this, humAttributes); + this.faction = humAttributes.faction; + this.weapons = humAttributes.weapons; + this.language = humAttributes.language; +} + +Humanoid.prototype = Object.create(NPC.prototype); + +Humanoid.prototype.greet = function () { + return `${this.name} offers a greeting in ${this.language}.`; +}; + +const JesusChrist = new Humanoid({ + createdAt: new Date(), + dimensions: { + length: 3, + width: 3, + height: 3, + }, + hp: 333, + name: 'JesusChrist', + faction: 'Jewish', + weapons: [ + 'Cross', + 'Pardon', + 'Fishes', + 'Bread', + 'Wine', + ], + language: 'Hebrew', +}); + module.exports = { GameObject, NPC, diff --git a/src/recursion.js b/src/recursion.js index a6a6c13..b6a9572 100644 --- a/src/recursion.js +++ b/src/recursion.js @@ -3,11 +3,16 @@ const nFibonacci = (n) => { // fibonacci sequence: 1 1 2 3 5 8 13 ... // return the nth number in the sequence + if (n === 1) return 1; + if (n === 0) return 0; + return nFibonacci(n - 1) + nFibonacci(n - 2); }; const nFactorial = (n) => { // factorial example: !5 = 5 * 4 * 3 * 2 * 1 // return the factorial of `n` + if (n === 1) return 1; + return n * nFactorial(n - 1); }; /* Extra Credit */ diff --git a/src/this.js b/src/this.js index f0f994c..5d75c31 100644 --- a/src/this.js +++ b/src/this.js @@ -7,10 +7,15 @@ class User { constructor(options) { // set a username and password property on the user object that is created + this.username = options.username; + this.password = options.password; } // create a method on the User class called `checkPassword` // this method should take in a string and compare it to the object's password property // return `true` if they match, otherwise return `false` + checkPassword(str) { + return str === this.password; + } } const me = new User({ @@ -27,13 +32,18 @@ const checkPassword = function comparePasswords(passwordToCompare) { // use `this` to access the object's `password` property. // do not modify this function's parameters // note that we use the `function` keyword and not `=>` + return passwordToCompare === this.password; }; // invoke `checkPassword` on `me` by explicitly setting the `this` context // use .call, .apply, and .bind +const example = ['example1', 'example2', 'example3']; // .call +checkPassword.call(me, ...example); // .apply +checkPassword.apply(me, example); // .bind +const checkPass = checkPassword.bind(me, ...example); diff --git a/yarn-error.log b/yarn-error.log new file mode 100644 index 0000000..da2c087 --- /dev/null +++ b/yarn-error.log @@ -0,0 +1,69 @@ +Arguments: + C:\Program Files\nodejs\node.exe C:\Users\Julian Alexander\AppData\Roaming\npm\node_modules\yarn\bin\yarn.js test recursion + +PATH: + C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\Julian Alexander\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files\nodejs;C:\Program Files\Git\cmd;C:\Users\Julian Alexander\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Microsoft VS Code\bin;C:\Users\Julian Alexander\AppData\Roaming\npm + +Yarn version: + 1.5.1 + +Node version: + 8.9.4 + +Platform: + win32 x64 + +npm manifest: + { + "name": "javascript-ii", + "version": "1.0.0", + "description": "JavaScript II", + "main": "index.js", + "scripts": { + "test": "eslint tests/*.test.js && eslint src/*.js && jest --verbose", + "test:watch": "npm test -- --watch" + }, + "author": "Ben Nelson", + "license": "ISC", + "repository": { + "type": "git", + "url": "git+https://github.com/LambdaSchool/javascript-ii.git" + }, + "devDependencies": { + "babel-jest": "^19.0.0", + "eslint": "^3.17.1", + "eslint-config-airbnb-base": "^11.1.3", + "eslint-plugin-import": "^2.2.0", + "jest": "^19.0.2", + "regenerator-runtime": "^0.10.3" + }, + "dependencies": { + "babel-preset-es2015": "^6.24.0", + "eslint-config-airbnb": "^14.1.0", + "eslint-plugin-jsx-a11y": "^3.0.2 || ^4.0.0", + "eslint-plugin-react": "6.9.0", + "yarn": "^1.5.1" + } + } + +yarn manifest: + No manifest + +Lockfile: + No lockfile + +Trace: + Error: Command failed. + Exit code: 1 + Command: C:\Windows\system32\cmd.exe + Arguments: /d /s /c eslint tests/*.test.js && eslint src/*.js && jest --verbose recursion + Directory: C:\Users\Julian Alexander\Documents\LambdaSchool\javascript-ii + Output: + + at ProcessTermError.MessageError (C:\Users\Julian Alexander\AppData\Roaming\npm\node_modules\yarn\lib\cli.js:186:110) + at new ProcessTermError (C:\Users\Julian Alexander\AppData\Roaming\npm\node_modules\yarn\lib\cli.js:226:113) + at ChildProcess. (C:\Users\Julian Alexander\AppData\Roaming\npm\node_modules\yarn\lib\cli.js:30281:17) + at emitTwo (events.js:126:13) + at ChildProcess.emit (events.js:214:7) + at maybeClose (internal/child_process.js:925:16) + at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)