Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect after a delay if an if statement if fulfilled [duplicate]

Tags:

javascript

I've created a random site thing at the request of one of my friends that asks what the question is (The answer (An internet joke) Is "Do he got the booty?" At the moment I've got it to check the passcode given and write to the document depending on whether it's right or wrong. But I'd like it to, if the condition for the booty is fulfilled, redirect (After a 5 second delay) to Tumblr, the site of awesomeness.

This is my code so far :)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
   <head>
      <title>The ultimate question</title>
      <style>
     body{
     background-color:rgb(238, 235, 229);
     }
     #scriptresult{
     font-family:calibri;
     font-size:26px;
     width:30%;
     margin-left:35%;
     text-align:center;
     margin-top:15%;
     border-color:rgb(91, 122, 221);
     border-style:solid;
     border-width:5px;
     padding:20px;
     background-color:rgb(240, 219, 200);    
     }

  </style>
  </head>
  <body>
  <div id="scriptresult">


<script language="Javascript">
var passcode;
passcode = prompt("What is the ultimate question? (Make sure to include the ? at the end)");
passcode = (passcode.toUpperCase());
document.write("Your guess was" + " " + passcode);
if (passcode == "DO HE GOT A BOOTY?" || passcode == "DO HE GOT THE BOOTY?" || passcode == "DO HE GOT DA BOOTY?") {
    document.write("<br>Congratulations! You got da answer! Visit the awesomness!");
    else if (passcode == "DOCTOR WHO?" || passcode == "WHAT IS THE MEANING OF LIFE?" || passcode == "WHAT IS THE DOCTORS NAME?" || passcode == "WHAT IS THE DOCTOR'S NAME?") {
        document.write("<br>Not quite... But I love the guess! Think along the line of booty...<br><h6>(Hit refresh to try again)</h6>");
    } else {
        document.write("<br>Nope. That's wrong.<br><h6>(Hit refresh to try again)</h6>");
    }
</script>
</div>
</body>
</html>

Thank you so much in advance!

like image 910
Jack Spence Avatar asked May 31 '13 17:05

Jack Spence


People also ask

How do I redirect after delay?

If you want to redirect a page automatically after a delay then you can use the setTimeout() method in JavaScript and it will call the above property after a time delay. The solution is very simple. The setTimeout() method will call a function or execute a piece of code after a time delay (in millisecond).

How do you delay a href?

To delay a link with inline javascript, just set your href attribute as href="javascript:setTimeout(()=>{window. location = 'URL' },500);" . When you replace the URL with your link, just make sure it is inside the ' ' .


1 Answers

Insert this code into your success condition.

setTimeout(function(){window.location.href="tumblr.com"},5000);
like image 52
Bad Wolf Avatar answered Oct 24 '22 01:10

Bad Wolf