I am currently working on a functionality involving checkboxes within a list. The goal is to display an alert message congratulating the user once they have selected 5 checkboxes. I am implementing validation using promises, however, I am encountering an issue. When I do not use the reject code, everything works fine. But when I include the reject code as shown below, it executes and displays an error as 'undefined'. Can you help me pinpoint where I may have made a mistake?
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);
});