2. Why is it important?
Without documentation, programs
may be confusing and/or make no
sense.
3. va r sla ying = t rue ;
va r youH it = M a t h.f loor (M a t h.ra ndom () * 2);
va r da m a ge ThisRound = M a t h.floor (M a t h.ra ndom () *
5 + 1);
va r t ot a lD a m a ge = 0;
w hile (sla ying) { if (youH it ) {
c onsole .log("You hit t he dra gon a nd did " +
da m a ge ThisRound + " da m a ge !");
t ot a lD a m a ge + = da m a ge ThisRound ;
if (t ot a lD a m a ge > = 4) {
c onsole .log("You did it ! You sle w t he dra gon!");
sla ying = f a lse ;
} e lse {
youH it = M a t h.f loor (M a t h.ra ndom () * 2);
} } e lse {
c onsole .log("The dra gon burnina t e s you! You' re
t oa st .");
sla ying = fa lse ; }}
?
5. Commenting
Comments can be used as a form of pseudocode to
outline intention prior to writing the actual code. In
this case it should explain the logic behind the code
rather than the code itself.
7. General Rules for Commenting
Not every line should be commented, but any line that
performs an operation should.
Any line that causes confusion should be commented.
At the top of the program there should be comments on
its purpose and scope of the program.
Another common comment is a last revised date and
version number at the top of the program.