Magic 8 Ball To what mystery do you seek an answer? Ask Behind the scenes: Random Number Generation Magic 8 Ball uses Random Number Generation (RNG) to decide the answer to the question of the user. RNG is one of the world’s interesting devices, usually used in video games and different kinds of code. RNG has many different examples but in my opinion one of the best examples is Undertale. Whenever you create a file, it creates a fun value, and depending on the fun value, certain things will happen and certain things will not. For example, there is a certain fun value where a certain room will load, and then another random value determines whether a door will load, so it uses two layers of RNG to decide whether you’re able to encounter a certain character. To run as code, the Magic 8 Ball needs an input field and a button to activate the code, as well as a list of possible of possible outcomes. This is as accurate as a regular Magic 8 Ball. Having a Magic 8 ball in code instead of the physical thing, the answers will be similarly accurate, unless the code or 8 Ball says is broken. I think it is the same end result and both the processes take about the same time, so I wouldn’t necessarily argue that having it in code version is advantageous. I am not sure what I would replace it with on my website as it is still fun and saves people having to buy a Magic 8 Ball itself. The code <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <p> To what mystery do you seek an answer? </p> <p><form><input type="text" id="UserAsks"> <button type="button" onclick="magicball()">Ask</button></p> <script type="text/javascript"> function magicball(){ var userQuestion=document.getElementById('UserAsks').value; <!--tell the program to use the built-in Math function in order to generate a random number and set it to its lowest whole number (the Floor)--> randomNumber=Math.floor(Math.random()*8) let eightBall="" <!--the If statements generate 8 options. Depending on the number generated by Math.random, the user gets a different answer.--> if (randomNumber===1){ eightBall='It is decidedly so' }else if (randomNumber===2){ eightBall='Reply hazy try again' }else if (randomNumber===3){ eightBall='Cannot predict now' }else if (randomNumber===4){ eightBall='Do not count on it' }else if (randomNumber===5){ eightBall='My sources say no' }else if (randomNumber===6){ eightBall='Outlook not so good' }else if (randomNumber===7){ eightBall='Signs point to yes' }else{ eightBall='It is certain' } <!--Output the selected answer--> document.getElementById("eightanswer").innerHTML=`The ancients have spoken the answer is:${eightBall}`; return; } </script> <br><p id="eightanswer"></p> </body> </html>