I need to write a function that takes two arguments, a number to start and a number to end a range. The function returns an array of the range including start and end. Also, I need to test the arguments: If they are not numbers return a meaningful message and an array of ALL the arguments. I now how to write this function with numbers but not with Strings.
Here is an example.
This will take the two numbers given and populate the array from smallest to largest.
You can can then decide how to handle the array after that.
let arr = []; //create array
let numOne = validateNumber();
let numTwo = validateNumber();
createArray(numOne, numTwo); // call function to populate array
arr.forEach(number => {
console.log(number);
})
function validateNumber(){
let pass = false;
let number = 0;
while (!pass){
number = parseInt(prompt('Enter a number'));
if (Number.isInteger(number)) pass = true;
}
return number;
}
function createArray(numOne, numTwo){
var start = numOne;
var end = numTwo;
if (numOne > numTwo){
start = numTwo;
end = numOne;
}
for (var i = start; i <= end; i++) {
arr.push(i)
}
}