Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7591761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:43:53+00:00 2026-05-30T20:43:53+00:00

function myfunction() { window.setTimeout(alert(‘I waited for you.’),700000000); } I call a function like this

  • 0
function myfunction()
  {
  window.setTimeout(alert('I waited for you.'),700000000);
  }

I call a function like this and I get an immediate alert saying “I waited for you”.

I initially put in 7000 as the second argument, but kept pushing it up in case it was something besides seconds. I obviously want the function to do something else, but I broke it down to this simplistic example to prove to myself where the problem lies.

What’s my mistake?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:43:55+00:00Added an answer on May 30, 2026 at 8:43 pm

    You have to pass a function reference, not the result of executing alert() like this:

    function myfunction() {
        window.setTimeout(function() {alert('I waited for you.')},700000000);
    }
    

    When you pass alert('I waited for you.') to setTimeout(), you’re telling the javascript interpreter to execute alert('I waited for you.') and then pass the return result to setTimeout(). Since that immediately executes the alert() statement and alert doesn’t return a function for setTimeout() to use, that is clearly not what you want.

    Instead, you want to pass a function reference to setTimeout(). That can be done either with an anonymous function as in the example I provided above or it can be done with a separate named function like this:

    function myAlert() {
        alert('I waited for you.');
    }
    
    function myfunction() {
        window.setTimeout(myAlert, 700000000);
    }
    

    Note: for more advanced usages, you can actually pass an immediately executed function to setTimeout() as long as that function returns a function reference that setTimeout() can call later. But, that is clearly not the usage you are attempting here with your alert()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function like this: MyFunction(double matrix[4][4]) {/*do stuff*/} I am calling this
I call my JavaScript function. Why do I sometimes get the error 'myFunction is
I have this javascript function myFunction(source) { window.open(source, Title, 'width=400, height=400'); } and in
If I have this window.onresize = function() { alert('resized!!'); }; My function gets fired
I have a javascript code like this <script type=text/javascript> window.onload=myFunction; </script> Is there any
I used a code: jQuery.fn.MyFunction = function(){ return this.each(function() { attributes = test; return
I have this code: window.onload= function() { window.scrollTo(0, 0.9); if (navigator.standalone) return; for (var
function myFunction(message) { this.message = message; return this.message; } document.body.innerHTML = new myFunction(Hello); I
Let say I have the following code $(p).bind(click, function(){ alert( $(this).text() ); }); When
This works in Drupal 7: jQuery(document).ready(function myfunction($) { }); But what is the syntax

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.