MediaWiki:Zerospace EN.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 9: | Line 9: | ||
dice_total += Math.floor((Math.random() * dice_size) + 1); | dice_total += Math.floor((Math.random() * dice_size) + 1); | ||
} | } | ||
return dice_total; | return dice_total; | ||
Line 20: | Line 19: | ||
var dice_count = 3; | var dice_count = 3; | ||
alien_type_roll = roll_dice(dice_size, dice_count); | |||
if ( | if (alien_type_roll <= 13) | ||
{ | { | ||
alien_type = 'Humanoid alien'; | alien_type = 'Humanoid alien'; | ||
} | } | ||
else if ( | else if (alien_type_roll <= 15) | ||
{ | { | ||
alien_type = 'Android; | alien_type = 'Android; | ||
Line 32: | Line 31: | ||
else | else | ||
{ | { | ||
alien_type_roll = 'Exotic alien'; | |||
} | } | ||
return alien_type; | return alien_type; | ||
} | } | ||
Line 42: | Line 42: | ||
random_alien = generate_alien_type(); | random_alien = generate_alien_type(); | ||
document.getElementById(" | document.getElementById("random_alien_title").innerHTML = 'Your Random Alien'; | ||
document.getElementById("random_alien_output").innerHTML = random_alien; | document.getElementById("random_alien_output").innerHTML = random_alien; | ||
} | } |
Revision as of 14:53, 25 April 2018
function roll_dice(dice_size, dice_count)
{
dice_size = typeof dice_size !== 'undefined' ? dice_size : 6;
dice_count = typeof dice_count !== 'undefined' ? dice_count : 1;
var dice_total = 0;
for (i = 0; i < dice_count; i++) {
dice_total += Math.floor((Math.random() * dice_size) + 1);
}
return dice_total;
}
function generate_alien_type()
{
var alien_type = '';
var dice_size = 6;
var dice_count = 3;
alien_type_roll = roll_dice(dice_size, dice_count);
if (alien_type_roll <= 13)
{
alien_type = 'Humanoid alien';
}
else if (alien_type_roll <= 15)
{
alien_type = 'Android;
}
else
{
alien_type_roll = 'Exotic alien';
}
return alien_type;
}
function generate_alien()
{
var random_alien = '';
random_alien = generate_alien_type();
document.getElementById("random_alien_title").innerHTML = 'Your Random Alien';
document.getElementById("random_alien_output").innerHTML = random_alien;
}
$(function () {
var random_alien_title = document.getElementById('random_alien_title');
var random_alien_button = document.getElementById('random_alien_button');
random_alien_title.innerHTML = 'Randomly Generate An Alien';
random_alien_button.innerHTML = '<input type="button" value="Generate An Alien" onclick="generate_alien();" />';
}());