5/07/2017

How To Create A Simple Code Your Own Adventure Game With Javascript

How To Create A Simple Code Your Own Adventure Game With Javascript Codecademy

I have started learning Javascript through the easy to follow tutorials on codecademy.com, which I highly recommend checking out and am here to share my journey. This is the first of many tutorials / articles I plan to write related to this programming language. My first creation is a code your own adventure game with a simple interactive prompt feature for the user (as seen in the above screenshot from codecademy). The games focus is on one of my favorite comic book characters: Hellboy and whether or not you'd like to try arm wrestling him! Think you have what it takes?

If you decide to go through the Javascript tutorials on codecademy you'll come across a similar code your own adventure you'll have to create that focuses on singer Justin Bieber. While I didn't want to post up the exact program I made for that challenge, I decided to create one focused on Hellboy which can be used as a reference if you run into any obstacles.

Code:

<script>

// Ask if the user is ready to play!

confirm("Are you ready to play?")

var age = prompt("How old are you?");

if (age < 15) {
console.log ("Play at your own risk!");
}

else {
console.log ("Let's play a game!");
}

console.log ("You see Hellboy sitting at a table with a sign that says 'Arm Wrestle Me.'");

console.log ("As you walk by him he asks: 'Do you want to arm wrestle?'");

var userAnswer = prompt("Do you want to arm wrestle Hellboy?");

if (userAnswer==="yes") {
console.log ("You arm wrestle Hellboy and he beats you!");
}

else {
console.log ("Oh no! Hellboy has no one to arm wrestle!");
}

var feedback = prompt("Please rate this game out of 10.");

if (feedback < 8) {
console.log ("Thank you! We should arm wrestle again!");
}

else {
console.log ("I'll keep practicing coding and arm wrestling.");
}

</script>

No comments:

Post a Comment


Copyright © justinwoodie.com ©