If I make this function without payable and don't take any money from the caller then return value accurately returns me the code.
You are on the right track but misinterpreting what you see. I'll break it down.
accurately returns me the code
I think you mean returns(string memory).
Payable has nothing to do with it. You have to ...
Since it is private is there a way to replace solidity with vanilla JS?
You'd need to write a compiler that could compile JS to EVM bytecode, and I'm pretty sure no one has done that yet.
The accepted answer to the following question might help explain the rationale behind developing a new smart contract languages, rather than use an existing language ...