From 35621b381ce2700acf44b9ee1fceaab42aaf9fcf Mon Sep 17 00:00:00 2001 From: 2940cristian <2940cristian@gmail.com> Date: Wed, 21 Mar 2018 15:43:33 -0700 Subject: [PATCH 1/6] working on recursion, some this done --- package-lock.json | 165 +++++++++++++++++++++++++++++++++++++++++----- package.json | 2 +- src/recursion.js | 8 ++- src/this.js | 9 ++- 4 files changed, 163 insertions(+), 21 deletions(-) diff --git a/package-lock.json b/package-lock.json index c2d7130..c1b8751 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, @@ -127,6 +127,14 @@ "sprintf-js": "1.0.3" } }, + "aria-query": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/aria-query/-/aria-query-0.3.0.tgz", + "integrity": "sha1-y4qZhOKGJxHIPICt5bj1yg3itGc=", + "requires": { + "ast-types-flow": "0.0.7" + } + }, "arr-diff": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/arr-diff/-/arr-diff-2.0.0.tgz", @@ -169,6 +177,15 @@ "integrity": "sha1-odl8yvy8JiXMcPrc6zalDFiwGlM=", "dev": true }, + "array.prototype.find": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/array.prototype.find/-/array.prototype.find-2.0.4.tgz", + "integrity": "sha1-VWpcU2LAhkgyPdrrnenRS8GGTJA=", + "requires": { + "define-properties": "1.1.2", + "es-abstract": "1.11.0" + } + }, "arrify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", @@ -187,6 +204,11 @@ "integrity": "sha1-104bh+ev/A24qttwIfP+SBAasjQ=", "dev": true }, + "ast-types-flow": { + "version": "0.0.7", + "resolved": "https://registry.npmjs.org/ast-types-flow/-/ast-types-flow-0.0.7.tgz", + "integrity": "sha1-9wtzXGvKGlycItmCw+Oef+ujva0=" + }, "async": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/async/-/async-2.5.0.tgz", @@ -1049,6 +1071,11 @@ "es5-ext": "0.10.30" } }, + "damerau-levenshtein": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/damerau-levenshtein/-/damerau-levenshtein-1.0.4.tgz", + "integrity": "sha1-AxkcQyy27qFou3fzpV/9zLiXhRQ=" + }, "dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", @@ -1095,6 +1122,15 @@ "strip-bom": "2.0.0" } }, + "define-properties": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.2.tgz", + "integrity": "sha1-g6c/L+pWmJj7c3GTyPhzyvbUXJQ=", + "requires": { + "foreach": "2.0.5", + "object-keys": "1.0.11" + } + }, "del": { "version": "2.2.2", "resolved": "https://registry.npmjs.org/del/-/del-2.2.2.tgz", @@ -1151,6 +1187,11 @@ "jsbn": "0.1.1" } }, + "emoji-regex": { + "version": "6.5.1", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-6.5.1.tgz", + "integrity": "sha512-PAHp6TxrCy7MGMFidro8uikr+zlJJKJ/Q6mm2ExZ7HwkyR9lSVFfE3kt36qcwa24BQL7y0G9axycGjK1A/0uNQ==" + }, "errno": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/errno/-/errno-0.1.4.tgz", @@ -1169,6 +1210,28 @@ "is-arrayish": "0.2.1" } }, + "es-abstract": { + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.11.0.tgz", + "integrity": "sha512-ZnQrE/lXTTQ39ulXZ+J1DTFazV9qBy61x2bY071B+qGco8Z8q1QddsLdt/EF8Ai9hcWH72dWS0kFqXLxOxqslA==", + "requires": { + "es-to-primitive": "1.1.1", + "function-bind": "1.1.1", + "has": "1.0.1", + "is-callable": "1.1.3", + "is-regex": "1.0.4" + } + }, + "es-to-primitive": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.1.1.tgz", + "integrity": "sha1-RTVSSKiJeQNLZ5Lhm7gfK3l13Q0=", + "requires": { + "is-callable": "1.1.3", + "is-date-object": "1.0.1", + "is-symbol": "1.0.1" + } + }, "es5-ext": { "version": "0.10.30", "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.30.tgz", @@ -1458,6 +1521,40 @@ } } }, + "eslint-plugin-jsx-a11y": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-jsx-a11y/-/eslint-plugin-jsx-a11y-4.0.0.tgz", + "integrity": "sha1-d5uw/nsI2lZKQiYkkR3hAGHgSO4=", + "requires": { + "aria-query": "0.3.0", + "ast-types-flow": "0.0.7", + "damerau-levenshtein": "1.0.4", + "emoji-regex": "6.5.1", + "jsx-ast-utils": "1.4.1", + "object-assign": "4.1.1" + } + }, + "eslint-plugin-react": { + "version": "6.9.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-6.9.0.tgz", + "integrity": "sha1-VMLpkGt2+dEBQgML3DTp1oQKC7I=", + "requires": { + "array.prototype.find": "2.0.4", + "doctrine": "1.5.0", + "jsx-ast-utils": "1.4.1" + }, + "dependencies": { + "doctrine": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-1.5.0.tgz", + "integrity": "sha1-N53Ocw9hZvds76TmcHoVmwLFpvo=", + "requires": { + "esutils": "2.0.2", + "isarray": "1.0.0" + } + } + } + }, "eslint-restricted-globals": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/eslint-restricted-globals/-/eslint-restricted-globals-0.1.1.tgz", @@ -1673,6 +1770,11 @@ "for-in": "1.0.2" } }, + "foreach": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/foreach/-/foreach-2.0.5.tgz", + "integrity": "sha1-C+4AUBiusmDQo6865ljdATbsG5k=" + }, "forever-agent": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", @@ -1699,8 +1801,7 @@ "function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", - "dev": true + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" }, "generate-function": { "version": "2.0.0", @@ -1853,7 +1954,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/has/-/has-1.0.1.tgz", "integrity": "sha1-hGFzP1OLCDfJNh45qauelwTcLyg=", - "dev": true, "requires": { "function-bind": "1.1.1" } @@ -2022,6 +2122,11 @@ "builtin-modules": "1.1.1" } }, + "is-callable": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.3.tgz", + "integrity": "sha1-hut1OSgF3cM69xySoO7fdO52BLI=" + }, "is-ci": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-1.0.10.tgz", @@ -2031,6 +2136,11 @@ "ci-info": "1.1.1" } }, + "is-date-object": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.1.tgz", + "integrity": "sha1-mqIOtq7rv/d/vTPnTKAbM1gdOhY=" + }, "is-dotfile": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/is-dotfile/-/is-dotfile-1.0.3.tgz", @@ -2148,6 +2258,14 @@ "integrity": "sha1-V/4cTkhHTt1lsJkR8msc1Ald2oQ=", "dev": true }, + "is-regex": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.0.4.tgz", + "integrity": "sha1-VRdIm1RwkbCTDglWVM7SXul+lJE=", + "requires": { + "has": "1.0.1" + } + }, "is-resolvable": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-resolvable/-/is-resolvable-1.0.0.tgz", @@ -2157,6 +2275,11 @@ "tryit": "1.0.3" } }, + "is-symbol": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.1.tgz", + "integrity": "sha1-PMWfAAJRlLarLjjbrmaJJWtmBXI=" + }, "is-typedarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", @@ -2172,8 +2295,7 @@ "isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", - "dev": true + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" }, "isexe": { "version": "2.0.0", @@ -2688,6 +2810,11 @@ } } }, + "jsx-ast-utils": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-1.4.1.tgz", + "integrity": "sha1-OGchPo3Xm/Ho8jAMDPwe+xgsDfE=" + }, "kind-of": { "version": "3.2.2", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", @@ -2929,8 +3056,12 @@ "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", - "dev": true + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" + }, + "object-keys": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.0.11.tgz", + "integrity": "sha1-xUYBd4rVYPEULODgG8yotW0TQm0=" }, "object.omit": { "version": "2.0.1", @@ -3695,15 +3826,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 +3846,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", diff --git a/package.json b/package.json index f761ac7..6c36267 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", diff --git a/src/recursion.js b/src/recursion.js index a6a6c13..afd0b75 100644 --- a/src/recursion.js +++ b/src/recursion.js @@ -1,13 +1,17 @@ // Complete the following functions. const nFibonacci = (n) => { - // fibonacci sequence: 1 1 2 3 5 8 13 ... - // return the nth number in the sequence + if() }; const nFactorial = (n) => { // factorial example: !5 = 5 * 4 * 3 * 2 * 1 // return the factorial of `n` + if (n===0) { + return 1 + } else { + return n * nFactorial(n-1); + } }; /* Extra Credit */ diff --git a/src/this.js b/src/this.js index f0f994c..0854405 100644 --- a/src/this.js +++ b/src/this.js @@ -7,12 +7,17 @@ class User { constructor(options) { // set a username and password property on the user object that is created + this.usernamee = 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){ + console.log(str === this.password); + return str === this.password; + } } - const me = new User({ username: 'LambdaSchool', password: 'correcthorsebatterystaple', @@ -23,6 +28,8 @@ const result = me.checkPassword('correcthorsebatterystaple'); // should return ` /* part 2 */ const checkPassword = function comparePasswords(passwordToCompare) { + if (this.password === passwordToCompare) return true; + return false; // recreate the `checkPassword` method that you made on the `User` class // use `this` to access the object's `password` property. // do not modify this function's parameters From e0d339c490be2e2f1e4a84136cf3b3e97971fcef Mon Sep 17 00:00:00 2001 From: 2940cristian <2940cristian@gmail.com> Date: Thu, 22 Mar 2018 12:28:24 -0700 Subject: [PATCH 2/6] fixed some errors on class, recursion, and this --- src/class.js | 32 +++++++++++++++++++++++ src/recursion.js | 14 +++++----- src/this.js | 4 +-- yarn-error.log | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 109 insertions(+), 8 deletions(-) create mode 100644 yarn-error.log diff --git a/src/class.js b/src/class.js index 1ec26ec..2c27a66 100644 --- a/src/class.js +++ b/src/class.js @@ -8,6 +8,23 @@ // 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() { + if (this.password === options.password) { + return true; + } + } +} + +// this.comparePasswords = (password) => { +// if(password === this.password) { +// return true; +// } +// } // Part 2 // Create a class called `Animal` and a class called `Cat` using ES6 classes. @@ -20,6 +37,21 @@ // property set on the Cat instance. // code here +class Animal { + constructor(options) { + this.age = options.age; + } + growOlder() { + this.age = this.age + 1; + } +} + +class Cat extends Animal { + meow() { + return this.name + ' meowed!'; + } +} + /* eslint-disable no-undef */ diff --git a/src/recursion.js b/src/recursion.js index afd0b75..68cacb5 100644 --- a/src/recursion.js +++ b/src/recursion.js @@ -1,17 +1,19 @@ // Complete the following functions. const nFibonacci = (n) => { - if() + // fibonacci sequence: 1 1 2 3 5 8 13 ... + // return the nth number in the sequence + if (n <= 1) { + return n; + } 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===0) { - return 1 - } else { - return n * nFactorial(n-1); - } + if (n === 0) { + return 1; + } return n * nFactorial(n - 1); }; /* Extra Credit */ diff --git a/src/this.js b/src/this.js index 0854405..3f11405 100644 --- a/src/this.js +++ b/src/this.js @@ -13,8 +13,8 @@ class User { // 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){ - console.log(str === this.password); + checkPassword(str) { + // console.log(str === this.password); return str === this.password; } } diff --git a/yarn-error.log b/yarn-error.log new file mode 100644 index 0000000..51c00ff --- /dev/null +++ b/yarn-error.log @@ -0,0 +1,67 @@ +Arguments: + C:\Program Files\nodejs\node.exe C:\Program Files (x86)\Yarn\bin\yarn.js test class.test.js + +PATH: + C:\Users\2940c\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\2940c\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Program Files\Git\cmd;C:\Program Files\nodejs;C:\Program Files (x86)\Yarn\bin;C:\Users\2940c\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Microsoft VS Code\bin;C:\Users\2940c\AppData\Local\Microsoft\WindowsApps;C:\Users\2940c\AppData\Roaming\npm;C:\Users\2940c\AppData\Local\Yarn\bin;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl + +Yarn version: + 1.5.1 + +Node version: + 9.7.1 + +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 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 class.test.js + Directory: C:\Users\2940c\Desktop\Lambda\JavaScript-II + Output: + + at ProcessTermError.MessageError (C:\Program Files (x86)\Yarn\lib\cli.js:186:110) + at new ProcessTermError (C:\Program Files (x86)\Yarn\lib\cli.js:226:113) + at ChildProcess. (C:\Program Files (x86)\Yarn\lib\cli.js:30281:17) + at ChildProcess.emit (events.js:127:13) + at maybeClose (internal/child_process.js:936:16) + at Process.ChildProcess._handle.onexit (internal/child_process.js:220:5) From d9dbb17b90cce2ce33f7aab8fd6c76a3a373ed3c Mon Sep 17 00:00:00 2001 From: 2940cristian <2940cristian@gmail.com> Date: Thu, 22 Mar 2018 12:47:53 -0700 Subject: [PATCH 3/6] completed classes challenge --- src/class.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/class.js b/src/class.js index 2c27a66..8c9de7e 100644 --- a/src/class.js +++ b/src/class.js @@ -13,10 +13,10 @@ class User { this.email = options.email; this.password = options.password; } - comparePasswords() { - if (this.password === options.password) { + comparePasswords(password) { + if (this.password === password) { return true; - } + } return false; } } @@ -43,12 +43,17 @@ class Animal { } growOlder() { this.age = this.age + 1; + return this.age; } } class Cat extends Animal { + constructor(options) { + super(options, options); + this.name = options.name; + } meow() { - return this.name + ' meowed!'; + return `${this.name} meowed!`; } } From 1a4e4ce7fa9ac034e1c40b399b17ff4a8839e2b5 Mon Sep 17 00:00:00 2001 From: 2940cristian <2940cristian@gmail.com> Date: Thu, 22 Mar 2018 14:04:25 -0700 Subject: [PATCH 4/6] prototype challenge complete --- src/prototype.js | 48 ++++++++++++++++++++++++++++++++++++++++-------- yarn-error.log | 4 ++-- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/prototype.js b/src/prototype.js index e2494a6..0c5869c 100644 --- a/src/prototype.js +++ b/src/prototype.js @@ -1,31 +1,63 @@ /* Object oriented design is commonly used in video games. For this part of the assignment you will be implementing several classes with their correct inheritance heirarchy. - In this file you will be creating three classes: GameObject createdAt dimensions destroy() // prototype method -> returns the string 'Game object was removed from the game.' + */ + function GameObject(object) { + this.createdAt = object.createdAt; + this.dimensions = object.dimensions; + } + GameObject.prototype.destroy = () => { + return 'Game object was removed from the game.'; + }; + /* NPC hp name takeDamage() // prototype method -> returns the string ' took damage.' // should inherit destroy() from GameObject's prototype + */ + function NPC(npc) { + GameObject.call(this, npc); + this.hp = npc.hp; + this.name = npc.name; + // GameObject.call(this, options); + } + NPC.prototype = Object.create(GameObject.prototype); + NPC.prototype.takeDamage = function () { + return `${this.name} took damage.`; + }; + /* Humanoid faction weapons language greet() // prototype method -> returns the string ' offers a greeting in .' // should inherit destroy() from GameObject through NPC - // should inherit takeDamage() from NPC + // should inherit takeDamage() from NPC */ + function Humanoid(player) { + NPC.call(this, player); + GameObject.call(this, player); + this.faction = player.faction; + this.weapons = player.weapons; + this.language = player.language; + } + // Humanoid.prototype = Object.create(GameObject.prototype); + Humanoid.prototype = Object.create(NPC.prototype); + Humanoid.prototype.greet = function () { + return `${this.name} offers a greeting in ${this.language}.`; + }; + /* Inheritance chain: Humanoid -> NPC -> GameObject Instances of Humanoid should have all of the same properties as NPC and GameObject. Instances of NPC should have all of the same properties as GameObject. - Example: const hamsterHuey = new Humanoid({ @@ -51,8 +83,8 @@ /* eslint-disable no-undef */ -module.exports = { - GameObject, - NPC, - Humanoid, -}; + module.exports = { + GameObject, + NPC, + Humanoid, + }; diff --git a/yarn-error.log b/yarn-error.log index 51c00ff..4c35ba6 100644 --- a/yarn-error.log +++ b/yarn-error.log @@ -1,5 +1,5 @@ Arguments: - C:\Program Files\nodejs\node.exe C:\Program Files (x86)\Yarn\bin\yarn.js test class.test.js + C:\Program Files\nodejs\node.exe C:\Program Files (x86)\Yarn\bin\yarn.js test prototype.test.js PATH: C:\Users\2940c\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\2940c\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Program Files\Git\cmd;C:\Program Files\nodejs;C:\Program Files (x86)\Yarn\bin;C:\Users\2940c\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Microsoft VS Code\bin;C:\Users\2940c\AppData\Local\Microsoft\WindowsApps;C:\Users\2940c\AppData\Roaming\npm;C:\Users\2940c\AppData\Local\Yarn\bin;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl @@ -55,7 +55,7 @@ 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 class.test.js + Arguments: /d /s /c eslint tests/*.test.js && eslint src/*.js && jest --verbose prototype.test.js Directory: C:\Users\2940c\Desktop\Lambda\JavaScript-II Output: From 2d10d2fe2e9f29aa01221727eb1bc3294193238c Mon Sep 17 00:00:00 2001 From: 2940cristian <2940cristian@gmail.com> Date: Thu, 22 Mar 2018 14:19:56 -0700 Subject: [PATCH 5/6] 'this' challenge completed --- src/this.js | 25 +++++++++++++++++-------- yarn-error.log | 4 ++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/this.js b/src/this.js index 3f11405..48e6c94 100644 --- a/src/this.js +++ b/src/this.js @@ -14,22 +14,29 @@ class User { // 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) { - // console.log(str === this.password); - return str === this.password; - } + if(str === this.password) { + console.log("true") + return true; + } console.log("false"); + return false; + } } const me = new User({ username: 'LambdaSchool', password: 'correcthorsebatterystaple', }); -const result = me.checkPassword('correcthorsebatterystaple'); // should return `true` - +const result = me.checkPassword('lol'); // should return `true` or 'false' if false +// will return false as a test^^^ /* part 2 */ const checkPassword = function comparePasswords(passwordToCompare) { - if (this.password === passwordToCompare) return true; + if (passwordToCompare === this.password) { + console.log("true test 2"); + return true; + }console.log("false test 2"); return false; + // recreate the `checkPassword` method that you made on the `User` class // use `this` to access the object's `password` property. // do not modify this function's parameters @@ -40,7 +47,9 @@ const checkPassword = function comparePasswords(passwordToCompare) { // use .call, .apply, and .bind // .call - +checkPassword.call(me, 'correcthorseblatterystaple'); +// will also return false as a test^^^^^ // .apply - +checkPassword.apply(me, ['correcthorsebatterystaple']); // .bind +checkPassword.bind(me, 'correcthorsebatterystaple')(); diff --git a/yarn-error.log b/yarn-error.log index 4c35ba6..ef9d67f 100644 --- a/yarn-error.log +++ b/yarn-error.log @@ -1,5 +1,5 @@ Arguments: - C:\Program Files\nodejs\node.exe C:\Program Files (x86)\Yarn\bin\yarn.js test prototype.test.js + C:\Program Files\nodejs\node.exe C:\Program Files (x86)\Yarn\bin\yarn.js test recursion.test.js PATH: C:\Users\2940c\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\2940c\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Program Files\Git\cmd;C:\Program Files\nodejs;C:\Program Files (x86)\Yarn\bin;C:\Users\2940c\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Microsoft VS Code\bin;C:\Users\2940c\AppData\Local\Microsoft\WindowsApps;C:\Users\2940c\AppData\Roaming\npm;C:\Users\2940c\AppData\Local\Yarn\bin;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl @@ -55,7 +55,7 @@ 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 prototype.test.js + Arguments: /d /s /c eslint tests/*.test.js && eslint src/*.js && jest --verbose recursion.test.js Directory: C:\Users\2940c\Desktop\Lambda\JavaScript-II Output: From f99552e7cec5223533a147e68867dbc4c76023d7 Mon Sep 17 00:00:00 2001 From: 2940cristian <2940cristian@gmail.com> Date: Thu, 22 Mar 2018 15:31:51 -0700 Subject: [PATCH 6/6] playing with the code and attempthing a sprint challenge --- src/class.js | 11 ++--------- src/prototype.js | 28 ++++++++++++++-------------- src/recursion.js | 12 ++++++++++-- src/this.js | 18 +++++++++--------- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/class.js b/src/class.js index 8c9de7e..c1e54d4 100644 --- a/src/class.js +++ b/src/class.js @@ -19,16 +19,9 @@ class User { } return false; } } - -// this.comparePasswords = (password) => { -// if(password === this.password) { -// return true; -// } -// } - // Part 2 // Create a class called `Animal` and a class called `Cat` using ES6 classes. -// `Cat` should extend the `Animal` class. +// `Cat` should extend the `Animal` class. // Animal and Cat should both have a parameter called `options` in their constructors. // Animal should have the property `age` that's set in the constructor and the method // `growOlder` that returns the age after incrementing it. @@ -47,6 +40,7 @@ class Animal { } } + class Cat extends Animal { constructor(options) { super(options, options); @@ -59,7 +53,6 @@ class Cat extends Animal { /* eslint-disable no-undef */ - module.exports = { User, Cat, diff --git a/src/prototype.js b/src/prototype.js index 0c5869c..68064cc 100644 --- a/src/prototype.js +++ b/src/prototype.js @@ -1,15 +1,15 @@ /* Object oriented design is commonly used in video games. For this part of the assignment you will be implementing several classes with their correct inheritance heirarchy. - In this file you will be creating three classes: + In this file you will be creating three classes: GameObject createdAt dimensions destroy() // prototype method -> returns the string 'Game object was removed from the game.' */ - function GameObject(object) { - this.createdAt = object.createdAt; - this.dimensions = object.dimensions; + function GameObject(options) { + this.createdAt = options.createdAt; + this.dimensions = options.dimensions; } GameObject.prototype.destroy = () => { return 'Game object was removed from the game.'; @@ -22,10 +22,10 @@ takeDamage() // prototype method -> returns the string ' took damage.' // should inherit destroy() from GameObject's prototype */ - function NPC(npc) { - GameObject.call(this, npc); - this.hp = npc.hp; - this.name = npc.name; + function NPC(options) { + GameObject.call(this, options); + this.hp = options.hp; + this.name = options.name; // GameObject.call(this, options); } @@ -42,12 +42,12 @@ // should inherit destroy() from GameObject through NPC // should inherit takeDamage() from NPC */ - function Humanoid(player) { - NPC.call(this, player); - GameObject.call(this, player); - this.faction = player.faction; - this.weapons = player.weapons; - this.language = player.language; + function Humanoid(options) { + NPC.call(this, options); + GameObject.call(this, options); + this.faction = options.faction; + this.weapons = options.weapons; + this.language = options.language; } // Humanoid.prototype = Object.create(GameObject.prototype); Humanoid.prototype = Object.create(NPC.prototype); diff --git a/src/recursion.js b/src/recursion.js index 68cacb5..5fbebed 100644 --- a/src/recursion.js +++ b/src/recursion.js @@ -1,7 +1,7 @@ // Complete the following functions. const nFibonacci = (n) => { - // fibonacci sequence: 1 1 2 3 5 8 13 ... + // fibonacci sequence: 1 1 2 3 5 8 13 ... // return the nth number in the sequence if (n <= 1) { return n; @@ -17,10 +17,18 @@ const nFactorial = (n) => { }; /* Extra Credit */ -const checkMatchingLeaves = (obj) => { +const checkMatchingLeaves = (obj, c) => { // return true if every property on `obj` is the same // otherwise return false + if (Object.keys(obj)[0] !== Object.keys(obj)[c]) { + return false; + } else if (Object.keys(obj)[0] === Object.keys(obj)[c]) { + return true; + } + checkMatchingLeaves(c + 1); }; +// attempted but failed, oh well! + /* eslint-enable no-unused-vars */ diff --git a/src/this.js b/src/this.js index 48e6c94..169a2ae 100644 --- a/src/this.js +++ b/src/this.js @@ -14,12 +14,12 @@ class User { // 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) { - if(str === this.password) { - console.log("true") - return true; - } console.log("false"); - return false; - } + if (str === this.password) { + console.log('true'); + return true; + } console.lo('false'); + return false; + } } const me = new User({ username: 'LambdaSchool', @@ -32,12 +32,12 @@ const result = me.checkPassword('lol'); // should return `true` or 'false' if fa const checkPassword = function comparePasswords(passwordToCompare) { if (passwordToCompare === this.password) { - console.log("true test 2"); + console.log('true test 2'); return true; - }console.log("false test 2"); + }console.log('false test 2'); return false; - // recreate the `checkPassword` method that you made on the `User` class + // recreate the `checkPassword` method that you made on the `User` class // 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 `=>`