Recently, I've been working on a project to develop a 5th Edition D&D Character Generator App (I know, nerdy but fun!). One challenge I'm facing is how to ask specific questions based on the character's level without repeating all previous questions. For instance, if a character reaches level 1 as a Ranger, the app should inquire about favored terrain and enemies. When the character advances to level 2, it should only ask the new question for that level in addition to updating existing information. How can I achieve this seamless transition of updating information with each level progression?
I believe solving this issue will also help address how to update experience points without redundancy. If not, that will be my next hurdle to tackle.
Your insights would be greatly appreciated!
Take a look at a snippet of the code related to this:
if (level >= 1) {
var favTerrain1 = prompt("Name your favorite terrain.");
var favEnemy1 = prompt("Name your favorite enemy type or 2 humanoid races. (If you choose the latter, please separate with a comma.)");
document.getElementById("level1").innerHTML = "<h4><b> Favored Terrain: </b>" + favTerrain1 + "<br><b>Favored Enemy(Enemies): </b>" + favEnemy1 + "</h4>";
}
if (level >= 2) {
var lv2 = +prompt("Select a fighting style: 1. Archery 2. Defense 3. Dueling 4. Two-Weapon Fighting");
var level2;
switch(lv2) {
case 1:
level2 = "<b>Archery</b> You gain +2 bonus attack rolls you make with ranged weapons.";
break;
case 2:
level2 = "<b>Defense</b> While wearing armor, you gain a +1 bonus to armor class.";
armorClass = armorClass + 1;
break;
case 3:
level2 = "</b>Dueling</b> When wielding a melee weapon exclusively, a +2 bonus applies to damage rolls with that weapon.";
break;
case 4:
level2 = "<b>Two-Weapon Fighting</b> During two-weapon combat, you can add your ability modifier to the second attack's damage.";
break;
}
} else {
level2= " ";
}
The current setup prompts questions for both level 1 and level 2 upon upgrading from 1 to 2.