在线javascript课程,任务有问题

时间:2018-11-11 07:43:17

标签: javascript

我是javascript方面的完全入门者,以及一般的编程知识。在线课程给我的任务非常复杂。

基本上,它被称为checks.js(因为它假定检查索引工作)应像这样工作:

// Built-in  Node.JS module for the check
var assert = require('assert');

// input your function
var addTime = require('./index.js');

assert.equal(addTime(12, 30, 30), '13:00', 'when 30 min is added to 12:30 we get 13:00');
assert.equal(addTime(23, 59, 31), '00:30', 'when 31 min is added to 23:59 we get 00:30');
assert.equal(addTime(11, 50, 61), '12:51', 'when 61 min is added to 11:50 we get 12:51');
assert.equal(addTime(23, 1, 80), '00:21', 'when 80 min is added to 23:01 we get 00:21');

console.info('OK!');

'index.js'由学生制作,模板如下:

/**
 * @param {Number} hours
 * @param {Number} minutes
 * @param {Number} interval
 * @returns {String}
 */
module.exports = function (hours, minutes, interval) {

};

所以我已经被编成这样的索引:

module.exports = function (hours, minutes, interval) {
    var allmin = (hours * 60)+minutes+interval;
    var allhours = Math.floor(allmin / 60);
    var fMin = allmin % 60

    if (allhours < 10) {
        allhours = toString(allhours);
        allhours = '0'+allhours;
    }

    if (fMin < 10) {
        fMin = toString(fMin); 
        fMin = '0'+fMin;
    }
    return allhours+':'+fMin
}

第二个是这样的

module.exports = function (hours, minutes, interval) {

   if (hours < 0 || hours > 23) {return false}
    var hours = Math.floor((minutes + interval) / 60);
    var minutes = (minutes + interval) % 60;

    if (hours < 10) {
        hours = toString(hours);
        hours = '0'+hours;
    }

    if (minutes < 10) {
        minutes = toString(minutes); 
        minutes = '0'+minutes;
    }

    return (hours+':'+minutes);
}

几乎相同,但是当我在终端中运行check.js来检查我的index.js时,我不断收到错误消息:

MBP-John-2:coursera JJ$ node checks.js
assert.js:86
  throw new AssertionError(obj);
  ^

AssertionError [ERR_ASSERTION]: При добавлении 30 мин. к 12:30 получится 13:00
    at Object.<anonymous> (/Users/JJ/js_playground/coursera/checks.js:7:8)
    at Module._compile (internal/modules/cjs/loader.js:707:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:718:10)
    at Module.load (internal/modules/cjs/loader.js:605:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:544:12)
    at Function.Module._load (internal/modules/cjs/loader.js:536:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:760:12)
    at startup (internal/bootstrap/node.js:308:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:878:3)
MBP-John-2:coursera JJ$ 

真的需要帮助!

提前谢谢!

0 个答案:

没有答案