Paper Fortune Teller
Here is an example of a simple HTML and JavaScript-based paper fortune teller:
<div id="fortune-teller" style="text-align:center; margin-top:20px;">
<button onclick="tellFortune()">Get Your Fortune</button>
<p id="fortune-result" style="font-weight:bold;"></p>
</div>
<script>
function tellFortune() {
const fortunes = [
"You will have a great day!",
"Adventure awaits you.",
"A surprise is coming your way.",
"You will achieve your dreams.",
"Expect good news soon!",
"Take a chance on something new.",
"Happiness is just around the corner.",
"You will make a new friend soon."
];
const randomIndex = Math.floor(Math.random() * fortunes.length);
document.getElementById("fortune-result").innerText = fortunes[randomIndex];
}
</script>
The paper fortune teller is a simple interactive feature using JavaScript and HTML. Here's how it works: HTML Structure: A <div> container holds the fortune teller interface. A <button> labeled "Get Your Fortune" triggers the JavaScript function. A <p> element (id="fortune-result") displays the randomly selected fortune. JavaScript Function (tellFortune): An array of predefined fortunes is stored in fortunes[]. The function selects a random fortune using Math.random() * fortunes.length, which generates a random index. The selected fortune is displayed by updating the innerText of the <p> element. When the user clicks the button, the function runs, selecting and displaying a random fortune message. Let me know if you want to customize it further!
In action
How to draw using WebGL
Static
Dynamic mouse response: if yuou are using a touch screen, the box will respond to the location tapped by moving towards that direction.
Battleship Game
Click a cell to guess the ship's location!
Randomization Methods
1. Fisher-Yates Shuffle
2. Mersenne Twister (Random Integer)
3. Cryptographic Random Generator
How it works:
- Fisher-Yates Shuffle: This button shuffles a predefined array and displays the shuffled result.
- Mersenne Twister: This button generates a random integer between 1 and 100 using JavaScript’s Math.random().
- Cryptographic Random Generator: This button generates a cryptographically secure random number using the crypto.getRandomValues() method.