Reputation: 29
I have a homework:
import 3 numbers
n
,m
,k
. Count all numbers betweenm
andn
divisible byk
And this is my code, can anyone tell me what is wrong with that?
var n = parseInt(prompt("enter N"));
var m = parseInt(prompt("enter M"));
var k = parseInt(prompt("enter K"));
for (var i=0; n<=i<=m; i++)
{
if (i % k == 0)
{
document.write( i + ' ');
}
}
Upvotes: 0
Views: 130
Reputation: 18473
The for
loop has to be rewritten as such:
var n = parseInt(prompt("enter N"));
var m = parseInt(prompt("enter M"));
var k = parseInt(prompt("enter K"));
for(var i=n; i<=m; i++){
if (i % k == 0){
document.write( i + ' ');
}
}
Upvotes: 1