1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
aleksley [76]
2 years ago
9

Have the javascript function CountingMinutes(str) take the str parameter being passed which will be two times (each properly for

matted with a colon and am or pm) separated by a hyphen and return the total number of minutes between the two times. The time will be in a 12 hour clock format. For example: if str is 9:00am-10:00am then the output should be 60. If str is 1:00pm-11:00am the output should be 1320.
function CountingMinutes(str) {
// code goes here
return str;
}
// keep this function call here
console.log(CountingMinutes(readline()));
Computers and Technology
1 answer:
jarptica [38.1K]2 years ago
5 0

Using the knowledge in computational language in Java it is possible to write a code that function as CountingMinutes:

<h3>Writing the code in Java:</h3>

function CountingMinutes(str) {

     // code goes here  

     // Declare variables for calculating difference in minutes

     // variables in JavaScript are declared with "let" keyword

     /* Build regelar expression which will match the pattern of "12houttime-12hourtime"

        and extract time or hours in numbers from it */

     let extractedTimeStringArray = str.match(/(\d+)\:(\d+)(\w+)-(\d+)\:(\d+)(\w+)/);

     // extractedTimeStringArray array will be like- ["1:00pm-11:00am", "1", "00", "pm", "11", "00", "am", index: 0, input: "1:00pm-11:00am", groups: undefined]    for str = "1:00pm-11:00am"

     // console.log('object', time)

     

     // Extract array value at 1st index for getting first time's hours (ie time before hyphen like 1:00pm in 1:00pm-11:00am )  (like 11 from 11:32am) and convert them to minutes by multiplying by 60

     let mintsOfFirstTimeFromHours = extractedTimeStringArray[1] * 60;

     // Extract array value at 2nd index for getting first time's minutes like 32 from 11:32am

     let mintsOfFirstTimeFromMints = extractedTimeStringArray[2];

     // Extract array value at 4th index for getting second time's hours (ie time after hyphen like 11:00am in 1:00pm-11:00am ) and convert them to minutes by multiplying by 60

     let mintsOfSecondTimeFromHours = extractedTimeStringArray[4] * 60;

     // Extract array value at 5th index for getting second time's minutes like 32 from 11:32am

     let mintsOfSecondTimeFromMints = extractedTimeStringArray[5];

     // if second time's 12 hour time is in pm

     if (extractedTimeStringArray[6] === "pm") {

       // Add 12 * 60 = 720 minutes for 12 hrs

         mintsOfSecondTimeFromHours += 720;

     }

     // if first time's 12 hour time is in pm

     if (extractedTimeStringArray[3] === "pm") {

        // Add 12 * 60 = 720 minutes for 12 hrs to first time

       mintsOfFirstTimeFromHours += 720;

        // Add 12 * 60 *2 = 1440 minutes for 24 hrs to second time

       mintsOfSecondTimeFromHours += 1440;

     }

     // Calculate output minutes difference between two times separated by hyphen

    str = (mintsOfSecondTimeFromHours - mintsOfFirstTimeFromHours) + (mintsOfSecondTimeFromMints - mintsOfFirstTimeFromMints);

     // return calculated minutes difference

     return str;

   }

   // keep this function call here

   // call the function and console log the result

   console.log(CountingMinutes("1:00pm-11:00am"));

   // output in console will be-  1320

See more about Java at: brainly.com/question/12975450

#SPJ1

You might be interested in
Evaluate the expression. Be sure to list a value of appropriate type (e.g., 7.0 rather than 7 for a double, Strings in quotes).
Mashutka [201]
<h2>Answer:</h2>

14.0

<h2>Explanation:</h2>

Using the level of precedence in Java,

From left to right;

(i) the first division operation will be done.

(ii)followed by the second division operation.

(iii)followed by the first multiplication operation.

(iv)followed by the third division operation.

(v)followed by the second multiplication operation.

(vi) followed by the first addition operation.

(vii)lastly followed by the second addition operation.

=================================================

Taking the steps above one after the other;

<em>(i) the first division operation will be done (i.e 19 / 2)</em>

=> Integer division in Java gives an integer result. Therefore, 19 / 2 = 9.5 will give 9.

So,

=><em> </em><u>19 / 2</u> / 2.0 + 2.5 * 6 / 2 + 0.5 * 4

=> 9 / 2.0 + 2.5 * 6 / 2 + 0.5 * 4

<em>(ii)followed by the second division operation. (i.e 9 / 2.0)</em>

=> From the result from step (i), the second division operation is now 9 / 2.0.

=> 9 / 2.0 = 4.5

So,

=> <u>9 / 2.0</u> + 2.5 * 6 / 2 + 0.5 * 4

=> 4.5 + 2.5 * 6 / 2 + 0.5 * 4

<em>(iii)followed by the first multiplication operation. (i.e 2.5 * 6)</em>

=> The first multiplication operation is given by 2.5 * 6

=> 2.5 * 6 = 15.0

So,

=> 4.5 + <u>2.5 * 6</u> / 2 + 0.5 * 4

=> 4.5 + 15.0 / 2 + 0.5 * 4

<em>(iv)followed by the third division operation. (i.e 15.0 / 2)</em>

=> The third division operation is given by 15.0 / 2

=> 15.0 / 2 = 7.5

So,

=> 4.5 + <u>15.0 / 2</u> + 0.5 * 4

=> 4.5 + 7.5 + 0.5 * 4

<em>(v)followed by the second multiplication operation. (i.e 0.5 * 4)</em>

=> The second multiplication operation is given by 0.5 * 4

=> 0.5 * 4 = 2.0

So,

=> 4.5 + 7.5 + <u>0.5 * 4</u>

=> 4.5 + 7.5 + 2.0

<em>(vi) followed by the first addition operation. (i.e 4.5 + 7.5)</em>

=> The first addition operation is given by 4.5 + 7.5

=> 4.5 + 7.5 = 12.0

So,

=> <u>4.5 + 7.5</u> + 2.0

=> 12.0 + 2.0

<em>(vii) lastly followed by the second addition operation. (i.e 12.0 + 2.0)</em>

=> The second addition operation is given by 12.0 + 2.0

=> 12.0 + 2.0 = 14.0

So,

=> <u>12.0 + 2.0</u>

=> 14.0

<em>Therefore, 19 / 2 / 2.0 + 2.5 * 6 / 2 + 0.5 * 4 = 14.0</em>

<h2>Note:</h2>

In Java, the order of precedence for arithmetic operators is;

=> /, * and %

=> followed by + and -

6 0
3 years ago
Which of the following is a difference between a centralized communication network and a decentralized communication network? a.
Crazy boy [7]

Option D is the answer.

Option A is rejected because in centralized communication notwork there is no free flow of communication in all directions ( all direction means between all the groups or layers of the network).

Option B is not the answer because centralized and decentralized networks has nothing to do with the size of organizations.

Option C is rejected because decision making process depends on the hard work and technical skills of groups of an organization about a field but not by the network discipline.

Option D is selected because in centralized network the information or decision making power is primarily limited to the upper level or higher members of organization and as mentioned decentralized decides on the basis of decision of all the groups or levels of the network.

5 0
3 years ago
Write a C program to perform simple C arithmetic calculations. The user is to enter a simple expression (integer operator intege
Ilya [14]

Answer:

Input example:

select the funcion: 1                                                                                                                  

write the 1sd number2                                                                                                                  

write the 2nd number1                                                                                                                  

value is 2.000000                                                                                                                      

Explanation:

#include <stdio.h>

main()

{

//define the variables as float

float a, b, c, e;

char d;

while (1)  

{      

//input values

printf("select the function: ");

scanf("%c",&d);

printf("write the 1sd number");

scanf("%f",&a);

getchar();

printf("write the 2nd number");

scanf("%f",&b);

getchar();

if (d=='%')

{

    a=a*b/100;

}

if (d=='*')

{

    a=a*b;

}

if (d=='+')

{

    a=a+b;

}

if (d=='/')

{

    a=a/b;

}

if (d=='-')

{

    a=a-b;

}

printf("value is %f \n",a);

}

printf("final value is %f",a);

getchar();

}

8 0
4 years ago
HELPPP!! Ghost_diary
Elena-2011 [213]

Answer:

manga or an anime a a a a a a a a

8 0
3 years ago
How many types of string types does python support?​
Andru [333]

Answer:

47

Explanation:

they support all of them,more their babies and offspring

7 0
3 years ago
Other questions:
  • This toolbar has icons representing the application's basic operations such as Save and Copy. Drawing Formatting Standard Task
    11·2 answers
  • What is grid computing? It is distributed computing where autonomous computers perform independent tasks. It is interconnected c
    12·1 answer
  • ____ is a font that resembles the letters that typewriters produced.
    9·1 answer
  • Fill in the blank <br>computers are closed in......​
    6·1 answer
  • Huffman trees use the _________ of each character to work out their encoding. A) Frequency B) Order in ASCll
    12·1 answer
  • Examine the following algorithm.
    9·1 answer
  • Pls help I will give points
    7·1 answer
  • Write a program that gets a list of integers from a user. First, the user should be asked to enter the number of integers to be
    5·1 answer
  • What is the purpose of including comments in code?
    15·1 answer
  • what technique, in which multiple phones take turns sharing a channel, does the global system for mobile communications (gsm) us
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!