// Print (semi-)gramatically correct message if(weeksToXmas == 1) document.writeln(' there is 1 week and '); else document.writeln(' there are ' + weeksToXmas + ' weeks '); if(daysToXmas == 1) document.writeln(' and 1 day '); else document.writeln('and ' + daysToXmas + ' days '); document.write('left until Christmas. Ho! Ho! Ho!</font>'); if(weeksToXmas == 0 && daysToXmas ==0) document.writeln('</font><font size = "7" ><p>Have you been naughty or nice?');
This section of code formats the output. Incorrect grammer distract people (see?), so we want to make sure that we don't print,
There are 3 weeks and 1 days until Christmas!
To accomplish this, all that is necessary is to check the value of weeksToBday and daysToBday using the if/else construction to print appropriate phrases. When either variable is 1, the phrase is printed to reflect the "tense" of the variable. In all other cases, the variable is assumed to be plural.
Consider the case where either variable is 0. As the code stands, the output is,
There are 3 weeks and 0 days until Christmas!
Although the phrase is gramatically correct, it would be nice if the output was,
There are 3 weeks until Christmas!
I will leave this as an exercise in program logic. Enjoy!