diff --git a/js/script.js b/js/script.js index 379aa93..2294b8f 100644 --- a/js/script.js +++ b/js/script.js @@ -30,9 +30,35 @@ backspace.addEventListener('click',()=>{ blockInput() }) +// Blocking the inputs after crossing the limit +displayGuessed.addEventListener('input', blockInput) +displayGenerated.addEventListener('input', blockInput) + // Functionality of submit button submitBtn.addEventListener('click', submitFunction) -// Blocking the inputs after crossing the limit -displayGuessed.addEventListener('input', blockInput) -displayGenerated.addEventListener('input', blockInput) \ No newline at end of file +function submitFunction() { + const generatedPin = displayGenerated.value; + const guessedPin = displayGuessed.value; + + if (!guessedPin) { + alert("Please enter your guess before submitting."); + return; + } + + if (guessedPin === generatedPin) { + alert("✅ PIN matched successfully!"); + // Additional success logic here + } else { + leftTries--; + alert(`❌ Incorrect PIN. Tries left: ${leftTries}`); + if (leftTries <= 0) { + alert("🔒 You have used all attempts. Input blocked."); + blockInput(); + } + } + + displayGuessed.value = ''; +} + +