www.webdeveloper.com
Results 1 to 2 of 2

Thread: Javascript alert box wont appear on website, but works locally?

  1. #1
    Join Date
    Dec 2012
    Posts
    1

    Javascript alert box wont appear on website, but works locally?

    This is probably a simple query for the pros on this forum but my issue is the alert box wont appear after I posted this html with javascript in it on a webpage inside a template the page addy is http://www.rockpaperscissors.webatu.com/

    The script works fine locally on my computer. I hope someone can solve this. The HTML is as follows:

    <HTML>
    <HEAD>
    <meta charset="UTF-8">
    <TITLE>
    Jascript "Rock, Scissors, Paper" Game
    </TITLE>
    <SCRIPT>
    function whoWon (iplay, uplay) {
    // "I" am the computer


    switch (iplay) {
    case uplay:
    return "IT'S A TIE! TRY AGAIN, FRAIL HUMAN ENTITY?";
    case "rock": {
    if (uplay == "scissors")
    return "I WIN! ROCK SMASHES SCISSORS! COMPUTERS FOREVER!"
    else
    return "YOU WIN. Paper covers rock. Paltry human, how did you beat me?";
    }
    case "scissors": {
    if (uplay == "paper")
    return "I WIN! SCISSORS CUT PAPER! CHIPS BEAT BRAINS!"
    else
    return "YOU WIN. Rock smashes scissors. Frail human, would you like to try again?";
    }
    case "paper": {
    if (uplay == "rock")
    return "I WIN! PAPER COVERS ROCK! ROCK AND ROLL, *****ES!"
    else
    return "YOU WIN. Scissors cut paper. Oh, vain flesh and bone entity, I'll get you next TIME!";
    }
    }
    }




    function shakeIt(){
    var randGen = Math.random();
    if (randGen <= .33)
    var computerPlay = "rock";
    if ((randGen >.33) && (randGen <= .66))
    var computerPlay = "scissors";
    if (randGen > .66)
    var computerPlay = "paper";
    if (document.gameForm.game[0].checked)
    var personPlay = "rock";
    if (document.gameForm.game[1].checked)
    var personPlay = "paper";
    if (document.gameForm.game[2].checked)
    var personPlay = "scissors";
    alert ("The computer played: " + computerPlay +
    ". You played: " + personPlay + ". " +
    whoWon(computerPlay,personPlay));
    }
    </SCRIPT>
    </HEAD>
    <BODY>
    <H2>
    Play "Rock, Scissors and Paper" the Javascript way!
    </H2>
    <UL>
    <Li>Rock smashes scissors!
    <Li>Scissors cut paper!
    <Li>Paper covers rock!
    </UL>
    <FORM name="gameForm">
    <P>Make a choice:
    <BR>
    <input type="radio" name="game" value="Rock"
    checked><STRONG>Rock</STRONG><BR>
    <input type="radio" name="game"
    value="Paper"><STRONG>Paper</STRONG><BR>
    <input type="radio" name="game"
    value="Scissors"><STRONG>Scissors</STRONG>
    <P>
    <BR>
    <BR>
    <INPUT type="button" name="play" value="Play" onClick="shakeIt();">
    </FORM>
    </BODY>
    </HTML>

  2. #2
    Join Date
    Jan 2010
    Posts
    80
    When you pasted your code into your live page you neglected to add the name of the form

    In your live page the line

    Code:
    <form>
    should be
    Code:
    <form name="gameForm">

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles