I am trying to take the numbers on a PHP data page and convert them to their word form through JavasScript onclick. When I console.log the result of each if statement- its doing what I am asking it to do in the background.. But I cant get it to return as a unit or display on the page. Any suggestions?
function trans(){
let n = document.body.innerText;
let match = n.match(/(d+)/g);
if (match.text = "0")
console.log (match.toString().replace(/0/g,'zero'));
if (match.text = 1)
console.log (match.toString().replace(/1/g,'one'));
if (match.text = 2)
console.log (match.toString().replace(/2/g,'two'));
if (match.text = 3)
console.log (match.toString().replace(/3/g,'three'));
if (match.text = 4)
console.log (match.toString().replace(/4/g,'four'));
if (match.text = 5)
console.log (match.toString().replace(/5/g,'five'));
if (match.text = 6)
console.log (match.toString().replace(/6/g,'six'));
if (match.text = 7)
console.log (match.toString().replace(/7/g,'seven'));
if (match.text = 8)
console.log (match.toString().replace(/8/g,'eight'));
if (match.text = 9)
console.log (match.toString().replace(/6/g,'nine'));}
New contributor
felohcin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.