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

264
Visualizações
Condition is false, but still executed

I have this code

const prompt = require("prompt-sync")({ sigint: true });
var cmd
var start = 0;
var stats = {
                "player1":
                    {
                        "name": "",
                        "money": 0,
                        "properties": [],
                        "position": 0,
                    },
                "player2":
                    {
                        "name": "",
                        "money": 0,
                        "properties": [],
                        "position": 0,
                    },
                "player3":
                    {
                        "name": "",
                        "money": 0,
                        "properties": [],
                        "position": 0,
                    },
                "player4":
                    {
                        "name": "",
                        "money": 0,
                        "properties": [],
                        "position": 0,
                    },
                "player5":
                    {
                        "name": "",
                        "money": 0,
                        "properties": [],
                        "position": 0,
                    }
            }

cmd = prompt("There can be 5 players. Enter the first player's name: ")
stats.player1.name = cmd;
cmd = prompt("Enter the second player's name: ")
stats.player2.name = cmd;
cmd = prompt("Enter the third player's name. Type 0 to start: ")
if (cmd != 0) {
        stats.player3.name = cmd;
    } else {
        start = true;
    }

cmd = prompt("Enter the fourth player's name. Type 0 to start: ")
if (start != true) {
    if (cmd != 0) {
        stats.player4.name = cmd;
    } else {
        start = true;
    }
}

cmd = prompt("Enter the fifth player's name, Type 0 to start: ")
if (start != true) {
    if (cmd != 0) {
        stats.player5.name = cmd;
    } else {
        start = true;
    }
}
while (start = true) {
    cmd = prompt("Enter a command: ")
}

But when I get to the "Enter the third player's name. Type 0 to start" if statement, and type 0, it gets pass this statement but stops at 4th statement. I expected that when I type 0, it will start the game automatically. I used prompt-sync for user input. I'm bad at loops; please help me =[

about 4 years ago · Juan Pablo Isaza
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