0

Wondering What im doing wrong, I want to call to a property that belong to a function object, from a function inside a function object.

When I check the value of "problems" variable, it stays "0".

This is my code(object declare):

function ValidateClass () {
    this.messege = "";
    this.problems = 0;

    this.getResults = function () {
            alert (this.problems);
        if (this.problems > 0) {
            
            showAlertModal(this.messege);
            return false;
        }
    }

    this.CompareDates = function (parent) {
        
        $(parent).each(function () {
            
            let startDate = $(this).find($(".datepickercheckin")).datepicker("getDate");
            let endDate = $(this).find($(".datepickercheckout")).datepicker("getDate");
            if (endDate === null) {
                endDate = startDate
            }

            if (endDate < startDate) {

                this.messege += '<span class="note"><i class="fas fa-sad-tear w3-small"></i>&nbsp;&nbsp;End date cannot be earlier or equal to Start date</span><br>';
                this.problems += 1;
                return false;
                
            }
            
        })
        
    }
}


The instance of the function object:

let validate = new ValidateClass();
validate.CompareDates($(".perioddiv"));
let result = validate.getResults();
Eyal Biton
  • 11
  • 4

0 Answers0