scrimba
Note at 1:04
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 1:04
AboutCommentsNotes
Note at 1:04
Expand for more info
main.js
run
preview
console
function validTime(str) {
// write code here.
// console.log(str);
const arrTime = [];

const strSplit = str.split('');
// console.log(strSplit);
for(let i = 0; i < strSplit.length; i++) {
// console.log(strSplit[i]);
if(strSplit[i] != ':') {
arrTime.push(parseInt(strSplit[i]))
}
}

if(
arrTime[0] >= 0 && arrTime[0] <= 2 &&
arrTime[1] >= 0 && arrTime[1] <= 3 &&
arrTime[2] >= 0 && arrTime[2] <= 5 &&
arrTime[3] >= 0 && arrTime[3] <= 9
) {
// console.log(arrTime);
return true;
} else {
return false;
}
}



/**
* 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