Creating Number Objects Rather than Performing String-to-Number Conversions
<html>
<head>
<script language="JavaScript1.1" type="text/javascript">
<!--
Number.prototype.description = null;
Highway = new Number(65);
City = new Number(35);
SchoolZone = new Number(25);
Highway.description = "Interstate Highway Speed Limit";
City.description = "City Speed Limit";
SchoolZone.description = "School Zone Speed Limit";
function tellDifference(num1, num2) {
diff = num1 - num2;
document.write("The speed difference between " + num1.description +
" and " + num2.description + " is " + diff); }
//-->
</script>
</head>
<body>
<script language="JavaScript1.1" type="text/javascript">
<!--
// Call function
tellDifference(Highway, City);
//-->
</script>
</body>
</html>
Related examples in the same category