0
I created a basic script to generate a random value from 1 to 100. But when I opened the html in which I created the script it only appeared on the page’s console and not on the page I created. How would you make the result appear on the screen?
<html>
<script>
function rollDice() {
let roll = Math.floor(Math.random() * 100) + 1;
console.log(`Rolled: ${roll}`);
}
rollDice()
</script>
</html>
This answers your question? Create HTML element with Javascript (appendchild vs innerHTML)
– BrTkCa
Puts this line in the Document.write("<span style='color:red'>Rolled:"+roll+"</span>");
– user60252
You don’t even need a function just put the script wherever it appears on the <script>Let roll = Math.floor(Math.Random() * 100) + 1; Document.write("<span style='color:red'>Rolled:"+roll+"</span>");</script>
– user60252
more Leo I am implementing this script and another html more exactly: I put this script in an input and when I click the input the page it reloads and turns completely white and with only the data value you can fix it?
– almeidaab
<input type="image" src="img/Dice.png" id="sanibotao" onclick="rolldice()"> I put your code in Function to test
– almeidaab