VendingMachine2
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/ajv/3.8.0/ajv.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.5.1/lodash.min.js"></script>
See https://gist.github.com/aercolino/4c474de6c95c3bedeef2
JavaScript
(function() {
'use strict';
const stopCode = '++';
console.log('To start the Vending Machine, issue vm.Start().');
console.log('To stop the Vending Machine, type "' + stopCode + '" at any prompt.');
issue vm.Start()
window.vm = VendingMachine({
products: {
'COKE': {
name: 'Coca Cola',
price: 129,
units: 12,
maxUnits: 20
},
'AQUA': {
name: 'Water',
price: 99,
units: 4,
maxUnits: 20
}
},
coins: {
'1¢': {
name: '1 cent',
price: 1,
units: 41,
maxUnits: 50
},
'2¢': {
name: '2 cents',
price: 2,
units: 33,
maxUnits: 50
},
'5¢': {
name: '5 cents',
price: 5,
units: 27,
maxUnits: 50
},
'10¢': {
name: '10 cents',
price: 10,
units: 41,
maxUnits: 50
},
'20¢': {
name: '20 cents',
price: 20,
units: 33,
maxUnits: 50
},
'50¢': {
name: '50 cents',
price: 50,
units: 27,
maxUnits: 50
},
'1€': {
name: '1 euro',
price: 100,
units: 41,
maxUnits: 50
},
'2€': {
name: '2 euros',
price: 200,
units: 33,
maxUnits: 50
},
}
});
return;
function VendingMachine(data, displayProvider, promptProvider) {
var privateStorage = {};
var ajv = Ajv({
...