RexyBadDog

HackerU_2020_09_23_AngularJS-Custom_Services_Task2.html

Sep 23rd, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.31 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3.  
  4. <head>
  5.     <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
  6.     <meta content="utf-8" http-equiv="encoding">
  7.     <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
  8.     <style>
  9.         hr.hr1 {
  10.             height: 5px;
  11.             border: none;
  12.             color: rgb(90, 90, 90);
  13.             background-color: rgb(90, 90, 90);
  14.         }
  15.     </style>
  16.  
  17. </head>
  18.  
  19. <body>
  20.     <div ng-app="myServices" style="width:800px; margin:0 auto;">
  21.         <div ng-controller="myCtrl">
  22.             <h3>Task 2 - Tax Deductions</h3>
  23.             <p>enter salary in BRUTO amount: <input type="number" ng-model="salary" ng-keyup="calc()" />
  24.             </p>
  25.             <p> car tax worth (7%) of {{salary}}: {{car_tax}}</p>
  26.             <p> income ar tax worth (20%) of {{salary}}: {{income_tax}}</p>
  27.             <p> social security tax worth (12%) of {{salary}}: {{social_security_tax}}</p>
  28.             </br>
  29.             <p> after all tax deduction, u have left: {{after_tax}}</p>
  30.             <br />
  31.         </div>
  32.         <hr class="h1" /><br />
  33.     </div>
  34.     <script>
  35.         var app = angular.module('myServices', []);
  36.         app.controller('myCtrl', function ($scope, salaryDeduction) {
  37.             //function to listen to event on html when keypress
  38.             $scope.calc = function () {
  39.                 var salary = parseFloat($scope.salary);
  40.                 $scope.car_tax = salaryDeduction.carTax(salary, 7);
  41.                 $scope.income_tax = salaryDeduction.incomeTax(salary, 20);
  42.                 $scope.social_security_tax = salaryDeduction.socialSecurityTax(salary, 12);
  43.                 $scope.after_tax = salary - $scope.car_tax - $scope.income_tax - $scope.social_security_tax;
  44.             }
  45.         });
  46.         app.service('salaryDeduction', function () {
  47.             this.carTax = function (x, percentage) {
  48.                 return parseFloat(x * (percentage / 100)).toFixed(2);
  49.             }
  50.             this.incomeTax = function (x, percentage) {
  51.                 return parseFloat(x * (percentage / 100)).toFixed(2);
  52.             }
  53.             this.socialSecurityTax = function (x, percentage) {
  54.                 return parseFloat(x * (percentage / 100)).toFixed(2);
  55.             }
  56.         });
  57.     </script>
  58. </body>
  59.  
  60. </html>
Add Comment
Please, Sign In to add comment