I made an object, and it doesn't work(all the way). Please forgive me if I made beginner mistakes, I'm only 14.
Code:
/**********************************************/
/* This JavaScript Prototype object was made  */
/* by Braxton Spence. It is meant for making  */
/* an Accordion object. Please leave this     */
/* intact if you intend on using it .         */
/**********************************************/
var Accordion = function(descr, main, second, fc, marg)
{
    this.descr = descr;
    this.main = main;
    this.second = second;
    this.fc = fc;
    this.marg = marg;
    var listitems = new Array();
    var urls = new Array();
    this.addItem = function(itemname, url)
    {
        var i = listitems.length;
        var j = urls.length;
        listitems[i] = itemname;
        urls[j] = url;
    }
    this.listTheItems = function()
    {
        for(i = 0; i < listitems.length; i ++ )
        {
            document.writeln(listitems[i] + '<br />');
        }
    }
    this.listTheUrls = function()
    {
        for(i = 0; i < urls.length; i ++ )
        {
            document.writeln(urls[i] + '<br />');
        }
    }
    
    this.createAccordion = function(hsize, vsize, aid)
    {
        document.write('<div style="padding: auto;text-align:center;width:'+hsize+'px;height:'+vsize+';background-color:'+main+';margin:'+marg+';color:'+fc+'">' + descr + '</div><div id="'+aid+'" style="display:block;">');
        document.write('<div style="display:inline;" id="'+aid+'">');
        for(i = 0; i < listitems.length; i ++ )
        {
            document.write('<a href=' + urls[i] + ' style="text-decoration:none; display: inline;"><div style="display:block;padding:auto;text-align:center;width:'+hsize+'px;height:'+vsize+';background-color:'+second+';margin-left:'+marg*2+';margin-top:'+marg+';margin-right:'+marg+';margin-bottom:'+marg+';color:'+fc+'">' + listitems[i] + '</div></a></div>');            
        }
    }
    
    this.hideAccordion = function(aid)
    {
        document.getElementById(aid).style.display='none';
    }
    this.showAccordion = function(aid)
    {
        document.getElementById(aid).style.display='inline';
    }
}
/****************************************************/
/* INSTRUCTIONS:                                                                    */
/* new Accordion(description, main color,                                      */ 
/* secondary color, font color, margin)                                          */
/* addItem(item name, link)                                                         */
/* createAccordion(block width, block height,                                 */
/* accordion id)                                                                         */
/* hideAccordion(accordion id)                                                      */
/* showAccordion(accordion id)                                                    */
/****************************************************/
Here are the things that don't work:
  • hideAccordion only hides the first two items.
  • I couldn't even figure out how to make a removeItem method without the entire accordion disappearing altogether.
  • I couldn't finish the wrapping div(the one that contains the subtopics) by using +(i==listitems.length-1)?'</div>':'' at the end of the createAccodion function, nor could I simply write 'document.write('</div>');' after the for loop. It's like the browser is ignoring all my efforts.