Estoy comenzando a aprender html y js, tengo el siguiente problema:
Estoy intentando que la variable finalTxt se muestre en mi innerHTML. Cuando pongo otras variables o texto sí las muestra. El programa es para cifrar una palabra con el Cifrado César dejando que el usuario elija el offset.
html:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Semillas</title>
<link rel="stylesheet" href="style.css"/>
<link href="https://fonts.googleapis.com/css?family=Ropa+Sans&display=swap" rel="stylesheet">
</head>
<body>
Nombre de usuario: <input type="text" id="nText">
Número de la suerte: <input type="number" id="offNumber" min="0" max="26">
<input id="cipher" class="send-btn" type="button" value="Send"/>
<div id="showResult"></div>
</body>
<script src="cipher.js"> </script>
</html>
js:
var cipherFunction = document.getElementById('cipher');
var decipherFunction = document.getElementById('decipher');
cipherFunction.addEventListener("click", cipher);
if(decipherFunction){
decipherFunction.addEventListener("click", decipher);
}
function cipher (offNum, nTxt) {
var nTxt = document.getElementById('nText').value;
var offNum = parseInt(document.getElementById("offNumber").value);
var i=0;
var finalTxt = " ";
for (i=0; i<=nTxt.length; i++){
r=(nTxt.charCodeAt(i) -65 +offNum) %26 +65;
var finalTxt= String.fromCharCode(r);
console.log(finalTxt);
document.getElementById("showResult").innerHTML = finalTxt;
}
}
function decipher (offNum, nTxt) {
}