├── js ├── super_hero.js └── tests.js ├── .gitignore ├── .travis.yml ├── index.html ├── package.json ├── Gruntfile.js └── README.md /js/super_hero.js: -------------------------------------------------------------------------------- 1 | // var SuperHero = ... 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | /validation-*.json 3 | -------------------------------------------------------------------------------- /js/tests.js: -------------------------------------------------------------------------------- 1 | QUnit.test("hello test", function(assert) { 2 | assert.strictEqual(1 + 1, 2, "One plus one is two"); 3 | }); 4 | 5 | // ADD TESTS HERE 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.10" 4 | branches: 5 | only: 6 | - /.*/ 7 | before_install: npm install -g grunt-cli 8 | sudo: false 9 | cache: 10 | directories: 11 | - node_modules 12 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | OOP exercise 10 | 11 | 12 |
13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "oop", 3 | "description": "superhero oop exercise", 4 | "scripts": { 5 | "test": "grunt" 6 | }, 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/advanced-js/oop" 10 | }, 11 | "bugs": { 12 | "url": "https://github.com/advanced-js/oop" 13 | }, 14 | "homepage": "https://github.com/advanced-js/oop", 15 | "devDependencies": { 16 | "grunt": "^0.4.4", 17 | "grunt-contrib-jshint": "^0.10.0", 18 | "grunt-contrib-qunit": "^0.5.1", 19 | "grunt-html-validation": "^0.1.15" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function(grunt) { 2 | grunt.initConfig({ 3 | jshint: { 4 | files: { 5 | src: [ 6 | '**/*.js', 7 | '!node_modules/**/*' 8 | ] 9 | } 10 | }, 11 | qunit: { 12 | all: ['index.html'] 13 | }, 14 | validation: { 15 | options: { 16 | reset: true 17 | }, 18 | files: { 19 | src: ['*.html'] 20 | } 21 | } 22 | }); 23 | 24 | grunt.loadNpmTasks('grunt-contrib-jshint'); 25 | grunt.loadNpmTasks('grunt-contrib-qunit'); 26 | grunt.loadNpmTasks('grunt-html-validation'); 27 | 28 | grunt.registerTask('default', ['jshint', 'qunit', 'validation']); 29 | }; 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Object Oriented Programming exercise 2 | 3 | ## V1 4 | 5 | Make a base `SuperHero` class. Give it some properties, and actions (methods) that change those properties. 6 | 7 | ## V2 8 | 9 | Make at least one of the methods interact with another `SuperHero`, such as `attack(otherHero)` or `giveMotivationalSpeech(otherHero)`. Be creative! 10 | 11 | ## V3 12 | 13 | Add tests for your `SuperHero` class. 14 | 15 | 1. Write tests for what it should do in [tests.js](js/tests.js). 16 | 1. Open [index.html](index.html) to run the tests. 17 | 18 | ### Resources 19 | 20 | * [QUnit links in the syllabus](https://github.com/advanced-js/syllabus#class-3) 21 | 22 | ## V4 23 | 24 | Make a base class with two subclasses that have two or special properties and actions, with tests covering all of the functionality, using [test-driven development (TDD)](https://en.wikipedia.org/wiki/Test-driven_development). 25 | 26 | 1. Write a test for what it should do in [tests.js](js/tests.js). 27 | 1. Open [index.html](index.html) to run the tests. 28 | 1. Define the class in [super_hero.js](js/super_hero.js), and make the tests pass. 29 | 1. Repeat from step 1. 30 | 31 | As an example, you could make a `SuperHuman` base class with `SuperHero` and `SuperVillain` subclasses. Maybe `SuperHero`es have the ability to have a shield, and therefore `attack(hero)` will have different behavior than `attack(villain)`. 32 | 33 | ### Resources 34 | 35 | * [Slide on inheritance](http://advanced-js.github.io/deck/examples/oop_inheritance/) 36 | * [Slide on calling superclass methods](http://advanced-js.github.io/deck/examples/oop_super/) 37 | --------------------------------------------------------------------------------