Skip to main content
5 of 5
saved 6 bytes
Arnauld
  • 197.6k
  • 20
  • 179
  • 649

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)}")`

Try it online!

Arnauld
  • 197.6k
  • 20
  • 179
  • 649