JSFiddle - React, Tailwind, and code Playground

JavaScript

var a = "This is an example sentence, thanks.";
var result ="";
for(var i=0;i <a.length-4; i+=4){
    result +=a.substr(i, 4)+'X';
}

alert(result)