Programming for the web – A Level Information Technology (9626)

66 questions · page 4 of 5

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
46
9626/32/O/N/19 · Question 4Oct/Nov 2019Paper 3210 marks
Loading question…
Question text

4
A web page uses JavaScript code to display a list of food crops.
Line numbers are provided only for your convenience when referring to the code.
1
<html>
2
<body>
3
<p id="foodcrops"></p>
4
<script>
5
var crops = ["corn", "rice", "maize", "sugarcane"];
6
var i = 0;
7
var show = "";
8
while (crops[i]) {
9
show += crops[i] + "<br>";
10
i++;
11
}
12
document.getElementById("foodcrops").innerHTML = show;
13
</script>
14
</body>
15
</html>
(a) Explain, in detail, how the JavaScript code produces this list from an array.
corn
rice
maize
sugarcane
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [8]
(b) Explain how you would amend the existing JavaScript code to add ‘beans’ to the array so that
it would produce this list.
beans
corn
rice
maize
sugarcane
…
…
…

47
9626/31/M/J/19 · Question 2May/June 2019Paper 316 marks
Loading question…
Question text

2
In JavaScript code, the sort() function is used to sort lists into ascending order.
(a) Explain, in detail, why, when using the sort() function, the list in Fig. 2.1 is sorted correctly, but
the list in Fig. 2.2 is not.
Before sorting
After sorting
Before sorting
After sorting
fly
ant
1345
1111
cockroach
beetle
3666
12
ant
butterfly
1111
1345
butterfly
cockroach
23
23
moth
fly
37
3666
beetle
moth
12
37
Fig. 2.1
Fig. 2.2
…
…
…
…
…
…
…
…
…
… [4]
(b) Write a line of JavaScript code that could be used to sort the list of insects in Fig. 2.1 into
descending order.
…
…
… [2]

48
9626/31/M/J/19 · Question 3May/June 2019Paper 3116 marks
Loading question…
Question text

3
An online retailer uses a simple form on its website to enable customers to contact its After Sales
department by email. The form looks like this:
Send an email to [email protected]:
Your Name:
Your email address:
Comment:
Send
Reset
Some of the code that created the form is shown.
Note that the lines have been numbered only for your convenience and reference.
1
<html>
2
<body>
3
4
<h2>Send an email to [email protected]:</h2>
5
6
<form action="mailto: [email protected]" method="post"
enctype="text/plain">
7
8
Your Name:<br>
9
10
Your email address:<br>
11
12
Comment:<br>
13
14
15
16
</form>
17
</body>
18
</html>
19
20
(a) Explain what the different parts of the code in line 6 do.
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]
(b) Create some additional lines of code that could be inserted into the script at appropriate
locations to collect the name and email address of the customer. Indicate, with reference to
the line numbers, where your additional code should be inserted.
Line number
Code
[4]
(c) Write down the code that would allow:
•
the comment to be entered
•
the form to be submitted
•
the form to be reset.
Indicate which line numbers the codes would appear on.
Line number
Code
[6]

Advertisement
49
9626/32/M/J/19 · Question 3May/June 2019Paper 328 marks
Loading question…
Question text

3
An author has written the source code of a web page that will be used when a person applies for a
driving licence. The code, shown in Fig. 3.1, is intended to check that a person is at least 16 years
of age.
The lines of the code are numbered only for your convenience when referring to the code.
The JavaScript code is in lines 8 to 19.
1
<html>
2
<body>
3
<p>You can apply for a licence to drive when you are 16 years
old.</p>
4
<p>To check if you are old enough to drive, input your age and
click the button:</p>
5
<input id="AgeNow" value="16" />
6
<button onclick="CheckAgFunction()">Check now</button>
7
<p id="AgeCheck"></p>
8
9
function CheckAgeFunction()
10
var AgeNow;
11
AgeNow = Number(document.getElementById("AgeNow").value);
12
if (isNaN(AgeNow)) {
13
CanApply = "Please enter your age in numbers.";
14
} else {
15
CanApply = (AgeNow >15)? "You are too young to apply
for a licence.": "You are old enough to apply for a licence.";
16
}
17
document.getElementById("AgeCheck).innerHTML = CanApply;
18
}
19
20
</body>
21
</html>
Fig. 3.1
Testing has shown that the code contains a number of errors of different types which must be
corrected before the code will perform as expected.
Identify the line numbers containing the errors. Explain why each of the errors prevents the code
from running correctly and how each should be corrected. Use the table for your response.
Line number of error and explanation of
Explanation of suggested correction.
error.
[8]

50
9626/32/F/M/19 · Question 1Feb/March 2019Paper 327 marks
Loading question…
Question text

1
Errors in JavaScript code can cause the code to fail to execute when run by a web browser. The
code shown is intended to display a table on a web page when run in a web browser.
The line numbers are shown only for your convenience when referencing the code in your
answers.
1
<html>
2
<body>
3
<script language="JavaScript">
4
tableout = "<table border='1' width='300' cellspacing='0'
cellpadding='3'>"
5
for (b = 1; b <= 10; b++) {
6
tableout = tableout + "<tr>":
7
for (g = 1; g <= 10; g++) {
8
tableout = tableout + "<td>" + b * g + "</td>";
9
}
10
tableout = tableout + "</tr>";
11
}
12
tableout = tableout + "</table>";
13
document.write (tableout);
14
</script>
15
</body>
16
</html>
(a) The code does not run as intended in web browsers because there is an error in the code.
Describe how the error in the code prevents the web browser from running as intended.
…
…
…
…
…
… [2]
(b) Errors can be ‘trapped’ in order that the performance of the web browser is not affected.
Explain how you can use error handling techniques to trap errors in JavaScript code.
…
…
…
…
…
…
…
…
…
…
…
… [5]

51
9626/32/F/M/19 · Question 8Feb/March 2019Paper 328 marks
Loading question…
Question text

8
The owners of a bank are replacing its current system by transferring all accounts and processes
to a new computer system. They have to be sure that the new system will carry out all the functions
of the old system.
It is essential that there is no interruption in the services provided by the bank’s computer system
to its staff and customers.
Choose the most appropriate method of implementation and explain how the new system will be
implemented.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [8]

52
9626/32/O/N/18 · Question 5Oct/Nov 2018Paper 3214 marks
Loading question…
Question text

5
Quintin is a programmer who writes code in HTML and JavaScript for use in online forms. The
code is developed and ‘white-box’ tested before being used.
Quintin is developing the code below. He has added comments to the code. The code asks a user
to input two numbers and adds the numbers together. It also displays the total and whether or not
it is greater than 10.
<html>
<body>
<!-- the next six lines collect the two numbers to be added-->
<br/>Enter first number:
<input type="number" id="nm1" name="num1">
<br/><br/>Enter second number:
<input type="number" id="nm2" name="num2">
<p id="add"></p>
<script>
function myaddfunction() {
//the next line assigns the first number input to the variable y
var y = document.getElementById("nm1").value;
//the next line assigns the second number input to the variable z
var z = document.getElementById("nm2").value;
//the next line adds the two numbers and assigns the result to the variable x
var x = +y + +z;
//the next line checks if x is greater or not greater than 10 and reports
accordingly
var A = (x >10) ? x+ " is greater than 10":x+ " is not greater
than 10";
//the next line prints the results onto the page
document.getElementById("add").innerHTML = A ;
}
</script>
<!-- the next two lines asks the user to click the button and then the script
is executed
<p>Click the button to calculate the total.</p>
<button onclick="myaddfunction()">Add the numbers</button>
<br/>
</body>
</html>
(a) Explain how Quintin could use ‘white box’ testing to ensure that the JavaScript code produces
the correct result every time.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

53
9626/32/O/N/18 · Question 7Oct/Nov 2018Paper 328 marks
Loading question…
Question text

7
The table shows part of a database used to control the level of stock items in a clothing store.
Reordering is done when the number left in stock reaches or falls below the minimum level allowed
by the store management.
Item_Code Description_of_Item Item_Price Current_Stock_ Minimum_Stock_ Quantity_to-be_
Level
Level_Allowed
Reordered
XYP234
Walking boots (pair)
$128.50
16
15
10
ABG765
Jackets
$99.56
15
10
15
SCC653
Gloves (pair)
$36.99
23
20
25
SOX785
Socks (pair)
$25.99
33
30
50
XYT981
Scarf
$34.45
16
10
20
A customer purchases two pairs of walking boots, three pairs of socks and a scarf. The items each
have a barcode and are scanned at the checkout when purchased.
Describe, in detail, the processes that would occur when the purchases have been made to ensure
that the appropriate new orders are placed to maintain the stock levels.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [8]

Advertisement
54
9626/33/O/N/18 · Question 5Oct/Nov 2018Paper 336 marks
Loading question…
Question text

5
JavaScript can be embedded in the code of web pages to add interactivity to a page.
Explain what is meant by the following terms when they are used in JavaScript:
(a) an array.
…
…
… [1]
(b) a variable.
…
…
… [1]
(c) a function.
…
…
… [1]
(d) a comment.
…
…
… [1]
(e) an object.
…
…
… [1]
(f)
an expression.
…
…
… [1]

55
9626/31/M/J/18 · Question 2May/June 2018Paper 315 marks
Loading question…
Question text

2
JavaScript defines a number of primitive data types.
(a) Explain the term ‘primitive’ when used in this context.
…
…
…
…
… [2]
(b) Describe three primitive data types used in JavaScript.
1 …
…
…
2 …
…
…
3 …
…
… [3]

56
9626/31/M/J/18 · Question 3May/June 2018Paper 314 marks
Loading question…
Question text

3
Variables are used in JavaScript to hold values.
Explain how a variable is created in JavaScript code.
…
…
…
…
…
…
…
…
… [4]

57
9626/31/M/J/18 · Question 6May/June 2018Paper 315 marks
Loading question…
Question text

6
Tamsin is evaluating CPU hardware for use in a new tablet computer. She uses the charts in
Fig. 1 to help her make a decision between using CPU 1 or CPU 2 in the new tablet.
Time taken to run a JavaScript
Performance tests
benchmark test
CPU 1
Physics
CPU 1
calculations
test
CPU 2
Graphics
performance
CPU 2
0
2
4 6 8 10 12 14 16
Time in seconds
0
5
10
15
Score (points)
Fig. 1
Identify, with reasons based on the information in Fig. 1, the most suitable CPU for Tamsin to use
in the new tablet computer.
…
…
…
…
…
…
…
…
…
… [5]

58
9626/31/M/J/18 · Question 7May/June 2018Paper 316 marks
Loading question…
Question text

7
Cynthia has created a database to store details of her friends in the UK and wants to include
their home addresses. She will create a validation routine to check that the UK postcode of their
address is in a valid format when it is entered into the database.
UK postcodes must have an outward code and an inward code separated by a single space. The
outward code is made up of the postal area and the postal district. The inward code also has two
parts: the postal sector and the postal unit. A typical UK postcode is CB1 2EU.
The whole postcode conforms to a format as shown by the examples in Fig. 2.
UK Postcode Formats
Outward Code
Inward Code
Area
District
Sector
Unit
Written as:
Example 1:
CB
1
2
EU
CB1 2EU
Example 2:
SW
1A
1
AA
SW1A 1AA
Example 3:
SW
1A
0
AA
SW1A 0AA
Example 4:
CV
4
8
JQ
CV4 8JQ
Fig. 2
Using the information given above, describe what the validation routine would have to do in order
to check that the entered postcode was in a valid format.
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]

Advertisement
59
9626/32/M/J/18 · Question 4May/June 2018Paper 3215 marks
Loading question…
Question text

4
‘Loops’ are used in JavaScript to execute a block of code several times.
The following code shows a ‘for’ loop and the code for displaying the result.
<p id="Number"></p>
<script>
//JavaScript code follows
var displayresult = "";
var X;
for (X = 1; X < 10; X += 3) {
displayresult += X + "<br>";
}
//the following line displays the contents of ‘displayresult’ on the
webpage
document.getElementById("Number").innerHTML = displayresult;
</script>
(a) Describe what each statement in the ‘for’ loop does and the results that are output when the
code is executed.
…
…
…
…
…
…
…
…
…
…
…
… [5]
(b) Rewrite the ‘loop’ code as a DO WHILE loop to display the same results.
…
…
…
…
…
…
…
…
…
…
…

60
9626/33/M/J/18 · Question 2May/June 2018Paper 336 marks
Loading question…
Question text

2
The use of JavaScript within the HTML code of a web page allows the page to react to user
intervention.
The code below contains a function named checkreadpagefunction that will ask the user to
confirm that the page has been read.
Complete the JavaScript code by writing extra code that will capture the click event and execute
the function.
<html>
<body>
<p>Click on the button to confirm that you have read this page.</p>
<button id="button1">Click here</button>
<script>
…
…
…
…
…
… [6]
function checkreadpagefunction() {
alert ("I have read this page.");
}
</script>
</body>
</html>
You may use the space below for any rough work.

Advertisement