Skip to content

Instantly share code, notes, and snippets.

@NEWeber
Last active August 29, 2015 14:02
Show Gist options
  • Save NEWeber/5535ef558b3232f842f8 to your computer and use it in GitHub Desktop.
Save NEWeber/5535ef558b3232f842f8 to your computer and use it in GitHub Desktop.

Revisions

  1. NEWeber revised this gist Jun 8, 2014. 1 changed file with 1 addition and 4 deletions.
    5 changes: 1 addition & 4 deletions macbethGuess.html
    Original file line number Diff line number Diff line change
    @@ -6,16 +6,13 @@
    alert("Great! Let's get started.");
    alert("You've got three guesses to get the right answer. Let me get your question.");


    var guessIt = function(qaIndex) {

    //Here are the Questions and answers
    var questions = ["What year did Macbeth debut?", "Who said, 'Out, out damn spot!'?", "How many acts long is the play?"];
    var answers = [1606, "Lady Macbeth", 5];

    var guess
    guess = prompt(questions[qaIndex]);

    if(guess == answers[qaIndex]) {
    stopPlaying = true
    return "Nice work!";
    @@ -34,7 +31,7 @@
    return (Math.floor(Math.random() * 3))
    }

    var thisIndex
    var gameIndex
    gameIndex = getIndex()
    for(tries = 1; tries < 4; tries++) {
    alert(guessIt(gameIndex));
  2. NEWeber created this gist Jun 8, 2014.
    51 changes: 51 additions & 0 deletions macbethGuess.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    <script>
    var playIt
    playIt = confirm("Welcome to the Macbeth Quiz! Do you want to play?");

    if (playIt) {
    alert("Great! Let's get started.");
    alert("You've got three guesses to get the right answer. Let me get your question.");


    var guessIt = function(qaIndex) {

    //Here are the Questions and answers
    var questions = ["What year did Macbeth debut?", "Who said, 'Out, out damn spot!'?", "How many acts long is the play?"];
    var answers = [1606, "Lady Macbeth", 5];

    var guess
    guess = prompt(questions[qaIndex]);

    if(guess == answers[qaIndex]) {
    stopPlaying = true
    return "Nice work!";
    }
    else {
    return "Sorry, try again";
    }
    }

    //stopPlaying tracks if the user has gotten the question right yet and will end the program early if they have
    var stopPlaying
    stopPlaying = false

    //Generate a random number between 0 and 2 to get the index of the question
    var getIndex = function() {
    return (Math.floor(Math.random() * 3))
    }

    var thisIndex
    gameIndex = getIndex()
    for(tries = 1; tries < 4; tries++) {
    alert(guessIt(gameIndex));
    //Ends the program if the user has gotten the question right
    if (stopPlaying) {
    break
    }
    }
    }

    else {
    alert("I'm sorry to hear that. Goodbye.")
    }
    </script>