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

  • Home
  • SEARCH
  • 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 8083423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:28:07+00:00 2026-06-05T17:28:07+00:00

Yo community! might need some insights here.. :) I’m learning some more advance js-concepts.

  • 0

Yo community! might need some insights here.. 🙂 I’m learning some more advance js-concepts. Im running this code but the result is not showing up as I was expecting..I can’t see the error…any idea? thanks!

<script type="text/javascript">

    (function() {
        var results, queue = [];
        this.assert = function(pass, msg) {
            var type = pass ? "PASS" : "FAIL";
            var str = "<li class='" + type + "'><b>" +
                      type + "</b> " + msg + "</li>";
            if ( queue )
                queue.push( str );
            else    
                results.innerHTML += str;
        };

        window.addEventListener("load", function() {
            results = document.getElementById("results");
            results.innerHTML = queue.join('');
            queue = null;
        });

        // calling assert but it's not showing up the <li> with the message....( why? ) 
        assert( true, "I always pass!" );
    })();
</script>
  • 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-06-05T17:28:09+00:00Added an answer on June 5, 2026 at 5:28 pm

    “.is there any chance that else-statement will be used? why is the idea of the else-statement?”

    The way this assert() function works is that if it is called before the document load event has occurred any results are stored in the queue array: the condition if (queue) will be true because queue refers to the array.

    Then when the load handler runs it takes everything already in queue and outputs it to the results element before setting queue to null:

    results.innerHTML = queue.join('');
    queue = null;
    

    Any calls to assert() after the document load will then find that if (queue) is false because queue is null, so then the else will be executed and any results will be output directly to the results element.

    In your code as shown, there is only one call to assert() and it will occur before the document load handler has run.

    (Here’s a clunky demonstration of this – presses to the button will be after the load event: http://jsfiddle.net/JDFuR/1/)

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

Sidebar

Related Questions

This might be one of the more difficult questions I've asked, but I have
With the help of this community, I just recently solved some issues with PHPExcel
This might get closed, but I'll try anyway. I was showing a VB6 programmer
This might sound a little stupid but I am still curious about what the
I am using Magento community ver1.6.1.0. I found this state diagram on Magento wiki
This is a follow up post to some problems I've had using Java built
I already asked a similar question but this one is a bit different/specific: I'm
i need some advice. I am developing an iPhone application (later for Android also)
With the help of the Stack Overflow community I've written a pretty basic-but fun
Possible Duplicate: In what areas might the use of F# be more appropriate than

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.