Created
June 11, 2014 07:25
-
-
Save NEWeber/6923699807e227fc4ad6 to your computer and use it in GitHub Desktop.
Revisions
-
NEWeber created this gist
Jun 11, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,57 @@ <script> function GuessIt (title, questions, numGuesses) { this.title = title; this.questions = questions; this.guesses = numGuesses; this.numQ = questions.length; this.questionIndex = (Math.floor(Math.random() * this.numQ)) this.question = this.questions[this.questionIndex][0] this.answer = this.questions[this.questionIndex][1] } var macData; macData = [["What year did Macbeth debut?", 1606], ["Who said, 'Out, out damn spot!'?", "Lady Macbeth"], ["How many acts long is the play?", 5]]; macGame = new GuessIt("Macbeth", macData, 3); var game = function(gameObject) { var guess guess = prompt(gameObject.question); if(guess == gameObject.answer) { stopPlaying = true return "Nice work!"; } else { if(tries < gameObject.guesses) { return "Sorry, try again"; } else { return "Sorry, you're out of guesses." } } } //stopPlaying tracks if the user has gotten the question right yet and will end the program early if they have var stopPlaying stopPlaying = false var playIt playIt = confirm("Welcome to the " + macGame.title + " Quiz! Do you want to play?"); if (playIt) { alert("Great! Let's get started."); alert("You've got " + macGame.guesses + " guesses to get the right answer. Let me get your question."); for(tries = 1; tries < (macGame.guesses + 1); tries++) { alert(game(macGame)); //Ends the program if the user has gotten the question right if (stopPlaying) { break } } } else { alert("I'm sorry to hear that. Goodbye.") } </script>