Thursday, January 6, 2011

I have no idea how I managed to write this thing and actually get it to work:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Lab 002</title>
<script type="text/javascript">
// I wrote one function to get the values for both sides of the rectangle
function getValue(numNumber){

var stringValue = "";
if (numNumber == 1) {
stringValue = "the length of the rectangle";
}
else
if (numNumber == 2) {
stringValue = "the width of the rectangle";
}

var integerHolder = 0;
while (integerHolder < 1) {
var valueHolder = prompt("Please enter the value for " + stringValue);
if (valueHolder == "") {
alert("Value was empty");
}
else
if (isNaN(valueHolder)) {
alert("Please enter a number");
}
else {
integerHolder++;
}
return valueHolder;
}
}



var xValue = getValue(1);
var yValue = getValue(2);

var total = parseInt(xValue) * parseInt(yValue);
alert("The area of the rectangle is " + total);



</script>
</head>
<body>

</body>
</html>

No comments: