JavaScript (V8), 96 bytes
-3 thanks to @Shaggy
-6 thanks to @tsh
I overlooked the rule allowing anonymous functions, so this generates a full program using either print
or console.log
with extra precaution for n
which is present in both instructions.
s=>`${S="print",S.match(s)?'co\\u006esole.log':S}("\\${s.charCodeAt().toString(8)+s.slice(1)}")`