mi código está agregando cMO1 = lTBC + keyCodeStr[lKIO] . encuentra lTBC y keyCodeStr correctos, pero cuando los agrega, comienzan a aparecer cosas extrañas en la consola. Empecé a aprender javascript hace 3 días y estoy atascado.
consola:
4 o 14 match lTBC=14 keyCodeStr[lKIO]=2 conclusion2 = conclusion-25 keyCode= 48892 conclusion = 14 + 2=116el código:
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 = [] var keyCodeStr; //////////////////////////////////////////////////////////////////////////////////////////////// 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) if (lLIO == abc[lTBC]) { console.log("match") console.log("lTBC=" + lTBC) let keyCodeStr = keyCode.toString(); console.log("keycodeStr[lKIO]=" + " " + keyCodeStr[lKIO]) cMO1 = lTBC + keyCodeStr[lKIO] if (cMO1 > abc.length) { cMO1 = cMO1 - abc.length console.log("conclusion2 = conclusion-25") } console.log("keycode= " + keyCode) console.log("conclusion =" + " " + lTBC + " " + "+" + " " + keyCodeStr[lKIO] + "=" + cMO1) cypheredletter = abc[cMO1] cypheredmessage.push(cypheredletter, ) console.log(cypheredmessage) lTBC = 0 lKIO++ lNIO++ uMessageLength-- } else { lTBC++ } } }; cypher(message)