scrimba
Note at 0:00
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:00
AboutCommentsNotes
Note at 0:00
Expand for more info
main.js
run
preview
console
function validTime(str) {
// write code here.

// Goal: To Use ParseInt , Split
// Got Memories of school, This is called railway time in india
// Thanks for the memories....
// Tried without variables for fun...

return str.split(':').length === 2
&& parseInt(str.split(':')[0],10)>=0
&& parseInt(str.split(':')[0],10)<=23
&& parseInt(str.split(':')[1],10)>=0
&& parseInt(str.split(':')[1],10)<=59;

}



/**
* Test Suite
*/
describe('validTime()', () => {
it('returns true for valid time', () => {
// arrange
const str = '14: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