Skip to content

Instantly share code, notes, and snippets.

@indraai
Last active October 26, 2020 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indraai/8277b7a72f5dad50eeba916a3abbe206 to your computer and use it in GitHub Desktop.
Save indraai/8277b7a72f5dad50eeba916a3abbe206 to your computer and use it in GitHub Desktop.
A usage of list based state choice logic
// HTML
// <input type="text" id="choice" value="choice1" onchange="ch.decide()"></input>
// JAVASCRIPT
class ChoiceMaker {
constructor() {
this.choice = false;
this.logs = [];
}
log() {
this.logs.push({choice:this.choice, created:Date.now()});
}
decide() {
try {
this.choice = document.getElementById('choice').value;
this.log();
return console.log(this[this.choice]());
}
catch(err) {
throw new Error(err);
}
}
choice1() {
return `FIRST CUSTOM CHOICES ${this.choice}`;
}
choice2() {
return this.logs;
}
choice3() {
return Date.now();
}
choice4() {
return "I'M DANCING!!!!!!! :) --- " + this.choice;
}
}
const ch = new ChoiceMaker();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment