JavaStrip
09-26-2003, 03:10 PM
This is a class asignment and you can probably see how little I know javascript. I don't know where to start, esspecially with this script. Everything but the javascript should be right, can anyone help? Or Explain?
<html>
<head>
<title>-</title>
</head>
<body>
<center>
<h3><b>5</b></h3>
</center>
<form name="lab05">
Type an integer into this box and hit "MakeList" to make a list of random numbers.<br>
Size of list: <input type=text name="n">
<input type=button value="MakeList" onclick="MakeList()"> <hr>
Click this button to find the largest element in the list.<br>
<input type=button value="GetMax" onclick="GetMax()">
<input type=text name="max"> <hr>
Enter a number (smaller than the size of the list) to find out the value of a specific list element.<br>
Element Number:<input type=text name="k">
<input type=button value="GetElement" onclick="GetElement()">
Result:<input type=text name="result">
</form>
<script language="JavaScript">
var list = new array();
function MakeList()
{
var i;
var n;
n = eval(document.form.n.value);
for(i=0; i<n; i++) {
list[i]= math.round(1000*math.random());
}
}
function GetMax()
{
var max;
var n;
var i;
n = eval(document.form.n.value);
max = list[0];
for(i=0; i<(n-1); i++) {
if (list[i] > max) }
{
else
max = list[i];
}
}
document.form.max.value = max;
function GetElement()
{
var k;
var n;
k = eval(document.form.k.value);
n = eval(document.form.n.value);
for(k > n) {
alert("List has only" + n + "elements.");
}
ELSE {
document.form.result.value = list[k-1];
}
}
</script>
</body>
</html>
As you can see, its a mess...
<html>
<head>
<title>-</title>
</head>
<body>
<center>
<h3><b>5</b></h3>
</center>
<form name="lab05">
Type an integer into this box and hit "MakeList" to make a list of random numbers.<br>
Size of list: <input type=text name="n">
<input type=button value="MakeList" onclick="MakeList()"> <hr>
Click this button to find the largest element in the list.<br>
<input type=button value="GetMax" onclick="GetMax()">
<input type=text name="max"> <hr>
Enter a number (smaller than the size of the list) to find out the value of a specific list element.<br>
Element Number:<input type=text name="k">
<input type=button value="GetElement" onclick="GetElement()">
Result:<input type=text name="result">
</form>
<script language="JavaScript">
var list = new array();
function MakeList()
{
var i;
var n;
n = eval(document.form.n.value);
for(i=0; i<n; i++) {
list[i]= math.round(1000*math.random());
}
}
function GetMax()
{
var max;
var n;
var i;
n = eval(document.form.n.value);
max = list[0];
for(i=0; i<(n-1); i++) {
if (list[i] > max) }
{
else
max = list[i];
}
}
document.form.max.value = max;
function GetElement()
{
var k;
var n;
k = eval(document.form.k.value);
n = eval(document.form.n.value);
for(k > n) {
alert("List has only" + n + "elements.");
}
ELSE {
document.form.result.value = list[k-1];
}
}
</script>
</body>
</html>
As you can see, its a mess...