Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I didnt get the helped I needed in my previous questions as prototypes were not used. I need to use prototypes. It seems that this.pGuess

I didnt get the helped I needed in my previous questions as prototypes were not used. I need to use prototypes. It seems that this.pGuess is not being set when game.prototype.PlayersGuessSubmission checks if it is a number and then calls checkGuess.

image text in transcribed

html file:__________________________

Guessing Game

Guessing Game

Guess a number between 1-100!

Previous Guesses:

js file_______________________________________________

window.onload = function (){

startGame();

};

function makeGuess(){

var guess = parseInt(document.getElementById("num").value);

game.prototype.playersGuessSubmission(guess);

}

var game = function(){

this.pGuess = null;

this.rand = randomNumberGenerator();

this.last=[];

}

function randomNumberGenerator(){

return Math.floor((Math.random() * 100) + 1);

}

function startGame(){

return new game();

}

game.prototype.closeness = function(){

return Math.abs(pGuess-rand);

}

game.prototype.isLower = function() {

return this.pGuess

}

game.prototype.playersGuessSubmission = function(guess) {

if(typeof guess !== 'number' || guess 100) {

throw "That is an invalid guess.";

}

this.pGuess = guess;

return this.checkGuess();

}

game.prototype.checkGuess = function() {

if(this.pGuess == this.rand) {

document.getElementById("status").innerHTML = "You Win";

}

else {

if(this.last.indexOf(this.pGuess) > -1) { /* -1 if element not in array*/

return 'You have already guessed that number.';

}

else {

this.last.push(this.pGuess);

if(this.last.length === 5) {

document.getElementById("status").innerHTML = "You Lose";

}

else {

var entry = document.createElement('li');

entry.appendChild(document.createTextNode(this.guess));

unordered.appendChild(entry);

var diff = this.closeness();

if(diff

document.getElementById("status").innerHTML = "Hot";

document.getElementById("status").style.textShadow = '0 0 20px #fefcc9, 10px -10px 30px #feec85, -20px -20px 40px #ffae34, 20px -40px 50px #ec760c, -20px -60px 60px #cd4606, 0 -80px 70px #973716, 10px -90px 80px #451b0e';

document.getElementById("status").style.color = "#FFCC00";

}

else if(diff

else if(diff

else{

document.getElementById("status").innerHTML = "Ice Cold";

document.body.style.backgroundImage = "url('ice-background-14140151326az.jpg')";

}

}

}

}

}

function hint(){

game.prototype.provideHint();

}

game.prototype.provideHint = function() {

var hintArray = [this.rand, randomNumberGenerator(), randomNumberGenerator()];

return shuffle(hintArray);

}

function shuffle(arr) { //Fisher-Yates - https://bost.ocks.org/mike/shuffle/

for(var i = arr.length-1; i > 0; i--) {

var randomIndex = Math.floor(Math.random() * (i + 1));

var temp = arr[i];

arr[i] = arr[randomIndex];

arr[randomIndex] = temp;

}

document.getElementById("status").innerHTML = "Guessing Game";

return arr;

}

38 39 40 game . prototype . checkGuess 41 42 43 function() if(this .pGuess == this . rand) { document.getElementById("status").innerHTML - "You Win"; Ado else f 45 if(this.last.indexOf(this.pGuess) 1) -1 if element n Call Unable to get property 'indexof' of undefined or null reference return 'You have already guessed that number.' 46 47 48 49 50 51 Ma else this.last.push(this.pGuess) if(this . last. length = 5) { document.getElementById("status").innerHTML "You

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

2. How will the team select a leader?

Answered: 1 week ago

Question

3. What may be the goal of the team?

Answered: 1 week ago