View Single Post
mirtos
Senior Member
 
Join Date: Oct 2011
Posts: 865

Old August 8th, 2014, 11:55 PM
ok, here you go. I changed a couple things.

1. array can be any size (you dont need a makeArray method)
2. using "ranges" (technically percentile from 1-100) it actually only looks at the max. (you dont need to specify a min)

Now i havent tried this inline yet, but this is vanilla javascript.


<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE>Moods and Attitudes</TITLE>
</HEAD>
<BODY>

<script language="JavaScript">
rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd() {
rnd.today=new Date();
rnd.seed=rnd.today.getTime();
rnd.seed = (rnd.seed*9301+49297) % 233280;
return rnd.seed/(233280.0);
}

function rand(number) {
return Math.ceil(rnd()*number);
}

function BitchRule() {
var randomNum = rand(100) + 1;
console.log(randomNum);
var arrayOfChoices = [];
arrayOfChoices.push( {"max": 15, "content": "happy, cheerful, optimistic, helpful, friendly" });
arrayOfChoices.push({"max": 30, "content": "happy, cheerful, optimistic, helpful, friendly"});
arrayOfChoices.push({"max": 45, "content": "self-pity, unhelpful, brooding, pessimistic"});
arrayOfChoices.push({"max": 60, "content": "pissed off, vengeful, cruel"});
arrayOfChoices.push({"max": 75, "content": "playful, energetic, daring, foolhardy, practical joker"});
arrayOfChoices.push({"max": 99, "content": "vain, proud, lazy, bored, omnipotent feeling"});
arrayOfChoices.push({"max": 100,"content": "restless, impatient, takes control, urge to get on with things, roll 1d6 for obsession check"});

var chosenString = "";
for (var itemIndex in arrayOfChoices) {
var item = arrayOfChoices[itemIndex];
if (randomNum <= item.max) {
chosenString = item.content;
break;
}
}
return chosenString;

}

</script>

<form>
<input type="button" name="Button1" value="Moods and Attitudes" onClick="this.form.textField1.value = BitchRule()" size="" />
<textarea name="textField1" cols="40" rows="1" wrap="soft"></textarea>
</form>

</BODY>
</HTML>
mirtos is offline   #8 Reply With Quote