please help me to figure out how to organize my result in rows of 10 numbers and create the look multiplication tables from 1 to 10 (SEE PICTURE SAMPLE OUTPUT)
I was asked to modify the following for loop (see below) to print out a table horizontally and write the function to execute multiple tables:
<script>
const multiplier = 2;
for(let i=i, i<=10; i++){
console.log(i*multiplier);
}
</script>
I got the for loop modified and it works (see below my code) but I get a long string of numbers:
let multiplier = 1;
let locationTables = '';
const tables = function tables(){
for(let y=1; y<= 10; y++){
let multiplication = y*multiplier;
locationTables += multiplication + ' ';
};
return multiplier +=1;
}
const factory = function factory(f){
while(multiplier <= 10){
let subtable = f();
}
}
var factortables = factory(tables);
console.log(locationTables);
I want to organize then in rows of 10 numbers and 10 columns (table 10×10).
3
Answers
You can add a new line to each output but then the are still not aligned. You can use padStart to fix this.
Here is an alternative way:
Try this. Instead of building up string we can push each value into an array within a main array. Each array is a "row" of data.
Ad the end you can either view the raw array data or format each row as a string