Our site uses cookies. Learn more about their purpose and change of settings in a browser If you are using the site, you give you consent to use cookies, according to current browser settings. Got it

Angular egghead 17 - An alternative approach to controllers

  • Language JavaScript
Angular egghead is set of tests which depends on Egghead lessons. This exercise tests your knowledge about controller as syntax.

Exercise 17: An alternative approach to controllers

Summary

An alternative approach to controllers assumes that the function should be assigned to the controller, not to the $scope. Create SumCtrl and SubCtrl providing the basic math sum (addition)and subtract (subtraction) functions according to the requirements.

Goals

  • Calc.js should contain SumCtrl and SubCtrl controllers
  • SumCtrl should have an addition function assigned to itself
  • addition should consume two arguments and assign the result to sum variable
  • SubCtrl should be like SumCtrl but should have subtraction function and should have the result assigned to sub variable instead
  • each controller should have two variables (firstNumber, secondNumber) initialized with values 12 and 1
  • use addition and subtraction functions to display the result in the correct header (check comments)

Before you start, please refer to

Setup

To install dependencies

npm install

bower install

To start application in live reload mode

grunt serve

Jshint

To run jshint:

grunt jshint:default

Run tests

To run unit tests in development mode:

grunt test:dev

To run jshint, tests and coverage:

npm test

Good luck!

Start this test

I agree to subscription in accordance with the terms of service.
Go to the top and begin