The first time I enter the command n it should run the first if statement, when I enter n it should then run the second one as its in zone two. However this is just not happening… What am I doing wrong. Its simply running the second one and skipping the first. Thanks in advance folks
// gameFunctions.js
// Javascript file for Game.html
// September 29th 2010 Edition
// The below represent our global variables for the game. The first variable
// is called playerScore, and represents the total earned points. The player
// earns or loses points based on progress in the game, this value can either
// increase or decrease.
var playerLocation = “zone”;
function runProgram()
{
var command = “”;
command = document.getElementById(“txtCommand”).value;
switch (command)
{
case “n”: north();
break;
case “s”: south();
break;
case “e”: east();
break;
case “w”: west();
break;
case “north”: north();
break;
case “south”: south();
break;
case “east”: east();
break;
case “west”: west();
break;
default: giveError();
}
}
// The following function when called will take the player north.
function north()
{
if(playerLocation = “zone”)
{
var message = “You have come to what seems to be a beach”;
post(message);
var playerLocation = “zoneTwo”;
}
if(playerLocation = “zoneTwo”)
{
var message = “You are unsure if you should set up camp. Set up camp?”
post(message);
var playerLocation = “zoneThree”;
}
else
{
giveError();
}
}
// The following function when called will take the player east.
function east()
{
if(playerLocation = “zone”)
{
var message = “You have come to a very large and steep mountain”;
post(message);
var playerLocation = “zoneTwo”;
}
if(playerLocation = “zoneTwo”)
{
var message = “You are unsure if you should set up camp. Set up Camp?”;
post(message);
var playerLocation = “zoneThree”;
}
else
{
giveError();
}
}
// The following function when called will take the player south.
function south()
{
if(playerLocation = “zone”)
{
var message = “You have come to the entrance of a mine”;
post(message);
var playerLocation = “zoneTwo”;
}
if(playerLocation = “zoneTwo”)
{
var message = “You are unsure if you should set up camp. Set up Camp?”;
post(message);
var playerLocation = “zoneThree”;
}
else
{
giveError();
}
}
}
// The following function when called will take the player west.
function west()
{
if(playerLocation = “zone”)
{
var message = “You have found the edge of the world”;
post(message);
var playerLocation = “zoneTwo”;
}
if(playerLocation = “zoneTwo”)
{
var message = “You are unsure if you should set up camp. Set up Camp?”;
post(message);
var playerLocation = “zoneThree”;
}
else
{
giveError();
}
}
// The following function reports an error when the program deviates from standard functionality. It is used mainly for debugging.
function giveError()
{
alert(“gameFunctions.js has encountered a critical error”)
alert(“Please check that you are not using Internet Explorer to run this page”)
alert(“The program will now close”)
}
// The following function reports an error when the typed in command is not recognized by the program database.
function doNotUnderstand()
{
alert(“I am sorry but I do not understand please try again”)
}
function post(newText)
{
document.getElementById(“taGameText”).value = “”
var gameTextBox = document.getElementById(“taGameText”);
gameTextBox.value = newText + gameTextBox.value;
}