Professional Documents
Culture Documents
Teaching and Learning Activity: 1 Hsyd300-1-Jan-June 2022-Tl-Stm-W8-V1-23032022
Teaching and Learning Activity: 1 Hsyd300-1-Jan-June 2022-Tl-Stm-W8-V1-23032022
Instructions:
To enrich your learning experience at Boston even further, and to ensure that you are exposed to a
variety of resources in this module, announcements will be posted every week containing additional
materials or activities for you to work through.
It is important to note that these activities are neither compulsory nor weighted, but that it will be to your
advantage to participate. The purpose of the activities is to help you better understand the content of
your weekly unit/s of study, and it will assist in creating insight and deeper meaning.
Activity 6 is based on Chapter 14, 15, and 16 of the prescribed courseware for this module.
The suggested solutions for this Activity will be posted end of day Thursday.
1.1 Predict the output produced by the following JavaScript code. Explain the program code.
<body>
<script type = "text/javascript">
a = [1,2,3,4,5, 6,7,8,9,10];
function printArray(a)
{
var len = a.length, i = 0;
if (len == 0)
document.write("Empty Array");
else
{
do
{
document.write(a[i] + " ");
} while (++i < len);
if (i == len)
document.write("|");
}
1 HSYD300-1-Jan-June 2022-TL-StM-W8-v1-23032022
}
function printRevArray(a)
{
var len = a.length, i = len - 1;
if (len == 0)
document.write("Empty Array");
else
{
do
{
document.write(a[i] + " ");
} while (--i >= 0);
}
}
printArray(a);
printRevArray(a);
</script>
</body>
1.2 What will be the output of the following JavaScript code if usrNum is 6?
1.3 Dry run the following JavaScript code and explain why it produces 111111111111 as output
in the browser.
function range(length)
{
var a=5;
for(i=0;i<length;++i)
{
document.write(a+6);
}
}
range(6);
3 HSYD300-1-Jan-June 2022-TL-StM-W8-v1-23032022