Output is 3
Similarly the following code will give output of 0
Example : Using modules to reset an incremental counterWe will display on incremental counter by showing the value increasing from 0 to 29. The counter will increase by 1 after every second and on 30th second it will reset to 0.
Example : Changing background color of alternate elements of an arrayUsing this we can develop one application where alternate rows background color can be changed. We have seen how to display elements of an array here. Now by using modulus function we will make alternate array elements background colour to different one.
Here the variable i will have incremental numbers on each loop. By dividing it with 2 we will get reminder either zero or one alternately. So we can change the display of background colour by html span tag. Same way we can add each row background colour if we use a table to display elements.
Modulus is also called as modulo