scrimba
Note at 0:30
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:30
AboutCommentsNotes
Note at 0:30
Expand for more info
main.js
run
preview
console
const validTime = (str) => {
let arr = str.split(":")

arr.length != 2 ? false : true

let hour = parseInt(arr[0])
let minute = parseInt(arr[1])

return hour > 24 ? false : minute > 59 ? false : true

}


/**
* 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: "
,
false
,
"result 1: "
,
false
,
"result 1: "
,
true
,
/index.html
LIVE