-
Notifications
You must be signed in to change notification settings - Fork 0
Class #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Class #2
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| //base class | ||
| class Vehicle{ | ||
| constructor(color,type,year){ | ||
| this.name='Vehicle'; | ||
| this.color =color; | ||
| this.type =type; | ||
| this.year =year; | ||
|
|
||
| } | ||
| accelerate(){ | ||
| return this.name+"move forward"; | ||
| } | ||
|
|
||
|
|
||
| } | ||
| //instatiating a car model of a vehicle | ||
| let v = new Vehicle(red,car); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a good variable name, variable names should be descriptive |
||
| return "This is a " + v.red +v.name; | ||
|
|
||
|
|
||
|
|
||
| //inheritance to class 'car' from class 'vehicle' | ||
| class Car extends Vehicle{ | ||
| constructor(color,type,year){ | ||
| super(); | ||
| this.color=color; | ||
| this.type=type; | ||
| this.year =year; | ||
|
|
||
| } | ||
| } | ||
| //encapsulating the class Car into toyota | ||
| let toyota = new Car('red','new',2012); | ||
|
|
||
|
|
||
|
|
||
| class Truck extends Vehicle{ | ||
| constructor(color,type,year){ | ||
| super(); | ||
| this.color=color; | ||
| } | ||
| accelerate(){ | ||
| return this.name+"move forward"; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| let Hiace = new Truck | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Always end your files with a new line |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import chai from 'chai' | ||
| import app from '../src/main'; | ||
| let assert = chai.assert; | ||
|
|
||
| describe('app to test as', () => { | ||
| let result = app(); | ||
| it('app should return hello', () => { | ||
|
|
||
| assert.equal(result, 'hello') | ||
| }); // we put app() becos we checking for app()----goto terminal type npm run test | ||
|
|
||
| it('it should be a string', () => { | ||
| assert.typeOf(result, 'string') | ||
| }); | ||
| }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You wrote tests but your tests are not running because you didn't update your package.json with the test script |
||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These variables are not private
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, with the way you assigned 'Vehicle' to this.name. that means all classes inherited will always have 'vehicle' as the name. I'm not sure that's what you intended to do.