Please help me with this question. I am having trouble understanding what to do. The HTML code is provided in one of the images below as well as the instructions. The client_side.js and the CSS code are provide below Thank you CLIENT; var url = "http://localhost:3000/post"; var myID; var guessWord; function resetGame(){ var myName = prompt("What is your name?") document.getElementById("mistakes").innerHTML = "Wrong Letters: " // request server to start a new game! $.post(url+'?data='+JSON.stringify({ 'name':myName, //client's identity on the server 'action':'generateWord'}), response); } function printGuess(){ //you write code here! //1. Locate the HTML element with ID 'guessarea' //2. Cycle through the 'guessWord' array and write // each character to the 'guessarea' in turn } function makeGuess(){ //ask the server to validate the guess $.post( url+'?data='+JSON.stringify({ 'name':myID, 'action':'evaluate', 'letterGuess':document.hangman.elements["guess"].value, //the user's guess! 'guessWord':guessWord }), response // a function that will be called once the server responds. ); } function response(data, status){ var response = JSON.parse(data); if (response['action'] == 'generateWord'){ //have we asked to generate a word? myID = response['nameID']; var wordLen = response['len'] //TO DO: initialize the guessWord array //1. Create a new Array that contains from for wordLen elements //2. Initialize each element in guessWord to be this: "_ " printGuess(); } else if (response['action'] == 'evaluate'){ //retrieve info from the response //this includes the number of incorrect responses //and the updated state of the guess word var correct = response['correct']; var error_count = response['num_errors']; guessWord = response['attemptWord']; printGuess(); //TO DO: //1. If the letter is NOT correct, we need to add it to the MISTAKES! In this case: //1a. Get the value in the HTML element with the ID "guess" //1b. Add this letter to the letters in the HTML element with the ID "mistakes" //1c. Once you've done this, make sure the HTML element with the ID "guess" is set to contain "" (an empty string) //2. Check to see if you have a winner! //2a. To do this, cycle thru guessWord to see if every element is a LETTER //2b. If yes, you have a winner! In this case, create an alert that reads "You Won!" //2c. Then, call 'resetGame()' to start the game over //3. Check to see if you have a loser! //3a. To do this, check to see if error_count is >= 6 //3b. If yes, you have a loser :(. In this case, create an alert that reads "You Lose!" //3c. Then, call 'resetGame()' to start the game over } } STYLE.CSS @import url(https://fonts.googleapis.com/css?family=Permanent+Marker); body { font-family: Helvetica,Arial,sans-serif; margin: 0px 0px 0px 20px; font-size: 18px; background-color: #94cff3; text-align: center; } input { border: 2px solid #cc0000; font-family: Helvetica, sans-serif; color: #333333; padding: 10px; } #ratefeld { font-family: 'Permanent Marker', 'cursive'; font-size: 2.0em; } h1 { font-family: 'Permanent Marker', 'cursive'; }
Please help me with this question. I am having trouble understanding what to do. The HTML code is provided in one of the images below as well as the instructions. The client_side.js and the CSS code are provide below
Thank you
CLIENT;
var url = "http://localhost:3000/post";
var myID;
var guessWord;
function resetGame(){
var myName = prompt("What is your name?")
document.getElementById("mistakes").innerHTML = "Wrong Letters: "
// request server to start a new game!
$.post(url+'?data='+JSON.stringify({
'name':myName, //client's identity on the server
'action':'generateWord'}),
response);
}
function printGuess(){
//you write code here!
//1. Locate the HTML element with ID 'guessarea'
//2. Cycle through the 'guessWord' array and write
// each character to the 'guessarea' in turn
}
function makeGuess(){
//ask the server to validate the guess
$.post(
url+'?data='+JSON.stringify({
'name':myID,
'action':'evaluate',
'letterGuess':document.hangman.elements["guess"].value, //the user's guess!
'guessWord':guessWord
}),
response // a function that will be called once the server responds.
);
}
function response(data, status){
var response = JSON.parse(data);
if (response['action'] == 'generateWord'){ //have we asked to generate a word?
myID = response['nameID'];
var wordLen = response['len']
//TO DO: initialize the guessWord array
//1. Create a new Array that contains from for wordLen elements
//2. Initialize each element in guessWord to be this: "_ "
printGuess();
} else if (response['action'] == 'evaluate'){
//retrieve info from the response
//this includes the number of incorrect responses
//and the updated state of the guess word
var correct = response['correct'];
var error_count = response['num_errors'];
guessWord = response['attemptWord'];
printGuess();
//TO DO:
//1. If the letter is NOT correct, we need to add it to the MISTAKES! In this case:
//1a. Get the value in the HTML element with the ID "guess"
//1b. Add this letter to the letters in the HTML element with the ID "mistakes"
//1c. Once you've done this, make sure the HTML element with the ID "guess" is set to contain "" (an empty string)
//2. Check to see if you have a winner!
//2a. To do this, cycle thru guessWord to see if every element is a LETTER
//2b. If yes, you have a winner! In this case, create an alert that reads "You Won!"
//2c. Then, call 'resetGame()' to start the game over
//3. Check to see if you have a loser!
//3a. To do this, check to see if error_count is >= 6
//3b. If yes, you have a loser :(. In this case, create an alert that reads "You Lose!"
//3c. Then, call 'resetGame()' to start the game over
}
}
STYLE.CSS
@import url(https://fonts.googleapis.com/css?family=Permanent+Marker);
body {
font-family: Helvetica,Arial,sans-serif;
margin: 0px 0px 0px 20px;
font-size: 18px;
background-color: #94cff3;
text-align: center;
}
input {
border: 2px solid #cc0000;
font-family: Helvetica, sans-serif;
color: #333333;
padding: 10px;
}
#ratefeld {
font-family: 'Permanent Marker', 'cursive';
font-size: 2.0em;
}
h1 {
font-family: 'Permanent Marker', 'cursive';
}
Step by step
Solved in 3 steps