I am basically trying to have a number displayed that starts at 0 and goes up randomly every time you press a button. But I need a variable to equal the current number(which is stored within an h1 tag). How do I do that? Currently when I try to check if it worked by alerting the page, all I get is [object HtmlHeadingElement] Here is my JavaScript, CSS, and HTML code, respectively:
function myRandom() {
var headnumber = document.getElementById('headnum');
alert(headnumber)
//the alert is just to check if '0' comes up'
}
h1 {
text-align: center;
font-size: 30px;
color: blue;
font-family: Verdana;
}
button {
margin-left: 640px;
border: solid blue 5px;
font-size: 14px;
font-family: Verdana;
font-weight: bold;
background-color: cyan;
border-radius: 6px;
}
<h1 id='headnum'>3</h1>
<button onclick="myRandom()">Button</button>
var headnumber = +document.getElementById('headnum').textContent;