Skip to content

Instantly share code, notes, and snippets.

@indraai

indraai/DecisionLogic.js

Last active Oct 26, 2020
Embed
What would you like to do?
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