csyouk
csyouk

Reputation: 73

Is there any elegance way to input boolean data in if statement

I coded like below. item.count and item.chip 's data type is number

If item.amout is less than item.chip, completion variable is assigned to true. If not, completion is assigned to false. Then that variable is goes to value in hash.

But I think this is not a best way.

if item.amount is item.chip
    completion = true
    teamRegionModel.create
        isRegionCompleted : completion
else
    completion = false
    teamRegionModel.create
        isRegionCompleted : completion

Upvotes: 0

Views: 128

Answers (1)

mu is too short
mu is too short

Reputation: 434795

The result of a JavaScript equality operator is a boolean value and CoffeeScript's is (or ==) is just JavaScript's === in disguise. That means that this:

item.amount is item.chip

is a boolean expression and has the value true or false.

You don't need your if/else at all, you can simply say:

completion = item.amount is item.chip
teamRegionModel.create
    isRegionCompleted : completion

or, if you don't need completion elsewhere:

teamRegionModel.create
    isRegionCompleted : item.amount is item.chip

Upvotes: 1

Related Questions