JSFiddle - React, Tailwind, and code Playground

by Emily Humphrey

JavaScript

function getFixedCounter(k) {
	const obj = {
		value: 0
	}
	obj.increment = function(){
		this.value += k;
	};
	obj.decrement = function(){
		this.value = this.value - k;
	};
	obj.getValue = function(){
		return this.value;
	};
	return obj;
}

const a = getFixedCounter(10);

a.decrement();
a.increment();
a.decrement();


console.log(a.getValue())