Created
May 20, 2017 01:33
-
-
Save janchor/5063f56da41d3e32c825ff154c6bd3be to your computer and use it in GitHub Desktop.
Stackoverflow example: how to store javascript in an array?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Stackoverflow example</title> | |
<script> | |
var y=0 | |
adventure = new Array | |
adventure[y++]={ | |
//notes: | |
d:"Adventure zero, choose an equipment. Bug: for some reason the script crashes when you click the Adventure button", | |
i:"<img src='cave_entrance.jpg' alt='cave entrance' /><figcaption></figcaption>", | |
b:"<button type="button" onclick="window.alert('Gotten')">Get equipment</button>" | |
} | |
adventure[y++]={ | |
//notes: | |
d:"Adventure 1", | |
i:"<img src='cave_entrance.jpg' alt='cave entrance' /><figcaption></figcaption>", | |
b:"<button type="button" onclick="window.alert('You gain 100 gold')">Gold</button>" | |
} | |
adventure[y++]={ | |
//notes: | |
d:"Adventure 2", | |
i:"<img src='cave_entrance.jpg' alt='cave entrance' /><figcaption></figcaption>", | |
b:"<button type="button" onclick="window.alert('You gain 200 gold')">Gold</button>" | |
} | |
adventure[y++]={ | |
//notes: | |
d:"Adventure 3", | |
i:"<img src='cave_entrance.jpg' alt='cave entrance' /><figcaption></figcaption>", | |
b:"<button type="button" onclick="window.alert('You gain 300 gold')">Gold</button>" | |
} | |
adventure[y++]={ | |
d:"Adventure 4", | |
i:"<img src='cave_entrance.jpg' alt='cave entrance' /><figcaption></figcaption>", | |
b:"<button type="button" onclick="window.alert('You gain 400 gold')">Gold</button>" | |
} | |
</script> | |
</head> | |
<body> | |
<main> | |
<figure id="picture"> | |
<img src="logo.png" alt="logo" /> | |
<figcaption></figcaption> <!-- is this necessary? Who knows. --> | |
</figure> | |
<p id="description">RogueMine feels like a rogue-like as you wander around through randomly generated encounters, fighting monsters and mining resources in order to build a better robot.</p> | |
<button type="button" onclick="highLevel = y-1; while (y >highLevel){ y = Math.round(Math.random() * 5)};document.getElementById('description').innerHTML = adventure[y].d;document.getElementById('picture').innerHTML = adventure[y].i;document.getElementById('buttons').innerHTML = adventure[y].b">Adventure</button> | |
<div id="buttons"> | |
<button id="choice3" type="button" onclick="window.alert('Credits: James. Otis. The Internet.')">Credits</button> | |
</div> | |
</main> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment