Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

225
Vistas
JavaScript: variable is identified but a special character of that variable is unidentified

i have the variable "keycode" and i can console.log it outside the if{ } but can't inside of it. what my code tries to do: it produces a 5 digit number called keyCode then it takes the "message" variable it takes the first letter of it finds out which order it has in the alphabet and adds the first number of the keycode of it and converts it back to a letter. and so on(second letter of message-second digit of keycode)

the problem: console.log won't tell what the first or second digit of the keycode is

what the console says:

match
keycode is69097
cMO1 is NaN
1stthingofkeycodeis unidentified

the code:

getKeyCode()
var keyCode; // the keycode used to cypher the message
var message = "hello";
var uMessageLength; // the length of the uncyphered message
var lNIO; // what number the variable "lLIO" has 
var lLIO; //the letter that is going to get cyphered
var lTBC = 0 //which order of the letter in the alphabet the variable "lLIO" is going to get compared to 
var lKIO
var cMO1 = 0
var cM = []
var abc = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ];
var cypheredletter = " "
var cypheredmessage = []
////////////////////////////////////////////////////////////////////////////////////////////////    
function getKeyCode() {

  keyCode = Math.floor(Math.random() * 100000)
  console.log(keyCode)

};
////////////////////////////////////////////////////////////////////////////////////////////////
function cypher(string) {

  uMessageLength = string.length
  lNIO = 0
  lKIO = 0
  while (uMessageLength > 0) {
    lLIO = message[lNIO]
    console.log(lNIO, lLIO, lTBC)
    console.log("keycode is" + keyCode)
    if (lLIO == abc[lTBC]) {

      console.log("match")
      console.log("1stthingofkeycodeis" + " " + keyCode[0])
      console.log(keyCode)
      cMO1 = lTBC + keyCode[lKIO]
      console.log("cMO1 is" + " " + cMO1)
      if (cMO1 > abc.length) {

        cMO1 = cMO1 - abc.length

      }
      cypheredletter = abc[cMO1]
      cypheredmessage.push(cypheredletter, )
      lTBC = 0
      lKIO++
      lNIO++
      uMessageLength--

    } else {

      lTBC++

    }
  }
};
cypher(message)

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are trying to get an indexed value from an int. Instead try converting the int to a string and then getting the indexed value. Here's a snippet of your code which help resolve your issue:

if (lLIO == abc[lTBC]) {
  let keyCodeStr = keyCode.toString();
  console.log("match")
  console.log("1stthingofkeycodeis" + " " + keyCodeStr[0]) 

  cMO1 = lTBC + keyCodeStr[lKIO]

}

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda