...

View Full Version : fun script, mysterious problem...



zemonster
12-24-2011, 06:30 PM
Dear friends

I am trying to code this piece of wonderful fun :) there is some glitch with it though - the 'female occupation' always gets stuck on lady of leisure'. I cannot figure what the problem is - can anyone spot it? Thank yoo!!

Beth xx

//define sex
var sex=Math.random();
if (sex>0.5)
{document.write(". You were male. ");}
else
{document.write(". You were female. ");}

//define occupation number
var occu_num=Math.random()*10;
occu_num=Math.round(occu_num);

//define male occupation
var occupation;
if (sex>0.5){
if (occu_num==0)
{occupation="jeweler or watch-maker.";}
else if (occu_num==1)
{occupation="jeweler or watch-maker.";}
else if (occu_num==2)
{occupation="priest.";}
else
{occupation="man of the law, probably a judge.";}
document.write("<br>You were a respected and accomplished " + occupation);}

//define female occupation
else
{
if (occu_num==0)
{occupation="jeweler or watch-maker.";}
else if (occu_num==1)
{occupation="jeweler or watch-maker.";}
else if (occu_num==2)
{occupation="nun or priestess.";}
else (occu_num==10)
{occupation="lady of leisure.";}
document.write("<br>You were a respected and accomplished " + occupation);}

xelawho
12-24-2011, 07:24 PM
depending on how you define occu_num, but I think you either need:


else if (occu_num==10)
{occupation="lady of leisure.";}

or


else
{occupation="lady of leisure.";}

zemonster
12-25-2011, 03:39 AM
very well spotted - thank you xelawho !! :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum