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

256
Views
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
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!