Skip to content

Commit bad0a2a

Browse files
author
Kevin Nguyen
committed
code from chapter 5 in javascript
1 parent 040cfe5 commit bad0a2a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
const book = {};
4+
// an apple costs 67 cents
5+
book['apple'] = 0.67;
6+
// milk costs $1.49
7+
book['milk'] = 1.49;
8+
book['avocado'] = 1.49;
9+
10+
console.log(book); // { apple: 0.67, milk: 1.49, avocado: 1.49 }

05_hash_tables/02_check_voter.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
const voted = {};
4+
function check_voter(name) {
5+
if (voted[name]) {
6+
console.log('kick them out!');
7+
} else {
8+
voted[name] = true;
9+
console.log('let them vote!');
10+
}
11+
}
12+
13+
14+
check_voter("tom"); // let them vote!
15+
check_voter("mike"); // let them vote!
16+
check_voter("mike"); // kick them out!

0 commit comments

Comments
 (0)