Skip to content

Instantly share code, notes, and snippets.

@dons20
Last active November 2, 2020 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dons20/b3f8bca5de2390c733d9de7cb21d2690 to your computer and use it in GitHub Desktop.
Save dons20/b3f8bca5de2390c733d9de7cb21d2690 to your computer and use it in GitHub Desktop.
Prints out the multiplication table up to 12x12
// Create array of 12 items from 1-12
let values = Array.from({length: 12}, (_, i) => i + 1);
// Iterate through array (new console log for each line)
values.forEach(value => console.log(Array.from({length: 12}, (_, i) => (i+1) * value).join(" ")));
// Alternative if one console log is to be displayed.
let table = [];
table = values.map(value => Array.from({length: 12}, (_, i) => (i+1) * value).join("\t\t"));
console.log(table.join("\n"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment