Jay: how to make a horoscope program in javascript?
I’m having a problem on making a horoscope type program in javascript. Since i’m just a newbie, i don’t know how or what to use(switch statements or if statements or if i need to add a little more). Can anyone help me?
Answers and Views:
Answer by Penumbra
Depends on how complex you want your horoscope to be. If you just want it to display a different message depending on the month, then a switch/case is ideal. I can’t remember if Javascript allows for string literals in a case statement. If it doesn’t then you’ll have to map the months to integers first.
If you want it to have daily messages, or perhaps have an algorithmic way to select a message and maybe tweak the meaning then you’ll need something more complex than a switch/case as it would be quite tedious to manually write out 365 possible outputs.
For example, say you have 36 possible messages, with “You will not have good luck today.” being being the 23rd message. Lets then say that the date is August 21st 2010. Then you could add 8 + 21 + 2010 to get 2039. Then do modulus 36 to get 23, meaning that the 23rd message will be displayed. To make it more fun you could add that if the day is odd (21 is odd in this case) that all instances of ‘not ‘ will be removed. So now the output reads “You will have good luck today.” From there you can add whatever creative twists you want. Maybe on years evenly divisible by 6 all the instances of ‘good’ and ‘bad’ are interchanged?
Leave a Reply