Print Multiplication Tables

artydev - Oct 13 '23 - - Dev Community

I have been asked to print arbitrary multiplication tables for kids.
Note the usage of 'bind', very handy, and the absence of 'for loops'.


function mul (x, y) {
  return x * y
}

function multTables(tables = []) {
    tables.map(n => {
      let mulby = mul.bind(null, n)
      app.innerHTML += `
        <div>
          <ul>
            ${[...Array(10)]
              .map((_, v) => v + 1)
              .map(mulby)
              .map((x, i) => `
                <li>
                  <span>${n}</span>
                  <span>x</span>
                  <span>${i + 1}</span>
                  <span>=</span>
                  <span class="result">${x}</span>
                </li>`
              ).join('')}
          </ul>
        </div>`
   });
}

multTables([3, 4, 6, 13])

Enter fullscreen mode Exit fullscreen mode

Result :

Image description

You can play with it here : Tables

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player