Please send questions to
st10@humboldt.edu .
<html>
<!--
js_ck_functs.html
Check functions isNumber and isInteger
by: Sharon Tuttle
last modified: 8-29-06
-->
<head>
<title> js_ck_functs: check functions isNumber and isInteger </title>
<script type="text/javascript">
<!--
// returns true if value can be converted to a number using
// Number; returns false otherwise
//
// Examples: canValueBeNumber("13") == true
// canValueBeNumber("george") == false
function canValueBeNumber (value)
{
return !(isNaN( Number(value) ))
}
// returns true if value can be converted to an integer using
// Number; returns false otherwise
//
// Examples: canValueBeInteger("13") == true
// canValueBeInteger("13.7") == false
// canValueBeNumber("george") == false
function canValueBeInteger (value)
{
return canValueBeNumber(value) &&
(Number(value) == parseInt(value))
}
//-->
</script>
</head>
<body>
<h1> CIS 180 Checking-Functions Experiment </h1>
<h3> js_ck_functs.html </h3>
<h4> (by Sharon Tuttle, last modified 8-29-06) </h4>
<hr>
<script type="text/javascript">
<!--
var input = prompt("Please enter something")
if (canValueBeNumber(input))
{
document.write(input + " is a number!<br>")
}
if (canValueBeInteger(input))
{
document.write(input + " is an integer!<br>")
}
if (!canValueBeNumber(input) && !canValueBeInteger(input))
{
document.write(input + " is neither integer nor number!<br>")
}
//-->
</script>
<noscript>
<hr>
<h3> Your browser does not support JavaScript, or has it disabled;
<br>
please note that, as a result, this page will not work. </h3>
<hr>
</noscript>
<hr>
</body>
</html>