javascript course online, problems with task
up vote
1
down vote
favorite
I am complete beginner in javascript, well and programming in general. The task given in online course is pretty complicated for me.
Basically, it is called checks.js (because it suppose to check your index work) suppose to work like this:
// 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' is made by a student, the template is like this:
/**
* @param {Number} hours
* @param {Number} minutes
* @param {Number} interval
* @returns {String}
*/
module.exports = function (hours, minutes, interval) {
};
So I have been made index like this:
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
}
And the second one like this:
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);
}
which is pretty much the same, but when i run checks.js in terminal to check my index.js, I constantly getting an error:
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$
Really need help!
Thanks in advance!!!
javascript
add a comment |
up vote
1
down vote
favorite
I am complete beginner in javascript, well and programming in general. The task given in online course is pretty complicated for me.
Basically, it is called checks.js (because it suppose to check your index work) suppose to work like this:
// 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' is made by a student, the template is like this:
/**
* @param {Number} hours
* @param {Number} minutes
* @param {Number} interval
* @returns {String}
*/
module.exports = function (hours, minutes, interval) {
};
So I have been made index like this:
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
}
And the second one like this:
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);
}
which is pretty much the same, but when i run checks.js in terminal to check my index.js, I constantly getting an error:
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$
Really need help!
Thanks in advance!!!
javascript
The error comes from the fact that your code does not return what the assertion expects. Just call the function you've developed (without the asserts), for example:addTime(12, 30, 30)
, you will see that the result is not13:00
.
– sjahan
Nov 11 at 8:23
Just helping you debugging it: you cannot calltoString(something)
, what you should do issomething.toString()
.
– sjahan
Nov 11 at 8:26
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am complete beginner in javascript, well and programming in general. The task given in online course is pretty complicated for me.
Basically, it is called checks.js (because it suppose to check your index work) suppose to work like this:
// 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' is made by a student, the template is like this:
/**
* @param {Number} hours
* @param {Number} minutes
* @param {Number} interval
* @returns {String}
*/
module.exports = function (hours, minutes, interval) {
};
So I have been made index like this:
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
}
And the second one like this:
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);
}
which is pretty much the same, but when i run checks.js in terminal to check my index.js, I constantly getting an error:
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$
Really need help!
Thanks in advance!!!
javascript
I am complete beginner in javascript, well and programming in general. The task given in online course is pretty complicated for me.
Basically, it is called checks.js (because it suppose to check your index work) suppose to work like this:
// 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' is made by a student, the template is like this:
/**
* @param {Number} hours
* @param {Number} minutes
* @param {Number} interval
* @returns {String}
*/
module.exports = function (hours, minutes, interval) {
};
So I have been made index like this:
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
}
And the second one like this:
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);
}
which is pretty much the same, but when i run checks.js in terminal to check my index.js, I constantly getting an error:
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$
Really need help!
Thanks in advance!!!
javascript
javascript
asked Nov 11 at 7:43
Grimmie
61
61
The error comes from the fact that your code does not return what the assertion expects. Just call the function you've developed (without the asserts), for example:addTime(12, 30, 30)
, you will see that the result is not13:00
.
– sjahan
Nov 11 at 8:23
Just helping you debugging it: you cannot calltoString(something)
, what you should do issomething.toString()
.
– sjahan
Nov 11 at 8:26
add a comment |
The error comes from the fact that your code does not return what the assertion expects. Just call the function you've developed (without the asserts), for example:addTime(12, 30, 30)
, you will see that the result is not13:00
.
– sjahan
Nov 11 at 8:23
Just helping you debugging it: you cannot calltoString(something)
, what you should do issomething.toString()
.
– sjahan
Nov 11 at 8:26
The error comes from the fact that your code does not return what the assertion expects. Just call the function you've developed (without the asserts), for example:
addTime(12, 30, 30)
, you will see that the result is not 13:00
.– sjahan
Nov 11 at 8:23
The error comes from the fact that your code does not return what the assertion expects. Just call the function you've developed (without the asserts), for example:
addTime(12, 30, 30)
, you will see that the result is not 13:00
.– sjahan
Nov 11 at 8:23
Just helping you debugging it: you cannot call
toString(something)
, what you should do is something.toString()
.– sjahan
Nov 11 at 8:26
Just helping you debugging it: you cannot call
toString(something)
, what you should do is something.toString()
.– sjahan
Nov 11 at 8:26
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246777%2fjavascript-course-online-problems-with-task%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The error comes from the fact that your code does not return what the assertion expects. Just call the function you've developed (without the asserts), for example:
addTime(12, 30, 30)
, you will see that the result is not13:00
.– sjahan
Nov 11 at 8:23
Just helping you debugging it: you cannot call
toString(something)
, what you should do issomething.toString()
.– sjahan
Nov 11 at 8:26