javascript - 用javascript编写的计数程序

标签 javascript

我有作业:

import 3 numbers n,m,k. Count all numbers between m and n divisible by k

这是我的代码,谁能告诉我有什么问题吗?

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 + '&nbsp;');
    }
}

最佳答案

for 循环必须重写如下:

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 + '&nbsp;');
	}
}

关于javascript - 用javascript编写的计数程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53141972/

相关文章:

javascript - RequestBody 在 Controller 中为空

javascript - 如何将 gulp.watch() 传递给管道?

javascript - 如何在自定义博客模板中包含更多字体精美的图标?

javascript - 使用 GitLab 持续部署 NodeJS 问问题

javascript - Dojo:TypeError:marketStore.query 不是函数

javascript - 多个 Axios 请求进入 ReactJS 状态

javascript - 禁用asp项目中的右键单击

javascript - 使用 javascript 将数据传递到模态

javascript - JavaScript 中使用内联函数的闭包

javascript - 是否可以利用跨域 iframe 进行非阻塞计算?