Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

206
Vistas
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 Respuestas
Responde la pregunta

0

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda