A
A
Alexander2018-01-30 14:46:47
JavaScript
Alexander, 2018-01-30 14:46:47

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

3 answer(s)
M
Mike, 2018-01-30
@AleksandrB

var output = [], n, p;
for (i=0; i<=9999; i++) {
    p = ('000'+i).slice(-4);
    output.push(p);
}
console.log(output);

V
vaskadogana, 2018-01-30
@vaskadogana

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;
    }

A
Ainur Valiev, 2018-01-30
@vaajnur

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 question

Ask a Question

731 491 924 answers to any question