Quotes help make search much faster. Example: "Practice Makes Perfect"
Sunday, October 21, 2012
Codecademy: Sample Solution to "Program your first game!"
//Check if the user is ready to play!
var age = prompt("What's your age?");
if(age >= 18)
{
console.log("You are allowed to play but I take no responsibility!");
}
else
{
console.log("You are encougraged to play on!");
}
console.log("\nSnow White and Batman were hanging out at the bus stop, waiting to go to the shops. There was a sale on and both needed some new threads. You've never really liked Batman. You walk up to him.");
console.log("\nBatman glares at you.");
var userAnswer = prompt("\nAre you feeling lucky, punk?");
if(userAnswer === "yes")
{
console.log("\nBatman hits you very hard. It's Batman and you're you! Of course Batman wins!");
}
else
{
console.log("\nYou did not say yes to feeling lucky. Good choice! You are a winner in the game of not getting beaten up by Batman.");
}
//feedback
var feedback = prompt("How would you rate the game on a scale of 1 to 10, 10 being the highest?");
if(feedback > 8)
{
console.log("This is just the beginning of my game empire. Stay tuned for more!");
}
else
{
console.log("I slaved away at this game and you gave me that score?! The nerve! Just you wait!");
}
Subscribe to:
Comments (Atom)
This is an example of scrolling text using Javascript.
Popular Posts
-
//sample solution // Card Constructor function Card(num1,num2) { //properties var suit = num1; var number = num2; //methods ...
-
Find an expression using two values and the modulus operator that results as 4 Answer: 32%7
-
Question: The total power dissipation in an RL series circuit is due to which component? Answer: The total power dissipation is due to ...
-
Question: How much internal resistance does an ideal current source have? Answer: An ideal current source has infinite resistance.
-
function spinalCase(str) { var str2 = str.replace(/([a-z](?=[A-Z]))/g,'$1 '); var newStr = str2.replace(/\s|\x5F/g,"-...
-
// What's an API key? // A: An alphanumeric string used to identify you to an API // B: An OAuth token // C: An All-Purpose Interne...
-
// Sample solution to style.css html, body { /* The universe takes up all available space */ width: 100%; height: 100%; ...
-
function steamrollArray(arr) { // I'm a steamroller, baby var flattened = arr.reduce( function(a, b) { return a.conca...
-
Question: When is the maximum power delivered from a practical source to a load? Answer: Maximum power is delivered to the load when it...
-
//sample solution NSNumber *age = @10; Back to the list of sample solutions for Try Objective C: Level 1 challenges