JSFiddle - React, Tailwind, and code Playground
HTML
<button id="btn_minus">-</button>
<pre id="inp">1</pre>
<button id="btn_plus">+</button>
CSS
#inp {
display: inline-block;
outline: dashed 1px gray;
padding: 0.5em;
}
JavaScript
const values = [1, 2, 4, 6, 8, 10, 12, 16, 20, 24, 32, 48, 56, 64]
btn_plus.addEventListener('click', increment)
btn_minus.addEventListener('click', decrement)
function increment() {
const nextIndex = getCurrentIndex() + 1
if (values[nextIndex])
inp.textContent = values[nextIndex]
}
function decrement() {
const prevIndex = getCurrentIndex() - 1
if (values[prevIndex])
inp.textContent = values[prevIndex]
}
function getCurrentIndex() {
const currentVal = parseInt(inp.textContent)
return values.indexOf(currentVal)
}