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">
	<meta charset="UTF-8">
	<title>Magic 8 ball</title>
	<input type="text" placeholder="Ask your question?">
	<button onclick="myFunction()">Answer</button>
	<p id="demo"></p>

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";
	    case 2:
	        answer = "No";
	    case 3:
	        answer = "Try Again";
	    case 4:
	        answer = "Outlook not so good";
	    case 5:
	        answer = "Most definitely!";
	document.getElementById("demo").innerHTML = answer;


Magic 8 Ball Demo