JSFiddle - React, Tailwind, and code Playground
by nmartin413
HTML
<input type="text" id="ninjaCount" value="???" />
<button id="addNinja">Add Ninja</button>
<button id="updateCount">Update Ninja Count</button>
JavaScript
function NinjaDen() {
// scoped & not accessible to the global context
var ninjaCount = 0;
this.addNinja = function () {
ninjaCount++;
}
this.getNinjaCount = function () {
return ninjaCount;
}
}
window.onload = function () {
var ninjaDen = new NinjaDen();
document.getElementById('addNinja').onclick = ninjaDen.addNinja;
document.getElementById('updateCount').onclick = function () {
this.value = ninjaDen.getNinjaCount();
}
}