Skip to content

Instantly share code, notes, and snippets.

@colorful-tones
Last active September 24, 2018 20:53
Show Gist options
  • Save colorful-tones/49cbf2ac9ce8efdc0357edea8a3e65c5 to your computer and use it in GitHub Desktop.
Save colorful-tones/49cbf2ac9ce8efdc0357edea8a3e65c5 to your computer and use it in GitHub Desktop.
[Fun with `for` loops] #JavaScript
// https://courses.wesbos.com/account/access/5b6921eb99ce1f5578c26a50/view/174357559
const cuts = [ 'Chuck', 'Brisket', 'Shank', 'Short Rib' ];
for ( const index in cuts ) {
console.log( cuts[index] );
}
// https://courses.wesbos.com/account/access/5b6921eb99ce1f5578c26a50/view/174357559
const cuts = [ 'Chuck', 'Brisket', 'Shank', 'Short Rib' ];
for ( let i = 0; i < cuts; i++ ) {
console.log( cuts[i];
}
// https://courses.wesbos.com/account/access/5b6921eb99ce1f5578c26a50/view/174357559
const cuts = [ 'Chuck', 'Brisket', 'Shank', 'Short Rib' ];
cuts.forEach( ( cut ) -> {
console.log( cut );
} );
// https://courses.wesbos.com/account/access/5b6921eb99ce1f5578c26a50/view/174357559
const cuts = [ 'Chuck', 'Brisket', 'Shank', 'Short Rib' ];
for ( const cut of cuts ) {
console.log( cut );
}
const buttons = document.querySelectorAll( '.button' );
for ( const button of buttons ) {
button.addEventListener( 'click', function() {
console.log( this.textContent );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment