beginning in coding, I'm trying to build a function that asks the user to enter a value for hour then for minutes and return an array showing clock one minute later, but it isn't working I tried to fix it for some hours now and am really stuck, could anyone tell me where am wrong please?
let hour = window.prompt("Enter hour", "");
let minutes = window.prompt("Enter minutes", "");
function clock(hour, minutes) {
let arr = [];
if(0 <= hour < 23 && 0 <= minutes < 59) {
arr.push(hour, minutes + 1);
} else if((minutes == 59) && (hour == 23)){
arr.push(0, 0);
}
return arr;
}
clock();
console.log(clock(23, 59));// Got [23, 60] ❌ should return [0, 0]
console.log(clock(15, 3));// Got [15, 4] ✅
Thanks for answering, here is the clean code
function clock(hour, minutes) {
let arr = [];
if(0 <= minutes && minutes < 59) {
arr.push(hour, minutes + 1);
} else if(minutes == 59){
arr.push(hour + 1, 0);
if(hour == 23){
arr.push(0, 0);
}
}
return arr;
}
clock();
console.log(clock(13, 27)); // returns [13, 28];
console.log(clock(13, 59)); // returns [14, 0];