# Example of% in JavaScript for remainder or modulo

Source: Internet
Author: User
Tags time and seconds

Take the remainder in JS

0%4
0
1%4
1
2%4
2
3%4
3
4%4
0
5%4
1

Example

Gets the day, hour, and minute contained in minutes, based on the number of minutes

function Getcosttime (minutes) {
var day=parseint (minutes/1440);
var hour=parseint (MINUTES/60);
var minute=parseint (minutes%60);
var string_description=day>0?day+ "Day": "";
String_description+=hour>0?hour+ "Hour": "";
String_description+=minute>0?minute+ "Minutes": "";
return string_description;
}

Perform
(function () {
var minutes=1426;
var time=getcosttime (minutes);
})();
Results
23 hours, 46 minutes.

example, JS modulus (for remainder) interlace color

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<TITLE>JS-mode interlace color </title>
<script type= "Text/javascript" >
{
var Oul=document.getelementbyid (' Ul1 ');
var ali=oul.getelementsbytagname (' Li ');

for (var i=0; i< aLi. length; i++)
{
if (i%2==0)//modulo remainder
{
ali[i].style.background= ' Red ';
}
}
}
</script>
</script><body>
<ul id= "UL1" >
<li>webtall</li>
<li>webtall</li>
<li>webtall</li>
<li>webtall</li>
<li>webtall</li>
</ul>
</body>

Examples of alternating discoloration (% remainder or modulo)

The color of a small instance of interlacing before the first understanding of the remainder (modulo)% operation, this is the remainder of the operation, not division operations.
12 divided by 5=2, the remainder is 2, that is 5*2+2=12, so 12%5=2
7 divided by 3=2, the remainder is 1, that is 3*2+1=7, so 7%3=1
1 divided by 2, but the remainder is 1.
2*0+1=1
/*

--no remainder, so 0---

......   */

small instances of interlaced discoloration

JS:

var ali= document.getElementsByTagName (' li ');

/*
for (var i=0 i<ali.length; i++)
{
if (i%2==0)
{
ali[i].style.background= ' red ';
}
}
<--  Complementary methods  -->
*/

;
for (var i=0 i<ali.length; i+=2)
{
ali[i].style.background= ' red ';
}  /*for Loop method */

};

HTML:

<ol>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ol>

conversion of time and seconds using the mode of taking

Var inum=605;  //sec

Alert ( parseint (INUM/60) + ' min ' +inum%60+ ' seconds ');

Related Keywords:
Related Article

## E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

## Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

## Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth \$300-1200 USD