Question: (Answer this question with a thumb up! - Using Javascript and js to run) Write a Constructor function named Duration. Duration should take a single

(Answer this question with a thumb up! - Using Javascript and js to run)

Write a Constructor function named Duration. Duration should take a single argument, value, which is a Number of seconds, and it should store value on the Object being created. If value is missing, default to 0 (zero).

The Duration Constructor should have 3 methods defined on its Prototype:

  1. function seconds(raw) {...}

  2. function minutes(raw) {...}

  3. function hours(raw) {...}

All three work in the same way: if the raw argument is true, return the number of seconds, minutes, or hours for this duration (i.e., calculate it based on the instances value property). If raw is false (not true), return a formatted string. Here are some examples of how it should work:

let d = new Duration(0); d.seconds(true); // should return 0 (zero) 
let d = new Duration(1); d.seconds(true); // should return 1 d.seconds(); // should return 1 second, note the singular second 
let d = new Duration(2); d.seconds(true); // should return 2 d.seconds(); // should return 2 seconds, note the plural seconds 
let d = new Duration(59); d.minutes(true); // should return 0.9833333333333333 d.minutes(); // should return Less than a minute 
let d = new Duration(60); d.minutes(true); // should return 1 d.minutes(); // should return 1 minute, note the singular minute 
let d = new Duration(120); d.minutes(true); // should return 2 d.minutes(); // should return 2 minutes, note the plural minutes 
let d = new Duration(360); d.hours(true); // should return 0.1 d.hours(); // should return Less than an hour 
let d = new Duration(3600); d.hours(true); // should return 1 d.hours(); // should return 1 hour, note the singular hour 
let d = new Duration(10800); d.hours(true); // should return 3 d.hours(); // should return 3 hours, note the plural hours 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!