Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Object-Oriented JavaScript (2015) Practice Project User Interface Code

Itsik Dangoor
Itsik Dangoor
Front End Web Development Techdegree Student 5,330 Points

why we have the quiz_ui.js file? what is the purpose of having this file code written in separate file? and also...

and also the quiz_ui.js is referring to quiz Object that was create in the quiz.js file, if a programmer want to have various of quizzes: quiz_1 quiz_2 ... the references inside the Object QuizUI won't be relevant and we have to create another QuizUI with the new quiz_2 name!

why we separated like that?

thank you

1 Answer

Hi Itsik,

All the code in the course could be written in one file, you are quite right. Actually, after all the <script> files are loaded, the code "looks like" its all on the same page to the browser.

But not only do we have to think about the computer, we have to think about our own brains! We want to build walls around the code so it's easier to think about in isolation, maybe use pieces of it for other projects.

I think you are right about the code not being totally adapted to running multiple quizzes. But if the project were to be "perfected" to handle multiple quizzes, we'd likely want to generalize the QuizUI object, perhaps give it a constructor and prototype functions. Or maybe add the functionality to the Quiz prototype. Then apps.js would also have to be updated to cycle through all the quizzes. And you'd want to maybe include modifiable text in the HTML to mention "Quiz Topic" or something like that.

I think I did hear Andrew mention in one of the videos that QuizUI was a one-off object.

Take care! -- Cal

I think the QuizUI should have been its own class/constructor, in which you pass the Quiz object. If you named the parameter quiz, then you just replace quiz with this.quiz in the functions.