I'm trying to implement a button-press that generates numbers into an alert box. In that alert box I want the numbers to be separated by < > =
.
Any help is much appreciated!
<html>
<body>
<script type="text/javascript">
function getRNG(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
function rollD20()
{
var x = document.getElementById("output").value = getRNG(1, 20);
var y = document.getElementById("output").value = getRNG(1, 20);
var z = document.getElementById("output").value = getRNG(1, 20);
if(y == z && y == x && y != null)
alert(display.output)
}
</script>
<div id="output"></div>
<button onclick="rollD20();">Roll</button>
</body>
</html>
Something like this what you're looking for?
var x = document.getElementById("output").value = getRNG(1, 20);
var y = document.getElementById("output").value = getRNG(1, 20);
var z = document.getElementById("output").value = getRNG(1, 20);
alert(output(x, y, z));
// e.g. If x = 8, y = 15, z = 3, then output = "x < y > z";
function output(x, y, z) {
var output = "x "
if (x < y)
output += '< y '
else if (x === y)
output += '= y ';
else
output += '> y ';
if (y < z)
output += '< z'
else if (y === z)
output += '= z ';
else
output += '> z ';
return output;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.