Past-paper question · 2018 May-June · Paper 32 · Q4(b)

Question 4(b) 2018 · May-June · Paper 32 · 6 marks

Original past-paper question for 4(B)
Original past-paper question for 4(B)
Reveal official mark-scheme answer Official mark-scheme answer for 4(B)

Official answer for Question 4

Part (b)

✓
Suitable code could be:

Question 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

Mark scheme 9626_s18_ms_32.pdf →

Show text version of question

Question 4

Part (b)

Question 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>

Part (b)

Rewrite the ‘loop’ code as a DO WHILE loop to display the same results.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...............................................................................................................................................[6]

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_s18_qp_32.pdf

Keep practising this topic