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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:59:34+00:00 2026-06-18T05:59:34+00:00

<!DOCTYPE html> <html> <body> <p>Click the button to loop through a block of code

  • 0
<!DOCTYPE html>
<html>
<body>

<p>Click the button to loop through a block of code five times.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>

<script>
function myFunction() {
  var x = "";
  for ( var i = 0; i < 5; i++ ) {
      x = x + "The number is " + i + "<br>";
  }
  document.getElementById("demo").innerHTML=x;
}
</script>

</body>
</html>

I understand what it returns but I don’t understand the x before each statement.

x = x + "The number is " + i + "<br>";
  • 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-18T05:59:36+00:00Added an answer on June 18, 2026 at 5:59 am

    x is a variable which is going to grow over the loop.

    The line:

    x = x + "The number is " + i + <br>
    

    just appends the line
    “The number is ” + i + end of line
    to the current value of x.

    Think of this line as:

    var y = x + "The number is " + i + <br>
    x = y
    

    At the end of the loop, x is worth all that:

    “The number is 0
    The number is 1
    The number is 2
    The number is 3
    The number is 4
    “

    If instead of x = “”, you had x = “Hello, “, then the final result would be:

    “Hello, The number is 0
    The number is 1
    The number is 2
    The number is 3
    The number is 4
    “

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

Sidebar

Related Questions

i confused with this code <!DOCTYPE html> <html> <body> <p>Click the button to replace
HTML <!doctype html> <html> <head> </head> <body> <button id=b1 type=button>Show Spoiler</button> <p id=p1 style=display:none>
I have the following html and css code: <!DOCTYPE HTML> <html> <head> </head> <body>
i am trying to understand following fragment of javascript code <!DOCTYPE html> <html> <body>
<!DOCTYPE HTML> <html> <head> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.2.js></script> <script type=text/javascript> $(#myBtn).on(click,function(){ alert('myBtn Clicked'); }); </script>
Here is my code: <!doctype html> <html> <head> <meta charset=utf-8> <title>Date Picker</title> </head> <body>
<!DOCTYPE html> <html> <head> <script type=text/javascript src=jquery-1.7.1.min.js></script> <script type=text/javascript> $(document).ready(function(){ $(button).click(function(){ $(p).toggle(function(){ $(p).hide();}, function(){
<!DOCTYPE HTML> <html> <body> <video width=320 height=240 controls=controls> <source src=tutorial.mp4 type=video/mp4 /> Your browser
This is my html content, I have a button, on click of button I
My HTML file <!DOCTYPE HTML> <html lang=en-US> <head> <meta charset=UTF-8> <title></title> </head> <body> <p>Hello

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.