Move js to after canvas creation. Add beat functions to js.