Random Project Help- Javascript expert required


#1

Hi everyone- Just some stuff I am doing but for some unknown reason (unknown to me), four statements are printed to the console instead of just one. The strings of the three variables are just trials ones and can be either true or false. Desperately need some help. Thanks - RachelTGB

//THE LAWS OF ROBOTICS 3/5
//Basic program with no interactivity- JavaScript
//Rachel Sheppard

var law_1 = "true";
var law_2 = "true";
var law_3 = "false";

if(law_1 == "true")
{
    if(law_2 == "true")
    {
        if(law_3 == "true")
        {
            console.log("You are a perfect robot");
        }
        else if (law_3 == "false");
        {
            console.log("You are a self-destructive robot");
        }
    }
    else if (law_2 == "false");
    {
        if(law_3 == "true")
        {
            console.log("You disobey orders");
        }
        else if (law_3 == "false");
        {
            console.log("You are a loner robot");
        }
    }

}

else if (law_1 == "false");
{
    if(law_2 == "true")
    {
        if(law_3 == "true")
        {
            console.log("You injure humans");
        }
        else if (law_3 == "false");
        {
            console.log("You are a perfect soldier");
        }
    }
    else if (law_2 == "false");
    {
        if(law_3 == "true")
        {
            console.log("You are a robot rebel");
        }
        else if (law_3 == "false");
        {
            console.log("You are a psychopath robot");
        }
    }
}

#2

Hi Rachel,

I'm happy to see you are doing something outside of CC to practice.

Here is what I noticed so far: (I added comments where I removed code)

var law_1 = "true";
var law_2 = "true";
var law_3 = "false";

if(law_1 == "true")
{
    if(law_2 == "true")
    {
        if(law_3 == "true")
        {
            console.log("You are a perfect robot");
        }
        else if (law_3 == "false") //you had a semi-colon here
        {
            console.log("You are a self-destructive robot");
        }
    }
    else if (law_2 == "false") //you had a semi-colon here
    {
        if(law_3 == "true")
        {
            console.log("You disobey orders");
        }
        else if (law_3 == "false") //you had a semi-colon here
        {
            console.log("You are a loner robot");
        }
    }

}

else if (law_1 == "false") //you had a semi-colon here
{
    if(law_2 == "true")
    {
        if(law_3 == "true")
        {
            console.log("You injure humans");
        }
        else if (law_3 == "false") //you had a semi-colon here
        {
            console.log("You are a perfect soldier");
        }
    }
    else if (law_2 == "false") //you had a semi-colon here
    {
        if(law_3 == "true")
        {
            console.log("You are a robot rebel");
        }
        else if (law_3 == "false") //you had a semi-colon here
        {
            console.log("You are a psychopath robot");
        }
    }
}

For all of your else if conditionals, you had a semi-colon - try removing them - i added the code I edited with the comments above.

Now it prints that it's a destructive robot.