This is a magic 8 ball program written in html and javascript. So it’s very lean fast and quick. You are free to use this script because it’s open source I made this solely for fun. So fork it. This is basically a random answer generator which uses random number and switch statement to be written. Have fun. 😉
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Magic 8 ball</title> </head> <body> <input type="text" placeholder="Ask your question?"> <button onclick="myFunction()">Answer</button> <p id="demo"></p> <script> function myFunction() { function getRandomArbitrary(min, max) { return Math.floor(Math.random() * (max - min) + min); } var num = getRandomArbitrary(1,6); switch(num) { case 1: answer = "Yes"; break; case 2: answer = "No"; break; case 3: answer = "Try Again"; break; case 4: answer = "Outlook not so good"; break; case 5: answer = "Most definitely!"; break; } document.getElementById("demo").innerHTML = answer; } </script> </body> </html>