-3

I'm trying to get my JavaScript file to work properly on my webpage, and it did the first few times I tried it. However after that, all of a sudden nothing happens when I try to run it by pressing a button.

JsFiddle

HTML:

<!DOCTYPE html>
<head>
    <title>Stevo's Website</title>
    <link rel='stylesheet' href='style.css'/>
    <script LANGUAGE="JavaScript" src="C:\Users\Steven\Desktop\website\rockScissorPaper.js"></script>
</head>

<body class="body">
    <div class="navbar">
        <ul class="pull-left">
            <li><a href="website.html" id="navtabnow">Owl</a>
                <ul>
                    <li><a href="#1">Test1</a></li>
                    <li><a href="#2">Test2</a></li>
                </ul>
            </li>
            <li><a href="news.html" id="norightborder">Wolf</a></li>
            <li><a href="#">About</a>
                <ul>
                    <li><a href="#1" onclick="compare()">Test1</a></li>
                    <li><a href="#2" onclick="compare()">Test2</a></li>
                </ul>
            </li>
        </ul>

        <ul class="pull-right">
            <li><a href="javascript:compare();">Login</a></li>
            <li><a href="#signup">Sign Up</a></li>
            <li><a href="#support">Support</a></li>
        </ul>
    </div>

    <div class="jumbotron">
    </div>
</body>

Javascript:

    var compare = function()
{
    var userChoice = prompt("Do you choose rock, paper or scissors?");
    userChoice = userChoice.toLowerCase();
    alert(userChoice);
    if (userChoice != "rock" && "paper" && "scissors")
    {
        alert("You need to choose rock, paper or scissors.");
    }
    else
    {
        var computerChoice = Math.random();

        if (computerChoice < 0.34)
        {
            computerChoice = "rock";
        }
        else if (computerChoice <= 0.67)
        {
            computerChoice = "paper";
        }
        else
        {
            computerChoice = "scissors";
        }

        choice1 = userChoice;
        choice2 = computerChoice.toLowerCase;

        if (choice1 === choice2)
        {
            return "The result is a tie!";
        }

            //choice1 is rock
        else if (choice1 === "rock")
        {
            if (choice2 === "scissors")
            {
                alert("The computer chose: " + computerChoice + "\nRock wins!");
            }

            else if (choice2 === "paper")
            {
                alert("The computer chose: " + computerChoice + "\nPaper wins!";
            };
        }

            //choice1 is paper
        else if (choice1 === "paper")
        {
            if (choice2 === "rock")
            {
                return "Paper wins!";
            }

            else if (choice2 === "scissors")
            {
                return "Scissors wins!";
            };
        }

            //choice1 is scissors
        else if (choice1 === "scissors")
        {
            if (choice2 === "paper")
            {
                return "Scissors wins!";
            }

            else if (choice2 === "rock")
            {
                return "Paper wins!";
            };
        };
    };
};

Don't mind the layout etc. as I haven't put my css and other html files in the JsFiddle. The point is just that my javascript should run when pressing one of the temporary test buttons. (About: Test1, About:Test2 & Login)

I tried a couple of different things as you might also be able to tell, but for some reason I can't get it to work again.

halfer
  • 19,824
  • 17
  • 99
  • 186
StevoHN
  • 441
  • 1
  • 5
  • 19

1 Answers1

0
else if (choice2 === "paper")
{
   alert("The computer chose: " + computerChoice + "\nPaper wins!";
};

You have unclosed bracket")" try fixing it.

Sameera Thilakasiri
  • 9,452
  • 10
  • 51
  • 86