Jump to content

s_gibson86

Members
  • Posts

    6
  • Joined

  • Last visited

Posts posted by s_gibson86

  1. Hey, As the title describes, i am having a bit of trouble creating a script which will move an image back and forth across the screen. I have been to my lecturer for a bit of advice and hoping that he would point me in the right direction but no such luck. So far i have written the script to make it move from left to right across the screen but now i'm struggling to make it move right to left and so forth. I am new to Javascript so a nudge in the right direction would be a huge help. This is my script so far:Thank youSarah

    var max_x = 1024var cup = document.getElementById("cup")var cup_x = 0function moveWin(){	cup_x = cup_x + 10	cup.style.left = cup_x + 'px'	if (cup_x <= max_x) {		timerID = setTimeout("moveWin()", 25)	}}function clicked(thing){	moveWin()}

  2. Hey, As the title describes, i am having a bit of trouble creating a script which will move an image back and forth across the screen. I have been to my lecturer for a bit of advice and hoping that he would point me in the right direction but no such luck. So far i have written the script to make it move from left to right across the screen but now i'm struggling to make it move right to left and so forth. I am new to Javascript so a nudge in the right direction would be a huge help. This is my script so far:Thank youSarah

    var max_x = 1024var cup = document.getElementById("cup")var cup_x = 0function moveWin(){	cup_x = cup_x + 10	cup.style.left = cup_x + 'px'	if (cup_x <= max_x) {		timerID = setTimeout("moveWin()", 25)	}}function clicked(thing){	moveWin()}

  3. Hi, This is the first time i've posted on here so not sure if i've done it right, but i'm looking for a bit of guidance really. I'm doing an introduction to programming module at university and we are studying Javascript; i've never touched the language before so i'm slowly learning. For one of my lab exercises i have been asked to create a javascript fruit/slot machine, just something basic where you click on the handle and it randomly chooses three images from an array list. I've managed all of that so far; however, for the final question we have to make the images change several times as if they are rotating drums, then eventually stop on a random image. Can anyone point me in the right direction how i should go about doing this? This is the javascript code i have so far, which on double click of the handle chooses three random images...

    tim = 0var i = 0var imageSources = new Array;	imageSources[0] = "bar.gif"	imageSources[1] = "cherry.bmp"	imageSources[2] = "lemon.gif"	imageSources[3] = "banana.gif"	imageSources[4] = "orange.gif"	imageSources[5] = "apple.gif"	imageSources[6] = "grapes.gif"	imageSources[7] = "coins.gif"	function randomNumber() {	 return Math.floor(Math.random()*8);		}																		   			function load() {	var testImage1 = document.getElementById("drum1");			testImage1.src = imageSources[randomNumber()];				var testImage2 = document.getElementById("drum2");        testImage2.src = imageSources[randomNumber()];	var testImage3 = document.getElementById("drum3");        testImage3.src = imageSources[randomNumber()];}function handleup() {																	var handle1 = document.getElementById("handle")					handle1.src = "handle.gif";}function handledown() {																	var handle2 = document.getElementById("handle");				handle2.src = "handle2.gif";													tim = setTimeout("handleup()", 4000)									}

×
×
  • Create New...