JSFiddle - React, Tailwind, and code Playground
HTML
<style>
body{
direction: rtl;
}
</style>
<script>
function convert(){
x=document.getElementById('number').value
str= x.toString();
last ="و"
qa5 ="و"
first ="و"
uniary=["","واحد","إثنان","ثلاثة","أربعه","خمسة","ستة","سبعة","ثمانية","تسعة"]
beforelast =["","عشر","عشرون","ثلاثون","أربعون","خمسون","ستون","سبعون","ثمانون","تسعون","ستة","سبعة","ثمانية","تسعة"]
binary = ["","مئة","مئتان","ثلثمائة","أربعمائة","خمسمائة","ستمائة","سبعمائة","ثمانمائة","تسعمائة"]
tinary =["","ألف","ألفان","ثلاث آلاف","أربع آلاف","خمسة الاف","ست الآف", "سبع الاف","ثمان الاف", "تسع الاف","عشر الآف "]
qa5 = (str[3]==0) ? qa5 = "": qa5=qa5;
first= (str[1]==0) ? first="": first=first;
last = (str[2]==1) ? last="" : last=last;
last = (str[2]==0) ? last="" : last=last;
if (str.length == 4)
document.write(tinary[parseInt(str[0])] + " "+ first +" " + binary[parseInt(str[1])] + " "+ qa5 +" " + uniary[parseInt(str[3])] + " "+ last + " " + beforelast[parseInt(str[2])])
else if (str.length == 3)
document.write(binary[parseInt(str[0])] +" "+ first+" " + uniary[parseInt(str[2])] + " "+qa5 +" "+ beforelast[parseInt(str[1])])
else if(str.length == 2)
document.write(uniary[parseInt(str[1])]+ " و " + beforelast[parseInt(str[0])])
else if (str.length == 5)
document.write(uniary[parseInt(str[1])]+ " و " + beforelast[parseInt(str[0])] + " ألف و " + binary[parseInt(str[2])] + " و "+ uniary[parseInt(str[4])] + " و " + beforelast[parseInt(str[3])] )
else if (str.length == 6)
document.write(binary[str[0]] + " و " + uniary[str[2]] + " و " + beforelast[str[1]] + " الف و " + binary[str[3]] + " و " + uniary[str[5]] + "و ")
}
</script>
<body>
<input type="text" name="number" id="number">
<button type="submit" onclick="convert()" placeholder="try">
</body>