Reputation: 49
Below is a loop that decrements. How can I rewrite this to count from 1
to 100
:
for (var i =100; i > 0; i--) {
console.log(from 1 to 100);
}
Upvotes: 3
Views: 5485
Reputation: 9441
for(var i =1;i<=100;i++){
console.log(i);
}
for(var i =100;i>=1;i--){
console.log(i);
}
Only the last 50 lines are shown in the console in Stack Overflow
Any previous output lines scroll off the top and are lost. So although the output may look incomplete, they were indeed all logged in the console.
Upvotes: 7
Reputation: 386756
You could take the delta of 101
.
for (var i = 100; i > 0; i--) {
document.getElementById('out').innerHTML += (101 - i) + '\n'
}
<pre id="out"></pre>
Upvotes: 3
Reputation: 3824
This will work but the snippet will only show 50-100.
for(var i=1;i<=100;i++){
console.log(i);
}
Upvotes: 1