code from chapter 5 in javascript

This commit is contained in:
Kevin Nguyen
2016-06-17 10:03:11 -07:00
parent bad0a2ac3d
commit 96c766f9d9
2 changed files with 26 additions and 0 deletions

View 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 }

View 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!