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:
-
function seconds(raw) {...}
-
function minutes(raw) {...}
-
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started