Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
Javascript: OR operator not giving expected output

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."?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!