how to stop examplecodes/text within my html being recognized as code/activating

I’m currently working on a hackertyper, and my fake codes (the script that you "type out" is currently being read as real code, thus messing up my program. I also have commands within the fake code/script that need to trigger, which is br, because if they wont trigger, the entire program will be written on one line when someone is using the hackertyper.

Is there a command that lets me exclude the scriptcode, but leaves room for functions (I want to use the € sign as a function for br) so that my program will stop crashing? The solution to this is probably obvious but I can’t seem to find it, thanks in advance!

// pre defined variables
let num;
let counter;
counter = true;
num =0;

// this shows which text will go on the screen
let text = String("//right here is the problem. code that's put inside these brackets will be recognized as "real code" and at the same time <br>(or €)'s need to be recognized also// ");
// splits the text into an array after every character
let result = text.split("");

// start of the hackertyper
function keyPress(){
    music();
    document.onkeypress = function() {
        // where text will be shown
        num++;
        document.write(result[num]);
        // a loop
        keyPress();
    }
}