Moving on javascript random pick and collapsable div

One of the first javascripts I have planned to use was random pick. Code for this kind of function was found on website:

http://gnwda.org/tutorials/Q&A/java-random.htm

This javascript was working properly on and off for some reason. But on the top of it, after going back from game page to home page useing home btn, javascript failed to load as this example doesnt work in a loop.

Different code was find on website: http://www.javascriptkit.com/javatutors/random2.shtml

After implementing this new code:

function randomGame(){
var myrandom=Math.round(Math.random()*9)
var link1=”game1.html”
var link2=”game2.html”
var link3=”game3.html”
var link4=”game4.html”
var link5=”game5.html”
var link6=”game6.html”
var link7=”game7.html”
var link8=”game8.html”
var link9=”game9.html”
var link10=”game10.html”
if (myrandom==0)
window.location=link1
else if (myrandom==1)
window.location=link2
else if (myrandom==2)
window.location=link3
else if (myrandom==3)
window.location=link4
else if (myrandom==4)
window.location=link5
else if (myrandom==5)
window.location=link6
else if (myrandom==6)
window.location=link7
else if (myrandom==7)
window.location=link8
else if (myrandom==8)
window.location=link9
else if (myrandom==9)
window.location=link10
}

Second function I wanted to implement in one of the game rules was collapsable div.  There is many jQuery with this function, so why do I have to look for simple javascript?

Answer is simple, as jquery should be used in web browsing only, not in app development. Phone runs on different software and hasn’t got that powerfull hardware as PC or Mac.

I was also consider useing just pure CSS3 to achieve this as I came a croos this tutorial: http://dev.opera.com/articles/view/css3-show-and-hide/#sec1

Code seem to be very long and complicated for such a small function so to the end I have decided to use one of the javascripts from my library:

http://www.boristav.sk/_sub/jakub/collapsible/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: