I’m trying to use the prompt method to write two numbers in this format 1 – 10 and when you press OK, the program prints the consecutive numbers between these two numbers, just like this
1
2
3
4
5
6
7
8
9
10
but some of ranges of numbers made the loop don’t print any thing like when using this range: 5-10
while when using this range 1-10 it works successfully
I have used this code to run this
let promptMsg = prompt(“Print Number From – To”, “Example:5-20”);
let promptNum = promptMsg.split(“-“);
let lowEnd = promptNum[0];
let highEnd = promptNum[1];
let array = [];
for (let i = lowEnd; i <= highEnd; i++){
array.push([i]);
};
for (let i = 0; i < array.length; i++){
document.write(<div>${array[i]}</div>
);
};
Ahmed Saad is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.