From 9eb9aa8e5809881c7ffc7fc5db70c6a1a7ebca34 Mon Sep 17 00:00:00 2001 From: JulianAlexander Date: Thu, 22 Mar 2018 03:45:10 +0200 Subject: [PATCH 1/3] Added completed recursion.js and this.js --- src/recursion.js | 5 +++++ src/this.js | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/recursion.js b/src/recursion.js index a6a6c13..f7de875 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 1; + 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..317121a 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 +let example = ['example1', 'example2', 'example3']; // .call +checkPassword.call(me, ...example); // .apply +checkPassword.apply(me, example); // .bind +const checkPass = checkPassword.bind(me, ...example); From 2691bffb89fd16a4910a3c8eca0b172f50edeec3 Mon Sep 17 00:00:00 2001 From: JulianAlexander Date: Fri, 23 Mar 2018 00:05:55 +0200 Subject: [PATCH 2/3] Prototype.js and class.js --- src/class.js | 30 +++++++++++++++++++++++++++++- src/prototype.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/class.js b/src/class.js index 1ec26ec..5604c6c 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,7 +28,27 @@ // 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 */ module.exports = { diff --git a/src/prototype.js b/src/prototype.js index e2494a6..e8981bf 100644 --- a/src/prototype.js +++ b/src/prototype.js @@ -51,6 +51,41 @@ /* eslint-disable no-undef */ +function GameObjecs(attributes) { + this.createdAt = attributes.createdAt; + this.dimensions = attributes.dimensions; +} + +GameObjecs.prototype.destroy = function() { + return 'Game object was removed from the game.'; +} + +function NPC(npcAttributes) { + GameObjecs.call(this, npcAttributes); + this.hp = npcAttributes.hp; + this.name = npcAttributes.name; +} + +NPC.prototype = Object.create(GameObjecs.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; +} + +Humanoid.prototype = Object.create(NPC.prototype); + +Humanoid.prototype.greet = function () { + return `${this.name} offers a greeting in ${this.language}.`; +}; + + module.exports = { GameObject, NPC, From 0bbbb39f913a3b98ef1e000e70f05020a17396de Mon Sep 17 00:00:00 2001 From: JulianAlexander Date: Fri, 23 Mar 2018 02:12:31 +0200 Subject: [PATCH 3/3] Fixed typos, improved code. Added Character to prototype. --- package-lock.json | 25 ++++++++++------- package.json | 5 ++-- src/class.js | 6 ++--- src/prototype.js | 31 ++++++++++++++++----- src/recursion.js | 10 +++---- src/this.js | 2 +- yarn-error.log | 69 +++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 121 insertions(+), 27 deletions(-) create mode 100644 yarn-error.log 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 5604c6c..0aac61e 100644 --- a/src/class.js +++ b/src/class.js @@ -9,7 +9,7 @@ // code here class User { - constructor (options) { + constructor(options) { this.email = options.email; this.password = options.password; } @@ -29,7 +29,7 @@ class User { // code here class Animal { - constructor(options){ + constructor(options) { this.age = options.age; } @@ -48,7 +48,7 @@ class Cat extends Animal { return `${this.name} meowed!`; } } - + /* eslint-disable no-undef */ module.exports = { diff --git a/src/prototype.js b/src/prototype.js index e8981bf..7975245 100644 --- a/src/prototype.js +++ b/src/prototype.js @@ -51,22 +51,22 @@ /* eslint-disable no-undef */ -function GameObjecs(attributes) { +function GameObject(attributes) { this.createdAt = attributes.createdAt; this.dimensions = attributes.dimensions; } -GameObjecs.prototype.destroy = function() { +GameObject.prototype.destroy = function () { return 'Game object was removed from the game.'; -} +}; function NPC(npcAttributes) { - GameObjecs.call(this, npcAttributes); + GameObject.call(this, npcAttributes); this.hp = npcAttributes.hp; this.name = npcAttributes.name; } -NPC.prototype = Object.create(GameObjecs.prototype); +NPC.prototype = Object.create(GameObject.prototype); NPC.prototype.takeDamage = function () { return `${this.name} took damage.`; @@ -76,7 +76,7 @@ function Humanoid(humAttributes) { NPC.call(this, humAttributes); this.faction = humAttributes.faction; this.weapons = humAttributes.weapons; - this.language = humAttributes; + this.language = humAttributes.language; } Humanoid.prototype = Object.create(NPC.prototype); @@ -85,6 +85,25 @@ 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, diff --git a/src/recursion.js b/src/recursion.js index f7de875..b6a9572 100644 --- a/src/recursion.js +++ b/src/recursion.js @@ -3,16 +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 1; - return nFibonacci(n-1) + nFibonacci(n-2); + 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); + if (n === 1) return 1; + return n * nFactorial(n - 1); }; /* Extra Credit */ diff --git a/src/this.js b/src/this.js index 317121a..5d75c31 100644 --- a/src/this.js +++ b/src/this.js @@ -37,7 +37,7 @@ const checkPassword = function comparePasswords(passwordToCompare) { // invoke `checkPassword` on `me` by explicitly setting the `this` context // use .call, .apply, and .bind -let example = ['example1', 'example2', 'example3']; +const example = ['example1', 'example2', 'example3']; // .call checkPassword.call(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)