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

220
Views
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 answers
Answer question

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 Report
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!