Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

211
Visualizações
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 Respostas
Responde à pergunta

0

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

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda