/    Sign up×
Community /Pin to ProfileBookmark

Javascript Circular Array

Please someone give me insight into why the SHIFT RIGHT function doesn’t work. It’s pretty much the opposite of the left shift function….but it just doesn’t work.

[code]
function updateMe() {
box = document.getElementById(“pictures”);
box.innerHTML = ”;
for (x=0; x<pictures.length; x++)
{
box.innerHTML += pictures[x];
}
}

function shiftLeft() {
box = document.getElementById(“pictures”);
var saveMe = pictures[0];
for(x=0; x<pictures.length-1; x++)
{
pictures[x] = pictures[x+1];
}
pictures[pictures.length-1] = saveMe;
updateMe();
}

function shiftRight() {
box = document.getElementById(“pictures”);
var goAway = pictures[pictures.length-1];
for(x=1; x<pictures.length; x++)
{
pictures[x] = pictures[x-1];
}
pictures[0] = goAway;
updateMe();
}
[/code]

I haven’t done a lot in JS, but logically I swear this should work.

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterJul 03.2005 — for([color=red]var[/color] x=[color=red]0[/color]; x<pictures.length; x++)

<i>
</i>function shiftRight() {
[color=red]var[/color] box = document.getElementById("pictures");
var goAway = pictures[pictures.length-1];
for([color=red]var[/color] x=[color=red]0[/color]; x&lt;pictures.length; x++)
pictures[x] = pictures[x-1];
pictures[0] = goAway;
updateMe();
}
Copy linkTweet thisAlerts:
@CompGeek01authorJul 03.2005 — Hm. Still does the same thing.

Here it is in context.

http://www.lifeofbrian.us/
Copy linkTweet thisAlerts:
@ExuroJul 03.2005 — You just need to go backward through your images when you shift right instead of forward: function shiftRight() {
var box = document.getElementById("pictures");
var goAway = pictures[pictures.length-1];
for([color=red]var x=pictures.length-1; x&gt;0; x--[/color])
{
pictures[x] = pictures[x-1];
}
pictures[0] = goAway;
updateMe();
}
Copy linkTweet thisAlerts:
@UltimaterJul 03.2005 — Multipul onload events... change 'em to:
window.onload = function(){multipleEmailCloak();setUp();}

Your image flopping is also flawed...
Copy linkTweet thisAlerts:
@CompGeek01authorJul 03.2005 — Thanks, I figured out the logic issue.

How is my image flopping flawed? Works in all major browsers and doesn't generate errors...
Copy linkTweet thisAlerts:
@ExuroJul 03.2005 — You should really just be changing the [FONT=Courier New]src[/FONT] element of the image tags rather than re-writing them all to the page every time you shift them.
Copy linkTweet thisAlerts:
@UltimaterJul 03.2005 — #1 you should preload all your images.

#2 all your images are lacking the required ALT attribute.

#3 XHTML doesn't allow the name attribute in the IMG tag.

#4 there is no LANGUAGE attribute for the SCRIPT tag.

#5 document.left and document.right work for references, but they could also be refering to frames -- might wanna add an "images" in there or "forms[0]" and add a form. However, since there is no NAME attribute in XHTML, you should give 'em an ID.
Copy linkTweet thisAlerts:
@CompGeek01authorJul 04.2005 — Thanks for the help. I don't really care about the standards atm. I do positioning and layout then go back and standardize on personal sites like this.

I really appreciate the help though. Good point on the changing of image sources.
×

Success!

Help @CompGeek01 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...