I have this code and it works pretty well. It gives me responses based off of who I put in the prompt. Only issue is that I want the code to give me a magic 8 ball effect when it doesn't recognize the name I put in. If I put in 'sdhjfgdsfdgds', for example, I want it to switch to the other code I have at the bottom of this question and give me a random response. If I put in 'Brandon', however, I still want it to tell him he's going to die. How do I accomplish this?
function myFunction() {
var person = prompt("Whose future are you inquiring about?", "Brandon");
if (person === 'Brandon') {
document.getElementById("demo").innerHTML = "He will die a grusome death";
}
if (person === 'Daniel') {
document.getElementById("demo").innerHTML = "He will receive free ice cream tomorrow";
}
}
<p>Welcome.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
I have this code as well:
var future = ['bright', 'bleak', 'not good', 'will probably die a horrible death soon', 'ask him', 'happy', 'fulfilled']; var show =
future[Math.floor(Math.random() * future.length)];
document.write(show);