Adding headings in a script element (HTML)

Hey!
I am attempting to create a random system where there’s a 1 in 2 chance of it either working, or it not. Now, I actually (this may be confusing) to use HTML in the parts where the 1/2 happens. Basically, If it works, then a new heading appears. How could I do this?

<h1>
    WAITING FOR INTERNAL SERVER RESPONSE
</h1>

<script>
    var RandomNum = Math.round(Math.random() * 2)
    var now = new Date();
    var ticks = now.getTime();
    var ticksadd = ticks += 100000
    console.log(ticks -= ticksadd)
   
    if (RandomNum === 1) {
       window.alert("Could not recieve")
    }

    else {
        window.alert("Received")
    }
</script>

You can use innerHTML : - https://www.w3schools.com/jsref/prop_html_innerhtml.asp

Not sure. It seems pretty confusing and unrelated.

You’ll need to learn some DOM manipulation.

Assuming the h1 element exists on the page before your script runs, you’ll need to query for that node and save it to a variable. The easiest way to do this is to add a unique id to the element.

<h1 id="theHeader"></h1>

<script>
const theHeader = document.getElementById("theHeader");

theHeader.textContent = "Here's the text that's displayed on the page.";
</script>
2 Likes