简体   繁体   English

使用JavaScript的任务(node.js)

[英]A task using JavaScript (node.js)

I have the following task: check that A do not divide A and B do not divide A The function must return true / false. 我有以下任务:检查A不除A,B不除A函数必须返回true / false。 In input put 2 integer positive numbers A and B. 1 <= A, B <= 10000 在输入中放入2个整数正数A和B.1 <= A,B <= 10000

The sample: 样品:

node task.js 5 3 节点task.js 5 3

true 真正

The first argument puts in process.argv [1] 第一个参数放入process.argv [1]

My code: 我的代码:

function not_divide(a, b) {
    if ((a % b > 0) && (b % a > 0)){
        return console.log(true);
    }
    else{
        return console.log(false);
    }
}

not_divide(process.argv[1], process.argv[2]);

The task is very easy, but checker don't want to accept it. 这项任务非常简单,但是Checker不想接受它。 Help me, please 请帮帮我

console.log() returns undefined...not the values passed to it. console.log()返回undefined ...而不是传递给它的值。

That means your function always returns undefined 这意味着您的函数总是返回undefined

change 更改

return console.log(true);

To

console.log(true);
return true;

Same for the other return 相同的其他回报

I think You need process.argv[2] and process.argv[3] instead of [1] and [2] ; 我认为您需要process.argv[2]process.argv[3]而不是[1][2]
process.argv[0] - path to node.exe ; process.argv[0] node.exe路径;
process.argv[1] - path to script; process.argv[1] -脚本路径;
process.argv[2... etc] - params; process.argv[2... etc] -参数;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM