-1

I'm currently challenging myself to make a D&D 5E character sheet from scratch using HTML, CSS, and JavaScript. Currently, I'm merely testing because I'm very new to JavaScript and I'm not too sure how it operates yet. The problem I am having right now is creating if statements with OR operators. I don't want to create a giant, bloated "if, if else, else" block, I want to streamline it a bit.

Here is my HTML for the dropdown selector for character classes.

<input type="number" id="stat" value="0"> <button id="roll-btn">Roll Stats</button><br><br>
    <select name="class" id="character-class">
        <option value="artificer">Artificer</option>
        <option value="barbarian">Barbarian</option>
        <option value="bard">Bard</option>
        <option value="cleric">Cleric</option>
        <option value="druid">Druid</option>
        <option value="fighter">Fighter</option>
        <option value="monk">Monk</option>
        <option value="paladin">Paladin</option>
        <option value="ranger">Ranger</option>
        <option value="rogue">Rogue</option>
        <option value="sorcerer">Sorcerer</option>
        <option value="warlock">Warlock</option>
        <option value="wizard">Wizard</option>
    </select>

Here is the test version of the javascript that is supposed to read what type of class is selected, and then change values depending on what type of class (what hit dice it uses, saving throw proficiencies, etc.)

let characterClass = document.getElementById("character-class").value /* Determines the selected class. Will be set to "artificer" by default */
console.log(characterClass)

if (characterClass === "wizard"||"sorcerer") { /* Wizard and sorcerer both have a hit die value of a D6 */
    console.log("Squishy boi")
} else {
    console.log("Not a wizard/sorcerer")
}

However, when I run this code, it prints "squishy boi" despite being set to "artificer" by default. Am I misunderstanding how || (or) works in JS? Is it not "if characterClass is either wizard or sorcerer, do this, otherwise do this."?

tubahorse
  • 3
  • 2

1 Answers1

0

it needs to be if (characterClass === "wizard"|| characterClass === "sorcerer") {

dippas
  • 58,591
  • 15
  • 114
  • 126