You are on page 1of 3

Teaching and Learning Activity: Suggested Solutions

Module: Systems Development 3 (HSYD300-1)


Week number (Date): 7 (7 April 2022)
Unit covered: Chapter 14 - 16

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.

This activity is based on Chapter 13 to Chapter 15 of the prescribed courseware for this module.

Question 1
In very simple terms, explain the use of JavaScript in developing web content.

Suggested solution:
JavaScript is a client-side scripting language that enables you to create dynamically updating content,
control multimedia, animate images, and pretty much everything else. The core client-side JavaScript
language consists of some common programming features that allow you to do things such as the
following:

1. Store useful values inside variables.


2. Operations on pieces of text (known as "strings" in programming).
3. Running code in response to certain events occurring on a web page e.g., a click event can
detect when a button is clicked and then run the code for a specific operation.

Page 309 - 310

1 HSYD300-1-Jan-June2022-T&L-StM-W7-Memo-V1-23032022
Question 2

Use the JavaScript if… statement to determine if a person qualifies to drive a vehicle on public roads.
In your code, put the age of 20 as input and use that to test if at that age, a person qualifies for driving.
Assume that the legal age for driving is over 16 years.
Suggested solution:
<html>
<body>
<script type = "text/javascript">
<!--
var age = 20;

if( age > 16 ) {


document.write("<b>Qualifies for driving</b>");
}
//-->
</script>

</body>
</html>

Page 339 - 340


Question 3
What would be the program’s output if the age provided in the code is below 16 e.g., 14? Refactor
your code in Question 2 so that the program can also issue appropriate output if the age provided is
below the legal age for driving e.g., 14 years.

Suggested solution:
The program delivers no output because the selection condition is not satisfied when the age is below
16 years. The refactored program is:
<html>
<body>
<script type = "text/javascript">
<!--
var age = 15;

if( age > 18 ) {

2 HSYD300-1-Jan-June2022-T&L-StM-W7-Memo-V1-23032022
document.write("<b>Qualifies for driving</b>");
} else {
document.write("<b>Does not qualify for driving</b>");
}
//-->
</script>
<p>Set the variable to different value and then try...</p>
</body>
</html>

Page 339 – 340


Question 4
Explain the following terms in the context of JavaScript.

4.1 A Function?

Suggested solution:
A function is a subprogram designed to perform a particular task. Functions are executed when they
are called. This is known as invoking a function. Values can be passed into functions and used
within the function.
Functions are objects.
Functions always return a value. In JavaScript, if no return value is specified, the function will return
undefined.
4.2 A Function Declaration

Suggested solution:
A Function Declaration defines a named function. The function keyword followed by the name of the
function is used to create a function declaration. The general form of a function declaration is:
function name(parameters)
{
statements
}
4.3 A Function Expression

Suggested solution:
A Function Expressions defines a function. Unlike function declarations, a function Expression
cannot be used before they are defined.
3 HSYD300-1-Jan-June2022-T&L-StM-W7-Memo-V1-23032022

You might also like