I have a set of list with checkboxes, when I click 5 checkboxes an alert message to be displayed congrates you have selected 5 options. I have to do the validation using promise. If I am not using reject, it is working fine. But if I add the code as given below, 'reject' code is executed and displaying error as 'undefined'. Where have I gone wrong?
let clickvalidation = new Promise(function(resolve, reject) {
$('input[type=checkbox][id=chk1]').change(function() {
if ($(this).is(':checked')) {
noOfClick++;
if (noOfClick == 5) {
resolve();
} else {
reject();
}
}
});
});
clickvalidation
.then(function() {
console.log('Success, You are a GEEK');
alert(`Congrats 5 tasks have been successfully completed`);
})
.catch(function(e) {
console.log(e.stack);
});