Last active
October 26, 2020 08:05
-
-
Save indraai/8277b7a72f5dad50eeba916a3abbe206 to your computer and use it in GitHub Desktop.
A usage of list based state choice logic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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