So I try to run simple function that generates a winner based on number randomly generated. So far so good but when I want not only return the "winner" but return change innerHTML it does not give say ".innerHTML is not a function".
**I tried return also as a return than the document.innerHTML... Also, I try to make it in var and return the var but the same problem always.
function runNum() {
// randomize of number between 1-6
var a = Math.floor(Math.random() * 6 + 1);
var b = Math.floor(Math.random() * 6 + 1);
console.log(a, b);
if (a > b) {
document.querySelector(".winnerclick").innerHTML("winner1");
console.log("a");
}
if (b > a) {
return document.querySelector(".winnerclick").innerHTML("winner2");
console.log("b");
}
if (a === b) {
document.querySelector(".winnerclick").innerTEXT("Draw - no winner");
}
}
<h1 class="winnerclick">
Click on the button to play!
</h1>
<button onclick="runNum()">
Click to start
</button>
I try found answers but nothing solved this problem. Why it's not returned?
.innerHTMLis not a function. You assign a value to it.innerHTMLdocumentation? It's defined as a property, not a function.