Generate Multiplication Table

// You can make it as big as you want, I think // Also it formats the numbers so they are evenly spaced // JS Bin DEMO: http://jsbin.com/akiyoy/7/ var multiTable = function(a,b) { var maxX; var maxY = b; var counterY = 1; var maxNum = (a * b) + ""; var counterX; var lineOut; var temp; while(maxY > 0) { counterX = 1; maxX = a; lineOut = ""; while(maxX > 0) { temp = 0; lineOut += counterX * counterY; temp = (counterX * counterY) + ""; spaceLength = maxNum.length - temp.length; while(spaceLength >= 0) { lineOut += " "; spaceLength--; } maxX--; counterX++; } console.log(lineOut); counterY++; maxY--; } }; multiTable(15,65);
Takes in two variables, the maximum numbers to create the table and outputs a multiplication table formatted so the numbers are evenly spaced.

Here's a link to a JS Bin as an example: http://jsbin.com/akiyoy/7/

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.