0
Someone help please...
Write a program DigitsInOrder that reads a four-digit integer from the user, and then display one digit per line. For example user enters 1234, then your program will display 1234 per line.
3 Réponses
+ 3
var a = prompt("enter any digit of number");
var arr = a.split("");
for (var i = 0; i < arr.length; i++) {
if (arr.length > 1) {
console.log(arr[i]);
} else {
console.log(arr[0]);
}
}
e.g
if the input is 1234
result:
1
2
3
4
however if the input is only a digit it will output accordingly
0
I don't know Javascript, but I would look into a for loop
putting user input into an array is simple, you can figure that out.. from there, use a for loop. it will loop thru your array of numbers and you can print each one to the screen
0
123