Skip to content

Instantly share code, notes, and snippets.

@luisangelma
Created August 4, 2015 00:35
Show Gist options
  • Select an option

  • Save luisangelma/551608bee8e3fe809a7a to your computer and use it in GitHub Desktop.

Select an option

Save luisangelma/551608bee8e3fe809a7a to your computer and use it in GitHub Desktop.
Dictionary
var Dictionary = function() {
var self = this;
var words = []
this.acceptWord = true;
this.addWord = function(word, def) {
words.push({
reference: word.toLowerCase(),
word: word.toLowerCase(),
def: def,
});
console.log(word + ' has been added to the dictionary');
};
this.lookUpWord = function(string) {
var string = string.toLowerCase();
for (var i = 0; i < words.length; i++) {
if(string === words[i].reference) {
console.log(string.toUpperCase() + '\n\nDefiniton: ' + words[i].def);
console.log('========================================');
}
}
};
};
var dictionary = new Dictionary();
dictionary.addWord('Car', 'a type of vehicle.');
dictionary.addWord('Dog', 'a domesticated carnivorous mammal.');
dictionary.addWord('Cat', 'a small domesticated carnivorous mammal.');
dictionary.lookUpWord('dog');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment