37 lines
885 B
HTML
Executable File
37 lines
885 B
HTML
Executable File
<html>
|
|
<head>
|
|
<title>Example 7.16</title>
|
|
<script type="text/javascript" src="mySource.js"></script>
|
|
<script>
|
|
function shipIt()
|
|
{
|
|
var shipCode = "FREEBIE";
|
|
var userCode = prompt("Enter your code:");
|
|
if (checkWord(shipCode, userCode))
|
|
document.getElementById('result').innerHTML = ("Shipping is free!");
|
|
else
|
|
document.getElementById('result').innerHTML = ("Sorry, your code is not valid");
|
|
}
|
|
function checkWord(one, two)
|
|
{
|
|
var one; var two; var code = true;
|
|
for (i = 1; i < 4; i++)
|
|
{
|
|
code = true;
|
|
if (one != two)
|
|
{
|
|
code = false;
|
|
two = prompt("Invalid code but try again or enter Q to quit:");
|
|
if (two == "Q")
|
|
break;
|
|
}
|
|
}
|
|
return code;
|
|
}
|
|
</script>
|
|
</head>
|
|
<body><table align="center" width = "70%"><tr><td><br />
|
|
<input type ="button" onclick="shipIt()" value = "Enter free shipping code"><br />
|
|
<h3><span id = "result"> </span></h3>
|
|
</body>
|
|
</html> |