JAVASCRIPT ODD EVEN GAME I need to develop a playervscompute
JAVASCRIPT ODD EVEN GAME
I need to develop a player-vs-computer game that tallies odd and even numbers until there’s a winner . im running into trouble with it and could use some help. ive inclued the html and the script i have. thanks for your time and help!!
The game ends when either the player or the computer reaches 50 or when the user enters 999 to quit. In either case, the application should display an appropriate message like: “You WIN!”, “You lose :(”, or “You quit” in the span element to the right of the Play button.
In the JavaScript file, note that five functions are supplied. The $ function. The getRandomNumber function. A resetFields function that resets the text boxes and message area. The start of a playGame function. And an onload event handler that attaches the playGame function to the click event of the Play button.
Code and test the playGame function. Within this function, use a while loop to get user entries until the player quits or either the player or computer has reached 50. Then, display the appropriate message to the right of the Play button. Within the while loop, consider using a break statement to end the loop if the player quits.
Within the playGame function, call the resetFields function whenever the fields need to be reset.
If you haven’t already done so, add data validation to make sure the entry is a valid number from 0 through 5.
<html lang=\"en\">
 <head>
 <meta charset=\"UTF-8\">  
 <title>Odds and Evens Game</title>
 <link rel=\"stylesheet\" href=\"game.css\">
 <script src=\"game.js\"></script>
 </head>
 <body>
 <main>
 <h1>Let\'s Play ODDS AND EVENS!</h1>
 <fieldset>
 <legend>Rules</legend>
 <ul>
 <li>The computer is even, you are odd (no offense).</li>
 <li>Each round, you and the computer \"hold up\" 1 to 5 fingers.</li>
 <li>The total number of fingers are tallied.</li>
 <li>Even totals go to the computer.</li>
 <li>Odd totals go to you.</li>
 <li>First to 50 wins.</li>
 </ul>
 </fieldset>
   
 <input type=\"button\" id=\"play\" value=\"Play\">
 <span id=\'message\'> </span><br>
 <fieldset>
 <legend>This round</legend>
 <label for=\"player\">You:</label>
 <input type=\"text\" id=\"player\" value=\"0\" disabled>
 <label for=\"computer\">Computer:</label>
 <input type=\"text\" id=\"computer\" value=\"0\" disabled>
 </fieldset>
 <fieldset>
 <legend>Totals</legend>
 <label for=\"odd\">You:</label>
 <input type=\"text\" id=\"odd\" value=\"0\" disabled>
 <label for=\"even\">Computer:</label>
 <input type=\"text\" id=\"even\" value=\"0\" disabled>
 </fieldset>
 </main>
 </body>
 </html>
\"use strict\";
 var $ = function(id) { return document.getElementById(id); };
var getRandomNumber = function(max) {
 var random;
 if (!isNaN(max)) {
 random = Math.random(); //value >= 0.0 and < 1.0
 random = Math.floor(random * max); //value is an integer between 0 and max - 1
 random = random + 1; //value is an integer between 1 and max
 }
 return random;
 };
var playGame = function() {
   
 };
var resetFields = function() {
 $(\"player\").value = \"0\";
 $(\"computer\").value = \"0\";
 $(\"odd\").value = \"0\";
 $(\"even\").value = \"0\";
 $(\"message\").firstChild.nodeValue = \"\";
 };
window.onload = function() {
 $(\"play\").onclick = playGame;
 $(\"play\").focus();
 };
Solution
Algorithm:
 1) Declare a character stack S.
 2) Now traverse the expression string exp.
 a) If the current character is a starting bracket (‘(‘ or ‘{‘ or ‘[‘) then push it to stack.
 b) If the current character is a closing bracket (‘)’ or ‘}’ or ‘]’) then pop from stack and if the popped character is the matching starting bracket then fine else parenthesis are not balanced.
 3) After complete traversal, if there is some starting bracket left in stack then “not balanced”


