Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

229
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda