Thank you for your response! However, while this does help a ton with some organization issues, it does not fix the main issue I am having. I think it was a bit unclear on what I needed. I have to rerun the code every time I need to add score, which resets all of the scores to 0 when I run it again. Here is my code to explain what I mean:
var game = {
i: 0,
c: 0,
g: 0,
e: 0,
addScore: function(add1, add2, add3, add4) {
game.i += add1;
game.c += add2;
game.g += add3;
game.e += add4;
}
};
function scoring(stats) {
switch (stats[0]) {
case "ian":
switch (stats[1]) {
case "win":
game.addScore(500,0,0,0);
break;
case "dealer":
if (i - 2000 >= 0) {
game.addScore(-2000,0,0,0);
}
break;
case "magician":
if (i - 5000 >= 0) {
game.addScore(-5000,0,0,0);
}
break;
}
break;
case "caden":
switch (stats[1]) {
case "win":
game.addScore(0,500,0,0);
break;
case "dealer":
if (c - 2000 >= 0) {
game.addScore(0,-2000,0,0);
}
break;
case "magician":
if (c - 5000 >= 0) {
game.addScore(0,-5000,0,0);
}
break;
}
break;
case "grace":
switch (stats[1]) {
case "win":
game.addScore(0,0,500,0);
break;
case "dealer":
if (g - 2000 >= 0) {
game.addScore(0,0,-2000,0);
}
break;
case "magician":
if (g - 5000 >= 0) {
game.addScore(0,0,-5000,0);
}
break;
}
break;
case "evan":
switch (stats[1]) {
case "win":
game.addScore(0,0,0,500);
break;
case "dealer":
if (e - 2000 >= 0) {
game.addScore(0,0,0,-2000);
}
break;
case "magician":
if (e - 5000 >= 0) {
game.addScore(0,0,0,-5000);
}
break;
}
break;
}
console.log("Ian: "+game.i+"\nCaden: "+game.c+"\nGrace: "+game.g+"\nEvan: "+game.e);
}
var stats = [];
stats.push(prompt("Enter a name"));
stats.push(prompt("Enter scoring type (kit name or win)"));
scoring(stats);
The format for scoring is in the form of a function, and I cannot figure out how to loop it so I don’t have to rerun the code every time. Is there a way for me to do that, or possibly a way to remove the function but keep the way it works?