JavaScript III bis

Required Reading

On the recommendation of a CSCI 107 student, I’ve added another reference, available on-line, as useful reading for the course. This reference has a little cover of jQuery, a very popular JavaScript library.

Stuff to know

You really don’t have to know everything about JavaScript for CSCI 107. Conditionals and loops would be very nice, but let&rsquos;s come up with a list that would allow you to do a lot of nifty things.

A matter of scope and objects

What is the difference between the following?

Example A

function changePartingQuote() {
    var partingElement = document.getElementById('parting');
    partingElement.innerHTML = partingElement.innerHTML + " twoBee || !twoBee";
}

function startup() {
    setInterval(changePartingQuote, 10000);
}

Example B

var partingElement ;

function changePartingQuote() {
    partingElement.innerHTML = partingElement.innerHTML + " twoBee || !twoBee";
}

function startup() {
    partingElement = document.getElementById('parting');
    setInterval(changePartingQuote, 10000);
}

Example C

var partingAdvice;

function changePartingQuote() {
    partingAdvice = partingAdvice + " twoBee || !twoBee";
}

function startup() {
    partingAdvice = document.getElementById('parting').innerHTML;
    setInterval(changePartingQuote, 10000);
}