Lottery JavaScript
From DHTML Wiki
A script designed to generate a random number for the computer and one for the user so that the odds of the numbers being equal are one in ten. Then it allows the user to check if their number won OR equals 7. If it did, an exclusive access code for exclusive content is displayed in an alert window.
Contents |
[edit] User Information
Invented by Matthewinventor of Lightbulb Productions. Tested in Internet Explorer 7+.
[edit] Code
<html>
<head><title>Lotto</title></head>
<body>
<script type="text/javascript">
/*
*DO NOT EDIT FROM HERE TO "END NO EDIT NOTICE"!
*Lottery Generator by Lightbulb Productions
*Lightbulb Productions, the author of this script, and DHTML Wiki assume no repsonsibility for any damage caused by the use, modification, and/or sharing of this script.
*Lightbulb Productions, the author of this script, and {{SITENAME}} allow the use of this script as long as this notice is kept intact and do not endorse any site or the its content on which this code is placed.
<br /><nowiki>*/
//END NO EDIT NOTICE
var userNum = parseInt(Math.floor(Math.random() * 10) + 1);
var winNum = parseInt(Math.floor(Math.random() * 2) + 1);
function lotto() {
if (winNum == userNum) {
alert('Congradulations, ticket number ' + userNum + ', you are a winner! Enter the code qjNG8kSjiv to get exclusive content.')
} else if (userNum == parseInt(7)) {
('Your lotto number was 7! You won the LUCKY SEVEN JACKPOT! Enter this code: unua8kjieSqrc7jyvGikblNsm for exclusive content.');
} else {
alert('I am sorry, ticket number ' + userNum + ', you did not win.');
}
}
</script>
Welcome to the virtual lotto! Generate your ticket. You will get an alert telling you if you won or lost. If you won, enter the code provided for exclusive content. Note: You must refresh the page for a new lottery ticket.
<p>Generate Virtual Lotto Ticket:</p>
<form method=post action="#">
<input type="button" value="Check Ticket" onclick="lotto()">
</form>
</body>
</html>
</nowiki>
[edit] How To Use
Copy the HTML code into a blank page and edit to your needs. The exclusive access codes from winning are unua8kjieSqrc7jyvGikblNsm and qjNG8kSjiv.
[edit] Edits
- Examples:
- Matthewinventor 23:04, 14 March 2008 (UTC) Debugged syntax error on line 7
- Matthewinventor 23:04, 14 March 2008 (UTC) Added <!-- --> comment to line 72
- Real Edits:
- Matthewinventor 23:04, 14 March 2008 (UTC) Added <!-- --> comment to line 72 (okay, I was the creator of this code, just wanted to tell about the edit)
