Lukas Baliƫnas Lukas Baliƫnas - 2 months ago 6
HTML Question

Naming variables in for loop

I'm new to JS and HTML. I learned that it's possible to name a variable by code. So i tried some simple variable naming code. However, it doesn't print anything on the page.

What seems to be the problem?


for (var i = 0; i < 10; i++) {
window['var' + i] = i;
document.getElementById("text").innerHTML = "" + var8;


<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8" />
<script src="JScript.js"></script>
<p><span id="text"></span>left</p>


Enclose your javascript code in below document.ready function, so that it will execute only when your page is ready.

$(document).ready(function () {
    // enter your code here