Open In App

JavaScript Program to Convert Minutes into Seconds

Last Updated : 01 May, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Minutes and seconds are important for planning schedules and managing daily activities. Understanding this conversion helps in better time management. These units are essential for managing schedules, planning activities, and organizing daily routines.

Example:

// Formula to convert minutes into seconds:
1 minute = 1 * 60 seconds

Below are the approaches for converting minutes into seconds in JavaScript:

Table of Content

Using Function

In this approach, the code defines a function, convertMinutesToSeconds, that takes the minutes as an input parameter for converting it into seconds. It then invokes the function with a minute value of 4. Inside the function, use the formula: minute*60, to convert it into seconds in JavaScript. Finally, return the result.

Example: The example below demonstrates converting minutes into seconds using a function.

JavaScript
function convertMinutesToSeconds(minutes) {
    return minutes * 60;
}

const minutes = 4;
const seconds = convertMinutesToSeconds(minutes);
console.log("Seconds:", seconds);

Output
Seconds: 240

Time Complexity: O(1)

Space Complexity: O(1)

Using Class

In this approach, define a class named TimeConverter which will contain a method called convertToSeconds, which will handle the conversion of minutes into seconds. Instantiate the TimeConverter class using the new keyword, which creates an object of the class. Call the convertToSeconds method on the converter object, passing the number of minutes you want to convert as an argument. Print result.

Example: The example below demonstrates converting minutes into seconds using class.

JavaScript
class TimeConverter {
    convertToSeconds(minutes) {
        return minutes * 60;
    }
}

const converter = new TimeConverter();
const minutes = 4;
const seconds = converter.convertToSeconds(minutes);
console.log("Seconds:", seconds);

Output
Seconds: 240

Time Complexity: O(1)

Space Complexity: O(1)


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads