Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
return devuelve un valor indefinido

tengo problemas con el return en mi función, tengo dos funciones, la primera crea una serie aleatoria de letras y números y la otra junta algunas combinaciones en una clave y verifica la base de datos (para verificar si ya existe) y si lo hace, vuelve a intentarlo), al final de la segunda función, devuelvo el valor clave mientras intento usarlo en mi código de solicitud posterior. aquí está el código:

 function keyGen(length) { var result = ''; var characters = '0123ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789456789'; var charactersLength = characters.length; for ( var i = 0; i < length; i++ ) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } return result; } function makeKey(company) { var gen1 = keyGen(6); var gen2 = keyGen(4); var gen3 = keyGen(6); var key = `${company}-${gen1}-${gen2}-${gen3}`; var rawKey = `${gen1}-${gen2}-${gen3}`; con.query('SELECT * FROM lkeys WHERE chars = ?', [rawKey], function(err, rows, fields) { console.log("here") if (err) throw err if (rows.length > 0) { makeKey(company) } else { console.log("here2") console.log(key) return key; } }) }

así es como trato de usar el valor de la función:

 let lkey = makeKey(company);

la salida para lkey no está undefined

cualquier ayuda sería apreciada, gracias.

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

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!