Created
August 4, 2015 00:35
-
-
Save luisangelma/551608bee8e3fe809a7a to your computer and use it in GitHub Desktop.
Dictionary
This file contains hidden or 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 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