Answer the question
In order to leave comments, you need to log in
How to write such a script?
We need such a script: display all numbers from 0000 to 9999 in a column
Thanks in advance. I haven’t worked with js for a long time, I forgot how))
Answer the question
In order to leave comments, you need to log in
var output = [], n, p;
for (i=0; i<=9999; i++) {
p = ('000'+i).slice(-4);
output.push(p);
}
console.log(output);
var where = document.createElement(div);
function myFunction() {
for(var i=0; i<=9999; i++){
var p = document.createElement("p");
var b = i/10000;
b=b.toFixed(4)
p.innerText = setDecimal(b);
where.appendChild(p);
}
function setDecimal(num) {
var str = "" + num;
var zeroPos = str.indexOf(".")+1;
if (zeroPos == -1) return 0;
str = str.slice(zeroPos);
return str;
}
for(let i = 0; i <= 9999; i++){
console.log( Array(5 - (i + '').length ).join('0') + i + '\n\r')
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question