-
-
Save Mariana88/9cc7ad2b66a9986e18df72f1a73ffc9e to your computer and use it in GitHub Desktop.
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
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