Categories: web development

Javascript – Magic 8 Ball Script

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>

 

Magic 8 Ball Demo

Admin

Share
Published by
Admin

Recent Posts

Unveiling the Intricacies of the Tinder Algorithm: 5 Surprising Metrics

Monitored by Tinder The inner workings of the Tinder algorithm remain shrouded in secrecy, known…

4 weeks ago

Is Shopping Temu Safe

Use fav19073 30% OFF Shop Now I recently had a fantastic buying experience on Temu,…

4 months ago

Cheap Netflix Subscription

Unlocking Affordable Streaming: How Gamsgo.com is Revolutionizing Netflix Subscriptions Sign Up Save1 coupon code for…

4 months ago

Domains for SALE.

razerkeyb.com gloriousmouse.com

9 months ago

How to Start your own vegetable garden?

Planting your own vegetables and fruit is a great way to save money and eat…

1 year ago

Jobs AI can’t replace

While AI has the potential to automate many tasks, there are still some jobs that…

1 year ago