You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
727 B
JavaScript

3 years ago
function updateSplitBlocks(num, selectors) {
const numStr = numberPad(num, selectors.length, true)
for (let index in numStr) {
document.querySelector(selectors[index]).innerText = numStr[index].toString()
}
}
function numberPad(num, length, abs = false) {
3 years ago
// if (isNaN(num)) {
// num = 0
// }
3 years ago
const negative = num < 0 && !abs
3 years ago
// const outStr = Math.abs(num).toString().padStart(length, '0')
if (isNaN(num)) {
var outStr = num.toString().padStart(length, '-')
} else {
var outStr = num.toString().padStart(length, '0')
}
// const outStr = num.toString().padStart(length, '0')
3 years ago
if (negative) {
return '-' + outStr
}
return outStr
}