console.log(formatted_string('0000',123,1));
console.log(formatted_string('00000000',123,0))
console.log(formatted_string('00000000',123,4))
function formatted_string(str,num,pos)
{
    var temp = [];
    var st = str.split('')
   
    if( pos == null || pos == '')
    {
        return 'Invalid';
    }
    else
    {
        for(var i =0 ; i<=pos ; i++)
        {
            
            temp.push(st[i]);
           
        }
         temp[pos] = num
        return temp.join('');
    }
    
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: