scrimba
Note at 0:45
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Note at 0:45
AboutCommentsNotes
Note at 0:45
Expand for more info
main.js
run
preview
console
const validTime = str => parseInt(str.split(":")[0], 10) >= 0 && parseInt(str.split(":")[0], 10) <= 24 && parseInt(str.split(":")[1], 10) >= 0 && parseInt(str.split(":")[1], 10) < 60 

// const validTime = str => ~~str.split(":")[0] >= 0 && ~~str.split(":")[0] <= 24 && ~~str.split(":")[1] >= 0 && ~~str.split(":")[1] < 60

// In the 24-hour time notation, the day begins at midnight, 00:00, and the last minute of the day begins at 23:59. Where convenient, the notation 24:00 may also be used to refer to midnight at the end of a given date[5] — that is, 24:00 of one day is the same time as 00:00 of the following day.


/**
* Test Suite
*/
describe('validTime()', () => {
it('returns true for valid time', () => {
// arrange
const str = '13:58';

// act
const result = validTime(str);

// log
console.log("result 1: ", result);

// assert
expect(result).toBe(true);
});

it('returns false when invalid hours', () => {
// arrange
const str = '25:51';

// act
const result = validTime(str);

// log
console.log("result 1: ", result);

// assert
expect(result).toBe(false);
});

it('returns false when invalid minutes', () => {
// arrange
const str = '02:76';

// act
const result = validTime(str);

// log
console.log("result 1: ", result);

// assert
expect(result).toBe(false);
});
});
Console
"result 1: "
,
true
,
"result 1: "
,
false
,
"result 1: "
,
false
,
/index.html
LIVE