//Brooke Henderson
// variables
var height = 6000;
var position = 0;
var health = 100;
var food = 50;
var goat = 0;
var distance = height;
var restNum = 0;
// messages
var m1 = "You're at the base of a mountain that is " + height + " feet high. Your goal is to climb it. Watch out for mountain goats.";
var m2 = "A large mountain goat with gigantic horns blocks your path.";
var m3 = "Oh, no! A mountain goat has knocked you down!";
var m4 = "Oh, snap! You are too exhausted to continue.";
var m5 = "Congratulations! You've reached the summit!";
var m6 = "You must select an option before you click Go.";
var m7 = "You are climbing the mountain!";
var m8 = "Oh, snap! You are too hungry to continue.";
var m9 = "You can only rest 5 times.";
var m10 = "You are resting.";
// the value of message will be changed depending on player actions
// m1 is the starting message value
var message = m1;
// this function executes immediately when the page loads
writeResults();
// click the button to execute this function
// NOTE: no parentheses after the function name in this case
document.getElementById("go").onclick = climberResult;
// the main function - it calls other functions
function climberResult() {
if (health <= 0) {
message = m4;
climb.checked = false;
eat.checked = false;
rest.checked = false;
} else if (climb.checked) {
climbAction();
} else if (eat.checked) {
eatAction();
} else if (rest.checked) {
restAction();
} else {
// if nothing is checked
message = m6;
}
// calculate the remaining distance
distance = height - position;
// write out the new values for all the vars
writeResults();
}
// more functions
function climbAction() {
position += 100;
health -= 10;
message = m7;
climb.checked = false;
if (position >=6000) {
position = 6000;}
if (position==3000) {
goatAttack();
}
}
function eatAction() {
food -= 5;
if (food <= 0) {
food = 0;
message = m8;
}
health += 10;
if...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.