code from chapter 5 in javascript
This commit is contained in:
10
05_hash_tables/javascript/01_price_of_groceries.js
Normal file
10
05_hash_tables/javascript/01_price_of_groceries.js
Normal file
@@ -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 }
|
||||||
16
05_hash_tables/javascript/02_check_voter.js
Normal file
16
05_hash_tables/javascript/02_check_voter.js
Normal file
@@ -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!
|
||||||
Reference in New Issue
Block a user