Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
Trying to build a function() returning hour + (minutes + 1)

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];
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I don't think you can do this: 0 <= hour < 23 && 0 <= minutes < 59

It should be: 0 <= hour && hour < 23 && 0 <= minutes && minutes < 59

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!