Lesson 5 Challenge 1

by nathanesa

JavaScript

// Create the arrays.
var firstNames = ['Ugbar', 'Clint', 'Luglug', 'Rohan', 'Marielle', 'Elinore'];
var surnames = ['Rizrad', 'Deepforge', 'Ravenspell'];
var races = ['human', 'dwarf', 'troll', 'elf'];

// Choose random numbers.
var firstNameRand = Math.floor(Math.random()*6);
var surnameRand = Math.floor(Math.random()*3);
var raceRand = Math.floor(Math.random()*4);
var strength = Math.floor(Math.random()*15) + 1;
var intelligence = Math.floor(Math.random()*15) + 1;
var dexterity = Math.floor(Math.random()*15) + 1;
var charisma = Math.floor(Math.random()*15) + 1;

// Output.
document.write('Your character is a ' + races[raceRand]);
document.write(' called ' + firstNames[firstNameRand] + " " + surnames[surnameRand] + "<br>");
document.write('strength: ' + strength + "<br>");
document.write('intelligence: ' + intelligence + "<br>");
document.write('dexterity: ' + dexterity + "<br>");
document.write('charisma: ' + charisma);