根据输入因素计算变量值
Calculate value of variable depending on input factors
我正在尝试根据选择的数量来计算一个座位的费用,问题是第一个座位的费用与其余座位不同。
第一个 = 2250
额外座位收费995
我的语法和计算应该是什么?
//seats variable
var costOfSeats;
//Calculate cost of seats and display cost of seats
$('#range--seats').on("change", function() {
if ($(this).val(1)) {
costOfSeats == 2250;
} else {
costOfSeats == costOfSeats + ($(this).val(-1) * 995);// problem here
}
$('.output--seats').val("£" + costOfSeats);
}).trigger("change");
var n = 3; //number of seats
var sum = 0;
var extraSeat = 995;
var seat = 2250;
if (n != 0) {
sum = seat + ((n-1) * extraSeat)
}
if ($(this).val(1)) {
costOfSeats == 2250;
} else {
costOfSeats == costOfSeats + ($(this).val(-1) * 995);// problem here
}
您正在使用 costOfSeats == costOfSeats
,而不是 costOfSeats = costOfSeats
。您正在比较值而不是分配它们
我正在尝试根据选择的数量来计算一个座位的费用,问题是第一个座位的费用与其余座位不同。
第一个 = 2250 额外座位收费995
我的语法和计算应该是什么?
//seats variable
var costOfSeats;
//Calculate cost of seats and display cost of seats
$('#range--seats').on("change", function() {
if ($(this).val(1)) {
costOfSeats == 2250;
} else {
costOfSeats == costOfSeats + ($(this).val(-1) * 995);// problem here
}
$('.output--seats').val("£" + costOfSeats);
}).trigger("change");
var n = 3; //number of seats
var sum = 0;
var extraSeat = 995;
var seat = 2250;
if (n != 0) {
sum = seat + ((n-1) * extraSeat)
}
if ($(this).val(1)) { costOfSeats == 2250; } else { costOfSeats == costOfSeats + ($(this).val(-1) * 995);// problem here }
您正在使用 costOfSeats == costOfSeats
,而不是 costOfSeats = costOfSeats
。您正在比较值而不是分配它们