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.
<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 gameIndex
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment