0

I have what I thought would be a simple logic check. In my code

$scope.seatMap.PlaneTypeCode = "175"

However, when I set

$scope.seatMap.PlaneTypeCode === "175" //my debugger returns <b>false </b>

parseInt($scope.seatMap.PlaneTypeCode,10) ===175  // equals 17

I added a few zeros on the radix but that did nothing to help.

I am not sure how to do a comparison check. Any insight on this would be hugely appreciated.

Here is my full if statement

if (parseInt(col.name,10) ===4 && parseInt($scope.seatMap.PlaneTypeCode,10) ===175 && $scope.TripSummary) {
       col.available = false;
    }

****** Changed my response to this

if (parseInt(col.name,10) ===4 && $scope.seatMap.PlaneTypeCode ==="175" && $scope.TripSummary) {
            col.available = false;
        }  // still getting false
Winnemucca
  • 3,309
  • 11
  • 37
  • 66
  • 1
    The first step would be to find out what `console.log($scope.seatMap.PlaneTypeCode);` shows in the console. You don’t have to guess. – Sebastian Simon Aug 03 '16 at 05:10
  • _However, when I set_: you're not using assignment operator, where `=` is assignment, Try `$scope.seatMap.PlaneTypeCode = "175"` instead `$scope.seatMap.PlaneTypeCode === "175"` – Dhaval Marthak Aug 03 '16 at 05:13
  • it returned "175". I am missing something simple here. just not sure what. – Winnemucca Aug 03 '16 at 05:13

3 Answers3

1

You can use == instead of ===

$scope.seatMap.PlaneTypeCode == "175"

Please refer to Difference between == and === to know more

Community
  • 1
  • 1
Joyson
  • 3,025
  • 1
  • 20
  • 34
1

=== is a best practice, you should use it. Review the reference provided by @Joyson

You don't need the ,10 in parseInt because it is the default.

var PlaneTypeCode = "175";
if (parseInt(PlaneTypeCode) === 175) {
  console.log('equal');
}

If PlaneTypeCode is a code and can contain anything other than digits, a better comparison would be:

if (PlaneTypeCode === "175")
user2182349
  • 9,569
  • 3
  • 29
  • 41
  • I know this should be the case basic javascript, but I am getting false on this and have been for a while. there has to be something I am missing. – Winnemucca Aug 03 '16 at 05:23
  • if (PlaneTypeCode === "175") would be better since in the first portion of this answer, the variable is a string and following the parseInt, the comparison value will be converted to a number - hence the fail on the strict comparison – gavgrif Aug 03 '16 at 05:30
  • A radix should continue to be used since not all browsers in use are compliant with ES5, which introduced the default of 10. Also, `0x` will still indicate base 16. Using strict equality can introduce as many issues as it solves, and in this case is illogical. If *PlaneTypeCode* is a string and strict equality is necessary, then `PlaneTypeCode === "175"` should be used since `parseInt(PlaneTypeCode) === 175` is equivalent to `PlaneTypeCode == 175` (i.e. the conversion implicit in `==` is explicit using parseInt, so what's the point?). – RobG Aug 03 '16 at 06:24
0

use angular.equals($scope.seatMap.PlaneTypeCode,"175")

nktkarnany
  • 43
  • 1
  • 11