Question: /* global model, view */ var controller = { guesses: 0, processGuess: function(guess) { var location = this.parseGuess(guess); if (location) { this.guesses++; var hit =
/* global model, view */
var controller = { guesses: 0,
processGuess: function(guess) { var location = this.parseGuess(guess); if (location) { this.guesses++; var hit = model.fire(location); if (hit && model.shipsSunk === model.numShips) { view.displayMessage("You sank all my battleships, in " + this.guesses + " guesses"); } } },
parseGuess: function(guess) { var alphabet = ["A", "B", "C", "D", "E", "F", "G"];
if (guess === null || guess.length !== 2) { alert("Oops, please enter a letter and a number on the board."); } else { var firstChar = guess.charAt(0); var row = alphabet.indexOf(firstChar); var column = guess.charAt(1);
if (isNaN(row) || isNaN(column)) { alert("Oops, that isn't on the board."); } else if (row < 0 || row >= model.boardSize || column < 0 || column >= model.boardSize) { alert("Oops, that's off the board!"); } else { return row + column; } } return null; } };
****************** Question: How can I make this JavaScript code above ^ look like the code down below it in terms of format? ****************************
var MAXCRDS=52;
var MINCRDS=0;
function Card(number){
//Public properties of the class
if(number>=MINCRDS&&number
this.number=number;
this.setFace();
this.setSuit();
this.setName();
this.setPict();
}else{
this.number=-1;
this.faceVal=-1;
this.suit="none";
this.name="none";
this.pic="none";
}
}
//Setting the Face Value
Card.prototype.setFace=function(){
var num=this.number%13+1;
if(num>10)num=10;
else if(num==1)num=11;
if(num>=2&&num<=11)this.faceVal=num;
else this.faceVal=-2;
};
//Setting the Suit Value
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
