• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

112
Views
Creación de una validación de código Pin Javascript simple

Estoy tratando de crear una validación de pin en javascript. Quiero pedirle al usuario un pin y ellos ingresan 1234. Si ingresan el pin incorrecto 3 veces, quiero que diga el mensaje "pin incorrecto. Póngase en contacto con el banco". Gracias por cualquier ayuda

 function pinCode() { const Pin = "1234"; {} const name = prompt("Please enter your full name"); const user_Attempt = prompt("Please enter your PIN number to access your bank account"); if (user_Attempt = Pin) { alert("Welcome" + name); } else { alert("Incorrect pin. Please contact your bank"); return; } }

about 3 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Tal vez use la recursividad para esto

 var incorrectCount = 0; function pinCode() { if (incorrectCount != 3) { // prompts here if (user_Attempt === Pin) { // do stuff } else { incorrectCount += 1; pinCode(); } } else { // code for too many incorrect tries } }
about 3 years ago · Juan Pablo Isaza Report

0

 const pin = "1234"; let attemptsLeft = 3 const name = prompt("Please enter your full name"); for (attemptsLeft; attemptsLeft >= 0; attemptsLeft--) { if (attemptsLeft === 0) { alert("Incorrect pin. Please contact your bank"); break; } const userAttempt = prompt(`Please enter your PIN number to access your bank account. You have ${attemptsLeft} left.`); if (userAttempt === pin) { alert("Welcome " + name); break; } }

about 3 years ago · Juan Pablo Isaza Report

0

Use un ciclo while para seguir repitiendo hasta que se agoten los attempts o pinCorrect sea true .

 const correctPin = '1234'; const maxAttempts = 3; let attempts = 0; let pinCorrect = false; while (attempts < maxAttempts && !pinCorrect) { const pinInput = prompt(`Please enter your PIN number to access your bank account. ${maxAttempts - attempts} attempts left.`); pinCorrect = pinInput === correctPin; attempts++; } if (!pinCorrect) { alert('Incorrect pin. Please contact your bank'); } else { alert('Pin accepted'); }

about 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error