Past-paper question · 2020 February-March · Paper 32 · Q9(a)

Question 9(a) 2020 · February-March · Paper 32 · 6 marks

Question 9

Part (a)

Question 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

Part (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]

Question 14

Reveal official mark-scheme answer Official mark-scheme answer for 9(A)

Official answer for Question 9

Part (a)

✓
Six from:

Question 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.
✓
9626/32
✓
Cambridge International AS & A Level – Mark Scheme
✓
March 2020
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9626_m20_ms_32.pdf →

Topic relevance

Why this question appears here

98% assigned-topic match · Programming for the web

Topic-match percentages estimate how closely each question fits the selected syllabus topic. They are a guide for choosing stricter or broader practice.

Permanent source page: Educate A Change · From 9626_m20_qp_32.pdf

Keep practising this topic