Question 5(b) 2018 · October-November · Paper 32 · 6 marks
Reveal official mark-scheme answer
Official answer for Question 5
Part (b)
Question 6
Show text version of question
Question 5
Part (b)
Question 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>
Question 9
Part (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]
Question 11
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_w18_qp_32.pdf
