Day 12 is checking the value of time.
If the given value is 13:58
will gives true
value as a valid time.
If the given value is 25:51
will gives false
value as a not valid time.
If the given value is 02:76
will gives false
value as a not valid time.
This is the JavaScript solution
function validTime(str) {
let [hour, min] = str.split(':').map(val => parseInt(val));
let hoursMark = false, minsMark = false;
if(hour >= 0 && hour < 24){
hoursMark = true;
}
if (min >= 0 && min < 60) {
minsMark = true;
}
if(hoursMark && minsMark === true) {
return true;
}
else {
return false;
}
}
Top comments (0)