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.

6th Feb 2017, 10:18 PM
Mark glenn
Mark glenn - avatar
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
7th Feb 2017, 12:42 AM
Benneth Yankey
Benneth Yankey - avatar
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
6th Feb 2017, 11:11 PM
LordHill
LordHill - avatar
0
123
7th Feb 2017, 4:26 AM
Shantu Dey
Shantu Dey - avatar