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 3606438
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:14:54+00:00 2026-05-18T21:14:54+00:00

Look at this code var count = 0, count2 = 0 setInterval(function() { //

  • 0

Look at this code

var count = 0, count2 = 0
setInterval(function() {
    // I wrote this on two lines for clarity.
    ++count;
    count2 = count;
}, 1000);
if(count2==5)
{
alert('testing script')
}

How come the if statement does not execute when count2 = 5

  • 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-18T21:14:54+00:00Added an answer on May 18, 2026 at 9:14 pm

    The problem is: First you only define the logic for the interval and then you check the count2 variable. But in that context the variable has still the value 0.

    Each time the interval is fired (and in most cases it is after the if-check), only the part inside the function() { } block is executed

    function() {
        // I wrote this on two lines for clarity.
        ++count;
        count2 = count;
    }
    

    and it is not continued to the if statement because it is not part of the interval logic.

    The first idea I have is to put the if statement into the function() { } block like this:

    var count = 0, count2 = 0;
    
    setInterval(function() {
    
        // I wrote this on two lines for clarity.
        ++count;
        count2 = count;
    
        if(count2 == 5)
        {
            alert('testing script');
        }
    
    }, 1000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's look at this code: IList<IHouseAnnouncement> list = new List<IHouseAnnouncement>(); var table = adapter.GetData();
take a look at this example code: public class Comment { private Comment() {
Edit: Of course my real code doesn't look exactly like this. I tried to
Look at this example code, from a Telerik MVC grid: <% Html.Telerik().Grid(Model.InstallerList) .Name(InstallerGrid) .DataKeys(key
I have a javascript function which get datagrid's header into THEAD tags. This code
Look at this image: alt text http://img139.imageshack.us/img139/4488/picture2ep3.png I know how to add UITableView with
Look at this situation: www.websitea.com displays an img tag with a src attribute of
Have a look at this very simple example WPF program: <Window x:Class=WpfApplication1.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
I was having a look at this tutorial at Sun on command line I/O.
8 bits representing the number 7 look like this: 00000111 Three bits are set.

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.