One interesting application of computers is the drawing of graphs and bar charts. Write a script that reads five numbers between 1 and 30 out put XHTML text that displays a line containing the same number of adjacent asterisks. For example, if your program reads the number 7, it should output XHTML text that displays *******.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- JavaScript by Eduardo Lauro P. Abad -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Web 2 HW: ch 8.10 pg 317</title>
</head>
<body>
<script type="text/javascript">
var minn = 1
var maxn = 30;
var maxnout = 5;
var numbers = new Array();
for (var i = 0; i < maxnout; i++)
{
// Generate a random number between minn and maxn
numbers[i] = minn + Math.floor(Math.random()*maxn);
document.write(numbers[i] + " ");
for (var j = 0; j < numbers[i]; j++)
{
document.write(" * ");
}
document.write("<br/>");
}
</script>
<p><a href="javascript: window.location.reload()">Click here to reload the page.</a></p>
</body>
</html>
Please note that this is in no way the best possible way of doing it. I’m only posting this in my blog so that they are not lost in the future unless something happens to my dedicated server. Plus it is a good way to look back at how you used to write code.
Informasi Online Perkumpulan Warga Jawa Keluyuran di Sumatera…
[...]JavaScript Code Snippet #3[...]…