Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    fun script, mysterious problem...

    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);}

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    3,020
    Thanks
    56
    Thanked 566 Times in 563 Posts
    depending on how you define occu_num, but I think you either need:

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

  • #3
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    very well spotted - thank you xelawho !!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •