Skip to content

Instantly share code, notes, and snippets.

@linxinemily
Last active April 27, 2019 17:00
Show Gist options
  • Save linxinemily/301d314937a49fc1a3dc3628b4e038c3 to your computer and use it in GitHub Desktop.
Save linxinemily/301d314937a49fc1a3dc3628b4e038c3 to your computer and use it in GitHub Desktop.
9x9-example
// data
const grid : HTMLElement = document.querySelector('.grid')
const titleCell : HTMLElement = document.querySelector('.grid-title')
// UI
function addNewElement(startNum : number) {
let newCell : HTMLElement = document.createElement('div')
newCell.className = 'grid-cell'
let str :string = `<div class="title">${startNum}</div>`
for (let i = 1; i < 10; i++) {
str += `<div>${startNum} x ${i} = ${startNum * i }</div>`
}
newCell.innerHTML = str
grid.insertBefore(newCell, titleCell.nextSibling)
}
for (let i = 9; i > 1; i--) {
addNewElement(i)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment