Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


How advanced you think this JavaScript code is?

I mean, is this for you a very advanced JS code?

This is an accordion Plug In made by me and my teacher.

var opts = {divId:'divMiAccordion',
            displayMode: 'single',
            titleEvent: 'mouseover'

var acc1 = new Accordion(opts);

var acc2 = new Accordion({divId:'divMiAccordion2',
                          displayMode: 'multiple',
                          titleEvent: 'click'});

function Accordion(opciones){

    var self = this;
    this.init = function(){

        this.container = document.getElementById(opciones.divId);
        this.contenedores = this.container.querySelectorAll('div.panel-body');
        this.titulos = this.container.querySelectorAll('h3');
        this.options = opciones;

        for(var i=0; i<this.contenedores.length; i++){


        for (var i = 0; i < this.titulos.length; i++) {
            if(this.options.titleEvent === 'click'){
                this.titulos[i].onclick = tituloEvent;
                this.titulos[i].onmouseover = tituloEvent;
    } //fin init

     this.getId = function(){
        return self.container.id;

function tituloEvent(){

    var tempNode = null;

    if(self.options.displayMode === 'single'){

        for (var i = 0; i < self.titulos.length; i++) {
                tempNode = self.titulos[i].parentNode.nextElementSibling;

            tempNode = this.parentNode.nextElementSibling;


} //fin accordion

4 Answers

Jimmy Hsu
Jimmy Hsu
6,511 Points

It's not what I'd consider very advanced JavaScript code. Seems closer to intermediate, as you haven't even entered the territory of prototypes or even callbacks.

Don't get me wrong through, it's good code from what I could skim and very clean.

James Barnett
James Barnett
39,199 Points

Beginner, it's basic functional JavaScript.

You are using functions, conditionals, for loops and the this keyword.

Beginner - Intermediate Javascript code. It's not super advanced.

Thank you for all your answers.

I've been struggling with JS for the last 5 months, and now, I feel as if I am dominating the Objects.

What I don't know yet, is how to use Objects with forms and stuff like GETing and POSTing things to the server. I need a course on that, that I think is not on Treehouse yet.

Usually, that's done with a server side language like PHP