Please send questions to
st10@humboldt.edu .
<html>
<!--
js_if2.html
Playing with JavaScript if statements and comparison
adapted from example in:
http://www.w3schools.com/js/js_if_else.asp
a JavaScript tutorial from w3schools.com
adapted by: Sharon Tuttle
last modified: 8-27-06
-->
<head>
<title> js_if2.html: Playing with JavaScript if statement and
comparison</title>
</head>
<body>
<h3> js_if2.html </h3>
<h3> ADAPTED from example in: <br>
http://www.w3schools.com/js/js_if_else.asp, <br>
a JavaScript tutorial from w3schools.com <h3>
<h4> (adapted by Sharon Tuttle, last modified 8-23-06) </h4>
<hr>
<script type="text/javascript">
<!--
// Write a "Good morning" greeting if the time is < 10
var dt = new Date()
var time = dt.getHours()
if (time < 10)
{
document.write("<strong> Good morning! </strong>")
}
else
{
document.write("<strong> Howdy! </strong>")
}
document.write("<hr>")
// playing with comparing strings
var name = "George"
document.write("<h4>")
if (name == "Greg")
{
document.write("How can [" + name + "] be Greg?!")
}
else
{
document.write("Yup, [" + name + "] is not Greg")
}
document.write("</h4>")
document.write("<h4>")
if (name == "George")
{
document.write("Yup, [" + name + "] is George")
}
else
{
document.write("How can [" + name + "] NOT equal George?!")
}
document.write("</h4>")
document.write("<hr>")
var code = "13"
var quant = 13
document.write("<h3>code is \"13\", quant is 13:</h3>")
document.write("<h4>")
if (code == quant)
{
document.write("code and quant contain the same value")
}
else
{
document.write("code and quant do not contain the same value")
}
document.write("<br>")
if (code === quant)
{
document.write("code and quant are the same value AND type")
}
else
{
document.write("code and quant are NOT the same value and type")
}
document.write("<h4>")
//-->
</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>