Reputation: 23
Case 1: discount works well.
function Car (plate,make,model,price,color) {
this.carPrice = price;
this.disc = function () {
return (this.carPrice > 20000 ? this.carPrice * .75 :
this.carPrice < 5000 ? this.carPrice * .9 : this.carPrice * .85);
};
this.discount = this.disc();
}
console.log(new Car('test', 'test', 'test', 10000, null));
Case 2: discount renders NaN. why?
function Car (plate,make,model,price,color) {
this.carPrice = price;
this.discount = function () {
return (this.carPrice > 20000 ? this.carPrice * .75 :
this.carPrice < 5000 ? this.carPrice * .9 : this.carPrice * .85);
}();
}
console.log(new Car('test', 'test', 'test', 10000, null));
Upvotes: 0
Views: 42