diff --git a/05_hash_tables/01_price_of_groceries.js b/05_hash_tables/01_price_of_groceries.js new file mode 100644 index 0000000..a95d3d2 --- /dev/null +++ b/05_hash_tables/01_price_of_groceries.js @@ -0,0 +1,10 @@ +'use strict'; + +const book = {}; +// an apple costs 67 cents +book['apple'] = 0.67; +// milk costs $1.49 +book['milk'] = 1.49; +book['avocado'] = 1.49; + +console.log(book); // { apple: 0.67, milk: 1.49, avocado: 1.49 } diff --git a/05_hash_tables/02_check_voter.js b/05_hash_tables/02_check_voter.js new file mode 100644 index 0000000..288eba6 --- /dev/null +++ b/05_hash_tables/02_check_voter.js @@ -0,0 +1,16 @@ +'use strict'; + +const voted = {}; +function check_voter(name) { + if (voted[name]) { + console.log('kick them out!'); + } else { + voted[name] = true; + console.log('let them vote!'); + } +} + + +check_voter("tom"); // let them vote! +check_voter("mike"); // let them vote! +check_voter("mike"); // kick them out!