So I am trying to make a simple translator. I am just having some issues with it. For example, I want it to register the letter B and then it will write bob. Now when I write b in the translate to box (which is the normal variable) it says in the translated to box (which is theifTalk) [object HTMLTextAreaElement]bob. And in the console it says: Cannot read property 'repeat' of undefined. Anyways here's my code:
const theifTalk = document.getElementById('theiftalk');
const normal = document.getElementById('normal');
const translateBtn = document.getElementById('translateBtn');
translateBtn.onclick = function() {
theifTalk.value = "";
translate();
}
function translate() {
if (normal.value.includes("b")) {
var bCount = normal.value.match(/b/g)||[].length;
b().repeat(bCount.length);
}
}
function b() {
theifTalk.value = theifTalk + "bob";
}
HTML CODE:
<textarea type="text" id="normal" rows="15" cols="80" placeholder="Normal text goes in here..."></textarea>
<textarea type="text" id="theiftalk" rows="15" cols="80" placeholder="Theif Talk text goes out here..."></textarea>
<br>
<button id="translateBtn">translate</button>
b()function is not returning anything, so when you callb().repeatthe result of the function is undefined, so it is impossible to userepeat