ASDV-WebDev/Semester 1/Chapter ZIPs/JavaScript/ch7/ex_7_16.html

37 lines
885 B
HTML

2023-03-30 13:50:50 +07:00
<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">&nbsp;</span></h3>
</body>
</html>