JSFiddle - React, Tailwind, and code Playground
HTML
<button id="click">Click</button>
<textarea id="test" rows="5"></textarea>
<button id="combine">123:123</button>
JavaScript
// always use better names of your functions (names that would be like a hint what is the purpose of that function)
function ra (length) {
// all the varaibles that won't change during your function should be declared as constansts
const consonants = "123456789".split('');
const vowels = '123456789'.split('');
const consonantLength = consonants.length;
const vowelsLength = vowels.length;
let rand = function(limit){
return Math.floor(Math.random()*limit);
}
// no need to declar i here when you can do so in the for loop
//-- var i = '';
// not sure why would you use this radix (the second argument of parseInt)
length = parseInt(length,10);
// there is no need to perform the split() on a separate row as this can be done with the initial declaration of your
//-- consonants = consonants.split('');
//-- vowels = vowels.split('');
let word = '';
let loopLength = length/2; // check this for more explanations https://stackoverflow.com/questions/8452317/do-loops-check-the-array-length-every-time-when-comparing-i-against-array-length
for (let i = 0; i < loopLength; i++) {
// in your code you where using consonants.lenght which will be executed each time so insted of this I will use the constant consonantLength that I have declared above
let randConsonant = consonants[rand(consonantLength)];
let randVowel = vowels[rand(vowelsLength)];
// not sure waht are you doing here, so can't comment much. It is a very good practice to leave some comments on places where the main logic of your code is happening
word += (i === 0) ? randConsonant.toLowerCase() : randConsonant;
word += i*2 < length-1 ? randVowel : '';
}
return word;
}
// the jQuery event 'click' is a bit old and will get some day depricated, instead I would sugges to use 'on'
$("#click").on('click',function(){
$("#test").text('');
//-- var pass1 = ra; // there is no need of this row. you can just call the function ra down below
...