Question 4(b) 2018 · May-June · Paper 32 · 6 marks
Reveal official mark-scheme answer
Official answer for Question 4
Part (b)
Question 6
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]
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
