Any web codemonkeys that can help me out?

Status
Not open for further replies.

doomdragon6

Staff member
So I got this script for my site; it's just a simple random quote per page load. The script has a default of 10 quotes as you can see here:

Code:
<script language="JavaScript">
// ==============================================
// Copyright 2004 by CodeLifter.com
// Free for all; but please leave in this header.
// ==============================================
var Quotation=new Array() // do not change this!
// Set up the quotations to be shown, below.
// To add more quotations, continue with the
// pattern, adding to the array.  Remember
// to increment the Quotation[x] index!
Quotation[0] = "Like an anime, only you're in it!";
Quotation[1] = "Shio Says: Never let anyone put you in a dryer!";
Quotation[2] = "Shio means \"salt\" in Japanese, and Kosho means \"pepper\".";
Quotation[3] = "Kosho's motorcycle has a name. It's \"Grinder\".";
Quotation[4] = "You only just now realized this line is randomly generated.";
Quotation[5] = "How many times have you refreshed?";
Quotation[6] = "Seriously, stop refreshing.";
Quotation[7] = "Voted \"Most Likely to be an Anime Con\" in high school!";
Quotation[8] = "The turtle's name is Shoyu. :3";
Quotation[9] = "Kosho was originally going to be a shadowy demon creature called Nega-Shio.";
// ======================================
// Do not change anything below this line
// ======================================
var Q = Quotation.length;
var whichQuotation=Math.round(Math.random()*(Q-1));
function showQuotation(){document.write(Quotation[whichQuotation]);}
showQuotation();
</script>
</font>
</center>
I want to add more, and the instructions make it pretty clear that all you have to do is add more and increase the number each time. I did that, but it breaks the code and it doesn't work at all. Only when I reduce it back to the 10 originals can it function.

Am I missing anything? This seems fairly simple, but maybe I'm just not getting something.
 

doomdragon6

Staff member
I'm an idiot. I found what broke it. I put a link in one of the quotes improperly and completely forgot that I put it there, and it was breaking everything.

Oh well, thanks Tin! XD;
 

doomdragon6

Staff member
Actually, while you're here(?), can you tell me how to vertically align that code? I've tried for a bit and I can't seem to get it to work.

If you haven't noticed yet, I don't know code very well. :|
 

doomdragon6

Staff member
And that will... center it vertically? >> That seems like it would just left-align it.

Yeah, that just left-aligned. I need to know the rest. :p

I'm not a real coder guys, I use WYSIWYG, and I have an html box with that code it it, and I can "center" it but I can't get it aligned vertically.
 

fade

Staff member
If you don't want it left aligned, what do you mean "align vertically"? I admit I'm confused.
 

fade

Staff member
Ah, I see. That's actually one of the weak points of html and css. Whole articles are devoted to how to center something vertically. It's technically not correct syntax, but you can probably do it by wrapping everything inside your center tags in a div with vertical-align set to middle, like so:
Code:
<center>
<div style="vertical-align: middle">
Stuff
</div>
</center>
Technically this is incorrect, because vertical-align is supposed to only work on images and table cells. But most browswers will probably do what you want.

Technically correct but probably more confusing is this:
Code:
<div style="position: relative">
<div style="position: absolute; top: 50%; height: 10em (or whatever you want); margin-top: 5em; (half that last number)">
<center>
stuff
</center>
</div>
</div>
But like I said, more confusing, and still not correct, because center is deprecated (html should no longer say anything about how the page looks, just what the logical blocks are. Like "this is the title", "this is content", etc.)
 
You might want to replace everything in the script tag above the do not modify comment with the array definition below. This will let you add and remove quotations without having to worry about adjusting the index.
Code:
var Quotation = [
    "first quote",
    "any quote you want",
    "just be sure to place a comma after each quote",
    "except for the last quote"
];
 
Status
Not open for further replies.
Top