Hello everyone,
I am attempting to insert a javascript script into the HTML overlya of the DOM element. It is a random number generator with if statements to determine what is printed in the HTML. When I try it independent of my project, it works. When I load the HTML file that the DOM element is linked to by itself, it works. However, when I run the project, it does not work. The rest of the text does, but not the javascript output. Here is the code I have inside the div where I want it to run.
let result;if (Math.random() < 0.1) {
raiders = Math.floor(Math.random()*3+1);
result = You encounter ${raiders} raiders
;
}
else if (Math.random() < 0.3) {
result = “You find nothing”;
}
else {
stones = Math.floor(Math.random()*4+1);
result = You find ${stones} stones
;
}
document.getElementById(“salvage”).innerHTML = result;
I want the result to show in the HTML so that it is accessible to screen readers. Ideallyonce this works, I also want to add a button to switch to a combat scene and a button to take items found to add to inventory.