From 128ff8902cc336d74ffed2a0fbb2e08d0f789913 Mon Sep 17 00:00:00 2001 From: jasvictoria Date: Tue, 11 Apr 2017 09:19:48 -0700 Subject: [PATCH 1/4] Day 1 Progress --- README.md | 2 +- bike-shop/src/stage1-literals.js | 10 ++++++++++ jsinfo/helloObject.js | 9 +++++++++ jsinfo/multNumericBy2.js | 16 ++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 jsinfo/helloObject.js create mode 100644 jsinfo/multNumericBy2.js diff --git a/README.md b/README.md index 54b2dfb..c5fe9e1 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ This is the base repository for the [Init 2: OOP Practice with Bike Shop](http:/ 1. Install Node.js and npm
Follow the instructions in this [Treehouse blog](http://blog.teamtreehouse.com/install-node-js-npm-mac) to install [Node.js](https://nodejs.org/en/) and [npm](https://www.npmjs.com/) using Homebrew on your Mac. 1. Do your work in the subdirectories (`bike-shop/`, `jsinfo/`, `music-player/`) -
Be sure to read the `README.md` files in the subdiretories as well. +
Be sure to read the `README.md` files in the subdirectories as well. ## Resources diff --git a/bike-shop/src/stage1-literals.js b/bike-shop/src/stage1-literals.js index c749dd2..19ba66a 100644 --- a/bike-shop/src/stage1-literals.js +++ b/bike-shop/src/stage1-literals.js @@ -2,4 +2,14 @@ const myBike = { // your code here } +let user = {} +user.name = "John" +user.surname = "Smith" +//user.name = "Pete" +Object.assign (user, {name: "Pete", isAdmin: true}) +delete user.name +//Object.assign (user, {name: "Pete", isAdmin: true}) + +console.log(user) + module.exports = myBike diff --git a/jsinfo/helloObject.js b/jsinfo/helloObject.js new file mode 100644 index 0000000..bc1a78b --- /dev/null +++ b/jsinfo/helloObject.js @@ -0,0 +1,9 @@ +let user = {} +user.name = "John" +user.surname = "Smith" +user.name = "Pete" +//Object.assign (user, {name: "Pete", isAdmin: true}) +delete user.name +//Object.assign (user, {name: "Pete", isAdmin: true}) + +console.log(user) diff --git a/jsinfo/multNumericBy2.js b/jsinfo/multNumericBy2.js new file mode 100644 index 0000000..ba0cf25 --- /dev/null +++ b/jsinfo/multNumericBy2.js @@ -0,0 +1,16 @@ +let fee = { adult: 5, child: 10, title: "Entrance Fee"} + + + + function multiplyNumeric(obj) { + for (let key in obj){ + if (typeof obj[key] == 'number'){ + obj[key] *= 2 + } + } + } + //if value === num + //mult value x + + +console.log(multiplyNumeric(fee)) From 1eacbec4f5375a5611ebab577f63e700399419d2 Mon Sep 17 00:00:00 2001 From: jasvictoria Date: Tue, 11 Apr 2017 09:26:48 -0700 Subject: [PATCH 2/4] Day 1 Progress --- jsinfo/multNumericBy2.js | 1 + 1 file changed, 1 insertion(+) diff --git a/jsinfo/multNumericBy2.js b/jsinfo/multNumericBy2.js index ba0cf25..0cc3168 100644 --- a/jsinfo/multNumericBy2.js +++ b/jsinfo/multNumericBy2.js @@ -14,3 +14,4 @@ let fee = { adult: 5, child: 10, title: "Entrance Fee"} console.log(multiplyNumeric(fee)) +//github From acfd891588cfe398ef3315141a4daf14aa8421ec Mon Sep 17 00:00:00 2001 From: jasvictoria Date: Tue, 11 Apr 2017 11:41:53 -0700 Subject: [PATCH 3/4] Stage 1 completed --- bike-shop/src/stage1-literals.js | 27 +++++++++++++++++++-------- jsinfo/calculator.js | 12 ++++++++++++ jsinfo/chaining.js | 17 +++++++++++++++++ 3 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 jsinfo/calculator.js create mode 100644 jsinfo/chaining.js diff --git a/bike-shop/src/stage1-literals.js b/bike-shop/src/stage1-literals.js index 19ba66a..01881b1 100644 --- a/bike-shop/src/stage1-literals.js +++ b/bike-shop/src/stage1-literals.js @@ -1,15 +1,26 @@ const myBike = { // your code here + name: "Roadster", + price: 199.99, + frame: { + height: 55, + color: "blue", + style: "cruiser" + }, + + brakes: { + front: false, + back: true + }, + + tires: { + diameter: 22, + type: 'fat' + }, + rings: [2,5], + } -let user = {} -user.name = "John" -user.surname = "Smith" -//user.name = "Pete" -Object.assign (user, {name: "Pete", isAdmin: true}) -delete user.name -//Object.assign (user, {name: "Pete", isAdmin: true}) -console.log(user) module.exports = myBike diff --git a/jsinfo/calculator.js b/jsinfo/calculator.js new file mode 100644 index 0000000..8c7a19c --- /dev/null +++ b/jsinfo/calculator.js @@ -0,0 +1,12 @@ +let calculator = { + sum () { + return this.a + this.b; + }, + mul () { + return this.a * this.b; + }, + read () { + this.a = +prompt('a?', 0); + this.b = +prompt('b?', 0); + } +} diff --git a/jsinfo/chaining.js b/jsinfo/chaining.js new file mode 100644 index 0000000..3f5f00e --- /dev/null +++ b/jsinfo/chaining.js @@ -0,0 +1,17 @@ +let ladder = { + step: 0, + up() { + this.step++; + return this; + }, + + down() { + this.step--; + return this; + }, + + showStep: function(){ //current step + alert( this.step); + return this; + } + } From 2319dd03cf461c8074ae50d46ed23db644b4c57d Mon Sep 17 00:00:00 2001 From: jasvictoria Date: Fri, 14 Apr 2017 14:29:21 -0700 Subject: [PATCH 4/4] Final --- .DS_Store | Bin 0 -> 6148 bytes bike-shop/src/stage2-constructors.js | 29 ++++++++++++---- bike-shop/src/stage3-methods.js | 44 ++++++++++++++++++++--- bike-shop/src/stage4-inheritance.js | 50 ++++++++++++++++++++++++--- bike-shop/test/stage3.test.js | 1 + jsinfo/Accumulator.js | 11 ++++++ jsinfo/calculator.js | 4 +-- jsinfo/extendableCalculator.js | 33 ++++++++++++++++++ jsinfo/newCalculator.js | 23 ++++++++++++ jsinfo/searching.js | 21 +++++++++++ music-player/album.js | 12 ++++++- music-player/artist.js | 12 ++++++- music-player/song.js | 31 ++++++++++++++++- npm-debug.log | 23 ++++++++++++ 14 files changed, 275 insertions(+), 19 deletions(-) create mode 100644 .DS_Store create mode 100644 jsinfo/Accumulator.js create mode 100644 jsinfo/extendableCalculator.js create mode 100644 jsinfo/newCalculator.js create mode 100644 jsinfo/searching.js create mode 100644 npm-debug.log diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..73821be66f5cc0c39439176c7ab2ad622161bfde GIT binary patch literal 6148 zcmeHK!A=4(5Pd}=5HaECagSag@efu66B6|RAD}Lah^{V?aPYRD;YayT`exdYUC^r` zW+s`wZac4?zHYW#0It7I&wvhqCS9=BV)27Xzxa;TLQ8|_bc`-mctnonDBFp)hJ92( z_O68l3p`_n(*EVsB+C=_%ByinKmAf;4LHOTcY1+WJRl!smDta%*aogJ!Ucx7!34u< zv>R_lxAB6tjy+{IOJummJ2QK$@-(B5Qbuj&k|Sm0Ek}^rn%o&yTRh3G%sVD;Nk&(> z30ZUW$jmXXGBwjOvxPC&bdCY8i9L>yRvD6`YnF24)MloDDPRihg#tXY#hOPRtuzHp z0aIY3fP5b!x?miz@Ti{-7J3CB*4eDay8JK-Ckhw`EIhJ@<~)_?sV-bGoTsxr3UP73 z!lS3dh0BKvGrMp@aXLH4k2D-E_GqOkUh-~X#5dol$~fq$ids}ClF zK9>~E)}6)4SsT&s=wcFAc-&A}(W98LaulD?)z}_Mg%}4cJhFvmKLRR)6{f(SD)0@; C=WJ~N literal 0 HcmV?d00001 diff --git a/bike-shop/src/stage2-constructors.js b/bike-shop/src/stage2-constructors.js index c422386..6a68d8c 100644 --- a/bike-shop/src/stage2-constructors.js +++ b/bike-shop/src/stage2-constructors.js @@ -1,13 +1,30 @@ -function Bike() { - // your code here +function Bike(name, price) { + this.name = name; + this.price = price; + this.rings = [3,7]; + this.brakes = { + front: true, + back: true } + this.frame = new Frame(); + this.tires = []; + this.tires[0] = new Tire(); + this.tires[1] = new Tire(); -function Frame() { - // your code here } -function Tire() { - // your code here + +function Frame(color, size, style) { + this.color = color || "black"; + this.size = size || 55; + this.style = style || "street"; + + } + + +function Tire(diameter, type) { + this.diameter = diameter || 22, + this.type = type || "street" } module.exports = { diff --git a/bike-shop/src/stage3-methods.js b/bike-shop/src/stage3-methods.js index c422386..58cb824 100644 --- a/bike-shop/src/stage3-methods.js +++ b/bike-shop/src/stage3-methods.js @@ -1,17 +1,53 @@ function Bike() { - // your code here -} + this.isMoving = function(){ + return false; +}; + this.tires = [new Tire(), new Tire()] + this.pedal = function (){ + if (this.tires[0].isFlat() || this.tires[1].isFlat()) { + throw "Can't pedal with a flat tire" + } + + this.isMoving = function (){ + return true; + } + } + this.brake = function(){ + this.isMoving = function(){ + return false; + } + } + this.gearSpeeds = function(){ + } + this.rings = [3,7]; + this.gearSpeeds = function(){ + return this.rings[0] *this.rings[1] + } + } + function Frame() { // your code here } function Tire() { - // your code here + this.isFlat = function(){ + return false; + } + this.puncture = function(){ + this.isFlat = function(){ + return true; + } + }; + this.repair = function(){ + this.isFlat = function(){ + return false; + }; + } } module.exports = { Bike: Bike, Frame: Frame, Tire: Tire -} +}; diff --git a/bike-shop/src/stage4-inheritance.js b/bike-shop/src/stage4-inheritance.js index 2281fd5..9dfc78c 100644 --- a/bike-shop/src/stage4-inheritance.js +++ b/bike-shop/src/stage4-inheritance.js @@ -1,16 +1,58 @@ class Frame { -// your code here + constructor () { + this.style = "default"; + } } class Tire { - // your code here + constructor (){ + this.type = "default"; + this.diameter = 20; + + } +} + +class Bike { + constructor (){ + this.frame = new Frame; + this.tires = [new Tire(), new Tire()]; + this.brakes = new Brakes; + } +} + +class MountainBike extends Bike { + constructor () { super(); + this.frame.style = "mountain"; + this.tires[0].type = "dirt"; + this.tires[1].type = "dirt"; + this.shocks = 20; + } + + adjustShocks (num){ + this.shocks = num; + } +} + +class BMXBike extends Bike { +} + +class RacingBike extends Bike { + // this.style = "racing" + // this.type = "road" + } -class Bike { - // your code here +class Brakes { + constructor(){ + this.front = false; + this.back = true; + } } module.exports = { Bike: Bike, + MountainBike: MountainBike, + BMXBike: BMXBike, + RacingBike: RacingBike, // you'll need to export new classes here } diff --git a/bike-shop/test/stage3.test.js b/bike-shop/test/stage3.test.js index 4f82562..34b0673 100644 --- a/bike-shop/test/stage3.test.js +++ b/bike-shop/test/stage3.test.js @@ -95,6 +95,7 @@ describe('Bike', () => { test('can tell the number of speeds with #gearSpeeds()', () => { const myBike = new Bike() + myBike.rings = [3,7] expect(myBike.gearSpeeds()).toBe(21) myBike.rings = [2,5] expect(myBike.gearSpeeds()).toBe(10) diff --git a/jsinfo/Accumulator.js b/jsinfo/Accumulator.js new file mode 100644 index 0000000..025530e --- /dev/null +++ b/jsinfo/Accumulator.js @@ -0,0 +1,11 @@ +var Accumulator = function(startingValue){ + this.value = startingValue; + + this.read = function (){ + this.value += +prompt("enter a number:", 0); + }; +} + + + +let accumulator = new Accumulator() diff --git a/jsinfo/calculator.js b/jsinfo/calculator.js index 8c7a19c..287f647 100644 --- a/jsinfo/calculator.js +++ b/jsinfo/calculator.js @@ -6,7 +6,7 @@ let calculator = { return this.a * this.b; }, read () { - this.a = +prompt('a?', 0); - this.b = +prompt('b?', 0); + this.a = +prompt('first number', 0); + this.b = +prompt('second number', 0); } } diff --git a/jsinfo/extendableCalculator.js b/jsinfo/extendableCalculator.js new file mode 100644 index 0000000..bb6f940 --- /dev/null +++ b/jsinfo/extendableCalculator.js @@ -0,0 +1,33 @@ +//method calculate(str) takes a str and returns result +//make "+" = + +//make "-" = - +//add operator constructor function +//func will = calculate(str)^^ + +function calculate(){ + this.calculate = function(str){ + + var split = str.split(" ") + var a = parseInt(split[0]); //num + var b = parseInt(split[2]); //num + let operator = split[1] // op + } + +} +//method obj + +//each operator stores in an array + + + }; +this.addMethod = function(name, func) +// function addOperator(name, func){ +// this.name = name; +// this.func = func; //** +// +// } + //calculator.add methods of operations = function created, actual function) + this.addMethod = function(name, func) { + methods.name = func;// what does this mean? + }; +// diff --git a/jsinfo/newCalculator.js b/jsinfo/newCalculator.js new file mode 100644 index 0000000..fdfc309 --- /dev/null +++ b/jsinfo/newCalculator.js @@ -0,0 +1,23 @@ +//calculator is a constructor function w 3 methods + +//this.read is a function/prompts for values store as obj properties +//sum a + b +//mul a * b + +function calculator(){ //calculator org func + this.read = function (){ + this.a = +prompt("enter first number:", 0) //num 1 + this.b = +prompt("enter second number:", 0) //num 2 + }, + this.sum = function (){ //calculator sum obj/func/prop + return this.a + this.b; //return num a + b + }, + this.mul = function (){ + return this.a * this.b; + } + +} +let calculator = new Calculator; + +alert( "Sum =" + calculator.sum() ); +alert( "Mul =" + calculator.mul() ); diff --git a/jsinfo/searching.js b/jsinfo/searching.js new file mode 100644 index 0000000..49b9af7 --- /dev/null +++ b/jsinfo/searching.js @@ -0,0 +1,21 @@ + + +let head = { + glasses: 1 +}; + +let table = { + pen: 3 + _proto_: head +}; + +let bed = { + sheet: 1, + pillow: 2 + _proto_: table +}; + +let pockets = { + money: 2000 + _proto_: bed +}; diff --git a/music-player/album.js b/music-player/album.js index 877a3aa..991eef1 100644 --- a/music-player/album.js +++ b/music-player/album.js @@ -1 +1,11 @@ -// Your code here + +const Artist = require('/.artist'); +class Album { + constructor (title, songcount, artist){ + this.title = title; + this.songcount = songcount; + this.artist = artist; + } +} + +module.exports = Album diff --git a/music-player/artist.js b/music-player/artist.js index 877a3aa..c792b5e 100644 --- a/music-player/artist.js +++ b/music-player/artist.js @@ -1 +1,11 @@ -// Your code here +class Artist { + constructor(name, bandmembers, genre){ + this.name = name; + this.bandmembers = bandmembers; + this.genre = genre; + } +} + +let littleDragon = new Artist ("Little Dragon", ["Yukimi Nagano", "Erik Bodin", "Hakan Wirenstrand", "Frederik Wallin"], "Indie"); + +console.log(littleDragon.artist) diff --git a/music-player/song.js b/music-player/song.js index 877a3aa..5bb0e1b 100644 --- a/music-player/song.js +++ b/music-player/song.js @@ -1 +1,30 @@ -// Your code here +class Song { + constructor(title){ + this.name = name; + this.length = length; + } + + Song.prototype = { + play: function(){ + return this.name + "plays"; + }, + pause: function(){ + return this.name + "pauses"; + }; + } + +} + +// } +// +// class Artist { +// constructor(name, bandmembers, genre){ +// this.name = name; +// this.bandmembers = bandmembers; +// this.genre = genre; +// } +// } +// +// let littleDragon = new Artist (("Little Dragon", "Yukimi Nagano, Erik Bodin, Hakan Wirenstrand, Frederik Wallin", "Indie")); +// +// diff --git a/npm-debug.log b/npm-debug.log new file mode 100644 index 0000000..c2062c4 --- /dev/null +++ b/npm-debug.log @@ -0,0 +1,23 @@ +0 info it worked if it ends with ok +1 verbose cli [ '/usr/local/bin/node', +1 verbose cli '/usr/local/bin/npm', +1 verbose cli 'run', +1 verbose cli 'test:stage2' ] +2 info using npm@3.8.6 +3 info using node@v6.0.0 +4 verbose stack Error: ENOENT: no such file or directory, open '/Users/Jaszly/LG/oop-practice/package.json' +4 verbose stack at Error (native) +5 verbose cwd /Users/Jaszly/LG/oop-practice +6 error Darwin 15.4.0 +7 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "test:stage2" +8 error node v6.0.0 +9 error npm v3.8.6 +10 error path /Users/Jaszly/LG/oop-practice/package.json +11 error code ENOENT +12 error errno -2 +13 error syscall open +14 error enoent ENOENT: no such file or directory, open '/Users/Jaszly/LG/oop-practice/package.json' +15 error enoent ENOENT: no such file or directory, open '/Users/Jaszly/LG/oop-practice/package.json' +15 error enoent This is most likely not a problem with npm itself +15 error enoent and is related to npm not being able to find a file. +16 verbose exit [ -2, true ]