[JavaScript] 7-2 and then what time (15 minutes)



Sometimes people use four digits to represent a time. For example, 1106 means 11:06. Now, your program calculates the end time based on the start time and the elapsed time.

Read in two numbers. The first number represents the current time with such four digits, and the second number represents the minutes. Calculate the time after so many minutes, and the result is also expressed as four digits. When the hour is a single digit, there is no leading zero, for example, 5:30 is 530; 0:30 means 030. Note that the second number may represent more than 60 minutes or a negative number.

Input format:

Input gives two integers in one line, which are the starting time represented by four digits and the elapsed minutes, separated by spaces. Note: in the starting time, when the hour is a single digit, there is no leading zero, that is, 5:30 is 530; 0:30 means 030. The number of minutes passed may be more than 60 or negative.

Output format:

Output the termination time represented by four digits. When the hour is a single digit, there is no leading zero. The title shall be guaranteed to start and end on the same day.

Input sample:

1120 110



Output example:




Javascript code:

const { parse } = require('path')
var readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout

rl.on('line', function(line) {
    var tokens = line. Split ("") // space delimited strings as string arrays
    var m = parseInt(tokens[0])
    var n = parseInt(tokens[1])
    var ret = time(m,n)

function time(m,n){
    var a1 = m % 100
    var a2 = (m - a1) / 100
    Var begin = A2 * 60 + A1 // starting minutes
    Var final = n + begin // termination minutes

    Var min = final% 60 // termination minutes
    Var hour = (final - min) / 60 // termination hours
    if(hour != 0){
        s = hour * 100 + min
    } else{
        var str1 = hour.toString()
        var str2 = min.toString()
        s = str1 + str2
    return s 


Recommended Today

CSS function those things (III) background image function

url() The URL function represents a reference to a resource, which can pass in links and relative addresses, such as Background image: URL (‘.. / background image function. PNG’); background-image: url(‘https://s3.ax1x.com/2020/11/29/DcV9V1.png’); image() Image functions are similar to URLs, but unlike URLs, image provides agraceful degradation Ability. such as background-image: image(‘a.webP’,’a.png’,’a.jpg’); This code means that if […]