HTML gives a page structure, CSS controls presentation and JavaScript implements behaviour. Follow the input through those three roles, then distinguish finding a page from deciding how it ranks.
Content owner: Michael Print · Written for A-Level learners · Checked against official specifications
The idea to start with
HTML elements represent content and its structure; CSS rules select elements and style them; JavaScript reads input, applies logic and updates output. A browser runs client-side code, while server-side code executes on a server and can enforce trusted checks/access data.
A search engine crawls content and builds an index used to find relevant pages. PageRank considers the directed link graph, sharing a page's contribution across its outgoing links.
It is one link-ranking idea, not a guarantee of factual accuracy or a complete description of current search ranking.
Interpret the named HTML tags and CSS selectors/properties
Run and modify a simple three-file page
Distinguish client/server validation and processing
Explain indexing and calculate a small PageRank update
Read the appendix's HTML vocabulary
The html element contains the document; head holds metadata such as title and a link to CSS; body holds visible content. h1/h2/h3 form a heading hierarchy; p holds a paragraph; div groups content. An a element uses href for a destination.
An img uses src plus alt text and can state height/width. ol/ul contain li items for ordered/unordered lists. form groups controls; input type=text with a name supplies a text value, while type=submit submits it. script includes JavaScript.
The runnable example also introduces doctype, lang, charset and label for a valid accessible document; these additions are explained rather than silently treated as extra memorisation requirements. Label's for attribute matches an input id.
Meaningful alternative text provides the image's information when it is unavailable or cannot be seen. The embedded SVG is an original tiny diagram carried inside its image URL, so no separate picture download is needed.
Select and style elements
An element selector such as h1 matches headings of that type; .info matches elements with class=info; #result matches id=result. A class can be reused, whereas an id should identify one document element.
Inline style places declarations on one element; an external stylesheet keeps reusable rules in a linked file. Under ordinary author styles of the same importance/layer, an id selector has greater specificity than a class selector, which exceeds an element selector.
OCR names background-color, border-color, border-style, border-width, color, font-family, font-size, height and width, with named and hexadecimal colours. A visible border needs a style, not merely a width or colour. Our three files demonstrate these properties/selectors.
JavaScript's event listener, preventDefault, Number, Number.isInteger, trim, toFixed and textContent are explained conveniences; exact form-input API memorisation is not required by the appendix.
Save as index.html
Save all three files in the same folder, then open index.html in a browser. The form sends no real order and has no server: the listener prevents submission and computes a demonstration cost locally.
The unit cost is £3; quantity must be a whole number from 0 to 1000000 so multiplication stays within this bounded demonstration.
The body element rule chooses a font and colour. The class rule styles the reusable information region; the id rule styles the result. Named colours and hex colours are both shown. The image dimensions are attributes; CSS could instead control appropriate sizes.
The submit listener receives an event; preventDefault stops navigation/submission. trim removes surrounding whitespace; Number converts the supplied text.
Reject blank, non-integer, negative and over-limit input before calculation. textContent places text into an element without interpreting it as HTML. toFixed(2) formats this demonstration's result with two decimal places; real financial systems need an appropriate bounded amount representation.
calculator.js — input, selection and outputjavascript
const form = document.getElementById("cost-form");
const result = document.getElementById("result");
form.addEventListener("submit", function (event) {
event.preventDefault();
const raw = document.getElementById("quantity").value.trim();
const quantity = Number(raw);
if (raw === "" || !Number.isInteger(quantity) || quantity < 0 || quantity > 1000000) {
result.textContent = "Enter a whole quantity from 0 to 1000000.";
return;
}
result.textContent = "Total: £" + (quantity * 3).toFixed(2);
});
JavaScript control structures and output
JavaScript uses assignment and expressions, if/else selection, for/while iteration, arrays with zero-based indexes and function calls/returns. In a for loop, initialise the index once, test before each pass and update after the body.
A while loop also tests before executing, so it may run zero times. Keep the progress condition explicit.
OCR appendix output alternatives include alert(message), which requests a modal browser message, and document.write(text), which writes into the document stream. document.write can replace a loaded document and interprets markup, so this calculator uses textContent for text in an existing element.
Recognise the appendix forms while choosing output appropriate to the task. The pure example below uses console.log for a reproducible trace.
Client and server processing
Client-side validation gives quick feedback and reduces unnecessary requests; client-side rendering/calculation uses the user's device and can work locally. Users can change or bypass browser code, so a server must recheck any data on which a trusted decision depends.
In a real order, the server obtains its own price, validates quantity, checks authorisation and calculates the stored total.
Server-side processing can use protected credentials/databases and central rules, but needs connectivity and server capacity; responses may incur network delay. Choose both roles deliberately. Putting a secret into downloaded JavaScript does not keep it secret, and a disabled button is not an access-control boundary.
Crawling and indexing: make pages searchable
Stale content, inaccessible pages and crawling restrictions can limit the index. Index membership and query ranking are different tasks.
Find content before ranking results
1
Crawl
Discover/fetch pages and extract their content and links.
2
Index
Store searchable associations, such as which pages contain a term, so each query need not scan the web anew.
3
Rank
Order candidate results using suitable signals. PageRank is one historical link-ranking idea.
PageRank: share contributions through links
In a simple normalised PageRank model, PR(v) = (1−d)/N + d × sum(PR(u)/L(u)) over pages u linking to v. N is page count, d a damping factor and L(u) u's outgoing-link count. Each update uses all values from the preceding iteration.
Rank from a strongly ranked page matters, and its contribution is divided among its outlinks. Dangling pages require a rule to redistribute their rank; our example has none. Links do not establish truth, and current search systems use many signals beyond this historical model.
Worked example
Test the local calculator
Load the three files together. Submit 4: output is Total: £12.00. Submit 0: output is Total: £0.00. Submit 1000000: output is Total: £3000000.00.
Submit blank, -1, 1.5, hello or 1000001: each displays Enter a whole quantity from 0 to 1000000. The blank check is needed because Number of an empty string would otherwise be 0.
For OCR JavaScript practice, extend a pure function with a loop summing several valid quantities, and explain the accumulated total. The DOM/event mechanism only supplies input/output; the control structures remain the familiar programming constructs.
Worked example
JavaScript: iterate through quantities
Run this standalone JavaScript in a browser console or Node. Inputs are an array of at most 1000 integers, each from 0 to 1000000. No DOM is needed for this core algorithm.
For [2,0,3], i visits 0,1,2; cumulative units are 2,2,5. At i=3 the test i < quantities.length is false, so return 5×3=15. The empty array runs no for-loop body and returns zero.
A negative, fractional or over-limit quantity raises RangeError instead of silently producing a cost. With these limits even the maximum cost, 1000×1000000×3, is within exact JavaScript integer range.
The separate while loop counts remaining from 3 to 0. Changing it to start at zero runs no body; failing to reduce remaining would prevent termination.
Array trace for [2,0,3]
i
quantity
units after addition
0
2
2
1
0
2
2
3
5
Original JavaScript: arrays, for, while and a functionjavascript
function totalCost(quantities) {
if (!Array.isArray(quantities) || quantities.length > 1000) {
throw new TypeError("Use an array of at most 1000 quantities");
}
let units = 0;
for (let i = 0; i < quantities.length; i = i + 1) {
const quantity = quantities[i];
if (!Number.isInteger(quantity) || quantity < 0 || quantity > 1000000) {
throw new RangeError("Invalid quantity");
}
units = units + quantity;
}
return units * 3;
}
console.log(totalCost([2, 0, 3]));
console.log(totalCost([]));
let remaining = 3;
while (remaining > 0) {
remaining = remaining - 1;
}
console.log(remaining);
// Output: 15, then 0, then 0 on separate lines.
Worked example
One PageRank iteration
Pages have links A→B,C; B→C; C→A. Set N=3, d=0.85 and initial ranks A=B=C=1/3. The base contribution is (1−0.85)/3 = 0.05.
A receives all of C's old rank: 0.05 + 0.85×1/3 = 1/3. B receives half of A's: 0.05 + 0.85×1/6 = 23/120 ≈ 0.1917. C receives half of A's plus all of B's: 0.05 + 0.85×(1/6+1/3) = 19/40 = 0.475.
The exact new ranks sum to 1. C gains most in this iteration because it has the strongest combined incoming contribution, not simply because it has the most words. Reusing a newly calculated A rank when calculating B would change the synchronous algorithm.
One synchronous PageRank update; rounded display
Page
Old rank
Incoming old-rank contribution
New rank
A
0.3333
0.3333
0.3333
B
0.3333
0.1667
0.1917
C
0.3333
0.5000
0.4750
Original A-Level practice
7 original questions total 27 marks. Attempt each before opening the independently written indicative marking guidance.
Question 1
3 marks
Explain the roles of HTML, CSS and JavaScript in the calculator.
Show solution and marking guidance+
Indicative answer
1 mark: HTML supplies the form, headings and result element.
1 mark: CSS selects elements/classes/ids to control presentation.
1 mark: JavaScript validates quantity, calculates a value and updates output.
Question 2
3 marks
Write CSS to make elements with class warning have a pale background and a solid red 2px border.
Show solution and marking guidance+
Indicative answer
1 mark: use a class selector .warning.
1 mark: specify a valid pale background-color, such as #fff4cc.
1 mark: specify border-style: solid; border-color: red; border-width: 2px. A valid equivalent border shorthand is acceptable though beyond the named property list.
Question 3
4 marks
What does the calculator display for 3, 0 and blank input, and why does blank need a separate check?
Show solution and marking guidance+
Indicative answer
1 mark: 3 gives Total: £9.00.
1 mark: 0 gives Total: £0.00.
1 mark: blank gives the whole-quantity validation message.
1 mark: converting an empty string with Number gives 0, so conversion/integer checks alone would accept it.
Question 4
4 marks
A real shop trusts the browser's calculated total. Explain two necessary server actions and their purpose.
Show solution and marking guidance+
Indicative answer
1 mark: server validates quantity and permissions independently.
1 mark: users can bypass/edit client code, so browser acceptance is insufficient.
1 mark: server obtains an authoritative price and recalculates the total.
1 mark: this prevents a submitted altered price/total from determining the accepted order.
Question 5
5 marks
Trace totalCost for [1,4,0], state the returned value, and explain its empty-array and invalid-negative-input behaviour.
Show solution and marking guidance+
Indicative answer
Cumulative units are 1,5,5 (1).
Index 3 fails i < length, ending iteration (1).
Return value is 5×3=15 (1).
An empty array performs no additions and returns zero (1).
A negative quantity raises RangeError at validation instead of returning a cost (1).
Question 6
4 marks
Using the worked link graph, replace damping with d=0.6 and perform one update from equal initial ranks.
Show solution and marking guidance+
Indicative answer
1 mark: base contribution is 0.4/3 = 2/15.
1 mark: A = 2/15 + 0.6×1/3 = 1/3.
1 mark: B = 2/15 + 0.6×1/6 = 7/30 ≈ 0.2333.
1 mark: C = 2/15 + 0.6×1/2 = 13/30 ≈ 0.4333; exact total is 1.
Question 7
4 marks
Distinguish search indexing and PageRank, with a limitation of each.
Show solution and marking guidance+
Indicative answer
1 mark: indexing builds searchable associations/representations of page content.
1 mark: inaccessible/stale/unfetched pages can limit the index.
1 mark: PageRank distributes ranking contributions through incoming links.
1 mark: link rank is not proof of accuracy or the only signal determining current search results.
Specification and references
This guide addresses OCR H446 1.3.4(a–d); appendix 5d HTML, CSS and JavaScript scope. Check your examination year and the complete specification for the assessment scope.
These are independently written explanations and practice questions. CompSciTutoring.co.uk is not affiliated with or endorsed by an examination board. The marking guidance is indicative; always check the syllabus for your examination year.