Skip to content

Instantly share code, notes, and snippets.

@Mariana88
Forked from colevandersWands/App-Object.js
Last active April 17, 2018 10:32
Show Gist options
  • Save Mariana88/9cc7ad2b66a9986e18df72f1a73ffc9e to your computer and use it in GitHub Desktop.
Save Mariana88/9cc7ad2b66a9986e18df72f1a73ffc9e to your computer and use it in GitHub Desktop.
var app = {
db: {},
next_id: 0,
create: function(newThing) {
// this.db[this.next_id] = newThing;
// this.next_id ++;
if(newThing !== ''){
this.db[this.next_id] = newThing;
this.next_id ++;
console.log("THING WAS ADDED")
return 'THING WAS ADDED';
}else{
console.log("ERROR")
return 'new value was an empty string, nopes.';
}
},
read: function(ID) {
if(this.db[ID]){
return this.db[ID];
} else {
return 'NOT FOUND';
}
},
update: function(ID, new_value) {
var returner = '';
if (this.db[ID]){
if (new_value !== ''){
this.db[ID] = new_value;
return 'ID was updated'
}
else {
return 'Invalid input';
}
}else if (new_value == ''){
return "Bad ID and bad input";
}
else {
return 'ID does not exist';
}
// make this work
return returner // all good, bad id, bad input or bad id & bad input
},
delete: function(ID) {
if(this.db[ID]){
this.db[ID] = undefined;
console.log('item WAS DELETED');
} else{
console.log('UNKNOWN ID');
}
}
};
console.log(app.create('Mariana'));
console.log(app.update(0,'Mariana wake up!'));
console.log(app.update (0, ''));
console.log(app.update (1, 'Bad proxy of Mariana'));
console.log(app.update (3,''));
console.log(app.db); //{0: 'Mariana wake up!'}
/*function app_handler() {
// read user input from dom
var result = app.create(user_input);
// write result to dom
}*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment