finally found a way to incorporate && and || into my Javascript Choose Your Own Adventure 2. While Codeacademy said it worked, there is at least one logical error in my code. I put the code on the server and the problem still exists. Here is the source code.
alert("You are on a quest to seak the Holy Grail.");
alert("You approch a bridge.");
alert("Suddenly ...");
alert("Stop! Who would cross the Bridge of Death must answer me these questions three! Ere the other side he see.");
var user = prompt("What is your name?");
user.toUpperCase();
switch(user)
{
case 'SIR LANCELOT' :
var quest = prompt("What is your quest?");
quest.toUpperCase();
var color = prompt("What is your favorite color");
color.toUpperCase();
if (quest === "TO SEAK THE HOLY GRAIL" || color === "BLUE") {
alert("You cross the bridge.");
}
else {
alert("You are cast into the Gorge of Eternal Peril.");
}
break;
case 'SIR GALAHAD' :
var quest = prompt("What is your quest?");
quest.toUpperCase();
var color = prompt("What is your favorite color");
color.toUpperCase();
if (quest === "I SEAK THE GRAIL!" && color === "GREEN") {
alert("You cross the bridge");
}
else {
alert("You are cast into the Gorge of Eternal Peril.");
}
break;
case 'SIR ROBIN' :
var quest = prompt("What is your quest?");
quest.toUpperCase();
var Assyria = prompt("What is the capital of Assyria?");
Assyria.toUpperCase();
if (quest === "TO SEAK THE HOLY GRAIL" && Assyria === "NINEVEH") {
alert("You cross the bridge.");
}
else {
alert("You are cast into the Gorge of Eternal Peril.");
}
break;
case 'ARTHUR KING OF THE BRITAINS' :
var quest = prompt("What is your quest?");
quest.toUpperCase();
var swallow = prompt("What is the average air speed of an unleaden swallow?");
swallow.toUpperCase();
if (quest === "TO SEAK THE HOLY GRAIL" && swallow === "AFRICAN OR EUROPEAN")
{
alert("The Bridgekeeper is cast into the Gorge of Eternal Peril and you cross the bridge");
}
else
{
alert("You are cast into the Gorge of Eternal Peril.");
}
break;
default :
var quest = prompt("What is your quest?");
quest.toUpperCase();
var color = prompt("What is your favorite color");
color.toUpperCase();
if (quest === "TO SEAK THE HOLY GRAIL" || color === "GREY") {
alert("You cross the bridge.");
}
else {
alert("You are cast into the Gorge of Eternal Peril.");
}
break;
};
No comments:
Post a Comment