// // Note: refactoring the multiplication table example // 1. add initial column and row ??? // 2. extract padSpace() call // 3. turn above program into a function that takes a number N, so that you can produce N x N multiplication table // function multiplication( N ) { for(var a=1; a<=N; a++) { var line = ""; for(var b=1; b<=N; b++) { var v = a * b; line = line + padSpace(v) + v; } console.log( line ); } } function padSpace( v ) { // add spaces for proper formatting var spaces = ""; if( v < 10 ) { spaces = " "; } else if( v < 100 ) { spaces = " "; } else { spaces = " " } return spaces; } // invoke it multiplication( 12 );