Java Reference
In-Depth Information
Quiz Ninja Project
We'll now put some of the ideas we've learned in this chapter into practice in our quiz pro-
ject. Our first task is to move all the view logic into a self-contained module using an IIFE.
This includes all the variables that refer to elements (those with names that start with the
$ symbol) and the update() , hide() , and show() functions. We'll move all of these
into an anonymous IIFE that returns an object assigned to the global variable view . Add
the following code to the beginning of the scripts.js file (right after the "use strict"
var view = (function () {
function update(element,content,klass) {
var p = element.firstChild ||
p.textContent = content;
if(klass) {
p.className = klass;
function hide(element) { = "none";
function show(element) { = "block";
return {
question: document.getElementById("question"),
score: document.getElementById("score"),
feedback: document.getElementById("feedback"),
start: document.getElementById("start"),
form: document.getElementById("answer"),
timer: document.getElementById("timer"),
hiScore: document.getElementById("hiScore"),
Search WWH ::

Custom Search