Skip to content

Instantly share code, notes, and snippets.

@sionjlewis
Created May 30, 2015 14:39
Show Gist options
  • Save sionjlewis/abce88f4af9a435e9bcc to your computer and use it in GitHub Desktop.
Save sionjlewis/abce88f4af9a435e9bcc to your computer and use it in GitHub Desktop.
Every 2nd item

Every 2nd item ('-' * 14) The Javascript modulus operator ( % ) is used to calculate the remainder of two values if they were divided

A Pen by Siôn J. Lewis on CodePen.

License.

var myItem = ['item 01', 'item 02', 'item 03', 'item 04', 'item 05', 'item 06', 'item 07', 'item 08', 'item 09', 'item 10'];
for (i = 0; i < myItem.length; ++i) {
document.write(i + ': <span class="item">' + myItem[i] + '</span>');
if(i % 2 !== 0) {
document.write('</br>');
} else {
document.write('<span class="brake">, </span>');
}
}
.item {
color: lightgrey;
}
.brake {
color: red;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment