I'm trying to write a basic function which allows a user to enter a category (either game or player) and a number within that category to return either the player name or the game name.
var objName = "";
var playerObj = {
12: "Tasneem",
16: "Kevin",
19: "Bevan"
};
var gameObj = {
22: "Tetris",
56: "Mario",
16: "Donkey Kong"
};
function playerOrGame(prefix, num) {
objName = prefix + "Obj";
return objName[num];
};
console.log(playerOrGame("player", 16))
In the above code,
playerOrGame("player", 16)
should return "Kevin". What am I doing wrong?