for loop printing i in div incorrectly
function generer() {
var antall = Number(document.getElementById('antall').value);
var drikke = document.getElementById('drikke').value;
for (let i = antall; i >= 0; i--) {
vers = i + ' bottles of ' + drikke + ' on the wall <br>' + i + ' bottles of ' + drikke + '<br> If one of those bottles should happen to fall <br><br>';
console.log(vers);
}
document.getElementById('output').innerHTML = vers.repeat(antall);
}<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8">
<title>100-bottles</title>
<script src="script.js"></script>
</head>
<body>
<input type="text" id="antall" placeholder="Antall vers"><br>
<input type="text" id="drikke" placeholder="Type drikke"><br>
<button id="knapp" onclick="generer()">Generer vers</button>
<div id="output">
<p>Vers kommer her:</p>
</div>
</body>
</html>So the idea is to print out a number of verses, and a drink, and to then repeat that verse x(inputted) amount of times. My code does this, however, i have no clue as to why it outputs correctly in console, yet the number inputted always displays as 0 in the div I'm outputting it in. I tried making a while loop (not very skillful at that) yet to no avail. Also if helping, please mention WHY i am wrong/ it doesn't work.
javascript
add a comment |
function generer() {
var antall = Number(document.getElementById('antall').value);
var drikke = document.getElementById('drikke').value;
for (let i = antall; i >= 0; i--) {
vers = i + ' bottles of ' + drikke + ' on the wall <br>' + i + ' bottles of ' + drikke + '<br> If one of those bottles should happen to fall <br><br>';
console.log(vers);
}
document.getElementById('output').innerHTML = vers.repeat(antall);
}<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8">
<title>100-bottles</title>
<script src="script.js"></script>
</head>
<body>
<input type="text" id="antall" placeholder="Antall vers"><br>
<input type="text" id="drikke" placeholder="Type drikke"><br>
<button id="knapp" onclick="generer()">Generer vers</button>
<div id="output">
<p>Vers kommer her:</p>
</div>
</body>
</html>So the idea is to print out a number of verses, and a drink, and to then repeat that verse x(inputted) amount of times. My code does this, however, i have no clue as to why it outputs correctly in console, yet the number inputted always displays as 0 in the div I'm outputting it in. I tried making a while loop (not very skillful at that) yet to no avail. Also if helping, please mention WHY i am wrong/ it doesn't work.
javascript
@connexo that's not what the song sings about. 99-bottles-of-beer.net/lyrics.html
– Dropout
Nov 16 '18 at 10:18
You might also consider using type number for your input since as far as i understand it is about putting in an amount of iterations.<input type="number" id="antall" placeholder="Antall vers">
– Honkalonkalooooohhh
Nov 16 '18 at 10:21
add a comment |
function generer() {
var antall = Number(document.getElementById('antall').value);
var drikke = document.getElementById('drikke').value;
for (let i = antall; i >= 0; i--) {
vers = i + ' bottles of ' + drikke + ' on the wall <br>' + i + ' bottles of ' + drikke + '<br> If one of those bottles should happen to fall <br><br>';
console.log(vers);
}
document.getElementById('output').innerHTML = vers.repeat(antall);
}<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8">
<title>100-bottles</title>
<script src="script.js"></script>
</head>
<body>
<input type="text" id="antall" placeholder="Antall vers"><br>
<input type="text" id="drikke" placeholder="Type drikke"><br>
<button id="knapp" onclick="generer()">Generer vers</button>
<div id="output">
<p>Vers kommer her:</p>
</div>
</body>
</html>So the idea is to print out a number of verses, and a drink, and to then repeat that verse x(inputted) amount of times. My code does this, however, i have no clue as to why it outputs correctly in console, yet the number inputted always displays as 0 in the div I'm outputting it in. I tried making a while loop (not very skillful at that) yet to no avail. Also if helping, please mention WHY i am wrong/ it doesn't work.
javascript
function generer() {
var antall = Number(document.getElementById('antall').value);
var drikke = document.getElementById('drikke').value;
for (let i = antall; i >= 0; i--) {
vers = i + ' bottles of ' + drikke + ' on the wall <br>' + i + ' bottles of ' + drikke + '<br> If one of those bottles should happen to fall <br><br>';
console.log(vers);
}
document.getElementById('output').innerHTML = vers.repeat(antall);
}<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8">
<title>100-bottles</title>
<script src="script.js"></script>
</head>
<body>
<input type="text" id="antall" placeholder="Antall vers"><br>
<input type="text" id="drikke" placeholder="Type drikke"><br>
<button id="knapp" onclick="generer()">Generer vers</button>
<div id="output">
<p>Vers kommer her:</p>
</div>
</body>
</html>So the idea is to print out a number of verses, and a drink, and to then repeat that verse x(inputted) amount of times. My code does this, however, i have no clue as to why it outputs correctly in console, yet the number inputted always displays as 0 in the div I'm outputting it in. I tried making a while loop (not very skillful at that) yet to no avail. Also if helping, please mention WHY i am wrong/ it doesn't work.
function generer() {
var antall = Number(document.getElementById('antall').value);
var drikke = document.getElementById('drikke').value;
for (let i = antall; i >= 0; i--) {
vers = i + ' bottles of ' + drikke + ' on the wall <br>' + i + ' bottles of ' + drikke + '<br> If one of those bottles should happen to fall <br><br>';
console.log(vers);
}
document.getElementById('output').innerHTML = vers.repeat(antall);
}<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8">
<title>100-bottles</title>
<script src="script.js"></script>
</head>
<body>
<input type="text" id="antall" placeholder="Antall vers"><br>
<input type="text" id="drikke" placeholder="Type drikke"><br>
<button id="knapp" onclick="generer()">Generer vers</button>
<div id="output">
<p>Vers kommer her:</p>
</div>
</body>
</html>function generer() {
var antall = Number(document.getElementById('antall').value);
var drikke = document.getElementById('drikke').value;
for (let i = antall; i >= 0; i--) {
vers = i + ' bottles of ' + drikke + ' on the wall <br>' + i + ' bottles of ' + drikke + '<br> If one of those bottles should happen to fall <br><br>';
console.log(vers);
}
document.getElementById('output').innerHTML = vers.repeat(antall);
}<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8">
<title>100-bottles</title>
<script src="script.js"></script>
</head>
<body>
<input type="text" id="antall" placeholder="Antall vers"><br>
<input type="text" id="drikke" placeholder="Type drikke"><br>
<button id="knapp" onclick="generer()">Generer vers</button>
<div id="output">
<p>Vers kommer her:</p>
</div>
</body>
</html>javascript
javascript
edited Nov 16 '18 at 10:11
Mark
3,70921126
3,70921126
asked Nov 16 '18 at 10:07
KenKen
407
407
@connexo that's not what the song sings about. 99-bottles-of-beer.net/lyrics.html
– Dropout
Nov 16 '18 at 10:18
You might also consider using type number for your input since as far as i understand it is about putting in an amount of iterations.<input type="number" id="antall" placeholder="Antall vers">
– Honkalonkalooooohhh
Nov 16 '18 at 10:21
add a comment |
@connexo that's not what the song sings about. 99-bottles-of-beer.net/lyrics.html
– Dropout
Nov 16 '18 at 10:18
You might also consider using type number for your input since as far as i understand it is about putting in an amount of iterations.<input type="number" id="antall" placeholder="Antall vers">
– Honkalonkalooooohhh
Nov 16 '18 at 10:21
@connexo that's not what the song sings about. 99-bottles-of-beer.net/lyrics.html
– Dropout
Nov 16 '18 at 10:18
@connexo that's not what the song sings about. 99-bottles-of-beer.net/lyrics.html
– Dropout
Nov 16 '18 at 10:18
You might also consider using type number for your input since as far as i understand it is about putting in an amount of iterations.
<input type="number" id="antall" placeholder="Antall vers">– Honkalonkalooooohhh
Nov 16 '18 at 10:21
You might also consider using type number for your input since as far as i understand it is about putting in an amount of iterations.
<input type="number" id="antall" placeholder="Antall vers">– Honkalonkalooooohhh
Nov 16 '18 at 10:21
add a comment |
2 Answers
2
active
oldest
votes
You are seeing the expected result in the console because you display vers for each iteration of the for-loop. While you are iterating in the for-loop, the value of i is decreasing, and a new value of vers, with i in it, is logged. Each console log shows the current value of vers as i decreases.
When you finally write to the DOM, you have completed all of your for-loop iterations. At this time, the value of vers has settled to its last value, and it begins with "0 bottles".
Your code then creates a new string in which the value of vers, beginning with "0 bottles", is repeated several times. You render this big string to the DOM. So you see "0 bottles" repeated over and over.
This and then just putdocument.getElementById('output').innerHTML = document.getElementById('output').innerHTML + verswhere you have yourconsole.log()inside of the for loop.
– Honkalonkalooooohhh
Nov 16 '18 at 10:23
Or as @Mark suggests in a different answer, accumulate the output into an array and then output the join of the array as a single string in one shot to the DOM.
– Ray Toal
Nov 16 '18 at 10:29
add a comment |
You keep overriding the variable vers and therefore it will only contain the vers generated by the last iteration of the for loop. After that you're repeating the text of the last iteration antall amount of times and displaying it.
You can do something like this, the value generated in each iteration of the for loop is added to an array, and later joined after which it's displayed in the element:
function generer() {
var antall = Number(document.getElementById('antall').value);
var drikke = document.getElementById('drikke').value;
var verses = ;
for (let i = antall; i >= 0; i--) {
vers = i + ' bottles of ' + drikke + ' on the wall <br>' + i + ' bottles of ' + drikke + '<br> If one of those bottles should happen to fall <br><br>';
console.log(vers);
verses.push(vers);
}
document.getElementById('output').innerHTML = verses.join("");
}<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8">
<title>100-bottles</title>
<script src="script.js"></script>
</head>
<body>
<input type="text" id="antall" placeholder="Antall vers"><br>
<input type="text" id="drikke" placeholder="Type drikke"><br>
<button id="knapp" onclick="generer()">Generer vers</button>
<div id="output">
<p>Vers kommer her:</p>
</div>
</body>
</html>
This answer should be accepted because it offers a solution, which probably helps the OP to understand what went wrong better.
– Ray Toal
Nov 16 '18 at 10:22
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53335559%2ffor-loop-printing-i-in-div-incorrectly%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are seeing the expected result in the console because you display vers for each iteration of the for-loop. While you are iterating in the for-loop, the value of i is decreasing, and a new value of vers, with i in it, is logged. Each console log shows the current value of vers as i decreases.
When you finally write to the DOM, you have completed all of your for-loop iterations. At this time, the value of vers has settled to its last value, and it begins with "0 bottles".
Your code then creates a new string in which the value of vers, beginning with "0 bottles", is repeated several times. You render this big string to the DOM. So you see "0 bottles" repeated over and over.
This and then just putdocument.getElementById('output').innerHTML = document.getElementById('output').innerHTML + verswhere you have yourconsole.log()inside of the for loop.
– Honkalonkalooooohhh
Nov 16 '18 at 10:23
Or as @Mark suggests in a different answer, accumulate the output into an array and then output the join of the array as a single string in one shot to the DOM.
– Ray Toal
Nov 16 '18 at 10:29
add a comment |
You are seeing the expected result in the console because you display vers for each iteration of the for-loop. While you are iterating in the for-loop, the value of i is decreasing, and a new value of vers, with i in it, is logged. Each console log shows the current value of vers as i decreases.
When you finally write to the DOM, you have completed all of your for-loop iterations. At this time, the value of vers has settled to its last value, and it begins with "0 bottles".
Your code then creates a new string in which the value of vers, beginning with "0 bottles", is repeated several times. You render this big string to the DOM. So you see "0 bottles" repeated over and over.
This and then just putdocument.getElementById('output').innerHTML = document.getElementById('output').innerHTML + verswhere you have yourconsole.log()inside of the for loop.
– Honkalonkalooooohhh
Nov 16 '18 at 10:23
Or as @Mark suggests in a different answer, accumulate the output into an array and then output the join of the array as a single string in one shot to the DOM.
– Ray Toal
Nov 16 '18 at 10:29
add a comment |
You are seeing the expected result in the console because you display vers for each iteration of the for-loop. While you are iterating in the for-loop, the value of i is decreasing, and a new value of vers, with i in it, is logged. Each console log shows the current value of vers as i decreases.
When you finally write to the DOM, you have completed all of your for-loop iterations. At this time, the value of vers has settled to its last value, and it begins with "0 bottles".
Your code then creates a new string in which the value of vers, beginning with "0 bottles", is repeated several times. You render this big string to the DOM. So you see "0 bottles" repeated over and over.
You are seeing the expected result in the console because you display vers for each iteration of the for-loop. While you are iterating in the for-loop, the value of i is decreasing, and a new value of vers, with i in it, is logged. Each console log shows the current value of vers as i decreases.
When you finally write to the DOM, you have completed all of your for-loop iterations. At this time, the value of vers has settled to its last value, and it begins with "0 bottles".
Your code then creates a new string in which the value of vers, beginning with "0 bottles", is repeated several times. You render this big string to the DOM. So you see "0 bottles" repeated over and over.
answered Nov 16 '18 at 10:17
Ray ToalRay Toal
67.1k11125184
67.1k11125184
This and then just putdocument.getElementById('output').innerHTML = document.getElementById('output').innerHTML + verswhere you have yourconsole.log()inside of the for loop.
– Honkalonkalooooohhh
Nov 16 '18 at 10:23
Or as @Mark suggests in a different answer, accumulate the output into an array and then output the join of the array as a single string in one shot to the DOM.
– Ray Toal
Nov 16 '18 at 10:29
add a comment |
This and then just putdocument.getElementById('output').innerHTML = document.getElementById('output').innerHTML + verswhere you have yourconsole.log()inside of the for loop.
– Honkalonkalooooohhh
Nov 16 '18 at 10:23
Or as @Mark suggests in a different answer, accumulate the output into an array and then output the join of the array as a single string in one shot to the DOM.
– Ray Toal
Nov 16 '18 at 10:29
This and then just put
document.getElementById('output').innerHTML = document.getElementById('output').innerHTML + vers where you have your console.log() inside of the for loop.– Honkalonkalooooohhh
Nov 16 '18 at 10:23
This and then just put
document.getElementById('output').innerHTML = document.getElementById('output').innerHTML + vers where you have your console.log() inside of the for loop.– Honkalonkalooooohhh
Nov 16 '18 at 10:23
Or as @Mark suggests in a different answer, accumulate the output into an array and then output the join of the array as a single string in one shot to the DOM.
– Ray Toal
Nov 16 '18 at 10:29
Or as @Mark suggests in a different answer, accumulate the output into an array and then output the join of the array as a single string in one shot to the DOM.
– Ray Toal
Nov 16 '18 at 10:29
add a comment |
You keep overriding the variable vers and therefore it will only contain the vers generated by the last iteration of the for loop. After that you're repeating the text of the last iteration antall amount of times and displaying it.
You can do something like this, the value generated in each iteration of the for loop is added to an array, and later joined after which it's displayed in the element:
function generer() {
var antall = Number(document.getElementById('antall').value);
var drikke = document.getElementById('drikke').value;
var verses = ;
for (let i = antall; i >= 0; i--) {
vers = i + ' bottles of ' + drikke + ' on the wall <br>' + i + ' bottles of ' + drikke + '<br> If one of those bottles should happen to fall <br><br>';
console.log(vers);
verses.push(vers);
}
document.getElementById('output').innerHTML = verses.join("");
}<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8">
<title>100-bottles</title>
<script src="script.js"></script>
</head>
<body>
<input type="text" id="antall" placeholder="Antall vers"><br>
<input type="text" id="drikke" placeholder="Type drikke"><br>
<button id="knapp" onclick="generer()">Generer vers</button>
<div id="output">
<p>Vers kommer her:</p>
</div>
</body>
</html>
This answer should be accepted because it offers a solution, which probably helps the OP to understand what went wrong better.
– Ray Toal
Nov 16 '18 at 10:22
add a comment |
You keep overriding the variable vers and therefore it will only contain the vers generated by the last iteration of the for loop. After that you're repeating the text of the last iteration antall amount of times and displaying it.
You can do something like this, the value generated in each iteration of the for loop is added to an array, and later joined after which it's displayed in the element:
function generer() {
var antall = Number(document.getElementById('antall').value);
var drikke = document.getElementById('drikke').value;
var verses = ;
for (let i = antall; i >= 0; i--) {
vers = i + ' bottles of ' + drikke + ' on the wall <br>' + i + ' bottles of ' + drikke + '<br> If one of those bottles should happen to fall <br><br>';
console.log(vers);
verses.push(vers);
}
document.getElementById('output').innerHTML = verses.join("");
}<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8">
<title>100-bottles</title>
<script src="script.js"></script>
</head>
<body>
<input type="text" id="antall" placeholder="Antall vers"><br>
<input type="text" id="drikke" placeholder="Type drikke"><br>
<button id="knapp" onclick="generer()">Generer vers</button>
<div id="output">
<p>Vers kommer her:</p>
</div>
</body>
</html>
This answer should be accepted because it offers a solution, which probably helps the OP to understand what went wrong better.
– Ray Toal
Nov 16 '18 at 10:22
add a comment |
You keep overriding the variable vers and therefore it will only contain the vers generated by the last iteration of the for loop. After that you're repeating the text of the last iteration antall amount of times and displaying it.
You can do something like this, the value generated in each iteration of the for loop is added to an array, and later joined after which it's displayed in the element:
function generer() {
var antall = Number(document.getElementById('antall').value);
var drikke = document.getElementById('drikke').value;
var verses = ;
for (let i = antall; i >= 0; i--) {
vers = i + ' bottles of ' + drikke + ' on the wall <br>' + i + ' bottles of ' + drikke + '<br> If one of those bottles should happen to fall <br><br>';
console.log(vers);
verses.push(vers);
}
document.getElementById('output').innerHTML = verses.join("");
}<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8">
<title>100-bottles</title>
<script src="script.js"></script>
</head>
<body>
<input type="text" id="antall" placeholder="Antall vers"><br>
<input type="text" id="drikke" placeholder="Type drikke"><br>
<button id="knapp" onclick="generer()">Generer vers</button>
<div id="output">
<p>Vers kommer her:</p>
</div>
</body>
</html>You keep overriding the variable vers and therefore it will only contain the vers generated by the last iteration of the for loop. After that you're repeating the text of the last iteration antall amount of times and displaying it.
You can do something like this, the value generated in each iteration of the for loop is added to an array, and later joined after which it's displayed in the element:
function generer() {
var antall = Number(document.getElementById('antall').value);
var drikke = document.getElementById('drikke').value;
var verses = ;
for (let i = antall; i >= 0; i--) {
vers = i + ' bottles of ' + drikke + ' on the wall <br>' + i + ' bottles of ' + drikke + '<br> If one of those bottles should happen to fall <br><br>';
console.log(vers);
verses.push(vers);
}
document.getElementById('output').innerHTML = verses.join("");
}<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8">
<title>100-bottles</title>
<script src="script.js"></script>
</head>
<body>
<input type="text" id="antall" placeholder="Antall vers"><br>
<input type="text" id="drikke" placeholder="Type drikke"><br>
<button id="knapp" onclick="generer()">Generer vers</button>
<div id="output">
<p>Vers kommer her:</p>
</div>
</body>
</html>function generer() {
var antall = Number(document.getElementById('antall').value);
var drikke = document.getElementById('drikke').value;
var verses = ;
for (let i = antall; i >= 0; i--) {
vers = i + ' bottles of ' + drikke + ' on the wall <br>' + i + ' bottles of ' + drikke + '<br> If one of those bottles should happen to fall <br><br>';
console.log(vers);
verses.push(vers);
}
document.getElementById('output').innerHTML = verses.join("");
}<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8">
<title>100-bottles</title>
<script src="script.js"></script>
</head>
<body>
<input type="text" id="antall" placeholder="Antall vers"><br>
<input type="text" id="drikke" placeholder="Type drikke"><br>
<button id="knapp" onclick="generer()">Generer vers</button>
<div id="output">
<p>Vers kommer her:</p>
</div>
</body>
</html>function generer() {
var antall = Number(document.getElementById('antall').value);
var drikke = document.getElementById('drikke').value;
var verses = ;
for (let i = antall; i >= 0; i--) {
vers = i + ' bottles of ' + drikke + ' on the wall <br>' + i + ' bottles of ' + drikke + '<br> If one of those bottles should happen to fall <br><br>';
console.log(vers);
verses.push(vers);
}
document.getElementById('output').innerHTML = verses.join("");
}<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8">
<title>100-bottles</title>
<script src="script.js"></script>
</head>
<body>
<input type="text" id="antall" placeholder="Antall vers"><br>
<input type="text" id="drikke" placeholder="Type drikke"><br>
<button id="knapp" onclick="generer()">Generer vers</button>
<div id="output">
<p>Vers kommer her:</p>
</div>
</body>
</html>answered Nov 16 '18 at 10:20
MarkMark
3,70921126
3,70921126
This answer should be accepted because it offers a solution, which probably helps the OP to understand what went wrong better.
– Ray Toal
Nov 16 '18 at 10:22
add a comment |
This answer should be accepted because it offers a solution, which probably helps the OP to understand what went wrong better.
– Ray Toal
Nov 16 '18 at 10:22
This answer should be accepted because it offers a solution, which probably helps the OP to understand what went wrong better.
– Ray Toal
Nov 16 '18 at 10:22
This answer should be accepted because it offers a solution, which probably helps the OP to understand what went wrong better.
– Ray Toal
Nov 16 '18 at 10:22
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53335559%2ffor-loop-printing-i-in-div-incorrectly%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
@connexo that's not what the song sings about. 99-bottles-of-beer.net/lyrics.html
– Dropout
Nov 16 '18 at 10:18
You might also consider using type number for your input since as far as i understand it is about putting in an amount of iterations.
<input type="number" id="antall" placeholder="Antall vers">– Honkalonkalooooohhh
Nov 16 '18 at 10:21