Assignment: Even or Odd with AngularJS
Table of Content:
Assignment: Even or Odd with AngularJS
1. Even or Odd with AngularJS
In index.html, there are 2 input fields that accept two numbers, and display the sum and difference (result) of those numbers.
Write a function odd_even, that takes the result as input, and returns the text odd or even, based on the logic.
Expected Result:
100
11
100+ 11 = 111 which is an odd number
100 1189 which is odd number -
Solution
index.html
Odd or Even!
{{number1}} + {{number2}} = {{number1 + number2}} which is an number
{{number1}} - {{number2}} = {{number1 - number2}} which is number
index.js
// Add your code here var app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { $scope.odd_even = function(result) { if (result % 2 === 0) { return "even"; } else { return "odd"; } }; });
If you will run above code, you will get below output.