var X =1; 1 mark Do {...} 1 mark +=X 1 mark + “
” 1 mark X=X+3 1 mark while (X < 10) 1 mark 4(c) Four from: 4 The code is executed by the web browser Not on the web server Web browser may not support the code language So the code may not execute properly/at all/produce errors Different browsers run code in different ways Developers must test all code with all browsers Same browsers on different operating systems behave differently Code may produce different results Code requires high processing power So webpages may display slowly/not at all Non-functioning code may deter viewers leading to loss of audience/sales via the website."},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":10,"name":"Q10 · The use of JavaScript within the HTML code of a web page allows the page to react to user…","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q10-text","text":"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 …","acceptedAnswer":{"@type":"Answer","text":"2 A suitable line of code would be: 6 document.getElementById(“button1”).addEventListener(“click”, checkreadpagefunction); Six from: 1 mark for each of: Capturing the element: document.getElementById Identifying the button by name: “button1” Checking for the event: addEventListener Correct reference to click by mouse: “click”, Calling the correct function by name: checkreadpagefunction); All correct delimiters and all correct brackets: . between key words, , after click AND ; after function () around button1 () around parameter (“click”, checkreadpagefunction);"},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":11,"name":"Q11 · Quintin is a programmer who writes code in HTML and JavaScript for use in online forms","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q11-text","text":"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…","acceptedAnswer":{"@type":"Answer","text":"5(a) Eight from: 8 Checking each line of code/statement Ensures that each line of code is executed at least once Ensures that var y and z assign the collected numbers as required Checks that the additon of y and z is correct Ensures that the correct message is displayed when result assigned to A Checking each branch/decision in the code Checks that decisions are carried out correctly So that values put in A can be compared Ensures that result is checked against > 10 Ensures that the correct result is put in var × as required Checks every possible pathway through the code So that test values in var y and z cause each subsequent path to be followed So that test values in x are assigned to A to produce both the messages “is greater than 10” and “is not greater than 10” depending on value in A. 5(b) Six from: 6 Can separate code into different conceptual/functional areas for ease of development/testing/understanding Separating HTML and JavaScript code provides modularity to code Which is easier to read/maintain/update by Quintin/different coders as required Can call the code several times/from different pages/re-use the code No need to rewrite/have several copies/copies on each web page Code only has to be tested once/checked for errors once File/JavaScript is cached by web browser No need to reload it/fetch code repeatedly if need on other pages Reduces network access/reduces cost of fetching data JavaScript code embedded in web pages can slow loading times/reduce browser performance Web page can slow/stop while browser executes code."},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":12,"name":"Q12 · JavaScript can be embedded in the code of web pages to add interactivity to a page","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q12-text","text":"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 …","acceptedAnswer":{"@type":"Answer","text":"5(a) Stores multiple values in a single variable. 1 5(b) Containers for storing data values. 1 5(c) One from: 1 A block of code designed to perform a particular task Code executed when it is invoked (called). 5(d) One from: 1 Text preceded by // is not executed/ignored by JavaScript Used to explain the code Used to halt execution of the code Text that is not executed before a line of code Text that is not executed at end of line of code. 5(e) One from: 1 A collection of variables and functions Representing the attributes and behaviour of an ‘item’/‘thing’ being modelled in a program. 5(f) One from: 1 Any (valid) unit of code that resolves to a value Two types of expression exist: … can have a value … can assign a value to a variable."},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":13,"name":"Q13 · Errors in JavaScript code can cause the code to fail to execute when run by a web browser","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q13-text","text":"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…","acceptedAnswer":{"@type":"Answer","text":"Question Answer Marks 1(a) Two from: 2 A colon (:) is shown instead of a semi-colon (;) in line 6 ...this is a syntax error Syntax errors prevent JavaScript from being executed/are fatal errors in code The web browser displays nothing at all from this code The variable ‘tableout’ has not been declared before it is used Some browsers will ignore/compensate/interpret this differently from others Results can be different/unexpected in different browsers. 1(b) Five from: 5 Add specific code to deal with the errors transparently/without affecting the web browser Specify block of code to be tested Add some code produce output that depends on (the type of) error encountered Use try() block of code to be tested Use catch() to define the error handling code Use final() to allow code to be executed/run Use throw() to display information about the error/error message Specify the text to be displayed on screen as a result of the error."},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":14,"name":"Q14 · In JavaScript code, the sort() function is used to sort lists into ascending order","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q14-text","text":"In JavaScript code, the sort() function is used to sort lists into ascending order. (a) Explain, in detail, why, when using the sort() func…","acceptedAnswer":{"@type":"Answer","text":"2(a) Four from: 4 Function sort () treats values as strings not numbers Strings are sorted alphabetically Strings are not sorted numerically a is before / ‘lower’ than b so list 1 is sorted alphabetically by the first letter and then by the second etc. in list 2, the list is also sorted alphabetically so e.g. 1111 is before 12 because 2 is ‘bigger’ than 1 Max. 1 for additional examples e.g.: The third character in 1111 has no match so is ‘bigger’ than 12 3666 is before 37 because while the 3s match, and 6 is before 7, there is no match for the second 6 so it is ‘bigger’ than no number. 2(b) A suitable line with the function is: insects.reverse(); 2 The variable name can be anything suitable, reverse() is the function. Mark allocation: Use of suitable variable name e.g. insects 1 mark All correct function and syntax .reverse(); 1 mark"},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":15,"name":"Q15 · An online retailer uses a simple form on its website to enable customers to contact its…","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q15-text","text":"An online retailer uses a simple form on its website to enable customers to contact its After Sales department by email. The form looks lik…","acceptedAnswer":{"@type":"Answer","text":"3(a) Six from: 6
Specifies the encoding of the data As plain text. 3(b) Four from: 4 Line Code number 9 1 mark
1 mark 11
1 mark 3(c) 6 Line Code number 13 14 15 Six from: Code on correct lines Correct syntax Size=\"100\" or suitable value value=\"Submit your details\" following submit value=\"Reset the form\" following reset Correct input types 1 mark each"},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":16,"name":"Q16 · An author has written the source code of a web page that will be used when a person…","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q16-text","text":"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. …","acceptedAnswer":{"@type":"Answer","text":"3 8 Line number of error and Explanation of suggested explanation of error correction Line 6/9 and the function is spelt Should be same as function/ incorrectly / differently, so will not CheckAgeFunction/ run on button click CheckAgFunction Line 8 script is not opened so web Add to close the script browser cannot interpret it 1 mark for error and 1 mark for matching correction."},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":17,"name":"Q17 · In JavaScript code, the sort() function is used to sort lists into ascending order","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q17-text","text":"In JavaScript code, the sort() function is used to sort lists into ascending order. (a) Explain, in detail, why, when using the sort() func…","acceptedAnswer":{"@type":"Answer","text":"2(a) Four from: 4 Function sort () treats values as strings not numbers Strings are sorted alphabetically Strings are not sorted numerically a is before / ‘lower’ than b so list 1 is sorted alphabetically by the first letter and then by the second etc. in list 2, the list is also sorted alphabetically so e.g. 1111 is before 12 because 2 is ‘bigger’ than 1 Max. 1 for additional examples e.g.: The third character in 1111 has no match so is ‘bigger’ than 12 3666 is before 37 because while the 3s match, and 6 is before 7, there is no match for the second 6 so it is ‘bigger’ than no number. 2(b) A suitable line with the function is: insects.reverse(); 2 The variable name can be anything suitable, reverse() is the function. Mark allocation: Use of suitable variable name e.g. insects 1 mark All correct function and syntax .reverse(); 1 mark"},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":18,"name":"Q18 · An online retailer uses a simple form on its website to enable customers to contact its…","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q18-text","text":"An online retailer uses a simple form on its website to enable customers to contact its After Sales department by email. The form looks lik…","acceptedAnswer":{"@type":"Answer","text":"3(a) Six from: 6 Specifies the encoding of the data As plain text. 3(b) Four from: 4 Line Code number 9 1 mark
1 mark 11
1 mark 3(c) 6 Line Code number 13 14 15 Six from: Code on correct lines Correct syntax Size=\"100\" or suitable value value=\"Submit your details\" following submit value=\"Reset the form\" following reset Correct input types 1 mark each"},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":19,"name":"Q19 · The area of a rectangle can be calculated using the JavaScript embedded in a web page as…","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q19-text","text":"The area of a rectangle can be calculated using the JavaScript embedded in a web page as shown below. 1 2 3 delimiters/markers The browser executes the JavaScript code within the delimiters Variable crops is set to contain the list of crops Variables i and show are initialised While loop will continue looping as long as crops[i] contains data/string (var) i is incremented by 1 each time loop is executed (var) show is set to the current value of show concatenated with next crop value Loop terminates when array has no more items/final value in array is reached Final values of (var) show are displayed on screen/web page Values shown in vertical list as
code forces carriage return/line feed. 4(b) Two from: 2 Amend the array var crops = [] 1 mark to [“beans”, \"corn\", \"rice\", \"maize\", \"sugarcane\"]; 1 mark Add the line crops.unshift(\"beans\"); « 1 mark « any line between var crops and while() 1 mark Amend the var show line to « 1 mark « \"beans
\"; 1 mark"},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":25,"name":"Q25 · The area of a rectangle can be calculated using the JavaScript embedded in a web page as…","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q25-text","text":"The area of a rectangle can be calculated using the JavaScript embedded in a web page as shown below. 1 2 3 tags Variables x and y declared Values stored in x and y/x stores 12 and y stores 6 window.alert(x + y); function adds/sums x and y to produce 18 window.alert(x + y); function creates/displays an alert box (on web page) Appears as popup (window) User must press OK to clear. 5(b) JavaScript does not have its own built-in capabilities/lacks capability for 1 displaying its output."},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":35,"name":"Q35 · Jasmine is using JavaScript on her web pages to provide interactivity","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q35-text","text":"Jasmine is using JavaScript on her web pages to provide interactivity. She has encountered some runtime errors during the testing of her Ja…","acceptedAnswer":{"@type":"Answer","text":"10 Six from: 6 Error event is triggered whenever an exception occurs in JavaScript code The onerror() function only captures the error The onerror() function stores the details of/data of error for later examination Function passes error event details to alert box for display to user Variables are used to pass parameters of the error to the program for further processing Msg is the message that the browser displays (to Jasmine) URL is the file name/path of code in which the error has occurred (so Jasmine knows which file to look in) Line is the line which contains the error (so Jasmine knows where to look in code)."},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":36,"name":"Q36 · Jasmine is using JavaScript on her web pages to provide interactivity","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q36-text","text":"Jasmine is using JavaScript on her web pages to provide interactivity. She has encountered some runtime errors during the testing of her Ja…","acceptedAnswer":{"@type":"Answer","text":"10 Six from: 6 Error event is triggered whenever an exception occurs in JavaScript code The onerror() function only captures the error The onerror() function stores the details of/data of error for later examination Function passes error event details to alert box for display to user Variables are used to pass parameters of the error to the program for further processing Msg is the message that the browser displays (to Jasmine) URL is the file name/path of code in which the error has occurred (so Jasmine knows which file to look in) Line is the line which contains the error (so Jasmine knows where to look in code)."},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":37,"name":"Q37 · JavaScript is an interpreted language that can be used on web pages","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q37-text","text":"JavaScript is an interpreted language that can be used on web pages. Runtime errors, called exceptions, can occur during the execution of J…","acceptedAnswer":{"@type":"Answer","text":"10 Six from e.g.: 6 Use of ‘throw’ to trap error/exception by testing block of code Use of ‘try’ to determine program flow when error occurs/handle the error/using nested blocks of code Use of ‘catch’ to allow execution of code after an error/generate custom error message via e.g. ‘message.innerHTML’/catch error in ‘err’ Use of ‘finally’ to execute code after catch/try/catch regardless of result from these Use of ‘error‘ object to provide information about the error ‘Error’ returns name with message about error for use in custom error handling Example of return from ‘error’ e.g. EvalError/ RangeError/ReferenceError/ SyntaxError /TypeError/URIError."},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":38,"name":"Q38 · JavaScript is a programming language used within HTML on web pages","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q38-text","text":"JavaScript is a programming language used within HTML on web pages. Explain why it is considered good practice when coding in JavaScript to…","acceptedAnswer":{"@type":"Answer","text":"3(a) Two from: 2 Creates cleaner/neater code Provides a single place to look for local variables Makes it easier to avoid unwanted (implied) global variables Reduces the possibility of unwanted re-declarations of variables. 3(b) Two from: 2 Avoids undefined values Creates concise code that is easier to follow/program Provides a single place to initialise variables. 3(c) One from: 1 Because it allows arbitrary/inserted code to be run It can create a security problem/issue when extra code is run. 3(d) Local variables must be declared with the var keyword otherwise they will 1 become global variables."},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":39,"name":"Q39 · JavaScript is an interpreted language that can be used on web pages","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q39-text","text":"JavaScript is an interpreted language that can be used on web pages. Runtime errors, called exceptions, can occur during the execution of J…","acceptedAnswer":{"@type":"Answer","text":"10 Six from e.g.: 6 Use of ‘throw’ to trap error/exception by testing block of code Use of ‘try’ to determine program flow when error occurs/handle the error/using nested blocks of code Use of ‘catch’ to allow execution of code after an error/generate custom error message via e.g. ‘message.innerHTML’/catch error in ‘err’ Use of ‘finally’ to execute code after catch/try/catch regardless of result from these Use of ‘error‘ object to provide information about the error ‘Error’ returns name with message about error for use in custom error handling Example of return from ‘error’ e.g. EvalError/ RangeError/ReferenceError/ SyntaxError /TypeError/URIError."},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":40,"name":"Q40 · The prompt() method is used in JavaScript to provide a popup dialog box for users to…","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q40-text","text":"The prompt() method is used in JavaScript to provide a popup dialog box for users to interact with web pages. (a) Explain how the result of…","acceptedAnswer":{"@type":"Answer","text":"7(a) Four from: 4 (Appropriate) variables are declared/used to store values Prompt() box pops up on screen Can display default entry/sample data entry required in the input box The user is required to input a value/text/string before being allowed to move on/creates a modal window The user is required to click/press/choose (either) OK or CANCEL/Escape key/close button If the user chooses OK then user input/value/string is returned to variable(s) If the user does not enter a value/string/text/input and then chooses OK, then NULL is returned to variable(s) If the user chooses CANCEL/close button/Escape then NULL value is returned to variable(s) 7(b) Two from: 2 Position of the dialog box cannot be specified by the programmer/is determined by the browser so may not be in the ‘best’ position for the user The appearance of the dialog box is determined by the browser/cannot be modified by the programmer so may not be as desired by the programmer The script is paused until the user interacts with the dialog box/creates a modal window so the user cannot access the rest of page until the box is closed Additional code is required to validate the entered data Some browsers/versions of browsers require a default value to be supplied by the programmer to make the dialog box appear correctly/may not appear/function properly in all browsers unless a default is supplied."},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":41,"name":"Q41 · JavaScript code can use comparison operators","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q41-text","text":"JavaScript code can use comparison operators. Explain how each of the following comparison operators works in JavaScript when comparing the…","acceptedAnswer":{"@type":"Answer","text":"8(a) Two from: Converts characters to same type if necessary Then compares values to determine if strictly equal/have same sequence of characters, same length, and same characters in corresponding positions/same value Returns TRUE if the same Returns FALSE if not the same. 8(b) Two from: Compares (both) type and value Returns TRUE if of the same value and different type Returns TRUE if of the same type and different value Returns FALSE if same type AND value. 2"},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":42,"name":"Q42 · The confirm() method is used in JavaScript to create and provide dialog boxes for users…","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q42-text","text":"The confirm() method is used in JavaScript to create and provide dialog boxes for users to interact with web pages. (a) Describe the purpos…","acceptedAnswer":{"@type":"Answer","text":"4(a) Two from: (Provides OK (button)) to indicate acceptance/verified by the user of choice (Provides Cancel (button)) to indicate rejection by the user of choice Provides a message specified by programmer to explain the choices available/question asked by programmer Provides (in some browsers) a Close (X) (button) on the top right of the box which may act as a cancel button. 4(b) Three from: User is forced to look at/interpret/read the message/attention drawn away from main web page display causing user to lose concentration on page content Input focus is taken away from the web site/pages until box is closed so no other user interaction is possible/creates a modal window Other codes may stop running/functioning until the dialogue box is closed causing errors/interruptions to web page/code/ user interactions Position of dialog box cannot be controlled by programmer so may block information on page Some browsers may not (properly) support all of the elements of the dialogue box so some actions may not be possible. 3 Question Answer Marks 4(c) Three from: Return value will be stored in a declared variable Return value is Boolean/either-or/one of two values If user clicks/chooses OK then TRUE is returned to the variable If user clicks cancel/close then FALSE is returned to the variable Result in variable can be used to display appropriate message depending on choice by user. 3"},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":43,"name":"Q43 · JavaScript code can use comparison operators","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q43-text","text":"JavaScript code can use comparison operators. Explain how each of the following comparison operators works in JavaScript when comparing the…","acceptedAnswer":{"@type":"Answer","text":"8(a) Two from: Converts characters to same type if necessary Then compares values to determine if strictly equal/have same sequence of characters, same length, and same characters in corresponding positions/same value Returns TRUE if the same Returns FALSE if not the same. 8(b) Two from: Compares (both) type and value Returns TRUE if of the same value and different type Returns TRUE if of the same type and different value Returns FALSE if same type AND value. 2"},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":44,"name":"Q44 · A programmer is writing some JavaScript code to display this text on a web page: This is…","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q44-text","text":"A programmer is writing some JavaScript code to display this text on a web page: This is “Cambridge International IT 9626 Paper 3” The prog…","acceptedAnswer":{"@type":"Answer","text":"9(a) (Strings are used) to store (and manipulate) characters. 1 9(b) Four from: 4 Use of same (type of) quotes causes code to stop executing so string is not displayed Code returns focus to HTML/stops browser from executing the remainder of page code JavaScript strings must be enclosed by matching quotes Quotes inside quotes cannot be the same as the enclosing quotes Inside quotes can be escaped/use of backslash i.e. \\ Quotes can be either single(‘) or double (“). 9(c) Five from: 5 Similarities: Both are part of the HTML Window object/Document Object Model controlling display of documents/parts of documents/both can be prefixed with window. Both takes/require two parameters inside the () separated by , First parameter in both references the function to be executed Second parameter in both sets is a time in milliseconds Both can be interrupted by clear Interval() function Differences: setTimeout() delays the execution of code which runs only once setInterval() allows/provides for repeated execution of the code at (pre-set) intervals clearInterval() can prevent function in setTimeout() from ever being executed/stop the timeout timer setInterval() loop only stops when the window is closed/clear Interval() is invoked/used setTimeout() minimum value is 0/zero (milliseconds) setInterval() minimum value is 10 (milliseconds)/if set to less than 10 then 10 is used."},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":45,"name":"Q45 · JavaScript code can be written to perform different actions depending on different…","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q45-text","text":"JavaScript code can be written to perform different actions depending on different conditions. (a) Describe the use of the switch operator,…","acceptedAnswer":{"@type":"Answer","text":"8(a) Four from: 4 • Variable is declared to store a specified condition • Switch () used to gather/hold/collect data to be tested against the variable • Use of case to enumerate/number condition/create blocks of code that could/may be executed • Variable with the condition listed for testing (against case) • Use of break to end/jump out of switch () when variable matches case/case matches variable • Use of default at end of code block to specify code to be executed if no match (by case) 8(b) Six from: 6 • Used in if/switch statements to test if conditions are true • Compare/determine the logic between (two or more) variables/values • Can be used with any data type producing a result of any data type • Can be used in a more complex manner than in other languages/valid example e.g. use of OR/|| to select from lists of variables • Represented by symbols not words (in JavaScript) • Double ‘not’/!! can be used to convert a value to Boolean data type • ‘not’ has higher precedence to ‘and’ which has higher precedence than ‘or’ in statements/’not’ is executed before ‘and’ which is executed before ‘or’ in statements • ‘and’/&& used to determine if both/all conditions are true and if so/all, are true returns true, if (any one condition) is not then it returns false • ‘or’/||/pipe symbol used to determine if one or other/either conditions are true and if so it returns true, else it returns false when both/all operands are false • ‘not’/! used to determine if values are the same/equal and if so it returns true, if not it returns false."},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":46,"name":"Q46 · JavaScript can be used in a web-based form to test whether a number entered by a user…","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q46-text","text":"JavaScript can be used in a web-based form to test whether a number entered by a user matches a certain condition and to select and output …","acceptedAnswer":{"@type":"Answer","text":"Question Answer Marks 1(a) Four from: 4  If … else allows different actions to occur as a condition/number is examined/evaluated  If the condition is TRUE an action is taken but/and/else  If the condition is FALSE another (different) action is taken  produce a Boolean result/  Number is stored in variable/declared variable  Comparison operators/equal/not equal/greater than/less than to test value of variable/number with pre-set/16 condition  (Statement used to provide) message if condition is TRUE  (ELSE statement used to provide) message if condition is FALSE. 1(b) Three from: 3  Reduces code to a single statement to make code/more efficient/execute faster/load quicker/take up less storage space  Code is less complex/easier to follow/understand (by programmers)/easier to wite/faster to write/simpler/less repetitive coding  Code is easier to debug/error check/less chance of error  Can run multiple operations with code that is easier to follow/understand."},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":47,"name":"Q47 · Describe each of the following terms when referring to JavaScript statements","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q47-text","text":"(a) Describe each of the following terms when referring to JavaScript statements. (i) operand .............................................…","acceptedAnswer":{"@type":"Answer","text":"7(a)(i) • The numbers used/involved in an arithmetical operation. 1 7(a)(ii) One from: 1 • The order of the arithmetic actions that will be/to be performed between/carried out on operands/numbers • Can be specified/changed by use of parentheses/(s) • Same presence operations are performed/calculated/computed from left to right/along statement from start to end. 7(a)(iii) • Used to give a value to a variable. 1 7(a)(iv) • Fixed values/numbers/strings (stored in/assigned to a variable). 1 7(b) One from: 1 • Names of HTML objects/properties • Names of any HTML event handlers • Names of HTML window handler objects/properties • (Reserved) terms/words that are keywords/reserved/used in other web programming languages e.g. Java objects/properties."},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":48,"name":"Q48 · Loops in JavaScript repeatedly execute blocks of code","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q48-text","text":"Loops in JavaScript repeatedly execute blocks of code. (a) Describe how a for loop works in JavaScript code. ..............................…","acceptedAnswer":{"@type":"Answer","text":"6(a) Four from: 4 • Loops through a block of code a number of times − depending on the outcome of testing a condition/counting a condition set in the code • Requires (at least/usually) three expressions/statements in the syntax − A declared variable/an expression to be evaluated (before each iteration) − Expression to be evaluated at start may be omitted/not always required/does not produce an error by JavaScript if omitted − Expression to be evaluated at end of each iteration/increment the value of the declared variable • Incrementing the variable at end of iteration/loop is optional • Loop continues until condition is met • Loop will/may continue forever if condition not met • If evaluate statement (which is expression 2) is omitted then a Break must be included to prevent loop going on forever Allow 1 mark for a valid example. 6(b) Two from: 2 • While loop tests condition at the beginning of the loop − whereas do while tests the condition at the end of the loop • While loop only executes the code block if condition is true − whereas do while executes the code block even if condition is false/test fails • Code block in while loop may never be executed − whereas code block in do while is always executed at least once."},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":49,"name":"Q49 · In JavaScript, an object is defined as a collection of properties which can be amended or…","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q49-text","text":"In JavaScript, an object is defined as a collection of properties which can be amended or deleted. (a) Describe how an object may be given …","acceptedAnswer":{"@type":"Answer","text":"7(a) • (A new property may be added) by assigning it/declaring a value. 1 7(b) Four from: 4 • JS code enclosed in HTML for use/to run in web browser • Use of the for…in loop (in JS) • Define a variable (var/const) for storing the (iterated) properties • Specify the object to examined/iterated • Enclose the code to be interrogated within brackets/{ } • Include code to count iterations of loop/code loops through/iterates through variable array of (stored) properties • Use code to pass results/results passed to HTML for display by browser/valid example e.g. document.getElementById(\"xx\").innerHTML = xx; • use of console.log() to pass results to browser console accessed by user."},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":50,"name":"Q50 · Describe each of the following terms when referring to JavaScript statements","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q50-text","text":"(a) Describe each of the following terms when referring to JavaScript statements. (i) operand .............................................…","acceptedAnswer":{"@type":"Answer","text":"7(a)(i) • The numbers used/involved in an arithmetical operation. 1 7(a)(ii) One from: 1 • The order of the arithmetic actions that will be/to be performed between/carried out on operands/numbers • Can be specified/changed by use of parentheses/(s) • Same presence operations are performed/calculated/computed from left to right/along statement from start to end. 7(a)(iii) • Used to give a value to a variable. 1 7(a)(iv) • Fixed values/numbers/strings (stored in/assigned to a variable). 1 7(b) One from: 1 • Names of HTML objects/properties • Names of any HTML event handlers • Names of HTML window handler objects/properties • (Reserved) terms/words that are keywords/reserved/used in other web programming languages e.g. Java objects/properties."},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":51,"name":"Q51 · Explain why break statements, functions and comments are used in JavaScript code","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q51-text","text":"Explain why break statements, functions and comments are used in JavaScript code. (a) Break statements ....................................…","acceptedAnswer":{"@type":"Answer","text":"2(a) Two from: 2 • Used to exit/break out of a switch/loop • When exiting a loop the code in the switch/loop stops • Any code outside/after a switch/loop is then executed. 2(b) Two from: 2 • Functions are (JavaScript) objects with properties • Declared/initiated by the function statement • Used to save a section of code for later/repeated use • Set of statements (in JS code) that perform a task/calculation (1st) – Must have/with input/return output (1) • (Only) invoked/executed/run when called/invoked by other code. 2(c) Two from: 2 • Used to explain (JavaScript) code • Used to stop/prevent code being executed (when testing alternative code) • Used to make code more understandable/allows (future) programmers to follow/debug/understand code • Single line comments begin with // • Multi line comments begin with /* and end with */"},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":52,"name":"Q52 · Web pages can be made more attractive and easier to read by using colours","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q52-text","text":"Web pages can be made more attractive and easier to read by using colours. All major web browsers support the use of HSL to specify the col…","acceptedAnswer":{"@type":"Answer","text":"2 Six from: 6  (Syntax is) hsl(…) used in HTML/CSS (for specifying a colour)  HSL is the hue, saturation and lightness of a colour – ALL 3 for 1 mark  Uses codes/HEX/example of hex value for colours  (Creates) gradients of colours (part of) RGB (model) (1st)  Red, green, blue – ALL 3 for 1 mark  Hue is a value/degree (on the standard colour wheel) (1st) ranging from 0 to 360 (1)  0 for red/120 for green/240 for blue (1)  Hue is ‘brightness’/how much white is added to a colour  Saturation is the intensity of the colour/from no colour/grey to full colour  Saturation is a percentage/% of the colour sign must included with the parameter (1)  Lightness ranges from black (through) to white  Lightness is a percentage/% of the colour/(1st) sign must included with the parameter (1)."},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":53,"name":"Q53 · JavaScript code has been developed for an interactive website","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q53-text","text":"JavaScript code has been developed for an interactive website. White box testing is carried out by the developers. (a) Describe how white b…","acceptedAnswer":{"@type":"Answer","text":"4(a) Six from: 6 Developers/testers…  create/write/use a test plan  create/write/use test data  test each/every line of code  test each/every branch in the code  test each/every condition in the code4  test the calculations/arithmetic  test the logic of the code  test inputs/outputs  can use (automated) testing tools to check code  if test fails/changes are made/errors are noted/errors are found/errors are corrected  repeat the testing  (must) have good knowledge/understanding of JavaScript theory/coding  (must) understand/learn/determine how the code/script works. 4(b) One from: 1  Code is used to collect user data/input for use in (subsequent) code/require an answer to a question  Use of confirm()/prompt() popup windows/box to enable user interaction  Code can be inserted into/placed within the HTML of the web page  Code can be stored in external scripts that are stored/executed when called/invoked by HTML code. 4(c) Five from: 5 Max three for naming valid events without descriptions:  Use of onload to execute the JavaScript immediately/as soon as the web page is (fully) loaded into a browser  Use of onchange to execute code when a user changes a value/state of radio button/checkbox  Use of onclick to execute code when a user clicks a button/HTML element  Use of onmouseover  to execute code when a user moves the mouse pointer onto/over an element e.g. an image  Use of onmouseout to execute code when a user moves the mouse pointer off/away from an element e.g. an image  Use of onkeydown to execute code when a user presses a key."},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":54,"name":"Q54 · JavaScript uses for loops to run through a block of code","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q54-text","text":"JavaScript uses for loops to run through a block of code. (a) In JavaScript, the for loop has the following syntax: for (Statement_1; State…","acceptedAnswer":{"@type":"Answer","text":"Question Answer Marks 1(a) Statement_1: 3 One from: • Initialises the counter with a starting value • sets the variable • Is executed (one time) before the execution of the block of code. Statement_2: One from: • Defines the condition for executing the block of code • Is the test statement / tests whether condition is true or not • If condition is true loop starts over/if false loop ends Statement_3: One from: • Counter/value in loop is incremented/decremented • Is the iteration statement • Is executed (every time) after the block of code has been executed. 1(b) Command word: Compare: identify/comment on similarities and/or differences. 3 Three from: Similarities: • Both used to execute/loop through a block of code repeatedly/number of times/over and over/iterate • Both have condition (statements) used (for comparison) when executing the block of code • Both have a limit on the number times the block of code is executed • stops after a set/pre-determined number of times Differences: • For loop used for going through a (sequential) array whereas for in loop is used with objects • For loop creates an integer which is used to index an array/count the number of iterations in order whereas for in loop executes in arbitrary order / not sequential order • For in loop is used for going through the properties of an object to check that the variable is a property of the object."},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":55,"name":"Q55 · JavaScript can manipulate and store strings in variables","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q55-text","text":"JavaScript can manipulate and store strings in variables. (a) Define the term string as used in JavaScript. ...............................…","acceptedAnswer":{"@type":"Answer","text":"Question Answer Marks 1(a) (An object representing) a sequence of (any) characters. 1 1(b) One from: 1 • Enclosing the characters inside quotes • Use of keyword newString to create a string object. 1(c)(i) Two from: 2 • Use the + operator to join the two variables // use of concat() • Use additional + to place a space inside speech marks / quotes / inverted commas / \" \" in between the two variables • Declare variable text3 • Ensure statement defining the new variable / text3 is placed after the assigning of text1 and text2 • Ensure the statement terminates in a semi-colon / ; Max one for example: • text3 = text1 + \" \" + text2; OR: use of concat() method i.e.: • text3 = text1.concat(\" \", text2); 1(c)(ii) Two from: 2 There are three methods for extracting a part of a string: Marks for: • identifying the keyword of the method • mark for describing that a start point and a corresponding end point/length is used to extract the characters One method, max two per method from: The methods are: • use keyword • slice(start, end) // slice() • substring(start, end) // substring() • substr(start, length) // substr() Allow other methods but syntax must be all correct."},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":56,"name":"Q56 · Programmers can use JavaScript to make a web page react when an HTML event occurs","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q56-text","text":"Programmers can use JavaScript to make a web page react when an HTML event occurs. (a) Describe what is meant by an HTML event. ...........…","acceptedAnswer":{"@type":"Answer","text":"Question Answer Marks 1(a) One mark per bullet point to a maximum of two marks. 2 • (An HTML Event is an action / occurrence) that happens in a web page / change in (interactive) element • by a user • by the browser. 1(b)(i) One mark per bullet point to a maximum of one mark. 1 • (start a script) when the mouse pointer moves / hovers over an element / image. 1(b)(ii) One mark per bullet point to a maximum of one mark. 1 • (start a script) when the mouse pointer moves away from / off an element / image. 1(b)(iii) One mark per bullet point to a maximum of one mark. 1 • (start a script is triggered) when a page has (completely) finished loading / is fully loaded into a browser."},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":57,"name":"Q57 · Arithmetic on numbers in JavaScript is carried out by using operators","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q57-text","text":"Arithmetic on numbers in JavaScript is carried out by using operators. Addition and subtraction are carried out by the + and – operators. (…","acceptedAnswer":{"@type":"Answer","text":"4(a)(i) ONE from: 1 • Increments / adds 1 to a number 4(a)(ii) ONE from: 2 • raises to the power/exponential / exponentiation • first number (in variable) / operand (raised) to that of second number / operand 4(b) FOUR from: 4 TWO arithmetic operators from: • * / star symbol (1) • multiplication/multiplies numbers together (1) • / / forward slash symbol (1) • division/divides one number into another (1) • % / percentage symbol (1) • modulus (remainder) (1) • - - / double minus symbols (1) • decrement/removes 1 from a number (1)"},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":58,"name":"Q58 · JavaScript statements can contain comparison operators such as > and <","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q58-text","text":"JavaScript statements can contain comparison operators such as > and <. (a) Describe the purpose of comparison operators. .................…","acceptedAnswer":{"@type":"Answer","text":"9(a) TWO from: 2 • used in logical operations • to determine equality / inequality (1st) between variables / values (1) • returns TRUE / FALSE as the result of the comparison 9(b) FOUR from: 4 • === returns TRUE if (both) the value and the type are equal / the same returns FALSE if either is unequal / not the same • !== returns TRUE if the value is not equal or the type is not equal returns FALSE if either is equal / the same"},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":59,"name":"Q59 · JavaScript code can be executed when an HTML event happens in a web browser","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q59-text","text":"JavaScript code can be executed when an HTML event happens in a web browser. An example of an HTML event is when a user clicks a mouse butt…","acceptedAnswer":{"@type":"Answer","text":"10(a) Four from: 4 • Onclick() captures the mouse click • (when user) clicks on the text1 (in line 5) • Passes control to script line 7 / function in line 8 • id parameter is passed to function • id.innerHTML changes text in HTML

(in line 9) • New text appears on web page. 10(b) Two from: 2 Examples of HTML events include, e.g.: • When a web page has loaded • When an image has been loaded • When the mouse moves over an HTML element • When an input field is changed • When an HTML form is submitted • When a user strokes / touches / presses a key"},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}},{"@type":"Question","position":60,"name":"Q60 · The JavaScript code in Fig","url":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3#q60-text","text":"The JavaScript code in Fig. 7.1 is executed when it is loaded into a web browser. The line numbers are for reference only. 1 2 tags • ALP3 is given id in line 4 • Array qp holds the text for display / [\"A Level\", \"IT\", \"9626\", \"Paper\", 3] • Variable paper declared / initialised to empty / blank / null / zero • for in used to loop / iterate through array • Variable x used to count / hold array items during loop iterations • Variable paper used to construct / hold array item plus line break − BR used to force line break on web page • Contents of variable paper written / passed back to HTML… using document.getElementById(\"ALP3\").innerHTML = paper − HTML element with id ALP3 − initiated before script as blank − JS changes its content to contents of variable paper − displayed on web page • Iterates through array until no more items left − JS script / code terminates / stops"},"educationalAlignment":{"@type":"AlignmentObject","alignmentType":"educationalSubject","educationalFramework":"Cambridge Information Technology (from 2017) 9626 syllabus","targetName":"Programming for the web"}}]},{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://pastlit.com"},{"@type":"ListItem","position":2,"name":"A Level","item":"https://pastlit.com/alevel"},{"@type":"ListItem","position":3,"name":"Information Technology (from 2017) 9626","item":"https://pastlit.com/alevel/information-technology-from-2017-9626"},{"@type":"ListItem","position":4,"name":"Topical","item":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical"},{"@type":"ListItem","position":5,"name":"Programming for the web","item":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web"},{"@type":"ListItem","position":6,"name":"Programming for the web","item":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web"},{"@type":"ListItem","position":7,"name":"Paper 3","item":"https://pastlit.com/alevel/information-technology-from-2017-9626/topical/21-programming-for-the-web/21-1-programming-for-the-web/paper-3"}]}]

Programming for the web — Paper 3 · A Level Information Technology (from 2017) 9626

21.1· 60 questions · 389 marks · 467 min · 2017–2025· Structured questions

Every Cambridge A Level Information Technology (from 2017) Paper 3 question on programming for the web, laid out as 66 A4 pages with the mark scheme below. Nothing is left out. Free to read, no account.

Questions66 pages

Question 1: JavaScript can be embedded in the code of web pages to add interactivity to a page. Jonas uses JavaScript code to store, list and display t…1 / 66
Question 1 (continued)2 / 66
Question 2: Frank is a web designer who writes his own code and uses JavaScript on his webpages. He wants to print his name on every page. He creates t…3 / 66
Question 3: JavaScript is a programming language used in webpages. Fig. 2 shows a table created with JavaScript in a webpage. 1 2 3 4 5 6 7 8 9 10 2 4 …4 / 66
Question 3 (continued)5 / 66
Question 4: Frank is a web designer who writes his own code and uses JavaScript on his webpages. He wants to print his name on every page. He creates t…6 / 66
Question 5: A shop is open between 12 noon and 10 pm. While the shop is closed in the morning, a message saying “Sorry, we are closed” is displayed. Af…7 / 66
Question 6: Drivers who are 16 years of age or older can apply for a driving licence online. The government web page code requires applicants to enter …8 / 66
Question 7: JavaScript defines a number of primitive data types. (a) Explain the term ‘primitive’ when used in this context. ..........................…Question 8: Variables are used in JavaScript to hold values. Explain how a variable is created in JavaScript code. ....................................…9 / 66
Question 9: ‘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 …10 / 66
Question 9 (continued)11 / 66
Question 10: 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 …Question 11: 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…12 / 66
Question 11 (continued)13 / 66
Question 11 (continued)14 / 66
Question 12: 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 …15 / 66
Question 13: 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…16 / 66
Question 13 (continued)Question 14: In JavaScript code, the sort() function is used to sort lists into ascending order. (a) Explain, in detail, why, when using the sort() func…17 / 66
Question 15: An online retailer uses a simple form on its website to enable customers to contact its After Sales department by email. The form looks lik…18 / 66
Question 15 (continued)19 / 66
Question 15 (continued)20 / 66
Question 16: 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. …21 / 66
Question 16 (continued)22 / 66
Question 17: In JavaScript code, the sort() function is used to sort lists into ascending order. (a) Explain, in detail, why, when using the sort() func…Question 18: An online retailer uses a simple form on its website to enable customers to contact its After Sales department by email. The form looks lik…23 / 66
Question 18 (continued)24 / 66
Question 18 (continued)25 / 66
Question 18 (continued)Question 19: The area of a rectangle can be calculated using the JavaScript embedded in a web page as shown below. 1 <html> 2 <body> 3 <script> 4 var le…Question 20: document.write(" The sides of the rectangle are " + length + " by " + width + ".</font><br>");26 / 66
Question 21: document.write(" The area of the rectangle is " + calc_area + ".</font><br>");Question 22: </html> 19 Explain, with reference to the code shown, how the JavaScript collects the dimensions of the rectangle, calculates the area and …27 / 66
Question 23: JavaScript uses strings to store data. This script is intended to display the contents of three variables on a web page. Line numbers are p…Question 24: 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 …28 / 66
Question 24 (continued)29 / 66
Question 24 (continued)Question 25: The area of a rectangle can be calculated using the JavaScript embedded in a web page as shown below. 1 <html> 2 <body> 3 <script> 4 var le…Question 26: document.write(" The sides of the rectangle are " + length + " by " + width + ".</font><br>");Question 27: document.write(" The area of the rectangle is " + calc_area + ".</font><br>");30 / 66
Question 28: </html> 19 Explain, with reference to the code shown, how the JavaScript collects the dimensions of the rectangle, calculates the area and …Question 29: In JavaScript, conditional statements can be used to carry out specific actions based upon different conditions. The value of the variable …31 / 66
Question 29 (continued)32 / 66
Question 30: Nigel is creating a website which uses JavaScript. He uses scripts to manipulate text held in HTML elements so that it can be displayed on …33 / 66
Question 31: A teacher is creating a web page for his students to find out their result, Merit, Pass or Fail, by entering their test score. The teacher …34 / 66
Question 31 (continued)35 / 66
Question 32: Nigel is creating a website which uses JavaScript. He uses scripts to manipulate text held in HTML elements so that it can be displayed on …36 / 66
Question 33: (a) Explain the meanings of these terms when referring to JavaScript objects. (i) string ..................................................…37 / 66
Question 33 (continued)Question 34: (a) The JavaScript code shown in Fig. 5.1 adds together 12 and 6 to produce the result 18. Line numbers are shown only for reference purpos…38 / 66
Question 34 (continued)Question 35: Jasmine is using JavaScript on her web pages to provide interactivity. She has encountered some runtime errors during the testing of her Ja…39 / 66
Question 36: Jasmine is using JavaScript on her web pages to provide interactivity. She has encountered some runtime errors during the testing of her Ja…40 / 66
Question 37: JavaScript is an interpreted language that can be used on web pages. Runtime errors, called exceptions, can occur during the execution of J…41 / 66
Question 38: JavaScript is a programming language used within HTML on web pages. Explain why it is considered good practice when coding in JavaScript to…42 / 66
Question 39: JavaScript is an interpreted language that can be used on web pages. Runtime errors, called exceptions, can occur during the execution of J…43 / 66
Question 40: The prompt() method is used in JavaScript to provide a popup dialog box for users to interact with web pages. (a) Explain how the result of…44 / 66
Question 41: JavaScript code can use comparison operators. Explain how each of the following comparison operators works in JavaScript when comparing the…45 / 66
Question 42: The confirm() method is used in JavaScript to create and provide dialog boxes for users to interact with web pages. (a) Describe the purpos…46 / 66
Question 43: JavaScript code can use comparison operators. Explain how each of the following comparison operators works in JavaScript when comparing the…Question 44: A programmer is writing some JavaScript code to display this text on a web page: This is “Cambridge International IT 9626 Paper 3” The prog…47 / 66
Question 44 (continued)48 / 66
Question 44 (continued)49 / 66
Question 45: JavaScript code can be written to perform different actions depending on different conditions. (a) Describe the use of the switch operator,…50 / 66
Question 46: JavaScript can be used in a web-based form to test whether a number entered by a user matches a certain condition and to select and output …51 / 66
Question 47: (a) Describe each of the following terms when referring to JavaScript statements. (i) operand .............................................…52 / 66
Question 48: Loops in JavaScript repeatedly execute blocks of code. (a) Describe how a for loop works in JavaScript code. ..............................…53 / 66
Question 49: In JavaScript, an object is defined as a collection of properties which can be amended or deleted. (a) Describe how an object may be given …54 / 66
Question 50: (a) Describe each of the following terms when referring to JavaScript statements. (i) operand .............................................…55 / 66
Question 51: Explain why break statements, functions and comments are used in JavaScript code. (a) Break statements ....................................…56 / 66
Question 52: Web pages can be made more attractive and easier to read by using colours. All major web browsers support the use of HSL to specify the col…Question 53: JavaScript code has been developed for an interactive website. White box testing is carried out by the developers. (a) Describe how white b…57 / 66
Question 53 (continued)58 / 66
Question 54: JavaScript uses for loops to run through a block of code. (a) In JavaScript, the for loop has the following syntax: for (Statement_1; State…59 / 66
Question 55: JavaScript can manipulate and store strings in variables. (a) Define the term string as used in JavaScript. ...............................…60 / 66
Question 56: Programmers can use JavaScript to make a web page react when an HTML event occurs. (a) Describe what is meant by an HTML event. ...........…61 / 66
Question 57: Arithmetic on numbers in JavaScript is carried out by using operators. Addition and subtraction are carried out by the + and – operators. (…62 / 66
Question 58: JavaScript statements can contain comparison operators such as > and <. (a) Describe the purpose of comparison operators. .................…63 / 66
Question 59: JavaScript code can be executed when an HTML event happens in a web browser. An example of an HTML event is when a user clicks a mouse butt…64 / 66
Question 60: The JavaScript code in Fig. 7.1 is executed when it is loaded into a web browser. The line numbers are for reference only. 1 <html> 2 <body…65 / 66
Question 60 (continued)66 / 66

Mark scheme60 answers

Answers below. Sit the paper first if you are practising.

Pastlit

Information Technology (from 2017) 9626 · Programming for the web — Paper 3

A Level · topical answer key — answer key (teacher use)

Question

Answer

Marks

1Mark scheme for question 113
2Mark scheme for question 26
3Mark scheme for question 38
4Mark scheme for question 46
5Mark scheme for question 56
6Mark scheme for question 68
7Mark scheme for question 75
8Mark scheme for question 84
9Mark scheme for question 915
10Mark scheme for question 106
11Mark scheme for question 1114
12Mark scheme for question 126
13Mark scheme for question 137
14Mark scheme for question 146
15Mark scheme for question 1516
16Mark scheme for question 168
17Mark scheme for question 176
18Mark scheme for question 1816
19Mark scheme for question 190
200
210
226
23Mark scheme for question 233
24Mark scheme for question 2410
25Mark scheme for question 250
260
270
286
29Mark scheme for question 2910
30Mark scheme for question 304
31Mark scheme for question 318
32Mark scheme for question 324
33Mark scheme for question 339
34Mark scheme for question 347
35Mark scheme for question 356
36Mark scheme for question 366
37Mark scheme for question 376
38Mark scheme for question 386
39Mark scheme for question 396
40Mark scheme for question 406
41Mark scheme for question 414
42Mark scheme for question 428
43Mark scheme for question 434
44Mark scheme for question 4410
45Mark scheme for question 4510
46Mark scheme for question 467
47Mark scheme for question 475
48Mark scheme for question 486
49Mark scheme for question 495
50Mark scheme for question 505
51Mark scheme for question 516
52Mark scheme for question 526
53Mark scheme for question 5312
54Mark scheme for question 546
55Mark scheme for question 556
56Mark scheme for question 565
57Mark scheme for question 577
58Mark scheme for question 586
59Mark scheme for question 596
60Mark scheme for question 606
QuestionAnswerMarksFrom
1see sheet139626/32 Feb/March 2017
2see sheet69626/31 May/June 2017
3see sheet89626/32 May/June 2017
4see sheet69626/33 May/June 2017
5see sheet69626/32 Oct/Nov 2017
6see sheet89626/32 Feb/March 2018
7see sheet59626/31 May/June 2018
8see sheet49626/31 May/June 2018
9see sheet159626/32 May/June 2018
10see sheet69626/33 May/June 2018
11see sheet149626/32 Oct/Nov 2018
12see sheet69626/33 Oct/Nov 2018
13see sheet79626/32 Feb/March 2019
14see sheet69626/31 May/June 2019
15see sheet169626/31 May/June 2019
16see sheet89626/32 May/June 2019
17see sheet69626/33 May/June 2019
18see sheet169626/33 May/June 2019
19see sheet09626/31 Oct/Nov 2019
20see sheet09626/31 Oct/Nov 2019
21see sheet09626/31 Oct/Nov 2019
22see sheet69626/31 Oct/Nov 2019
23see sheet39626/32 Oct/Nov 2019
24see sheet109626/32 Oct/Nov 2019
25see sheet09626/33 Oct/Nov 2019
26see sheet09626/33 Oct/Nov 2019
27see sheet09626/33 Oct/Nov 2019
28see sheet69626/33 Oct/Nov 2019
29see sheet109626/32 Feb/March 2020
30see sheet49626/31 May/June 2020
31see sheet89626/32 May/June 2020
32see sheet49626/33 May/June 2020
33see sheet99626/32 Oct/Nov 2020
34see sheet79626/33 Oct/Nov 2020
35see sheet69626/31 May/June 2021
36see sheet69626/33 May/June 2021
37see sheet69626/31 Oct/Nov 2021
38see sheet69626/32 Oct/Nov 2021
39see sheet69626/33 Oct/Nov 2021
40see sheet69626/32 Feb/March 2022
41see sheet49626/31 May/June 2022
42see sheet89626/32 May/June 2022
43see sheet49626/33 May/June 2022
44see sheet109626/32 Oct/Nov 2022
45see sheet109626/32 Feb/March 2023
46see sheet79626/32 May/June 2023
47see sheet59626/31 Oct/Nov 2023
48see sheet69626/32 Oct/Nov 2023
49see sheet59626/32 Oct/Nov 2023
50see sheet59626/33 Oct/Nov 2023
51see sheet69626/32 Feb/March 2024
52see sheet69626/32 May/June 2024
53see sheet129626/32 May/June 2024
54see sheet69626/32 Oct/Nov 2024
55see sheet69626/33 Oct/Nov 2024
56see sheet59626/32 Feb/March 2025
57see sheet79626/31 May/June 2025
58see sheet69626/32 May/June 2025
59see sheet69626/32 Oct/Nov 2025
60see sheet69626/33 Oct/Nov 2025

Another paper, or another topic

All of Programming for the web

Questions as text

Q1 · JavaScript can be embedded in the code of web pages to add interactivity to a page 9626/32 Feb/March 2017

9 JavaScript can be embedded in the code of web pages to add interactivity to a page. Jonas uses JavaScript code to store, list and display the names of cities on a web page. (a) Two methods of storing the names are shown below. Method 1: var city1 = "London"; var city2 = "Cambridge"; var city3 = "Oxford"; var city4 = "Manchester"; Method 2: var city = ["London", "Cambridge", "Oxford", "Manchester"]; Explain why storing the names using Method 2 is more suitable for storing large numbers of cities. … … … … … … … … … … [4] (b) Jonas has added some lines to the JavaScript code: /* The code below stores the list of cities. */ var city = ["London", "Cambridge", "Oxford", "Manchester"]; Explain why Jonas would have added the new code to the script. … … … … … [2] (c) Jonas wants to extract ‘Oxford’ from the list in the code below to display it on the web page. var city = ["London", "Cambridge", "Oxford", "Manchester"]; Write a line of JavaScript code to access the list and store the city name. … … … … … … [3] (d) Write a loop in JavaScript code to extract and display the first three city names. … … … … … … … … [4]

13 marks

Mark scheme: 9(a) Four from: 4 Method 2 uses an array... … which stores multiple values in a single variable More suitable for storing large numbers of items/data items as it reduces the complexity of the code Increases the code easier to understand Increases the execution speed of the code Method 2 can be looped through using an iterative function ...to find a specific data item 9(b) Two from: 2 Jonas wanted to explain/add comments to the code/what the line of code means/is for To make it clear that the code referred to a list of the cities Ensures that the explanation/comment was ignored by the web browser To make the code more readable/understandable 9(c) A suitable line of code would be: var place = city(2) 3 Three from: var =1 mark plus suitable variable name to store city e.g. place =1 mark = city(2) =1 mark 9(d) Suitable code would be: 4 for (b = 0; b <= 3; b++) { document.write (city (b)); } Marks, four from: for () 1 mark suitable var names 1 mark count from to 0 to 2 (b from 0 to <=3) 1 mark adding 1 inside loop (b++) 1 mark displaying the result of loop 1 mark

This question in 9626/32 Feb/March 2017

Q2 · Frank is a web designer who writes his own code and uses JavaScript on his webpages 9626/31 May/June 2017

3 Frank is a web designer who writes his own code and uses JavaScript on his webpages. He wants to print his name on every page. He creates two versions of the code to run his JavaScript on the webpage. These versions are represented here: Version 1: <script language="JavaScript"> document.write ("<p>My name is <b>Frank </b> </p>"); </script> Version 2: <script language="JavaScript" src="FranksJavaScriptcode.js"> </script> where the instructions for writing Frank’s name are in the file called “FranksJavaScriptcode.js” Explain why Frank prefers to use Version 2 of the code. … … … … … … … … … … … … … … [6]

6 marks

Mark scheme: 3 Six from: 6 Can call the code several times/from different pages/re-use the code No need of re-writing/having several copies/copies on each webpage Code only has to be tested once/checked for errors once File/JavaScript is cached by web browser ...reduces network access time/reduces cost of fetching data JavaScript code embedded in webpages can slow loading times/reduce browser performance ...webpage can slow/stop while browser executes code Can separate code into different conceptual/functional areas ...provides modularity to code ...separate html and JavaScript code so easier to read/maintain.

This question in 9626/31 May/June 2017

Q3 · JavaScript is a programming language used in webpages 9626/32 May/June 2017

9 JavaScript is a programming language used in webpages. Fig. 2 shows a table created with JavaScript in a webpage. 1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 12 14 16 18 20 3 6 9 12 15 18 21 24 27 30 4 8 12 16 20 24 28 32 36 40 5 10 15 20 25 30 35 40 45 50 6 12 18 24 30 36 42 48 54 60 7 14 21 28 35 42 49 56 63 70 8 16 24 32 40 48 56 64 72 80 9 18 27 36 45 54 63 72 81 90 10 20 30 40 50 60 70 80 90 100 Fig. 2 The code that created the table is shown below: <html> <body> <script language="javascript"> var tableout; tableout = "<table border='1' width='300' cellspacing='0' cellpadding='3'>" for (b = 1; b <= 10; b++) { tableout = tableout + "<tr>"; for (g = 1; g <= 10; g++) { tableout = tableout + "<td>" + b * g + "</td>"; } tableout = tableout + "</tr>"; } tableout = tableout + "</table>"; document.write (tableout); </script> </body> </html> Explain how the loops in the code create the table. … … … … … … … … … … … … … … … … … … … … … [8]

8 marks

Mark scheme: 9 Six from: 8 Code is embedded within the body HTML code (global) variable (tableout) is declared/created/initialised The HTML table values are placed within the variable First/outer loop (on 4th line of JS code) executes 10 times« «to create 10 rows using global variable and HTML <tr> code/to create each row Second/inner loop is executed each time outer loop executes «to create 10 columns/cells First time inner loop executes, the cell contains 1*1=1... «second time inner loop executes, the cell contains 1*2=2 «third time inner loop executes, the cell contains 1*3=3 «up to cell that contains 1*10=10 When inner loop reaches 10, first row of cells is complete« «next row is started with 2*1=2, 2*4 etc. «up to 2*10=20 The process continues until outer loop reaches 10 and all 10 rows have been created and filled.

This question in 9626/32 May/June 2017

Q4 · Frank is a web designer who writes his own code and uses JavaScript on his webpages 9626/33 May/June 2017

3 Frank is a web designer who writes his own code and uses JavaScript on his webpages. He wants to print his name on every page. He creates two versions of the code to run his JavaScript on the webpage. These versions are represented here: Version 1: <script language="JavaScript"> document.write ("<p>My name is <b>Frank </b> </p>"); </script> Version 2: <script language="JavaScript" src="FranksJavaScriptcode.js"> </script> where the instructions for writing Frank’s name are in the file called “FranksJavaScriptcode.js” Explain why Frank prefers to use Version 2 of the code. … … … … … … … … … … … … … … [6]

6 marks

Mark scheme: 3 Six from: 6 Can call the code several times/from different pages/re-use the code No need of re-writing/having several copies/copies on each webpage Code only has to be tested once/checked for errors once File/JavaScript is cached by web browser ...reduces network access time/reduces cost of fetching data JavaScript code embedded in webpages can slow loading times/reduce browser performance ...webpage can slow/stop while browser executes code Can separate code into different conceptual/functional areas ...provides modularity to code ...separate html and JavaScript code so easier to read/maintain.

This question in 9626/33 May/June 2017

Q5 · A shop is open between 12 noon and 10 pm 9626/32 Oct/Nov 2017

11 A shop is open between 12 noon and 10 pm. While the shop is closed in the morning, a message saying “Sorry, we are closed” is displayed. After the shop has closed in the evening a message saying “Please try again tomorrow” is displayed. At all other times, a message saying, “Hello, we are open now” is displayed. JavaScript code can be used to alter web pages in real time. Complete the code in the function below that will allow a user to find out if the shop is open or closed. function OpenTimesFunction() { var welcome; var timenow = new Date().getHours(); … … … … … … … … document.getElementById(“open”).innerHTML = welcome; //This line displays the result of the code } [6]

6 marks

Mark scheme: 11(b) Six from: 6 An example code is: if (timenow <12) { welcome = ‘Sorry, we are closed’; } else if (timenow < 22) { welcome = ‘Hello, we are open now’; } else { welcome = ‘Please try again tomorrow’; } 1 mark per correct line.

This question in 9626/32 Oct/Nov 2017

Q6 · Drivers who are 16 years of age or older can apply for a driving licence online 9626/32 Feb/March 2018

6 Drivers who are 16 years of age or older can apply for a driving licence online. The government web page code requires applicants to enter their age and then checks if they are old enough to apply. The following code captures the applicant’s age. When the applicant clicks the ‘Check now’ button the age is first checked to ensure that it is numeric. The age is then checked to see if the applicant is old enough. Suitable messages are displayed as a result of the checks. Complete the code for the function CheckAgeFunction that checks the age entered by the applicant and displays an appropriate response. <html> <body> <p>You can apply for a licence to drive when you are 16 years old.</p> <p>To check if you are old enough to drive, input your age and click the button:</p> <input id="AgeNow" value="16" /> <button onclick="CheckAgeFunction()">Check now</button> <p id="AgeCheck"></p> <script> function CheckAgeFunction() { … … … … … … … … … … … … [8] } document.getElementById("AgeCheck").innerHTML = CanApply; } </script> </body></html>

8 marks

Mark scheme: 6 Eight from: 8 Suitable code would be: var AgeNow, CanApply; AgeNow = Number(document.getElementById("AgeNow").value); if (isNaN(AgeNow)) { CanApply = "Please enter your age in numbers."; } else { CanApply = (AgeNow < 16)? "You are too young to apply for a licence.": "You are old enough to apply for a licence."; Mark points: 8 from: Declare the variables, must be exact variable names as in Question: var AgeNow, CanApply; Capture the input of the age: AgeNow=Number() Use of correct capture code: document.getElementById("AgeNow").value; Use of “isNaN” to check that the input is a number: if (isNaN(AgeNow)) Display error message if not a number: CanApply = "Please enter your age in numbers."; Use of “if...else” to make decision: } else { Use of comparison check: CanApply = (AgeNow < 16)? Appropriate display messages: e.g. "You are too young to apply for a licence.": "You are old enough to apply for a licence."; Messages match comparison: i.e.: < 16... too young; old enough >16 … old enough; too young

This question in 9626/32 Feb/March 2018

Q7 · JavaScript defines a number of primitive data types 9626/31 May/June 2018

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]

5 marks

Mark scheme: 2(a) Two from: 2 (The data type is) hard-coded/built-in Cannot be altered/is fixed Have no additional properties. 2(b) Three from: 3 String is a series of characters Number is any number, with or without decimal places Boolean has only two possible values, true or false Undefined is a variable without a value Null is ‘nothing’ but it is still an object in JavaScript, it is usually empty Symbol has a unique identifier, is static.

This question in 9626/31 May/June 2018

Q8 · Variables are used in JavaScript to hold values 9626/31 May/June 2018

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

4 marks

Mark scheme: 3 Four from: 4 Use a (suitable) name «. that is not a reserved word Declare the variable with ‘var’ (command word) Declared once only in the script/code Use as global or local variable but not both Initialise the variable with a value Do not use quotes around the variable name.

This question in 9626/31 May/June 2018

Q9 · ‘Loops’ are used in JavaScript to execute a block of code several times 9626/32 May/June 2018

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. … … … … … … … … … … … … … … [6] (c) The JavaScript code is deemed to be ‘client-side’ code. Explain why the use of ‘client-side’ code can cause problems. … … … … … … … … … [4]

15 marks

Mark scheme: 4(a) Five from: 5 Variables X and ‘displayresult’ are declared ...and cleared before use by loop Loop starts with X at 1 X is incremented by 3 each time it loops Continues until X reaches 10/while X is less than 10 Displays result as 1, 4, 7 With carriage return between each/on separate lines/underneath each other. 4(b) Suitable code could be: 6 <p id="Number"></p> /JavaScript code follows <script> var X = 1; do { document.getElementById("Number").innerHTML += X + "<br>"; X=X+3 } while (X < 10) </script> var X =1; 1 mark Do {...} 1 mark +=X 1 mark + “<br>” 1 mark X=X+3 1 mark while (X < 10) 1 mark 4(c) Four from: 4 The code is executed by the web browser Not on the web server Web browser may not support the code language So the code may not execute properly/at all/produce errors Different browsers run code in different ways Developers must test all code with all browsers Same browsers on different operating systems behave differently Code may produce different results Code requires high processing power So webpages may display slowly/not at all Non-functioning code may deter viewers leading to loss of audience/sales via the website.

This question in 9626/32 May/June 2018

Q10 · The use of JavaScript within the HTML code of a web page allows the page to react to user… 9626/33 May/June 2018

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.

6 marks

Mark scheme: 2 A suitable line of code would be: 6 document.getElementById(“button1”).addEventListener(“click”, checkreadpagefunction); Six from: 1 mark for each of: Capturing the element: document.getElementById Identifying the button by name: “button1” Checking for the event: addEventListener Correct reference to click by mouse: “click”, Calling the correct function by name: checkreadpagefunction); All correct delimiters and all correct brackets: . between key words, , after click AND ; after function () around button1 () around parameter (“click”, checkreadpagefunction);

This question in 9626/33 May/June 2018

Q11 · Quintin is a programmer who writes code in HTML and JavaScript for use in online forms 9626/32 Oct/Nov 2018

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. … … … … … … … … … … … … … … … … … … … … [8] (b) Explain why it is good practice that Quintin places his JavaScript code in external files rather than embeds the code in the actual page code. … … … … … … … … … … … … … … [6]

14 marks

Mark scheme: 5(a) Eight from: 8 Checking each line of code/statement Ensures that each line of code is executed at least once Ensures that var y and z assign the collected numbers as required Checks that the additon of y and z is correct Ensures that the correct message is displayed when result assigned to A Checking each branch/decision in the code Checks that decisions are carried out correctly So that values put in A can be compared Ensures that result is checked against > 10 Ensures that the correct result is put in var × as required Checks every possible pathway through the code So that test values in var y and z cause each subsequent path to be followed So that test values in x are assigned to A to produce both the messages “is greater than 10” and “is not greater than 10” depending on value in A. 5(b) Six from: 6 Can separate code into different conceptual/functional areas for ease of development/testing/understanding Separating HTML and JavaScript code provides modularity to code Which is easier to read/maintain/update by Quintin/different coders as required Can call the code several times/from different pages/re-use the code No need to rewrite/have several copies/copies on each web page Code only has to be tested once/checked for errors once File/JavaScript is cached by web browser No need to reload it/fetch code repeatedly if need on other pages Reduces network access/reduces cost of fetching data JavaScript code embedded in web pages can slow loading times/reduce browser performance Web page can slow/stop while browser executes code.

This question in 9626/32 Oct/Nov 2018

Q12 · JavaScript can be embedded in the code of web pages to add interactivity to a page 9626/33 Oct/Nov 2018

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]

6 marks

Mark scheme: 5(a) Stores multiple values in a single variable. 1 5(b) Containers for storing data values. 1 5(c) One from: 1 A block of code designed to perform a particular task Code executed when it is invoked (called). 5(d) One from: 1 Text preceded by // is not executed/ignored by JavaScript Used to explain the code Used to halt execution of the code Text that is not executed before a line of code Text that is not executed at end of line of code. 5(e) One from: 1 A collection of variables and functions Representing the attributes and behaviour of an ‘item’/‘thing’ being modelled in a program. 5(f) One from: 1 Any (valid) unit of code that resolves to a value Two types of expression exist: … can have a value … can assign a value to a variable.

This question in 9626/33 Oct/Nov 2018

Q13 · Errors in JavaScript code can cause the code to fail to execute when run by a web browser 9626/32 Feb/March 2019

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]

7 marks

Mark scheme: Question Answer Marks 1(a) Two from: 2 A colon (:) is shown instead of a semi-colon (;) in line 6 ...this is a syntax error Syntax errors prevent JavaScript from being executed/are fatal errors in code The web browser displays nothing at all from this code The variable ‘tableout’ has not been declared before it is used Some browsers will ignore/compensate/interpret this differently from others Results can be different/unexpected in different browsers. 1(b) Five from: 5 Add specific code to deal with the errors transparently/without affecting the web browser Specify block of code to be tested Add some code produce output that depends on (the type of) error encountered Use try() block of code to be tested Use catch() to define the error handling code Use final() to allow code to be executed/run Use throw() to display information about the error/error message Specify the text to be displayed on screen as a result of the error.

This question in 9626/32 Feb/March 2019

Q14 · In JavaScript code, the sort() function is used to sort lists into ascending order 9626/31 May/June 2019

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]

6 marks

Mark scheme: 2(a) Four from: 4 Function sort () treats values as strings not numbers Strings are sorted alphabetically Strings are not sorted numerically a is before / ‘lower’ than b so list 1 is sorted alphabetically by the first letter and then by the second etc. in list 2, the list is also sorted alphabetically so e.g. 1111 is before 12 because 2 is ‘bigger’ than 1 Max. 1 for additional examples e.g.: The third character in 1111 has no match so is ‘bigger’ than 12 3666 is before 37 because while the 3s match, and 6 is before 7, there is no match for the second 6 so it is ‘bigger’ than no number. 2(b) A suitable line with the function is: insects.reverse(); 2 The variable name can be anything suitable, reverse() is the function. Mark allocation: Use of suitable variable name e.g. insects 1 mark All correct function and syntax .reverse(); 1 mark

This question in 9626/31 May/June 2019

Q15 · An online retailer uses a simple form on its website to enable customers to contact its… 9626/31 May/June 2019

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 aftersales@mycompany.com: 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 aftersales@mycompany.com:</h2> 5 6 <form action="mailto: aftersales@mycompany.com" 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]

16 marks

Mark scheme: 3(a) Six from: 6 <form action="mailto: aftersales@mycompany.com" Tells the page that this is a form to be actioned by sending / submitting the form to a specified URL / default URL is this page To send an email via mailto to the specified address method="post" Specifies the HTTP method to be used when submitting the form In this case post means not to display the submitted data / used for sensitive or private / personal data / make the submitted data invisible in the field / will not allow bookmarking / is not saved in browser history Post can send unlimited amounts of data so no need to specify the size enctype="text/plain"> Specifies the encoding of the data As plain text. 3(b) Four from: 4 Line Code number 9 <input type="text" 1 mark name="name"> 1 mark <br> 1 mark 11 <input type="text name"="email"> <br> 1 mark 3(c) 6 Line Code number 13 <input type="text" name="comment" size="100"> 14 <input type="submit" value="Submit your details"> 15 <input type="reset" value="Reset the form"> Six from: Code on correct lines Correct syntax Size="100" or suitable value value="Submit your details" following submit value="Reset the form" following reset Correct input types 1 mark each

This question in 9626/31 May/June 2019

Q16 · An author has written the source code of a web page that will be used when a person… 9626/32 May/June 2019

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]

8 marks

Mark scheme: 3 8 Line number of error and Explanation of suggested explanation of error correction Line 6/9 and the function is spelt Should be same as function/ incorrectly / differently, so will not CheckAgeFunction/ run on button click CheckAgFunction Line 8 script is not opened so web Add <script> to open the script browser cannot interpret it Line 9 missing {/open curly bracket Add {/open curly bracket so line is not terminated correctly Line 10 the variable CanApply is Add , to separate variables / add not declared so cannot be used in new line with var / add CanApply function to declare the variable Line 15 age is wrongly shown as Should be 16 as per intended age 15 so age check is incorrectly check/stem/line 3 compared Line 15 incorrect logic comparison Change to < for correct so age messages are reversed comparison/reverse the messages when displayed to match comparison Line 17 “ is missing from Add “ ("AgeCheck “ so AgeCheck is not interpreted as p id so its value is not returned Line 19 script is not closed so web Add </script> to close the script browser cannot interpret it 1 mark for error and 1 mark for matching correction.

This question in 9626/32 May/June 2019

Q17 · In JavaScript code, the sort() function is used to sort lists into ascending order 9626/33 May/June 2019

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]

6 marks

Mark scheme: 2(a) Four from: 4 Function sort () treats values as strings not numbers Strings are sorted alphabetically Strings are not sorted numerically a is before / ‘lower’ than b so list 1 is sorted alphabetically by the first letter and then by the second etc. in list 2, the list is also sorted alphabetically so e.g. 1111 is before 12 because 2 is ‘bigger’ than 1 Max. 1 for additional examples e.g.: The third character in 1111 has no match so is ‘bigger’ than 12 3666 is before 37 because while the 3s match, and 6 is before 7, there is no match for the second 6 so it is ‘bigger’ than no number. 2(b) A suitable line with the function is: insects.reverse(); 2 The variable name can be anything suitable, reverse() is the function. Mark allocation: Use of suitable variable name e.g. insects 1 mark All correct function and syntax .reverse(); 1 mark

This question in 9626/33 May/June 2019

Q18 · An online retailer uses a simple form on its website to enable customers to contact its… 9626/33 May/June 2019

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 aftersales@mycompany.com: 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 aftersales@mycompany.com:</h2> 5 6 <form action="mailto: aftersales@mycompany.com" 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]

16 marks

Mark scheme: 3(a) Six from: 6 <form action="mailto: aftersales@mycompany.com" Tells the page that this is a form to be actioned by sending / submitting the form to a specified URL / default URL is this page To send an email via mailto to the specified address method="post" Specifies the HTTP method to be used when submitting the form In this case post means not to display the submitted data / used for sensitive or private / personal data / make the submitted data invisible in the field / will not allow bookmarking / is not saved in browser history Post can send unlimited amounts of data so no need to specify the size enctype="text/plain"> Specifies the encoding of the data As plain text. 3(b) Four from: 4 Line Code number 9 <input type="text" 1 mark name="name"> 1 mark <br> 1 mark 11 <input type="text name"="email"> <br> 1 mark 3(c) 6 Line Code number 13 <input type="text" name="comment" size="100"> 14 <input type="submit" value="Submit your details"> 15 <input type="reset" value="Reset the form"> Six from: Code on correct lines Correct syntax Size="100" or suitable value value="Submit your details" following submit value="Reset the form" following reset Correct input types 1 mark each

This question in 9626/33 May/June 2019

Q19 · The area of a rectangle can be calculated using the JavaScript embedded in a web page as… 9626/31 Oct/Nov 2019

11 The area of a rectangle can be calculated using the JavaScript embedded in a web page as shown below. 1 <html> 2 <body> 3 <script> 4 var length = parseFloat(prompt("Enter length of the rectangle : ")); 5 var width = parseFloat(prompt("Enter width of the rectangle : ")); 6 7 var calc_area = (length * width); 8 9 document.write("<br>"); 10 document.write("<h3> Area of a rectangle</h3>"); 11 document.write("<font face='arial' size='3'>")

0 marks

Mark scheme: 11 Six from: 6 Line 4 declares the variable/var length to hold one side of rectangle Line 5 declares the variable/var width to hold other side of rectangle parseFloat (prompt(“”)); used to display message parseFloat (prompt(“”)); used to collect values for both sides of rectangle parseFloat (prompt(“”)); used to create a (text) box for the user to enter the values Variable/var calc_area is declared to calculate the area Holds result of calculation document.write() is used to display the messages on screen about the values/area of the rectangle Displays the results of the calculation/contents of var calc_area.

This question in 9626/31 Oct/Nov 2019

Q20 · Document.write(" The sides of the rectangle are " + length + " by " + width +… 9626/31 Oct/Nov 2019

12 document.write(" The sides of the rectangle are " + length + " by " + width + ".</font><br>");

0 marks

This question in 9626/31 Oct/Nov 2019

Q21 · Document.write(" The area of the rectangle is " + calc_area + ".</font><br>"); 9626/31 Oct/Nov 2019

14 document.write(" The area of the rectangle is " + calc_area + ".</font><br>");

0 marks

This question in 9626/31 Oct/Nov 2019

Q22 · </html> 19 Explain, with reference to the code shown, how the JavaScript collects the… 9626/31 Oct/Nov 2019

18 </html> 19 Explain, with reference to the code shown, how the JavaScript collects the dimensions of the rectangle, calculates the area and displays the area on-screen. The lines of the code are numbered only for your convenience when referring to the code. … … … … … … … … … … … … … … [6]

6 marks

This question in 9626/31 Oct/Nov 2019

Q23 · JavaScript uses strings to store data 9626/32 Oct/Nov 2019

3 JavaScript uses strings to store data. This script is intended to display the contents of three variables on a web page. Line numbers are provided only for your convenience when referring to the code. 1 <html> 2 <body> 3 4 <p id="names"> </p> 5 <script> 6 var statementtxt1 = "It's only me, 'Hardeep'"; 7 var statementtxt2 = "His name is "Peter""; 8 var statementtxt3 = "We call her Jasmine"; 9 document.getElementById( 'names' ).innerHTML = statementtxt1 + "<br>" + statementtxt2 + "<br>" + statementtxt3; 10 </script> 11 </body> 12 </html> Explain, giving reasons, why no output is produced when this JavaScript is executed by a web browser as part of a web page. … … … … … … … … [3]

3 marks

Mark scheme: 3 Three from: 3 Line 7 contains a syntax error ”Peter” is enclosed in quotes that are the same as the quotes for the string (Strings in JavaScript can contain quotes but) the quotes in a string must not be the same as the enclosing quotes Any syntax error causes the script to fail/not run No error message is produced.

This question in 9626/32 Oct/Nov 2019

Q24 · A web page uses JavaScript code to display a list of food crops 9626/32 Oct/Nov 2019

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 … … … … … … [2]

10 marks

Mark scheme: 4(a) Eight from: 8 Code is embedded in HTML code of the website by <script> and </script> delimiters/markers The browser executes the JavaScript code within the delimiters Variable crops is set to contain the list of crops Variables i and show are initialised While loop will continue looping as long as crops[i] contains data/string (var) i is incremented by 1 each time loop is executed (var) show is set to the current value of show concatenated with next crop value Loop terminates when array has no more items/final value in array is reached Final values of (var) show are displayed on screen/web page Values shown in vertical list as <br> code forces carriage return/line feed. 4(b) Two from: 2 Amend the array var crops = [] 1 mark to [“beans”, "corn", "rice", "maize", "sugarcane"]; 1 mark Add the line crops.unshift("beans"); « 1 mark « any line between var crops and while() 1 mark Amend the var show line to « 1 mark « "beans <br>"; 1 mark

This question in 9626/32 Oct/Nov 2019

Q25 · The area of a rectangle can be calculated using the JavaScript embedded in a web page as… 9626/33 Oct/Nov 2019

11 The area of a rectangle can be calculated using the JavaScript embedded in a web page as shown below. 1 <html> 2 <body> 3 <script> 4 var length = parseFloat(prompt("Enter length of the rectangle : ")); 5 var width = parseFloat(prompt("Enter width of the rectangle : ")); 6 7 var calc_area = (length * width); 8 9 document.write("<br>"); 10 document.write("<h3> Area of a rectangle</h3>"); 11 document.write("<font face='arial' size='3'>")

0 marks

Mark scheme: 11 Six from: 6 Line 4 declares the variable/var length to hold one side of rectangle Line 5 declares the variable/var width to hold other side of rectangle parseFloat (prompt(“”)); used to display message parseFloat (prompt(“”)); used to collect values for both sides of rectangle parseFloat (prompt(“”)); used to create a (text) box for the user to enter the values Variable/var calc_area is declared to calculate the area Holds result of calculation document.write() is used to display the messages on screen about the values/area of the rectangle Displays the results of the calculation/contents of var calc_area.

This question in 9626/33 Oct/Nov 2019

Q26 · Document.write(" The sides of the rectangle are " + length + " by " + width +… 9626/33 Oct/Nov 2019

12 document.write(" The sides of the rectangle are " + length + " by " + width + ".</font><br>");

0 marks

This question in 9626/33 Oct/Nov 2019

Q27 · Document.write(" The area of the rectangle is " + calc_area + ".</font><br>"); 9626/33 Oct/Nov 2019

14 document.write(" The area of the rectangle is " + calc_area + ".</font><br>");

0 marks

This question in 9626/33 Oct/Nov 2019

Q28 · </html> 19 Explain, with reference to the code shown, how the JavaScript collects the… 9626/33 Oct/Nov 2019

18 </html> 19 Explain, with reference to the code shown, how the JavaScript collects the dimensions of the rectangle, calculates the area and displays the area on-screen. The lines of the code are numbered only for your convenience when referring to the code. … … … … … … … … … … … … … … [6]

6 marks

This question in 9626/33 Oct/Nov 2019

Q29 · In JavaScript, conditional statements can be used to carry out specific actions based… 9626/32 Feb/March 2020

9 In JavaScript, conditional statements can be used to carry out specific actions based upon different conditions. The value of the variable ‘age’ is entered into a web page and collected by the HTML code of the page. The function in Fig. 9.1 uses the ‘if else’ and ‘else if’ conditional statements to test the value of the variable ‘age’. Line numbers are shown only for your convenience when referring to the code. 1 function myFunction() { 2 var statement; 3 var age = document.getElementById("age").value; 4 if (age < 10) { 5 statement = "You are not old enough to go to this school"; 6 } else if (age < 18) { 7 statement = "You can go to this school"; 8 } else { 9 statement = "You are too old to go to this school"; 10 } Fig. 9.1 (a) Explain, with reference to the code in the function, how the ‘if else’ and ‘else if’ statements operate to provide the appropriate statement when an age is entered into the web page and collected by the HTML code. … … … … … … … … … … … … … … [6] (b) The code could have been written using the ‘switch’ function, e.g. lines 4 to 7 could have been: 4 switch(true) { 5 case age < 10: 6 statement = "You are not old enough to go to this school"; 7 break; with additional lines for the other conditions. Explain the drawbacks of using the ‘switch’ function. … … … … … … … … … … [4]

10 marks

Mark scheme: 9(a) Six from: 6 If statement specifies block of code that is executed if a condition is TRUE Line 4 if statement compares ‘age’ with condition <10 if TRUE ‘You are not old enough…’is stored in variable ‘statement’ if FALSE execution is passed to line 6 Else-if statement specifies a new condition to be checked if the first condition is FALSE Line 6 else if statement compares ‘age’ with condition <18 if TRUE ‘You can go to this school’ is stored in variable ‘statement’ if FALSE execution is passed to line 8 and "You are too old to go to this school" is stored in variable ‘statement’ Else statement specifies the code to be executed if condition is FALSE. 9(b) Four from: 4 The order of Case/conditions checks in code must be logically correct/perfect …for correct /expected comparisons to be made (Switch) syntax does not follow the usual rules/colons not semi-colons so code is difficult/confusing to write/read Code can be lengthy as each condition has to be individually stated …this is repetitive and prone to error ‘break’ has to be manually inserted after every ‘case’ ….debugging problems/difficulties with ‘nested’ conditions ’default’ condition should be included to catch/trap unexpected conditions.

This question in 9626/32 Feb/March 2020

Q30 · Nigel is creating a website which uses JavaScript 9626/31 May/June 2020

8 Nigel is creating a website which uses JavaScript. He uses scripts to manipulate text held in HTML elements so that it can be displayed on his pages. (a) Explain what is meant by an ‘HTML element’. … … … … … … [2] Nigel uses this code to manipulate the text on his page. The line numbers are shown only for reference purposes. 1 2 <html> 3 <body> 4 5 <h2>Nigel uses this JavaScript to change HTML</h2> 6 7 <p id="a1">Nigel's original text was here</p> 8 9 <script> 10 document.getElementById("a1").innerHTML = "Nigel changed this!"; 11 </script> 12 13 <p>The paragraph above was changed by Nigel's script.</p> 14 15 </body> 16 </html> (b) Explain, in detail, how this JavaScript would change what is displayed on the web page. … … … … … … [2]

4 marks

Mark scheme: 8(a) Two from: 2 Component of a webpage/HTML document. Surrounded/contained between tags. Starting tag has <name of tag> and ending tag has </name of tag> Node which can have attributes. Node can have ‘child nodes’. Part of the Document Object Model (DOM) when browser has parsed/read/displayed the HTML into a page. 8(b) Two from: 2 HTML document contains a <p> element with id="a1" HTML DOM is used to get the element with id="a1" (Line 7 changes the content of) innerHTML (to " Nigel changed this!").

This question in 9626/31 May/June 2020

Q31 · A teacher is creating a web page for his students to find out their result, Merit, Pass… 9626/32 May/June 2020

10 A teacher is creating a web page for his students to find out their result, Merit, Pass or Fail, by entering their test score. The teacher has chosen to use the JavaScript switch function to examine the test score entered by the student and report the result on the web page. The code for the web page is shown in Fig. 10.1. The lines are numbered only for your convenience. 1 2 <html> 3 <body> 4 5 <input id="myTscore" type="number" value=0> 6 <button onclick="tscorelookup()">Check Your Result by entering your test score 0-100 </button> 7 <p id="myresult"></p> 8 9 <script> 10 function tscorelookup(){ 11 var report; 12 var result = document.getElementById("myTscore").value; 13 14 switch(true){ 15 case result < 0: 16 report = "You cannot score a mark below 0"; 17 break; 18 case result > 100: 19 report = "You cannot score a mark above 100"; 20 break; 21 case result >= 40: 22 report = "Your result is a Merit"; 23 break; 24 case result >= 20: 25 report = "Your result is a Pass"; 26 break; 27 case result < 20: 28 report = "Your result is a Fail"; 29 break; 30 default: 31 report = "Please enter a valid mark"; 32 } 33 document.getElementById("myresult").innerHTML = report; 34 } 35 </script> 36 37 </body> 38 </html> Fig. 10.1 The HTML code in lines 5 to 7 collects the test score entered by the student and, when the button is clicked, makes the test score available to the JavaScript code that starts at line 9. Describe, in detail, how the JavaScript code works to handle a test score of 18. … … … … … … … … … … … … … … … … … … … … [8]

8 marks

Mark scheme: 10 Eight from: 8 Line 9 <script> declares the code to be JavaScript. Line 10 declares a function called tscorelookup() Line 11 declares variable report. Line 12 declares variable result. Line 12 collects value/18 of ‘myTScore’ from user input into HTML code at line 5 and stores it in variable ‘result’. Line 14 ‘switch’ function is used to compare the value in ‘result’ against pre- set ‘case’ values. Line 15 checks value of ‘result’ to see if condition <0 is TRUE. Line 18 checks value of ‘result’ to see if condition >100 is TRUE. Line 21 checks value of ‘result’ to see if condition >=40 is TRUE. Line 24 checks value of ‘result’ to see if condition >=20 is TRUE …none of these are TRUE/all are untrue/all of these are FALSE …control moves to next case. Line 27 checks value of ‘result to see if condition <20 is TRUE …this is TRUE so control passes to Line 28 and FAIL comment is stored in variable ‘report’. Line 33 function displays contents of variable ‘report’ on webpage/displays "Your result is a Fail"; ‘break’ is included to exit/jump out of any case ‘default’ is included in case no preceding case/condition is TRUE Including ‘default’ is good coding practice even if (probably) not required.

This question in 9626/32 May/June 2020

Q32 · Nigel is creating a website which uses JavaScript 9626/33 May/June 2020

8 Nigel is creating a website which uses JavaScript. He uses scripts to manipulate text held in HTML elements so that it can be displayed on his pages. (a) Explain what is meant by an ‘HTML element’. … … … … … … [2] Nigel uses this code to manipulate the text on his page. The line numbers are shown only for reference purposes. 1 2 <html> 3 <body> 4 5 <h2>Nigel uses this JavaScript to change HTML</h2> 6 7 <p id="a1">Nigel's original text was here</p> 8 9 <script> 10 document.getElementById("a1").innerHTML = "Nigel changed this!"; 11 </script> 12 13 <p>The paragraph above was changed by Nigel's script.</p> 14 15 </body> 16 </html> (b) Explain, in detail, how this JavaScript would change what is displayed on the web page. … … … … … … [2]

4 marks

Mark scheme: 8(a) Two from: 2 Component of a webpage/HTML document. Surrounded/contained between tags. Starting tag has <name of tag> and ending tag has </name of tag> Node which can have attributes. Node can have ‘child nodes’. Part of the Document Object Model (DOM) when browser has parsed/read/displayed the HTML into a page. 8(b) Two from: 2 HTML document contains a <p> element with id="a1" HTML DOM is used to get the element with id="a1" (Line 7 changes the content of) innerHTML (to " Nigel changed this!").

This question in 9626/33 May/June 2020

Q33 · Explain the meanings of these terms when referring to JavaScript objects 9626/32 Oct/Nov 2020

1 (a) Explain the meanings of these terms when referring to JavaScript objects. (i) string … … … [1] (ii) global … … … [1] (iii) regular expression … … … [1] (iv) operator … … … [1] (v) statement … … … [1] (b) Describe, in detail, the use of console.log() in JavaScript to output data for display. … … … … … … … … … … [4]

9 marks

Mark scheme: Question Answer Marks 1(a)(i) Text/characters within double/single quotes. 1 1(a)(ii) One from: 1 A variable declared outside a function A variable used throughout the script/program A value assigned to an undeclared variable. 1(a)(iii) One from: 1 Sequence of characters forming a search pattern (Object/character) patterns used with functions to search strings A description of what is being searched for. 1(a)(iv) (Arithmetic operators or) signs to compare/assign/calculate values. 1 1(a)(v) Instructions (in the code) that are executed/carried out (in order) by the 1 computer/web browser/interpreter. 1(b) Four from: 4 Writes a message to the browser console Requires later versions of browsers/not all browsers support the console Requires console to be open in browser/f12 to be pressed in browser to see the message Is used for testing purposes Information in brackets will appear in the console Two max from: Message is a string/object Is mandatory/required Can have more than one object Objects can be variables.

This question in 9626/32 Oct/Nov 2020

Q34 · The JavaScript code shown in Fig 9626/33 Oct/Nov 2020

5 (a) The JavaScript code shown in Fig. 5.1 adds together 12 and 6 to produce the result 18. Line numbers are shown only for reference purposes. 1 <html> 2 <head> 3 </head> 4 <body> 5 <br> 6 <h1>A Web Page</h1> 7 <p>A Paragraph</p> 8 <script> 9 var x, y; 10 x=12; 11 y=6; 12 window.alert(x + y); 13 </script> 14 </body> 15 </html> Fig. 5.1 Describe how the script operates to display the result on the screen. … … … … … … … … … … … … … … [6] JavaScript uses the display capabilities of web browsers’ windows to output the results of its scripts. (b) Explain why JavaScript uses a browser’s windows to display results of running scripts. … … … … [1]

7 marks

Mark scheme: 5(a) Six from: 6 Script embedded in HTML code/in body of HTML code …. between <script> </script> tags Variables x and y declared Values stored in x and y/x stores 12 and y stores 6 window.alert(x + y); function adds/sums x and y to produce 18 window.alert(x + y); function creates/displays an alert box (on web page) Appears as popup (window) User must press OK to clear. 5(b) JavaScript does not have its own built-in capabilities/lacks capability for 1 displaying its output.

This question in 9626/33 Oct/Nov 2020

Q35 · Jasmine is using JavaScript on her web pages to provide interactivity 9626/31 May/June 2021

10 Jasmine is using JavaScript on her web pages to provide interactivity. She has encountered some runtime errors during the testing of her JavaScript code. She has written some code including window.onerror = function (msg, url, line) The onerror() event handler will trap errors. Describe how this can help Jasmine locate the mistakes in the rest of her code. … … … … … … … … … … … … … … [6]

6 marks

Mark scheme: 10 Six from: 6 Error event is triggered whenever an exception occurs in JavaScript code The onerror() function only captures the error The onerror() function stores the details of/data of error for later examination Function passes error event details to alert box for display to user Variables are used to pass parameters of the error to the program for further processing Msg is the message that the browser displays (to Jasmine) URL is the file name/path of code in which the error has occurred (so Jasmine knows which file to look in) Line is the line which contains the error (so Jasmine knows where to look in code).

This question in 9626/31 May/June 2021

Q36 · Jasmine is using JavaScript on her web pages to provide interactivity 9626/33 May/June 2021

10 Jasmine is using JavaScript on her web pages to provide interactivity. She has encountered some runtime errors during the testing of her JavaScript code. She has written some code including window.onerror = function (msg, url, line) The onerror() event handler will trap errors. Describe how this can help Jasmine locate the mistakes in the rest of her code. … … … … … … … … … … … … … … [6]

6 marks

Mark scheme: 10 Six from: 6 Error event is triggered whenever an exception occurs in JavaScript code The onerror() function only captures the error The onerror() function stores the details of/data of error for later examination Function passes error event details to alert box for display to user Variables are used to pass parameters of the error to the program for further processing Msg is the message that the browser displays (to Jasmine) URL is the file name/path of code in which the error has occurred (so Jasmine knows which file to look in) Line is the line which contains the error (so Jasmine knows where to look in code).

This question in 9626/33 May/June 2021

Q37 · JavaScript is an interpreted language that can be used on web pages 9626/31 Oct/Nov 2021

10 JavaScript is an interpreted language that can be used on web pages. Runtime errors, called exceptions, can occur during the execution of JavaScript code. Explain how exceptions can be handled during the execution of JavaScript code. … … … … … … … … … … … … … … [6]

6 marks

Mark scheme: 10 Six from e.g.: 6 Use of ‘throw’ to trap error/exception by testing block of code Use of ‘try’ to determine program flow when error occurs/handle the error/using nested blocks of code Use of ‘catch’ to allow execution of code after an error/generate custom error message via e.g. ‘message.innerHTML’/catch error in ‘err’ Use of ‘finally’ to execute code after catch/try/catch regardless of result from these Use of ‘error‘ object to provide information about the error ‘Error’ returns name with message about error for use in custom error handling Example of return from ‘error’ e.g. EvalError/ RangeError/ReferenceError/ SyntaxError /TypeError/URIError.

This question in 9626/31 Oct/Nov 2021

Q38 · JavaScript is a programming language used within HTML on web pages 9626/32 Oct/Nov 2021

3 JavaScript is a programming language used within HTML on web pages. Explain why it is considered good practice when coding in JavaScript to: (a) place all declarations at the start of each script or function … … … … … … [2] (b) initialise variables when first declared … … … … … … [2] (c) avoid using eval() to run a string as code … … … [1] (d) always declare local variables. … … … [1]

6 marks

Mark scheme: 3(a) Two from: 2 Creates cleaner/neater code Provides a single place to look for local variables Makes it easier to avoid unwanted (implied) global variables Reduces the possibility of unwanted re-declarations of variables. 3(b) Two from: 2 Avoids undefined values Creates concise code that is easier to follow/program Provides a single place to initialise variables. 3(c) One from: 1 Because it allows arbitrary/inserted code to be run It can create a security problem/issue when extra code is run. 3(d) Local variables must be declared with the var keyword otherwise they will 1 become global variables.

This question in 9626/32 Oct/Nov 2021

Q39 · JavaScript is an interpreted language that can be used on web pages 9626/33 Oct/Nov 2021

10 JavaScript is an interpreted language that can be used on web pages. Runtime errors, called exceptions, can occur during the execution of JavaScript code. Explain how exceptions can be handled during the execution of JavaScript code. … … … … … … … … … … … … … … [6]

6 marks

Mark scheme: 10 Six from e.g.: 6 Use of ‘throw’ to trap error/exception by testing block of code Use of ‘try’ to determine program flow when error occurs/handle the error/using nested blocks of code Use of ‘catch’ to allow execution of code after an error/generate custom error message via e.g. ‘message.innerHTML’/catch error in ‘err’ Use of ‘finally’ to execute code after catch/try/catch regardless of result from these Use of ‘error‘ object to provide information about the error ‘Error’ returns name with message about error for use in custom error handling Example of return from ‘error’ e.g. EvalError/ RangeError/ReferenceError/ SyntaxError /TypeError/URIError.

This question in 9626/33 Oct/Nov 2021

Q40 · The prompt() method is used in JavaScript to provide a popup dialog box for users to… 9626/32 Feb/March 2022

7 The prompt() method is used in JavaScript to provide a popup dialog box for users to interact with web pages. (a) Explain how the result of the user interaction from prompt() is used by a programmer to collect the input from a user. … … … … … … … … … … … [4] (b) Explain two limitations of using the prompt() method of user interaction. 1 … … … 2 … … … [2]

6 marks

Mark scheme: 7(a) Four from: 4 (Appropriate) variables are declared/used to store values Prompt() box pops up on screen Can display default entry/sample data entry required in the input box The user is required to input a value/text/string before being allowed to move on/creates a modal window The user is required to click/press/choose (either) OK or CANCEL/Escape key/close button If the user chooses OK then user input/value/string is returned to variable(s) If the user does not enter a value/string/text/input and then chooses OK, then NULL is returned to variable(s) If the user chooses CANCEL/close button/Escape then NULL value is returned to variable(s) 7(b) Two from: 2 Position of the dialog box cannot be specified by the programmer/is determined by the browser so may not be in the ‘best’ position for the user The appearance of the dialog box is determined by the browser/cannot be modified by the programmer so may not be as desired by the programmer The script is paused until the user interacts with the dialog box/creates a modal window so the user cannot access the rest of page until the box is closed Additional code is required to validate the entered data Some browsers/versions of browsers require a default value to be supplied by the programmer to make the dialog box appear correctly/may not appear/function properly in all browsers unless a default is supplied.

This question in 9626/32 Feb/March 2022

Q41 · JavaScript code can use comparison operators 9626/31 May/June 2022

8 JavaScript code can use comparison operators. Explain how each of the following comparison operators works in JavaScript when comparing the number 1 with the text “1”. (a) the == operator … … … … … [2] (b) the !== operator … … … … … [2]

4 marks

Mark scheme: 8(a) Two from: Converts characters to same type if necessary Then compares values to determine if strictly equal/have same sequence of characters, same length, and same characters in corresponding positions/same value Returns TRUE if the same Returns FALSE if not the same. 8(b) Two from: Compares (both) type and value Returns TRUE if of the same value and different type Returns TRUE if of the same type and different value Returns FALSE if same type AND value. 2

This question in 9626/31 May/June 2022

Q42 · The confirm() method is used in JavaScript to create and provide dialog boxes for users… 9626/32 May/June 2022

4 The confirm() method is used in JavaScript to create and provide dialog boxes for users to interact with web pages. (a) Describe the purpose of two elements of the dialog box that appears when confirm() is used. … … … … … [2] (b) Explain why the use of confirm() may cause problems on web pages. … … … … … … … … [3] (c) Explain how the result of the user interaction from confirm() is reported back to the JavaScript code for use in the remaining code. … … … … … [3]

8 marks

Mark scheme: 4(a) Two from: (Provides OK (button)) to indicate acceptance/verified by the user of choice (Provides Cancel (button)) to indicate rejection by the user of choice Provides a message specified by programmer to explain the choices available/question asked by programmer Provides (in some browsers) a Close (X) (button) on the top right of the box which may act as a cancel button. 4(b) Three from: User is forced to look at/interpret/read the message/attention drawn away from main web page display causing user to lose concentration on page content Input focus is taken away from the web site/pages until box is closed so no other user interaction is possible/creates a modal window Other codes may stop running/functioning until the dialogue box is closed causing errors/interruptions to web page/code/ user interactions Position of dialog box cannot be controlled by programmer so may block information on page Some browsers may not (properly) support all of the elements of the dialogue box so some actions may not be possible. 3 Question Answer Marks 4(c) Three from: Return value will be stored in a declared variable Return value is Boolean/either-or/one of two values If user clicks/chooses OK then TRUE is returned to the variable If user clicks cancel/close then FALSE is returned to the variable Result in variable can be used to display appropriate message depending on choice by user. 3

This question in 9626/32 May/June 2022

Q43 · JavaScript code can use comparison operators 9626/33 May/June 2022

8 JavaScript code can use comparison operators. Explain how each of the following comparison operators works in JavaScript when comparing the number 1 with the text “1”. (a) the == operator … … … … … [2] (b) the !== operator … … … … … [2]

4 marks

Mark scheme: 8(a) Two from: Converts characters to same type if necessary Then compares values to determine if strictly equal/have same sequence of characters, same length, and same characters in corresponding positions/same value Returns TRUE if the same Returns FALSE if not the same. 8(b) Two from: Compares (both) type and value Returns TRUE if of the same value and different type Returns TRUE if of the same type and different value Returns FALSE if same type AND value. 2

This question in 9626/33 May/June 2022

Q44 · A programmer is writing some JavaScript code to display this text on a web page: This is… 9626/32 Oct/Nov 2022

9 A programmer is writing some JavaScript code to display this text on a web page: This is “Cambridge International IT 9626 Paper 3” The programmer uses strings in the code. (a) Describe the purpose of strings in JavaScript. … … … [1] (b) The programmer’s first attempt at the HTML and JavaScript code is shown in Fig. 9.1. Line numbers are shown only for your use when referring to the code. 1 <!DOCTYPE html> 2 <html> 3 <body> 4 5 <h2>This is "Cambridge Assessment International Education"</h2> 6 7 <p id="string"></p> 8 9 <script> 10 var x = "This is "Cambridge International IT 9626 Paper 3""; 11 document.getElementById("string").innerHTML = x; 12 </script> 13 14 </body> 15 </html> Fig. 9.1 When run in a web browser the HTML code outputs the heading in line 5 on the page. The browser executes the JavaScript code shown in lines 9 to 12. The expected output of the code on the web page is shown in Fig. 9.2 but the actual output is shown in Fig. 9.3. Fig. 9.2 Fig. 9.3 Explain why the error in line 10 prevents the JavaScript code from outputting: This is “Cambridge International IT 9626 Paper 3” … … … … … … … … … … … [4] (c) JavaScript programmers often wish to control when sections of their code are executed. Compare the use of setTimeout() and setInterval() for delaying the execution of JavaScript code. … … … … … … … … … … … … [5] Please turn over for Question 10.

10 marks

Mark scheme: 9(a) (Strings are used) to store (and manipulate) characters. 1 9(b) Four from: 4 Use of same (type of) quotes causes code to stop executing so string is not displayed Code returns focus to HTML/stops browser from executing the remainder of page code JavaScript strings must be enclosed by matching quotes Quotes inside quotes cannot be the same as the enclosing quotes Inside quotes can be escaped/use of backslash i.e. \ Quotes can be either single(‘) or double (“). 9(c) Five from: 5 Similarities: Both are part of the HTML Window object/Document Object Model controlling display of documents/parts of documents/both can be prefixed with window. Both takes/require two parameters inside the () separated by , First parameter in both references the function to be executed Second parameter in both sets is a time in milliseconds Both can be interrupted by clear Interval() function Differences: setTimeout() delays the execution of code which runs only once setInterval() allows/provides for repeated execution of the code at (pre-set) intervals clearInterval() can prevent function in setTimeout() from ever being executed/stop the timeout timer setInterval() loop only stops when the window is closed/clear Interval() is invoked/used setTimeout() minimum value is 0/zero (milliseconds) setInterval() minimum value is 10 (milliseconds)/if set to less than 10 then 10 is used.

This question in 9626/32 Oct/Nov 2022

Q45 · JavaScript code can be written to perform different actions depending on different… 9626/32 Feb/March 2023

8 JavaScript code can be written to perform different actions depending on different conditions. (a) Describe the use of the switch operator, such as switch(name), in JavaScript code to select different actions. … … … … … … … … … … [4] (b) Describe the use of logical operators in conditional statements in JavaScript code. … … … … … … … … … … … … … … [6]

10 marks

Mark scheme: 8(a) Four from: 4 • Variable is declared to store a specified condition • Switch () used to gather/hold/collect data to be tested against the variable • Use of case to enumerate/number condition/create blocks of code that could/may be executed • Variable with the condition listed for testing (against case) • Use of break to end/jump out of switch () when variable matches case/case matches variable • Use of default at end of code block to specify code to be executed if no match (by case) 8(b) Six from: 6 • Used in if/switch statements to test if conditions are true • Compare/determine the logic between (two or more) variables/values • Can be used with any data type producing a result of any data type • Can be used in a more complex manner than in other languages/valid example e.g. use of OR/|| to select from lists of variables • Represented by symbols not words (in JavaScript) • Double ‘not’/!! can be used to convert a value to Boolean data type • ‘not’ has higher precedence to ‘and’ which has higher precedence than ‘or’ in statements/’not’ is executed before ‘and’ which is executed before ‘or’ in statements • ‘and’/&& used to determine if both/all conditions are true and if so/all, are true returns true, if (any one condition) is not then it returns false • ‘or’/||/pipe symbol used to determine if one or other/either conditions are true and if so it returns true, else it returns false when both/all operands are false • ‘not’/! used to determine if values are the same/equal and if so it returns true, if not it returns false.

This question in 9626/32 Feb/March 2023

Q46 · JavaScript can be used in a web-based form to test whether a number entered by a user… 9626/32 May/June 2023

1 JavaScript can be used in a web-based form to test whether a number entered by a user matches a certain condition and to select and output an appropriate message. (a) Explain how if...else statements are used to do this. … … … … … … … … … … [4] (b) The ternary operator could be used instead of if...else. Explain why the ternary operator could be used to do this. … … … … … … … … [3]

7 marks

Mark scheme: Question Answer Marks 1(a) Four from: 4  If … else allows different actions to occur as a condition/number is examined/evaluated  If the condition is TRUE an action is taken but/and/else  If the condition is FALSE another (different) action is taken  produce a Boolean result/  Number is stored in variable/declared variable  Comparison operators/equal/not equal/greater than/less than to test value of variable/number with pre-set/16 condition  (Statement used to provide) message if condition is TRUE  (ELSE statement used to provide) message if condition is FALSE. 1(b) Three from: 3  Reduces code to a single statement to make code/more efficient/execute faster/load quicker/take up less storage space  Code is less complex/easier to follow/understand (by programmers)/easier to wite/faster to write/simpler/less repetitive coding  Code is easier to debug/error check/less chance of error  Can run multiple operations with code that is easier to follow/understand.

This question in 9626/32 May/June 2023

Q47 · Describe each of the following terms when referring to JavaScript statements 9626/31 Oct/Nov 2023

7 (a) Describe each of the following terms when referring to JavaScript statements. (i) operand … … … [1] (ii) operator precedence … … … [1] (iii) assignment operator … … … [1] (iv) literals … … … [1] (b) JavaScript has its own group of reserved keywords which cannot be used as names for variables, labels or functions. Describe one other group of reserved words that should not be used when writing JavaScript code for use on web pages. … … … [1]

5 marks

Mark scheme: 7(a)(i) • The numbers used/involved in an arithmetical operation. 1 7(a)(ii) One from: 1 • The order of the arithmetic actions that will be/to be performed between/carried out on operands/numbers • Can be specified/changed by use of parentheses/(s) • Same presence operations are performed/calculated/computed from left to right/along statement from start to end. 7(a)(iii) • Used to give a value to a variable. 1 7(a)(iv) • Fixed values/numbers/strings (stored in/assigned to a variable). 1 7(b) One from: 1 • Names of HTML objects/properties • Names of any HTML event handlers • Names of HTML window handler objects/properties • (Reserved) terms/words that are keywords/reserved/used in other web programming languages e.g. Java objects/properties.

This question in 9626/31 Oct/Nov 2023

Q48 · Loops in JavaScript repeatedly execute blocks of code 9626/32 Oct/Nov 2023

6 Loops in JavaScript repeatedly execute blocks of code. (a) Describe how a for loop works in JavaScript code. … … … … … … … … … … [4] (b) Contrast the use of while and do while loops in JavaScript code. … … … … … … [2]

6 marks

Mark scheme: 6(a) Four from: 4 • Loops through a block of code a number of times − depending on the outcome of testing a condition/counting a condition set in the code • Requires (at least/usually) three expressions/statements in the syntax − A declared variable/an expression to be evaluated (before each iteration) − Expression to be evaluated at start may be omitted/not always required/does not produce an error by JavaScript if omitted − Expression to be evaluated at end of each iteration/increment the value of the declared variable • Incrementing the variable at end of iteration/loop is optional • Loop continues until condition is met • Loop will/may continue forever if condition not met • If evaluate statement (which is expression 2) is omitted then a Break must be included to prevent loop going on forever Allow 1 mark for a valid example. 6(b) Two from: 2 • While loop tests condition at the beginning of the loop − whereas do while tests the condition at the end of the loop • While loop only executes the code block if condition is true − whereas do while executes the code block even if condition is false/test fails • Code block in while loop may never be executed − whereas code block in do while is always executed at least once.

This question in 9626/32 Oct/Nov 2023

Q49 · In JavaScript, an object is defined as a collection of properties which can be amended or… 9626/32 Oct/Nov 2023

7 In JavaScript, an object is defined as a collection of properties which can be amended or deleted. (a) Describe how an object may be given a new property. … … … … [1] (b) Describe how the properties of an object in JavaScript can be displayed using a loop. … … … … … … … … … … [4]

5 marks

Mark scheme: 7(a) • (A new property may be added) by assigning it/declaring a value. 1 7(b) Four from: 4 • JS code enclosed in HTML for use/to run in web browser • Use of the for…in loop (in JS) • Define a variable (var/const) for storing the (iterated) properties • Specify the object to examined/iterated • Enclose the code to be interrogated within brackets/{ } • Include code to count iterations of loop/code loops through/iterates through variable array of (stored) properties • Use code to pass results/results passed to HTML for display by browser/valid example e.g. document.getElementById("xx").innerHTML = xx; • use of console.log() to pass results to browser console accessed by user.

This question in 9626/32 Oct/Nov 2023

Q50 · Describe each of the following terms when referring to JavaScript statements 9626/33 Oct/Nov 2023

7 (a) Describe each of the following terms when referring to JavaScript statements. (i) operand … … … [1] (ii) operator precedence … … … [1] (iii) assignment operator … … … [1] (iv) literals … … … [1] (b) JavaScript has its own group of reserved keywords which cannot be used as names for variables, labels or functions. Describe one other group of reserved words that should not be used when writing JavaScript code for use on web pages. … … … [1]

5 marks

Mark scheme: 7(a)(i) • The numbers used/involved in an arithmetical operation. 1 7(a)(ii) One from: 1 • The order of the arithmetic actions that will be/to be performed between/carried out on operands/numbers • Can be specified/changed by use of parentheses/(s) • Same presence operations are performed/calculated/computed from left to right/along statement from start to end. 7(a)(iii) • Used to give a value to a variable. 1 7(a)(iv) • Fixed values/numbers/strings (stored in/assigned to a variable). 1 7(b) One from: 1 • Names of HTML objects/properties • Names of any HTML event handlers • Names of HTML window handler objects/properties • (Reserved) terms/words that are keywords/reserved/used in other web programming languages e.g. Java objects/properties.

This question in 9626/33 Oct/Nov 2023

Q51 · Explain why break statements, functions and comments are used in JavaScript code 9626/32 Feb/March 2024

2 Explain why break statements, functions and comments are used in JavaScript code. (a) Break statements … … … … … … [2] (b) Functions … … … … … … [2] (c) Comments … … … … … … [2]

6 marks

Mark scheme: 2(a) Two from: 2 • Used to exit/break out of a switch/loop • When exiting a loop the code in the switch/loop stops • Any code outside/after a switch/loop is then executed. 2(b) Two from: 2 • Functions are (JavaScript) objects with properties • Declared/initiated by the function statement • Used to save a section of code for later/repeated use • Set of statements (in JS code) that perform a task/calculation (1st) – Must have/with input/return output (1) • (Only) invoked/executed/run when called/invoked by other code. 2(c) Two from: 2 • Used to explain (JavaScript) code • Used to stop/prevent code being executed (when testing alternative code) • Used to make code more understandable/allows (future) programmers to follow/debug/understand code • Single line comments begin with // • Multi line comments begin with /* and end with */

This question in 9626/32 Feb/March 2024

Q52 · Web pages can be made more attractive and easier to read by using colours 9626/32 May/June 2024

2 Web pages can be made more attractive and easier to read by using colours. All major web browsers support the use of HSL to specify the colours used in web pages. Explain how HSL is used to specify colours. … … … … … … … … … … … … … … [6]

6 marks

Mark scheme: 2 Six from: 6  (Syntax is) hsl(…) used in HTML/CSS (for specifying a colour)  HSL is the hue, saturation and lightness of a colour – ALL 3 for 1 mark  Uses codes/HEX/example of hex value for colours  (Creates) gradients of colours (part of) RGB (model) (1st)  Red, green, blue – ALL 3 for 1 mark  Hue is a value/degree (on the standard colour wheel) (1st) ranging from 0 to 360 (1)  0 for red/120 for green/240 for blue (1)  Hue is ‘brightness’/how much white is added to a colour  Saturation is the intensity of the colour/from no colour/grey to full colour  Saturation is a percentage/% of the colour sign must included with the parameter (1)  Lightness ranges from black (through) to white  Lightness is a percentage/% of the colour/(1st) sign must included with the parameter (1).

This question in 9626/32 May/June 2024

Q53 · JavaScript code has been developed for an interactive website 9626/32 May/June 2024

4 JavaScript code has been developed for an interactive website. White box testing is carried out by the developers. (a) Describe how white box testing is used to test the code. … … … … … … … … … … … … … … [6] (b) Describe one way that JavaScript code can add interactivity to a web page. … … … … [1] (c) HTML events occur when users interact with a web page. Describe how JavaScript code can be made to react to an HTML event. … … … … … … … … … … … … [5]

12 marks

Mark scheme: 4(a) Six from: 6 Developers/testers…  create/write/use a test plan  create/write/use test data  test each/every line of code  test each/every branch in the code  test each/every condition in the code4  test the calculations/arithmetic  test the logic of the code  test inputs/outputs  can use (automated) testing tools to check code  if test fails/changes are made/errors are noted/errors are found/errors are corrected  repeat the testing  (must) have good knowledge/understanding of JavaScript theory/coding  (must) understand/learn/determine how the code/script works. 4(b) One from: 1  Code is used to collect user data/input for use in (subsequent) code/require an answer to a question  Use of confirm()/prompt() popup windows/box to enable user interaction  Code can be inserted into/placed within the HTML of the web page  Code can be stored in external scripts that are stored/executed when called/invoked by HTML code. 4(c) Five from: 5 Max three for naming valid events without descriptions:  Use of onload to execute the JavaScript immediately/as soon as the web page is (fully) loaded into a browser  Use of onchange to execute code when a user changes a value/state of radio button/checkbox  Use of onclick to execute code when a user clicks a button/HTML element  Use of onmouseover  to execute code when a user moves the mouse pointer onto/over an element e.g. an image  Use of onmouseout to execute code when a user moves the mouse pointer off/away from an element e.g. an image  Use of onkeydown to execute code when a user presses a key.

This question in 9626/32 May/June 2024

Q54 · JavaScript uses for loops to run through a block of code 9626/32 Oct/Nov 2024

1 JavaScript uses for loops to run through a block of code. (a) In JavaScript, the for loop has the following syntax: for (Statement_1; Statement_2; Statement_3){ // block of code to be executed is written here } Describe the purpose of each of the three statements: Statement_1 … … … Statement_2 … … … Statement_3 … … … [3] (b) Compare the use of a for loop with a for in loop. … … … … … … … … [3]

6 marks

Mark scheme: Question Answer Marks 1(a) Statement_1: 3 One from: • Initialises the counter with a starting value • sets the variable • Is executed (one time) before the execution of the block of code. Statement_2: One from: • Defines the condition for executing the block of code • Is the test statement / tests whether condition is true or not • If condition is true loop starts over/if false loop ends Statement_3: One from: • Counter/value in loop is incremented/decremented • Is the iteration statement • Is executed (every time) after the block of code has been executed. 1(b) Command word: Compare: identify/comment on similarities and/or differences. 3 Three from: Similarities: • Both used to execute/loop through a block of code repeatedly/number of times/over and over/iterate • Both have condition (statements) used (for comparison) when executing the block of code • Both have a limit on the number times the block of code is executed • stops after a set/pre-determined number of times Differences: • For loop used for going through a (sequential) array whereas for in loop is used with objects • For loop creates an integer which is used to index an array/count the number of iterations in order whereas for in loop executes in arbitrary order / not sequential order • For in loop is used for going through the properties of an object to check that the variable is a property of the object.

This question in 9626/32 Oct/Nov 2024

Q55 · JavaScript can manipulate and store strings in variables 9626/33 Oct/Nov 2024

1 JavaScript can manipulate and store strings in variables. (a) Define the term string as used in JavaScript. … … … [1] (b) Describe how a string can be created in JavaScript. … … … [1] (c) A variable text1 is used to store Cambridge and a variable text2 is used to store International Examinations in a block of JavaScript code. (i) Describe how the two strings can be joined together (concatenated) as Cambridge International Examinations and stored in a new variable called text3 in a JavaScript statement. … … … … … … [2] (ii) Describe one method by which the word Examinations can be extracted from text3 for use in another variable. … … … … … … [2]

6 marks

Mark scheme: Question Answer Marks 1(a) (An object representing) a sequence of (any) characters. 1 1(b) One from: 1 • Enclosing the characters inside quotes • Use of keyword newString to create a string object. 1(c)(i) Two from: 2 • Use the + operator to join the two variables // use of concat() • Use additional + to place a space inside speech marks / quotes / inverted commas / " " in between the two variables • Declare variable text3 • Ensure statement defining the new variable / text3 is placed after the assigning of text1 and text2 • Ensure the statement terminates in a semi-colon / ; Max one for example: • text3 = text1 + " " + text2; OR: use of concat() method i.e.: • text3 = text1.concat(" ", text2); 1(c)(ii) Two from: 2 There are three methods for extracting a part of a string: Marks for: • identifying the keyword of the method • mark for describing that a start point and a corresponding end point/length is used to extract the characters One method, max two per method from: The methods are: • use keyword • slice(start, end) // slice() • substring(start, end) // substring() • substr(start, length) // substr() Allow other methods but syntax must be all correct.

This question in 9626/33 Oct/Nov 2024

Q56 · Programmers can use JavaScript to make a web page react when an HTML event occurs 9626/32 Feb/March 2025

1 Programmers can use JavaScript to make a web page react when an HTML event occurs. (a) Describe what is meant by an HTML event. … … … … … … [2] (b) Describe the action that causes each of the following HTML events to start. (i) onmouseover() … … … [1] (ii) onmouseout() … … … [1] (iii) onload() … … … [1]

5 marks

Mark scheme: Question Answer Marks 1(a) One mark per bullet point to a maximum of two marks. 2 • (An HTML Event is an action / occurrence) that happens in a web page / change in (interactive) element • by a user • by the browser. 1(b)(i) One mark per bullet point to a maximum of one mark. 1 • (start a script) when the mouse pointer moves / hovers over an element / image. 1(b)(ii) One mark per bullet point to a maximum of one mark. 1 • (start a script) when the mouse pointer moves away from / off an element / image. 1(b)(iii) One mark per bullet point to a maximum of one mark. 1 • (start a script is triggered) when a page has (completely) finished loading / is fully loaded into a browser.

This question in 9626/32 Feb/March 2025

Q57 · Arithmetic on numbers in JavaScript is carried out by using operators 9626/31 May/June 2025

4 Arithmetic on numbers in JavaScript is carried out by using operators. Addition and subtraction are carried out by the + and – operators. (a) Describe the use of each of these arithmetic operators. (i) ++ … … … [1] (ii) ** … … … … … … [2] (b) Describe the use of two other arithmetic operators in JavaScript. … … … … … … … … … … [4]

7 marks

Mark scheme: 4(a)(i) ONE from: 1 • Increments / adds 1 to a number 4(a)(ii) ONE from: 2 • raises to the power/exponential / exponentiation • first number (in variable) / operand (raised) to that of second number / operand 4(b) FOUR from: 4 TWO arithmetic operators from: • * / star symbol (1) • multiplication/multiplies numbers together (1) • / / forward slash symbol (1) • division/divides one number into another (1) • % / percentage symbol (1) • modulus (remainder) (1) • - - / double minus symbols (1) • decrement/removes 1 from a number (1)

This question in 9626/31 May/June 2025

Q58 · JavaScript statements can contain comparison operators such as > and < 9626/32 May/June 2025

9 JavaScript statements can contain comparison operators such as > and <. (a) Describe the purpose of comparison operators. … … … … … … [2] (b) Explain the differences in function between the === and !== comparison operators. … … … … … … … … … … [4]

6 marks

Mark scheme: 9(a) TWO from: 2 • used in logical operations • to determine equality / inequality (1st) between variables / values (1) • returns TRUE / FALSE as the result of the comparison 9(b) FOUR from: 4 • === returns TRUE if (both) the value and the type are equal / the same returns FALSE if either is unequal / not the same • !== returns TRUE if the value is not equal or the type is not equal returns FALSE if either is equal / the same

This question in 9626/32 May/June 2025

Q59 · JavaScript code can be executed when an HTML event happens in a web browser 9626/32 Oct/Nov 2025

10 JavaScript code can be executed when an HTML event happens in a web browser. An example of an HTML event is when a user clicks a mouse button. (a) Describe how the JavaScript in this HTML code changes the display of text on the web page when a mouse button is clicked. The line numbers are included for reference only. 1 <html> 2 <body> 3 4 <h2>Cambridge International JS Code: HTML Event</h2> 5 <h2 onclick="changeText(this)">Click on this line to see the name of this 9626 QP</h2> 6 7 <script> 8 function changeText(id) { 9 id.innerHTML = "A Level IT Paper 3"; 10 } 11 </script> 12 13 </body> 14 </html> … … … … … … … … … … [4] (b) Describe two other HTML events that can be used to trigger the execution of JavaScript code. … … … … … … [2]

6 marks

Mark scheme: 10(a) Four from: 4 • Onclick() captures the mouse click • (when user) clicks on the text1 (in line 5) • Passes control to script line 7 / function in line 8 • id parameter is passed to function • id.innerHTML changes text in HTML <h2> (in line 9) • New text appears on web page. 10(b) Two from: 2 Examples of HTML events include, e.g.: • When a web page has loaded • When an image has been loaded • When the mouse moves over an HTML element • When an input field is changed • When an HTML form is submitted • When a user strokes / touches / presses a key

This question in 9626/32 Oct/Nov 2025

Q60 · The JavaScript code in Fig 9626/33 Oct/Nov 2025

7 The JavaScript code in Fig. 7.1 is executed when it is loaded into a web browser. The line numbers are for reference only. 1 <html> 2 <body> 3 4 <p id="ALP3"></p> 5 6 <script> 7 8 const qp = ["A Level", "IT", "9626", "Paper", 3]; 9 10 let paper = ""; 11 for (let x in qp) { 12 paper += qp[x] + "<BR>"; 13 } 14 15 document.getElementById("ALP3").innerHTML = paper; 16 17 </script> 18 19 </body> 20 </html> Fig. 7.1 Explain how the code produces the list shown in Fig.7.2. File | M:/CIE/202... A Level IT 9626 Paper 3 Fig. 7.2 … … … … … … … … … … … … … … [6]

6 marks

Mark scheme: 7 Six from: 6 • JS code embedded within HTML − inside < / script> tags • ALP3 is given id in line 4 • Array qp holds the text for display / ["A Level", "IT", "9626", "Paper", 3] • Variable paper declared / initialised to empty / blank / null / zero • for in used to loop / iterate through array • Variable x used to count / hold array items during loop iterations • Variable paper used to construct / hold array item plus line break − BR used to force line break on web page • Contents of variable paper written / passed back to HTML… using document.getElementById("ALP3").innerHTML = paper − HTML element with id ALP3 − initiated before script as blank − JS changes its content to contents of variable paper − displayed on web page • Iterates through array until no more items left − JS script / code terminates / stops

This question in 9626/33 Oct/Nov 2025