I have written the following code
<!DOCTYPE html>
<html>
<body>
<h1 id="para"></h1>
<script>
function Dice(sides) {
this.sides = sides;
this.roll = function() {
var randomNumber = Math.floor(Math.random() * this.sides) + 1;
console.log(randomNumber);
}
}
var dice = new Dice(6);
var dice10 = new Dice(10);
</script>
</body>
</html>
When I check the console, it's not printing random numbers & it seems my 'roll' method is not working. If I write code without roll method, it's working. But I want to enhance my skills in JS, so I am curious to know what's the problem with roll method in my constructor function.