Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Teaching and Learning Activity

Module: Systems Development 3 (HSYD300-1)


Week number (Date): 8 (7 April 2022)
Unit covered: Chapter 15, 16, 17

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?

<script type = "text/javascript">


var usrNum;
function findDigit(usrNum){
switch (usrNum)
{
case 7:
case 8:
case 9:
document.write ("The digit " + usrNum + " is on the Top row.")
break
case 4:
case 5:
case 6:
document.write ("The digit " + usrNum + " is on the Central row.")
break
case 1:
case 2:
case 3:
document.write ("The digit " + usrNum + " is on the Lower row.")
break
default:
2 HSYD300-1-Jan-June 2022-TL-StM-W8-v1-23032022
document.write ("The digit " + usrNum + " must be on the very last row.")
break
}
}
findDigit (usrNum)
</script>

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

You might also like