Listing 10.03 - Using a function to add ages
JS Bin
var ages = {};
var addAge = function (name, age) {
ages[name] = age;
};
addAge("Kandra Smith", 56);
addAge("Dax Aniaku", 21);
console.log(ages["Kandra Smith"]);
console.log(ages["Dax Aniaku"]);
Listing 10.03 - Using a function to add ages - Tasks 1 & 2
- Use the addAge function to add a couple more people and their ages.
- Log the new info to the console.
var ages = {};
var addAge = function (name, age) {
ages[name] = age;
};
addAge("Kandra Smith", 56);
addAge("Dax Aniaku", 21);
// add a couple more people
addAge("Filboid Studge", 120);
addAge("??? Mr Nigma ???", 37);
console.log(ages["Kandra Smith"]);
console.log(ages["Dax Aniaku"]);
// log new info
console.log(ages["Filboid Studge"]);
console.log(ages["??? Mr Nigma ???"]);