$(document).ready(function () {
var t=true;
var f=false;
var cheap;
$('.day1').on('change', function (e) {
if($(this).val() == "Saturday"){
cheap = true;
}
else{
cheap=false;
}
});
if(cheap==true){
$('.pricing1').change(function () {
var price = parseFloat($('.total').data('base-price')) || 0;
$('.pricing1').each(function (i, el) {
price += parseFloat($('option:selected', el).data('cheap'));
$('.total').val('$' + price.toFixed(2));
});
//console.log('cheap',cheap)
});
}
else{
$('.pricing').change(function () {
var price = parseFloat($('.total').data('base-price')) || 0;
$('.pricing').each(function (i, el) {
price += parseFloat($('option:selected', el).data('price'));
$('.total').val('$' + price.toFixed(2));
});
console.log('cheap',cheap)
});
}
});
The console reading returns true for cheap when saturday is selected. but the if part is not executed. Every time only else part is executed. logically it should execute the if part if cheap is true. and the console displays the cheap value to true so the value of cheap is true. This is weird!