so ive been stuck on this assignment for the past 2 days and i dont know what im doing wrongquestion
so i did this which in my head should pass the question but according to the custom website we have to do it on the answer is wrong and i dont know what else to do so any help would be appreciated
//writes the parameters 1-10
var result = "";
function count(num1, num2)
{
for (var i = num1 + 1; i <= num2; i++)
{
result += i;
if (i < num2)
{
result += ",";
}
}
return result;
}
i attempted this with the help of my friends and with chatgpt to assist me in what i could be doing wrong however it doesnt really give the answer i was looking for
3
Answers
From what I understood, the only thing that seems to be missing is the starting number:
You can greatly simplify the code by incrementing the number in a loop and pushing the resulting number into an array. Once all of the numbers are in the array, you can use the
Array.prototype.toString
method to convert the array into a comma-separated string:Source
Tests
You could iterate with
start
and iterate untilend
is found.